Source-Changes-HG archive

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

[src/trunk]: src Add ure(4): RealTek RTL8152/RTL8153 10/100/Gigabit USB Ether...



details:   https://anonhg.NetBSD.org/src/rev/8c13db4b1aea
branches:  trunk
changeset: 448651:8c13db4b1aea
user:      rin <rin%NetBSD.org@localhost>
date:      Wed Feb 06 11:55:05 2019 +0000

description:
Add ure(4): RealTek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device.
Ported from OpenBSD. Support for RX/TX checksum offload added by myself.

diffstat:

 distrib/sets/lists/man/mi        |     5 +-
 distrib/sets/lists/modules/mi    |     4 +-
 doc/CHANGES                      |     4 +-
 share/man/man4/Makefile          |     4 +-
 share/man/man4/ure.4             |    79 +
 sys/dev/usb/files.usb            |     7 +-
 sys/dev/usb/if_ure.c             |  1661 ++++++++++++++++++++++++++++++++++++++
 sys/dev/usb/if_urereg.h          |   381 ++++++++
 sys/dev/usb/if_urevar.h          |   139 +++
 sys/modules/Makefile             |     3 +-
 sys/modules/if_ure/Makefile      |    13 +
 sys/modules/if_ure/if_ure.ioconf |    10 +
 12 files changed, 2303 insertions(+), 7 deletions(-)

diffs (truncated from 2429 to 300 lines):

diff -r be0ca937f9cc -r 8c13db4b1aea distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Wed Feb 06 11:54:02 2019 +0000
+++ b/distrib/sets/lists/man/mi Wed Feb 06 11:55:05 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1636 2018/12/29 11:30:11 maxv Exp $
+# $NetBSD: mi,v 1.1637 2019/02/06 11:55:05 rin Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1883,6 +1883,7 @@
 ./usr/share/man/cat4/upl.0                     man-sys-catman          .cat
 ./usr/share/man/cat4/uplcom.0                  man-sys-catman          .cat
 ./usr/share/man/cat4/urandom.0                 man-sys-catman          .cat
+./usr/share/man/cat4/ure.0                     man-sys-catman          .cat
 ./usr/share/man/cat4/urio.0                    man-sys-catman          .cat
 ./usr/share/man/cat4/url.0                     man-sys-catman          .cat
 ./usr/share/man/cat4/urlphy.0                  man-sys-catman          .cat
@@ -4963,6 +4964,7 @@
 ./usr/share/man/html4/upl.html                 man-sys-htmlman         html
 ./usr/share/man/html4/uplcom.html              man-sys-htmlman         html
 ./usr/share/man/html4/urandom.html             man-sys-htmlman         html
+./usr/share/man/html4/ure.html                 man-sys-htmlman         html
 ./usr/share/man/html4/urio.html                        man-sys-htmlman         html
 ./usr/share/man/html4/url.html                 man-sys-htmlman         html
 ./usr/share/man/html4/urlphy.html              man-sys-htmlman         html
@@ -7967,6 +7969,7 @@
 ./usr/share/man/man4/upl.4                     man-sys-man             .man
 ./usr/share/man/man4/uplcom.4                  man-sys-man             .man
 ./usr/share/man/man4/urandom.4                 man-sys-man             .man
+./usr/share/man/man4/ure.4                     man-sys-man             .man
 ./usr/share/man/man4/urio.4                    man-sys-man             .man
 ./usr/share/man/man4/url.4                     man-sys-man             .man
 ./usr/share/man/man4/urlphy.4                  man-sys-man             .man
diff -r be0ca937f9cc -r 8c13db4b1aea distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi     Wed Feb 06 11:54:02 2019 +0000
+++ b/distrib/sets/lists/modules/mi     Wed Feb 06 11:55:05 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.118 2019/01/27 02:08:33 pgoyette Exp $
+# $NetBSD: mi,v 1.119 2019/02/06 11:55:05 rin Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -230,6 +230,8 @@
 ./@MODULEDIR@/if_strip/if_strip.kmod           base-kernel-modules     kmod
 ./@MODULEDIR@/if_tun                           base-kernel-modules     kmod
 ./@MODULEDIR@/if_tun/if_tun.kmod               base-kernel-modules     kmod
