Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb Convert smsc(4) to usbnet
details: https://anonhg.NetBSD.org/src/rev/68be8fcaa5e9
branches: trunk
changeset: 1002576:68be8fcaa5e9
user: skrll <skrll%NetBSD.org@localhost>
date: Wed Aug 07 07:05:54 2019 +0000
description:
Convert smsc(4) to usbnet
diffstat:
sys/dev/usb/if_smsc.c | 1345 ++++++++++++---------------------------------
sys/dev/usb/if_smscvar.h | 104 ---
2 files changed, 357 insertions(+), 1092 deletions(-)
diffs (truncated from 2046 to 300 lines):
diff -r f040afcc718e -r 68be8fcaa5e9 sys/dev/usb/if_smsc.c
--- a/sys/dev/usb/if_smsc.c Wed Aug 07 06:31:03 2019 +0000
+++ b/sys/dev/usb/if_smsc.c Wed Aug 07 07:05:54 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_smsc.c,v 1.46 2019/08/01 00:10:22 mrg Exp $ */
+/* $NetBSD: if_smsc.c,v 1.47 2019/08/07 07:05:54 skrll 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,48 +61,18 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.46 2019/08/01 00:10:22 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.47 2019/08/07 07:05:54 skrll Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
-#include "opt_inet.h"
#endif
#include <sys/param.h>
-#include <sys/bus.h>
-#include <sys/device.h>
-#include <sys/kernel.h>
-#include <sys/mbuf.h>
-#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/rndsource.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-#include <sys/systm.h>
-
-#include <net/if.h>
-#include <net/if_dl.h>
-#include <net/if_media.h>
-#include <net/if_ether.h>
+#include <sys/module.h>
-#include <net/bpf.h>
-
-#ifdef INET
-#include <netinet/in.h>
-#include <netinet/if_inarp.h>
-#endif
-
-#include <dev/mii/mii.h>
-#include <dev/mii/miivar.h>
-
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
-#include <dev/usb/usbdivar.h>
-#include <dev/usb/usbdevs.h>
+#include <dev/usb/usbnet.h>
#include <dev/usb/if_smscreg.h>
-#include <dev/usb/if_smscvar.h>
#include "ioconf.h"
@@ -110,6 +80,22 @@
int smsc_debug = 0;
#endif
+struct smsc_softc {
+ struct usbnet smsc_un;
+
+ /*
+ * The following stores the settings in the mac control (MAC_CSR)
+ * register
+ */
+ uint32_t sc_mac_csr;
+ uint32_t sc_rev_id;
+
+ uint32_t sc_coe_ctrl;
+};
+
+#define SMSC_MIN_BUFSZ 2048
+#define SMSC_MAX_BUFSZ 18944
+
/*
* Various supported device vendors/products.
*/
@@ -135,84 +121,71 @@
};
#ifdef USB_DEBUG
-#define smsc_dbg_printf(sc, fmt, args...) \
+#define smsc_dbg_printf(un, fmt, args...) \
do { \
if (smsc_debug > 0) \
printf("debug: " fmt, ##args); \
} while(0)
#else
-#define smsc_dbg_printf(sc, fmt, args...)
+#define smsc_dbg_printf(un, fmt, args...)
#endif
-#define smsc_warn_printf(sc, fmt, args...) \
- printf("%s: warning: " fmt, device_xname((sc)->sc_dev), ##args)
+#define smsc_warn_printf(un, fmt, args...) \
+ printf("%s: warning: " fmt, device_xname((un)->un_dev), ##args)
-#define smsc_err_printf(sc, fmt, args...) \
- printf("%s: error: " fmt, device_xname((sc)->sc_dev), ##args)
+#define smsc_err_printf(un, fmt, args...) \
+ printf("%s: error: " fmt, device_xname((un)->un_dev), ##args)
/* Function declarations */
-int smsc_chip_init(struct smsc_softc *);
-void smsc_setmulti(struct smsc_softc *);
-int smsc_setmacaddress(struct smsc_softc *, const uint8_t *);
-
int smsc_match(device_t, cfdata_t, void *);
void smsc_attach(device_t, device_t, void *);
-int smsc_detach(device_t, int);
-int smsc_activate(device_t, enum devact);
+
+CFATTACH_DECL_NEW(usmsc, sizeof(struct smsc_softc),
+ smsc_match, smsc_attach, usbnet_detach, usbnet_activate);
+
+int smsc_chip_init(struct usbnet *);
+int smsc_setmacaddress(struct usbnet *, const uint8_t *);
int smsc_init(struct ifnet *);
int smsc_init_locked(struct ifnet *);
-void smsc_start(struct ifnet *);
-void smsc_start_locked(struct ifnet *);
int smsc_ioctl(struct ifnet *, u_long, void *);
-void smsc_stop(struct ifnet *, int);
-void smsc_stop_locked(struct ifnet *, int);
+void smsc_stop_cb(struct ifnet *, int);
void smsc_reset(struct smsc_softc *);
-struct mbuf *smsc_newbuf(void);
-
-void smsc_tick(void *);
-void smsc_tick_task(void *);
-void smsc_miibus_statchg(struct ifnet *);
-void smsc_miibus_statchg_locked(struct ifnet *);
-int smsc_miibus_readreg(device_t, int, int, uint16_t *);
-int smsc_miibus_writereg(device_t, int, int, uint16_t);
-int smsc_ifmedia_upd(struct ifnet *);
-void smsc_lock_mii(struct smsc_softc *);
-void smsc_unlock_mii(struct smsc_softc *);
-int smsc_tx_list_init(struct smsc_softc *);
-void smsc_tx_list_free(struct smsc_softc *);
-int smsc_rx_list_init(struct smsc_softc *);
-void smsc_rx_list_free(struct smsc_softc *);
-int smsc_encap(struct smsc_softc *, struct mbuf *, int);
-void smsc_rxeof(struct usbd_xfer *, void *, usbd_status);
-void smsc_txeof(struct usbd_xfer *, void *, usbd_status);
+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);
-int smsc_read_reg(struct smsc_softc *, uint32_t, uint32_t *);
-int smsc_write_reg(struct smsc_softc *, uint32_t, uint32_t);
-int smsc_wait_for_bits(struct smsc_softc *, uint32_t, uint32_t);
-int smsc_sethwcsum(struct smsc_softc *);
-
-CFATTACH_DECL_NEW(usmsc, sizeof(struct smsc_softc), smsc_match, smsc_attach,
- smsc_detach, smsc_activate);
+static unsigned smsc_tx_prepare(struct usbnet *, struct mbuf *,
+ struct usbnet_chain *);
+static void smsc_rxeof_loop(struct usbnet *, struct usbd_xfer *,
+ struct usbnet_chain *, uint32_t);
int
-smsc_read_reg(struct smsc_softc *sc, uint32_t off, uint32_t *data)
+smsc_readreg(struct usbnet *un, uint32_t off, uint32_t *data)
{
usb_device_request_t req;
uint32_t buf;
usbd_status err;
+ usbnet_isowned_mii(un);
+
+ if (un->un_dying)
+ return 0;
+
req.bmRequestType = UT_READ_VENDOR_DEVICE;
req.bRequest = SMSC_UR_READ_REG;
USETW(req.wValue, 0);
USETW(req.wIndex, off);
USETW(req.wLength, 4);
- err = usbd_do_request(sc->sc_udev, &req, &buf);
+ err = usbd_do_request(un->un_udev, &req, &buf);
if (err != 0)
- smsc_warn_printf(sc, "Failed to read register 0x%0x\n", off);
+ smsc_warn_printf(un, "Failed to read register 0x%0x\n", off);
*data = le32toh(buf);
@@ -220,12 +193,17 @@
}
int
-smsc_write_reg(struct smsc_softc *sc, uint32_t off, uint32_t data)
+smsc_writereg(struct usbnet *un, uint32_t off, uint32_t data)
{
usb_device_request_t req;
uint32_t buf;
usbd_status err;
+ usbnet_isowned_mii(un);
+
+ if (un->un_dying)
+ return 0;
+
buf = htole32(data);
req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
@@ -234,21 +212,21 @@
USETW(req.wIndex, off);
USETW(req.wLength, 4);
- err = usbd_do_request(sc->sc_udev, &req, &buf);
+ err = usbd_do_request(un->un_udev, &req, &buf);
if (err != 0)
- smsc_warn_printf(sc, "Failed to write register 0x%0x\n", off);
+ smsc_warn_printf(un, "Failed to write register 0x%0x\n", off);
return err;
}
int
-smsc_wait_for_bits(struct smsc_softc *sc, uint32_t reg, uint32_t bits)
+smsc_wait_for_bits(struct usbnet *un, uint32_t reg, uint32_t bits)
{
uint32_t val;
int err, i;
for (i = 0; i < 100; i++) {
- if ((err = smsc_read_reg(sc, reg, &val)) != 0)
+ if ((err = smsc_readreg(un, reg, &val)) != 0)
return err;
if (!(val & bits))
return 0;
@@ -258,62 +236,58 @@
return 1;
}
-int
-smsc_miibus_readreg(device_t dev, int phy, int reg, uint16_t *val)
+usbd_status
+smsc_miibus_readreg(struct usbnet *un, int phy, int reg, uint16_t *val)
{
- struct smsc_softc * const sc = device_private(dev);
uint32_t addr;
uint32_t data = 0;
int rv = 0;
- smsc_lock_mii(sc);
- if (smsc_wait_for_bits(sc, SMSC_MII_ADDR, SMSC_MII_BUSY) != 0) {
- smsc_warn_printf(sc, "MII is busy\n");
+ usbnet_isowned_mii(un);
+
+ if (smsc_wait_for_bits(un, SMSC_MII_ADDR, SMSC_MII_BUSY) != 0) {
+ smsc_warn_printf(un, "MII is busy\n");
rv = -1;
goto done;
}
addr = (phy << 11) | (reg << 6) | SMSC_MII_READ;
- smsc_write_reg(sc, SMSC_MII_ADDR, addr);
+ smsc_writereg(un, SMSC_MII_ADDR, addr);
- if (smsc_wait_for_bits(sc, SMSC_MII_ADDR, SMSC_MII_BUSY) != 0) {
- smsc_warn_printf(sc, "MII read timeout\n");
+ if (smsc_wait_for_bits(un, SMSC_MII_ADDR, SMSC_MII_BUSY) != 0) {
+ smsc_warn_printf(un, "MII read timeout\n");
rv = ETIMEDOUT;
}
- smsc_read_reg(sc, SMSC_MII_DATA, &data);
+ smsc_readreg(un, SMSC_MII_DATA, &data);
done:
- smsc_unlock_mii(sc);
-
*val = data & 0xffff;
return rv;
}
-int
-smsc_miibus_writereg(device_t dev, int phy, int reg, uint16_t val)
+usbd_status
+smsc_miibus_writereg(struct usbnet *un, int phy, int reg, uint16_t val)
{
- struct smsc_softc * const sc = device_private(dev);
uint32_t addr;
- if (sc->sc_phyno != phy)
Home |
Main Index |
Thread Index |
Old Index