Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci More sync with the FreeBSD driver.



details:   https://anonhg.NetBSD.org/src/rev/a0f3512f32e1
branches:  trunk
changeset: 583692:a0f3512f32e1
user:      skrll <skrll%NetBSD.org@localhost>
date:      Fri Aug 19 08:50:06 2005 +0000

description:
More sync with the FreeBSD driver.

diffstat:

 sys/dev/pci/if_iwi.c    |  614 ++++++++++++++++++++++++++++-------------------
 sys/dev/pci/if_iwireg.h |   74 +++--
 sys/dev/pci/if_iwivar.h |   78 +++--
 3 files changed, 449 insertions(+), 317 deletions(-)

diffs (truncated from 1294 to 300 lines):

diff -r f5f2649e6ff4 -r a0f3512f32e1 sys/dev/pci/if_iwi.c
--- a/sys/dev/pci/if_iwi.c      Fri Aug 19 07:04:33 2005 +0000
+++ b/sys/dev/pci/if_iwi.c      Fri Aug 19 08:50:06 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_iwi.c,v 1.13 2005/08/01 15:14:54 skrll Exp $  */
+/*     $NetBSD: if_iwi.c,v 1.14 2005/08/19 08:50:06 skrll Exp $  */
 
 /*-
  * Copyright (c) 2004, 2005
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_iwi.c,v 1.13 2005/08/01 15:14:54 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_iwi.c,v 1.14 2005/08/19 08:50:06 skrll Exp $");
 
 /*-
  * Intel(R) PRO/Wireless 2200BG/2225BG/2915ABG driver
@@ -90,16 +90,28 @@
 static int iwi_match(struct device *, struct cfdata *, void *);
 static void iwi_attach(struct device *, struct device *, void *);
 static int iwi_detach(struct device *, int);
-static int iwi_dma_alloc(struct iwi_softc *);
-static void iwi_release(struct iwi_softc *);
+
+static int iwi_alloc_cmd_ring(struct iwi_softc *, struct iwi_cmd_ring *,
+    int);
+static void iwi_reset_cmd_ring(struct iwi_softc *, struct iwi_cmd_ring *);
+static void iwi_free_cmd_ring(struct iwi_softc *, struct iwi_cmd_ring *);
+static int iwi_alloc_tx_ring(struct iwi_softc *, struct iwi_tx_ring *,
+    int);
+static void iwi_reset_tx_ring(struct iwi_softc *, struct iwi_tx_ring *);
+static void iwi_free_tx_ring(struct iwi_softc *, struct iwi_tx_ring *);
+static int iwi_alloc_rx_ring(struct iwi_softc *, struct iwi_rx_ring *,
+    int);
+static void iwi_reset_rx_ring(struct iwi_softc *, struct iwi_rx_ring *);
+static void iwi_free_rx_ring(struct iwi_softc *, struct iwi_rx_ring *);
+
 static int iwi_media_change(struct ifnet *);
 static void iwi_media_status(struct ifnet *, struct ifmediareq *);
 static u_int16_t iwi_read_prom_word(struct iwi_softc *, u_int8_t);
 static int iwi_newstate(struct ieee80211com *, enum ieee80211_state, int);
 static void iwi_fix_channel(struct ieee80211com *, struct mbuf *);
-static void iwi_frame_intr(struct iwi_softc *, struct iwi_rx_buf *, int,
+static void iwi_frame_intr(struct iwi_softc *, struct iwi_rx_data *, int,
     struct iwi_frame *);
-static void iwi_notification_intr(struct iwi_softc *, struct iwi_rx_buf *,
+static void iwi_notification_intr(struct iwi_softc *, struct iwi_rx_data *,
     struct iwi_notif *);
 static void iwi_rx_intr(struct iwi_softc *);
 static void iwi_tx_intr(struct iwi_softc *);
@@ -242,10 +254,25 @@
                return;
        }
 
-       if (iwi_dma_alloc(sc) != 0) {
-               aprint_error("%s: could not allocate DMA resources\n",
+       /*
+        * Allocate rings.
+        */
+       if (iwi_alloc_cmd_ring(sc, &sc->cmdq, IWI_CMD_RING_COUNT) != 0) {
+               aprint_error("%s: could not allocate command ring\n",
                    sc->sc_dev.dv_xname);
-               return;
+               goto fail;
+       }
+
+       if (iwi_alloc_tx_ring(sc, &sc->txq, IWI_TX_RING_COUNT) != 0) {
+               aprint_error("%s: could not allocate Tx ring\n",
+                   sc->sc_dev.dv_xname);
+               goto fail;
+       }
+
+       if (iwi_alloc_rx_ring(sc, &sc->rxq, IWI_RX_RING_COUNT) != 0) {
+               aprint_error("%s: could not allocate Rx ring\n",
+                   sc->sc_dev.dv_xname);
+               goto fail;
        }
 
        ic->ic_ifp = ifp;
