Skip to contentSkip to conversation

FC Transport Extensions (FC sysfs)

RFC PATCH New Robert Love 1 participant 11 messages Aug 22, 2011

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

v2 cover FC Transport Extensions (FC sysfs)

v2 -

This update adds some attributes to the FC port and FC fabric devices that the original series defined. The newly exposed attributes were mostly chosen because they are members of libfcoe.ko and fcoe.ko's
'struct fcoe_interface' and 'struct fcoe_fcf'. These two structures are now allocated with the 'struct fc_port' and 'struct fc_fabric', respectively. I've also put some FIP controller attributes on the fc_port.

There is a SMHBA FCoE extension proposal that defines more devices than I have in this series. That proposal defines ports, phys, fabrics, and controllers. This series defines only ports and fabrics. I think that the attibutes for the ports, controllers and the host may be able to be added to a single device in sysfs. Should that just be the shost/fc_host? Phy(s) complicate this, but maybe there could just be a phy count on within 'struct fc_host_attrs'.

Before reading the SMHBA proposal I had the fc_port representing the fixed characteristics of the port (i.e. its capabilities) and the host's attributes describing the runtime properties of an N_Port or VN_Port. In this v2 series that distinction is not as clear as it was originally envisioned, mostly because I've added controller attributes to the fc_port.

====

v1 -

This is a functional series of patches that adds new API calls to the FC Transport to allow a LLD to create FC Port and FC Fabric devices. This series also has a patch to add the usage of these new APIs to libfc, libfcoe and fcoe.

This series originally started as a much larger effort. The original try created a FC subsystem that could link with SCSI as only one FC4 type. It allowed for other FC4s to register with the FC subsystem in the future. This model also created more devices than just the FC Port and FC Fabric. It made the vports we currently use more flexible and reordered the existing device tree to attach the Scsi_Host as a child of a FC vport device. It placed the vports and rports on fabrics and fabrics on ports. This model, although ideal from a FC standpoint, was quite complicated and impractical as generally only SCSI is transported over FC in modern adapters. This initial approach was abandoned following the last LSF conference.

A second approach was taken where there was less of a FC4 plug-in model, but the device tree was still re-arranged. This model also proved to be problematic mostly due to moving the Scsi_Host to be a child of a FC device. Specifically, libfc and fcoe had problems with circular locking around the Scsi_Host lock when dealing with the list of NPIV ports that was both maintained by the FC Transport as well as the N_Port's lport (for link events). Seeing that moving the Scsi_Host was being a pain I chose an even more simplified approach.

This series is that simplified approach. It simply adds the following APIs.

fc_port_add - Adds a FC Port Device to represent the
FC characteristics of a physical port
capable of FC or FCoE.
fc_port_del - Deletes a created FC Port.
fc_fabric_add - Adds a FC Fabric device to represent
the FC characteristics of a discovered
FC switch, FCF or underlying fabric.
fc_fabric_del - Deletes a created FC Fabric.

These APIs are extensions and should not impact any implementations using the current FC Transport interface.

I focused on functionality over attributes in this series. These patches work, under developer testing, and adding attributes shouldn't be too difficult. I have an idea of what attributes I'd like to add and there is a proposal to extend the HBA API that maps well to these two new devices that this series adds.

I opted to allow libfcoe to continue to manage FCF selection, but that logic could move to the transport.

I need to do some testing in both P2P (VN2VN) and target modes, but I believe that running this code as a SW FCoE initiator in a switched fabric environment is functional, including NPIV support.

The first 5 patches are pre-work patches for this series and may be able to be merged without the FC Transport additions (they still need official validation).

I'd be happy to share those (rough) patch series upon request.

---

Robert Love (10):
fcoe: Do not switch context in vport_delete callback
fcoe: Don't hold fcoe_config_mutex for fcoe_if_destroy or fcoe_interface_cleanup
fcoe: Remove reference counting on 'stuct fcoe_interface'
fcoe: Rename out_nomod label to out_putmod
FC Transport: Add API for LLDs to add FC port and FC fabric devices
fcoe: Use the new FC Transport APIs for FC ports and fabrics
FC Transport: Add Fabric Attributes
fcoe: Use fabric attributes
FC Transport: Add FC Port Attributes
libfcoe, fcoe: Use FC Port Attributes

 drivers/scsi/fcoe/fcoe.c           |  483 +++++++++++++-------
 drivers/scsi/fcoe/fcoe.h           |    6 
 drivers/scsi/fcoe/fcoe_ctlr.c      |  412 ++++++++++++++---
 drivers/scsi/fcoe/fcoe_transport.c |    7 
 drivers/scsi/libfc/fc_lport.c      |    2 
 drivers/scsi/scsi_transport_fc.c   |  871 +++++++++++++++++++++++++++++++++++-
 include/scsi/libfc.h               |    1 
 include/scsi/libfcoe.h             |   50 ++
 include/scsi/scsi_transport_fc.h   |  236 ++++++++++
 9 files changed, 1795 insertions(+), 273 deletions(-)
Signature · 1 line
Thanks, //Rob
#1 lore raw

RFC PATCH v2 1/10 fcoe: Do not switch context in vport_delete callback

Currently all port deletion is routed though the FCoE workqueue (fcoe_wq). When fc_remove_host is called on an N_Port (for example, from fcoe_destroy) the vports are queued into a FC Transport workqueue. fc_remove_host flushes that queue and each vport is passed to fcoe's fcoe_vport_destroy, which simply queues the associated fcoe_ports for later deletion. This queue cannot be flushed within the N_Ports destroy path because of circular locking issues. The result is that the NPIV ports are destroyed after the N_Port, which is reverse of how they are created.

This quirk causes fcoe to keep references on the fcoe_interface shared by each of these ports (N_Port and NPIV). This in itself is goofy, but isn't a problem until new APIs are added to allow LLDs to create a FC Port device. fcoe wants to allocate the fcoe_interface as driver data of the FC Transport's FC Port. The odd ordering creates locking problems between the Scsi_Host mutex and the fcoe_config_mutex when destroying the FC Port and freeing this LLD shared object.

This patch simply allows fcoe_vport_destory to destroy NPIV ports without deferring them to a workqueue context. This ensures that when fc_remove_host is called the NPIV ports will be destroyed first before the N_Port and allows reference counting on the fcoe's fcoe_interface to be remove in a later patch.

---
 drivers/scsi/fcoe/fcoe.c |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)
drivers/scsi/fcoe/fcoe.c +6 -9
index 781fbaa..0f621d3 100644
@@ -1943,20 +1943,14 @@ static void fcoe_destroy_work(struct work_struct *work)
 {
 	struct fcoe_port *port;
 	struct fcoe_interface *fcoe;
-	int npiv = 0;
 
 	port = container_of(work, struct fcoe_port, destroy_work);
 	mutex_lock(&fcoe_config_mutex);
 
-	/* set if this is an NPIV port */
-	npiv = port->lport->vport ? 1 : 0;
-
 	fcoe = port->priv;
 	fcoe_if_destroy(port->lport);
 
-	/* Do not tear down the fcoe interface for NPIV port */
-	if (!npiv)
-		fcoe_interface_cleanup(fcoe);
+	fcoe_interface_cleanup(fcoe);
 
 	mutex_unlock(&fcoe_config_mutex);
 }
@@ -2485,12 +2479,15 @@ static int fcoe_vport_destroy(struct fc_vport *vport)
 	struct Scsi_Host *shost = vport_to_shost(vport);
 	struct fc_lport *n_port = shost_priv(shost);
 	struct fc_lport *vn_port = vport->dd_data;
-	struct fcoe_port *port = lport_priv(vn_port);
 
 	mutex_lock(&n_port->lp_mutex);
 	list_del(&vn_port->list);
 	mutex_unlock(&n_port->lp_mutex);
-	queue_work(fcoe_wq, &port->destroy_work);
+
+	mutex_lock(&fcoe_config_mutex);
+	fcoe_if_destroy(vn_port);
+	mutex_unlock(&fcoe_config_mutex);
+
 	return 0;
 }
 
#2 lore raw

RFC PATCH v2 2/10 fcoe: Don't hold fcoe_config_mutex for fcoe_if_destroy or fcoe_interface_cleanup

In reply to Robert Love

The fcoe_config_mutex is used to synchronize the hostlist, to protect EM creation and cloning and to serialize the creating and deltion of fcoe instances.

It is not needed to protect anything in either fcoe_if_destroy or fcoe_interface_cleanup. This unnecessary locking causes later problems with the usage of upcoming FC Transport API extensions.

This patch simply removes the unnecessary use of the fcoe_config_mutex.

---
 drivers/scsi/fcoe/fcoe.c |   13 +++----------
 1 files changed, 3 insertions(+), 10 deletions(-)
drivers/scsi/fcoe/fcoe.c +3 -10
index 0f621d3..30ead6f 100644
@@ -1941,18 +1941,13 @@ out_nodev:
  */
 static void fcoe_destroy_work(struct work_struct *work)
 {
-	struct fcoe_port *port;
-	struct fcoe_interface *fcoe;
-
-	port = container_of(work, struct fcoe_port, destroy_work);
-	mutex_lock(&fcoe_config_mutex);
+	struct fcoe_port *port =
+		container_of(work, struct fcoe_port, destroy_work);
+	struct fcoe_interface *fcoe = port->priv;
 
-	fcoe = port->priv;
 	fcoe_if_destroy(port->lport);
 
 	fcoe_interface_cleanup(fcoe);
-
-	mutex_unlock(&fcoe_config_mutex);
 }
 
 /**
@@ -2484,9 +2479,7 @@ static int fcoe_vport_destroy(struct fc_vport *vport)
 	list_del(&vn_port->list);
 	mutex_unlock(&n_port->lp_mutex);
 
-	mutex_lock(&fcoe_config_mutex);
 	fcoe_if_destroy(vn_port);
-	mutex_unlock(&fcoe_config_mutex);
 
 	return 0;
 }
#3 lore raw

RFC PATCH v2 3/10 fcoe: Remove reference counting on 'stuct fcoe_interface'

In reply to Robert Love

The reference counting was necessary on these instances because it was possible for NPIV ports to be destroyed after the N_Port. A previous patch ensures that all NPIV ports are destroyed before the N_Port making the need to track references on the interface unnecessary.

---
 drivers/scsi/fcoe/fcoe.c |   48 +++++-----------------------------------------
 drivers/scsi/fcoe/fcoe.h |    3 ---
 2 files changed, 5 insertions(+), 46 deletions(-)
drivers/scsi/fcoe/fcoe.c +5 -43
index 30ead6f..f61e1dc 100644
@@ -356,7 +356,6 @@ static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
 	}
 
 	dev_hold(netdev);
-	kref_init(&fcoe->kref);
 
 	/*
 	 * Initialize FIP.
@@ -384,42 +383,6 @@ out:
 }
 
 /**
- * fcoe_interface_release() - fcoe_port kref release function
- * @kref: Embedded reference count in an fcoe_interface struct
- */
-static void fcoe_interface_release(struct kref *kref)
-{
-	struct fcoe_interface *fcoe;
-	struct net_device *netdev;
-
-	fcoe = container_of(kref, struct fcoe_interface, kref);
-	netdev = fcoe->netdev;
-	/* tear-down the FCoE controller */
-	fcoe_ctlr_destroy(&fcoe->ctlr);
-	kfree(fcoe);
-	dev_put(netdev);
-	module_put(THIS_MODULE);
-}
-
-/**
- * fcoe_interface_get() - Get a reference to a FCoE interface
- * @fcoe: The FCoE interface to be held
- */
-static inline void fcoe_interface_get(struct fcoe_interface *fcoe)
-{
-	kref_get(&fcoe->kref);
-}
-
-/**
- * fcoe_interface_put() - Put a reference to a FCoE interface
- * @fcoe: The FCoE interface to be released
- */
-static inline void fcoe_interface_put(struct fcoe_interface *fcoe)
-{
-	kref_put(&fcoe->kref, fcoe_interface_release);
-}
-
-/**
  * fcoe_interface_cleanup() - Clean up a FCoE interface
  * @fcoe: The FCoE interface to be cleaned up
  *
@@ -466,7 +429,11 @@ void fcoe_interface_cleanup(struct fcoe_interface *fcoe)
 	rtnl_unlock();
 
 	/* Release the self-reference taken during fcoe_interface_create() */
-	fcoe_interface_put(fcoe);
+	/* tear-down the FCoE controller */
+	fcoe_ctlr_destroy(fip);
+	kfree(fcoe);
+	dev_put(netdev);
+	module_put(THIS_MODULE);
 }
 
 /**
@@ -885,9 +852,6 @@ static void fcoe_if_destroy(struct fc_lport *lport)
 		dev_uc_del(netdev, port->data_src_addr);
 	rtnl_unlock();
 
-	/* Release reference held in fcoe_if_create() */
-	fcoe_interface_put(fcoe);
-
 	/* Free queued packets for the per-CPU receive threads */
 	fcoe_percpu_clean(lport);
 
@@ -1074,7 +1038,6 @@ static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
 		goto out_lp_destroy;
 	}
 
-	fcoe_interface_get(fcoe);
 	return lport;
 
 out_lp_destroy:
@@ -1946,7 +1909,6 @@ static void fcoe_destroy_work(struct work_struct *work)
 	struct fcoe_interface *fcoe = port->priv;
 
 	fcoe_if_destroy(port->lport);
-
 	fcoe_interface_cleanup(fcoe);
 }
 
