Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/le/am79900.c
| Show First 20 Lines • Show All 179 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 | ||||
| am79900_meminit(struct lance_softc *sc) | am79900_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_HTOLE32(LE_MODE_NORMAL | LE_MODE_PROM); | init.init_mode = LE_HTOLE32(LE_MODE_NORMAL | LE_MODE_PROM); | ||||
| else | else | ||||
| init.init_mode = LE_HTOLE32(LE_MODE_NORMAL); | init.init_mode = LE_HTOLE32(LE_MODE_NORMAL); | ||||
| init.init_mode |= LE_HTOLE32(((ffs(sc->sc_ntbuf) - 1) << 28) | | init.init_mode |= LE_HTOLE32(((ffs(sc->sc_ntbuf) - 1) << 28) | | ||||
| ((ffs(sc->sc_nrbuf) - 1) << 20)); | ((ffs(sc->sc_nrbuf) - 1) << 20)); | ||||
| init.init_padr[0] = LE_HTOLE32(sc->sc_enaddr[0] | | init.init_padr[0] = LE_HTOLE32(sc->sc_enaddr[0] | | ||||
| Show All 40 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 inline void | static inline void | ||||
| am79900_rint(struct lance_softc *sc) | am79900_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; | ||||
| uint32_t rmd1; | uint32_t rmd1; | ||||
| int bix, rp; | int bix, rp; | ||||
| #if defined(__i386__) | #if defined(__i386__) | ||||
| struct ether_header *eh; | struct ether_header *eh; | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | #if defined(__i386__) | ||||
| if (!ether_cmp(eh->ether_shost, sc->sc_enaddr)) { | if (!ether_cmp(eh->ether_shost, sc->sc_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 inline void | static inline void | ||||
| am79900_tint(struct lance_softc *sc) | am79900_tint(struct lance_softc *sc) | ||||
| { | { | ||||
| struct ifnet *ifp = sc->sc_ifp; | if_t ifp = sc->sc_ifp; | ||||
| struct letmd tmd; | struct letmd tmd; | ||||
| uint32_t tmd1, tmd2; | uint32_t tmd1, tmd2; | ||||
| 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) | ||||
| Show All 9 Lines | if (sc->sc_flags & LE_DEBUG) | ||||
| if_printf(ifp, "trans tmd: " | if_printf(ifp, "trans tmd: " | ||||
| "adr %08x, flags/blen %08x\n", | "adr %08x, flags/blen %08x\n", | ||||
| LE_LE32TOH(tmd.tmd0), tmd1); | LE_LE32TOH(tmd.tmd0), tmd1); | ||||
| #endif | #endif | ||||
| if (tmd1 & LE_T1_OWN) | if (tmd1 & LE_T1_OWN) | ||||
| break; | break; | ||||
| ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; | if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE); | ||||
| if (tmd1 & LE_T1_ERR) { | if (tmd1 & LE_T1_ERR) { | ||||
| tmd2 = LE_LE32TOH(tmd.tmd2); | tmd2 = LE_LE32TOH(tmd.tmd2); | ||||
| if (tmd2 & LE_T2_BUFF) | if (tmd2 & LE_T2_BUFF) | ||||
| if_printf(ifp, "transmit buffer error\n"); | if_printf(ifp, "transmit buffer error\n"); | ||||
| else if (tmd2 & LE_T2_UFLO) | else if (tmd2 & LE_T2_UFLO) | ||||
| if_printf(ifp, "underflow\n"); | if_printf(ifp, "underflow\n"); | ||||
| if (tmd2 & (LE_T2_BUFF | LE_T2_UFLO)) { | if (tmd2 & (LE_T2_BUFF | LE_T2_UFLO)) { | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| /* | /* | ||||
| * Controller interrupt | * Controller interrupt | ||||
| */ | */ | ||||
| void | void | ||||
| am79900_intr(void *arg) | am79900_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) | ||||
| am79900_rint(sc); | am79900_rint(sc); | ||||
| if (isr & LE_C0_TINT) | if (isr & LE_C0_TINT) | ||||
| am79900_tint(sc); | am79900_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)) | ||||
| am79900_start_locked(sc); | am79900_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 | ||||
| am79900_start_locked(struct lance_softc *sc) | am79900_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 (LE_LE32TOH(tmd.tmd1) & LE_T1_OWN) { | if (LE_LE32TOH(tmd.tmd1) & 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 25 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 | ||||
| am79900_recv_print(struct lance_softc *sc, int no) | am79900_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 = LE_LE32TOH(rmd.rmd2) & 0xfff; | len = LE_LE32TOH(rmd.rmd2) & 0xfff; | ||||
| 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, "adr %08x, flags/blen %08x\n", LE_LE32TOH(rmd.rmd0), | if_printf(ifp, "adr %08x, flags/blen %08x\n", LE_LE32TOH(rmd.rmd0), | ||||
| LE_LE32TOH(rmd.rmd1)); | LE_LE32TOH(rmd.rmd1)); | ||||
| 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 | ||||
| am79900_xmit_print(struct lance_softc *sc, int no) | am79900_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 = -(LE_LE32TOH(tmd.tmd1) & 0xfff); | len = -(LE_LE32TOH(tmd.tmd1) & 0xfff); | ||||
| 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 10 Lines | |||||