The following diff adds a basic PHY for Axis dongles. Changes: ukphy0 at axe0 phy 16: Generic IEEE 802.3u media interface, rev. 1: OUI 0x000ec6, model 0x0001 ukphy0 at axe0 phy 16: Generic IEEE 802.3u media interface, rev. 1: OUI 0x000ec6, model 0x0008
To: axphy0 at axe0 phy 16: AX88772 10/100 PHY, rev. 1 axphy0 at axe0 phy 16: AX88772B 10/100 PHY, rev. 1 Tested on landisk and amd64. Okay? Index: dev/mii/axphy.c =================================================================== RCS file: dev/mii/axphy.c diff -N dev/mii/axphy.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dev/mii/axphy.c 22 Oct 2015 22:03:32 -0000 @@ -0,0 +1,174 @@ +/* $OpenBSD$ */ + +/* + * Copyright (c) 2015 Paul Irofti <piro...@openbsd.org> + * + * Permission to use, copy, modify, and/or 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. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/device.h> +#include <sys/socket.h> +#include <sys/errno.h> + +#include <net/if.h> +#include <net/if_var.h> +#include <net/if_media.h> + +#include <dev/mii/mii.h> +#include <dev/mii/miivar.h> +#include <dev/mii/miidevs.h> + +struct axphy_softc { + struct mii_softc sc_mii; /* common mii device part */ + + uint8_t sc_current_page; +}; + +int axphymatch(struct device *, void *, void *); +void axphyattach(struct device *, struct device *, void *); + +struct cfattach axphy_ca = { sizeof(struct axphy_softc), + axphymatch, axphyattach, mii_phy_detach, +}; + +struct cfdriver axphy_cd = { + NULL, "axphy", DV_DULL +}; + +int axphy_service(struct mii_softc *, struct mii_data *, int); +void axphy_status(struct mii_softc *); +void axphy_reset(struct mii_softc *); + +const struct mii_phy_funcs axphy_funcs = { + axphy_service, ukphy_status, mii_phy_reset, +}; + +static const struct mii_phydesc axphys[] = { + { MII_OUI_ASIX, MII_MODEL_ASIX_AX88772, + MII_STR_ASIX_AX88772 }, + { MII_OUI_ASIX, MII_MODEL_ASIX_AX88772B, + MII_STR_ASIX_AX88772B }, + + { 0, 0, + NULL }, +}; + +int +axphymatch(struct device *parent, void *match, void *aux) +{ + struct mii_attach_args *ma = aux; + + if (mii_phy_match(ma, axphys) != NULL) + return (10); + + return (0); +} + +void +axphyattach(struct device *parent, struct device *self, void *aux) +{ + struct axphy_softc *bsc = (struct axphy_softc *)self; + struct mii_softc *sc = &bsc->sc_mii; + struct mii_attach_args *ma = aux; + struct mii_data *mii = ma->mii_data; + const struct mii_phydesc *mpd; + + mpd = mii_phy_match(ma, axphys); + printf(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2)); + + sc->mii_inst = mii->mii_instance; + sc->mii_phy = ma->mii_phyno; + sc->mii_funcs = &axphy_funcs; + sc->mii_model = MII_MODEL(ma->mii_id2); + sc->mii_rev = MII_REV(ma->mii_id2); + sc->mii_pdata = mii; + sc->mii_flags = ma->mii_flags; + sc->mii_anegticks = MII_ANEGTICKS_GIGE; + + sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP; + + sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask; + + if (sc->mii_capabilities & BMSR_EXTSTAT) + sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR); + if ((sc->mii_capabilities & BMSR_MEDIAMASK) || + (sc->mii_extcapabilities & EXTSR_MEDIAMASK)) + mii_phy_add_media(sc); + + PHY_RESET(sc); +} + +int +axphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +{ + struct ifmedia_entry *ife = mii->mii_media.ifm_cur; + int reg; + + if ((sc->mii_dev.dv_flags & DVF_ACTIVE) == 0) + return (ENXIO); + + switch (cmd) { + case MII_POLLSTAT: + /* + * If we're not polling our PHY instance, just return. + */ + if (IFM_INST(ife->ifm_media) != sc->mii_inst) + return (0); + break; + + case MII_MEDIACHG: + /* + * If the media indicates a different PHY instance, + * isolate ourselves. + */ + if (IFM_INST(ife->ifm_media) != sc->mii_inst) { + reg = PHY_READ(sc, MII_BMCR); + PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO); + return (0); + } + + /* + * If the interface is not up, don't do anything. + */ + if ((mii->mii_ifp->if_flags & IFF_UP) == 0) + break; + + mii_phy_setmedia(sc); + break; + + case MII_TICK: + /* + * If we're not currently selected, just return. + */ + if (IFM_INST(ife->ifm_media) != sc->mii_inst) + return (0); + + if (mii_phy_tick(sc) == EJUSTRETURN) + return (0); + break; + + case MII_DOWN: + mii_phy_down(sc); + return (0); + } + + /* Update the media status. */ + mii_phy_status(sc); + + /* Callback if something changed. */ + mii_phy_update(sc, cmd); + return (0); +} Index: dev/mii/files.mii =================================================================== RCS file: /cvs/src/sys/dev/mii/files.mii,v retrieving revision 1.32 diff -u -p -r1.32 files.mii --- dev/mii/files.mii 6 May 2014 17:09:02 -0000 1.32 +++ dev/mii/files.mii 22 Oct 2015 22:03:32 -0000 @@ -148,3 +148,7 @@ file dev/mii/mlphy.c mlphy device brswphy: mii_phy attach brswphy at mii file dev/mii/brswphy.c brswphy + +device axphy: mii_phy +attach axphy at mii +file dev/mii/axphy.c axphy Index: dev/mii/miidevs =================================================================== RCS file: /cvs/src/sys/dev/mii/miidevs,v retrieving revision 1.124 diff -u -p -r1.124 miidevs --- dev/mii/miidevs 19 Jul 2015 06:30:02 -0000 1.124 +++ dev/mii/miidevs 22 Oct 2015 22:03:32 -0000 @@ -117,6 +117,10 @@ model AMD 79C873phy 0x0036 Am79C873 int /* Agere PHYs */ model AGERE ET1011 0x0004 ET1011 10/100/1000baseT PHY +/* Asix PHYs */ +model ASIX AX88772 0x0001 AX88772 10/100 PHY +model ASIX AX88772B 0x0008 AX88772B 10/100 PHY + /* Atheros PHYs */ model ATHEROS F1 0x0001 F1 10/100/1000 PHY model ATHEROS F2 0x0002 F2 10/100 PHY Index: dev/mii/miidevs.h =================================================================== RCS file: /cvs/src/sys/dev/mii/miidevs.h,v retrieving revision 1.127 diff -u -p -r1.127 miidevs.h --- dev/mii/miidevs.h 19 Jul 2015 06:31:16 -0000 1.127 +++ dev/mii/miidevs.h 22 Oct 2015 22:03:32 -0000 @@ -1,4 +1,4 @@ -/* $OpenBSD: miidevs.h,v 1.127 2015/07/19 06:31:16 yuo Exp $ */ +/* $OpenBSD$ */ /* * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT. @@ -127,6 +127,12 @@ /* Agere PHYs */ #define MII_MODEL_AGERE_ET1011 0x0004 #define MII_STR_AGERE_ET1011 "ET1011 10/100/1000baseT PHY" + +/* Asix PHYs */ +#define MII_MODEL_ASIX_AX88772 0x0001 +#define MII_STR_ASIX_AX88772 "AX88772 10/100 PHY" +#define MII_MODEL_ASIX_AX88772B 0x0008 +#define MII_STR_ASIX_AX88772B "AX88772B 10/100 PHY" /* Atheros PHYs */ #define MII_MODEL_ATHEROS_F1 0x0001 Index: arch/amd64/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/amd64/conf/GENERIC,v retrieving revision 1.396 diff -u -p -r1.396 GENERIC --- arch/amd64/conf/GENERIC 10 Sep 2015 16:30:23 -0000 1.396 +++ arch/amd64/conf/GENERIC 22 Oct 2015 22:03:32 -0000 @@ -527,6 +527,7 @@ etphy* at mii? # Agere/LSI ET1011 Tru jmphy* at mii? # JMicron JMP202/JMP211 PHYs atphy* at mii? # Attansic F1 PHYs ipgphy* at mii? # IC Plus IP1000A PHYs +axphy* at mii? # Asix 10/100 PHYs ukphy* at mii? # "unknown" PHYs eap* at pci? # Ensoniq AudioPCI S5016 Index: arch/landisk/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/landisk/conf/GENERIC,v retrieving revision 1.49 diff -u -p -r1.49 GENERIC --- arch/landisk/conf/GENERIC 16 Apr 2015 09:09:49 -0000 1.49 +++ arch/landisk/conf/GENERIC 22 Oct 2015 22:03:32 -0000 @@ -66,6 +66,7 @@ eephy* at mii? # Marvell 88E1000 seri rgephy* at mii? # Realtek 8169S/8110S PHY rlphy* at mii? # Realtek 8139/8201L PHYs urlphy* at mii? # Realtek RTL8150L internal PHYs +axphy* at mii? # Asix 10/100 PHYs ukphy* at mii? # generic unknown PHYs # PCIIDE