Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci - remove leftovers of FreeBSD code in #if 0/#endif



details:   https://anonhg.NetBSD.org/src/rev/2b0249037fe5
branches:  trunk
changeset: 483753:2b0249037fe5
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Fri Mar 17 09:20:16 2000 +0000

description:
- remove leftovers of FreeBSD code in #if 0/#endif
- fix a bug in ti_encap() where a NULL pointer could be used if we run out
  of tx descriptors (return ENOMEM instead, and let the caller assert OACTIVE)
- sync boot messages with NetBSD's pci standart (print ti_name and irq
  line)
- add a shutdown hook to stop the board, so that the board will not DMA at
  random places while we're rebooting
- convert all but TIGON 1 transmit descriptors to use bus_space
  (this last one isn't trivial to get rigth and I don't have the hardware to
  test)
- If we can't map the mem space linar, retry to map it nolinear. Punt if
  we couldn't map the mem space linear and we found a Tigon 1 chip.

With these changes a Tigon 2 board (netgear BA620 at last) can be used in
my DS20.

diffstat:

 sys/dev/pci/if_ti.c |  280 ++++++++++++++++-----------------------------------
 1 files changed, 89 insertions(+), 191 deletions(-)

diffs (truncated from 527 to 300 lines):

diff -r 2fde812f8025 -r 2b0249037fe5 sys/dev/pci/if_ti.c
--- a/sys/dev/pci/if_ti.c       Fri Mar 17 06:11:55 2000 +0000
+++ b/sys/dev/pci/if_ti.c       Fri Mar 17 09:20:16 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ti.c,v 1.5 2000/03/06 21:02:37 thorpej Exp $ */
+/* $NetBSD: if_ti.c,v 1.6 2000/03/17 09:20:16 bouyer Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999
@@ -81,9 +81,6 @@
  */
 
 #include "bpfilter.h"
-#if 0
-#include "vlan.h"
-#endif
 #include "opt_inet.h"
 #include "opt_ns.h"
 
@@ -107,13 +104,6 @@
 #include <net/bpf.h>
 #endif
 
-#if 0
-#if NVLAN > 0
-#include <net/if_types.h>
-#include <net/if_vlan_var.h>
-#endif
-#endif
-
 #ifdef INET
 #include <netinet/in.h>
 #include <netinet/if_inarp.h>
@@ -124,17 +114,7 @@
 #include <netns/ns_if.h>
 #endif
 
-#if 0
-#include <vm/vm.h>              /* for vtophys */
-#include <vm/pmap.h>            /* for vtophys */
-#include <machine/clock.h>      /* for DELAY */
-#endif
 #include <machine/bus.h>
-#if 0
-#include <machine/resource.h>
-#include <sys/bus.h>
-#include <sys/rman.h>
-#endif
 
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>
@@ -166,11 +146,10 @@
        { 0, 0, NULL }
 };
 
+static struct ti_type *ti_type_match __P((struct pci_attach_args *));
 static int ti_probe    __P((struct device *, struct cfdata *, void *));
 static void ti_attach  __P((struct device *, struct device *, void *));
-#if 0
-static int ti_detach           __P((device_t));
-#endif
+static void ti_shutdown __P((void *));
 static void ti_txeof           __P((struct ti_softc *));
 static void ti_rxeof           __P((struct ti_softc *));
 
@@ -185,9 +164,6 @@
 static void ti_init2           __P((struct ti_softc *));
 static void ti_stop            __P((struct ti_softc *));
 static void ti_watchdog                __P((struct ifnet *));
-#if 0
-static void ti_shutdown                __P((device_t));
-#endif
 static int ti_ifmedia_upd      __P((struct ifnet *));
 static void ti_ifmedia_sts     __P((struct ifnet *, struct ifmediareq *));
 
@@ -210,9 +186,6 @@
 static int ti_alloc_jumbo_mem  __P((struct ti_softc *));
 static void *ti_jalloc         __P((struct ti_softc *));
 static void ti_jfree           __P((caddr_t, u_int, void *));
