Lines Matching +full:sun4i +full:- +full:a10 +full:- +full:sid

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
29 /* A10/A20 EMAC driver */
136 bus_space_read_4(sc->emac_tag, sc->emac_handle, reg)
138 bus_space_write_4(sc->emac_tag, sc->emac_handle, reg, val)
146 error = clk_get_by_ofw_index(sc->emac_dev, 0, 0, &sc->emac_clk); in emac_sys_setup()
148 device_printf(sc->emac_dev, "cannot get clock\n"); in emac_sys_setup()
151 error = clk_enable(sc->emac_clk); in emac_sys_setup()
153 device_printf(sc->emac_dev, "cannot enable clock\n"); in emac_sys_setup()
172 * If there is something non-zero there just use it. in emac_get_hwaddr()
175 * using the SID rootkey. in emac_get_hwaddr()
179 * 'bsd' + random 24 low-order bits. 'b' is 0x62, which has the locally in emac_get_hwaddr()
236 ifp = sc->emac_ifp; in emac_set_rx_mode()
294 ifp = sc->emac_ifp; in emac_txeof()
296 sc->emac_fifo_mask &= ~status; in emac_txeof()
304 sc->emac_watchdog_timer = 0; in emac_txeof()
317 ifp = sc->emac_ifp; in emac_rxeof()
319 (if_getdrvflags(ifp) & IFF_DRV_RUNNING) != 0; count--) { in emac_rxeof()
346 for (i = 100; i > 0; i--) { in emac_rxeof()
353 device_printf(sc->emac_dev, in emac_rxeof()
396 m->m_len = m->m_pkthdr.len = MCLBYTES; in emac_rxeof()
399 bus_space_read_multi_4(sc->emac_tag, sc->emac_handle, in emac_rxeof()
402 m->m_pkthdr.rcvif = ifp; in emac_rxeof()
403 m->m_len = m->m_pkthdr.len = len - ETHER_CRC_LEN; in emac_rxeof()
412 if (m->m_len <= (MHLEN - ETHER_HDR_LEN)) { in emac_rxeof()
413 bcopy(m->m_data, m->m_data + ETHER_HDR_LEN, m->m_len); in emac_rxeof()
414 m->m_data += ETHER_HDR_LEN; in emac_rxeof()
415 } else if (m->m_len <= (MCLBYTES - ETHER_HDR_LEN) && in emac_rxeof()
416 m->m_len > (MHLEN - ETHER_HDR_LEN)) { in emac_rxeof()
419 len = ETHER_HDR_LEN + m->m_pkthdr.l2hlen; in emac_rxeof()
420 bcopy(m->m_data, m0->m_data, len); in emac_rxeof()
421 m->m_data += len; in emac_rxeof()
422 m->m_len -= len; in emac_rxeof()
423 m0->m_len = len; in emac_rxeof()
425 m0->m_next = m; in emac_rxeof()
433 } else if (m->m_len > EMAC_MAC_MAXF) { in emac_rxeof()
453 if (sc->emac_watchdog_timer == 0 || --sc->emac_watchdog_timer) in emac_watchdog()
456 ifp = sc->emac_ifp; in emac_watchdog()
458 if (sc->emac_link == 0) { in emac_watchdog()
460 if_printf(sc->emac_ifp, "watchdog timeout " in emac_watchdog()
463 if_printf(sc->emac_ifp, "watchdog timeout -- resetting\n"); in emac_watchdog()
479 mii = device_get_softc(sc->emac_miibus); in emac_tick()
483 callout_reset(&sc->emac_tick_ch, hz, emac_tick, sc); in emac_tick()
507 ifp = sc->emac_ifp; in emac_init_locked()
590 sc->emac_link = 0; in emac_init_locked()
593 mii = device_get_softc(sc->emac_miibus); in emac_init_locked()
596 callout_reset(&sc->emac_tick_ch, hz, emac_tick, sc); in emac_init_locked()
620 if (sc->emac_fifo_mask == (EMAC_TX_FIFO0 | EMAC_TX_FIFO1)) in emac_start_locked()
622 if (sc->emac_link == 0) in emac_start_locked()
629 if (sc->emac_fifo_mask & EMAC_TX_FIFO0) in emac_start_locked()
633 sc->emac_fifo_mask |= (1 << fifo); in emac_start_locked()
634 if (sc->emac_fifo_mask == (EMAC_TX_FIFO0 | EMAC_TX_FIFO1)) in emac_start_locked()
642 if (m->m_next != NULL || (mtod(m, uintptr_t) & 3) != 0) { in emac_start_locked()
652 bus_space_write_multi_4(sc->emac_tag, sc->emac_handle, in emac_start_locked()
654 roundup2(m->m_len, 4) / 4); in emac_start_locked()
658 EMAC_WRITE_REG(sc, reg, m->m_len); in emac_start_locked()
665 sc->emac_watchdog_timer = 5; in emac_start_locked()
680 ifp = sc->emac_ifp; in emac_stop_locked()
682 sc->emac_link = 0; in emac_stop_locked()
694 callout_stop(&sc->emac_tick_ch); in emac_stop_locked()
716 emac_rxeof(sc, sc->emac_rx_process_limit); in emac_intr()
721 ifp = sc->emac_ifp; in emac_intr()
726 /* Re-enable interrupt mask */ in emac_intr()
749 if ((if_getflags(ifp) ^ sc->emac_if_flags) & in emac_ioctl()
758 sc->emac_if_flags = if_getflags(ifp); in emac_ioctl()
771 mii = device_get_softc(sc->emac_miibus); in emac_ioctl()
772 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command); in emac_ioctl()
788 if (!ofw_bus_is_compatible(dev, "allwinner,sun4i-a10-emac")) in emac_probe()
791 device_set_desc(dev, "A10/A20 EMAC ethernet controller"); in emac_probe()
801 if_setdrvflagbits(sc->emac_ifp, 0, IFF_DRV_RUNNING); in emac_detach()
803 ether_ifdetach(sc->emac_ifp); in emac_detach()
807 callout_drain(&sc->emac_tick_ch); in emac_detach()
810 if (sc->emac_intrhand != NULL) in emac_detach()
811 bus_teardown_intr(sc->emac_dev, sc->emac_irq, in emac_detach()
812 sc->emac_intrhand); in emac_detach()
814 if (sc->emac_miibus != NULL) { in emac_detach()
815 device_delete_child(sc->emac_dev, sc->emac_miibus); in emac_detach()
816 bus_generic_detach(sc->emac_dev); in emac_detach()
819 if (sc->emac_clk != NULL) in emac_detach()
820 clk_disable(sc->emac_clk); in emac_detach()
822 if (sc->emac_res != NULL) in emac_detach()
823 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->emac_res); in emac_detach()
825 if (sc->emac_irq != NULL) in emac_detach()
826 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->emac_irq); in emac_detach()
828 if (sc->emac_ifp != NULL) in emac_detach()
829 if_free(sc->emac_ifp); in emac_detach()
831 if (mtx_initialized(&sc->emac_mtx)) in emac_detach()
832 mtx_destroy(&sc->emac_mtx); in emac_detach()
853 ifp = sc->emac_ifp; in emac_suspend()
870 ifp = sc->emac_ifp; in emac_resume()
889 sc->emac_dev = dev; in emac_attach()
892 mtx_init(&sc->emac_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, in emac_attach()
894 callout_init_mtx(&sc->emac_tick_ch, &sc->emac_mtx, 0); in emac_attach()
897 sc->emac_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in emac_attach()
899 if (sc->emac_res == NULL) { in emac_attach()
905 sc->emac_tag = rman_get_bustag(sc->emac_res); in emac_attach()
906 sc->emac_handle = rman_get_bushandle(sc->emac_res); in emac_attach()
909 sc->emac_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, in emac_attach()
911 if (sc->emac_irq == NULL) { in emac_attach()
921 &sc->emac_rx_process_limit, 0, sysctl_hw_emac_proc_limit, "I", in emac_attach()
924 sc->emac_rx_process_limit = EMAC_PROC_DEFAULT; in emac_attach()
926 "process_limit", &sc->emac_rx_process_limit); in emac_attach()
928 if (sc->emac_rx_process_limit < EMAC_PROC_MIN || in emac_attach()
929 sc->emac_rx_process_limit > EMAC_PROC_MAX) { in emac_attach()
932 sc->emac_rx_process_limit = EMAC_PROC_DEFAULT; in emac_attach()
942 ifp = sc->emac_ifp = if_alloc(IFT_ETHER); in emac_attach()
946 error = mii_attach(dev, &sc->emac_miibus, ifp, emac_ifmedia_upd, in emac_attach()
967 /* Tell the upper layer we support VLAN over-sized frames. */ in emac_attach()
970 error = bus_setup_intr(dev, sc->emac_irq, INTR_TYPE_NET | INTR_MPSAFE, in emac_attach()
971 NULL, emac_intr, sc, &sc->emac_intrhand); in emac_attach()
989 for (timeout = 100; timeout != 0; --timeout) { in emac_miibus_iowait()
1058 mii = device_get_softc(sc->emac_miibus); in emac_miibus_statchg()
1059 ifp = sc->emac_ifp; in emac_miibus_statchg()
1064 sc->emac_link = 0; in emac_miibus_statchg()
1065 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == in emac_miibus_statchg()
1067 switch (IFM_SUBTYPE(mii->mii_media_active)) { in emac_miibus_statchg()
1070 sc->emac_link = 1; in emac_miibus_statchg()
1077 if (sc->emac_link != 0) { in emac_miibus_statchg()
1079 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) { in emac_miibus_statchg()
1108 mii = device_get_softc(sc->emac_miibus); in emac_ifmedia_upd()
1110 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) in emac_ifmedia_upd()
1125 mii = device_get_softc(sc->emac_miibus); in emac_ifmedia_sts()
1129 ifmr->ifm_active = mii->mii_media_active; in emac_ifmedia_sts()
1130 ifmr->ifm_status = mii->mii_media_status; in emac_ifmedia_sts()
1175 if (error || req->newptr == NULL) in sysctl_int_range()