diff --git a/sys/contrib/octeon-sdk/cvmx-helper-board.c b/sys/contrib/octeon-sdk/cvmx-helper-board.c index 5bf29904779c..cca2b22bd76d 100644 --- a/sys/contrib/octeon-sdk/cvmx-helper-board.c +++ b/sys/contrib/octeon-sdk/cvmx-helper-board.c @@ -181,10 +181,11 @@ int cvmx_helper_board_get_mii_address(int ipd_port) /* Private vendor-defined boards. */ #if defined(OCTEON_VENDOR_LANNER) case CVMX_BOARD_TYPE_CUST_LANNER_MR320: + /* Port 0 is a Marvell 88E6161 switch, ports 1 and 2 are Marvell + 88E1111 interfaces. */ switch (ipd_port) { case 0: - /* XXX Switch PHY? */ - return -1; + return 16; case 1: return 1; case 2: diff --git a/sys/mips/cavium/files.octeon1 b/sys/mips/cavium/files.octeon1 index 34e7dfc875fc..7dcaa3203116 100644 --- a/sys/mips/cavium/files.octeon1 +++ b/sys/mips/cavium/files.octeon1 @@ -21,6 +21,7 @@ mips/cavium/cryptocteon/cavium_crypto.c optional cryptocteon mips/cavium/cryptocteon/cryptocteon.c optional cryptocteon mips/cavium/octe/ethernet.c optional octe +mips/cavium/octe/ethernet-mv88e61xx.c optional octe octeon_vendor_lanner mips/cavium/octe/ethernet-common.c optional octe mips/cavium/octe/ethernet-mdio.c optional octe mips/cavium/octe/ethernet-mem.c optional octe diff --git a/sys/mips/cavium/octe/cavium-ethernet.h b/sys/mips/cavium/octe/cavium-ethernet.h index d4727190aece..c240e8f1876f 100644 --- a/sys/mips/cavium/octe/cavium-ethernet.h +++ b/sys/mips/cavium/octe/cavium-ethernet.h @@ -72,6 +72,8 @@ typedef struct { uint8_t mac[6]; int phy_id; + int (*mdio_read)(struct ifnet *, int, int); + void (*mdio_write)(struct ifnet *, int, int, int); struct ifqueue tx_free_queue[16]; diff --git a/sys/mips/cavium/octe/ethernet-common.c b/sys/mips/cavium/octe/ethernet-common.c index 2ebbb09a017e..9db9830915e8 100644 --- a/sys/mips/cavium/octe/ethernet-common.c +++ b/sys/mips/cavium/octe/ethernet-common.c @@ -266,6 +266,20 @@ int cvm_oct_common_init(struct ifnet *ifp) memset(ifp->get_stats(ifp), 0, sizeof(struct ifnet_stats)); #endif + /* + * Do any last-minute board-specific initialization. + */ + switch (cvmx_sysinfo_get()->board_type) { +#if defined(OCTEON_VENDOR_LANNER) + case CVMX_BOARD_TYPE_CUST_LANNER_MR320: + if (priv->phy_id == 16) + cvm_oct_mv88e61xx_setup_device(ifp); + break; +#endif + default: + break; + } + device_attach(priv->dev); return 0; diff --git a/sys/mips/cavium/octe/ethernet-headers.h b/sys/mips/cavium/octe/ethernet-headers.h index ec87c4562883..3945e13ac678 100644 --- a/sys/mips/cavium/octe/ethernet-headers.h +++ b/sys/mips/cavium/octe/ethernet-headers.h @@ -40,4 +40,11 @@ AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR W #include "ethernet-tx.h" #include "ethernet-util.h" +/* + * Any board- or vendor-specific includes. + */ +#ifdef OCTEON_VENDOR_LANNER +#include "ethernet-mv88e61xx.h" +#endif + #endif diff --git a/sys/mips/cavium/octe/ethernet-mdio.c b/sys/mips/cavium/octe/ethernet-mdio.c index 0aff27e6f72c..8aeb8016d3a3 100644 --- a/sys/mips/cavium/octe/ethernet-mdio.c +++ b/sys/mips/cavium/octe/ethernet-mdio.c @@ -132,6 +132,8 @@ int cvm_oct_mdio_setup_device(struct ifnet *ifp) cvm_oct_private_t *priv = (cvm_oct_private_t *)ifp->if_softc; priv->phy_id = cvmx_helper_board_get_mii_address(priv->port); + priv->mdio_read = NULL; + priv->mdio_write = NULL; return 0; } diff --git a/sys/mips/cavium/octe/ethernet-mv88e61xx.c b/sys/mips/cavium/octe/ethernet-mv88e61xx.c new file mode 100644 index 000000000000..e53cbcc523fe --- /dev/null +++ b/sys/mips/cavium/octe/ethernet-mv88e61xx.c @@ -0,0 +1,151 @@ +/*- + * Copyright (c) 2010 Juli Mallett + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Interface to the Marvell 88E61XX SMI/MDIO. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include "wrapper-cvmx-includes.h" +#include "ethernet-headers.h" + +#define MV88E61XX_SMI_PHY_SW 0x10 /* Switch PHY. */ + +#define MV88E61XX_SMI_REG_CMD 0x00 /* Indirect command register. */ +#define MV88E61XX_SMI_CMD_BUSY 0x8000 /* Busy bit. */ +#define MV88E61XX_SMI_CMD_22 0x1000 /* Clause 22 (default 45.) */ +#define MV88E61XX_SMI_CMD_READ 0x0800 /* Read command. */ +#define MV88E61XX_SMI_CMD_WRITE 0x0400 /* Write command. */ +#define MV88E61XX_SMI_CMD_PHY(phy) (((phy) & 0x1f) << 5) +#define MV88E61XX_SMI_CMD_REG(reg) ((reg) & 0x1f) + +#define MV88E61XX_SMI_REG_DAT 0x01 /* Indirect data register. */ + +static int cvm_oct_mv88e61xx_mdio_read(struct ifnet *, int, int); +static void cvm_oct_mv88e61xx_mdio_write(struct ifnet *, int, int, int); +static int cvm_oct_mv88e61xx_smi_read(struct ifnet *, int, int); +static void cvm_oct_mv88e61xx_smi_write(struct ifnet *, int, int, int); +static int cvm_oct_mv88e61xx_smi_wait(struct ifnet *, int); + +int +cvm_oct_mv88e61xx_setup_device(struct ifnet *ifp) +{ + cvm_oct_private_t *priv = (cvm_oct_private_t *)ifp->if_softc; + + priv->mdio_read = cvm_oct_mv88e61xx_mdio_read; + priv->mdio_write = cvm_oct_mv88e61xx_mdio_write; + + return (0); +} + +static int +cvm_oct_mv88e61xx_mdio_read(struct ifnet *ifp, int phy_id, int location) +{ + /* + * Intercept reads of MII_BMSR. The miibus uses this to determine + * PHY presence and we only want it to look for a PHY attachment + * for the switch PHY itself. The PHY driver will talk to all of + * the other ports as need be. + */ + switch (location) { + case MII_BMSR: + if (phy_id != MV88E61XX_SMI_PHY_SW) + return (0); + return (BMSR_EXTSTAT | BMSR_ACOMP | BMSR_LINK); + default: + return (cvm_oct_mv88e61xx_smi_read(ifp, phy_id, location)); + } +} + +static void +cvm_oct_mv88e61xx_mdio_write(struct ifnet *ifp, int phy_id, int location, int val) +{ + return (cvm_oct_mv88e61xx_smi_write(ifp, phy_id, location, val)); +} + +static int +cvm_oct_mv88e61xx_smi_read(struct ifnet *ifp, int phy_id, int location) +{ + int error; + + error = cvm_oct_mv88e61xx_smi_wait(ifp, phy_id); + if (error != 0) + return (0); + + cvm_oct_mdio_write(ifp, phy_id, MV88E61XX_SMI_REG_CMD, + MV88E61XX_SMI_CMD_BUSY | MV88E61XX_SMI_CMD_22 | + MV88E61XX_SMI_CMD_READ | MV88E61XX_SMI_CMD_PHY(phy_id) | + MV88E61XX_SMI_CMD_REG(location)); + + error = cvm_oct_mv88e61xx_smi_wait(ifp, phy_id); + if (error != 0) + return (0); + + return (cvm_oct_mdio_read(ifp, phy_id, MV88E61XX_SMI_REG_DAT)); +} + +static void +cvm_oct_mv88e61xx_smi_write(struct ifnet *ifp, int phy_id, int location, int val) +{ + cvm_oct_mv88e61xx_smi_wait(ifp, phy_id); + cvm_oct_mdio_write(ifp, phy_id, MV88E61XX_SMI_REG_DAT, val); + cvm_oct_mdio_write(ifp, phy_id, MV88E61XX_SMI_REG_CMD, + MV88E61XX_SMI_CMD_BUSY | MV88E61XX_SMI_CMD_22 | + MV88E61XX_SMI_CMD_WRITE | MV88E61XX_SMI_CMD_PHY(phy_id) | + MV88E61XX_SMI_CMD_REG(location)); + cvm_oct_mv88e61xx_smi_wait(ifp, phy_id); +} + +static int +cvm_oct_mv88e61xx_smi_wait(struct ifnet *ifp, int phy_id) +{ + uint16_t cmd; + unsigned i; + + for (i = 0; i < 10000; i++) { + cmd = cvm_oct_mdio_read(ifp, phy_id, MV88E61XX_SMI_REG_CMD); + if ((cmd & MV88E61XX_SMI_CMD_BUSY) == 0) + return (0); + } + return (ETIMEDOUT); +} diff --git a/sys/mips/cavium/octe/ethernet-mv88e61xx.h b/sys/mips/cavium/octe/ethernet-mv88e61xx.h new file mode 100644 index 000000000000..b61c05494d98 --- /dev/null +++ b/sys/mips/cavium/octe/ethernet-mv88e61xx.h @@ -0,0 +1,34 @@ +/*- + * Copyright (c) 2010 Juli Mallett + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _CAVIUM_OCTE_ETHERNET_MV88E61XX_H_ +#define _CAVIUM_OCTE_ETHERNET_MV88E61XX_H_ + +int cvm_oct_mv88e61xx_setup_device(struct ifnet *ifp); + +#endif /* !_CAVIUM_OCTE_ETHERNET_MV88E61XX_H_ */ diff --git a/sys/mips/cavium/octe/octe.c b/sys/mips/cavium/octe/octe.c index d693314777c7..407aceebcfd5 100644 --- a/sys/mips/cavium/octe/octe.c +++ b/sys/mips/cavium/octe/octe.c @@ -224,6 +224,15 @@ octe_miibus_readreg(device_t dev, int phy, int reg) priv = device_get_softc(dev); + /* + * Try interface-specific MII routine. + */ + if (priv->mdio_read != NULL) + return (priv->mdio_read(priv->ifp, phy, reg)); + + /* + * Try generic MII routine. + */ if (phy != priv->phy_id) return (0); @@ -237,9 +246,19 @@ octe_miibus_writereg(device_t dev, int phy, int reg, int val) priv = device_get_softc(dev); + /* + * Try interface-specific MII routine. + */ + if (priv->mdio_write != NULL) { + priv->mdio_write(priv->ifp, phy, reg, val); + return (0); + } + + /* + * Try generic MII routine. + */ KASSERT(phy == priv->phy_id, ("write to phy %u but our phy is %u", phy, priv->phy_id)); - cvm_oct_mdio_write(priv->ifp, phy, reg, val); return (0);