Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/le/am7990.c
| Show First 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* | /* | ||||
| * Set up the initialization block and the descriptor rings. | * Set up the initialization block and the descriptor rings. | ||||
| */ | */ | ||||
| static void | static void | ||||
| am7990_meminit(struct lance_softc *sc) | am7990_meminit(struct lance_softc *sc) | ||||
| { | { | ||||
| struct ifnet *ifp = sc->sc_ifp; | if_t ifp = sc->sc_ifp; | ||||
| struct leinit init; | struct leinit init; | ||||
| struct lermd rmd; | struct lermd rmd; | ||||
| struct letmd tmd; | struct letmd tmd; | ||||
| u_long a; | u_long a; | ||||
| int bix; | int bix; | ||||
| LE_LOCK_ASSERT(sc, MA_OWNED); | LE_LOCK_ASSERT(sc, MA_OWNED); | ||||
| if (ifp->if_flags & IFF_PROMISC) | if (if_getflags(ifp) & IFF_PROMISC) | ||||
| init.init_mode = LE_MODE_NORMAL | LE_MODE_PROM; | init.init_mode = LE_MODE_NORMAL | LE_MODE_PROM; | ||||
| else | else | ||||
| init.init_mode = LE_MODE_NORMAL; | init.init_mode = LE_MODE_NORMAL; | ||||
| init.init_padr[0] = (sc->sc_enaddr[1] << 8) | sc->sc_enaddr[0]; | init.init_padr[0] = (sc->sc_enaddr[1] << 8) | sc->sc_enaddr[0]; | ||||
| init.init_padr[1] = (sc->sc_enaddr[3] << 8) | sc->sc_enaddr[2]; | init.init_padr[1] = (sc->sc_enaddr[3] << 8) | sc->sc_enaddr[2]; | ||||
| init.init_padr[2] = (sc->sc_enaddr[5] << 8) | sc->sc_enaddr[4]; | init.init_padr[2] = (sc->sc_enaddr[5] << 8) | sc->sc_enaddr[4]; | ||||
| lance_setladrf(sc, init.init_ladrf); | lance_setladrf(sc, init.init_ladrf); | ||||
| Show All 38 Lines | for (bix = 0; bix < sc->sc_ntbuf; bix++) { | ||||
| (*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix), | (*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix), | ||||
| sizeof(tmd)); | sizeof(tmd)); | ||||
| } | } | ||||
| } | } | ||||
| static void | static void | ||||
| am7990_rint(struct lance_softc *sc) | am7990_rint(struct lance_softc *sc) | ||||
| { | { | ||||
| struct ifnet *ifp = sc->sc_ifp; | if_t ifp = sc->sc_ifp; | ||||
| struct mbuf *m; | struct mbuf *m; | ||||
| struct lermd rmd; | struct lermd rmd; | ||||
| int bix, rp; | int bix, rp; | ||||
| #if defined(LANCE_REVC_BUG) | #if defined(LANCE_REVC_BUG) | ||||
| struct ether_header *eh; | struct ether_header *eh; | ||||
| /* Make sure this is short-aligned, for ether_cmp(). */ | /* Make sure this is short-aligned, for ether_cmp(). */ | ||||
| static uint16_t bcast_enaddr[3] = { ~0, ~0, ~0 }; | static uint16_t bcast_enaddr[3] = { ~0, ~0, ~0 }; | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | #ifdef LANCE_REVC_BUG | ||||
| ether_cmp(eh->ether_dhost, bcast_enaddr)) { | ether_cmp(eh->ether_dhost, bcast_enaddr)) { | ||||
| m_freem(m); | m_freem(m); | ||||
| continue; | continue; | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* Pass the packet up. */ | /* Pass the packet up. */ | ||||
| LE_UNLOCK(sc); | LE_UNLOCK(sc); | ||||
| (*ifp->if_input)(ifp, m); | if_input(ifp, m); | ||||
| LE_LOCK(sc); | LE_LOCK(sc); | ||||
| } else | } else | ||||
| if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); | if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); | ||||
| } | } | ||||
| sc->sc_last_rd = bix; | sc->sc_last_rd = bix; | ||||
| } | } | ||||
| static void | static void | ||||
| am7990_tint(struct lance_softc *sc) | am7990_tint(struct lance_softc *sc) | ||||
| { | { | ||||
| struct ifnet *ifp = sc->sc_ifp; | if_t ifp = sc->sc_ifp; | ||||
| struct letmd tmd; | struct letmd tmd; | ||||
| int bix; | int bix; | ||||
| bix = sc->sc_first_td; | bix = sc->sc_first_td; | ||||
| for (;;) { | for (;;) { | ||||
| if (sc->sc_no_td <= 0) | if (sc->sc_no_td <= 0) | ||||
| break; | break; | ||||
| (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix), | (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix), | ||||
| sizeof(tmd)); | sizeof(tmd)); | ||||
| #ifdef LEDEBUG | #ifdef LEDEBUG | ||||
| if (sc->sc_flags & LE_DEBUG) | if (sc->sc_flags & LE_DEBUG) | ||||
| if_printf(ifp, "trans tmd: " | if_printf(ifp, "trans tmd: " | ||||
| "ladr %04x, hadr %02x, flags %02x, " | "ladr %04x, hadr %02x, flags %02x, " | ||||
| "bcnt %04x, mcnt %04x\n", | "bcnt %04x, mcnt %04x\n", | ||||
| tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits, | tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits, | ||||
| tmd.tmd2, tmd.tmd3); | tmd.tmd2, tmd.tmd3); | ||||
| #endif | #endif | ||||
| if (tmd.tmd1_bits & LE_T1_OWN) | if (tmd.tmd1_bits & LE_T1_OWN) | ||||
| break; | break; | ||||
| ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; | if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE); | ||||
| if (tmd.tmd1_bits & LE_T1_ERR) { | if (tmd.tmd1_bits & LE_T1_ERR) { | ||||
| if (tmd.tmd3 & LE_T3_BUFF) | if (tmd.tmd3 & LE_T3_BUFF) | ||||
| if_printf(ifp, "transmit buffer error\n"); | if_printf(ifp, "transmit buffer error\n"); | ||||
| else if (tmd.tmd3 & LE_T3_UFLO) | else if (tmd.tmd3 & LE_T3_UFLO) | ||||
| if_printf(ifp, "underflow\n"); | if_printf(ifp, "underflow\n"); | ||||
| if (tmd.tmd3 & (LE_T3_BUFF | LE_T3_UFLO)) { | if (tmd.tmd3 & (LE_T3_BUFF | LE_T3_UFLO)) { | ||||
| lance_init_locked(sc); | lance_init_locked(sc); | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| /* | /* | ||||
| * Controller interrupt | * Controller interrupt | ||||
| */ | */ | ||||
| void | void | ||||
| am7990_intr(void *arg) | am7990_intr(void *arg) | ||||
| { | { | ||||
| struct lance_softc *sc = arg; | struct lance_softc *sc = arg; | ||||
| struct ifnet *ifp = sc->sc_ifp; | if_t ifp = sc->sc_ifp; | ||||
| uint16_t isr; | uint16_t isr; | ||||
| LE_LOCK(sc); | LE_LOCK(sc); | ||||
| if (sc->sc_hwintr && (*sc->sc_hwintr)(sc) == -1) { | if (sc->sc_hwintr && (*sc->sc_hwintr)(sc) == -1) { | ||||
| if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); | if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); | ||||
| lance_init_locked(sc); | lance_init_locked(sc); | ||||
| LE_UNLOCK(sc); | LE_UNLOCK(sc); | ||||
| ▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | #endif | ||||
| if (isr & LE_C0_RINT) | if (isr & LE_C0_RINT) | ||||
| am7990_rint(sc); | am7990_rint(sc); | ||||
| if (isr & LE_C0_TINT) | if (isr & LE_C0_TINT) | ||||
| am7990_tint(sc); | am7990_tint(sc); | ||||
| /* Enable interrupts again. */ | /* Enable interrupts again. */ | ||||
| (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA); | (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA); | ||||
| if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) | if (!if_sendq_empty(ifp)) | ||||
| am7990_start_locked(sc); | am7990_start_locked(sc); | ||||
| LE_UNLOCK(sc); | LE_UNLOCK(sc); | ||||
| } | } | ||||
| /* | /* | ||||
| * Set up output on interface. | * Set up output on interface. | ||||
| * Get another datagram to send off of the interface queue, and map it to the | * Get another datagram to send off of the interface queue, and map it to the | ||||
| * interface before starting the output. | * interface before starting the output. | ||||
| */ | */ | ||||
| static void | static void | ||||
| am7990_start_locked(struct lance_softc *sc) | am7990_start_locked(struct lance_softc *sc) | ||||
| { | { | ||||
| struct ifnet *ifp = sc->sc_ifp; | if_t ifp = sc->sc_ifp; | ||||
| struct letmd tmd; | struct letmd tmd; | ||||
| struct mbuf *m; | struct mbuf *m; | ||||
| int bix, enq, len, rp; | int bix, enq, len, rp; | ||||
| LE_LOCK_ASSERT(sc, MA_OWNED); | LE_LOCK_ASSERT(sc, MA_OWNED); | ||||
| if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != | if ((if_getdrvflags(ifp) & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != | ||||
| IFF_DRV_RUNNING) | IFF_DRV_RUNNING) | ||||
| return; | return; | ||||
| bix = sc->sc_last_td; | bix = sc->sc_last_td; | ||||
| enq = 0; | enq = 0; | ||||
| for (; sc->sc_no_td < sc->sc_ntbuf && | for (; sc->sc_no_td < sc->sc_ntbuf && | ||||
| !IFQ_DRV_IS_EMPTY(&ifp->if_snd);) { | !if_sendq_empty(ifp);) { | ||||
| rp = LE_TMDADDR(sc, bix); | rp = LE_TMDADDR(sc, bix); | ||||
| (*sc->sc_copyfromdesc)(sc, &tmd, rp, sizeof(tmd)); | (*sc->sc_copyfromdesc)(sc, &tmd, rp, sizeof(tmd)); | ||||
| if (tmd.tmd1_bits & LE_T1_OWN) { | if (tmd.tmd1_bits & LE_T1_OWN) { | ||||
| ifp->if_drv_flags |= IFF_DRV_OACTIVE; | if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0); | ||||
| if_printf(ifp, | if_printf(ifp, | ||||
| "missing buffer, no_td = %d, last_td = %d\n", | "missing buffer, no_td = %d, last_td = %d\n", | ||||
| sc->sc_no_td, sc->sc_last_td); | sc->sc_no_td, sc->sc_last_td); | ||||
| } | } | ||||
| IFQ_DRV_DEQUEUE(&ifp->if_snd, m); | m = if_dequeue(ifp); | ||||
| if (m == NULL) | if (m == NULL) | ||||
| break; | break; | ||||
| /* | /* | ||||
| * If BPF is listening on this interface, let it see the packet | * If BPF is listening on this interface, let it see the packet | ||||
| * before we commit it to the wire. | * before we commit it to the wire. | ||||
| */ | */ | ||||
| BPF_MTAP(ifp, m); | BPF_MTAP(ifp, m); | ||||
| Show All 24 Lines | #endif | ||||
| (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD); | (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD); | ||||
| enq++; | enq++; | ||||
| if (++bix == sc->sc_ntbuf) | if (++bix == sc->sc_ntbuf) | ||||
| bix = 0; | bix = 0; | ||||
| if (++sc->sc_no_td == sc->sc_ntbuf) { | if (++sc->sc_no_td == sc->sc_ntbuf) { | ||||
| ifp->if_drv_flags |= IFF_DRV_OACTIVE; | if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| sc->sc_last_td = bix; | sc->sc_last_td = bix; | ||||
| if (enq > 0) | if (enq > 0) | ||||
| sc->sc_wdog_timer = 5; | sc->sc_wdog_timer = 5; | ||||
| } | } | ||||
| #ifdef LEDEBUG | #ifdef LEDEBUG | ||||
| static void | static void | ||||
| am7990_recv_print(struct lance_softc *sc, int no) | am7990_recv_print(struct lance_softc *sc, int no) | ||||
| { | { | ||||
| struct ifnet *ifp = sc->sc_ifp; | if_t ifp = sc->sc_ifp; | ||||
| struct ether_header eh; | struct ether_header eh; | ||||
| struct lermd rmd; | struct lermd rmd; | ||||
| uint16_t len; | uint16_t len; | ||||
| (*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd)); | (*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd)); | ||||
| len = rmd.rmd3; | len = rmd.rmd3; | ||||
| if_printf(ifp, "receive buffer %d, len = %d\n", no, len); | if_printf(ifp, "receive buffer %d, len = %d\n", no, len); | ||||
| if_printf(ifp, "status %04x\n", (*sc->sc_rdcsr)(sc, LE_CSR0)); | if_printf(ifp, "status %04x\n", (*sc->sc_rdcsr)(sc, LE_CSR0)); | ||||
| if_printf(ifp, | if_printf(ifp, | ||||
| "ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n", | "ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n", | ||||
| rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits, rmd.rmd2, rmd.rmd3); | rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits, rmd.rmd2, rmd.rmd3); | ||||
| if (len - ETHER_CRC_LEN >= sizeof(eh)) { | if (len - ETHER_CRC_LEN >= sizeof(eh)) { | ||||
| (*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh)); | (*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh)); | ||||
| if_printf(ifp, "dst %s", ether_sprintf(eh.ether_dhost)); | if_printf(ifp, "dst %s", ether_sprintf(eh.ether_dhost)); | ||||
| printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), | printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), | ||||
| ntohs(eh.ether_type)); | ntohs(eh.ether_type)); | ||||
| } | } | ||||
| } | } | ||||
| static void | static void | ||||
| am7990_xmit_print(struct lance_softc *sc, int no) | am7990_xmit_print(struct lance_softc *sc, int no) | ||||
| { | { | ||||
| struct ifnet *ifp = sc->sc_ifp; | if_t ifp = sc->sc_ifp; | ||||
| struct ether_header eh; | struct ether_header eh; | ||||
| struct letmd tmd; | struct letmd tmd; | ||||
| uint16_t len; | uint16_t len; | ||||
| (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd)); | (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd)); | ||||
| len = -tmd.tmd2; | len = -tmd.tmd2; | ||||
| if_printf(ifp, "transmit buffer %d, len = %d\n", no, len); | if_printf(ifp, "transmit buffer %d, len = %d\n", no, len); | ||||
| if_printf(ifp, "status %04x\n", (*sc->sc_rdcsr)(sc, LE_CSR0)); | if_printf(ifp, "status %04x\n", (*sc->sc_rdcsr)(sc, LE_CSR0)); | ||||
| Show All 11 Lines | |||||