Lines Matching +full:enable +full:- +full:soft +full:- +full:reset

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
34 * USB-To-Ethernet adapter driver for Microchip's LAN78XX and related families.
42 * USB 2 to 10/100/1000 Mbps Ethernet with built-in USB hub
45 * This driver is based on the if_smsc driver, with lan78xx-specific
49 * ------------------
53 * - TX checksum offloading: Nothing has been implemented yet.
54 * - Direct address translation filtering: Implemented but untested.
55 * - VLAN tag removal.
56 * - Support for USB interrupt endpoints.
57 * - Latency Tolerance Messaging (LTM) support.
58 * - TCP LSO support.
120 "Microchip LAN78xx USB-GigE");
141 device_printf((sc)->sc_ue.ue_dev, "debug: " fmt, ##args); \
148 device_printf((sc)->sc_ue.ue_dev, "warning: " fmt, ##args)
151 device_printf((sc)->sc_ue.ue_dev, "error: " fmt, ##args)
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)
264 * lan78xx_read_reg - Read a 32-bit register on the device
265 * @sc: driver soft context
290 err = uether_do_request(&sc->sc_ue, &req, &buf, 1000);
298 * lan78xx_write_reg - Write a 32-bit register on the device
299 * @sc: driver soft context
301 * @data: the 32-bit value to write into the register
326 err = uether_do_request(&sc->sc_ue, &req, &buf, 1000);
333 * lan78xx_wait_for_bits - Poll on a register value until bits are cleared
334 * @sc: soft context
360 uether_pause(&sc->sc_ue, hz / 100);
361 } while (((usb_ticks_t)(ticks - start_ticks)) < max_ticks);
367 * lan78xx_eeprom_read_raw - Read the attached EEPROM
368 * @sc: soft context
392 locked = mtx_owned(&sc->sc_mtx); /* XXX */
396 if (sc->chipid == ETH_ID_REV_CHIP_ID_7800_) {
427 uether_pause(&sc->sc_ue, hz / 100);
428 } while (((usb_ticks_t)(ticks - start_ticks)) < max_ticks);
445 if (sc->chipid == ETH_ID_REV_CHIP_ID_7800_) {
464 * @sc: soft context
486 locked = mtx_owned(&sc->sc_mtx);
531 * @sc: soft context
557 err = -EINVAL;
566 * lan78xx_setmacaddress - Set the mac address in the device
567 * @sc: driver soft context
601 * @sc: driver soft context
631 /* If it were enabled before, we enable it back. */
642 * lan78xx_miibus_readreg - Read a MII/MDIO register
651 * Returns the 16-bits read from the MII register, if this function fails
662 locked = mtx_owned(&sc->sc_mtx);
693 * lan78xx_miibus_writereg - Writes a MII/MDIO register
714 if (sc->sc_phyno != phy)
717 locked = mtx_owned(&sc->sc_mtx);
744 * lan78xx_miibus_statchg - Called to detect phy status change
757 struct mii_data *mii = uether_getmii(&sc->sc_ue);
764 locked = mtx_owned(&sc->sc_mtx);
768 ifp = uether_getifp(&sc->sc_ue);
774 sc->sc_flags &= ~MUGE_FLAG_LINK;
775 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
778 switch (IFM_SUBTYPE(mii->mii_media_active)) {
781 sc->sc_flags |= MUGE_FLAG_LINK;
785 sc->sc_flags |= MUGE_FLAG_LINK;
793 if ((sc->sc_flags & MUGE_FLAG_LINK) == 0) {
806 /* Enable/disable full duplex operation and TX/RX pause. */
807 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) {
810 /* Enable transmit MAC flow control function. */
811 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_TXPAUSE) != 0)
814 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_RXPAUSE) != 0)
819 switch(usbd_get_speed(sc->sc_ue.ue_udev)) {
841 * lan78xx_set_mdix_auto - Configure the device to enable automatic
842 * crossover and polarity detection. LAN7800 provides HP Auto-MDIX
845 * @sc: driver soft context
855 err = lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno,
858 buf = lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno,
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,
867 err += lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno,
873 sc->sc_mdix_ctl = buf;
877 * lan78xx_phy_init - Initialises the in-built MUGE phy
878 * @sc: driver soft context
881 * values. The 'link down' and 'auto-negotiation complete' interrupts
886 * Returns 0 on success or EIO if failed to reset the PHY.
899 /* Reset phy and wait for reset to complete. */
900 lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR,
905 uether_pause(&sc->sc_ue, hz / 100);
906 bmcr = lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno,
908 } while ((bmcr & BMCR_RESET) && ((ticks - start_ticks) < max_ticks));
910 if (((usb_ticks_t)(ticks - start_ticks)) >= max_ticks) {
911 muge_err_printf(sc, "PHY reset timed-out\n");
916 lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno,
918 lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno,
922 /* Enable Auto-MDIX for crossover and polarity detection. */
925 /* Enable all modes. */
926 lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_ANAR,
930 /* Restart auto-negotiation. */
933 lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR, bmcr);
934 bmcr = lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR);
937 if (sc->sc_led_modes_mask != 0) {
938 lmsr = lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno,
940 lmsr &= ~sc->sc_led_modes_mask;
941 lmsr |= sc->sc_led_modes;
942 lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno,
946 /* Enable appropriate LEDs. */
947 if (sc->sc_leds != 0 &&
951 hw_reg |= sc->sc_leds;
958 * lan78xx_chip_init - Initialises the chip after power on
959 * @sc: driver soft context
982 "timed-out waiting for lite reset to complete\n");
987 if ((err = lan78xx_setmacaddress(sc, sc->sc_ue.ue_eaddr)) != 0) {
998 sc->chipid = (buf & ETH_ID_REV_CHIP_ID_MASK_) >> 16;
999 sc->chiprev = buf & ETH_ID_REV_CHIP_REV_MASK_;
1000 switch (sc->chipid) {
1006 sc->chipid);
1009 device_printf(sc->sc_ue.ue_dev, "Chip ID 0x%04x rev %04x\n", sc->chipid,
1010 sc->chiprev);
1012 /* Respond to BULK-IN tokens with a NAK when RX FIFO is empty. */
1025 switch (usbd_get_speed(sc->sc_ue.ue_udev)) {
1046 /* Enable burst cap. */
1061 buf = (MUGE_MAX_RX_FIFO_SIZE - 512) / 512;
1064 buf = (MUGE_MAX_TX_FIFO_SIZE - 512) / 512;
1072 * properly set is handled in link-reset function in the Linux driver.
1078 * Settings for the RFE, we enable broadcast and destination address
1091 /* Reset the PHY. */
1096 "timed-out waiting for phy reset to complete\n");
1101 if (sc->chipid == ETH_ID_REV_CHIP_ID_7800_ &&
1109 * Enable PHY interrupts (Not really getting used for now)
1131 * Set max frame length. In linux this is dev->mtu (which by default
1140 /* Enable MAC RX. */
1145 /* Enable FIFO controller RX. */
1150 sc->sc_flags |= MUGE_FLAG_INIT_DONE;
1162 struct usb_ether *ue = &sc->sc_ue;
1234 (pktlen > (actlen - off)))
1246 if (pktlen > m->m_len) {
1249 pktlen, m->m_len);
1281 m->m_pkthdr.csum_flags |=
1293 &m->m_pkthdr.csum_data, 2);
1301 m->m_pkthdr.csum_data =
1306 m->m_pkthdr.csum_data);
1316 uether_rxmbuf(ue, m, pktlen - 4);
1344 * muge_bulk_write_callback - Write callback used to send ethernet frame(s)
1356 if_t ifp = uether_getifp(&sc->sc_ue);
1371 if ((sc->sc_flags & MUGE_FLAG_LINK) == 0 ||
1374 "sc->sc_flags & MUGE_FLAG_LINK: %d\n",
1375 (sc->sc_flags & MUGE_FLAG_LINK));
1399 * Each frame is prefixed with two 32-bit values
1402 tx_cmd_a = (m->m_pkthdr.len & TX_CMD_A_LEN_MASK_) |
1416 usbd_m_copy_in(pc, frm_len, m, 0, m->m_pkthdr.len);
1417 frm_len += m->m_pkthdr.len;
1456 * muge_set_mac_addr - Initiailizes NIC MAC address
1460 * EEPROM, DTB blob. If all sources fail - generates random MAC.
1468 memset(ue->ue_eaddr, 0xff, ETHER_ADDR_LEN);
1476 ue->ue_eaddr[5] = (uint8_t)((mac_h >> 8) & 0xff);
1477 ue->ue_eaddr[4] = (uint8_t)((mac_h) & 0xff);
1478 ue->ue_eaddr[3] = (uint8_t)((mac_l >> 24) & 0xff);
1479 ue->ue_eaddr[2] = (uint8_t)((mac_l >> 16) & 0xff);
1480 ue->ue_eaddr[1] = (uint8_t)((mac_l >> 8) & 0xff);
1481 ue->ue_eaddr[0] = (uint8_t)((mac_l) & 0xff);
1489 if (ETHER_IS_VALID(ue->ue_eaddr)) {
1492 ETH_E2P_MAC_OFFSET, ue->ue_eaddr, ETHER_ADDR_LEN) == 0 &&
1493 ETHER_IS_VALID(ue->ue_eaddr)) {
1495 } else if (lan78xx_otp_read(sc, OTP_MAC_OFFSET, ue->ue_eaddr,
1496 ETHER_ADDR_LEN) == 0 && ETHER_IS_VALID(ue->ue_eaddr)) {
1501 /* ue->ue_eaddr modified only if config exists for this dev instance. */
1502 usb_fdt_get_mac_addr(ue->ue_dev, ue);
1503 if (ETHER_IS_VALID(ue->ue_eaddr)) {
1508 if (!ETHER_IS_VALID(ue->ue_eaddr)) {
1510 arc4rand(ue->ue_eaddr, ETHER_ADDR_LEN, 0);
1511 ue->ue_eaddr[0] &= ~0x01; /* unicast */
1512 ue->ue_eaddr[0] |= 0x02; /* locally administered */
1517 * muge_set_leds - Initializes NIC LEDs pattern
1533 if ((node = usb_fdt_get_node(ue->ue_dev, ue->ue_udev)) != -1 &&
1534 (proplen = OF_getencprop(node, "microchip,led-modes", modes,
1537 sc->sc_leds = (count > 0) * ETH_HW_CFG_LEDO_EN_ |
1541 while (count-- > 0) {
1542 sc->sc_led_modes |= (modes[count] & 0xf) << (4 * count);
1543 sc->sc_led_modes_mask |= 0xf << (4 * count);
1551 * muge_attach_post - Called after the driver attached to the USB interface
1556 * setup the H/W to match the UE settings and can be called after a reset.
1567 sc->sc_phyno = 1;
1577 * muge_attach_post_sub - Called after attach to the USB interface
1595 ifp = ue->ue_ifp;
1616 * In the Linux driver they also enable scatter/gather (NETIF_F_SG)
1633 mii_attach(ue->ue_dev, &ue->ue_miibus, ifp, uether_ifmedia_upd,
1634 ue->ue_methods->ue_mii_sts, BMSR_DEFCAPMASK, sc->sc_phyno,
1642 * muge_start - Starts communication with the LAN78xx chip
1653 usbd_transfer_start(sc->sc_xfer[MUGE_BULK_DT_RD]);
1654 usbd_transfer_start(sc->sc_xfer[MUGE_BULK_DT_WR]);
1658 * muge_ioctl - ioctl function for the device
1689 mask = ifr->ifr_reqcap ^ if_getcapenable(ifp);
1691 /* Modify the RX CSUM enable bits. */
1713 * muge_reset - Reset the SMSC chip
1714 * @sc: device soft context
1725 cd = usbd_get_config_descriptor(sc->sc_ue.ue_udev);
1727 err = usbd_req_set_config(sc->sc_ue.ue_udev, &sc->sc_mtx,
1728 cd->bConfigurationValue);
1730 muge_warn_printf(sc, "reset failed (ignored)\n");
1733 uether_pause(&sc->sc_ue, hz / 100);
1735 /* Reinitialize controller to achieve full reset. */
1742 * @sc: device soft context
1758 sc->sc_pfilter_table[index][1] = tmp;
1762 sc->sc_pfilter_table[index][0] = tmp;
1767 * lan78xx_dataport_write - write to the selected RAM
1768 * @sc: The device soft context.
1771 * @buf: word-sized buffer to write to RAM, starting at @addr.
1812 * @sc: device's soft context
1824 sc->sc_mchash_table);
1829 sc->sc_pfilter_table[i][1]);
1831 sc->sc_pfilter_table[i][0]);
1836 * muge_hash - Calculate the hash of a mac address
1844 * Returns a value from 0-63 value which is the hash of the mac address.
1863 sc->sc_mchash_table[bitnum / 32] |= (1 << (bitnum % 32));
1864 sc->sc_rfe_ctl |= ETH_RFE_CTL_MCAST_HASH_;
1871 * muge_setmulti - Setup multicast
1889 sc->sc_rfe_ctl &= ~(ETH_RFE_CTL_UCAST_EN_ | ETH_RFE_CTL_MCAST_EN_ |
1894 sc->sc_mchash_table[i] = 0;
1898 sc->sc_pfilter_table[i][0] = sc->sc_pfilter_table[i][1] = 0;
1901 sc->sc_rfe_ctl |= ETH_RFE_CTL_BCAST_EN_;
1905 sc->sc_rfe_ctl |= ETH_RFE_CTL_MCAST_EN_ | ETH_RFE_CTL_UCAST_EN_;
1908 sc->sc_rfe_ctl |= ETH_RFE_CTL_MCAST_EN_;
1913 lan78xx_write_reg(sc, ETH_RFE_CTL, sc->sc_rfe_ctl);
1917 * muge_setpromisc - Enables/disables promiscuous mode
1935 sc->sc_rfe_ctl |= ETH_RFE_CTL_MCAST_EN_ | ETH_RFE_CTL_UCAST_EN_;
1937 sc->sc_rfe_ctl &= ~(ETH_RFE_CTL_MCAST_EN_);
1939 lan78xx_write_reg(sc, ETH_RFE_CTL, sc->sc_rfe_ctl);
1943 * muge_sethwcsum - Enable or disable H/W UDP and TCP checksumming
1944 * @sc: driver soft context
1955 if_t ifp = uether_getifp(&sc->sc_ue);
1959 return (-EIO);
1964 sc->sc_rfe_ctl |= ETH_RFE_CTL_IGMP_COE_ | ETH_RFE_CTL_ICMP_COE_;
1965 sc->sc_rfe_ctl |= ETH_RFE_CTL_TCPUDP_COE_ | ETH_RFE_CTL_IP_COE_;
1967 sc->sc_rfe_ctl &=
1969 sc->sc_rfe_ctl &=
1973 sc->sc_rfe_ctl &= ~ETH_RFE_CTL_VLAN_FILTER_;
1975 err = lan78xx_write_reg(sc, ETH_RFE_CTL, sc->sc_rfe_ctl);
1987 * muge_ifmedia_upd - Set media options
2004 struct mii_data *mii = uether_getmii(&sc->sc_ue);
2010 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
2017 * muge_init - Initialises the LAN95xx chip
2043 /* Reset the ethernet interface. */
2052 usbd_xfer_set_stall(sc->sc_xfer[MUGE_BULK_DT_WR]);
2063 * muge_stop - Stops communication with the LAN78xx chip
2075 sc->sc_flags &= ~MUGE_FLAG_LINK;
2080 usbd_transfer_stop(sc->sc_xfer[MUGE_BULK_DT_WR]);
2081 usbd_transfer_stop(sc->sc_xfer[MUGE_BULK_DT_RD]);
2085 * muge_tick - Called periodically to monitor the state of the LAN95xx chip
2098 struct mii_data *mii = uether_getmii(&sc->sc_ue);
2103 if ((sc->sc_flags & MUGE_FLAG_LINK) == 0) {
2104 lan78xx_miibus_statchg(ue->ue_dev);
2105 if ((sc->sc_flags & MUGE_FLAG_LINK) != 0)
2111 * muge_ifmedia_sts - Report current media status
2124 struct mii_data *mii = uether_getmii(&sc->sc_ue);
2128 ifmr->ifm_active = mii->mii_media_active;
2129 ifmr->ifm_status = mii->mii_media_status;
2134 * muge_probe - Probe the interface.
2147 if (uaa->usb_mode != USB_MODE_HOST)
2149 if (uaa->info.bConfigIndex != MUGE_CONFIG_INDEX)
2151 if (uaa->info.bIfaceIndex != MUGE_IFACE_IDX)
2157 * muge_attach - Attach the interface.
2170 struct usb_ether *ue = &sc->sc_ue;
2174 sc->sc_flags = USB_GET_DRIVER_INFO(uaa);
2178 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
2182 err = usbd_transfer_setup(uaa->device, &iface_index, sc->sc_xfer,
2183 muge_config, MUGE_N_TRANSFER, sc, &sc->sc_mtx);
2189 ue->ue_sc = sc;
2190 ue->ue_dev = dev;
2191 ue->ue_udev = uaa->device;
2192 ue->ue_mtx = &sc->sc_mtx;
2193 ue->ue_methods = &muge_ue_methods;
2201 /* Wait for lan78xx_chip_init from post-attach callback to complete. */
2203 if (!(sc->sc_flags & MUGE_FLAG_INIT_DONE))
2211 usbd_transfer_unsetup(sc->sc_xfer, MUGE_N_TRANSFER);
2213 mtx_destroy(&sc->sc_mtx);
2218 * muge_detach - Detach the interface.
2229 struct usb_ether *ue = &sc->sc_ue;
2231 usbd_transfer_unsetup(sc->sc_xfer, MUGE_N_TRANSFER);
2233 mtx_destroy(&sc->sc_mtx);