Make size of transmit/receive queues variable. Restrict queue size again

to 1 for LAN7500 as some chips fail.

Read Chip revision register and report value. Maybe we can identify
chisp better now.
This commit is contained in:
mlelstv 2019-02-03 13:11:07 +00:00
parent b65e77441f
commit fc09497c36
3 changed files with 35 additions and 23 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_mue.c,v 1.30 2019/01/31 05:25:48 rin Exp $ */ /* $NetBSD: if_mue.c,v 1.31 2019/02/03 13:11:07 mlelstv Exp $ */
/* $OpenBSD: if_mue.c,v 1.3 2018/08/04 16:42:46 jsg 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. */ /* Driver for Microchip LAN7500/LAN7800 chipsets. */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.30 2019/01/31 05:25:48 rin Exp $"); __KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.31 2019/02/03 13:11:07 mlelstv Exp $");
#ifdef _KERNEL_OPT #ifdef _KERNEL_OPT
#include "opt_usb.h" #include "opt_usb.h"
@ -897,6 +897,7 @@ mue_attach(device_t parent, device_t self, void *aux)
struct mii_data *mii; struct mii_data *mii;
struct ifnet *ifp; struct ifnet *ifp;
usbd_status err; usbd_status err;
const char *descr;
uint8_t i; uint8_t i;
int s; int s;
@ -932,12 +933,19 @@ mue_attach(device_t parent, device_t self, void *aux)
sc->mue_product = uaa->uaa_product; sc->mue_product = uaa->uaa_product;
sc->mue_flags = MUE_LOOKUP(uaa)->mue_flags; sc->mue_flags = MUE_LOOKUP(uaa)->mue_flags;
sc->mue_id_rev = mue_csr_read(sc, MUE_ID_REV);
/* Decide on what our bufsize will be. */ /* Decide on what our bufsize will be. */
if (sc->mue_flags & LAN7500) if (sc->mue_flags & LAN7500) {
sc->mue_rxbufsz = (sc->mue_udev->ud_speed == USB_SPEED_HIGH) ? sc->mue_rxbufsz = (sc->mue_udev->ud_speed == USB_SPEED_HIGH) ?
MUE_7500_HS_RX_BUFSIZE : MUE_7500_FS_RX_BUFSIZE; MUE_7500_HS_RX_BUFSIZE : MUE_7500_FS_RX_BUFSIZE;
else sc->mue_rx_list_cnt = 1;
sc->mue_tx_list_cnt = 1;
} else {
sc->mue_rxbufsz = MUE_7800_RX_BUFSIZE; sc->mue_rxbufsz = MUE_7800_RX_BUFSIZE;
sc->mue_rx_list_cnt = MUE_RX_LIST_CNT;
sc->mue_tx_list_cnt = MUE_TX_LIST_CNT;
}
sc->mue_txbufsz = MUE_TX_BUFSIZE; sc->mue_txbufsz = MUE_TX_BUFSIZE;
/* Find endpoints. */ /* Find endpoints. */
@ -974,10 +982,10 @@ mue_attach(device_t parent, device_t self, void *aux)
} }
/* A Microchip chip was detected. Inform the world. */ /* A Microchip chip was detected. Inform the world. */
if (sc->mue_flags & LAN7500) descr = (sc->mue_flags & LAN7500) ? "LAN7500" : "LAN7800";
aprint_normal_dev(self, "LAN7500\n"); aprint_normal_dev(self, "%s id 0x%x rev 0x%x\n", descr,
else (unsigned)__SHIFTOUT(sc->mue_id_rev, MUE_ID_REV_ID),
aprint_normal_dev(self, "LAN7800\n"); (unsigned)__SHIFTOUT(sc->mue_id_rev, MUE_ID_REV_REV));
if (mue_get_macaddr(sc, dict)) { if (mue_get_macaddr(sc, dict)) {
aprint_error_dev(self, "failed to read MAC address\n"); aprint_error_dev(self, "failed to read MAC address\n");
@ -1125,7 +1133,7 @@ mue_rx_list_init(struct mue_softc *sc)
int err; int err;
cd = &sc->mue_cdata; cd = &sc->mue_cdata;
for (i = 0; i < __arraycount(cd->mue_rx_chain); i++) { for (i = 0; i < sc->mue_rx_list_cnt; i++) {
c = &cd->mue_rx_chain[i]; c = &cd->mue_rx_chain[i];
c->mue_sc = sc; c->mue_sc = sc;
c->mue_idx = i; c->mue_idx = i;
@ -1150,7 +1158,7 @@ mue_tx_list_init(struct mue_softc *sc)
int err; int err;
cd = &sc->mue_cdata; cd = &sc->mue_cdata;
for (i = 0; i < __arraycount(cd->mue_tx_chain); i++) { for (i = 0; i < sc->mue_tx_list_cnt; i++) {
c = &cd->mue_tx_chain[i]; c = &cd->mue_tx_chain[i];
c->mue_sc = sc; c->mue_sc = sc;
c->mue_idx = i; c->mue_idx = i;
@ -1198,7 +1206,7 @@ mue_startup_rx_pipes(struct mue_softc *sc)
size_t i; size_t i;
/* Start up the receive pipe. */ /* Start up the receive pipe. */
for (i = 0; i < __arraycount(sc->mue_cdata.mue_rx_chain); i++) { for (i = 0; i < sc->mue_rx_list_cnt; i++) {
c = &sc->mue_cdata.mue_rx_chain[i]; c = &sc->mue_cdata.mue_rx_chain[i];
usbd_setup_xfer(c->mue_xfer, c, c->mue_buf, sc->mue_rxbufsz, usbd_setup_xfer(c->mue_xfer, c, c->mue_buf, sc->mue_rxbufsz,
USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, mue_rxeof); USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, mue_rxeof);
@ -1461,11 +1469,6 @@ mue_rxeof(struct usbd_xfer *xfer, void *priv, usbd_status status)
return; return;
} }
if (__predict_false(!(ifp->if_flags & IFF_RUNNING))) {
DPRINTF(sc, "not running\n");
return;
}
if (__predict_false(status != USBD_NORMAL_COMPLETION)) { if (__predict_false(status != USBD_NORMAL_COMPLETION)) {
DPRINTF(sc, "%s\n", usbd_errstr(status)); DPRINTF(sc, "%s\n", usbd_errstr(status));
if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
@ -1790,7 +1793,7 @@ mue_start(struct ifnet *ifp)
} }
idx = cd->mue_tx_prod; idx = cd->mue_tx_prod;
while (cd->mue_tx_cnt < MUE_TX_LIST_CNT) { while ((unsigned)cd->mue_tx_cnt < sc->mue_tx_list_cnt) {
IFQ_POLL(&ifp->if_snd, m); IFQ_POLL(&ifp->if_snd, m);
if (m == NULL) if (m == NULL)
break; break;
@ -1804,13 +1807,13 @@ mue_start(struct ifnet *ifp)
bpf_mtap(ifp, m, BPF_D_OUT); bpf_mtap(ifp, m, BPF_D_OUT);
m_freem(m); m_freem(m);
idx = (idx + 1) % MUE_TX_LIST_CNT; idx = (idx + 1) % sc->mue_tx_list_cnt;
cd->mue_tx_cnt++; cd->mue_tx_cnt++;
} }
cd->mue_tx_prod = idx; cd->mue_tx_prod = idx;
if (cd->mue_tx_cnt >= MUE_TX_LIST_CNT) if ((unsigned)cd->mue_tx_cnt >= sc->mue_tx_list_cnt)
ifp->if_flags |= IFF_OACTIVE; ifp->if_flags |= IFF_OACTIVE;
/* Set a timeout in case the chip goes out to lunch. */ /* Set a timeout in case the chip goes out to lunch. */
@ -1841,7 +1844,7 @@ mue_stop(struct ifnet *ifp, int disable __unused)
} }
/* Free RX resources. */ /* Free RX resources. */
for (i = 0; i < __arraycount(sc->mue_cdata.mue_rx_chain); i++) for (i = 0; i < sc->mue_rx_list_cnt; i++)
if (sc->mue_cdata.mue_rx_chain[i].mue_xfer != NULL) { if (sc->mue_cdata.mue_rx_chain[i].mue_xfer != NULL) {
usbd_destroy_xfer( usbd_destroy_xfer(
sc->mue_cdata.mue_rx_chain[i].mue_xfer); sc->mue_cdata.mue_rx_chain[i].mue_xfer);
@ -1849,7 +1852,7 @@ mue_stop(struct ifnet *ifp, int disable __unused)
} }
/* Free TX resources. */ /* Free TX resources. */
for (i = 0; i < __arraycount(sc->mue_cdata.mue_tx_chain); i++) for (i = 0; i < sc->mue_tx_list_cnt; i++)
if (sc->mue_cdata.mue_tx_chain[i].mue_xfer != NULL) { if (sc->mue_cdata.mue_tx_chain[i].mue_xfer != NULL) {
usbd_destroy_xfer( usbd_destroy_xfer(
sc->mue_cdata.mue_tx_chain[i].mue_xfer); sc->mue_cdata.mue_tx_chain[i].mue_xfer);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_muereg.h,v 1.4 2018/12/11 13:35:02 rin Exp $ */ /* $NetBSD: if_muereg.h,v 1.5 2019/02/03 13:11:07 mlelstv Exp $ */
/* $OpenBSD: if_muereg.h,v 1.1 2018/08/03 01:50:15 kevlo Exp $ */ /* $OpenBSD: if_muereg.h,v 1.1 2018/08/03 01:50:15 kevlo Exp $ */
/* /*
@ -34,6 +34,7 @@
#define MUE_UR_READREG 0xa1 #define MUE_UR_READREG 0xa1
/* registers */ /* registers */
#define MUE_ID_REV 0x000
#define MUE_INT_STATUS 0x00c #define MUE_INT_STATUS 0x00c
#define MUE_HW_CFG 0x010 #define MUE_HW_CFG 0x010
#define MUE_PMT_CTL 0x014 #define MUE_PMT_CTL 0x014
@ -81,6 +82,10 @@
#define MUE_7800_ADDR_FILTX(i) (MUE_7800_ADDR_FILTX_BASE + 8 * (i)) #define MUE_7800_ADDR_FILTX(i) (MUE_7800_ADDR_FILTX_BASE + 8 * (i))
#define MUE_NUM_ADDR_FILTX 33 #define MUE_NUM_ADDR_FILTX 33
/* device ID and revision register */
#define MUE_ID_REV_ID __BITS(16,31)
#define MUE_ID_REV_REV __BITS(0,15)
/* hardware configuration register */ /* hardware configuration register */
#define MUE_HW_CFG_SRST 0x00000001 #define MUE_HW_CFG_SRST 0x00000001
#define MUE_HW_CFG_LRST 0x00000002 #define MUE_HW_CFG_LRST 0x00000002

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_muevar.h,v 1.5 2019/01/31 05:25:07 rin Exp $ */ /* $NetBSD: if_muevar.h,v 1.6 2019/02/03 13:11:07 mlelstv Exp $ */
/* $OpenBSD: if_muereg.h,v 1.1 2018/08/03 01:50:15 kevlo Exp $ */ /* $OpenBSD: if_muereg.h,v 1.1 2018/08/03 01:50:15 kevlo Exp $ */
/* /*
@ -111,6 +111,7 @@ struct mue_softc {
uint16_t mue_product; uint16_t mue_product;
uint16_t mue_flags; uint16_t mue_flags;
uint32_t mue_id_rev;
int mue_if_flags; int mue_if_flags;
int mue_refcnt; int mue_refcnt;
@ -121,6 +122,9 @@ struct mue_softc {
uint32_t mue_rxbufsz; uint32_t mue_rxbufsz;
uint32_t mue_txbufsz; uint32_t mue_txbufsz;
int mue_link; int mue_link;
unsigned mue_rx_list_cnt;
unsigned mue_tx_list_cnt;
}; };
#endif /* _IF_MUEVAR_H_ */ #endif /* _IF_MUEVAR_H_ */