drivers/scsi/fcoe/fcoe.h +0 -3
index c4a9399..a1c3b54 100644
@@ -73,8 +73,6 @@ do {                                                            	\
  * @ctlr:	      The FCoE controller (for FIP)
  * @oem:	      The offload exchange manager for all local port
  *		      instances associated with this port
- * @kref:	      The kernel reference
- *
  * This structure is 1:1 with a net devive.
  */
 struct fcoe_interface {
@@ -84,7 +82,6 @@ struct fcoe_interface {
 	struct packet_type fip_packet_type;
 	struct fcoe_ctlr   ctlr;
 	struct fc_exch_mgr *oem;
-	struct kref	   kref;
 };
 
 #define fcoe_from_ctlr(fip) container_of(fip, struct fcoe_interface, ctlr)
#4 lore raw

RFC PATCH v2 4/10 fcoe: Rename out_nomod label to out_putmod

In reply to Robert Love

The label implies that it should be called when there is 'nomod.' I read that to mean that the module reference 'get' failed. However, it's only called when the module reference 'get' succeeded.

I think it makes more sense to name the label, 'out_putmod' since it should be called when we need to 'put' the module reference taken in the routine before returning.

---
 drivers/scsi/fcoe/fcoe.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/fcoe/fcoe.c +3 -3
index f61e1dc..c40035c 100644
@@ -352,7 +352,7 @@ static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
 	if (!fcoe) {
 		FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n");
 		fcoe = ERR_PTR(-ENOMEM);
-		goto out_nomod;
+		goto out_putmod;
 	}
 
 	dev_hold(netdev);
@@ -371,12 +371,12 @@ static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
 		kfree(fcoe);
 		dev_put(netdev);
 		fcoe = ERR_PTR(err);
-		goto out_nomod;
+		goto out_putmod;
 	}
 
 	goto out;
 
-out_nomod:
+out_putmod:
 	module_put(THIS_MODULE);
 out:
 	return fcoe;
#5 lore raw

RFC PATCH v2 5/10 FC Transport: Add API for LLDs to add FC port and FC fabric devices

In reply to Robert Love

This patch extends the FC Transport API to LLDs to allow them to create FC Port and FC Fabric devices that will be represented in sysfs.

The FC Port device is intended to contain attributes describing FC/FCoE properties of the physical port.

The FC Fabric device is intended to contain attributes describing FC/FCoE properties of a FC switch or FCoE switch. The term "fabric" is used very loosly.

The Attribute Container code is used to create these new devices and their attributes and these extensions should be in line with the other classes of devices defined by the FC Transport.

Notes:

The FC Port is 1:1 with the FC Host. This begs the question if the FC Port is necessary or if those attributes should simply be added to the FC Host.

Temporary fabric's are needed when calling fc_fabric_add so that the FC Transport can look for duplicates in its list of fabrics. A match routine can be provided by the LLD to compare fabrics. An FCoE LLD may have differen criteria to match FCFs than a purely FC LLD would. This can all be up-leveled to the FC Transport if we want different selection modes at that layer.

---
 drivers/scsi/scsi_transport_fc.c |  541 ++++++++++++++++++++++++++++++++++++++
 include/scsi/scsi_transport_fc.h |  139 +++++++++-
 2 files changed, 671 insertions(+), 9 deletions(-)
drivers/scsi/scsi_transport_fc.c +537 -4
index 1b21491..86600e0 100644
@@ -314,6 +314,8 @@ static void fc_scsi_scan_rport(struct work_struct *work);
 #define FC_RPORT_NUM_ATTRS	10
 #define FC_VPORT_NUM_ATTRS	9
 #define FC_HOST_NUM_ATTRS	22
+#define FC_PORT_NUM_ATTRS       1
+#define FC_FABRIC_NUM_ATTRS     1
 
 struct fc_internal {
 	struct scsi_transport_template t;
@@ -326,9 +328,18 @@ struct fc_internal {
 	 *     structures - used for mid-layer interaction.
 	 *
 	 * The attribute containers for the starget and host are are
-	 * part of the midlayer. As the remote port is specific to the
-	 * fc transport, we must provide the attribute container.
+	 * part of the midlayer. As the FC port, FC fabrics and
+	 * remote ports are specific to the fc transport, we must
+	 * provide the attribute container.
 	 */
+	struct transport_container port_attr_cont;
+	struct device_attribute private_port_attrs[FC_PORT_NUM_ATTRS];
+	struct device_attribute *port_attrs[FC_PORT_NUM_ATTRS + 1];
+
+	struct transport_container fabric_attr_cont;
+	struct device_attribute private_fabric_attrs[FC_FABRIC_NUM_ATTRS];
+	struct device_attribute *fabric_attrs[FC_FABRIC_NUM_ATTRS + 1];
+
 	struct device_attribute private_starget_attrs[
 							FC_STARGET_NUM_ATTRS];
 	struct device_attribute *starget_attrs[FC_STARGET_NUM_ATTRS + 1];
@@ -415,6 +426,7 @@ static int fc_host_setup(struct transport_container *tc, struct device *dev,
 	INIT_LIST_HEAD(&fc_host->rports);
 	INIT_LIST_HEAD(&fc_host->rport_bindings);
 	INIT_LIST_HEAD(&fc_host->vports);
+	INIT_LIST_HEAD(&fc_host->fabrics);
 	fc_host->next_rport_number = 0;
 	fc_host->next_target_id = 0;
 	fc_host->next_vport_number = 0;
@@ -480,6 +492,72 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
 			       NULL,
 			       NULL);
 
+static DECLARE_TRANSPORT_CLASS(fc_port_class,
+			       "fc_port",
+			       NULL,
+			       NULL,
+			       NULL);
+
+static DECLARE_TRANSPORT_CLASS(fc_fabric_class,
+			       "fc_fabric",
+			       NULL,
+			       NULL,
+			       NULL);
+
+#define fc_private_port_show_function(field, format_string, sz, cast)	\
+static ssize_t								\
+show_fc_port_##field(struct device *dev,				\
+		     struct device_attribute *attr, char *buf)		\
+{									\
+	struct fc_port *port = transport_class_to_port(dev);		\
+	return snprintf(buf, sz, format_string, cast port->field);	\
+}
+
+#define fc_private_port_rd_attr(field, format_string, sz)		\
+	fc_private_port_show_function(field, format_string, sz, )	\
+	static FC_DEVICE_ATTR(port, field, S_IRUGO,			\
+		      show_fc_port_##field, NULL)
+
+#define SETUP_PORT_ATTRIBUTE_RD(field)					\
+	i->private_port_attrs[count] = device_attr_port_##field;	\
+	i->private_port_attrs[count].attr.mode = S_IRUGO;		\
+	i->private_port_attrs[count].store = NULL;			\
+	i->port_attrs[count] = &i->private_port_attrs[count];		\
+	if (i->f->show_port_##field)					\
+		count++
+
+fc_private_port_rd_attr(maxframe_size, "%u bytes\n", 20);
+
+
+#define fc_fabric_show_function(field, format_string, sz, cast)		\
+static ssize_t								\
+show_fc_fabric_##field(struct device *dev,				\
+		       struct device_attribute *attr, char *buf)	\
+{									\
+	struct fc_fabric *fabric = transport_class_to_fabric(dev);	\
+	struct fc_internal *i = to_fc_internal(fabric->t);		\
+	if (i->f->get_fabric_##field)					\
+		i->f->get_fabric_##field(fabric);			\
+	return snprintf(buf, sz, format_string,				\
+			cast fc_fabric_##field(fabric));		\
+}
+
+#define fc_fabric_rd_attr_cast(field, format_string, sz, cast)		\
+	fc_fabric_show_function(field, format_string, sz, (cast))	\
+	static FC_DEVICE_ATTR(fabric, field, S_IRUGO,			\
+		      show_fc_fabric_##field, NULL)
+
+#define SETUP_FABRIC_ATTRIBUTE_RD(field)				\
+	i->private_fabric_attrs[count] = device_attr_fabric_##field;	\
+	i->private_fabric_attrs[count].attr.mode = S_IRUGO;		\
+	i->private_fabric_attrs[count].store = NULL;			\
+	i->fabric_attrs[count] = &i->private_fabric_attrs[count];	\
+	if (i->f->show_fabric_##field)					\
+		count++
+
+fc_fabric_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
+
+
 /*
  * Netlink Infrastructure
  */
@@ -647,9 +725,15 @@ static __init int fc_transport_init(void)
 
 	atomic_set(&fc_event_seq, 0);
 
-	error = transport_class_register(&fc_host_class);
+	error = transport_class_register(&fc_port_class);
 	if (error)
 		return error;
+	error = transport_class_register(&fc_fabric_class);
+	if (error)
+		goto unreg_port_class;
+	error = transport_class_register(&fc_host_class);
+	if (error)
+		goto unreg_fabric_class;
 	error = transport_class_register(&fc_vport_class);
 	if (error)
 		goto unreg_host_class;
@@ -667,6 +751,10 @@ unreg_vport_class:
 	transport_class_unregister(&fc_vport_class);
 unreg_host_class:
 	transport_class_unregister(&fc_host_class);
+unreg_fabric_class:
+	transport_class_unregister(&fc_fabric_class);
+unreg_port_class:
+	transport_class_unregister(&fc_port_class);
 	return error;
 }
 
@@ -676,6 +764,8 @@ static void __exit fc_transport_exit(void)
 	transport_class_unregister(&fc_rport_class);
 	transport_class_unregister(&fc_host_class);
 	transport_class_unregister(&fc_vport_class);
+	transport_class_unregister(&fc_fabric_class);
+	transport_class_unregister(&fc_port_class);
 }
 
 /*
@@ -2014,6 +2104,85 @@ static int fc_vport_match(struct attribute_container *cont,
 	return &i->vport_attr_cont.ac == cont;
 }
 
+/**
+ * fc_port_dev_release() - Release the FC port memory
+ * @dev: Pointer to the FC port's embedded device
+ *
+ * Called when the last FC port reference is released.
+ */
+static void fc_port_dev_release(struct device *dev)
+{
+	struct fc_port *port = dev_to_port(dev);
+
+	put_device(port->dev.parent);
+	port->dev.parent = NULL;
+	kfree(port);
+}
+
+int dev_is_fc_port(const struct device *dev)
+{
+	return dev->release == fc_port_dev_release;
+}
+EXPORT_SYMBOL(dev_is_fc_port);
+
+static int fc_port_match(struct attribute_container *cont,
+			 struct device *dev)
+{
+	struct fc_port *port;
+	struct fc_internal *i;
+
+	if (!dev_is_fc_port(dev))
+		return 0;
+	port = dev_to_port(dev);
+
+	if (!port->t || port->t->host_attrs.ac.class
+	    != &fc_host_class.class)
+		return 0;
+
+	i = to_fc_internal(port->t);
+
+	return &i->port_attr_cont.ac == cont;
+}
+
+/**
+ * fc_fabric_dev_release() - Release the FC port memory
+ * @dev: Pointer to the FC fabric's embedded device
+ *
+ * Called when the last FC fabric reference is released.
+ */
+static void fc_fabric_dev_release(struct device *dev)
+{
+	struct fc_fabric *fabric = dev_to_fabric(dev);
+
+	put_device(fabric->dev.parent);
+	fabric->dev.parent = NULL;
+	kfree(fabric);
+}
+
+int dev_is_fc_fabric(const struct device *dev)
+{
+	return dev->release == fc_fabric_dev_release;
+}
+EXPORT_SYMBOL(dev_is_fc_fabric);
+
+static int fc_fabric_match(struct attribute_container *cont,
+			   struct device *dev)
+{
+	struct fc_fabric *fabric;
+	struct fc_internal *i;
+
+	if (!dev_is_fc_fabric(dev))
+		return 0;
+	fabric = dev_to_fabric(dev);
+
+	if (!fabric->t || fabric->t->host_attrs.ac.class
+	    != &fc_host_class.class)
+		return 0;
+
+	i = to_fc_internal(fabric->t);
+
+	return &i->fabric_attr_cont.ac == cont;
+}
 
 /**
  * fc_timed_out - FC Transport I/O timeout intercept handler
@@ -2166,6 +2335,16 @@ fc_attach_transport(struct fc_function_template *ft)
 	i->vport_attr_cont.ac.match = fc_vport_match;
 	transport_container_register(&i->vport_attr_cont);
 
+	i->port_attr_cont.ac.attrs = &i->port_attrs[0];
+	i->port_attr_cont.ac.class = &fc_port_class.class;
+	i->port_attr_cont.ac.match = fc_port_match;
+	transport_container_register(&i->port_attr_cont);
+
+	i->fabric_attr_cont.ac.attrs = &i->fabric_attrs[0];
+	i->fabric_attr_cont.ac.class = &fc_fabric_class.class;
+	i->fabric_attr_cont.ac.match = fc_fabric_match;
+	transport_container_register(&i->fabric_attr_cont);
+
 	i->f = ft;
 
 	/* Transport uses the shost workq for scsi scanning */
@@ -2180,6 +2359,24 @@ fc_attach_transport(struct fc_function_template *ft)
 	i->t.it_nexus_response = fc_it_nexus_response;
 
 	/*
+	 * Setup FC Port Attributes.
+	 */
+	count = 0;
+	SETUP_PORT_ATTRIBUTE_RD(maxframe_size);
+	BUG_ON(count > FC_PORT_NUM_ATTRS);
+
+	i->port_attrs[count] = NULL;
+
+	/*
+	 * Setup FC Fabric Attributes.
+	 */
+	count = 0;
+	SETUP_FABRIC_ATTRIBUTE_RD(fabric_name);
+	BUG_ON(count > FC_FABRIC_NUM_ATTRS);
+
+	i->fabric_attrs[count] = NULL;
+
+	/*
 	 * Setup SCSI Target Attributes.
 	 */
 	count = 0;
@@ -2281,6 +2478,8 @@ void fc_release_transport(struct scsi_transport_template *t)
 	transport_container_unregister(&i->t.host_attrs);
 	transport_container_unregister(&i->rport_attr_cont);
 	transport_container_unregister(&i->vport_attr_cont);
+	transport_container_unregister(&i->port_attr_cont);
+	transport_container_unregister(&i->fabric_attr_cont);
 
 	kfree(i);
 }
@@ -2372,7 +2571,6 @@ fc_flush_devloss(struct Scsi_Host *shost)
 	flush_workqueue(fc_host_devloss_work_q(shost));
 }
 
-
 /**
  * fc_remove_host - called to terminate any fc_transport-related elements for a scsi host.
  * @shost:	Which &Scsi_Host
@@ -2393,6 +2591,7 @@ fc_remove_host(struct Scsi_Host *shost)
 {
 	struct fc_vport *vport = NULL, *next_vport = NULL;
 	struct fc_rport *rport = NULL, *next_rport = NULL;
+	struct fc_fabric *fabric = NULL, *next_fabric = NULL;
 	struct workqueue_struct *work_q;
 	struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
 	unsigned long flags;
@@ -2418,8 +2617,20 @@ fc_remove_host(struct Scsi_Host *shost)
 		fc_queue_work(shost, &rport->rport_delete_work);
 	}
 
+	/* Remove any fabrics */
+	list_for_each_entry_safe(fabric, next_fabric,
+				 &fc_host->fabrics, peers) {
+		list_del(&fabric->peers);
+		fabric->state = FC_FABRICSTATE_DISCONNECTED;
+		fc_queue_work(shost, &fabric->fabric_delete_work);
+	}
+
 	spin_unlock_irqrestore(shost->host_lock, flags);
 
+	/* Remove the fc port */
+	if (fc_host->port)
+		fc_port_del(fc_host->port);
+
 	/* flush all scan work items */
 	scsi_flush_work(shost);
 
@@ -3509,6 +3720,328 @@ fc_vport_sched_delete(struct work_struct *work)
 			vport->channel, stat);
 }
 
+/**
+ * fc_port_del() - Delete a FC port and its subtree from sysfs
+ * @fcport: A pointer to the port to be deleted
+ *
+ * Deletes a FC port and any fabrics attached
+ * to it. Deleting fabrics will cause their childen
+ * to be deleted as well.
+ *
+ * The port is detached from sysfs and it's resources
+ * are freed, but the memory is not freed until its
+ * last reference is released.
+ *
+ * This routine expects no locks to be held before
+ * calling.
+ */
+void fc_port_del(struct fc_port *fcport)
+{
+	struct Scsi_Host *shost = port_to_shost(fcport);
+	struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
+
+	fc_host->port = NULL;
+
+	transport_unregister_device(&fcport->dev);
+	device_del(&fcport->dev);
+	put_device(&fcport->dev); /* self-reference */
+}
+EXPORT_SYMBOL(fc_port_del);
+
+static atomic_t fc_port_next_id;
+
+/**
+ * fc_port_add() - Add a FC port to sysfs
+ * @shost: The SCSI Host that the port will be a child of
+ *
+ * This routine allocates a FC port object with some additional memory
+ * for the LLD. The FC port is initialized, added to sysfs and then
+ * attributes are added to it.
+ */
+struct fc_port *fc_port_add(struct Scsi_Host *shost)
+{
+	struct fc_internal *fci = to_fc_internal(shost->transportt);
+	struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
+	struct fc_port *fcport;
+	unsigned long flags;
+	int error = 0;
+
+	spin_lock_irqsave(shost->host_lock, flags);
+	if (fc_host->port) {
+		spin_unlock_irqrestore(shost->host_lock, flags);
+		goto out;
+	}
+	spin_unlock_irqrestore(shost->host_lock, flags);
+
+
+	fcport = kzalloc(sizeof(struct fc_port) + fci->f->dd_fcport_size,
+			 GFP_KERNEL);
+	if (!fcport)
+		goto out;
+
+	/* Initialize members */
+	memset(fcport->system_hostname, 0, sizeof(fcport->system_hostname));
+	fcport->maxframe_size = -1;
+	fcport->supported_classes = FC_COS_UNSPECIFIED;
+	fcport->supported_speeds = FC_PORTSPEED_UNKNOWN;
+	fcport->speed = FC_PORTSPEED_UNKNOWN;
+	fcport->fab_dev_loss_tmo = 600; /* default to 10mins */
+	memset(fcport->supported_fc4s, 0,
+	       sizeof(fcport->supported_fc4s));
+	memset(fcport->active_fc4s, 0,
+	       sizeof(fcport->active_fc4s));
+	memset(fcport->serial_number, 0,
+	       sizeof(fcport->serial_number));
+
+	/* Setup internal structures */
+	fcport->id = atomic_inc_return(&fc_port_next_id) - 1;
+	dev_set_name(&fcport->dev, "port%d", fcport->id);
+	device_initialize(&fcport->dev);
+	fcport->dev.parent = get_device(&shost->shost_gendev);
+	fcport->dev.release = fc_port_dev_release;
+	fcport->t = shost->transportt;
+
+	spin_lock_irqsave(shost->host_lock, flags);
+	fc_host->port = fcport;
+	spin_unlock_irqrestore(shost->host_lock, flags);
+
+	error = device_add(&fcport->dev);
+	if (error)
+		goto out_del;
+
+	transport_register_device(&fcport->dev);
+	transport_configure_device(&fcport->dev);
+
+	return fcport;
+
+out_del:
+	put_device(&shost->shost_gendev);
+	kfree(fcport);
+out:
+	return NULL;
+}
+EXPORT_SYMBOL(fc_port_add);
+
+/**
+ * fc_fabric_final_delete() - Final delete routine
+ * @work: The FC fabric's embedded work struct
+ *
+ * Delete the fabric's N_Port, which will in turn delete
+ * any FC vports on the fabric. Finally, remove the device
+ * from sysfs and drop the last reference.
+ */
+static void fc_fabric_final_delete(struct work_struct *work)
+{
+	struct fc_fabric *fabric =
+		container_of(work, struct fc_fabric,
+			     fabric_delete_work);
+	struct fc_port *port = fc_fabric_to_port(fabric);
+	struct Scsi_Host *shost = fabric_to_shost(fabric);
+	struct fc_internal *fci = to_fc_internal(shost->transportt);
+	unsigned long flags;
+
+	/*
+	 * Cancel any outstanding timers. These should really exist
+	 * only when rmmod'ing the LLDD and we're asking for
+	 * immediate termination of the rports
+	 */
+	spin_lock_irqsave(shost->host_lock, flags);
+	if (fabric->flags & FC_FABRIC_DEVLOSS_PENDING) {
+		spin_unlock_irqrestore(shost->host_lock, flags);
+		if (!cancel_delayed_work(&fabric->dev_loss_work))
+			fc_flush_devloss(shost);
+		spin_lock_irqsave(shost->host_lock, flags);
+		fabric->flags &= ~FC_FABRIC_DEVLOSS_PENDING;
+	}
+	spin_unlock_irqrestore(shost->host_lock, flags);
+
+	if (fci->f->fabric_destroy)
+		fci->f->fabric_destroy(port, fabric);
+
+	/* TODO: Need to remove the scsi_host, or will the caller do that? */
+
+	transport_unregister_device(&fabric->dev);
+	device_del(&fabric->dev);
+	put_device(&fabric->dev); /* self-reference */
+}
+
+/**
+ * fc_timeout_deleted_fabric() - Delete a fabric when the devloss timer fires
+ * @work: The FC fabric's embedded work struct
+ *
+ * Removes the fabric from the FC port's list of fabrics and
+ * queues the final deletion.
+ */
+static void fc_timeout_deleted_fabric(struct work_struct *work)
+{
+	struct fc_fabric *fabric =
+		container_of(work, struct fc_fabric, dev_loss_work.work);
+	struct Scsi_Host *shost = fabric_to_shost(fabric);
+	unsigned long flags;
+
+	spin_lock_irqsave(shost->host_lock, flags);
+
+	fabric->flags &= ~FC_FABRIC_DEVLOSS_PENDING;
+
+	if (fabric->state == FC_FABRICSTATE_CONNECTED) {
+		spin_unlock_irqrestore(shost->host_lock, flags);
+		return;
+	}
+
+	dev_printk(KERN_ERR, &fabric->dev,
+		   "FC fabric connection time out: removing fabric\n");
+
+	list_del(&fabric->peers);
+	fc_queue_work(shost, &fabric->fabric_delete_work);
+
+	spin_unlock_irqrestore(shost->host_lock, flags);
+}
+
+/**
+ * fc_fabric_del() - Delete a FC fabric
+ * @fabric: Pointer to the fabric which is to be deleted
+ *
+ * Queues the FC fabric on the devloss workqueue
+ */
+void fc_fabric_del(struct fc_fabric *fabric)
+{
+	struct Scsi_Host *shost = fabric_to_shost(fabric);
+	int timeout = fabric->dev_loss_tmo;
+	unsigned long flags;
+
+	spin_lock_irqsave(shost->host_lock, flags);
+
+	if (fabric->state != FC_FABRICSTATE_CONNECTED) {
+		spin_unlock_irqrestore(shost->host_lock, flags);
+		return;
+	}
+
+	fabric->state = FC_FABRICSTATE_DISCONNECTED;
+	fabric->flags |= FC_FABRIC_DEVLOSS_PENDING;
+
+	spin_unlock_irqrestore(shost->host_lock, flags);
+
+	fc_queue_devloss_work(shost, &fabric->dev_loss_work,
+			      timeout * HZ);
+}
+EXPORT_SYMBOL(fc_fabric_del);
+
+int fc_fabric_fcf_match(struct fc_fabric *fabric,
+			struct fc_fabric *new_fabric)
+{
+	/* stub */
+	return 1;
+}
+
+static atomic_t fc_fabric_next_id;
+/**
+ * fc_fabric_create() - Allocate a new FC Fabric
+ * @shost: The Scsi Host associated with the to-be-created fabric
+ * @port:  The FC Port that will be the parent of the to-be-created fabric
+ */
+struct fc_fabric *fc_fabric_create(struct Scsi_Host *shost,
+				   struct fc_port *port)
+{
+	struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
+	struct fc_internal *fci = to_fc_internal(shost->transportt);
+	struct fc_fabric *fabric;
+	unsigned long flags;
+	int error = 0;
+	int size;
+
+	size = (sizeof(struct fc_fabric) + fci->f->dd_fcfabric_size);
+	fabric = kzalloc(size, GFP_KERNEL);
+	if (unlikely(!fabric))
+		goto out;
+
+	/* Initialize members */
+	INIT_WORK(&fabric->fabric_delete_work, fc_fabric_final_delete);
+	INIT_DELAYED_WORK(&fabric->dev_loss_work, fc_timeout_deleted_fabric);
+	fabric->dev_loss_tmo = port->fab_dev_loss_tmo;
+
+	/* Setup internal structures */
+	fabric->id = atomic_inc_return(&fc_fabric_next_id) - 1;
+	dev_set_name(&fabric->dev, "fabric%d", fabric->id);
+	device_initialize(&fabric->dev);
+	fabric->dev.parent = get_device(&port->dev);
+	fabric->dev.release = fc_fabric_dev_release;
+	fabric->t = port->t;
+
+	fabric->state = FC_FABRICSTATE_CONNECTED;
+
+	spin_lock_irqsave(shost->host_lock, flags);
+	list_add_tail(&fabric->peers, &fc_host->fabrics);
+	spin_unlock_irqrestore(shost->host_lock, flags);
+
+	error = device_add(&fabric->dev);
+	if (error)
+		goto out_del_dev;
+
+	transport_register_device(&fabric->dev);
+	transport_configure_device(&fabric->dev);
+
+	if (fci->f->fabric_create)
+		fci->f->fabric_create(port, fabric);
+
+	return fabric;
+
+out_del_dev:
+	spin_lock_irqsave(shost->host_lock, flags);
+	list_del(&fabric->peers);
+	spin_unlock_irqrestore(shost->host_lock, flags);
+	put_device(&port->dev);
+	kfree(fabric);
+out:
+	return NULL;
+}
+
+/**
+ * fc_fabric_add() - Add a FC fabric to sysfs
+ * @port:       The FC port that the fabric is to be added to
+ * @new_fabric: The new fabric to add
+ *
+ * Expects the port lock to be held
+ * (TODO: should the lock be held? fc_remote_port_add doesn't
+ *  have it held. Does either approach have a clear advantage?
+ *
+ */
+struct fc_fabric *fc_fabric_add(struct fc_port *port,
+				struct fc_fabric *new_fabric)
+{
+	struct Scsi_Host *shost = port_to_shost(port);
+	struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
+	struct fc_internal *fci = to_fc_internal(port->t);
+	struct fc_fabric *fabric;
+	unsigned long flags;
+
+	spin_lock_irqsave(shost->host_lock, flags);
+
+	list_for_each_entry(fabric, &fc_host->fabrics, peers) {
+		if (fci->f->fabric_match(fabric, new_fabric)) {
+			if (fabric->state == FC_FABRICSTATE_CONNECTED)
+				goto out;
+
+			fabric->flags &= ~FC_FABRIC_DEVLOSS_PENDING;
+			fabric->state = FC_FABRICSTATE_CONNECTED;
+
+			if (!cancel_delayed_work(&fabric->dev_loss_work))
+				fc_flush_devloss(shost);
+			else
+				goto out;
+		}
+	}
+
+	spin_unlock_irqrestore(shost->host_lock, flags);
+
+	fabric = fc_fabric_create(shost, port);
+	return fabric;
+
+out:
+	spin_unlock_irqrestore(shost->host_lock, flags);
+	return fabric;
+}
+EXPORT_SYMBOL(fc_fabric_add);
+
 
 /*
  * BSG support
include/scsi/scsi_transport_fc.h +134 -5

197 lines not on this page · raw message

#6 lore raw

RFC PATCH v2 6/10 fcoe: Use the new FC Transport APIs for FC ports and fabrics

In reply to Robert Love

This patch adds the usage of the FC Port and FC Fabric device API added to the FC Transport in a previous patch.

There is minimal impact to libfc with the currently limited set of attributes on the FC Port and FC Fabric devices. When more attributes are used on these new devices and are not used on the FC Host there is likely to be more impact on libfc.

libfcoe requires the following changes to use the new FC Transport APIs.

* Creation of FCoE FCF Event Queue (fcoe_fcf_eq) to avoid locking issues when adding and deleting new FCFs from sysfs
* Allocation of 'struct fcoe_fcf' with 'struct fc_fabric'
* Implemention of fcoe_fabric_match to compare FCFs
* Helper routines for fabric adition and deletion (list manipulation for new FCFs)
* Break out fcoe_ctlr_process_fcf from fcoe_ctlr_recv_adv so that FCFs can be processed either in the receive context (for simple updates) or from the fcoe_fcf_wq
* Use of fc_fabric_add and fc_fabric_del

fcoe requires the following changes to use the new FC Transport APIs.

* Use of libfcoe's fabric addition/deletion helper routines
* Allocation of 'struct fcoe_port' with 'struct fc_port'
* Use of fc_port_add and fc_port_del

---
 drivers/scsi/fcoe/fcoe.c           |  333 ++++++++++++++++++++++++------------
 drivers/scsi/fcoe/fcoe.h           |    3 
 drivers/scsi/fcoe/fcoe_ctlr.c      |  310 +++++++++++++++++++++++++++-------
 drivers/scsi/fcoe/fcoe_transport.c |    7 +
 drivers/scsi/libfc/fc_lport.c      |    1 
 include/scsi/libfcoe.h             |   34 ++++
 6 files changed, 509 insertions(+), 179 deletions(-)
drivers/scsi/fcoe/fcoe.c +219 -114
index c40035c..fb8a504 100644
@@ -140,6 +140,26 @@ static void fcoe_set_vport_symbolic_name(struct fc_vport *);
 static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *);
 static int fcoe_validate_vport_create(struct fc_vport *);
 
+static int fcoe_fabric_create(struct fc_port *port,
+			      struct fc_fabric *fabric)
+{
+	struct fcoe_interface *fcoe = fc_port_priv(port);
+	struct fcoe_ctlr *fip = &fcoe->ctlr;
+	struct fcoe_fcf *fcf = fc_fabric_priv(fabric);
+
+	return fcoe_ctlr_fabric_create(fip, fcf);
+}
+
+static int fcoe_fabric_destroy(struct fc_port *port,
+			       struct fc_fabric *fabric)
+{
+	struct fcoe_interface *fcoe = fc_port_priv(port);
+	struct fcoe_ctlr *fip = &fcoe->ctlr;
+	struct fcoe_fcf *fcf = fc_fabric_priv(fabric);
+
+	return fcoe_ctlr_fabric_destroy(fip, fcf);
+}
+
 static struct libfc_function_template fcoe_libfc_fcn_templ = {
 	.frame_send = fcoe_xmit,
 	.ddp_setup = fcoe_ddp_setup,
@@ -151,12 +171,21 @@ static struct libfc_function_template fcoe_libfc_fcn_templ = {
 };
 
 struct fc_function_template fcoe_nport_fc_functions = {
+	.dd_fcport_size = sizeof(struct fcoe_interface),
+	.show_port_maxframe_size = 1,
+
+	.dd_fcfabric_size = sizeof(struct fcoe_fcf),
+	.fabric_match = fcoe_fabric_match,
+	.show_fabric_fabric_name = 1,
+
+	.fabric_create = fcoe_fabric_create,
+	.fabric_destroy = fcoe_fabric_destroy,
+
 	.show_host_node_name = 1,
 	.show_host_port_name = 1,
 	.show_host_supported_classes = 1,
 	.show_host_supported_fc4s = 1,
 	.show_host_active_fc4s = 1,
-	.show_host_maxframe_size = 1,
 
 	.show_host_port_id = 1,
 	.show_host_supported_speeds = 1,
@@ -171,7 +200,6 @@ struct fc_function_template fcoe_nport_fc_functions = {
 	.show_rport_maxframe_size = 1,
 	.show_rport_supported_classes = 1,
 
-	.show_host_fabric_name = 1,
 	.show_starget_node_name = 1,
 	.show_starget_port_name = 1,
 	.show_starget_port_id = 1,
@@ -196,7 +224,6 @@ struct fc_function_template fcoe_vport_fc_functions = {
 	.show_host_supported_classes = 1,
 	.show_host_supported_fc4s = 1,
 	.show_host_active_fc4s = 1,
-	.show_host_maxframe_size = 1,
 
 	.show_host_port_id = 1,
 	.show_host_supported_speeds = 1,
@@ -211,7 +238,6 @@ struct fc_function_template fcoe_vport_fc_functions = {
 	.show_rport_maxframe_size = 1,
 	.show_rport_supported_classes = 1,
 
-	.show_host_fabric_name = 1,
 	.show_starget_node_name = 1,
 	.show_starget_port_name = 1,
 	.show_starget_port_id = 1,
@@ -261,6 +287,8 @@ static int fcoe_interface_setup(struct fcoe_interface *fcoe,
 	u8 flogi_maddr[ETH_ALEN];
 	const struct net_device_ops *ops;
 
+	rtnl_lock();
+
 	fcoe->netdev = netdev;
 
 	/* Let LLD initialize for FCoE */
@@ -325,19 +353,25 @@ static int fcoe_interface_setup(struct fcoe_interface *fcoe,
 	fcoe->fip_packet_type.dev = netdev;
 	dev_add_pack(&fcoe->fip_packet_type);
 
+	rtnl_unlock();
+
 	return 0;
 }
 
 /**
  * fcoe_interface_create() - Create a FCoE interface on a net device
+ * @shost: The SCSI Host to attach the FC Port to
  * @netdev: The net device to create the FCoE interface on
  * @fip_mode: The mode to use for FIP
  *
  * Returns: pointer to a struct fcoe_interface or NULL on error
+ * Note: Called after fcoe_shost_create()
  */
-static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
+static struct fcoe_interface *fcoe_interface_create(struct Scsi_Host *shost,
+						    struct net_device *netdev,
 						    enum fip_state fip_mode)
 {
+	struct fc_port *port;
 	struct fcoe_interface *fcoe;
 	int err;
 
@@ -348,18 +382,21 @@ static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
 		goto out;
 	}
 
-	fcoe = kzalloc(sizeof(*fcoe), GFP_KERNEL);
-	if (!fcoe) {
-		FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n");
+	port = fc_port_add(shost);
+	if (!port) {
+		printk(KERN_ERR "Failed to add a fcport\n");
 		fcoe = ERR_PTR(-ENOMEM);
 		goto out_putmod;
 	}
 
+	fcoe = fc_port_priv(port);
+
 	dev_hold(netdev);
 
 	/*
 	 * Initialize FIP.
 	 */
+	fcoe->ctlr.port = port;
 	fcoe_ctlr_init(&fcoe->ctlr, fip_mode);
 	fcoe->ctlr.send = fcoe_fip_send;
 	fcoe->ctlr.update_mac = fcoe_update_src_mac;
@@ -367,11 +404,9 @@ static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
 
 	err = fcoe_interface_setup(fcoe, netdev);
 	if (err) {
-		fcoe_ctlr_destroy(&fcoe->ctlr);
-		kfree(fcoe);
-		dev_put(netdev);
+		fc_port_del(port);
 		fcoe = ERR_PTR(err);
-		goto out_putmod;
+		goto out;
 	}
 
 	goto out;
@@ -518,9 +553,8 @@ static u8 *fcoe_get_src_mac(struct fc_lport *lport)
  * fcoe_lport_config() - Set up a local port
  * @lport: The local port to be setup
  *
- * Returns: 0 for success
  */
-static int fcoe_lport_config(struct fc_lport *lport)
+static void fcoe_lport_config(struct fc_lport *lport)
 {
 	lport->link_up = 0;
 	lport->qfull = 0;
@@ -543,8 +577,6 @@ static int fcoe_lport_config(struct fc_lport *lport)
 	lport->lro_enabled = 0;
 	lport->lro_xid = 0;
 	lport->lso_max = 0;
-
-	return 0;
 }
 
 /**
@@ -565,6 +597,26 @@ static int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type)
 }
 
 /**
+ * fcoe_set_mfs() - Sets the lport and fc port max frame size
+ * @lport: The lport to change
+ * @mfs:   The new max frame size
+ */
+static int fcoe_set_mfs(struct fc_lport *lport, u32 mfs)
+{
+	struct fcoe_port *port = lport_priv(lport);
+	struct fcoe_interface *fcoe = port->priv;
+	struct fc_port *fcport = fcoe_to_fcport(fcoe);
+	int rc;
+
+	rc = fc_set_mfs(lport, mfs);
+
+	if (!rc)
+		fc_port_maxframe_size(fcport) = mfs;
+
+	return rc;
+}
+
+/**
  * fcoe_netdev_features_change - Updates the lport's offload flags based
  * on the LLD netdev's FCoE feature flags
  */
@@ -639,7 +691,7 @@ static int fcoe_netdev_config(struct fc_lport *lport, struct net_device *netdev)
 		FCOE_NETDEV_DBG(netdev, "Supports FCOE_MTU of %d bytes\n", mfs);
 	}
 	mfs -= (sizeof(struct fcoe_hdr) + sizeof(struct fcoe_crc_eof));
-	if (fc_set_mfs(lport, mfs))
+	if (fcoe_set_mfs(lport, mfs))
 		return -EINVAL;
 
 	/* offload features support */
@@ -699,10 +751,6 @@ static int fcoe_shost_config(struct fc_lport *lport, struct device *dev)
 	if (!lport->vport)
 		fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
 
-	snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE,
-		 "%s v%s over %s", FCOE_NAME, FCOE_VERSION,
-		 fcoe_netdev(lport)->name);
-
 	return 0;
 }
 
