Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Add support for setting the clock and adapt the ...



details:   https://anonhg.NetBSD.org/src/rev/97201eca7c0e
branches:  trunk
changeset: 480108:97201eca7c0e
user:      chopps <chopps%NetBSD.org@localhost>
date:      Tue Jan 04 06:31:39 2000 +0000

description:
Add support for setting the clock and adapt the code to the new more
generic ic/hd56470.c core which now supports the isa version of the
same card.

diffstat:

 sys/dev/pci/files.pci         |    4 +-
 sys/dev/pci/if_ntwoc_pci.c    |  415 ++++++++++++++++++++++++++++++++++++++++-
 sys/dev/pci/if_ntwoc_pcireg.h |   39 +++-
 3 files changed, 437 insertions(+), 21 deletions(-)

diffs (truncated from 595 to 300 lines):

diff -r 5907e3ffd7fa -r 97201eca7c0e sys/dev/pci/files.pci
--- a/sys/dev/pci/files.pci     Tue Jan 04 06:30:04 2000 +0000
+++ b/sys/dev/pci/files.pci     Tue Jan 04 06:31:39 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.pci,v 1.73 1999/12/13 20:19:25 augustss Exp $
+#      $NetBSD: files.pci,v 1.74 2000/01/04 06:31:39 chopps Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -115,7 +115,7 @@
 file    dev/pci/if_tl.c                tl
 
 # SDL Communications N2 PCI Network Interface
-device ntwoc: ifnet, hd64570
+# device declaration in sys/conf/files
 attach ntwoc at pci with ntwoc_pci
 file   dev/pci/if_ntwoc_pci.c          ntwoc_pci
 
diff -r 5907e3ffd7fa -r 97201eca7c0e sys/dev/pci/if_ntwoc_pci.c
--- a/sys/dev/pci/if_ntwoc_pci.c        Tue Jan 04 06:30:04 2000 +0000
+++ b/sys/dev/pci/if_ntwoc_pci.c        Tue Jan 04 06:31:39 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ntwoc_pci.c,v 1.2 1999/02/15 04:54:35 hubertf Exp $ */
+/*     $NetBSD: if_ntwoc_pci.c,v 1.3 2000/01/04 06:31:39 chopps Exp $  */
 
 /*
  * Copyright (c) 1998 Vixie Enterprises
@@ -68,6 +68,29 @@
 #endif
 
 /*
+ * buffers per tx and rx channels, per port, and the size of each.
+ * Don't use these constants directly, as they are really only hints.
+ * Use the calculated values stored in struct sca_softc instead.
+ *
+ * Each must be at least 2, receive would be better at around 20 or so.
+ *
+ * XXX Due to a damned near impossible to track down bug, transmit buffers
+ * MUST be 2, no more, no less.
+ */
+#ifndef NTWOC_NtxBUFS
+#define NTWOC_NtxBUFS     40
+#endif
+#ifndef NTWOC_NrxBUFS
+#define NTWOC_NrxBUFS     20
+#endif
+
+#if __NetBSD_Version__ >= 104160000
+static void ntwoc_pci_config_interrupts __P((struct device *));
+#else
+#define        SCA_BASECLOCK   16000000
+#endif
+
+/*
  * Card specific config register location
  */
 #define PCI_CBMA_ASIC  0x10    /* Configuration Base Memory Address */
@@ -90,9 +113,14 @@
 static  int ntwoc_pci_match __P((struct device *, struct cfdata *, void *));
 static  void ntwoc_pci_attach __P((struct device *, struct device *, void *));
 
