101#include <sys/stdint.h>
102#include <sys/stddef.h>
103#include <sys/param.h>
104#include <sys/queue.h>
105#include <sys/types.h>
106#include <sys/systm.h>
107#include <sys/socket.h>
108#include <sys/kernel.h>
110#include <sys/module.h>
112#include <sys/mutex.h>
113#include <sys/condvar.h>
114#include <sys/sysctl.h>
116#include <sys/unistd.h>
117#include <sys/callout.h>
118#include <sys/malloc.h>
122#include <net/if_var.h>
123#include <net/if_media.h>
125#include <dev/mii/mii.h>
126#include <dev/mii/miivar.h>
133#define USB_DEBUG_VAR mos_debug
139#include "miibus_if.h"
145static int mos_debug = 0;
147static SYSCTL_NODE(_hw_usb, OID_AUTO, mos, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
153#define MOS_DPRINTFN(fmt,...) \
154 DPRINTF("mos: %s: " fmt "\n",__FUNCTION__,## __VA_ARGS__)
156#define USB_PRODUCT_MOSCHIP_MCS7730 0x7730
157#define USB_PRODUCT_SITECOMEU_LN030 0x0021
162 {
USB_VPI(USB_VENDOR_MOSCHIP, USB_PRODUCT_MOSCHIP_MCS7830,
MCS7830)},
163 {
USB_VPI(USB_VENDOR_MOSCHIP, USB_PRODUCT_MOSCHIP_MCS7832,
MCS7832)},
203 .bufsize = (MCLBYTES + 2),
213 .bufsize = (MCLBYTES + 4 + ETHER_CRC_LEN),
222 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
434 locked = mtx_owned(&sc->
sc_mtx);
464 locked = mtx_owned(&sc->
sc_mtx);
490 struct mii_data *mii =
GET_MII(sc);
491 int val, err, locked;
493 locked = mtx_owned(&sc->
sc_mtx);
505 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
510 switch (IFM_SUBTYPE(mii->mii_media_active)) {
537 struct mii_data *mii =
GET_MII(sc);
538 struct mii_softc *miisc;
544 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
546 error = mii_mediachg(mii);
557 struct mii_data *mii =
GET_MII(sc);
562 ifmr->ifm_active = mii->mii_media_active;
563 ifmr->ifm_status = mii->mii_media_status;
580 if (ifp->if_flags & IFF_PROMISC) {
583 rxmode &= ~MOS_CTL_RX_PROMISC;
592 uint8_t *hashtbl = arg;
595 h = ether_crc32_be(LLADDR(sdl), ETHER_ADDR_LEN) >> 26;
596 hashtbl[h / 8] |= 1 << (h % 8);
607 uint8_t hashtbl[8] = {0, 0, 0, 0, 0, 0, 0, 0};
614 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC)
625 rxmode &= ~MOS_CTL_ALLMULTI;
703 mtx_init(&sc->
sc_mtx, device_get_nameunit(
dev), NULL, MTX_DEF);
711 device_printf(
dev,
"allocating USB transfers failed\n");
729 device_printf(
dev,
"could not attach interface\n");
792 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
811 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
816 if (pktlen <
sizeof(
struct ether_header)) {
818 "than ether_header %zd", pktlen,
819 sizeof(
struct ether_header));
820 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
857 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
864 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
883 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
887 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
900 struct mii_data *mii =
GET_MII(sc);
905 if (!sc->
mos_link && mii->mii_media_status & IFM_ACTIVE &&
906 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
963 ifp->if_drv_flags |= IFF_DRV_RUNNING;
976 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1012 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+")
#define USB_PRODUCT_MOSCHIP_MCS7730
static void mos_reset(struct mos_softc *sc)
static int mos_reg_read_2(struct mos_softc *, int)
static int mos_probe(device_t dev)
static int mos_miibus_writereg(device_t, int, int, int)
static void mos_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
static void mos_attach_post(struct usb_ether *ue)
USB_PNP_HOST_INFO(mos_devs)
static int mos_readmac(struct mos_softc *, uint8_t *)
static int mos_detach(device_t dev)
static int mos_reg_write_2(struct mos_softc *, int, int)
DRIVER_MODULE(mos, uhub, mos_driver, mos_devclass, NULL, 0)
static void mos_ifmedia_sts(struct ifnet *, struct ifmediareq *)
static void mos_tick(struct usb_ether *)
MODULE_DEPEND(mos, uether, 1, 1, 1)
static void mos_setmulti(struct usb_ether *)
static int mos_miibus_readreg(device_t, int, int)
static driver_t mos_driver
static void mos_setpromisc(struct usb_ether *)
static devclass_t mos_devclass
static const STRUCT_USB_HOST_ID mos_devs[]
static int mos_attach(device_t dev)
static void mos_start(struct usb_ether *)
static int mos_ifmedia_upd(struct ifnet *)
static int mos_reg_read_1(struct mos_softc *, int)
#define MOS_DPRINTFN(fmt,...)
static void mos_init(struct usb_ether *)
static u_int mos_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt)
static void mos_chip_init(struct mos_softc *)
static int mos_reg_write_1(struct mos_softc *, int, int)
static int mos_writemac(struct mos_softc *, uint8_t *)
static int mos_write_mcast(struct mos_softc *, u_char *)
static const struct usb_config mos_config[MOS_ENDPT_MAX]
static void mos_stop(struct usb_ether *)
static void mos_miibus_statchg(device_t)
static device_method_t mos_methods[]
static void mos_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
#define USB_PRODUCT_SITECOMEU_LN030
static const struct usb_ether_methods mos_ue_methods
static void mos_intr_callback(struct usb_xfer *xfer, usb_error_t error)
#define MOS_PHYSTS_PHYREG
#define MOS_FRAME_DROP_CNT
#define MOS_LOCK_ASSERT(_sc, t)
#define MOS_PAUSE_REWRITES
#define MOS_RXSTS_SHORT_FRAME
#define MOS_RXSTS_ALIGN_ERROR
#define MOS_RXSTS_CRC_ERROR
#define MOS_RXSTS_LARGE_FRAME
#define MOS_PHYCTL_PHYADDR
#define MOS_PHYSTS_PENDING
#define MOS_CTL_RX_PROMISC
struct usb_xfer * sc_xfer[MOS_ENDPT_MAX]
unsigned char mos_phyaddrs[2]
unsigned char mos_ipgs[2]
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_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)
int uether_ifattach(struct usb_ether *ue)
#define uether_do_request(ue, req, data, timo)
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)
void usb_pause_mtx(struct mtx *mtx, int timo)
#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)
#define USB_VPI(vend, prod, info)
#define STRUCT_USB_HOST_ID
#define USB_GET_DRIVER_INFO(did)
#define USB_GET_STATE(xfer)