Module Name: src
Committed By: mrg
Date: Fri Aug 9 06:44:42 UTC 2019
Modified Files:
src/sys/dev/usb: if_udav.c
Log Message:
switch to usbnet as softc, using un_flags.
To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/dev/usb/if_udav.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/usb/if_udav.c
diff -u src/sys/dev/usb/if_udav.c:1.63 src/sys/dev/usb/if_udav.c:1.64
--- src/sys/dev/usb/if_udav.c:1.63 Fri Aug 9 01:17:33 2019
+++ src/sys/dev/usb/if_udav.c Fri Aug 9 06:44:42 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: if_udav.c,v 1.63 2019/08/09 01:17:33 mrg Exp $ */
+/* $NetBSD: if_udav.c,v 1.64 2019/08/09 06:44:42 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.63 2019/08/09 01:17:33 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_udav.c,v 1.64 2019/08/09 06:44:42 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -59,16 +59,11 @@ __KERNEL_RCSID(0, "$NetBSD: if_udav.c,v
#include <dev/usb/usbnet.h>
#include <dev/usb/if_udavreg.h>
-struct udav_softc {
- struct usbnet sc_un;
- uint16_t sc_flags;
-};
-
/* Function declarations */
int udav_match(device_t, cfdata_t, void *);
void udav_attach(device_t, device_t, void *);
-CFATTACH_DECL_NEW(udav, sizeof(struct udav_softc), udav_match, udav_attach,
+CFATTACH_DECL_NEW(udav, sizeof(struct usbnet), udav_match, udav_attach,
usbnet_detach, usbnet_activate);
static void udav_chip_init(struct usbnet *);
@@ -87,15 +82,15 @@ static void udav_setiff(struct usbnet *)
static void udav_setiff_locked(struct usbnet *);
static void udav_reset(struct usbnet *);
-static int udav_csr_read(struct udav_softc *, int, void *, int);
-static int udav_csr_write(struct udav_softc *, int, void *, int);
-static int udav_csr_read1(struct udav_softc *, int);
-static int udav_csr_write1(struct udav_softc *, int, unsigned char);
+static int udav_csr_read(struct usbnet *, int, void *, int);
+static int udav_csr_write(struct usbnet *, int, void *, int);
+static int udav_csr_read1(struct usbnet *, int);
+static int udav_csr_write1(struct usbnet *, int, unsigned char);
#if 0
-static int udav_mem_read(struct udav_softc *, int, void *, int);
-static int udav_mem_write(struct udav_softc *, int, void *, int);
-static int udav_mem_write1(struct udav_softc *, int, unsigned char);
+static int udav_mem_read(struct usbnet *, int, void *, int);
+static int udav_mem_write(struct usbnet *, int, void *, int);
+static int udav_mem_write1(struct usbnet *, int, unsigned char);
#endif
/* Macros */
@@ -108,11 +103,11 @@ int udavdebug = 10;
#define DPRINTFN(n, x)
#endif
-#define UDAV_SETBIT(sc, reg, x) \
- udav_csr_write1(sc, reg, udav_csr_read1(sc, reg) | (x))
+#define UDAV_SETBIT(un, reg, x) \
+ udav_csr_write1(un, reg, udav_csr_read1(un, reg) | (x))
-#define UDAV_CLRBIT(sc, reg, x) \
- udav_csr_write1(sc, reg, udav_csr_read1(sc, reg) & ~(x))
+#define UDAV_CLRBIT(un, reg, x) \
+ udav_csr_write1(un, reg, udav_csr_read1(un, reg) & ~(x))
static const struct udav_type {
struct usb_devno udav_dev;
@@ -165,8 +160,7 @@ udav_match(device_t parent, cfdata_t mat
void
udav_attach(device_t parent, device_t self, void *aux)
{
- struct udav_softc *sc = device_private(self);
- struct usbnet * const un = &sc->sc_un;
+ struct usbnet * const un = device_private(self);
struct usb_attach_arg *uaa = aux;
struct usbd_device *dev = uaa->uaa_device;
struct usbd_interface *iface;
@@ -176,9 +170,6 @@ udav_attach(device_t parent, device_t se
char *devinfop;
int i;
- /* Switch to usbnet for device_private() */
- self->dv_private = un;
-
aprint_naive("\n");
aprint_normal("\n");
devinfop = usbd_devinfo_alloc(dev, 0);
@@ -187,7 +178,7 @@ udav_attach(device_t parent, device_t se
un->un_dev = self;
un->un_udev = dev;
- un->un_sc = sc;
+ un->un_sc = un;
un->un_ops = &udav_ops;
/* Move the device into the configured state. */
@@ -207,7 +198,7 @@ udav_attach(device_t parent, device_t se
}
un->un_iface = iface;
- sc->sc_flags = udav_lookup(uaa->uaa_vendor,
+ un->un_flags = udav_lookup(uaa->uaa_vendor,
uaa->uaa_product)->udav_flags;
/* get interface descriptor */
@@ -252,14 +243,14 @@ udav_attach(device_t parent, device_t se
/* Get Ethernet Address */
usbnet_lock_mii(un);
- err = udav_csr_read(sc, UDAV_PAR, un->un_eaddr, ETHER_ADDR_LEN);
+ err = udav_csr_read(un, UDAV_PAR, un->un_eaddr, ETHER_ADDR_LEN);
usbnet_unlock_mii(un);
if (err) {
aprint_error_dev(self, "read MAC address failed\n");
return;
}
- bool have_mii = !ISSET(sc->sc_flags, UDAV_NO_PHY);
+ bool have_mii = !ISSET(un->un_flags, UDAV_NO_PHY);
if (!have_mii)
un->un_link = 1;
@@ -273,14 +264,11 @@ udav_attach(device_t parent, device_t se
#if 0
/* read memory */
static int
-udav_mem_read(struct udav_softc *sc, int offset, void *buf, int len)
+udav_mem_read(struct usbnet *un, int offset, void *buf, int len)
{
usb_device_request_t req;
usbd_status err;
- if (sc == NULL)
- return 0;
-
DPRINTFN(0x200,
("%s: %s: enter\n", device_xname(un->un_dev), __func__));
@@ -307,14 +295,11 @@ udav_mem_read(struct udav_softc *sc, int
/* write memory */
static int
-udav_mem_write(struct udav_softc *sc, int offset, void *buf, int len)
+udav_mem_write(struct usbnet *un, int offset, void *buf, int len)
{
usb_device_request_t req;
usbd_status err;
- if (sc == NULL)
- return 0;
-
DPRINTFN(0x200,
("%s: %s: enter\n", device_xname(un->un_dev), __func__));
@@ -341,14 +326,11 @@ udav_mem_write(struct udav_softc *sc, in
/* write memory */
static int
-udav_mem_write1(struct udav_softc *sc, int offset, unsigned char ch)
+udav_mem_write1(struct usbnet *un, int offset, unsigned char ch)
{
usb_device_request_t req;
usbd_status err;
- if (sc == NULL)
- return 0;
-
DPRINTFN(0x200,
("%s: %s: enter\n", device_xname(un->un_dev), __func__));
@@ -375,9 +357,8 @@ udav_mem_write1(struct udav_softc *sc, i
/* read register(s) */
static int
-udav_csr_read(struct udav_softc *sc, int offset, void *buf, int len)
+udav_csr_read(struct usbnet *un, int offset, void *buf, int len)
{
- struct usbnet * const un = &sc->sc_un;
usb_device_request_t req;
usbd_status err;
@@ -407,9 +388,8 @@ udav_csr_read(struct udav_softc *sc, int
/* write register(s) */
static int
-udav_csr_write(struct udav_softc *sc, int offset, void *buf, int len)
+udav_csr_write(struct usbnet *un, int offset, void *buf, int len)
{
- struct usbnet * const un = &sc->sc_un;
usb_device_request_t req;
usbd_status err;
@@ -438,9 +418,8 @@ udav_csr_write(struct udav_softc *sc, in
}
static int
-udav_csr_read1(struct udav_softc *sc, int offset)
+udav_csr_read1(struct usbnet *un, int offset)
{
- struct usbnet * const un = &sc->sc_un;
uint8_t val = 0;
usbnet_isowned_mii(un);
@@ -451,14 +430,13 @@ udav_csr_read1(struct udav_softc *sc, in
if (usbnet_isdying(un))
return 0;
- return udav_csr_read(sc, offset, &val, 1) ? 0 : val;
+ return udav_csr_read(un, offset, &val, 1) ? 0 : val;
}
/* write a register */
static int
-udav_csr_write1(struct udav_softc *sc, int offset, unsigned char ch)
+udav_csr_write1(struct usbnet *un, int offset, unsigned char ch)
{
- struct usbnet * const un = &sc->sc_un;
usb_device_request_t req;
usbd_status err;
@@ -490,7 +468,6 @@ udav_init_locked(struct ifnet *ifp)
{
struct usbnet * const un = ifp->if_softc;
struct mii_data * const mii = usbnet_mii(un);
- struct udav_softc *sc = usbnet_softc(un);
uint8_t eaddr[ETHER_ADDR_LEN];
int rc;
@@ -508,30 +485,30 @@ udav_init_locked(struct ifnet *ifp)
usbnet_lock_mii_un_locked(un);
memcpy(eaddr, CLLADDR(ifp->if_sadl), sizeof(eaddr));
- udav_csr_write(sc, UDAV_PAR, eaddr, ETHER_ADDR_LEN);
+ udav_csr_write(un, UDAV_PAR, eaddr, ETHER_ADDR_LEN);
/* Initialize network control register */
/* Disable loopback */
- UDAV_CLRBIT(sc, UDAV_NCR, UDAV_NCR_LBK0 | UDAV_NCR_LBK1);
+ UDAV_CLRBIT(un, UDAV_NCR, UDAV_NCR_LBK0 | UDAV_NCR_LBK1);
/* Initialize RX control register */
- UDAV_SETBIT(sc, UDAV_RCR, UDAV_RCR_DIS_LONG | UDAV_RCR_DIS_CRC);
+ UDAV_SETBIT(un, UDAV_RCR, UDAV_RCR_DIS_LONG | UDAV_RCR_DIS_CRC);
/* If we want promiscuous mode, accept all physical frames. */
if (ifp->if_flags & IFF_PROMISC)
- UDAV_SETBIT(sc, UDAV_RCR, UDAV_RCR_ALL | UDAV_RCR_PRMSC);
+ UDAV_SETBIT(un, UDAV_RCR, UDAV_RCR_ALL | UDAV_RCR_PRMSC);
else
- UDAV_CLRBIT(sc, UDAV_RCR, UDAV_RCR_ALL | UDAV_RCR_PRMSC);
+ UDAV_CLRBIT(un, UDAV_RCR, UDAV_RCR_ALL | UDAV_RCR_PRMSC);
/* Load the multicast filter */
udav_setiff_locked(un);
/* Enable RX */
- UDAV_SETBIT(sc, UDAV_RCR, UDAV_RCR_RXEN);
+ UDAV_SETBIT(un, UDAV_RCR, UDAV_RCR_RXEN);
/* clear POWER_DOWN state of internal PHY */
- UDAV_SETBIT(sc, UDAV_GPCR, UDAV_GPCR_GEP_CNTL0);
- UDAV_CLRBIT(sc, UDAV_GPR, UDAV_GPR_GEPIO0);
+ UDAV_SETBIT(un, UDAV_GPCR, UDAV_GPCR_GEP_CNTL0);
+ UDAV_CLRBIT(un, UDAV_GPR, UDAV_GPR_GEPIO0);
usbnet_unlock_mii_un_locked(un);
@@ -575,8 +552,6 @@ udav_reset(struct usbnet *un)
static void
udav_chip_init(struct usbnet *un)
{
- struct udav_softc * const sc = usbnet_softc(un);
-
usbnet_lock_mii_un_locked(un);
/* Select PHY */
@@ -585,19 +560,19 @@ udav_chip_init(struct usbnet *un)
* XXX: force select internal phy.
* external phy routines are not tested.
*/
- UDAV_CLRBIT(sc, UDAV_NCR, UDAV_NCR_EXT_PHY);
+ UDAV_CLRBIT(un, UDAV_NCR, UDAV_NCR_EXT_PHY);
#else
- if (sc->sc_flags & UDAV_EXT_PHY) {
- UDAV_SETBIT(sc, UDAV_NCR, UDAV_NCR_EXT_PHY);
+ if (un->un_flags & UDAV_EXT_PHY) {
+ UDAV_SETBIT(un, UDAV_NCR, UDAV_NCR_EXT_PHY);
} else {
- UDAV_CLRBIT(sc, UDAV_NCR, UDAV_NCR_EXT_PHY);
+ UDAV_CLRBIT(un, UDAV_NCR, UDAV_NCR_EXT_PHY);
}
#endif
- UDAV_SETBIT(sc, UDAV_NCR, UDAV_NCR_RST);
+ UDAV_SETBIT(un, UDAV_NCR, UDAV_NCR_RST);
for (int i = 0; i < UDAV_TX_TIMEOUT; i++) {
- if (!(udav_csr_read1(sc, UDAV_NCR) & UDAV_NCR_RST))
+ if (!(udav_csr_read1(un, UDAV_NCR) & UDAV_NCR_RST))
break;
delay(10); /* XXX */
}
@@ -614,7 +589,6 @@ udav_chip_init(struct usbnet *un)
static void
udav_setiff_locked(struct usbnet *un)
{
- struct udav_softc *sc = usbnet_softc(un);
struct ethercom *ec = usbnet_ec(un);
struct ifnet * const ifp = usbnet_ifp(un);
struct ether_multi *enm;
@@ -629,27 +603,27 @@ udav_setiff_locked(struct usbnet *un)
if (usbnet_isdying(un))
return;
- if (ISSET(sc->sc_flags, UDAV_NO_PHY)) {
- UDAV_SETBIT(sc, UDAV_RCR, UDAV_RCR_ALL);
- UDAV_SETBIT(sc, UDAV_RCR, UDAV_RCR_PRMSC);
+ if (ISSET(un->un_flags, UDAV_NO_PHY)) {
+ UDAV_SETBIT(un, UDAV_RCR, UDAV_RCR_ALL);
+ UDAV_SETBIT(un, UDAV_RCR, UDAV_RCR_PRMSC);
return;
}
if (ifp->if_flags & IFF_PROMISC) {
- UDAV_SETBIT(sc, UDAV_RCR, UDAV_RCR_ALL | UDAV_RCR_PRMSC);
+ UDAV_SETBIT(un, UDAV_RCR, UDAV_RCR_ALL | UDAV_RCR_PRMSC);
return;
} else if (ifp->if_flags & IFF_ALLMULTI) {
allmulti:
ifp->if_flags |= IFF_ALLMULTI;
- UDAV_SETBIT(sc, UDAV_RCR, UDAV_RCR_ALL);
- UDAV_CLRBIT(sc, UDAV_RCR, UDAV_RCR_PRMSC);
+ UDAV_SETBIT(un, UDAV_RCR, UDAV_RCR_ALL);
+ UDAV_CLRBIT(un, UDAV_RCR, UDAV_RCR_PRMSC);
return;
}
/* first, zot all the existing hash bits */
memset(hashes, 0x00, sizeof(hashes));
hashes[7] |= 0x80; /* broadcast address */
- udav_csr_write(sc, UDAV_MAR, hashes, sizeof(hashes));
+ udav_csr_write(un, UDAV_MAR, hashes, sizeof(hashes));
/* now program new ones */
ETHER_LOCK(ec);
@@ -669,10 +643,10 @@ allmulti:
/* disable all multicast */
ifp->if_flags &= ~IFF_ALLMULTI;
- UDAV_CLRBIT(sc, UDAV_RCR, UDAV_RCR_ALL);
+ UDAV_CLRBIT(un, UDAV_RCR, UDAV_RCR_ALL);
/* write hash value to the register */
- udav_csr_write(sc, UDAV_MAR, hashes, sizeof(hashes));
+ udav_csr_write(un, UDAV_MAR, hashes, sizeof(hashes));
}
static void
@@ -792,7 +766,6 @@ udav_stop_cb(struct ifnet *ifp, int disa
static usbd_status
udav_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
{
- struct udav_softc *sc = usbnet_softc(un);
uint8_t data[2];
usbnet_isowned_mii(un);
@@ -816,19 +789,19 @@ udav_mii_read_reg(struct usbnet *un, int
}
/* select internal PHY and set PHY register address */
- udav_csr_write1(sc, UDAV_EPAR,
+ udav_csr_write1(un, UDAV_EPAR,
UDAV_EPAR_PHY_ADR0 | (reg & UDAV_EPAR_EROA_MASK));
/* select PHY operation and start read command */
- udav_csr_write1(sc, UDAV_EPCR, UDAV_EPCR_EPOS | UDAV_EPCR_ERPRR);
+ udav_csr_write1(un, UDAV_EPCR, UDAV_EPCR_EPOS | UDAV_EPCR_ERPRR);
/* XXX: should be wait? */
/* end read command */
- UDAV_CLRBIT(sc, UDAV_EPCR, UDAV_EPCR_ERPRR);
+ UDAV_CLRBIT(un, UDAV_EPCR, UDAV_EPCR_ERPRR);
/* retrieve the result from data registers */
- udav_csr_read(sc, UDAV_EPDRL, data, 2);
+ udav_csr_read(un, UDAV_EPDRL, data, 2);
*val = data[0] | (data[1] << 8);
@@ -841,7 +814,6 @@ udav_mii_read_reg(struct usbnet *un, int
static usbd_status
udav_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
{
- struct udav_softc *sc = usbnet_softc(un);
uint8_t data[2];
usbnet_isowned_mii(un);
@@ -865,21 +837,21 @@ udav_mii_write_reg(struct usbnet *un, in
}
/* select internal PHY and set PHY register address */
- udav_csr_write1(sc, UDAV_EPAR,
+ udav_csr_write1(un, UDAV_EPAR,
UDAV_EPAR_PHY_ADR0 | (reg & UDAV_EPAR_EROA_MASK));
/* put the value to the data registers */
data[0] = val & 0xff;
data[1] = (val >> 8) & 0xff;
- udav_csr_write(sc, UDAV_EPDRL, data, 2);
+ udav_csr_write(un, UDAV_EPDRL, data, 2);
/* select PHY operation and start write command */
- udav_csr_write1(sc, UDAV_EPCR, UDAV_EPCR_EPOS | UDAV_EPCR_ERPRW);
+ udav_csr_write1(un, UDAV_EPCR, UDAV_EPCR_EPOS | UDAV_EPCR_ERPRW);
/* XXX: should be wait? */
/* end write command */
- UDAV_CLRBIT(sc, UDAV_EPCR, UDAV_EPCR_ERPRW);
+ UDAV_CLRBIT(un, UDAV_EPCR, UDAV_EPCR_ERPRW);
return USBD_NORMAL_COMPLETION;
}