Skip to contentSkip to conversation

FCoE Sysfs

PATCH Superseded Robert Love 3 participants 11 messages Mar 16, 2012 – Mar 20, 2012

Subsystems (3)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover FCoE Sysfs

v2: Addressed Greg KH's review comments

* moved fcoe_ctlr_attrs and fcoe_fcf_attrs attribute helper macros from fcoe_sysfs.h to fcoe_sysfs.c so that they don't temp developers to use them. They're intended to be used in attribute show/store routine generating macros, but not by drivers.

* Removed unnecessary put_device calls on parent devices. Also removed unnecessary de-initialization of pointers to parent and removed unnecessary zero'ing of memory before freeing it.

* Added Documentation/ABI/testing/sysfs-class-fcoe document.

* Changed simple_strtoul usage to kstrtoul to avoid checkpatch.pl warning that I missed before. There's a bunch of noise in checkpatch.pl due to an odd macro usage, but I think any remaining checkpatch.pl warnings are OK.

---

This patch series adds a sysfs layer to libfcoe. It adds a sysfs instance for FIP controllers (a SW entity) and discovered Fibre Channel Forwarders (FCFs), which are simply FCoE switches.

The new sysfs code is used by any driver that currently uses libfcoe, namely fcoe.ko and bnx2fc_fcoe.ko. Any other FCoE capable device that wishes to use the high-level APIs defined in fcoe_syfs.h may, without having to use the the protocol processing portions of libfcoe.

The code borrows heavily from the FC Transport, but is less complicated because it does not need to interact with the SCSI layer directly.

I think one thing to consider with this series is that drivers, such as traditional HBAs, which wish to use this infrastructure will now need to depend on libfcoe.ko. It was either this or create a superfluous kernel module; I think libfcoe is an appropriate place for this code.

This series was created against scsi-misc + 9 patches mailed by me to linux-scsi on 03/09/12. (Note that 10 patches were mailed, but that patch 01/10 will be dropped)

I'm not sure if there's somewhere I should cross-post this for general sysfs review. I don't think I'm doing anything odd; I added Greg K-H to the CC list to try and get some sysfs eyes on this code.

---

Robert Love (4):
fcoe: Allocate fcoe_ctlr with fcoe_interface, not as a member
bnx2fc: Allocate fcoe_ctlr with bnx2fc_interface, not as a member
libfcoe: Add fcoe_sysfs
fcoe, bnx2fc, libfcoe: SW FCoE and bnx2fc use FCoE Syfs

 Documentation/ABI/testing/sysfs-class-fcoe |   77 +++
 drivers/scsi/bnx2fc/bnx2fc.h               |    7 
 drivers/scsi/bnx2fc/bnx2fc_els.c           |    2 
 drivers/scsi/bnx2fc/bnx2fc_fcoe.c          |  171 ++++--
 drivers/scsi/bnx2fc/bnx2fc_hwi.c           |   39 +
 drivers/scsi/fcoe/Makefile                 |    2 
 drivers/scsi/fcoe/fcoe.c                   |  196 +++++--
 drivers/scsi/fcoe/fcoe.h                   |    8 
 drivers/scsi/fcoe/fcoe_ctlr.c              |  159 +++++
 drivers/scsi/fcoe/fcoe_sysfs.c             |  840 ++++++++++++++++++++++++++++
 drivers/scsi/fcoe/fcoe_transport.c         |   13 
 include/scsi/fcoe_sysfs.h                  |  124 ++++
 include/scsi/libfcoe.h                     |   27 +
 13 files changed, 1532 insertions(+), 133 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-fcoe
 create mode 100644 drivers/scsi/fcoe/fcoe_sysfs.c
 create mode 100644 include/scsi/fcoe_sysfs.h
Signature · 1 line
Thanks, //Rob
#1 lore raw

PATCH v2 1/4 fcoe: Allocate fcoe_ctlr with fcoe_interface, not as a member

Currently the fcoe_ctlr associated with an interface is allocated as a member of struct fcoe_interface. This causes problems when attempting to use the new fcoe_sysfs APIs which allow us to allocate the fcoe_interface as private data to the fcoe_ctlr_attrs instance. The problem is that libfcoe wants to be able use pointer math to find a fcoe_ctlr's fcoe_ctlr_attrs as well as finding a fcoe_ctlr_attrs' assocated fcoe_ctlr. To do this we need to allocate the fcoe_ctlr_attrs, with private data for the LLD. The private data contains the fcoe_ctlr and it's private data is the fcoe_interface.

+-----------------+
| fcoe_ctlr_attrs |
+-----------------+
| fcoe_ctlr       |
+-----------------+
| fcoe_interface  |
+-----------------+

This prep work allows us to go from a fcoe_ctlr_attrs instance to its fcoe_ctlr and we can also go from a fcoe_ctlr to its fcoe_ctlr_attrs once the fcoe_sysfs API is in use (later patches in this series).

---
 drivers/scsi/fcoe/fcoe.c |  132 ++++++++++++++++++++++++++++++----------------
 drivers/scsi/fcoe/fcoe.h |    8 ++-
 include/scsi/libfcoe.h   |    9 +++
 3 files changed, 99 insertions(+), 50 deletions(-)
