Lines Matching +full:sram +full:- +full:others
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
98 * enable MSI-X in alc_attach() depending on the card type. The operator can
248 nitems(alc_ident_table) - 1);
253 { -1, 0, 0 }
258 { -1, 0, 0 }
263 { -1, 0, 0 }
268 { -1, 0, 0 }
280 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) in alc_miibus_readreg()
299 if ((sc->alc_flags & ALC_FLAG_FASTETHER) != 0 && in alc_mii_readreg_813x()
305 for (i = ALC_PHY_TIMEOUT; i > 0; i--) { in alc_mii_readreg_813x()
313 device_printf(sc->alc_dev, "phy read timeout : %d\n", reg); in alc_mii_readreg_813x()
326 if ((sc->alc_flags & ALC_FLAG_LINK) != 0) in alc_mii_readreg_816x()
332 for (i = ALC_PHY_TIMEOUT; i > 0; i--) { in alc_mii_readreg_816x()
340 device_printf(sc->alc_dev, "phy read timeout : %d\n", reg); in alc_mii_readreg_816x()
354 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) in alc_miibus_writereg()
370 for (i = ALC_PHY_TIMEOUT; i > 0; i--) { in alc_mii_writereg_813x()
378 device_printf(sc->alc_dev, "phy write timeout : %d\n", reg); in alc_mii_writereg_813x()
389 if ((sc->alc_flags & ALC_FLAG_LINK) != 0) in alc_mii_writereg_816x()
396 for (i = ALC_PHY_TIMEOUT; i > 0; i--) { in alc_mii_writereg_816x()
404 device_printf(sc->alc_dev, "phy write timeout : %d\n", reg); in alc_mii_writereg_816x()
419 mii = device_get_softc(sc->alc_miibus); in alc_miibus_statchg()
420 ifp = sc->alc_ifp; in alc_miibus_statchg()
425 sc->alc_flags &= ~ALC_FLAG_LINK; in alc_miibus_statchg()
426 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == in alc_miibus_statchg()
428 switch (IFM_SUBTYPE(mii->mii_media_active)) { in alc_miibus_statchg()
431 sc->alc_flags |= ALC_FLAG_LINK; in alc_miibus_statchg()
434 if ((sc->alc_flags & ALC_FLAG_FASTETHER) == 0) in alc_miibus_statchg()
435 sc->alc_flags |= ALC_FLAG_LINK; in alc_miibus_statchg()
444 /* Program MACs with resolved speed/duplex/flow-control. */ in alc_miibus_statchg()
445 if ((sc->alc_flags & ALC_FLAG_LINK) != 0) { in alc_miibus_statchg()
448 /* Re-enable Tx/Rx MACs. */ in alc_miibus_statchg()
453 alc_aspm(sc, 0, IFM_SUBTYPE(mii->mii_media_active)); in alc_miibus_statchg()
454 alc_dsp_fixup(sc, IFM_SUBTYPE(mii->mii_media_active)); in alc_miibus_statchg()
461 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, ALC_MII_DBG_ADDR, in alc_miidbg_readreg()
463 return (alc_miibus_readreg(sc->alc_dev, sc->alc_phyaddr, in alc_miidbg_readreg()
471 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, ALC_MII_DBG_ADDR, in alc_miidbg_writereg()
473 return (alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_miidbg_writereg()
485 if ((sc->alc_flags & ALC_FLAG_LINK) != 0) in alc_miiext_readreg()
491 for (i = ALC_PHY_TIMEOUT; i > 0; i--) { in alc_miiext_readreg()
499 device_printf(sc->alc_dev, "phy ext read timeout : %d, %d\n", in alc_miiext_readreg()
515 if ((sc->alc_flags & ALC_FLAG_LINK) != 0) in alc_miiext_writereg()
522 for (i = ALC_PHY_TIMEOUT; i > 0; i--) { in alc_miiext_writereg()
530 device_printf(sc->alc_dev, "phy ext write timeout : %d, %d\n", in alc_miiext_writereg()
541 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) in alc_dsp_fixup()
543 if (AR816X_REV(sc->alc_rev) >= AR816X_REV_C0) in alc_dsp_fixup()
550 if ((sc->alc_flags & ALC_FLAG_LINK) != 0) { in alc_dsp_fixup()
576 if ((sc->alc_flags & ALC_FLAG_LINK_WAR) != 0 && in alc_dsp_fixup()
577 AR816X_REV(sc->alc_rev) == AR816X_REV_B0) { in alc_dsp_fixup()
596 if ((sc->alc_flags & ALC_FLAG_LINK_WAR) != 0 && in alc_dsp_fixup()
597 AR816X_REV(sc->alc_rev) == AR816X_REV_B0) { in alc_dsp_fixup()
620 mii = device_get_softc(sc->alc_miibus); in alc_mediastatus()
623 ifmr->ifm_status = mii->mii_media_status; in alc_mediastatus()
624 ifmr->ifm_active = mii->mii_media_active; in alc_mediastatus()
651 mii = device_get_softc(sc->alc_miibus); in alc_mediachange_locked()
652 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) in alc_mediachange_locked()
667 for (ident = alc_ident_table; ident->name != NULL; ident++) { in alc_find_ident()
668 if (vendor == ident->vendorid && devid == ident->deviceid) in alc_find_ident()
682 device_set_desc(dev, ident->name); in alc_probe()
693 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) in alc_get_macaddr()
715 switch (sc->alc_ident->deviceid) { in alc_get_macaddr_813x()
729 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_get_macaddr_813x()
731 val = alc_miibus_readreg(sc->alc_dev, sc->alc_phyaddr, in alc_get_macaddr_813x()
733 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_get_macaddr_813x()
735 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_get_macaddr_813x()
737 val = alc_miibus_readreg(sc->alc_dev, sc->alc_phyaddr, in alc_get_macaddr_813x()
739 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_get_macaddr_813x()
752 for (i = 100; i > 0; i--) { in alc_get_macaddr_813x()
759 device_printf(sc->alc_dev, in alc_get_macaddr_813x()
763 device_printf(sc->alc_dev, "EEPROM not found!\n"); in alc_get_macaddr_813x()
766 switch (sc->alc_ident->deviceid) { in alc_get_macaddr_813x()
780 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_get_macaddr_813x()
782 val = alc_miibus_readreg(sc->alc_dev, sc->alc_phyaddr, in alc_get_macaddr_813x()
784 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_get_macaddr_813x()
786 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_get_macaddr_813x()
788 val = alc_miibus_readreg(sc->alc_dev, sc->alc_phyaddr, in alc_get_macaddr_813x()
790 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_get_macaddr_813x()
808 for (i = 100; i > 0; i--) { in alc_get_macaddr_816x()
816 for (i = 100; i > 0; i--) { in alc_get_macaddr_816x()
825 device_printf(sc->alc_dev, in alc_get_macaddr_816x()
834 for (i = 100; i > 0; i--) { in alc_get_macaddr_816x()
844 for (i = 100; i > 0; i--) { in alc_get_macaddr_816x()
851 device_printf(sc->alc_dev, in alc_get_macaddr_816x()
866 sc->alc_eaddr[0] = (ea[1] >> 8) & 0xFF; in alc_get_macaddr_par()
867 sc->alc_eaddr[1] = (ea[1] >> 0) & 0xFF; in alc_get_macaddr_par()
868 sc->alc_eaddr[2] = (ea[0] >> 24) & 0xFF; in alc_get_macaddr_par()
869 sc->alc_eaddr[3] = (ea[0] >> 16) & 0xFF; in alc_get_macaddr_par()
870 sc->alc_eaddr[4] = (ea[0] >> 8) & 0xFF; in alc_get_macaddr_par()
871 sc->alc_eaddr[5] = (ea[0] >> 0) & 0xFF; in alc_get_macaddr_par()
879 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) == 0) { in alc_disable_l0s_l1()
895 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) in alc_phy_reset()
917 if (sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8152_B) { in alc_phy_reset_813x()
918 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
920 data = alc_miibus_readreg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
922 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
925 if (sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8151 || in alc_phy_reset_813x()
926 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8151_V2 || in alc_phy_reset_813x()
927 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8152_B || in alc_phy_reset_813x()
928 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8152_B2) { in alc_phy_reset_813x()
929 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
931 data = alc_miibus_readreg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
933 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
937 if (sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8151) { in alc_phy_reset_813x()
938 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
940 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
943 if (sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8131 || in alc_phy_reset_813x()
944 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8132 || in alc_phy_reset_813x()
945 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8151_V2 || in alc_phy_reset_813x()
946 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8152_B2) { in alc_phy_reset_813x()
947 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
949 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
956 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
958 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
964 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
966 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
974 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
976 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
983 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
985 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
991 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
993 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
998 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, ALC_MII_DBG_ADDR, in alc_phy_reset_813x()
1000 data = alc_miibus_readreg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
1003 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, ALC_MII_DBG_DATA, in alc_phy_reset_813x()
1006 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, ALC_MII_DBG_ADDR, in alc_phy_reset_813x()
1008 data = alc_miibus_readreg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_reset_813x()
1011 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, ALC_MII_DBG_DATA, in alc_phy_reset_813x()
1072 if ((sc->alc_flags & ALC_FLAG_LINK_WAR) != 0) { in alc_phy_reset_816x()
1093 switch (sc->alc_ident->deviceid) { in alc_phy_down()
1124 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_phy_down()
1141 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) in alc_aspm()
1153 if ((sc->alc_flags & ALC_FLAG_LINK) == 0) in alc_aspm_813x()
1157 if ((sc->alc_flags & (ALC_FLAG_APS | ALC_FLAG_PCIE)) == in alc_aspm_813x()
1159 linkcfg = CSR_READ_2(sc, sc->alc_expcap + in alc_aspm_813x()
1169 if ((sc->alc_flags & ALC_FLAG_APS) != 0) { in alc_aspm_813x()
1172 if (sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8152_B && in alc_aspm_813x()
1173 sc->alc_rev == ATHEROS_AR8152_B_V10) in alc_aspm_813x()
1175 CSR_WRITE_2(sc, sc->alc_expcap + PCIER_LINK_CTL, in alc_aspm_813x()
1187 if ((sc->alc_flags & ALC_FLAG_LINK) != 0) { in alc_aspm_813x()
1188 if ((sc->alc_flags & ALC_FLAG_L0S) != 0) in alc_aspm_813x()
1190 if ((sc->alc_flags & ALC_FLAG_L1S) != 0) in alc_aspm_813x()
1192 if ((sc->alc_flags & ALC_FLAG_APS) != 0) { in alc_aspm_813x()
1193 if (sc->alc_ident->deviceid == in alc_aspm_813x()
1202 switch (sc->alc_ident->deviceid) { in alc_aspm_813x()
1229 if ((sc->alc_flags & ALC_FLAG_L1S) != 0) in alc_aspm_813x()
1253 if (AR816X_REV(sc->alc_rev) <= AR816X_REV_A1 && in alc_aspm_816x()
1254 (sc->alc_rev & 0x01) != 0) in alc_aspm_816x()
1256 if ((sc->alc_flags & ALC_FLAG_LINK) != 0) { in alc_aspm_816x()
1264 else if ((if_getdrvflags(sc->alc_ifp) & IFF_DRV_RUNNING) != 0) in alc_aspm_816x()
1277 /* Clear data link and flow-control protocol error. */ in alc_init_pcie()
1282 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) == 0) { in alc_init_pcie()
1288 if (sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8152_B && in alc_init_pcie()
1289 sc->alc_rev == ATHEROS_AR8152_B_V10) { in alc_init_pcie()
1298 cap = CSR_READ_2(sc, sc->alc_expcap + PCIER_LINK_CAP); in alc_init_pcie()
1300 ctl = CSR_READ_2(sc, sc->alc_expcap + PCIER_LINK_CTL); in alc_init_pcie()
1302 sc->alc_rcb = DMA_CFG_RCB_128; in alc_init_pcie()
1304 device_printf(sc->alc_dev, "RCB %u bytes\n", in alc_init_pcie()
1305 sc->alc_rcb == DMA_CFG_RCB_64 ? 64 : 128); in alc_init_pcie()
1308 sc->alc_flags |= ALC_FLAG_L0S; in alc_init_pcie()
1310 sc->alc_flags |= ALC_FLAG_L1S; in alc_init_pcie()
1312 device_printf(sc->alc_dev, "ASPM %s %s\n", in alc_init_pcie()
1318 device_printf(sc->alc_dev, in alc_init_pcie()
1326 if (AR816X_REV(sc->alc_rev) <= AR816X_REV_A1 && in alc_init_pcie()
1327 (sc->alc_rev & 0x01) != 0) { in alc_init_pcie()
1350 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) { in alc_config_msi()
1360 mod = ALC_USECS(sc->alc_int_rx_mod); in alc_config_msi()
1364 if ((sc->alc_flags & ALC_FLAG_MSIX) != 0) in alc_config_msi()
1367 else if ((sc->alc_flags & ALC_FLAG_MSI) != 0) in alc_config_msi()
1385 sc->alc_dev = dev; in alc_attach()
1386 sc->alc_rev = pci_get_revid(dev); in alc_attach()
1388 mtx_init(&sc->alc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, in alc_attach()
1390 callout_init_mtx(&sc->alc_tick_ch, &sc->alc_mtx, 0); in alc_attach()
1391 NET_TASK_INIT(&sc->alc_int_task, 0, alc_int_task, sc); in alc_attach()
1392 sc->alc_ident = alc_find_ident(dev); in alc_attach()
1396 sc->alc_res_spec = alc_res_spec_mem; in alc_attach()
1397 sc->alc_irq_spec = alc_irq_spec_legacy; in alc_attach()
1398 error = bus_alloc_resources(dev, sc->alc_res_spec, sc->alc_res); in alc_attach()
1405 sc->alc_phyaddr = ALC_PHY_ADDR; in alc_attach()
1414 switch (sc->alc_ident->deviceid) { in alc_attach()
1418 sc->alc_flags |= ALC_FLAG_E2X00; in alc_attach()
1421 * Disable MSI-X by default on Killer devices, since this is in alc_attach()
1430 pci_get_subdevice(dev) == 0x0091 && sc->alc_rev == 0) in alc_attach()
1431 sc->alc_flags |= ALC_FLAG_LINK_WAR; in alc_attach()
1434 sc->alc_flags |= ALC_FLAG_AR816X_FAMILY; in alc_attach()
1438 sc->alc_flags |= ALC_FLAG_FASTETHER | ALC_FLAG_AR816X_FAMILY; in alc_attach()
1442 sc->alc_flags |= ALC_FLAG_APS; in alc_attach()
1445 sc->alc_flags |= ALC_FLAG_FASTETHER; in alc_attach()
1449 sc->alc_flags |= ALC_FLAG_APS; in alc_attach()
1451 sc->alc_flags |= ALC_FLAG_MT; in alc_attach()
1458 * The default value of msix_disable is 2, which means auto-detect. If in alc_attach()
1459 * we didn't auto-detect it, default to enabling it. in alc_attach()
1464 sc->alc_flags |= ALC_FLAG_JUMBO; in alc_attach()
1472 sc->alc_flags |= ALC_FLAG_SMB_BUG; in alc_attach()
1476 sc->alc_flags |= ALC_FLAG_CMB_BUG; in alc_attach()
1477 sc->alc_chip_rev = CSR_READ_4(sc, ALC_MASTER_CFG) >> in alc_attach()
1481 sc->alc_rev); in alc_attach()
1483 sc->alc_chip_rev); in alc_attach()
1484 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) in alc_attach()
1486 AR816X_REV(sc->alc_rev)); in alc_attach()
1493 sc->alc_dma_rd_burst = 0; in alc_attach()
1494 sc->alc_dma_wr_burst = 0; in alc_attach()
1495 sc->alc_rcb = DMA_CFG_RCB_64; in alc_attach()
1497 sc->alc_flags |= ALC_FLAG_PCIE; in alc_attach()
1498 sc->alc_expcap = base; in alc_attach()
1500 sc->alc_dma_rd_burst = in alc_attach()
1502 sc->alc_dma_wr_burst = (burst & PCIEM_CTL_MAX_PAYLOAD) >> 5; in alc_attach()
1505 alc_dma_burst[sc->alc_dma_rd_burst]); in alc_attach()
1507 alc_dma_burst[sc->alc_dma_wr_burst]); in alc_attach()
1509 if (alc_dma_burst[sc->alc_dma_rd_burst] > 1024) in alc_attach()
1510 sc->alc_dma_rd_burst = 3; in alc_attach()
1511 if (alc_dma_burst[sc->alc_dma_wr_burst] > 1024) in alc_attach()
1512 sc->alc_dma_wr_burst = 3; in alc_attach()
1518 if ((sc->alc_flags & in alc_attach()
1520 sc->alc_dma_wr_burst = 0; in alc_attach()
1554 sc->alc_flags |= ALC_FLAG_MSIX; in alc_attach()
1555 sc->alc_irq_spec = alc_irq_spec_msix; in alc_attach()
1559 if (msi_disable == 0 && (sc->alc_flags & ALC_FLAG_MSIX) == 0 && in alc_attach()
1564 sc->alc_flags |= ALC_FLAG_MSI; in alc_attach()
1565 sc->alc_irq_spec = alc_irq_spec_msi; in alc_attach()
1571 error = bus_alloc_resources(dev, sc->alc_irq_spec, sc->alc_irq); in alc_attach()
1586 ifp = sc->alc_ifp = if_alloc(IFT_ETHER); in alc_attach()
1593 if_setsendqlen(ifp, ALC_TX_RING_CNT - 1); in alc_attach()
1599 sc->alc_flags |= ALC_FLAG_PM; in alc_attach()
1600 sc->alc_pmcap = base; in alc_attach()
1605 error = mii_attach(dev, &sc->alc_miibus, ifp, alc_mediachange, in alc_attach()
1606 alc_mediastatus, BMSR_DEFCAPMASK, sc->alc_phyaddr, MII_OFFSET_ANY, in alc_attach()
1613 ether_ifattach(ifp, sc->alc_eaddr); in alc_attach()
1631 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) == 0) { in alc_attach()
1640 sc->alc_tq = taskqueue_create_fast("alc_taskq", M_WAITOK, in alc_attach()
1641 taskqueue_thread_enqueue, &sc->alc_tq); in alc_attach()
1642 taskqueue_start_threads(&sc->alc_tq, 1, PI_NET, "%s taskq", in alc_attach()
1643 device_get_nameunit(sc->alc_dev)); in alc_attach()
1646 if ((sc->alc_flags & ALC_FLAG_MSIX) != 0) in alc_attach()
1648 else if ((sc->alc_flags & ALC_FLAG_MSI) != 0) in alc_attach()
1653 error = bus_setup_intr(dev, sc->alc_irq[i], in alc_attach()
1655 &sc->alc_intrhand[i]); in alc_attach()
1661 taskqueue_free(sc->alc_tq); in alc_attach()
1662 sc->alc_tq = NULL; in alc_attach()
1686 ifp = sc->alc_ifp; in alc_detach()
1692 callout_drain(&sc->alc_tick_ch); in alc_detach()
1693 taskqueue_drain(sc->alc_tq, &sc->alc_int_task); in alc_detach()
1696 if (sc->alc_tq != NULL) { in alc_detach()
1697 taskqueue_drain(sc->alc_tq, &sc->alc_int_task); in alc_detach()
1698 taskqueue_free(sc->alc_tq); in alc_detach()
1699 sc->alc_tq = NULL; in alc_detach()
1702 if (sc->alc_miibus != NULL) { in alc_detach()
1703 device_delete_child(dev, sc->alc_miibus); in alc_detach()
1704 sc->alc_miibus = NULL; in alc_detach()
1711 sc->alc_ifp = NULL; in alc_detach()
1714 if ((sc->alc_flags & ALC_FLAG_MSIX) != 0) in alc_detach()
1716 else if ((sc->alc_flags & ALC_FLAG_MSI) != 0) in alc_detach()
1721 if (sc->alc_intrhand[i] != NULL) { in alc_detach()
1722 bus_teardown_intr(dev, sc->alc_irq[i], in alc_detach()
1723 sc->alc_intrhand[i]); in alc_detach()
1724 sc->alc_intrhand[i] = NULL; in alc_detach()
1727 if (sc->alc_res[0] != NULL) in alc_detach()
1729 bus_release_resources(dev, sc->alc_irq_spec, sc->alc_irq); in alc_detach()
1730 if ((sc->alc_flags & (ALC_FLAG_MSI | ALC_FLAG_MSIX)) != 0) in alc_detach()
1732 bus_release_resources(dev, sc->alc_res_spec, sc->alc_res); in alc_detach()
1733 mtx_destroy(&sc->alc_mtx); in alc_detach()
1752 stats = &sc->alc_stats; in alc_sysctl_node()
1753 ctx = device_get_sysctl_ctx(sc->alc_dev); in alc_sysctl_node()
1754 child = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->alc_dev)); in alc_sysctl_node()
1757 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, &sc->alc_int_rx_mod, in alc_sysctl_node()
1760 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, &sc->alc_int_tx_mod, in alc_sysctl_node()
1763 sc->alc_int_rx_mod = ALC_IM_RX_TIMER_DEFAULT; in alc_sysctl_node()
1764 error = resource_int_value(device_get_name(sc->alc_dev), in alc_sysctl_node()
1765 device_get_unit(sc->alc_dev), "int_rx_mod", &sc->alc_int_rx_mod); in alc_sysctl_node()
1767 if (sc->alc_int_rx_mod < ALC_IM_TIMER_MIN || in alc_sysctl_node()
1768 sc->alc_int_rx_mod > ALC_IM_TIMER_MAX) { in alc_sysctl_node()
1769 device_printf(sc->alc_dev, "int_rx_mod value out of " in alc_sysctl_node()
1772 sc->alc_int_rx_mod = ALC_IM_RX_TIMER_DEFAULT; in alc_sysctl_node()
1775 sc->alc_int_tx_mod = ALC_IM_TX_TIMER_DEFAULT; in alc_sysctl_node()
1776 error = resource_int_value(device_get_name(sc->alc_dev), in alc_sysctl_node()
1777 device_get_unit(sc->alc_dev), "int_tx_mod", &sc->alc_int_tx_mod); in alc_sysctl_node()
1779 if (sc->alc_int_tx_mod < ALC_IM_TIMER_MIN || in alc_sysctl_node()
1780 sc->alc_int_tx_mod > ALC_IM_TIMER_MAX) { in alc_sysctl_node()
1781 device_printf(sc->alc_dev, "int_tx_mod value out of " in alc_sysctl_node()
1784 sc->alc_int_tx_mod = ALC_IM_TX_TIMER_DEFAULT; in alc_sysctl_node()
1789 &sc->alc_process_limit, 0, sysctl_hw_alc_proc_limit, "I", in alc_sysctl_node()
1792 sc->alc_process_limit = ALC_PROC_DEFAULT; in alc_sysctl_node()
1793 error = resource_int_value(device_get_name(sc->alc_dev), in alc_sysctl_node()
1794 device_get_unit(sc->alc_dev), "process_limit", in alc_sysctl_node()
1795 &sc->alc_process_limit); in alc_sysctl_node()
1797 if (sc->alc_process_limit < ALC_PROC_MIN || in alc_sysctl_node()
1798 sc->alc_process_limit > ALC_PROC_MAX) { in alc_sysctl_node()
1799 device_printf(sc->alc_dev, in alc_sysctl_node()
1802 sc->alc_process_limit = ALC_PROC_DEFAULT; in alc_sysctl_node()
1815 &stats->rx_frames, "Good frames"); in alc_sysctl_node()
1817 &stats->rx_bcast_frames, "Good broadcast frames"); in alc_sysctl_node()
1819 &stats->rx_mcast_frames, "Good multicast frames"); in alc_sysctl_node()
1821 &stats->rx_pause_frames, "Pause control frames"); in alc_sysctl_node()
1823 &stats->rx_control_frames, "Control frames"); in alc_sysctl_node()
1825 &stats->rx_crcerrs, "CRC errors"); in alc_sysctl_node()
1827 &stats->rx_lenerrs, "Frames with length mismatched"); in alc_sysctl_node()
1829 &stats->rx_bytes, "Good octets"); in alc_sysctl_node()
1831 &stats->rx_bcast_bytes, "Good broadcast octets"); in alc_sysctl_node()
1833 &stats->rx_mcast_bytes, "Good multicast octets"); in alc_sysctl_node()
1835 &stats->rx_runts, "Too short frames"); in alc_sysctl_node()
1837 &stats->rx_fragments, "Fragmented frames"); in alc_sysctl_node()
1839 &stats->rx_pkts_64, "64 bytes frames"); in alc_sysctl_node()
1841 &stats->rx_pkts_65_127, "65 to 127 bytes frames"); in alc_sysctl_node()
1843 &stats->rx_pkts_128_255, "128 to 255 bytes frames"); in alc_sysctl_node()
1845 &stats->rx_pkts_256_511, "256 to 511 bytes frames"); in alc_sysctl_node()
1847 &stats->rx_pkts_512_1023, "512 to 1023 bytes frames"); in alc_sysctl_node()
1849 &stats->rx_pkts_1024_1518, "1024 to 1518 bytes frames"); in alc_sysctl_node()
1851 &stats->rx_pkts_1519_max, "1519 to max frames"); in alc_sysctl_node()
1853 &stats->rx_pkts_truncated, "Truncated frames due to MTU size"); in alc_sysctl_node()
1855 &stats->rx_fifo_oflows, "FIFO overflows"); in alc_sysctl_node()
1857 &stats->rx_rrs_errs, "Return status write-back errors"); in alc_sysctl_node()
1859 &stats->rx_alignerrs, "Alignment errors"); in alc_sysctl_node()
1861 &stats->rx_pkts_filtered, in alc_sysctl_node()
1869 &stats->tx_frames, "Good frames"); in alc_sysctl_node()
1871 &stats->tx_bcast_frames, "Good broadcast frames"); in alc_sysctl_node()
1873 &stats->tx_mcast_frames, "Good multicast frames"); in alc_sysctl_node()
1875 &stats->tx_pause_frames, "Pause control frames"); in alc_sysctl_node()
1877 &stats->tx_control_frames, "Control frames"); in alc_sysctl_node()
1879 &stats->tx_excess_defer, "Frames with excessive derferrals"); in alc_sysctl_node()
1881 &stats->tx_excess_defer, "Frames with derferrals"); in alc_sysctl_node()
1883 &stats->tx_bytes, "Good octets"); in alc_sysctl_node()
1885 &stats->tx_bcast_bytes, "Good broadcast octets"); in alc_sysctl_node()
1887 &stats->tx_mcast_bytes, "Good multicast octets"); in alc_sysctl_node()
1889 &stats->tx_pkts_64, "64 bytes frames"); in alc_sysctl_node()
1891 &stats->tx_pkts_65_127, "65 to 127 bytes frames"); in alc_sysctl_node()
1893 &stats->tx_pkts_128_255, "128 to 255 bytes frames"); in alc_sysctl_node()
1895 &stats->tx_pkts_256_511, "256 to 511 bytes frames"); in alc_sysctl_node()
1897 &stats->tx_pkts_512_1023, "512 to 1023 bytes frames"); in alc_sysctl_node()
1899 &stats->tx_pkts_1024_1518, "1024 to 1518 bytes frames"); in alc_sysctl_node()
1901 &stats->tx_pkts_1519_max, "1519 to max frames"); in alc_sysctl_node()
1903 &stats->tx_single_colls, "Single collisions"); in alc_sysctl_node()
1905 &stats->tx_multi_colls, "Multiple collisions"); in alc_sysctl_node()
1907 &stats->tx_late_colls, "Late collisions"); in alc_sysctl_node()
1909 &stats->tx_excess_colls, "Excessive collisions"); in alc_sysctl_node()
1911 &stats->tx_underrun, "FIFO underruns"); in alc_sysctl_node()
1913 &stats->tx_desc_underrun, "Descriptor write-back errors"); in alc_sysctl_node()
1915 &stats->tx_lenerrs, "Frames with length mismatched"); in alc_sysctl_node()
1917 &stats->tx_pkts_truncated, "Truncated frames due to MTU size"); in alc_sysctl_node()
1938 ctx->alc_busaddr = segs[0].ds_addr; in alc_dmamap_cb()
1951 rx_ring_end = sc->alc_rdata.alc_rx_ring_paddr + ALC_RX_RING_SZ; in alc_check_boundary()
1952 rr_ring_end = sc->alc_rdata.alc_rr_ring_paddr + ALC_RR_RING_SZ; in alc_check_boundary()
1953 cmb_end = sc->alc_rdata.alc_cmb_paddr + ALC_CMB_SZ; in alc_check_boundary()
1954 tx_ring_end = sc->alc_rdata.alc_tx_ring_paddr + ALC_TX_RING_SZ; in alc_check_boundary()
1958 ALC_ADDR_HI(sc->alc_rdata.alc_rx_ring_paddr)) || in alc_check_boundary()
1960 ALC_ADDR_HI(sc->alc_rdata.alc_rr_ring_paddr)) || in alc_check_boundary()
1962 ALC_ADDR_HI(sc->alc_rdata.alc_cmb_paddr)) || in alc_check_boundary()
1964 ALC_ADDR_HI(sc->alc_rdata.alc_tx_ring_paddr))) in alc_check_boundary()
1987 if (sc->alc_flags & ALC_FLAG_MT) in alc_dma_alloc()
1992 bus_get_dma_tag(sc->alc_dev), /* parent */ in alc_dma_alloc()
2002 &sc->alc_cdata.alc_parent_tag); in alc_dma_alloc()
2004 device_printf(sc->alc_dev, in alc_dma_alloc()
2011 sc->alc_cdata.alc_parent_tag, /* parent */ in alc_dma_alloc()
2021 &sc->alc_cdata.alc_tx_ring_tag); in alc_dma_alloc()
2023 device_printf(sc->alc_dev, in alc_dma_alloc()
2030 sc->alc_cdata.alc_parent_tag, /* parent */ in alc_dma_alloc()
2040 &sc->alc_cdata.alc_rx_ring_tag); in alc_dma_alloc()
2042 device_printf(sc->alc_dev, in alc_dma_alloc()
2048 sc->alc_cdata.alc_parent_tag, /* parent */ in alc_dma_alloc()
2058 &sc->alc_cdata.alc_rr_ring_tag); in alc_dma_alloc()
2060 device_printf(sc->alc_dev, in alc_dma_alloc()
2067 sc->alc_cdata.alc_parent_tag, /* parent */ in alc_dma_alloc()
2077 &sc->alc_cdata.alc_cmb_tag); in alc_dma_alloc()
2079 device_printf(sc->alc_dev, in alc_dma_alloc()
2085 sc->alc_cdata.alc_parent_tag, /* parent */ in alc_dma_alloc()
2095 &sc->alc_cdata.alc_smb_tag); in alc_dma_alloc()
2097 device_printf(sc->alc_dev, in alc_dma_alloc()
2103 error = bus_dmamem_alloc(sc->alc_cdata.alc_tx_ring_tag, in alc_dma_alloc()
2104 (void **)&sc->alc_rdata.alc_tx_ring, in alc_dma_alloc()
2106 &sc->alc_cdata.alc_tx_ring_map); in alc_dma_alloc()
2108 device_printf(sc->alc_dev, in alc_dma_alloc()
2113 error = bus_dmamap_load(sc->alc_cdata.alc_tx_ring_tag, in alc_dma_alloc()
2114 sc->alc_cdata.alc_tx_ring_map, sc->alc_rdata.alc_tx_ring, in alc_dma_alloc()
2117 device_printf(sc->alc_dev, in alc_dma_alloc()
2121 sc->alc_rdata.alc_tx_ring_paddr = ctx.alc_busaddr; in alc_dma_alloc()
2124 error = bus_dmamem_alloc(sc->alc_cdata.alc_rx_ring_tag, in alc_dma_alloc()
2125 (void **)&sc->alc_rdata.alc_rx_ring, in alc_dma_alloc()
2127 &sc->alc_cdata.alc_rx_ring_map); in alc_dma_alloc()
2129 device_printf(sc->alc_dev, in alc_dma_alloc()
2134 error = bus_dmamap_load(sc->alc_cdata.alc_rx_ring_tag, in alc_dma_alloc()
2135 sc->alc_cdata.alc_rx_ring_map, sc->alc_rdata.alc_rx_ring, in alc_dma_alloc()
2138 device_printf(sc->alc_dev, in alc_dma_alloc()
2142 sc->alc_rdata.alc_rx_ring_paddr = ctx.alc_busaddr; in alc_dma_alloc()
2145 error = bus_dmamem_alloc(sc->alc_cdata.alc_rr_ring_tag, in alc_dma_alloc()
2146 (void **)&sc->alc_rdata.alc_rr_ring, in alc_dma_alloc()
2148 &sc->alc_cdata.alc_rr_ring_map); in alc_dma_alloc()
2150 device_printf(sc->alc_dev, in alc_dma_alloc()
2155 error = bus_dmamap_load(sc->alc_cdata.alc_rr_ring_tag, in alc_dma_alloc()
2156 sc->alc_cdata.alc_rr_ring_map, sc->alc_rdata.alc_rr_ring, in alc_dma_alloc()
2159 device_printf(sc->alc_dev, in alc_dma_alloc()
2163 sc->alc_rdata.alc_rr_ring_paddr = ctx.alc_busaddr; in alc_dma_alloc()
2166 error = bus_dmamem_alloc(sc->alc_cdata.alc_cmb_tag, in alc_dma_alloc()
2167 (void **)&sc->alc_rdata.alc_cmb, in alc_dma_alloc()
2169 &sc->alc_cdata.alc_cmb_map); in alc_dma_alloc()
2171 device_printf(sc->alc_dev, in alc_dma_alloc()
2176 error = bus_dmamap_load(sc->alc_cdata.alc_cmb_tag, in alc_dma_alloc()
2177 sc->alc_cdata.alc_cmb_map, sc->alc_rdata.alc_cmb, in alc_dma_alloc()
2180 device_printf(sc->alc_dev, in alc_dma_alloc()
2184 sc->alc_rdata.alc_cmb_paddr = ctx.alc_busaddr; in alc_dma_alloc()
2187 error = bus_dmamem_alloc(sc->alc_cdata.alc_smb_tag, in alc_dma_alloc()
2188 (void **)&sc->alc_rdata.alc_smb, in alc_dma_alloc()
2190 &sc->alc_cdata.alc_smb_map); in alc_dma_alloc()
2192 device_printf(sc->alc_dev, in alc_dma_alloc()
2197 error = bus_dmamap_load(sc->alc_cdata.alc_smb_tag, in alc_dma_alloc()
2198 sc->alc_cdata.alc_smb_map, sc->alc_rdata.alc_smb, in alc_dma_alloc()
2201 device_printf(sc->alc_dev, in alc_dma_alloc()
2205 sc->alc_rdata.alc_smb_paddr = ctx.alc_busaddr; in alc_dma_alloc()
2210 device_printf(sc->alc_dev, "4GB boundary crossed, " in alc_dma_alloc()
2229 bus_get_dma_tag(sc->alc_dev), /* parent */ in alc_dma_alloc()
2239 &sc->alc_cdata.alc_buffer_tag); in alc_dma_alloc()
2241 device_printf(sc->alc_dev, in alc_dma_alloc()
2248 sc->alc_cdata.alc_buffer_tag, /* parent */ in alc_dma_alloc()
2258 &sc->alc_cdata.alc_tx_tag); in alc_dma_alloc()
2260 device_printf(sc->alc_dev, "could not create Tx DMA tag.\n"); in alc_dma_alloc()
2266 sc->alc_cdata.alc_buffer_tag, /* parent */ in alc_dma_alloc()
2276 &sc->alc_cdata.alc_rx_tag); in alc_dma_alloc()
2278 device_printf(sc->alc_dev, "could not create Rx DMA tag.\n"); in alc_dma_alloc()
2283 txd = &sc->alc_cdata.alc_txdesc[i]; in alc_dma_alloc()
2284 txd->tx_m = NULL; in alc_dma_alloc()
2285 txd->tx_dmamap = NULL; in alc_dma_alloc()
2286 error = bus_dmamap_create(sc->alc_cdata.alc_tx_tag, 0, in alc_dma_alloc()
2287 &txd->tx_dmamap); in alc_dma_alloc()
2289 device_printf(sc->alc_dev, in alc_dma_alloc()
2295 if ((error = bus_dmamap_create(sc->alc_cdata.alc_rx_tag, 0, in alc_dma_alloc()
2296 &sc->alc_cdata.alc_rx_sparemap)) != 0) { in alc_dma_alloc()
2297 device_printf(sc->alc_dev, in alc_dma_alloc()
2302 rxd = &sc->alc_cdata.alc_rxdesc[i]; in alc_dma_alloc()
2303 rxd->rx_m = NULL; in alc_dma_alloc()
2304 rxd->rx_dmamap = NULL; in alc_dma_alloc()
2305 error = bus_dmamap_create(sc->alc_cdata.alc_rx_tag, 0, in alc_dma_alloc()
2306 &rxd->rx_dmamap); in alc_dma_alloc()
2308 device_printf(sc->alc_dev, in alc_dma_alloc()
2326 if (sc->alc_cdata.alc_tx_tag != NULL) { in alc_dma_free()
2328 txd = &sc->alc_cdata.alc_txdesc[i]; in alc_dma_free()
2329 if (txd->tx_dmamap != NULL) { in alc_dma_free()
2330 bus_dmamap_destroy(sc->alc_cdata.alc_tx_tag, in alc_dma_free()
2331 txd->tx_dmamap); in alc_dma_free()
2332 txd->tx_dmamap = NULL; in alc_dma_free()
2335 bus_dma_tag_destroy(sc->alc_cdata.alc_tx_tag); in alc_dma_free()
2336 sc->alc_cdata.alc_tx_tag = NULL; in alc_dma_free()
2339 if (sc->alc_cdata.alc_rx_tag != NULL) { in alc_dma_free()
2341 rxd = &sc->alc_cdata.alc_rxdesc[i]; in alc_dma_free()
2342 if (rxd->rx_dmamap != NULL) { in alc_dma_free()
2343 bus_dmamap_destroy(sc->alc_cdata.alc_rx_tag, in alc_dma_free()
2344 rxd->rx_dmamap); in alc_dma_free()
2345 rxd->rx_dmamap = NULL; in alc_dma_free()
2348 if (sc->alc_cdata.alc_rx_sparemap != NULL) { in alc_dma_free()
2349 bus_dmamap_destroy(sc->alc_cdata.alc_rx_tag, in alc_dma_free()
2350 sc->alc_cdata.alc_rx_sparemap); in alc_dma_free()
2351 sc->alc_cdata.alc_rx_sparemap = NULL; in alc_dma_free()
2353 bus_dma_tag_destroy(sc->alc_cdata.alc_rx_tag); in alc_dma_free()
2354 sc->alc_cdata.alc_rx_tag = NULL; in alc_dma_free()
2357 if (sc->alc_cdata.alc_tx_ring_tag != NULL) { in alc_dma_free()
2358 if (sc->alc_rdata.alc_tx_ring_paddr != 0) in alc_dma_free()
2359 bus_dmamap_unload(sc->alc_cdata.alc_tx_ring_tag, in alc_dma_free()
2360 sc->alc_cdata.alc_tx_ring_map); in alc_dma_free()
2361 if (sc->alc_rdata.alc_tx_ring != NULL) in alc_dma_free()
2362 bus_dmamem_free(sc->alc_cdata.alc_tx_ring_tag, in alc_dma_free()
2363 sc->alc_rdata.alc_tx_ring, in alc_dma_free()
2364 sc->alc_cdata.alc_tx_ring_map); in alc_dma_free()
2365 sc->alc_rdata.alc_tx_ring_paddr = 0; in alc_dma_free()
2366 sc->alc_rdata.alc_tx_ring = NULL; in alc_dma_free()
2367 bus_dma_tag_destroy(sc->alc_cdata.alc_tx_ring_tag); in alc_dma_free()
2368 sc->alc_cdata.alc_tx_ring_tag = NULL; in alc_dma_free()
2371 if (sc->alc_cdata.alc_rx_ring_tag != NULL) { in alc_dma_free()
2372 if (sc->alc_rdata.alc_rx_ring_paddr != 0) in alc_dma_free()
2373 bus_dmamap_unload(sc->alc_cdata.alc_rx_ring_tag, in alc_dma_free()
2374 sc->alc_cdata.alc_rx_ring_map); in alc_dma_free()
2375 if (sc->alc_rdata.alc_rx_ring != NULL) in alc_dma_free()
2376 bus_dmamem_free(sc->alc_cdata.alc_rx_ring_tag, in alc_dma_free()
2377 sc->alc_rdata.alc_rx_ring, in alc_dma_free()
2378 sc->alc_cdata.alc_rx_ring_map); in alc_dma_free()
2379 sc->alc_rdata.alc_rx_ring_paddr = 0; in alc_dma_free()
2380 sc->alc_rdata.alc_rx_ring = NULL; in alc_dma_free()
2381 bus_dma_tag_destroy(sc->alc_cdata.alc_rx_ring_tag); in alc_dma_free()
2382 sc->alc_cdata.alc_rx_ring_tag = NULL; in alc_dma_free()
2385 if (sc->alc_cdata.alc_rr_ring_tag != NULL) { in alc_dma_free()
2386 if (sc->alc_rdata.alc_rr_ring_paddr != 0) in alc_dma_free()
2387 bus_dmamap_unload(sc->alc_cdata.alc_rr_ring_tag, in alc_dma_free()
2388 sc->alc_cdata.alc_rr_ring_map); in alc_dma_free()
2389 if (sc->alc_rdata.alc_rr_ring != NULL) in alc_dma_free()
2390 bus_dmamem_free(sc->alc_cdata.alc_rr_ring_tag, in alc_dma_free()
2391 sc->alc_rdata.alc_rr_ring, in alc_dma_free()
2392 sc->alc_cdata.alc_rr_ring_map); in alc_dma_free()
2393 sc->alc_rdata.alc_rr_ring_paddr = 0; in alc_dma_free()
2394 sc->alc_rdata.alc_rr_ring = NULL; in alc_dma_free()
2395 bus_dma_tag_destroy(sc->alc_cdata.alc_rr_ring_tag); in alc_dma_free()
2396 sc->alc_cdata.alc_rr_ring_tag = NULL; in alc_dma_free()
2399 if (sc->alc_cdata.alc_cmb_tag != NULL) { in alc_dma_free()
2400 if (sc->alc_rdata.alc_cmb_paddr != 0) in alc_dma_free()
2401 bus_dmamap_unload(sc->alc_cdata.alc_cmb_tag, in alc_dma_free()
2402 sc->alc_cdata.alc_cmb_map); in alc_dma_free()
2403 if (sc->alc_rdata.alc_cmb != NULL) in alc_dma_free()
2404 bus_dmamem_free(sc->alc_cdata.alc_cmb_tag, in alc_dma_free()
2405 sc->alc_rdata.alc_cmb, in alc_dma_free()
2406 sc->alc_cdata.alc_cmb_map); in alc_dma_free()
2407 sc->alc_rdata.alc_cmb_paddr = 0; in alc_dma_free()
2408 sc->alc_rdata.alc_cmb = NULL; in alc_dma_free()
2409 bus_dma_tag_destroy(sc->alc_cdata.alc_cmb_tag); in alc_dma_free()
2410 sc->alc_cdata.alc_cmb_tag = NULL; in alc_dma_free()
2413 if (sc->alc_cdata.alc_smb_tag != NULL) { in alc_dma_free()
2414 if (sc->alc_rdata.alc_smb_paddr != 0) in alc_dma_free()
2415 bus_dmamap_unload(sc->alc_cdata.alc_smb_tag, in alc_dma_free()
2416 sc->alc_cdata.alc_smb_map); in alc_dma_free()
2417 if (sc->alc_rdata.alc_smb != NULL) in alc_dma_free()
2418 bus_dmamem_free(sc->alc_cdata.alc_smb_tag, in alc_dma_free()
2419 sc->alc_rdata.alc_smb, in alc_dma_free()
2420 sc->alc_cdata.alc_smb_map); in alc_dma_free()
2421 sc->alc_rdata.alc_smb_paddr = 0; in alc_dma_free()
2422 sc->alc_rdata.alc_smb = NULL; in alc_dma_free()
2423 bus_dma_tag_destroy(sc->alc_cdata.alc_smb_tag); in alc_dma_free()
2424 sc->alc_cdata.alc_smb_tag = NULL; in alc_dma_free()
2426 if (sc->alc_cdata.alc_buffer_tag != NULL) { in alc_dma_free()
2427 bus_dma_tag_destroy(sc->alc_cdata.alc_buffer_tag); in alc_dma_free()
2428 sc->alc_cdata.alc_buffer_tag = NULL; in alc_dma_free()
2430 if (sc->alc_cdata.alc_parent_tag != NULL) { in alc_dma_free()
2431 bus_dma_tag_destroy(sc->alc_cdata.alc_parent_tag); in alc_dma_free()
2432 sc->alc_cdata.alc_parent_tag = NULL; in alc_dma_free()
2445 * restarting auto-negotiation in suspend/shutdown phase but we
2446 * don't know whether that auto-negotiation would succeed or not
2454 * Save current negotiated media speed/duplex/flow-control to
2465 mii = device_get_softc(sc->alc_miibus); in alc_setlinkspeed()
2468 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == in alc_setlinkspeed()
2470 switch IFM_SUBTYPE(mii->mii_media_active) { in alc_setlinkspeed()
2481 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, MII_100T2CR, 0); in alc_setlinkspeed()
2482 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_setlinkspeed()
2484 alc_miibus_writereg(sc->alc_dev, sc->alc_phyaddr, in alc_setlinkspeed()
2493 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) in alc_setlinkspeed()
2496 mii->mii_media_active)) { in alc_setlinkspeed()
2510 device_printf(sc->alc_dev, in alc_setlinkspeed()
2514 * No link, force MAC to have 100Mbps, full-duplex link. in alc_setlinkspeed()
2517 mii->mii_media_status = IFM_AVALID | IFM_ACTIVE; in alc_setlinkspeed()
2518 mii->mii_media_active = IFM_ETHER | IFM_100_TX | IFM_FDX; in alc_setlinkspeed()
2526 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) in alc_setwol()
2542 ifp = sc->alc_ifp; in alc_setwol_813x()
2543 if ((sc->alc_flags & ALC_FLAG_PM) == 0) { in alc_setwol_813x()
2557 if ((sc->alc_flags & ALC_FLAG_FASTETHER) == 0) in alc_setwol_813x()
2586 pmstat = pci_read_config(sc->alc_dev, in alc_setwol_813x()
2587 sc->alc_pmcap + PCIR_POWER_STATUS, 2); in alc_setwol_813x()
2591 pci_write_config(sc->alc_dev, in alc_setwol_813x()
2592 sc->alc_pmcap + PCIR_POWER_STATUS, pmstat, 2); in alc_setwol_813x()
2604 ifp = sc->alc_ifp; in alc_setwol_816x()
2611 if ((sc->alc_flags & ALC_FLAG_PM) == 0) { in alc_setwol_816x()
2618 if ((sc->alc_flags & ALC_FLAG_FASTETHER) == 0) in alc_setwol_816x()
2649 if ((sc->alc_flags & ALC_FLAG_PM) != 0) { in alc_setwol_816x()
2651 pmstat = pci_read_config(sc->alc_dev, in alc_setwol_816x()
2652 sc->alc_pmcap + PCIR_POWER_STATUS, 2); in alc_setwol_816x()
2656 pci_write_config(sc->alc_dev, in alc_setwol_816x()
2657 sc->alc_pmcap + PCIR_POWER_STATUS, pmstat, 2); in alc_setwol_816x()
2686 if ((sc->alc_flags & ALC_FLAG_PM) != 0) { in alc_resume()
2688 pmstat = pci_read_config(sc->alc_dev, in alc_resume()
2689 sc->alc_pmcap + PCIR_POWER_STATUS, 2); in alc_resume()
2692 pci_write_config(sc->alc_dev, in alc_resume()
2693 sc->alc_pmcap + PCIR_POWER_STATUS, pmstat, 2); in alc_resume()
2698 ifp = sc->alc_ifp; in alc_resume()
2729 if ((m->m_pkthdr.csum_flags & (ALC_CSUM_FEATURES | CSUM_TSO)) != 0) { in alc_encap()
2763 if (eh->ether_type == htons(ETHERTYPE_VLAN)) { in alc_encap()
2777 poff = ip_off + (ip->ip_hl << 2); in alc_encap()
2778 if ((m->m_pkthdr.csum_flags & CSUM_TSO) != 0) { in alc_encap()
2785 m = m_pullup(m, poff + (tcp->th_off << 2)); in alc_encap()
2805 ip->ip_sum = 0; in alc_encap()
2806 tcp->th_sum = in_pseudo(ip->ip_src.s_addr, in alc_encap()
2807 ip->ip_dst.s_addr, htons(IPPROTO_TCP)); in alc_encap()
2812 prod = sc->alc_cdata.alc_tx_prod; in alc_encap()
2813 txd = &sc->alc_cdata.alc_txdesc[prod]; in alc_encap()
2815 map = txd->tx_dmamap; in alc_encap()
2817 error = bus_dmamap_load_mbuf_sg(sc->alc_cdata.alc_tx_tag, map, in alc_encap()
2827 error = bus_dmamap_load_mbuf_sg(sc->alc_cdata.alc_tx_tag, map, in alc_encap()
2843 if (sc->alc_cdata.alc_tx_cnt + nsegs >= ALC_TX_RING_CNT - 3) { in alc_encap()
2844 bus_dmamap_unload(sc->alc_cdata.alc_tx_tag, map); in alc_encap()
2847 bus_dmamap_sync(sc->alc_cdata.alc_tx_tag, map, BUS_DMASYNC_PREWRITE); in alc_encap()
2855 if ((m->m_flags & M_VLANTAG) != 0) { in alc_encap()
2856 vtag = htons(m->m_pkthdr.ether_vtag); in alc_encap()
2860 if ((m->m_pkthdr.csum_flags & CSUM_TSO) != 0) { in alc_encap()
2863 cflags |= ((uint32_t)m->m_pkthdr.tso_segsz << TD_MSS_SHIFT) & in alc_encap()
2873 hdrlen = poff + (tcp->th_off << 2); in alc_encap()
2874 desc = &sc->alc_rdata.alc_tx_ring[prod]; in alc_encap()
2875 desc->len = htole32(TX_BYTES(hdrlen | vtag)); in alc_encap()
2876 desc->flags = htole32(cflags); in alc_encap()
2877 desc->addr = htole64(txsegs[0].ds_addr); in alc_encap()
2878 sc->alc_cdata.alc_tx_cnt++; in alc_encap()
2880 if (m->m_len - hdrlen > 0) { in alc_encap()
2882 desc = &sc->alc_rdata.alc_tx_ring[prod]; in alc_encap()
2883 desc->len = htole32(TX_BYTES((m->m_len - hdrlen) | in alc_encap()
2885 desc->flags = htole32(cflags); in alc_encap()
2886 desc->addr = htole64(txsegs[0].ds_addr + hdrlen); in alc_encap()
2887 sc->alc_cdata.alc_tx_cnt++; in alc_encap()
2892 } else if ((m->m_pkthdr.csum_flags & ALC_CSUM_FEATURES) != 0) { in alc_encap()
2900 cflags |= (((poff + m->m_pkthdr.csum_data) >> 1) << in alc_encap()
2903 if ((m->m_pkthdr.csum_flags & CSUM_IP) != 0) in alc_encap()
2905 if ((m->m_pkthdr.csum_flags & CSUM_TCP) != 0) in alc_encap()
2907 if ((m->m_pkthdr.csum_flags & CSUM_UDP) != 0) in alc_encap()
2915 desc = &sc->alc_rdata.alc_tx_ring[prod]; in alc_encap()
2916 desc->len = htole32(TX_BYTES(txsegs[idx].ds_len) | vtag); in alc_encap()
2917 desc->flags = htole32(cflags); in alc_encap()
2918 desc->addr = htole64(txsegs[idx].ds_addr); in alc_encap()
2919 sc->alc_cdata.alc_tx_cnt++; in alc_encap()
2923 sc->alc_cdata.alc_tx_prod = prod; in alc_encap()
2926 prod = (prod + ALC_TX_RING_CNT - 1) % ALC_TX_RING_CNT; in alc_encap()
2927 desc = &sc->alc_rdata.alc_tx_ring[prod]; in alc_encap()
2928 desc->flags |= htole32(TD_EOP); in alc_encap()
2931 txd = &sc->alc_cdata.alc_txdesc[prod]; in alc_encap()
2932 map = txd_last->tx_dmamap; in alc_encap()
2933 txd_last->tx_dmamap = txd->tx_dmamap; in alc_encap()
2934 txd->tx_dmamap = map; in alc_encap()
2935 txd->tx_m = m; in alc_encap()
2963 if (sc->alc_cdata.alc_tx_cnt >= ALC_TX_DESC_HIWAT) in alc_start_locked()
2967 IFF_DRV_RUNNING || (sc->alc_flags & ALC_FLAG_LINK) == 0) in alc_start_locked()
3004 bus_dmamap_sync(sc->alc_cdata.alc_tx_ring_tag, in alc_start_tx()
3005 sc->alc_cdata.alc_tx_ring_map, BUS_DMASYNC_PREWRITE); in alc_start_tx()
3007 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) in alc_start_tx()
3009 (uint16_t)sc->alc_cdata.alc_tx_prod); in alc_start_tx()
3012 (sc->alc_cdata.alc_tx_prod << in alc_start_tx()
3016 sc->alc_watchdog_timer = ALC_TX_TIMEOUT; in alc_start_tx()
3026 if (sc->alc_watchdog_timer == 0 || --sc->alc_watchdog_timer) in alc_watchdog()
3029 ifp = sc->alc_ifp; in alc_watchdog()
3030 if ((sc->alc_flags & ALC_FLAG_LINK) == 0) { in alc_watchdog()
3031 if_printf(sc->alc_ifp, "watchdog timeout (lost link)\n"); in alc_watchdog()
3037 if_printf(sc->alc_ifp, "watchdog timeout -- resetting\n"); in alc_watchdog()
3058 if (ifr->ifr_mtu < ETHERMIN || in alc_ioctl()
3059 ifr->ifr_mtu > (sc->alc_ident->max_framelen - in alc_ioctl()
3060 sizeof(struct ether_vlan_header) - ETHER_CRC_LEN) || in alc_ioctl()
3061 ((sc->alc_flags & ALC_FLAG_JUMBO) == 0 && in alc_ioctl()
3062 ifr->ifr_mtu > ETHERMTU)) in alc_ioctl()
3064 else if (if_getmtu(ifp) != ifr->ifr_mtu) { in alc_ioctl()
3066 if_setmtu(ifp, ifr->ifr_mtu); in alc_ioctl()
3081 ((if_getflags(ifp) ^ sc->alc_if_flags) & in alc_ioctl()
3088 sc->alc_if_flags = if_getflags(ifp); in alc_ioctl()
3100 mii = device_get_softc(sc->alc_miibus); in alc_ioctl()
3101 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, cmd); in alc_ioctl()
3105 mask = ifr->ifr_reqcap ^ if_getcapenable(ifp); in alc_ioctl()
3166 mii = device_get_softc(sc->alc_miibus); in alc_mac_config()
3170 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0 || in alc_mac_config()
3171 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8151 || in alc_mac_config()
3172 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8151_V2 || in alc_mac_config()
3173 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8152_B2) in alc_mac_config()
3176 switch (IFM_SUBTYPE(mii->mii_media_active)) { in alc_mac_config()
3185 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) { in alc_mac_config()
3187 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_TXPAUSE) != 0) in alc_mac_config()
3189 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_RXPAUSE) != 0) in alc_mac_config()
3202 if ((sc->alc_flags & ALC_FLAG_SMB_BUG) == 0) { in alc_stats_clear()
3203 bus_dmamap_sync(sc->alc_cdata.alc_smb_tag, in alc_stats_clear()
3204 sc->alc_cdata.alc_smb_map, in alc_stats_clear()
3206 smb = sc->alc_rdata.alc_smb; in alc_stats_clear()
3208 smb->updated = 0; in alc_stats_clear()
3209 bus_dmamap_sync(sc->alc_cdata.alc_smb_tag, in alc_stats_clear()
3210 sc->alc_cdata.alc_smb_map, in alc_stats_clear()
3238 ifp = sc->alc_ifp; in alc_stats_update()
3239 stat = &sc->alc_stats; in alc_stats_update()
3240 if ((sc->alc_flags & ALC_FLAG_SMB_BUG) == 0) { in alc_stats_update()
3241 bus_dmamap_sync(sc->alc_cdata.alc_smb_tag, in alc_stats_update()
3242 sc->alc_cdata.alc_smb_map, in alc_stats_update()
3244 smb = sc->alc_rdata.alc_smb; in alc_stats_update()
3245 if (smb->updated == 0) in alc_stats_update()
3264 stat->rx_frames += smb->rx_frames; in alc_stats_update()
3265 stat->rx_bcast_frames += smb->rx_bcast_frames; in alc_stats_update()
3266 stat->rx_mcast_frames += smb->rx_mcast_frames; in alc_stats_update()
3267 stat->rx_pause_frames += smb->rx_pause_frames; in alc_stats_update()
3268 stat->rx_control_frames += smb->rx_control_frames; in alc_stats_update()
3269 stat->rx_crcerrs += smb->rx_crcerrs; in alc_stats_update()
3270 stat->rx_lenerrs += smb->rx_lenerrs; in alc_stats_update()
3271 stat->rx_bytes += smb->rx_bytes; in alc_stats_update()
3272 stat->rx_runts += smb->rx_runts; in alc_stats_update()
3273 stat->rx_fragments += smb->rx_fragments; in alc_stats_update()
3274 stat->rx_pkts_64 += smb->rx_pkts_64; in alc_stats_update()
3275 stat->rx_pkts_65_127 += smb->rx_pkts_65_127; in alc_stats_update()
3276 stat->rx_pkts_128_255 += smb->rx_pkts_128_255; in alc_stats_update()
3277 stat->rx_pkts_256_511 += smb->rx_pkts_256_511; in alc_stats_update()
3278 stat->rx_pkts_512_1023 += smb->rx_pkts_512_1023; in alc_stats_update()
3279 stat->rx_pkts_1024_1518 += smb->rx_pkts_1024_1518; in alc_stats_update()
3280 stat->rx_pkts_1519_max += smb->rx_pkts_1519_max; in alc_stats_update()
3281 stat->rx_pkts_truncated += smb->rx_pkts_truncated; in alc_stats_update()
3282 stat->rx_fifo_oflows += smb->rx_fifo_oflows; in alc_stats_update()
3283 stat->rx_rrs_errs += smb->rx_rrs_errs; in alc_stats_update()
3284 stat->rx_alignerrs += smb->rx_alignerrs; in alc_stats_update()
3285 stat->rx_bcast_bytes += smb->rx_bcast_bytes; in alc_stats_update()
3286 stat->rx_mcast_bytes += smb->rx_mcast_bytes; in alc_stats_update()
3287 stat->rx_pkts_filtered += smb->rx_pkts_filtered; in alc_stats_update()
3290 stat->tx_frames += smb->tx_frames; in alc_stats_update()
3291 stat->tx_bcast_frames += smb->tx_bcast_frames; in alc_stats_update()
3292 stat->tx_mcast_frames += smb->tx_mcast_frames; in alc_stats_update()
3293 stat->tx_pause_frames += smb->tx_pause_frames; in alc_stats_update()
3294 stat->tx_excess_defer += smb->tx_excess_defer; in alc_stats_update()
3295 stat->tx_control_frames += smb->tx_control_frames; in alc_stats_update()
3296 stat->tx_deferred += smb->tx_deferred; in alc_stats_update()
3297 stat->tx_bytes += smb->tx_bytes; in alc_stats_update()
3298 stat->tx_pkts_64 += smb->tx_pkts_64; in alc_stats_update()
3299 stat->tx_pkts_65_127 += smb->tx_pkts_65_127; in alc_stats_update()
3300 stat->tx_pkts_128_255 += smb->tx_pkts_128_255; in alc_stats_update()
3301 stat->tx_pkts_256_511 += smb->tx_pkts_256_511; in alc_stats_update()
3302 stat->tx_pkts_512_1023 += smb->tx_pkts_512_1023; in alc_stats_update()
3303 stat->tx_pkts_1024_1518 += smb->tx_pkts_1024_1518; in alc_stats_update()
3304 stat->tx_pkts_1519_max += smb->tx_pkts_1519_max; in alc_stats_update()
3305 stat->tx_single_colls += smb->tx_single_colls; in alc_stats_update()
3306 stat->tx_multi_colls += smb->tx_multi_colls; in alc_stats_update()
3307 stat->tx_late_colls += smb->tx_late_colls; in alc_stats_update()
3308 stat->tx_excess_colls += smb->tx_excess_colls; in alc_stats_update()
3309 stat->tx_underrun += smb->tx_underrun; in alc_stats_update()
3310 stat->tx_desc_underrun += smb->tx_desc_underrun; in alc_stats_update()
3311 stat->tx_lenerrs += smb->tx_lenerrs; in alc_stats_update()
3312 stat->tx_pkts_truncated += smb->tx_pkts_truncated; in alc_stats_update()
3313 stat->tx_bcast_bytes += smb->tx_bcast_bytes; in alc_stats_update()
3314 stat->tx_mcast_bytes += smb->tx_mcast_bytes; in alc_stats_update()
3317 if_inc_counter(ifp, IFCOUNTER_OPACKETS, smb->tx_frames); in alc_stats_update()
3319 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, smb->tx_single_colls + in alc_stats_update()
3320 smb->tx_multi_colls * 2 + smb->tx_late_colls + in alc_stats_update()
3321 smb->tx_excess_colls * HDPX_CFG_RETRY_DEFAULT); in alc_stats_update()
3323 if_inc_counter(ifp, IFCOUNTER_OERRORS, smb->tx_late_colls + in alc_stats_update()
3324 smb->tx_excess_colls + smb->tx_underrun + smb->tx_pkts_truncated); in alc_stats_update()
3326 if_inc_counter(ifp, IFCOUNTER_IPACKETS, smb->rx_frames); in alc_stats_update()
3329 smb->rx_crcerrs + smb->rx_lenerrs + in alc_stats_update()
3330 smb->rx_runts + smb->rx_pkts_truncated + in alc_stats_update()
3331 smb->rx_fifo_oflows + smb->rx_rrs_errs + in alc_stats_update()
3332 smb->rx_alignerrs); in alc_stats_update()
3334 if ((sc->alc_flags & ALC_FLAG_SMB_BUG) == 0) { in alc_stats_update()
3336 smb->updated = 0; in alc_stats_update()
3337 bus_dmamap_sync(sc->alc_cdata.alc_smb_tag, in alc_stats_update()
3338 sc->alc_cdata.alc_smb_map, in alc_stats_update()
3351 if (sc->alc_flags & ALC_FLAG_MT) { in alc_intr()
3352 taskqueue_enqueue(sc->alc_tq, &sc->alc_int_task); in alc_intr()
3361 taskqueue_enqueue(sc->alc_tq, &sc->alc_int_task); in alc_intr()
3375 ifp = sc->alc_ifp; in alc_int_task()
3379 if (sc->alc_morework != 0) { in alc_int_task()
3380 sc->alc_morework = 0; in alc_int_task()
3392 more = alc_rxintr(sc, sc->alc_process_limit); in alc_int_task()
3394 sc->alc_morework = 1; in alc_int_task()
3405 device_printf(sc->alc_dev, in alc_int_task()
3406 "DMA read error! -- resetting\n"); in alc_int_task()
3408 device_printf(sc->alc_dev, in alc_int_task()
3409 "DMA write error! -- resetting\n"); in alc_int_task()
3411 device_printf(sc->alc_dev, in alc_int_task()
3412 "TxQ reset! -- resetting\n"); in alc_int_task()
3426 taskqueue_enqueue(sc->alc_tq, &sc->alc_int_task); in alc_int_task()
3432 /* Re-enable interrupts if we're running. */ in alc_int_task()
3433 if (sc->alc_flags & ALC_FLAG_MT) in alc_int_task()
3450 ifp = sc->alc_ifp; in alc_txeof()
3452 if (sc->alc_cdata.alc_tx_cnt == 0) in alc_txeof()
3454 bus_dmamap_sync(sc->alc_cdata.alc_tx_ring_tag, in alc_txeof()
3455 sc->alc_cdata.alc_tx_ring_map, BUS_DMASYNC_POSTWRITE); in alc_txeof()
3456 if ((sc->alc_flags & ALC_FLAG_CMB_BUG) == 0) { in alc_txeof()
3457 bus_dmamap_sync(sc->alc_cdata.alc_cmb_tag, in alc_txeof()
3458 sc->alc_cdata.alc_cmb_map, BUS_DMASYNC_POSTREAD); in alc_txeof()
3459 prod = sc->alc_rdata.alc_cmb->cons; in alc_txeof()
3461 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) in alc_txeof()
3470 cons = sc->alc_cdata.alc_tx_cons; in alc_txeof()
3476 if (sc->alc_cdata.alc_tx_cnt <= 0) in alc_txeof()
3479 sc->alc_cdata.alc_tx_cnt--; in alc_txeof()
3480 txd = &sc->alc_cdata.alc_txdesc[cons]; in alc_txeof()
3481 if (txd->tx_m != NULL) { in alc_txeof()
3483 bus_dmamap_sync(sc->alc_cdata.alc_tx_tag, in alc_txeof()
3484 txd->tx_dmamap, BUS_DMASYNC_POSTWRITE); in alc_txeof()
3485 bus_dmamap_unload(sc->alc_cdata.alc_tx_tag, in alc_txeof()
3486 txd->tx_dmamap); in alc_txeof()
3487 m_freem(txd->tx_m); in alc_txeof()
3488 txd->tx_m = NULL; in alc_txeof()
3492 if ((sc->alc_flags & ALC_FLAG_CMB_BUG) == 0) in alc_txeof()
3493 bus_dmamap_sync(sc->alc_cdata.alc_cmb_tag, in alc_txeof()
3494 sc->alc_cdata.alc_cmb_map, BUS_DMASYNC_PREREAD); in alc_txeof()
3495 sc->alc_cdata.alc_tx_cons = cons; in alc_txeof()
3500 if (sc->alc_cdata.alc_tx_cnt == 0) in alc_txeof()
3501 sc->alc_watchdog_timer = 0; in alc_txeof()
3515 m->m_len = m->m_pkthdr.len = RX_BUF_SIZE_MAX; in alc_newbuf()
3520 if (bus_dmamap_load_mbuf_sg(sc->alc_cdata.alc_rx_tag, in alc_newbuf()
3521 sc->alc_cdata.alc_rx_sparemap, m, segs, &nsegs, 0) != 0) { in alc_newbuf()
3527 if (rxd->rx_m != NULL) { in alc_newbuf()
3528 bus_dmamap_sync(sc->alc_cdata.alc_rx_tag, rxd->rx_dmamap, in alc_newbuf()
3530 bus_dmamap_unload(sc->alc_cdata.alc_rx_tag, rxd->rx_dmamap); in alc_newbuf()
3532 map = rxd->rx_dmamap; in alc_newbuf()
3533 rxd->rx_dmamap = sc->alc_cdata.alc_rx_sparemap; in alc_newbuf()
3534 sc->alc_cdata.alc_rx_sparemap = map; in alc_newbuf()
3535 bus_dmamap_sync(sc->alc_cdata.alc_rx_tag, rxd->rx_dmamap, in alc_newbuf()
3537 rxd->rx_m = m; in alc_newbuf()
3538 rxd->rx_desc->addr = htole64(segs[0].ds_addr); in alc_newbuf()
3550 bus_dmamap_sync(sc->alc_cdata.alc_rr_ring_tag, in alc_rxintr()
3551 sc->alc_cdata.alc_rr_ring_map, in alc_rxintr()
3553 bus_dmamap_sync(sc->alc_cdata.alc_rx_ring_tag, in alc_rxintr()
3554 sc->alc_cdata.alc_rx_ring_map, BUS_DMASYNC_POSTWRITE); in alc_rxintr()
3555 rr_cons = sc->alc_cdata.alc_rr_cons; in alc_rxintr()
3556 ifp = sc->alc_ifp; in alc_rxintr()
3558 if (count-- <= 0) in alc_rxintr()
3560 rrd = &sc->alc_rdata.alc_rr_ring[rr_cons]; in alc_rxintr()
3561 status = le32toh(rrd->status); in alc_rxintr()
3564 nsegs = RRD_RD_CNT(le32toh(rrd->rdinfo)); in alc_rxintr()
3567 device_printf(sc->alc_dev, in alc_rxintr()
3568 "unexpected segment count -- resetting\n"); in alc_rxintr()
3573 rrd->status = 0; in alc_rxintr()
3575 sc->alc_cdata.alc_rx_cons += nsegs; in alc_rxintr()
3576 sc->alc_cdata.alc_rx_cons %= ALC_RR_RING_CNT; in alc_rxintr()
3582 sc->alc_cdata.alc_rr_cons = rr_cons; in alc_rxintr()
3584 bus_dmamap_sync(sc->alc_cdata.alc_rr_ring_tag, in alc_rxintr()
3585 sc->alc_cdata.alc_rr_ring_map, in alc_rxintr()
3591 bus_dmamap_sync(sc->alc_cdata.alc_rx_ring_tag, in alc_rxintr()
3592 sc->alc_cdata.alc_rx_ring_map, BUS_DMASYNC_PREWRITE); in alc_rxintr()
3597 * only when Rx buffer pre-fetching is required. In in alc_rxintr()
3600 * it still seems that pre-fetching needs more in alc_rxintr()
3603 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) in alc_rxintr()
3605 (uint16_t)sc->alc_cdata.alc_rx_cons); in alc_rxintr()
3608 sc->alc_cdata.alc_rx_cons); in alc_rxintr()
3623 dst = src - 3; in alc_fixup_rx()
3625 if (m->m_next == NULL) { in alc_fixup_rx()
3626 for (i = 0; i < (m->m_len / sizeof(uint16_t) + 1); i++) in alc_fixup_rx()
3628 m->m_data -= 6; in alc_fixup_rx()
3642 bcopy(m->m_data, n->m_data, ETHER_HDR_LEN); in alc_fixup_rx()
3643 m->m_data += ETHER_HDR_LEN; in alc_fixup_rx()
3644 m->m_len -= ETHER_HDR_LEN; in alc_fixup_rx()
3645 n->m_len = ETHER_HDR_LEN; in alc_fixup_rx()
3647 n->m_next = m; in alc_fixup_rx()
3662 ifp = sc->alc_ifp; in alc_rxeof()
3663 status = le32toh(rrd->status); in alc_rxeof()
3664 rdinfo = le32toh(rrd->rdinfo); in alc_rxeof()
3668 sc->alc_cdata.alc_rxlen = RRD_BYTES(status); in alc_rxeof()
3690 rxd = &sc->alc_cdata.alc_rxdesc[rx_cons]; in alc_rxeof()
3691 mp = rxd->rx_m; in alc_rxeof()
3696 if (sc->alc_cdata.alc_rxhead != NULL) in alc_rxeof()
3697 m_freem(sc->alc_cdata.alc_rxhead); in alc_rxeof()
3704 * multi-segmented frame. in alc_rxeof()
3706 mp->m_len = sc->alc_buf_size; in alc_rxeof()
3709 if (sc->alc_cdata.alc_rxhead == NULL) { in alc_rxeof()
3710 sc->alc_cdata.alc_rxhead = mp; in alc_rxeof()
3711 sc->alc_cdata.alc_rxtail = mp; in alc_rxeof()
3713 mp->m_flags &= ~M_PKTHDR; in alc_rxeof()
3714 sc->alc_cdata.alc_rxprev_tail = in alc_rxeof()
3715 sc->alc_cdata.alc_rxtail; in alc_rxeof()
3716 sc->alc_cdata.alc_rxtail->m_next = mp; in alc_rxeof()
3717 sc->alc_cdata.alc_rxtail = mp; in alc_rxeof()
3720 if (count == nsegs - 1) { in alc_rxeof()
3722 m = sc->alc_cdata.alc_rxhead; in alc_rxeof()
3723 m->m_flags |= M_PKTHDR; in alc_rxeof()
3728 m->m_pkthdr.len = in alc_rxeof()
3729 sc->alc_cdata.alc_rxlen - ETHER_CRC_LEN; in alc_rxeof()
3732 mp->m_len = sc->alc_cdata.alc_rxlen - in alc_rxeof()
3733 (nsegs - 1) * sc->alc_buf_size; in alc_rxeof()
3735 if (mp->m_len <= ETHER_CRC_LEN) { in alc_rxeof()
3736 sc->alc_cdata.alc_rxtail = in alc_rxeof()
3737 sc->alc_cdata.alc_rxprev_tail; in alc_rxeof()
3738 sc->alc_cdata.alc_rxtail->m_len -= in alc_rxeof()
3739 (ETHER_CRC_LEN - mp->m_len); in alc_rxeof()
3740 sc->alc_cdata.alc_rxtail->m_next = NULL; in alc_rxeof()
3743 mp->m_len -= ETHER_CRC_LEN; in alc_rxeof()
3746 m->m_len = m->m_pkthdr.len; in alc_rxeof()
3747 m->m_pkthdr.rcvif = ifp; in alc_rxeof()
3754 vtag = RRD_VLAN(le32toh(rrd->vtag)); in alc_rxeof()
3755 m->m_pkthdr.ether_vtag = ntohs(vtag); in alc_rxeof()
3756 m->m_flags |= M_VLANTAG; in alc_rxeof()
3784 mii = device_get_softc(sc->alc_miibus); in alc_tick()
3796 callout_reset(&sc->alc_tick_ch, hz, alc_tick, sc); in alc_tick()
3810 if (AR816X_REV(sc->alc_rev) >= AR816X_REV_B0) { in alc_osc_reset()
3812 * Restore over-current protection default value. in alc_osc_reset()
3828 if (AR816X_REV(sc->alc_rev) <= AR816X_REV_A1) in alc_osc_reset()
3844 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) { in alc_reset()
3847 if (AR816X_REV(sc->alc_rev) <= AR816X_REV_A1 && in alc_reset()
3848 (sc->alc_rev & 0x01) != 0) { in alc_reset()
3863 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) { in alc_reset()
3864 for (i = ALC_RESET_TIMEOUT; i > 0; i--) { in alc_reset()
3870 device_printf(sc->alc_dev, "MAC reset timeout!\n"); in alc_reset()
3872 for (i = ALC_RESET_TIMEOUT; i > 0; i--) { in alc_reset()
3878 device_printf(sc->alc_dev, "master reset timeout!\n"); in alc_reset()
3880 for (i = ALC_RESET_TIMEOUT; i > 0; i--) { in alc_reset()
3888 device_printf(sc->alc_dev, "reset timeout(0x%08x)!\n", reg); in alc_reset()
3890 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) { in alc_reset()
3891 if (AR816X_REV(sc->alc_rev) <= AR816X_REV_A1 && in alc_reset()
3892 (sc->alc_rev & 0x01) != 0) { in alc_reset()
3909 if (AR816X_REV(sc->alc_rev) <= AR816X_REV_A1) in alc_reset()
3914 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0 || in alc_reset()
3915 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8152_B || in alc_reset()
3916 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8151_V2) in alc_reset()
3943 ifp = sc->alc_ifp; in alc_init_locked()
3958 device_printf(sc->alc_dev, "no memory for Rx buffers.\n"); in alc_init_locked()
3968 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) { in alc_init_locked()
3973 if (AR816X_REV(sc->alc_rev) >= AR816X_REV_B0) in alc_init_locked()
3991 paddr = sc->alc_rdata.alc_tx_ring_paddr; in alc_init_locked()
4000 paddr = sc->alc_rdata.alc_rx_ring_paddr; in alc_init_locked()
4003 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) == 0) { in alc_init_locked()
4020 * For strict-alignment architectures make sure to reduce buffer in alc_init_locked()
4024 sc->alc_buf_size = RX_BUF_SIZE_MAX - sizeof(uint64_t); in alc_init_locked()
4026 sc->alc_buf_size = RX_BUF_SIZE_MAX; in alc_init_locked()
4028 CSR_WRITE_4(sc, ALC_RX_BUF_SIZE, sc->alc_buf_size); in alc_init_locked()
4030 paddr = sc->alc_rdata.alc_rr_ring_paddr; in alc_init_locked()
4033 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) == 0) { in alc_init_locked()
4042 paddr = sc->alc_rdata.alc_cmb_paddr; in alc_init_locked()
4044 paddr = sc->alc_rdata.alc_smb_paddr; in alc_init_locked()
4048 if (sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8152_B) { in alc_init_locked()
4049 /* Reconfigure SRAM - Vendor magic. */ in alc_init_locked()
4064 reg = ALC_USECS(sc->alc_int_rx_mod) << IM_TIMER_RX_SHIFT; in alc_init_locked()
4065 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) == 0) in alc_init_locked()
4066 reg |= ALC_USECS(sc->alc_int_tx_mod) << IM_TIMER_TX_SHIFT; in alc_init_locked()
4075 if (ALC_USECS(sc->alc_int_rx_mod) != 0) in alc_init_locked()
4077 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) == 0 && in alc_init_locked()
4078 ALC_USECS(sc->alc_int_tx_mod) != 0) in alc_init_locked()
4082 * Disable interrupt re-trigger timer. We don't want automatic in alc_init_locked()
4083 * re-triggering of un-ACKed interrupts. in alc_init_locked()
4087 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) { in alc_init_locked()
4090 ALC_USECS(sc->alc_int_tx_mod)); in alc_init_locked()
4092 if ((sc->alc_flags & ALC_FLAG_CMB_BUG) == 0) { in alc_init_locked()
4112 * would make path-MTU discovery hard as sender wouldn't get in alc_init_locked()
4114 * multi-fragmented frames on Rx path so it has no issue on in alc_init_locked()
4120 * accept from others - RFC 793. in alc_init_locked()
4122 CSR_WRITE_4(sc, ALC_FRAME_SIZE, sc->alc_ident->max_framelen); in alc_init_locked()
4124 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) == 0) { in alc_init_locked()
4138 /* Set parameters for half-duplex media. */ in alc_init_locked()
4155 reg = (sc->alc_ident->max_framelen >> TSO_OFFLOAD_THRESH_UNIT_SHIFT) & in alc_init_locked()
4157 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) in alc_init_locked()
4161 reg = (alc_dma_burst[sc->alc_dma_rd_burst] << in alc_init_locked()
4163 if (sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8152_B || in alc_init_locked()
4164 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8152_B2) in alc_init_locked()
4170 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) { in alc_init_locked()
4183 /* Configure Rx free descriptor pre-fetching. */ in alc_init_locked()
4196 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) { in alc_init_locked()
4201 reg -= RX_FIFO_PAUSE_816X_RSVD; in alc_init_locked()
4203 reg -= RX_BUF_SIZE_MAX; in alc_init_locked()
4211 } else if (sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8131 || in alc_init_locked()
4212 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8132) { in alc_init_locked()
4223 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) == 0) { in alc_init_locked()
4233 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) { in alc_init_locked()
4237 if ((sc->alc_flags & ALC_FLAG_FASTETHER) == 0) in alc_init_locked()
4240 if ((sc->alc_flags & ALC_FLAG_FASTETHER) == 0 && in alc_init_locked()
4241 sc->alc_ident->deviceid != DEVICEID_ATHEROS_AR8151_V2) in alc_init_locked()
4248 reg |= sc->alc_rcb; in alc_init_locked()
4249 if ((sc->alc_flags & ALC_FLAG_CMB_BUG) == 0) in alc_init_locked()
4251 if ((sc->alc_flags & ALC_FLAG_SMB_BUG) == 0) in alc_init_locked()
4255 reg |= (sc->alc_dma_rd_burst & DMA_CFG_RD_BURST_MASK) << in alc_init_locked()
4257 reg |= (sc->alc_dma_wr_burst & DMA_CFG_WR_BURST_MASK) << in alc_init_locked()
4263 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0) { in alc_init_locked()
4264 switch (AR816X_REV(sc->alc_rev)) { in alc_init_locked()
4280 * - Auto-padding for short frames. in alc_init_locked()
4281 * - Enable CRC generation. in alc_init_locked()
4294 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0 || in alc_init_locked()
4295 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8151 || in alc_init_locked()
4296 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8151_V2 || in alc_init_locked()
4297 sc->alc_ident->deviceid == DEVICEID_ATHEROS_AR8152_B2) in alc_init_locked()
4299 if ((sc->alc_flags & ALC_FLAG_FASTETHER) != 0) in alc_init_locked()
4317 sc->alc_flags &= ~ALC_FLAG_LINK; in alc_init_locked()
4321 callout_reset(&sc->alc_tick_ch, hz, alc_tick, sc); in alc_init_locked()
4337 ifp = sc->alc_ifp; in alc_stop()
4339 sc->alc_flags &= ~ALC_FLAG_LINK; in alc_stop()
4340 callout_stop(&sc->alc_tick_ch); in alc_stop()
4341 sc->alc_watchdog_timer = 0; in alc_stop()
4359 if (sc->alc_cdata.alc_rxhead != NULL) in alc_stop()
4360 m_freem(sc->alc_cdata.alc_rxhead); in alc_stop()
4366 rxd = &sc->alc_cdata.alc_rxdesc[i]; in alc_stop()
4367 if (rxd->rx_m != NULL) { in alc_stop()
4368 bus_dmamap_sync(sc->alc_cdata.alc_rx_tag, in alc_stop()
4369 rxd->rx_dmamap, BUS_DMASYNC_POSTREAD); in alc_stop()
4370 bus_dmamap_unload(sc->alc_cdata.alc_rx_tag, in alc_stop()
4371 rxd->rx_dmamap); in alc_stop()
4372 m_freem(rxd->rx_m); in alc_stop()
4373 rxd->rx_m = NULL; in alc_stop()
4377 txd = &sc->alc_cdata.alc_txdesc[i]; in alc_stop()
4378 if (txd->tx_m != NULL) { in alc_stop()
4379 bus_dmamap_sync(sc->alc_cdata.alc_tx_tag, in alc_stop()
4380 txd->tx_dmamap, BUS_DMASYNC_POSTWRITE); in alc_stop()
4381 bus_dmamap_unload(sc->alc_cdata.alc_tx_tag, in alc_stop()
4382 txd->tx_dmamap); in alc_stop()
4383 m_freem(txd->tx_m); in alc_stop()
4384 txd->tx_m = NULL; in alc_stop()
4402 for (i = ALC_TIMEOUT; i > 0; i--) { in alc_stop_mac()
4409 device_printf(sc->alc_dev, in alc_stop_mac()
4429 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) == 0) { in alc_start_queue()
4449 if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) == 0) { in alc_stop_queue()
4467 for (i = ALC_TIMEOUT; i > 0; i--) { in alc_stop_queue()
4474 device_printf(sc->alc_dev, in alc_stop_queue()
4487 sc->alc_cdata.alc_tx_prod = 0; in alc_init_tx_ring()
4488 sc->alc_cdata.alc_tx_cons = 0; in alc_init_tx_ring()
4489 sc->alc_cdata.alc_tx_cnt = 0; in alc_init_tx_ring()
4491 rd = &sc->alc_rdata; in alc_init_tx_ring()
4492 bzero(rd->alc_tx_ring, ALC_TX_RING_SZ); in alc_init_tx_ring()
4494 txd = &sc->alc_cdata.alc_txdesc[i]; in alc_init_tx_ring()
4495 txd->tx_m = NULL; in alc_init_tx_ring()
4498 bus_dmamap_sync(sc->alc_cdata.alc_tx_ring_tag, in alc_init_tx_ring()
4499 sc->alc_cdata.alc_tx_ring_map, BUS_DMASYNC_PREWRITE); in alc_init_tx_ring()
4511 sc->alc_cdata.alc_rx_cons = ALC_RX_RING_CNT - 1; in alc_init_rx_ring()
4512 sc->alc_morework = 0; in alc_init_rx_ring()
4513 rd = &sc->alc_rdata; in alc_init_rx_ring()
4514 bzero(rd->alc_rx_ring, ALC_RX_RING_SZ); in alc_init_rx_ring()
4516 rxd = &sc->alc_cdata.alc_rxdesc[i]; in alc_init_rx_ring()
4517 rxd->rx_m = NULL; in alc_init_rx_ring()
4518 rxd->rx_desc = &rd->alc_rx_ring[i]; in alc_init_rx_ring()
4528 bus_dmamap_sync(sc->alc_cdata.alc_rx_ring_tag, in alc_init_rx_ring()
4529 sc->alc_cdata.alc_rx_ring_map, BUS_DMASYNC_PREWRITE); in alc_init_rx_ring()
4531 CSR_WRITE_4(sc, ALC_MBOX_RD0_PROD_IDX, sc->alc_cdata.alc_rx_cons); in alc_init_rx_ring()
4543 sc->alc_cdata.alc_rr_cons = 0; in alc_init_rr_ring()
4546 rd = &sc->alc_rdata; in alc_init_rr_ring()
4547 bzero(rd->alc_rr_ring, ALC_RR_RING_SZ); in alc_init_rr_ring()
4548 bus_dmamap_sync(sc->alc_cdata.alc_rr_ring_tag, in alc_init_rr_ring()
4549 sc->alc_cdata.alc_rr_ring_map, in alc_init_rr_ring()
4560 rd = &sc->alc_rdata; in alc_init_cmb()
4561 bzero(rd->alc_cmb, ALC_CMB_SZ); in alc_init_cmb()
4562 bus_dmamap_sync(sc->alc_cdata.alc_cmb_tag, sc->alc_cdata.alc_cmb_map, in alc_init_cmb()
4573 rd = &sc->alc_rdata; in alc_init_smb()
4574 bzero(rd->alc_smb, ALC_SMB_SZ); in alc_init_smb()
4575 bus_dmamap_sync(sc->alc_cdata.alc_smb_tag, sc->alc_cdata.alc_smb_map, in alc_init_smb()
4587 ifp = sc->alc_ifp; in alc_rxvlan()
4617 ifp = sc->alc_ifp; in alc_rxfilter()
4651 if (error || req->newptr == NULL) in sysctl_int_range()
4682 KASSERT(sc->alc_buf_size <= MCLBYTES, ("incorrect cluster size")); in alc_debugnet_init()