Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Jan 2019 01:19:24 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r342751 - in stable: 11/sys/dev/cxgbe 12/sys/dev/cxgbe
Message-ID:  <201901040119.x041JOkU030400@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Fri Jan  4 01:19:23 2019
New Revision: 342751
URL: https://svnweb.freebsd.org/changeset/base/342751

Log:
  MFC 340022: Add support for port unit wiring to cxgbe(4).
  
  - Add a bus_child_location_str method to the nexus drivers that prints
    out 'port=N' as the location string exported via devinfo and the
    '%location' sysctl node.
  
  - We can't use a bus_hint_device_unit to wire the unit numbers of
    devices with a fixed devclass as the device gets assigned a unit in
    make_device() before the device creator can set softc, etc.
    Instead, when adding a child device, use a helper function much like
    a bus_hint_device_unit method to look for wiring hints or to return
    -1 to let the system choose a unit number.  This function requires
    an "at" hint for the port pointing to the nexus device and a "port"
    hint listing the port number.  For example:
  
  hint.cxl.4.at="t5nex0"
  hint.cxl.4.port="0"
  
    wires cxl4 to the first port on the t5nex0 adapter.

Modified:
  stable/11/sys/dev/cxgbe/t4_main.c
Directory Properties:
  stable/11/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/12/sys/dev/cxgbe/t4_main.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/11/sys/dev/cxgbe/t4_main.c
==============================================================================
--- stable/11/sys/dev/cxgbe/t4_main.c	Fri Jan  4 00:06:30 2019	(r342750)
+++ stable/11/sys/dev/cxgbe/t4_main.c	Fri Jan  4 01:19:23 2019	(r342751)
@@ -85,6 +85,7 @@ __FBSDID("$FreeBSD$");
 static int t4_probe(device_t);
 static int t4_attach(device_t);
 static int t4_detach(device_t);
+static int t4_child_location_str(device_t, device_t, char *, size_t);
 static int t4_ready(device_t);
 static int t4_read_port_device(device_t, int, device_t *);
 static device_method_t t4_methods[] = {
@@ -92,6 +93,8 @@ static device_method_t t4_methods[] = {
 	DEVMETHOD(device_attach,	t4_attach),
 	DEVMETHOD(device_detach,	t4_detach),
 
+	DEVMETHOD(bus_child_location_str, t4_child_location_str),
+
 	DEVMETHOD(t4_is_main_ready,	t4_ready),
 	DEVMETHOD(t4_read_port_device,	t4_read_port_device),
 
@@ -151,6 +154,8 @@ static device_method_t t5_methods[] = {
 	DEVMETHOD(device_attach,	t4_attach),
 	DEVMETHOD(device_detach,	t4_detach),
 
+	DEVMETHOD(bus_child_location_str, t4_child_location_str),
+
 	DEVMETHOD(t4_is_main_ready,	t4_ready),
 	DEVMETHOD(t4_read_port_device,	t4_read_port_device),
 
@@ -184,6 +189,8 @@ static device_method_t t6_methods[] = {
 	DEVMETHOD(device_attach,	t4_attach),
 	DEVMETHOD(device_detach,	t4_detach),
 
+	DEVMETHOD(bus_child_location_str, t4_child_location_str),
+
 	DEVMETHOD(t4_is_main_ready,	t4_ready),
 	DEVMETHOD(t4_read_port_device,	t4_read_port_device),
 
@@ -846,6 +853,24 @@ t4_init_devnames(struct adapter *sc)
 }
 
 static int
+t4_ifnet_unit(struct adapter *sc, struct port_info *pi)
+{
+	const char *parent, *name;
+	long value;
+	int line, unit;
+
+	line = 0;
+	parent = device_get_nameunit(sc->dev);
+	name = sc->names->ifnet_name;
+	while (resource_find_dev(&line, name, &unit, "at", parent) == 0) {
+		if (resource_long_value(name, unit, "port", &value) == 0 &&
+		    value == pi->port_id)
+			return (unit);
+	}
+	return (-1);
+}
+
+static int
 t4_attach(device_t dev)
 {
 	struct adapter *sc;
@@ -1040,7 +1065,8 @@ t4_attach(device_t dev)
 			pi->flags |= FIXED_IFMEDIA;
 		PORT_UNLOCK(pi);
 
-		pi->dev = device_add_child(dev, sc->names->ifnet_name, -1);
+		pi->dev = device_add_child(dev, sc->names->ifnet_name,
+		    t4_ifnet_unit(sc, pi));
 		if (pi->dev == NULL) {
 			device_printf(dev,
 			    "failed to add device for port %d.\n", i);
@@ -1238,6 +1264,16 @@ done:
 		t4_sysctls(sc);
 
 	return (rc);
+}
+
+static int
+t4_child_location_str(device_t bus, device_t dev, char *buf, size_t buflen)
+{
+	struct port_info *pi;
+
+	pi = device_get_softc(dev);
+	snprintf(buf, buflen, "port=%d", pi->port_id);
+	return (0);
 }
 
 static int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201901040119.x041JOkU030400>