Re: ure(4): add preliminary support for RTL8156

2019-12-04 Thread Shawn Chiou
On Tue, Dec 3, 2019 at 5:24 PM Kevin Lo  wrote:

> Hi,
>
> This diff adds preliminary support for RTL8156 to ure(4).
> Tested with the Planex USB-LAN2500R.
>
> Index: share/man/man4/ure.4
> ===
> RCS file: /cvs/src/share/man/man4/ure.4,v
> retrieving revision 1.6
> diff -u -p -u -p -r1.6 ure.4
> --- share/man/man4/ure.429 Aug 2019 08:55:05 -  1.6
> +++ share/man/man4/ure.43 Dec 2019 08:29:40 -
> @@ -31,7 +31,7 @@
>  .Os
>  .Sh NAME
>  .Nm ure
> -.Nd RealTek RTL8152/RTL8153/RTL8153B 10/100/Gigabit USB Ethernet device
> +.Nd RealTek RTL8152/RTL8153/RTL8153B/RTL8156 10/100/Gigabit/2.5Gb USB
> Ethernet device
>  .Sh SYNOPSIS
>  .Cd "ure*   at uhub?"
>  .Cd "rgephy* at mii?"
> @@ -40,12 +40,13 @@
>  The
>  .Nm
>  driver provides support for USB Ethernet adapters based on the RealTek
> -RTL8152, RTL8153 and RTL8153B chipsets.
> +RTL8152, RTL8153, RTL8153B and RTL8156 chipsets.
>  .Pp
>  The RTL8152 contains an integrated Fast Ethernet MAC, which supports
>  both 10 and 100Mbps speeds in either full or half duplex.
>  The RTL8153 and RTL8153B have Gigabit Ethernet MACs and additionally
>  support 1000Mbps speeds.
> +NICs based on the RTL8156 are capable of 10, 100, 1000 and 2500Mbps
> operation.
>  .Pp
>  For more information on configuring this device, see
>  .Xr ifconfig 8 .
> Index: share/man/man4/usb.4
> ===
> RCS file: /cvs/src/share/man/man4/usb.4,v
> retrieving revision 1.197
> diff -u -p -u -p -r1.197 usb.4
> --- share/man/man4/usb.429 Aug 2019 08:55:05 -  1.197
> +++ share/man/man4/usb.43 Dec 2019 08:29:40 -
> @@ -128,7 +128,7 @@ SMSC LAN95xx 10/100 USB Ethernet device
>  .It Xr udav 4
>  Davicom DM9601 10/100 USB Ethernet device
>  .It Xr ure 4
> -RealTek RTL8152/RTL8153/RTL8153B 10/100/Gigabit USB Ethernet device
> +RealTek RTL8152/RTL8153/RTL8153B/RTL8156 10/100/Gigabit/2.5Gb USB
> Ethernet device
>  .It Xr url 4
>  Realtek RTL8150L 10/100 USB Ethernet device
>  .It Xr urndis 4
> Index: sys/dev/usb/if_ure.c
> ===
> RCS file: /cvs/src/sys/dev/usb/if_ure.c,v
> retrieving revision 1.12
> diff -u -p -u -p -r1.12 if_ure.c
> --- sys/dev/usb/if_ure.c29 Aug 2019 14:04:48 -  1.12
> +++ sys/dev/usb/if_ure.c3 Dec 2019 08:29:41 -
> @@ -50,6 +50,7 @@
>  #include 
>  #include 
>
> +#include 
>  #include 
>
>  #include 
> @@ -73,7 +74,8 @@ int   uredebug = 0;
>  const struct usb_devno ure_devs[] = {
> { USB_VENDOR_LENOVO, USB_PRODUCT_LENOVO_DOCK_ETHERNET },
> { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8152 },
> -   { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8153 }
> +   { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8153 },
> +   { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8156 }
>  };
>
>  inture_match(struct device *, void *, void *);
> @@ -107,6 +109,7 @@ voidure_init(void *);
>  void   ure_stop(struct ure_softc *);
>  void   ure_start(struct ifnet *);
>  void   ure_reset(struct ure_softc *);
> +void   ure_watchdog(struct ifnet *);
>
>  void   ure_miibus_statchg(struct device *);
>  inture_miibus_readreg(struct device *, int, int);
> @@ -125,6 +128,9 @@ voidure_tick(void *);
>
>  inture_ifmedia_upd(struct ifnet *);
>  void   ure_ifmedia_sts(struct ifnet *, struct ifmediareq *);
> +void   ure_add_media_types(struct ure_softc *);
> +void   ure_link_state(struct ure_softc *);
> +inture_get_link_status(struct ure_softc *);
>  void   ure_iff(struct ure_softc *);
>  void   ure_rxvlan(struct ure_softc *);
>  inture_ioctl(struct ifnet *, u_long, caddr_t);
> @@ -379,7 +385,57 @@ ure_ifmedia_upd(struct ifnet *ifp)
>  {
> struct ure_softc*sc = ifp->if_softc;
> struct mii_data *mii = >ure_mii;
> -   int err;
> +   struct ifmedia  *ifm = >ure_ifmedia;
> +   int anar, gig, err, reg;
> +
> +   if (sc->ure_flags & URE_FLAG_8156) {
> +   if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
> +   return (EINVAL);
> +
> +   reg = ure_ocp_reg_read(sc, 0xa5d4);
> +   reg &= ~URE_ADV_2500TFDX;
> +
> +   anar = gig = 0;
> +   switch (IFM_SUBTYPE(ifm->ifm_media)) {
> +   case IFM_AUTO:
> +   anar |= ANAR_TX_FD | ANAR_TX | ANAR_10_FD |
> ANAR_10;
> +   gig |= GTCR_ADV_1000TFDX | GTCR_ADV_1000THDX;
> +   reg |= URE_ADV_2500TFDX;
> +   break;
> +   case IFM_2500_T:
> +   anar |= ANAR_TX_FD | ANAR_TX | ANAR_10_FD |
> ANAR_10;
> +   gig |= GTCR_ADV_1000TFDX | 

ure(4): add preliminary support for RTL8156

2019-12-03 Thread Kevin Lo
Hi,

This diff adds preliminary support for RTL8156 to ure(4).
Tested with the Planex USB-LAN2500R.

Index: share/man/man4/ure.4
===
RCS file: /cvs/src/share/man/man4/ure.4,v
retrieving revision 1.6
diff -u -p -u -p -r1.6 ure.4
--- share/man/man4/ure.429 Aug 2019 08:55:05 -  1.6
+++ share/man/man4/ure.43 Dec 2019 08:29:40 -
@@ -31,7 +31,7 @@
 .Os
 .Sh NAME
 .Nm ure
-.Nd RealTek RTL8152/RTL8153/RTL8153B 10/100/Gigabit USB Ethernet device
+.Nd RealTek RTL8152/RTL8153/RTL8153B/RTL8156 10/100/Gigabit/2.5Gb USB Ethernet 
device
 .Sh SYNOPSIS
 .Cd "ure*   at uhub?"
 .Cd "rgephy* at mii?"
@@ -40,12 +40,13 @@
 The
 .Nm
 driver provides support for USB Ethernet adapters based on the RealTek
-RTL8152, RTL8153 and RTL8153B chipsets.
+RTL8152, RTL8153, RTL8153B and RTL8156 chipsets.
 .Pp
 The RTL8152 contains an integrated Fast Ethernet MAC, which supports
 both 10 and 100Mbps speeds in either full or half duplex.
 The RTL8153 and RTL8153B have Gigabit Ethernet MACs and additionally
 support 1000Mbps speeds.
+NICs based on the RTL8156 are capable of 10, 100, 1000 and 2500Mbps operation.
 .Pp
 For more information on configuring this device, see
 .Xr ifconfig 8 .
Index: share/man/man4/usb.4
===
RCS file: /cvs/src/share/man/man4/usb.4,v
retrieving revision 1.197
diff -u -p -u -p -r1.197 usb.4
--- share/man/man4/usb.429 Aug 2019 08:55:05 -  1.197
+++ share/man/man4/usb.43 Dec 2019 08:29:40 -
@@ -128,7 +128,7 @@ SMSC LAN95xx 10/100 USB Ethernet device
 .It Xr udav 4
 Davicom DM9601 10/100 USB Ethernet device
 .It Xr ure 4
-RealTek RTL8152/RTL8153/RTL8153B 10/100/Gigabit USB Ethernet device
+RealTek RTL8152/RTL8153/RTL8153B/RTL8156 10/100/Gigabit/2.5Gb USB Ethernet 
device
 .It Xr url 4
 Realtek RTL8150L 10/100 USB Ethernet device
 .It Xr urndis 4
Index: sys/dev/usb/if_ure.c
===
RCS file: /cvs/src/sys/dev/usb/if_ure.c,v
retrieving revision 1.12
diff -u -p -u -p -r1.12 if_ure.c
--- sys/dev/usb/if_ure.c29 Aug 2019 14:04:48 -  1.12
+++ sys/dev/usb/if_ure.c3 Dec 2019 08:29:41 -
@@ -50,6 +50,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 #include 
@@ -73,7 +74,8 @@ int   uredebug = 0;
 const struct usb_devno ure_devs[] = {
{ USB_VENDOR_LENOVO, USB_PRODUCT_LENOVO_DOCK_ETHERNET },
{ USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8152 },
-   { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8153 }
+   { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8153 },
+   { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8156 }
 };
 
 inture_match(struct device *, void *, void *);
@@ -107,6 +109,7 @@ voidure_init(void *);
 void   ure_stop(struct ure_softc *);
 void   ure_start(struct ifnet *);
 void   ure_reset(struct ure_softc *);
+void   ure_watchdog(struct ifnet *);
 
 void   ure_miibus_statchg(struct device *);
 inture_miibus_readreg(struct device *, int, int);
@@ -125,6 +128,9 @@ voidure_tick(void *);
 
 inture_ifmedia_upd(struct ifnet *);
 void   ure_ifmedia_sts(struct ifnet *, struct ifmediareq *);
+void   ure_add_media_types(struct ure_softc *);
+void   ure_link_state(struct ure_softc *);
+inture_get_link_status(struct ure_softc *);
 void   ure_iff(struct ure_softc *);
 void   ure_rxvlan(struct ure_softc *);
 inture_ioctl(struct ifnet *, u_long, caddr_t);
@@ -379,7 +385,57 @@ ure_ifmedia_upd(struct ifnet *ifp)
 {
struct ure_softc*sc = ifp->if_softc;
struct mii_data *mii = >ure_mii;
-   int err;
+   struct ifmedia  *ifm = >ure_ifmedia;
+   int anar, gig, err, reg;
+
+   if (sc->ure_flags & URE_FLAG_8156) {
+   if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
+   return (EINVAL);
+
+   reg = ure_ocp_reg_read(sc, 0xa5d4);
+   reg &= ~URE_ADV_2500TFDX;
+
+   anar = gig = 0;
+   switch (IFM_SUBTYPE(ifm->ifm_media)) {
+   case IFM_AUTO:
+   anar |= ANAR_TX_FD | ANAR_TX | ANAR_10_FD | ANAR_10;
+   gig |= GTCR_ADV_1000TFDX | GTCR_ADV_1000THDX;
+   reg |= URE_ADV_2500TFDX;
+   break;
+   case IFM_2500_T:
+   anar |= ANAR_TX_FD | ANAR_TX | ANAR_10_FD | ANAR_10;
+   gig |= GTCR_ADV_1000TFDX | GTCR_ADV_1000THDX;
+   reg |= URE_ADV_2500TFDX;
+   ifp->if_baudrate = IF_Mbps(2500);
+   break;
+   case IFM_1000_T:
+   anar |= ANAR_TX_FD | ANAR_TX | ANAR_10_FD | ANAR_10;
+   gig |=