couple of minor API updates:

- change the read/write register callbacks to have the same phy/reg
  order as the MII code.
- add "mii_flags" param to usbnet_attach_ifp().  axe(4) wants it.

also:
- add usbnet debug code, sysctl node support
- remove commented DPRINTF()s accidentally left in place
- add usbnet_softc()
- reorder some attach code to be consistent
- re-add USBD_FORCE_SHORT_XFER for axen rx chain

ride 9.99.2 bump.
This commit is contained in:
mrg 2019-07-31 23:47:16 +00:00
parent 3bd03214d0
commit 699d292a9e
4 changed files with 73 additions and 44 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_axen.c,v 1.51 2019/07/31 09:13:16 mrg Exp $ */
/* $NetBSD: if_axen.c,v 1.52 2019/07/31 23:47:16 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.51 2019/07/31 09:13:16 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.52 2019/07/31 23:47:16 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -127,9 +127,9 @@ axen_cmd(struct axen_softc *sc, int cmd, int index, int val, void *buf)
}
static usbd_status
axen_mii_read_reg(struct usbnet *un, int reg, int phy, uint16_t *val)
axen_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
{
struct axen_softc * const sc = un->un_sc;
struct axen_softc * const sc = usbnet_softc(un);
uint16_t data;
usbd_status err = axen_cmd(sc, AXEN_CMD_MII_READ_REG, reg, phy, &data);
@ -144,9 +144,9 @@ axen_mii_read_reg(struct usbnet *un, int reg, int phy, uint16_t *val)
}
static usbd_status
axen_mii_write_reg(struct usbnet *un, int reg, int phy, uint16_t val)
axen_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
{
struct axen_softc * const sc = un->un_sc;
struct axen_softc * const sc = usbnet_softc(un);
uint16_t uval = htole16(val);
return axen_cmd(sc, AXEN_CMD_MII_WRITE_REG, reg, phy, &uval);
@ -156,7 +156,7 @@ static void
axen_miibus_statchg(struct ifnet *ifp)
{
struct usbnet * const un = ifp->if_softc;
struct axen_softc * const sc = un->un_sc;
struct axen_softc * const sc = usbnet_softc(un);
struct mii_data * const mii = usbnet_mii(un);
int err;
uint16_t val;
@ -215,7 +215,7 @@ axen_miibus_statchg(struct ifnet *ifp)
static void
axen_setiff_locked(struct usbnet *un)
{
struct axen_softc * const sc = un->un_sc;
struct axen_softc * const sc = usbnet_softc(un);
struct ifnet * const ifp = usbnet_ifp(un);
struct ethercom *ec = &un->un_ec;
struct ether_multi *enm;
@ -519,7 +519,7 @@ axen_ax88179_init(struct axen_softc *sc)
static void
axen_setoe_locked(struct usbnet *un)
{
struct axen_softc * const sc = un->un_sc;
struct axen_softc * const sc = usbnet_softc(un);
struct ifnet * const ifp = usbnet_ifp(un);
uint64_t enabled = ifp->if_capenable;
uint8_t val;
@ -612,6 +612,9 @@ axen_attach(device_t parent, device_t self, void *aux)
aprint_naive("\n");
aprint_normal("\n");
devinfop = usbd_devinfo_alloc(dev, 0);
aprint_normal_dev(self, "%s\n", devinfop);
usbd_devinfo_free(devinfop);
un->un_dev = self;
un->un_udev = dev;
@ -626,10 +629,6 @@ axen_attach(device_t parent, device_t self, void *aux)
un->un_init_cb = axen_init;
un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
devinfop = usbd_devinfo_alloc(dev, 0);
aprint_normal_dev(self, "%s\n", devinfop);
usbd_devinfo_free(devinfop);
err = usbd_set_config_no(dev, AXEN_CONFIG_NO, 1);
if (err) {
@ -724,7 +723,7 @@ axen_attach(device_t parent, device_t self, void *aux)
IFCAP_CSUM_UDPv6_Rx | IFCAP_CSUM_UDPv6_Tx;
usbnet_attach_ifp(un, true, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0);
0, 0);
}
static int
@ -916,7 +915,7 @@ static int
axen_init_locked(struct ifnet *ifp)
{
struct usbnet * const un = ifp->if_softc;
struct axen_softc * const sc = un->un_sc;
struct axen_softc * const sc = usbnet_softc(un);
uint16_t rxmode;
uint16_t wval;
uint8_t bval;
@ -953,7 +952,7 @@ axen_init_locked(struct ifnet *ifp)
usbnet_unlock_mii_un_locked(un);
return usbnet_init_rx_tx(un, 0, 0);
return usbnet_init_rx_tx(un, 0, USBD_FORCE_SHORT_XFER);
}
static int
@ -968,15 +967,11 @@ axen_init(struct ifnet *ifp)
return ret;
}
/*
* Stop the adapter and free any mbufs allocated to the
* RX and TX lists.
*/
static void
axen_stop_cb(struct ifnet *ifp, int disable)
{
struct usbnet * const un = ifp->if_softc;
struct axen_softc * const sc = un->un_sc;
struct axen_softc * const sc = usbnet_softc(un);
uint16_t rxmode, wval;
axen_reset(sc);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_cdce.c,v 1.54 2019/07/31 09:13:16 mrg Exp $ */
/* $NetBSD: if_cdce.c,v 1.55 2019/07/31 23:47:16 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.54 2019/07/31 09:13:16 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.55 2019/07/31 23:47:16 mrg Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -254,7 +254,7 @@ cdce_attach(device_t parent, device_t self, void *aux)
usbnet_attach(un, "cdcedet", CDCE_RX_LIST_CNT, CDCE_TX_LIST_CNT);
usbnet_attach_ifp(un, false, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
0);
0, 0);
}
static int

View File

@ -1,4 +1,4 @@
/* $NetBSD: usbnet.c,v 1.1 2019/07/31 09:13:16 mrg Exp $ */
/* $NetBSD: usbnet.c,v 1.2 2019/07/31 23:47:16 mrg Exp $ */
/*
* Copyright (c) 2019 Matthew R. Green
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.1 2019/07/31 09:13:16 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.2 2019/07/31 23:47:16 mrg Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -44,8 +44,46 @@ __KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.1 2019/07/31 09:13:16 mrg Exp $");
static int usbnet_modcmd(modcmd_t, void *);
#define DPRINTF(fmt, ...) \
printf("%s:%d: " fmt "\n", __func__, __LINE__, ## __VA_ARGS__)
#ifdef USB_DEBUG
#ifndef USBNET_DEBUG
#define usbnetdebug 0
#else
static int usbnetdebug = 20;
SYSCTL_SETUP(sysctl_hw_usbnet_setup, "sysctl hw.usbnet setup")
{
int err;
const struct sysctlnode *rnode;
const struct sysctlnode *cnode;
err = sysctl_createv(clog, 0, NULL, &rnode,
CTLFLAG_PERMANENT, CTLTYPE_NODE, "usbnet",
SYSCTL_DESCR("usbnet global controls"),
NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
if (err)
goto fail;
/* control debugging printfs */
err = sysctl_createv(clog, 0, &rnode, &cnode,
CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT,
"debug", SYSCTL_DESCR("Enable debugging output"),
NULL, 0, &usbnetdebug, sizeof(usbnetdebug), CTL_CREATE, CTL_EOL);
if (err)
goto fail;
return;
fail:
aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err);
}
#endif /* USBNET_DEBUG */
#endif /* USB_DEBUG */
#define DPRINTF(FMT,A,B,C,D) USBHIST_LOGN(usbnetdebug,1,FMT,A,B,C,D)
#define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(usbnetdebug,N,FMT,A,B,C,D)
#define USBNETHIST_FUNC() USBHIST_FUNC()
#define USBNETHIST_CALLED(name) USBHIST_CALLED(usbnetdebug)
/* Interrupt handling. */
@ -83,7 +121,6 @@ usbnet_enqueue(struct usbnet * const un, uint8_t *buf, size_t buflen,
struct ifnet *ifp = &un->un_ec.ec_if;
struct mbuf *m;
//DPRINTF("enter");
KASSERT(mutex_owned(&un->un_rxlock));
m = usbnet_newbuf();
@ -113,7 +150,6 @@ usbnet_rxeof(struct usbd_xfer *xfer, void * priv, usbd_status status)
struct ifnet *ifp = &un->un_ec.ec_if;
uint32_t total_len;
//DPRINTF("enter");
mutex_enter(&un->un_rxlock);
if (un->un_dying || un->un_stopping ||
@ -166,7 +202,6 @@ usbnet_txeof(struct usbd_xfer *xfer, void * priv, usbd_status status)
struct usbnet_cdata *cd = &un->un_cdata;
struct ifnet * const ifp = usbnet_ifp(un);
//DPRINTF("enter");
mutex_enter(&un->un_txlock);
if (un->un_stopping || un->un_dying) {
mutex_exit(&un->un_txlock);
@ -213,7 +248,6 @@ usbnet_start_locked(struct ifnet *ifp)
unsigned length;
int idx;
//DPRINTF("enter");
KASSERT(mutex_owned(&un->un_txlock));
KASSERT(cd->uncd_tx_cnt <= cd->uncd_tx_list_cnt);
@ -221,7 +255,6 @@ usbnet_start_locked(struct ifnet *ifp)
return;
idx = cd->uncd_tx_prod;
//DPRINTF("idx %d", idx);
while (cd->uncd_tx_cnt < cd->uncd_tx_list_cnt) {
IFQ_POLL(&ifp->if_snd, m);
if (m == NULL)
@ -262,7 +295,6 @@ usbnet_start_locked(struct ifnet *ifp)
idx = (idx + 1) % cd->uncd_tx_list_cnt;
cd->uncd_tx_cnt++;
}
//DPRINTF("idx %d", idx);
cd->uncd_tx_prod = idx;
/*
@ -276,7 +308,6 @@ usbnet_start(struct ifnet *ifp)
{
struct usbnet * const un = ifp->if_softc;
//DPRINTF("enter");
mutex_enter(&un->un_txlock);
if (!un->un_stopping)
usbnet_start_locked(ifp);
@ -596,7 +627,7 @@ usbnet_miibus_readreg(device_t dev, int phy, int reg, uint16_t *val)
mutex_exit(&un->un_lock);
usbnet_lock_mii(un);
err = (*un->un_read_reg_cb)(un, reg, phy, val);
err = (*un->un_read_reg_cb)(un, phy, reg, val);
usbnet_unlock_mii(un);
if (err) {
@ -621,7 +652,7 @@ usbnet_miibus_writereg(device_t dev, int phy, int reg, uint16_t val)
mutex_exit(&un->un_lock);
usbnet_lock_mii(un);
err = (*un->un_write_reg_cb)(un, reg, phy, val);
err = (*un->un_write_reg_cb)(un, phy, reg, val);
usbnet_unlock_mii(un);
if (err) {
@ -893,7 +924,7 @@ usbnet_attach(struct usbnet *un,
}
static void
usbnet_attach_mii(struct usbnet *un)
usbnet_attach_mii(struct usbnet *un, int mii_flags)
{
struct mii_data * const mii = &un->un_mii;
struct ifnet *ifp = usbnet_ifp(un);
@ -907,7 +938,7 @@ usbnet_attach_mii(struct usbnet *un)
un->un_ec.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, 0);
MII_OFFSET_ANY, mii_flags);
if (LIST_FIRST(&mii->mii_phys) == NULL) {
ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL);
@ -925,7 +956,8 @@ void
usbnet_attach_ifp(struct usbnet *un,
bool have_mii, /* setup MII */
unsigned if_flags, /* additional if_flags */
unsigned if_extflags) /* additional if_extflags */
unsigned if_extflags, /* additional if_extflags */
int mii_flags) /* additional mii_attach flags */
{
struct ifnet *ifp = usbnet_ifp(un);
@ -945,7 +977,7 @@ usbnet_attach_ifp(struct usbnet *un,
IFQ_SET_READY(&ifp->if_snd);
if (have_mii)
usbnet_attach_mii(un);
usbnet_attach_mii(un, mii_flags);
/* Attach the interface. */
if_attach(ifp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: usbnet.h,v 1.1 2019/07/31 09:13:16 mrg Exp $ */
/* $NetBSD: usbnet.h,v 1.2 2019/07/31 23:47:16 mrg Exp $ */
/*
* Copyright (c) 2019 Matthew R. Green
@ -76,7 +76,7 @@
*/
/*
* Converted drivers: if_axen if_cdce.
* Converted drivers: if_axe if_axen if_cdce if_ure.
*
* Note: these drivers have slightly different mbuf handling that need to be
* adjusted to the common method (see if_cdce conversion):
@ -87,6 +87,7 @@
#include <sys/device.h>
#include <sys/mbuf.h>
#include <sys/rndsource.h>
#include <sys/mutex.h>
#include <net/bpf.h>
#include <net/if.h>
@ -229,6 +230,7 @@ struct usbnet {
#define usbnet_ifp(un) (&(un)->un_ec.ec_if)
#define usbnet_mii(un) (un->un_ec.ec_mii)
#define usbnet_softc(un) (un->un_sc)
/*
* Endpoint / rx/tx chain management:
@ -259,7 +261,7 @@ void usbnet_enqueue(struct usbnet * const, uint8_t *, size_t, int);
/* autoconf */
void usbnet_attach(struct usbnet *un, const char *, unsigned, unsigned);
void usbnet_attach_ifp(struct usbnet *, bool, unsigned, unsigned);
void usbnet_attach_ifp(struct usbnet *, bool, unsigned, unsigned, int);
int usbnet_detach(device_t, int);
int usbnet_activate(device_t, devact_t);