From 2e6450e7f86ddd2ad328bb0d3410c4189a15f25b Mon Sep 17 00:00:00 2001
From: David Gwynne <dlg@cvs.openbsd.org>
Date: Sun, 22 Apr 2007 04:38:32 +0000
Subject: start implementing processing of the rx descriptor fifo. this is the
 one that returns rx buffers to us that we previously posted in the rx free.
 theoretically we should now be receiving packets.

practically, im still waiting on a cable so i can plug this card into
something and test it, and then that's going to be difficult cos i only
have two tht cards to test it. i need tx and rx working before i can test
if tx and rx work. fun fun fun.

this code doesnt process rx data change descriptors yet.
---
 sys/dev/pci/if_tht.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 60 insertions(+), 4 deletions(-)

(limited to 'sys')

diff --git a/sys/dev/pci/if_tht.c b/sys/dev/pci/if_tht.c
index 04f5a590766..34280d73016 100644
--- a/sys/dev/pci/if_tht.c
+++ b/sys/dev/pci/if_tht.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: if_tht.c,v 1.47 2007/04/22 04:24:40 dlg Exp $ */
+/*	$OpenBSD: if_tht.c,v 1.48 2007/04/22 04:38:31 dlg Exp $ */
 
 /*
  * Copyright (c) 2007 David Gwynne <dlg@openbsd.org>
@@ -470,6 +470,7 @@ void			tht_start(struct ifnet *);
 
 void			tht_rxf_fill(struct tht_softc *, int);
 void			tht_rxf_drain(struct tht_softc *);
+void			tht_rxd(struct tht_softc *);
 
 void			tht_up(struct tht_softc *);
 void			tht_down(struct tht_softc *);
@@ -829,14 +830,13 @@ tht_start(struct ifnet *ifp)
 	/* do nothing */
 }
 
-
 void
 tht_rxf_fill(struct tht_softc *sc, int wait)
 {
-	struct tht_rx_free		rxf;
-	struct tht_pbd			pbd;
 	bus_dma_tag_t			dmat = sc->sc_thtc->sc_dmat;
 	bus_dmamap_t			dmap;
+	struct tht_rx_free		rxf;
+	struct tht_pbd			pbd;
 	struct tht_pkt			*pkt;
 	struct mbuf			*m;
 	u_int64_t			dva;
@@ -926,6 +926,62 @@ tht_rxf_drain(struct tht_softc *sc)
 	}
 }
 
+void
+tht_rxd(struct tht_softc *sc)
+{
+	struct ifnet			*ifp = &sc->sc_ac.ac_if;
+	bus_dma_tag_t			dmat = sc->sc_thtc->sc_dmat;
+	bus_dmamap_t			dmap;
+	struct tht_rx_desc		rxd;
+	struct tht_pkt			*pkt;
+	struct mbuf			*m;
+	int				ready, bc;
+	u_int32_t			flags;
+
+	ready = sc->sc_rxd.tf_len - tht_fifo_ready(sc, &sc->sc_rxd);
+	if (ready == 0)
+		return;
+
+	tht_fifo_pre(sc, &sc->sc_rxd);
+
+	do {
+		tht_fifo_read(sc, &sc->sc_rxd, &rxd, sizeof(rxd));
+		ready -= sizeof(rxd);
+
+		flags = letoh32(rxd.flags);
+		bc = THT_RXD_FLAGS_BC(flags) * 8;
+		bc -= sizeof(rxd);
+		pkt = &sc->sc_rx_list.tpl_pkts[rxd.uid];
+
+		dmap = pkt->tp_dmap;
+
+		bus_dmamap_sync(dmat, dmap, 0, dmap->dm_mapsize,
+		    BUS_DMASYNC_POSTREAD);
+		bus_dmamap_unload(dmat, dmap);
+
+		m = pkt->tp_m;
+		m->m_pkthdr.rcvif = ifp;
+		m->m_pkthdr.len = m->m_len = letoh16(rxd.len);
+
+		/* XXX process type 3 rx descriptors */
+
+		ether_input_mbuf(ifp, m);
+
+		tht_pkt_put(&sc->sc_rx_list, pkt);
+
+		while (bc > 0) {
+			static u_int32_t pad;
+
+			tht_fifo_read(sc, &sc->sc_rxd, &pad, sizeof(pad));
+			ready -= sizeof(pad);
+			bc -= sizeof(pad);
+		}
+
+	} while (ready > 0);
+
+	tht_fifo_post(sc, &sc->sc_rxd);
+}
+
 void
 tht_watchdog(struct ifnet *ifp)
 {
-- 
cgit v1.2.3