@@ -933,86 +981,42 @@ static int fcoe_ddp_done(struct fc_lport *lport, u16 xid)
 }
 
 /**
- * fcoe_if_create() - Create a FCoE instance on an interface
- * @fcoe:   The FCoE interface to create a local port on
- * @parent: The device pointer to be the parent in sysfs for the SCSI host
- * @npiv:   Indicates if the port is a vport or not
+ * fcoe_if_config() - Configure an FCoE instance on an interface
+ * @fcoe: The FCoE interface to configure a local port on
+ * @port: The FCoE port assocated with the local port
+ * @vport: The vport, if configuring on a vport. NULL if N_Port.
  *
  * Creates a fc_lport instance and a Scsi_Host instance and configure them.
- *
- * Returns: The allocated fc_lport or an error pointer
  */
-static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
-				       struct device *parent, int npiv)
+static int fcoe_if_config(struct fcoe_interface *fcoe,
+			  struct fcoe_port *port,
+			  struct fc_vport *vport)
 {
 	struct net_device *netdev = fcoe->netdev;
-	struct fc_lport *lport, *n_port;
-	struct fcoe_port *port;
+	struct fc_lport *n_lport;
 	struct Scsi_Host *shost;
 	int rc;
-	/*
-	 * parent is only a vport if npiv is 1,
-	 * but we'll only use vport in that case so go ahead and set it
-	 */
-	struct fc_vport *vport = dev_to_vport(parent);
 
 	FCOE_NETDEV_DBG(netdev, "Create Interface\n");
 
-	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;
-		goto out;
-	}
-	port = lport_priv(lport);
-	port->lport = lport;
+	/* Associate the interface with the port */
 	port->priv = fcoe;
