2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (C) 2012 Ben Gray <bgray@freebsd.org>.
5 * Copyright (C) 2018 The FreeBSD Foundation.
7 * This software was developed by Arshan Khanifar <arshankhanifar@gmail.com>
8 * under sponsorship from the FreeBSD Foundation.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
38 * USB-To-Ethernet adapter driver for Microchip's LAN78XX and related families.
40 * USB 3.1 to 10/100/1000 Mbps Ethernet
41 * LAN7800 http://www.microchip.com/wwwproducts/en/LAN7800
43 * USB 2.0 to 10/100/1000 Mbps Ethernet
44 * LAN7850 http://www.microchip.com/wwwproducts/en/LAN7850
46 * USB 2 to 10/100/1000 Mbps Ethernet with built-in USB hub
47 * LAN7515 (no datasheet available, but probes and functions as LAN7800)
49 * This driver is based on the if_smsc driver, with lan78xx-specific
50 * functionality modelled on Microchip's Linux lan78xx driver.
52 * UNIMPLEMENTED FEATURES
54 * A number of features supported by the lan78xx are not yet implemented in
57 * - RX/TX checksum offloading: Nothing has been implemented yet for
58 * TX checksumming. RX checksumming works with ICMP messages, but is broken
59 * for TCP/UDP packets.
60 * - Direct address translation filtering: Implemented but untested.
62 * - Support for USB interrupt endpoints.
63 * - Latency Tolerance Messaging (LTM) support.
68 #include <sys/param.h>
70 #include <sys/callout.h>
71 #include <sys/condvar.h>
72 #include <sys/kernel.h>
74 #include <sys/malloc.h>
75 #include <sys/module.h>
76 #include <sys/mutex.h>
78 #include <sys/queue.h>
79 #include <sys/random.h>
80 #include <sys/socket.h>
81 #include <sys/stddef.h>
82 #include <sys/stdint.h>
84 #include <sys/sysctl.h>
85 #include <sys/systm.h>
86 #include <sys/unistd.h>
89 #include <net/if_var.h>
91 #include <netinet/in.h>
92 #include <netinet/ip.h>
94 #include "opt_platform.h"
97 #include <dev/fdt/fdt_common.h>
98 #include <dev/ofw/ofw_bus.h>
99 #include <dev/ofw/ofw_bus_subr.h>
102 #include <dev/usb/usb.h>
103 #include <dev/usb/usbdi.h>
104 #include <dev/usb/usbdi_util.h>
107 #define USB_DEBUG_VAR lan78xx_debug
108 #include <dev/usb/usb_debug.h>
109 #include <dev/usb/usb_process.h>
111 #include <dev/usb/net/usb_ethernet.h>
113 #include <dev/usb/net/if_mugereg.h>
116 static int muge_debug = 0;
118 SYSCTL_NODE(_hw_usb, OID_AUTO, muge, CTLFLAG_RW, 0,
119 "Microchip LAN78xx USB-GigE");
120 SYSCTL_INT(_hw_usb_muge, OID_AUTO, debug, CTLFLAG_RWTUN, &muge_debug, 0,
124 #define MUGE_DEFAULT_RX_CSUM_ENABLE (false)
125 #define MUGE_DEFAULT_TX_CSUM_ENABLE (false)
126 #define MUGE_DEFAULT_TSO_CSUM_ENABLE (false)
128 /* Supported Vendor and Product IDs. */
129 static const struct usb_device_id lan78xx_devs[] = {
130 #define MUGE_DEV(p,i) { USB_VPI(USB_VENDOR_SMC2, USB_PRODUCT_SMC2_##p, i) }
131 MUGE_DEV(LAN7800_ETH, 0),
132 MUGE_DEV(LAN7801_ETH, 0),
133 MUGE_DEV(LAN7850_ETH, 0),
138 #define muge_dbg_printf(sc, fmt, args...) \
140 if (muge_debug > 0) \
141 device_printf((sc)->sc_ue.ue_dev, "debug: " fmt, ##args); \
144 #define muge_dbg_printf(sc, fmt, args...) do { } while (0)
147 #define muge_warn_printf(sc, fmt, args...) \
148 device_printf((sc)->sc_ue.ue_dev, "warning: " fmt, ##args)
150 #define muge_err_printf(sc, fmt, args...) \
151 device_printf((sc)->sc_ue.ue_dev, "error: " fmt, ##args)
153 #define ETHER_IS_ZERO(addr) \
154 (!(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]))
156 #define ETHER_IS_VALID(addr) \
157 (!ETHER_IS_MULTICAST(addr) && !ETHER_IS_ZERO(addr))
164 #if 0 /* Ignore interrupt endpoints for now as we poll on MII status. */
172 struct usb_ether sc_ue;
174 struct usb_xfer *sc_xfer[MUGE_N_TRANSFER];
177 /* Settings for the mac control (MAC_CSR) register. */
179 uint32_t sc_mdix_ctl;
182 uint32_t sc_mchash_table[ETH_DP_SEL_VHF_HASH_LEN];
183 uint32_t sc_pfilter_table[MUGE_NUM_PFILTER_ADDRS_][2];
186 #define MUGE_FLAG_LINK 0x0001
187 #define MUGE_FLAG_INIT_DONE 0x0002
190 #define MUGE_IFACE_IDX 0
192 #define MUGE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
193 #define MUGE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
194 #define MUGE_LOCK_ASSERT(_sc, t) mtx_assert(&(_sc)->sc_mtx, t)
196 static device_probe_t muge_probe;
197 static device_attach_t muge_attach;
198 static device_detach_t muge_detach;
200 static usb_callback_t muge_bulk_read_callback;
201 static usb_callback_t muge_bulk_write_callback;
203 static miibus_readreg_t lan78xx_miibus_readreg;
204 static miibus_writereg_t lan78xx_miibus_writereg;
205 static miibus_statchg_t lan78xx_miibus_statchg;
207 static int muge_attach_post_sub(struct usb_ether *ue);
208 static uether_fn_t muge_attach_post;
209 static uether_fn_t muge_init;
210 static uether_fn_t muge_stop;
211 static uether_fn_t muge_start;
212 static uether_fn_t muge_tick;
213 static uether_fn_t muge_setmulti;
214 static uether_fn_t muge_setpromisc;
216 static int muge_ifmedia_upd(struct ifnet *);
217 static void muge_ifmedia_sts(struct ifnet *, struct ifmediareq *);
219 static int lan78xx_chip_init(struct muge_softc *sc);
220 static int muge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
222 static const struct usb_config muge_config[MUGE_N_TRANSFER] = {
224 [MUGE_BULK_DT_WR] = {
226 .endpoint = UE_ADDR_ANY,
227 .direction = UE_DIR_OUT,
229 .bufsize = 16 * (MCLBYTES + 16),
230 .flags = {.pipe_bof = 1,.force_short_xfer = 1,},
231 .callback = muge_bulk_write_callback,
232 .timeout = 10000, /* 10 seconds */
235 [MUGE_BULK_DT_RD] = {
237 .endpoint = UE_ADDR_ANY,
238 .direction = UE_DIR_IN,
239 .bufsize = 20480, /* bytes */
240 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
241 .callback = muge_bulk_read_callback,
242 .timeout = 0, /* no timeout */
245 * The chip supports interrupt endpoints, however they aren't
246 * needed as we poll on the MII status.
250 static const struct usb_ether_methods muge_ue_methods = {
251 .ue_attach_post = muge_attach_post,
252 .ue_attach_post_sub = muge_attach_post_sub,
253 .ue_start = muge_start,
254 .ue_ioctl = muge_ioctl,
255 .ue_init = muge_init,
256 .ue_stop = muge_stop,
257 .ue_tick = muge_tick,
258 .ue_setmulti = muge_setmulti,
259 .ue_setpromisc = muge_setpromisc,
260 .ue_mii_upd = muge_ifmedia_upd,
261 .ue_mii_sts = muge_ifmedia_sts,
265 * lan78xx_read_reg - Read a 32-bit register on the device
266 * @sc: driver soft context
267 * @off: offset of the register
268 * @data: pointer a value that will be populated with the register value
271 * The device lock must be held before calling this function.
274 * 0 on success, a USB_ERR_?? error code on failure.
277 lan78xx_read_reg(struct muge_softc *sc, uint32_t off, uint32_t *data)
279 struct usb_device_request req;
283 MUGE_LOCK_ASSERT(sc, MA_OWNED);
285 req.bmRequestType = UT_READ_VENDOR_DEVICE;
286 req.bRequest = UVR_READ_REG;
287 USETW(req.wValue, 0);
288 USETW(req.wIndex, off);
289 USETW(req.wLength, 4);
291 err = uether_do_request(&sc->sc_ue, &req, &buf, 1000);
293 muge_warn_printf(sc, "Failed to read register 0x%0x\n", off);
294 *data = le32toh(buf);
299 * lan78xx_write_reg - Write a 32-bit register on the device
300 * @sc: driver soft context
301 * @off: offset of the register
302 * @data: the 32-bit value to write into the register
305 * The device lock must be held before calling this function.
308 * 0 on success, a USB_ERR_?? error code on failure.
311 lan78xx_write_reg(struct muge_softc *sc, uint32_t off, uint32_t data)
313 struct usb_device_request req;
317 MUGE_LOCK_ASSERT(sc, MA_OWNED);
321 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
322 req.bRequest = UVR_WRITE_REG;
323 USETW(req.wValue, 0);
324 USETW(req.wIndex, off);
325 USETW(req.wLength, 4);
327 err = uether_do_request(&sc->sc_ue, &req, &buf, 1000);
329 muge_warn_printf(sc, "Failed to write register 0x%0x\n", off);
334 * lan78xx_wait_for_bits - Poll on a register value until bits are cleared
336 * @reg: offset of the register
337 * @bits: if the bits are clear the function returns
340 * The device lock must be held before calling this function.
343 * 0 on success, or a USB_ERR_?? error code on failure.
346 lan78xx_wait_for_bits(struct muge_softc *sc, uint32_t reg, uint32_t bits)
348 usb_ticks_t start_ticks;
349 const usb_ticks_t max_ticks = USB_MS_TO_TICKS(1000);
353 MUGE_LOCK_ASSERT(sc, MA_OWNED);
355 start_ticks = (usb_ticks_t)ticks;
357 if ((err = lan78xx_read_reg(sc, reg, &val)) != 0)
361 uether_pause(&sc->sc_ue, hz / 100);
362 } while (((usb_ticks_t)(ticks - start_ticks)) < max_ticks);
364 return (USB_ERR_TIMEOUT);
368 * lan78xx_eeprom_read_raw - Read the attached EEPROM
370 * @off: the eeprom address offset
371 * @buf: stores the bytes
372 * @buflen: the number of bytes to read
374 * Simply reads bytes from an attached eeprom.
377 * The function takes and releases the device lock if not already held.
380 * 0 on success, or a USB_ERR_?? error code on failure.
383 lan78xx_eeprom_read_raw(struct muge_softc *sc, uint16_t off, uint8_t *buf,
386 usb_ticks_t start_ticks;
387 const usb_ticks_t max_ticks = USB_MS_TO_TICKS(1000);
392 locked = mtx_owned(&sc->sc_mtx); /* XXX */
396 if (sc->chipid == ETH_ID_REV_CHIP_ID_7800_) {
397 /* EEDO/EECLK muxed with LED0/LED1 on LAN7800. */
398 err = lan78xx_read_reg(sc, ETH_HW_CFG, &val);
401 val &= ~(ETH_HW_CFG_LEDO_EN_ | ETH_HW_CFG_LED1_EN_);
402 err = lan78xx_write_reg(sc, ETH_HW_CFG, val);
405 err = lan78xx_wait_for_bits(sc, ETH_E2P_CMD, ETH_E2P_CMD_BUSY_);
407 muge_warn_printf(sc, "eeprom busy, failed to read data\n");
411 /* Start reading the bytes, one at a time. */
412 for (i = 0; i < buflen; i++) {
413 val = ETH_E2P_CMD_BUSY_ | ETH_E2P_CMD_READ_;
414 val |= (ETH_E2P_CMD_ADDR_MASK_ & (off + i));
415 if ((err = lan78xx_write_reg(sc, ETH_E2P_CMD, val)) != 0)
418 start_ticks = (usb_ticks_t)ticks;
420 if ((err = lan78xx_read_reg(sc, ETH_E2P_CMD, &val)) !=
423 if (!(val & ETH_E2P_CMD_BUSY_) ||
424 (val & ETH_E2P_CMD_TIMEOUT_))
427 uether_pause(&sc->sc_ue, hz / 100);
428 } while (((usb_ticks_t)(ticks - start_ticks)) < max_ticks);
430 if (val & (ETH_E2P_CMD_BUSY_ | ETH_E2P_CMD_TIMEOUT_)) {
431 muge_warn_printf(sc, "eeprom command failed\n");
432 err = USB_ERR_IOERROR;
436 if ((err = lan78xx_read_reg(sc, ETH_E2P_DATA, &val)) != 0)
439 buf[i] = (val & 0xff);
445 if (sc->chipid == ETH_ID_REV_CHIP_ID_7800_) {
446 /* Restore saved LED configuration. */
447 lan78xx_write_reg(sc, ETH_HW_CFG, saved);
453 lan78xx_eeprom_present(struct muge_softc *sc)
458 ret = lan78xx_eeprom_read_raw(sc, ETH_E2P_INDICATOR_OFFSET, &sig, 1);
459 return (ret == 0 && sig == ETH_E2P_INDICATOR);
463 * lan78xx_otp_read_raw
465 * @off: the otp address offset
466 * @buf: stores the bytes
467 * @buflen: the number of bytes to read
469 * Simply reads bytes from the OTP.
472 * The function takes and releases the device lock if not already held.
475 * 0 on success, or a USB_ERR_?? error code on failure.
479 lan78xx_otp_read_raw(struct muge_softc *sc, uint16_t off, uint8_t *buf,
485 locked = mtx_owned(&sc->sc_mtx);
489 err = lan78xx_read_reg(sc, OTP_PWR_DN, &val);
491 /* Checking if bit is set. */
492 if (val & OTP_PWR_DN_PWRDN_N) {
493 /* Clear it, then wait for it to be cleared. */
494 lan78xx_write_reg(sc, OTP_PWR_DN, 0);
495 err = lan78xx_wait_for_bits(sc, OTP_PWR_DN, OTP_PWR_DN_PWRDN_N);
497 muge_warn_printf(sc, "OTP off? failed to read data\n");
501 /* Start reading the bytes, one at a time. */
502 for (i = 0; i < buflen; i++) {
503 err = lan78xx_write_reg(sc, OTP_ADDR1,
504 ((off + i) >> 8) & OTP_ADDR1_15_11);
505 err = lan78xx_write_reg(sc, OTP_ADDR2,
506 ((off + i) & OTP_ADDR2_10_3));
507 err = lan78xx_write_reg(sc, OTP_FUNC_CMD, OTP_FUNC_CMD_READ_);
508 err = lan78xx_write_reg(sc, OTP_CMD_GO, OTP_CMD_GO_GO_);
510 err = lan78xx_wait_for_bits(sc, OTP_STATUS, OTP_STATUS_BUSY_);
512 muge_warn_printf(sc, "OTP busy failed to read data\n");
516 if ((err = lan78xx_read_reg(sc, OTP_RD_DATA, &val)) != 0)
519 buf[i] = (uint8_t)(val & 0xff);
531 * @off: the otp address offset
532 * @buf: stores the bytes
533 * @buflen: the number of bytes to read
535 * Simply reads bytes from the otp.
538 * The function takes and releases device lock if it is not already held.
541 * 0 on success, or a USB_ERR_?? error code on failure.
544 lan78xx_otp_read(struct muge_softc *sc, uint16_t off, uint8_t *buf,
550 err = lan78xx_otp_read_raw(sc, OTP_INDICATOR_OFFSET, &sig, 1);
552 if (sig == OTP_INDICATOR_1) {
553 } else if (sig == OTP_INDICATOR_2) {
554 off += 0x100; /* XXX */
559 err = lan78xx_otp_read_raw(sc, off, buf, buflen);
565 * lan78xx_setmacaddress - Set the mac address in the device
566 * @sc: driver soft context
567 * @addr: pointer to array contain at least 6 bytes of the mac
570 * Should be called with the MUGE lock held.
573 * Returns 0 on success or a negative error code.
576 lan78xx_setmacaddress(struct muge_softc *sc, const uint8_t *addr)
582 "setting mac address to %02x:%02x:%02x:%02x:%02x:%02x\n",
583 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
585 MUGE_LOCK_ASSERT(sc, MA_OWNED);
587 val = (addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) | addr[0];
588 if ((err = lan78xx_write_reg(sc, ETH_RX_ADDRL, val)) != 0)
591 val = (addr[5] << 8) | addr[4];
592 err = lan78xx_write_reg(sc, ETH_RX_ADDRH, val);
599 * lan78xx_set_rx_max_frame_length
600 * @sc: driver soft context
601 * @size: pointer to array contain at least 6 bytes of the mac
603 * Sets the maximum frame length to be received. Frames bigger than
604 * this size are aborted.
607 * Returns 0 on success or a negative error code.
610 lan78xx_set_rx_max_frame_length(struct muge_softc *sc, int size)
616 /* First we have to disable rx before changing the length. */
617 err = lan78xx_read_reg(sc, ETH_MAC_RX, &buf);
618 rxenabled = ((buf & ETH_MAC_RX_EN_) != 0);
621 buf &= ~ETH_MAC_RX_EN_;
622 err = lan78xx_write_reg(sc, ETH_MAC_RX, buf);
625 /* Setting max frame length. */
626 buf &= ~ETH_MAC_RX_MAX_FR_SIZE_MASK_;
627 buf |= (((size + 4) << ETH_MAC_RX_MAX_FR_SIZE_SHIFT_) &
628 ETH_MAC_RX_MAX_FR_SIZE_MASK_);
629 err = lan78xx_write_reg(sc, ETH_MAC_RX, buf);
631 /* If it were enabled before, we enable it back. */
634 buf |= ETH_MAC_RX_EN_;
635 err = lan78xx_write_reg(sc, ETH_MAC_RX, buf);
642 * lan78xx_miibus_readreg - Read a MII/MDIO register
643 * @dev: usb ether device
644 * @phy: the number of phy reading from
645 * @reg: the register address
648 * Takes and releases the device mutex lock if not already held.
651 * Returns the 16-bits read from the MII register, if this function fails
655 lan78xx_miibus_readreg(device_t dev, int phy, int reg) {
657 struct muge_softc *sc = device_get_softc(dev);
662 locked = mtx_owned(&sc->sc_mtx);
666 if (lan78xx_wait_for_bits(sc, ETH_MII_ACC, ETH_MII_ACC_MII_BUSY_) !=
668 muge_warn_printf(sc, "MII is busy\n");
672 addr = (phy << 11) | (reg << 6) |
673 ETH_MII_ACC_MII_READ_ | ETH_MII_ACC_MII_BUSY_;
674 lan78xx_write_reg(sc, ETH_MII_ACC, addr);
676 if (lan78xx_wait_for_bits(sc, ETH_MII_ACC, ETH_MII_ACC_MII_BUSY_) !=
678 muge_warn_printf(sc, "MII read timeout\n");
682 lan78xx_read_reg(sc, ETH_MII_DATA, &val);
689 return (val & 0xFFFF);
693 * lan78xx_miibus_writereg - Writes a MII/MDIO register
694 * @dev: usb ether device
695 * @phy: the number of phy writing to
696 * @reg: the register address
697 * @val: the value to write
699 * Attempts to write a PHY register through the usb controller registers.
702 * Takes and releases the device mutex lock if not already held.
705 * Always returns 0 regardless of success or failure.
708 lan78xx_miibus_writereg(device_t dev, int phy, int reg, int val)
710 struct muge_softc *sc = device_get_softc(dev);
714 if (sc->sc_phyno != phy)
717 locked = mtx_owned(&sc->sc_mtx);
721 if (lan78xx_wait_for_bits(sc, ETH_MII_ACC, ETH_MII_ACC_MII_BUSY_) !=
723 muge_warn_printf(sc, "MII is busy\n");
728 lan78xx_write_reg(sc, ETH_MII_DATA, val);
730 addr = (phy << 11) | (reg << 6) |
731 ETH_MII_ACC_MII_WRITE_ | ETH_MII_ACC_MII_BUSY_;
732 lan78xx_write_reg(sc, ETH_MII_ACC, addr);
734 if (lan78xx_wait_for_bits(sc, ETH_MII_ACC, ETH_MII_ACC_MII_BUSY_) != 0)
735 muge_warn_printf(sc, "MII write timeout\n");
744 * lan78xx_miibus_statchg - Called to detect phy status change
745 * @dev: usb ether device
747 * This function is called periodically by the system to poll for status
748 * changes of the link.
751 * Takes and releases the device mutex lock if not already held.
754 lan78xx_miibus_statchg(device_t dev)
756 struct muge_softc *sc = device_get_softc(dev);
757 struct mii_data *mii = uether_getmii(&sc->sc_ue);
762 uint32_t fct_flow = 0;
764 locked = mtx_owned(&sc->sc_mtx);
768 ifp = uether_getifp(&sc->sc_ue);
769 if (mii == NULL || ifp == NULL ||
770 (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
773 /* Use the MII status to determine link status */
774 sc->sc_flags &= ~MUGE_FLAG_LINK;
775 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
776 (IFM_ACTIVE | IFM_AVALID)) {
777 muge_dbg_printf(sc, "media is active\n");
778 switch (IFM_SUBTYPE(mii->mii_media_active)) {
781 sc->sc_flags |= MUGE_FLAG_LINK;
782 muge_dbg_printf(sc, "10/100 ethernet\n");
785 sc->sc_flags |= MUGE_FLAG_LINK;
786 muge_dbg_printf(sc, "Gigabit ethernet\n");
792 /* Lost link, do nothing. */
793 if ((sc->sc_flags & MUGE_FLAG_LINK) == 0) {
794 muge_dbg_printf(sc, "link flag not set\n");
798 err = lan78xx_read_reg(sc, ETH_FCT_FLOW, &fct_flow);
801 "failed to read initial flow control thresholds, error %d\n",
806 /* Enable/disable full duplex operation and TX/RX pause. */
807 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) {
808 muge_dbg_printf(sc, "full duplex operation\n");
810 /* Enable transmit MAC flow control function. */
811 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_TXPAUSE) != 0)
812 flow |= ETH_FLOW_CR_TX_FCEN_ | 0xFFFF;
814 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_RXPAUSE) != 0)
815 flow |= ETH_FLOW_CR_RX_FCEN_;
818 /* XXX Flow control settings obtained from Microchip's driver. */
819 switch(usbd_get_speed(sc->sc_ue.ue_udev)) {
820 case USB_SPEED_SUPER:
830 err += lan78xx_write_reg(sc, ETH_FLOW, flow);
831 err += lan78xx_write_reg(sc, ETH_FCT_FLOW, fct_flow);
833 muge_warn_printf(sc, "media change failed, error %d\n", err);
841 * lan78xx_set_mdix_auto - Configure the device to enable automatic
842 * crossover and polarity detection. LAN7800 provides HP Auto-MDIX
843 * functionality for seamless crossover and polarity detection.
845 * @sc: driver soft context
848 * Takes and releases the device mutex lock if not already held.
851 lan78xx_set_mdix_auto(struct muge_softc *sc)
855 err = lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno,
856 MUGE_EXT_PAGE_ACCESS, MUGE_EXT_PAGE_SPACE_1);
858 buf = lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno,
860 buf &= ~MUGE_EXT_MODE_CTRL_MDIX_MASK_;
861 buf |= MUGE_EXT_MODE_CTRL_AUTO_MDIX_;
863 lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR);
864 err += lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno,
865 MUGE_EXT_MODE_CTRL, buf);
867 err += lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno,
868 MUGE_EXT_PAGE_ACCESS, MUGE_EXT_PAGE_SPACE_0);
871 muge_warn_printf(sc, "error setting PHY's MDIX status\n");
873 sc->sc_mdix_ctl = buf;
877 * lan78xx_phy_init - Initialises the in-built MUGE phy
878 * @sc: driver soft context
880 * Resets the PHY part of the chip and then initialises it to default
881 * values. The 'link down' and 'auto-negotiation complete' interrupts
882 * from the PHY are also enabled, however we don't monitor the interrupt
883 * endpoints for the moment.
886 * Returns 0 on success or EIO if failed to reset the PHY.
889 lan78xx_phy_init(struct muge_softc *sc)
891 muge_dbg_printf(sc, "Initializing PHY.\n");
893 usb_ticks_t start_ticks;
894 const usb_ticks_t max_ticks = USB_MS_TO_TICKS(1000);
896 MUGE_LOCK_ASSERT(sc, MA_OWNED);
898 /* Reset phy and wait for reset to complete. */
899 lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR,
904 uether_pause(&sc->sc_ue, hz / 100);
905 bmcr = lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno,
907 } while ((bmcr & BMCR_RESET) && ((ticks - start_ticks) < max_ticks));
909 if (((usb_ticks_t)(ticks - start_ticks)) >= max_ticks) {
910 muge_err_printf(sc, "PHY reset timed-out\n");
914 /* Setup phy to interrupt upon link down or autoneg completion. */
915 lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno,
917 lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno,
919 (MUGE_PHY_INTR_ANEG_COMP | MUGE_PHY_INTR_LINK_CHANGE));
921 /* Enable Auto-MDIX for crossover and polarity detection. */
922 lan78xx_set_mdix_auto(sc);
924 /* Enable all modes. */
925 lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_ANAR,
926 ANAR_10 | ANAR_10_FD | ANAR_TX | ANAR_TX_FD |
927 ANAR_CSMA | ANAR_FC | ANAR_PAUSE_ASYM);
929 /* Restart auto-negotation. */
930 bmcr |= BMCR_STARTNEG;
932 lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR, bmcr);
933 bmcr = lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR);
938 * lan78xx_chip_init - Initialises the chip after power on
939 * @sc: driver soft context
941 * This initialisation sequence is modelled on the procedure in the Linux
945 * Returns 0 on success or an error code on failure.
948 lan78xx_chip_init(struct muge_softc *sc)
954 MUGE_LOCK_ASSERT(sc, MA_OWNED);
956 /* Enter H/W config mode. */
957 lan78xx_write_reg(sc, ETH_HW_CFG, ETH_HW_CFG_LRST_);
959 if ((err = lan78xx_wait_for_bits(sc, ETH_HW_CFG, ETH_HW_CFG_LRST_)) !=
962 "timed-out waiting for lite reset to complete\n");
966 /* Set the mac address. */
967 if ((err = lan78xx_setmacaddress(sc, sc->sc_ue.ue_eaddr)) != 0) {
968 muge_warn_printf(sc, "failed to set the MAC address\n");
972 /* Read and display the revision register. */
973 if ((err = lan78xx_read_reg(sc, ETH_ID_REV, &buf)) < 0) {
974 muge_warn_printf(sc, "failed to read ETH_ID_REV (err = %d)\n",
978 sc->chipid = (buf & ETH_ID_REV_CHIP_ID_MASK_) >> 16;
979 sc->chiprev = buf & ETH_ID_REV_CHIP_REV_MASK_;
980 switch (sc->chipid) {
981 case ETH_ID_REV_CHIP_ID_7800_:
982 case ETH_ID_REV_CHIP_ID_7850_:
985 muge_warn_printf(sc, "Chip ID 0x%04x not yet supported\n",
989 device_printf(sc->sc_ue.ue_dev, "Chip ID 0x%04x rev %04x\n", sc->chipid,
992 /* Respond to BULK-IN tokens with a NAK when RX FIFO is empty. */
993 if ((err = lan78xx_read_reg(sc, ETH_USB_CFG0, &buf)) != 0) {
994 muge_warn_printf(sc, "failed to read ETH_USB_CFG0 (err=%d)\n", err);
997 buf |= ETH_USB_CFG_BIR_;
998 lan78xx_write_reg(sc, ETH_USB_CFG0, buf);
1001 * XXX LTM support will go here.
1004 /* Configuring the burst cap. */
1005 switch (usbd_get_speed(sc->sc_ue.ue_udev)) {
1006 case USB_SPEED_SUPER:
1007 burst_cap = MUGE_DEFAULT_BURST_CAP_SIZE/MUGE_SS_USB_PKT_SIZE;
1009 case USB_SPEED_HIGH:
1010 burst_cap = MUGE_DEFAULT_BURST_CAP_SIZE/MUGE_HS_USB_PKT_SIZE;
1013 burst_cap = MUGE_DEFAULT_BURST_CAP_SIZE/MUGE_FS_USB_PKT_SIZE;
1016 lan78xx_write_reg(sc, ETH_BURST_CAP, burst_cap);
1018 /* Set the default bulk in delay (same value from Linux driver). */
1019 lan78xx_write_reg(sc, ETH_BULK_IN_DLY, MUGE_DEFAULT_BULK_IN_DELAY);
1021 /* Multiple ethernet frames per USB packets. */
1022 err = lan78xx_read_reg(sc, ETH_HW_CFG, &buf);
1023 buf |= ETH_HW_CFG_MEF_;
1024 err = lan78xx_write_reg(sc, ETH_HW_CFG, buf);
1026 /* Enable burst cap. */
1027 if ((err = lan78xx_read_reg(sc, ETH_USB_CFG0, &buf)) < 0) {
1028 muge_warn_printf(sc, "failed to read ETH_USB_CFG0 (err=%d)\n",
1032 buf |= ETH_USB_CFG_BCE_;
1033 err = lan78xx_write_reg(sc, ETH_USB_CFG0, buf);
1036 * Set FCL's RX and TX FIFO sizes: according to data sheet this is
1037 * already the default value. But we initialize it to the same value
1038 * anyways, as that's what the Linux driver does.
1041 buf = (MUGE_MAX_RX_FIFO_SIZE - 512) / 512;
1042 err = lan78xx_write_reg(sc, ETH_FCT_RX_FIFO_END, buf);
1044 buf = (MUGE_MAX_TX_FIFO_SIZE - 512) / 512;
1045 err = lan78xx_write_reg(sc, ETH_FCT_TX_FIFO_END, buf);
1047 /* Enabling interrupts. (Not using them for now) */
1048 err = lan78xx_write_reg(sc, ETH_INT_STS, ETH_INT_STS_CLEAR_ALL_);
1051 * Initializing flow control registers to 0. These registers are
1052 * properly set is handled in link-reset function in the Linux driver.
1054 err = lan78xx_write_reg(sc, ETH_FLOW, 0);
1055 err = lan78xx_write_reg(sc, ETH_FCT_FLOW, 0);
1058 * Settings for the RFE, we enable broadcast and destination address
1059 * perfect filtering.
1061 err = lan78xx_read_reg(sc, ETH_RFE_CTL, &buf);
1062 buf |= ETH_RFE_CTL_BCAST_EN_ | ETH_RFE_CTL_DA_PERFECT_;
1063 err = lan78xx_write_reg(sc, ETH_RFE_CTL, buf);
1066 * At this point the Linux driver writes multicast tables, and enables
1067 * checksum engines. But in FreeBSD that gets done in muge_init,
1068 * which gets called when the interface is brought up.
1071 /* Reset the PHY. */
1072 lan78xx_write_reg(sc, ETH_PMT_CTL, ETH_PMT_CTL_PHY_RST_);
1073 if ((err = lan78xx_wait_for_bits(sc, ETH_PMT_CTL,
1074 ETH_PMT_CTL_PHY_RST_)) != 0) {
1075 muge_warn_printf(sc,
1076 "timed-out waiting for phy reset to complete\n");
1080 err = lan78xx_read_reg(sc, ETH_MAC_CR, &buf);
1081 if (sc->chipid == ETH_ID_REV_CHIP_ID_7800_ &&
1082 !lan78xx_eeprom_present(sc)) {
1083 /* Set automatic duplex and speed on LAN7800 without EEPROM. */
1084 buf |= ETH_MAC_CR_AUTO_DUPLEX_ | ETH_MAC_CR_AUTO_SPEED_;
1086 err = lan78xx_write_reg(sc, ETH_MAC_CR, buf);
1089 * Enable PHY interrupts (Not really getting used for now)
1090 * ETH_INT_EP_CTL: interrupt endpoint control register
1091 * phy events cause interrupts to be issued
1093 err = lan78xx_read_reg(sc, ETH_INT_EP_CTL, &buf);
1094 buf |= ETH_INT_ENP_PHY_INT;
1095 err = lan78xx_write_reg(sc, ETH_INT_EP_CTL, buf);
1098 * Enables mac's transmitter. It will transmit frames from the buffer
1101 err = lan78xx_read_reg(sc, ETH_MAC_TX, &buf);
1102 buf |= ETH_MAC_TX_TXEN_;
1103 err = lan78xx_write_reg(sc, ETH_MAC_TX, buf);
1105 /* FIFO is capable of transmitting frames to MAC. */
1106 err = lan78xx_read_reg(sc, ETH_FCT_TX_CTL, &buf);
1107 buf |= ETH_FCT_TX_CTL_EN_;
1108 err = lan78xx_write_reg(sc, ETH_FCT_TX_CTL, buf);
1111 * Set max frame length. In linux this is dev->mtu (which by default
1112 * is 1500) + VLAN_ETH_HLEN = 1518.
1114 err = lan78xx_set_rx_max_frame_length(sc, ETHER_MAX_LEN);
1116 /* Initialise the PHY. */
1117 if ((err = lan78xx_phy_init(sc)) != 0)
1120 /* Enable MAC RX. */
1121 err = lan78xx_read_reg(sc, ETH_MAC_RX, &buf);
1122 buf |= ETH_MAC_RX_EN_;
1123 err = lan78xx_write_reg(sc, ETH_MAC_RX, buf);
1125 /* Enable FIFO controller RX. */
1126 err = lan78xx_read_reg(sc, ETH_FCT_RX_CTL, &buf);
1127 buf |= ETH_FCT_TX_CTL_EN_;
1128 err = lan78xx_write_reg(sc, ETH_FCT_RX_CTL, buf);
1130 sc->sc_flags |= MUGE_FLAG_INIT_DONE;
1134 muge_err_printf(sc, "lan78xx_chip_init failed (err=%d)\n", err);
1139 muge_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
1141 struct muge_softc *sc = usbd_xfer_softc(xfer);
1142 struct usb_ether *ue = &sc->sc_ue;
1143 struct ifnet *ifp = uether_getifp(ue);
1145 struct usb_page_cache *pc;
1147 uint32_t rx_cmd_a, rx_cmd_b;
1152 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
1153 muge_dbg_printf(sc, "rx : actlen %d\n", actlen);
1155 switch (USB_GET_STATE(xfer)) {
1156 case USB_ST_TRANSFERRED:
1159 * There is always a zero length frame after bringing the
1162 if (actlen < (sizeof(rx_cmd_a) + ETHER_CRC_LEN))
1166 * There may be multiple packets in the USB frame. Each will
1167 * have a header and each needs to have its own mbuf allocated
1168 * and populated for it.
1170 pc = usbd_xfer_get_frame(xfer, 0);
1173 while (off < actlen) {
1175 /* The frame header is aligned on a 4 byte boundary. */
1176 off = ((off + 0x3) & ~0x3);
1178 /* Extract RX CMD A. */
1179 if (off + sizeof(rx_cmd_a) > actlen)
1181 usbd_copy_out(pc, off, &rx_cmd_a, sizeof(rx_cmd_a));
1182 off += (sizeof(rx_cmd_a));
1183 rx_cmd_a = le32toh(rx_cmd_a);
1186 /* Extract RX CMD B. */
1187 if (off + sizeof(rx_cmd_b) > actlen)
1189 usbd_copy_out(pc, off, &rx_cmd_b, sizeof(rx_cmd_b));
1190 off += (sizeof(rx_cmd_b));
1191 rx_cmd_b = le32toh(rx_cmd_b);
1194 /* Extract RX CMD C. */
1195 if (off + sizeof(rx_cmd_c) > actlen)
1197 usbd_copy_out(pc, off, &rx_cmd_c, sizeof(rx_cmd_c));
1198 off += (sizeof(rx_cmd_c));
1199 rx_cmd_c = le32toh(rx_cmd_c);
1204 pktlen = (rx_cmd_a & RX_CMD_A_LEN_MASK_);
1207 "rx_cmd_a 0x%08x rx_cmd_b 0x%08x rx_cmd_c 0x%04x "
1208 " pktlen %d actlen %d off %d\n",
1209 rx_cmd_a, rx_cmd_b, rx_cmd_c, pktlen, actlen, off);
1211 if (rx_cmd_a & RX_CMD_A_RED_) {
1213 "rx error (hdr 0x%08x)\n", rx_cmd_a);
1214 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1216 /* Ethernet frame too big or too small? */
1217 if ((pktlen < ETHER_HDR_LEN) ||
1218 (pktlen > (actlen - off)))
1221 /* Create a new mbuf to store the packet. */
1222 m = uether_newbuf();
1224 muge_warn_printf(sc,
1225 "failed to create new mbuf\n");
1226 if_inc_counter(ifp, IFCOUNTER_IQDROPS,
1231 usbd_copy_out(pc, off, mtod(m, uint8_t *),
1235 * Check if RX checksums are computed, and
1238 if ((ifp->if_capabilities & IFCAP_RXCSUM) &&
1239 !(rx_cmd_a & RX_CMD_A_ICSM_)) {
1240 struct ether_header *eh;
1241 eh = mtod(m, struct ether_header *);
1243 * Remove the extra 2 bytes of the csum
1245 * The checksum appears to be
1246 * simplistically calculated over the
1247 * protocol headers up to the end of the
1248 * eth frame. Which means if the eth
1249 * frame is padded the csum calculation
1250 * is incorrectly performed over the
1251 * padding bytes as well. Therefore to
1252 * be safe we ignore the H/W csum on
1253 * frames less than or equal to
1256 * Protocols checksummed:
1257 * TCP, UDP, ICMP, IGMP, IP
1259 if (pktlen > ETHER_MIN_LEN) {
1260 m->m_pkthdr.csum_flags |=
1264 * Copy the checksum from the
1265 * last 2 bytes of the transfer
1266 * and put in the csum_data
1271 &m->m_pkthdr.csum_data, 2);
1274 * The data is copied in network
1275 * order, but the csum algorithm
1276 * in the kernel expects it to
1277 * be in host network order.
1279 m->m_pkthdr.csum_data =
1280 ntohs(m->m_pkthdr.csum_data);
1283 "RX checksum offloaded (0x%04x)\n",
1284 m->m_pkthdr.csum_data);
1288 /* Enqueue the mbuf on the receive queue. */
1289 if (pktlen < (4 + ETHER_HDR_LEN)) {
1293 /* Remove 4 trailing bytes */
1294 uether_rxmbuf(ue, m, pktlen - 4);
1298 * Update the offset to move to the next potential
1307 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
1308 usbd_transfer_submit(xfer);
1313 if (error != USB_ERR_CANCELLED) {
1314 muge_warn_printf(sc, "bulk read error, %s\n",
1315 usbd_errstr(error));
1316 usbd_xfer_set_stall(xfer);
1324 * muge_bulk_write_callback - Write callback used to send ethernet frame(s)
1325 * @xfer: the USB transfer
1326 * @error: error code if the transfers is in an errored state
1328 * The main write function that pulls ethernet frames off the queue and
1333 muge_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
1335 struct muge_softc *sc = usbd_xfer_softc(xfer);
1336 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
1337 struct usb_page_cache *pc;
1340 uint32_t frm_len = 0, tx_cmd_a = 0, tx_cmd_b = 0;
1342 switch (USB_GET_STATE(xfer)) {
1343 case USB_ST_TRANSFERRED:
1345 "USB TRANSFER status: USB_ST_TRANSFERRED\n");
1346 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1349 muge_dbg_printf(sc, "USB TRANSFER status: USB_ST_SETUP\n");
1351 if ((sc->sc_flags & MUGE_FLAG_LINK) == 0 ||
1352 (ifp->if_drv_flags & IFF_DRV_OACTIVE) != 0) {
1354 "sc->sc_flags & MUGE_FLAG_LINK: %d\n",
1355 (sc->sc_flags & MUGE_FLAG_LINK));
1357 "ifp->if_drv_flags & IFF_DRV_OACTIVE: %d\n",
1358 (ifp->if_drv_flags & IFF_DRV_OACTIVE));
1360 "USB TRANSFER not sending: no link or controller is busy \n");
1362 * Don't send anything if there is no link or
1363 * controller is busy.
1367 for (nframes = 0; nframes < 16 &&
1368 !IFQ_DRV_IS_EMPTY(&ifp->if_snd); nframes++) {
1369 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
1372 usbd_xfer_set_frame_offset(xfer, nframes * MCLBYTES,
1375 pc = usbd_xfer_get_frame(xfer, nframes);
1378 * Each frame is prefixed with two 32-bit values
1379 * describing the length of the packet and buffer.
1381 tx_cmd_a = (m->m_pkthdr.len & TX_CMD_A_LEN_MASK_) |
1383 tx_cmd_a = htole32(tx_cmd_a);
1384 usbd_copy_in(pc, 0, &tx_cmd_a, sizeof(tx_cmd_a));
1388 /* TCP LSO Support will probably be implemented here. */
1389 tx_cmd_b = htole32(tx_cmd_b);
1390 usbd_copy_in(pc, 4, &tx_cmd_b, sizeof(tx_cmd_b));
1394 /* Next copy in the actual packet */
1395 usbd_m_copy_in(pc, frm_len, m, 0, m->m_pkthdr.len);
1396 frm_len += m->m_pkthdr.len;
1398 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
1401 * If there's a BPF listener, bounce a copy of this
1407 /* Set frame length. */
1408 usbd_xfer_set_frame_len(xfer, nframes, frm_len);
1411 muge_dbg_printf(sc, "USB TRANSFER nframes: %d\n", nframes);
1413 muge_dbg_printf(sc, "USB TRANSFER submit attempt\n");
1414 usbd_xfer_set_frames(xfer, nframes);
1415 usbd_transfer_submit(xfer);
1416 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
1421 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1422 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1424 if (error != USB_ERR_CANCELLED) {
1426 "usb error on tx: %s\n", usbd_errstr(error));
1427 usbd_xfer_set_stall(xfer);
1436 * muge_fdt_find_eth_node - find descendant node with required compatibility
1437 * @start: start node
1438 * @compatible: compatible string used to identify the node
1440 * Loop through all descendant nodes and return first match with required
1444 * Returns node's phandle on success -1 otherwise
1447 muge_fdt_find_eth_node(phandle_t start, const char *compatible)
1449 phandle_t child, node;
1451 /* Traverse through entire tree to find usb ethernet nodes. */
1452 for (node = OF_child(start); node != 0; node = OF_peer(node)) {
1453 if (ofw_bus_node_is_compatible(node, compatible))
1455 child = muge_fdt_find_eth_node(node, compatible);
1464 * muge_fdt_read_mac_property - read MAC address from node
1465 * @node: USB device node
1466 * @mac: memory to store MAC address to
1468 * Check for common properties that might contain MAC address
1469 * passed by boot loader.
1472 * Returns 0 on success, error code otherwise
1475 muge_fdt_read_mac_property(phandle_t node, unsigned char *mac)
1479 /* Check if there is property */
1480 if ((len = OF_getproplen(node, "local-mac-address")) > 0) {
1481 if (len != ETHER_ADDR_LEN)
1484 OF_getprop(node, "local-mac-address", mac,
1489 if ((len = OF_getproplen(node, "mac-address")) > 0) {
1490 if (len != ETHER_ADDR_LEN)
1493 OF_getprop(node, "mac-address", mac,
1502 * muge_fdt_find_mac - read MAC address from node
1503 * @compatible: compatible string for DTB node in the form "usb[N]NNN,[M]MMM"
1504 * where NNN is vendor id and MMM is product id
1505 * @mac: memory to store MAC address to
1507 * Tries to find matching node in DTS and obtain MAC address info from it
1510 * Returns 0 on success, error code otherwise
1513 muge_fdt_find_mac(const char *compatible, unsigned char *mac)
1515 phandle_t node, root;
1517 root = OF_finddevice("/");
1518 node = muge_fdt_find_eth_node(root, compatible);
1520 if (muge_fdt_read_mac_property(node, mac) == 0)
1529 * muge_set_mac_addr - Initiailizes NIC MAC address
1530 * @ue: the USB ethernet device
1532 * Tries to obtain MAC address from number of sources: registers,
1533 * EEPROM, DTB blob. If all sources fail - generates random MAC.
1536 muge_set_mac_addr(struct usb_ether *ue)
1538 struct muge_softc *sc = uether_getsc(ue);
1539 uint32_t mac_h, mac_l;
1541 char compatible[16];
1542 struct usb_attach_arg *uaa = device_get_ivars(ue->ue_dev);
1545 memset(sc->sc_ue.ue_eaddr, 0xff, ETHER_ADDR_LEN);
1548 lan78xx_read_reg(sc, 0, &val);
1550 /* Read current MAC address from RX_ADDRx registers. */
1551 if ((lan78xx_read_reg(sc, ETH_RX_ADDRL, &mac_l) == 0) &&
1552 (lan78xx_read_reg(sc, ETH_RX_ADDRH, &mac_h) == 0)) {
1553 sc->sc_ue.ue_eaddr[5] = (uint8_t)((mac_h >> 8) & 0xff);
1554 sc->sc_ue.ue_eaddr[4] = (uint8_t)((mac_h) & 0xff);
1555 sc->sc_ue.ue_eaddr[3] = (uint8_t)((mac_l >> 24) & 0xff);
1556 sc->sc_ue.ue_eaddr[2] = (uint8_t)((mac_l >> 16) & 0xff);
1557 sc->sc_ue.ue_eaddr[1] = (uint8_t)((mac_l >> 8) & 0xff);
1558 sc->sc_ue.ue_eaddr[0] = (uint8_t)((mac_l) & 0xff);
1561 /* If RX_ADDRx did not provide a valid MAC address, try EEPROM. */
1562 if (ETHER_IS_VALID(sc->sc_ue.ue_eaddr)) {
1563 muge_dbg_printf(sc, "MAC assigned from registers\n");
1567 if ((lan78xx_eeprom_present(sc) &&
1568 lan78xx_eeprom_read_raw(sc, ETH_E2P_MAC_OFFSET,
1569 sc->sc_ue.ue_eaddr, ETHER_ADDR_LEN) == 0) ||
1570 (lan78xx_otp_read(sc, OTP_MAC_OFFSET,
1571 sc->sc_ue.ue_eaddr, ETHER_ADDR_LEN) == 0)) {
1572 if (ETHER_IS_VALID(sc->sc_ue.ue_eaddr)) {
1573 muge_dbg_printf(sc, "MAC read from EEPROM\n");
1579 snprintf(compatible, sizeof(compatible), "usb%x,%x",
1580 uaa->info.idVendor, uaa->info.idProduct);
1581 if (muge_fdt_find_mac(compatible, sc->sc_ue.ue_eaddr) == 0) {
1582 muge_dbg_printf(sc, "MAC assigned from FDT blob\n");
1587 muge_dbg_printf(sc, "MAC assigned randomly\n");
1588 arc4rand(sc->sc_ue.ue_eaddr, ETHER_ADDR_LEN, 0);
1589 sc->sc_ue.ue_eaddr[0] &= ~0x01; /* unicast */
1590 sc->sc_ue.ue_eaddr[0] |= 0x02; /* locally administered */
1594 * muge_attach_post - Called after the driver attached to the USB interface
1595 * @ue: the USB ethernet device
1597 * This is where the chip is intialised for the first time. This is
1598 * different from the muge_init() function in that that one is designed to
1599 * setup the H/W to match the UE settings and can be called after a reset.
1603 muge_attach_post(struct usb_ether *ue)
1605 struct muge_softc *sc = uether_getsc(ue);
1607 muge_dbg_printf(sc, "Calling muge_attach_post.\n");
1609 /* Setup some of the basics */
1612 muge_set_mac_addr(ue);
1614 /* Initialise the chip for the first time */
1615 lan78xx_chip_init(sc);
1619 * muge_attach_post_sub - Called after attach to the USB interface
1620 * @ue: the USB ethernet device
1622 * Most of this is boilerplate code and copied from the base USB ethernet
1623 * driver. It has been overriden so that we can indicate to the system
1624 * that the chip supports H/W checksumming.
1627 * Returns 0 on success or a negative error code.
1630 muge_attach_post_sub(struct usb_ether *ue)
1632 struct muge_softc *sc;
1636 sc = uether_getsc(ue);
1637 muge_dbg_printf(sc, "Calling muge_attach_post_sub.\n");
1639 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1640 ifp->if_start = uether_start;
1641 ifp->if_ioctl = muge_ioctl;
1642 ifp->if_init = uether_init;
1643 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
1644 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
1645 IFQ_SET_READY(&ifp->if_snd);
1648 * The chip supports TCP/UDP checksum offloading on TX and RX paths,
1649 * however currently only RX checksum is supported in the driver
1650 * (see top of file).
1652 ifp->if_hwassist = 0;
1653 if (MUGE_DEFAULT_RX_CSUM_ENABLE)
1654 ifp->if_capabilities |= IFCAP_RXCSUM;
1656 if (MUGE_DEFAULT_TX_CSUM_ENABLE)
1657 ifp->if_capabilities |= IFCAP_TXCSUM;
1660 * In the Linux driver they also enable scatter/gather (NETIF_F_SG)
1661 * here, that's something related to socket buffers used in Linux.
1662 * FreeBSD doesn't have that as an interface feature.
1664 if (MUGE_DEFAULT_TSO_CSUM_ENABLE)
1665 ifp->if_capabilities |= IFCAP_TSO4 | IFCAP_TSO6;
1668 /* TX checksuming is disabled since not yet implemented. */
1669 ifp->if_capabilities |= IFCAP_TXCSUM;
1670 ifp->if_capenable |= IFCAP_TXCSUM;
1671 ifp->if_hwassist = CSUM_TCP | CSUM_UDP;
1674 ifp->if_capenable = ifp->if_capabilities;
1677 error = mii_attach(ue->ue_dev, &ue->ue_miibus, ifp,
1678 uether_ifmedia_upd, ue->ue_methods->ue_mii_sts,
1679 BMSR_DEFCAPMASK, sc->sc_phyno, MII_OFFSET_ANY, 0);
1686 * muge_start - Starts communication with the LAN78xx chip
1687 * @ue: USB ether interface
1690 muge_start(struct usb_ether *ue)
1692 struct muge_softc *sc = uether_getsc(ue);
1695 * Start the USB transfers, if not already started.
1697 usbd_transfer_start(sc->sc_xfer[MUGE_BULK_DT_RD]);
1698 usbd_transfer_start(sc->sc_xfer[MUGE_BULK_DT_WR]);
1702 * muge_ioctl - ioctl function for the device
1703 * @ifp: interface pointer
1704 * @cmd: the ioctl command
1705 * @data: data passed in the ioctl call, typically a pointer to struct
1708 * The ioctl routine is overridden to detect change requests for the H/W
1709 * checksum capabilities.
1712 * 0 on success and an error code on failure.
1715 muge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
1717 struct usb_ether *ue = ifp->if_softc;
1718 struct muge_softc *sc;
1724 if (cmd == SIOCSIFCAP) {
1725 sc = uether_getsc(ue);
1726 ifr = (struct ifreq *)data;
1733 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1735 /* Modify the RX CSUM enable bits. */
1736 if ((mask & IFCAP_RXCSUM) != 0 &&
1737 (ifp->if_capabilities & IFCAP_RXCSUM) != 0) {
1738 ifp->if_capenable ^= IFCAP_RXCSUM;
1740 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1741 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1751 rc = uether_ioctl(ifp, cmd, data);
1758 * muge_reset - Reset the SMSC chip
1759 * @sc: device soft context
1762 * Should be called with the SMSC lock held.
1765 muge_reset(struct muge_softc *sc)
1767 struct usb_config_descriptor *cd;
1770 cd = usbd_get_config_descriptor(sc->sc_ue.ue_udev);
1772 err = usbd_req_set_config(sc->sc_ue.ue_udev, &sc->sc_mtx,
1773 cd->bConfigurationValue);
1775 muge_warn_printf(sc, "reset failed (ignored)\n");
1777 /* Wait a little while for the chip to get its brains in order. */
1778 uether_pause(&sc->sc_ue, hz / 100);
1780 /* Reinitialize controller to achieve full reset. */
1781 lan78xx_chip_init(sc);
1785 * muge_set_addr_filter
1787 * @sc: device soft context
1788 * @index: index of the entry to the perfect address table
1789 * @addr: address to be written
1793 muge_set_addr_filter(struct muge_softc *sc, int index,
1794 uint8_t addr[ETHER_ADDR_LEN])
1798 if ((sc) && (index > 0) && (index < MUGE_NUM_PFILTER_ADDRS_)) {
1800 tmp |= addr[2] | (tmp << 8);
1801 tmp |= addr[1] | (tmp << 8);
1802 tmp |= addr[0] | (tmp << 8);
1803 sc->sc_pfilter_table[index][1] = tmp;
1805 tmp |= addr[4] | (tmp << 8);
1806 tmp |= ETH_MAF_HI_VALID_ | ETH_MAF_HI_TYPE_DST_;
1807 sc->sc_pfilter_table[index][0] = tmp;
1812 * lan78xx_dataport_write - write to the selected RAM
1813 * @sc: The device soft context.
1814 * @ram_select: Select which RAM to access.
1815 * @addr: Starting address to write to.
1816 * @buf: word-sized buffer to write to RAM, starting at @addr.
1817 * @length: length of @buf
1821 * 0 if write successful.
1824 lan78xx_dataport_write(struct muge_softc *sc, uint32_t ram_select,
1825 uint32_t addr, uint32_t length, uint32_t *buf)
1830 MUGE_LOCK_ASSERT(sc, MA_OWNED);
1831 ret = lan78xx_wait_for_bits(sc, ETH_DP_SEL, ETH_DP_SEL_DPRDY_);
1835 ret = lan78xx_read_reg(sc, ETH_DP_SEL, &dp_sel);
1837 dp_sel &= ~ETH_DP_SEL_RSEL_MASK_;
1838 dp_sel |= ram_select;
1840 ret = lan78xx_write_reg(sc, ETH_DP_SEL, dp_sel);
1842 for (i = 0; i < length; i++) {
1843 ret = lan78xx_write_reg(sc, ETH_DP_ADDR, addr + i);
1844 ret = lan78xx_write_reg(sc, ETH_DP_DATA, buf[i]);
1845 ret = lan78xx_write_reg(sc, ETH_DP_CMD, ETH_DP_CMD_WRITE_);
1846 ret = lan78xx_wait_for_bits(sc, ETH_DP_SEL, ETH_DP_SEL_DPRDY_);
1856 * muge_multicast_write
1857 * @sc: device's soft context
1859 * Writes perfect addres filters and hash address filters to their
1860 * corresponding registers and RAMs.
1864 muge_multicast_write(struct muge_softc *sc)
1867 lan78xx_dataport_write(sc, ETH_DP_SEL_RSEL_VLAN_DA_,
1868 ETH_DP_SEL_VHF_VLAN_LEN, ETH_DP_SEL_VHF_HASH_LEN,
1869 sc->sc_mchash_table);
1871 for (i = 1; i < MUGE_NUM_PFILTER_ADDRS_; i++) {
1872 ret = lan78xx_write_reg(sc, PFILTER_HI(i), 0);
1873 ret = lan78xx_write_reg(sc, PFILTER_LO(i),
1874 sc->sc_pfilter_table[i][1]);
1875 ret = lan78xx_write_reg(sc, PFILTER_HI(i),
1876 sc->sc_pfilter_table[i][0]);
1881 * muge_hash - Calculate the hash of a mac address
1882 * @addr: The mac address to calculate the hash on
1884 * This function is used when configuring a range of multicast mac
1885 * addresses to filter on. The hash of the mac address is put in the
1886 * device's mac hash table.
1889 * Returns a value from 0-63 value which is the hash of the mac address.
1891 static inline uint32_t
1892 muge_hash(uint8_t addr[ETHER_ADDR_LEN])
1894 return (ether_crc32_be(addr, ETHER_ADDR_LEN) >> 26) & 0x3f;
1898 * muge_setmulti - Setup multicast
1899 * @ue: usb ethernet device context
1901 * Tells the device to either accept frames with a multicast mac address,
1902 * a select group of m'cast mac addresses or just the devices mac address.
1905 * Should be called with the MUGE lock held.
1908 muge_setmulti(struct usb_ether *ue)
1910 struct muge_softc *sc = uether_getsc(ue);
1911 struct ifnet *ifp = uether_getifp(ue);
1913 struct ifmultiaddr *ifma;
1915 MUGE_LOCK_ASSERT(sc, MA_OWNED);
1917 sc->sc_rfe_ctl &= ~(ETH_RFE_CTL_UCAST_EN_ | ETH_RFE_CTL_MCAST_EN_ |
1918 ETH_RFE_CTL_DA_PERFECT_ | ETH_RFE_CTL_MCAST_HASH_);
1920 /* Initialize hash filter table. */
1921 for (i = 0; i < ETH_DP_SEL_VHF_HASH_LEN; i++)
1922 sc->sc_mchash_table[i] = 0;
1924 /* Initialize perfect filter table. */
1925 for (i = 1; i < MUGE_NUM_PFILTER_ADDRS_; i++) {
1926 sc->sc_pfilter_table[i][0] =
1927 sc->sc_pfilter_table[i][1] = 0;
1930 sc->sc_rfe_ctl |= ETH_RFE_CTL_BCAST_EN_;
1932 if (ifp->if_flags & IFF_PROMISC) {
1933 muge_dbg_printf(sc, "promiscuous mode enabled\n");
1934 sc->sc_rfe_ctl |= ETH_RFE_CTL_MCAST_EN_ | ETH_RFE_CTL_UCAST_EN_;
1935 } else if (ifp->if_flags & IFF_ALLMULTI){
1936 muge_dbg_printf(sc, "receive all multicast enabled\n");
1937 sc->sc_rfe_ctl |= ETH_RFE_CTL_MCAST_EN_;
1939 /* Lock the mac address list before hashing each of them. */
1940 if_maddr_rlock(ifp);
1941 if (!CK_STAILQ_EMPTY(&ifp->if_multiaddrs)) {
1943 CK_STAILQ_FOREACH(ifma, &ifp->if_multiaddrs,
1945 /* First fill up the perfect address table. */
1946 addr = LLADDR((struct sockaddr_dl *)
1948 if (i < 33 /* XXX */) {
1949 muge_set_addr_filter(sc, i, addr);
1951 uint32_t bitnum = muge_hash(addr);
1952 sc->sc_mchash_table[bitnum / 32] |=
1953 (1 << (bitnum % 32));
1955 ETH_RFE_CTL_MCAST_HASH_;
1960 if_maddr_runlock(ifp);
1961 muge_multicast_write(sc);
1963 lan78xx_write_reg(sc, ETH_RFE_CTL, sc->sc_rfe_ctl);
1967 * muge_setpromisc - Enables/disables promiscuous mode
1968 * @ue: usb ethernet device context
1971 * Should be called with the MUGE lock held.
1974 muge_setpromisc(struct usb_ether *ue)
1976 struct muge_softc *sc = uether_getsc(ue);
1977 struct ifnet *ifp = uether_getifp(ue);
1979 muge_dbg_printf(sc, "promiscuous mode %sabled\n",
1980 (ifp->if_flags & IFF_PROMISC) ? "en" : "dis");
1982 MUGE_LOCK_ASSERT(sc, MA_OWNED);
1984 if (ifp->if_flags & IFF_PROMISC)
1985 sc->sc_rfe_ctl |= ETH_RFE_CTL_MCAST_EN_ | ETH_RFE_CTL_UCAST_EN_;
1987 sc->sc_rfe_ctl &= ~(ETH_RFE_CTL_MCAST_EN_);
1989 lan78xx_write_reg(sc, ETH_RFE_CTL, sc->sc_rfe_ctl);
1993 * muge_sethwcsum - Enable or disable H/W UDP and TCP checksumming
1994 * @sc: driver soft context
1997 * Should be called with the MUGE lock held.
2000 * Returns 0 on success or a negative error code.
2002 static int muge_sethwcsum(struct muge_softc *sc)
2004 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
2010 MUGE_LOCK_ASSERT(sc, MA_OWNED);
2012 if (ifp->if_capabilities & IFCAP_RXCSUM) {
2013 sc->sc_rfe_ctl |= ETH_RFE_CTL_IGMP_COE_ | ETH_RFE_CTL_ICMP_COE_;
2014 sc->sc_rfe_ctl |= ETH_RFE_CTL_TCPUDP_COE_ | ETH_RFE_CTL_IP_COE_;
2017 ~(ETH_RFE_CTL_IGMP_COE_ | ETH_RFE_CTL_ICMP_COE_);
2019 ~(ETH_RFE_CTL_TCPUDP_COE_ | ETH_RFE_CTL_IP_COE_);
2022 sc->sc_rfe_ctl &= ~ETH_RFE_CTL_VLAN_FILTER_;
2024 err = lan78xx_write_reg(sc, ETH_RFE_CTL, sc->sc_rfe_ctl);
2027 muge_warn_printf(sc, "failed to write ETH_RFE_CTL (err=%d)\n",
2036 * muge_ifmedia_upd - Set media options
2037 * @ifp: interface pointer
2039 * Basically boilerplate code that simply calls the mii functions to set
2040 * the media options.
2043 * The device lock must be held before this function is called.
2046 * Returns 0 on success or a negative error code.
2049 muge_ifmedia_upd(struct ifnet *ifp)
2051 struct muge_softc *sc = ifp->if_softc;
2052 muge_dbg_printf(sc, "Calling muge_ifmedia_upd.\n");
2053 struct mii_data *mii = uether_getmii(&sc->sc_ue);
2054 struct mii_softc *miisc;
2057 MUGE_LOCK_ASSERT(sc, MA_OWNED);
2059 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
2061 err = mii_mediachg(mii);
2066 * muge_init - Initialises the LAN95xx chip
2067 * @ue: USB ether interface
2069 * Called when the interface is brought up (i.e. ifconfig ue0 up), this
2070 * initialise the interface and the rx/tx pipes.
2073 * Should be called with the MUGE lock held.
2076 muge_init(struct usb_ether *ue)
2078 struct muge_softc *sc = uether_getsc(ue);
2079 muge_dbg_printf(sc, "Calling muge_init.\n");
2080 struct ifnet *ifp = uether_getifp(ue);
2081 MUGE_LOCK_ASSERT(sc, MA_OWNED);
2083 if (lan78xx_setmacaddress(sc, IF_LLADDR(ifp)))
2084 muge_dbg_printf(sc, "setting MAC address failed\n");
2086 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
2089 /* Cancel pending I/O. */
2092 /* Reset the ethernet interface. */
2095 /* Load the multicast filter. */
2098 /* TCP/UDP checksum offload engines. */
2101 usbd_xfer_set_stall(sc->sc_xfer[MUGE_BULK_DT_WR]);
2103 /* Indicate we are up and running. */
2104 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2106 /* Switch to selected media. */
2107 muge_ifmedia_upd(ifp);
2112 * muge_stop - Stops communication with the LAN78xx chip
2113 * @ue: USB ether interface
2116 muge_stop(struct usb_ether *ue)
2118 struct muge_softc *sc = uether_getsc(ue);
2119 struct ifnet *ifp = uether_getifp(ue);
2121 MUGE_LOCK_ASSERT(sc, MA_OWNED);
2123 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
2124 sc->sc_flags &= ~MUGE_FLAG_LINK;
2127 * Stop all the transfers, if not already stopped.
2129 usbd_transfer_stop(sc->sc_xfer[MUGE_BULK_DT_WR]);
2130 usbd_transfer_stop(sc->sc_xfer[MUGE_BULK_DT_RD]);
2134 * muge_tick - Called periodically to monitor the state of the LAN95xx chip
2135 * @ue: USB ether interface
2137 * Simply calls the mii status functions to check the state of the link.
2140 * Should be called with the MUGE lock held.
2143 muge_tick(struct usb_ether *ue)
2146 struct muge_softc *sc = uether_getsc(ue);
2147 struct mii_data *mii = uether_getmii(&sc->sc_ue);
2149 MUGE_LOCK_ASSERT(sc, MA_OWNED);
2152 if ((sc->sc_flags & MUGE_FLAG_LINK) == 0) {
2153 lan78xx_miibus_statchg(ue->ue_dev);
2154 if ((sc->sc_flags & MUGE_FLAG_LINK) != 0)
2160 * muge_ifmedia_sts - Report current media status
2161 * @ifp: inet interface pointer
2162 * @ifmr: interface media request
2164 * Call the mii functions to get the media status.
2167 * Internally takes and releases the device lock.
2170 muge_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
2172 struct muge_softc *sc = ifp->if_softc;
2173 struct mii_data *mii = uether_getmii(&sc->sc_ue);
2177 ifmr->ifm_active = mii->mii_media_active;
2178 ifmr->ifm_status = mii->mii_media_status;
2183 * muge_probe - Probe the interface.
2184 * @dev: muge device handle
2186 * Checks if the device is a match for this driver.
2189 * Returns 0 on success or an error code on failure.
2192 muge_probe(device_t dev)
2194 struct usb_attach_arg *uaa = device_get_ivars(dev);
2196 if (uaa->usb_mode != USB_MODE_HOST)
2198 if (uaa->info.bConfigIndex != MUGE_CONFIG_INDEX)
2200 if (uaa->info.bIfaceIndex != MUGE_IFACE_IDX)
2202 return (usbd_lookup_id_by_uaa(lan78xx_devs, sizeof(lan78xx_devs), uaa));
2206 * muge_attach - Attach the interface.
2207 * @dev: muge device handle
2209 * Allocate softc structures, do ifmedia setup and ethernet/BPF attach.
2212 * Returns 0 on success or a negative error code.
2215 muge_attach(device_t dev)
2217 struct usb_attach_arg *uaa = device_get_ivars(dev);
2218 struct muge_softc *sc = device_get_softc(dev);
2219 struct usb_ether *ue = &sc->sc_ue;
2220 uint8_t iface_index;
2223 sc->sc_flags = USB_GET_DRIVER_INFO(uaa);
2225 device_set_usb_desc(dev);
2227 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
2229 /* Setup the endpoints for the Microchip LAN78xx device. */
2230 iface_index = MUGE_IFACE_IDX;
2231 err = usbd_transfer_setup(uaa->device, &iface_index, sc->sc_xfer,
2232 muge_config, MUGE_N_TRANSFER, sc, &sc->sc_mtx);
2234 device_printf(dev, "error: allocating USB transfers failed\n");
2240 ue->ue_udev = uaa->device;
2241 ue->ue_mtx = &sc->sc_mtx;
2242 ue->ue_methods = &muge_ue_methods;
2244 err = uether_ifattach(ue);
2246 device_printf(dev, "error: could not attach interface\n");
2250 /* Wait for lan78xx_chip_init from post-attach callback to complete. */
2251 uether_ifattach_wait(ue);
2252 if (!(sc->sc_flags & MUGE_FLAG_INIT_DONE))
2258 uether_ifdetach(ue);
2260 usbd_transfer_unsetup(sc->sc_xfer, MUGE_N_TRANSFER);
2262 mtx_destroy(&sc->sc_mtx);
2267 * muge_detach - Detach the interface.
2268 * @dev: muge device handle
2274 muge_detach(device_t dev)
2277 struct muge_softc *sc = device_get_softc(dev);
2278 struct usb_ether *ue = &sc->sc_ue;
2280 usbd_transfer_unsetup(sc->sc_xfer, MUGE_N_TRANSFER);
2281 uether_ifdetach(ue);
2282 mtx_destroy(&sc->sc_mtx);
2287 static device_method_t muge_methods[] = {
2288 /* Device interface */
2289 DEVMETHOD(device_probe, muge_probe),
2290 DEVMETHOD(device_attach, muge_attach),
2291 DEVMETHOD(device_detach, muge_detach),
2294 DEVMETHOD(bus_print_child, bus_generic_print_child),
2295 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
2298 DEVMETHOD(miibus_readreg, lan78xx_miibus_readreg),
2299 DEVMETHOD(miibus_writereg, lan78xx_miibus_writereg),
2300 DEVMETHOD(miibus_statchg, lan78xx_miibus_statchg),
2305 static driver_t muge_driver = {
2307 .methods = muge_methods,
2308 .size = sizeof(struct muge_softc),
2311 static devclass_t muge_devclass;
2313 DRIVER_MODULE(muge, uhub, muge_driver, muge_devclass, NULL, 0);
2314 DRIVER_MODULE(miibus, muge, miibus_driver, miibus_devclass, 0, 0);
2315 MODULE_DEPEND(muge, uether, 1, 1, 1);
2316 MODULE_DEPEND(muge, usb, 1, 1, 1);
2317 MODULE_DEPEND(muge, ether, 1, 1, 1);
2318 MODULE_DEPEND(muge, miibus, 1, 1, 1);
2319 MODULE_VERSION(muge, 1);
2320 USB_PNP_HOST_INFO(lan78xx_devs);