diff --git a/etc/devd/usb.conf b/etc/devd/usb.conf index 449b20b..10ee84b 100644 --- a/etc/devd/usb.conf +++ b/etc/devd/usb.conf @@ -833,7 +833,7 @@ nomatch 32 { match "bus" "uhub[0-9]+"; match "mode" "host"; match "vendor" "0x050d"; - match "product" "0x935a"; + match "product" "(0x935a|0x935b)"; action "kldload -n if_run"; }; @@ -1801,6 +1801,14 @@ nomatch 32 { match "bus" "uhub[0-9]+"; match "mode" "host"; match "vendor" "0x0846"; + match "product" "0x1100"; + action "kldload -n uslcom"; +}; + +nomatch 32 { + match "bus" "uhub[0-9]+"; + match "mode" "host"; + match "vendor" "0x0846"; match "product" "0x4240"; action "kldload -n if_upgt"; }; @@ -2185,7 +2193,23 @@ nomatch 32 { match "bus" "uhub[0-9]+"; match "mode" "host"; match "vendor" "0x0af0"; - match "product" "(0x7601|0xc031|0xd013|0xd031)"; + match "product" "0x7601"; + action "kldload -n uhso"; +}; + +nomatch 32 { + match "bus" "uhub[0-9]+"; + match "mode" "host"; + match "vendor" "0x0af0"; + match "product" "0x9000"; + action "kldload -n u3g"; +}; + +nomatch 32 { + match "bus" "uhub[0-9]+"; + match "mode" "host"; + match "vendor" "0x0af0"; + match "product" "(0xc031|0xd013|0xd031)"; action "kldload -n uhso"; }; @@ -2289,7 +2313,7 @@ nomatch 32 { match "bus" "uhub[0-9]+"; match "mode" "host"; match "vendor" "0x0b05"; - match "product" "0x17b5"; + match "product" "(0x17b5|0x17cb)"; action "kldload -n ng_ubt"; }; @@ -2361,7 +2385,23 @@ nomatch 32 { match "bus" "uhub[0-9]+"; match "mode" "host"; match "vendor" "0x0b95"; - match "product" "(0x1720|0x1780|0x7720|0x772a|0x772b|0x7e2b)"; + match "product" "(0x1720|0x1780)"; + action "kldload -n if_axe"; +}; + +nomatch 32 { + match "bus" "uhub[0-9]+"; + match "mode" "host"; + match "vendor" "0x0b95"; + match "product" "(0x178a|0x1790)"; + action "kldload -n if_axge"; +}; + +nomatch 32 { + match "bus" "uhub[0-9]+"; + match "mode" "host"; + match "vendor" "0x0b95"; + match "product" "(0x7720|0x772a|0x772b|0x7e2b)"; action "kldload -n if_axe"; }; @@ -2433,7 +2473,7 @@ nomatch 32 { match "bus" "uhub[0-9]+"; match "mode" "host"; match "vendor" "0x0bda"; - match "product" "(0x8176|0x8177|0x8178|0x817a|0x817b|0x817c|0x817d|0x817e)"; + match "product" "(0x8176|0x8176|0x8177|0x8178|0x817a|0x817b|0x817c|0x817d|0x817e)"; action "kldload -n if_urtwn"; }; @@ -3104,6 +3144,14 @@ nomatch 32 { nomatch 32 { match "bus" "uhub[0-9]+"; match "mode" "host"; + match "vendor" "0x0fde"; + match "product" "0xca05"; + action "kldload -n uslcom"; +}; + +nomatch 32 { + match "bus" "uhub[0-9]+"; + match "mode" "host"; match "vendor" "0x0fe6"; match "product" "(0x8101|0x9700)"; action "kldload -n if_udav"; @@ -3265,7 +3313,7 @@ nomatch 32 { match "bus" "uhub[0-9]+"; match "mode" "host"; match "vendor" "0x10c4"; - match "product" "(0x8066|0x806f|0x807a|0x80c4|0x80ca|0x80dd|0x80ed|0x80f6|0x8115|0x813d|0x813f|0x814a|0x814a|0x814b|0x8156|0x815e|0x815f|0x818b|0x819f|0x81a6|0x81a9|0x81ac|0x81ad|0x81c8|0x81e2|0x81e7|0x81e8|0x81f2|0x8218|0x822b|0x826b|0x8293|0x82f9|0x8341|0x8382|0x83a8|0x83d8|0x8411|0x8418|0x846e|0x8477|0x85ea|0x85eb|0x8664|0x8665|0xea60|0xea61|0xea70|0xea71|0xea80|0xf001|0xf002|0xf003|0xf004)"; + match "product" "(0x8066|0x806f|0x807a|0x80c4|0x80ca|0x80dd|0x80ed|0x80f6|0x8115|0x813d|0x813f|0x814a|0x814a|0x814b|0x8156|0x815e|0x815f|0x818b|0x819f|0x81a6|0x81a9|0x81ac|0x81ad|0x81c8|0x81e2|0x81e7|0x81e8|0x81f2|0x8218|0x822b|0x826b|0x8293|0x82f9|0x8341|0x8382|0x83a8|0x83d8|0x8411|0x8418|0x846e|0x8477|0x85ea|0x85eb|0x85f8|0x8664|0x8665|0x88a4|0x88a5|0xea60|0xea61|0xea70|0xea71|0xea80|0xf001|0xf002|0xf003|0xf004)"; action "kldload -n uslcom"; }; @@ -3777,7 +3825,7 @@ nomatch 32 { match "bus" "uhub[0-9]+"; match "mode" "host"; match "vendor" "0x148f"; - match "product" "(0x2770|0x2870|0x3070|0x3071|0x3072|0x3370|0x3572|0x8070)"; + match "product" "(0x2770|0x2870|0x3070|0x3071|0x3072|0x3370|0x3572|0x5370|0x8070)"; action "kldload -n if_run"; }; @@ -4376,6 +4424,14 @@ nomatch 32 { nomatch 32 { match "bus" "uhub[0-9]+"; match "mode" "host"; + match "vendor" "0x1adb"; + match "product" "0x0001"; + action "kldload -n uslcom"; +}; + +nomatch 32 { + match "bus" "uhub[0-9]+"; + match "mode" "host"; match "vendor" "0x1b3d"; match "product" "(0x0100|0x0101|0x0102|0x0103|0x0104|0x0105|0x0106|0x0107|0x0108|0x0109|0x010a|0x010b|0x010c|0x010d|0x010e|0x010f|0x0110|0x0111|0x0112|0x0113|0x0114|0x0115|0x0116|0x0117|0x0118|0x0119|0x011a|0x011b|0x011c|0x011d|0x011e|0x011f|0x0120|0x0121|0x0122|0x0123|0x0124|0x0125|0x0126|0x0128|0x0129|0x012a|0x012b|0x012d|0x012e|0x012f|0x0130|0x0131|0x0132|0x0133|0x0134|0x0135|0x0136|0x0137|0x0138|0x0139|0x013a|0x013b|0x013c|0x013d|0x013e|0x013f|0x0140|0x0141|0x0142|0x0143|0x0144|0x0145|0x0146|0x0147|0x0148|0x0149|0x014a|0x014b|0x014c|0x014d|0x014e|0x014f|0x0150|0x0151|0x0152|0x0153|0x0159|0x015a|0x015b|0x015c|0x015d|0x015e|0x015f|0x0160|0x0161|0x0162|0x0163|0x0164|0x0165|0x0166|0x0167|0x0168|0x0169|0x016a|0x016b|0x016c|0x016d|0x016e|0x016f|0x0170|0x0171|0x0172|0x0173|0x0174|0x0175|0x0176|0x0177|0x0178|0x0179|0x017a|0x017b|0x017c|0x017d|0x017e|0x017f|0x0180|0x0181|0x0182|0x0183|0x0184|0x0185|0x0186|0x0187|0x0188|0x0189|0x018a|0x018b|0x018c|0x018d|0x018e|0x018f|0x0190|0x0191|0x0192|0x0193|0x0194|0x0195|0x0196|0x0197|0x0198|0x0199|0x019a|0x019b|0x019c|0x019d|0x019e|0x019f|0x01a0|0x01a1|0x01a2|0x01a3|0x01a4|0x01a5|0x01a6|0x01a7|0x01a8|0x01a9|0x01aa|0x01ab|0x01ac|0x01ad|0x01ae|0x01af|0x01b0|0x01b1|0x01b2|0x01b3|0x01b4|0x01b5|0x01b6|0x01b7|0x01b8|0x01b9|0x01ba|0x01bb|0x01bc|0x01bd|0x01be|0x01bf|0x01c0|0x01c1|0x01c2|0x01c3|0x01c4|0x01c5|0x01c6|0x01c7|0x01c8|0x01c9|0x01ca|0x01cb|0x01cc|0x01cd|0x01ce|0x01cf|0x01d0|0x01d1|0x01d2|0x01d3|0x01d4|0x01d5|0x01d6|0x01d7|0x01d8|0x01d9|0x01da|0x01db|0x01dc|0x01dd|0x01de|0x01df|0x01e0|0x01e1|0x01e2|0x01e3|0x01e4|0x01e5|0x01e6|0x01e7|0x01e8|0x01e9|0x01ea|0x01eb|0x01ec|0x01ed|0x01ee|0x01ef|0x01f0|0x01f1|0x01f2|0x01f3|0x01f4|0x01f5|0x01f6|0x01f7|0x01f8|0x01f9|0x01fa|0x01fb|0x01fc|0x01fd|0x01fe|0x01ff)"; action "kldload -n uftdi"; @@ -4512,6 +4568,14 @@ nomatch 32 { nomatch 32 { match "bus" "uhub[0-9]+"; match "mode" "host"; + match "vendor" "0x1fb9"; + match "product" "(0x0100|0x0200|0x0201|0x0202|0x0203|0x0300|0x0301|0x0302|0x0303|0x0400|0x0401|0x0402|0x0403|0x0404|0x0600|0x0601|0x0602|0x0700|0x0701)"; + action "kldload -n uslcom"; +}; + +nomatch 32 { + match "bus" "uhub[0-9]+"; + match "mode" "host"; match "vendor" "0x2001"; match "product" "(0x1a00|0x1a02)"; action "kldload -n if_axe"; @@ -4561,7 +4625,7 @@ nomatch 32 { match "bus" "uhub[0-9]+"; match "mode" "host"; match "vendor" "0x2001"; - match "product" "(0x3c09|0x3c0a)"; + match "product" "(0x3c09|0x3c0a|0x3c15|0x3c1b)"; action "kldload -n if_run"; }; @@ -4768,6 +4832,14 @@ nomatch 32 { nomatch 32 { match "bus" "uhub[0-9]+"; match "mode" "host"; + match "vendor" "0x2405"; + match "product" "0x0003"; + action "kldload -n uslcom"; +}; + +nomatch 32 { + match "bus" "uhub[0-9]+"; + match "mode" "host"; match "vendor" "0x2478"; match "product" "0x2008"; action "kldload -n uplcom"; @@ -5122,6 +5194,15 @@ nomatch 32 { match "mode" "host"; match "intclass" "0x02"; match "intsubclass" "0x02"; + match "intprotocol" "0x00"; + action "kldload -n umodem"; +}; + +nomatch 32 { + match "bus" "uhub[0-9]+"; + match "mode" "host"; + match "intclass" "0x02"; + match "intsubclass" "0x02"; match "intprotocol" "0x01"; action "kldload -n umodem"; }; @@ -5260,5 +5341,5 @@ nomatch 32 { action "kldload -n umass"; }; -# 2537 USB entries processed +# 2573 USB entries processed diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile index bc26f13..b09b815 100644 --- a/share/man/man4/Makefile +++ b/share/man/man4/Makefile @@ -67,6 +67,7 @@ MAN= aac.4 \ auditpipe.4 \ aue.4 \ axe.4 \ + axge.4 \ bce.4 \ bfe.4 \ bge.4 \ diff --git a/share/man/man4/axge.4 b/share/man/man4/axge.4 new file mode 100644 index 0000000..1868203 --- /dev/null +++ b/share/man/man4/axge.4 @@ -0,0 +1,149 @@ +.\" Copyright (c) 1997, 1998, 1999, 2000-2003 +.\" Bill Paul . 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. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Bill Paul. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY Bill Paul 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 Bill Paul OR THE VOICES IN HIS HEAD +.\" 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$ +.\" +.Dd November 12, 2013 +.Dt AXGE 4 +.Os +.Sh NAME +.Nm axge +.Nd "ASIX Electronics AX88178A/AX88179 USB Gigabit Ethernet driver" +.Sh SYNOPSIS +To compile this driver into the kernel, +place the following lines in your +kernel configuration file: +.Bd -ragged -offset indent +.Cd "device ehci" +.Cd "device uhci" +.Cd "device ohci" +.Cd "device usb" +.Cd "device miibus" +.Cd "device axge" +.Ed +.Pp +Alternatively, to load the driver as a +module at boot time, place the following line in +.Xr loader.conf 5 : +.Bd -literal -offset indent +if_axge_load="YES" +.Ed +.Sh DESCRIPTION +The +.Nm +driver provides support for USB Gigabit Ethernet adapters based on the ASIX +Electronics AX88179 USB 3.0 and AX88178A USB 2.0 chipsets. +.Pp +The AX88179 and AX88178A contain a 10/100/1000 Ethernet MAC with a GMII +interface for interfacing with the Gigabit Ethernet PHY. +.Pp +These devices will operate with both USB 1.x and USB 2.0 controllers, and the +AX88179 will operate with USB 3.0 controllers. +Packets are received and transmitted over separate USB bulk transfer endpoints. +.Pp +The +.Nm +driver supports the following media types: +.Bl -tag -width ".Cm 10baseT/UTP" +.It Cm autoselect +Enable autoselection of the media type and options. +The user can manually override +the autoselected mode by adding media options to +.Xr rc.conf 5 . +.It Cm 10baseT/UTP +Set 10Mbps operation. +The +.Xr ifconfig 8 +.Cm mediaopt +option can also be used to select either +.Cm full-duplex +or +.Cm half-duplex +modes. +.It Cm 100baseTX +Set 100Mbps (Fast Ethernet) operation. +The +.Xr ifconfig 8 +.Cm mediaopt +option can also be used to select either +.Cm full-duplex +or +.Cm half-duplex +modes. +.It Cm 1000baseT +Set 1000Mbps (Gigabit Ethernet) operation (AX88178 only). +The +.Xr ifconfig 8 +.Cm mediaopt +option can also be used to select either +.Cm full-duplex +or +.Cm half-duplex +modes. +.El +.Pp +The +.Nm +driver supports the following media options: +.Bl -tag -width ".Cm full-duplex" +.It Cm full-duplex +Force full duplex operation. +.It Cm half-duplex +Force half duplex operation. +.El +.Pp +For more information on configuring this device, see +.Xr ifconfig 8 . +.Sh SEE ALSO +.Xr altq 4 , +.Xr arp 4 , +.Xr miibus 4 , +.Xr netintro 4 , +.Xr ng_ether 4 , +.Xr rgephy 4 , +.Xr vlan 4 , +.Xr ifconfig 8 +.Sh HISTORY +The +.Nm +device driver first appeared in +.Fx 10.1 . +.Sh AUTHORS +The +.Nm +driver was written by +.An Kevin Lo Aq kevlo@FreeBSD.org +and +.An Li-Wen Hsu Aq lwhsu@FreeBSD.org . +This manual page was adapted by +.An Mark Johnston Aq markj@FreeBSD.org +from the +.Xr axe 4 +manual page. diff --git a/sys/conf/files b/sys/conf/files index 776a59e..12ed191 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -2311,6 +2311,7 @@ dev/usb/usb_util.c optional usb # dev/usb/net/if_aue.c optional aue dev/usb/net/if_axe.c optional axe +dev/usb/net/if_axge.c optional axge dev/usb/net/if_cdce.c optional cdce dev/usb/net/if_cue.c optional cue dev/usb/net/if_ipheth.c optional ipheth @@ -2321,8 +2322,8 @@ dev/usb/net/if_smsc.c optional smsc dev/usb/net/if_udav.c optional udav dev/usb/net/if_usie.c optional usie dev/usb/net/ruephy.c optional rue -dev/usb/net/usb_ethernet.c optional aue | axe | cdce | cue | kue | mos | \ - rue | smsc | udav | ipheth +dev/usb/net/usb_ethernet.c optional aue | axe | axge | cdce | cue | kue | \ + mos | rue | smsc | udav | ipheth dev/usb/net/uhso.c optional uhso # # USB WLAN drivers diff --git a/sys/dev/usb/net/if_axge.c b/sys/dev/usb/net/if_axge.c new file mode 100644 index 0000000..2a983a1 --- /dev/null +++ b/sys/dev/usb/net/if_axge.c @@ -0,0 +1,1023 @@ +/*- + * Copyright (c) 2013 Kevin Lo + * 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * ASIX Electronics AX88178A/AX88179 USB 2.0/3.0 gigabit ethernet driver. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include "usbdevs.h" + +#define USB_DEBUG_VAR axge_debug +#include +#include + +#include +#include + +/* + * Various supported device vendors/products. + */ + +static const STRUCT_USB_HOST_ID axge_devs[] = { +#define AXGE_DEV(v,p) { USB_VP(USB_VENDOR_##v, USB_PRODUCT_##v##_##p) } + AXGE_DEV(ASIX, AX88178A), + AXGE_DEV(ASIX, AX88179), + /* AXGE_DEV(SITECOMEU, LN032), */ +#undef AXGE_DEV +}; + +static const struct { + unsigned char ctrl, timer_l, timer_h, size, ifg; +} AX88179_BULKIN_SIZE[] = { + {7, 0x4f, 0, 0x12, 0xff}, + {7, 0x20, 3, 0x16, 0xff}, + {7, 0xae, 7, 0x18, 0xff}, + {7, 0xcc, 0x4c, 0x18, 8}, +}; + +/* prototypes */ + +static device_probe_t axge_probe; +static device_attach_t axge_attach; +static device_detach_t axge_detach; + +static usb_callback_t axge_bulk_read_callback; +static usb_callback_t axge_bulk_write_callback; + +static miibus_readreg_t axge_miibus_readreg; +static miibus_writereg_t axge_miibus_writereg; +static miibus_statchg_t axge_miibus_statchg; + +static uether_fn_t axge_attach_post; +static uether_fn_t axge_init; +static uether_fn_t axge_stop; +static uether_fn_t axge_start; +static uether_fn_t axge_tick; +static uether_fn_t axge_setmulti; +static uether_fn_t axge_setpromisc; + +static int axge_read_mem(struct axge_softc *, uint8_t, uint16_t, + uint16_t, void *, int); +static void axge_write_mem(struct axge_softc *, uint8_t, uint16_t, + uint16_t, void *, int); +static uint16_t axge_read_cmd_2(struct axge_softc *, uint8_t, uint16_t, + uint16_t); +static void axge_write_cmd_1(struct axge_softc *, uint8_t, uint16_t, + uint16_t, uint8_t); +static void axge_write_cmd_2(struct axge_softc *, uint8_t, uint16_t, + uint16_t, uint16_t); +static void axge_chip_init(struct axge_softc *); +static void axge_reset(struct axge_softc *); + +static int axge_attach_post_sub(struct usb_ether *); +static int axge_ifmedia_upd(struct ifnet *); +static void axge_ifmedia_sts(struct ifnet *, struct ifmediareq *); +static int axge_ioctl(struct ifnet *, u_long, caddr_t); +static int axge_rx_frame(struct usb_ether *, struct usb_page_cache *, int); +static int axge_rxeof(struct usb_ether *, struct usb_page_cache *, + unsigned int, unsigned int, struct axge_csum_hdr *); +static void axge_csum_cfg(struct usb_ether *); + +#define AXGE_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP) + +#ifdef USB_DEBUG +static int axge_debug = 0; + +static SYSCTL_NODE(_hw_usb, OID_AUTO, axge, CTLFLAG_RW, 0, "USB axge"); +SYSCTL_INT(_hw_usb_axge, OID_AUTO, debug, CTLFLAG_RW, &axge_debug, 0, + "Debug level"); +#endif + +static const struct usb_config axge_config[AXGE_N_TRANSFER] = { + [AXGE_BULK_DT_WR] = { + .type = UE_BULK, + .endpoint = UE_ADDR_ANY, + .direction = UE_DIR_OUT, + .frames = 16, + .bufsize = 16 * (MCLBYTES + 16), + .flags = {.pipe_bof = 1,.force_short_xfer = 1,}, + .callback = axge_bulk_write_callback, + .timeout = 10000, /* 10 seconds */ + }, + [AXGE_BULK_DT_RD] = { + .type = UE_BULK, + .endpoint = UE_ADDR_ANY, + .direction = UE_DIR_IN, + .bufsize = 20480, + .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, + .callback = axge_bulk_read_callback, + .timeout = 0, /* no timeout */ + }, +}; + +static device_method_t axge_methods[] = { + /* Device interface. */ + DEVMETHOD(device_probe, axge_probe), + DEVMETHOD(device_attach, axge_attach), + DEVMETHOD(device_detach, axge_detach), + + /* MII interface. */ + DEVMETHOD(miibus_readreg, axge_miibus_readreg), + DEVMETHOD(miibus_writereg, axge_miibus_writereg), + DEVMETHOD(miibus_statchg, axge_miibus_statchg), + + DEVMETHOD_END +}; + +static driver_t axge_driver = { + .name = "axge", + .methods = axge_methods, + .size = sizeof(struct axge_softc), +}; + +static devclass_t axge_devclass; + +DRIVER_MODULE(axge, uhub, axge_driver, axge_devclass, NULL, NULL); +DRIVER_MODULE(miibus, axge, miibus_driver, miibus_devclass, NULL, NULL); +MODULE_DEPEND(axge, uether, 1, 1, 1); +MODULE_DEPEND(axge, usb, 1, 1, 1); +MODULE_DEPEND(axge, ether, 1, 1, 1); +MODULE_DEPEND(axge, miibus, 1, 1, 1); +MODULE_VERSION(axge, 1); + +static const struct usb_ether_methods axge_ue_methods = { + .ue_attach_post = axge_attach_post, + .ue_attach_post_sub = axge_attach_post_sub, + .ue_start = axge_start, + .ue_init = axge_init, + .ue_stop = axge_stop, + .ue_tick = axge_tick, + .ue_setmulti = axge_setmulti, + .ue_setpromisc = axge_setpromisc, + .ue_mii_upd = axge_ifmedia_upd, + .ue_mii_sts = axge_ifmedia_sts, +}; + +static int +axge_read_mem(struct axge_softc *sc, uint8_t cmd, uint16_t index, + uint16_t val, void *buf, int len) +{ + struct usb_device_request req; + + AXGE_LOCK_ASSERT(sc, MA_OWNED); + + req.bmRequestType = UT_READ_VENDOR_DEVICE; + req.bRequest = cmd; + USETW(req.wValue, val); + USETW(req.wIndex, index); + USETW(req.wLength, len); + + return (uether_do_request(&sc->sc_ue, &req, buf, 1000)); +} + +static void +axge_write_mem(struct axge_softc *sc, uint8_t cmd, uint16_t index, + uint16_t val, void *buf, int len) +{ + struct usb_device_request req; + + AXGE_LOCK_ASSERT(sc, MA_OWNED); + + req.bmRequestType = UT_WRITE_VENDOR_DEVICE; + req.bRequest = cmd; + USETW(req.wValue, val); + USETW(req.wIndex, index); + USETW(req.wLength, len); + + if (uether_do_request(&sc->sc_ue, &req, buf, 1000)) { + /* Error ignored. */ + } +} + +static uint16_t +axge_read_cmd_2(struct axge_softc *sc, uint8_t cmd, uint16_t index, + uint16_t reg) +{ + uint8_t val[2]; + + axge_read_mem(sc, cmd, index, reg, &val, 2); + return (UGETW(val)); +} + +static void +axge_write_cmd_1(struct axge_softc *sc, uint8_t cmd, uint16_t index, + uint16_t reg, uint8_t val) +{ + axge_write_mem(sc, cmd, index, reg, &val, 1); +} + +static void +axge_write_cmd_2(struct axge_softc *sc, uint8_t cmd, uint16_t index, + uint16_t reg, uint16_t val) +{ + uint8_t temp[2]; + + USETW(temp, val); + axge_write_mem(sc, cmd, index, reg, &temp, 2); +} + +static int +axge_miibus_readreg(device_t dev, int phy, int reg) +{ + struct axge_softc *sc; + uint16_t val; + int locked; + + sc = device_get_softc(dev); + locked = mtx_owned(&sc->sc_mtx); + if (!locked) + AXGE_LOCK(sc); + + val = axge_read_cmd_2(sc, AXGE_ACCESS_PHY, reg, phy); + + if (!locked) + AXGE_UNLOCK(sc); + + return (val); +} + +static int +axge_miibus_writereg(device_t dev, int phy, int reg, int val) +{ + struct axge_softc *sc; + int locked; + + sc = device_get_softc(dev); + if (sc->sc_phyno != phy) + return (0); + locked = mtx_owned(&sc->sc_mtx); + if (!locked) + AXGE_LOCK(sc); + + axge_write_cmd_2(sc, AXGE_ACCESS_PHY, reg, phy, val); + + if (!locked) + AXGE_UNLOCK(sc); + + return (0); +} + +static void +axge_miibus_statchg(device_t dev) +{ + struct axge_softc *sc; + struct mii_data *mii; + struct ifnet *ifp; + uint16_t val; + int locked; + + sc = device_get_softc(dev); + mii = GET_MII(sc); + locked = mtx_owned(&sc->sc_mtx); + if (!locked) + AXGE_LOCK(sc); + + ifp = uether_getifp(&sc->sc_ue); + if (mii == NULL || ifp == NULL || + (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) + goto done; + + sc->sc_flags &= ~AXGE_FLAG_LINK; + if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == + (IFM_ACTIVE | IFM_AVALID)) { + switch (IFM_SUBTYPE(mii->mii_media_active)) { + case IFM_10_T: + case IFM_100_TX: + case IFM_1000_T: + sc->sc_flags |= AXGE_FLAG_LINK; + break; + default: + break; + } + } + + /* Lost link, do nothing. */ + if ((sc->sc_flags & AXGE_FLAG_LINK) == 0) + goto done; + + val = 0; + if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) { + val |= AXGE_MEDIUM_FULL_DUPLEX; + if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_TXPAUSE) != 0) + val |= AXGE_MEDIUM_TXFLOW_CTRLEN; + if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_RXPAUSE) != 0) + val |= AXGE_MEDIUM_RXFLOW_CTRLEN; + } + val |= AXGE_MEDIUM_RECEIVE_EN | AXGE_MEDIUM_ALWAYS_ONE; + switch (IFM_SUBTYPE(mii->mii_media_active)) { + case IFM_1000_T: + val |= AXGE_MEDIUM_GIGAMODE; + case IFM_100_TX: + val |= AXGE_MEDIUM_PS; + case IFM_10_T: + /* Doesn't need to be handled. */ + break; + } + axge_write_cmd_2(sc, AXGE_ACCESS_MAC, 2, AXGE_MEDIUM_STATUS_MODE, val); + +done: + if (!locked) + AXGE_UNLOCK(sc); +} + +static void +axge_chip_init(struct axge_softc *sc) +{ + /* Power up ethernet PHY. */ + axge_write_cmd_2(sc, AXGE_ACCESS_MAC, 2, AXGE_PHYPWR_RSTCTL, 0); + axge_write_cmd_2(sc, AXGE_ACCESS_MAC, 2, AXGE_PHYPWR_RSTCTL, + AXGE_PHYPWR_RSTCTL_IPRL); + uether_pause(&sc->sc_ue, hz / 4); + axge_write_cmd_1(sc, AXGE_ACCESS_MAC, 1, AXGE_CLK_SELECT, + AXGE_CLK_SELECT_ACS | AXGE_CLK_SELECT_BCS); + uether_pause(&sc->sc_ue, hz / 10); +} + +static void +axge_reset(struct axge_softc *sc) +{ + struct usb_config_descriptor *cd; + usb_error_t err; + + cd = usbd_get_config_descriptor(sc->sc_ue.ue_udev); + + err = usbd_req_set_config(sc->sc_ue.ue_udev, &sc->sc_mtx, + cd->bConfigurationValue); + if (err) + DPRINTF("reset failed (ignored)\n"); + + /* Wait a little while for the chip to get its brains in order. */ + uether_pause(&sc->sc_ue, hz / 100); + + /* Reinitialize controller to achieve full reset. */ + axge_chip_init(sc); +} + +static void +axge_attach_post(struct usb_ether *ue) +{ + struct axge_softc *sc; + uint8_t tmp[5]; + + sc = uether_getsc(ue); + sc->sc_phyno = 3; + + /* Initialize controller and get station address. */ + axge_chip_init(sc); + + memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5); + axge_read_mem(sc, AXGE_ACCESS_MAC, 5, AXGE_RX_BULKIN_QCTRL, tmp, 5); + axge_read_mem(sc, AXGE_ACCESS_MAC, ETHER_ADDR_LEN, AXGE_NODE_ID, + ue->ue_eaddr, ETHER_ADDR_LEN); +} + +static int +axge_attach_post_sub(struct usb_ether *ue) +{ + struct axge_softc *sc; + struct ifnet *ifp; + int error; + + sc = uether_getsc(ue); + ifp = ue->ue_ifp; + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + ifp->if_start = uether_start; + ifp->if_ioctl = axge_ioctl; + ifp->if_init = uether_init; + IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); + ifp->if_snd.ifq_drv_maxlen = ifqmaxlen; + IFQ_SET_READY(&ifp->if_snd); + + ifp->if_capabilities |= IFCAP_VLAN_MTU | IFCAP_TXCSUM | IFCAP_RXCSUM; + ifp->if_hwassist = AXGE_CSUM_FEATURES; + ifp->if_capenable = ifp->if_capabilities; + + mtx_lock(&Giant); + error = mii_attach(ue->ue_dev, &ue->ue_miibus, ifp, + uether_ifmedia_upd, ue->ue_methods->ue_mii_sts, + BMSR_DEFCAPMASK, sc->sc_phyno, MII_OFFSET_ANY, 0); + mtx_unlock(&Giant); + + return (error); +} + +/* + * Set media options. + */ +static int +axge_ifmedia_upd(struct ifnet *ifp) +{ + struct axge_softc *sc; + struct mii_data *mii; + struct mii_softc *miisc; + int error; + + sc = ifp->if_softc; + mii = GET_MII(sc); + AXGE_LOCK_ASSERT(sc, MA_OWNED); + + LIST_FOREACH(miisc, &mii->mii_phys, mii_list) + PHY_RESET(miisc); + error = mii_mediachg(mii); + + return (error); +} + +/* + * Report current media status. + */ +static void +axge_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) +{ + struct axge_softc *sc; + struct mii_data *mii; + + sc = ifp->if_softc; + mii = GET_MII(sc); + AXGE_LOCK(sc); + mii_pollstat(mii); + ifmr->ifm_active = mii->mii_media_active; + ifmr->ifm_status = mii->mii_media_status; + AXGE_UNLOCK(sc); +} + +/* + * Probe for a AX88179 chip. + */ +static int +axge_probe(device_t dev) +{ + struct usb_attach_arg *uaa; + + uaa = device_get_ivars(dev); + if (uaa->usb_mode != USB_MODE_HOST) + return (ENXIO); + if (uaa->info.bConfigIndex != AXGE_CONFIG_IDX) + return (ENXIO); + if (uaa->info.bIfaceIndex != AXGE_IFACE_IDX) + return (ENXIO); + + return (usbd_lookup_id_by_uaa(axge_devs, sizeof(axge_devs), uaa)); +} + +/* + * Attach the interface. Allocate softc structures, do ifmedia + * setup and ethernet/BPF attach. + */ +static int +axge_attach(device_t dev) +{ + struct usb_attach_arg *uaa; + struct axge_softc *sc; + struct usb_ether *ue; + uint8_t iface_index; + int error; + + uaa = device_get_ivars(dev); + sc = device_get_softc(dev); + ue = &sc->sc_ue; + + device_set_usb_desc(dev); + mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); + + iface_index = AXGE_IFACE_IDX; + error = usbd_transfer_setup(uaa->device, &iface_index, + sc->sc_xfer, axge_config, AXGE_N_TRANSFER, sc, &sc->sc_mtx); + if (error) { + device_printf(dev, "allocating USB transfers failed\n"); + goto detach; + } + + ue->ue_sc = sc; + ue->ue_dev = dev; + ue->ue_udev = uaa->device; + ue->ue_mtx = &sc->sc_mtx; + ue->ue_methods = &axge_ue_methods; + + error = uether_ifattach(ue); + if (error) { + device_printf(dev, "could not attach interface\n"); + goto detach; + } + return (0); /* success */ + +detach: + axge_detach(dev); + return (ENXIO); /* failure */ +} + +static int +axge_detach(device_t dev) +{ + struct axge_softc *sc; + struct usb_ether *ue; + + sc = device_get_softc(dev); + ue = &sc->sc_ue; + usbd_transfer_unsetup(sc->sc_xfer, AXGE_N_TRANSFER); + uether_ifdetach(ue); + mtx_destroy(&sc->sc_mtx); + + return (0); +} + +static void +axge_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error) +{ + struct axge_softc *sc; + struct usb_ether *ue; + struct usb_page_cache *pc; + int actlen; + + sc = usbd_xfer_softc(xfer); + ue = &sc->sc_ue; + usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); + + switch (USB_GET_STATE(xfer)) { + case USB_ST_TRANSFERRED: + pc = usbd_xfer_get_frame(xfer, 0); + axge_rx_frame(ue, pc, actlen); + + /* FALLTHROUGH */ + case USB_ST_SETUP: +tr_setup: + usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); + usbd_transfer_submit(xfer); + uether_rxflush(ue); + return; + + default: + if (error != USB_ERR_CANCELLED) { + usbd_xfer_set_stall(xfer); + goto tr_setup; + } + return; + + } +} + +static void +axge_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error) +{ + struct axge_softc *sc; + struct ifnet *ifp; + struct usb_page_cache *pc; + struct mbuf *m; + uint32_t txhdr; + uint32_t txhdr2; + int nframes; + int frm_len; + + sc = usbd_xfer_softc(xfer); + ifp = uether_getifp(&sc->sc_ue); + + switch (USB_GET_STATE(xfer)) { + case USB_ST_TRANSFERRED: + ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + /* FALLTHROUGH */ + case USB_ST_SETUP: +tr_setup: + if ((sc->sc_flags & AXGE_FLAG_LINK) == 0 || + (ifp->if_drv_flags & IFF_DRV_OACTIVE) != 0) { + /* + * Don't send anything if there is no link or + * controller is busy. + */ + return; + } + + for (nframes = 0; nframes < 16 && + !IFQ_DRV_IS_EMPTY(&ifp->if_snd); nframes++) { + IFQ_DRV_DEQUEUE(&ifp->if_snd, m); + if (m == NULL) + break; + usbd_xfer_set_frame_offset(xfer, nframes * MCLBYTES, + nframes); + frm_len = 0; + pc = usbd_xfer_get_frame(xfer, nframes); + + txhdr = m->m_pkthdr.len; + txhdr = htole32(txhdr); + usbd_copy_in(pc, 0, &txhdr, sizeof(txhdr)); + frm_len += sizeof(txhdr); + + txhdr2 = 0; + if ((m->m_pkthdr.len + sizeof(txhdr) + sizeof(txhdr2)) % + usbd_xfer_max_framelen(xfer) == 0) { + txhdr2 |= 0x80008000; + } + txhdr2 = htole32(txhdr2); + usbd_copy_in(pc, frm_len, &txhdr2, sizeof(txhdr2)); + frm_len += sizeof(txhdr2); + + /* Next copy in the actual packet. */ + usbd_m_copy_in(pc, frm_len, m, 0, m->m_pkthdr.len); + frm_len += m->m_pkthdr.len; + + /* + * XXX + * Update TX packet counter here. This is not + * correct way but it seems that there is no way + * to know how many packets are sent at the end + * of transfer because controller combines + * multiple writes into single one if there is + * room in TX buffer of controller. + */ + ifp->if_opackets++; + + /* + * if there's a BPF listener, bounce a copy + * of this frame to him: + */ + BPF_MTAP(ifp, m); + + m_freem(m); + + /* Set frame length. */ + usbd_xfer_set_frame_len(xfer, nframes, frm_len); + } + if (nframes != 0) { + usbd_xfer_set_frames(xfer, nframes); + usbd_transfer_submit(xfer); + ifp->if_drv_flags |= IFF_DRV_OACTIVE; + } + return; + /* NOTREACHED */ + default: + ifp->if_oerrors++; + ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + + if (error != USB_ERR_CANCELLED) { + usbd_xfer_set_stall(xfer); + goto tr_setup; + } + return; + + } +} + +static void +axge_tick(struct usb_ether *ue) +{ + struct axge_softc *sc; + struct mii_data *mii; + + sc = uether_getsc(ue); + mii = GET_MII(sc); + AXGE_LOCK_ASSERT(sc, MA_OWNED); + + mii_tick(mii); + if ((sc->sc_flags & AXGE_FLAG_LINK) == 0) { + axge_miibus_statchg(ue->ue_dev); + if ((sc->sc_flags & AXGE_FLAG_LINK) != 0) + axge_start(ue); + } +} + +static void +axge_setmulti(struct usb_ether *ue) +{ + struct axge_softc *sc; + struct ifnet *ifp; + struct ifmultiaddr *ifma; + uint32_t h; + uint16_t rxmode; + uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + + sc = uether_getsc(ue); + ifp = uether_getifp(ue); + h = 0; + AXGE_LOCK_ASSERT(sc, MA_OWNED); + + rxmode = axge_read_cmd_2(sc, AXGE_ACCESS_MAC, 2, AXGE_RX_CTL); + if (ifp->if_flags & (IFF_ALLMULTI | IFF_PROMISC)) { + rxmode |= AXGE_RX_CTL_AMALL; + axge_write_cmd_2(sc, AXGE_ACCESS_MAC, 2, AXGE_RX_CTL, rxmode); + return; + } + rxmode &= ~AXGE_RX_CTL_AMALL; + + if_maddr_rlock(ifp); + TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { + if (ifma->ifma_addr->sa_family != AF_LINK) + continue; + h = ether_crc32_be(LLADDR((struct sockaddr_dl *) + ifma->ifma_addr), ETHER_ADDR_LEN) >> 26; + hashtbl[h / 8] |= 1 << (h % 8); + } + if_maddr_runlock(ifp); + + axge_write_mem(sc, AXGE_ACCESS_MAC, 8, AXGE_MULTI_FILTER_ARRY, + (void *)&hashtbl, 8); + axge_write_cmd_2(sc, AXGE_ACCESS_MAC, 2, AXGE_RX_CTL, rxmode); +} + +static void +axge_setpromisc(struct usb_ether *ue) +{ + struct axge_softc *sc; + struct ifnet *ifp; + uint16_t rxmode; + + sc = uether_getsc(ue); + ifp = uether_getifp(ue); + rxmode = axge_read_cmd_2(sc, AXGE_ACCESS_MAC, 2, AXGE_RX_CTL); + + if (ifp->if_flags & IFF_PROMISC) + rxmode |= AXGE_RX_CTL_PRO; + else + rxmode &= ~AXGE_RX_CTL_PRO; + + axge_write_cmd_2(sc, AXGE_ACCESS_MAC, 2, AXGE_RX_CTL, rxmode); + axge_setmulti(ue); +} + +static void +axge_start(struct usb_ether *ue) +{ + struct axge_softc *sc; + + sc = uether_getsc(ue); + /* + * Start the USB transfers, if not already started. + */ + usbd_transfer_start(sc->sc_xfer[AXGE_BULK_DT_RD]); + usbd_transfer_start(sc->sc_xfer[AXGE_BULK_DT_WR]); +} + +static void +axge_init(struct usb_ether *ue) +{ + struct axge_softc *sc; + struct ifnet *ifp; + uint16_t rxmode; + + sc = uether_getsc(ue); + ifp = uether_getifp(ue); + AXGE_LOCK_ASSERT(sc, MA_OWNED); + + if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) + return; + + /* + * Cancel pending I/O and free all RX/TX buffers. + */ + axge_stop(ue); + + axge_reset(sc); + + /* Set MAC address. */ + axge_write_mem(sc, AXGE_ACCESS_MAC, ETHER_ADDR_LEN, AXGE_NODE_ID, + IF_LLADDR(ifp), ETHER_ADDR_LEN); + + axge_write_cmd_1(sc, AXGE_ACCESS_MAC, 1, AXGE_PAUSE_WATERLVL_LOW, 0x34); + axge_write_cmd_1(sc, AXGE_ACCESS_MAC, 1, AXGE_PAUSE_WATERLVL_HIGH, + 0x52); + + /* Configure TX/RX checksum offloading. */ + axge_csum_cfg(ue); + + /* Configure RX settings. */ + rxmode = (AXGE_RX_CTL_IPE | AXGE_RX_CTL_AM | AXGE_RX_CTL_START); + + /* If we want promiscuous mode, set the allframes bit. */ + if (ifp->if_flags & IFF_PROMISC) + rxmode |= AXGE_RX_CTL_PRO; + + if (ifp->if_flags & IFF_BROADCAST) + rxmode |= AXGE_RX_CTL_AB; + + axge_write_cmd_2(sc, AXGE_ACCESS_MAC, 2, AXGE_RX_CTL, rxmode); + + /* Load the multicast filter. */ + axge_setmulti(ue); + + usbd_xfer_set_stall(sc->sc_xfer[AXGE_BULK_DT_WR]); + + ifp->if_drv_flags |= IFF_DRV_RUNNING; + /* Switch to selected media. */ + axge_ifmedia_upd(ifp); +} + +static void +axge_stop(struct usb_ether *ue) +{ + struct axge_softc *sc; + struct ifnet *ifp; + + sc = uether_getsc(ue); + ifp = uether_getifp(ue); + + AXGE_LOCK_ASSERT(sc, MA_OWNED); + + ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); + sc->sc_flags &= ~AXGE_FLAG_LINK; + + /* + * Stop all the transfers, if not already stopped: + */ + usbd_transfer_stop(sc->sc_xfer[AXGE_BULK_DT_WR]); + usbd_transfer_stop(sc->sc_xfer[AXGE_BULK_DT_RD]); +} + +static int +axge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) +{ + struct usb_ether *ue; + struct axge_softc *sc; + struct ifreq *ifr; + int error, mask, reinit; + + ue = ifp->if_softc; + sc = uether_getsc(ue); + ifr = (struct ifreq *)data; + error = 0; + reinit = 0; + if (cmd == SIOCSIFCAP) { + AXGE_LOCK(sc); + mask = ifr->ifr_reqcap ^ ifp->if_capenable; + if ((mask & IFCAP_TXCSUM) != 0 && + (ifp->if_capabilities & IFCAP_TXCSUM) != 0) { + ifp->if_capenable ^= IFCAP_TXCSUM; + if ((ifp->if_capenable & IFCAP_TXCSUM) != 0) + ifp->if_hwassist |= AXGE_CSUM_FEATURES; + else + ifp->if_hwassist &= ~AXGE_CSUM_FEATURES; + reinit++; + } + if ((mask & IFCAP_RXCSUM) != 0 && + (ifp->if_capabilities & IFCAP_RXCSUM) != 0) { + ifp->if_capenable ^= IFCAP_RXCSUM; + reinit++; + } + if (reinit > 0 && ifp->if_drv_flags & IFF_DRV_RUNNING) + ifp->if_drv_flags &= ~IFF_DRV_RUNNING; + else + reinit = 0; + AXGE_UNLOCK(sc); + if (reinit > 0) + uether_init(ue); + } else + error = uether_ioctl(ifp, cmd, data); + + return (error); +} + +static int +axge_rx_frame(struct usb_ether *ue, struct usb_page_cache *pc, int actlen) +{ + struct axge_softc *sc; + struct axge_csum_hdr csum_hdr; + int error, len, pos; + int pkt_cnt; + uint32_t rxhdr; + uint16_t hdr_off; + uint16_t pktlen; + + sc = uether_getsc(ue); + pos = 0; + len = 0; + error = 0; + + usbd_copy_out(pc, actlen - sizeof(rxhdr), &rxhdr, sizeof(rxhdr)); + actlen -= sizeof(rxhdr); + rxhdr = le32toh(rxhdr); + + pkt_cnt = (uint16_t)rxhdr; + hdr_off = (uint16_t)(rxhdr >> 16); + + usbd_copy_out(pc, pos + hdr_off, &csum_hdr, sizeof(csum_hdr)); + csum_hdr.len = le16toh(csum_hdr.len); + csum_hdr.cstatus = le16toh(csum_hdr.cstatus); + + while (pkt_cnt--) { + if (actlen <= sizeof(csum_hdr) + sizeof(struct ether_header)) { + error = EINVAL; + break; + } + pktlen = AXGE_CSUM_RXBYTES(csum_hdr.len); + + if (pkt_cnt == 0) + /* Skip the 2-byte IP alignment header. */ + axge_rxeof(ue, pc, 2, pktlen - 2, &csum_hdr); + } + + if (error != 0) + ue->ue_ifp->if_ierrors++; + return (error); +} + +static int +axge_rxeof(struct usb_ether *ue, struct usb_page_cache *pc, + unsigned int offset, unsigned int len, struct axge_csum_hdr *csum_hdr) +{ + struct ifnet *ifp; + struct mbuf *m; + + ifp = ue->ue_ifp; + if (len < ETHER_HDR_LEN || len > MCLBYTES - ETHER_ALIGN) { + ifp->if_ierrors++; + return (EINVAL); + } + + m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); + if (m == NULL) { + ifp->if_iqdrops++; + return (ENOMEM); + } + m->m_len = m->m_pkthdr.len = MCLBYTES; + m_adj(m, ETHER_ALIGN); + + usbd_copy_out(pc, offset, mtod(m, uint8_t *), len); + + ifp->if_ipackets++; + m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.len = m->m_len = len; + + if (csum_hdr != NULL && + csum_hdr->cstatus & AXGE_CSUM_HDR_L3_TYPE_IPV4) { + if ((csum_hdr->cstatus & (AXGE_CSUM_HDR_L4_CSUM_ERR | + AXGE_RXHDR_L4CSUM_ERR)) == 0) { + m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED | + CSUM_IP_VALID; + if ((csum_hdr->cstatus & AXGE_CSUM_HDR_L4_TYPE_MASK) == + AXGE_CSUM_HDR_L4_TYPE_TCP || + (csum_hdr->cstatus & AXGE_CSUM_HDR_L4_TYPE_MASK) == + AXGE_CSUM_HDR_L4_TYPE_UDP) { + m->m_pkthdr.csum_flags |= + CSUM_DATA_VALID | CSUM_PSEUDO_HDR; + m->m_pkthdr.csum_data = 0xffff; + } + } + } + + _IF_ENQUEUE(&ue->ue_rxq, m); + return (0); +} + +static void +axge_csum_cfg(struct usb_ether *ue) +{ + struct axge_softc *sc; + struct ifnet *ifp; + uint8_t csum; + + sc = uether_getsc(ue); + AXGE_LOCK_ASSERT(sc, MA_OWNED); + ifp = uether_getifp(ue); + + csum = 0; + if ((ifp->if_capenable & IFCAP_TXCSUM) != 0) + csum |= AXGE_TXCOE_IP | AXGE_TXCOE_TCP | AXGE_TXCOE_UDP; + axge_write_cmd_1(sc, AXGE_ACCESS_MAC, 1, AXGE_TXCOE_CTL, csum); + + csum = 0; + if ((ifp->if_capenable & IFCAP_RXCSUM) != 0) + csum |= AXGE_RXCOE_IP | AXGE_RXCOE_TCP | AXGE_RXCOE_UDP | + AXGE_RXCOE_ICMP | AXGE_RXCOE_IGMP; + axge_write_cmd_1(sc, AXGE_ACCESS_MAC, 1, AXGE_RXCOE_CTL, csum); +} diff --git a/sys/dev/usb/net/if_axgereg.h b/sys/dev/usb/net/if_axgereg.h new file mode 100644 index 0000000..6ba9346 --- /dev/null +++ b/sys/dev/usb/net/if_axgereg.h @@ -0,0 +1,212 @@ +/*- + * Copyright (c) 2013 Kevin Lo + * 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 Bill Paul 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 Bill Paul OR THE VOICES IN HIS HEAD + * 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$ + */ + +#define AX88179_PHY_ID 0x03 +#define AXGE_MCAST_FILTER_SIZE 8 +#define AXGE_MAXGE_MCAST 64 +#define AXGE_EEPROM_LEN 0x40 +#define AXGE_RX_CHECKSUM 1 +#define AXGE_TX_CHECKSUM 2 + +#define AXGE_ACCESS_MAC 0x01 +#define AXGE_ACCESS_PHY 0x02 +#define AXGE_ACCESS_WAKEUP 0x03 +#define AXGE_ACCESS_EEPROM 0x04 +#define AXGE_ACCESS_EFUSE 0x05 +#define AXGE_RELOAD_EEPROM_EFUSE 0x06 +#define AXGE_WRITE_EFUSE_EN 0x09 +#define AXGE_WRITE_EFUSE_DIS 0x0A +#define AXGE_ACCESS_MFAB 0x10 + +#define AXGE_LINK_STATUS 0x02 +#define AXGE_LINK_STATUS_USB_FS 0x01 +#define AXGE_LINK_STATUS_USB_HS 0x02 +#define AXGE_LINK_STATUS_USB_SS 0x04 + +#define AXGE_SROM_ADDR 0x07 +#define AXGE_SROM_DATA_LOW 0x08 +#define AXGE_SROM_DATA_HIGH 0x09 +#define AXGE_SROM_CMD 0x0a +#define AXGE_SROM_CMD_RD 0x04 /* EEprom read command */ +#define AXGE_SROM_CMD_WR 0x08 /* EEprom write command */ +#define AXGE_SROM_CMD_BUSY 0x10 /* EEprom access module busy */ + +#define AXGE_RX_CTL 0x0b +#define AXGE_RX_CTL_DROPCRCERR 0x0100 /* Drop CRC error packet */ +#define AXGE_RX_CTL_IPE 0x0200 /* 4-byte IP header alignment */ +#define AXGE_RX_CTL_TXPADCRC 0x0400 /* Csum value in rx header 3 */ +#define AXGE_RX_CTL_START 0x0080 /* Ethernet MAC start */ +#define AXGE_RX_CTL_AP 0x0020 /* Accept physical address from + multicast array */ +#define AXGE_RX_CTL_AM 0x0010 +#define AXGE_RX_CTL_AB 0x0008 +#define AXGE_RX_CTL_HA8B 0x0004 +#define AXGE_RX_CTL_AMALL 0x0002 /* Accept all multicast frames */ +#define AXGE_RX_CTL_PRO 0x0001 /* Promiscuous Mode */ +#define AXGE_RX_CTL_STOP 0x0000 /* Stop MAC */ + +#define AXGE_NODE_ID 0x10 +#define AXGE_MULTI_FILTER_ARRY 0x16 + +#define AXGE_MEDIUM_STATUS_MODE 0x22 +#define AXGE_MEDIUM_GIGAMODE 0x0001 +#define AXGE_MEDIUM_FULL_DUPLEX 0x0002 +#define AXGE_MEDIUM_ALWAYS_ONE 0x0004 +#define AXGE_MEDIUM_EN_125MHZ 0x0008 +#define AXGE_MEDIUM_RXFLOW_CTRLEN 0x0010 +#define AXGE_MEDIUM_TXFLOW_CTRLEN 0x0020 +#define AXGE_MEDIUM_RECEIVE_EN 0x0100 +#define AXGE_MEDIUM_PS 0x0200 +#define AXGE_MEDIUM_JUMBO_EN 0x8040 + +#define AXGE_MONITOR_MODE 0x24 +#define AXGE_MONITOR_MODE_RWLC 0x02 +#define AXGE_MONITOR_MODE_RWMP 0x04 +#define AXGE_MONITOR_MODE_RWWF 0x08 +#define AXGE_MONITOR_MODE_RW_FLAG 0x10 +#define AXGE_MONITOR_MODE_PMEPOL 0x20 +#define AXGE_MONITOR_MODE_PMETYPE 0x40 + +#define AXGE_GPIO_CTRL 0x25 +#define AXGE_GPIO_CTRL_GPIO3EN 0x80 +#define AXGE_GPIO_CTRL_GPIO2EN 0x40 +#define AXGE_GPIO_CTRL_GPIO1EN 0x20 + +#define AXGE_PHYPWR_RSTCTL 0x26 +#define AXGE_PHYPWR_RSTCTL_BZ 0x0010 +#define AXGE_PHYPWR_RSTCTL_IPRL 0x0020 +#define AXGE_PHYPWR_RSTCTL_AUTODETACH 0x1000 + +#define AXGE_RX_BULKIN_QCTRL 0x2e +#define AXGE_RX_BULKIN_QCTRL_TIME 0x01 +#define AXGE_RX_BULKIN_QCTRL_IFG 0x02 +#define AXGE_RX_BULKIN_QCTRL_SIZE 0x04 + +#define AXGE_RX_BULKIN_QTIMR_LOW 0x2f +#define AXGE_RX_BULKIN_QTIMR_HIGH 0x30 +#define AXGE_RX_BULKIN_QSIZE 0x31 +#define AXGE_RX_BULKIN_QIFG 0x32 + +#define AXGE_CLK_SELECT 0x33 +#define AXGE_CLK_SELECT_BCS 0x01 +#define AXGE_CLK_SELECT_ACS 0x02 +#define AXGE_CLK_SELECT_ACSREQ 0x10 +#define AXGE_CLK_SELECT_ULR 0x08 + +#define AXGE_RXCOE_CTL 0x34 +#define AXGE_RXCOE_IP 0x01 +#define AXGE_RXCOE_TCP 0x02 +#define AXGE_RXCOE_UDP 0x04 +#define AXGE_RXCOE_ICMP 0x08 +#define AXGE_RXCOE_IGMP 0x10 +#define AXGE_RXCOE_TCPV6 0x20 +#define AXGE_RXCOE_UDPV6 0x40 +#define AXGE_RXCOE_ICMV6 0x80 + +#define AXGE_TXCOE_CTL 0x35 +#define AXGE_TXCOE_IP 0x01 +#define AXGE_TXCOE_TCP 0x02 +#define AXGE_TXCOE_UDP 0x04 +#define AXGE_TXCOE_ICMP 0x08 +#define AXGE_TXCOE_IGMP 0x10 +#define AXGE_TXCOE_TCPV6 0x20 +#define AXGE_TXCOE_UDPV6 0x40 +#define AXGE_TXCOE_ICMV6 0x80 + +#define AXGE_PAUSE_WATERLVL_HIGH 0x54 +#define AXGE_PAUSE_WATERLVL_LOW 0x55 + +#define AXGE_EEP_EFUSE_CORRECT 0x00 +#define AX88179_EEPROM_MAGIC 0x17900b95 + +#define AXGE_CONFIG_IDX 0 /* config number 1 */ +#define AXGE_IFACE_IDX 0 + +#define AXGE_RXHDR_CRC_ERR 0x80000000 +#define AXGE_RXHDR_L4_ERR (1 << 8) +#define AXGE_RXHDR_L3_ERR (1 << 9) + +#define AXGE_RXHDR_L4_TYPE_ICMP 2 +#define AXGE_RXHDR_L4_TYPE_IGMP 3 +#define AXGE_RXHDR_L4_TYPE_TCMPV6 5 + +#define AXGE_RXHDR_L3_TYPE_IP 1 +#define AXGE_RXHDR_L3_TYPE_IPV6 2 + +#define AXGE_RXHDR_L4_TYPE_MASK 0x1c +#define AXGE_RXHDR_L4_TYPE_UDP 4 +#define AXGE_RXHDR_L4_TYPE_TCP 16 +#define AXGE_RXHDR_L3CSUM_ERR 2 +#define AXGE_RXHDR_L4CSUM_ERR 1 +#define AXGE_RXHDR_CRC_ERR 0x80000000 +#define AXGE_RXHDR_DROP_ERR 0x40000000 + +struct axge_csum_hdr { + uint16_t cstatus; +#define AXGE_CSUM_HDR_L4_CSUM_ERR 0x0001 +#define AXGE_CSUM_HDR_L3_CSUM_ERR 0x0002 +#define AXGE_CSUM_HDR_L4_TYPE_UDP 0x0004 +#define AXGE_CSUM_HDR_L4_TYPE_ICMP 0x0008 +#define AXGE_CSUM_HDR_L4_TYPE_IGMP 0x000C +#define AXGE_CSUM_HDR_L4_TYPE_TCP 0x0010 +#define AXGE_CSUM_HDR_L4_TYPE_TCPV6 0x0014 +#define AXGE_CSUM_HDR_L4_TYPE_MASK 0x001C +#define AXGE_CSUM_HDR_L3_TYPE_IPV4 0x0020 +#define AXGE_CSUM_HDR_L3_TYPE_IPV6 0x0040 +#define AXGE_CSUM_HDR_VLAN_MASK 0x0700 + uint16_t len; +#define AXGE_CSUM_HDR_LEN_MASK 0x1FFF +#define AXGE_CSUM_HDR_CRC_ERR 0x2000 +#define AXGE_CSUM_HDR_MII_ERR 0x4000 +#define AXGE_CSUM_HDR_DROP 0x8000 +} __packed; + +#define AXGE_CSUM_RXBYTES(x) ((x) & AXGE_CSUM_HDR_LEN_MASK) + +#define GET_MII(sc) uether_getmii(&(sc)->sc_ue) + +/* The interrupt endpoint is currently unused by the ASIX part. */ +enum { + AXGE_BULK_DT_WR, + AXGE_BULK_DT_RD, + AXGE_N_TRANSFER, +}; + +struct axge_softc { + struct usb_ether sc_ue; + struct mtx sc_mtx; + struct usb_xfer *sc_xfer[AXGE_N_TRANSFER]; + int sc_phyno; + + int sc_flags; +#define AXGE_FLAG_LINK 0x0001 /* got a link */ +}; + +#define AXGE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) +#define AXGE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) +#define AXGE_LOCK_ASSERT(_sc, t) mtx_assert(&(_sc)->sc_mtx, t) diff --git a/sys/modules/usb/Makefile b/sys/modules/usb/Makefile index 325b00d..caf4ebb 100644 --- a/sys/modules/usb/Makefile +++ b/sys/modules/usb/Makefile @@ -38,7 +38,7 @@ SUBDIR += ${_urtwn} ${_urtwnfw} SUBDIR += atp uhid ukbd ums udbp ufm uep SUBDIR += ucom u3g uark ubsa ubser uchcom ucycom ufoma uftdi ugensa uipaq ulpt \ umct umcs umodem umoscom uplcom uslcom uvisor uvscom -SUBDIR += uether aue axe cdce cue ${_kue} mos rue smsc udav uhso ipheth +SUBDIR += uether aue axe axge cdce cue ${_kue} mos rue smsc udav uhso ipheth SUBDIR += usfs umass urio SUBDIR += quirk template SUBDIR += ${_g_audio} ${_g_keyboard} ${_g_modem} ${_g_mouse} diff --git a/sys/modules/usb/axge/Makefile b/sys/modules/usb/axge/Makefile new file mode 100644 index 0000000..bad4b94 --- /dev/null +++ b/sys/modules/usb/axge/Makefile @@ -0,0 +1,10 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../../dev/usb/net + +KMOD= if_axge +SRCS+= if_axge.c usbdevs.h +SRCS+= bus_if.h device_if.h miibus_if.h usb_if.h \ + opt_bus.h opt_inet.h opt_usb.h + +.include