Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci - Change the definition and usage of TI_HOSTADDR...



details:   https://anonhg.NetBSD.org/src/rev/fd5cebc07d97
branches:  trunk
changeset: 745358:fd5cebc07d97
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Feb 29 18:49:53 2020 +0000

description:
- Change the definition and usage of TI_HOSTADDR() to allow for 64-bit
  DMA addresses.  Modeled after similar usage in the bge(4) driver (the
  chips supported by bge(4) are descendants of those supported by ti(4)).
- Use the 64-bit PCI DMA tag if available, otherwise we're allocating (and
  using) bounce buffers needlessly.

diffstat:

 sys/dev/pci/if_ti.c    |  63 ++++++++++++++++++++++++++++++-------------------
 sys/dev/pci/if_tireg.h |  10 +------
 2 files changed, 40 insertions(+), 33 deletions(-)

diffs (222 lines):

diff -r 663d2f934fb6 -r fd5cebc07d97 sys/dev/pci/if_ti.c
--- a/sys/dev/pci/if_ti.c       Sat Feb 29 18:46:12 2020 +0000
+++ b/sys/dev/pci/if_ti.c       Sat Feb 29 18:49:53 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ti.c,v 1.114 2020/02/01 06:38:58 thorpej Exp $ */
+/* $NetBSD: if_ti.c,v 1.115 2020/02/29 18:49:53 thorpej Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999
@@ -81,7 +81,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ti.c,v 1.114 2020/02/01 06:38:58 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ti.c,v 1.115 2020/02/29 18:49:53 thorpej Exp $");
 
 #include "opt_inet.h"
 
@@ -123,6 +123,16 @@
 #include <dev/microcode/tigon/ti_fw.h>
 #include <dev/microcode/tigon/ti_fw2.h>
 
+#define        TI_HOSTADDR(x, y)                                               \
+       do {                                                            \
+               (x).ti_addr_lo = (uint32_t)(y);                         \
+               if (sizeof(bus_addr_t) == 8)                            \
+                       (x).ti_addr_hi =                                \
+                           (uint32_t)(((uint64_t)(y) >> 32));          \
+               else                                                    \
+                       (x).ti_addr_hi = 0;                             \
+       } while (/*CONSTCOND*/0)
+
 /*
  * Various supported device vendors/types and their names.
  */
@@ -740,7 +750,7 @@
 
        sc->ti_cdata.ti_rx_std_chain[i] = m_new;
        r = &sc->ti_rdata->ti_rx_std_ring[i];
-       TI_HOSTADDR(r->ti_addr) = dmamap->dm_segs[0].ds_addr;
+       TI_HOSTADDR(r->ti_addr, dmamap->dm_segs[0].ds_addr);
        r->ti_type = TI_BDTYPE_RECV_BD;
        r->ti_flags = 0;
        if (sc->ethercom.ec_if.if_capenable & IFCAP_CSUM_IPv4_Rx)
@@ -807,7 +817,7 @@
 
        r = &sc->ti_rdata->ti_rx_mini_ring[i];
        sc->ti_cdata.ti_rx_mini_chain[i] = m_new;
-       TI_HOSTADDR(r->ti_addr) = dmamap->dm_segs[0].ds_addr;
+       TI_HOSTADDR(r->ti_addr, dmamap->dm_segs[0].ds_addr);
        r->ti_type = TI_BDTYPE_RECV_BD;
        r->ti_flags = TI_BDFLAG_MINI_RING;
        if (sc->ethercom.ec_if.if_capenable & IFCAP_CSUM_IPv4_Rx)
@@ -866,8 +876,8 @@
        /* Set up the descriptor. */
        r = &sc->ti_rdata->ti_rx_jumbo_ring[i];
        sc->ti_cdata.ti_rx_jumbo_chain[i] = m_new;
-       TI_HOSTADDR(r->ti_addr) = sc->jumbo_dmaaddr +
-               (mtod(m_new, char *) - (char *)sc->ti_cdata.ti_jumbo_buf);
+       TI_HOSTADDR(r->ti_addr, sc->jumbo_dmaaddr +
+           (mtod(m_new, char *) - (char *)sc->ti_cdata.ti_jumbo_buf));
        r->ti_type = TI_BDTYPE_RECV_JUMBO_BD;
        r->ti_flags = TI_BDFLAG_JUMBO_RING;
        if (sc->ethercom.ec_if.if_capenable & IFCAP_CSUM_IPv4_Rx)