+./@MODULEDIR@/if_ure                           base-kernel-modules     kmod
+./@MODULEDIR@/if_ure/if_ure.kmod               base-kernel-modules     kmod
 ./@MODULEDIR@/if_vioif                         base-obsolete           obsolete
 ./@MODULEDIR@/if_vioif/if_vioif.kmod           base-obsolete           obsolete
 ./@MODULEDIR@/if_vlan                          base-kernel-modules     kmod
diff -r be0ca937f9cc -r 8c13db4b1aea doc/CHANGES
--- a/doc/CHANGES       Wed Feb 06 11:54:02 2019 +0000
+++ b/doc/CHANGES       Wed Feb 06 11:55:05 2019 +0000
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:                   <$Revision: 1.2497 $>
+# LIST OF CHANGES FROM LAST RELEASE:                   <$Revision: 1.2498 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -322,3 +322,5 @@
                the kernel module framework. [pgoyette 20190127]
        macppc: Include EDID block for Clamshell iBook G3 displays.
                [sevan 20190128]
+       ure(4): Add driver for Realtek RTL8152/RTL8153 from OpenBSD.
+               [rin 20190206]
diff -r be0ca937f9cc -r 8c13db4b1aea share/man/man4/Makefile
--- a/share/man/man4/Makefile   Wed Feb 06 11:54:02 2019 +0000
+++ b/share/man/man4/Makefile   Wed Feb 06 11:55:05 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.676 2018/12/12 08:20:53 maxv Exp $
+#      $NetBSD: Makefile,v 1.677 2019/02/06 11:55:05 rin Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/18/93
 
 MAN=   aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -82,7 +82,7 @@
        ucom.4 ucycom.4 udav.4 udsbr.4 uftdi.4 ugen.4 ugensa.4 uhci.4 uhid.4 \
        uhidev.4 uhmodem.4 uhso.4 uipad.4 uipaq.4 uirda.4 ukbd.4 ukyopon.4 \
        ulpt.4 umass.4 umcs.4 umct.4 umidi.4 umodem.4 ums.4 upgt.4 upl.4 \
-       uplcom.4 urio.4 url.4 urndis.4 urtw.4 urtwn.4 \
+       uplcom.4 ure.4 urio.4 url.4 urndis.4 urtw.4 urtwn.4 \
        usb.4 uscanner.4 uslsa.4 usmsc.4 usscanner.4 \
        ustir.4 uthum.4 utoppy.4 uts.4 uvideo.4 uvisor.4 uvscom.4 uyap.4 \
        uyurex.4 \
diff -r be0ca937f9cc -r 8c13db4b1aea share/man/man4/ure.4
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man4/ure.4      Wed Feb 06 11:55:05 2019 +0000
@@ -0,0 +1,79 @@
+.\" $NetBSD: ure.4,v 1.1 2019/02/06 11:55:05 rin Exp $
+.\" $OpenBSD: ure.4,v 1.5 2017/04/16 20:26:34 jmc Exp $
+.\"
+.\" Copyright (c) 2015 Kevin Lo <kevlo%FreeBSD.org@localhost>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD: head/share/man/man4/ure.4 291557 2015-12-01 05:12:13Z kevlo $
+.\"
+.Dd $Mdocdate: April 16 2017 $
+.Dt URE 4
+.Os
+.Sh NAME
+.Nm ure
+.Nd RealTek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device
+.Sh SYNOPSIS
+.Cd "ure*   at uhub?"
+.Cd "rgephy* at mii?"
+.Cd "rlphy* at mii?"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for USB Ethernet adapters based on the RealTek
+RTL8152 USB Fast Ethernet and RTL8153 USB Gigabit Ethernet controller
+chips.
+.Pp
+The RTL8152 contains an integrated Fast Ethernet MAC, which supports
+both 10 and 100Mbps speeds in either full or half duplex.
+The RTL8153 has a Gigabit Ethernet MAC and additionally supports
+1000Mbps speeds.
+.Pp
+For more information on configuring this device, see
+.Xr ifconfig 8 .
+.Sh SEE ALSO
+.Xr arp 4 ,
+.Xr ifmedia 4 ,
+.Xr mii 4 ,
+.Xr netintro 4 ,
+.Xr rgephy 4 ,
+.Xr rlphy 4 ,
+.Xr uhub 4 ,
+.Xr usb 4 ,
+.Xr ifconfig 8
+.Sh HISTORY
+The
+.Nm
+device driver first appeared in
+.Ox 6.0
+and
+.Nx 9.0 .
+.Sh AUTHORS
+The
+.Nm
+driver was written by
+.An Kevin Lo Aq Mt kevlo%FreeBSD.org@localhost
+for
+.Ox and ported to
+.Nx by
+.An Rin Okuyama Aq Mt rin%NetBSD.org@localhost .
diff -r be0ca937f9cc -r 8c13db4b1aea sys/dev/usb/files.usb
--- a/sys/dev/usb/files.usb     Wed Feb 06 11:54:02 2019 +0000
+++ b/sys/dev/usb/files.usb     Wed Feb 06 11:55:05 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.usb,v 1.153 2018/10/24 07:42:12 jdolecek Exp $
+#      $NetBSD: files.usb,v 1.154 2019/02/06 11:55:06 rin Exp $
 #
 # Config file and device description for machine-independent USB code.
 # Included by ports that need it.  Ports that use it must provide
