PERFORCE change 168972 for review
Yohanes Nugroho
yohanes at FreeBSD.org
Mon Sep 28 14:04:47 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=168972
Change 168972 by yohanes at econa on 2009/09/28 14:04:34
network speed improvement
Affected files ...
.. //depot/projects/str91xx/src/sys/arm/conf/CNS11XXNAS#3 edit
.. //depot/projects/str91xx/src/sys/arm/econa/econa_machdep.c#2 edit
.. //depot/projects/str91xx/src/sys/arm/econa/if_ece.c#4 edit
.. //depot/projects/str91xx/src/sys/arm/econa/timer.c#3 edit
Differences ...
==== //depot/projects/str91xx/src/sys/arm/conf/CNS11XXNAS#3 (text+ko) ====
@@ -33,7 +33,6 @@
makeoptions MODULES_OVERRIDE=""
makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols
-makeoptions CONF_CFLAGS= -march=armv4
options HZ=100
options DEVICE_POLLING
==== //depot/projects/str91xx/src/sys/arm/econa/econa_machdep.c#2 (text+ko) ====
==== //depot/projects/str91xx/src/sys/arm/econa/if_ece.c#4 (text+ko) ====
@@ -39,6 +39,7 @@
#include <sys/sockio.h>
#include <sys/sysctl.h>
#include <machine/bus.h>
+#include <sys/taskqueue.h>
#include <net/ethernet.h>
#include <net/if.h>
@@ -61,9 +62,11 @@
#include <dev/mii/mii.h>
#include <dev/mii/miivar.h>
#include <arm/econa/if_ece.h>
+#include <machine/intr.h>
#include "miibus_if.h"
+
#define ECE_MAX_TX_BUFFERS 256
#define ECE_MAX_RX_BUFFERS 256
@@ -77,6 +80,8 @@
struct mtx sc_mtx_tx; /* tx mutex */
struct mtx sc_mtx_rx; /* rx mutex */
+ bus_dma_tag_t sc_parent_tag; /* parent bus DMA tag */
+
device_t dev; /* Myself */
device_t miibus; /* My child miibus */
void *intrhand; /* Interrupt handle */
@@ -91,37 +96,43 @@
struct callout tick_ch; /* Tick callout */
+ bus_dmamap_t dmamap_tx;
+ bus_dmamap_t dmamap_rx;
+
- bus_dmamap_t desc_dmap_tx;
- bus_dmamap_t desc_dmap_rx;
+ bus_dmamap_t sparemap_rx;
+
eth_tx_desc_t* desc_tx;
eth_rx_desc_t* desc_rx;
- bus_addr_t ece_desc_paddr_tx; //desc_start_tx
- bus_addr_t ece_desc_paddr_rx; //desc_start_rx
- bus_dmamap_t dmap_tx;
- bus_dmamap_t dmap_rx;
+ bus_dma_tag_t dmatag_ring_tx;
+ bus_dma_tag_t dmatag_ring_rx;
+
+ bus_addr_t ring_paddr_tx;
+ bus_addr_t ring_paddr_rx;
+ bus_dmamap_t dmap_tx[ECE_MAX_TX_BUFFERS];
+ bus_dmamap_t dmap_rx[ECE_MAX_TX_BUFFERS];
struct mbuf* buffer_tx[ECE_MAX_TX_BUFFERS];
struct mbuf* buffer_rx[ECE_MAX_RX_BUFFERS];
- bus_dma_tag_t ece_desc_dtag_tx;
- bus_dma_tag_t ece_desc_dtag_rx;
- bus_dma_tag_t ece_dtag_tx;
- bus_dma_tag_t ece_dtag_rx;
+ bus_dma_tag_t dmatag_tx;
+ bus_dma_tag_t dmatag_rx;
- bus_addr_t desc_start_tx;
- bus_addr_t desc_start_rx;
uint32_t desc_curr_tx;
uint32_t desc_curr_rx;
uint32_t curr_tx_mbuf;
-
+ int sent_position[ECE_MAX_RX_BUFFERS];
int use_rmii;
+ struct taskqueue *sc_tq;
+ struct task sc_intr_task;
+ struct task sc_tx_task;
+
};
@@ -201,21 +212,20 @@
mtx_init(&_sc->sc_mtx_tx, device_get_nameunit(_sc->dev), \
"ECE TX Lock", MTX_DEF)
-
#define ECE_RXLOCK(_sc) mtx_lock(&(_sc)->sc_mtx_rx)
#define ECE_RXUNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx_rx)
#define ECE_RXLOCK_INIT(_sc) \
mtx_init(&_sc->sc_mtx_rx, device_get_nameunit(_sc->dev), \
"ECE RX Lock", MTX_DEF)
+#define ECE_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx);
+#define ECE_TXLOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx_tx);
+#define ECE_RXLOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx_rx);
-#define ECE_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx);
#define ECE_ASSERT_LOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED);
#define ECE_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED);
-
-
static devclass_t ece_devclass;
/* ifnet entry points */
@@ -253,14 +263,63 @@
static void set_vlan_vid(struct ece_softc *sc, int vlan, int vid);
static void set_vlan_member(struct ece_softc *sc, int vlan, int group);
static void set_vlan_tag(struct ece_softc *sc, int vlan, int tag);
-static int phy_read(struct ece_softc *sc, int phy, int reg);
-static void phy_write(struct ece_softc *sc, int phy, int reg, int data);
static int gsw_hardware_init(struct ece_softc *sc);
static void ece_intr_rx_locked(struct ece_softc *sc, int count);
static void ece_free_desc_dma_tx(struct ece_softc *sc);
static void ece_free_desc_dma_rx(struct ece_softc *sc);
+static void ece_intr_task(void *arg, int pending __unused);
+static void ece_tx_task(void *arg, int pending __unused);
+
+static int ece_allocate_dma(struct ece_softc *sc);
+
+static inline int
+phy_read(struct ece_softc *sc, int phy, int reg)
+{
+ int val;
+ int ii;
+ int status;
+
+
+ WR4(sc, PHY_CONTROL, 1 << 15);
+
+ WR4(sc, PHY_CONTROL, ((phy & 0x1) |
+ ((reg & 0x1F) << 8) | (0x1 << 14)));
+
+ for (ii = 0; ii < 0x1000; ii++) {
+ status = RD4(sc, PHY_CONTROL);
+ if (status & (0x1 << 15)) {
+ /* clear the rw_ok status, and clear other bits value */
+ WR4(sc, PHY_CONTROL, (0x1 << 15));
+ val = ((status >> 16) & 0xFFFF);
+ return val;
+ }
+ }
+ return 0;
+}
+
+
+static inline void
+phy_write(struct ece_softc *sc, int phy, int reg, int data)
+{
+ int ii;
+
+ WR4(sc, PHY_CONTROL, 1 << 15);
+
+ WR4(sc, PHY_CONTROL,
+ ((phy & 0x1) | ((reg & 0x1F) << 8) |
+ (0x1 << 13) | ((data & 0xFFFF) << 16)));
+
+ for (ii = 0; ii < 0x1000; ii++) {
+ if (RD4(sc, PHY_CONTROL) & (0x1 << 15)) {
+ /* clear the rw_ok status, and clear other bits value */
+ WR4(sc, PHY_CONTROL, (0x1 << 15));
+ return;
+ }
+ }
+}
+
static int
ece_probe(device_t dev)
@@ -297,6 +356,7 @@
}
+
static int
ece_attach(device_t dev)
{
@@ -313,7 +373,7 @@
poweron();
- //DEBUG_TRACE;
+ //
sc->dev = dev;
@@ -326,7 +386,7 @@
goto out;
- //DEBUG_TRACE;
+ //
rid = 2; /*FSRC: Fm-Switch-Rx-Complete*/
sc->irq_res_rec = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
RF_ACTIVE);
@@ -339,7 +399,7 @@
if (sc->irq_res_status == NULL)
goto out;
- //DEBUG_TRACE;
+ //
rid = 4; /*FSQF: Fm-Switch-Queue-Full*/
sc->irq_res_qf = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
RF_ACTIVE);
@@ -347,7 +407,10 @@
goto out;
- //DEBUG_TRACE;
+
+ //
+
+
err = ece_activate(dev);
if (err)
@@ -394,20 +457,22 @@
}
}
+ DEBUG_TRACE;
ece_set_mac(sc, eaddr);
-
+ DEBUG_TRACE;
sc->ifp = ifp = if_alloc(IFT_ETHER);
if (mii_phy_probe(dev, &sc->miibus, ece_ifmedia_upd, ece_ifmedia_sts)) {
device_printf(dev, "Cannot find my PHY.\n");
err = ENXIO;
goto out;
}
-
+ DEBUG_TRACE;
ifp->if_softc = sc;
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
ifp->if_mtu = ETHERMTU;
ifp->if_capabilities = IFCAP_HWCSUM;
+ ifp->if_hwassist = (CSUM_IP | CSUM_TCP | CSUM_UDP);
ifp->if_capenable = ifp->if_capabilities; /* */
ifp->if_start = ecestart;
ifp->if_ioctl = eceioctl;
@@ -417,14 +482,28 @@
IFQ_SET_MAXLEN(&ifp->if_snd, ECE_MAX_TX_BUFFERS-1);
IFQ_SET_READY(&ifp->if_snd);
ifp->if_timer = 0;
+ DEBUG_TRACE;
+
+ /* Create local taskq. */
+
+ TASK_INIT(&sc->sc_intr_task, 0, ece_intr_task, sc);
+ TASK_INIT(&sc->sc_tx_task, 1, ece_tx_task, ifp);
+ sc->sc_tq = taskqueue_create_fast("ece_taskq", M_WAITOK,
+ taskqueue_thread_enqueue, &sc->sc_tq);
+ if (sc->sc_tq == NULL) {
+ printf("could not create taskqueue\n");
+ goto out;
+ }
+ DEBUG_TRACE;
ether_ifattach(ifp, eaddr);
+
/*
* Activate the interrupt
*/
err = bus_setup_intr(dev, sc->irq_res_rec, INTR_TYPE_NET | INTR_MPSAFE,
- NULL, ece_intr, sc, &sc->intrhand);
+ NULL, ece_intr, sc, &sc->intrhand);
if (err) {
ether_ifdetach(ifp);
ECE_LOCK_DESTROY(sc);
@@ -432,14 +511,14 @@
}
err = bus_setup_intr(dev, sc->irq_res_status, INTR_TYPE_NET | INTR_MPSAFE,
- NULL, ece_intr_status, sc, &sc->intrhand_status);
+ NULL, ece_intr_status, sc, &sc->intrhand_status);
if (err) {
ether_ifdetach(ifp);
ECE_LOCK_DESTROY(sc);
goto out;
}
err = bus_setup_intr(dev, sc->irq_res_qf, INTR_TYPE_NET | INTR_MPSAFE,
- NULL, ece_intr_qf, sc, &sc->intrhand_qf);
+ NULL,ece_intr_qf, sc, &sc->intrhand_qf);
if (err) {
ether_ifdetach(ifp);
@@ -449,14 +528,17 @@
ECE_TXLOCK_INIT(sc);
ECE_RXLOCK_INIT(sc);
+ DEBUG_TRACE;
+
//enable all interrupt sources
WR4(sc, INTERRUPT_MASK, 0x00000000);
-
+ DEBUG_TRACE;
/*enable port 0*/
WR4(sc, PORT_0_CONFIG, RD4(sc, PORT_0_CONFIG) & ~((0x1 << 18)));
- /* enable dma */
- WR4(sc, FS_DMA_CONTROL, 1);
+ taskqueue_start_threads(&sc->sc_tq, 1, PI_NET, "%s taskq",
+ device_get_nameunit(sc->dev));
+ DEBUG_TRACE;
out:;
if (err)
@@ -469,7 +551,7 @@
static int
ece_detach(device_t dev)
{
- //DEBUG_TRACE;
+ //
return EBUSY; /* XXX TODO(1) */
}
@@ -488,16 +570,16 @@
ece_alloc_desc_dma_tx(struct ece_softc *sc)
{
bus_addr_t desc_paddr;
- //int i;
+ int i;
int error;
- DEBUG_TRACE;
+
desc_paddr = 0;
/* Allocate a busdma tag and DMA safe memory for TX/RX descriptors. */
- error = bus_dma_tag_create(NULL, /* parent */
+ error = bus_dma_tag_create(sc->sc_parent_tag, /* parent */
16, 0, /* alignment, boundary */
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
@@ -505,36 +587,36 @@
sizeof(eth_tx_desc_t)*ECE_MAX_TX_BUFFERS, 1, /* maxsize, nsegments */
sizeof(eth_tx_desc_t)*ECE_MAX_TX_BUFFERS, 0, /* maxsegsz, flags */
NULL, NULL, /* lockfunc, lockfuncarg */
- &sc->ece_desc_dtag_tx); /* dmat */
+ &sc->dmatag_tx); /* dmat */
- error = bus_dmamem_alloc(sc->ece_desc_dtag_tx,
+ error = bus_dmamem_alloc(sc->dmatag_tx,
(void**)&(sc->desc_tx),
BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT,
- &(sc->desc_dmap_tx));
+ &(sc->dmamap_tx));
if (error) {
if_printf(sc->ifp, "failed to allocate DMA memory\n");
return (ENXIO);
}
- error = bus_dmamap_load(sc->ece_desc_dtag_tx, sc->desc_dmap_tx,
+ error = bus_dmamap_load(sc->dmatag_tx, sc->dmamap_tx,
sc->desc_tx, sizeof(eth_tx_desc_t)*ECE_MAX_TX_BUFFERS, ece_getaddr,
- &(sc->ece_desc_paddr_tx), BUS_DMA_NOWAIT);
+ &(sc->ring_paddr_tx), BUS_DMA_NOWAIT);
if (error) {
if_printf(sc->ifp, "can't load descriptor\n");
- bus_dmamem_free(sc->ece_desc_dtag_tx, sc->desc_tx,
- sc->desc_dmap_tx);
+ bus_dmamem_free(sc->dmatag_tx, sc->desc_tx,
+ sc->dmamap_tx);
sc->desc_tx = NULL;
return (ENXIO);
}
- desc_paddr = sc->ece_desc_paddr_tx;
+ desc_paddr = sc->ring_paddr_tx;
/* Allocate a busdma tag for mbufs. */
- error = bus_dma_tag_create(NULL, /* parent */
+ error = bus_dma_tag_create(sc->sc_parent_tag, /* parent */
16, 0, /* alignment, boundary */
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
@@ -542,7 +624,7 @@
MCLBYTES*MAX_FRAGMENT, MAX_FRAGMENT, /* maxsize, nsegments */
MCLBYTES, 0, /* maxsegsz, flags */
NULL, NULL, /* lockfunc, lockfuncarg */
- &sc->ece_dtag_tx); /* dmat */
+ &sc->dmatag_ring_tx); /* dmat */
if (error) {
@@ -550,12 +632,15 @@
return (ENXIO);
}
- error = bus_dmamap_create(sc->ece_dtag_tx, 0, &sc->dmap_tx);
- if (error) {
- if_printf(sc->ifp, "failed to create map for mbuf\n");
- return (ENXIO);
+
+
+ for (i=0; i<ECE_MAX_TX_BUFFERS; i++) {
+ error = bus_dmamap_create(sc->dmatag_ring_tx, 0, &sc->dmap_tx[i]);
+ if (error) {
+ if_printf(sc->ifp, "failed to create map for mbuf\n");
+ return (ENXIO);
+ }
}
-
return 0;
}
@@ -571,37 +656,33 @@
if (sc->buffer_tx[i]) {
m_freem(sc->buffer_tx[i]);
sc->buffer_tx[i]= 0;
- }
+ }
}
- if (sc->desc_dmap_tx) {
- DEBUG_TRACE;
- bus_dmamap_unload(sc->ece_desc_dtag_tx, sc->desc_dmap_tx);
+ if (sc->dmamap_tx) {
+ bus_dmamap_unload(sc->dmatag_tx, sc->dmamap_tx);
if (sc->desc_tx) {
- bus_dmamem_free(sc->ece_desc_dtag_tx, sc->desc_tx, sc->desc_dmap_tx);
+ bus_dmamem_free(sc->dmatag_tx, sc->desc_tx, sc->dmamap_tx);
}
- sc->desc_dmap_tx = 0;
+ sc->dmamap_tx = 0;
}
- if (sc->ece_desc_dtag_tx) {
- DEBUG_TRACE;
- bus_dma_tag_destroy(sc->ece_desc_dtag_tx);
- sc->ece_desc_dtag_tx = 0;
+ if (sc->dmatag_tx) {
+ bus_dma_tag_destroy(sc->dmatag_tx);
+ sc->dmatag_tx = 0;
}
- if (sc->dmap_tx) {
- DEBUG_TRACE;
- bus_dmamap_destroy(sc->ece_dtag_tx, sc->dmap_tx);
- bus_dma_tag_destroy(sc->ece_dtag_tx);
- sc->dmap_tx = 0;
- sc->ece_dtag_tx = 0;
+ if (sc->dmatag_ring_tx) {
+ for (i = 0; i<ECE_MAX_TX_BUFFERS; i++) {
+ bus_dmamap_destroy(sc->dmatag_ring_tx, sc->dmap_tx[i]);
+ sc->dmap_tx[i] = 0;
+ }
+ bus_dma_tag_destroy(sc->dmatag_ring_tx);
+ sc->dmatag_ring_tx = 0;
}
-
}
-
-
static int
ece_alloc_desc_dma_rx(struct ece_softc *sc)
{
@@ -610,12 +691,12 @@
int error;
- DEBUG_TRACE;
+
desc_paddr = 0;
/* Allocate a busdma tag and DMA safe memory for RX/RX descriptors. */
- error = bus_dma_tag_create(NULL, /* parent */
+ error = bus_dma_tag_create(sc->sc_parent_tag, /* parent */
16, 0, /* alignment, boundary */
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
@@ -623,58 +704,61 @@
sizeof(eth_rx_desc_t)*ECE_MAX_RX_BUFFERS, 1, /* maxsize, nsegments */
sizeof(eth_rx_desc_t)*ECE_MAX_RX_BUFFERS, 0, /* maxsegsz, flags */
NULL, NULL, /* lockfunc, lockfuncarg */
- &sc->ece_desc_dtag_rx); /* dmat */
+ &sc->dmatag_rx); /* dmat */
- error = bus_dmamem_alloc(sc->ece_desc_dtag_rx,
+ error = bus_dmamem_alloc(sc->dmatag_rx,
(void**)&(sc->desc_rx),
BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT,
- &(sc->desc_dmap_rx));
+ &(sc->dmamap_rx));
if (error) {
if_printf(sc->ifp, "failed to allocate DMA memory\n");
return (ENXIO);
}
- error = bus_dmamap_load(sc->ece_desc_dtag_rx, sc->desc_dmap_rx,
+ error = bus_dmamap_load(sc->dmatag_rx, sc->dmamap_rx,
sc->desc_rx, sizeof(eth_rx_desc_t)*ECE_MAX_RX_BUFFERS, ece_getaddr,
- &(sc->ece_desc_paddr_rx), BUS_DMA_NOWAIT);
+ &(sc->ring_paddr_rx), BUS_DMA_NOWAIT);
if (error) {
if_printf(sc->ifp, "can't load descriptor\n");
- bus_dmamem_free(sc->ece_desc_dtag_rx, sc->desc_rx,
- sc->desc_dmap_rx);
+ bus_dmamem_free(sc->dmatag_rx, sc->desc_rx,
+ sc->dmamap_rx);
sc->desc_rx = NULL;
return (ENXIO);
}
- desc_paddr = sc->ece_desc_paddr_rx;
+ desc_paddr = sc->ring_paddr_rx;
+
- DEBUG_TRACE;
/* Allocate a busdma tag for mbufs. */
- error = bus_dma_tag_create(NULL, /* parent */
- 8, 0, /* alignment, boundary */
+ error = bus_dma_tag_create(sc->sc_parent_tag, /* parent */
+ 16, 0, /* alignment, boundary */
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
NULL, NULL, /* filtfunc, filtfuncarg */
MCLBYTES, 1, /* maxsize, nsegments */
MCLBYTES, 0, /* maxsegsz, flags */
NULL, NULL, /* lockfunc, lockfuncarg */
- &sc->ece_dtag_rx); /* dmat */
+ &sc->dmatag_ring_rx); /* dmat */
if (error) {
if_printf(sc->ifp, "failed to create busdma tag for mbufs\n");
return (ENXIO);
}
- DEBUG_TRACE;
+
+ error = bus_dmamap_create(sc->dmatag_ring_rx, 0, &sc->sparemap_rx);
- error = bus_dmamap_create(sc->ece_dtag_rx, 0, &sc->dmap_rx);
- if (error) {
- if_printf(sc->ifp, "failed to create map for mbuf\n");
- return (ENXIO);
+ for (int i =0; i<ECE_MAX_RX_BUFFERS; i++) {
+ error = bus_dmamap_create(sc->dmatag_ring_rx, 0, &sc->dmap_rx[i]);
+ if (error) {
+ if_printf(sc->ifp, "failed to create map for mbuf\n");
+ return (ENXIO);
+ }
}
@@ -686,7 +770,7 @@
ece_free_desc_dma_rx(struct ece_softc *sc)
{
int i;
- //bus_dmamap_sync(sc->ece_dtag_rx, sc->dmap_rx, BUS_DMASYNC_POSTWRITE);
+ //bus_dmamap_sync(sc->dmatag_ring_rx, sc->dmap_rx, BUS_DMASYNC_POSTWRITE);
for (i = 0; i < ECE_MAX_RX_BUFFERS; i++) {
@@ -696,21 +780,22 @@
}
}
- if (sc->ece_desc_dtag_rx) {
- bus_dmamap_unload(sc->ece_desc_dtag_rx, sc->desc_dmap_rx);
- bus_dmamem_free(sc->ece_desc_dtag_rx, sc->desc_rx,
- sc->desc_dmap_rx);
- bus_dma_tag_destroy(sc->ece_desc_dtag_rx);
- sc->ece_desc_dtag_rx = 0;
- sc->desc_dmap_rx = 0;
+ if (sc->dmatag_rx) {
+ bus_dmamap_unload(sc->dmatag_rx, sc->dmamap_rx);
+ bus_dmamem_free(sc->dmatag_rx, sc->desc_rx,
+ sc->dmamap_rx);
+ bus_dma_tag_destroy(sc->dmatag_rx);
+ sc->dmatag_rx = 0;
+ sc->dmamap_rx = 0;
sc->desc_rx = 0;
}
- if (sc->ece_dtag_rx) {
- bus_dmamap_destroy(sc->ece_dtag_rx, sc->dmap_rx);
- bus_dma_tag_destroy(sc->ece_dtag_rx);
- sc->ece_dtag_rx = 0;
- sc->dmap_rx = 0;
+ if (sc->dmatag_ring_rx) {
+ for (i = 0; i<ECE_MAX_RX_BUFFERS; i++) {
+ bus_dmamap_destroy(sc->dmatag_ring_rx, sc->dmap_rx[i]);
+ }
+ bus_dma_tag_destroy(sc->dmatag_ring_rx);
+ sc->dmatag_ring_rx = 0;
}
}
@@ -718,7 +803,7 @@
static int
-ece_new_rxbuf(bus_dma_tag_t tag, bus_dmamap_t map, struct mbuf **mbufp,
+ece_new_rxbuf(bus_dma_tag_t tag, bus_dmamap_t *sparemap, struct mbuf **mbufp,
bus_addr_t *paddr)
{
struct mbuf *new_mbuf;
@@ -726,7 +811,7 @@
int error;
int nsegs;
- //DEBUG_TRACE;
+ //
KASSERT(mbufp != NULL, ("NULL mbuf pointer!"));
@@ -736,18 +821,18 @@
new_mbuf->m_len = new_mbuf->m_pkthdr.len = new_mbuf->m_ext.ext_size;
if (*mbufp) {
- bus_dmamap_sync(tag, map, BUS_DMASYNC_POSTREAD);
- bus_dmamap_unload(tag, map);
+ bus_dmamap_sync(tag, *sparemap, BUS_DMASYNC_POSTREAD);
+ bus_dmamap_unload(tag, *sparemap);
//cpu_dcache_wbinv_all();
}
- error = bus_dmamap_load_mbuf_sg(tag, map, new_mbuf, seg, &nsegs,
+ error = bus_dmamap_load_mbuf_sg(tag, *sparemap, new_mbuf, seg, &nsegs,
BUS_DMA_NOWAIT);
KASSERT(nsegs == 1, ("Too many segments returned!"));
if (nsegs != 1 || error)
panic("mge_new_rxbuf(): nsegs(%d), error(%d)", nsegs, error);
- bus_dmamap_sync(tag, map, BUS_DMASYNC_PREREAD);
+ bus_dmamap_sync(tag, *sparemap, BUS_DMASYNC_PREREAD);
//cpu_dcache_wbinv_all();
(*mbufp) = new_mbuf;
@@ -764,11 +849,26 @@
eth_tx_desc_t *desctx;
eth_rx_desc_t *descrx;
int i;
+ int error;
- DEBUG_TRACE;
+
+ error = bus_dma_tag_create(
+ bus_get_dma_tag(sc->dev), /* parent */
+ 1, 0, /* alignment, boundary */
+ BUS_SPACE_MAXADDR, /* lowaddr */
+ BUS_SPACE_MAXADDR, /* highaddr */
+ NULL, NULL, /* filter, filterarg */
+ BUS_SPACE_MAXSIZE_32BIT, 0, /* maxsize, nsegments */
+ BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
+ 0, /* flags */
+ NULL, NULL, /* lockfunc, lockarg */
+ &sc->sc_parent_tag);
+
+
+
ece_alloc_desc_dma_tx(sc);
- DEBUG_TRACE;
+
printf("size of rx = %d tx = %d\n", sizeof(eth_rx_desc_t), sizeof(eth_tx_desc_t));
@@ -776,6 +876,7 @@
desctx = (eth_tx_desc_t *)(&sc->desc_tx[i]);
memset(desctx, 0, sizeof(eth_tx_desc_t));
desctx->length = MAX_PACKET_LEN;
+ sc->sent_position[i] = -1;
desctx->cown = 1;
if (i==ECE_MAX_TX_BUFFERS-1) {
desctx->eor = 1;
@@ -783,13 +884,12 @@
}
ece_alloc_desc_dma_rx(sc);
-
- DEBUG_TRACE;
-
+
for (i = 0; i < ECE_MAX_RX_BUFFERS; i++) {
descrx = (eth_rx_desc_t *)&(sc->desc_rx[i]);
memset(descrx, 0, sizeof(eth_rx_desc_t));
- ece_new_rxbuf(sc->ece_dtag_rx, sc->dmap_rx, &(sc->buffer_rx[i]),
+ ece_new_rxbuf(sc->dmatag_ring_rx, &sc->sparemap_rx,
+ &(sc->buffer_rx[i]),
(bus_addr_t *)&(descrx->data_ptr));
descrx->length = sc->buffer_rx[i]->m_len;
if (i==ECE_MAX_RX_BUFFERS-1) {
@@ -798,8 +898,6 @@
}
sc->desc_curr_tx = 0;
sc->desc_curr_rx = 0;
- sc->curr_tx_mbuf = 0;
-
return (0);
}
@@ -815,9 +913,10 @@
uint32_t mac_port_config;
uint32_t cpu_port_config;
uint32_t cfg_reg;
-
+ struct ifnet *ifp;
sc = device_get_softc(dev);
+ ifp = sc->ifp;
while (1) {
@@ -843,13 +942,13 @@
mac_port_config |= ((0x1 << 18));
WR4(sc, MAC_PORT_1_CONFIG, mac_port_config);
- DEBUG_TRACE;
+
vlan_init();
gsw_hardware_init(sc);
- DEBUG_TRACE;
+
mac_port_config = RD4(sc, MAC_PORT_0_CONFIG);
mac_port_config &= (~(0x1 << 18)); /* Enable Port 0 */
WR4(sc, MAC_PORT_0_CONFIG, mac_port_config);
@@ -860,29 +959,26 @@
cpu_port_config &= ~(0x1 << 18);
WR4(sc, CPU_PORT_CONFIG, cpu_port_config);
-
- DEBUG_TRACE;
err = ece_allocate_dma(sc);
if (err) {
if_printf(sc->ifp, "failed allocating dma\n");
- goto errout;
+ goto out;
}
- WR4(sc, TS_DESCRIPTOR_POINTER, sc->ece_desc_paddr_tx);
- WR4(sc, TS_DESCRIPTOR_BASE_ADDR, sc->ece_desc_paddr_tx);
+
+ WR4(sc, TS_DESCRIPTOR_POINTER, sc->ring_paddr_tx);
+ WR4(sc, TS_DESCRIPTOR_BASE_ADDR, sc->ring_paddr_tx);
- WR4(sc, FS_DESCRIPTOR_POINTER, sc->ece_desc_paddr_rx);
- WR4(sc, FS_DESCRIPTOR_BASE_ADDR, sc->ece_desc_paddr_rx);
+ WR4(sc, FS_DESCRIPTOR_POINTER, sc->ring_paddr_rx);
+ WR4(sc, FS_DESCRIPTOR_BASE_ADDR, sc->ring_paddr_rx);
WR4(sc, FS_DMA_CONTROL, 1);
+
+ return (0);
+out:
+ return (ENXIO);
-
- DEBUG_TRACE;
- return (0);
-errout:
- ece_deactivate(dev);
- return (ENOMEM);
}
static void
@@ -890,6 +986,8 @@
{
struct ece_softc *sc;
+ printf("deactivating\n");
+
sc = device_get_softc(dev);
if (sc->intrhand)
@@ -924,6 +1022,8 @@
sc->irq_res_rec = 0;
sc->irq_res_qf = 0;
sc->irq_res_status = 0;
+ ECE_TXLOCK_DESTROY(sc);
+ ECE_RXLOCK_DESTROY(sc);
return;
}
@@ -1362,7 +1462,7 @@
{
struct gsw_arl_table_entry_t arl_table_entry;
- DEBUG_TRACE;
+
/* erase old mac */
arl_table_entry.filter = 0;
@@ -1396,9 +1496,7 @@
ece_set_mac(struct ece_softc *sc, u_char *eaddr)
{
int i;
-
for (i = 0; i<6; i++) {
-
my_vlan0_mac[i] = eaddr[i];
}
gsw_set_mac_address(sc, 0, eaddr, 6);
@@ -1411,7 +1509,6 @@
}
-
static void
ece_intr_rx_locked(struct ece_softc *sc, int count)
{
@@ -1425,12 +1522,9 @@
struct mbuf *mb;
eth_rx_desc_t *desc;
- //ECE_ASSERT_LOCKED(sc);
-
-
fssd_curr = RD4(sc, FS_DESCRIPTOR_POINTER);
- fssd = (fssd_curr - (uint32_t)sc->ece_desc_paddr_rx)>>4;
+ fssd = (fssd_curr - (uint32_t)sc->ring_paddr_rx)>>4;
desc = (eth_rx_desc_t *)&(sc->desc_rx[sc->desc_curr_rx]);
@@ -1440,71 +1534,30 @@
rxcount = (ECE_MAX_RX_BUFFERS - sc->desc_curr_rx) + fssd;
} else {
if (desc->cown == 0) {
- if_printf(sc->ifp, "str9104 failed, line %d\n", __LINE__);
- rxcount = 0;
+ return;
} else {
rxcount = ECE_MAX_RX_BUFFERS;
}
}
- bus_dmamap_sync(sc->ece_desc_dtag_rx, sc->desc_dmap_rx,
- BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
-
for (i= 0; i<rxcount; i++) {
-
- //cpu_dcache_wbinv_all();
-
/* Get status */
status = desc->cown;
bufsize = desc->length;
- //printf("status = %d length = %d\n", status, bufsize);
if (status) {
int idx = sc->desc_curr_rx;
- //bus_dmamap_sync(sc->ece_desc_dtag_rx, sc->dmap_rx,BUS_DMASYNC_POSTREAD);
- //cpu_dcache_wbinv_all();
-
+ bus_dmamap_sync(sc->dmatag_rx, sc->dmap_rx[idx],
+ BUS_DMASYNC_PREREAD);
+
mb = m_devget((void *)sc->buffer_rx[idx]->m_data,
- //sc->buffer_rx[idx]->m_len,
desc->length+16,
0, ifp, NULL);
- //cpu_dcache_wbinv_all();
- /*printf("sc->buffer_rx[idx]->m_data = %p\n", sc->buffer_rx[idx]->m_data);
- printf("desc->length = %d\n", desc->length);
- printf("desc->fs = %d\n", desc->fs);
- printf("desc->prot = %d\n", desc->prot);
- printf("desc->ip_fail = %d\n", desc->ipf);
- printf("desc->l4_fail = %d\n", desc->l4f);
- printf("packet header length = %d\n", mb->m_pkthdr.len);
- int j;
- for (j=0; j<desc->length+2; j++) {
- printf("%02x ", (unsigned char)(sc->buffer_rx[idx]->m_data[j]));
- }
- printf("\n");
- */
-
if (mb) {
mb->m_data += 2;
-
-/* if (mb->m_pkthdr.len-desc->length!=2) {
- printf("delta > 2 %d\n", mb->m_pkthdr.len-desc->length);
- printf("sc->buffer_rx[idx]->m_data = %p\n", sc->buffer_rx[idx]->m_data);
- printf("desc->length = %d\n", desc->length);
- printf("desc->fs = %d\n", desc->fs);
- printf("desc->prot = %d\n", desc->prot);
- printf("desc->ip_fail = %d\n", desc->ipf);
- printf("desc->l4_fail = %d\n", desc->l4f);
- printf("packet header length = %d\n", mb->m_pkthdr.len);
- int j;
- for (j=0; j<desc->length+2; j++) {
- printf("%02x ", (unsigned char)(sc->buffer_rx[idx]->m_data[j]));
- }
- printf("\n");
- }*/
-
if (desc->prot!=3) {
mb->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
mb->m_pkthdr.csum_flags |= CSUM_IP_VALID;
@@ -1512,44 +1565,40 @@
}
mb->m_len = mb->m_pkthdr.len;
- //printf("process packet\n");
ECE_RXUNLOCK(sc);
(*ifp->if_input)(ifp, mb);
ECE_RXLOCK(sc);
-
- //bus_dmamap_sync(sc->ece_desc_dtag_rx, sc->dmap_rx,BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
} else {
if_printf(sc->ifp, "no mbuf length = %d\n", desc->length);
/* Give up if no mbufs */
}
} else {
- printf("error cown not valid\n");
+ /*not ready, process later*/
+ return;
}
desc->cown = 0;
desc->length = sc->buffer_rx[sc->desc_curr_rx]->m_len;
- //cpu_dcache_wbinv_all();
if (sc->desc_curr_rx==ECE_MAX_RX_BUFFERS-1) {
- desc = (eth_rx_desc_t *)&(sc->desc_rx[0]);
+ desc = (eth_rx_desc_t *)&(sc->desc_rx[0]);
sc->desc_curr_rx = 0;
} else {
sc->desc_curr_rx++;
- desc = (eth_rx_desc_t *)&(sc->desc_rx[sc->desc_curr_rx]);
+ desc++;
}
- bus_dmamap_sync(sc->ece_desc_dtag_rx, sc->desc_dmap_rx,BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
}
-
return;
}
+
static void
-ece_intr(void *xsc)
+ece_intr_task(void *arg, int pending __unused)
{
- struct ece_softc *sc = xsc;
-
- //printf("INTERRUPT --->receive packet\n");
+// printf("ECE INTR TASK");
+ struct ece_softc *sc = arg;
+ //struct ifnet *ifp = sc->ifp;
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list