@@ -339,6 +366,10 @@
        sc->dwelltime = 100;
        sc->bluetooth = 1;
        sc->antenna = 0;
+
+       return;
+
+fail:  iwi_detach(self, 0);
 }
 
 static int
@@ -356,7 +387,9 @@
        ieee80211_ifdetach(&sc->sc_ic);
        if_detach(ifp);
 
-       iwi_release(sc);
+       iwi_free_cmd_ring(sc, &sc->cmdq);
+       iwi_free_tx_ring(sc, &sc->txq);
+       iwi_free_rx_ring(sc, &sc->rxq);
 
        if (sc->sc_ih != NULL) {
                pci_intr_disestablish(sc->sc_pct, sc->sc_ih);
@@ -369,59 +402,22 @@
 }
 
 static int
-iwi_dma_alloc(struct iwi_softc *sc)
+iwi_alloc_cmd_ring(struct iwi_softc *sc, struct iwi_cmd_ring *ring,
+    int count)
 {
-       int i, nsegs, error;
-
-       /*
-        * Allocate and map Tx ring
-        */
-       error = bus_dmamap_create(sc->sc_dmat,
-           sizeof (struct iwi_tx_desc) * IWI_TX_RING_SIZE, 1,
-           sizeof (struct iwi_tx_desc) * IWI_TX_RING_SIZE, 0, BUS_DMA_NOWAIT,
-           &sc->tx_ring_map);
-       if (error != 0) {
-               aprint_error("%s: could not create tx ring DMA map\n",
-                   sc->sc_dev.dv_xname);
-               goto fail;
-       }
+       int error, nsegs;
 
-       error = bus_dmamem_alloc(sc->sc_dmat,
-           sizeof (struct iwi_tx_desc) * IWI_TX_RING_SIZE, PAGE_SIZE, 0,
-           &sc->tx_ring_seg, 1, &nsegs, BUS_DMA_NOWAIT);
-       if (error != 0) {
-               aprint_error("%s: could not allocate tx ring DMA memory\n",
-                   sc->sc_dev.dv_xname);
-               goto fail;
-       }
-
-       error = bus_dmamem_map(sc->sc_dmat, &sc->tx_ring_seg, nsegs,
-           sizeof (struct iwi_tx_desc) * IWI_TX_RING_SIZE,
-           (caddr_t *)&sc->tx_desc, BUS_DMA_NOWAIT);
-       if (error != 0) {
-               aprint_error("%s: could not map tx ring DMA memory\n",
-                   sc->sc_dev.dv_xname);
-               goto fail;
-       }
-
-       error = bus_dmamap_load(sc->sc_dmat, sc->tx_ring_map, sc->tx_desc,
-           sizeof (struct iwi_tx_desc) * IWI_TX_RING_SIZE, NULL,
-           BUS_DMA_NOWAIT);
-       if (error != 0) {
-               aprint_error("%s: could not load tx ring DMA map\n",
-                   sc->sc_dev.dv_xname);
-               goto fail;
-       }
-
-       memset(sc->tx_desc, 0, sizeof (struct iwi_tx_desc) * IWI_TX_RING_SIZE);
+       ring->count = count;
+       ring->queued = 0;
+       ring->cur = ring->next = 0;
 
        /*
         * Allocate and map command ring
         */
        error = bus_dmamap_create(sc->sc_dmat,
-           sizeof (struct iwi_cmd_desc) * IWI_CMD_RING_SIZE, 1,
-           sizeof (struct iwi_cmd_desc) * IWI_CMD_RING_SIZE, 0,
-           BUS_DMA_NOWAIT, &sc->cmd_ring_map);
+           sizeof (struct iwi_cmd_desc) * count, 1,
+           sizeof (struct iwi_cmd_desc) * count, 0,
+           BUS_DMA_NOWAIT, &ring->desc_map);
        if (error != 0) {
                aprint_error("%s: could not create command ring DMA map\n",
                    sc->sc_dev.dv_xname);
@@ -429,25 +425,25 @@
        }
 
        error = bus_dmamem_alloc(sc->sc_dmat,
-           sizeof (struct iwi_cmd_desc) * IWI_CMD_RING_SIZE, PAGE_SIZE, 0,
-           &sc->cmd_ring_seg, 1, &nsegs, BUS_DMA_NOWAIT);
+           sizeof (struct iwi_cmd_desc) * count, PAGE_SIZE, 0,
+           &sc->cmdq.desc_seg, 1, &nsegs, BUS_DMA_NOWAIT);
        if (error != 0) {
                aprint_error("%s: could not allocate command ring DMA memory\n",
                    sc->sc_dev.dv_xname);
                goto fail;
        }
 