-static int ntwoc_intr __P((void *));
-static void ntwoc_shutdown __P((void *sc));
-static void ntwoc_dtr_callback __P((void *, int, int));
+static int ntwoc_pci_alloc_dma __P((struct sca_softc *));
+static void ntwoc_pci_clock_callback __P((void *, int, int));
+static void ntwoc_pci_dtr_callback __P((void *, int, int));
+static void ntwoc_pci_get_clock __P((struct sca_port *, u_int8_t, u_int8_t,
+    u_int8_t, u_int8_t));
+static int ntwoc_pci_intr __P((void *));
+static void ntwoc_pci_setup_dma __P((struct sca_softc *));
+static void ntwoc_pci_shutdown __P((void *sc));
 
 struct cfattach ntwoc_pci_ca = {
   sizeof(struct ntwoc_pci_softc), ntwoc_pci_match, ntwoc_pci_attach,
@@ -101,11 +129,49 @@
 /*
  * Names for daughter card types.  These match the NTWOC_DB_* defines.
  */
-char *ntwoc_db_names[] = {
+char *ntwoc_pci_db_names[] = {
        "V.35", "Unknown 0x01", "Test", "Unknown 0x03",
        "RS232", "Unknown 0x05", "RS422", "None"
 };
 
+/*
+ * At least one implementation uses a somewhat strange register address
+ * mapping.  If a card doesn't, define this to be a pass-through
+ * macro.  (The ntwo driver needs this...)
+ */
+#define SCA_REG(y)  (((y) & 0x0002) ? (((y) & 0x00fd) + 0x100) : (y))
+
+/*
+ * functions that read and write to the sca registers
+ */
+static void
+ntwoc_pci_sca_write_1(struct sca_softc *sc, u_int reg, u_int8_t val)
+{
+       bus_space_write_1(sc->sc_iot, sc->sc_ioh, SCA_REG(reg), val);
+}
+
+static void
+ntwoc_pci_sca_write_2(struct sca_softc *sc, u_int reg, u_int16_t val)
+{
+       bus_space_write_2(sc->sc_iot, sc->sc_ioh, SCA_REG(reg), val);
+}
+
+static u_int8_t
+ntwoc_pci_sca_read_1(struct sca_softc *sc, u_int reg)
+{
+       return
+           bus_space_read_1(sc->sc_iot, sc->sc_ioh, SCA_REG(reg));
+}
+
+static u_int16_t
+ntwoc_pci_sca_read_2(struct sca_softc *sc, u_int reg)
+{
+       return
+           bus_space_read_2(sc->sc_iot, sc->sc_ioh, SCA_REG(reg));
+}
+
+
+
 static int
 ntwoc_pci_match(struct device *parent, struct cfdata *match, void *aux)
 {
@@ -127,11 +193,14 @@
        pci_intr_handle_t ih;
        const char *intrstr;
        pcireg_t csr;
+       u_int8_t tmc, rdiv, tdiv;
        u_int16_t frontend_cr;
        u_int16_t db0, db1;
+       u_int32_t flags;
        u_int numports;
 
        printf(": N2 Serial Interface\n");
+       flags = sc->sc_dev.dv_cfdata->cf_flags;
 
        /*
         * Map in the ASIC configuration space
@@ -167,7 +236,8 @@
                return;
        }
        intrstr = pci_intr_string(pa->pa_pc, ih);
-       sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET, ntwoc_intr, sc);
+       sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET, ntwoc_pci_intr,
+           sc);
        if (sc->sc_ih == NULL) {
                printf("%s: couldn't establish interrupt",
                       sc->sc_dev.dv_xname);
@@ -214,7 +284,8 @@
        /*
         * pass the dma tag to the SCA
         */
-       sca->sc_dmat = pa->pa_dmat;
+       sca->sc_usedma = 1;
+       sca->scu_dmat = pa->pa_dmat;
 
        /*
         * Read the configuration information off the daughter card.
@@ -245,10 +316,10 @@
        printf("%s: %d port%s\n", sc->sc_dev.dv_xname, numports,
               (numports > 1 ? "s" : ""));
        printf("%s: port 0 interface card: %s\n", sc->sc_dev.dv_xname,
-              ntwoc_db_names[db0]);
+              ntwoc_pci_db_names[db0]);
        if (numports > 1)
                printf("%s: port 1 interface card: %s\n", sc->sc_dev.dv_xname,
-                      ntwoc_db_names[db1]);
+                      ntwoc_pci_db_names[db1]);
 
        /*
         * enable the RS422 tristate transmit
@@ -264,10 +335,40 @@
         * on the number of ports we passed in, the size of each
         * buffer, and the number of buffers per port.
         */
-       sca->parent = &sc->sc_dev;
-       sca->dtr_callback = ntwoc_dtr_callback;
-       sca->dtr_aux = sc;
-       sca_init(sca, numports);
+       sca->sc_parent = &sc->sc_dev;
+       sca->sc_read_1 = ntwoc_pci_sca_read_1;
+       sca->sc_read_2 = ntwoc_pci_sca_read_2;
+       sca->sc_write_1 = ntwoc_pci_sca_write_1;
+       sca->sc_write_2 = ntwoc_pci_sca_write_2;
+       sca->sc_dtr_callback = ntwoc_pci_dtr_callback;
+       sca->sc_clock_callback = ntwoc_pci_clock_callback;
+       sca->sc_aux = sc;
+       sca->sc_numports = numports;
+
+       /*
+        * get clock information from user
+        */
+       rdiv = (flags & NTWOC_FLAGS_RXDIV_MASK) >> NTWOC_FLAGS_RXDIV_SHIFT;
+       if (rdiv > 9)
+               panic("bad rx divisor in flags");
+
+       tdiv = (flags & NTWOC_FLAGS_TXDIV_MASK) >> NTWOC_FLAGS_TXDIV_SHIFT;
+       if (tdiv > 9)
+               panic("bad tx divisor in flags");
+       tmc = (flags & NTWOC_FLAGS_TMC_MASK) >> NTWOC_FLAGS_TMC_SHIFT;
+
+       ntwoc_pci_get_clock(&sca->sc_ports[0], flags & NTWOC_FLAGS_CLK0_MASK,
+           tmc, rdiv, tdiv);
+       if (sca->sc_numports > 1)
+               ntwoc_pci_get_clock(&sca->sc_ports[1],
+                   (flags & NTWOC_FLAGS_CLK1_MASK) >> NTWOC_FLAGS_CLK1_SHIFT,
+                   tmc, rdiv, tdiv);
+
+       /* allocate dma'able memory for card to use */
+       ntwoc_pci_alloc_dma(sca);
+       ntwoc_pci_setup_dma(sca);
+
+       sca_init(sca);
 
        /*
         * always initialize port 0, since we have to have found it to
@@ -283,11 +384,73 @@
         * doing do could allow DMA to corrupt kernel memory during the
         * reboot before the driver initializes.
         */
-       shutdownhook_establish(ntwoc_shutdown, sc);
+       shutdownhook_establish(ntwoc_pci_shutdown, sc);
+
+#if __NetBSD_Version__ >= 104160000
+       /*
+        * defer getting the base clock until interrupts are enabled
+        * (and thus we have microtime())
+        */
+       config_interrupts(self, ntwoc_pci_config_interrupts);
+#else
+       sca->sc_baseclock = SCA_BASECLOCK;
+       sca_print_clock_info(&sc->sc_sca);
+#endif
 }
 
+/*
+ * extract the clock information for a port from the flags field
+ */
+static void
+ntwoc_pci_get_clock(struct sca_port *scp, u_int8_t flags, u_int8_t tmc,
+    u_int8_t rdiv, u_int8_t tdiv)
+{
+       scp->sp_eclock =
+           (flags & NTWOC_FLAGS_ECLOCK_MASK) >> NTWOC_FLAGS_ECLOCK_SHIFT;
+       scp->sp_rxs = rdiv;
+       scp->sp_txs = tdiv;
+       scp->sp_tmc = tmc;
+
+       /* get rx source */
+       switch ((flags & NTWOC_FLAGS_RXS_MASK) >> NTWOC_FLAGS_RXS_SHIFT) {
+       case NTWOC_FLAGS_RXS_LINE:
+               scp->sp_rxs = 0;
+               break;
+       case NTWOC_FLAGS_RXS_LINE_SN:
+               scp->sp_rxs |= SCA_RXS_CLK_LINE_SN;
+               break;
+       case NTWOC_FLAGS_RXS_INTERNAL:
+               scp->sp_rxs |= SCA_RXS_CLK_INTERNAL;
+               break;
+       case NTWOC_FLAGS_RXS_ADPLL_OUT:
+               scp->sp_rxs |= SCA_RXS_CLK_ADPLL_OUT;
+               break;
+       case NTWOC_FLAGS_RXS_ADPLL_IN:
+               scp->sp_rxs |= SCA_RXS_CLK_ADPLL_IN;
+               break;
+       default:
+               panic("bad rx source in flags");
+       }
+
+       /* get tx source */
+       switch ((flags & NTWOC_FLAGS_TXS_MASK) >> NTWOC_FLAGS_TXS_SHIFT) {
+       case NTWOC_FLAGS_TXS_LINE:
+               scp->sp_txs = 0;
+               break;
+       case NTWOC_FLAGS_TXS_INTERNAL:
+               scp->sp_txs |= SCA_TXS_CLK_INTERNAL;
+               break;
+       case NTWOC_FLAGS_TXS_RXCLOCK:
+               scp->sp_txs |= SCA_TXS_CLK_RXCLK;
+               break;
+       default:
+               panic("bad rx source in flags");
+       }
+}
+
+
 static int
-ntwoc_intr(void *arg)
+ntwoc_pci_intr(void *arg)
 {
        struct ntwoc_pci_softc *sc = (struct ntwoc_pci_softc *)arg;
 
@@ -299,7 +462,7 @@
  * boot.  Also, lower DTR on each port and disable card interrupts.
  */
 static void
-ntwoc_shutdown(void *aux)



Home | Main Index | Thread Index | Old Index