Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add mue(4), driver for Microchip LAN75xx/LAN78xx known as in...



details:   https://anonhg.NetBSD.org/src/rev/43487216cc2d
branches:  trunk
changeset: 364112:43487216cc2d
user:      rin <rin%NetBSD.org@localhost>
date:      Sat Aug 25 20:12:21 2018 +0000

description:
Add mue(4), driver for Microchip LAN75xx/LAN78xx known as internal NIC of
Raspberry Pi 3 B+, from OpenBSD.

Tested on Raspberry Pi 3 B+ (LAN7800) and Z-TEK ZE582 (LAN7500).

* BUGS/TODO

- If the media type is set to something other than 1000baseT-FDX, data
  transmission becomes quite unstable. Also, ukphy(4) recognize 1000baseT as
  a supported media type, but it is not in fact.

- Catch up with changes made to usmsc(4) in nick-nhusb branch, i.e.,
  make the driver MP-safe.

- Support RX/VLAN/TX chekcsum offloading.

diffstat:

 distrib/sets/lists/man/mi        |     5 +-
 distrib/sets/lists/modules/mi    |     4 +-
 share/man/man4/Makefile          |     5 +-
 share/man/man4/mue.4             |    71 +
 sys/dev/usb/files.usb            |     7 +-
 sys/dev/usb/if_mue.c             |  1773 ++++++++++++++++++++++++++++++++++++++
 sys/dev/usb/if_muereg.h          |   225 ++++
 sys/dev/usb/if_muevar.h          |   106 ++
 sys/dev/usb/usbdevices.config    |     3 +-
 sys/modules/Makefile             |     3 +-
 sys/modules/if_mue/Makefile      |    13 +
 sys/modules/if_mue/if_mue.ioconf |    10 +
 12 files changed, 2218 insertions(+), 7 deletions(-)

diffs (truncated from 2347 to 300 lines):

diff -r 7fe601c5d996 -r 43487216cc2d distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Sat Aug 25 19:38:37 2018 +0000
+++ b/distrib/sets/lists/man/mi Sat Aug 25 20:12:21 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1611 2018/08/25 11:10:52 martin Exp $
+# $NetBSD: mi,v 1.1612 2018/08/25 20:12:21 rin Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1455,6 +1455,7 @@
 ./usr/share/man/cat4/mt2131.0                  man-sys-catman          .cat
 ./usr/share/man/cat4/mtd.0                     man-sys-catman          .cat
 ./usr/share/man/cat4/mtio.0                    man-sys-catman          .cat
+./usr/share/man/cat4/mue.0                     man-sys-catman          .cat
 ./usr/share/man/cat4/multicast.0               man-sys-catman          .cat
 ./usr/share/man/cat4/music.0                   man-sys-catman          .cat
 ./usr/share/man/cat4/mvme68k/autoconf.0                man-sys-catman          .cat
@@ -4566,6 +4567,7 @@
 ./usr/share/man/html4/mt2131.html              man-sys-htmlman         html
 ./usr/share/man/html4/mtd.html                 man-sys-htmlman         html
 ./usr/share/man/html4/mtio.html                        man-sys-htmlman         html
+./usr/share/man/html4/mue.html                 man-sys-htmlman         html
 ./usr/share/man/html4/multicast.html           man-sys-htmlman         html
 ./usr/share/man/html4/music.html               man-sys-htmlman         html
 ./usr/share/man/html4/mvme68k/autoconf.html    man-sys-htmlman         html
@@ -7527,6 +7529,7 @@
 ./usr/share/man/man4/mt2131.4                  man-sys-man             .man
 ./usr/share/man/man4/mtd.4                     man-sys-man             .man
 ./usr/share/man/man4/mtio.4                    man-sys-man             .man
+./usr/share/man/man4/mue.4                     man-sys-man             .man
 ./usr/share/man/man4/multicast.4               man-sys-man             .man
 ./usr/share/man/man4/music.4                   man-sys-man             .man
 ./usr/share/man/man4/mvme68k/autoconf.4                man-sys-man             .man
diff -r 7fe601c5d996 -r 43487216cc2d distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi     Sat Aug 25 19:38:37 2018 +0000
+++ b/distrib/sets/lists/modules/mi     Sat Aug 25 20:12:21 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.116 2018/05/20 14:08:33 thorpej Exp $
+# $NetBSD: mi,v 1.117 2018/08/25 20:12:21 rin Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -166,6 +166,8 @@
 ./@MODULEDIR@/if_loop/if_loop.kmod             base-kernel-modules     kmod
 ./@MODULEDIR@/if_mpls                          base-kernel-modules     kmod
 ./@MODULEDIR@/if_mpls/if_mpls.kmod             base-kernel-modules     kmod
