Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Discard previous driver; it didnt really do anyt...



details:   https://anonhg.NetBSD.org/src/rev/7c22f2cd3d4f
branches:  trunk
changeset: 550127:7c22f2cd3d4f
user:      jonathan <jonathan%NetBSD.org@localhost>
date:      Wed Jul 30 18:49:27 2003 +0000

description:
Discard previous driver; it didnt really do anything.

Replace with  a new from-scratch port of  recent OpenBSD hifn7751 source,
with changes to the crypto-framework calls to fit Sam Leffler's rework.
(Some of the attach-time changes from the previous driver were carried over).
Many thanks to Quentin Garnier (cube%cubidou.net@localhost) for testing an pre-release
of the driver and finding a couple of missing initializations.

Note that RNG support is temporarily disabled, until a potential issue
with RNG quality is investigated and resolved.

diffstat:

 sys/dev/pci/hifn7751.c    |  2665 ++++++++++++++++++++++++++++++++++----------
 sys/dev/pci/hifn7751reg.h |   353 +++--
 sys/dev/pci/hifn7751var.h |   249 ++-
 3 files changed, 2453 insertions(+), 814 deletions(-)

diffs (truncated from 4056 to 300 lines):

diff -r fe59edf45e28 -r 7c22f2cd3d4f sys/dev/pci/hifn7751.c
--- a/sys/dev/pci/hifn7751.c    Wed Jul 30 18:45:31 2003 +0000
+++ b/sys/dev/pci/hifn7751.c    Wed Jul 30 18:49:27 2003 +0000
@@ -1,11 +1,12 @@
-/*     $NetBSD: hifn7751.c,v 1.14 2003/05/03 18:11:34 wiz Exp $        */
-/*     $OpenBSD: hifn7751.c,v 1.47 2000/10/11 13:15:41 itojun Exp $    */
+/*     $NetBSD: hifn7751.c,v 1.15 2003/07/30 18:49:27 jonathan Exp $   */
+/*     $FreeBSD: hifn7751.c,v 1.5.2.6 2003/07/02 17:04:50 sam Exp $ */
+/*     $OpenBSD: hifn7751.c,v 1.139 2003/03/13 20:08:06 jason Exp $    */
 
 /*
- * Invertex AEON / Hi/fn 7751 driver
+ * Invertex AEON / Hifn 7751 driver
  * Copyright (c) 1999 Invertex Inc. All rights reserved.
  * Copyright (c) 1999 Theo de Raadt
- * Copyright (c) 2000 Network Security Technologies, Inc.
+ * Copyright (c) 2000-2001 Network Security Technologies, Inc.
  *                     http://www.netsec.net
  *
  * This driver is based on a previous driver by Invertex, for which they
@@ -34,14 +35,27 @@
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Effort sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F30602-01-2-0537.
+ *
  */
 
 /*
- * Driver for the Hi/Fn 7751 encryption processor.
+ * Driver for the Hifn 7751 encryption processor.
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hifn7751.c,v 1.14 2003/05/03 18:11:34 wiz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hifn7751.c,v 1.15 2003/07/30 18:49:27 jonathan Exp $");
+
+#include "rnd.h"
+#include "opencrypto.h"
+
+#if NRND == 0 || NOPENCRYPTO == 0
+#error hifn7751 requires rnd and opencrypto pseudo-devices
+#endif
+
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -50,41 +64,51 @@
 #include <sys/malloc.h>
 #include <sys/kernel.h>
 #include <sys/mbuf.h>
-#ifdef __OpenBSD__
-#include <vm/vm.h>
-#include <vm/vm_extern.h>
-#include <vm/pmap.h>
-#else
-#include <uvm/uvm.h>
+#include <sys/device.h>
+
 #include <uvm/uvm_extern.h>
-#include <uvm/uvm_pmap.h>
-#endif
-#include <machine/pmap.h>
-#include <sys/device.h>
+
 
 #ifdef __OpenBSD__
 #include <crypto/crypto.h>
 #include <dev/rndvar.h>
+#else
+#include <opencrypto/cryptodev.h>
+#include <sys/rnd.h>
 #endif
 
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcidevs.h>
 
+#include <dev/pci/hifn7751reg.h>
 #include <dev/pci/hifn7751var.h>
-#include <dev/pci/hifn7751reg.h>
 
 #undef HIFN_DEBUG
 
+#ifdef __NetBSD__
+#define        HIFN_NO_RNG                     /* until statistically tested */
+#define M_DUP_PKTHDR M_COPY_PKTHDR     /* XXX */
+#endif
+
+#ifdef HIFN_DEBUG
+extern int hifn_debug;         /* patchable */
+int hifn_debug = 1;
+#endif
+
+#ifdef __OpenBSD__
+#define HAVE_CRYPTO_LZS                /* OpenBSD OCF supports CRYPTO_COMP_LZS */
+#endif
+
 /*
  * Prototypes and count for the pci_device structure
  */
 #ifdef __OpenBSD__
