couple more changes to usbnet(9):

- MII read/write reg return int instead of usbd_status (requested by skrll)
- usbnet_attach_ifp(9) changes arg, two mii-specific flags are placed by a
  pointer to new struct usbnet_mii.  if not NULL, then attach an MII to this
  interface like previous have_mii parameter.  use this to allow ure(4) to
  properly pass PHY location to mii_attach().

welcome netbsd 9.99.10.
This commit is contained in:
mrg 2019-08-20 06:37:06 +00:00
parent dd6018f574
commit 65dae9683e
15 changed files with 184 additions and 152 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_axe.c,v 1.117 2019/08/19 07:33:37 mrg Exp $ */
/* $NetBSD: if_axe.c,v 1.118 2019/08/20 06:37:06 mrg Exp $ */
/* $OpenBSD: if_axe.c,v 1.137 2016/04/13 11:03:37 mpi Exp $ */
/*
@ -87,7 +87,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.117 2019/08/19 07:33:37 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.118 2019/08/20 06:37:06 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -259,8 +259,8 @@ CFATTACH_DECL_NEW(axe, sizeof(struct axe_softc),
static void axe_stop(struct ifnet *, int);
static int axe_ioctl(struct ifnet *, u_long, void *);
static int axe_init(struct ifnet *);
static usbd_status axe_mii_read_reg(struct usbnet *, int, int, uint16_t *);
static usbd_status axe_mii_write_reg(struct usbnet *, int, int, uint16_t);
static int axe_mii_read_reg(struct usbnet *, int, int, uint16_t *);
static int axe_mii_write_reg(struct usbnet *, int, int, uint16_t);
static void axe_mii_statchg(struct ifnet *);
static void axe_rx_loop(struct usbnet *, struct usbnet_chain *, uint32_t);
static unsigned axe_tx_prepare(struct usbnet *, struct mbuf *,
@ -313,7 +313,7 @@ axe_cmd(struct axe_softc *sc, int cmd, int index, int val, void *buf)
return err;
}
static usbd_status
static int
axe_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
{
AXEHIST_FUNC(); AXEHIST_CALLED();
@ -324,7 +324,7 @@ axe_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
DPRINTFN(30, "phy 0x%jx reg 0x%jx\n", phy, reg, 0, 0);
if (un->un_phyno != phy)
return USBD_INVAL;
return EINVAL;
axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL);
@ -333,7 +333,7 @@ axe_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
if (err) {
aprint_error_dev(un->un_dev, "read PHY failed\n");
return err;
return EIO;
}
*val = le16toh(data);
@ -349,10 +349,10 @@ axe_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
DPRINTFN(30, "phy 0x%jx reg 0x%jx val %#jx", phy, reg, *val, 0);
return USBD_NORMAL_COMPLETION;
return 0;
}
static usbd_status
static int
axe_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
{
struct axe_softc * const sc = usbnet_softc(un);
@ -360,7 +360,7 @@ axe_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
uint16_t aval;
if (un->un_phyno != phy)
return USBD_INVAL;
return EINVAL;
aval = htole16(val);
@ -368,7 +368,9 @@ axe_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
err = axe_cmd(sc, AXE_CMD_MII_WRITE_REG, reg, phy, &aval);
axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL);
return err;
if (err)
return EIO;
return 0;
}
static void
@ -861,6 +863,7 @@ void
axe_attach(device_t parent, device_t self, void *aux)
{
AXEHIST_FUNC(); AXEHIST_CALLED();
UBSNET_MII_DECL_DEFAULT(unm);
struct axe_softc *sc = device_private(self);
struct usbnet * const un = &sc->axe_un;
struct usb_attach_arg *uaa = aux;
@ -1009,8 +1012,9 @@ axe_attach(device_t parent, device_t self, void *aux)
adv_pause = 0;
adv_pause = 0;
usbnet_attach_ifp(un, true, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, adv_pause);
unm.un_mii_flags = adv_pause;
usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, &unm);
}
static void

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_axen.c,v 1.65 2019/08/19 07:33:37 mrg Exp $ */
/* $NetBSD: if_axen.c,v 1.66 2019/08/20 06:37:06 mrg Exp $ */
/* $OpenBSD: if_axen.c,v 1.3 2013/10/21 10:10:22 yuo Exp $ */
/*
@ -23,7 +23,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.65 2019/08/19 07:33:37 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.66 2019/08/20 06:37:06 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -80,8 +80,8 @@ static void axen_ax88179_init(struct usbnet *);
static void axen_stop_cb(struct ifnet *, int);
static int axen_ioctl_cb(struct ifnet *, u_long, void *);
static usbd_status axen_mii_read_reg(struct usbnet *, int, int, uint16_t *);
static usbd_status axen_mii_write_reg(struct usbnet *, int, int, uint16_t);
static int axen_mii_read_reg(struct usbnet *, int, int, uint16_t *);
static int axen_mii_write_reg(struct usbnet *, int, int, uint16_t);
static void axen_mii_statchg(struct ifnet *);
static void axen_rx_loop(struct usbnet *, struct usbnet_chain *, uint32_t);
static unsigned axen_tx_prepare(struct usbnet *, struct mbuf *,
@ -131,34 +131,38 @@ axen_cmd(struct usbnet *un, int cmd, int index, int val, void *buf)
return 0;
}
static usbd_status
static int
axen_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
{
uint16_t data;
if (un->un_phyno != phy)
return USBD_INVAL;
return EINVAL;
usbd_status err = axen_cmd(un, AXEN_CMD_MII_READ_REG, reg, phy, &data);
if (!err) {
*val = le16toh(data);
if (err)
return EIO;
if (reg == MII_BMSR)
*val &= ~BMSR_EXTCAP;
}
*val = le16toh(data);
if (reg == MII_BMSR)
*val &= ~BMSR_EXTCAP;
return err;
return 0;
}
static usbd_status
static int
axen_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
{
uint16_t uval = htole16(val);
if (un->un_phyno != phy)
return USBD_INVAL;
return EINVAL;
return axen_cmd(un, AXEN_CMD_MII_WRITE_REG, reg, phy, &uval);
usbd_status err = axen_cmd(un, AXEN_CMD_MII_WRITE_REG, reg, phy, &uval);
if (err)
return EIO;
return 0;
}
static void
@ -595,6 +599,7 @@ axen_match(device_t parent, cfdata_t match, void *aux)
static void
axen_attach(device_t parent, device_t self, void *aux)
{
UBSNET_MII_DECL_DEFAULT(unm);
struct usbnet * const un = device_private(self);
struct usb_attach_arg *uaa = aux;
struct usbd_device *dev = uaa->uaa_device;
@ -709,8 +714,8 @@ axen_attach(device_t parent, device_t self, void *aux)
IFCAP_CSUM_TCPv6_Rx | IFCAP_CSUM_TCPv6_Tx |
IFCAP_CSUM_UDPv6_Rx | IFCAP_CSUM_UDPv6_Tx;
usbnet_attach_ifp(un, true, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, 0);
usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, &unm);
}
static int

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_cdce.c,v 1.66 2019/08/15 05:52:23 mrg Exp $ */
/* $NetBSD: if_cdce.c,v 1.67 2019/08/20 06:37:06 mrg Exp $ */
/*
* Copyright (c) 1997, 1998, 1999, 2000-2003 Bill Paul <wpaul@windriver.com>
@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.66 2019/08/15 05:52:23 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.67 2019/08/20 06:37:06 mrg Exp $");
#include <sys/param.h>
@ -247,8 +247,8 @@ cdce_attach(device_t parent, device_t self, void *aux)
}
usbnet_attach(un, "cdcedet");
usbnet_attach_ifp(un, false, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, 0);
usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, NULL);
}
static int

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_cue.c,v 1.85 2019/08/15 08:02:32 mrg Exp $ */
/* $NetBSD: if_cue.c,v 1.86 2019/08/20 06:37:06 mrg Exp $ */
/*
* Copyright (c) 1997, 1998, 1999, 2000
@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_cue.c,v 1.85 2019/08/15 08:02:32 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_cue.c,v 1.86 2019/08/20 06:37:06 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -536,8 +536,8 @@ cue_attach(device_t parent, device_t self, void *aux)
*/
cue_getmac(un);
usbnet_attach_ifp(un, false, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, 0);
usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, NULL);
}
static void

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_kue.c,v 1.99 2019/08/18 11:46:38 mrg Exp $ */
/* $NetBSD: if_kue.c,v 1.100 2019/08/20 06:37:06 mrg Exp $ */
/*
* Copyright (c) 1997, 1998, 1999, 2000
@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_kue.c,v 1.99 2019/08/18 11:46:38 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_kue.c,v 1.100 2019/08/20 06:37:06 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -509,8 +509,8 @@ kue_attach(device_t parent, device_t self, void *aux)
sc->kue_mcfilters = kmem_alloc(KUE_MCFILTCNT(sc) * ETHER_ADDR_LEN,
KM_SLEEP);
usbnet_attach_ifp(un, false, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, 0);
usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, NULL);
}
int

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_mue.c,v 1.53 2019/08/19 07:33:37 mrg Exp $ */
/* $NetBSD: if_mue.c,v 1.54 2019/08/20 06:37:06 mrg Exp $ */
/* $OpenBSD: if_mue.c,v 1.3 2018/08/04 16:42:46 jsg Exp $ */
/*
@ -20,7 +20,7 @@
/* Driver for Microchip LAN7500/LAN7800 chipsets. */
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.53 2019/08/19 07:33:37 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.54 2019/08/20 06:37:06 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -99,8 +99,8 @@ static void mue_reset(struct usbnet *);
static void mue_stop_cb(struct ifnet *, int);
static int mue_ioctl_cb(struct ifnet *, u_long, void *);
static usbd_status mue_mii_read_reg(struct usbnet *, int, int, uint16_t *);
static usbd_status mue_mii_write_reg(struct usbnet *, int, int, uint16_t);
static int mue_mii_read_reg(struct usbnet *, int, int, uint16_t *);
static int mue_mii_write_reg(struct usbnet *, int, int, uint16_t);
static void mue_mii_statchg(struct ifnet *);
static void mue_rx_loop(struct usbnet *, struct usbnet_chain *, uint32_t);
static unsigned mue_tx_prepare(struct usbnet *, struct mbuf *,
@ -210,7 +210,7 @@ mue_wait_for_bits(struct usbnet *un, uint32_t reg,
return 1;
}
static usbd_status
static int
mue_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
{
uint32_t data;
@ -218,11 +218,11 @@ mue_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
usbnet_isowned_mii(un);
if (un->un_phyno != phy)
return USBD_INVAL;
return EINVAL;
if (MUE_WAIT_CLR(un, MUE_MII_ACCESS, MUE_MII_ACCESS_BUSY, 0)) {
MUE_PRINTF(un, "not ready\n");
return USBD_IN_USE;
return EBUSY;
}
mue_csr_write(un, MUE_MII_ACCESS, MUE_MII_ACCESS_READ |
@ -231,26 +231,26 @@ mue_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
if (MUE_WAIT_CLR(un, MUE_MII_ACCESS, MUE_MII_ACCESS_BUSY, 0)) {
MUE_PRINTF(un, "timed out\n");
return USBD_TIMEOUT;
return ETIMEDOUT;
}
data = mue_csr_read(un, MUE_MII_DATA);
*val = data & 0xffff;
return USBD_NORMAL_COMPLETION;
return 0;
}
static usbd_status
static int
mue_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
{
usbnet_isowned_mii(un);
if (un->un_phyno != phy)
return USBD_INVAL;
return EINVAL;
if (MUE_WAIT_CLR(un, MUE_MII_ACCESS, MUE_MII_ACCESS_BUSY, 0)) {
MUE_PRINTF(un, "not ready\n");
return USBD_IN_USE;
return EBUSY;
}
mue_csr_write(un, MUE_MII_DATA, val);
@ -260,10 +260,10 @@ mue_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
if (MUE_WAIT_CLR(un, MUE_MII_ACCESS, MUE_MII_ACCESS_BUSY, 0)) {
MUE_PRINTF(un, "timed out\n");
return USBD_TIMEOUT;
return ETIMEDOUT;
}
return USBD_NORMAL_COMPLETION;
return 0;
}
static void
@ -761,6 +761,7 @@ mue_match(device_t parent, cfdata_t match, void *aux)
static void
mue_attach(device_t parent, device_t self, void *aux)
{
UBSNET_MII_DECL_DEFAULT(unm);
struct usbnet * const un = device_private(self);
prop_dictionary_t dict = device_properties(self);
struct usb_attach_arg *uaa = aux;
@ -885,8 +886,8 @@ mue_attach(device_t parent, device_t self, void *aux)
ec->ec_capabilities = ETHERCAP_VLAN_MTU | ETHERCAP_JUMBO_MTU;
#endif
usbnet_attach_ifp(un, true, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, 0);
usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, &unm);
}
static unsigned

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_smsc.c,v 1.59 2019/08/19 07:33:37 mrg Exp $ */
/* $NetBSD: if_smsc.c,v 1.60 2019/08/20 06:37:06 mrg Exp $ */
/* $OpenBSD: if_smsc.c,v 1.4 2012/09/27 12:38:11 jsg Exp $ */
/* $FreeBSD: src/sys/dev/usb/net/if_smsc.c,v 1.1 2012/08/15 04:03:55 gonzo Exp $ */
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.59 2019/08/19 07:33:37 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.60 2019/08/20 06:37:06 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -184,8 +184,8 @@ static void smsc_miibus_statchg(struct ifnet *);
int smsc_readreg(struct usbnet *, uint32_t, uint32_t *);
int smsc_writereg(struct usbnet *, uint32_t, uint32_t);
int smsc_wait_for_bits(struct usbnet *, uint32_t, uint32_t);
usbd_status smsc_miibus_readreg(struct usbnet *, int, int, uint16_t *);
usbd_status smsc_miibus_writereg(struct usbnet *, int, int, uint16_t);
static int smsc_miibus_readreg(struct usbnet *, int, int, uint16_t *);
static int smsc_miibus_writereg(struct usbnet *, int, int, uint16_t);
static int smsc_ioctl_cb(struct ifnet *, u_long, void *);
static unsigned smsc_tx_prepare(struct usbnet *, struct mbuf *,
@ -274,7 +274,7 @@ smsc_wait_for_bits(struct usbnet *un, uint32_t reg, uint32_t bits)
return 1;
}
usbd_status
static int
smsc_miibus_readreg(struct usbnet *un, int phy, int reg, uint16_t *val)
{
uint32_t addr;
@ -283,11 +283,11 @@ smsc_miibus_readreg(struct usbnet *un, int phy, int reg, uint16_t *val)
usbnet_isowned_mii(un);
if (un->un_phyno != phy)
return USBD_INVAL;
return EINVAL;
if (smsc_wait_for_bits(un, SMSC_MII_ADDR, SMSC_MII_BUSY) != 0) {
smsc_warn_printf(un, "MII is busy\n");
return USBD_TIMEOUT;
return ETIMEDOUT;
}
addr = (phy << 11) | (reg << 6) | SMSC_MII_READ;
@ -295,16 +295,16 @@ smsc_miibus_readreg(struct usbnet *un, int phy, int reg, uint16_t *val)
if (smsc_wait_for_bits(un, SMSC_MII_ADDR, SMSC_MII_BUSY) != 0) {
smsc_warn_printf(un, "MII read timeout\n");
return USBD_TIMEOUT;
return ETIMEDOUT;
}
smsc_readreg(un, SMSC_MII_DATA, &data);
*val = data & 0xffff;
return USBD_NORMAL_COMPLETION;
return 0;
}
usbd_status
static int
smsc_miibus_writereg(struct usbnet *un, int phy, int reg, uint16_t val)
{
uint32_t addr;
@ -312,11 +312,11 @@ smsc_miibus_writereg(struct usbnet *un, int phy, int reg, uint16_t val)
usbnet_isowned_mii(un);
if (un->un_phyno != phy)
return USBD_INVAL;
return EINVAL;
if (smsc_wait_for_bits(un, SMSC_MII_ADDR, SMSC_MII_BUSY) != 0) {
smsc_warn_printf(un, "MII is busy\n");
return USBD_TIMEOUT;
return ETIMEDOUT;
}
smsc_writereg(un, SMSC_MII_DATA, val);
@ -326,10 +326,10 @@ smsc_miibus_writereg(struct usbnet *un, int phy, int reg, uint16_t val)
if (smsc_wait_for_bits(un, SMSC_MII_ADDR, SMSC_MII_BUSY) != 0) {
smsc_warn_printf(un, "MII write timeout\n");
return USBD_TIMEOUT;
return ETIMEDOUT;
}
return USBD_NORMAL_COMPLETION;
return 0;
}
void
@ -809,6 +809,7 @@ smsc_match(device_t parent, cfdata_t match, void *aux)
void
smsc_attach(device_t parent, device_t self, void *aux)
{
UBSNET_MII_DECL_DEFAULT(unm);
struct smsc_softc * const sc = device_private(self);
struct usbnet * const un = &sc->smsc_un;
struct usb_attach_arg *uaa = aux;
@ -931,8 +932,8 @@ smsc_attach(device_t parent, device_t self, void *aux)
}
usbnet_unlock_mii(un);
usbnet_attach_ifp(un, true, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, 0);
usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, &unm);
}
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_udav.c,v 1.69 2019/08/16 08:29:20 mrg Exp $ */
/* $NetBSD: if_udav.c,v 1.70 2019/08/20 06:37:06 mrg Exp $ */
/* $nabe: if_udav.c,v 1.3 2003/08/21 16:57:19 nabe Exp $ */
/*
@ -45,7 +45,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_udav.c,v 1.69 2019/08/16 08:29:20 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_udav.c,v 1.70 2019/08/20 06:37:06 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -70,8 +70,8 @@ static unsigned udav_tx_prepare(struct usbnet *, struct mbuf *,
static void udav_rx_loop(struct usbnet *, struct usbnet_chain *, uint32_t);
static void udav_stop_cb(struct ifnet *, int);
static int udav_ioctl_cb(struct ifnet *, u_long, void *);
static usbd_status udav_mii_read_reg(struct usbnet *, int, int, uint16_t *);
static usbd_status udav_mii_write_reg(struct usbnet *, int, int, uint16_t);
static int udav_mii_read_reg(struct usbnet *, int, int, uint16_t *);
static int udav_mii_write_reg(struct usbnet *, int, int, uint16_t);
static void udav_mii_statchg(struct ifnet *);
static int udav_init(struct ifnet *);
static void udav_setiff(struct usbnet *);
@ -156,6 +156,8 @@ udav_match(device_t parent, cfdata_t match, void *aux)
void
udav_attach(device_t parent, device_t self, void *aux)
{
UBSNET_MII_DECL_DEFAULT(unm);
struct usbnet_mii *unmp;
struct usbnet * const un = device_private(self);
struct usb_attach_arg *uaa = aux;
struct usbd_device *dev = uaa->uaa_device;
@ -250,11 +252,14 @@ udav_attach(device_t parent, device_t self, void *aux)
return;
}
bool have_mii = !ISSET(un->un_flags, UDAV_NO_PHY);
if (ISSET(un->un_flags, UDAV_NO_PHY))
unmp = NULL;
else
unmp = &unm;
/* initialize interface information */
usbnet_attach_ifp(un, have_mii,
IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST, 0, 0);
usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, unmp);
return;
}
@ -755,7 +760,7 @@ udav_stop_cb(struct ifnet *ifp, int disable)
udav_reset(un);
}
static usbd_status
static int
udav_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
{
uint8_t data[2];
@ -770,14 +775,14 @@ udav_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
printf("%s: %s: dying\n", device_xname(un->un_dev),
__func__);
#endif
return USBD_INVAL;
return EINVAL;
}
/* XXX: one PHY only for the internal PHY */
if (phy != 0) {
DPRINTFN(0xff, ("%s: %s: phy=%d is not supported\n",
device_xname(un->un_dev), __func__, phy));
return USBD_INVAL;
return EINVAL;
}
/* select internal PHY and set PHY register address */
@ -800,10 +805,10 @@ udav_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
DPRINTFN(0xff, ("%s: %s: phy=%d reg=0x%04x => 0x%04hx\n",
device_xname(un->un_dev), __func__, phy, reg, *val));
return USBD_NORMAL_COMPLETION;
return 0;
}
static usbd_status
static int
udav_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
{
uint8_t data[2];
@ -818,14 +823,14 @@ udav_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
printf("%s: %s: dying\n", device_xname(un->un_dev),
__func__);
#endif
return -1;
return EIO;
}
/* XXX: one PHY only for the internal PHY */
if (phy != 0) {
DPRINTFN(0xff, ("%s: %s: phy=%d is not supported\n",
device_xname(un->un_dev), __func__, phy));
return -1;
return EIO;
}
/* select internal PHY and set PHY register address */
@ -845,7 +850,7 @@ udav_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
/* end write command */
UDAV_CLRBIT(un, UDAV_EPCR, UDAV_EPCR_ERPRW);
return USBD_NORMAL_COMPLETION;
return 0;
}
static void

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_upl.c,v 1.65 2019/08/18 09:29:38 mrg Exp $ */
/* $NetBSD: if_upl.c,v 1.66 2019/08/20 06:37:06 mrg Exp $ */
/*
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_upl.c,v 1.65 2019/08/18 09:29:38 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_upl.c,v 1.66 2019/08/20 06:37:06 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -221,8 +221,8 @@ upl_attach(device_t parent, device_t self, void *aux)
ifp->if_baudrate = 12000000;
ifp->if_dlt = DLT_RAW;
usbnet_attach_ifp(un, false, IFF_POINTOPOINT | IFF_NOARP | IFF_SIMPLEX,
0, 0);
usbnet_attach_ifp(un, IFF_POINTOPOINT | IFF_NOARP | IFF_SIMPLEX,
0, NULL);
}
static void

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_ure.c,v 1.29 2019/08/19 07:33:37 mrg Exp $ */
/* $NetBSD: if_ure.c,v 1.30 2019/08/20 06:37:06 mrg Exp $ */
/* $OpenBSD: if_ure.c,v 1.10 2018/11/02 21:32:30 jcs Exp $ */
/*-
@ -30,7 +30,7 @@
/* RealTek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device */
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.29 2019/08/19 07:33:37 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.30 2019/08/20 06:37:06 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -83,8 +83,8 @@ static void ure_init_fifo(struct usbnet *);
static void ure_stop_cb(struct ifnet *, int);
static int ure_ioctl_cb(struct ifnet *, u_long, void *);
static usbd_status ure_mii_read_reg(struct usbnet *, int, int, uint16_t *);
static usbd_status ure_mii_write_reg(struct usbnet *, int, int, uint16_t);
static int ure_mii_read_reg(struct usbnet *, int, int, uint16_t *);
static int ure_mii_write_reg(struct usbnet *, int, int, uint16_t);
static void ure_miibus_statchg(struct ifnet *);
static unsigned ure_tx_prepare(struct usbnet *, struct mbuf *,
struct usbnet_chain *);
@ -268,13 +268,13 @@ ure_ocp_reg_write(struct usbnet *un, uint16_t addr, uint16_t data)
ure_write_2(un, reg, URE_MCU_TYPE_PLA, data);
}
static usbd_status
static int
ure_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
{
usbnet_isowned_mii(un);
if (un->un_phyno != phy)
return USBD_INVAL;
return EINVAL;
/* Let the rgephy driver read the URE_PLA_PHYSTATUS register. */
if (reg == RTK_GMEDIASTAT) {
@ -284,20 +284,20 @@ ure_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
*val = ure_ocp_reg_read(un, URE_OCP_BASE_MII + reg * 2);
return USBD_NORMAL_COMPLETION;
return 0;
}
static usbd_status
static int
ure_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
{
usbnet_isowned_mii(un);
if (un->un_phyno != phy)
return USBD_INVAL;
return EINVAL;
ure_ocp_reg_write(un, URE_OCP_BASE_MII + reg * 2, val);
return USBD_NORMAL_COMPLETION;
return 0;
}
static void
@ -838,6 +838,7 @@ ure_match(device_t parent, cfdata_t match, void *aux)
static void
ure_attach(device_t parent, device_t self, void *aux)
{
UBSNET_MII_DECL_DEFAULT(unm);
struct usbnet * const un = device_private(self);
struct usb_attach_arg *uaa = aux;
struct usbd_device *dev = uaa->uaa_device;
@ -971,8 +972,9 @@ ure_attach(device_t parent, device_t self, void *aux)
ec->ec_capabilities |= ETHERCAP_JUMBO_MTU;
#endif
usbnet_attach_ifp(un, true, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, 0);
unm.un_mii_phyloc = un->un_phyno;
usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, &unm);
}
static void

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_url.c,v 1.68 2019/08/15 08:02:32 mrg Exp $ */
/* $NetBSD: if_url.c,v 1.69 2019/08/20 06:37:06 mrg Exp $ */
/*
* Copyright (c) 2001, 2002
@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_url.c,v 1.68 2019/08/15 08:02:32 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_url.c,v 1.69 2019/08/20 06:37:06 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -75,8 +75,8 @@ CFATTACH_DECL_NEW(url, sizeof(struct usbnet), url_match, url_attach,
static unsigned url_tx_prepare(struct usbnet *, struct mbuf *,
struct usbnet_chain *);
static void url_rx_loop(struct usbnet *, struct usbnet_chain *, uint32_t);
static usbd_status url_int_mii_read_reg(struct usbnet *, int, int, uint16_t *);
static usbd_status url_int_mii_write_reg(struct usbnet *, int, int, uint16_t);
static int url_int_mii_read_reg(struct usbnet *, int, int, uint16_t *);
static int url_int_mii_write_reg(struct usbnet *, int, int, uint16_t);
static int url_ioctl_cb(struct ifnet *, u_long, void *);
static void url_stop_cb(struct ifnet *, int);
static void url_mii_statchg_cb(struct ifnet *);
@ -157,6 +157,7 @@ url_match(device_t parent, cfdata_t match, void *aux)
void
url_attach(device_t parent, device_t self, void *aux)
{
UBSNET_MII_DECL_DEFAULT(unm);
struct usbnet * const un = device_private(self);
struct usb_attach_arg *uaa = aux;
struct usbd_device *dev = uaa->uaa_device;
@ -259,8 +260,8 @@ url_attach(device_t parent, device_t self, void *aux)
}
/* initialize interface information */
usbnet_attach_ifp(un, true, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, 0);
usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, &unm);
return;
@ -637,7 +638,7 @@ url_stop_cb(struct ifnet *ifp, int disable)
url_reset(un);
}
static usbd_status
static int
url_int_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
{
uint16_t data;
@ -652,7 +653,7 @@ url_int_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
if (phy != 0) {
DPRINTFN(0xff, ("%s: %s: phy=%d is not supported\n",
device_xname(un->un_dev), __func__, phy));
return USBD_INVAL;
return EINVAL;
}
switch (reg) {
@ -679,9 +680,7 @@ url_int_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
default:
printf("%s: %s: bad register %04x\n",
device_xname(un->un_dev), __func__, reg);
err = USBD_INVAL;
goto R_DONE;
break;
return EINVAL;
}
if (reg == URL_MSR)
@ -697,11 +696,9 @@ url_int_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
return err;
}
static usbd_status
static int
url_int_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
{
usbd_status err = USBD_NORMAL_COMPLETION;
usbnet_isowned_mii(un);
DPRINTFN(0xff, ("%s: %s: enter, phy=%d reg=0x%04x val=0x%04hx\n",
@ -711,7 +708,7 @@ url_int_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
if (phy != 0) {
DPRINTFN(0xff, ("%s: %s: phy=%d is not supported\n",
device_xname(un->un_dev), __func__, phy));
return USBD_INVAL;
return EINVAL;
}
switch (reg) {
@ -723,8 +720,7 @@ url_int_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
break;
case MII_PHYIDR1:
case MII_PHYIDR2:
goto W_DONE;
break;
return 0;
case MII_ANAR: /* Autonegotiation advertisement */
reg = URL_ANAR;
break;
@ -737,18 +733,15 @@ url_int_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
default:
printf("%s: %s: bad register %04x\n",
device_xname(un->un_dev), __func__, reg);
err = USBD_INVAL;
goto W_DONE;
break;
return EINVAL;
}
if (reg == URL_MSR)
url_csr_write_1(un, reg, val);
else
url_csr_write_2(un, reg, val);
W_DONE:
return err;
return 0;
}
static void

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_urndis.c,v 1.32 2019/08/18 08:16:34 mrg Exp $ */
/* $NetBSD: if_urndis.c,v 1.33 2019/08/20 06:37:06 mrg Exp $ */
/* $OpenBSD: if_urndis.c,v 1.31 2011/07/03 15:47:17 matthew Exp $ */
/*
@ -21,7 +21,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_urndis.c,v 1.32 2019/08/18 08:16:34 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_urndis.c,v 1.33 2019/08/20 06:37:06 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -1093,8 +1093,8 @@ urndis_attach(device_t parent, device_t self, void *aux)
usbnet_stop(un, ifp, 1);
usbnet_unlock(un);
usbnet_attach_ifp(un, false, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, 0);
usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0, NULL);
}
#ifdef _MODULE

View File

@ -1,4 +1,4 @@
/* $NetBSD: usbnet.c,v 1.21 2019/08/20 06:18:54 mrg Exp $ */
/* $NetBSD: usbnet.c,v 1.22 2019/08/20 06:37:06 mrg Exp $ */
/*
* Copyright (c) 2019 Matthew R. Green
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.21 2019/08/20 06:18:54 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.22 2019/08/20 06:37:06 mrg Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -866,7 +866,7 @@ usbnet_mii_readreg(device_t dev, int phy, int reg, uint16_t *val)
USBNETHIST_FUNC();
struct usbnet * const un = device_private(dev);
struct usbnet_private * const unp = un->un_pri;
usbd_status err;
int err;
mutex_enter(&unp->unp_lock);
if (unp->unp_dying) {
@ -881,7 +881,7 @@ usbnet_mii_readreg(device_t dev, int phy, int reg, uint16_t *val)
if (err) {
USBNETHIST_CALLARGS("read PHY failed: %d", err, 0, 0, 0);
return EIO;
return err;
}
return 0;
@ -893,7 +893,7 @@ usbnet_mii_writereg(device_t dev, int phy, int reg, uint16_t val)
USBNETHIST_FUNC();
struct usbnet * const un = device_private(dev);
struct usbnet_private * const unp = un->un_pri;
usbd_status err;
int err;
mutex_enter(&unp->unp_lock);
if (unp->unp_dying) {
@ -908,7 +908,7 @@ usbnet_mii_writereg(device_t dev, int phy, int reg, uint16_t val)
if (err) {
USBNETHIST_CALLARGS("write PHY failed: %d", err, 0, 0, 0);
return EIO;
return err;
}
return 0;
@ -1324,7 +1324,7 @@ usbnet_attach(struct usbnet *un,
}
static void
usbnet_attach_mii(struct usbnet *un, int mii_flags)
usbnet_attach_mii(struct usbnet *un, const struct usbnet_mii *unm)
{
USBNETHIST_FUNC(); USBNETHIST_CALLED();
struct usbnet_private * const unp = un->un_pri;
@ -1343,8 +1343,8 @@ usbnet_attach_mii(struct usbnet *un, int mii_flags)
usbnet_ec(un)->ec_mii = mii;
ifmedia_init(&mii->mii_media, 0, usbnet_media_upd, ether_mediastatus);
mii_attach(un->un_dev, mii, 0xffffffff, MII_PHY_ANY,
MII_OFFSET_ANY, mii_flags);
mii_attach(un->un_dev, mii, unm->un_mii_capmask, unm->un_mii_phyloc,
unm->un_mii_offset, unm->un_mii_flags);
if (LIST_FIRST(&mii->mii_phys) == NULL) {
ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL);
@ -1355,10 +1355,9 @@ usbnet_attach_mii(struct usbnet *un, int mii_flags)
void
usbnet_attach_ifp(struct usbnet *un,
bool have_mii, /* setup MII */
unsigned if_flags, /* additional if_flags */
unsigned if_extflags, /* additional if_extflags */
int mii_flags) /* additional mii_attach flags */
const struct usbnet_mii *unm) /* additional mii_attach flags */
{
USBNETHIST_FUNC(); USBNETHIST_CALLED();
struct usbnet_private * const unp = un->un_pri;
@ -1374,8 +1373,8 @@ usbnet_attach_ifp(struct usbnet *un,
ifp->if_init = usbnet_init;
ifp->if_stop = usbnet_stop_ifp;
if (have_mii)
usbnet_attach_mii(un, mii_flags);
if (unm)
usbnet_attach_mii(un, unm);
else
unp->unp_link = true;

View File

@ -1,4 +1,4 @@
/* $NetBSD: usbnet.h,v 1.12 2019/08/15 05:52:23 mrg Exp $ */
/* $NetBSD: usbnet.h,v 1.13 2019/08/20 06:37:06 mrg Exp $ */
/*
* Copyright (c) 2019 Matthew R. Green
@ -137,11 +137,11 @@ typedef int (*usbnet_ioctl_cb)(struct ifnet *, u_long, void *);
typedef int (*usbnet_init_cb)(struct ifnet *);
/* MII read register callback. */
typedef usbd_status (*usbnet_mii_read_reg_cb)(struct usbnet *, int reg,
int phy, uint16_t *val);
typedef int (*usbnet_mii_read_reg_cb)(struct usbnet *, int reg,
int phy, uint16_t *val);
/* MII write register callback. */
typedef usbd_status (*usbnet_mii_write_reg_cb)(struct usbnet *, int reg,
int phy, uint16_t val);
typedef int (*usbnet_mii_write_reg_cb)(struct usbnet *, int reg,
int phy, uint16_t val);
/* MII status change callback. */
typedef void (*usbnet_mii_statchg_cb)(struct ifnet *);
@ -185,6 +185,28 @@ struct usbnet_intr {
unsigned uni_interval;
};
/*
* Structure to setup MII. Use the UBSNET_MII_DECL_DEFAULT() macro for
* sane default. Pass a copy to usbnet_attach_ifp(). Not used
* after the usbnet_attach_ifp() function returns.
*/
struct usbnet_mii {
int un_mii_flags;
int un_mii_capmask;
int un_mii_phyloc;
int un_mii_offset;
};
#define UBSNET_MII_DECL(name, capmask, loc, off, flags) \
struct usbnet_mii name = { \
.un_mii_capmask = capmask, \
.un_mii_phyloc = loc, \
.un_mii_offset = off, \
.un_mii_flags = flags, \
}
#define UBSNET_MII_DECL_DEFAULT(name) \
UBSNET_MII_DECL(name, 0xffffffff, MII_PHY_ANY, MII_OFFSET_ANY, 0)
/*
* Generic USB ethernet structure. Use this as ifp->if_softc and set as
* device_private() in attach unless already using struct usbnet here.
@ -321,7 +343,7 @@ void usbnet_input(struct usbnet * const, uint8_t *, size_t);
/* autoconf */
void usbnet_attach(struct usbnet *un, const char *);
void usbnet_attach_ifp(struct usbnet *, bool, unsigned, unsigned, int);
void usbnet_attach_ifp(struct usbnet *, unsigned, unsigned, const struct usbnet_mii *);
int usbnet_detach(device_t, int);
int usbnet_activate(device_t, devact_t);

View File

@ -1,4 +1,4 @@
/* $NetBSD: param.h,v 1.608 2019/08/15 05:52:23 mrg Exp $ */
/* $NetBSD: param.h,v 1.609 2019/08/20 06:37:06 mrg Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@ -67,7 +67,7 @@
* 2.99.9 (299000900)
*/
#define __NetBSD_Version__ 999000900 /* NetBSD 9.99.9 */
#define __NetBSD_Version__ 999001000 /* NetBSD 9.99.10 */
#define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \
(m) * 1000000) + (p) * 100) <= __NetBSD_Version__)