Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb switch to usbnet as softc, using un_flags.
details: https://anonhg.NetBSD.org/src/rev/b496ea9f83fd
branches: trunk
changeset: 453372:b496ea9f83fd
user: mrg <mrg%NetBSD.org@localhost>
date: Fri Aug 09 06:44:42 2019 +0000
description:
switch to usbnet as softc, using un_flags.
diffstat:
sys/dev/usb/if_udav.c | 144 ++++++++++++++++++++-----------------------------
1 files changed, 58 insertions(+), 86 deletions(-)
diffs (truncated from 432 to 300 lines):
diff -r ea961c6d8ced -r b496ea9f83fd sys/dev/usb/if_udav.c
--- a/sys/dev/usb/if_udav.c Fri Aug 09 06:38:39 2019 +0000
+++ b/sys/dev/usb/if_udav.c Fri Aug 09 06:44:42 2019 +0000
@@ -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 @@
#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_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 @@
#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 @@
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 @@
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 @@
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 @@
}
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 @@
/* 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 @@
#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 @@
/* 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 @@
/* 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 @@
/* 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 @@
/* 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 @@
}
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 @@
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 @@
{
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 @@
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 @@
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 @@
* 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
Home |
Main Index |
Thread Index |
Old Index