+./@MODULEDIR@/if_mue                           base-kernel-modules     kmod
+./@MODULEDIR@/if_mue/if_mue.kmod               base-kernel-modules     kmod
 ./@MODULEDIR@/if_npflog                                base-kernel-modules     kmod
 ./@MODULEDIR@/if_npflog/if_npflog.kmod         base-kernel-modules     kmod
 ./@MODULEDIR@/if_ppp                           base-kernel-modules     kmod
diff -r 7fe601c5d996 -r 43487216cc2d share/man/man4/Makefile
--- a/share/man/man4/Makefile   Sat Aug 25 19:38:37 2018 +0000
+++ b/share/man/man4/Makefile   Sat Aug 25 20:12:21 2018 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.664 2018/08/14 14:49:13 maxv Exp $
+#      $NetBSD: Makefile,v 1.665 2018/08/25 20:12:21 rin Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/18/93
 
 MAN=   aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -75,7 +75,8 @@
        zero.4 zstty.4 zyd.4
 
 # USB devices
-MAN+=  atu.4 aubtfwl.4 aue.4 axe.4 axen.4 cdce.4 cue.4 ehci.4 kue.4 ohci.4 \
+MAN+=  atu.4 aubtfwl.4 aue.4 axe.4 axen.4 cdce.4 cue.4 ehci.4 kue.4 mue.4 \
+       ohci.4 \
        slhci.4 stuirda.4 u3g.4 ualea.4 uatp.4 uaudio.4 uberry.4 ubsa.4 ubt.4 \
        uchcom.4 \
        ucom.4 ucycom.4 udav.4 udsbr.4 uftdi.4 ugen.4 ugensa.4 uhci.4 uhid.4 \
diff -r 7fe601c5d996 -r 43487216cc2d share/man/man4/mue.4
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man4/mue.4      Sat Aug 25 20:12:21 2018 +0000
@@ -0,0 +1,71 @@
+.\"     $NetBSD: mue.4,v 1.1 2018/08/25 20:12:21 rin Exp $
+.\"     $OpenBSD: mue.4,v 1.2 2018/08/03 06:13:14 jmc Exp $
+.\"
+.\" Copyright (c) 2018 Kevin Lo <kevlo%openbsd.org@localhost>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: August 25 2018 $
+.Dt MUE 4
+.Os
+.Sh NAME
+.Nm mue
+.Nd Microchip LAN75xx/LAN78xx 10/100/Gigabit USB Ethernet device
+.Sh SYNOPSIS
+.Cd "mue*   at uhub?"
+.Cd "ukphy* at mii?"
+.Sh DESCRIPTION
+The
+.Nm
+driver supports Microchip LAN7500/LAN7505/LAN7515/LAN7850 USB 2.0 Gigabit
+Ethernet devices and LAN7800/LAN7801 USB 3.0 Gigabit Ethernet devices,
+including the following:
+.Pp
+.Bl -tag -width Ds -offset indent -compact
+.It Raspberry Pi 3 Model B+
+.It Microchip EVB-LAN7800LC
+.It Z-TEK ZE582
+.El
+.Pp
+For more information on configuring this device, see
+.Xr ifconfig 8 .
+.Sh SEE ALSO
+.Xr arp 4 ,
+.Xr ifmedia 4 ,
+.Xr intro 4 ,
+.Xr netintro 4 ,
+.Xr ukphy 4 ,
+.Xr usb 4 ,
+.\".Xr hostname.if 5 ,
+.Xr ifconfig 8
+.Sh HISTORY
+The
+.Nm
+device driver first appeared in
+.Ox 6.3 and
+.Nx 9.0 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Kevin Lo Aq Mt kevlo%openbsd.org@localhost
+for
+.Ox and ported to
+.Nx by
+.An Rin Okuyama Aq Mt rin%netbsd.org@localhost .
+.Sh BUGS
+If the media type is set to other than 1000BASE-T full-duplex,
+data transmission becomes quite unstable.
+Also, ukphy mistakenly recognizes 1000BASE-T half-duplex as a supported media
+type, although the adapters do not support it.
diff -r 7fe601c5d996 -r 43487216cc2d sys/dev/usb/files.usb
--- a/sys/dev/usb/files.usb     Sat Aug 25 19:38:37 2018 +0000
+++ b/sys/dev/usb/files.usb     Sat Aug 25 20:12:21 2018 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.usb,v 1.151 2018/07/31 16:44:29 khorben Exp $
+#      $NetBSD: files.usb,v 1.152 2018/08/25 20:12:22 rin Exp $
 #
 # Config file and device description for machine-independent USB code.
 # Included by ports that need it.  Ports that use it must provide
@@ -369,6 +369,11 @@
 attach axen at usbdevif
 file   dev/usb/if_axen.c               axen
 
+# Microchip LAN750x and LAN85xx
+device mue: arp, ether, ifnet, mii, mii_phy
+attach mue at usbdevif
+file   dev/usb/if_mue.c                mue
+
 # DAVICOM DM9601
 device udav: arp, ether, ifnet, mii, mii_phy
 attach udav at usbdevif
