Lines Matching +full:always +full:- +full:turbo

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
31 * Microchip LAN9xxx devices (https://www.microchip.com/en-us/product/lan9500a)
33 * The LAN9500 & LAN9500A devices are stand-alone USB to Ethernet chips that
47 * ---------------------------------
52 * the Ethernet frame, this means if the frame is padded with non-zero values
167 device_printf((sc)->sc_ue.ue_dev, "debug: " fmt, ##args); \
174 device_printf((sc)->sc_ue.ue_dev, "warning: " fmt, ##args)
177 device_printf((sc)->sc_ue.ue_dev, "error: " fmt, ##args)
252 * smsc_read_reg - Reads a 32-bit register on the device
278 err = uether_do_request(&sc->sc_ue, &req, &buf, 1000); in smsc_read_reg()
288 * smsc_write_reg - Writes a 32-bit register on the device
291 * @data: the 32-bit value to write into the register
316 err = uether_do_request(&sc->sc_ue, &req, &buf, 1000); in smsc_write_reg()
324 * smsc_wait_for_bits - Polls on a register value until bits are cleared
352 uether_pause(&sc->sc_ue, hz / 100); in smsc_wait_for_bits()
353 } while (((usb_ticks_t)(ticks - start_ticks)) < max_ticks); in smsc_wait_for_bits()
359 * smsc_eeprom_read - Reads the attached EEPROM
383 locked = mtx_owned(&sc->sc_mtx); in smsc_eeprom_read()
406 uether_pause(&sc->sc_ue, hz / 100); in smsc_eeprom_read()
407 } while (((usb_ticks_t)(ticks - start_ticks)) < max_ticks); in smsc_eeprom_read()
429 * smsc_miibus_readreg - Reads a MII/MDIO register
440 * Returns the 16-bits read from the MII register, if this function fails 0
451 locked = mtx_owned(&sc->sc_mtx); in smsc_miibus_readreg()
477 * smsc_miibus_writereg - Writes a MII/MDIO register
489 * Always returns 0 regardless of success or failure.
498 if (sc->sc_phyno != phy) in smsc_miibus_writereg()
501 locked = mtx_owned(&sc->sc_mtx); in smsc_miibus_writereg()
526 * smsc_miibus_statchg - Called to detect phy status change
539 struct mii_data *mii = uether_getmii(&sc->sc_ue); in smsc_miibus_statchg()
546 locked = mtx_owned(&sc->sc_mtx); in smsc_miibus_statchg()
550 ifp = uether_getifp(&sc->sc_ue); in smsc_miibus_statchg()
556 sc->sc_flags &= ~SMSC_FLAG_LINK; in smsc_miibus_statchg()
557 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == in smsc_miibus_statchg()
559 switch (IFM_SUBTYPE(mii->mii_media_active)) { in smsc_miibus_statchg()
562 sc->sc_flags |= SMSC_FLAG_LINK; in smsc_miibus_statchg()
573 if ((sc->sc_flags & SMSC_FLAG_LINK) == 0) { in smsc_miibus_statchg()
585 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) { in smsc_miibus_statchg()
587 sc->sc_mac_csr &= ~SMSC_MAC_CSR_RCVOWN; in smsc_miibus_statchg()
588 sc->sc_mac_csr |= SMSC_MAC_CSR_FDPX; in smsc_miibus_statchg()
590 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_RXPAUSE) != 0) in smsc_miibus_statchg()
595 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_TXPAUSE) != 0) in smsc_miibus_statchg()
602 sc->sc_mac_csr &= ~SMSC_MAC_CSR_FDPX; in smsc_miibus_statchg()
603 sc->sc_mac_csr |= SMSC_MAC_CSR_RCVOWN; in smsc_miibus_statchg()
609 err = smsc_write_reg(sc, SMSC_MAC_CSR, sc->sc_mac_csr); in smsc_miibus_statchg()
621 * smsc_ifmedia_upd - Set media options
637 struct mii_data *mii = uether_getmii(&sc->sc_ue); in smsc_ifmedia_upd()
643 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) in smsc_ifmedia_upd()
650 * smsc_ifmedia_sts - Report current media status
664 struct mii_data *mii = uether_getmii(&sc->sc_ue); in smsc_ifmedia_sts()
668 ifmr->ifm_active = mii->mii_media_active; in smsc_ifmedia_sts()
669 ifmr->ifm_status = mii->mii_media_status; in smsc_ifmedia_sts()
674 * smsc_hash - Calculate the hash of a mac address
682 * Returns a value from 0-63 value which is the hash of the mac address.
702 * smsc_setmulti - Setup multicast
722 sc->sc_mac_csr |= SMSC_MAC_CSR_MCPAS; in smsc_setmulti()
723 sc->sc_mac_csr &= ~SMSC_MAC_CSR_HPFILT; in smsc_setmulti()
731 sc->sc_mac_csr |= SMSC_MAC_CSR_HPFILT; in smsc_setmulti()
732 sc->sc_mac_csr &= ~(SMSC_MAC_CSR_PRMS | SMSC_MAC_CSR_MCPAS); in smsc_setmulti()
737 sc->sc_mac_csr &= ~(SMSC_MAC_CSR_MCPAS | SMSC_MAC_CSR_HPFILT); in smsc_setmulti()
741 if (sc->sc_mac_csr & SMSC_MAC_CSR_HPFILT) in smsc_setmulti()
750 smsc_write_reg(sc, SMSC_MAC_CSR, sc->sc_mac_csr); in smsc_setmulti()
754 * smsc_setpromisc - Enables/disables promiscuous mode
772 sc->sc_mac_csr |= SMSC_MAC_CSR_PRMS; in smsc_setpromisc()
774 sc->sc_mac_csr &= ~SMSC_MAC_CSR_PRMS; in smsc_setpromisc()
776 smsc_write_reg(sc, SMSC_MAC_CSR, sc->sc_mac_csr); in smsc_setpromisc()
780 * smsc_sethwcsum - Enable or disable H/W UDP and TCP checksumming
791 if_t ifp = uether_getifp(&sc->sc_ue); in smsc_sethwcsum()
796 return (-EIO); in smsc_sethwcsum()
828 * smsc_setmacaddress - Sets the mac address in the device
864 * smsc_reset - Reset the SMSC chip
876 cd = usbd_get_config_descriptor(sc->sc_ue.ue_udev); in smsc_reset()
878 err = usbd_req_set_config(sc->sc_ue.ue_udev, &sc->sc_mtx, in smsc_reset()
879 cd->bConfigurationValue); in smsc_reset()
884 uether_pause(&sc->sc_ue, hz / 100); in smsc_reset()
891 * smsc_init - Initialises the LAN95xx chip
926 usbd_xfer_set_stall(sc->sc_xfer[SMSC_BULK_DT_WR]); in smsc_init()
937 * smsc_bulk_read_callback - Read callback used to process the USB URB
951 struct usb_ether *ue = &sc->sc_ue; in smsc_bulk_read_callback()
966 /* There is always a zero length frame after bringing the IF up */ in smsc_bulk_read_callback()
979 /* The frame header is always aligned on a 4 byte boundary */ in smsc_bulk_read_callback()
1002 if ((pktlen < ETHER_HDR_LEN) || (pktlen > (actlen - off))) in smsc_bulk_read_callback()
1012 if (pktlen > m->m_len) { in smsc_bulk_read_callback()
1014 pktlen, m->m_len); in smsc_bulk_read_callback()
1028 pktlen -= 2; in smsc_bulk_read_callback()
1038 * Ignore H/W csum for non-IPv4 packets. in smsc_bulk_read_callback()
1040 if ((be16toh(eh->ether_type) == ETHERTYPE_IP) && in smsc_bulk_read_callback()
1045 if ((ip->ip_v == IPVERSION) && in smsc_bulk_read_callback()
1046 ((ip->ip_p == IPPROTO_TCP) || in smsc_bulk_read_callback()
1047 (ip->ip_p == IPPROTO_UDP))) { in smsc_bulk_read_callback()
1049 m->m_pkthdr.csum_flags |= CSUM_DATA_VALID; in smsc_bulk_read_callback()
1055 &m->m_pkthdr.csum_data, 2); in smsc_bulk_read_callback()
1061 m->m_pkthdr.csum_data = ntohs(m->m_pkthdr.csum_data); in smsc_bulk_read_callback()
1064 m->m_pkthdr.csum_data); in smsc_bulk_read_callback()
1081 uether_rxmbuf(ue, m, pktlen - 4); in smsc_bulk_read_callback()
1108 * smsc_bulk_write_callback - Write callback used to send ethernet frame(s)
1122 if_t ifp = uether_getifp(&sc->sc_ue); in smsc_bulk_write_callback()
1136 if ((sc->sc_flags & SMSC_FLAG_LINK) == 0 || in smsc_bulk_write_callback()
1152 /* Each frame is prefixed with two 32-bit values describing the in smsc_bulk_write_callback()
1155 txhdr = SMSC_TX_CTRL_0_BUF_SIZE(m->m_pkthdr.len) | in smsc_bulk_write_callback()
1160 txhdr = SMSC_TX_CTRL_1_PKT_LENGTH(m->m_pkthdr.len); in smsc_bulk_write_callback()
1167 usbd_m_copy_in(pc, frm_len, m, 0, m->m_pkthdr.len); in smsc_bulk_write_callback()
1168 frm_len += m->m_pkthdr.len; in smsc_bulk_write_callback()
1201 * smsc_tick - Called periodically to monitor the state of the LAN95xx chip
1213 struct mii_data *mii = uether_getmii(&sc->sc_ue); in smsc_tick()
1218 if ((sc->sc_flags & SMSC_FLAG_LINK) == 0) { in smsc_tick()
1219 smsc_miibus_statchg(ue->ue_dev); in smsc_tick()
1220 if ((sc->sc_flags & SMSC_FLAG_LINK) != 0) in smsc_tick()
1226 * smsc_start - Starts communication with the LAN95xx chip
1240 usbd_transfer_start(sc->sc_xfer[SMSC_BULK_DT_RD]); in smsc_start()
1241 usbd_transfer_start(sc->sc_xfer[SMSC_BULK_DT_WR]); in smsc_start()
1245 * smsc_stop - Stops communication with the LAN95xx chip
1260 sc->sc_flags &= ~SMSC_FLAG_LINK; in smsc_stop()
1265 usbd_transfer_stop(sc->sc_xfer[SMSC_BULK_DT_WR]); in smsc_stop()
1266 usbd_transfer_stop(sc->sc_xfer[SMSC_BULK_DT_RD]); in smsc_stop()
1270 * smsc_phy_init - Initialises the in-built SMSC phy
1274 * values. The 'link down' and 'auto-negotiation complete' interrupts
1291 smsc_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR, BMCR_RESET); in smsc_phy_init()
1295 uether_pause(&sc->sc_ue, hz / 100); in smsc_phy_init()
1296 bmcr = smsc_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR); in smsc_phy_init()
1297 } while ((bmcr & BMCR_RESET) && ((ticks - start_ticks) < max_ticks)); in smsc_phy_init()
1299 if (((usb_ticks_t)(ticks - start_ticks)) >= max_ticks) { in smsc_phy_init()
1300 smsc_err_printf(sc, "PHY reset timed-out"); in smsc_phy_init()
1304 smsc_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_ANAR, in smsc_phy_init()
1311 smsc_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, SMSC_PHY_INTR_STAT); in smsc_phy_init()
1312 smsc_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, SMSC_PHY_INTR_MASK, in smsc_phy_init()
1315 /* Restart auto-negotiation */ in smsc_phy_init()
1316 bmcr = smsc_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR); in smsc_phy_init()
1318 smsc_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR, bmcr); in smsc_phy_init()
1324 * smsc_chip_init - Initialises the chip after power on
1341 locked = mtx_owned(&sc->sc_mtx); in smsc_chip_init()
1349 smsc_warn_printf(sc, "timed-out waiting for reset to complete\n"); in smsc_chip_init()
1357 smsc_warn_printf(sc, "timed-out waiting for phy reset to complete\n"); in smsc_chip_init()
1362 if ((err = smsc_setmacaddress(sc, sc->sc_ue.ue_eaddr)) != 0) { in smsc_chip_init()
1377 /* There is a so called 'turbo mode' that the linux driver supports, it in smsc_chip_init()
1390 else if (usbd_get_speed(sc->sc_ue.ue_udev) == USB_SPEED_HIGH) in smsc_chip_init()
1414 /* The following settings are used for 'turbo mode', a.k.a multiple frames in smsc_chip_init()
1426 if ((err = smsc_read_reg(sc, SMSC_ID_REV, &sc->sc_rev_id)) < 0) { in smsc_chip_init()
1431 device_printf(sc->sc_ue.ue_dev, "chip 0x%04lx, rev. %04lx\n", in smsc_chip_init()
1432 (sc->sc_rev_id & SMSC_ID_REV_CHIP_ID_MASK) >> 16, in smsc_chip_init()
1433 (sc->sc_rev_id & SMSC_ID_REV_CHIP_REV_MASK)); in smsc_chip_init()
1448 if ((err = smsc_read_reg(sc, SMSC_MAC_CSR, &sc->sc_mac_csr)) < 0) { in smsc_chip_init()
1465 sc->sc_mac_csr |= SMSC_MAC_CSR_TXEN; in smsc_chip_init()
1466 smsc_write_reg(sc, SMSC_MAC_CSR, sc->sc_mac_csr); in smsc_chip_init()
1472 sc->sc_mac_csr |= SMSC_MAC_CSR_RXEN; in smsc_chip_init()
1473 smsc_write_reg(sc, SMSC_MAC_CSR, sc->sc_mac_csr); in smsc_chip_init()
1489 * smsc_ioctl - ioctl function for the device
1519 mask = ifr->ifr_reqcap ^ if_getcapenable(ifp); in smsc_ioctl()
1558 smsc_warn_printf((struct smsc_softc *)ue->ue_sc, in smsc_get_smsc95xx_macaddr()
1564 ue->ue_eaddr[i] = values[i]; in smsc_get_smsc95xx_macaddr()
1566 smsc_dbg_printf((struct smsc_softc *)ue->ue_sc, in smsc_get_smsc95xx_macaddr()
1567 "bootargs mac=%6D.\n", ue->ue_eaddr, ":"); in smsc_get_smsc95xx_macaddr()
1587 if (node == -1) in smsc_bootargs_get_mac_addr()
1590 smsc_dbg_printf((struct smsc_softc *)ue->ue_sc, in smsc_bootargs_get_mac_addr()
1595 if (len == -1 || bootargs == NULL) { in smsc_bootargs_get_mac_addr()
1596 smsc_warn_printf((struct smsc_softc *)ue->ue_sc, in smsc_bootargs_get_mac_addr()
1600 smsc_dbg_printf((struct smsc_softc *)ue->ue_sc, "bootargs: %s.\n", in smsc_bootargs_get_mac_addr()
1608 ue->ue_eaddr, ":"); in smsc_bootargs_get_mac_addr()
1614 * smsc_attach_post - Called after the driver attached to the USB interface
1635 sc->sc_phyno = 1; in smsc_attach_post()
1641 memset(sc->sc_ue.ue_eaddr, 0xff, ETHER_ADDR_LEN); in smsc_attach_post()
1646 sc->sc_ue.ue_eaddr[5] = (uint8_t)((mac_h >> 8) & 0xff); in smsc_attach_post()
1647 sc->sc_ue.ue_eaddr[4] = (uint8_t)((mac_h) & 0xff); in smsc_attach_post()
1648 sc->sc_ue.ue_eaddr[3] = (uint8_t)((mac_l >> 24) & 0xff); in smsc_attach_post()
1649 sc->sc_ue.ue_eaddr[2] = (uint8_t)((mac_l >> 16) & 0xff); in smsc_attach_post()
1650 sc->sc_ue.ue_eaddr[1] = (uint8_t)((mac_l >> 8) & 0xff); in smsc_attach_post()
1651 sc->sc_ue.ue_eaddr[0] = (uint8_t)((mac_l) & 0xff); in smsc_attach_post()
1657 if (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr)) { in smsc_attach_post()
1658 err = smsc_eeprom_read(sc, 0x01, sc->sc_ue.ue_eaddr, ETHER_ADDR_LEN); in smsc_attach_post()
1660 if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) in smsc_attach_post()
1661 err = usb_fdt_get_mac_addr(sc->sc_ue.ue_dev, &sc->sc_ue); in smsc_attach_post()
1662 if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) in smsc_attach_post()
1663 err = smsc_bootargs_get_mac_addr(sc->sc_ue.ue_dev, in smsc_attach_post()
1664 &sc->sc_ue) ? (0) : (1); in smsc_attach_post()
1666 if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) { in smsc_attach_post()
1669 ether_gen_addr_byname(device_get_nameunit(ue->ue_dev), in smsc_attach_post()
1672 sc->sc_ue.ue_eaddr[i] = eaddr.octet[i]; in smsc_attach_post()
1681 * smsc_attach_post_sub - Called after the driver attached to the USB interface
1699 ifp = ue->ue_ifp; in smsc_attach_post_sub()
1722 error = mii_attach(ue->ue_dev, &ue->ue_miibus, ifp, in smsc_attach_post_sub()
1723 uether_ifmedia_upd, ue->ue_methods->ue_mii_sts, in smsc_attach_post_sub()
1724 BMSR_DEFCAPMASK, sc->sc_phyno, MII_OFFSET_ANY, 0); in smsc_attach_post_sub()
1731 * smsc_probe - Probe the interface.
1744 if (uaa->usb_mode != USB_MODE_HOST) in smsc_probe()
1746 if (uaa->info.bConfigIndex != SMSC_CONFIG_INDEX) in smsc_probe()
1748 if (uaa->info.bIfaceIndex != SMSC_IFACE_IDX) in smsc_probe()
1755 * smsc_attach - Attach the interface.
1768 struct usb_ether *ue = &sc->sc_ue; in smsc_attach()
1772 sc->sc_flags = USB_GET_DRIVER_INFO(uaa); in smsc_attach()
1776 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); in smsc_attach()
1780 err = usbd_transfer_setup(uaa->device, &iface_index, sc->sc_xfer, in smsc_attach()
1781 smsc_config, SMSC_N_TRANSFER, sc, &sc->sc_mtx); in smsc_attach()
1787 ue->ue_sc = sc; in smsc_attach()
1788 ue->ue_dev = dev; in smsc_attach()
1789 ue->ue_udev = uaa->device; in smsc_attach()
1790 ue->ue_mtx = &sc->sc_mtx; in smsc_attach()
1791 ue->ue_methods = &smsc_ue_methods; in smsc_attach()
1806 * smsc_detach - Detach the interface.
1816 struct usb_ether *ue = &sc->sc_ue; in smsc_detach()
1818 usbd_transfer_unsetup(sc->sc_xfer, SMSC_N_TRANSFER); in smsc_detach()
1820 mtx_destroy(&sc->sc_mtx); in smsc_detach()