-int hifn_probe         __P((struct device *, void *, void *));
+int hifn_probe((struct device *, void *, void *);
 #else
-int hifn_probe         __P((struct device *, struct cfdata *, void *));
+int hifn_probe(struct device *, struct cfdata *, void *);
 #endif
-void hifn_attach       __P((struct device *, struct device *, void *));
+void hifn_attach(struct device *, struct device *, void *);
 
 CFATTACH_DECL(hifn, sizeof(struct hifn_softc),
     hifn_probe, hifn_attach, NULL, NULL);
@@ -95,40 +119,65 @@
 };
 #endif
 
-void   hifn_reset_board __P((struct hifn_softc *));
-int    hifn_enable_crypto __P((struct hifn_softc *, pcireg_t));
-void   hifn_init_dma __P((struct hifn_softc *));
-void   hifn_init_pci_registers __P((struct hifn_softc *));
-int    hifn_sramsize __P((struct hifn_softc *));
-int    hifn_dramsize __P((struct hifn_softc *));
-void   hifn_ramtype __P((struct hifn_softc *));
-void   hifn_sessions __P((struct hifn_softc *));
-int    hifn_intr __P((void *));
-u_int  hifn_write_command __P((struct hifn_command *, u_int8_t *));
-u_int32_t hifn_next_signature __P((u_int32_t a, u_int cnt));
-#ifdef __OpenBSD__
-int    hifn_newsession __P((u_int32_t *, struct cryptoini *));
-int    hifn_freesession __P((u_int64_t));
-int    hifn_process __P((struct cryptop *));
-void   hifn_callback __P((struct hifn_softc *, struct hifn_command *, u_int8_t *));
+void   hifn_reset_board(struct hifn_softc *, int);
+void   hifn_reset_puc(struct hifn_softc *);
+void   hifn_puc_wait(struct hifn_softc *);
+int    hifn_enable_crypto(struct hifn_softc *, pcireg_t);
+void   hifn_set_retry(struct hifn_softc *);
+void   hifn_init_dma(struct hifn_softc *);
+void   hifn_init_pci_registers(struct hifn_softc *);
+int    hifn_sramsize(struct hifn_softc *);
+int    hifn_dramsize(struct hifn_softc *);
+int    hifn_ramtype(struct hifn_softc *);
+void   hifn_sessions(struct hifn_softc *);
+int    hifn_intr(void *);
+u_int  hifn_write_command(struct hifn_command *, u_int8_t *);
+u_int32_t hifn_next_signature(u_int32_t a, u_int cnt);
+int    hifn_newsession(void*, u_int32_t *, struct cryptoini *);
+int    hifn_freesession(void*, u_int64_t);
+int    hifn_process(void*, struct cryptop *, int);
+void   hifn_callback(struct hifn_softc *, struct hifn_command *, u_int8_t *);
+int    hifn_crypto(struct hifn_softc *, struct hifn_command *,
+                   struct cryptop*, int);
+int    hifn_readramaddr(struct hifn_softc *, int, u_int8_t *);
+int    hifn_writeramaddr(struct hifn_softc *, int, u_int8_t *);
+int    hifn_dmamap_aligned(bus_dmamap_t);
+int    hifn_dmamap_load_src(struct hifn_softc *, struct hifn_command *);
+int    hifn_dmamap_load_dst(struct hifn_softc *, struct hifn_command *);
+int    hifn_init_pubrng(struct hifn_softc *);
+#ifndef HIFN_NO_RNG
+static void hifn_rng(void *);
 #endif