@@ -389,6 +389,11 @@
 attach umb at usbifif
 file   dev/usb/if_umb.c                umb
 
+# RealTek RTL8152 and RTL8153
+device ure: arp, ether, ifnet, mii, mii_phy
+attach ure at usbdevif
+file   dev/usb/if_ure.c                ure
+
 # Serial drivers
 # Modems
 define umodem_common
diff -r be0ca937f9cc -r 8c13db4b1aea sys/dev/usb/if_ure.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/if_ure.c      Wed Feb 06 11:55:05 2019 +0000
@@ -0,0 +1,1661 @@
+/*     $NetBSD: if_ure.c,v 1.1 2019/02/06 11:55:06 rin Exp $   */
+/*     $OpenBSD: if_ure.c,v 1.10 2018/11/02 21:32:30 jcs Exp $ */
+/*-
+ * Copyright (c) 2015-2016 Kevin Lo <kevlo%FreeBSD.org@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* RealTek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.1 2019/02/06 11:55:06 rin Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_usb.h"
+#include "opt_inet.h"
+#endif
+
+#include <sys/param.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/socket.h>
+#include <sys/device.h>
+
+#include <sys/rndsource.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_ether.h>
+#include <net/if_media.h>
+
+#include <net/bpf.h>
+
+#include <netinet/in.h>
+
+#include <netinet/in_offload.h>                /* XXX for in_undefer_cksum() */
+#ifdef INET6
+#include <netinet6/in6_offload.h>      /* XXX for in6_undefer_cksum() */
+#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/ic/rtl81x9reg.h>         /* XXX for RTK_GMEDIASTAT */
+#include <dev/usb/if_urereg.h>
+#include <dev/usb/if_urevar.h>
+
+#define URE_PRINTF(sc, fmt, args...) \
+       device_printf((sc)->ure_dev, "%s: " fmt, __func__, ##args);
+
+#define URE_DEBUG
+#ifdef URE_DEBUG
+#define DPRINTF(x)     do { if (uredebug) printf x; } while (0)
+#define DPRINTFN(n, x) do { if (uredebug >= (n)) printf x; } while (0)
+int    uredebug = 1;
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n, x)
+#endif
+
+static const struct usb_devno ure_devs[] = {
+       { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8152 },
+       { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8153 }
+};
+
+static int     ure_match(device_t, cfdata_t, void *);
+static void    ure_attach(device_t, device_t, void *);
+static int     ure_detach(device_t, int);
+static int     ure_activate(device_t, enum devact);
+
+static int     ure_ctl(struct ure_softc *, uint8_t, uint16_t, uint16_t,
+                   void *, int);
+static int     ure_read_mem(struct ure_softc *, uint16_t, uint16_t, void *,
+                   int);
+static int     ure_write_mem(struct ure_softc *, uint16_t, uint16_t, void *,
+                   int);
+static uint8_t ure_read_1(struct ure_softc *, uint16_t, uint16_t);
+static uint16_t        ure_read_2(struct ure_softc *, uint16_t, uint16_t);



Home | Main Index | Thread Index | Old Index