@@ -1414,10 +1424,10 @@
        /* Set up the event ring and producer pointer. */
        rcb = &sc->ti_rdata->ti_info.ti_ev_rcb;
 
-       TI_HOSTADDR(rcb->ti_hostaddr) = TI_CDEVENTADDR(sc, 0);
+       TI_HOSTADDR(rcb->ti_hostaddr, TI_CDEVENTADDR(sc, 0));
        rcb->ti_flags = 0;
-       TI_HOSTADDR(sc->ti_rdata->ti_info.ti_ev_prodidx_ptr) =
-           TI_CDEVPRODADDR(sc);
+       TI_HOSTADDR(sc->ti_rdata->ti_info.ti_ev_prodidx_ptr,
+           TI_CDEVPRODADDR(sc));
 
        sc->ti_ev_prodidx.ti_idx = 0;
        CSR_WRITE_4(sc, TI_GCR_EVENTCONS_IDX, 0);
@@ -1426,7 +1436,7 @@
        /* Set up the command ring and producer mailbox. */
        rcb = &sc->ti_rdata->ti_info.ti_cmd_rcb;
 
-       TI_HOSTADDR(rcb->ti_hostaddr) = TI_GCR_NIC_ADDR(TI_GCR_CMDRING);
+       TI_HOSTADDR(rcb->ti_hostaddr, TI_GCR_NIC_ADDR(TI_GCR_CMDRING));
        rcb->ti_flags = 0;
        rcb->ti_max_len = 0;
        for (i = 0; i < TI_CMD_RING_CNT; i++) {
@@ -1441,12 +1451,12 @@
         * We re-use the current stats buffer for this to
         * conserve memory.
         */
-       TI_HOSTADDR(sc->ti_rdata->ti_info.ti_refresh_stats_ptr) =
-           TI_CDSTATSADDR(sc);
+       TI_HOSTADDR(sc->ti_rdata->ti_info.ti_refresh_stats_ptr,
+           TI_CDSTATSADDR(sc));
 
        /* Set up the standard receive ring. */
        rcb = &sc->ti_rdata->ti_info.ti_std_rx_rcb;
-       TI_HOSTADDR(rcb->ti_hostaddr) = TI_CDRXSTDADDR(sc, 0);
+       TI_HOSTADDR(rcb->ti_hostaddr, TI_CDRXSTDADDR(sc, 0));
        rcb->ti_max_len = ETHER_MAX_LEN;
        rcb->ti_flags = 0;
        if (ifp->if_capenable & IFCAP_CSUM_IPv4_Rx)
@@ -1458,7 +1468,7 @@
 
        /* Set up the jumbo receive ring. */
        rcb = &sc->ti_rdata->ti_info.ti_jumbo_rx_rcb;
-       TI_HOSTADDR(rcb->ti_hostaddr) = TI_CDRXJUMBOADDR(sc, 0);
+       TI_HOSTADDR(rcb->ti_hostaddr, TI_CDRXJUMBOADDR(sc, 0));
        rcb->ti_max_len = ETHER_MAX_LEN_JUMBO;
        rcb->ti_flags = 0;
        if (ifp->if_capenable & IFCAP_CSUM_IPv4_Rx)
@@ -1474,7 +1484,7 @@
         * still there on the Tigon 1.
         */
        rcb = &sc->ti_rdata->ti_info.ti_mini_rx_rcb;
-       TI_HOSTADDR(rcb->ti_hostaddr) = TI_CDRXMINIADDR(sc, 0);
+       TI_HOSTADDR(rcb->ti_hostaddr, TI_CDRXMINIADDR(sc, 0));
        rcb->ti_max_len = MHLEN - ETHER_ALIGN;
        if (sc->ti_hwrev == TI_HWREV_TIGON)
                rcb->ti_flags = TI_RCB_FLAG_RING_DISABLED;
@@ -1491,11 +1501,11 @@
         * Set up the receive return ring.
         */
        rcb = &sc->ti_rdata->ti_info.ti_return_rcb;
-       TI_HOSTADDR(rcb->ti_hostaddr) = TI_CDRXRTNADDR(sc, 0);
+       TI_HOSTADDR(rcb->ti_hostaddr, TI_CDRXRTNADDR(sc, 0));
        rcb->ti_flags = 0;
        rcb->ti_max_len = TI_RETURN_RING_CNT;
-       TI_HOSTADDR(sc->ti_rdata->ti_info.ti_return_prodidx_ptr) =
-           TI_CDRTNPRODADDR(sc);
+       TI_HOSTADDR(sc->ti_rdata->ti_info.ti_return_prodidx_ptr,
+           TI_CDRTNPRODADDR(sc));
 
        /*
         * Set up the tx ring. Note: for the Tigon 2, we have the option
@@ -1532,11 +1542,11 @@
                rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
        rcb->ti_max_len = TI_TX_RING_CNT;
        if (sc->ti_hwrev == TI_HWREV_TIGON)
-               TI_HOSTADDR(rcb->ti_hostaddr) = TI_TX_RING_BASE;
+               TI_HOSTADDR(rcb->ti_hostaddr, TI_TX_RING_BASE);
        else
-               TI_HOSTADDR(rcb->ti_hostaddr) = TI_CDTXADDR(sc, 0);
-       TI_HOSTADDR(sc->ti_rdata->ti_info.ti_tx_considx_ptr) =
-           TI_CDTXCONSADDR(sc);
+               TI_HOSTADDR(rcb->ti_hostaddr, TI_CDTXADDR(sc, 0));
+       TI_HOSTADDR(sc->ti_rdata->ti_info.ti_tx_considx_ptr,
+           TI_CDTXCONSADDR(sc));
 
        /*
         * We're done frobbing the General Information Block.  Sync
@@ -1728,7 +1738,10 @@
         */
        aprint_normal_dev(self, "Ethernet address %s\n", ether_sprintf(eaddr));
 
-       sc->sc_dmat = pa->pa_dmat;
+       if (pci_dma64_available(pa))
+               sc->sc_dmat = pa->pa_dmat64;
+       else
+               sc->sc_dmat = pa->pa_dmat;
 
        /* Allocate the general information block and ring buffers. */
        if ((error = bus_dmamem_alloc(sc->sc_dmat,
@@ -2260,7 +2273,7 @@
                f = &sc->ti_tx_ring_nic[frag % 128];
                if (sc->ti_cdata.ti_tx_chain[frag] != NULL)
                        break;
-               TI_HOSTADDR(f->ti_addr) = dmamap->dm_segs[i].ds_addr;
+               TI_HOSTADDR(f->ti_addr, dmamap->dm_segs[i].ds_addr);
                f->ti_len = dmamap->dm_segs[i].ds_len;
                f->ti_flags = csum_flags;
                if (vlan_has_tag(m_head)) {
@@ -2351,7 +2364,7 @@
                f = &sc->ti_rdata->ti_tx_ring[frag];
                if (sc->ti_cdata.ti_tx_chain[frag] != NULL)
                        break;
-               TI_HOSTADDR(f->ti_addr) = dmamap->dm_segs[i].ds_addr;
+               TI_HOSTADDR(f->ti_addr, dmamap->dm_segs[i].ds_addr);
                f->ti_len = dmamap->dm_segs[i].ds_len;
                f->ti_flags = csum_flags;
                if (vlan_has_tag(m_head)) {
diff -r 663d2f934fb6 -r fd5cebc07d97 sys/dev/pci/if_tireg.h
--- a/sys/dev/pci/if_tireg.h    Sat Feb 29 18:46:12 2020 +0000
+++ b/sys/dev/pci/if_tireg.h    Sat Feb 29 18:49:53 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_tireg.h,v 1.23 2020/02/01 06:38:58 thorpej Exp $ */
+/* $NetBSD: if_tireg.h,v 1.24 2020/02/29 18:49:53 thorpej Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999
@@ -270,7 +270,7 @@
 #define TI_GCR_RXRETURNCONS_IDX                0x680
 #define TI_GCR_CMDRING                 0x700
 
-#define TI_GCR_NIC_ADDR(x)             (x - TI_GCR_BASE);
+#define TI_GCR_NIC_ADDR(x)             (x - TI_GCR_BASE)
 
 /*
  * Local memory window. The local memory window is a 2K shared
@@ -373,21 +373,15 @@
  */
 #define TI_MEM_MAX             0x7FFFFF
 
-/*
- * Even on the alpha, pci addresses are 32-bit quantities
- */
-
 #ifdef __64_bit_pci_addressing__
 typedef struct {
        u_int64_t               ti_addr;
 } ti_hostaddr;
-#define TI_HOSTADDR(x) x.ti_addr
 #else
 typedef struct {
        u_int32_t               ti_addr_hi;
        u_int32_t               ti_addr_lo;
 } ti_hostaddr;
-#define TI_HOSTADDR(x) x.ti_addr_lo
 #endif
 
 /*



Home | Main Index | Thread Index | Old Index