From nobody Tue Aug 09 14:48:14 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4M2GCM01D3z4Y3sL; Tue, 9 Aug 2022 14:48:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4M2GCL6ChRz46nr; Tue, 9 Aug 2022 14:48:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660056494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AMKxaoPxJ8VWe6KdcQVv0ycWhQeITzkGAgMva+7eE8Q=; b=ANaW5todpvnIldlZTD1Xk8elm+mml2AwO5mJKfJikC9JBC1RYDteNnwTryU/D5unj+G4Ya BaMEBqee8jzXzQ8nC61Tt13bCnXRtAr4fwJwxhboSXbEvMG+lPFyyVgI1teWWbodhxc7LL KEjEVW+u/GYCl1tD/vq8f3CyEvYftCIsMQKKn4Jaaa/GVzQhOalBRogMTjRx/JJ/1oX1wT sjQOTnszNTdeg7tS/g84eE6sbQ070blAiuMT/N91tvlnIU7l8OFQQ1e+VmoIWdvXtPAzHI jG0rfqPFArrAEtG23ILPeLw0oTuqqHFYEXv+I220LXGYtlXgdYx6OSsP7rQ6Hw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4M2GCL5GxJzb2F; Tue, 9 Aug 2022 14:48:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 279EmEjA098929; Tue, 9 Aug 2022 14:48:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 279EmEAX098928; Tue, 9 Aug 2022 14:48:14 GMT (envelope-from git) Date: Tue, 9 Aug 2022 14:48:14 GMT Message-Id: <202208091448.279EmEAX098928@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: adff82ea35b7 - main - Add the PHY driver for the Marvell 88E1512. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: adff82ea35b77a2961376f0806794698d97ed018 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660056494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AMKxaoPxJ8VWe6KdcQVv0ycWhQeITzkGAgMva+7eE8Q=; b=n/JEy9LboGi6PyetDoxxB3QIjfxFXiBQB40lqlW+9AIblbqR5fDUCasNTbVrvLEQJ93/NI Wp6agfcy0qYAI3/kh7pKku4JX3gxkKqBIaSDoRyy68rhgxEY8tYWoLiC20FE0u83hJrsdV wqIJbUr0e5u5coW7cLfl4jLkYSROp8FjQGyVCowS+FOm/Yejcn6uB8QTkHIrNqLte+qQy7 y5xmOLmXqDZDqHuNbj0eyLUePqZ/NhD94PdObDBpIZpbW+WRsucEeNNIAhSOC6TrATl7Ny S349R56neMBNoeRZx143mFP1XuHeq1ZjLA7aCElu50pRp7dYqH6MOVCyG2Z9qg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660056494; a=rsa-sha256; cv=none; b=t9zoyh4CQxAdJenXsyaqVqiUKf1MpStsE6/MTXrs/HEz10mWdfWUSmFncOSpeKF631RSDl iCOPZkXBI4D1rbC3Mc24QNnPbIKVdA7thbU3MN1JvLmmp1CuCTz2x7BjjWl2ryIK7+6sF8 2UoaN9e+vaZ3kKQK6EdkUuvXkbDCuepW7I68UHRbnQkm/fb0rk/DHYOgZDEzA47uM9sXJk Goc/d6CbxnzRQEphQR5Yyt0j7xZ3YHkRH6+MbdPYfZDLmM3ZXomRw3mVWX7lv6SCaxrJtu XBSh3lNYGsHBMZUxPodEjCkmVWXHeKrLMafDwd3c5MC9S/6JwLtNo69dYC1ZiA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=adff82ea35b77a2961376f0806794698d97ed018 commit adff82ea35b77a2961376f0806794698d97ed018 Author: Luiz Souza AuthorDate: 2022-07-29 15:43:56 +0000 Commit: Kristof Provost CommitDate: 2022-08-09 13:59:22 +0000 Add the PHY driver for the Marvell 88E1512. This driver supports the auto negotiation mode between the copper and fiber ports. This PHY has two independent PHYs (one for copper and other for fiber) but in this case the functionality is presented as a single PHY for easy management. Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/conf/files | 1 + sys/dev/mii/miidevs | 1 + sys/dev/mii/mv88e151x.c | 268 +++++++++++++++++++++++++++++++++++++++++++++ sys/dev/mii/mv88e151xreg.h | 49 +++++++++ 4 files changed, 319 insertions(+) diff --git a/sys/conf/files b/sys/conf/files index bca5c127b525..93437e711886 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -2434,6 +2434,7 @@ dev/mii/mii_bitbang.c optional miibus | mii_bitbang dev/mii/mii_physubr.c optional miibus | mii dev/mii/mii_fdt.c optional miibus fdt | mii fdt dev/mii/miibus_if.m optional miibus | mii +dev/mii/mv88e151x.c optional miibus | mv88e151x dev/mii/nsgphy.c optional miibus | nsgphy dev/mii/nsphy.c optional miibus | nsphy dev/mii/nsphyter.c optional miibus | nsphyter diff --git a/sys/dev/mii/miidevs b/sys/dev/mii/miidevs index 579d6ef2d4e4..1ef40a9b116d 100644 --- a/sys/dev/mii/miidevs +++ b/sys/dev/mii/miidevs @@ -272,6 +272,7 @@ model xxMARVELL E1112 0x0009 Marvell 88E1112 Gigabit PHY model xxMARVELL E1149 0x000b Marvell 88E1149 Gigabit PHY model xxMARVELL E1111 0x000c Marvell 88E1111 Gigabit PHY model xxMARVELL E1145 0x000d Marvell 88E1145 Quad Gigabit PHY +model xxMARVELL E1512 0x001d Marvell 88E1512 Gigabit PHY model xxMARVELL E1116 0x0021 Marvell 88E1116 Gigabit PHY model xxMARVELL E1116R 0x0024 Marvell 88E1116R Gigabit PHY model xxMARVELL E1118 0x0022 Marvell 88E1118 Gigabit PHY diff --git a/sys/dev/mii/mv88e151x.c b/sys/dev/mii/mv88e151x.c new file mode 100644 index 000000000000..9a15cf9238ab --- /dev/null +++ b/sys/dev/mii/mv88e151x.c @@ -0,0 +1,268 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-NetBSD + * + * Copyright (c) 2019 Rubicon Communications, LLC (Netgate) + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center, and by Frank van der Linden. + * + * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* Driver for the Marvell 88e151x gigabit ethernet PHY. */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include "miidevs.h" + +#include "miibus_if.h" + +static int mv88e151x_probe(device_t); +static int mv88e151x_attach(device_t); + +static device_method_t mv88e151x_methods[] = { + /* device interface */ + DEVMETHOD(device_probe, mv88e151x_probe), + DEVMETHOD(device_attach, mv88e151x_attach), + DEVMETHOD(device_detach, mii_phy_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + DEVMETHOD_END +}; + +static devclass_t mv88e151x_devclass; + +static driver_t mv88e151x_driver = { + "mv88e151x", + mv88e151x_methods, + sizeof(struct mii_softc) +}; + +DRIVER_MODULE(mv88e151x, miibus, mv88e151x_driver, mv88e151x_devclass, 0, 0); + +static int mv88e151x_service(struct mii_softc *, struct mii_data *, int); +static void mv88e151x_status(struct mii_softc *); + +static const struct mii_phydesc mv88e151xphys[] = { + MII_PHY_DESC(xxMARVELL, E1512), + MII_PHY_END +}; + +static const struct mii_phy_funcs mv88e151x_funcs = { + mv88e151x_service, + mv88e151x_status, + mii_phy_reset +}; + +static int +mv88e151x_probe(device_t dev) +{ + + return (mii_phy_dev_probe(dev, mv88e151xphys, BUS_PROBE_DEFAULT)); +} + +static int +mv88e151x_attach(device_t dev) +{ + const struct mii_attach_args *ma; + struct mii_softc *sc; + uint32_t cop_cap, cop_extcap; + + sc = device_get_softc(dev); + ma = device_get_ivars(dev); + + mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &mv88e151x_funcs, 0); + + PHY_RESET(sc); + sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask; + cop_cap = sc->mii_capabilities; + if (sc->mii_capabilities & BMSR_EXTSTAT) { + sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR); + cop_extcap = sc->mii_extcapabilities; + } + device_printf(dev, " "); + if (MII_MODEL(ma->mii_id2) == MII_MODEL_xxMARVELL_E1512) + sc->mii_capabilities &= ~BMSR_ANEG; + mii_phy_add_media(sc); + if (MII_MODEL(ma->mii_id2) == MII_MODEL_xxMARVELL_E1512) { + /* Switch the fiber PHY and add the supported media. */ + PHY_WRITE(sc, MV88E151X_PAGE, MV88E151X_PAGE_FIBER); + PHY_RESET(sc); + sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask; + if (sc->mii_capabilities & BMSR_EXTSTAT) + sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR); + sc->mii_flags |= MIIF_NOISOLATE; + printf(", "); + mii_phy_add_media(sc); + + /* Switch back to copper PHY. */ + PHY_WRITE(sc, MV88E151X_PAGE, MV88E151X_PAGE_COPPER); + sc->mii_flags &= ~MIIF_NOISOLATE; + sc->mii_capabilities = cop_cap; + sc->mii_extcapabilities = cop_extcap; + } + printf("\n"); + + MIIBUS_MEDIAINIT(sc->mii_dev); + + mii_phy_setmedia(sc); + + /* Enable the fiber PHY auto negotiation. */ + if (MII_MODEL(ma->mii_id2) == MII_MODEL_xxMARVELL_E1512) { + PHY_WRITE(sc, MV88E151X_PAGE, MV88E151X_PAGE_FIBER); + PHY_WRITE(sc, MII_BMCR, BMCR_RESET | BMCR_AUTOEN | + BMCR_STARTNEG | BMCR_FDX | BMCR_S1000); + PHY_WRITE(sc, MV88E151X_PAGE, MV88E151X_PAGE_COPPER); + } + + return (0); +} + +static int +mv88e151x_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +{ + switch (cmd) { + case MII_POLLSTAT: + break; + + case MII_MEDIACHG: + mii_phy_setmedia(sc); + break; + + case MII_TICK: + if (mii_phy_tick(sc) == EJUSTRETURN) + return (0); + break; + } + + /* Update the media status. */ + PHY_STATUS(sc); + + /* Callback if something changed. */ + mii_phy_update(sc, cmd); + return (0); +} + +static void +mv88e151x_fiber_status(struct mii_softc *phy) +{ + struct mii_data *mii = phy->mii_pdata; + struct ifmedia_entry *ife = mii->mii_media.ifm_cur; + int bmsr, bmcr, anlpar; //, gtcr, gtsr; + uint32_t reg; + + mii->mii_media_status = IFM_AVALID; + mii->mii_media_active = IFM_ETHER; + + /* Switch to the fiber PHY. */ + PHY_WRITE(phy, MV88E151X_PAGE, MV88E151X_PAGE_FIBER); + + reg = PHY_READ(phy, MV88E151X_FIBER_STATUS); + bmsr = PHY_READ(phy, MII_BMSR) | PHY_READ(phy, MII_BMSR); + if (reg & MV88E151X_STATUS_LINK) + mii->mii_media_status |= IFM_ACTIVE; + bmcr = PHY_READ(phy, MII_BMCR); + if (bmcr & BMCR_ISO) { + mii->mii_media_active |= IFM_NONE; + mii->mii_media_status = 0; + PHY_WRITE(phy, MV88E151X_PAGE, MV88E151X_PAGE_COPPER); + return; + } + + if (bmcr & BMCR_LOOP) + mii->mii_media_active |= IFM_LOOP; + + if (bmcr & BMCR_AUTOEN) { + /* + * NWay autonegotiation takes the highest-order common + * bit of the ANAR and ANLPAR (i.e. best media advertised + * both by us and our link partner). + */ + if ((bmsr & BMSR_ACOMP) == 0) { + /* Erg, still trying, I guess... */ + mii->mii_media_active |= IFM_NONE; + PHY_WRITE(phy, MV88E151X_PAGE, MV88E151X_PAGE_COPPER); + return; + } + + anlpar = PHY_READ(phy, MII_ANAR) & PHY_READ(phy, MII_ANLPAR); + if (anlpar & ANLPAR_X_FD) + mii->mii_media_active |= IFM_1000_SX | IFM_FDX; + else if (anlpar & ANLPAR_X_HD) + mii->mii_media_active |= IFM_1000_SX | IFM_HDX; + else if (reg & MV88E151X_STATUS_LINK && + reg & MV88E151X_STATUS_SYNC && + (reg & MV88E151X_STATUS_ENERGY) == 0) { + if ((reg & MV88E151X_STATUS_SPEED_MASK) == + MV88E151X_STATUS_SPEED_1000) + mii->mii_media_active |= IFM_1000_SX; + else if ((reg & MV88E151X_STATUS_SPEED_MASK) == + MV88E151X_STATUS_SPEED_100) + mii->mii_media_active |= IFM_100_FX; + else + mii->mii_media_active |= IFM_NONE; + if ((reg & MV88E151X_STATUS_SPEED_MASK) != 0 && + (reg & MV88E151X_STATUS_FDX)) + mii->mii_media_active |= IFM_FDX; + } else + mii->mii_media_active |= IFM_NONE; + + if ((mii->mii_media_active & IFM_NONE) == 0) + phy->mii_flags |= MIIF_IS_1000X; + if ((mii->mii_media_active & IFM_FDX) != 0) + mii->mii_media_active |= mii_phy_flowstatus(phy); + } else + mii->mii_media_active = ife->ifm_media; + + if ((mii->mii_media_status & IFM_ACTIVE) == 0) + phy->mii_flags &= ~MIIF_IS_1000X; + + /* Switch back to copper PHY. */ + PHY_WRITE(phy, MV88E151X_PAGE, MV88E151X_PAGE_COPPER); +} + +static void +mv88e151x_status(struct mii_softc *phy) +{ + struct mii_data *mii = phy->mii_pdata; + + mv88e151x_fiber_status(phy); + if (mii->mii_media_status & IFM_ACTIVE) + return; + ukphy_status(phy); +} diff --git a/sys/dev/mii/mv88e151xreg.h b/sys/dev/mii/mv88e151xreg.h new file mode 100644 index 000000000000..95e17caaa83e --- /dev/null +++ b/sys/dev/mii/mv88e151xreg.h @@ -0,0 +1,49 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-NetBSD + * + * Copyright (c) 2019 Rubicon Communications, LLC (Netgate). + * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 _DEV_MII_MV88E151XREG_H_ +#define _DEV_MII_MV88E151XREG_H_ + +#define MV88E151X_FIBER_STATUS 17 +#define MV88E151X_STATUS_SPEED_MASK 0xc000 +#define MV88E151X_STATUS_SPEED_SHIFT 14 +#define MV88E151X_STATUS_SPEED_1000 2 +#define MV88E151X_STATUS_SPEED_100 1 +#define MV88E151X_STATUS_SPEED_10 0 +#define MV88E151X_STATUS_FDX (1 << 13) +#define MV88E151X_STATUS_RESOLVED (1 << 11) +#define MV88E151X_STATUS_LINK (1 << 10) +#define MV88E151X_STATUS_SYNC (1 << 5) +#define MV88E151X_STATUS_ENERGY (1 << 4) +#define MV88E151X_PAGE 22 +#define MV88E151X_PAGE_COPPER 0 +#define MV88E151X_PAGE_FIBER 1 + +#endif /* _DEV_MII_MV88E151XREG_H_ */