73#include <sys/stdint.h>
74#include <sys/stddef.h>
79#include <sys/socket.h>
80#include <sys/kernel.h>
82#include <sys/module.h>
85#include <sys/condvar.h>
86#include <sys/sysctl.h>
88#include <sys/unistd.h>
89#include <sys/callout.h>
90#include <sys/malloc.h>
94#include <net/if_var.h>
95#include <net/if_media.h>
97#include <dev/mii/mii.h>
98#include <dev/mii/miivar.h>
105#define USB_DEBUG_VAR aue_debug
112#include "miibus_if.h"
115static int aue_debug = 0;
117static SYSCTL_NODE(_hw_usb, OID_AUTO, aue, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
127#define AUE_DEV(v,p,i) { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) }
129 AUE_DEV(ABOCOM, DSB650TX_PNA, 0),
151 AUE_DEV(BILLIONTON, USB100, 0),
153 AUE_DEV(BILLIONTON, USBEL100, 0),
156 AUE_DEV(COREGA, FETHER_USB_TX, 0),
171 AUE_DEV(ELSA, USB2ETHERNET, 0),
172 AUE_DEV(GIGABYTE, GNBR402W, 0),
177 AUE_DEV(KINGSTON, KNU101TX, 0),
236 .bufsize = (MCLBYTES + 2),
246 .bufsize = (MCLBYTES + 4 + ETHER_CRC_LEN),
255 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
304#define AUE_SETBIT(sc, reg, x) \
305 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x))
307#define AUE_CLRBIT(sc, reg, x) \
308 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x))
345 return (le16toh(
val));
402 device_printf(sc->
sc_ue.
ue_dev,
"EEPROM read timed out\n");
416 for (i = 0,
offset = 0; i < ETHER_ADDR_LEN / 2; i++) {
418 eaddr[i * 2] = (uint8_t)word;
419 eaddr[i * 2 + 1] = (uint8_t)(word >> 8);
430 locked = mtx_owned(&sc->
sc_mtx);
460 device_printf(sc->
sc_ue.
ue_dev,
"MII read timed out\n");
480 locked = mtx_owned(&sc->
sc_mtx);
496 device_printf(sc->
sc_ue.
ue_dev,
"MII write timed out\n");
507 struct mii_data *mii =
GET_MII(sc);
510 locked = mtx_owned(&sc->
sc_mtx);
515 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX)
520 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
546 uint8_t *hashtbl = arg;
549 h = ether_crc32_le(LLADDR(sdl), ETHER_ADDR_LEN) & ((1 <<
AUE_BITS) - 1);
550 hashtbl[(h >> 3)] |= 1 << (h & 0x7);
561 uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
565 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
576 for (i = 0; i != 8; i++)
587 if ((sc->
sc_flags & HAS_HOME_PNA) && mii_mode)
699 mtx_init(&sc->
sc_mtx, device_get_nameunit(
dev), NULL, MTX_DEF);
706 device_printf(
dev,
"allocating USB transfers failed\n");
718 device_printf(
dev,
"could not attach interface\n");
755 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) &&
756 actlen >= (
int)
sizeof(pkt)) {
761 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
764 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1);
798 DPRINTFN(11,
"received %d bytes\n", actlen);
802 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
806 if (actlen <= (
int)(
sizeof(stat) + ETHER_CRC_LEN)) {
807 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
819 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
823 actlen -= (
sizeof(stat) + ETHER_CRC_LEN);
836 DPRINTF(
"bulk read error, %s\n",
863 DPRINTFN(11,
"transfer of %d bytes complete\n", actlen);
864 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
875 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
879 if (m->m_pkthdr.len > MCLBYTES)
880 m->m_pkthdr.len = MCLBYTES;
897 buf[0] = (uint8_t)(m->m_pkthdr.len);
898 buf[1] = (uint8_t)(m->m_pkthdr.len >> 8);
916 DPRINTFN(11,
"transfer error, %s\n",
919 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
934 struct mii_data *mii =
GET_MII(sc);
940 && mii->mii_media_status & IFM_ACTIVE &&
941 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
975 for (i = 0; i != ETHER_ADDR_LEN; i++)
991 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1004 if (ifp->if_flags & IFF_PROMISC)
1017 struct mii_data *mii =
GET_MII(sc);
1018 struct mii_softc *miisc;
1024 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
1026 error = mii_mediachg(mii);
1037 struct mii_data *mii =
GET_MII(sc);
1041 ifmr->ifm_active = mii->mii_media_active;
1042 ifmr->ifm_status = mii->mii_media_status;
1058 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
static SYSCTL_NODE(_hw_usb, OID_AUTO, dwc_otg, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "USB DWC OTG")
SYSCTL_INT(_hw_usb_dwc_otg, OID_AUTO, phy_type, CTLFLAG_RDTUN, &dwc_otg_phy_type, 0, "DWC OTG PHY TYPE - 0/1/2/3 - ULPI/HSIC/INTERNAL/UTMI+")
static uint16_t aue_eeprom_getword(struct aue_softc *, int)
#define AUE_CLRBIT(sc, reg, x)
static uether_fn_t aue_setpromisc
MODULE_DEPEND(aue, uether, 1, 1, 1)
static driver_t aue_driver
static void aue_reset(struct aue_softc *)
static usb_callback_t aue_bulk_write_callback
static void aue_read_mac(struct aue_softc *sc, uint8_t *eaddr)
static uether_fn_t aue_tick
static const struct usb_ether_methods aue_ue_methods
static uether_fn_t aue_attach_post
static uether_fn_t aue_start
static device_method_t aue_methods[]
static void aue_csr_write_2(struct aue_softc *, uint16_t, uint16_t)
static devclass_t aue_devclass
static const STRUCT_USB_HOST_ID aue_devs[]
#define AUE_SETBIT(sc, reg, x)
static const struct usb_config aue_config[AUE_N_TRANSFER]
static void aue_ifmedia_sts(struct ifnet *, struct ifmediareq *)
DRIVER_MODULE(aue, uhub, aue_driver, aue_devclass, NULL, 0)
static miibus_readreg_t aue_miibus_readreg
static uether_fn_t aue_init
static usb_callback_t aue_bulk_read_callback
static usb_callback_t aue_intr_callback
static void aue_reset_pegasus_II(struct aue_softc *)
static device_attach_t aue_attach
static void aue_csr_write_1(struct aue_softc *, uint16_t, uint8_t)
static device_detach_t aue_detach
static int aue_ifmedia_upd(struct ifnet *)
static uether_fn_t aue_stop
static miibus_statchg_t aue_miibus_statchg
static uint16_t aue_csr_read_2(struct aue_softc *, uint16_t)
USB_PNP_HOST_INFO(aue_devs)
static uether_fn_t aue_setmulti
static u_int aue_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt)
static miibus_writereg_t aue_miibus_writereg
static device_probe_t aue_probe
static uint8_t aue_csr_read_1(struct aue_softc *, uint16_t)
#define AUE_CTL0_ALLMULTI
#define AUE_CTL1_SPEEDSEL
#define AUE_TXSTAT0_EXCESSCOLL
#define AUE_LOCK_ASSERT(_sc, t)
#define AUE_TXSTAT0_LATECOLL
#define AUE_CTL1_RESETMAC
#define AUE_CTL2_RX_PROMISC
#define AUE_FLAG_DUAL_PHY
#define AUE_CTL0_RXSTAT_APPEND
struct usb_xfer * sc_xfer[AUE_N_TRANSFER]
enum usb_hc_mode usb_mode
struct usbd_lookup_info info
struct usb_device * device
struct usb_xfer_flags flags
uether_fn_t * ue_attach_post
const struct usb_ether_methods * ue_methods
struct usb_device * ue_udev
uint8_t ue_eaddr[ETHER_ADDR_LEN]
#define UT_WRITE_VENDOR_DEVICE
#define UT_READ_VENDOR_DEVICE
void usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset, const void *ptr, usb_frlength_t len)
void usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset, void *ptr, usb_frlength_t len)
const char * usbd_errstr(usb_error_t err)
void uether_rxflush(struct usb_ether *ue)
void uether_ifdetach(struct usb_ether *ue)
void * uether_getsc(struct usb_ether *ue)
int uether_rxbuf(struct usb_ether *ue, struct usb_page_cache *pc, unsigned int offset, unsigned int len)
struct ifnet * uether_getifp(struct usb_ether *ue)
uint8_t uether_pause(struct usb_ether *ue, unsigned int _ticks)
int uether_ifattach(struct usb_ether *ue)
#define uether_do_request(ue, req, data, timo)
void() uether_fn_t(struct usb_ether *)
int usbd_lookup_id_by_uaa(const struct usb_device_id *id, usb_size_t sizeof_id, struct usb_attach_arg *uaa)
void usbd_transfer_submit(struct usb_xfer *xfer)
void usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup)
void usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex, usb_frlength_t len)
struct usb_page_cache * usbd_xfer_get_frame(struct usb_xfer *xfer, usb_frcount_t frindex)
usb_error_t usbd_transfer_setup(struct usb_device *udev, const uint8_t *ifaces, struct usb_xfer **ppxfer, const struct usb_config *setup_start, uint16_t n_setup, void *priv_sc, struct mtx *xfer_mtx)
void usbd_transfer_start(struct usb_xfer *xfer)
void * usbd_xfer_softc(struct usb_xfer *xfer)
void usbd_xfer_set_stall(struct usb_xfer *xfer)
void usbd_transfer_stop(struct usb_xfer *xfer)
void usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen, int *aframes, int *nframes)
usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer)
void device_set_usb_desc(device_t dev)
#define USB_ST_TRANSFERRED
void usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset, struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len)
void() usb_callback_t(struct usb_xfer *, usb_error_t)
#define STRUCT_USB_HOST_ID
#define USB_GET_DRIVER_INFO(did)
#define USB_GET_STATE(xfer)