Lines Matching +full:rev +full:- +full:mii
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
30 * Microchip LAN9xxx devices (https://www.microchip.com/en-us/product/lan9500a)
32 * The LAN9500 & LAN9500A devices are stand-alone USB to Ethernet chips that
46 * ---------------------------------
51 * the Ethernet frame, this means if the frame is padded with non-zero values
89 #include <dev/mii/mii.h>
90 #include <dev/mii/miivar.h>
166 device_printf((sc)->sc_ue.ue_dev, "debug: " fmt, ##args); \
173 device_printf((sc)->sc_ue.ue_dev, "warning: " fmt, ##args)
176 device_printf((sc)->sc_ue.ue_dev, "error: " fmt, ##args)
232 * needed as we poll on the MII status.
251 * smsc_read_reg - Reads a 32-bit register on the device
277 err = uether_do_request(&sc->sc_ue, &req, &buf, 1000); in smsc_read_reg()
287 * smsc_write_reg - Writes a 32-bit register on the device
290 * @data: the 32-bit value to write into the register
315 err = uether_do_request(&sc->sc_ue, &req, &buf, 1000); in smsc_write_reg()
323 * smsc_wait_for_bits - Polls on a register value until bits are cleared
351 uether_pause(&sc->sc_ue, hz / 100); in smsc_wait_for_bits()
352 } while (((usb_ticks_t)(ticks - start_ticks)) < max_ticks); in smsc_wait_for_bits()
358 * smsc_eeprom_read - Reads the attached EEPROM
382 locked = mtx_owned(&sc->sc_mtx); in smsc_eeprom_read()
405 uether_pause(&sc->sc_ue, hz / 100); in smsc_eeprom_read()
406 } while (((usb_ticks_t)(ticks - start_ticks)) < max_ticks); in smsc_eeprom_read()
428 * smsc_miibus_readreg - Reads a MII/MDIO register
433 * Attempts to read a phy register over the MII bus.
439 * Returns the 16-bits read from the MII register, if this function fails 0
450 locked = mtx_owned(&sc->sc_mtx); in smsc_miibus_readreg()
455 smsc_warn_printf(sc, "MII is busy\n"); in smsc_miibus_readreg()
463 smsc_warn_printf(sc, "MII read timeout\n"); in smsc_miibus_readreg()
476 * smsc_miibus_writereg - Writes a MII/MDIO register
482 * Attempts to write a phy register over the MII bus.
497 if (sc->sc_phyno != phy) in smsc_miibus_writereg()
500 locked = mtx_owned(&sc->sc_mtx); in smsc_miibus_writereg()
505 smsc_warn_printf(sc, "MII is busy\n"); in smsc_miibus_writereg()
516 smsc_warn_printf(sc, "MII write timeout\n"); in smsc_miibus_writereg()
525 * smsc_miibus_statchg - Called to detect phy status change
538 struct mii_data *mii = uether_getmii(&sc->sc_ue); in smsc_miibus_statchg() local
545 locked = mtx_owned(&sc->sc_mtx); in smsc_miibus_statchg()
549 ifp = uether_getifp(&sc->sc_ue); in smsc_miibus_statchg()
550 if (mii == NULL || ifp == NULL || in smsc_miibus_statchg()
554 /* Use the MII status to determine link status */ in smsc_miibus_statchg()
555 sc->sc_flags &= ~SMSC_FLAG_LINK; in smsc_miibus_statchg()
556 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == in smsc_miibus_statchg()
558 switch (IFM_SUBTYPE(mii->mii_media_active)) { in smsc_miibus_statchg()
561 sc->sc_flags |= SMSC_FLAG_LINK; in smsc_miibus_statchg()
572 if ((sc->sc_flags & SMSC_FLAG_LINK) == 0) { in smsc_miibus_statchg()
584 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) { in smsc_miibus_statchg()
586 sc->sc_mac_csr &= ~SMSC_MAC_CSR_RCVOWN; in smsc_miibus_statchg()
587 sc->sc_mac_csr |= SMSC_MAC_CSR_FDPX; in smsc_miibus_statchg()
589 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_RXPAUSE) != 0) in smsc_miibus_statchg()
594 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_TXPAUSE) != 0) in smsc_miibus_statchg()
601 sc->sc_mac_csr &= ~SMSC_MAC_CSR_FDPX; in smsc_miibus_statchg()
602 sc->sc_mac_csr |= SMSC_MAC_CSR_RCVOWN; in smsc_miibus_statchg()
608 err = smsc_write_reg(sc, SMSC_MAC_CSR, sc->sc_mac_csr); in smsc_miibus_statchg()
620 * smsc_ifmedia_upd - Set media options
623 * Basically boilerplate code that simply calls the mii functions to set the
636 struct mii_data *mii = uether_getmii(&sc->sc_ue); in smsc_ifmedia_upd() local
642 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) in smsc_ifmedia_upd()
644 err = mii_mediachg(mii); in smsc_ifmedia_upd()
649 * smsc_ifmedia_sts - Report current media status
653 * Basically boilerplate code that simply calls the mii functions to get the
663 struct mii_data *mii = uether_getmii(&sc->sc_ue); in smsc_ifmedia_sts() local
666 mii_pollstat(mii); in smsc_ifmedia_sts()
667 ifmr->ifm_active = mii->mii_media_active; in smsc_ifmedia_sts()
668 ifmr->ifm_status = mii->mii_media_status; in smsc_ifmedia_sts()
673 * smsc_hash - Calculate the hash of a mac address
681 * Returns a value from 0-63 value which is the hash of the mac address.
701 * smsc_setmulti - Setup multicast
721 sc->sc_mac_csr |= SMSC_MAC_CSR_MCPAS; in smsc_setmulti()
722 sc->sc_mac_csr &= ~SMSC_MAC_CSR_HPFILT; in smsc_setmulti()
730 sc->sc_mac_csr |= SMSC_MAC_CSR_HPFILT; in smsc_setmulti()
731 sc->sc_mac_csr &= ~(SMSC_MAC_CSR_PRMS | SMSC_MAC_CSR_MCPAS); in smsc_setmulti()
736 sc->sc_mac_csr &= ~(SMSC_MAC_CSR_MCPAS | SMSC_MAC_CSR_HPFILT); in smsc_setmulti()
740 if (sc->sc_mac_csr & SMSC_MAC_CSR_HPFILT) in smsc_setmulti()
749 smsc_write_reg(sc, SMSC_MAC_CSR, sc->sc_mac_csr); in smsc_setmulti()
753 * smsc_setpromisc - Enables/disables promiscuous mode
771 sc->sc_mac_csr |= SMSC_MAC_CSR_PRMS; in smsc_setpromisc()
773 sc->sc_mac_csr &= ~SMSC_MAC_CSR_PRMS; in smsc_setpromisc()
775 smsc_write_reg(sc, SMSC_MAC_CSR, sc->sc_mac_csr); in smsc_setpromisc()
779 * smsc_sethwcsum - Enable or disable H/W UDP and TCP checksumming
790 if_t ifp = uether_getifp(&sc->sc_ue); in smsc_sethwcsum()
795 return (-EIO); in smsc_sethwcsum()
827 * smsc_setmacaddress - Sets the mac address in the device
863 * smsc_reset - Reset the SMSC chip
875 cd = usbd_get_config_descriptor(sc->sc_ue.ue_udev); in smsc_reset()
877 err = usbd_req_set_config(sc->sc_ue.ue_udev, &sc->sc_mtx, in smsc_reset()
878 cd->bConfigurationValue); in smsc_reset()
883 uether_pause(&sc->sc_ue, hz / 100); in smsc_reset()
890 * smsc_init - Initialises the LAN95xx chip
925 usbd_xfer_set_stall(sc->sc_xfer[SMSC_BULK_DT_WR]); in smsc_init()
936 * smsc_bulk_read_callback - Read callback used to process the USB URB
950 struct usb_ether *ue = &sc->sc_ue; in smsc_bulk_read_callback()
1001 if ((pktlen < ETHER_HDR_LEN) || (pktlen > (actlen - off))) in smsc_bulk_read_callback()
1011 if (pktlen > m->m_len) { in smsc_bulk_read_callback()
1013 pktlen, m->m_len); in smsc_bulk_read_callback()
1027 pktlen -= 2; in smsc_bulk_read_callback()
1037 * Ignore H/W csum for non-IPv4 packets. in smsc_bulk_read_callback()
1039 if ((be16toh(eh->ether_type) == ETHERTYPE_IP) && in smsc_bulk_read_callback()
1044 if ((ip->ip_v == IPVERSION) && in smsc_bulk_read_callback()
1045 ((ip->ip_p == IPPROTO_TCP) || in smsc_bulk_read_callback()
1046 (ip->ip_p == IPPROTO_UDP))) { in smsc_bulk_read_callback()
1048 m->m_pkthdr.csum_flags |= CSUM_DATA_VALID; in smsc_bulk_read_callback()
1054 &m->m_pkthdr.csum_data, 2); in smsc_bulk_read_callback()
1060 m->m_pkthdr.csum_data = ntohs(m->m_pkthdr.csum_data); in smsc_bulk_read_callback()
1063 m->m_pkthdr.csum_data); in smsc_bulk_read_callback()
1080 uether_rxmbuf(ue, m, pktlen - 4); in smsc_bulk_read_callback()
1107 * smsc_bulk_write_callback - Write callback used to send ethernet frame(s)
1121 if_t ifp = uether_getifp(&sc->sc_ue); in smsc_bulk_write_callback()
1135 if ((sc->sc_flags & SMSC_FLAG_LINK) == 0 || in smsc_bulk_write_callback()
1151 /* Each frame is prefixed with two 32-bit values describing the in smsc_bulk_write_callback()
1154 txhdr = SMSC_TX_CTRL_0_BUF_SIZE(m->m_pkthdr.len) | in smsc_bulk_write_callback()
1159 txhdr = SMSC_TX_CTRL_1_PKT_LENGTH(m->m_pkthdr.len); in smsc_bulk_write_callback()
1166 usbd_m_copy_in(pc, frm_len, m, 0, m->m_pkthdr.len); in smsc_bulk_write_callback()
1167 frm_len += m->m_pkthdr.len; in smsc_bulk_write_callback()
1200 * smsc_tick - Called periodically to monitor the state of the LAN95xx chip
1203 * Simply calls the mii status functions to check the state of the link.
1212 struct mii_data *mii = uether_getmii(&sc->sc_ue); in smsc_tick() local
1216 mii_tick(mii); in smsc_tick()
1217 if ((sc->sc_flags & SMSC_FLAG_LINK) == 0) { in smsc_tick()
1218 smsc_miibus_statchg(ue->ue_dev); in smsc_tick()
1219 if ((sc->sc_flags & SMSC_FLAG_LINK) != 0) in smsc_tick()
1225 * smsc_start - Starts communication with the LAN95xx chip
1239 usbd_transfer_start(sc->sc_xfer[SMSC_BULK_DT_RD]); in smsc_start()
1240 usbd_transfer_start(sc->sc_xfer[SMSC_BULK_DT_WR]); in smsc_start()
1244 * smsc_stop - Stops communication with the LAN95xx chip
1259 sc->sc_flags &= ~SMSC_FLAG_LINK; in smsc_stop()
1264 usbd_transfer_stop(sc->sc_xfer[SMSC_BULK_DT_WR]); in smsc_stop()
1265 usbd_transfer_stop(sc->sc_xfer[SMSC_BULK_DT_RD]); in smsc_stop()
1269 * smsc_phy_init - Initialises the in-built SMSC phy
1273 * values. The 'link down' and 'auto-negotiation complete' interrupts
1290 smsc_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR, BMCR_RESET); in smsc_phy_init()
1294 uether_pause(&sc->sc_ue, hz / 100); in smsc_phy_init()
1295 bmcr = smsc_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR); in smsc_phy_init()
1296 } while ((bmcr & BMCR_RESET) && ((ticks - start_ticks) < max_ticks)); in smsc_phy_init()
1298 if (((usb_ticks_t)(ticks - start_ticks)) >= max_ticks) { in smsc_phy_init()
1299 smsc_err_printf(sc, "PHY reset timed-out"); in smsc_phy_init()
1303 smsc_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_ANAR, in smsc_phy_init()
1310 smsc_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, SMSC_PHY_INTR_STAT); in smsc_phy_init()
1311 smsc_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, SMSC_PHY_INTR_MASK, in smsc_phy_init()
1314 /* Restart auto-negotiation */ in smsc_phy_init()
1315 bmcr = smsc_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR); in smsc_phy_init()
1317 smsc_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR, bmcr); in smsc_phy_init()
1323 * smsc_chip_init - Initialises the chip after power on
1340 locked = mtx_owned(&sc->sc_mtx); in smsc_chip_init()
1348 smsc_warn_printf(sc, "timed-out waiting for reset to complete\n"); in smsc_chip_init()
1356 smsc_warn_printf(sc, "timed-out waiting for phy reset to complete\n"); in smsc_chip_init()
1361 if ((err = smsc_setmacaddress(sc, sc->sc_ue.ue_eaddr)) != 0) { in smsc_chip_init()
1389 else if (usbd_get_speed(sc->sc_ue.ue_udev) == USB_SPEED_HIGH) in smsc_chip_init()
1425 if ((err = smsc_read_reg(sc, SMSC_ID_REV, &sc->sc_rev_id)) < 0) { in smsc_chip_init()
1430 device_printf(sc->sc_ue.ue_dev, "chip 0x%04lx, rev. %04lx\n", in smsc_chip_init()
1431 (sc->sc_rev_id & SMSC_ID_REV_CHIP_ID_MASK) >> 16, in smsc_chip_init()
1432 (sc->sc_rev_id & SMSC_ID_REV_CHIP_REV_MASK)); in smsc_chip_init()
1447 if ((err = smsc_read_reg(sc, SMSC_MAC_CSR, &sc->sc_mac_csr)) < 0) { in smsc_chip_init()
1464 sc->sc_mac_csr |= SMSC_MAC_CSR_TXEN; in smsc_chip_init()
1465 smsc_write_reg(sc, SMSC_MAC_CSR, sc->sc_mac_csr); in smsc_chip_init()
1471 sc->sc_mac_csr |= SMSC_MAC_CSR_RXEN; in smsc_chip_init()
1472 smsc_write_reg(sc, SMSC_MAC_CSR, sc->sc_mac_csr); in smsc_chip_init()
1488 * smsc_ioctl - ioctl function for the device
1518 mask = ifr->ifr_reqcap ^ if_getcapenable(ifp); in smsc_ioctl()
1557 smsc_warn_printf((struct smsc_softc *)ue->ue_sc, in smsc_get_smsc95xx_macaddr()
1563 ue->ue_eaddr[i] = values[i]; in smsc_get_smsc95xx_macaddr()
1565 smsc_dbg_printf((struct smsc_softc *)ue->ue_sc, in smsc_get_smsc95xx_macaddr()
1566 "bootargs mac=%6D.\n", ue->ue_eaddr, ":"); in smsc_get_smsc95xx_macaddr()
1586 if (node == -1) in smsc_bootargs_get_mac_addr()
1589 smsc_dbg_printf((struct smsc_softc *)ue->ue_sc, in smsc_bootargs_get_mac_addr()
1594 if (len == -1 || bootargs == NULL) { in smsc_bootargs_get_mac_addr()
1595 smsc_warn_printf((struct smsc_softc *)ue->ue_sc, in smsc_bootargs_get_mac_addr()
1599 smsc_dbg_printf((struct smsc_softc *)ue->ue_sc, "bootargs: %s.\n", in smsc_bootargs_get_mac_addr()
1607 ue->ue_eaddr, ":"); in smsc_bootargs_get_mac_addr()
1613 * smsc_attach_post - Called after the driver attached to the USB interface
1634 sc->sc_phyno = 1; in smsc_attach_post()
1640 memset(sc->sc_ue.ue_eaddr, 0xff, ETHER_ADDR_LEN); in smsc_attach_post()
1645 sc->sc_ue.ue_eaddr[5] = (uint8_t)((mac_h >> 8) & 0xff); in smsc_attach_post()
1646 sc->sc_ue.ue_eaddr[4] = (uint8_t)((mac_h) & 0xff); in smsc_attach_post()
1647 sc->sc_ue.ue_eaddr[3] = (uint8_t)((mac_l >> 24) & 0xff); in smsc_attach_post()
1648 sc->sc_ue.ue_eaddr[2] = (uint8_t)((mac_l >> 16) & 0xff); in smsc_attach_post()
1649 sc->sc_ue.ue_eaddr[1] = (uint8_t)((mac_l >> 8) & 0xff); in smsc_attach_post()
1650 sc->sc_ue.ue_eaddr[0] = (uint8_t)((mac_l) & 0xff); in smsc_attach_post()
1656 if (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr)) { in smsc_attach_post()
1657 err = smsc_eeprom_read(sc, 0x01, sc->sc_ue.ue_eaddr, ETHER_ADDR_LEN); in smsc_attach_post()
1659 if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) in smsc_attach_post()
1660 err = usb_fdt_get_mac_addr(sc->sc_ue.ue_dev, &sc->sc_ue); in smsc_attach_post()
1661 if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) in smsc_attach_post()
1662 err = smsc_bootargs_get_mac_addr(sc->sc_ue.ue_dev, in smsc_attach_post()
1663 &sc->sc_ue) ? (0) : (1); in smsc_attach_post()
1665 if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) { in smsc_attach_post()
1668 ether_gen_addr_byname(device_get_nameunit(ue->ue_dev), in smsc_attach_post()
1671 sc->sc_ue.ue_eaddr[i] = eaddr.octet[i]; in smsc_attach_post()
1680 * smsc_attach_post_sub - Called after the driver attached to the USB interface
1698 ifp = ue->ue_ifp; in smsc_attach_post_sub()
1721 error = mii_attach(ue->ue_dev, &ue->ue_miibus, ifp, in smsc_attach_post_sub()
1722 uether_ifmedia_upd, ue->ue_methods->ue_mii_sts, in smsc_attach_post_sub()
1723 BMSR_DEFCAPMASK, sc->sc_phyno, MII_OFFSET_ANY, 0); in smsc_attach_post_sub()
1730 * smsc_probe - Probe the interface.
1743 if (uaa->usb_mode != USB_MODE_HOST) in smsc_probe()
1745 if (uaa->info.bConfigIndex != SMSC_CONFIG_INDEX) in smsc_probe()
1747 if (uaa->info.bIfaceIndex != SMSC_IFACE_IDX) in smsc_probe()
1754 * smsc_attach - Attach the interface.
1767 struct usb_ether *ue = &sc->sc_ue; in smsc_attach()
1771 sc->sc_flags = USB_GET_DRIVER_INFO(uaa); in smsc_attach()
1775 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); in smsc_attach()
1779 err = usbd_transfer_setup(uaa->device, &iface_index, sc->sc_xfer, in smsc_attach()
1780 smsc_config, SMSC_N_TRANSFER, sc, &sc->sc_mtx); in smsc_attach()
1786 ue->ue_sc = sc; in smsc_attach()
1787 ue->ue_dev = dev; in smsc_attach()
1788 ue->ue_udev = uaa->device; in smsc_attach()
1789 ue->ue_mtx = &sc->sc_mtx; in smsc_attach()
1790 ue->ue_methods = &smsc_ue_methods; in smsc_attach()
1805 * smsc_detach - Detach the interface.
1815 struct usb_ether *ue = &sc->sc_ue; in smsc_detach()
1817 usbd_transfer_unsetup(sc->sc_xfer, SMSC_N_TRANSFER); in smsc_detach()
1819 mtx_destroy(&sc->sc_mtx); in smsc_detach()
1834 /* MII interface */