-int    hifn_crypto __P((struct hifn_softc *, hifn_command_t *));
-int    hifn_readramaddr __P((struct hifn_softc *, int, u_int8_t *, int));
-int    hifn_writeramaddr __P((struct hifn_softc *, int, u_int8_t *, int));
-
-struct hifn_stats {
-       u_int64_t hst_ibytes;
-       u_int64_t hst_obytes;
-       u_int32_t hst_ipackets;
-       u_int32_t hst_opackets;
-       u_int32_t hst_invalid;
-       u_int32_t hst_nomem;
-} hifnstats;
+void   hifn_tick(void *);
+void   hifn_abort(struct hifn_softc *);
+void   hifn_alloc_slot(struct hifn_softc *, int *, int *, int *, int *);
+void   hifn_write_4(struct hifn_softc *, int, bus_size_t, u_int32_t);
+u_int32_t hifn_read_4(struct hifn_softc *, int, bus_size_t);
+#ifdef HAVE_CRYPTO_LZS
+int    hifn_compression(struct hifn_softc *, struct cryptop *,
+                        struct hifn_command *);
+struct mbuf *hifn_mkmbuf_chain(int, struct mbuf *);
+int    hifn_compress_enter(struct hifn_softc *, struct hifn_command *);
+void   hifn_callback_comp(struct hifn_softc *, struct hifn_command *,
+                          u_int8_t *);
+#endif /* HAVE_CRYPTO_LZS */
+
+
+#ifdef notyet
+int    hifn_compression(struct hifn_softc *, struct cryptop *,
+    struct hifn_command *);
+struct mbuf *hifn_mkmbuf_chain(int, struct mbuf *);
+int    hifn_compress_enter(struct hifn_softc *, struct hifn_command *);
+void   hifn_callback_comp(struct hifn_softc *, struct hifn_command *,
+    u_int8_t *);
+#endif
+
+struct hifn_stats hifnstats;
 
 int
 hifn_probe(parent, match, aux)
        struct device *parent;
-#ifdef __OpenBSD__
+#ifdef __OpenBSD__
        void *match;
 #else
        struct cfdata *match;
@@ -143,6 +192,12 @@
        if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_HIFN &&
            PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_HIFN_7751)
                return (1);
+       if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_HIFN &&
+           PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_HIFN_7811)
+               return (1);
+       if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_HIFN &&
+           PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_HIFN_7951)
+               return (1);
        if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NETSEC &&
            PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NETSEC_7751)
                return (1);
@@ -170,6 +225,18 @@
 
        aprint_naive(": Crypto processor\n");
 
+       sc->sc_pci_pc = pa->pa_pc;
+       sc->sc_pci_tag = pa->pa_tag;
+
+       if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_HIFN &&
+           PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_HIFN_7951)
+               sc->sc_flags = HIFN_HAS_RNG | HIFN_HAS_PUBLIC;
+
+       if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_HIFN &&
+           PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_HIFN_7811)
+               sc->sc_flags |= HIFN_IS_7811 | HIFN_HAS_RNG | HIFN_HAS_LEDS |
+                   HIFN_NO_BURSTWRITE;
+
        cmd = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
        cmd |= PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE;
        pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, cmd);
@@ -192,6 +259,13 @@
                goto fail_io0;
        }
 
+       hifn_set_retry(sc);
+
+       if (sc->sc_flags & HIFN_NO_BURSTWRITE) {
+               sc->sc_waw_lastgroup = -1;
+               sc->sc_waw_lastreg = 1;
+       }
+
        sc->sc_dmat = pa->pa_dmat;
        if (bus_dmamem_alloc(sc->sc_dmat, sizeof(*sc->sc_dma), PAGE_SIZE, 0,
            &seg, 1, &rseg, BUS_DMA_NOWAIT)) {
@@ -220,47 +294,45 @@
                bus_dmamem_free(sc->sc_dmat, &seg, rseg);
                goto fail_io1;
        }
+       sc->sc_dmamap = dmamap;
        sc->sc_dma = (struct hifn_dma *)kva;
-       memset(sc->sc_dma, 0, sizeof(*sc->sc_dma));
-
-       hifn_reset_board(sc);
+       bzero(sc->sc_dma, sizeof(*sc->sc_dma));
+
+       hifn_reset_board(sc, 0);
 
        if (hifn_enable_crypto(sc, pa->pa_id) != 0) {
                aprint_error("%s: crypto enabling failed\n",
                    sc->sc_dv.dv_xname);
                goto fail_mem;
        }
+       hifn_reset_puc(sc);
 
        hifn_init_dma(sc);
        hifn_init_pci_registers(sc);
 
-       hifn_ramtype(sc);
+       if (hifn_ramtype(sc))
+               goto fail_mem;
 
        if (sc->sc_drammodel == 0)
                hifn_sramsize(sc);
        else
                hifn_dramsize(sc);
 
+       /*
+        * Workaround for NetSec 7751 rev A: half ram size because two
+        * of the address lines were left floating
+        */
        if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NETSEC &&
            PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NETSEC_7751 &&
            PCI_REVISION(pa->pa_class) == 0x61)
                sc->sc_ramsize >>= 1;
 
-       /*
-        * Reinitialize again, since the DRAM/SRAM detection shifted our ring



Home | Main Index | Thread Index | Old Index