-#if 0
-static void ti_jref            __P((caddr_t, u_int));
-#endif
 static int ti_newbuf_std       __P((struct ti_softc *, int, struct mbuf *, bus_dmamap_t));
 static int ti_newbuf_mini      __P((struct ti_softc *, int, struct mbuf *, bus_dmamap_t));
 static int ti_newbuf_jumbo     __P((struct ti_softc *, int, struct mbuf *));
@@ -387,11 +360,10 @@
        caddr_t                 buf;
 {
        int                     segptr, segsize, cnt;
-       caddr_t                 ti_winbase, ptr;
+       caddr_t                 ptr;
 
        segptr = addr;
        cnt = len;
-       ti_winbase = (caddr_t)(sc->ti_vhandle + TI_WINDOW);
        ptr = buf;
 
        while(cnt) {
@@ -400,12 +372,14 @@
                else
                        segsize = TI_WINLEN - (segptr % TI_WINLEN);
                CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
-               if (buf == NULL)
-                       bzero((char *)ti_winbase + (segptr &
-                           (TI_WINLEN - 1)), segsize);
-               else {
-                       bcopy((char *)ptr, (char *)ti_winbase +
-                           (segptr & (TI_WINLEN - 1)), segsize);
+               if (buf == NULL) {
+                       bus_space_set_region_4(sc->ti_btag, sc->ti_bhandle,
+                           TI_WINDOW + (segptr & (TI_WINLEN - 1)), 0,
+                           segsize / 4);
+               } else {
+                       bus_space_write_region_4(sc->ti_btag, sc->ti_bhandle,
+                           TI_WINDOW + (segptr & (TI_WINLEN - 1)),
+                           (u_int32_t *)ptr, segsize / 4);
                        ptr += segsize;
                }
                segptr += segsize;
@@ -484,9 +458,6 @@
 {
        u_int32_t               index;
 
-       if (sc->ti_rdata->ti_cmd_ring == NULL)
-               return;
-
        index = sc->ti_cmd_saved_prodidx;
        CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4), *(u_int32_t *)(cmd));
        TI_INC(index, TI_CMD_RING_CNT);
@@ -509,9 +480,6 @@
        u_int32_t               index;
        register int            i;
 
-       if (sc->ti_rdata->ti_cmd_ring == NULL)
-               return;
-
        index = sc->ti_cmd_saved_prodidx;
        CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4), *(u_int32_t *)(cmd));
        TI_INC(index, TI_CMD_RING_CNT);
@@ -711,47 +679,6 @@
        return(sc->ti_cdata.ti_jslots[entry->slot].ti_buf);
 }
 
-#if 0
-/*
- * Adjust usage count on a jumbo buffer. In general this doesn't
- * get used much because our jumbo buffers don't get passed around
- * too much, but it's implemented for correctness.
- */
-static void ti_jref(buf, size)
-       caddr_t                 buf;
-       u_int                   size;
-{
-       struct ti_softc         *sc;
-       u_int64_t               **aptr;
-       register int            i;
-
-       /* Extract the softc struct pointer. */
-       aptr = (u_int64_t **)(buf - sizeof(u_int64_t));
-       sc = (struct ti_softc *)(aptr[0]);
-
-       if (sc == NULL)
-               panic("ti_jref: can't find softc pointer!");
-
-       if (size != TI_JUMBO_FRAMELEN)
-               panic("ti_jref: adjusting refcount of buf of wrong size!");
-
-       /* calculate the slot this buffer belongs to */
-
-       i = ((caddr_t)aptr 
-            - (caddr_t)sc->ti_cdata.ti_jumbo_buf) / TI_JLEN;
-
-       if ((i < 0) || (i >= TI_JSLOTS))
-               panic("ti_jref: asked to reference buffer "
-                   "that we don't manage!");
-       else if (sc->ti_cdata.ti_jslots[i].ti_inuse == 0)
-               panic("ti_jref: buffer already free!");
-       else
-               sc->ti_cdata.ti_jslots[i].ti_inuse++;
-
-       return;
-}
-#endif
-
 /*
  * Release a jumbo buffer.
  */