-	port->max_queue_depth = FCOE_MAX_QUEUE_DEPTH;
-	port->min_queue_depth = FCOE_MIN_QUEUE_DEPTH;
-	INIT_WORK(&port->destroy_work, fcoe_destroy_work);
-
-	/* configure a fc_lport including the exchange manager */
-	rc = fcoe_lport_config(lport);
-	if (rc) {
-		FCOE_NETDEV_DBG(netdev, "Could not configure lport for the "
-				"interface\n");
-		goto out_host_put;
-	}
-
-	if (npiv) {
-		FCOE_NETDEV_DBG(netdev, "Setting vport names, "
-				"%16.16llx %16.16llx\n",
-				vport->node_name, vport->port_name);
-		fc_set_wwnn(lport, vport->node_name);
-		fc_set_wwpn(lport, vport->port_name);
-	}
 
 	/* configure lport network properties */
-	rc = fcoe_netdev_config(lport, netdev);
+	rc = fcoe_netdev_config(port->lport, netdev);
 	if (rc) {
 		FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the "
 				"interface\n");
-		goto out_lp_destroy;
-	}
-
-	/* configure lport scsi host properties */
-	rc = fcoe_shost_config(lport, parent);
-	if (rc) {
-		FCOE_NETDEV_DBG(netdev, "Could not configure shost for the "
-				"interface\n");
-		goto out_lp_destroy;
+		goto out;
 	}
 
 	/* Initialize the library */
