summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2020-06-25 12:39:20 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2020-06-25 12:39:20 +0000
commitb902c8a8d5a8766808ab8ec43f229df4b84ba7a4 (patch)
tree6bc0b68ab41a9012d849a54435f10e60e695376f /sys
parent5428c71d9d351f3adb06b1981f91f2cb458807cc (diff)
Register mvmdio(4) in the MII "framework". On the Armada 7K and 8K
SoCs there can be multiple instances of mvmdio(4), with SMI or XSMI support. This replaces the mvmdio_sc global with a nicer FDT-based interface to retrieve the methods to access the MII bus. ok kettenis@
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/fdt/if_mvneta.c22
-rw-r--r--sys/dev/fdt/if_mvpp.c4
-rw-r--r--sys/dev/fdt/mvmdio.c22
-rw-r--r--sys/dev/fdt/mvmdiovar.h19
4 files changed, 26 insertions, 41 deletions
diff --git a/sys/dev/fdt/if_mvneta.c b/sys/dev/fdt/if_mvneta.c
index 5d917fbaa08..79e436d6607 100644
--- a/sys/dev/fdt/if_mvneta.c
+++ b/sys/dev/fdt/if_mvneta.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_mvneta.c,v 1.11 2020/06/22 02:23:21 dlg Exp $ */
+/* $OpenBSD: if_mvneta.c,v 1.12 2020/06/25 12:39:19 patrick Exp $ */
/* $NetBSD: if_mvneta.c,v 1.41 2015/04/15 10:15:40 hsuenaga Exp $ */
/*
* Copyright (c) 2007, 2008, 2013 KIYOHARA Takashi
@@ -50,7 +50,6 @@
#include <dev/ofw/fdt.h>
#include <dev/fdt/if_mvnetareg.h>
-#include <dev/fdt/mvmdiovar.h>
#ifdef __armv7__
#include <armv7/marvell/mvmbusvar.h>
@@ -128,7 +127,7 @@ struct mvneta_buf {
struct mvneta_softc {
struct device sc_dev;
- struct device *sc_mdio;
+ struct mii_bus *sc_mdio;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
@@ -164,6 +163,7 @@ struct mvneta_softc {
int sc_fixed_link;
int sc_inband_status;
int sc_phy;
+ int sc_phyloc;
int sc_link;
int sc_sfp;
};
@@ -220,14 +220,14 @@ int
mvneta_miibus_readreg(struct device *dev, int phy, int reg)
{
struct mvneta_softc *sc = (struct mvneta_softc *) dev;
- return mvmdio_miibus_readreg(sc->sc_mdio, phy, reg);
+ return sc->sc_mdio->md_readreg(sc->sc_mdio->md_cookie, phy, reg);
}
void
mvneta_miibus_writereg(struct device *dev, int phy, int reg, int val)
{
struct mvneta_softc *sc = (struct mvneta_softc *) dev;
- return mvmdio_miibus_writereg(sc->sc_mdio, phy, reg, val);
+ return sc->sc_mdio->md_writereg(sc->sc_mdio->md_cookie, phy, reg, val);
}
void
@@ -419,14 +419,14 @@ mvneta_attach(struct device *parent, struct device *self, void *aux)
}
if (!sc->sc_fixed_link) {
- node = OF_getnodebyphandle(OF_getpropint(faa->fa_node,
- "phy", 0));
+ sc->sc_phy = OF_getpropint(faa->fa_node, "phy", 0);
+ node = OF_getnodebyphandle(sc->sc_phy);
if (!node) {
printf("%s: cannot find phy in fdt\n", self->dv_xname);
return;
}
- if ((sc->sc_phy = OF_getpropint(node, "reg", -1)) == -1) {
+ if ((sc->sc_phyloc = OF_getpropint(node, "reg", -1)) == -1) {
printf("%s: cannot extract phy addr\n", self->dv_xname);
return;
}
@@ -645,15 +645,13 @@ mvneta_attach_deferred(struct device *self)
struct ifnet *ifp = &sc->sc_ac.ac_if;
if (!sc->sc_fixed_link) {
- extern void *mvmdio_sc;
- sc->sc_mdio = mvmdio_sc;
-
+ sc->sc_mdio = mii_byphandle(sc->sc_phy);
if (sc->sc_mdio == NULL) {
printf("%s: mdio bus not yet attached\n", self->dv_xname);
return;
}
- mii_attach(self, &sc->sc_mii, 0xffffffff, sc->sc_phy,
+ mii_attach(self, &sc->sc_mii, 0xffffffff, sc->sc_phyloc,
MII_OFFSET_ANY, 0);
if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
printf("%s: no PHY found!\n", self->dv_xname);
diff --git a/sys/dev/fdt/if_mvpp.c b/sys/dev/fdt/if_mvpp.c
index f48d17188e3..a657ac0e085 100644
--- a/sys/dev/fdt/if_mvpp.c
+++ b/sys/dev/fdt/if_mvpp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_mvpp.c,v 1.1 2020/06/25 12:09:11 patrick Exp $ */
+/* $OpenBSD: if_mvpp.c,v 1.2 2020/06/25 12:39:19 patrick Exp $ */
/*
* Copyright (c) 2008, 2019 Mark Kettenis <kettenis@openbsd.org>
* Copyright (c) 2017, 2020 Patrick Wildt <patrick@blueri.se>
@@ -184,7 +184,7 @@ struct mvpp2_port {
#define sc_lladdr sc_ac.ac_enaddr
struct mii_data sc_mii;
#define sc_media sc_mii.mii_media
- struct mii_device *sc_mdio;
+ struct mii_bus *sc_mdio;
char sc_cur_lladdr[ETHER_ADDR_LEN];
enum {
diff --git a/sys/dev/fdt/mvmdio.c b/sys/dev/fdt/mvmdio.c
index ffcafda915e..80fe623a3b5 100644
--- a/sys/dev/fdt/mvmdio.c
+++ b/sys/dev/fdt/mvmdio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mvmdio.c,v 1.1 2017/08/25 20:09:34 patrick Exp $ */
+/* $OpenBSD: mvmdio.c,v 1.2 2020/06/25 12:39:19 patrick Exp $ */
/* $NetBSD: if_mvneta.c,v 1.41 2015/04/15 10:15:40 hsuenaga Exp $ */
/*
* Copyright (c) 2007, 2008, 2013 KIYOHARA Takashi
@@ -37,7 +37,9 @@
#include <machine/fdt.h>
#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_clock.h>
#include <dev/ofw/ofw_pinctrl.h>
+#include <dev/ofw/ofw_misc.h>
#include <dev/ofw/fdt.h>
#include <dev/fdt/if_mvnetareg.h>
@@ -56,15 +58,14 @@ struct mvmdio_softc {
bus_space_handle_t sc_ioh;
struct mutex sc_mtx;
+ struct mii_bus sc_mii;
};
-struct mvmdio_softc *mvmdio_sc;
-
static int mvmdio_match(struct device *, void *, void *);
static void mvmdio_attach(struct device *, struct device *, void *);
-int mvmdio_miibus_readreg(struct device *, int, int);
-void mvmdio_miibus_writereg(struct device *, int, int, int);
+int mvmdio_smi_readreg(struct device *, int, int);
+void mvmdio_smi_writereg(struct device *, int, int, int);
struct cfdriver mvmdio_cd = {
NULL, "mvmdio", DV_DULL
@@ -96,14 +97,19 @@ mvmdio_attach(struct device *parent, struct device *self, void *aux)
panic("%s: cannot map registers", sc->sc_dev.dv_xname);
pinctrl_byname(faa->fa_node, "default");
+ clock_enable_all(faa->fa_node);
mtx_init(&sc->sc_mtx, IPL_NET);
- mvmdio_sc = sc;
+ sc->sc_mii.md_node = faa->fa_node;
+ sc->sc_mii.md_cookie = sc;
+ sc->sc_mii.md_readreg = mvmdio_smi_readreg;
+ sc->sc_mii.md_writereg = mvmdio_smi_writereg;
+ mii_register(&sc->sc_mii);
}
int
-mvmdio_miibus_readreg(struct device *dev, int phy, int reg)
+mvmdio_smi_readreg(struct device *dev, int phy, int reg)
{
struct mvmdio_softc *sc = (struct mvmdio_softc *) dev;
uint32_t smi, val;
@@ -141,7 +147,7 @@ mvmdio_miibus_readreg(struct device *dev, int phy, int reg)
}
void
-mvmdio_miibus_writereg(struct device *dev, int phy, int reg, int val)
+mvmdio_smi_writereg(struct device *dev, int phy, int reg, int val)
{
struct mvmdio_softc *sc = (struct mvmdio_softc *) dev;
uint32_t smi;
diff --git a/sys/dev/fdt/mvmdiovar.h b/sys/dev/fdt/mvmdiovar.h
deleted file mode 100644
index 920e007c78e..00000000000
--- a/sys/dev/fdt/mvmdiovar.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* $OpenBSD: mvmdiovar.h,v 1.1 2017/08/25 20:09:34 patrick Exp $ */
-/*
- * Copyright (c) 2015 Patrick Wildt <patrick@blueri.se>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-int mvmdio_miibus_readreg(struct device *, int, int);
-void mvmdio_miibus_writereg(struct device *, int, int, int);