@@ -983,9 +910,6 @@
                    m_new->m_ext.ext_size = TI_JUMBO_FRAMELEN;
                m_new->m_ext.ext_free = ti_jfree;
                m_new->m_ext.ext_arg = sc;
-#if 0
-               m_new->m_ext.ext_ref = ti_jref;
-#endif
                MCLINITREFERENCE(m_new);
        } else {
                m_new = m;
@@ -1532,8 +1456,6 @@
        /* Set up the command ring and producer mailbox. */
        rcb = &sc->ti_rdata->ti_info.ti_cmd_rcb;
 
-       sc->ti_rdata->ti_cmd_ring =
-           (struct ti_cmd_desc *)(sc->ti_vhandle + TI_GCR_CMDRING);
        TI_HOSTADDR(rcb->ti_hostaddr) = TI_GCR_NIC_ADDR(TI_GCR_CMDRING);
        rcb->ti_flags = 0;
        rcb->ti_max_len = 0;
@@ -1670,6 +1592,26 @@
 }
 
 /*
+ * look for id in the device list, returning the first match
+ */
+static struct ti_type * ti_type_match(pa)
+       struct pci_attach_args *pa;
+{
+       struct ti_type          *t;
+
+       t = ti_devs;
+       while(t->ti_name != NULL) {
+               if ((PCI_VENDOR(pa->pa_id) == t->ti_vid) &&
+                   (PCI_PRODUCT(pa->pa_id) == t->ti_did)) {
+                       return (t);
+               }
+               t++;
+       }
+
+       return(NULL);
+}
+
+/*
  * Probe for a Tigon chip. Check the PCI vendor and device IDs
  * against our list and return its name if we find a match.
  */
@@ -1681,24 +1623,15 @@
        struct pci_attach_args *pa = aux;
        struct ti_type          *t;
 
-       t = ti_devs;
+       t = ti_type_match(pa);
 
-       while(t->ti_name != NULL) {
-               if ((PCI_VENDOR(pa->pa_id) == t->ti_vid) &&
-                   (PCI_PRODUCT(pa->pa_id) == t->ti_did)) {
-                       return(1);
-               }
-               t++;
-       }
-
-       return(0);
+       return((t == NULL) ? 0 : 1);
 }
 
 static void ti_attach(parent, self, aux)
        struct device *parent, *self;
        void *aux;
 {
-       int                     s;
        u_int32_t               command;
        struct ifnet            *ifp;
        struct ti_softc         *sc;
@@ -1708,23 +1641,39 @@
        pci_intr_handle_t ih;
        const char *intrstr = NULL;
        bus_dma_segment_t dmaseg;
-       int error, dmanseg;
+       int error, dmanseg, nolinear;
+       struct ti_type          *t;
 
-       s = splimp();
+       t = ti_type_match(pa);
+       if (t == NULL) {
+               printf("ti_attach: were did the card go ?\n");
+               return;
+       }
+
+       printf(": %s (rev. 0x%02x)\n", t->ti_name, PCI_REVISION(pa->pa_class));
 
        sc = (struct ti_softc *)self;
 
        /*
         * Map control/status registers.
         */
-       if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM, BUS_SPACE_MAP_LINEAR,
-           &sc->ti_btag, &sc->ti_bhandle, NULL, NULL)) {
-               printf(": can't map memory space\n");
-               goto fail;
+       nolinear = 0;
+       if (pci_mapreg_map(pa, 0x10,
+           PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
+           BUS_SPACE_MAP_LINEAR , &sc->ti_btag, &sc->ti_bhandle,
+           NULL, NULL)) {
+               nolinear = 1;
+               if (pci_mapreg_map(pa, 0x10,
+                   PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
+                   0 , &sc->ti_btag, &sc->ti_bhandle, NULL, NULL)) {
+                       printf(": can't map memory space\n");
+                       return;
+               }
        }
-       sc->ti_vhandle = (void *)(sc->ti_bhandle); /* XXX XXX XXX */



Home | Main Index | Thread Index | Old Index