-	rc = fcoe_libfc_config(lport, &fcoe->ctlr, &fcoe_libfc_fcn_templ, 1);
+	rc = fcoe_libfc_config(port->lport, &fcoe->ctlr,
+			       &fcoe_libfc_fcn_templ, 1);
 	if (rc) {
 		FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the "
 				"interface\n");
-		goto out_lp_destroy;
+		goto out;
 	}
 
 	/*
@@ -1024,28 +1028,22 @@ static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
 	 * This is currently handled through the fcoe_config_mutex
 	 * begin held.
 	 */
-	if (!npiv)
+	if (!vport)
 		/* lport exch manager allocation */
-		rc = fcoe_em_config(lport);
+		rc = fcoe_em_config(port->lport);
 	else {
 		shost = vport_to_shost(vport);
-		n_port = shost_priv(shost);
-		rc = fc_exch_mgr_list_clone(n_port, lport);
+		n_lport = shost_priv(shost);
+		rc = fc_exch_mgr_list_clone(n_lport, port->lport);
 	}
 
 	if (rc) {
 		FCOE_NETDEV_DBG(netdev, "Could not configure the EM\n");
-		goto out_lp_destroy;
+		goto out;
 	}
 
-	return lport;
-
-out_lp_destroy:
-	fc_exch_mgr_free(lport);
-out_host_put:
-	scsi_host_put(lport->host);
 out:
-	return ERR_PTR(rc);
+	return rc;
 }
 
 /**
@@ -1778,7 +1776,7 @@ static int fcoe_device_notification(struct notifier_block *notifier,
 		mfs = netdev->mtu - (sizeof(struct fcoe_hdr) +
 				     sizeof(struct fcoe_crc_eof));
 		if (mfs >= FC_MIN_MAX_FRAME)
-			fc_set_mfs(lport, mfs);
+			fcoe_set_mfs(lport, mfs);
 		break;
 	case NETDEV_REGISTER:
 		break;
@@ -1926,6 +1924,82 @@ static bool fcoe_match(struct net_device *netdev)
 	return true;
 }
 
+static struct Scsi_Host *fcoe_shost_create(struct net_device *netdev,
+					   struct fc_vport *vport)
+{
+	struct fc_lport *lport;
+	struct fcoe_port *port;
+	int rc;
+
+	if (!vport)
+		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;
+		return NULL;
+	}
+
+	port = lport_priv(lport);
+	port->lport = lport;
+	port->max_queue_depth = FCOE_MAX_QUEUE_DEPTH;
+	port->min_queue_depth = FCOE_MIN_QUEUE_DEPTH;
+	INIT_WORK(&port->destroy_work, fcoe_destroy_work);
+
+	/* configure a fc_lport including the exchange manager */
+	fcoe_lport_config(lport);
+
+	if (vport) {
+		FCOE_NETDEV_DBG(netdev, "Setting vport names, "
+				"%16.16llx %16.16llx\n",
+				vport->node_name, vport->port_name);
+		fc_set_wwnn(lport, vport->node_name);
+		fc_set_wwpn(lport, vport->port_name);
+	}
+
+	/* configure lport scsi host properties */
+	rc = fcoe_shost_config(lport, &netdev->dev);
+	if (rc) {
+		FCOE_NETDEV_DBG(netdev, "Could not configure shost for the "
+				"interface\n");
+//		goto out_lp_destroy;
+	}
+
+	snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE,
+		 "%s v%s over %s", FCOE_NAME, FCOE_VERSION,
+		 netdev->name);
+
+	return lport->host;
+}
+
+/**
+ * fcoe_shost_destroy() - Destroy the FC and Scsi_Host
+ * @shost: The host to be removed and destroyed
+ *
+ * This routine is called when fcoe_shost_create fails.
+ * In that scenario the EM has not been created so this
+ * routine doesn't call fc_exch_mgr_free or for that matter
+ * fc_lport_free_stats. Those routines are needed to
+ * destroy a completely allocated and configured
+ * fc_host/scsi_host.
+ */
+static void fcoe_shost_destroy(struct Scsi_Host *shost)
+{
+	struct fc_lport *lport = shost_priv(shost);
+
+	/* Detach from the scsi-ml */
+	fc_remove_host(shost);
+	scsi_remove_host(shost);
+
+	/* Destroy lport scsi_priv */
+	fc_fcp_destroy(lport);
+
+	/* Release the Scsi_Host */
+	scsi_host_put(shost);
+}
+
 /**
  * fcoe_create() - Create a fcoe interface
  * @netdev  : The net_device object the Ethernet interface to create on
@@ -1937,12 +2011,13 @@ static bool fcoe_match(struct net_device *netdev)
  */
 static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode)
 {
-	int rc = 0;
+	struct Scsi_Host *shost;
 	struct fcoe_interface *fcoe;
 	struct fc_lport *lport;
+	struct fcoe_port *port;
+	int rc = 0;
 
 	mutex_lock(&fcoe_config_mutex);
-	rtnl_lock();
 
 	/* look for existing lport */
 	if (fcoe_hostlist_lookup(netdev)) {
@@ -1950,20 +2025,28 @@ static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode)
 		goto out_nodev;
 	}
 
-	fcoe = fcoe_interface_create(netdev, fip_mode);
+	/* allocate and add the shost */
+	shost = fcoe_shost_create(netdev, NULL);
+	if (IS_ERR(shost)) {
+		rc = PTR_ERR(shost);
+		goto out_nodev;
+	}
+
+	fcoe = fcoe_interface_create(shost, netdev, fip_mode);
 	if (IS_ERR(fcoe)) {
 		rc = PTR_ERR(fcoe);
-		goto out_nodev;
+		goto out_shost_destroy;
 	}
 
-	lport = fcoe_if_create(fcoe, &netdev->dev, 0);
-	if (IS_ERR(lport)) {
+	lport = shost_priv(shost);
+	port = lport_priv(lport);
+
+	rc = fcoe_if_config(fcoe, port, NULL);
+	if (rc) {
 		printk(KERN_ERR "fcoe: Failed to create interface (%s)\n",
 		       netdev->name);
-		rc = -EIO;
-		rtnl_unlock();
 		fcoe_interface_cleanup(fcoe);
-		goto out_nortnl;
+		goto out_shost_destroy;
 	}
 
 	/* Make this the "master" N_Port */
@@ -1978,9 +2061,12 @@ static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode)
 	if (!fcoe_link_ok(lport))
 		fcoe_ctlr_link_up(&fcoe->ctlr);
 
+	mutex_unlock(&fcoe_config_mutex);
+	return rc;
+
+out_shost_destroy:
+	fcoe_shost_destroy(shost);
 out_nodev:
-	rtnl_unlock();
-out_nortnl:
 	mutex_unlock(&fcoe_config_mutex);
 	return rc;
 }
@@ -2387,12 +2473,14 @@ static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport, u32 did,
  */
 static int fcoe_vport_create(struct fc_vport *vport, bool disabled)
 {
-	struct Scsi_Host *shost = vport_to_shost(vport);
-	struct fc_lport *n_port = shost_priv(shost);
-	struct fcoe_port *port = lport_priv(n_port);
-	struct fcoe_interface *fcoe = port->priv;
+	struct Scsi_Host *n_shost = vport_to_shost(vport);
+	struct fc_lport *n_lport = shost_priv(n_shost);
+	struct fcoe_port *n_fcoe_port = lport_priv(n_lport);
+	struct fcoe_interface *fcoe = n_fcoe_port->priv;
 	struct net_device *netdev = fcoe->netdev;
-	struct fc_lport *vn_port;
+	struct Scsi_Host *vn_shost;
+	struct fc_lport *vn_lport;
+	struct fcoe_port *vn_fcoe_port;
 	int rc;
 	char buf[32];
 
@@ -2406,23 +2494,40 @@ static int fcoe_vport_create(struct fc_vport *vport, bool disabled)
 	}
 
 	mutex_lock(&fcoe_config_mutex);
-	vn_port = fcoe_if_create(fcoe, &vport->dev, 1);
+
+	/* TODO: Should this be called within the fcoe_config_mutex?*/
+	vn_shost = fcoe_shost_create(netdev, vport);
+	if (IS_ERR(vn_shost)) {
+		rc = PTR_ERR(vn_shost);
+		mutex_unlock(&fcoe_config_mutex);
+		goto out;
+	}
+
+	vn_lport = shost_priv(vn_shost);
+	vn_fcoe_port = lport_priv(vn_lport);
+
+	rc = fcoe_if_config(fcoe, vn_fcoe_port, vport);
 	mutex_unlock(&fcoe_config_mutex);
 
-	if (IS_ERR(vn_port)) {
+	if (rc) {
 		printk(KERN_ERR "fcoe: fcoe_vport_create(%s) failed\n",
 		       netdev->name);
-		return -EIO;
+		goto shost_destroy;
 	}
 
 	if (disabled) {
 		fc_vport_set_state(vport, FC_VPORT_DISABLED);
 	} else {
-		vn_port->boot_time = jiffies;
-		fc_fabric_login(vn_port);
-		fc_vport_setlink(vn_port);
+		vn_lport->boot_time = jiffies;
+		fc_fabric_login(vn_lport);
+		fc_vport_setlink(vn_lport);
 	}
 	return 0;
+
+shost_destroy:
+	fcoe_shost_destroy(vn_shost);
+out:
+	return rc;
 }
 
 /**
drivers/scsi/fcoe/fcoe.h +3 -0
index a1c3b54..129293f 100644
@@ -84,6 +84,9 @@ struct fcoe_interface {
 	struct fc_exch_mgr *oem;
 };
 
+#define fcoe_to_fcport(fcoe)					\
+	(struct fc_port *)(((struct fc_port *)(fcoe)) - 1)
+
 #define fcoe_from_ctlr(fip) container_of(fip, struct fcoe_interface, ctlr)
 
 /**
drivers/scsi/fcoe/fcoe_ctlr.c +246 -64

379 lines not on this page · raw message

drivers/scsi/fcoe/fcoe_transport.c +7 -0
index 41068e8..441e873 100644
@@ -714,6 +714,12 @@ out_nodev:
  */
 static int __init libfcoe_init(void)
 {
+	int rc;
+
+	rc = fcoe_ctlr_setup();
+	if (rc)
+		return rc;
+
 	fcoe_transport_init();
 
 	return 0;
@@ -726,5 +732,6 @@ module_init(libfcoe_init);
 static void __exit libfcoe_exit(void)
 {
 	fcoe_transport_exit();
+	fcoe_ctlr_teardown();
 }
 module_exit(libfcoe_exit);
drivers/scsi/libfc/fc_lport.c +0 -1
index 628f347..6be4a8f 100644
@@ -1639,7 +1639,6 @@ int fc_lport_init(struct fc_lport *lport)
 	       sizeof(fc_host_active_fc4s(lport->host)));
 	fc_host_active_fc4s(lport->host)[2] = 1;
 	fc_host_active_fc4s(lport->host)[7] = 1;
-	fc_host_maxframe_size(lport->host) = lport->mfs;
 	fc_host_supported_speeds(lport->host) = 0;
 	if (lport->link_supported_speeds & FC_PORTSPEED_1GBIT)
 		fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_1GBIT;