-       error = bus_dmamem_map(sc->sc_dmat, &sc->cmd_ring_seg, nsegs,
-           sizeof (struct iwi_cmd_desc) * IWI_CMD_RING_SIZE,
-           (caddr_t *)&sc->cmd_desc, BUS_DMA_NOWAIT);
+       error = bus_dmamem_map(sc->sc_dmat, &sc->cmdq.desc_seg, nsegs,
+           sizeof (struct iwi_cmd_desc) * count,
+           (caddr_t *)&sc->cmdq.desc, BUS_DMA_NOWAIT);
        if (error != 0) {
                aprint_error("%s: could not map command ring DMA memory\n",
                    sc->sc_dev.dv_xname);
                goto fail;
        }
 
-       error = bus_dmamap_load(sc->sc_dmat, sc->cmd_ring_map, sc->cmd_desc,
-           sizeof (struct iwi_cmd_desc) * IWI_CMD_RING_SIZE, NULL,
+       error = bus_dmamap_load(sc->sc_dmat, sc->cmdq.desc_map, sc->cmdq.desc,
+           sizeof (struct iwi_cmd_desc) * count, NULL,
            BUS_DMA_NOWAIT);
        if (error != 0) {
                aprint_error("%s: could not load command ring DMA map\n",
@@ -455,54 +451,216 @@
                goto fail;
        }
 
-       memset(sc->cmd_desc, 0,
-           sizeof (struct iwi_cmd_desc) * IWI_CMD_RING_SIZE);
+       memset(sc->cmdq.desc, 0,
+           sizeof (struct iwi_cmd_desc) * count);
+
+       return 0;
+
+fail:  iwi_free_cmd_ring(sc, ring);
+       return error;
+}
+
+static void
+iwi_reset_cmd_ring(struct iwi_softc *sc, struct iwi_cmd_ring *ring)
+{
+       ring->queued = 0;
+       ring->cur = ring->next = 0;
+}
+
+static void
+iwi_free_cmd_ring(struct iwi_softc *sc, struct iwi_cmd_ring *ring)
+{
+       if (ring->desc_map != NULL) {
+               if (ring->desc != NULL) {
+                       bus_dmamap_unload(sc->sc_dmat, ring->desc_map);
+                       bus_dmamem_unmap(sc->sc_dmat, (caddr_t)ring->desc,
+                           sizeof (struct iwi_cmd_desc) * ring->count);
+                       bus_dmamem_free(sc->sc_dmat, &ring->desc_seg, 1);
+               }
+               bus_dmamap_destroy(sc->sc_dmat, ring->desc_map);
+       }
+}
+
+static int
+iwi_alloc_tx_ring(struct iwi_softc *sc, struct iwi_tx_ring *ring,
+    int count)
+{
+       int i, error, nsegs;
+
+       ring->count = count;
+       ring->queued = 0;
+       ring->cur = ring->next = 0;
+
+       /*
+        * Allocate and map Tx ring
+        */
+       error = bus_dmamap_create(sc->sc_dmat,
+           sizeof (struct iwi_tx_desc) * count, 1,
+           sizeof (struct iwi_tx_desc) * count, 0, BUS_DMA_NOWAIT,
+           &ring->desc_map);
+       if (error != 0) {
+               aprint_error("%s: could not create tx ring DMA map\n",
+                   sc->sc_dev.dv_xname);
+               goto fail;
+       }
+
+       error = bus_dmamem_alloc(sc->sc_dmat,
+           sizeof (struct iwi_tx_desc) * count, PAGE_SIZE, 0,
+           &ring->desc_seg, 1, &nsegs, BUS_DMA_NOWAIT);
+       if (error != 0) {
+               aprint_error("%s: could not allocate tx ring DMA memory\n",
+                   sc->sc_dev.dv_xname);
+               goto fail;
+       }
+
+       error = bus_dmamem_map(sc->sc_dmat, &ring->desc_seg, nsegs,
+           sizeof (struct iwi_tx_desc) * count,
+           (caddr_t *)&ring->desc, BUS_DMA_NOWAIT);
+       if (error != 0) {
+               aprint_error("%s: could not map tx ring DMA memory\n",
+                   sc->sc_dev.dv_xname);
+               goto fail;
+       }
+
+       error = bus_dmamap_load(sc->sc_dmat, ring->desc_map, ring->desc,
+           sizeof (struct iwi_tx_desc) * count, NULL,
+           BUS_DMA_NOWAIT);
+       if (error != 0) {
+               aprint_error("%s: could not load tx ring DMA map\n",
+                   sc->sc_dev.dv_xname);
+               goto fail;
+       }
+
+       memset(ring->desc, 0, sizeof (struct iwi_tx_desc) * count);
+
+       ring->data = malloc(count * sizeof (struct iwi_tx_data), M_DEVBUF,
+           M_NOWAIT | M_ZERO);
+       if (ring->data == NULL) {
+               aprint_error("%s: could not allocate soft data\n",
+                   sc->sc_dev.dv_xname);
+               error = ENOMEM;
+               goto fail;
+       }



Home | Main Index | Thread Index | Old Index