Lines Matching refs:sc

196 #define	FFEC_LOCK(sc)			mtx_lock(&(sc)->mtx)  argument
197 #define FFEC_UNLOCK(sc) mtx_unlock(&(sc)->mtx) argument
198 #define FFEC_LOCK_INIT(sc) mtx_init(&(sc)->mtx, \ argument
199 device_get_nameunit((sc)->dev), MTX_NETWORK_LOCK, MTX_DEF)
200 #define FFEC_LOCK_DESTROY(sc) mtx_destroy(&(sc)->mtx); argument
201 #define FFEC_ASSERT_LOCKED(sc) mtx_assert(&(sc)->mtx, MA_OWNED); argument
202 #define FFEC_ASSERT_UNLOCKED(sc) mtx_assert(&(sc)->mtx, MA_NOTOWNED); argument
204 static void ffec_init_locked(struct ffec_softc *sc);
205 static void ffec_stop_locked(struct ffec_softc *sc);
206 static void ffec_txstart_locked(struct ffec_softc *sc);
207 static void ffec_txfinish_locked(struct ffec_softc *sc);
210 RD2(struct ffec_softc *sc, bus_size_t off) in RD2() argument
213 return (bus_read_2(sc->mem_res, off)); in RD2()
217 WR2(struct ffec_softc *sc, bus_size_t off, uint16_t val) in WR2() argument
220 bus_write_2(sc->mem_res, off, val); in WR2()
224 RD4(struct ffec_softc *sc, bus_size_t off) in RD4() argument
227 return (bus_read_4(sc->mem_res, off)); in RD4()
231 WR4(struct ffec_softc *sc, bus_size_t off, uint32_t val) in WR4() argument
234 bus_write_4(sc->mem_res, off, val); in WR4()
238 next_rxidx(struct ffec_softc *sc, uint32_t curidx) in next_rxidx() argument
245 next_txidx(struct ffec_softc *sc, uint32_t curidx) in next_txidx() argument
261 ffec_miigasket_setup(struct ffec_softc *sc) in ffec_miigasket_setup() argument
269 switch (sc->fectype) in ffec_miigasket_setup()
277 switch (sc->phy_conn_type) in ffec_miigasket_setup()
293 WR2(sc, FEC_MIIGSK_ENR, 0); in ffec_miigasket_setup()
294 while (RD2(sc, FEC_MIIGSK_ENR) & FEC_MIIGSK_ENR_READY) in ffec_miigasket_setup()
297 WR2(sc, FEC_MIIGSK_CFGR, ifmode); in ffec_miigasket_setup()
299 WR2(sc, FEC_MIIGSK_ENR, FEC_MIIGSK_ENR_EN); in ffec_miigasket_setup()
300 while (!(RD2(sc, FEC_MIIGSK_ENR) & FEC_MIIGSK_ENR_READY)) in ffec_miigasket_setup()
305 ffec_miibus_iowait(struct ffec_softc *sc) in ffec_miibus_iowait() argument
310 if (RD4(sc, FEC_IER_REG) & FEC_IER_MII) in ffec_miibus_iowait()
319 struct ffec_softc *sc; in ffec_miibus_readreg() local
322 sc = device_get_softc(dev); in ffec_miibus_readreg()
324 WR4(sc, FEC_IER_REG, FEC_IER_MII); in ffec_miibus_readreg()
326 WR4(sc, FEC_MMFR_REG, FEC_MMFR_OP_READ | in ffec_miibus_readreg()
331 if (!ffec_miibus_iowait(sc)) { in ffec_miibus_readreg()
336 val = RD4(sc, FEC_MMFR_REG) & FEC_MMFR_DATA_MASK; in ffec_miibus_readreg()
344 struct ffec_softc *sc; in ffec_miibus_writereg() local
346 sc = device_get_softc(dev); in ffec_miibus_writereg()
348 WR4(sc, FEC_IER_REG, FEC_IER_MII); in ffec_miibus_writereg()
350 WR4(sc, FEC_MMFR_REG, FEC_MMFR_OP_WRITE | in ffec_miibus_writereg()
356 if (!ffec_miibus_iowait(sc)) { in ffec_miibus_writereg()
367 struct ffec_softc *sc; in ffec_miibus_statchg() local
376 sc = device_get_softc(dev); in ffec_miibus_statchg()
378 FFEC_ASSERT_LOCKED(sc); in ffec_miibus_statchg()
380 mii = sc->mii_softc; in ffec_miibus_statchg()
383 sc->link_is_up = true; in ffec_miibus_statchg()
385 sc->link_is_up = false; in ffec_miibus_statchg()
387 ecr = RD4(sc, FEC_ECR_REG) & ~FEC_ECR_SPEED; in ffec_miibus_statchg()
388 rcr = RD4(sc, FEC_RCR_REG) & ~(FEC_RCR_RMII_10T | FEC_RCR_RMII_MODE | in ffec_miibus_statchg()
390 tcr = RD4(sc, FEC_TCR_REG) & ~FEC_TCR_FDEN; in ffec_miibus_statchg()
393 switch (sc->phy_conn_type) { in ffec_miibus_statchg()
419 sc->link_is_up = false; in ffec_miibus_statchg()
422 sc->link_is_up = false; in ffec_miibus_statchg()
436 WR4(sc, FEC_RCR_REG, rcr); in ffec_miibus_statchg()
437 WR4(sc, FEC_TCR_REG, tcr); in ffec_miibus_statchg()
438 WR4(sc, FEC_ECR_REG, ecr); in ffec_miibus_statchg()
444 struct ffec_softc *sc; in ffec_media_status() local
448 sc = if_getsoftc(ifp); in ffec_media_status()
449 mii = sc->mii_softc; in ffec_media_status()
450 FFEC_LOCK(sc); in ffec_media_status()
454 FFEC_UNLOCK(sc); in ffec_media_status()
458 ffec_media_change_locked(struct ffec_softc *sc) in ffec_media_change_locked() argument
461 return (mii_mediachg(sc->mii_softc)); in ffec_media_change_locked()
467 struct ffec_softc *sc; in ffec_media_change() local
470 sc = if_getsoftc(ifp); in ffec_media_change()
472 FFEC_LOCK(sc); in ffec_media_change()
473 error = ffec_media_change_locked(sc); in ffec_media_change()
474 FFEC_UNLOCK(sc); in ffec_media_change()
478 static void ffec_clear_stats(struct ffec_softc *sc) in ffec_clear_stats() argument
482 mibc = RD4(sc, FEC_MIBC_REG); in ffec_clear_stats()
489 if (sc->fectype == FECTYPE_IMX6 || sc->fectype == FECTYPE_MVF) { in ffec_clear_stats()
490 WR4(sc, FEC_MIBC_REG, mibc | FEC_MIBC_CLEAR); in ffec_clear_stats()
491 WR4(sc, FEC_MIBC_REG, mibc & ~FEC_MIBC_CLEAR); in ffec_clear_stats()
493 WR4(sc, FEC_MIBC_REG, mibc | FEC_MIBC_DIS); in ffec_clear_stats()
495 WR4(sc, FEC_IEEE_R_DROP, 0); in ffec_clear_stats()
496 WR4(sc, FEC_IEEE_R_MACERR, 0); in ffec_clear_stats()
497 WR4(sc, FEC_RMON_R_CRC_ALIGN, 0); in ffec_clear_stats()
498 WR4(sc, FEC_RMON_R_FRAG, 0); in ffec_clear_stats()
499 WR4(sc, FEC_RMON_R_JAB, 0); in ffec_clear_stats()
500 WR4(sc, FEC_RMON_R_MC_PKT, 0); in ffec_clear_stats()
501 WR4(sc, FEC_RMON_R_OVERSIZE, 0); in ffec_clear_stats()
502 WR4(sc, FEC_RMON_R_PACKETS, 0); in ffec_clear_stats()
503 WR4(sc, FEC_RMON_R_UNDERSIZE, 0); in ffec_clear_stats()
504 WR4(sc, FEC_RMON_T_COL, 0); in ffec_clear_stats()
505 WR4(sc, FEC_RMON_T_CRC_ALIGN, 0); in ffec_clear_stats()
506 WR4(sc, FEC_RMON_T_FRAG, 0); in ffec_clear_stats()
507 WR4(sc, FEC_RMON_T_JAB, 0); in ffec_clear_stats()
508 WR4(sc, FEC_RMON_T_MC_PKT, 0); in ffec_clear_stats()
509 WR4(sc, FEC_RMON_T_OVERSIZE , 0); in ffec_clear_stats()
510 WR4(sc, FEC_RMON_T_PACKETS, 0); in ffec_clear_stats()
511 WR4(sc, FEC_RMON_T_UNDERSIZE, 0); in ffec_clear_stats()
513 WR4(sc, FEC_MIBC_REG, mibc); in ffec_clear_stats()
518 ffec_harvest_stats(struct ffec_softc *sc) in ffec_harvest_stats() argument
522 ifp = sc->ifp; in ffec_harvest_stats()
529 if_inc_counter(ifp, IFCOUNTER_IPACKETS, RD4(sc, FEC_RMON_R_PACKETS)); in ffec_harvest_stats()
530 if_inc_counter(ifp, IFCOUNTER_IMCASTS, RD4(sc, FEC_RMON_R_MC_PKT)); in ffec_harvest_stats()
532 RD4(sc, FEC_RMON_R_CRC_ALIGN) + RD4(sc, FEC_RMON_R_UNDERSIZE) + in ffec_harvest_stats()
533 RD4(sc, FEC_RMON_R_OVERSIZE) + RD4(sc, FEC_RMON_R_FRAG) + in ffec_harvest_stats()
534 RD4(sc, FEC_RMON_R_JAB) + RD4(sc, FEC_IEEE_R_DROP)); in ffec_harvest_stats()
536 if_inc_counter(ifp, IFCOUNTER_IQDROPS, RD4(sc, FEC_IEEE_R_MACERR)); in ffec_harvest_stats()
538 if_inc_counter(ifp, IFCOUNTER_OPACKETS, RD4(sc, FEC_RMON_T_PACKETS)); in ffec_harvest_stats()
539 if_inc_counter(ifp, IFCOUNTER_OMCASTS, RD4(sc, FEC_RMON_T_MC_PKT)); in ffec_harvest_stats()
541 RD4(sc, FEC_RMON_T_CRC_ALIGN) + RD4(sc, FEC_RMON_T_UNDERSIZE) + in ffec_harvest_stats()
542 RD4(sc, FEC_RMON_T_OVERSIZE) + RD4(sc, FEC_RMON_T_FRAG) + in ffec_harvest_stats()
543 RD4(sc, FEC_RMON_T_JAB)); in ffec_harvest_stats()
545 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, RD4(sc, FEC_RMON_T_COL)); in ffec_harvest_stats()
547 ffec_clear_stats(sc); in ffec_harvest_stats()
553 struct ffec_softc *sc; in ffec_tick() local
557 sc = arg; in ffec_tick()
559 FFEC_ASSERT_LOCKED(sc); in ffec_tick()
561 ifp = sc->ifp; in ffec_tick()
571 if (sc->tx_watchdog_count > 0) { in ffec_tick()
572 if (--sc->tx_watchdog_count == 0) { in ffec_tick()
573 ffec_txfinish_locked(sc); in ffec_tick()
578 ffec_harvest_stats(sc); in ffec_tick()
581 link_was_up = sc->link_is_up; in ffec_tick()
582 mii_tick(sc->mii_softc); in ffec_tick()
583 if (sc->link_is_up && !link_was_up) in ffec_tick()
584 ffec_txstart_locked(sc); in ffec_tick()
587 callout_reset(&sc->ffec_callout, hz, ffec_tick, sc); in ffec_tick()
591 ffec_setup_txdesc(struct ffec_softc *sc, int idx, bus_addr_t paddr, in ffec_setup_txdesc() argument
597 nidx = next_txidx(sc, idx); in ffec_setup_txdesc()
602 --sc->txcount; in ffec_setup_txdesc()
605 ++sc->txcount; in ffec_setup_txdesc()
615 sc->txdesc_ring[idx].buf_paddr = (uint32_t)paddr; in ffec_setup_txdesc()
616 sc->txdesc_ring[idx].flags_len = flags | len; /* Must be set last! */ in ffec_setup_txdesc()
622 ffec_setup_txbuf(struct ffec_softc *sc, int idx, struct mbuf **mp) in ffec_setup_txbuf() argument
632 error = bus_dmamap_load_mbuf_sg(sc->txbuf_tag, sc->txbuf_map[idx].map, in ffec_setup_txbuf()
637 bus_dmamap_sync(sc->txbuf_tag, sc->txbuf_map[idx].map, in ffec_setup_txbuf()
640 sc->txbuf_map[idx].mbuf = m; in ffec_setup_txbuf()
641 ffec_setup_txdesc(sc, idx, seg.ds_addr, seg.ds_len); in ffec_setup_txbuf()
648 ffec_txstart_locked(struct ffec_softc *sc) in ffec_txstart_locked() argument
654 FFEC_ASSERT_LOCKED(sc); in ffec_txstart_locked()
656 if (!sc->link_is_up) in ffec_txstart_locked()
659 ifp = sc->ifp; in ffec_txstart_locked()
667 if (sc->txcount == (TX_DESC_COUNT-1)) { in ffec_txstart_locked()
674 if (ffec_setup_txbuf(sc, sc->tx_idx_head, &m) != 0) { in ffec_txstart_locked()
679 sc->tx_idx_head = next_txidx(sc, sc->tx_idx_head); in ffec_txstart_locked()
684 bus_dmamap_sync(sc->txdesc_tag, sc->txdesc_map, BUS_DMASYNC_PREWRITE); in ffec_txstart_locked()
685 WR4(sc, FEC_TDAR_REG, FEC_TDAR_TDAR); in ffec_txstart_locked()
686 bus_dmamap_sync(sc->txdesc_tag, sc->txdesc_map, BUS_DMASYNC_POSTWRITE); in ffec_txstart_locked()
687 sc->tx_watchdog_count = WATCHDOG_TIMEOUT_SECS; in ffec_txstart_locked()
694 struct ffec_softc *sc = if_getsoftc(ifp); in ffec_txstart() local
696 FFEC_LOCK(sc); in ffec_txstart()
697 ffec_txstart_locked(sc); in ffec_txstart()
698 FFEC_UNLOCK(sc); in ffec_txstart()
702 ffec_txfinish_locked(struct ffec_softc *sc) in ffec_txfinish_locked() argument
709 FFEC_ASSERT_LOCKED(sc); in ffec_txfinish_locked()
712 bus_dmamap_sync(sc->txdesc_tag, sc->txdesc_map, BUS_DMASYNC_PREREAD); in ffec_txfinish_locked()
713 bus_dmamap_sync(sc->txdesc_tag, sc->txdesc_map, BUS_DMASYNC_POSTREAD); in ffec_txfinish_locked()
714 ifp = sc->ifp; in ffec_txfinish_locked()
716 while (sc->tx_idx_tail != sc->tx_idx_head) { in ffec_txfinish_locked()
717 desc = &sc->txdesc_ring[sc->tx_idx_tail]; in ffec_txfinish_locked()
721 bmap = &sc->txbuf_map[sc->tx_idx_tail]; in ffec_txfinish_locked()
722 bus_dmamap_sync(sc->txbuf_tag, bmap->map, in ffec_txfinish_locked()
724 bus_dmamap_unload(sc->txbuf_tag, bmap->map); in ffec_txfinish_locked()
727 ffec_setup_txdesc(sc, sc->tx_idx_tail, 0, 0); in ffec_txfinish_locked()
728 sc->tx_idx_tail = next_txidx(sc, sc->tx_idx_tail); in ffec_txfinish_locked()
737 ffec_txstart_locked(sc); in ffec_txfinish_locked()
741 if (sc->tx_idx_tail == sc->tx_idx_head) { in ffec_txfinish_locked()
742 sc->tx_watchdog_count = 0; in ffec_txfinish_locked()
747 ffec_setup_rxdesc(struct ffec_softc *sc, int idx, bus_addr_t paddr) in ffec_setup_rxdesc() argument
756 nidx = next_rxidx(sc, idx); in ffec_setup_rxdesc()
757 sc->rxdesc_ring[idx].buf_paddr = (uint32_t)paddr; in ffec_setup_rxdesc()
758 sc->rxdesc_ring[idx].flags_len = FEC_RXDESC_EMPTY | in ffec_setup_rxdesc()
765 ffec_setup_rxbuf(struct ffec_softc *sc, int idx, struct mbuf * m) in ffec_setup_rxbuf() argument
770 if (!(sc->fecflags & FECFLAG_RACC)) { in ffec_setup_rxbuf()
779 m_adj(m, roundup(ETHER_ALIGN, sc->rxbuf_align)); in ffec_setup_rxbuf()
782 error = bus_dmamap_load_mbuf_sg(sc->rxbuf_tag, sc->rxbuf_map[idx].map, in ffec_setup_rxbuf()
788 bus_dmamap_sync(sc->rxbuf_tag, sc->rxbuf_map[idx].map, in ffec_setup_rxbuf()
791 sc->rxbuf_map[idx].mbuf = m; in ffec_setup_rxbuf()
792 ffec_setup_rxdesc(sc, idx, seg.ds_addr); in ffec_setup_rxbuf()
798 ffec_alloc_mbufcl(struct ffec_softc *sc) in ffec_alloc_mbufcl() argument
810 ffec_rxfinish_onebuf(struct ffec_softc *sc, int len) in ffec_rxfinish_onebuf() argument
822 if ((newmbuf = ffec_alloc_mbufcl(sc)) == NULL) { in ffec_rxfinish_onebuf()
823 if_inc_counter(sc->ifp, IFCOUNTER_IQDROPS, 1); in ffec_rxfinish_onebuf()
824 ffec_setup_rxdesc(sc, sc->rx_idx, in ffec_rxfinish_onebuf()
825 sc->rxdesc_ring[sc->rx_idx].buf_paddr); in ffec_rxfinish_onebuf()
829 FFEC_UNLOCK(sc); in ffec_rxfinish_onebuf()
831 bmap = &sc->rxbuf_map[sc->rx_idx]; in ffec_rxfinish_onebuf()
833 bus_dmamap_sync(sc->rxbuf_tag, bmap->map, BUS_DMASYNC_POSTREAD); in ffec_rxfinish_onebuf()
834 bus_dmamap_unload(sc->rxbuf_tag, bmap->map); in ffec_rxfinish_onebuf()
839 m->m_pkthdr.rcvif = sc->ifp; in ffec_rxfinish_onebuf()
851 if (sc->fecflags & FECFLAG_RACC) { in ffec_rxfinish_onebuf()
859 if_input(sc->ifp, m); in ffec_rxfinish_onebuf()
861 FFEC_LOCK(sc); in ffec_rxfinish_onebuf()
863 if ((error = ffec_setup_rxbuf(sc, sc->rx_idx, newmbuf)) != 0) { in ffec_rxfinish_onebuf()
864 device_printf(sc->dev, "ffec_setup_rxbuf error %d\n", error); in ffec_rxfinish_onebuf()
871 ffec_rxfinish_locked(struct ffec_softc *sc) in ffec_rxfinish_locked() argument
877 FFEC_ASSERT_LOCKED(sc); in ffec_rxfinish_locked()
880 bus_dmamap_sync(sc->rxdesc_tag, sc->rxdesc_map, BUS_DMASYNC_PREREAD); in ffec_rxfinish_locked()
881 bus_dmamap_sync(sc->rxdesc_tag, sc->rxdesc_map, BUS_DMASYNC_POSTREAD); in ffec_rxfinish_locked()
884 desc = &sc->rxdesc_ring[sc->rx_idx]; in ffec_rxfinish_locked()
893 ffec_setup_rxdesc(sc, sc->rx_idx, in ffec_rxfinish_locked()
894 sc->rxdesc_ring[sc->rx_idx].buf_paddr); in ffec_rxfinish_locked()
905 device_printf(sc->dev, in ffec_rxfinish_locked()
907 ffec_setup_rxdesc(sc, sc->rx_idx, in ffec_rxfinish_locked()
908 sc->rxdesc_ring[sc->rx_idx].buf_paddr); in ffec_rxfinish_locked()
917 ffec_setup_rxdesc(sc, sc->rx_idx, in ffec_rxfinish_locked()
918 sc->rxdesc_ring[sc->rx_idx].buf_paddr); in ffec_rxfinish_locked()
923 ffec_rxfinish_onebuf(sc, len); in ffec_rxfinish_locked()
925 sc->rx_idx = next_rxidx(sc, sc->rx_idx); in ffec_rxfinish_locked()
929 bus_dmamap_sync(sc->rxdesc_tag, sc->rxdesc_map, BUS_DMASYNC_PREWRITE); in ffec_rxfinish_locked()
930 WR4(sc, FEC_RDAR_REG, FEC_RDAR_RDAR); in ffec_rxfinish_locked()
931 bus_dmamap_sync(sc->rxdesc_tag, sc->rxdesc_map, BUS_DMASYNC_POSTWRITE); in ffec_rxfinish_locked()
936 ffec_get_hwaddr(struct ffec_softc *sc, uint8_t *hwaddr) in ffec_get_hwaddr() argument
949 palr = RD4(sc, FEC_PALR_REG); in ffec_get_hwaddr()
950 paur = RD4(sc, FEC_PAUR_REG) & FEC_PAUR_PADDR2_MASK; in ffec_get_hwaddr()
969 device_printf(sc->dev, in ffec_get_hwaddr()
990 ffec_setup_rxfilter(struct ffec_softc *sc) in ffec_setup_rxfilter() argument
996 FFEC_ASSERT_LOCKED(sc); in ffec_setup_rxfilter()
998 ifp = sc->ifp; in ffec_setup_rxfilter()
1009 WR4(sc, FEC_GAUR_REG, (uint32_t)(ghash >> 32)); in ffec_setup_rxfilter()
1010 WR4(sc, FEC_GALR_REG, (uint32_t)ghash); in ffec_setup_rxfilter()
1024 WR4(sc, FEC_IAUR_REG, (uint32_t)(ihash >> 32)); in ffec_setup_rxfilter()
1025 WR4(sc, FEC_IALR_REG, (uint32_t)ihash); in ffec_setup_rxfilter()
1031 WR4(sc, FEC_PALR_REG, (eaddr[0] << 24) | (eaddr[1] << 16) | in ffec_setup_rxfilter()
1033 WR4(sc, FEC_PAUR_REG, (eaddr[4] << 24) | (eaddr[5] << 16)); in ffec_setup_rxfilter()
1037 ffec_stop_locked(struct ffec_softc *sc) in ffec_stop_locked() argument
1044 FFEC_ASSERT_LOCKED(sc); in ffec_stop_locked()
1046 ifp = sc->ifp; in ffec_stop_locked()
1048 sc->tx_watchdog_count = 0; in ffec_stop_locked()
1054 WR4(sc, FEC_ECR_REG, RD4(sc, FEC_ECR_REG) & ~FEC_ECR_ETHEREN); in ffec_stop_locked()
1055 WR4(sc, FEC_IEM_REG, 0x00000000); in ffec_stop_locked()
1056 WR4(sc, FEC_IER_REG, 0xffffffff); in ffec_stop_locked()
1065 callout_stop(&sc->ffec_callout); in ffec_stop_locked()
1074 idx = sc->tx_idx_tail; in ffec_stop_locked()
1075 while (idx != sc->tx_idx_head) { in ffec_stop_locked()
1076 desc = &sc->txdesc_ring[idx]; in ffec_stop_locked()
1077 bmap = &sc->txbuf_map[idx]; in ffec_stop_locked()
1079 bus_dmamap_unload(sc->txbuf_tag, bmap->map); in ffec_stop_locked()
1082 ffec_setup_txdesc(sc, idx, 0, 0); in ffec_stop_locked()
1084 idx = next_txidx(sc, idx); in ffec_stop_locked()
1094 desc = &sc->rxdesc_ring[idx]; in ffec_stop_locked()
1095 ffec_setup_rxdesc(sc, idx, desc->buf_paddr); in ffec_stop_locked()
1100 ffec_init_locked(struct ffec_softc *sc) in ffec_init_locked() argument
1102 if_t ifp = sc->ifp; in ffec_init_locked()
1105 FFEC_ASSERT_LOCKED(sc); in ffec_init_locked()
1124 maxbuf = MCLBYTES - roundup(ETHER_ALIGN, sc->rxbuf_align); in ffec_init_locked()
1131 WR4(sc, FEC_IEM_REG, 0x00000000); in ffec_init_locked()
1132 WR4(sc, FEC_IER_REG, 0xffffffff); in ffec_init_locked()
1137 ffec_setup_rxfilter(sc); in ffec_init_locked()
1149 WR4(sc, FEC_TFWR_REG, FEC_TFWR_STRFWD | FEC_TFWR_TWFR_128BYTE); in ffec_init_locked()
1155 WR4(sc, FEC_RCR_REG, (maxfl << FEC_RCR_MAX_FL_SHIFT)); in ffec_init_locked()
1163 WR4(sc, FEC_TCR_REG, 0); in ffec_init_locked()
1170 WR4(sc, FEC_OPD_REG, 0x00010020); in ffec_init_locked()
1194 WR4(sc, FEC_MRBR_REG, maxfl << FEC_MRBR_R_BUF_SIZE_SHIFT); in ffec_init_locked()
1201 WR4(sc, FEC_FTRL_REG, maxfl); in ffec_init_locked()
1210 sc->rx_idx = 0; in ffec_init_locked()
1211 sc->tx_idx_head = sc->tx_idx_tail = 0; in ffec_init_locked()
1212 sc->txcount = 0; in ffec_init_locked()
1213 WR4(sc, FEC_RDSR_REG, sc->rxdesc_ring_paddr); in ffec_init_locked()
1214 WR4(sc, FEC_TDSR_REG, sc->txdesc_ring_paddr); in ffec_init_locked()
1223 WR4(sc, FEC_IEM_REG, FEC_IER_TXF | FEC_IER_RXF | FEC_IER_EBERR); in ffec_init_locked()
1229 regval = RD4(sc, FEC_MIBC_REG); in ffec_init_locked()
1230 WR4(sc, FEC_MIBC_REG, regval | FEC_MIBC_DIS); in ffec_init_locked()
1231 ffec_clear_stats(sc); in ffec_init_locked()
1232 WR4(sc, FEC_MIBC_REG, regval & ~FEC_MIBC_DIS); in ffec_init_locked()
1234 if (sc->fecflags & FECFLAG_RACC) { in ffec_init_locked()
1238 regval = RD4(sc, FEC_RACC_REG); in ffec_init_locked()
1239 WR4(sc, FEC_RACC_REG, regval | FEC_RACC_SHIFT16); in ffec_init_locked()
1251 regval = RD4(sc, FEC_ECR_REG); in ffec_init_locked()
1256 WR4(sc, FEC_ECR_REG, regval); in ffec_init_locked()
1264 mii_mediachg(sc->mii_softc); in ffec_init_locked()
1265 callout_reset(&sc->ffec_callout, hz, ffec_tick, sc); in ffec_init_locked()
1271 WR4(sc, FEC_RDAR_REG, FEC_RDAR_RDAR); in ffec_init_locked()
1277 struct ffec_softc *sc = if_softc; in ffec_init() local
1279 FFEC_LOCK(sc); in ffec_init()
1280 ffec_init_locked(sc); in ffec_init()
1281 FFEC_UNLOCK(sc); in ffec_init()
1287 struct ffec_softc *sc; in ffec_intr() local
1290 sc = arg; in ffec_intr()
1292 FFEC_LOCK(sc); in ffec_intr()
1294 ier = RD4(sc, FEC_IER_REG); in ffec_intr()
1297 WR4(sc, FEC_IER_REG, FEC_IER_TXF); in ffec_intr()
1298 ffec_txfinish_locked(sc); in ffec_intr()
1302 WR4(sc, FEC_IER_REG, FEC_IER_RXF); in ffec_intr()
1303 ffec_rxfinish_locked(sc); in ffec_intr()
1315 WR4(sc, FEC_IER_REG, FEC_IER_EBERR); in ffec_intr()
1316 device_printf(sc->dev, in ffec_intr()
1318 ffec_stop_locked(sc); in ffec_intr()
1319 ffec_init_locked(sc); in ffec_intr()
1322 FFEC_UNLOCK(sc); in ffec_intr()
1329 struct ffec_softc *sc; in ffec_ioctl() local
1334 sc = if_getsoftc(ifp); in ffec_ioctl()
1340 FFEC_LOCK(sc); in ffec_ioctl()
1343 if ((if_getflags(ifp) ^ sc->if_flags) & in ffec_ioctl()
1345 ffec_setup_rxfilter(sc); in ffec_ioctl()
1347 if (!sc->is_detaching) in ffec_ioctl()
1348 ffec_init_locked(sc); in ffec_ioctl()
1352 ffec_stop_locked(sc); in ffec_ioctl()
1354 sc->if_flags = if_getflags(ifp); in ffec_ioctl()
1355 FFEC_UNLOCK(sc); in ffec_ioctl()
1361 FFEC_LOCK(sc); in ffec_ioctl()
1362 ffec_setup_rxfilter(sc); in ffec_ioctl()
1363 FFEC_UNLOCK(sc); in ffec_ioctl()
1369 mii = sc->mii_softc; in ffec_ioctl()
1392 struct ffec_softc *sc; in ffec_detach() local
1401 sc = device_get_softc(dev); in ffec_detach()
1403 if (sc->is_attached) { in ffec_detach()
1404 FFEC_LOCK(sc); in ffec_detach()
1405 sc->is_detaching = true; in ffec_detach()
1406 ffec_stop_locked(sc); in ffec_detach()
1407 FFEC_UNLOCK(sc); in ffec_detach()
1408 callout_drain(&sc->ffec_callout); in ffec_detach()
1409 ether_ifdetach(sc->ifp); in ffec_detach()
1416 if ((map = sc->rxbuf_map[idx].map) != NULL) { in ffec_detach()
1417 bus_dmamap_unload(sc->rxbuf_tag, map); in ffec_detach()
1418 bus_dmamap_destroy(sc->rxbuf_tag, map); in ffec_detach()
1419 m_freem(sc->rxbuf_map[idx].mbuf); in ffec_detach()
1422 if (sc->rxbuf_tag != NULL) in ffec_detach()
1423 bus_dma_tag_destroy(sc->rxbuf_tag); in ffec_detach()
1424 if (sc->rxdesc_map != NULL) { in ffec_detach()
1425 bus_dmamap_unload(sc->rxdesc_tag, sc->rxdesc_map); in ffec_detach()
1426 bus_dmamem_free(sc->rxdesc_tag, sc->rxdesc_ring, in ffec_detach()
1427 sc->rxdesc_map); in ffec_detach()
1429 if (sc->rxdesc_tag != NULL) in ffec_detach()
1430 bus_dma_tag_destroy(sc->rxdesc_tag); in ffec_detach()
1434 if ((map = sc->txbuf_map[idx].map) != NULL) { in ffec_detach()
1436 bus_dmamap_destroy(sc->txbuf_tag, map); in ffec_detach()
1439 if (sc->txbuf_tag != NULL) in ffec_detach()
1440 bus_dma_tag_destroy(sc->txbuf_tag); in ffec_detach()
1441 if (sc->txdesc_map != NULL) { in ffec_detach()
1442 bus_dmamap_unload(sc->txdesc_tag, sc->txdesc_map); in ffec_detach()
1443 bus_dmamem_free(sc->txdesc_tag, sc->txdesc_ring, in ffec_detach()
1444 sc->txdesc_map); in ffec_detach()
1446 if (sc->txdesc_tag != NULL) in ffec_detach()
1447 bus_dma_tag_destroy(sc->txdesc_tag); in ffec_detach()
1451 if (sc->intr_cookie[irq] != NULL) { in ffec_detach()
1452 bus_teardown_intr(dev, sc->irq_res[irq], in ffec_detach()
1453 sc->intr_cookie[irq]); in ffec_detach()
1456 bus_release_resources(dev, irq_res_spec, sc->irq_res); in ffec_detach()
1458 if (sc->mem_res != NULL) in ffec_detach()
1459 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res); in ffec_detach()
1461 FFEC_LOCK_DESTROY(sc); in ffec_detach()
1468 struct ffec_softc *sc; in ffec_attach() local
1478 sc = device_get_softc(dev); in ffec_attach()
1479 sc->dev = dev; in ffec_attach()
1481 FFEC_LOCK_INIT(sc); in ffec_attach()
1488 sc->fectype = (uint8_t)(typeflags & FECTYPE_MASK); in ffec_attach()
1489 sc->fecflags = (uint32_t)(typeflags & ~FECTYPE_MASK); in ffec_attach()
1491 if (sc->fecflags & FECFLAG_AVB) { in ffec_attach()
1492 sc->rxbuf_align = 64; in ffec_attach()
1493 sc->txbuf_align = 1; in ffec_attach()
1495 sc->rxbuf_align = 16; in ffec_attach()
1496 sc->txbuf_align = 16; in ffec_attach()
1508 sc->phy_conn_type = mii_fdt_get_contype(ofw_node); in ffec_attach()
1509 if (sc->phy_conn_type == MII_CONTYPE_UNKNOWN) { in ffec_attach()
1510 device_printf(sc->dev, "No valid 'phy-mode' " in ffec_attach()
1516 callout_init_mtx(&sc->ffec_callout, &sc->mtx, 0); in ffec_attach()
1520 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in ffec_attach()
1522 if (sc->mem_res == NULL) { in ffec_attach()
1528 error = bus_alloc_resources(dev, irq_res_spec, sc->irq_res); in ffec_attach()
1547 &sc->txdesc_tag); in ffec_attach()
1549 device_printf(sc->dev, in ffec_attach()
1554 error = bus_dmamem_alloc(sc->txdesc_tag, (void**)&sc->txdesc_ring, in ffec_attach()
1555 BUS_DMA_COHERENT | BUS_DMA_WAITOK | BUS_DMA_ZERO, &sc->txdesc_map); in ffec_attach()
1557 device_printf(sc->dev, in ffec_attach()
1562 error = bus_dmamap_load(sc->txdesc_tag, sc->txdesc_map, sc->txdesc_ring, in ffec_attach()
1563 TX_DESC_SIZE, ffec_get1paddr, &sc->txdesc_ring_paddr, 0); in ffec_attach()
1565 device_printf(sc->dev, in ffec_attach()
1572 sc->txbuf_align, 0, /* alignment, boundary */ in ffec_attach()
1580 &sc->txbuf_tag); in ffec_attach()
1582 device_printf(sc->dev, in ffec_attach()
1588 error = bus_dmamap_create(sc->txbuf_tag, 0, in ffec_attach()
1589 &sc->txbuf_map[idx].map); in ffec_attach()
1591 device_printf(sc->dev, in ffec_attach()
1595 ffec_setup_txdesc(sc, idx, 0, 0); in ffec_attach()
1611 &sc->rxdesc_tag); in ffec_attach()
1613 device_printf(sc->dev, in ffec_attach()
1618 error = bus_dmamem_alloc(sc->rxdesc_tag, (void **)&sc->rxdesc_ring, in ffec_attach()
1619 BUS_DMA_COHERENT | BUS_DMA_WAITOK | BUS_DMA_ZERO, &sc->rxdesc_map); in ffec_attach()
1621 device_printf(sc->dev, in ffec_attach()
1626 error = bus_dmamap_load(sc->rxdesc_tag, sc->rxdesc_map, sc->rxdesc_ring, in ffec_attach()
1627 RX_DESC_SIZE, ffec_get1paddr, &sc->rxdesc_ring_paddr, 0); in ffec_attach()
1629 device_printf(sc->dev, in ffec_attach()
1644 &sc->rxbuf_tag); in ffec_attach()
1646 device_printf(sc->dev, in ffec_attach()
1652 error = bus_dmamap_create(sc->rxbuf_tag, 0, in ffec_attach()
1653 &sc->rxbuf_map[idx].map); in ffec_attach()
1655 device_printf(sc->dev, in ffec_attach()
1659 if ((m = ffec_alloc_mbufcl(sc)) == NULL) { in ffec_attach()
1664 if ((error = ffec_setup_rxbuf(sc, idx, m)) != 0) { in ffec_attach()
1665 device_printf(sc->dev, in ffec_attach()
1672 ffec_get_hwaddr(sc, eaddr); in ffec_attach()
1685 if (sc->fecflags & FECFLAG_AVB) in ffec_attach()
1686 WR4(sc, FEC_ECR_REG, 0); in ffec_attach()
1688 WR4(sc, FEC_ECR_REG, FEC_ECR_RESET); in ffec_attach()
1692 if (sc->irq_res[irq] != NULL) { in ffec_attach()
1693 error = bus_setup_intr(dev, sc->irq_res[irq], in ffec_attach()
1694 INTR_TYPE_NET | INTR_MPSAFE, NULL, ffec_intr, sc, in ffec_attach()
1695 &sc->intr_cookie[irq]); in ffec_attach()
1735 WR4(sc, FEC_MSCR_REG, mscr); in ffec_attach()
1738 sc->ifp = ifp = if_alloc(IFT_ETHER); in ffec_attach()
1740 if_setsoftc(ifp, sc); in ffec_attach()
1753 if_setlinkmib(ifp, &sc->mibdata); in ffec_attach()
1754 if_setlinkmiblen(ifp, sizeof(sc->mibdata)); in ffec_attach()
1758 ffec_miigasket_setup(sc); in ffec_attach()
1764 error = mii_attach(dev, &sc->miibus, ifp, ffec_media_change, in ffec_attach()
1766 (sc->fecflags & FECTYPE_MVF) ? MIIF_FORCEANEG : 0); in ffec_attach()
1771 sc->mii_softc = device_get_softc(sc->miibus); in ffec_attach()
1775 sc->is_attached = true; in ffec_attach()