aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/etherswitch
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/etherswitch')
-rw-r--r--sys/dev/etherswitch/ar40xx/ar40xx_main.c13
-rw-r--r--sys/dev/etherswitch/ar40xx/ar40xx_phy.c16
-rw-r--r--sys/dev/etherswitch/arswitch/arswitch.c35
-rw-r--r--sys/dev/etherswitch/e6000sw/e6000sw.c94
-rw-r--r--sys/dev/etherswitch/e6000sw/e6000swreg.h9
-rw-r--r--sys/dev/etherswitch/e6000sw/e6060sw.c33
-rw-r--r--sys/dev/etherswitch/etherswitch.c4
-rw-r--r--sys/dev/etherswitch/felix/felix.c14
-rw-r--r--sys/dev/etherswitch/infineon/adm6996fc.c53
-rw-r--r--sys/dev/etherswitch/ip17x/ip17x.c31
-rw-r--r--sys/dev/etherswitch/micrel/ksz8995ma.c53
-rw-r--r--sys/dev/etherswitch/miiproxy.c20
-rw-r--r--sys/dev/etherswitch/mtkswitch/mtkswitch.c32
-rw-r--r--sys/dev/etherswitch/rtl8366/rtl8366rb.c25
-rw-r--r--sys/dev/etherswitch/ukswitch/ukswitch.c27
15 files changed, 202 insertions, 257 deletions
diff --git a/sys/dev/etherswitch/ar40xx/ar40xx_main.c b/sys/dev/etherswitch/ar40xx/ar40xx_main.c
index 757dbe23071e..d5636d26120b 100644
--- a/sys/dev/etherswitch/ar40xx/ar40xx_main.c
+++ b/sys/dev/etherswitch/ar40xx/ar40xx_main.c
@@ -254,22 +254,23 @@ static int
ar40xx_detach(device_t dev)
{
struct ar40xx_softc *sc = device_get_softc(dev);
- int i;
+ int error, i;
device_printf(sc->sc_dev, "%s: called\n", __func__);
+ error = bus_generic_detach(dev);
+ if (error != 0)
+ return (error);
+
callout_drain(&sc->sc_phy_callout);
/* Free PHYs */
for (i = 0; i < AR40XX_NUM_PHYS; i++) {
- if (sc->sc_phys.miibus[i] != NULL)
- device_delete_child(dev, sc->sc_phys.miibus[i]);
if (sc->sc_phys.ifp[i] != NULL)
if_free(sc->sc_phys.ifp[i]);
free(sc->sc_phys.ifname[i], M_DEVBUF);
}
- bus_generic_detach(dev);
mtx_destroy(&sc->sc_mtx);
return (0);
@@ -482,9 +483,9 @@ ar40xx_attach(device_t dev)
/* Attach PHYs */
ret = ar40xx_attach_phys(sc);
- ret = bus_generic_probe(dev);
+ bus_identify_children(dev);
bus_enumerate_hinted_children(dev);
- ret = bus_generic_attach(dev);
+ bus_attach_children(dev);
/* Start timer */
callout_init_mtx(&sc->sc_phy_callout, &sc->sc_mtx, 0);
diff --git a/sys/dev/etherswitch/ar40xx/ar40xx_phy.c b/sys/dev/etherswitch/ar40xx/ar40xx_phy.c
index b9a308e3620d..aa02ef25ac7b 100644
--- a/sys/dev/etherswitch/ar40xx/ar40xx_phy.c
+++ b/sys/dev/etherswitch/ar40xx/ar40xx_phy.c
@@ -200,17 +200,9 @@ ar40xx_attach_phys(struct ar40xx_softc *sc)
snprintf(name, IFNAMSIZ, "%sport", device_get_nameunit(sc->sc_dev));
for (phy = 0; phy < AR40XX_NUM_PHYS; phy++) {
sc->sc_phys.ifp[phy] = if_alloc(IFT_ETHER);
- if (sc->sc_phys.ifp[phy] == NULL) {
- device_printf(sc->sc_dev,
- "PHY %d: couldn't allocate ifnet structure\n",
- phy);
- err = ENOMEM;
- break;
- }
-
- sc->sc_phys.ifp[phy]->if_softc = sc;
- sc->sc_phys.ifp[phy]->if_flags |= IFF_UP | IFF_BROADCAST |
- IFF_DRV_RUNNING | IFF_SIMPLEX;
+ if_setsoftc(sc->sc_phys.ifp[phy], sc);
+ if_setflagbits(sc->sc_phys.ifp[phy], IFF_UP | IFF_BROADCAST |
+ IFF_DRV_RUNNING | IFF_SIMPLEX, 0);
sc->sc_phys.ifname[phy] = malloc(strlen(name)+1, M_DEVBUF,
M_WAITOK);
bcopy(name, sc->sc_phys.ifname[phy], strlen(name)+1);
@@ -223,7 +215,7 @@ ar40xx_attach_phys(struct ar40xx_softc *sc)
device_printf(sc->sc_dev,
"%s attached to pseudo interface %s\n",
device_get_nameunit(sc->sc_phys.miibus[phy]),
- sc->sc_phys.ifp[phy]->if_xname);
+ if_name(sc->sc_phys.ifp[phy]));
if (err != 0) {
device_printf(sc->sc_dev,
"attaching PHY %d failed\n",
diff --git a/sys/dev/etherswitch/arswitch/arswitch.c b/sys/dev/etherswitch/arswitch/arswitch.c
index 1c2bcefdfe91..c53c82f1750c 100644
--- a/sys/dev/etherswitch/arswitch/arswitch.c
+++ b/sys/dev/etherswitch/arswitch/arswitch.c
@@ -95,7 +95,7 @@ arswitch_probe(device_t dev)
{
struct arswitch_softc *sc;
uint32_t id;
- char *chipname, desc[256];
+ char *chipname;
sc = device_get_softc(dev);
bzero(sc, sizeof(*sc));
@@ -132,12 +132,9 @@ arswitch_probe(device_t dev)
DPRINTF(sc, ARSWITCH_DBG_ANY, "chipname=%s, id=%08x\n", chipname, id);
if (chipname != NULL) {
- snprintf(desc, sizeof(desc),
+ device_set_descf(dev,
"Atheros %s Ethernet Switch (ver %d rev %d)",
- chipname,
- sc->chip_ver,
- sc->chip_rev);
- device_set_desc_copy(dev, desc);
+ chipname, sc->chip_ver, sc->chip_rev);
return (BUS_PROBE_DEFAULT);
}
return (ENXIO);
@@ -153,12 +150,6 @@ arswitch_attach_phys(struct arswitch_softc *sc)
snprintf(name, IFNAMSIZ, "%sport", device_get_nameunit(sc->sc_dev));
for (phy = 0; phy < sc->numphys; phy++) {
sc->ifp[phy] = if_alloc(IFT_ETHER);
- if (sc->ifp[phy] == NULL) {
- device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
- err = ENOMEM;
- break;
- }
-
if_setsoftc(sc->ifp[phy], sc);
if_setflagbits(sc->ifp[phy], IFF_UP | IFF_BROADCAST |
IFF_DRV_RUNNING | IFF_SIMPLEX, 0);
@@ -172,7 +163,7 @@ arswitch_attach_phys(struct arswitch_softc *sc)
#if 0
DPRINTF(sc->sc_dev, "%s attached to pseudo interface %s\n",
device_get_nameunit(sc->miibus[phy]),
- sc->ifp[phy]->if_xname);
+ if_name(sc->ifp[phy]));
#endif
if (err != 0) {
device_printf(sc->sc_dev,
@@ -658,14 +649,9 @@ arswitch_attach(device_t dev)
return (err);
}
- bus_generic_probe(dev);
+ bus_identify_children(dev);
bus_enumerate_hinted_children(dev);
- err = bus_generic_attach(dev);
- if (err != 0) {
- DPRINTF(sc, ARSWITCH_DBG_ANY,
- "%s: bus_generic_attach: err=%d\n", __func__, err);
- return (err);
- }
+ bus_attach_children(dev);
callout_init_mtx(&sc->callout_tick, &sc->sc_mtx, 0);
@@ -680,13 +666,15 @@ static int
arswitch_detach(device_t dev)
{
struct arswitch_softc *sc = device_get_softc(dev);
- int i;
+ int error, i;
callout_drain(&sc->callout_tick);
+ error = bus_generic_detach(dev);
+ if (error != 0)
+ return (error);
+
for (i=0; i < sc->numphys; i++) {
- if (sc->miibus[i] != NULL)
- device_delete_child(dev, sc->miibus[i]);
if (sc->ifp[i] != NULL)
if_free(sc->ifp[i]);
free(sc->ifname[i], M_DEVBUF);
@@ -694,7 +682,6 @@ arswitch_detach(device_t dev)
free(sc->atu.entries, M_DEVBUF);
- bus_generic_detach(dev);
mtx_destroy(&sc->sc_mtx);
return (0);
diff --git a/sys/dev/etherswitch/e6000sw/e6000sw.c b/sys/dev/etherswitch/e6000sw/e6000sw.c
index 95f1a2e96db6..7e9193f4ba47 100644
--- a/sys/dev/etherswitch/e6000sw/e6000sw.c
+++ b/sys/dev/etherswitch/e6000sw/e6000sw.c
@@ -51,7 +51,7 @@
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#else
-#include <machine/stdarg.h>
+#include <sys/stdarg.h>
#endif
#include "e6000swreg.h"
@@ -89,6 +89,7 @@ typedef struct e6000sw_softc {
device_t miibus[E6000SW_MAX_PORTS];
struct taskqueue *sc_tq;
struct timeout_task sc_tt;
+ bool is_shutdown;
int vlans[E6000SW_NUM_VLANS];
uint32_t swid;
@@ -195,17 +196,17 @@ DEFINE_CLASS_0(e6000sw, e6000sw_driver, e6000sw_methods,
sizeof(e6000sw_softc_t));
DRIVER_MODULE(e6000sw, mdio, e6000sw_driver, 0, 0);
-DRIVER_MODULE(etherswitch, e6000sw, etherswitch_driver, 0, 0);
DRIVER_MODULE(miibus, e6000sw, miibus_driver, 0, 0);
+DRIVER_MODULE_ORDERED(etherswitch, e6000sw, etherswitch_driver, 0, 0, SI_ORDER_ANY);
MODULE_DEPEND(e6000sw, mdio, 1, 1, 1);
-
+MODULE_DEPEND(e6000sw, etherswitch, 1, 1, 1);
static void
e6000sw_identify(driver_t *driver, device_t parent)
{
- if (device_find_child(parent, "e6000sw", -1) == NULL)
- BUS_ADD_CHILD(parent, 0, "e6000sw", -1);
+ if (device_find_child(parent, "e6000sw", DEVICE_UNIT_ANY) == NULL)
+ BUS_ADD_CHILD(parent, 0, "e6000sw", DEVICE_UNIT_ANY);
}
static int
@@ -216,7 +217,8 @@ e6000sw_probe(device_t dev)
#ifdef FDT
phandle_t switch_node;
#else
- int is_6190;
+ int is_6190 = 0;
+ int is_6190x = 0;
#endif
sc = device_get_softc(dev);
@@ -252,15 +254,25 @@ e6000sw_probe(device_t dev)
device_get_unit(sc->dev), "addr", &sc->sw_addr) != 0)
return (ENXIO);
if (resource_int_value(device_get_name(sc->dev),
- device_get_unit(sc->dev), "is6190", &is_6190) != 0)
+ device_get_unit(sc->dev), "is6190", &is_6190) != 0) {
/*
* Check "is8190" to keep backward compatibility with
* older setups.
*/
resource_int_value(device_get_name(sc->dev),
device_get_unit(sc->dev), "is8190", &is_6190);
+ }
+ resource_int_value(device_get_name(sc->dev),
+ device_get_unit(sc->dev), "is6190x", &is_6190x);
+ if (is_6190 != 0 && is_6190x != 0) {
+ device_printf(dev,
+ "Cannot configure conflicting variants (6190 / 6190x)\n");
+ return (ENXIO);
+ }
if (is_6190 != 0)
sc->swid = MV88E6190;
+ else if (is_6190x != 0)
+ sc->swid = MV88E6190X;
#endif
if (sc->sw_addr < 0 || sc->sw_addr > 32)
return (ENXIO);
@@ -302,6 +314,10 @@ e6000sw_probe(device_t dev)
description = "Marvell 88E6190";
sc->num_ports = 11;
break;
+ case MV88E6190X:
+ description = "Marvell 88E6190X";
+ sc->num_ports = 11;
+ break;
default:
device_printf(dev, "Unrecognized device, id 0x%x.\n", sc->swid);
return (ENXIO);
@@ -332,7 +348,7 @@ e6000sw_parse_fixed_link(e6000sw_softc_t *sc, phandle_t node, uint32_t port)
return (ENXIO);
}
if (speed == 2500 && (MVSWITCH(sc, MV88E6141) ||
- MVSWITCH(sc, MV88E6341) || MVSWITCH(sc, MV88E6190)))
+ MVSWITCH(sc, MV88E6341) || MVSWITCH(sc, MV88E6190) || MVSWITCH(sc, MV88E6190X)))
sc->fixed25_mask |= (1 << port);
}
@@ -454,8 +470,6 @@ e6000sw_init_interface(e6000sw_softc_t *sc, int port)
snprintf(name, IFNAMSIZ, "%sport", device_get_nameunit(sc->dev));
sc->ifp[port] = if_alloc(IFT_ETHER);
- if (sc->ifp[port] == NULL)
- return (ENOMEM);
if_setsoftc(sc->ifp[port], sc);
if_setflagbits(sc->ifp[port], IFF_UP | IFF_BROADCAST |
IFF_DRV_RUNNING | IFF_SIMPLEX, 0);
@@ -598,22 +612,26 @@ e6000sw_attach(device_t dev)
reg |= PSC_CONTROL_SPD2500;
else
reg |= PSC_CONTROL_SPD1000;
- if (MVSWITCH(sc, MV88E6190) &&
+ if ((MVSWITCH(sc, MV88E6190) ||
+ MVSWITCH(sc, MV88E6190X)) &&
e6000sw_is_fixed25port(sc, port))
reg |= PSC_CONTROL_ALT_SPD;
reg |= PSC_CONTROL_FORCED_DPX | PSC_CONTROL_FULLDPX |
PSC_CONTROL_FORCED_LINK | PSC_CONTROL_LINK_UP |
PSC_CONTROL_FORCED_SPD;
- if (!MVSWITCH(sc, MV88E6190))
+ if (!MVSWITCH(sc, MV88E6190) &&
+ !MVSWITCH(sc, MV88E6190X))
reg |= PSC_CONTROL_FORCED_FC | PSC_CONTROL_FC_ON;
if (MVSWITCH(sc, MV88E6141) ||
MVSWITCH(sc, MV88E6341) ||
- MVSWITCH(sc, MV88E6190))
+ MVSWITCH(sc, MV88E6190) ||
+ MVSWITCH(sc, MV88E6190X))
reg |= PSC_CONTROL_FORCED_EEE;
e6000sw_writereg(sc, REG_PORT(sc, port), PSC_CONTROL,
reg);
/* Power on the SERDES interfaces. */
- if (MVSWITCH(sc, MV88E6190) &&
+ if ((MVSWITCH(sc, MV88E6190) ||
+ MVSWITCH(sc, MV88E6190X)) &&
(port == 9 || port == 10)) {
if (e6000sw_is_fixed25port(sc, port))
sgmii = false;
@@ -644,14 +662,15 @@ e6000sw_attach(device_t dev)
device_printf(dev, "switch is ready.\n");
E6000SW_UNLOCK(sc);
- bus_generic_probe(dev);
- bus_generic_attach(dev);
+ bus_identify_children(dev);
+ bus_attach_children(dev);
taskqueue_enqueue_timeout(sc->sc_tq, &sc->sc_tt, hz);
return (0);
out_fail:
+ E6000SW_UNLOCK(sc);
e6000sw_detach(dev);
return (err);
@@ -847,19 +866,26 @@ e6000sw_writephy_locked(device_t dev, int phy, int reg, int data)
static int
e6000sw_detach(device_t dev)
{
- int phy;
+ int error, phy;
e6000sw_softc_t *sc;
sc = device_get_softc(dev);
- if (device_is_attached(dev))
- taskqueue_drain_timeout(sc->sc_tq, &sc->sc_tt);
+ E6000SW_LOCK(sc);
+ sc->is_shutdown = true;
+ if (sc->sc_tq != NULL) {
+ while (taskqueue_cancel_timeout(sc->sc_tq, &sc->sc_tt, NULL) != 0)
+ taskqueue_drain_timeout(sc->sc_tq, &sc->sc_tt);
+ }
+ E6000SW_UNLOCK(sc);
+
+ error = bus_generic_detach(dev);
+ if (error != 0)
+ return (error);
if (sc->sc_tq != NULL)
taskqueue_free(sc->sc_tq);
- device_delete_children(dev);
-
sx_destroy(&sc->sx);
for (phy = 0; phy < sc->num_ports; phy++) {
if (sc->ifp[phy] != NULL)
@@ -1376,11 +1402,17 @@ e6000sw_getvgroup(device_t dev, etherswitch_vlangroup_t *vg)
static __inline struct mii_data*
e6000sw_miiforphy(e6000sw_softc_t *sc, unsigned int phy)
{
+ device_t mii_dev;
if (!e6000sw_is_phyport(sc, phy))
return (NULL);
+ mii_dev = sc->miibus[phy];
+ if (mii_dev == NULL)
+ return (NULL);
+ if (device_get_state(mii_dev) != DS_ATTACHED)
+ return (NULL);
- return (device_get_softc(sc->miibus[phy]));
+ return (device_get_softc(mii_dev));
}
static int
@@ -1583,6 +1615,12 @@ e6000sw_tick(void *arg, int p __unused)
E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
E6000SW_LOCK(sc);
+
+ if (sc->is_shutdown) {
+ E6000SW_UNLOCK(sc);
+ return;
+ }
+
for (port = 0; port < sc->num_ports; port++) {
/* Tick only on PHY ports */
if (!e6000sw_is_portenabled(sc, port) ||
@@ -1600,6 +1638,17 @@ e6000sw_tick(void *arg, int p __unused)
&mii->mii_media_status, &mii->mii_media_active);
LIST_FOREACH(miisc, &mii->mii_phys, mii_list) {
+ /*
+ * Note: this is sometimes NULL during PHY
+ * enumeration, although that shouldn't be
+ * happening /after/ tick runs. To work
+ * around this whilst the problem is being
+ * debugged, just do a NULL check here and
+ * continue.
+ */
+ if (mii->mii_media.ifm_cur == NULL)
+ continue;
+
if (IFM_INST(mii->mii_media.ifm_cur->ifm_media)
!= miisc->mii_inst)
continue;
@@ -1607,6 +1656,7 @@ e6000sw_tick(void *arg, int p __unused)
}
}
E6000SW_UNLOCK(sc);
+ taskqueue_enqueue_timeout(sc->sc_tq, &sc->sc_tt, hz);
}
static void
diff --git a/sys/dev/etherswitch/e6000sw/e6000swreg.h b/sys/dev/etherswitch/e6000sw/e6000swreg.h
index 7c952052a401..ec4503faeec5 100644
--- a/sys/dev/etherswitch/e6000sw/e6000swreg.h
+++ b/sys/dev/etherswitch/e6000sw/e6000swreg.h
@@ -47,6 +47,7 @@ struct atu_opt {
#define MV88E6172 0x1720
#define MV88E6176 0x1760
#define MV88E6190 0x1900
+#define MV88E6190X 0x0a00
#define MVSWITCH(_sc, id) ((_sc)->swid == (id))
#define MVSWITCH_MULTICHIP(_sc) ((_sc)->sw_addr != 0)
@@ -56,7 +57,7 @@ struct atu_opt {
*/
#define REG_GLOBAL 0x1b
#define REG_GLOBAL2 0x1c
-#define REG_PORT(_sc, p) ((MVSWITCH((_sc), MV88E6190) ? 0 : 0x10) + (p))
+#define REG_PORT(_sc, p) (((MVSWITCH((_sc), MV88E6190) || MVSWITCH((_sc), MV88E6190X)) ? 0 : 0x10) + (p))
#define REG_NUM_MAX 31
@@ -138,13 +139,13 @@ struct atu_opt {
#define VTU_DATA 7
#define VTU_DATA2 8
-#define VTU_FID_MASK(_sc) (MVSWITCH((_sc), MV88E6190) ? 0xfff : 0xff)
+#define VTU_FID_MASK(_sc) ((MVSWITCH((_sc), MV88E6190) || MVSWITCH((_sc), MV88E6190X)) ? 0xfff : 0xff)
#define VTU_FID_POLICY (1 << 12)
#define VTU_PORT_UNMODIFIED 0
#define VTU_PORT_UNTAGGED 1
#define VTU_PORT_TAGGED 2
#define VTU_PORT_DISCARD 3
-#define VTU_PPREG(_sc) (MVSWITCH((_sc), MV88E6190) ? 8 : 4)
+#define VTU_PPREG(_sc) ((MVSWITCH((_sc), MV88E6190) || MVSWITCH((_sc), MV88E6190X)) ? 8 : 4)
#define VTU_PORT(_sc, p) (((p) % VTU_PPREG(_sc)) * (16 / VTU_PPREG(_sc)))
#define VTU_PORT_MASK 3
#define VTU_BUSY (1 << 15)
@@ -174,7 +175,7 @@ struct atu_opt {
#define ATU_MAC_ADDR45 15
#define ATU_DATA_LAG (1 << 15)
-#define ATU_PORT_MASK(_sc) (MVSWITCH((_sc), MV88E6190) ? 0xfff0 : 0xff0)
+#define ATU_PORT_MASK(_sc) ((MVSWITCH((_sc), MV88E6190) || MVSWITCH((_sc), MV88E6190X)) ? 0xfff0 : 0xff0)
#define ATU_PORT_SHIFT 4
#define ATU_LAG_MASK 0xf0
#define ATU_LAG_SHIFT 4
diff --git a/sys/dev/etherswitch/e6000sw/e6060sw.c b/sys/dev/etherswitch/e6000sw/e6060sw.c
index 19744f5e44a5..0af71692091c 100644
--- a/sys/dev/etherswitch/e6000sw/e6060sw.c
+++ b/sys/dev/etherswitch/e6000sw/e6060sw.c
@@ -162,7 +162,6 @@ e6060sw_probe(device_t dev)
struct e6060sw_softc *sc;
int devid, i;
char *devname;
- char desc[80];
sc = device_get_softc(dev);
bzero(sc, sizeof(*sc));
@@ -193,9 +192,8 @@ e6060sw_probe(device_t dev)
else
return (ENXIO);
- sprintf(desc, "Marvell %s MDIO switch driver at 0x%02x",
+ device_set_descf(dev, "Marvell %s MDIO switch driver at 0x%02x",
devname, sc->smi_offset);
- device_set_desc_copy(dev, desc);
return (BUS_PROBE_DEFAULT);
}
@@ -216,15 +214,9 @@ e6060sw_attach_phys(struct e6060sw_softc *sc)
sc->ifpport[phy] = port;
sc->portphy[port] = phy;
sc->ifp[port] = if_alloc(IFT_ETHER);
- if (sc->ifp[port] == NULL) {
- device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
- err = ENOMEM;
- break;
- }
-
- sc->ifp[port]->if_softc = sc;
- sc->ifp[port]->if_flags |= IFF_UP | IFF_BROADCAST |
- IFF_DRV_RUNNING | IFF_SIMPLEX;
+ if_setsoftc(sc->ifp[port], sc);
+ if_setflagbits(sc->ifp[port], IFF_UP | IFF_BROADCAST |
+ IFF_DRV_RUNNING | IFF_SIMPLEX, 0);
if_initname(sc->ifp[port], name, port);
sc->miibus[port] = malloc(sizeof(device_t), M_E6060SW,
M_WAITOK | M_ZERO);
@@ -233,7 +225,7 @@ e6060sw_attach_phys(struct e6060sw_softc *sc)
BMSR_DEFCAPMASK, phy + sc->smi_offset, MII_OFFSET_ANY, 0);
DPRINTF(sc->sc_dev, "%s attached to pseudo interface %s\n",
device_get_nameunit(*sc->miibus[port]),
- sc->ifp[port]->if_xname);
+ if_name(sc->ifp[port]));
if (err != 0) {
device_printf(sc->sc_dev,
"attaching PHY %d failed\n",
@@ -314,11 +306,9 @@ e6060sw_attach(device_t dev)
if (err != 0)
return (err);
- bus_generic_probe(dev);
+ bus_identify_children(dev);
bus_enumerate_hinted_children(dev);
- err = bus_generic_attach(dev);
- if (err != 0)
- return (err);
+ bus_attach_children(dev);
callout_init(&sc->callout_tick, 0);
@@ -331,18 +321,20 @@ static int
e6060sw_detach(device_t dev)
{
struct e6060sw_softc *sc;
- int i, port;
+ int error, i, port;
sc = device_get_softc(dev);
+ error = bus_generic_detach(dev);
+ if (error != 0)
+ return (error);
+
callout_drain(&sc->callout_tick);
for (i = 0; i < MII_NPHY; i++) {
if (((1 << i) & sc->phymask) == 0)
continue;
port = e6060sw_portforphy(sc, i);
- if (sc->miibus[port] != NULL)
- device_delete_child(dev, (*sc->miibus[port]));
if (sc->ifp[port] != NULL)
if_free(sc->ifp[port]);
free(sc->ifname[port], M_E6060SW);
@@ -354,7 +346,6 @@ e6060sw_detach(device_t dev)
free(sc->ifname, M_E6060SW);
free(sc->ifp, M_E6060SW);
- bus_generic_detach(dev);
mtx_destroy(&sc->sc_mtx);
return (0);
diff --git a/sys/dev/etherswitch/etherswitch.c b/sys/dev/etherswitch/etherswitch.c
index 74afcd259007..ba46d8b2299d 100644
--- a/sys/dev/etherswitch/etherswitch.c
+++ b/sys/dev/etherswitch/etherswitch.c
@@ -82,8 +82,8 @@ static struct cdevsw etherswitch_cdevsw = {
static void
etherswitch_identify(driver_t *driver, device_t parent)
{
- if (device_find_child(parent, "etherswitch", -1) == NULL)
- BUS_ADD_CHILD(parent, 0, "etherswitch", -1);
+ if (device_find_child(parent, "etherswitch", DEVICE_UNIT_ANY) == NULL)
+ BUS_ADD_CHILD(parent, 0, "etherswitch", DEVICE_UNIT_ANY);
}
static int
diff --git a/sys/dev/etherswitch/felix/felix.c b/sys/dev/etherswitch/felix/felix.c
index 92d654961f50..098767ee063e 100644
--- a/sys/dev/etherswitch/felix/felix.c
+++ b/sys/dev/etherswitch/felix/felix.c
@@ -240,9 +240,6 @@ felix_init_interface(felix_softc_t sc, int port)
snprintf(name, IFNAMSIZ, "%sport", device_get_nameunit(sc->dev));
sc->ports[port].ifp = if_alloc(IFT_ETHER);
- if (sc->ports[port].ifp == NULL)
- return (ENOMEM);
-
if_setsoftc(sc->ports[port].ifp, sc);
if_setflags(sc->ports[port].ifp, IFF_UP | IFF_BROADCAST | IFF_MULTICAST |
IFF_DRV_RUNNING | IFF_SIMPLEX);
@@ -466,8 +463,8 @@ felix_attach(device_t dev)
FELIX_UNLOCK(sc);
/* Allow etherswitch to attach as our child. */
- bus_generic_probe(dev);
- bus_generic_attach(dev);
+ bus_identify_children(dev);
+ bus_attach_children(dev);
return (0);
@@ -483,9 +480,10 @@ felix_detach(device_t dev)
int error;
int i;
- error = 0;
sc = device_get_softc(dev);
- bus_generic_detach(dev);
+ error = bus_generic_detach(dev);
+ if (error != 0)
+ return (error);
mtx_lock(&sc->mtx);
callout_stop(&sc->tick_callout);
@@ -500,8 +498,6 @@ felix_detach(device_t dev)
felix_setup(sc);
for (i = 0; i < sc->info.es_nports; i++) {
- if (sc->ports[i].miibus != NULL)
- device_delete_child(dev, sc->ports[i].miibus);
if (sc->ports[i].ifp != NULL)
if_free(sc->ports[i].ifp);
if (sc->ports[i].ifname != NULL)
diff --git a/sys/dev/etherswitch/infineon/adm6996fc.c b/sys/dev/etherswitch/infineon/adm6996fc.c
index cc67616d9fdf..fedab27c2610 100644
--- a/sys/dev/etherswitch/infineon/adm6996fc.c
+++ b/sys/dev/etherswitch/infineon/adm6996fc.c
@@ -153,7 +153,7 @@ adm6996fc_probe(device_t dev)
return (ENXIO);
}
- device_set_desc_copy(dev, "Infineon ADM6996FC/M/MX MDIO switch driver");
+ device_set_desc(dev, "Infineon ADM6996FC/M/MX MDIO switch driver");
return (BUS_PROBE_DEFAULT);
}
@@ -173,28 +173,18 @@ adm6996fc_attach_phys(struct adm6996fc_softc *sc)
sc->ifpport[phy] = port;
sc->portphy[port] = phy;
sc->ifp[port] = if_alloc(IFT_ETHER);
- if (sc->ifp[port] == NULL) {
- device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
- err = ENOMEM;
- break;
- }
-
- sc->ifp[port]->if_softc = sc;
- sc->ifp[port]->if_flags |= IFF_UP | IFF_BROADCAST |
- IFF_DRV_RUNNING | IFF_SIMPLEX;
+ if_setsoftc(sc->ifp[port], sc);
+ if_setflagbits(sc->ifp[port], IFF_UP | IFF_BROADCAST |
+ IFF_DRV_RUNNING | IFF_SIMPLEX, 0);
if_initname(sc->ifp[port], name, port);
sc->miibus[port] = malloc(sizeof(device_t), M_ADM6996FC,
M_WAITOK | M_ZERO);
- if (sc->miibus[port] == NULL) {
- err = ENOMEM;
- goto failed;
- }
err = mii_attach(sc->sc_dev, sc->miibus[port], sc->ifp[port],
adm6996fc_ifmedia_upd, adm6996fc_ifmedia_sts, \
BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0);
DPRINTF(sc->sc_dev, "%s attached to pseudo interface %s\n",
device_get_nameunit(*sc->miibus[port]),
- sc->ifp[port]->if_xname);
+ if_name(sc->ifp[port]));
if (err != 0) {
device_printf(sc->sc_dev,
"attaching PHY %d failed\n",
@@ -261,12 +251,6 @@ adm6996fc_attach(device_t dev)
sc->portphy = malloc(sizeof(int) * sc->numports, M_ADM6996FC,
M_WAITOK | M_ZERO);
- if (sc->ifp == NULL || sc->ifname == NULL || sc->miibus == NULL ||
- sc->portphy == NULL) {
- err = ENOMEM;
- goto failed;
- }
-
/*
* Attach the PHYs and complete the bus enumeration.
*/
@@ -274,11 +258,9 @@ adm6996fc_attach(device_t dev)
if (err != 0)
goto failed;
- bus_generic_probe(dev);
+ bus_identify_children(dev);
bus_enumerate_hinted_children(dev);
- err = bus_generic_attach(dev);
- if (err != 0)
- goto failed;
+ bus_attach_children(dev);
callout_init(&sc->callout_tick, 0);
@@ -287,14 +269,10 @@ adm6996fc_attach(device_t dev)
return (0);
failed:
- if (sc->portphy != NULL)
- free(sc->portphy, M_ADM6996FC);
- if (sc->miibus != NULL)
- free(sc->miibus, M_ADM6996FC);
- if (sc->ifname != NULL)
- free(sc->ifname, M_ADM6996FC);
- if (sc->ifp != NULL)
- free(sc->ifp, M_ADM6996FC);
+ free(sc->portphy, M_ADM6996FC);
+ free(sc->miibus, M_ADM6996FC);
+ free(sc->ifname, M_ADM6996FC);
+ free(sc->ifp, M_ADM6996FC);
return (err);
}
@@ -303,18 +281,20 @@ static int
adm6996fc_detach(device_t dev)
{
struct adm6996fc_softc *sc;
- int i, port;
+ int error, i, port;
sc = device_get_softc(dev);
+ error = bus_generic_detach(dev);
+ if (error != 0)
+ return (error);
+
callout_drain(&sc->callout_tick);
for (i = 0; i < MII_NPHY; i++) {
if (((1 << i) & sc->phymask) == 0)
continue;
port = adm6996fc_portforphy(sc, i);
- if (sc->miibus[port] != NULL)
- device_delete_child(dev, (*sc->miibus[port]));
if (sc->ifp[port] != NULL)
if_free(sc->ifp[port]);
free(sc->ifname[port], M_ADM6996FC);
@@ -326,7 +306,6 @@ adm6996fc_detach(device_t dev)
free(sc->ifname, M_ADM6996FC);
free(sc->ifp, M_ADM6996FC);
- bus_generic_detach(dev);
mtx_destroy(&sc->sc_mtx);
return (0);
diff --git a/sys/dev/etherswitch/ip17x/ip17x.c b/sys/dev/etherswitch/ip17x/ip17x.c
index 218c0c293662..42d3bf990c0e 100644
--- a/sys/dev/etherswitch/ip17x/ip17x.c
+++ b/sys/dev/etherswitch/ip17x/ip17x.c
@@ -83,8 +83,8 @@ static void ip17x_ifmedia_sts(if_t, struct ifmediareq *);
static void
ip17x_identify(driver_t *driver, device_t parent)
{
- if (device_find_child(parent, "ip17x", -1) == NULL)
- BUS_ADD_CHILD(parent, 0, "ip17x", -1);
+ if (device_find_child(parent, "ip17x", DEVICE_UNIT_ANY) == NULL)
+ BUS_ADD_CHILD(parent, 0, "ip17x", DEVICE_UNIT_ANY);
}
static int
@@ -152,7 +152,7 @@ ip17x_probe(device_t dev)
(void) resource_int_value(device_get_name(dev), device_get_unit(dev),
"mii-poll", &sc->miipoll);
#endif
- device_set_desc_copy(dev, "IC+ IP17x switch driver");
+ device_set_desc(dev, "IC+ IP17x switch driver");
return (BUS_PROBE_DEFAULT);
}
@@ -172,12 +172,6 @@ ip17x_attach_phys(struct ip17x_softc *sc)
sc->phyport[phy] = port;
sc->portphy[port] = phy;
sc->ifp[port] = if_alloc(IFT_ETHER);
- if (sc->ifp[port] == NULL) {
- device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
- err = ENOMEM;
- break;
- }
-
if_setsoftc(sc->ifp[port], sc);
if_setflags(sc->ifp[port], IFF_UP | IFF_BROADCAST |
IFF_DRV_RUNNING | IFF_SIMPLEX);
@@ -263,11 +257,9 @@ ip17x_attach(device_t dev)
*/
sc->hal.ip17x_set_vlan_mode(sc, ETHERSWITCH_VLAN_PORT);
- bus_generic_probe(dev);
+ bus_identify_children(dev);
bus_enumerate_hinted_children(dev);
- err = bus_generic_attach(dev);
- if (err != 0)
- return (err);
+ bus_attach_children(dev);
if (sc->miipoll) {
callout_init(&sc->callout_tick, 0);
@@ -282,7 +274,11 @@ static int
ip17x_detach(device_t dev)
{
struct ip17x_softc *sc;
- int i, port;
+ int error, i, port;
+
+ error = bus_generic_detach(dev);
+ if (error != 0)
+ return (error);
sc = device_get_softc(dev);
if (sc->miipoll)
@@ -292,8 +288,6 @@ ip17x_detach(device_t dev)
if (((1 << i) & sc->phymask) == 0)
continue;
port = sc->phyport[i];
- if (sc->miibus[port] != NULL)
- device_delete_child(dev, (*sc->miibus[port]));
if (sc->ifp[port] != NULL)
if_free(sc->ifp[port]);
free(sc->miibus[port], M_IP17X);
@@ -307,7 +301,6 @@ ip17x_detach(device_t dev)
/* Reset the switch. */
sc->hal.ip17x_reset(sc);
- bus_generic_detach(dev);
mtx_destroy(&sc->sc_mtx);
return (0);
@@ -556,7 +549,7 @@ ip17x_ifmedia_sts(if_t ifp, struct ifmediareq *ifmr)
static int
ip17x_readreg(device_t dev, int addr)
{
- struct ip17x_softc *sc;
+ struct ip17x_softc *sc __diagused;
sc = device_get_softc(dev);
IP17X_LOCK_ASSERT(sc, MA_OWNED);
@@ -568,7 +561,7 @@ ip17x_readreg(device_t dev, int addr)
static int
ip17x_writereg(device_t dev, int addr, int value)
{
- struct ip17x_softc *sc;
+ struct ip17x_softc *sc __diagused;
sc = device_get_softc(dev);
IP17X_LOCK_ASSERT(sc, MA_OWNED);
diff --git a/sys/dev/etherswitch/micrel/ksz8995ma.c b/sys/dev/etherswitch/micrel/ksz8995ma.c
index 43292d3b2007..cbffd5e39f49 100644
--- a/sys/dev/etherswitch/micrel/ksz8995ma.c
+++ b/sys/dev/etherswitch/micrel/ksz8995ma.c
@@ -197,7 +197,7 @@ ksz8995ma_probe(device_t dev)
return (ENXIO);
}
- device_set_desc_copy(dev, "Micrel KSZ8995MA SPI switch driver");
+ device_set_desc(dev, "Micrel KSZ8995MA SPI switch driver");
return (BUS_PROBE_DEFAULT);
}
@@ -219,28 +219,18 @@ ksz8995ma_attach_phys(struct ksz8995ma_softc *sc)
sc->ifpport[phy] = port;
sc->portphy[port] = phy;
sc->ifp[port] = if_alloc(IFT_ETHER);
- if (sc->ifp[port] == NULL) {
- device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
- err = ENOMEM;
- break;
- }
-
- sc->ifp[port]->if_softc = sc;
- sc->ifp[port]->if_flags |= IFF_UP | IFF_BROADCAST |
- IFF_DRV_RUNNING | IFF_SIMPLEX;
+ if_setsoftc(sc->ifp[port], sc);
+ if_setflagbits(sc->ifp[port], IFF_UP | IFF_BROADCAST |
+ IFF_DRV_RUNNING | IFF_SIMPLEX, 0);
if_initname(sc->ifp[port], name, port);
sc->miibus[port] = malloc(sizeof(device_t), M_KSZ8995MA,
M_WAITOK | M_ZERO);
- if (sc->miibus[port] == NULL) {
- err = ENOMEM;
- goto failed;
- }
err = mii_attach(sc->sc_dev, sc->miibus[port], sc->ifp[port],
ksz8995ma_ifmedia_upd, ksz8995ma_ifmedia_sts, \
BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0);
DPRINTF(sc->sc_dev, "%s attached to pseudo interface %s\n",
device_get_nameunit(*sc->miibus[port]),
- sc->ifp[port]->if_xname);
+ if_name(sc->ifp[port]));
if (err != 0) {
device_printf(sc->sc_dev,
"attaching PHY %d failed\n",
@@ -311,12 +301,6 @@ ksz8995ma_attach(device_t dev)
sc->portphy = malloc(sizeof(int) * sc->numports, M_KSZ8995MA,
M_WAITOK | M_ZERO);
- if (sc->ifp == NULL || sc->ifname == NULL || sc->miibus == NULL ||
- sc->portphy == NULL) {
- err = ENOMEM;
- goto failed;
- }
-
/*
* Attach the PHYs and complete the bus enumeration.
*/
@@ -324,11 +308,9 @@ ksz8995ma_attach(device_t dev)
if (err != 0)
goto failed;
- bus_generic_probe(dev);
+ bus_identify_children(dev);
bus_enumerate_hinted_children(dev);
- err = bus_generic_attach(dev);
- if (err != 0)
- goto failed;
+ bus_attach_children(dev);
callout_init(&sc->callout_tick, 0);
@@ -345,14 +327,10 @@ ksz8995ma_attach(device_t dev)
return (0);
failed:
- if (sc->portphy != NULL)
- free(sc->portphy, M_KSZ8995MA);
- if (sc->miibus != NULL)
- free(sc->miibus, M_KSZ8995MA);
- if (sc->ifname != NULL)
- free(sc->ifname, M_KSZ8995MA);
- if (sc->ifp != NULL)
- free(sc->ifp, M_KSZ8995MA);
+ free(sc->portphy, M_KSZ8995MA);
+ free(sc->miibus, M_KSZ8995MA);
+ free(sc->ifname, M_KSZ8995MA);
+ free(sc->ifp, M_KSZ8995MA);
return (err);
}
@@ -361,7 +339,11 @@ static int
ksz8995ma_detach(device_t dev)
{
struct ksz8995ma_softc *sc;
- int i, port;
+ int error, i, port;
+
+ error = bus_generic_detach(dev);
+ if (error != 0)
+ return (error);
sc = device_get_softc(dev);
@@ -371,8 +353,6 @@ ksz8995ma_detach(device_t dev)
if (((1 << i) & sc->phymask) == 0)
continue;
port = ksz8995ma_portforphy(sc, i);
- if (sc->miibus[port] != NULL)
- device_delete_child(dev, (*sc->miibus[port]));
if (sc->ifp[port] != NULL)
if_free(sc->ifp[port]);
free(sc->ifname[port], M_KSZ8995MA);
@@ -384,7 +364,6 @@ ksz8995ma_detach(device_t dev)
free(sc->ifname, M_KSZ8995MA);
free(sc->ifp, M_KSZ8995MA);
- bus_generic_detach(dev);
mtx_destroy(&sc->sc_mtx);
return (0);
diff --git a/sys/dev/etherswitch/miiproxy.c b/sys/dev/etherswitch/miiproxy.c
index 97d4b7f6eb67..79342a9e8e03 100644
--- a/sys/dev/etherswitch/miiproxy.c
+++ b/sys/dev/etherswitch/miiproxy.c
@@ -265,7 +265,8 @@ miiproxy_attach(device_t dev)
* The ethernet interface needs to call mii_attach_proxy() to pass
* the relevant parameters for rendezvous with the MDIO target.
*/
- return (bus_generic_attach(dev));
+ bus_attach_children(dev);
+ return (0);
}
static int
@@ -330,8 +331,8 @@ mdioproxy_rendezvous_callback(enum rendezvous_op op, struct rendezvous_entry *re
static void
mdioproxy_identify(driver_t *driver, device_t parent)
{
- if (device_find_child(parent, driver->name, -1) == NULL) {
- BUS_ADD_CHILD(parent, 0, driver->name, -1);
+ if (device_find_child(parent, driver->name, DEVICE_UNIT_ANY) == NULL) {
+ BUS_ADD_CHILD(parent, 0, driver->name, DEVICE_UNIT_ANY);
}
}
@@ -348,7 +349,8 @@ mdioproxy_attach(device_t dev)
{
rendezvous_register_target(dev, mdioproxy_rendezvous_callback);
- return (bus_generic_attach(dev));
+ bus_attach_children(dev);
+ return (0);
}
static int
@@ -368,7 +370,6 @@ device_t
mii_attach_proxy(device_t dev)
{
struct miiproxy_softc *sc;
- int error;
const char *name;
device_t miiproxy;
@@ -380,12 +381,8 @@ mii_attach_proxy(device_t dev)
return (NULL);
}
- miiproxy = device_add_child(dev, miiproxy_driver.name, -1);
- error = bus_generic_attach(dev);
- if (error != 0) {
- device_printf(dev, "can't attach miiproxy\n");
- return (NULL);
- }
+ miiproxy = device_add_child(dev, miiproxy_driver.name, DEVICE_UNIT_ANY);
+ bus_attach_children(dev);
sc = device_get_softc(miiproxy);
sc->parent = dev;
sc->proxy = miiproxy;
@@ -434,3 +431,4 @@ DRIVER_MODULE(mdioproxy, mdio, mdioproxy_driver, 0, 0);
DRIVER_MODULE(miibus, miiproxy, miibus_driver, 0, 0);
MODULE_VERSION(miiproxy, 1);
MODULE_DEPEND(miiproxy, miibus, 1, 1, 1);
+MODULE_DEPEND(miiproxy, mdio, 1, 1, 1);
diff --git a/sys/dev/etherswitch/mtkswitch/mtkswitch.c b/sys/dev/etherswitch/mtkswitch/mtkswitch.c
index 6e235097f189..ff7aee22398f 100644
--- a/sys/dev/etherswitch/mtkswitch/mtkswitch.c
+++ b/sys/dev/etherswitch/mtkswitch/mtkswitch.c
@@ -100,7 +100,7 @@ mtkswitch_probe(device_t dev)
bzero(sc, sizeof(*sc));
sc->sc_switchtype = switch_type;
- device_set_desc_copy(dev, "MTK Switch Driver");
+ device_set_desc(dev, "MTK Switch Driver");
return (0);
}
@@ -121,15 +121,9 @@ mtkswitch_attach_phys(struct mtkswitch_softc *sc)
continue;
}
sc->ifp[phy] = if_alloc(IFT_ETHER);
- if (sc->ifp[phy] == NULL) {
- device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
- err = ENOMEM;
- break;
- }
-
- sc->ifp[phy]->if_softc = sc;
- sc->ifp[phy]->if_flags |= IFF_UP | IFF_BROADCAST |
- IFF_DRV_RUNNING | IFF_SIMPLEX;
+ if_setsoftc(sc->ifp[phy], sc);
+ if_setflagbits(sc->ifp[phy], IFF_UP | IFF_BROADCAST |
+ IFF_DRV_RUNNING | IFF_SIMPLEX, 0);
sc->ifname[phy] = malloc(strlen(name) + 1, M_DEVBUF, M_WAITOK);
bcopy(name, sc->ifname[phy], strlen(name) + 1);
if_initname(sc->ifp[phy], sc->ifname[phy],
@@ -144,7 +138,7 @@ mtkswitch_attach_phys(struct mtkswitch_softc *sc)
} else {
DPRINTF(sc->sc_dev, "%s attached to pseudo interface "
"%s\n", device_get_nameunit(sc->miibus[phy]),
- sc->ifp[phy]->if_xname);
+ if_name(sc->ifp[phy]));
}
}
return (err);
@@ -237,12 +231,9 @@ mtkswitch_attach(device_t dev)
if (err != 0)
return (err);
- bus_generic_probe(dev);
+ bus_identify_children(dev);
bus_enumerate_hinted_children(dev);
- err = bus_generic_attach(dev);
- DPRINTF(dev, "%s: bus_generic_attach: err=%d\n", __func__, err);
- if (err != 0)
- return (err);
+ bus_attach_children(dev);
callout_init_mtx(&sc->callout_tick, &sc->sc_mtx, 0);
@@ -257,19 +248,20 @@ static int
mtkswitch_detach(device_t dev)
{
struct mtkswitch_softc *sc = device_get_softc(dev);
- int phy;
+ int error, phy;
+
+ error = bus_generic_detach(dev);
+ if (error != 0)
+ return (error);
callout_drain(&sc->callout_tick);
for (phy = 0; phy < MTKSWITCH_MAX_PHYS; phy++) {
- if (sc->miibus[phy] != NULL)
- device_delete_child(dev, sc->miibus[phy]);
if (sc->ifp[phy] != NULL)
if_free(sc->ifp[phy]);
free(sc->ifname[phy], M_DEVBUF);
}
- bus_generic_detach(dev);
mtx_destroy(&sc->sc_mtx);
return (0);
diff --git a/sys/dev/etherswitch/rtl8366/rtl8366rb.c b/sys/dev/etherswitch/rtl8366/rtl8366rb.c
index 8a74ae189284..9000061ae138 100644
--- a/sys/dev/etherswitch/rtl8366/rtl8366rb.c
+++ b/sys/dev/etherswitch/rtl8366/rtl8366rb.c
@@ -133,8 +133,8 @@ rtl8366rb_identify(driver_t *driver, device_t parent)
device_t child;
struct iicbus_ivar *devi;
- if (device_find_child(parent, "rtl8366rb", -1) == NULL) {
- child = BUS_ADD_CHILD(parent, 0, "rtl8366rb", -1);
+ if (device_find_child(parent, "rtl8366rb", DEVICE_UNIT_ANY) == NULL) {
+ child = BUS_ADD_CHILD(parent, 0, "rtl8366rb", DEVICE_UNIT_ANY);
devi = IICBUS_IVAR(child);
devi->addr = RTL8366_IIC_ADDR;
}
@@ -238,12 +238,6 @@ rtl8366rb_attach(device_t dev)
/* PHYs need an interface, so we generate a dummy one */
for (i = 0; i < sc->numphys; i++) {
sc->ifp[i] = if_alloc(IFT_ETHER);
- if (sc->ifp[i] == NULL) {
- device_printf(dev, "couldn't allocate ifnet structure\n");
- err = ENOMEM;
- break;
- }
-
if_setsoftc(sc->ifp[i], sc);
if_setflagbits(sc->ifp[i], IFF_UP | IFF_BROADCAST | IFF_DRV_RUNNING
| IFF_SIMPLEX, 0);
@@ -260,11 +254,9 @@ rtl8366rb_attach(device_t dev)
}
}
- bus_generic_probe(dev);
+ bus_identify_children(dev);
bus_enumerate_hinted_children(dev);
- err = bus_generic_attach(dev);
- if (err != 0)
- return (err);
+ bus_attach_children(dev);
callout_init_mtx(&sc->callout_tick, &sc->callout_mtx, 0);
rtl8366rb_tick(sc);
@@ -276,18 +268,19 @@ static int
rtl8366rb_detach(device_t dev)
{
struct rtl8366rb_softc *sc;
- int i;
+ int error, i;
+
+ error = bus_generic_detach(dev);
+ if (error != 0)
+ return (error);
sc = device_get_softc(dev);
for (i=0; i < sc->numphys; i++) {
- if (sc->miibus[i])
- device_delete_child(dev, sc->miibus[i]);
if (sc->ifp[i] != NULL)
if_free(sc->ifp[i]);
free(sc->ifname[i], M_DEVBUF);
}
- bus_generic_detach(dev);
callout_drain(&sc->callout_tick);
mtx_destroy(&sc->callout_mtx);
mtx_destroy(&sc->sc_mtx);
diff --git a/sys/dev/etherswitch/ukswitch/ukswitch.c b/sys/dev/etherswitch/ukswitch/ukswitch.c
index 6eff37bb118e..a2e30c3af8a1 100644
--- a/sys/dev/etherswitch/ukswitch/ukswitch.c
+++ b/sys/dev/etherswitch/ukswitch/ukswitch.c
@@ -106,7 +106,7 @@ ukswitch_probe(device_t dev)
sc = device_get_softc(dev);
bzero(sc, sizeof(*sc));
- device_set_desc_copy(dev, "Generic MDIO switch driver");
+ device_set_desc(dev, "Generic MDIO switch driver");
return (BUS_PROBE_DEFAULT);
}
@@ -124,12 +124,6 @@ ukswitch_attach_phys(struct ukswitch_softc *sc)
sc->ifpport[phy] = port;
sc->portphy[port] = phy;
sc->ifp[port] = if_alloc(IFT_ETHER);
- if (sc->ifp[port] == NULL) {
- device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
- err = ENOMEM;
- break;
- }
-
if_setsoftc(sc->ifp[port], sc);
if_setflags(sc->ifp[port], IFF_UP | IFF_BROADCAST |
IFF_DRV_RUNNING | IFF_SIMPLEX);
@@ -215,11 +209,9 @@ ukswitch_attach(device_t dev)
if (err != 0)
return (err);
- bus_generic_probe(dev);
+ bus_identify_children(dev);
bus_enumerate_hinted_children(dev);
- err = bus_generic_attach(dev);
- if (err != 0)
- return (err);
+ bus_attach_children(dev);
callout_init(&sc->callout_tick, 0);
@@ -232,7 +224,11 @@ static int
ukswitch_detach(device_t dev)
{
struct ukswitch_softc *sc = device_get_softc(dev);
- int i, port;
+ int error, i, port;
+
+ error = bus_generic_detach(dev);
+ if (error != 0)
+ return (error);
callout_drain(&sc->callout_tick);
@@ -240,8 +236,6 @@ ukswitch_detach(device_t dev)
if (((1 << i) & sc->phymask) == 0)
continue;
port = ukswitch_portforphy(sc, i);
- if (sc->miibus[port] != NULL)
- device_delete_child(dev, (*sc->miibus[port]));
if (sc->ifp[port] != NULL)
if_free(sc->ifp[port]);
free(sc->ifname[port], M_UKSWITCH);
@@ -253,7 +247,6 @@ ukswitch_detach(device_t dev)
free(sc->ifname, M_UKSWITCH);
free(sc->ifp, M_UKSWITCH);
- bus_generic_detach(dev);
mtx_destroy(&sc->sc_mtx);
return (0);
@@ -514,7 +507,7 @@ ukswitch_writephy(device_t dev, int phy, int reg, int data)
static int
ukswitch_readreg(device_t dev, int addr)
{
- struct ukswitch_softc *sc;
+ struct ukswitch_softc *sc __diagused;
sc = device_get_softc(dev);
UKSWITCH_LOCK_ASSERT(sc, MA_OWNED);
@@ -526,7 +519,7 @@ ukswitch_readreg(device_t dev, int addr)
static int
ukswitch_writereg(device_t dev, int addr, int value)
{
- struct ukswitch_softc *sc;
+ struct ukswitch_softc *sc __diagused;
sc = device_get_softc(dev);
UKSWITCH_LOCK_ASSERT(sc, MA_OWNED);