include/scsi/libfcoe.h +34 -0
index 8c1638b..2c03c6c 100644
@@ -86,6 +86,7 @@ enum fip_state {
  * struct fcoe_ctlr - FCoE Controller and FIP state
  * @state:	   internal FIP state for network link and FIP or non-FIP mode.
  * @mode:	   LLD-selected mode.
+ * @port:          The FC port that this controller is associated with
  * @lp:		   &fc_lport: libfc local port.
  * @sel_fcf:	   currently selected FCF, or NULL.
  * @fcfs:	   list of discovered FCFs.
@@ -123,6 +124,7 @@ enum fip_state {
 struct fcoe_ctlr {
 	enum fip_state state;
 	enum fip_state mode;
+	struct fc_port *port;
 	struct fc_lport *lp;
 	struct fcoe_fcf *sel_fcf;
 	struct list_head fcfs;
@@ -157,9 +159,27 @@ struct fcoe_ctlr {
 	spinlock_t ctlr_lock;
 };
 
+#define ctlr_to_port(x)				\
+	((x)->port)
+
+/**
+ * enum fcoe_fcf_event - FCF events
+ * @FCF_EV_NONE: No event
+ * @FCF_EV_ADD: Add the FCF to the transport
+ * @FCF_EV_DEL: Delete the FCF from the transport
+ */
+enum fcoe_fcf_event {
+	FCF_EV_NONE = 0,
+	FCF_EV_ADD,
+	FCF_EV_DEL
+};
+
 /**
  * struct fcoe_fcf - Fibre-Channel Forwarder
  * @list:	 list linkage
+ * @event_work:  Work for FC Transport actions queue
+ * @event:       The event to be processed
+ * @fip:         The controller that the FCF was discovered on
  * @time:	 system time (jiffies) when an advertisement was last received
  * @switch_name: WWN of switch from advertisement
  * @fabric_name: WWN of fabric from advertisement
@@ -180,6 +200,9 @@ struct fcoe_ctlr {
  */
 struct fcoe_fcf {
 	struct list_head list;
+	struct work_struct event_work;
+	enum fcoe_fcf_event event;
+	struct fcoe_ctlr *fip;
 	unsigned long time;
 
 	u64 switch_name;
@@ -195,6 +218,9 @@ struct fcoe_fcf {
 	u8 fd_flags:1;
 };
 
+#define fcf_to_fabric(x)					\
+	(struct fc_fabric *)(((struct fc_fabric *)(x)) - 1)
+
 /**
  * struct fcoe_rport - VN2VN remote port
  * @time:	time of create or last beacon packet received from node
@@ -229,6 +255,7 @@ int fcoe_libfc_config(struct fc_lport *, struct fcoe_ctlr *,
 		      const struct libfc_function_template *, int init_fcp);
 u32 fcoe_fc_crc(struct fc_frame *fp);
 int fcoe_start_io(struct sk_buff *skb);
+int fcoe_fabric_match(struct fc_fabric *new, struct fc_fabric *old);
 
 /**
  * is_fip_mode() - returns true if FIP mode selected.
@@ -323,6 +350,10 @@ void fcoe_queue_timer(ulong lport);
 int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen,
 			   struct fcoe_percpu_s *fps);
 
+/* FCF create/destroy helpers (list_add/del) */
+int fcoe_ctlr_fabric_create(struct fcoe_ctlr *, struct fcoe_fcf *);
+int fcoe_ctlr_fabric_destroy(struct fcoe_ctlr *, struct fcoe_fcf *);
+
 /**
  * struct netdev_list
  * A mapping from netdevice to fcoe_transport
@@ -337,4 +368,7 @@ struct fcoe_netdev_mapping {
 int fcoe_transport_attach(struct fcoe_transport *ft);
 int fcoe_transport_detach(struct fcoe_transport *ft);
 
+int fcoe_ctlr_setup(void);
+void fcoe_ctlr_teardown(void);
+
 #endif /* _LIBFCOE_H */
#7 lore raw

RFC PATCH v2 7/10 FC Transport: Add Fabric Attributes

In reply to Robert Love

This patch adds some FC Fabric attributes. They're added in the same style that all other FC Transport attributes are defined.

The interesting attributes are 'dev_loss_tmo' and 'selected'.

It might be desirable to make 'dev_loss_tmo' a module parameter as the rport's device loss timeout value is.

It might be desireable to make 'selected' writable with a callback to the LLD. This would allow the user to override the kernel's selection.

---
 drivers/scsi/scsi_transport_fc.c |  222 ++++++++++++++++++++++++++++++++++----
 include/scsi/scsi_transport_fc.h |   43 +++++++
 2 files changed, 241 insertions(+), 24 deletions(-)
drivers/scsi/scsi_transport_fc.c +198 -24
index 86600e0..8a28be9 100644
@@ -60,8 +60,12 @@ static void fc_bsg_goose_queue(struct fc_rport *);
  * dev_loss_tmo: the default number of seconds that the FC transport
  *   should insulate the loss of a remote port.
  *   The maximum will be capped by the value of SCSI_DEVICE_BLOCK_MAX_TIMEOUT.
+ *
+ * fab_dev_loss_tmo: the default number of seconds that the FC transport
+ *   should insulate the loss of a fabric.
  */
 static unsigned int fc_dev_loss_tmo = 60;		/* seconds */
+static unsigned int fc_fab_dev_loss_tmo = 600;          /* seconds */
 
 module_param_named(dev_loss_tmo, fc_dev_loss_tmo, uint, S_IRUGO|S_IWUSR);
 MODULE_PARM_DESC(dev_loss_tmo,
@@ -71,6 +75,13 @@ MODULE_PARM_DESC(dev_loss_tmo,
 		 " between 1 and SCSI_DEVICE_BLOCK_MAX_TIMEOUT if"
 		 " fast_io_fail_tmo is not set.");
 
+module_param_named(fab_dev_loss_tmo, fc_fab_dev_loss_tmo,
+		   uint, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(fab_dev_loss_tmo,
+		 "Maximum number of seconds that the FC transport should"
+		 " insulate the loss of a fabric. Once this value is"
+		 " exceeded, the fabric is removed.");
+
 /*
  * Redefine so that we can have same named attributes in the
  * sdev/starget/host objects.
@@ -110,6 +121,16 @@ static int get_fc_##title##_match(const char *table_key,		\
 	return 1; /* failure */						\
 }
 
+static struct {
+	enum fabric_state value;
+	char              *name;
+} fabric_state_names[] = {
+	{ FC_FABRICSTATE_UNKNOWN,      "Unknown" },
+	{ FC_FABRICSTATE_DISCONNECTED, "Disconnected" },
+	{ FC_FABRICSTATE_CONNECTED,    "Connected" },
+};
+fc_enum_name_search(fabric_state, fabric_state, fabric_state_names)
+#define FABRIC_STATE_MAX_NAMELEN 50
 
 /* Convert fc_port_type values to ascii string name */
 static struct {
@@ -131,7 +152,6 @@ fc_enum_name_search(port_type, fc_port_type, fc_port_type_names)
 /* Reuse fc_port_type enum function for vport_type */
 #define get_fc_vport_type_name get_fc_port_type_name
 
-
 /* Convert fc_host_event_code values to ascii string name */
 static const struct {
 	enum fc_host_event_code		value;
@@ -314,8 +334,8 @@ static void fc_scsi_scan_rport(struct work_struct *work);
 #define FC_RPORT_NUM_ATTRS	10
 #define FC_VPORT_NUM_ATTRS	9
 #define FC_HOST_NUM_ATTRS	22
-#define FC_PORT_NUM_ATTRS       1
-#define FC_FABRIC_NUM_ATTRS     1
+#define FC_PORT_NUM_ATTRS       2
+#define FC_FABRIC_NUM_ATTRS     13
 
 struct fc_internal {
 	struct scsi_transport_template t;
@@ -504,6 +524,25 @@ static DECLARE_TRANSPORT_CLASS(fc_fabric_class,
 			       NULL,
 			       NULL);
 
+/*
+ * dev_loss_tmo attribute
+ */
+static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
+{
+	char *cp;
+
+	*val = simple_strtoul(buf, &cp, 0);
+	if ((*cp && (*cp != '\n')) || (*val < 0))
+		return -EINVAL;
+	/*
+	 * Check for overflow; dev_loss_tmo is u32
+	 */
+	if (*val > UINT_MAX)
+		return -EINVAL;
+
+	return 0;
+}
+
 #define fc_private_port_show_function(field, format_string, sz, cast)	\
 static ssize_t								\
 show_fc_port_##field(struct device *dev,				\
@@ -545,7 +584,12 @@ show_fc_fabric_##field(struct device *dev,				\
 #define fc_fabric_rd_attr_cast(field, format_string, sz, cast)		\
 	fc_fabric_show_function(field, format_string, sz, (cast))	\
 	static FC_DEVICE_ATTR(fabric, field, S_IRUGO,			\
-		      show_fc_fabric_##field, NULL)
+			      show_fc_fabric_##field, NULL)
+
+#define fc_fabric_rd_attr(field, format_string, sz)			\
+	fc_fabric_show_function(field, format_string, sz, )		\
+	static FC_DEVICE_ATTR(fabric, field, S_IRUGO,			\
+			      show_fc_fabric_##field, NULL)
 
 #define SETUP_FABRIC_ATTRIBUTE_RD(field)				\
 	i->private_fabric_attrs[count] = device_attr_fabric_##field;	\
@@ -555,8 +599,135 @@ show_fc_fabric_##field(struct device *dev,				\
 	if (i->f->show_fabric_##field)					\
 		count++
 
+#define SETUP_PRIVATE_FABRIC_ATTRIBUTE_RW(field)			\
+{									\
+	i->private_fabric_attrs[count] = device_attr_fabric_##field;	\
+	i->fabric_attrs[count] = &i->private_fabric_attrs[count];	\
+	count++;							\
+}
+
+#define SETUP_PRIVATE_FABRIC_ATTRIBUTE_RD(field)                       \
+	i->private_fabric_attrs[count] = device_attr_fabric_##field;    \
+	i->private_fabric_attrs[count].attr.mode = S_IRUGO;             \
+	i->private_fabric_attrs[count].store = NULL;                    \
+	i->fabric_attrs[count] = &i->private_fabric_attrs[count];       \
+	count++
+
 fc_fabric_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
+fc_fabric_rd_attr_cast(switch_name, "0x%llx\n", 20, unsigned long long);
+fc_fabric_rd_attr(pri, "%u\n", 20);
+fc_fabric_rd_attr(e_d_tov, "%u\n", 20);
+fc_fabric_rd_attr(r_a_tov, "%u\n", 20);
+fc_fabric_rd_attr(csp_flags, "%d\n", 20);
+fc_fabric_rd_attr(selected, "%u\n", 20);
+
+#define fc_private_fabric_show_function(field, format_string, sz, cast)	\
+static ssize_t								\
+show_fc_fabric_##field(struct device *dev,				\
+		       struct device_attribute *attr, char *buf)	\
+{									\
+	struct fc_fabric *fabric = transport_class_to_fabric(dev);	\
+	return snprintf(buf, sz, format_string, cast fabric->field);	\
+}
+
+#define fc_private_fabric_rd_attr(field, format_string, sz)		\
+	fc_private_fabric_show_function(field, format_string, sz, )	\
+	static FC_DEVICE_ATTR(fabric, field, S_IRUGO,			\
+			      show_fc_fabric_##field, NULL)
+
+fc_private_fabric_rd_attr(fc_map, "%x\n", 20);
+fc_private_fabric_rd_attr(vfid, "%d\n", 20);
+fc_private_fabric_rd_attr(mac, "%pM\n", 20);
+fc_private_fabric_rd_attr(fka_period, "%d\n", 20);
+
+static ssize_t show_fabric_state(struct device *dev,
+				 struct device_attribute *attr,
+				 char *buf)
+{
+	struct fc_fabric *fabric = transport_class_to_fabric(dev);
+	const char *name;
+	name = get_fc_fabric_state_name(fabric->state);
+	if (!name)
+		return -EINVAL;
+	return snprintf(buf, FABRIC_STATE_MAX_NAMELEN, "%s\n", name);
+}
+static FC_DEVICE_ATTR(fabric, state, S_IRUGO, show_fabric_state, NULL);
+
+static int fc_fabric_set_dev_loss_tmo(struct fc_fabric *fabric,
+				      unsigned long val)
+{
+	struct Scsi_Host *shost = fabric_to_shost(fabric);
+	struct fc_internal *i = to_fc_internal(shost->transportt);
+
+	if (fabric->state == FC_FABRICSTATE_DISCONNECTED)
+		return -EBUSY;
+	/*
+	 * Check for overflow; dev_loss_tmo is u32
+	 */
+	if (val > UINT_MAX)
+		return -EINVAL;
+
+	i->f->set_fabric_dev_loss_tmo(fabric, val);
+	return 0;
+}
+
+fc_fabric_show_function(dev_loss_tmo, "%d\n", 20, )
+static ssize_t
+store_fc_fabric_dev_loss_tmo(struct device *dev, struct device_attribute *attr,
+			     const char *buf, size_t count)
+{
+	struct fc_fabric *fabric = transport_class_to_fabric(dev);
+	unsigned long val;
+	int rc;
+
+	rc = fc_str_to_dev_loss(buf, &val);
+	if (rc)
+		return rc;
+
+	rc = fc_fabric_set_dev_loss_tmo(fabric, val);
+	if (rc)
+		return rc;
+	return count;
+}
+static FC_DEVICE_ATTR(fabric, dev_loss_tmo, S_IRUGO | S_IWUSR,
+		      show_fc_fabric_dev_loss_tmo,
+		      store_fc_fabric_dev_loss_tmo);
+
+#define SETUP_PRIVATE_PORT_ATTRIBUTE_RW(field)				\
+{								\
+	i->private_port_attrs[count] = device_attr_port_##field;	\
+	i->port_attrs[count] = &i->private_port_attrs[count];		\
+	count++;							\
+}
+
+static ssize_t
+store_fc_private_port_fab_dev_loss_tmo(struct device *dev,
+				       struct device_attribute *attr,
+				       const char *buf, size_t count)
+{
+	struct fc_port *port = transport_class_to_port(dev);
+	struct Scsi_Host *shost = port_to_shost(port);
+	struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
+	struct fc_fabric *fabric;
+	unsigned long val, flags;
+	int rc;
 
+	rc = fc_str_to_dev_loss(buf, &val);
+	if (rc)
+		return rc;
+
+	fc_port_fab_dev_loss_tmo(port) = val;
+	spin_lock_irqsave(shost->host_lock, flags);
+	list_for_each_entry(fabric, &fc_host->fabrics, peers)
+		fc_fabric_set_dev_loss_tmo(fabric, val);
+	spin_unlock_irqrestore(shost->host_lock, flags);
+	return count;
+}
+
+fc_private_port_show_function(fab_dev_loss_tmo, "%d\n", 20, );
+static FC_DEVICE_ATTR(port, fab_dev_loss_tmo, S_IRUGO | S_IWUSR,
+		      show_fc_port_fab_dev_loss_tmo,
+		      store_fc_private_port_fab_dev_loss_tmo);
 
 /*
  * Netlink Infrastructure
@@ -917,25 +1088,6 @@ static FC_DEVICE_ATTR(rport, supported_classes, S_IRUGO,
 
 /* Dynamic Remote Port Attributes */
 
-/*
- * dev_loss_tmo attribute
- */
-static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
-{
-	char *cp;
-
-	*val = simple_strtoul(buf, &cp, 0);
-	if ((*cp && (*cp != '\n')) || (*val < 0))
-		return -EINVAL;
-	/*
-	 * Check for overflow; dev_loss_tmo is u32
-	 */
-	if (*val > UINT_MAX)
-		return -EINVAL;
-
-	return 0;
-}
-
 static int fc_rport_set_dev_loss_tmo(struct fc_rport *rport,
 				     unsigned long val)
 {
@@ -2363,6 +2515,7 @@ fc_attach_transport(struct fc_function_template *ft)
 	 */
 	count = 0;
 	SETUP_PORT_ATTRIBUTE_RD(maxframe_size);
+	SETUP_PRIVATE_PORT_ATTRIBUTE_RW(fab_dev_loss_tmo);
 	BUG_ON(count > FC_PORT_NUM_ATTRS);
 
 	i->port_attrs[count] = NULL;
@@ -2372,6 +2525,18 @@ fc_attach_transport(struct fc_function_template *ft)
 	 */
 	count = 0;
 	SETUP_FABRIC_ATTRIBUTE_RD(fabric_name);
+	SETUP_FABRIC_ATTRIBUTE_RD(switch_name);
+	SETUP_FABRIC_ATTRIBUTE_RD(fc_map);
+	SETUP_FABRIC_ATTRIBUTE_RD(vfid);
+	SETUP_FABRIC_ATTRIBUTE_RD(mac);
+	SETUP_FABRIC_ATTRIBUTE_RD(pri);
+	SETUP_FABRIC_ATTRIBUTE_RD(fka_period);
+	SETUP_FABRIC_ATTRIBUTE_RD(e_d_tov);
+	SETUP_FABRIC_ATTRIBUTE_RD(r_a_tov);
+	SETUP_FABRIC_ATTRIBUTE_RD(csp_flags);
+	SETUP_FABRIC_ATTRIBUTE_RD(selected);
+	SETUP_PRIVATE_FABRIC_ATTRIBUTE_RD(state);
+	SETUP_PRIVATE_FABRIC_ATTRIBUTE_RW(dev_loss_tmo);
 	BUG_ON(count > FC_FABRIC_NUM_ATTRS);
 
 	i->fabric_attrs[count] = NULL;
@@ -3785,7 +3950,7 @@ struct fc_port *fc_port_add(struct Scsi_Host *shost)
 	fcport->supported_classes = FC_COS_UNSPECIFIED;
 	fcport->supported_speeds = FC_PORTSPEED_UNKNOWN;
 	fcport->speed = FC_PORTSPEED_UNKNOWN;
-	fcport->fab_dev_loss_tmo = 600; /* default to 10mins */
+	fcport->fab_dev_loss_tmo = fc_fab_dev_loss_tmo;
 	memset(fcport->supported_fc4s, 0,
 	       sizeof(fcport->supported_fc4s));
 	memset(fcport->active_fc4s, 0,
@@ -3958,6 +4123,15 @@ struct fc_fabric *fc_fabric_create(struct Scsi_Host *shost,
 	INIT_WORK(&fabric->fabric_delete_work, fc_fabric_final_delete);
 	INIT_DELAYED_WORK(&fabric->dev_loss_work, fc_timeout_deleted_fabric);
 	fabric->dev_loss_tmo = port->fab_dev_loss_tmo;
+	fabric->fabric_name = -1;
+	fabric->switch_name = -1;
+	fabric->fc_map = -1;
+	fabric->vfid = -1;
+	memset(fabric->mac, 0, sizeof(*fabric->mac));
+	fabric->pri = -1;
+	fabric->fka_period = -1;
+	fabric->r_a_tov = -1;
+	fabric->e_d_tov = -1;
 
 	/* Setup internal structures */
 	fabric->id = atomic_inc_return(&fc_fabric_next_id) - 1;
include/scsi/scsi_transport_fc.h +43 -0

78 lines not on this page · raw message

#8 lore raw

RFC PATCH v2 8/10 fcoe: Use fabric attributes

In reply to Robert Love

This patch has the fcoe protocol stack select to display the previously added fabric attributes. The patch adds some helper routines in libfcoe to get information from the internal 'struct fcoe_fcf', which is private to the FC Transport's 'struct fc_fabric'.

---
 drivers/scsi/fcoe/fcoe.c      |   14 +++++++++++++
 drivers/scsi/fcoe/fcoe_ctlr.c |   45 +++++++++++++++++++++++++++++++++++++++++
 drivers/scsi/libfc/fc_lport.c |    1 +
 include/scsi/libfc.h          |    1 +
 include/scsi/libfcoe.h        |    6 +++++
 5 files changed, 67 insertions(+), 0 deletions(-)
drivers/scsi/fcoe/fcoe.c +14 -0
index fb8a504..4825c0a 100644
@@ -176,7 +176,21 @@ struct fc_function_template fcoe_nport_fc_functions = {
 
 	.dd_fcfabric_size = sizeof(struct fcoe_fcf),
 	.fabric_match = fcoe_fabric_match,
+	.get_fabric_pri = fcoe_get_fabric_pri,
+	.get_fabric_r_a_tov = fcoe_get_fabric_ra_tov,
+	.get_fabric_e_d_tov = fcoe_get_fabric_ed_tov,
+	.get_fabric_selected = fcoe_get_fabric_selected,
 	.show_fabric_fabric_name = 1,
+	.show_fabric_switch_name = 1,
+	.show_fabric_fc_map = 1,
+	.show_fabric_vfid = 1,
+	.show_fabric_mac = 1,
+	.show_fabric_pri = 1,
+	.show_fabric_fka_period = 1,
+	.show_fabric_r_a_tov = 1,
+	.show_fabric_e_d_tov = 1,
+	.show_fabric_csp_flags = 1,
+	.show_fabric_selected = 1,
 
 	.fabric_create = fcoe_fabric_create,
 	.fabric_destroy = fcoe_fabric_destroy,
drivers/scsi/fcoe/fcoe_ctlr.c +45 -0

63 lines not on this page · raw message

drivers/scsi/libfc/fc_lport.c +1 -0
index 6be4a8f..d85a326 100644
@@ -1542,6 +1542,7 @@ void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
 			} else {
 				lport->e_d_tov = e_d_tov;
 				lport->r_a_tov = r_a_tov;
+				lport->fabric_csp_flags = csp_flags;
 				fc_host_fabric_name(lport->host) =
 					get_unaligned_be64(&flp->fl_wwnn);
 				fc_lport_set_port_id(lport, did, fp);
include/scsi/libfc.h +1 -0
index 7d96829..17b080a 100644
@@ -877,6 +877,7 @@ struct fc_lport {
 	unsigned int		       service_params;
 	unsigned int		       e_d_tov;
 	unsigned int		       r_a_tov;
+	u16                            fabric_csp_flags;
 	struct fc_els_rnid_gen	       rnid_gen;
 
 	/* Capabilities */
include/scsi/libfcoe.h +6 -0
index 2c03c6c..bc5ff13 100644
@@ -364,6 +364,12 @@ struct fcoe_netdev_mapping {
 	struct fcoe_transport *ft;
 };
 
+/* Helpers for fc_function_template get_* routines */
+void fcoe_get_fabric_pri(struct fc_fabric *);
+void fcoe_get_fabric_ed_tov(struct fc_fabric *);
+void fcoe_get_fabric_ra_tov(struct fc_fabric *);
+void fcoe_get_fabric_selected(struct fc_fabric *);
+
 /* fcoe transports registration and deregistration */
 int fcoe_transport_attach(struct fcoe_transport *ft);
 int fcoe_transport_detach(struct fcoe_transport *ft);
#9 lore raw

RFC PATCH v2 9/10 FC Transport: Add FC Port Attributes

In reply to Robert Love

This patch adds additional attributes to the FC Port structure. These attributes are mostly FCoE related and were chosen because they were members of 'struct fcoe_ctlr' that is used in libfcoe.

Previous attributes on 'struct fc_port' were for fixed features of the port. This patch adds "FIP controller" members to 'strcut fc_port' and exposes them to the user as r-- attributes.

An alternative aproach would be to create a "controller" device that could be attached to the fc_host and exposed as a separate device in sysfs.

The fc_host, fc_port and "controller" are all 1:1 in regards to eachother. Is there a reason to keep these devices separate? Should all port and controller attributes be merged into the fc_host?

---
 drivers/scsi/scsi_transport_fc.c |  180 +++++++++++++++++++++++++++++++-------
 include/scsi/scsi_transport_fc.h |   54 +++++++++++
 2 files changed, 202 insertions(+), 32 deletions(-)
drivers/scsi/scsi_transport_fc.c +148 -32
index 8a28be9..4ee4640 100644
@@ -122,6 +122,17 @@ static int get_fc_##title##_match(const char *table_key,		\
 }
 
 static struct {
+	enum mac_mode value;
+	char          *name;
+} mac_mode_names[] = {
+	{ MAC_MODE_UNKNOWN, "Unknown" },
+	{ MAC_MODE_SPMA,    "SPMA" },
+	{ MAC_MODE_FPMA,    "FPMA" },
+};
+fc_enum_name_search(mac_mode, mac_mode, mac_mode_names)
+#define MAC_MODE_MAX_NAMELEN 50
+
+static struct {
 	enum fabric_state value;
 	char              *name;
 } fabric_state_names[] = {
@@ -334,7 +345,7 @@ static void fc_scsi_scan_rport(struct work_struct *work);
 #define FC_RPORT_NUM_ATTRS	10
 #define FC_VPORT_NUM_ATTRS	9
 #define FC_HOST_NUM_ATTRS	22
-#define FC_PORT_NUM_ATTRS       2
+#define FC_PORT_NUM_ATTRS       13
 #define FC_FABRIC_NUM_ATTRS     13
 
 struct fc_internal {
@@ -543,31 +554,6 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
 	return 0;
 }
 
-#define fc_private_port_show_function(field, format_string, sz, cast)	\
-static ssize_t								\
-show_fc_port_##field(struct device *dev,				\
-		     struct device_attribute *attr, char *buf)		\
-{									\
-	struct fc_port *port = transport_class_to_port(dev);		\
-	return snprintf(buf, sz, format_string, cast port->field);	\
-}
-
-#define fc_private_port_rd_attr(field, format_string, sz)		\
-	fc_private_port_show_function(field, format_string, sz, )	\
-	static FC_DEVICE_ATTR(port, field, S_IRUGO,			\
-		      show_fc_port_##field, NULL)
-
-#define SETUP_PORT_ATTRIBUTE_RD(field)					\
-	i->private_port_attrs[count] = device_attr_port_##field;	\
-	i->private_port_attrs[count].attr.mode = S_IRUGO;		\
-	i->private_port_attrs[count].store = NULL;			\
-	i->port_attrs[count] = &i->private_port_attrs[count];		\
-	if (i->f->show_port_##field)					\
-		count++
-
-fc_private_port_rd_attr(maxframe_size, "%u bytes\n", 20);
-
-
 #define fc_fabric_show_function(field, format_string, sz, cast)		\
 static ssize_t								\
 show_fc_fabric_##field(struct device *dev,				\
@@ -606,11 +592,11 @@ show_fc_fabric_##field(struct device *dev,				\
 	count++;							\
 }
 
-#define SETUP_PRIVATE_FABRIC_ATTRIBUTE_RD(field)                       \
-	i->private_fabric_attrs[count] = device_attr_fabric_##field;    \
-	i->private_fabric_attrs[count].attr.mode = S_IRUGO;             \
-	i->private_fabric_attrs[count].store = NULL;                    \
-	i->fabric_attrs[count] = &i->private_fabric_attrs[count];       \
+#define SETUP_PRIVATE_FABRIC_ATTRIBUTE_RD(field)			\
+	i->private_fabric_attrs[count] = device_attr_fabric_##field;	\
+	i->private_fabric_attrs[count].attr.mode = S_IRUGO;		\
+	i->private_fabric_attrs[count].store = NULL;			\
+	i->fabric_attrs[count] = &i->private_fabric_attrs[count];	\
 	count++
 
 fc_fabric_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
@@ -693,13 +679,122 @@ static FC_DEVICE_ATTR(fabric, dev_loss_tmo, S_IRUGO | S_IWUSR,
 		      show_fc_fabric_dev_loss_tmo,
 		      store_fc_fabric_dev_loss_tmo);
 
+#define fc_port_show_function(field, format_string, sz, cast)		\
+static ssize_t								\
+show_fc_port_##field(struct device *dev,				\
+		     struct device_attribute *attr, char *buf)		\
+{									\
+	struct fc_port *port = transport_class_to_port(dev);		\
+	struct fc_internal *i = to_fc_internal(port->t);		\
+	if (i->f->get_port_##field)					\
+		i->f->get_port_##field(port);				\
+	return snprintf(buf, sz, format_string,				\
+			cast fc_port_##field(port));			\
+}
+
+#define fc_port_rd_attr(field, format_string, sz)			\
+	fc_port_show_function(field, format_string, sz, )		\
+	static FC_DEVICE_ATTR(port, field, S_IRUGO,			\
+			      show_fc_port_##field, NULL)
+
+#define fc_private_port_show_function(field, format_string, sz, cast)	\
+static ssize_t								\
+show_fc_port_##field(struct device *dev,				\
+		     struct device_attribute *attr, char *buf)		\
+{									\
+	struct fc_port *port = transport_class_to_port(dev);		\
+	return snprintf(buf, sz, format_string, cast port->field);	\
+}
+
+#define fc_private_port_rd_attr(field, format_string, sz)		\
+	fc_private_port_show_function(field, format_string, sz, )	\
+	static FC_DEVICE_ATTR(port, field, S_IRUGO,			\
+		      show_fc_port_##field, NULL)
+
+#define SETUP_PORT_ATTRIBUTE_RD(field)					\
+	i->private_port_attrs[count] = device_attr_port_##field;	\
+	i->private_port_attrs[count].attr.mode = S_IRUGO;		\
+	i->private_port_attrs[count].store = NULL;			\
+	i->port_attrs[count] = &i->private_port_attrs[count];		\
+	if (i->f->show_port_##field)					\
+		count++
+
 #define SETUP_PRIVATE_PORT_ATTRIBUTE_RW(field)				\
-{								\
+{									\
 	i->private_port_attrs[count] = device_attr_port_##field;	\
 	i->port_attrs[count] = &i->private_port_attrs[count];		\
 	count++;							\
 }
 
+#define SETUP_PRIVATE_PORT_ATTRIBUTE_RD(field)				\
+	i->private_port_attrs[count] = device_attr_port_##field;	\
+	i->private_port_attrs[count].attr.mode = S_IRUGO;		\
+	i->private_port_attrs[count].store = NULL;			\
+	i->port_attrs[count] = &i->private_port_attrs[count];		\
+	count++
+
+fc_private_port_rd_attr(maxframe_size, "%u bytes\n", 20);
+
+fc_port_rd_attr(sol_time, "%lu\n", 20);
+fc_port_rd_attr(sel_time, "%lu\n", 20);
+fc_port_rd_attr(port_ka_time, "%lu\n", 20);
+fc_port_rd_attr(ctlr_ka_time, "%lu\n", 20);
+fc_port_rd_attr(probe_tries, "%u\n", 20);
+fc_port_rd_attr(port_dest_addr, "%pM\n", 20);
+fc_port_rd_attr(ctlr_src_addr, "%pM\n", 20);
+
+static ssize_t
+show_mac_mode(struct device *dev, struct device_attribute *attr,
+	      char *buf)
+{
+	struct fc_port *port = transport_class_to_port(dev);
+	const char *name;
+	name = get_fc_mac_mode_name(port->mode);
+	if (!name)
+		return -EINVAL;
+	return snprintf(buf, MAC_MODE_MAX_NAMELEN, "%s\n", name);
+}
+static FC_DEVICE_ATTR(port, mac_mode, S_IRUGO, show_mac_mode, NULL);
+
+static ssize_t
+show_fc_port_supported_classes(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buf)
+{
+	struct fc_port *port = transport_class_to_port(dev);
+
+	if (fc_port_supported_classes(port) == FC_COS_UNSPECIFIED)
+		return snprintf(buf, 20, "unspecified\n");
+
+	return get_fc_cos_names(fc_port_supported_classes(port), buf);
+}
+static FC_DEVICE_ATTR(port, supported_classes, S_IRUGO,
+		      show_fc_port_supported_classes, NULL);
+
+static ssize_t
+show_fc_port_supported_fc4s(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	struct fc_port *port = transport_class_to_port(dev);
+	return (ssize_t)show_fc_fc4s(buf, fc_port_supported_fc4s(port));
+}
+static FC_DEVICE_ATTR(port, supported_fc4s, S_IRUGO,
+		      show_fc_port_supported_fc4s, NULL);
+
+static ssize_t
+show_fc_port_supported_speeds(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	struct fc_port *port = transport_class_to_port(dev);
+
+	if (fc_port_supported_speeds(port) == FC_PORTSPEED_UNKNOWN)
+		return snprintf(buf, 20, "unknown\n");
+
+	return get_fc_port_speed_names(fc_port_supported_speeds(port), buf);
+}
+static FC_DEVICE_ATTR(port, supported_speeds, S_IRUGO,
+		      show_fc_port_supported_speeds, NULL);
+
 static ssize_t
 store_fc_private_port_fab_dev_loss_tmo(struct device *dev,
 				       struct device_attribute *attr,
@@ -2514,7 +2609,19 @@ fc_attach_transport(struct fc_function_template *ft)
 	 * Setup FC Port Attributes.
 	 */
 	count = 0;
+	SETUP_PORT_ATTRIBUTE_RD(supported_classes);
+	SETUP_PORT_ATTRIBUTE_RD(supported_fc4s);
+	SETUP_PORT_ATTRIBUTE_RD(supported_speeds);
 	SETUP_PORT_ATTRIBUTE_RD(maxframe_size);
+	SETUP_PORT_ATTRIBUTE_RD(sol_time);
+	SETUP_PORT_ATTRIBUTE_RD(sel_time);
+	SETUP_PORT_ATTRIBUTE_RD(port_ka_time);
+	SETUP_PORT_ATTRIBUTE_RD(ctlr_ka_time);
+	SETUP_PORT_ATTRIBUTE_RD(probe_tries);
+	SETUP_PORT_ATTRIBUTE_RD(port_dest_addr);
+	SETUP_PORT_ATTRIBUTE_RD(ctlr_src_addr);
+
+	SETUP_PRIVATE_PORT_ATTRIBUTE_RD(mac_mode);
 	SETUP_PRIVATE_PORT_ATTRIBUTE_RW(fab_dev_loss_tmo);
 	BUG_ON(count > FC_PORT_NUM_ATTRS);
 
@@ -2535,6 +2642,7 @@ fc_attach_transport(struct fc_function_template *ft)
 	SETUP_FABRIC_ATTRIBUTE_RD(r_a_tov);
 	SETUP_FABRIC_ATTRIBUTE_RD(csp_flags);
 	SETUP_FABRIC_ATTRIBUTE_RD(selected);
+
 	SETUP_PRIVATE_FABRIC_ATTRIBUTE_RD(state);
 	SETUP_PRIVATE_FABRIC_ATTRIBUTE_RW(dev_loss_tmo);
 	BUG_ON(count > FC_FABRIC_NUM_ATTRS);
@@ -3957,6 +4065,14 @@ struct fc_port *fc_port_add(struct Scsi_Host *shost)
 	       sizeof(fcport->active_fc4s));
 	memset(fcport->serial_number, 0,
 	       sizeof(fcport->serial_number));
+	fcport->sol_time = 0;
+	fcport->sel_time = 0;
+	fcport->port_ka_time = 0;
+	fcport->ctlr_ka_time = 0;
+	fcport->probe_tries = 0;
+	memset(fcport->port_dest_addr, 0, sizeof(*fcport->port_dest_addr));
+	memset(fcport->ctlr_src_addr, 0, sizeof(*fcport->ctlr_src_addr));
+	fcport->mode = MAC_MODE_UNKNOWN;
 
 	/* Setup internal structures */
 	fcport->id = atomic_inc_return(&fc_port_next_id) - 1;
include/scsi/scsi_transport_fc.h +54 -0

86 lines not on this page · raw message

#10 lore raw

RFC PATCH v2 10/10 libfcoe, fcoe: Use FC Port Attributes

In reply to Robert Love

This patch allows the SW FCoE kernel module to expose FCoE properties through the fc_port's sysfs attributes.

Helper routines were added to libfcoe to update the 'struct fc_port' fields with their 'struct fcoe_ctlr' conterparts. Other drivers that use libfcoe for FIP management can make use of these routines when they support the new sysfs extensions.

---
 drivers/scsi/fcoe/fcoe.c      |   60 +++++++++++++++++++++++++++++++++++++++++
 drivers/scsi/fcoe/fcoe_ctlr.c |   57 +++++++++++++++++++++++++++++++++++++++
 include/scsi/libfcoe.h        |   10 +++++++
 3 files changed, 127 insertions(+), 0 deletions(-)
drivers/scsi/fcoe/fcoe.c +60 -0
index 4825c0a..b336487 100644
@@ -160,6 +160,21 @@ static int fcoe_fabric_destroy(struct fc_port *port,
 	return fcoe_ctlr_fabric_destroy(fip, fcf);
 }
 
+#define fcoe_get_port_attr_from_ctlr(field)			\
+static void fcoe_get_##field(struct fc_port *port)	\
+{							\
+	struct fcoe_interface *fcoe = fc_port_priv(port);	\
+	return fcoe_get_port_##field(port, &fcoe->ctlr);	\
+}
+
+fcoe_get_port_attr_from_ctlr(sol_time)
+fcoe_get_port_attr_from_ctlr(sel_time)
+fcoe_get_port_attr_from_ctlr(port_ka_time)
+fcoe_get_port_attr_from_ctlr(ctlr_ka_time)
+fcoe_get_port_attr_from_ctlr(probe_tries)
+fcoe_get_port_attr_from_ctlr(port_dest_addr)
+fcoe_get_port_attr_from_ctlr(ctlr_src_addr)
+
 static struct libfc_function_template fcoe_libfc_fcn_templ = {
 	.frame_send = fcoe_xmit,
 	.ddp_setup = fcoe_ddp_setup,
@@ -173,6 +188,23 @@ static struct libfc_function_template fcoe_libfc_fcn_templ = {
 struct fc_function_template fcoe_nport_fc_functions = {
 	.dd_fcport_size = sizeof(struct fcoe_interface),
 	.show_port_maxframe_size = 1,
+	.show_port_supported_classes = 1,
+	.show_port_supported_fc4s = 1,
+	.show_port_supported_speeds = 1,
+	.show_port_sol_time = 1,
+	.show_port_sel_time = 1,
+	.show_port_port_ka_time = 1,
+	.show_port_ctlr_ka_time = 1,
+	.show_port_port_dest_addr = 1,
+	.show_port_ctlr_src_addr = 1,
+
+	.get_port_sol_time = fcoe_get_sol_time,
+	.get_port_sel_time = fcoe_get_sel_time,
+	.get_port_port_ka_time = fcoe_get_port_ka_time,
+	.get_port_ctlr_ka_time = fcoe_get_ctlr_ka_time,
+	.get_port_probe_tries = fcoe_get_probe_tries,
+	.get_port_port_dest_addr = fcoe_get_port_dest_addr,
+	.get_port_ctlr_src_addr = fcoe_get_ctlr_src_addr,
 
 	.dd_fcfabric_size = sizeof(struct fcoe_fcf),
 	.fabric_match = fcoe_fabric_match,
@@ -180,6 +212,7 @@ struct fc_function_template fcoe_nport_fc_functions = {
 	.get_fabric_r_a_tov = fcoe_get_fabric_ra_tov,
 	.get_fabric_e_d_tov = fcoe_get_fabric_ed_tov,
 	.get_fabric_selected = fcoe_get_fabric_selected,
+
 	.show_fabric_fabric_name = 1,
 	.show_fabric_switch_name = 1,
 	.show_fabric_fc_map = 1,
@@ -194,6 +227,7 @@ struct fc_function_template fcoe_nport_fc_functions = {
 
 	.fabric_create = fcoe_fabric_create,
 	.fabric_destroy = fcoe_fabric_destroy,
+	.set_fabric_dev_loss_tmo = fcoe_set_fabric_dev_loss_tmo,
 
 	.show_host_node_name = 1,
 	.show_host_port_name = 1,
@@ -387,6 +421,7 @@ static struct fcoe_interface *fcoe_interface_create(struct Scsi_Host *shost,
 {
 	struct fc_port *port;
 	struct fcoe_interface *fcoe;
+	struct ethtool_cmd ecmd;
 	int err;
 
 	if (!try_module_get(THIS_MODULE)) {
@@ -405,8 +440,33 @@ static struct fcoe_interface *fcoe_interface_create(struct Scsi_Host *shost,
 
 	fcoe = fc_port_priv(port);
 
+	/* Initialize the FC Port fixed attributes */
+	memset(fc_port_supported_fc4s(port), 0,
+	       sizeof(fc_port_supported_fc4s(port)));
+	fc_port_supported_fc4s(port)[2] = 1;
+	fc_port_supported_fc4s(port)[7] = 1;
+	fc_port_supported_classes(port) = FC_COS_CLASS3;
+
 	dev_hold(netdev);
 
+	/* TODO: Can this be folded into another routine?
+	 * fcoe_link_speed_update - per-lport, delay in
+	 * populating sysfs.
+	 * fcoe_interface_setup - currently takes a
+	 * fcoe_interface, already has the netdev held.
+	 * This is probably best candidate.
+	 */
+	fc_port_supported_speeds(port) = 0;
+	if (!dev_ethtool_get_settings(netdev, &ecmd)) {
+		if (ecmd.supported & (SUPPORTED_1000baseT_Half |
+				      SUPPORTED_1000baseT_Full))
+			fc_port_supported_speeds(port) |=
+				FC_PORTSPEED_1GBIT;
+		if (ecmd.supported & SUPPORTED_10000baseT_Full)
+			fc_port_supported_speeds(port) |=
+				FC_PORTSPEED_10GBIT;
+	}
+
 	/*
 	 * Initialize FIP.
 	 */
drivers/scsi/fcoe/fcoe_ctlr.c +57 -0

63 lines not on this page · raw message

include/scsi/libfcoe.h +10 -0
index bc5ff13..acfd56c 100644
@@ -369,6 +369,16 @@ void fcoe_get_fabric_pri(struct fc_fabric *);
 void fcoe_get_fabric_ed_tov(struct fc_fabric *);
 void fcoe_get_fabric_ra_tov(struct fc_fabric *);
 void fcoe_get_fabric_selected(struct fc_fabric *);
+void fcoe_get_fabric_state(struct fc_fabric *);
+void fcoe_set_fabric_dev_loss_tmo(struct fc_fabric *, u32);
+
+void fcoe_get_port_sol_time(struct fc_port *, struct fcoe_ctlr *);
+void fcoe_get_port_sel_time(struct fc_port *, struct fcoe_ctlr *);
+void fcoe_get_port_port_ka_time(struct fc_port *, struct fcoe_ctlr *);
+void fcoe_get_port_ctlr_ka_time(struct fc_port *, struct fcoe_ctlr *);
+void fcoe_get_port_probe_tries(struct fc_port *, struct fcoe_ctlr *);
+void fcoe_get_port_port_dest_addr(struct fc_port *, struct fcoe_ctlr *);
+void fcoe_get_port_ctlr_src_addr(struct fc_port *, struct fcoe_ctlr *);
 
 /* fcoe transports registration and deregistration */
 int fcoe_transport_attach(struct fcoe_transport *ft);