Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/tsec/if_tsec.c
| Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | |||||
| #include <dev/tsec/if_tsec.h> | #include <dev/tsec/if_tsec.h> | ||||
| #include <dev/tsec/if_tsecreg.h> | #include <dev/tsec/if_tsecreg.h> | ||||
| static int tsec_alloc_dma_desc(device_t dev, bus_dma_tag_t *dtag, | static int tsec_alloc_dma_desc(device_t dev, bus_dma_tag_t *dtag, | ||||
| bus_dmamap_t *dmap, bus_size_t dsize, void **vaddr, void *raddr, | bus_dmamap_t *dmap, bus_size_t dsize, void **vaddr, void *raddr, | ||||
| const char *dname); | const char *dname); | ||||
| static void tsec_dma_ctl(struct tsec_softc *sc, int state); | static void tsec_dma_ctl(struct tsec_softc *sc, int state); | ||||
| static void tsec_encap(struct ifnet *ifp, struct tsec_softc *sc, | static void tsec_encap(if_t ifp, struct tsec_softc *sc, | ||||
| struct mbuf *m0, uint16_t fcb_flags, int *start_tx); | struct mbuf *m0, uint16_t fcb_flags, int *start_tx); | ||||
| static void tsec_free_dma(struct tsec_softc *sc); | static void tsec_free_dma(struct tsec_softc *sc); | ||||
| static void tsec_free_dma_desc(bus_dma_tag_t dtag, bus_dmamap_t dmap, void *vaddr); | static void tsec_free_dma_desc(bus_dma_tag_t dtag, bus_dmamap_t dmap, void *vaddr); | ||||
| static int tsec_ifmedia_upd(struct ifnet *ifp); | static int tsec_ifmedia_upd(if_t ifp); | ||||
| static void tsec_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr); | static void tsec_ifmedia_sts(if_t ifp, struct ifmediareq *ifmr); | ||||
| static int tsec_new_rxbuf(bus_dma_tag_t tag, bus_dmamap_t map, | static int tsec_new_rxbuf(bus_dma_tag_t tag, bus_dmamap_t map, | ||||
| struct mbuf **mbufp, uint32_t *paddr); | struct mbuf **mbufp, uint32_t *paddr); | ||||
| static void tsec_map_dma_addr(void *arg, bus_dma_segment_t *segs, | static void tsec_map_dma_addr(void *arg, bus_dma_segment_t *segs, | ||||
| int nseg, int error); | int nseg, int error); | ||||
| static void tsec_intrs_ctl(struct tsec_softc *sc, int state); | static void tsec_intrs_ctl(struct tsec_softc *sc, int state); | ||||
| static void tsec_init(void *xsc); | static void tsec_init(void *xsc); | ||||
| static void tsec_init_locked(struct tsec_softc *sc); | static void tsec_init_locked(struct tsec_softc *sc); | ||||
| static int tsec_ioctl(struct ifnet *ifp, u_long command, caddr_t data); | static int tsec_ioctl(if_t ifp, u_long command, caddr_t data); | ||||
| static void tsec_reset_mac(struct tsec_softc *sc); | static void tsec_reset_mac(struct tsec_softc *sc); | ||||
| static void tsec_setfilter(struct tsec_softc *sc); | static void tsec_setfilter(struct tsec_softc *sc); | ||||
| static void tsec_set_mac_address(struct tsec_softc *sc); | static void tsec_set_mac_address(struct tsec_softc *sc); | ||||
| static void tsec_start(struct ifnet *ifp); | static void tsec_start(if_t ifp); | ||||
| static void tsec_start_locked(struct ifnet *ifp); | static void tsec_start_locked(if_t ifp); | ||||
| static void tsec_stop(struct tsec_softc *sc); | static void tsec_stop(struct tsec_softc *sc); | ||||
| static void tsec_tick(void *arg); | static void tsec_tick(void *arg); | ||||
| static void tsec_watchdog(struct tsec_softc *sc); | static void tsec_watchdog(struct tsec_softc *sc); | ||||
| static void tsec_add_sysctls(struct tsec_softc *sc); | static void tsec_add_sysctls(struct tsec_softc *sc); | ||||
| static int tsec_sysctl_ic_time(SYSCTL_HANDLER_ARGS); | static int tsec_sysctl_ic_time(SYSCTL_HANDLER_ARGS); | ||||
| static int tsec_sysctl_ic_count(SYSCTL_HANDLER_ARGS); | static int tsec_sysctl_ic_count(SYSCTL_HANDLER_ARGS); | ||||
| static void tsec_set_rxic(struct tsec_softc *sc); | static void tsec_set_rxic(struct tsec_softc *sc); | ||||
| static void tsec_set_txic(struct tsec_softc *sc); | static void tsec_set_txic(struct tsec_softc *sc); | ||||
| Show All 11 Lines | |||||
| MODULE_DEPEND(tsec, miibus, 1, 1, 1); | MODULE_DEPEND(tsec, miibus, 1, 1, 1); | ||||
| struct mtx tsec_phy_mtx; | struct mtx tsec_phy_mtx; | ||||
| int | int | ||||
| tsec_attach(struct tsec_softc *sc) | tsec_attach(struct tsec_softc *sc) | ||||
| { | { | ||||
| uint8_t hwaddr[ETHER_ADDR_LEN]; | uint8_t hwaddr[ETHER_ADDR_LEN]; | ||||
| struct ifnet *ifp; | if_t ifp; | ||||
| int error = 0; | int error = 0; | ||||
| int i; | int i; | ||||
| /* Initialize global (because potentially shared) MII lock */ | /* Initialize global (because potentially shared) MII lock */ | ||||
| if (!mtx_initialized(&tsec_phy_mtx)) | if (!mtx_initialized(&tsec_phy_mtx)) | ||||
| mtx_init(&tsec_phy_mtx, "tsec mii", NULL, MTX_DEF); | mtx_init(&tsec_phy_mtx, "tsec mii", NULL, MTX_DEF); | ||||
| /* Reset all TSEC counters */ | /* Reset all TSEC counters */ | ||||
| ▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | tsec_attach(struct tsec_softc *sc) | ||||
| /* Create network interface for upper layers */ | /* Create network interface for upper layers */ | ||||
| ifp = sc->tsec_ifp = if_alloc(IFT_ETHER); | ifp = sc->tsec_ifp = if_alloc(IFT_ETHER); | ||||
| if (ifp == NULL) { | if (ifp == NULL) { | ||||
| device_printf(sc->dev, "if_alloc() failed\n"); | device_printf(sc->dev, "if_alloc() failed\n"); | ||||
| tsec_detach(sc); | tsec_detach(sc); | ||||
| return (ENOMEM); | return (ENOMEM); | ||||
| } | } | ||||
| ifp->if_softc = sc; | if_setsoftc(ifp, sc); | ||||
| if_initname(ifp, device_get_name(sc->dev), device_get_unit(sc->dev)); | if_initname(ifp, device_get_name(sc->dev), device_get_unit(sc->dev)); | ||||
| ifp->if_flags = IFF_SIMPLEX | IFF_MULTICAST | IFF_BROADCAST; | if_setflags(ifp, IFF_SIMPLEX | IFF_MULTICAST | IFF_BROADCAST); | ||||
| ifp->if_init = tsec_init; | if_setinitfn(ifp, tsec_init); | ||||
| ifp->if_start = tsec_start; | if_setstartfn(ifp, tsec_start); | ||||
| ifp->if_ioctl = tsec_ioctl; | if_setioctlfn(ifp, tsec_ioctl); | ||||
| IFQ_SET_MAXLEN(&ifp->if_snd, TSEC_TX_NUM_DESC - 1); | |||||
| ifp->if_snd.ifq_drv_maxlen = TSEC_TX_NUM_DESC - 1; | |||||
| IFQ_SET_READY(&ifp->if_snd); | |||||
| ifp->if_capabilities = IFCAP_VLAN_MTU; | if_setsendqlen(ifp, TSEC_TX_NUM_DESC - 1); | ||||
| if_setsendqready(ifp); | |||||
| if_setcapabilities(ifp, IFCAP_VLAN_MTU); | |||||
| if (sc->is_etsec) | if (sc->is_etsec) | ||||
| ifp->if_capabilities |= IFCAP_HWCSUM; | if_setcapabilitiesbit(ifp, IFCAP_HWCSUM, 0); | ||||
| ifp->if_capenable = ifp->if_capabilities; | if_setcapenable(ifp, if_getcapabilities(ifp)); | ||||
| #ifdef DEVICE_POLLING | #ifdef DEVICE_POLLING | ||||
| /* Advertise that polling is supported */ | /* Advertise that polling is supported */ | ||||
| ifp->if_capabilities |= IFCAP_POLLING; | if_setcapabilitiesbit(ifp, IFCAP_POLLING, 0); | ||||
| #endif | #endif | ||||
| /* Attach PHY(s) */ | /* Attach PHY(s) */ | ||||
| error = mii_attach(sc->dev, &sc->tsec_miibus, ifp, tsec_ifmedia_upd, | error = mii_attach(sc->dev, &sc->tsec_miibus, ifp, tsec_ifmedia_upd, | ||||
| tsec_ifmedia_sts, BMSR_DEFCAPMASK, sc->phyaddr, MII_OFFSET_ANY, | tsec_ifmedia_sts, BMSR_DEFCAPMASK, sc->phyaddr, MII_OFFSET_ANY, | ||||
| 0); | 0); | ||||
| if (error) { | if (error) { | ||||
| device_printf(sc->dev, "attaching PHYs failed\n"); | device_printf(sc->dev, "attaching PHYs failed\n"); | ||||
| Show All 12 Lines | |||||
| } | } | ||||
| int | int | ||||
| tsec_detach(struct tsec_softc *sc) | tsec_detach(struct tsec_softc *sc) | ||||
| { | { | ||||
| if (sc->tsec_ifp != NULL) { | if (sc->tsec_ifp != NULL) { | ||||
| #ifdef DEVICE_POLLING | #ifdef DEVICE_POLLING | ||||
| if (sc->tsec_ifp->if_capenable & IFCAP_POLLING) | if (sc->tsec_if_getcapenable(ifp) & IFCAP_POLLING) | ||||
| ether_poll_deregister(sc->tsec_ifp); | ether_poll_deregister(sc->tsec_ifp); | ||||
| #endif | #endif | ||||
| /* Stop TSEC controller and free TX queue */ | /* Stop TSEC controller and free TX queue */ | ||||
| if (sc->sc_rres) | if (sc->sc_rres) | ||||
| tsec_shutdown(sc->dev); | tsec_shutdown(sc->dev); | ||||
| /* Detach network interface */ | /* Detach network interface */ | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | tsec_mii_wait(struct tsec_softc *sc, uint32_t flags) | ||||
| return (timeout == 0); | return (timeout == 0); | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_init_locked(struct tsec_softc *sc) | tsec_init_locked(struct tsec_softc *sc) | ||||
| { | { | ||||
| struct tsec_desc *tx_desc = sc->tsec_tx_vaddr; | struct tsec_desc *tx_desc = sc->tsec_tx_vaddr; | ||||
| struct tsec_desc *rx_desc = sc->tsec_rx_vaddr; | struct tsec_desc *rx_desc = sc->tsec_rx_vaddr; | ||||
| struct ifnet *ifp = sc->tsec_ifp; | if_t ifp = sc->tsec_ifp; | ||||
| uint32_t val, i; | uint32_t val, i; | ||||
| int timeout; | int timeout; | ||||
| if (ifp->if_drv_flags & IFF_DRV_RUNNING) | if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) | ||||
| return; | return; | ||||
| TSEC_GLOBAL_LOCK_ASSERT(sc); | TSEC_GLOBAL_LOCK_ASSERT(sc); | ||||
| tsec_stop(sc); | tsec_stop(sc); | ||||
| /* | /* | ||||
| * These steps are according to the MPC8555E PowerQUICCIII RM: | * These steps are according to the MPC8555E PowerQUICCIII RM: | ||||
| * 14.7 Initialization/Application Information | * 14.7 Initialization/Application Information | ||||
| ▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | tsec_init_locked(struct tsec_softc *sc) | ||||
| TSEC_WRITE(sc, TSEC_REG_IEVENT, 0xffffffff); | TSEC_WRITE(sc, TSEC_REG_IEVENT, 0xffffffff); | ||||
| /* Step 11: Enable interrupts */ | /* Step 11: Enable interrupts */ | ||||
| #ifdef DEVICE_POLLING | #ifdef DEVICE_POLLING | ||||
| /* | /* | ||||
| * ...only if polling is not turned on. Disable interrupts explicitly | * ...only if polling is not turned on. Disable interrupts explicitly | ||||
| * if polling is enabled. | * if polling is enabled. | ||||
| */ | */ | ||||
| if (ifp->if_capenable & IFCAP_POLLING ) | if (if_getcapenable(ifp) & IFCAP_POLLING ) | ||||
| tsec_intrs_ctl(sc, 0); | tsec_intrs_ctl(sc, 0); | ||||
| else | else | ||||
| #endif /* DEVICE_POLLING */ | #endif /* DEVICE_POLLING */ | ||||
| tsec_intrs_ctl(sc, 1); | tsec_intrs_ctl(sc, 1); | ||||
| /* Step 12: Initialize IADDRn */ | /* Step 12: Initialize IADDRn */ | ||||
| TSEC_WRITE(sc, TSEC_REG_IADDR0, 0); | TSEC_WRITE(sc, TSEC_REG_IADDR0, 0); | ||||
| TSEC_WRITE(sc, TSEC_REG_IADDR1, 0); | TSEC_WRITE(sc, TSEC_REG_IADDR1, 0); | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | #endif /* DEVICE_POLLING */ | ||||
| bus_dmamap_sync(sc->tsec_rx_dtag, sc->tsec_rx_dmap, | bus_dmamap_sync(sc->tsec_rx_dtag, sc->tsec_rx_dmap, | ||||
| BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); | ||||
| /* Step 18: Initialize the maximum receive buffer length */ | /* Step 18: Initialize the maximum receive buffer length */ | ||||
| TSEC_WRITE(sc, TSEC_REG_MRBLR, MCLBYTES); | TSEC_WRITE(sc, TSEC_REG_MRBLR, MCLBYTES); | ||||
| /* Step 19: Configure ethernet frame sizes */ | /* Step 19: Configure ethernet frame sizes */ | ||||
| TSEC_WRITE(sc, TSEC_REG_MINFLR, TSEC_MIN_FRAME_SIZE); | TSEC_WRITE(sc, TSEC_REG_MINFLR, TSEC_MIN_FRAME_SIZE); | ||||
| tsec_set_mtu(sc, ifp->if_mtu); | tsec_set_mtu(sc, if_getmtu(ifp)); | ||||
| /* Step 20: Enable Rx and RxBD sdata snooping */ | /* Step 20: Enable Rx and RxBD sdata snooping */ | ||||
| TSEC_WRITE(sc, TSEC_REG_ATTR, TSEC_ATTR_RDSEN | TSEC_ATTR_RBDSEN); | TSEC_WRITE(sc, TSEC_REG_ATTR, TSEC_ATTR_RDSEN | TSEC_ATTR_RBDSEN); | ||||
| TSEC_WRITE(sc, TSEC_REG_ATTRELI, 0); | TSEC_WRITE(sc, TSEC_REG_ATTRELI, 0); | ||||
| /* Step 21: Reset collision counters in hardware */ | /* Step 21: Reset collision counters in hardware */ | ||||
| TSEC_WRITE(sc, TSEC_REG_MON_TSCL, 0); | TSEC_WRITE(sc, TSEC_REG_MON_TSCL, 0); | ||||
| TSEC_WRITE(sc, TSEC_REG_MON_TMCL, 0); | TSEC_WRITE(sc, TSEC_REG_MON_TMCL, 0); | ||||
| Show All 16 Lines | #endif /* DEVICE_POLLING */ | ||||
| /* Step 25: Setup TCP/IP Off-Load engine */ | /* Step 25: Setup TCP/IP Off-Load engine */ | ||||
| if (sc->is_etsec) | if (sc->is_etsec) | ||||
| tsec_offload_setup(sc); | tsec_offload_setup(sc); | ||||
| /* Step 26: Setup multicast filters */ | /* Step 26: Setup multicast filters */ | ||||
| tsec_setup_multicast(sc); | tsec_setup_multicast(sc); | ||||
| /* Step 27: Activate network interface */ | /* Step 27: Activate network interface */ | ||||
| ifp->if_drv_flags |= IFF_DRV_RUNNING; | if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0); | ||||
| ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; | if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE); | ||||
| sc->tsec_if_flags = ifp->if_flags; | sc->tsec_if_flags = if_getflags(ifp); | ||||
| sc->tsec_watchdog = 0; | sc->tsec_watchdog = 0; | ||||
| /* Schedule watchdog timeout */ | /* Schedule watchdog timeout */ | ||||
| callout_reset(&sc->tsec_callout, hz, tsec_tick, sc); | callout_reset(&sc->tsec_callout, hz, tsec_tick, sc); | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_set_mac_address(struct tsec_softc *sc) | tsec_set_mac_address(struct tsec_softc *sc) | ||||
| { | { | ||||
| uint32_t macbuf[2] = { 0, 0 }; | uint32_t macbuf[2] = { 0, 0 }; | ||||
| char *macbufp, *curmac; | char *macbufp, *curmac; | ||||
| int i; | int i; | ||||
| TSEC_GLOBAL_LOCK_ASSERT(sc); | TSEC_GLOBAL_LOCK_ASSERT(sc); | ||||
| KASSERT((ETHER_ADDR_LEN <= sizeof(macbuf)), | KASSERT((ETHER_ADDR_LEN <= sizeof(macbuf)), | ||||
| ("tsec_set_mac_address: (%d <= %zd", ETHER_ADDR_LEN, | ("tsec_set_mac_address: (%d <= %zd", ETHER_ADDR_LEN, | ||||
| sizeof(macbuf))); | sizeof(macbuf))); | ||||
| macbufp = (char *)macbuf; | macbufp = (char *)macbuf; | ||||
| curmac = (char *)IF_LLADDR(sc->tsec_ifp); | curmac = (char *)if_getlladdr(sc->tsec_ifp); | ||||
| /* Correct order of MAC address bytes */ | /* Correct order of MAC address bytes */ | ||||
| for (i = 1; i <= ETHER_ADDR_LEN; i++) | for (i = 1; i <= ETHER_ADDR_LEN; i++) | ||||
| macbufp[ETHER_ADDR_LEN-i] = curmac[i-1]; | macbufp[ETHER_ADDR_LEN-i] = curmac[i-1]; | ||||
| /* Initialize MAC station address MACSTNADDR2 and MACSTNADDR1 */ | /* Initialize MAC station address MACSTNADDR2 and MACSTNADDR1 */ | ||||
| TSEC_WRITE(sc, TSEC_REG_MACSTNADDR2, macbuf[1]); | TSEC_WRITE(sc, TSEC_REG_MACSTNADDR2, macbuf[1]); | ||||
| TSEC_WRITE(sc, TSEC_REG_MACSTNADDR1, macbuf[0]); | TSEC_WRITE(sc, TSEC_REG_MACSTNADDR1, macbuf[0]); | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | tsec_reset_mac(struct tsec_softc *sc) | ||||
| maccfg1_flags = TSEC_READ(sc, TSEC_REG_MACCFG1); | maccfg1_flags = TSEC_READ(sc, TSEC_REG_MACCFG1); | ||||
| maccfg1_flags &= ~TSEC_MACCFG1_SOFT_RESET; | maccfg1_flags &= ~TSEC_MACCFG1_SOFT_RESET; | ||||
| TSEC_WRITE(sc, TSEC_REG_MACCFG1, maccfg1_flags); | TSEC_WRITE(sc, TSEC_REG_MACCFG1, maccfg1_flags); | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_watchdog(struct tsec_softc *sc) | tsec_watchdog(struct tsec_softc *sc) | ||||
| { | { | ||||
| struct ifnet *ifp; | if_t ifp; | ||||
| TSEC_GLOBAL_LOCK_ASSERT(sc); | TSEC_GLOBAL_LOCK_ASSERT(sc); | ||||
| if (sc->tsec_watchdog == 0 || --sc->tsec_watchdog > 0) | if (sc->tsec_watchdog == 0 || --sc->tsec_watchdog > 0) | ||||
| return; | return; | ||||
| ifp = sc->tsec_ifp; | ifp = sc->tsec_ifp; | ||||
| if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | ||||
| if_printf(ifp, "watchdog timeout\n"); | if_printf(ifp, "watchdog timeout\n"); | ||||
| tsec_stop(sc); | tsec_stop(sc); | ||||
| tsec_init_locked(sc); | tsec_init_locked(sc); | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_start(struct ifnet *ifp) | tsec_start(if_t ifp) | ||||
| { | { | ||||
| struct tsec_softc *sc = ifp->if_softc; | struct tsec_softc *sc = if_getsoftc(ifp); | ||||
| TSEC_TRANSMIT_LOCK(sc); | TSEC_TRANSMIT_LOCK(sc); | ||||
| tsec_start_locked(ifp); | tsec_start_locked(ifp); | ||||
| TSEC_TRANSMIT_UNLOCK(sc); | TSEC_TRANSMIT_UNLOCK(sc); | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_start_locked(struct ifnet *ifp) | tsec_start_locked(if_t ifp) | ||||
| { | { | ||||
| struct tsec_softc *sc; | struct tsec_softc *sc; | ||||
| struct mbuf *m0; | struct mbuf *m0; | ||||
| struct tsec_tx_fcb *tx_fcb; | struct tsec_tx_fcb *tx_fcb; | ||||
| int csum_flags; | int csum_flags; | ||||
| int start_tx; | int start_tx; | ||||
| uint16_t fcb_flags; | uint16_t fcb_flags; | ||||
| sc = ifp->if_softc; | sc = if_getsoftc(ifp); | ||||
| start_tx = 0; | start_tx = 0; | ||||
| TSEC_TRANSMIT_LOCK_ASSERT(sc); | TSEC_TRANSMIT_LOCK_ASSERT(sc); | ||||
| if (sc->tsec_link == 0) | if (sc->tsec_link == 0) | ||||
| return; | return; | ||||
| bus_dmamap_sync(sc->tsec_tx_dtag, sc->tsec_tx_dmap, | bus_dmamap_sync(sc->tsec_tx_dtag, sc->tsec_tx_dmap, | ||||
| BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); | BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); | ||||
| for (;;) { | for (;;) { | ||||
| if (TSEC_FREE_TX_DESC(sc) < TSEC_TX_MAX_DMA_SEGS) { | if (TSEC_FREE_TX_DESC(sc) < TSEC_TX_MAX_DMA_SEGS) { | ||||
| /* No free descriptors */ | /* No free descriptors */ | ||||
| ifp->if_drv_flags |= IFF_DRV_OACTIVE; | if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0); | ||||
| break; | break; | ||||
| } | } | ||||
| /* Get packet from the queue */ | /* Get packet from the queue */ | ||||
| IFQ_DRV_DEQUEUE(&ifp->if_snd, m0); | m0 = if_dequeue(ifp); | ||||
| if (m0 == NULL) | if (m0 == NULL) | ||||
| break; | break; | ||||
| /* Insert TCP/IP Off-load frame control block */ | /* Insert TCP/IP Off-load frame control block */ | ||||
| fcb_flags = 0; | fcb_flags = 0; | ||||
| csum_flags = m0->m_pkthdr.csum_flags; | csum_flags = m0->m_pkthdr.csum_flags; | ||||
| if (csum_flags) { | if (csum_flags) { | ||||
| M_PREPEND(m0, sizeof(struct tsec_tx_fcb), M_NOWAIT); | M_PREPEND(m0, sizeof(struct tsec_tx_fcb), M_NOWAIT); | ||||
| Show All 26 Lines | tsec_start_locked(if_t ifp) | ||||
| if (start_tx) { | if (start_tx) { | ||||
| /* Enable transmitter and watchdog timer */ | /* Enable transmitter and watchdog timer */ | ||||
| TSEC_WRITE(sc, TSEC_REG_TSTAT, TSEC_TSTAT_THLT); | TSEC_WRITE(sc, TSEC_REG_TSTAT, TSEC_TSTAT_THLT); | ||||
| sc->tsec_watchdog = 5; | sc->tsec_watchdog = 5; | ||||
| } | } | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_encap(struct ifnet *ifp, struct tsec_softc *sc, struct mbuf *m0, | tsec_encap(if_t ifp, struct tsec_softc *sc, struct mbuf *m0, | ||||
| uint16_t fcb_flags, int *start_tx) | uint16_t fcb_flags, int *start_tx) | ||||
| { | { | ||||
| bus_dma_segment_t segs[TSEC_TX_MAX_DMA_SEGS]; | bus_dma_segment_t segs[TSEC_TX_MAX_DMA_SEGS]; | ||||
| int error, i, nsegs; | int error, i, nsegs; | ||||
| struct tsec_bufmap *tx_bufmap; | struct tsec_bufmap *tx_bufmap; | ||||
| uint32_t tx_idx; | uint32_t tx_idx; | ||||
| uint16_t flags; | uint16_t flags; | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | tsec_encap(if_t ifp, struct tsec_softc *sc, struct mbuf *m0, | ||||
| BPF_MTAP(ifp, m0); | BPF_MTAP(ifp, m0); | ||||
| *start_tx = 1; | *start_tx = 1; | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_setfilter(struct tsec_softc *sc) | tsec_setfilter(struct tsec_softc *sc) | ||||
| { | { | ||||
| struct ifnet *ifp; | if_t ifp; | ||||
| uint32_t flags; | uint32_t flags; | ||||
| ifp = sc->tsec_ifp; | ifp = sc->tsec_ifp; | ||||
| flags = TSEC_READ(sc, TSEC_REG_RCTRL); | flags = TSEC_READ(sc, TSEC_REG_RCTRL); | ||||
| /* Promiscuous mode */ | /* Promiscuous mode */ | ||||
| if (ifp->if_flags & IFF_PROMISC) | if (if_getflags(ifp) & IFF_PROMISC) | ||||
| flags |= TSEC_RCTRL_PROM; | flags |= TSEC_RCTRL_PROM; | ||||
| else | else | ||||
| flags &= ~TSEC_RCTRL_PROM; | flags &= ~TSEC_RCTRL_PROM; | ||||
| TSEC_WRITE(sc, TSEC_REG_RCTRL, flags); | TSEC_WRITE(sc, TSEC_REG_RCTRL, flags); | ||||
| } | } | ||||
| #ifdef DEVICE_POLLING | #ifdef DEVICE_POLLING | ||||
| static poll_handler_t tsec_poll; | static poll_handler_t tsec_poll; | ||||
| static int | static int | ||||
| tsec_poll(struct ifnet *ifp, enum poll_cmd cmd, int count) | tsec_poll(if_t ifp, enum poll_cmd cmd, int count) | ||||
| { | { | ||||
| uint32_t ie; | uint32_t ie; | ||||
| struct tsec_softc *sc = ifp->if_softc; | struct tsec_softc *sc = if_getsoftc(ifp); | ||||
| int rx_npkts; | int rx_npkts; | ||||
| rx_npkts = 0; | rx_npkts = 0; | ||||
| TSEC_GLOBAL_LOCK(sc); | TSEC_GLOBAL_LOCK(sc); | ||||
| if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { | if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) { | ||||
| TSEC_GLOBAL_UNLOCK(sc); | TSEC_GLOBAL_UNLOCK(sc); | ||||
| return (rx_npkts); | return (rx_npkts); | ||||
| } | } | ||||
| if (cmd == POLL_AND_CHECK_STATUS) { | if (cmd == POLL_AND_CHECK_STATUS) { | ||||
| tsec_error_intr_locked(sc, count); | tsec_error_intr_locked(sc, count); | ||||
| /* Clear all events reported */ | /* Clear all events reported */ | ||||
| Show All 9 Lines | tsec_poll(if_t ifp, enum poll_cmd cmd, int count) | ||||
| TSEC_RECEIVE_UNLOCK(sc); | TSEC_RECEIVE_UNLOCK(sc); | ||||
| return (rx_npkts); | return (rx_npkts); | ||||
| } | } | ||||
| #endif /* DEVICE_POLLING */ | #endif /* DEVICE_POLLING */ | ||||
| static int | static int | ||||
| tsec_ioctl(struct ifnet *ifp, u_long command, caddr_t data) | tsec_ioctl(if_t ifp, u_long command, caddr_t data) | ||||
| { | { | ||||
| struct tsec_softc *sc = ifp->if_softc; | struct tsec_softc *sc = if_getsoftc(ifp); | ||||
| struct ifreq *ifr = (struct ifreq *)data; | struct ifreq *ifr = (struct ifreq *)data; | ||||
| int mask, error = 0; | int mask, error = 0; | ||||
| switch (command) { | switch (command) { | ||||
| case SIOCSIFMTU: | case SIOCSIFMTU: | ||||
| TSEC_GLOBAL_LOCK(sc); | TSEC_GLOBAL_LOCK(sc); | ||||
| if (tsec_set_mtu(sc, ifr->ifr_mtu)) | if (tsec_set_mtu(sc, ifr->ifr_mtu)) | ||||
| ifp->if_mtu = ifr->ifr_mtu; | if_setmtu(ifp, ifr->ifr_mtu); | ||||
| else | else | ||||
| error = EINVAL; | error = EINVAL; | ||||
| TSEC_GLOBAL_UNLOCK(sc); | TSEC_GLOBAL_UNLOCK(sc); | ||||
| break; | break; | ||||
| case SIOCSIFFLAGS: | case SIOCSIFFLAGS: | ||||
| TSEC_GLOBAL_LOCK(sc); | TSEC_GLOBAL_LOCK(sc); | ||||
| if (ifp->if_flags & IFF_UP) { | if (if_getflags(ifp) & IFF_UP) { | ||||
| if (ifp->if_drv_flags & IFF_DRV_RUNNING) { | if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { | ||||
| if ((sc->tsec_if_flags ^ ifp->if_flags) & | if ((sc->tsec_if_flags ^ if_getflags(ifp)) & | ||||
| IFF_PROMISC) | IFF_PROMISC) | ||||
| tsec_setfilter(sc); | tsec_setfilter(sc); | ||||
| if ((sc->tsec_if_flags ^ ifp->if_flags) & | if ((sc->tsec_if_flags ^ if_getflags(ifp)) & | ||||
| IFF_ALLMULTI) | IFF_ALLMULTI) | ||||
| tsec_setup_multicast(sc); | tsec_setup_multicast(sc); | ||||
| } else | } else | ||||
| tsec_init_locked(sc); | tsec_init_locked(sc); | ||||
| } else if (ifp->if_drv_flags & IFF_DRV_RUNNING) | } else if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) | ||||
| tsec_stop(sc); | tsec_stop(sc); | ||||
| sc->tsec_if_flags = ifp->if_flags; | sc->tsec_if_flags = if_getflags(ifp); | ||||
| TSEC_GLOBAL_UNLOCK(sc); | TSEC_GLOBAL_UNLOCK(sc); | ||||
| break; | break; | ||||
| case SIOCADDMULTI: | case SIOCADDMULTI: | ||||
| case SIOCDELMULTI: | case SIOCDELMULTI: | ||||
| if (ifp->if_drv_flags & IFF_DRV_RUNNING) { | if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { | ||||
| TSEC_GLOBAL_LOCK(sc); | TSEC_GLOBAL_LOCK(sc); | ||||
| tsec_setup_multicast(sc); | tsec_setup_multicast(sc); | ||||
| TSEC_GLOBAL_UNLOCK(sc); | TSEC_GLOBAL_UNLOCK(sc); | ||||
| } | } | ||||
| case SIOCGIFMEDIA: | case SIOCGIFMEDIA: | ||||
| case SIOCSIFMEDIA: | case SIOCSIFMEDIA: | ||||
| error = ifmedia_ioctl(ifp, ifr, &sc->tsec_mii->mii_media, | error = ifmedia_ioctl(ifp, ifr, &sc->tsec_mii->mii_media, | ||||
| command); | command); | ||||
| break; | break; | ||||
| case SIOCSIFCAP: | case SIOCSIFCAP: | ||||
| mask = ifp->if_capenable ^ ifr->ifr_reqcap; | mask = if_getcapenable(ifp) ^ ifr->ifr_reqcap; | ||||
| if ((mask & IFCAP_HWCSUM) && sc->is_etsec) { | if ((mask & IFCAP_HWCSUM) && sc->is_etsec) { | ||||
| TSEC_GLOBAL_LOCK(sc); | TSEC_GLOBAL_LOCK(sc); | ||||
| ifp->if_capenable &= ~IFCAP_HWCSUM; | if_setcapenablebit(ifp, 0, IFCAP_HWCSUM); | ||||
| ifp->if_capenable |= IFCAP_HWCSUM & ifr->ifr_reqcap; | if_setcapenablebit(ifp, IFCAP_HWCSUM & ifr->ifr_reqcap, 0); | ||||
| tsec_offload_setup(sc); | tsec_offload_setup(sc); | ||||
| TSEC_GLOBAL_UNLOCK(sc); | TSEC_GLOBAL_UNLOCK(sc); | ||||
| } | } | ||||
| #ifdef DEVICE_POLLING | #ifdef DEVICE_POLLING | ||||
| if (mask & IFCAP_POLLING) { | if (mask & IFCAP_POLLING) { | ||||
| if (ifr->ifr_reqcap & IFCAP_POLLING) { | if (ifr->ifr_reqcap & IFCAP_POLLING) { | ||||
| error = ether_poll_register(tsec_poll, ifp); | error = ether_poll_register(tsec_poll, ifp); | ||||
| if (error) | if (error) | ||||
| return (error); | return (error); | ||||
| TSEC_GLOBAL_LOCK(sc); | TSEC_GLOBAL_LOCK(sc); | ||||
| /* Disable interrupts */ | /* Disable interrupts */ | ||||
| tsec_intrs_ctl(sc, 0); | tsec_intrs_ctl(sc, 0); | ||||
| ifp->if_capenable |= IFCAP_POLLING; | if_setcapenablebit(ifp, IFCAP_POLLING, 0); | ||||
| TSEC_GLOBAL_UNLOCK(sc); | TSEC_GLOBAL_UNLOCK(sc); | ||||
| } else { | } else { | ||||
| error = ether_poll_deregister(ifp); | error = ether_poll_deregister(ifp); | ||||
| TSEC_GLOBAL_LOCK(sc); | TSEC_GLOBAL_LOCK(sc); | ||||
| /* Enable interrupts */ | /* Enable interrupts */ | ||||
| tsec_intrs_ctl(sc, 1); | tsec_intrs_ctl(sc, 1); | ||||
| ifp->if_capenable &= ~IFCAP_POLLING; | if_setcapenablebit(ifp, 0, IFCAP_POLLING); | ||||
| TSEC_GLOBAL_UNLOCK(sc); | TSEC_GLOBAL_UNLOCK(sc); | ||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| break; | break; | ||||
| default: | default: | ||||
| error = ether_ioctl(ifp, command, data); | error = ether_ioctl(ifp, command, data); | ||||
| } | } | ||||
| /* Flush buffers if not empty */ | /* Flush buffers if not empty */ | ||||
| if (ifp->if_flags & IFF_UP) | if (if_getflags(ifp) & IFF_UP) | ||||
| tsec_start(ifp); | tsec_start(ifp); | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| static int | static int | ||||
| tsec_ifmedia_upd(struct ifnet *ifp) | tsec_ifmedia_upd(if_t ifp) | ||||
| { | { | ||||
| struct tsec_softc *sc = ifp->if_softc; | struct tsec_softc *sc = if_getsoftc(ifp); | ||||
| struct mii_data *mii; | struct mii_data *mii; | ||||
| TSEC_TRANSMIT_LOCK(sc); | TSEC_TRANSMIT_LOCK(sc); | ||||
| mii = sc->tsec_mii; | mii = sc->tsec_mii; | ||||
| mii_mediachg(mii); | mii_mediachg(mii); | ||||
| TSEC_TRANSMIT_UNLOCK(sc); | TSEC_TRANSMIT_UNLOCK(sc); | ||||
| return (0); | return (0); | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) | tsec_ifmedia_sts(if_t ifp, struct ifmediareq *ifmr) | ||||
| { | { | ||||
| struct tsec_softc *sc = ifp->if_softc; | struct tsec_softc *sc = if_getsoftc(ifp); | ||||
| struct mii_data *mii; | struct mii_data *mii; | ||||
| TSEC_TRANSMIT_LOCK(sc); | TSEC_TRANSMIT_LOCK(sc); | ||||
| mii = sc->tsec_mii; | mii = sc->tsec_mii; | ||||
| mii_pollstat(mii); | mii_pollstat(mii); | ||||
| ifmr->ifm_active = mii->mii_media_active; | ifmr->ifm_active = mii->mii_media_active; | ||||
| ▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | tsec_free_dma_desc(sc->tsec_tx_dtag, sc->tsec_tx_dmap, | ||||
| sc->tsec_tx_vaddr); | sc->tsec_tx_vaddr); | ||||
| tsec_free_dma_desc(sc->tsec_rx_dtag, sc->tsec_rx_dmap, | tsec_free_dma_desc(sc->tsec_rx_dtag, sc->tsec_rx_dmap, | ||||
| sc->tsec_rx_vaddr); | sc->tsec_rx_vaddr); | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_stop(struct tsec_softc *sc) | tsec_stop(struct tsec_softc *sc) | ||||
| { | { | ||||
| struct ifnet *ifp; | if_t ifp; | ||||
| uint32_t tmpval; | uint32_t tmpval; | ||||
| TSEC_GLOBAL_LOCK_ASSERT(sc); | TSEC_GLOBAL_LOCK_ASSERT(sc); | ||||
| ifp = sc->tsec_ifp; | ifp = sc->tsec_ifp; | ||||
| /* Disable interface and watchdog timer */ | /* Disable interface and watchdog timer */ | ||||
| callout_stop(&sc->tsec_callout); | callout_stop(&sc->tsec_callout); | ||||
| ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); | if_setdrvflagbits(ifp, 0, (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)); | ||||
| sc->tsec_watchdog = 0; | sc->tsec_watchdog = 0; | ||||
| /* Disable all interrupts and stop DMA */ | /* Disable all interrupts and stop DMA */ | ||||
| tsec_intrs_ctl(sc, 0); | tsec_intrs_ctl(sc, 0); | ||||
| tsec_dma_ctl(sc, 0); | tsec_dma_ctl(sc, 0); | ||||
| /* Remove pending data from TX queue */ | /* Remove pending data from TX queue */ | ||||
| while (sc->tx_idx_tail != sc->tx_idx_head) { | while (sc->tx_idx_tail != sc->tx_idx_head) { | ||||
| Show All 13 Lines | tsec_stop(struct tsec_softc *sc) | ||||
| TSEC_WRITE(sc, TSEC_REG_MACCFG1, tmpval); | TSEC_WRITE(sc, TSEC_REG_MACCFG1, tmpval); | ||||
| DELAY(10); | DELAY(10); | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_tick(void *arg) | tsec_tick(void *arg) | ||||
| { | { | ||||
| struct tsec_softc *sc = arg; | struct tsec_softc *sc = arg; | ||||
| struct ifnet *ifp; | if_t ifp; | ||||
| int link; | int link; | ||||
| TSEC_GLOBAL_LOCK(sc); | TSEC_GLOBAL_LOCK(sc); | ||||
| tsec_watchdog(sc); | tsec_watchdog(sc); | ||||
| ifp = sc->tsec_ifp; | ifp = sc->tsec_ifp; | ||||
| link = sc->tsec_link; | link = sc->tsec_link; | ||||
| mii_tick(sc->tsec_mii); | mii_tick(sc->tsec_mii); | ||||
| if (link == 0 && sc->tsec_link == 1 && | if (link == 0 && sc->tsec_link == 1 && | ||||
| (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))) | (!if_sendq_empty(ifp))) | ||||
| tsec_start_locked(ifp); | tsec_start_locked(ifp); | ||||
| /* Schedule another timeout one second from now. */ | /* Schedule another timeout one second from now. */ | ||||
| callout_reset(&sc->tsec_callout, hz, tsec_tick, sc); | callout_reset(&sc->tsec_callout, hz, tsec_tick, sc); | ||||
| TSEC_GLOBAL_UNLOCK(sc); | TSEC_GLOBAL_UNLOCK(sc); | ||||
| } | } | ||||
| /* | /* | ||||
| * This is the core RX routine. It replenishes mbufs in the descriptor and | * This is the core RX routine. It replenishes mbufs in the descriptor and | ||||
| * sends data which have been dma'ed into host memory to upper layer. | * sends data which have been dma'ed into host memory to upper layer. | ||||
| * | * | ||||
| * Loops at most count times if count is > 0, or until done if count < 0. | * Loops at most count times if count is > 0, or until done if count < 0. | ||||
| */ | */ | ||||
| static int | static int | ||||
| tsec_receive_intr_locked(struct tsec_softc *sc, int count) | tsec_receive_intr_locked(struct tsec_softc *sc, int count) | ||||
| { | { | ||||
| struct tsec_desc *rx_desc; | struct tsec_desc *rx_desc; | ||||
| struct ifnet *ifp; | if_t ifp; | ||||
| struct rx_data_type *rx_data; | struct rx_data_type *rx_data; | ||||
| struct mbuf *m; | struct mbuf *m; | ||||
| uint32_t i; | uint32_t i; | ||||
| int c, rx_npkts; | int c, rx_npkts; | ||||
| uint16_t flags; | uint16_t flags; | ||||
| TSEC_RECEIVE_LOCK_ASSERT(sc); | TSEC_RECEIVE_LOCK_ASSERT(sc); | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | if (m != NULL) { | ||||
| m_fixhdr(m); | m_fixhdr(m); | ||||
| m_adj(m, -ETHER_CRC_LEN); | m_adj(m, -ETHER_CRC_LEN); | ||||
| if (sc->is_etsec) | if (sc->is_etsec) | ||||
| tsec_offload_process_frame(sc, m); | tsec_offload_process_frame(sc, m); | ||||
| TSEC_RECEIVE_UNLOCK(sc); | TSEC_RECEIVE_UNLOCK(sc); | ||||
| (*ifp->if_input)(ifp, m); | if_input(ifp, m); | ||||
| TSEC_RECEIVE_LOCK(sc); | TSEC_RECEIVE_LOCK(sc); | ||||
| rx_npkts++; | rx_npkts++; | ||||
| } | } | ||||
| } | } | ||||
| bus_dmamap_sync(sc->tsec_rx_dtag, sc->tsec_rx_dmap, | bus_dmamap_sync(sc->tsec_rx_dtag, sc->tsec_rx_dmap, | ||||
| BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); | ||||
| Show All 12 Lines | |||||
| void | void | ||||
| tsec_receive_intr(void *arg) | tsec_receive_intr(void *arg) | ||||
| { | { | ||||
| struct tsec_softc *sc = arg; | struct tsec_softc *sc = arg; | ||||
| TSEC_RECEIVE_LOCK(sc); | TSEC_RECEIVE_LOCK(sc); | ||||
| #ifdef DEVICE_POLLING | #ifdef DEVICE_POLLING | ||||
| if (sc->tsec_ifp->if_capenable & IFCAP_POLLING) { | if (sc->tsec_if_getcapenable(ifp) & IFCAP_POLLING) { | ||||
| TSEC_RECEIVE_UNLOCK(sc); | TSEC_RECEIVE_UNLOCK(sc); | ||||
| return; | return; | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* Confirm the interrupt was received by driver */ | /* Confirm the interrupt was received by driver */ | ||||
| TSEC_WRITE(sc, TSEC_REG_IEVENT, TSEC_IEVENT_RXB | TSEC_IEVENT_RXF); | TSEC_WRITE(sc, TSEC_REG_IEVENT, TSEC_IEVENT_RXB | TSEC_IEVENT_RXF); | ||||
| tsec_receive_intr_locked(sc, -1); | tsec_receive_intr_locked(sc, -1); | ||||
| TSEC_RECEIVE_UNLOCK(sc); | TSEC_RECEIVE_UNLOCK(sc); | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_transmit_intr_locked(struct tsec_softc *sc) | tsec_transmit_intr_locked(struct tsec_softc *sc) | ||||
| { | { | ||||
| struct ifnet *ifp; | if_t ifp; | ||||
| uint32_t tx_idx; | uint32_t tx_idx; | ||||
| TSEC_TRANSMIT_LOCK_ASSERT(sc); | TSEC_TRANSMIT_LOCK_ASSERT(sc); | ||||
| ifp = sc->tsec_ifp; | ifp = sc->tsec_ifp; | ||||
| /* Update collision statistics */ | /* Update collision statistics */ | ||||
| if_inc_counter(ifp, IFCOUNTER_COLLISIONS, TSEC_READ(sc, TSEC_REG_MON_TNCL)); | if_inc_counter(ifp, IFCOUNTER_COLLISIONS, TSEC_READ(sc, TSEC_REG_MON_TNCL)); | ||||
| Show All 33 Lines | while (tx_idx != sc->tx_idx_head) { | ||||
| tx_bufmap->mbuf = NULL; | tx_bufmap->mbuf = NULL; | ||||
| if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); | if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); | ||||
| } | } | ||||
| sc->tx_idx_tail = tx_idx; | sc->tx_idx_tail = tx_idx; | ||||
| bus_dmamap_sync(sc->tsec_tx_dtag, sc->tsec_tx_dmap, | bus_dmamap_sync(sc->tsec_tx_dtag, sc->tsec_tx_dmap, | ||||
| BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); | ||||
| ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; | if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE); | ||||
| tsec_start_locked(ifp); | tsec_start_locked(ifp); | ||||
| if (sc->tx_idx_tail == sc->tx_idx_head) | if (sc->tx_idx_tail == sc->tx_idx_head) | ||||
| sc->tsec_watchdog = 0; | sc->tsec_watchdog = 0; | ||||
| } | } | ||||
| void | void | ||||
| tsec_transmit_intr(void *arg) | tsec_transmit_intr(void *arg) | ||||
| { | { | ||||
| struct tsec_softc *sc = arg; | struct tsec_softc *sc = arg; | ||||
| TSEC_TRANSMIT_LOCK(sc); | TSEC_TRANSMIT_LOCK(sc); | ||||
| #ifdef DEVICE_POLLING | #ifdef DEVICE_POLLING | ||||
| if (sc->tsec_ifp->if_capenable & IFCAP_POLLING) { | if (sc->tsec_if_getcapenable(ifp) & IFCAP_POLLING) { | ||||
| TSEC_TRANSMIT_UNLOCK(sc); | TSEC_TRANSMIT_UNLOCK(sc); | ||||
| return; | return; | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* Confirm the interrupt was received by driver */ | /* Confirm the interrupt was received by driver */ | ||||
| TSEC_WRITE(sc, TSEC_REG_IEVENT, TSEC_IEVENT_TXB | TSEC_IEVENT_TXF); | TSEC_WRITE(sc, TSEC_REG_IEVENT, TSEC_IEVENT_TXB | TSEC_IEVENT_TXF); | ||||
| tsec_transmit_intr_locked(sc); | tsec_transmit_intr_locked(sc); | ||||
| TSEC_TRANSMIT_UNLOCK(sc); | TSEC_TRANSMIT_UNLOCK(sc); | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_error_intr_locked(struct tsec_softc *sc, int count) | tsec_error_intr_locked(struct tsec_softc *sc, int count) | ||||
| { | { | ||||
| struct ifnet *ifp; | if_t ifp; | ||||
| uint32_t eflags; | uint32_t eflags; | ||||
| TSEC_GLOBAL_LOCK_ASSERT(sc); | TSEC_GLOBAL_LOCK_ASSERT(sc); | ||||
| ifp = sc->tsec_ifp; | ifp = sc->tsec_ifp; | ||||
| eflags = TSEC_READ(sc, TSEC_REG_IEVENT); | eflags = TSEC_READ(sc, TSEC_REG_IEVENT); | ||||
| Show All 13 Lines | if (eflags & TSEC_IEVENT_TXE) { | ||||
| TSEC_WRITE(sc, TSEC_REG_TSTAT, TSEC_TSTAT_THLT); | TSEC_WRITE(sc, TSEC_REG_TSTAT, TSEC_TSTAT_THLT); | ||||
| } | } | ||||
| /* Check for discarded frame due to a lack of buffers */ | /* Check for discarded frame due to a lack of buffers */ | ||||
| if (eflags & TSEC_IEVENT_BSY) { | if (eflags & TSEC_IEVENT_BSY) { | ||||
| if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1); | if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1); | ||||
| } | } | ||||
| if (ifp->if_flags & IFF_DEBUG) | if (if_getflags(ifp) & IFF_DEBUG) | ||||
| if_printf(ifp, "tsec_error_intr(): event flags: 0x%x\n", | if_printf(ifp, "tsec_error_intr(): event flags: 0x%x\n", | ||||
| eflags); | eflags); | ||||
| if (eflags & TSEC_IEVENT_EBERR) { | if (eflags & TSEC_IEVENT_EBERR) { | ||||
| if_printf(ifp, "System bus error occurred during" | if_printf(ifp, "System bus error occurred during" | ||||
| "DMA transaction (flags: 0x%x)\n", eflags); | "DMA transaction (flags: 0x%x)\n", eflags); | ||||
| tsec_init_locked(sc); | tsec_init_locked(sc); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 259 Lines • ▼ Show 20 Lines | tsec_set_txic(struct tsec_softc *sc) | ||||
| } | } | ||||
| TSEC_WRITE(sc, TSEC_REG_TXIC, txic_val); | TSEC_WRITE(sc, TSEC_REG_TXIC, txic_val); | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_offload_setup(struct tsec_softc *sc) | tsec_offload_setup(struct tsec_softc *sc) | ||||
| { | { | ||||
| struct ifnet *ifp = sc->tsec_ifp; | if_t ifp = sc->tsec_ifp; | ||||
| uint32_t reg; | uint32_t reg; | ||||
| TSEC_GLOBAL_LOCK_ASSERT(sc); | TSEC_GLOBAL_LOCK_ASSERT(sc); | ||||
| reg = TSEC_READ(sc, TSEC_REG_TCTRL); | reg = TSEC_READ(sc, TSEC_REG_TCTRL); | ||||
| reg |= TSEC_TCTRL_IPCSEN | TSEC_TCTRL_TUCSEN; | reg |= TSEC_TCTRL_IPCSEN | TSEC_TCTRL_TUCSEN; | ||||
| if (ifp->if_capenable & IFCAP_TXCSUM) | if (if_getcapenable(ifp) & IFCAP_TXCSUM) | ||||
| ifp->if_hwassist = TSEC_CHECKSUM_FEATURES; | if_sethwassist(ifp, TSEC_CHECKSUM_FEATURES); | ||||
| else | else | ||||
| ifp->if_hwassist = 0; | if_sethwassist(ifp, 0); | ||||
| TSEC_WRITE(sc, TSEC_REG_TCTRL, reg); | TSEC_WRITE(sc, TSEC_REG_TCTRL, reg); | ||||
| reg = TSEC_READ(sc, TSEC_REG_RCTRL); | reg = TSEC_READ(sc, TSEC_REG_RCTRL); | ||||
| reg &= ~(TSEC_RCTRL_IPCSEN | TSEC_RCTRL_TUCSEN | TSEC_RCTRL_PRSDEP); | reg &= ~(TSEC_RCTRL_IPCSEN | TSEC_RCTRL_TUCSEN | TSEC_RCTRL_PRSDEP); | ||||
| reg |= TSEC_RCTRL_PRSDEP_PARSE_L2 | TSEC_RCTRL_VLEX; | reg |= TSEC_RCTRL_PRSDEP_PARSE_L2 | TSEC_RCTRL_VLEX; | ||||
| if (ifp->if_capenable & IFCAP_RXCSUM) | if (if_getcapenable(ifp) & IFCAP_RXCSUM) | ||||
| reg |= TSEC_RCTRL_IPCSEN | TSEC_RCTRL_TUCSEN | | reg |= TSEC_RCTRL_IPCSEN | TSEC_RCTRL_TUCSEN | | ||||
| TSEC_RCTRL_PRSDEP_PARSE_L234; | TSEC_RCTRL_PRSDEP_PARSE_L234; | ||||
| TSEC_WRITE(sc, TSEC_REG_RCTRL, reg); | TSEC_WRITE(sc, TSEC_REG_RCTRL, reg); | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_offload_process_frame(struct tsec_softc *sc, struct mbuf *m) | tsec_offload_process_frame(struct tsec_softc *sc, struct mbuf *m) | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | tsec_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt) | ||||
| return (1); | return (1); | ||||
| } | } | ||||
| static void | static void | ||||
| tsec_setup_multicast(struct tsec_softc *sc) | tsec_setup_multicast(struct tsec_softc *sc) | ||||
| { | { | ||||
| uint32_t hashtable[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; | uint32_t hashtable[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; | ||||
| struct ifnet *ifp = sc->tsec_ifp; | if_t ifp = sc->tsec_ifp; | ||||
| int i; | int i; | ||||
| TSEC_GLOBAL_LOCK_ASSERT(sc); | TSEC_GLOBAL_LOCK_ASSERT(sc); | ||||
| if (ifp->if_flags & IFF_ALLMULTI) { | if (if_getflags(ifp) & IFF_ALLMULTI) { | ||||
| for (i = 0; i < 8; i++) | for (i = 0; i < 8; i++) | ||||
| TSEC_WRITE(sc, TSEC_REG_GADDR(i), 0xFFFFFFFF); | TSEC_WRITE(sc, TSEC_REG_GADDR(i), 0xFFFFFFFF); | ||||
| return; | return; | ||||
| } | } | ||||
| if_foreach_llmaddr(ifp, tsec_hash_maddr, &hashtable); | if_foreach_llmaddr(ifp, tsec_hash_maddr, &hashtable); | ||||
| Show All 19 Lines | |||||