Lines Matching refs:afep

167 #define	KIOIP	KSTAT_INTR_PTR(afep->afe_intrstat)
308 afe_t *afep; in afe_attach() local
403 afep = kmem_zalloc(sizeof (afe_t), KM_SLEEP); in afe_attach()
404 ddi_set_driver_private(dip, afep); in afe_attach()
407 if (ddi_get_iblock_cookie(dip, 0, &afep->afe_icookie) != DDI_SUCCESS) { in afe_attach()
410 kmem_free(afep, sizeof (afe_t)); in afe_attach()
414 afep->afe_dip = dip; in afe_attach()
415 afep->afe_cardp = cardp; in afe_attach()
416 afep->afe_phyaddr = -1; in afe_attach()
417 afep->afe_cachesize = cachesize; in afe_attach()
419 afep->afe_forcefiber = ddi_prop_get_int(DDI_DEV_T_ANY, dip, 0, in afe_attach()
422 mutex_init(&afep->afe_xmtlock, NULL, MUTEX_DRIVER, afep->afe_icookie); in afe_attach()
423 mutex_init(&afep->afe_intrlock, NULL, MUTEX_DRIVER, afep->afe_icookie); in afe_attach()
439 afep->afe_intrstat = kstat_create("afe", inst, "intr", "controller", in afe_attach()
441 if (afep->afe_intrstat == NULL) { in afe_attach()
445 kstat_install(afep->afe_intrstat); in afe_attach()
450 if ((afep->afe_mii = mii_alloc(afep, dip, &afe_mii_ops)) == NULL) { in afe_attach()
457 if (AFE_MODEL(afep) == MODEL_CENTAUR) { in afe_attach()
458 mii_set_pauseable(afep->afe_mii, B_TRUE, B_FALSE); in afe_attach()
460 mii_set_pauseable(afep->afe_mii, B_FALSE, B_FALSE); in afe_attach()
466 if (ddi_regs_map_setup(dip, 1, (caddr_t *)&afep->afe_regs, in afe_attach()
467 0, 0, &afe_devattr, &afep->afe_regshandle)) { in afe_attach()
475 if ((afe_allocrxring(afep) != DDI_SUCCESS) || in afe_attach()
476 (afe_alloctxring(afep) != DDI_SUCCESS)) { in afe_attach()
482 mutex_enter(&afep->afe_intrlock); in afe_attach()
483 mutex_enter(&afep->afe_xmtlock); in afe_attach()
484 if (!afe_initialize(afep)) { in afe_attach()
485 mutex_exit(&afep->afe_xmtlock); in afe_attach()
486 mutex_exit(&afep->afe_intrlock); in afe_attach()
489 mutex_exit(&afep->afe_xmtlock); in afe_attach()
490 mutex_exit(&afep->afe_intrlock); in afe_attach()
493 afep->afe_sromwidth = afe_sromwidth(afep); in afe_attach()
499 afe_getfactaddr(afep, afep->afe_curraddr); in afe_attach()
500 afep->afe_promisc = B_FALSE; in afe_attach()
503 (void) afe_m_unicst(afep, afep->afe_curraddr); in afe_attach()
504 (void) afe_m_multicst(afep, B_TRUE, afe_broadcast); in afe_attach()
509 if (ddi_add_intr(dip, 0, NULL, NULL, afe_intr, (caddr_t)afep) != in afe_attach()
523 macp->m_driver = afep; in afe_attach()
525 macp->m_src_addr = afep->afe_curraddr; in afe_attach()
531 if (mac_register(macp, &afep->afe_mh) == DDI_SUCCESS) { in afe_attach()
539 if (afep->afe_icookie != NULL) { in afe_attach()
540 ddi_remove_intr(dip, 0, afep->afe_icookie); in afe_attach()
542 if (afep->afe_intrstat) { in afe_attach()
543 kstat_delete(afep->afe_intrstat); in afe_attach()
545 mutex_destroy(&afep->afe_intrlock); in afe_attach()
546 mutex_destroy(&afep->afe_xmtlock); in afe_attach()
548 afe_freerxring(afep); in afe_attach()
549 afe_freetxring(afep); in afe_attach()
551 if (afep->afe_regshandle != NULL) { in afe_attach()
552 ddi_regs_map_free(&afep->afe_regshandle); in afe_attach()
554 kmem_free(afep, sizeof (afe_t)); in afe_attach()
561 afe_t *afep; in afe_detach() local
563 afep = ddi_get_driver_private(dip); in afe_detach()
564 if (afep == NULL) { in afe_detach()
572 if (mac_unregister(afep->afe_mh) != 0) { in afe_detach()
577 mutex_enter(&afep->afe_intrlock); in afe_detach()
578 mutex_enter(&afep->afe_xmtlock); in afe_detach()
579 afep->afe_flags &= ~AFE_RUNNING; in afe_detach()
580 afe_stopall(afep); in afe_detach()
581 mutex_exit(&afep->afe_xmtlock); in afe_detach()
582 mutex_exit(&afep->afe_intrlock); in afe_detach()
585 ddi_remove_intr(dip, 0, afep->afe_icookie); in afe_detach()
588 mii_free(afep->afe_mii); in afe_detach()
591 kstat_delete(afep->afe_intrstat); in afe_detach()
596 afe_freerxring(afep); in afe_detach()
597 afe_freetxring(afep); in afe_detach()
599 ddi_regs_map_free(&afep->afe_regshandle); in afe_detach()
600 mutex_destroy(&afep->afe_intrlock); in afe_detach()
601 mutex_destroy(&afep->afe_xmtlock); in afe_detach()
603 kmem_free(afep, sizeof (afe_t)); in afe_detach()
608 mii_suspend(afep->afe_mii); in afe_detach()
611 mutex_enter(&afep->afe_intrlock); in afe_detach()
612 mutex_enter(&afep->afe_xmtlock); in afe_detach()
613 afep->afe_flags |= AFE_SUSPENDED; in afe_detach()
614 afe_stopall(afep); in afe_detach()
615 mutex_exit(&afep->afe_xmtlock); in afe_detach()
616 mutex_exit(&afep->afe_intrlock); in afe_detach()
626 afe_t *afep; in afe_resume() local
628 if ((afep = ddi_get_driver_private(dip)) == NULL) { in afe_resume()
632 mutex_enter(&afep->afe_intrlock); in afe_resume()
633 mutex_enter(&afep->afe_xmtlock); in afe_resume()
635 afep->afe_flags &= ~AFE_SUSPENDED; in afe_resume()
638 if (!afe_initialize(afep)) { in afe_resume()
639 afe_error(afep->afe_dip, "unable to resume chip!"); in afe_resume()
640 afep->afe_flags |= AFE_SUSPENDED; in afe_resume()
641 mutex_exit(&afep->afe_intrlock); in afe_resume()
642 mutex_exit(&afep->afe_xmtlock); in afe_resume()
647 if (afep->afe_flags & AFE_RUNNING) { in afe_resume()
648 afe_startall(afep); in afe_resume()
652 mutex_exit(&afep->afe_xmtlock); in afe_resume()
653 mutex_exit(&afep->afe_intrlock); in afe_resume()
655 mii_resume(afep->afe_mii); in afe_resume()
663 afe_t *afep; in afe_quiesce() local
665 if ((afep = ddi_get_driver_private(dip)) == NULL) { in afe_quiesce()
669 SETBIT(afep, CSR_PAR, PAR_RESET); in afe_quiesce()
677 if ((GETCSR(afep, CSR_PAR) & PAR_RESET) == 0) { in afe_quiesce()
687 afe_setrxfilt(afe_t *afep) in afe_setrxfilt() argument
691 if (afep->afe_flags & AFE_SUSPENDED) { in afe_setrxfilt()
696 rxen = GETCSR(afep, CSR_NAR) & NAR_RX_ENABLE; in afe_setrxfilt()
700 afe_stopmac(afep); in afe_setrxfilt()
704 if (afep->afe_promisc) in afe_setrxfilt()
705 SETBIT(afep, CSR_NAR, NAR_RX_PROMISC); in afe_setrxfilt()
707 CLRBIT(afep, CSR_NAR, NAR_RX_PROMISC); in afe_setrxfilt()
710 pa0 = (afep->afe_curraddr[3] << 24) | (afep->afe_curraddr[2] << 16) | in afe_setrxfilt()
711 (afep->afe_curraddr[1] << 8) | afep->afe_curraddr[0]; in afe_setrxfilt()
712 pa1 = (afep->afe_curraddr[5] << 8) | afep->afe_curraddr[4]; in afe_setrxfilt()
714 PUTCSR(afep, CSR_PAR0, pa0); in afe_setrxfilt()
715 PUTCSR(afep, CSR_PAR1, pa1); in afe_setrxfilt()
717 SETBIT(afep, CSR_NAR, rxen); in afe_setrxfilt()
721 if (AFE_MODEL(afep) == MODEL_COMET) { in afe_setrxfilt()
722 if (afep->afe_mctab[0] || afep->afe_mctab[1]) { in afe_setrxfilt()
723 SETBIT(afep, CSR_NAR, NAR_RX_MULTI); in afe_setrxfilt()
725 CLRBIT(afep, CSR_NAR, NAR_RX_MULTI); in afe_setrxfilt()
728 CLRBIT(afep, CSR_NAR, NAR_RX_MULTI); in afe_setrxfilt()
729 PUTCSR(afep, CSR_MAR0, afep->afe_mctab[0]); in afe_setrxfilt()
730 PUTCSR(afep, CSR_MAR1, afep->afe_mctab[1]); in afe_setrxfilt()
735 afe_startmac(afep); in afe_setrxfilt()
740 afe_watchdog(afe_t *afep) in afe_watchdog() argument
742 if ((afep->afe_txstall_time != 0) && in afe_watchdog()
743 (gethrtime() > afep->afe_txstall_time) && in afe_watchdog()
744 (afep->afe_txavail != AFE_TXRING)) { in afe_watchdog()
745 afep->afe_txstall_time = 0; in afe_watchdog()
746 afe_error(afep->afe_dip, "TX stall detected!"); in afe_watchdog()
756 afe_t *afep = arg; in afe_m_multicst() local
769 mutex_enter(&afep->afe_intrlock); in afe_m_multicst()
770 mutex_enter(&afep->afe_xmtlock); in afe_m_multicst()
771 newval = oldval = afep->afe_mctab[index]; in afe_m_multicst()
774 afep->afe_mccount[crc]++; in afe_m_multicst()
775 if (afep->afe_mccount[crc] == 1) in afe_m_multicst()
778 afep->afe_mccount[crc]--; in afe_m_multicst()
779 if (afep->afe_mccount[crc] == 0) in afe_m_multicst()
783 afep->afe_mctab[index] = newval; in afe_m_multicst()
784 afe_setrxfilt(afep); in afe_m_multicst()
787 mutex_exit(&afep->afe_xmtlock); in afe_m_multicst()
788 mutex_exit(&afep->afe_intrlock); in afe_m_multicst()
796 afe_t *afep = arg; in afe_m_promisc() local
799 mutex_enter(&afep->afe_intrlock); in afe_m_promisc()
800 mutex_enter(&afep->afe_xmtlock); in afe_m_promisc()
802 afep->afe_promisc = on; in afe_m_promisc()
804 afe_setrxfilt(afep); in afe_m_promisc()
805 mutex_exit(&afep->afe_xmtlock); in afe_m_promisc()
806 mutex_exit(&afep->afe_intrlock); in afe_m_promisc()
814 afe_t *afep = arg; in afe_m_unicst() local
817 mutex_enter(&afep->afe_intrlock); in afe_m_unicst()
818 mutex_enter(&afep->afe_xmtlock); in afe_m_unicst()
820 bcopy(macaddr, afep->afe_curraddr, ETHERADDRL); in afe_m_unicst()
821 afe_setrxfilt(afep); in afe_m_unicst()
823 mutex_exit(&afep->afe_xmtlock); in afe_m_unicst()
824 mutex_exit(&afep->afe_intrlock); in afe_m_unicst()
832 afe_t *afep = arg; in afe_m_tx() local
835 mutex_enter(&afep->afe_xmtlock); in afe_m_tx()
837 if (afep->afe_flags & AFE_SUSPENDED) { in afe_m_tx()
839 afep->afe_carrier_errors++; in afe_m_tx()
843 mutex_exit(&afep->afe_xmtlock); in afe_m_tx()
851 if (!afe_send(afep, mp)) { in afe_m_tx()
857 mutex_exit(&afep->afe_xmtlock); in afe_m_tx()
865 afe_t *afep = arg; in afe_m_ioctl() local
867 if (mii_m_loop_ioctl(afep->afe_mii, wq, mp)) in afe_m_ioctl()
877 afe_initialize(afe_t *afep) in afe_initialize() argument
883 ASSERT(mutex_owned(&afep->afe_intrlock)); in afe_initialize()
884 ASSERT(mutex_owned(&afep->afe_xmtlock)); in afe_initialize()
886 SETBIT(afep, CSR_PAR, PAR_RESET); in afe_initialize()
889 val = GETCSR(afep, CSR_PAR); in afe_initialize()
895 afe_error(afep->afe_dip, "timed out waiting for reset!"); in afe_initialize()
906 switch (afep->afe_cachesize) { in afe_initialize()
923 PUTCSR(afep, CSR_PAR, par); in afe_initialize()
926 SETBIT(afep, CSR_CR, CR_TXURAUTOR); in afe_initialize()
928 afe_resetrings(afep); in afe_initialize()
931 (void) GETCSR(afep, CSR_LPC); in afe_initialize()
933 nar = GETCSR(afep, CSR_NAR); in afe_initialize()
937 PUTCSR(afep, CSR_NAR, nar); in afe_initialize()
939 afe_setrxfilt(afep); in afe_initialize()
949 afe_sromwidth(afe_t *afep) in afe_sromwidth() argument
957 PUTCSR(afep, CSR_SPR, eeread & ~SPR_SROM_CHIP); in afe_sromwidth()
959 PUTCSR(afep, CSR_SPR, eeread); in afe_sromwidth()
965 PUTCSR(afep, CSR_SPR, eeread | val); in afe_sromwidth()
967 PUTCSR(afep, CSR_SPR, eeread | val | SPR_SROM_CLOCK); in afe_sromwidth()
971 PUTCSR(afep, CSR_SPR, eeread); in afe_sromwidth()
974 PUTCSR(afep, CSR_SPR, eeread | SPR_SROM_CLOCK); in afe_sromwidth()
976 if (!(GETCSR(afep, CSR_SPR) & SPR_SROM_DOUT)) { in afe_sromwidth()
977 PUTCSR(afep, CSR_SPR, eeread); in afe_sromwidth()
981 PUTCSR(afep, CSR_SPR, eeread); in afe_sromwidth()
986 PUTCSR(afep, CSR_SPR, eeread &~ SPR_SROM_CHIP); in afe_sromwidth()
997 afe_readsromword(afe_t *afep, unsigned romaddr) in afe_readsromword() argument
1008 addrlen = afep->afe_sromwidth; in afe_readsromword()
1016 PUTCSR(afep, CSR_SPR, eeread & ~SPR_SROM_CHIP); in afe_readsromword()
1017 PUTCSR(afep, CSR_SPR, eeread); in afe_readsromword()
1023 PUTCSR(afep, CSR_SPR, eeread | val); in afe_readsromword()
1025 PUTCSR(afep, CSR_SPR, eeread | val | SPR_SROM_CLOCK); in afe_readsromword()
1029 PUTCSR(afep, CSR_SPR, eeread); in afe_readsromword()
1032 PUTCSR(afep, CSR_SPR, eeread | SPR_SROM_CLOCK); in afe_readsromword()
1035 if (GETCSR(afep, CSR_SPR) & SPR_SROM_DOUT) { in afe_readsromword()
1038 PUTCSR(afep, CSR_SPR, eeread); in afe_readsromword()
1043 PUTCSR(afep, CSR_SPR, eeread &~ SPR_SROM_CHIP); in afe_readsromword()
1055 afe_readsrom(afe_t *afep, unsigned romaddr, unsigned len, char *dest) in afe_readsrom() argument
1061 word = afe_readsromword(afep, romaddr + i); in afe_readsrom()
1068 afe_getfactaddr(afe_t *afep, uchar_t *eaddr) in afe_getfactaddr() argument
1070 afe_readsrom(afep, SROM_ENADDR, ETHERADDRL / 2, (char *)eaddr); in afe_getfactaddr()
1081 afe_t *afep = arg; in afe_mii_reset() local
1091 if ((mii_get_id(afep->afe_mii) & 0xfffffff0) != 0x225410) { in afe_mii_reset()
1096 phyaddr = mii_get_addr(afep->afe_mii); in afe_mii_reset()
1100 switch (afep->afe_forcefiber) { in afe_mii_reset()
1111 mcr = afe_mii_read(afep, phyaddr, PHY_MCR); in afe_mii_reset()
1121 afe_mii_write(afep, phyaddr, PHY_MCR, mcr); in afe_mii_reset()
1128 pilr = afe_mii_read(afep, phyaddr, PHY_PILR); in afe_mii_reset()
1130 afe_mii_write(afep, phyaddr, PHY_PILR, pilr); in afe_mii_reset()
1136 afe_t *afep = arg; in afe_mii_notify() local
1138 if (AFE_MODEL(afep) == MODEL_CENTAUR) { in afe_mii_notify()
1139 if (mii_get_flowctrl(afep->afe_mii) == LINK_FLOWCTRL_BI) { in afe_mii_notify()
1140 SETBIT(afep, CSR_CR, CR_PAUSE); in afe_mii_notify()
1142 CLRBIT(afep, CSR_CR, CR_PAUSE); in afe_mii_notify()
1145 mac_link_update(afep->afe_mh, link); in afe_mii_notify()
1149 afe_miitristate(afe_t *afep) in afe_miitristate() argument
1153 PUTCSR(afep, CSR_SPR, val); in afe_miitristate()
1155 PUTCSR(afep, CSR_SPR, val | SPR_MII_CLOCK); in afe_miitristate()
1160 afe_miiwritebit(afe_t *afep, uint8_t bit) in afe_miiwritebit() argument
1164 PUTCSR(afep, CSR_SPR, val); in afe_miiwritebit()
1166 PUTCSR(afep, CSR_SPR, val | SPR_MII_CLOCK); in afe_miiwritebit()
1171 afe_miireadbit(afe_t *afep) in afe_miireadbit() argument
1176 PUTCSR(afep, CSR_SPR, val); in afe_miireadbit()
1178 bit = (GETCSR(afep, CSR_SPR) & SPR_MII_DIN) ? 1 : 0; in afe_miireadbit()
1179 PUTCSR(afep, CSR_SPR, val | SPR_MII_CLOCK); in afe_miireadbit()
1187 afe_t *afep = arg; in afe_mii_read() local
1195 switch (AFE_MODEL(afep)) { in afe_mii_read()
1197 return (afe_miireadcomet(afep, phy, reg)); in afe_mii_read()
1199 return (afe_miireadgeneral(afep, phy, reg)); in afe_mii_read()
1205 afe_miireadgeneral(afe_t *afep, uint8_t phy, uint8_t reg) in afe_miireadgeneral() argument
1212 afe_miiwritebit(afep, 1); in afe_miireadgeneral()
1216 afe_miiwritebit(afep, 0); in afe_miireadgeneral()
1217 afe_miiwritebit(afep, 1); in afe_miireadgeneral()
1220 afe_miiwritebit(afep, 1); in afe_miireadgeneral()
1221 afe_miiwritebit(afep, 0); in afe_miireadgeneral()
1225 afe_miiwritebit(afep, (phy & i) ? 1 : 0); in afe_miireadgeneral()
1230 afe_miiwritebit(afep, (reg & i) ? 1 : 0); in afe_miireadgeneral()
1234 afe_miitristate(afep); in afe_miireadgeneral()
1235 afe_miiwritebit(afep, 0); in afe_miireadgeneral()
1240 value |= afe_miireadbit(afep); in afe_miireadgeneral()
1242 afe_miitristate(afep); in afe_miireadgeneral()
1247 afe_miireadcomet(afe_t *afep, uint8_t phy, uint8_t reg) in afe_miireadcomet() argument
1277 return (GETCSR16(afep, reg) & 0xFFFF); in afe_miireadcomet()
1283 afe_t *afep = arg; in afe_mii_write() local
1292 switch (AFE_MODEL(afep)) { in afe_mii_write()
1294 afe_miiwritecomet(afep, phy, reg, val); in afe_mii_write()
1297 afe_miiwritegeneral(afep, phy, reg, val); in afe_mii_write()
1303 afe_miiwritegeneral(afe_t *afep, uint8_t phy, uint8_t reg, uint16_t val) in afe_miiwritegeneral() argument
1309 afe_miiwritebit(afep, 1); in afe_miiwritegeneral()
1313 afe_miiwritebit(afep, 0); in afe_miiwritegeneral()
1314 afe_miiwritebit(afep, 1); in afe_miiwritegeneral()
1317 afe_miiwritebit(afep, 0); in afe_miiwritegeneral()
1318 afe_miiwritebit(afep, 1); in afe_miiwritegeneral()
1322 afe_miiwritebit(afep, (phy & i) ? 1 : 0); in afe_miiwritegeneral()
1327 afe_miiwritebit(afep, (reg & i) ? 1 : 0); in afe_miiwritegeneral()
1331 afe_miiwritebit(afep, 1); in afe_miiwritegeneral()
1332 afe_miiwritebit(afep, 0); in afe_miiwritegeneral()
1336 afe_miiwritebit(afep, (val & i) ? 1 : 0); in afe_miiwritegeneral()
1340 afe_miitristate(afep); in afe_miiwritegeneral()
1344 afe_miiwritecomet(afe_t *afep, uint8_t phy, uint8_t reg, uint16_t val) in afe_miiwritecomet() argument
1374 PUTCSR16(afep, reg, val); in afe_miiwritecomet()
1380 afe_t *afep = arg; in afe_m_start() local
1383 mutex_enter(&afep->afe_intrlock); in afe_m_start()
1384 mutex_enter(&afep->afe_xmtlock); in afe_m_start()
1386 afe_startall(afep); in afe_m_start()
1387 afep->afe_flags |= AFE_RUNNING; in afe_m_start()
1389 mutex_exit(&afep->afe_xmtlock); in afe_m_start()
1390 mutex_exit(&afep->afe_intrlock); in afe_m_start()
1392 mii_start(afep->afe_mii); in afe_m_start()
1400 afe_t *afep = arg; in afe_m_stop() local
1402 mii_stop(afep->afe_mii); in afe_m_stop()
1405 mutex_enter(&afep->afe_intrlock); in afe_m_stop()
1406 mutex_enter(&afep->afe_xmtlock); in afe_m_stop()
1408 afe_stopall(afep); in afe_m_stop()
1409 afep->afe_flags &= ~AFE_RUNNING; in afe_m_stop()
1411 mutex_exit(&afep->afe_xmtlock); in afe_m_stop()
1412 mutex_exit(&afep->afe_intrlock); in afe_m_stop()
1416 afe_startmac(afe_t *afep) in afe_startmac() argument
1419 ASSERT(mutex_owned(&afep->afe_intrlock)); in afe_startmac()
1420 ASSERT(mutex_owned(&afep->afe_xmtlock)); in afe_startmac()
1423 SETBIT(afep, CSR_NAR, NAR_TX_ENABLE | NAR_RX_ENABLE); in afe_startmac()
1425 if (afep->afe_txavail != AFE_TXRING) in afe_startmac()
1426 PUTCSR(afep, CSR_TDR, 0); in afe_startmac()
1429 if (afep->afe_flags & AFE_RUNNING) in afe_startmac()
1430 mac_tx_update(afep->afe_mh); in afe_startmac()
1433 PUTCSR(afep, CSR_TIMER, TIMER_LOOP | in afe_startmac()
1438 afe_stopmac(afe_t *afep) in afe_stopmac() argument
1443 ASSERT(mutex_owned(&afep->afe_intrlock)); in afe_stopmac()
1444 ASSERT(mutex_owned(&afep->afe_xmtlock)); in afe_stopmac()
1446 CLRBIT(afep, CSR_NAR, NAR_TX_ENABLE | NAR_RX_ENABLE); in afe_stopmac()
1458 if ((GETCSR(afep, CSR_SR) & (SR_TX_STATE | SR_RX_STATE)) == 0) in afe_stopmac()
1464 PUTCSR(afep, CSR_SR2, INT_RXSTOPPED | INT_TXSTOPPED); in afe_stopmac()
1467 PUTCSR(afep, CSR_TIMER, 0); in afe_stopmac()
1471 afe_resetrings(afe_t *afep) in afe_resetrings() argument
1476 PUTCSR(afep, CSR_RDB, 0); in afe_resetrings()
1477 PUTCSR(afep, CSR_TDB, 0); in afe_resetrings()
1480 afep->afe_rxhead = 0; in afe_resetrings()
1481 afep->afe_txreclaim = 0; in afe_resetrings()
1482 afep->afe_txsend = 0; in afe_resetrings()
1483 afep->afe_txavail = AFE_TXRING; in afe_resetrings()
1487 afe_desc_t *tmdp = &afep->afe_txdescp[i]; in afe_resetrings()
1492 PUTTXDESC(afep, tmdp->desc_status, 0); in afe_resetrings()
1493 PUTTXDESC(afep, tmdp->desc_control, control); in afe_resetrings()
1494 PUTTXDESC(afep, tmdp->desc_buffer1, 0); in afe_resetrings()
1495 PUTTXDESC(afep, tmdp->desc_buffer2, 0); in afe_resetrings()
1496 SYNCTXDESC(afep, i, DDI_DMA_SYNC_FORDEV); in afe_resetrings()
1498 PUTCSR(afep, CSR_TDB, afep->afe_txdesc_paddr); in afe_resetrings()
1502 afe_rxbuf_t *rxb = afep->afe_rxbufs[i]; in afe_resetrings()
1503 afe_desc_t *rmdp = &afep->afe_rxdescp[i]; in afe_resetrings()
1510 PUTRXDESC(afep, rmdp->desc_buffer1, rxb->rxb_paddr); in afe_resetrings()
1511 PUTRXDESC(afep, rmdp->desc_buffer2, 0); in afe_resetrings()
1512 PUTRXDESC(afep, rmdp->desc_control, control); in afe_resetrings()
1513 PUTRXDESC(afep, rmdp->desc_status, RXSTAT_OWN); in afe_resetrings()
1514 SYNCRXDESC(afep, i, DDI_DMA_SYNC_FORDEV); in afe_resetrings()
1516 PUTCSR(afep, CSR_RDB, afep->afe_rxdesc_paddr); in afe_resetrings()
1520 afe_stopall(afe_t *afep) in afe_stopall() argument
1522 afe_disableinterrupts(afep); in afe_stopall()
1523 afe_stopmac(afep); in afe_stopall()
1527 afe_startall(afe_t *afep) in afe_startall() argument
1529 ASSERT(mutex_owned(&afep->afe_intrlock)); in afe_startall()
1530 ASSERT(mutex_owned(&afep->afe_xmtlock)); in afe_startall()
1533 afe_disableinterrupts(afep); in afe_startall()
1536 (void) afe_initialize(afep); in afe_startall()
1539 afe_enableinterrupts(afep); in afe_startall()
1542 afe_startmac(afep); in afe_startall()
1546 afe_resetall(afe_t *afep) in afe_resetall() argument
1548 afe_stopall(afep); in afe_resetall()
1549 afe_startall(afep); in afe_resetall()
1553 afe_alloctxbuf(afe_t *afep) in afe_alloctxbuf() argument
1562 if (ddi_dma_alloc_handle(afep->afe_dip, &afe_dma_txattr, in afe_alloctxbuf()
1597 afe_allocrxbuf(afe_t *afep) in afe_allocrxbuf() argument
1606 if (ddi_dma_alloc_handle(afep->afe_dip, &afe_dma_attr, in afe_allocrxbuf()
1646 afe_allocrxring(afe_t *afep) in afe_allocrxring() argument
1658 rval = ddi_dma_alloc_handle(afep->afe_dip, &afe_dma_attr, in afe_allocrxring()
1659 DDI_DMA_SLEEP, NULL, &afep->afe_rxdesc_dmah); in afe_allocrxring()
1661 afe_error(afep->afe_dip, in afe_allocrxring()
1666 rval = ddi_dma_mem_alloc(afep->afe_rxdesc_dmah, size, &afe_devattr, in afe_allocrxring()
1668 &afep->afe_rxdesc_acch); in afe_allocrxring()
1670 afe_error(afep->afe_dip, in afe_allocrxring()
1675 rval = ddi_dma_addr_bind_handle(afep->afe_rxdesc_dmah, NULL, kaddr, in afe_allocrxring()
1679 afe_error(afep->afe_dip, in afe_allocrxring()
1688 afep->afe_rxdesc_paddr = dmac.dmac_address; in afe_allocrxring()
1689 afep->afe_rxdescp = (void *)kaddr; in afe_allocrxring()
1692 afep->afe_rxbufs = kmem_zalloc(AFE_RXRING * sizeof (afe_rxbuf_t *), in afe_allocrxring()
1697 afe_rxbuf_t *rxb = afe_allocrxbuf(afep); in afe_allocrxring()
1700 afep->afe_rxbufs[i] = rxb; in afe_allocrxring()
1710 afe_alloctxring(afe_t *afep) in afe_alloctxring() argument
1722 rval = ddi_dma_alloc_handle(afep->afe_dip, &afe_dma_attr, in afe_alloctxring()
1723 DDI_DMA_SLEEP, NULL, &afep->afe_txdesc_dmah); in afe_alloctxring()
1725 afe_error(afep->afe_dip, in afe_alloctxring()
1730 rval = ddi_dma_mem_alloc(afep->afe_txdesc_dmah, size, &afe_devattr, in afe_alloctxring()
1732 &afep->afe_txdesc_acch); in afe_alloctxring()
1734 afe_error(afep->afe_dip, in afe_alloctxring()
1739 rval = ddi_dma_addr_bind_handle(afep->afe_txdesc_dmah, NULL, kaddr, in afe_alloctxring()
1743 afe_error(afep->afe_dip, in afe_alloctxring()
1752 afep->afe_txdesc_paddr = dmac.dmac_address; in afe_alloctxring()
1753 afep->afe_txdescp = (void *)kaddr; in afe_alloctxring()
1756 afep->afe_txbufs = kmem_zalloc(AFE_TXRING * sizeof (afe_txbuf_t *), in afe_alloctxring()
1761 afe_txbuf_t *txb = afe_alloctxbuf(afep); in afe_alloctxring()
1764 afep->afe_txbufs[i] = txb; in afe_alloctxring()
1771 afe_freerxring(afe_t *afep) in afe_freerxring() argument
1775 if (afep->afe_rxbufs) { in afe_freerxring()
1777 afe_destroyrxbuf(afep->afe_rxbufs[i]); in afe_freerxring()
1780 kmem_free(afep->afe_rxbufs, in afe_freerxring()
1784 if (afep->afe_rxdesc_paddr) in afe_freerxring()
1785 (void) ddi_dma_unbind_handle(afep->afe_rxdesc_dmah); in afe_freerxring()
1786 if (afep->afe_rxdesc_acch) in afe_freerxring()
1787 ddi_dma_mem_free(&afep->afe_rxdesc_acch); in afe_freerxring()
1788 if (afep->afe_rxdesc_dmah) in afe_freerxring()
1789 ddi_dma_free_handle(&afep->afe_rxdesc_dmah); in afe_freerxring()
1793 afe_freetxring(afe_t *afep) in afe_freetxring() argument
1797 if (afep->afe_txbufs) { in afe_freetxring()
1799 afe_destroytxbuf(afep->afe_txbufs[i]); in afe_freetxring()
1802 kmem_free(afep->afe_txbufs, in afe_freetxring()
1805 if (afep->afe_txdesc_paddr) in afe_freetxring()
1806 (void) ddi_dma_unbind_handle(afep->afe_txdesc_dmah); in afe_freetxring()
1807 if (afep->afe_txdesc_acch) in afe_freetxring()
1808 ddi_dma_mem_free(&afep->afe_txdesc_acch); in afe_freetxring()
1809 if (afep->afe_txdesc_dmah) in afe_freetxring()
1810 ddi_dma_free_handle(&afep->afe_txdesc_dmah); in afe_freetxring()
1819 afe_t *afep = (void *)arg; in afe_intr() local
1824 mutex_enter(&afep->afe_intrlock); in afe_intr()
1826 if (afep->afe_flags & AFE_SUSPENDED) { in afe_intr()
1828 mutex_exit(&afep->afe_intrlock); in afe_intr()
1833 status = GETCSR(afep, CSR_SR2) & INT_ALL; in afe_intr()
1837 mutex_exit(&afep->afe_intrlock); in afe_intr()
1841 PUTCSR(afep, CSR_SR2, status); in afe_intr()
1844 if (!(afep->afe_flags & AFE_RUNNING)) { in afe_intr()
1846 mutex_exit(&afep->afe_intrlock); in afe_intr()
1852 mp = afe_receive(afep); in afe_intr()
1854 PUTCSR(afep, CSR_RDR, 0); /* wake up chip */ in afe_intr()
1859 mutex_enter(&afep->afe_xmtlock); in afe_intr()
1860 afe_reclaim(afep); in afe_intr()
1861 mutex_exit(&afep->afe_xmtlock); in afe_intr()
1864 if ((status & INT_TIMER) && (afe_watchdog(afep) != DDI_SUCCESS)) { in afe_intr()
1872 afep->afe_jabber++; in afe_intr()
1878 switch (GETCSR(afep, CSR_SR) & SR_BERR_TYPE) { in afe_intr()
1880 afe_error(afep->afe_dip, "PCI parity error"); in afe_intr()
1883 afe_error(afep->afe_dip, "PCI target abort"); in afe_intr()
1886 afe_error(afep->afe_dip, "PCI master abort"); in afe_intr()
1889 afe_error(afep->afe_dip, "Unknown PCI error"); in afe_intr()
1899 mutex_enter(&afep->afe_xmtlock); in afe_intr()
1900 afe_resetall(afep); in afe_intr()
1901 mutex_exit(&afep->afe_xmtlock); in afe_intr()
1902 mutex_exit(&afep->afe_intrlock); in afe_intr()
1904 mii_reset(afep->afe_mii); in afe_intr()
1906 mutex_exit(&afep->afe_intrlock); in afe_intr()
1910 mii_check(afep->afe_mii); in afe_intr()
1917 mac_rx(afep->afe_mh, NULL, mp); in afe_intr()
1924 afe_enableinterrupts(afe_t *afep) in afe_enableinterrupts() argument
1928 if (afep->afe_wantw) in afe_enableinterrupts()
1931 PUTCSR(afep, CSR_IER2, mask); in afe_enableinterrupts()
1933 if (AFE_MODEL(afep) == MODEL_COMET) { in afe_enableinterrupts()
1939 PUTCSR16(afep, CSR_XIE, XIE_LDE | XIE_ANCE); in afe_enableinterrupts()
1944 afe_disableinterrupts(afe_t *afep) in afe_disableinterrupts() argument
1947 PUTCSR(afep, CSR_IER2, INT_NONE); in afe_disableinterrupts()
1950 PUTCSR(afep, CSR_SR2, INT_ALL); in afe_disableinterrupts()
1954 afe_send(afe_t *afep, mblk_t *mp) in afe_send() argument
1962 ASSERT(mutex_owned(&afep->afe_xmtlock)); in afe_send()
1967 afep->afe_macxmt_errors++; in afe_send()
1972 if (afep->afe_txavail < AFE_TXRECLAIM) in afe_send()
1973 afe_reclaim(afep); in afe_send()
1975 if (afep->afe_txavail == 0) { in afe_send()
1977 afep->afe_wantw = B_TRUE; in afe_send()
1979 afe_enableinterrupts(afep); in afe_send()
1983 txsend = afep->afe_txsend; in afe_send()
1990 txb = afep->afe_txbufs[txsend]; in afe_send()
1996 afep->afe_opackets++; in afe_send()
1997 afep->afe_obytes += len; in afe_send()
2000 afep->afe_multixmt++; in afe_send()
2002 afep->afe_brdcstxmt++; in afe_send()
2011 tmd = &afep->afe_txdescp[txsend]; in afe_send()
2014 PUTTXDESC(afep, tmd->desc_control, control); in afe_send()
2015 PUTTXDESC(afep, tmd->desc_buffer1, txb->txb_paddr); in afe_send()
2016 PUTTXDESC(afep, tmd->desc_buffer2, 0); in afe_send()
2017 PUTTXDESC(afep, tmd->desc_status, TXSTAT_OWN); in afe_send()
2019 SYNCTXDESC(afep, txsend, DDI_DMA_SYNC_FORDEV); in afe_send()
2024 afep->afe_txavail--; in afe_send()
2025 afep->afe_txsend = (txsend + 1) % AFE_TXRING; in afe_send()
2031 afep->afe_txstall_time = gethrtime() + (5 * 1000000000ULL); in afe_send()
2037 PUTCSR(afep, CSR_TDR, 0); in afe_send()
2046 afe_reclaim(afe_t *afep) in afe_reclaim() argument
2050 while (afep->afe_txavail != AFE_TXRING) { in afe_reclaim()
2053 int index = afep->afe_txreclaim; in afe_reclaim()
2055 tmdp = &afep->afe_txdescp[index]; in afe_reclaim()
2058 SYNCTXDESC(afep, index, DDI_DMA_SYNC_FORKERNEL); in afe_reclaim()
2060 control = GETTXDESC(afep, tmdp->desc_control); in afe_reclaim()
2061 status = GETTXDESC(afep, tmdp->desc_status); in afe_reclaim()
2068 afep->afe_txavail++; in afe_reclaim()
2069 afep->afe_txreclaim = (index + 1) % AFE_TXRING; in afe_reclaim()
2079 afep->afe_errxmt++; in afe_reclaim()
2083 afep->afe_macxmt_errors++; in afe_reclaim()
2087 afep->afe_carrier_errors++; in afe_reclaim()
2090 afep->afe_underflow++; in afe_reclaim()
2093 afep->afe_tx_late_collisions++; in afe_reclaim()
2096 afep->afe_ex_collisions++; in afe_reclaim()
2097 afep->afe_collisions += 16; in afe_reclaim()
2102 afep->afe_defer_xmts++; in afe_reclaim()
2107 afep->afe_collisions++; in afe_reclaim()
2108 afep->afe_first_collisions++; in afe_reclaim()
2110 afep->afe_collisions += TXCOLLCNT(status); in afe_reclaim()
2111 afep->afe_multi_collisions += TXCOLLCNT(status); in afe_reclaim()
2115 if (afep->afe_txavail >= AFE_TXRESCHED) { in afe_reclaim()
2116 if (afep->afe_wantw) { in afe_reclaim()
2121 afep->afe_wantw = B_FALSE; in afe_reclaim()
2122 afe_enableinterrupts(afep); in afe_reclaim()
2123 mac_tx_update(afep->afe_mh); in afe_reclaim()
2129 afe_receive(afe_t *afep) in afe_receive() argument
2140 head = afep->afe_rxhead; in afe_receive()
2145 rmd = &afep->afe_rxdescp[head]; in afe_receive()
2146 rxb = afep->afe_rxbufs[head]; in afe_receive()
2148 SYNCRXDESC(afep, head, DDI_DMA_SYNC_FORKERNEL); in afe_receive()
2149 status = GETRXDESC(afep, rmd->desc_status); in afe_receive()
2161 afep->afe_errrcv++; in afe_receive()
2170 afep->afe_toolong_errors++; in afe_receive()
2173 afep->afe_macrcv_errors++; in afe_receive()
2176 afep->afe_runt++; in afe_receive()
2180 afep->afe_macrcv_errors++; in afe_receive()
2183 afep->afe_align_errors++; in afe_receive()
2186 afep->afe_fcs_errors++; in afe_receive()
2189 afep->afe_overflow++; in afe_receive()
2194 afep->afe_errrcv++; in afe_receive()
2195 afep->afe_toolong_errors++; in afe_receive()
2204 afep->afe_errrcv++; in afe_receive()
2205 afep->afe_norcvbuf++; in afe_receive()
2215 afep->afe_ipackets++; in afe_receive()
2216 afep->afe_rbytes += len; in afe_receive()
2220 afep->afe_brdcstrcv++; in afe_receive()
2222 afep->afe_multircv++; in afe_receive()
2230 PUTRXDESC(afep, rmd->desc_status, RXSTAT_OWN); in afe_receive()
2231 SYNCRXDESC(afep, head, DDI_DMA_SYNC_FORDEV); in afe_receive()
2237 afep->afe_rxhead = head; in afe_receive()
2245 afe_t *afep = arg; in afe_m_stat() local
2247 mutex_enter(&afep->afe_xmtlock); in afe_m_stat()
2248 if ((afep->afe_flags & (AFE_RUNNING|AFE_SUSPENDED)) == AFE_RUNNING) in afe_m_stat()
2249 afe_reclaim(afep); in afe_m_stat()
2250 mutex_exit(&afep->afe_xmtlock); in afe_m_stat()
2252 if (mii_m_getstat(afep->afe_mii, stat, val) == 0) { in afe_m_stat()
2257 *val = afep->afe_multircv; in afe_m_stat()
2261 *val = afep->afe_brdcstrcv; in afe_m_stat()
2265 *val = afep->afe_multixmt; in afe_m_stat()
2269 *val = afep->afe_brdcstxmt; in afe_m_stat()
2273 *val = afep->afe_ipackets; in afe_m_stat()
2277 *val = afep->afe_rbytes; in afe_m_stat()
2281 *val = afep->afe_opackets; in afe_m_stat()
2285 *val = afep->afe_obytes; in afe_m_stat()
2289 *val = afep->afe_norcvbuf; in afe_m_stat()
2297 *val = afep->afe_collisions; in afe_m_stat()
2301 *val = afep->afe_errrcv; in afe_m_stat()
2305 *val = afep->afe_errxmt; in afe_m_stat()
2309 *val = afep->afe_align_errors; in afe_m_stat()
2313 *val = afep->afe_fcs_errors; in afe_m_stat()
2317 *val = afep->afe_sqe_errors; in afe_m_stat()
2321 *val = afep->afe_defer_xmts; in afe_m_stat()
2325 *val = afep->afe_first_collisions; in afe_m_stat()
2329 *val = afep->afe_multi_collisions; in afe_m_stat()
2333 *val = afep->afe_tx_late_collisions; in afe_m_stat()
2337 *val = afep->afe_ex_collisions; in afe_m_stat()
2341 *val = afep->afe_macxmt_errors; in afe_m_stat()
2345 *val = afep->afe_carrier_errors; in afe_m_stat()
2349 *val = afep->afe_toolong_errors; in afe_m_stat()
2353 *val = afep->afe_macrcv_errors; in afe_m_stat()
2357 *val = afep->afe_overflow; in afe_m_stat()
2361 *val = afep->afe_underflow; in afe_m_stat()
2365 *val = afep->afe_runt; in afe_m_stat()
2369 *val = afep->afe_jabber; in afe_m_stat()
2382 afe_t *afep = arg; in afe_m_getprop() local
2384 return (mii_m_getprop(afep->afe_mii, name, num, sz, val)); in afe_m_getprop()
2391 afe_t *afep = arg; in afe_m_setprop() local
2393 return (mii_m_setprop(afep->afe_mii, name, num, sz, val)); in afe_m_setprop()
2400 afe_t *afep = arg; in afe_m_propinfo() local
2402 mii_m_propinfo(afep->afe_mii, name, num, prh); in afe_m_propinfo()