diff -r 7fe601c5d996 -r 43487216cc2d sys/dev/usb/if_mue.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/if_mue.c      Sat Aug 25 20:12:21 2018 +0000
@@ -0,0 +1,1773 @@
+/*     $NetBSD: if_mue.c,v 1.1 2018/08/25 20:12:22 rin Exp $   */
+/*     $OpenBSD: if_mue.c,v 1.3 2018/08/04 16:42:46 jsg Exp $  */
+
+/*
+ * Copyright (c) 2018 Kevin Lo <kevlo%openbsd.org@localhost>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* Driver for Microchip LAN7500/LAN7800 chipsets. */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.1 2018/08/25 20:12:22 rin Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_usb.h"
+#include "opt_inet.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/cprng.h>
+#include <sys/bus.h>
+#include <sys/systm.h>
+#include <sys/sockio.h>
+#include <sys/mbuf.h>
+#include <sys/mutex.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/socket.h>
+
+#include <sys/device.h>
+
+#include <sys/rndsource.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_media.h>
+#include <net/if_ether.h>
+
+#include <net/bpf.h>
+
+#include <netinet/in.h>
+#include <netinet/if_inarp.h>
+
+#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/if_muereg.h>
+#include <dev/usb/if_muevar.h>
+
+#define MUE_PRINTF(sc, fmt, args...)                                   \
+       device_printf((sc)->mue_dev, "%s: " fmt, __func__, ##args);
+
+#ifdef USB_DEBUG
+int muedebug = 0;
+#define DPRINTF(sc, fmt, args...)                                      \
+       do {                                                            \
+               if (muedebug)                                           \
+                       MUE_PRINTF(sc, fmt, ##args);                    \
+       } while (0 /* CONSTCOND */)
+#else
+#define DPRINTF(sc, fmt, args...)      /* nothing */
+#endif
+
+/*
+ * Various supported device vendors/products.
+ */
+struct mue_type {
+       struct usb_devno        mue_dev;
+       uint16_t                mue_flags;
+#define LAN7500                0x0001  /* LAN7500 */
+};
+
+const struct mue_type mue_devs[] = {
+       { { USB_VENDOR_SMSC, USB_PRODUCT_SMSC_LAN7500 }, LAN7500 },
+       { { USB_VENDOR_SMSC, USB_PRODUCT_SMSC_LAN7505 }, LAN7500 },
+       { { USB_VENDOR_SMSC, USB_PRODUCT_SMSC_LAN7800 }, 0 },
+       { { USB_VENDOR_SMSC, USB_PRODUCT_SMSC_LAN7801 }, 0 },
+       { { USB_VENDOR_SMSC, USB_PRODUCT_SMSC_LAN7850 }, 0 }
+};
+
+#define MUE_LOOKUP(uaa)        ((const struct mue_type *)usb_lookup(mue_devs, \
+    uaa->uaa_vendor, uaa->uaa_product))
+
+#define MUE_ENADDR_LO(enaddr) \
+    ((enaddr[3] << 24) | (enaddr[2] << 16) | (enaddr[1] << 8) | enaddr[0])
+#define MUE_ENADDR_HI(enaddr) \
+    ((enaddr[5] << 8) | enaddr[4])
+
+static int     mue_match(device_t, cfdata_t, void *);
+static void    mue_attach(device_t, device_t, void *);
+static int     mue_detach(device_t, int);
+static int     mue_activate(device_t, enum devact);
+
+static uint32_t        mue_csr_read(struct mue_softc *, uint32_t);
+static int     mue_csr_write(struct mue_softc *, uint32_t, uint32_t);
+static int     mue_wait_for_bits(struct mue_softc *sc, uint32_t, uint32_t,
+                   uint32_t, uint32_t);
+
+static void    mue_lock_mii(struct mue_softc *);
+static void    mue_unlock_mii(struct mue_softc *);
+
+static int     mue_miibus_readreg(device_t, int, int);
+static void    mue_miibus_writereg(device_t, int, int, int);
+static void    mue_miibus_statchg(struct ifnet *);
+static int     mue_ifmedia_upd(struct ifnet *);
+static void    mue_ifmedia_sts(struct ifnet *, struct ifmediareq *);
+
+static uint8_t mue_eeprom_getbyte(struct mue_softc *, int, uint8_t *);
+static int     mue_read_eeprom(struct mue_softc *, uint8_t *, int, int);
+static bool    mue_eeprom_present(struct mue_softc *sc);
+
+static int     mue_read_otp_raw(struct mue_softc *, uint8_t *, int, int);
+static int     mue_read_otp(struct mue_softc *, uint8_t *, int, int);



Home | Main Index | Thread Index | Old Index