drivers/scsi/fcoe/fcoe.c +85 -47
index 58c88b0..85ab965 100644
@@ -282,7 +282,7 @@ static struct scsi_host_template fcoe_shost_template = {
 static int fcoe_interface_setup(struct fcoe_interface *fcoe,
 				struct net_device *netdev)
 {
-	struct fcoe_ctlr *fip = &fcoe->ctlr;
+	struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
 	struct netdev_hw_addr *ha;
 	struct net_device *real_dev;
 	u8 flogi_maddr[ETH_ALEN];
@@ -366,7 +366,9 @@ static int fcoe_interface_setup(struct fcoe_interface *fcoe,
 static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
 						    enum fip_state fip_mode)
 {
+	struct fcoe_ctlr *ctlr;
 	struct fcoe_interface *fcoe;
+	int size;
 	int err;
 
 	if (!try_module_get(THIS_MODULE)) {
@@ -376,7 +378,9 @@ static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
 		goto out;
 	}
 
-	fcoe = kzalloc(sizeof(*fcoe), GFP_KERNEL);
+	size = sizeof(struct fcoe_ctlr) + sizeof(struct fcoe_interface);
+	ctlr = kzalloc(size, GFP_KERNEL);
+	fcoe = fcoe_ctlr_priv(ctlr);
 	if (!fcoe) {
 		FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n");
 		fcoe = ERR_PTR(-ENOMEM);
@@ -388,15 +392,14 @@ static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
 	/*
 	 * Initialize FIP.
 	 */
-	fcoe_ctlr_init(&fcoe->ctlr, fip_mode);
-	fcoe->ctlr.send = fcoe_fip_send;
-	fcoe->ctlr.update_mac = fcoe_update_src_mac;
-	fcoe->ctlr.get_src_addr = fcoe_get_src_mac;
+	fcoe_ctlr_init(ctlr, fip_mode);
+	ctlr->send = fcoe_fip_send;
+	ctlr->update_mac = fcoe_update_src_mac;
+	ctlr->get_src_addr = fcoe_get_src_mac;
 
 	err = fcoe_interface_setup(fcoe, netdev);
 	if (err) {
-		fcoe_ctlr_destroy(&fcoe->ctlr);
-		kfree(fcoe);
+		fcoe_ctlr_destroy(ctlr);
 		dev_put(netdev);
 		fcoe = ERR_PTR(err);
 		goto out_putmod;
@@ -419,7 +422,7 @@ out:
 static void fcoe_interface_cleanup(struct fcoe_interface *fcoe)
 {
 	struct net_device *netdev = fcoe->netdev;
-	struct fcoe_ctlr *fip = &fcoe->ctlr;
+	struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
 	u8 flogi_maddr[ETH_ALEN];
 	const struct net_device_ops *ops;
 
@@ -459,7 +462,6 @@ static void fcoe_interface_cleanup(struct fcoe_interface *fcoe)
 	/* Release the self-reference taken during fcoe_interface_create() */
 	/* tear-down the FCoE controller */
 	fcoe_ctlr_destroy(fip);
-	kfree(fcoe);
 	dev_put(netdev);
 	module_put(THIS_MODULE);
 }
@@ -479,9 +481,11 @@ static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *netdev,
 			 struct net_device *orig_dev)
 {
 	struct fcoe_interface *fcoe;
+	struct fcoe_ctlr *ctlr;
 
 	fcoe = container_of(ptype, struct fcoe_interface, fip_packet_type);
-	fcoe_ctlr_recv(&fcoe->ctlr, skb);
+	ctlr = fcoe_to_ctlr(fcoe);
+	fcoe_ctlr_recv(ctlr, skb);
 	return 0;
 }
 
@@ -633,11 +637,13 @@ static int fcoe_netdev_config(struct fc_lport *lport, struct net_device *netdev)
 	u32 mfs;
 	u64 wwnn, wwpn;
 	struct fcoe_interface *fcoe;
+	struct fcoe_ctlr *ctlr;
 	struct fcoe_port *port;
 
 	/* Setup lport private data to point to fcoe softc */
 	port = lport_priv(lport);
 	fcoe = port->priv;
+	ctlr = fcoe_to_ctlr(fcoe);
 
 	/*
 	 * Determine max frame size based on underlying device and optional
@@ -664,10 +670,10 @@ static int fcoe_netdev_config(struct fc_lport *lport, struct net_device *netdev)
 
 	if (!lport->vport) {
 		if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
-			wwnn = fcoe_wwn_from_mac(fcoe->ctlr.ctl_src_addr, 1, 0);
+			wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr, 1, 0);
 		fc_set_wwnn(lport, wwnn);
 		if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
-			wwpn = fcoe_wwn_from_mac(fcoe->ctlr.ctl_src_addr,
+			wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
 						 2, 0);
 		fc_set_wwpn(lport, wwpn);
 	}
@@ -1036,6 +1042,7 @@ static int fcoe_ddp_done(struct fc_lport *lport, u16 xid)
 static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
 				       struct device *parent, int npiv)
 {
+	struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
 	struct net_device *netdev = fcoe->netdev;
 	struct fc_lport *lport, *n_port;
 	struct fcoe_port *port;
@@ -1099,7 +1106,7 @@ static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
 	}
 
 	/* Initialize the library */
-	rc = fcoe_libfc_config(lport, &fcoe->ctlr, &fcoe_libfc_fcn_templ, 1);
+	rc = fcoe_libfc_config(lport, ctlr, &fcoe_libfc_fcn_templ, 1);
 	if (rc) {
 		FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the "
 				"interface\n");
@@ -1366,6 +1373,7 @@ static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,
 {
 	struct fc_lport *lport;
 	struct fcoe_rcv_info *fr;
+	struct fcoe_ctlr *ctlr;
 	struct fcoe_interface *fcoe;
 	struct fc_frame_header *fh;
 	struct fcoe_percpu_s *fps;
@@ -1373,7 +1381,8 @@ static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,
 	unsigned int cpu;
 
 	fcoe = container_of(ptype, struct fcoe_interface, fcoe_packet_type);
-	lport = fcoe->ctlr.lp;
+	ctlr = fcoe_to_ctlr(fcoe);
+	lport = ctlr->lp;
 	if (unlikely(!lport)) {
 		FCOE_NETDEV_DBG(netdev, "Cannot find hba structure");
 		goto err2;
@@ -1389,8 +1398,8 @@ static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,
 
 	eh = eth_hdr(skb);
 
-	if (is_fip_mode(&fcoe->ctlr) &&
-	    compare_ether_addr(eh->h_source, fcoe->ctlr.dest_addr)) {
+	if (is_fip_mode(ctlr) &&
+	    compare_ether_addr(eh->h_source, ctlr->dest_addr)) {
 		FCOE_NETDEV_DBG(netdev, "wrong source mac address:%pM\n",
 				eh->h_source);
 		goto err;
@@ -1524,6 +1533,7 @@ static int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp)
 	unsigned int elen;		/* eth header, may include vlan */
 	struct fcoe_port *port = lport_priv(lport);
 	struct fcoe_interface *fcoe = port->priv;
+	struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
 	u8 sof, eof;
 	struct fcoe_hdr *hp;
 
@@ -1539,7 +1549,7 @@ static int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp)
 	}
 
 	if (unlikely(fh->fh_type == FC_TYPE_ELS) &&
-	    fcoe_ctlr_els_send(&fcoe->ctlr, lport, skb))
+	    fcoe_ctlr_els_send(ctlr, lport, skb))
 		return 0;
 
 	sof = fr_sof(fp);
@@ -1603,12 +1613,12 @@ static int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp)
 	/* fill up mac and fcoe headers */
 	eh = eth_hdr(skb);
 	eh->h_proto = htons(ETH_P_FCOE);
-	memcpy(eh->h_dest, fcoe->ctlr.dest_addr, ETH_ALEN);
-	if (fcoe->ctlr.map_dest)
+	memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
+	if (ctlr->map_dest)
 		memcpy(eh->h_dest + 3, fh->fh_d_id, 3);
 
-	if (unlikely(fcoe->ctlr.flogi_oxid != FC_XID_UNKNOWN))
-		memcpy(eh->h_source, fcoe->ctlr.ctl_src_addr, ETH_ALEN);
+	if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
+		memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
 	else
 		memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
 
@@ -1657,6 +1667,7 @@ static void fcoe_percpu_flush_done(struct sk_buff *skb)
 static inline int fcoe_filter_frames(struct fc_lport *lport,
 				     struct fc_frame *fp)
 {
+	struct fcoe_ctlr *ctlr;
 	struct fcoe_interface *fcoe;
 	struct fc_frame_header *fh;
 	struct sk_buff *skb = (struct sk_buff *)fp;
@@ -1678,7 +1689,8 @@ static inline int fcoe_filter_frames(struct fc_lport *lport,
 		return 0;
 
 	fcoe = ((struct fcoe_port *)lport_priv(lport))->priv;
-	if (is_fip_mode(&fcoe->ctlr) && fc_frame_payload_op(fp) == ELS_LOGO &&
+	ctlr = fcoe_to_ctlr(fcoe);
+	if (is_fip_mode(ctlr) && fc_frame_payload_op(fp) == ELS_LOGO &&
 	    ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
 		FCOE_DBG("fcoe: dropping FCoE lport LOGO in fip mode\n");
 		return -EINVAL;
@@ -1857,6 +1869,7 @@ static int fcoe_dcb_app_notification(struct notifier_block *notifier,
 				     ulong event, void *ptr)
 {
 	struct dcb_app_type *entry = ptr;
+	struct fcoe_ctlr *ctlr;
 	struct fcoe_interface *fcoe;
 	struct net_device *netdev;
 	struct fcoe_port *port;
@@ -1874,6 +1887,8 @@ static int fcoe_dcb_app_notification(struct notifier_block *notifier,
 	if (!fcoe)
 		return NOTIFY_OK;
 
+	ctlr = fcoe_to_ctlr(fcoe);
+
 	if (entry->dcbx & DCB_CAP_DCBX_VER_CEE)
 		prio = ffs(entry->app.priority) - 1;
 	else
@@ -1884,10 +1899,10 @@ static int fcoe_dcb_app_notification(struct notifier_block *notifier,
 
 	if (entry->app.protocol == ETH_P_FIP ||
 	    entry->app.protocol == ETH_P_FCOE)
-		fcoe->ctlr.priority = prio;
+		ctlr->priority = prio;
 
 	if (entry->app.protocol == ETH_P_FCOE) {
-		port = lport_priv(fcoe->ctlr.lp);
+		port = lport_priv(ctlr->lp);
 		port->priority = prio;
 	}
 
@@ -1909,6 +1924,7 @@ static int fcoe_device_notification(struct notifier_block *notifier,
 {
 	struct fc_lport *lport = NULL;
 	struct net_device *netdev = ptr;
+	struct fcoe_ctlr *ctlr;
 	struct fcoe_interface *fcoe;
 	struct fcoe_port *port;
 	struct fcoe_dev_stats *stats;
@@ -1918,7 +1934,8 @@ static int fcoe_device_notification(struct notifier_block *notifier,
 
 	list_for_each_entry(fcoe, &fcoe_hostlist, list) {
 		if (fcoe->netdev == netdev) {
-			lport = fcoe->ctlr.lp;
+			ctlr = fcoe_to_ctlr(fcoe);
+			lport = ctlr->lp;
 			break;
 		}
 	}
@@ -1947,7 +1964,7 @@ static int fcoe_device_notification(struct notifier_block *notifier,
 		break;
 	case NETDEV_UNREGISTER:
 		list_del(&fcoe->list);
-		port = lport_priv(fcoe->ctlr.lp);
+		port = lport_priv(ctlr->lp);
 		queue_work(fcoe_wq, &port->destroy_work);
 		goto out;
 		break;
@@ -1962,8 +1979,8 @@ static int fcoe_device_notification(struct notifier_block *notifier,
 	fcoe_link_speed_update(lport);
 
 	if (link_possible && !fcoe_link_ok(lport))
-		fcoe_ctlr_link_up(&fcoe->ctlr);
-	else if (fcoe_ctlr_link_down(&fcoe->ctlr)) {
+		fcoe_ctlr_link_up(ctlr);
+	else if (fcoe_ctlr_link_down(ctlr)) {
 		stats = per_cpu_ptr(lport->dev_stats, get_cpu());
 		stats->LinkFailureCount++;
 		put_cpu();
@@ -1983,6 +2000,7 @@ out:
  */
 static int fcoe_disable(struct net_device *netdev)
 {
+	struct fcoe_ctlr *ctlr;
 	struct fcoe_interface *fcoe;
 	int rc = 0;
 
@@ -1993,8 +2011,9 @@ static int fcoe_disable(struct net_device *netdev)
 	rtnl_unlock();
 
 	if (fcoe) {
-		fcoe_ctlr_link_down(&fcoe->ctlr);
-		fcoe_clean_pending_queue(fcoe->ctlr.lp);
+		ctlr = fcoe_to_ctlr(fcoe);
+		fcoe_ctlr_link_down(ctlr);
+		fcoe_clean_pending_queue(ctlr->lp);
 	} else
 		rc = -ENODEV;
 
@@ -2012,6 +2031,7 @@ static int fcoe_disable(struct net_device *netdev)
  */
 static int fcoe_enable(struct net_device *netdev)
 {
+	struct fcoe_ctlr *ctlr;
 	struct fcoe_interface *fcoe;
 	int rc = 0;
 
@@ -2020,11 +2040,17 @@ static int fcoe_enable(struct net_device *netdev)
 	fcoe = fcoe_hostlist_lookup_port(netdev);
 	rtnl_unlock();
 
-	if (!fcoe)
+	if (!fcoe) {
 		rc = -ENODEV;
-	else if (!fcoe_link_ok(fcoe->ctlr.lp))
-		fcoe_ctlr_link_up(&fcoe->ctlr);
+		goto out;
+	}
 
+	ctlr = fcoe_to_ctlr(fcoe);
+
+	if (!fcoe_link_ok(ctlr->lp))
+		fcoe_ctlr_link_up(ctlr);
+
+out:
 	mutex_unlock(&fcoe_config_mutex);
 	return rc;
 }
@@ -2039,6 +2065,7 @@ static int fcoe_enable(struct net_device *netdev)
  */
 static int fcoe_destroy(struct net_device *netdev)
 {
+	struct fcoe_ctlr *ctlr;
 	struct fcoe_interface *fcoe;
 	struct fc_lport *lport;
 	struct fcoe_port *port;
@@ -2051,7 +2078,8 @@ static int fcoe_destroy(struct net_device *netdev)
 		rc = -ENODEV;
 		goto out_nodev;
 	}
-	lport = fcoe->ctlr.lp;
+	ctlr = fcoe_to_ctlr(fcoe);
+	lport = ctlr->lp;
 	port = lport_priv(lport);
 	list_del(&fcoe->list);
 	queue_work(fcoe_wq, &port->destroy_work);
@@ -2106,7 +2134,8 @@ static void fcoe_dcb_create(struct fcoe_interface *fcoe)
 	int dcbx;
 	u8 fup, up;
 	struct net_device *netdev = fcoe->realdev;
-	struct fcoe_port *port = lport_priv(fcoe->ctlr.lp);
+	struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
+	struct fcoe_port *port = lport_priv(ctlr->lp);
 	struct dcb_app app = {
 				.priority = 0,
 				.protocol = ETH_P_FCOE
@@ -2129,7 +2158,7 @@ static void fcoe_dcb_create(struct fcoe_interface *fcoe)
 		}
 
 		port->priority = ffs(up) ? ffs(up) - 1 : 0;
-		fcoe->ctlr.priority = ffs(fup) ? ffs(fup) - 1 : port->priority;
+		ctlr->priority = ffs(fup) ? ffs(fup) - 1 : port->priority;
 	}
 #endif
 }
@@ -2146,6 +2175,7 @@ static void fcoe_dcb_create(struct fcoe_interface *fcoe)
 static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode)
 {
 	int rc = 0;
+	struct fcoe_ctlr *ctlr;
 	struct fcoe_interface *fcoe;
 	struct fc_lport *lport;
 
@@ -2164,6 +2194,8 @@ static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode)
 		goto out_nodev;
 	}
 
+	ctlr = fcoe_to_ctlr(fcoe);
+
 	lport = fcoe_if_create(fcoe, &netdev->dev, 0);
 	if (IS_ERR(lport)) {
 		printk(KERN_ERR "fcoe: Failed to create interface (%s)\n",
@@ -2175,7 +2207,7 @@ static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode)
 	}
 
 	/* Make this the "master" N_Port */
-	fcoe->ctlr.lp = lport;
+	ctlr->lp = lport;
 
 	/* setup DCB priority attributes. */
 	fcoe_dcb_create(fcoe);
@@ -2187,7 +2219,7 @@ static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode)
 	lport->boot_time = jiffies;
 	fc_fabric_login(lport);
 	if (!fcoe_link_ok(lport))
-		fcoe_ctlr_link_up(&fcoe->ctlr);
+		fcoe_ctlr_link_up(ctlr);
 
 out_nodev:
 	rtnl_unlock();
@@ -2297,11 +2329,12 @@ static int fcoe_reset(struct Scsi_Host *shost)
 	struct fc_lport *lport = shost_priv(shost);
 	struct fcoe_port *port = lport_priv(lport);
 	struct fcoe_interface *fcoe = port->priv;
+	struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
 
-	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);
+	fcoe_ctlr_link_down(ctlr);
+	fcoe_clean_pending_queue(ctlr->lp);
+	if (!fcoe_link_ok(ctlr->lp))
+		fcoe_ctlr_link_up(ctlr);
 	return 0;
 }
 
@@ -2336,10 +2369,12 @@ fcoe_hostlist_lookup_port(const struct net_device *netdev)
  */
 static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
 {
+	struct fcoe_ctlr *ctlr;
 	struct fcoe_interface *fcoe;
 
 	fcoe = fcoe_hostlist_lookup_port(netdev);
-	return (fcoe) ? fcoe->ctlr.lp : NULL;
+	ctlr = fcoe_to_ctlr(fcoe);
+	return (fcoe) ? ctlr->lp : NULL;
 }
 
 /**
@@ -2443,6 +2478,7 @@ module_init(fcoe_init);
 static void __exit fcoe_exit(void)
 {
 	struct fcoe_interface *fcoe, *tmp;
+	struct fcoe_ctlr *ctlr;
 	struct fcoe_port *port;
 	unsigned int cpu;
 
@@ -2454,7 +2490,8 @@ static void __exit fcoe_exit(void)
 	rtnl_lock();
 	list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list) {
 		list_del(&fcoe->list);
-		port = lport_priv(fcoe->ctlr.lp);
+		ctlr = fcoe_to_ctlr(fcoe);
+		port = lport_priv(ctlr->lp);
 		queue_work(fcoe_wq, &port->destroy_work);
 	}
 	rtnl_unlock();
@@ -2550,7 +2587,7 @@ static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport, u32 did,
 {
 	struct fcoe_port *port = lport_priv(lport);
 	struct fcoe_interface *fcoe = port->priv;
-	struct fcoe_ctlr *fip = &fcoe->ctlr;
+	struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
 	struct fc_frame_header *fh = fc_frame_header_get(fp);
 
 	switch (op) {
@@ -2724,7 +2761,8 @@ static void fcoe_set_port_id(struct fc_lport *lport,
 {
 	struct fcoe_port *port = lport_priv(lport);
 	struct fcoe_interface *fcoe = port->priv;
+	struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
 
 	if (fp && fc_frame_payload_op(fp) == ELS_FLOGI)
-		fcoe_ctlr_recv_flogi(&fcoe->ctlr, lport, fp);
+		fcoe_ctlr_recv_flogi(ctlr, lport, fp);
 }
drivers/scsi/fcoe/fcoe.h +5 -3
index 3c2733a..55fdbdc 100644
@@ -68,7 +68,6 @@ do {                                                            	\
  * @netdev:	      The associated net device
  * @fcoe_packet_type: FCoE packet type
  * @fip_packet_type:  FIP packet type
- * @ctlr:	      The FCoE controller (for FIP)
  * @oem:	      The offload exchange manager for all local port
  *		      instances associated with this port
  * This structure is 1:1 with a net devive.
@@ -79,11 +78,14 @@ struct fcoe_interface {
 	struct net_device  *realdev;
 	struct packet_type fcoe_packet_type;
 	struct packet_type fip_packet_type;
-	struct fcoe_ctlr   ctlr;
 	struct fc_exch_mgr *oem;
 };
 
-#define fcoe_from_ctlr(fip) container_of(fip, struct fcoe_interface, ctlr)
+#define fcoe_to_ctlr(x)						\
+	(struct fcoe_ctlr *)(((struct fcoe_ctlr *)(x)) - 1)
+
+#define fcoe_from_ctlr(x)			\
+	((struct fcoe_interface *)((x) + 1))
 
 /**
  * fcoe_netdev() - Return the net device associated with a local port
include/scsi/libfcoe.h +9 -0
index cfdb55f..69eca4b 100644
@@ -159,6 +159,15 @@ struct fcoe_ctlr {
 };
 
 /**
+ * fcoe_ctlr_priv() - Return the private data from a fcoe_ctlr
+ * @cltr: The fcoe_ctlr whose private data will be returned
+ */
+static inline void *fcoe_ctlr_priv(const struct fcoe_ctlr *ctlr)
+{
+	return (void *)(ctlr + 1);
+}
+
+/**
  * struct fcoe_fcf - Fibre-Channel Forwarder
  * @list:	 list linkage
  * @time:	 system time (jiffies) when an advertisement was last received
#2 lore raw

PATCH v2 2/4 bnx2fc: Allocate fcoe_ctlr with bnx2fc_interface, not as a member

In reply to Robert Love

Currently the fcoe_ctlr associated with an interface is allocated
as a member of struct bnx2fc_interface. This causes problems when attempting to use the new fcoe_sysfs APIs which allow us to allocate the bnx2fc_interface as private data to the fcoe_ctlr_attrs instance. The problem is that libfcoe wants to be able use pointer math to find a fcoe_ctlr's fcoe_ctlr_attrs as well as finding a fcoe_ctlr_attrs' assocated fcoe_ctlr. To do this we need to allocate the fcoe_ctlr_attrs, with private data for the LLD. The private data contains the fcoe_ctlr and it's private data is the bnx2fc_interface.

+------------------+
| fcoe_ctlr_attrs |
+------------------+
| fcoe_ctlr |
+------------------+
| bnx2fc_interface |
+------------------+

This prep work allows us to go from a fcoe_ctlr_attrs instance to its fcoe_ctlr and we can also go from a fcoe_ctlr to its fcoe_ctlr_attrs once the fcoe_sysfs API is in use (later patches in this series).

---
 drivers/scsi/bnx2fc/bnx2fc.h      |    7 ++
 drivers/scsi/bnx2fc/bnx2fc_els.c  |    2 -
 drivers/scsi/bnx2fc/bnx2fc_fcoe.c |  116 ++++++++++++++++++++++++-------------
 drivers/scsi/bnx2fc/bnx2fc_hwi.c  |   39 +++++++-----
 4 files changed, 101 insertions(+), 63 deletions(-)
drivers/scsi/bnx2fc/bnx2fc.h +5 -2
index a4953ef..349bb14 100644
@@ -228,13 +228,16 @@ struct bnx2fc_interface {
 	struct packet_type fip_packet_type;
 	struct workqueue_struct *timer_work_queue;
 	struct kref kref;
-	struct fcoe_ctlr ctlr;
 	u8 vlan_enabled;
 	int vlan_id;
 	bool enabled;
 };
 
-#define bnx2fc_from_ctlr(fip) container_of(fip, struct bnx2fc_interface, ctlr)
+#define bnx2fc_from_ctlr(x)			\
+	((struct bnx2fc_interface *)((x) + 1))
+
+#define bnx2fc_to_ctlr(x)					\
+	((struct fcoe_ctlr *)(((struct fcoe_ctlr *)(x)) - 1))
 
 struct bnx2fc_lport {
 	struct list_head list;
drivers/scsi/bnx2fc/bnx2fc_els.c +1 -1
index ce0ce3e..9a13912 100644
@@ -910,7 +910,7 @@ struct fc_seq *bnx2fc_elsct_send(struct fc_lport *lport, u32 did,
 {
 	struct fcoe_port *port = lport_priv(lport);
 	struct bnx2fc_interface *interface = port->priv;
-	struct fcoe_ctlr *fip = &interface->ctlr;
+	struct fcoe_ctlr *fip = bnx2fc_to_ctlr(interface);
 	struct fc_frame_header *fh = fc_frame_header_get(fp);
 
 	switch (op) {
drivers/scsi/bnx2fc/bnx2fc_fcoe.c +74 -42

397 lines not on this page · raw message

drivers/scsi/bnx2fc/bnx2fc_hwi.c +21 -18
index 1923a25..6aa6508 100644
@@ -167,6 +167,7 @@ int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
 {
 	struct fc_lport *lport = port->lport;
 	struct bnx2fc_interface *interface = port->priv;
+	struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
 	struct bnx2fc_hba *hba = interface->hba;
 	struct kwqe *kwqe_arr[4];
 	struct fcoe_kwqe_conn_offload1 ofld_req1;
@@ -314,13 +315,13 @@ int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
 	ofld_req4.src_mac_addr_mid[1] =  port->data_src_addr[2];
 	ofld_req4.src_mac_addr_hi[0] =  port->data_src_addr[1];
 	ofld_req4.src_mac_addr_hi[1] =  port->data_src_addr[0];
-	ofld_req4.dst_mac_addr_lo[0] =  interface->ctlr.dest_addr[5];
+	ofld_req4.dst_mac_addr_lo[0] =  ctlr->dest_addr[5];
 							/* fcf mac */
-	ofld_req4.dst_mac_addr_lo[1] =  interface->ctlr.dest_addr[4];
-	ofld_req4.dst_mac_addr_mid[0] =  interface->ctlr.dest_addr[3];
-	ofld_req4.dst_mac_addr_mid[1] =  interface->ctlr.dest_addr[2];
-	ofld_req4.dst_mac_addr_hi[0] =  interface->ctlr.dest_addr[1];
-	ofld_req4.dst_mac_addr_hi[1] =  interface->ctlr.dest_addr[0];
+	ofld_req4.dst_mac_addr_lo[1] = ctlr->dest_addr[4];
+	ofld_req4.dst_mac_addr_mid[0] = ctlr->dest_addr[3];
+	ofld_req4.dst_mac_addr_mid[1] = ctlr->dest_addr[2];
+	ofld_req4.dst_mac_addr_hi[0] = ctlr->dest_addr[1];
+	ofld_req4.dst_mac_addr_hi[1] = ctlr->dest_addr[0];
 
 	ofld_req4.lcq_addr_lo = (u32) tgt->lcq_dma;
 	ofld_req4.lcq_addr_hi = (u32)((u64) tgt->lcq_dma >> 32);
@@ -351,6 +352,7 @@ static int bnx2fc_send_session_enable_req(struct fcoe_port *port,
 {
 	struct kwqe *kwqe_arr[2];
 	struct bnx2fc_interface *interface = port->priv;
+	struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
 	struct bnx2fc_hba *hba = interface->hba;
 	struct fcoe_kwqe_conn_enable_disable enbl_req;
 	struct fc_lport *lport = port->lport;
@@ -374,12 +376,12 @@ static int bnx2fc_send_session_enable_req(struct fcoe_port *port,
 	enbl_req.src_mac_addr_hi[1] =  port->data_src_addr[0];
 	memcpy(tgt->src_addr, port->data_src_addr, ETH_ALEN);
 
-	enbl_req.dst_mac_addr_lo[0] =  interface->ctlr.dest_addr[5];
-	enbl_req.dst_mac_addr_lo[1] =  interface->ctlr.dest_addr[4];
-	enbl_req.dst_mac_addr_mid[0] =  interface->ctlr.dest_addr[3];
-	enbl_req.dst_mac_addr_mid[1] =  interface->ctlr.dest_addr[2];
-	enbl_req.dst_mac_addr_hi[0] =  interface->ctlr.dest_addr[1];
-	enbl_req.dst_mac_addr_hi[1] =  interface->ctlr.dest_addr[0];
+	enbl_req.dst_mac_addr_lo[0] =  ctlr->dest_addr[5];
+	enbl_req.dst_mac_addr_lo[1] =  ctlr->dest_addr[4];
+	enbl_req.dst_mac_addr_mid[0] = ctlr->dest_addr[3];
+	enbl_req.dst_mac_addr_mid[1] = ctlr->dest_addr[2];
+	enbl_req.dst_mac_addr_hi[0] = ctlr->dest_addr[1];
+	enbl_req.dst_mac_addr_hi[1] = ctlr->dest_addr[0];
 
 	port_id = fc_host_port_id(lport->host);
 	if (port_id != tgt->sid) {
@@ -419,6 +421,7 @@ int bnx2fc_send_session_disable_req(struct fcoe_port *port,
 				    struct bnx2fc_rport *tgt)
 {
 	struct bnx2fc_interface *interface = port->priv;
+	struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
 	struct bnx2fc_hba *hba = interface->hba;
 	struct fcoe_kwqe_conn_enable_disable disable_req;
 	struct kwqe *kwqe_arr[2];
@@ -440,12 +443,12 @@ int bnx2fc_send_session_disable_req(struct fcoe_port *port,
 	disable_req.src_mac_addr_hi[0] =  tgt->src_addr[1];
 	disable_req.src_mac_addr_hi[1] =  tgt->src_addr[0];
 
-	disable_req.dst_mac_addr_lo[0] =  interface->ctlr.dest_addr[5];
-	disable_req.dst_mac_addr_lo[1] =  interface->ctlr.dest_addr[4];
-	disable_req.dst_mac_addr_mid[0] =  interface->ctlr.dest_addr[3];
-	disable_req.dst_mac_addr_mid[1] =  interface->ctlr.dest_addr[2];
-	disable_req.dst_mac_addr_hi[0] =  interface->ctlr.dest_addr[1];
-	disable_req.dst_mac_addr_hi[1] =  interface->ctlr.dest_addr[0];
+	disable_req.dst_mac_addr_lo[0] =  ctlr->dest_addr[5];
+	disable_req.dst_mac_addr_lo[1] =  ctlr->dest_addr[4];
+	disable_req.dst_mac_addr_mid[0] = ctlr->dest_addr[3];
+	disable_req.dst_mac_addr_mid[1] = ctlr->dest_addr[2];
+	disable_req.dst_mac_addr_hi[0] = ctlr->dest_addr[1];
+	disable_req.dst_mac_addr_hi[1] = ctlr->dest_addr[0];
 
 	port_id = tgt->sid;
 	disable_req.s_id[0] = (port_id & 0x000000FF);
#3 lore raw

PATCH v2 3/4 libfcoe: Add fcoe_sysfs

In reply to Robert Love

This patch adds infrastructure to libfcoe allow LLDs to present FIP (FCoE Initialization Protocol) discovered entities and their attributes to user space via sysfs.

This patch adds the following APIs-

fcoe_ctlr_attrs_add
fcoe_ctlr_attrs_delete
fcoe_fcf_attrs_add
fcoe_fcf_attrs_delete

They allow the LLD to expose the FCoE ENode Controller and any discovered FCFs (Fibre Channel Forwarders, e.g. FCoE switches) to the user. Each of these new devices has their own class so that they are grouped together for easy lookup from a user space application. Each new class has an attribute_group to expose attributes for any created instances. The attributes are-

fcoe_ctlr_attrs
* fcf_dev_loss_tmo
* lesb_link_fail
* lesb_vlink_fail
* lesb_miss_fka
* lesb_symb_err
* lesb_err_block
* lesb_fcs_error

fcoe_fcf_attrs
* fabric_name
* switch_name
* priority
* selected
* fc_map
* vfid
* mac
* fka_peroid
* fabric_state
* dev_loss_tmo

A device loss infrastructre similar to the FC Transport's is also added by this patch. It is nice to have so that a link flapping adapter doesn't continually advance the count used to identify the discovered FCF. FCFs will exist in a "Disconnected" state until either the timer expires or the FCF is rediscovered and becomes "Connected."

This patch generates a few checkpatch.pl WARNINGS that I'm not sure what to do about. They're macros modeled around the FC Transport attribute building macros, which have the same 'feature' where the caller can ommit a cast in the argument list and no cast occurs in the code. I'm not sure how to keep the code condensed while keeping the macros. Any advice would be appreciated.

---
 Documentation/ABI/testing/sysfs-class-fcoe |   77 +++
 drivers/scsi/fcoe/Makefile                 |    2 
 drivers/scsi/fcoe/fcoe_sysfs.c             |  840 ++++++++++++++++++++++++++++
 drivers/scsi/fcoe/fcoe_transport.c         |   13 
 include/scsi/fcoe_sysfs.h                  |  124 ++++
 include/scsi/libfcoe.h                     |    1 
 6 files changed, 1054 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-fcoe
 create mode 100644 drivers/scsi/fcoe/fcoe_sysfs.c
 create mode 100644 include/scsi/fcoe_sysfs.h
Documentation/ABI/testing/sysfs-class-fcoe new file +77 -0
new file mode 100644
index 0000000..e9cd7e9
@@ -0,0 +1,77 @@
+What:		/sys/class/fcoe_ctlr/ctlr_X
+Date:		March 2012
+KernelVersion:	TBD
+Contact:	Robert Love <[email protected]>, [email protected]
+Description:	A class for 'FCoE Controller' instances
+Attributes:
+
+	fcf_dev_loss_tmo: Device loss timeout peroid (see below). Changing
+			  this value will change the dev_loss_tmo for all
+			  FCFs discovered by this controller.
+
+	lesb_link_fail:   Link Error Status Block (LESB) link failure count.
+
+	lesb_vlink_fail:  Link Error Status Block (LESB) virtual link
+			  failure count.
+
+	lesb_miss_fka:    Link Error Status Block (LESB) missed FCoE
+			  Initialization Protocol (FIP) Keep-Alives (FKA).
+
+	lesb_symb_err:    Link Error Status Block (LESB) symbolic error count.
+
+	lesb_err_block:   Link Error Status Block (LESB) block error count.
+
+	lesb_fcs_error:   Link Error Status Block (LESB) Fibre Channel
+			  Serivces error count.
+
+Notes: ctlr_X (global increment starting at 0)
+
+What:		/sys/class/fcoe_fcf/fcf_X
+Date:		March 2012
+KernelVersion:	TBD
+Contact:	Robert Love <[email protected]>, [email protected]
+Description:	A class for 'FCoE FCF' instances. A FCF is a Fibre Channel
+		Forwarder, which is a FCoE switch that can accept FCoE
+		(Ethernet) packets, unpack them, and forward the embedded
+		Fibre Channel frames into a FC fabric. It can also take
+		outbound FC frames and pack them in Ethernet packets to
+		be sent to their destination on the Ethernet segment.
+Attributes:
+
+	fabric_name: Identifies the fabric that the FCF services.
+
+	switch_name: Identifies the FCF.
+
+	priority:    The switch's priority amongst other FCFs on the same
+		     fabric.
+
+	selected:    1 indicates that the switch has been selected for use;
+		     0 indicates that the swich will not be used.
+
+	fc_map:      The Fibre Channel MAP
+
+	vfid:	     The Virtual Fabric ID
+
+	mac:         The FCF's MAC address
+
+	fka_peroid:  The FIP Keep-Alive peroid
+
+	fabric_state: The internal kernel state
+		      "Unknown" - Initialization value
+		      "Disconnected" - No link to the FCF/fabric
+		      "Connected" - Host is connected to the FCF
+		      "Deleted" - FCF is being removed from the system
+
+	dev_loss_tmo: The device loss timeout peroid for this FCF.
+
+Notes: A device loss infrastructre similar to the FC Transport's
+       is present in fcoe_sysfs. It is nice to have so that a
+       link flapping adapter doesn't continually advance the count
+       used to identify the discovered FCF. FCFs will exist in a
+       "Disconnected" state until either the timer expires and the
+       FCF becomes "Deleted" or the FCF is rediscovered and becomes
+       "Connected."
+
+
+Users: The first user of this interface will be the fcoeadm application,
+       which is commonly packaged in the fcoe-utils package.
drivers/scsi/fcoe/Makefile +1 -1
index f6d37d0..aed0f5d 100644
@@ -1,4 +1,4 @@
 obj-$(CONFIG_FCOE) += fcoe.o
 obj-$(CONFIG_LIBFCOE) += libfcoe.o
 
-libfcoe-objs := fcoe_ctlr.o fcoe_transport.o
+libfcoe-objs := fcoe_ctlr.o fcoe_transport.o fcoe_sysfs.o
drivers/scsi/fcoe/fcoe_sysfs.c new file +840 -0

840 lines not on this page · raw message

drivers/scsi/fcoe/fcoe_transport.c +11 -2
index 0897be0..58b6753 100644
@@ -816,9 +816,17 @@ out_nodev:
  */
 static int __init libfcoe_init(void)
 {
-	fcoe_transport_init();
+	int rc = 0;
 
-	return 0;
+	rc = fcoe_transport_init();
+	if (rc)
+		return rc;
+
+	rc = fcoe_sysfs_setup();
+	if (rc)
+		fcoe_transport_exit();
+
+	return rc;
 }
 module_init(libfcoe_init);
 
@@ -827,6 +835,7 @@ module_init(libfcoe_init);
  */
 static void __exit libfcoe_exit(void)
 {
+	fcoe_sysfs_teardown();
 	fcoe_transport_exit();
 }
 module_exit(libfcoe_exit);
include/scsi/fcoe_sysfs.h new file +124 -0

124 lines not on this page · raw message

include/scsi/libfcoe.h +1 -0
index 69eca4b..7b93f21 100644
@@ -29,6 +29,7 @@
 #include <linux/random.h>
 #include <scsi/fc/fc_fcoe.h>
 #include <scsi/libfc.h>
+#include <scsi/fcoe_sysfs.h>
 
 #define FCOE_MAX_CMD_LEN	16	/* Supported CDB length */
 
#4 lore raw

Re: [PATCH v2 3/4] libfcoe: Add fcoe_sysfs

Quoted 10 lines · Robert Love

This patch adds infrastructure to libfcoe allow LLDs to present FIP (FCoE Initialization Protocol) discovered entities and their attributes to user space via sysfs.

This patch adds the following APIs-

fcoe_ctlr_attrs_add
fcoe_ctlr_attrs_delete
fcoe_fcf_attrs_add
fcoe_fcf_attrs_delete

Maybe I'm a bit confused, but "traditionally" attrs are sysfs attribute files, right? These need to be created _before_ the device is exposed to userspace through a uevent call. Having a separate function for these is usually too late, unless your fcoe core delays the uevent call until after these are called?

Who would make these function calls, individual drivers? Why doesn't the core do this for all fcoe devices?

Quoted 64 lines

They allow the LLD to expose the FCoE ENode Controller and any discovered FCFs (Fibre Channel Forwarders, e.g. FCoE switches) to the user. Each of these new devices has their own class so that they are grouped together for easy lookup from a user space application. Each new class has an attribute_group to expose attributes for any created instances. The attributes are-

fcoe_ctlr_attrs
* fcf_dev_loss_tmo
* lesb_link_fail
* lesb_vlink_fail
* lesb_miss_fka
* lesb_symb_err
* lesb_err_block
* lesb_fcs_error

fcoe_fcf_attrs
* fabric_name
* switch_name
* priority
* selected
* fc_map
* vfid
* mac
* fka_peroid
* fabric_state
* dev_loss_tmo

A device loss infrastructre similar to the FC Transport's is also added by this patch. It is nice to have so that a link flapping adapter doesn't continually advance the count used to identify the discovered FCF. FCFs will exist in a "Disconnected" state until either the timer expires or the FCF is rediscovered and becomes "Connected."

This patch generates a few checkpatch.pl WARNINGS that I'm not sure what to do about. They're macros modeled around the FC Transport attribute building macros, which have the same 'feature' where the caller can ommit a cast in the argument list and no cast occurs in the code. I'm not sure how to keep the code condensed while keeping the macros. Any advice would be appreciated.

---
 Documentation/ABI/testing/sysfs-class-fcoe |   77 +++
 drivers/scsi/fcoe/Makefile                 |    2 
 drivers/scsi/fcoe/fcoe_sysfs.c             |  840 ++++++++++++++++++++++++++++
 drivers/scsi/fcoe/fcoe_transport.c         |   13 
 include/scsi/fcoe_sysfs.h                  |  124 ++++
 include/scsi/libfcoe.h                     |    1 
 6 files changed, 1054 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-fcoe
 create mode 100644 drivers/scsi/fcoe/fcoe_sysfs.c
 create mode 100644 include/scsi/fcoe_sysfs.h
Documentation/ABI/testing/sysfs-class-fcoe new file +0 -0
new file mode 100644
index 0000000..e9cd7e9

Documentation/ABI/testing/sysfs-class-fcoe line 1

Quoted 1 line
Documentation/ABI/testing/sysfs-class-fcoe new file +1 -0
@@ -0,0 +1,77 @@
+What:		/sys/class/fcoe_ctlr/ctlr_X

We are really trying to stay away from new classes being created. Why can't this be a bus and have the devices attach to that instead? You can have one bus with both types of "devices" attached to it, making things a bit simpler in the end.

Documentation/ABI/testing/sysfs-class-fcoe line 3

Quoted 2 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +2 -0
+static atomic_t ctlr_num;
+static atomic_t fcf_num;

I don't think you want to use an atomic variable here, see below for why.

Quoted 14 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +14 -0
+/**
+ * fcoe_ctlr_attrs_add() - Add a FIP ctlr to sysfs
+ * @parent:    The parent device to which the fcoe_ctlr instance
+ *             should be attached
+ * @f:         The LLD's FCoE sysfs function template pointer
+ * @priv_size: Size to be allocated with the fcoe_ctlr_attrs for the LLD
+ *
+ * This routine allocates a FIP ctlr object with some additional memory
+ * for the LLD. The FIP ctlr is initialized, added to sysfs and then
+ * attributes are added to it.
+ */
+struct fcoe_ctlr_attrs *fcoe_ctlr_attrs_add(struct device *parent,
+				    struct fcoe_sysfs_function_template *f,
+				    int priv_size)

Documentation/ABI/testing/sysfs-class-fcoe line 27

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +10 -0
+{
+	struct fcoe_ctlr_attrs *ctlr;
+	int error = 0;
+
+	ctlr = kzalloc(sizeof(struct fcoe_ctlr_attrs) + priv_size,
+		       GFP_KERNEL);
+	if (!ctlr)
+		goto out;
+
+	ctlr->id = atomic_inc_return(&ctlr_num) - 1;

Does this work properly over the long run? Shouldn't you use the idr interface instead, to keep holes from showing up?

Documentation/ABI/testing/sysfs-class-fcoe line 32

Quoted 5 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +5 -0
+	ctlr->f = f;
+	INIT_LIST_HEAD(&ctlr->fcfs);
+	mutex_init(&ctlr->lock);
+	device_initialize(&ctlr->dev);
+	ctlr->dev.parent = get_device(parent);

I thought you dropped these get_device() calls on the parent? The driver core handles this for you, please don't do it here, it's not needed.

Quoted 23 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +23 -0
+	ctlr->dev.class = &fcoe_ctlr_class;
+
+	ctlr->fcf_dev_loss_tmo = fcoe_fcf_dev_loss_tmo;
+
+	snprintf(ctlr->work_q_name, sizeof(ctlr->work_q_name),
+		 "ctlr_wq_%d", ctlr->id);
+	ctlr->work_q = create_singlethread_workqueue(
+		ctlr->work_q_name);
+	if (!ctlr->work_q)
+		goto out_del;
+
+	snprintf(ctlr->devloss_work_q_name,
+		 sizeof(ctlr->devloss_work_q_name),
+		 "ctlr_dl_wq_%d", ctlr->id);
+	ctlr->devloss_work_q = create_singlethread_workqueue(
+		ctlr->devloss_work_q_name);
+	if (!ctlr->devloss_work_q)
+		goto out_del_q;
+
+	dev_set_name(&ctlr->dev, "ctlr_%d", ctlr->id);
+	error = device_add(&ctlr->dev);
+	if (error)
+		goto out_del_q2;

Documentation/ABI/testing/sysfs-class-fcoe line 65

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +10 -0
+
+	error = sysfs_create_group(&ctlr->dev.kobj,
+				   &fcoe_ctlr_attribute_group);
+	if (error)
+		goto out_del_dev;
+
+	error = sysfs_create_group(&ctlr->dev.kobj,
+				   &fcoe_ctlr_lesb_attribute_group);
+	if (error)
+		goto out_del_dev;

You just raced userspace by creating your attributes after device_add() causing lots of problems in the longrun. Why not make these default attribute groups that the driver core automatically creates for you properly? That also makes your error path simpler, as well as your cleanup path for when this device goes away.

Quoted 7 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +7 -0
+	return ctlr;
+
+out_del_dev:
+	device_del(&ctlr->dev);
+out_del_q2:
+	destroy_workqueue(ctlr->devloss_work_q);
+	ctlr->devloss_work_q = NULL;

Documentation/ABI/testing/sysfs-class-fcoe

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +10 -0
+out_del_q:
+	destroy_workqueue(ctlr->work_q);
+	ctlr->work_q = NULL;
+out_del:
+	put_device(parent);
+	kfree(ctlr);
+out:
+	return NULL;
+}
+EXPORT_SYMBOL(fcoe_ctlr_attrs_add);

EXPORT_SYMBOL_GPL() for this, and other exports?

Quoted 26 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +26 -0
+/**
+ * fcoe_fcf_attrs_add() - Add a FCoE sysfs fcoe_fcf_attrs to the system
+ * @ctlr:    The fcoe_ctlr_attrs that will be the fcoe_fcf_attrs parent
+ * @new_fcf: A temporary FCF used for lookups on the current list of fcfs
+ *
+ * Expects to be called with the ctlr->lock held
+ */
+struct fcoe_fcf_attrs *fcoe_fcf_attrs_add(struct fcoe_ctlr_attrs *ctlr,
+					  struct fcoe_fcf_attrs *new_fcf)
+{
+	struct fcoe_fcf_attrs *fcf;
+	int error = 0;
+
+	list_for_each_entry(fcf, &ctlr->fcfs, peers) {
+		if (fcoe_fcf_attrs_match(new_fcf, fcf)) {
+			if (fcf->state == FCOE_FCF_STATE_CONNECTED)
+				return fcf;
+
+			fcf->state = FCOE_FCF_STATE_CONNECTED;
+
+			if (!cancel_delayed_work(&fcf->dev_loss_work))
+				fcoe_ctlr_attrs_flush_devloss(ctlr);
+
+			return fcf;
+		}
+	}

Documentation/ABI/testing/sysfs-class-fcoe

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +10 -0
+
+	fcf = kzalloc(sizeof(struct fcoe_fcf_attrs), GFP_ATOMIC);
+	if (unlikely(!fcf))
+		goto out;
+
+	INIT_WORK(&fcf->delete_work, fcoe_fcf_attrs_final_delete);
+	INIT_DELAYED_WORK(&fcf->dev_loss_work, fip_timeout_deleted_fcf);
+
+	device_initialize(&fcf->dev);
+	fcf->dev.parent = get_device(&ctlr->dev);

Same thing with the get_device() call here.

Documentation/ABI/testing/sysfs-class-fcoe

Quoted 2 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +2 -0
+	fcf->dev.class = &fcoe_fcf_class;
+	fcf->id = atomic_inc_return(&fcf_num) - 1;

And the id.

Quoted 13 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +13 -0
+	fcf->state = FCOE_FCF_STATE_UNKNOWN;
+
+	fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
+
+	dev_set_name(&fcf->dev, "fcf_%d", fcf->id);
+
+	fcf->fabric_name = new_fcf->fabric_name;
+	fcf->switch_name = new_fcf->switch_name;
+	fcf->fc_map = new_fcf->fc_map;
+	fcf->vfid = new_fcf->vfid;
+	memcpy(fcf->mac, new_fcf->mac, ETH_ALEN);
+	fcf->priority = new_fcf->priority;
+	fcf->fka_period = new_fcf->fka_period;

Documentation/ABI/testing/sysfs-class-fcoe

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +10 -0
+	fcf->selected = new_fcf->selected;
+
+	error = device_add(&fcf->dev);
+	if (error)
+		goto out_del;
+
+	error = sysfs_create_group(&fcf->dev.kobj,
+				   &fcoe_fcf_attribute_group);
+	if (error)
+		goto out_del_dev;

Same thing here, you just raced userspace.

thanks,

greg k-h

#5 lore raw

Re: [PATCH v2 3/4] libfcoe: Add fcoe_sysfs

Quoted 11 lines · Greg KH
Quoted 10 lines · Robert Love

This patch adds infrastructure to libfcoe allow LLDs to present FIP (FCoE Initialization Protocol) discovered entities and their attributes to user space via sysfs.

This patch adds the following APIs-

fcoe_ctlr_attrs_add
fcoe_ctlr_attrs_delete
fcoe_fcf_attrs_add
fcoe_fcf_attrs_delete

Quoted 8 lines

Maybe I'm a bit confused, but "traditionally" attrs are sysfs attribute files, right? These need to be created _before_ the device is exposed to userspace through a uevent call. Having a separate function for these is usually too late, unless your fcoe core delays the uevent call until after these are called?

Who would make these function calls, individual drivers? Why doesn't the core do this for all fcoe devices?

I think my function names are misleading... These aren't explicitly adding attributes to a device, they're adding and removing the devices to the system. The fcoe core (libfcoe) already has 'struct fcoe_ctlr' and 'struct fcoe_fcf' for protocol processing, so the structures that I use (which are 1:1 with those protocol structures) are named fcoe_*_attrs. They're the structures that are only used to store the values for the sysfs attributes, so that they can be read when queried by the 'show' handlers.

With this patch series this new API is only used by the fcoe core (libfcoe). Traditional HBAs that have the FCoE capability do not currently use libfcoe. Only the vendors with SW FCoE solutions use it (Intel, Broadcom, Cisco) and they get this feature simply because they use libfcoe for the protocol processing. libfcoe is the only user now, but I believe that my design would allow for HBA/CNA cards to use this new presentation layer without using the rest of libfcoe.

I debated whether I should just re-use the "protocol structures" or create these new "attribute structures." I decided to have new structures so that the HBA/CNAs that don't use libfcoe could just deal with structures for the presentation and didn't have to deal with structures that had members that libfcoe used internally. This is how the FC Transport (scsi_transport_fc.c) does things. It has its own 'struct fc_rport' that is used by many drivers, but only for presentation. Each driver has it's own "protocol structure" for rports (remote ports) that will be 1:1 with the FC Transports "attribute structure" fc_rport.

Quoted 58 lines
Quoted 58 lines

They allow the LLD to expose the FCoE ENode Controller and any discovered FCFs (Fibre Channel Forwarders, e.g. FCoE switches) to the user. Each of these new devices has their own class so that they are grouped together for easy lookup from a user space application. Each new class has an attribute_group to expose attributes for any created instances. The attributes are-

fcoe_ctlr_attrs
* fcf_dev_loss_tmo
* lesb_link_fail
* lesb_vlink_fail
* lesb_miss_fka
* lesb_symb_err
* lesb_err_block
* lesb_fcs_error

fcoe_fcf_attrs
* fabric_name
* switch_name
* priority
* selected
* fc_map
* vfid
* mac
* fka_peroid
* fabric_state
* dev_loss_tmo

A device loss infrastructre similar to the FC Transport's is also added by this patch. It is nice to have so that a link flapping adapter doesn't continually advance the count used to identify the discovered FCF. FCFs will exist in a "Disconnected" state until either the timer expires or the FCF is rediscovered and becomes "Connected."

This patch generates a few checkpatch.pl WARNINGS that I'm not sure what to do about. They're macros modeled around the FC Transport attribute building macros, which have the same 'feature' where the caller can ommit a cast in the argument list and no cast occurs in the code. I'm not sure how to keep the code condensed while keeping the macros. Any advice would be appreciated.

---
  Documentation/ABI/testing/sysfs-class-fcoe |   77 +++
  drivers/scsi/fcoe/Makefile                 |    2
  drivers/scsi/fcoe/fcoe_sysfs.c             |  840 ++++++++++++++++++++++++++++
  drivers/scsi/fcoe/fcoe_transport.c         |   13
  include/scsi/fcoe_sysfs.h                  |  124 ++++
  include/scsi/libfcoe.h                     |    1
  6 files changed, 1054 insertions(+), 3 deletions(-)

create mode 100644 Documentation/ABI/testing/sysfs-class-fcoe create mode 100644 drivers/scsi/fcoe/fcoe_sysfs.c create mode 100644 include/scsi/fcoe_sysfs.h

Quoted 11 lines

Documentation/ABI/testing/sysfs-class-fcoe line 1

Quoted 7 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +1 -0
new file mode 100644
index 0000000..e9cd7e9
@@ -0,0 +1,77 @@
+What:		/sys/class/fcoe_ctlr/ctlr_X

We are really trying to stay away from new classes being created. Why can't this be a bus and have the devices attach to that instead? You can have one bus with both types of "devices" attached to it, making things a bit simpler in the end.

I did have a series about a year ago, when this series was overly grandiose, and I was using a bus. I don't have a reason for using classes vs. a bus other than the FC Transport, which this code is heavily modeled after, uses classes. If I remember correctly my fcoe_fcf_attrs and fcoe_ctlr_attrs would become the drivers for the bus and devices would become instances of that driver on the bus. I'm sure I'm butchering the terminology...

Quoted 23 lines

Documentation/ABI/testing/sysfs-class-fcoe line 3

Quoted 2 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +2 -0
+static atomic_t ctlr_num;
+static atomic_t fcf_num;

I don't think you want to use an atomic variable here, see below for why.

Quoted 18 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +18 -0
+/**
+ * fcoe_ctlr_attrs_add() - Add a FIP ctlr to sysfs
+ * @parent:    The parent device to which the fcoe_ctlr instance
+ *             should be attached
+ * @f:         The LLD's FCoE sysfs function template pointer
+ * @priv_size: Size to be allocated with the fcoe_ctlr_attrs for the LLD
+ *
+ * This routine allocates a FIP ctlr object with some additional memory
+ * for the LLD. The FIP ctlr is initialized, added to sysfs and then
+ * attributes are added to it.
+ */
+struct fcoe_ctlr_attrs *fcoe_ctlr_attrs_add(struct device *parent,
+				    struct fcoe_sysfs_function_template *f,
+				    int priv_size)
+{
+	struct fcoe_ctlr_attrs *ctlr;
+	int error = 0;
+
Quoted 8 lines

Documentation/ABI/testing/sysfs-class-fcoe line 27

Quoted 6 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +6 -0
+	ctlr = kzalloc(sizeof(struct fcoe_ctlr_attrs) + priv_size,
+		       GFP_KERNEL);
+	if (!ctlr)
+		goto out;
+
+	ctlr->id = atomic_inc_return(&ctlr_num) - 1;

Does this work properly over the long run? Shouldn't you use the idr interface instead, to keep holes from showing up?

I'm not familiar wit the idr interface. I'll ask around and fix this.

Quoted 8 lines

Documentation/ABI/testing/sysfs-class-fcoe line 32

Quoted 5 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +5 -0
+	ctlr->f = f;
+	INIT_LIST_HEAD(&ctlr->fcfs);
+	mutex_init(&ctlr->lock);
+	device_initialize(&ctlr->dev);
+	ctlr->dev.parent = get_device(parent);

I thought you dropped these get_device() calls on the parent? The driver core handles this for you, please don't do it here, it's not needed.

How would the driver core know what this device's parent is? This is the only place I do that assignment.

Quoted 30 lines
Quoted 30 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +30 -0
+	ctlr->dev.class =&fcoe_ctlr_class;
+
+	ctlr->fcf_dev_loss_tmo = fcoe_fcf_dev_loss_tmo;
+
+	snprintf(ctlr->work_q_name, sizeof(ctlr->work_q_name),
+		 "ctlr_wq_%d", ctlr->id);
+	ctlr->work_q = create_singlethread_workqueue(
+		ctlr->work_q_name);
+	if (!ctlr->work_q)
+		goto out_del;
+
+	snprintf(ctlr->devloss_work_q_name,
+		 sizeof(ctlr->devloss_work_q_name),
+		 "ctlr_dl_wq_%d", ctlr->id);
+	ctlr->devloss_work_q = create_singlethread_workqueue(
+		ctlr->devloss_work_q_name);
+	if (!ctlr->devloss_work_q)
+		goto out_del_q;
+
+	dev_set_name(&ctlr->dev, "ctlr_%d", ctlr->id);
+	error = device_add(&ctlr->dev);
+	if (error)
+		goto out_del_q2;
+
+	error = sysfs_create_group(&ctlr->dev.kobj,
+				&fcoe_ctlr_attribute_group);
+	if (error)
+		goto out_del_dev;
+
+	error = sysfs_create_group(&ctlr->dev.kobj,
Quoted 8 lines

Documentation/ABI/testing/sysfs-class-fcoe line 65

Quoted 3 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +3 -0
+				&fcoe_ctlr_lesb_attribute_group);
+	if (error)
+		goto out_del_dev;

You just raced userspace by creating your attributes after device_add() causing lots of problems in the longrun. Why not make these default attribute groups that the driver core automatically creates for you properly? That also makes your error path simpler, as well as your cleanup path for when this device goes away.

Got it, will fix and re-post.

Quoted 85 lines
Quoted 7 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +7 -0
+	return ctlr;
+
+out_del_dev:
+	device_del(&ctlr->dev);
+out_del_q2:
+	destroy_workqueue(ctlr->devloss_work_q);
+	ctlr->devloss_work_q = NULL;

Documentation/ABI/testing/sysfs-class-fcoe

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +10 -0
+out_del_q:
+	destroy_workqueue(ctlr->work_q);
+	ctlr->work_q = NULL;
+out_del:
+	put_device(parent);
+	kfree(ctlr);
+out:
+	return NULL;
+}
+EXPORT_SYMBOL(fcoe_ctlr_attrs_add);

EXPORT_SYMBOL_GPL() for this, and other exports?

Quoted 26 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +26 -0
+/**
+ * fcoe_fcf_attrs_add() - Add a FCoE sysfs fcoe_fcf_attrs to the system
+ * @ctlr:    The fcoe_ctlr_attrs that will be the fcoe_fcf_attrs parent
+ * @new_fcf: A temporary FCF used for lookups on the current list of fcfs
+ *
+ * Expects to be called with the ctlr->lock held
+ */
+struct fcoe_fcf_attrs *fcoe_fcf_attrs_add(struct fcoe_ctlr_attrs *ctlr,
+					  struct fcoe_fcf_attrs *new_fcf)
+{
+	struct fcoe_fcf_attrs *fcf;
+	int error = 0;
+
+	list_for_each_entry(fcf,&ctlr->fcfs, peers) {
+		if (fcoe_fcf_attrs_match(new_fcf, fcf)) {
+			if (fcf->state == FCOE_FCF_STATE_CONNECTED)
+				return fcf;
+
+			fcf->state = FCOE_FCF_STATE_CONNECTED;
+
+			if (!cancel_delayed_work(&fcf->dev_loss_work))
+				fcoe_ctlr_attrs_flush_devloss(ctlr);
+
+			return fcf;
+		}
+	}

Documentation/ABI/testing/sysfs-class-fcoe

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +10 -0
+
+	fcf = kzalloc(sizeof(struct fcoe_fcf_attrs), GFP_ATOMIC);
+	if (unlikely(!fcf))
+		goto out;
+
+	INIT_WORK(&fcf->delete_work, fcoe_fcf_attrs_final_delete);
+	INIT_DELAYED_WORK(&fcf->dev_loss_work, fip_timeout_deleted_fcf);
+
+	device_initialize(&fcf->dev);
+	fcf->dev.parent = get_device(&ctlr->dev);

Same thing with the get_device() call here.

Documentation/ABI/testing/sysfs-class-fcoe

Quoted 2 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +2 -0
+	fcf->dev.class =&fcoe_fcf_class;
+	fcf->id = atomic_inc_return(&fcf_num) - 1;

And the id.

Quoted 13 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +13 -0
+	fcf->state = FCOE_FCF_STATE_UNKNOWN;
+
+	fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
+
+	dev_set_name(&fcf->dev, "fcf_%d", fcf->id);
+
+	fcf->fabric_name = new_fcf->fabric_name;
+	fcf->switch_name = new_fcf->switch_name;
+	fcf->fc_map = new_fcf->fc_map;
+	fcf->vfid = new_fcf->vfid;
+	memcpy(fcf->mac, new_fcf->mac, ETH_ALEN);
+	fcf->priority = new_fcf->priority;
+	fcf->fka_period = new_fcf->fka_period;

Documentation/ABI/testing/sysfs-class-fcoe

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +10 -0
+	fcf->selected = new_fcf->selected;
+
+	error = device_add(&fcf->dev);
+	if (error)
+		goto out_del;
+
+	error = sysfs_create_group(&fcf->dev.kobj,
+				&fcoe_fcf_attribute_group);
+	if (error)
+		goto out_del_dev;

Same thing here, you just raced userspace.

Quoted 3 lines

thanks,

greg k-h

Thanks for reviewing this Greg! I'll address your comments and re-post.

//Rob

maintainer
#6 lore raw

Re: [PATCH v2 3/4] libfcoe: Add fcoe_sysfs

Quoted 7 lines · Robert W
Quoted 2 lines
Quoted 1 line

+ ctlr->id = atomic_inc_return(&ctlr_num) - 1;

Does this work properly over the long run? Shouldn't you use the

idr

Quoted 1 line

interface instead, to keep holes from showing up?

I'm not familiar wit the idr interface. I'll ask around and fix this.

The rule of thumb we've been using for idr in SCSI is that we don't bother with it unless the name space is constrained. So for sd<x> we use it because we have a limited device space to fill (constrained by minor numbers) for target<n> we just use an incrementing counter because <n> is unconstrained.

James

#7 lore raw

Re: [PATCH v2 3/4] libfcoe: Add fcoe_sysfs

In reply to Love, Robert W
Quoted 11 lines · Robert W
Quoted 8 lines

drivers/scsi/fcoe/fcoe_sysfs.c line 529

Quoted 5 lines
drivers/scsi/fcoe/fcoe_sysfs.c new file +5 -0
+	ctlr->f = f;
+	INIT_LIST_HEAD(&ctlr->fcfs);
+	mutex_init(&ctlr->lock);
+	device_initialize(&ctlr->dev);
+	ctlr->dev.parent = get_device(parent);

I thought you dropped these get_device() calls on the parent? The driver core handles this for you, please don't do it here, it's not needed.

How would the driver core know what this device's parent is? This is the only place I do that assignment.

I'm not saying that assigning the parent is wrong, I'm saying you don't need to grab the reference to the parent here.

The code should just be:

	ctrl->dev.parent = parent;

When you register the device, the parent will be properly reference counted.

thanks,

greg k-h

#8 lore raw

Re: [PATCH v2 3/4] libfcoe: Add fcoe_sysfs

In reply to Greg KH
Quoted 1 line · Greg KH

On Fri, Mar 16, 2012 at 12:36:56PM -0700, Robert Love wrote:

<snip>

Quoted 11 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +1 -0
new file mode 100644
index 0000000..e9cd7e9
@@ -0,0 +1,77 @@
+What:		/sys/class/fcoe_ctlr/ctlr_X

We are really trying to stay away from new classes being created. Why can't this be a bus and have the devices attach to that instead? You can have one bus with both types of "devices" attached to it, making things a bit simpler in the end.

<snip>

Quoted 14 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +14 -0
+	dev_set_name(&ctlr->dev, "ctlr_%d", ctlr->id);
+	error = device_add(&ctlr->dev);
+	if (error)
+		goto out_del_q2;
+
+	error = sysfs_create_group(&ctlr->dev.kobj,
+				&fcoe_ctlr_attribute_group);
+	if (error)
+		goto out_del_dev;
+
+	error = sysfs_create_group(&ctlr->dev.kobj,
+				&fcoe_ctlr_lesb_attribute_group);
+	if (error)
+		goto out_del_dev;
Quoted 6 lines

You just raced userspace by creating your attributes after device_add() causing lots of problems in the longrun. Why not make these default attribute groups that the driver core automatically creates for you properly? That also makes your error path simpler, as well as your cleanup path for when this device goes away.

Hi Greg. I have a local series that addresses most of the comments you've made. I have a question about the above two requests.

I've converted my series to create a 'fcoe bus' and now instances of the 'fcoe_ctlr' and 'fcoe_fcf' are on the 'fcoe bus.' I did not create any drivers for the bus; I'm simply adding devices with their device pointer set to my 'fcoe bus' (dev->bus = &fcoe_bus_type) so that these devices are grouped under /sys/bus/fcoe/. This change results in the following, which I think is what you want.

[root@bubba ~]# ls -l /sys/bus/fcoe/drivers total 0
[root@bubba ~]# ls -l /sys/bus/fcoe/devices/ total 0
lrwxrwxrwx 1 root root 0 Mar 19 18:20 ctlr_0 -> ../../../devices/virtual/net/eth4.172-fcoe/ctlr_0 lrwxrwxrwx 1 root root 0 Mar 19 18:20 fcf_0 -> ../../../devices/virtual/net/eth4.172-fcoe/ctlr_0/fcf_0

Is there a way for me to make default attribute groups for each of these device types, as you suggest, without having a 'fcoe_ctlr' driver and a 'fcoe_fcf' driver, or does your suggestion imply that I should be creating drivers for these two types?

I think I'm limited to having default attributes for any device on the 'fcoe bus,' which is not what I want because my fcoe_fcf and fcoe_ctlr devices do not share attributes. Or to create a drivers which have default attribute groups and therefore the core will create attributes as devices are matched with their drivers. Since I'm dealing with a 'subsystem bus' and not a real bus, I'm not sure if it's appropriate for me to be creating virtual subsystem drivers...

Thanks, //Rob

#9 lore raw

Re: [PATCH v2 3/4] libfcoe: Add fcoe_sysfs

Quoted 50 lines · Robert W
Quoted 1 line · Greg KH

On Fri, Mar 16, 2012 at 12:36:56PM -0700, Robert Love wrote:

<snip>

Quoted 11 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +1 -0
new file mode 100644
index 0000000..e9cd7e9
@@ -0,0 +1,77 @@
+What:		/sys/class/fcoe_ctlr/ctlr_X

We are really trying to stay away from new classes being created. Why can't this be a bus and have the devices attach to that instead? You can have one bus with both types of "devices" attached to it, making things a bit simpler in the end.

<snip>

Quoted 14 lines
Documentation/ABI/testing/sysfs-class-fcoe new file +14 -0
+	dev_set_name(&ctlr->dev, "ctlr_%d", ctlr->id);
+	error = device_add(&ctlr->dev);
+	if (error)
+		goto out_del_q2;
+
+	error = sysfs_create_group(&ctlr->dev.kobj,
+				&fcoe_ctlr_attribute_group);
+	if (error)
+		goto out_del_dev;
+
+	error = sysfs_create_group(&ctlr->dev.kobj,
+				&fcoe_ctlr_lesb_attribute_group);
+	if (error)
+		goto out_del_dev;
Quoted 6 lines

You just raced userspace by creating your attributes after device_add() causing lots of problems in the longrun. Why not make these default attribute groups that the driver core automatically creates for you properly? That also makes your error path simpler, as well as your cleanup path for when this device goes away.

Hi Greg. I have a local series that addresses most of the comments you've made. I have a question about the above two requests.

I've converted my series to create a 'fcoe bus' and now instances of the 'fcoe_ctlr' and 'fcoe_fcf' are on the 'fcoe bus.' I did not create any drivers for the bus; I'm simply adding devices with their device pointer set to my 'fcoe bus' (dev->bus = &fcoe_bus_type) so that these devices are grouped under /sys/bus/fcoe/. This change results in the following, which I think is what you want.

Quoted 8 lines

[root@bubba ~]# ls -l /sys/bus/fcoe/drivers total 0
[root@bubba ~]# ls -l /sys/bus/fcoe/devices/ total 0
lrwxrwxrwx 1 root root 0 Mar 19 18:20 ctlr_0 -> ../../../devices/virtual/net/eth4.172-fcoe/ctlr_0 lrwxrwxrwx 1 root root 0 Mar 19 18:20 fcf_0 -> ../../../devices/virtual/net/eth4.172-fcoe/ctlr_0/fcf_0

Looks good to me.

Quoted 4 lines

Is there a way for me to make default attribute groups for each of these device types, as you suggest, without having a 'fcoe_ctlr' driver and a 'fcoe_fcf' driver, or does your suggestion imply that I should be creating drivers for these two types?

Yes you can do this. I think you just need to set a different type for the device, but I can't recall at the moment. Look at the sysdev code in 3.3 for examples of how to set up "interface" types, I think that's what you want to do here. It's what we do in the USB code.

Quoted 7 lines

I think I'm limited to having default attributes for any device on the 'fcoe bus,' which is not what I want because my fcoe_fcf and fcoe_ctlr devices do not share attributes. Or to create a drivers which have default attribute groups and therefore the core will create attributes as devices are matched with their drivers. Since I'm dealing with a 'subsystem bus' and not a real bus, I'm not sure if it's appropriate for me to be creating virtual subsystem drivers...

You can always, at registration time, dynamically determine which default attributes you enable or not, based on the type of the device. The driver core will callback to the attributes themselves, if you set it up properly. Use the is_visible() callback in the attribute group for this (search the kernel for lots of usages of this for examples.)

Hope this helps,

greg k-h

#10 lore raw

PATCH v2 4/4 fcoe, bnx2fc, libfcoe: SW FCoE and bnx2fc use FCoE Syfs

In reply to Robert Love

This patch has the SW FCoE driver and the bnx2fc driver make use of the new fcoe_sysfs API added earlier in this patch series.

After this patch a fcoe_ctlr_attrs is allocated with private data in this order.

+-----------------+   +------------------+
| fcoe_ctlr_attrs |   | fcoe_ctlr_attrs  |
+-----------------+   +------------------+
| fcoe_ctlr       |   | fcoe_ctlr        |
+-----------------+   +------------------+
| fcoe_interface  |   | bnx2fc_interface |
+-----------------+   +------------------+

libfcoe also takes part in this new model since it discovers and manages fcoe_fcf instances. The memory allocation is different for FCFs. I didn't want to impact libfcoe's fcoe_fcf processing, so this patch creates fcoe_fcf_attrs instances for each discovered fcoe_fcf. The two are paired using a (void * priv) member of the fcoe_ctlr_attrs. This allows libfcoe to continue maintaining its list of fcoe_fcf instances and simply attaches and detaches them from existing or new fcoe_fcf_attrs instances.

---
 drivers/scsi/bnx2fc/bnx2fc_fcoe.c |   63 ++++++++++++++-
 drivers/scsi/fcoe/fcoe.c          |   70 +++++++++++++++-
 drivers/scsi/fcoe/fcoe_ctlr.c     |  159 ++++++++++++++++++++++++++++++++++---
 include/scsi/libfcoe.h            |   17 ++++
 4 files changed, 285 insertions(+), 24 deletions(-)
drivers/scsi/bnx2fc/bnx2fc_fcoe.c +59 -4
index 90aaaf7..89547f6 100644
@@ -54,6 +54,7 @@ static struct cnic_ulp_ops bnx2fc_cnic_cb;
 static struct libfc_function_template bnx2fc_libfc_fcn_templ;
 static struct scsi_host_template bnx2fc_shost_template;
 static struct fc_function_template bnx2fc_transport_function;
+static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
 static struct fc_function_template bnx2fc_vport_xport_function;
 static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode);
 static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
@@ -88,6 +89,7 @@ static void bnx2fc_port_shutdown(struct fc_lport *lport);
 static void bnx2fc_stop(struct bnx2fc_interface *interface);
 static int __init bnx2fc_mod_init(void);
 static void __exit bnx2fc_mod_exit(void);
+static void bnx2fc_ctlr_get_lesb(struct fcoe_ctlr_attrs *ctlr_attrs);
 
 unsigned int bnx2fc_debug_level;
 module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
@@ -118,6 +120,41 @@ static void bnx2fc_get_lesb(struct fc_lport *lport,
 	__fcoe_get_lesb(lport, fc_lesb, netdev);
 }
 
+static void bnx2fc_ctlr_get_lesb(struct fcoe_ctlr_attrs *ctlr_attrs)
+{
+	struct fcoe_ctlr *fip = fcoe_ctlr_attrs_priv(ctlr_attrs);
+	struct net_device *netdev = bnx2fc_netdev(fip->lp);
+	struct fcoe_fc_els_lesb *fcoe_lesb;
+	struct fc_els_lesb fc_lesb;
+
+	__fcoe_get_lesb(fip->lp, &fc_lesb, netdev);
+	fcoe_lesb = (struct fcoe_fc_els_lesb *)(&fc_lesb);
+
+	ctlr_attrs->lesb.lesb_link_fail =
+		ntohl(fcoe_lesb->lesb_link_fail);
+	ctlr_attrs->lesb.lesb_vlink_fail =
+		ntohl(fcoe_lesb->lesb_vlink_fail);
+	ctlr_attrs->lesb.lesb_miss_fka =
+		ntohl(fcoe_lesb->lesb_miss_fka);
+	ctlr_attrs->lesb.lesb_symb_err =
+		ntohl(fcoe_lesb->lesb_symb_err);
+	ctlr_attrs->lesb.lesb_err_block =
+		ntohl(fcoe_lesb->lesb_err_block);
+	ctlr_attrs->lesb.lesb_fcs_error =
+		ntohl(fcoe_lesb->lesb_fcs_error);
+}
+EXPORT_SYMBOL(bnx2fc_ctlr_get_lesb);
+
+static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_attrs *fcf_attrs)
+{
+	struct fcoe_ctlr_attrs *ctlr_attrs =
+		fcoe_fcf_to_ctlr(fcf_attrs);
+	struct fcoe_ctlr *ctlr = fcoe_ctlr_attrs_priv(ctlr_attrs);
+	struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
+
+	fcf_attrs->vlan_id = fcoe->vlan_id;
+}
+
 static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
 {
 	struct fcoe_percpu_s *bg;
@@ -1236,6 +1273,7 @@ static void bnx2fc_release_transport(void)
 
 static void bnx2fc_interface_release(struct kref *kref)
 {
+	struct fcoe_ctlr_attrs *ctlr_attrs;
 	struct bnx2fc_interface *interface;
 	struct fcoe_ctlr *ctlr;
 	struct net_device *netdev;
@@ -1244,13 +1282,14 @@ static void bnx2fc_interface_release(struct kref *kref)
 	BNX2FC_MISC_DBG("Interface is being released\n");
 
 	ctlr = bnx2fc_to_ctlr(interface);
+	ctlr_attrs = ctlr_to_ctlr_attrs(ctlr);
 	netdev = interface->netdev;
 
 	/* tear-down FIP controller */
 	if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
 		fcoe_ctlr_destroy(ctlr);
 
-	kfree(ctlr);
+	fcoe_ctlr_attrs_delete(ctlr_attrs);
 
 	dev_put(netdev);
 	module_put(THIS_MODULE);
@@ -1343,17 +1382,20 @@ struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
 				      struct net_device *netdev,
 				      enum fip_state fip_mode)
 {
+	struct fcoe_ctlr_attrs *ctlr_attrs;
 	struct bnx2fc_interface *interface;
 	struct fcoe_ctlr *ctlr;
 	int size;
 	int rc = 0;
 
 	size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
-	ctlr = kzalloc(size, GFP_KERNEL);
-	if (!ctlr) {
+	ctlr_attrs = fcoe_ctlr_attrs_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
+					 size);
+	if (!ctlr_attrs) {
 		printk(KERN_ERR PFX "Unable to allocate interface structure\n");
 		return NULL;
 	}
+	ctlr = fcoe_ctlr_attrs_priv(ctlr_attrs);
 	interface = fcoe_ctlr_priv(ctlr);
 	dev_hold(netdev);
 	kref_init(&interface->kref);
@@ -1373,7 +1415,7 @@ struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
 
 	fcoe_ctlr_destroy(ctlr);
 	dev_put(netdev);
-	kfree(ctlr);
+	fcoe_ctlr_attrs_delete(ctlr_attrs);
 	return NULL;
 }
 
@@ -2472,6 +2514,19 @@ static void __exit bnx2fc_mod_exit(void)
 module_init(bnx2fc_mod_init);
 module_exit(bnx2fc_mod_exit);
 
+static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
+	.get_fcoe_ctlr_mode = fcoe_ctlr_get_fip_mode,
+	.get_fcoe_ctlr_link_fail = bnx2fc_ctlr_get_lesb,
+	.get_fcoe_ctlr_vlink_fail = bnx2fc_ctlr_get_lesb,
+	.get_fcoe_ctlr_miss_fka = bnx2fc_ctlr_get_lesb,
+	.get_fcoe_ctlr_symb_err = bnx2fc_ctlr_get_lesb,
+	.get_fcoe_ctlr_err_block = bnx2fc_ctlr_get_lesb,
+	.get_fcoe_ctlr_fcs_error = bnx2fc_ctlr_get_lesb,
+
+	.get_fcoe_fcf_selected = fcoe_fcf_get_selected,
+	.get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
+};
+
 static struct fc_function_template bnx2fc_transport_function = {
 	.show_host_node_name = 1,
 	.show_host_port_name = 1,
drivers/scsi/fcoe/fcoe.c +64 -6

134 lines not on this page · raw message

drivers/scsi/fcoe/fcoe_ctlr.c +145 -14

241 lines not on this page · raw message

include/scsi/libfcoe.h +17 -0
index 7b93f21..d46ac6e 100644
@@ -168,9 +168,16 @@ static inline void *fcoe_ctlr_priv(const struct fcoe_ctlr *ctlr)
 	return (void *)(ctlr + 1);
 }
 
+#define ctlr_to_ctlr_attrs(x)						\
+	(struct fcoe_ctlr_attrs *)(((struct fcoe_ctlr_attrs *)(x)) - 1)
+
 /**
  * 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
+ * @fcf_attrs:   The associated fcoe_fcf_attrs instance
  * @time:	 system time (jiffies) when an advertisement was last received
  * @switch_name: WWN of switch from advertisement
  * @fabric_name: WWN of fabric from advertisement
@@ -192,6 +199,9 @@ static inline void *fcoe_ctlr_priv(const struct fcoe_ctlr *ctlr)
  */
 struct fcoe_fcf {
 	struct list_head list;
+	struct work_struct event_work;
+	struct fcoe_ctlr *fip;
+	struct fcoe_fcf_attrs *fcf_attrs;
 	unsigned long time;
 
 	u64 switch_name;
@@ -208,6 +218,9 @@ struct fcoe_fcf {
 	u8 fd_flags:1;
 };
 
+#define fcf_to_fcf_attrs(x)			\
+	((x)->fcf_attrs)
+
 /**
  * struct fcoe_rport - VN2VN remote port
  * @time:	time of create or last beacon packet received from node
@@ -343,6 +356,10 @@ void fcoe_queue_timer(ulong lport);
 int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen,
 			   struct fcoe_percpu_s *fps);
 
+/* FCoE Sysfs helpers */
+void fcoe_fcf_get_selected(struct fcoe_fcf_attrs *);
+void fcoe_ctlr_get_fip_mode(struct fcoe_ctlr_attrs *);
+
 /**
  * struct netdev_list
  * A mapping from netdevice to fcoe_transport