1 /* $OpenBSD: hifn7751.c,v 1.120 2002/05/17 00:33:34 deraadt Exp $ */
4 * SPDX-License-Identifier: BSD-3-Clause
6 * Invertex AEON / Hifn 7751 driver
7 * Copyright (c) 1999 Invertex Inc. All rights reserved.
8 * Copyright (c) 1999 Theo de Raadt
9 * Copyright (c) 2000-2001 Network Security Technologies, Inc.
10 * http://www.netsec.net
11 * Copyright (c) 2003 Hifn Inc.
13 * This driver is based on a previous driver by Invertex, for which they
14 * requested: Please send any comments, feedback, bug-fixes, or feature
15 * requests to software@invertex.com.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 3. The name of the author may not be used to endorse or promote products
27 * derived from this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
30 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
31 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
34 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
38 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 * Effort sponsored in part by the Defense Advanced Research Projects
41 * Agency (DARPA) and Air Force Research Laboratory, Air Force
42 * Materiel Command, USAF, under agreement number F30602-01-2-0537.
45 #include <sys/cdefs.h>
46 __FBSDID("$FreeBSD$");
49 * Driver for various Hifn encryption processors.
53 #include <sys/param.h>
54 #include <sys/systm.h>
56 #include <sys/errno.h>
57 #include <sys/malloc.h>
58 #include <sys/kernel.h>
59 #include <sys/module.h>
62 #include <sys/mutex.h>
63 #include <sys/sysctl.h>
69 #include <machine/bus.h>
70 #include <machine/resource.h>
74 #include <opencrypto/cryptodev.h>
75 #include <opencrypto/xform_auth.h>
76 #include <sys/random.h>
79 #include "cryptodev_if.h"
81 #include <dev/pci/pcivar.h>
82 #include <dev/pci/pcireg.h>
85 #include <dev/rndtest/rndtest.h>
87 #include <dev/hifn/hifn7751reg.h>
88 #include <dev/hifn/hifn7751var.h>
94 static struct cdevsw vulcanpk_cdevsw; /* forward declaration */
98 * Prototypes and count for the pci_device structure
100 static int hifn_probe(device_t);
101 static int hifn_attach(device_t);
102 static int hifn_detach(device_t);
103 static int hifn_suspend(device_t);
104 static int hifn_resume(device_t);
105 static int hifn_shutdown(device_t);
107 static int hifn_probesession(device_t, const struct crypto_session_params *);
108 static int hifn_newsession(device_t, crypto_session_t,
109 const struct crypto_session_params *);
110 static int hifn_process(device_t, struct cryptop *, int);
112 static device_method_t hifn_methods[] = {
113 /* Device interface */
114 DEVMETHOD(device_probe, hifn_probe),
115 DEVMETHOD(device_attach, hifn_attach),
116 DEVMETHOD(device_detach, hifn_detach),
117 DEVMETHOD(device_suspend, hifn_suspend),
118 DEVMETHOD(device_resume, hifn_resume),
119 DEVMETHOD(device_shutdown, hifn_shutdown),
121 /* crypto device methods */
122 DEVMETHOD(cryptodev_probesession, hifn_probesession),
123 DEVMETHOD(cryptodev_newsession, hifn_newsession),
124 DEVMETHOD(cryptodev_process, hifn_process),
128 static driver_t hifn_driver = {
131 sizeof (struct hifn_softc)
133 static devclass_t hifn_devclass;
135 DRIVER_MODULE(hifn, pci, hifn_driver, hifn_devclass, 0, 0);
136 MODULE_DEPEND(hifn, crypto, 1, 1, 1);
138 MODULE_DEPEND(hifn, rndtest, 1, 1, 1);
141 static void hifn_reset_board(struct hifn_softc *, int);
142 static void hifn_reset_puc(struct hifn_softc *);
143 static void hifn_puc_wait(struct hifn_softc *);
144 static int hifn_enable_crypto(struct hifn_softc *);
145 static void hifn_set_retry(struct hifn_softc *sc);
146 static void hifn_init_dma(struct hifn_softc *);
147 static void hifn_init_pci_registers(struct hifn_softc *);
148 static int hifn_sramsize(struct hifn_softc *);
149 static int hifn_dramsize(struct hifn_softc *);
150 static int hifn_ramtype(struct hifn_softc *);
151 static void hifn_sessions(struct hifn_softc *);
152 static void hifn_intr(void *);
153 static u_int hifn_write_command(struct hifn_command *, u_int8_t *);
154 static u_int32_t hifn_next_signature(u_int32_t a, u_int cnt);
155 static void hifn_callback(struct hifn_softc *, struct hifn_command *, u_int8_t *);
156 static int hifn_crypto(struct hifn_softc *, struct hifn_command *, struct cryptop *, int);
157 static int hifn_readramaddr(struct hifn_softc *, int, u_int8_t *);
158 static int hifn_writeramaddr(struct hifn_softc *, int, u_int8_t *);
159 static int hifn_dmamap_load_src(struct hifn_softc *, struct hifn_command *);
160 static int hifn_dmamap_load_dst(struct hifn_softc *, struct hifn_command *);
161 static int hifn_init_pubrng(struct hifn_softc *);
162 static void hifn_rng(void *);
163 static void hifn_tick(void *);
164 static void hifn_abort(struct hifn_softc *);
165 static void hifn_alloc_slot(struct hifn_softc *, int *, int *, int *, int *);
167 static void hifn_write_reg_0(struct hifn_softc *, bus_size_t, u_int32_t);
168 static void hifn_write_reg_1(struct hifn_softc *, bus_size_t, u_int32_t);
170 static __inline u_int32_t
171 READ_REG_0(struct hifn_softc *sc, bus_size_t reg)
173 u_int32_t v = bus_space_read_4(sc->sc_st0, sc->sc_sh0, reg);
174 sc->sc_bar0_lastreg = (bus_size_t) -1;
177 #define WRITE_REG_0(sc, reg, val) hifn_write_reg_0(sc, reg, val)
179 static __inline u_int32_t
180 READ_REG_1(struct hifn_softc *sc, bus_size_t reg)
182 u_int32_t v = bus_space_read_4(sc->sc_st1, sc->sc_sh1, reg);
183 sc->sc_bar1_lastreg = (bus_size_t) -1;
186 #define WRITE_REG_1(sc, reg, val) hifn_write_reg_1(sc, reg, val)
188 static SYSCTL_NODE(_hw, OID_AUTO, hifn, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
189 "Hifn driver parameters");
192 static int hifn_debug = 0;
193 SYSCTL_INT(_hw_hifn, OID_AUTO, debug, CTLFLAG_RW, &hifn_debug,
194 0, "control debugging msgs");
197 static struct hifn_stats hifnstats;
198 SYSCTL_STRUCT(_hw_hifn, OID_AUTO, stats, CTLFLAG_RD, &hifnstats,
199 hifn_stats, "driver statistics");
200 static int hifn_maxbatch = 1;
201 SYSCTL_INT(_hw_hifn, OID_AUTO, maxbatch, CTLFLAG_RW, &hifn_maxbatch,
202 0, "max ops to batch w/o interrupt");
205 * Probe for a supported device. The PCI vendor and device
206 * IDs are used to detect devices we know how to handle.
209 hifn_probe(device_t dev)
211 if (pci_get_vendor(dev) == PCI_VENDOR_INVERTEX &&
212 pci_get_device(dev) == PCI_PRODUCT_INVERTEX_AEON)
213 return (BUS_PROBE_DEFAULT);
214 if (pci_get_vendor(dev) == PCI_VENDOR_HIFN &&
215 (pci_get_device(dev) == PCI_PRODUCT_HIFN_7751 ||
216 pci_get_device(dev) == PCI_PRODUCT_HIFN_7951 ||
217 pci_get_device(dev) == PCI_PRODUCT_HIFN_7955 ||
218 pci_get_device(dev) == PCI_PRODUCT_HIFN_7956 ||
219 pci_get_device(dev) == PCI_PRODUCT_HIFN_7811))
220 return (BUS_PROBE_DEFAULT);
221 if (pci_get_vendor(dev) == PCI_VENDOR_NETSEC &&
222 pci_get_device(dev) == PCI_PRODUCT_NETSEC_7751)
223 return (BUS_PROBE_DEFAULT);
228 hifn_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
230 bus_addr_t *paddr = (bus_addr_t*) arg;
231 *paddr = segs->ds_addr;
235 hifn_partname(struct hifn_softc *sc)
237 /* XXX sprintf numbers when not decoded */
238 switch (pci_get_vendor(sc->sc_dev)) {
239 case PCI_VENDOR_HIFN:
240 switch (pci_get_device(sc->sc_dev)) {
241 case PCI_PRODUCT_HIFN_6500: return "Hifn 6500";
242 case PCI_PRODUCT_HIFN_7751: return "Hifn 7751";
243 case PCI_PRODUCT_HIFN_7811: return "Hifn 7811";
244 case PCI_PRODUCT_HIFN_7951: return "Hifn 7951";
245 case PCI_PRODUCT_HIFN_7955: return "Hifn 7955";
246 case PCI_PRODUCT_HIFN_7956: return "Hifn 7956";
248 return "Hifn unknown-part";
249 case PCI_VENDOR_INVERTEX:
250 switch (pci_get_device(sc->sc_dev)) {
251 case PCI_PRODUCT_INVERTEX_AEON: return "Invertex AEON";
253 return "Invertex unknown-part";
254 case PCI_VENDOR_NETSEC:
255 switch (pci_get_device(sc->sc_dev)) {
256 case PCI_PRODUCT_NETSEC_7751: return "NetSec 7751";
258 return "NetSec unknown-part";
260 return "Unknown-vendor unknown-part";
264 default_harvest(struct rndtest_state *rsp, void *buf, u_int count)
266 /* MarkM: FIX!! Check that this does not swamp the harvester! */
267 random_harvest_queue(buf, count, RANDOM_PURE_HIFN);
271 checkmaxmin(device_t dev, const char *what, u_int v, u_int min, u_int max)
274 device_printf(dev, "Warning, %s %u out of range, "
275 "using max %u\n", what, v, max);
277 } else if (v < min) {
278 device_printf(dev, "Warning, %s %u out of range, "
279 "using min %u\n", what, v, min);
286 * Select PLL configuration for 795x parts. This is complicated in
287 * that we cannot determine the optimal parameters without user input.
288 * The reference clock is derived from an external clock through a
289 * multiplier. The external clock is either the host bus (i.e. PCI)
290 * or an external clock generator. When using the PCI bus we assume
291 * the clock is either 33 or 66 MHz; for an external source we cannot
294 * PLL configuration is done with a string: "pci" for PCI bus, or "ext"
295 * for an external source, followed by the frequency. We calculate
296 * the appropriate multiplier and PLL register contents accordingly.
297 * When no configuration is given we default to "pci66" since that
298 * always will allow the card to work. If a card is using the PCI
299 * bus clock and in a 33MHz slot then it will be operating at half
300 * speed until the correct information is provided.
302 * We use a default setting of "ext66" because according to Mike Ham
303 * of HiFn, almost every board in existence has an external crystal
304 * populated at 66Mhz. Using PCI can be a problem on modern motherboards,
305 * because PCI33 can have clocks from 0 to 33Mhz, and some have
306 * non-PCI-compliant spread-spectrum clocks, which can confuse the pll.
309 hifn_getpllconfig(device_t dev, u_int *pll)
312 u_int freq, mul, fl, fh;
316 if (resource_string_value("hifn", device_get_unit(dev),
317 "pllconfig", &pllspec))
321 if (strncmp(pllspec, "ext", 3) == 0) {
323 pllconfig |= HIFN_PLL_REF_SEL;
324 switch (pci_get_device(dev)) {
325 case PCI_PRODUCT_HIFN_7955:
326 case PCI_PRODUCT_HIFN_7956:
330 case PCI_PRODUCT_HIFN_7954:
335 } else if (strncmp(pllspec, "pci", 3) == 0)
337 freq = strtoul(pllspec, &nxt, 10);
341 freq = checkmaxmin(dev, "frequency", freq, fl, fh);
343 * Calculate multiplier. We target a Fck of 266 MHz,
344 * allowing only even values, possibly rounded down.
345 * Multipliers > 8 must set the charge pump current.
347 mul = checkmaxmin(dev, "PLL divisor", (266 / freq) &~ 1, 2, 12);
348 pllconfig |= (mul / 2 - 1) << HIFN_PLL_ND_SHIFT;
350 pllconfig |= HIFN_PLL_IS;
355 * Attach an interface that successfully probed.
358 hifn_attach(device_t dev)
360 struct hifn_softc *sc = device_get_softc(dev);
368 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), "hifn driver", MTX_DEF);
370 /* XXX handle power management */
373 * The 7951 and 795x have a random number generator and
374 * public key support; note this.
376 if (pci_get_vendor(dev) == PCI_VENDOR_HIFN &&
377 (pci_get_device(dev) == PCI_PRODUCT_HIFN_7951 ||
378 pci_get_device(dev) == PCI_PRODUCT_HIFN_7955 ||
379 pci_get_device(dev) == PCI_PRODUCT_HIFN_7956))
380 sc->sc_flags = HIFN_HAS_RNG | HIFN_HAS_PUBLIC;
382 * The 7811 has a random number generator and
383 * we also note it's identity 'cuz of some quirks.
385 if (pci_get_vendor(dev) == PCI_VENDOR_HIFN &&
386 pci_get_device(dev) == PCI_PRODUCT_HIFN_7811)
387 sc->sc_flags |= HIFN_IS_7811 | HIFN_HAS_RNG;
390 * The 795x parts support AES.
392 if (pci_get_vendor(dev) == PCI_VENDOR_HIFN &&
393 (pci_get_device(dev) == PCI_PRODUCT_HIFN_7955 ||
394 pci_get_device(dev) == PCI_PRODUCT_HIFN_7956)) {
395 sc->sc_flags |= HIFN_IS_7956 | HIFN_HAS_AES;
397 * Select PLL configuration. This depends on the
398 * bus and board design and must be manually configured
399 * if the default setting is unacceptable.
401 hifn_getpllconfig(dev, &sc->sc_pllconfig);
405 * Setup PCI resources. Note that we record the bus
406 * tag and handle for each register mapping, this is
407 * used by the READ_REG_0, WRITE_REG_0, READ_REG_1,
408 * and WRITE_REG_1 macros throughout the driver.
410 pci_enable_busmaster(dev);
413 sc->sc_bar0res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
415 if (sc->sc_bar0res == NULL) {
416 device_printf(dev, "cannot map bar%d register space\n", 0);
419 sc->sc_st0 = rman_get_bustag(sc->sc_bar0res);
420 sc->sc_sh0 = rman_get_bushandle(sc->sc_bar0res);
421 sc->sc_bar0_lastreg = (bus_size_t) -1;
424 sc->sc_bar1res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
426 if (sc->sc_bar1res == NULL) {
427 device_printf(dev, "cannot map bar%d register space\n", 1);
430 sc->sc_st1 = rman_get_bustag(sc->sc_bar1res);
431 sc->sc_sh1 = rman_get_bushandle(sc->sc_bar1res);
432 sc->sc_bar1_lastreg = (bus_size_t) -1;
437 * Setup the area where the Hifn DMA's descriptors
438 * and associated data structures.
440 if (bus_dma_tag_create(bus_get_dma_tag(dev), /* PCI parent */
441 1, 0, /* alignment,boundary */
442 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
443 BUS_SPACE_MAXADDR, /* highaddr */
444 NULL, NULL, /* filter, filterarg */
445 HIFN_MAX_DMALEN, /* maxsize */
446 MAX_SCATTER, /* nsegments */
447 HIFN_MAX_SEGLEN, /* maxsegsize */
448 BUS_DMA_ALLOCNOW, /* flags */
452 device_printf(dev, "cannot allocate DMA tag\n");
455 if (bus_dmamap_create(sc->sc_dmat, BUS_DMA_NOWAIT, &sc->sc_dmamap)) {
456 device_printf(dev, "cannot create dma map\n");
457 bus_dma_tag_destroy(sc->sc_dmat);
460 if (bus_dmamem_alloc(sc->sc_dmat, (void**) &kva, BUS_DMA_NOWAIT, &sc->sc_dmamap)) {
461 device_printf(dev, "cannot alloc dma buffer\n");
462 bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmamap);
463 bus_dma_tag_destroy(sc->sc_dmat);
466 if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmamap, kva,
467 sizeof (*sc->sc_dma),
468 hifn_dmamap_cb, &sc->sc_dma_physaddr,
470 device_printf(dev, "cannot load dma map\n");
471 bus_dmamem_free(sc->sc_dmat, kva, sc->sc_dmamap);
472 bus_dma_tag_destroy(sc->sc_dmat);
475 sc->sc_dma = (struct hifn_dma *)kva;
476 bzero(sc->sc_dma, sizeof(*sc->sc_dma));
478 KASSERT(sc->sc_st0 != 0, ("hifn_attach: null bar0 tag!"));
479 KASSERT(sc->sc_sh0 != 0, ("hifn_attach: null bar0 handle!"));
480 KASSERT(sc->sc_st1 != 0, ("hifn_attach: null bar1 tag!"));
481 KASSERT(sc->sc_sh1 != 0, ("hifn_attach: null bar1 handle!"));
484 * Reset the board and do the ``secret handshake''
485 * to enable the crypto support. Then complete the
486 * initialization procedure by setting up the interrupt
487 * and hooking in to the system crypto support so we'll
488 * get used for system services like the crypto device,
489 * IPsec, RNG device, etc.
491 hifn_reset_board(sc, 0);
493 if (hifn_enable_crypto(sc) != 0) {
494 device_printf(dev, "crypto enabling failed\n");
500 hifn_init_pci_registers(sc);
502 /* XXX can't dynamically determine ram type for 795x; force dram */
503 if (sc->sc_flags & HIFN_IS_7956)
504 sc->sc_drammodel = 1;
505 else if (hifn_ramtype(sc))
508 if (sc->sc_drammodel == 0)
514 * Workaround for NetSec 7751 rev A: half ram size because two
515 * of the address lines were left floating
517 if (pci_get_vendor(dev) == PCI_VENDOR_NETSEC &&
518 pci_get_device(dev) == PCI_PRODUCT_NETSEC_7751 &&
519 pci_get_revid(dev) == 0x61) /*XXX???*/
520 sc->sc_ramsize >>= 1;
523 * Arrange the interrupt line.
526 sc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
527 RF_SHAREABLE|RF_ACTIVE);
528 if (sc->sc_irq == NULL) {
529 device_printf(dev, "could not map interrupt\n");
533 * NB: Network code assumes we are blocked with splimp()
534 * so make sure the IRQ is marked appropriately.
536 if (bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_NET | INTR_MPSAFE,
537 NULL, hifn_intr, sc, &sc->sc_intrhand)) {
538 device_printf(dev, "could not setup interrupt\n");
545 * NB: Keep only the low 16 bits; this masks the chip id
548 rev = READ_REG_1(sc, HIFN_1_REVID) & 0xffff;
550 rseg = sc->sc_ramsize / 1024;
552 if (sc->sc_ramsize >= (1024 * 1024)) {
556 device_printf(sc->sc_dev, "%s, rev %u, %d%cB %cram",
557 hifn_partname(sc), rev,
558 rseg, rbase, sc->sc_drammodel ? 'd' : 's');
559 if (sc->sc_flags & HIFN_IS_7956)
560 printf(", pll=0x%x<%s clk, %ux mult>",
562 sc->sc_pllconfig & HIFN_PLL_REF_SEL ? "ext" : "pci",
563 2 + 2*((sc->sc_pllconfig & HIFN_PLL_ND) >> 11));
566 WRITE_REG_0(sc, HIFN_0_PUCNFG,
567 READ_REG_0(sc, HIFN_0_PUCNFG) | HIFN_PUCNFG_CHIPID);
568 sc->sc_ena = READ_REG_0(sc, HIFN_0_PUSTAT) & HIFN_PUSTAT_CHIPENA;
570 switch (sc->sc_ena) {
571 case HIFN_PUSTAT_ENA_2:
572 case HIFN_PUSTAT_ENA_1:
573 sc->sc_cid = crypto_get_driverid(dev,
574 sizeof(struct hifn_session), CRYPTOCAP_F_HARDWARE);
575 if (sc->sc_cid < 0) {
576 device_printf(dev, "could not get crypto driver id\n");
582 bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
583 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
585 if (sc->sc_flags & (HIFN_HAS_PUBLIC | HIFN_HAS_RNG))
586 hifn_init_pubrng(sc);
588 callout_init(&sc->sc_tickto, 1);
589 callout_reset(&sc->sc_tickto, hz, hifn_tick, sc);
594 bus_teardown_intr(dev, sc->sc_irq, sc->sc_intrhand);
596 /* XXX don't store rid */
597 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq);
599 bus_dmamap_unload(sc->sc_dmat, sc->sc_dmamap);
600 bus_dmamem_free(sc->sc_dmat, sc->sc_dma, sc->sc_dmamap);
601 bus_dma_tag_destroy(sc->sc_dmat);
603 /* Turn off DMA polling */
604 WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
605 HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
607 bus_release_resource(dev, SYS_RES_MEMORY, HIFN_BAR1, sc->sc_bar1res);
609 bus_release_resource(dev, SYS_RES_MEMORY, HIFN_BAR0, sc->sc_bar0res);
611 mtx_destroy(&sc->sc_mtx);
616 * Detach an interface that successfully probed.
619 hifn_detach(device_t dev)
621 struct hifn_softc *sc = device_get_softc(dev);
623 KASSERT(sc != NULL, ("hifn_detach: null software carrier!"));
625 /* disable interrupts */
626 WRITE_REG_1(sc, HIFN_1_DMA_IER, 0);
628 /*XXX other resources */
629 callout_stop(&sc->sc_tickto);
630 callout_stop(&sc->sc_rngto);
633 rndtest_detach(sc->sc_rndtest);
636 /* Turn off DMA polling */
637 WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
638 HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
640 crypto_unregister_all(sc->sc_cid);
642 bus_generic_detach(dev); /*XXX should be no children, right? */
644 bus_teardown_intr(dev, sc->sc_irq, sc->sc_intrhand);
645 /* XXX don't store rid */
646 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq);
648 bus_dmamap_unload(sc->sc_dmat, sc->sc_dmamap);
649 bus_dmamem_free(sc->sc_dmat, sc->sc_dma, sc->sc_dmamap);
650 bus_dma_tag_destroy(sc->sc_dmat);
652 bus_release_resource(dev, SYS_RES_MEMORY, HIFN_BAR1, sc->sc_bar1res);
653 bus_release_resource(dev, SYS_RES_MEMORY, HIFN_BAR0, sc->sc_bar0res);
655 mtx_destroy(&sc->sc_mtx);
661 * Stop all chip I/O so that the kernel's probe routines don't
662 * get confused by errant DMAs when rebooting.
665 hifn_shutdown(device_t dev)
668 hifn_stop(device_get_softc(dev));
674 * Device suspend routine. Stop the interface and save some PCI
675 * settings in case the BIOS doesn't restore them properly on
679 hifn_suspend(device_t dev)
681 struct hifn_softc *sc = device_get_softc(dev);
685 sc->sc_suspended = 1;
691 * Device resume routine. Restore some PCI settings in case the BIOS
692 * doesn't, re-enable busmastering, and restart the interface if
696 hifn_resume(device_t dev)
698 struct hifn_softc *sc = device_get_softc(dev);
700 /* reinitialize interface if necessary */
701 if (ifp->if_flags & IFF_UP)
704 sc->sc_suspended = 0;
710 hifn_init_pubrng(struct hifn_softc *sc)
716 sc->sc_rndtest = rndtest_attach(sc->sc_dev);
718 sc->sc_harvest = rndtest_harvest;
720 sc->sc_harvest = default_harvest;
722 sc->sc_harvest = default_harvest;
724 if ((sc->sc_flags & HIFN_IS_7811) == 0) {
725 /* Reset 7951 public key/rng engine */
726 WRITE_REG_1(sc, HIFN_1_PUB_RESET,
727 READ_REG_1(sc, HIFN_1_PUB_RESET) | HIFN_PUBRST_RESET);
729 for (i = 0; i < 100; i++) {
731 if ((READ_REG_1(sc, HIFN_1_PUB_RESET) &
732 HIFN_PUBRST_RESET) == 0)
737 device_printf(sc->sc_dev, "public key init failed\n");
742 /* Enable the rng, if available */
743 if (sc->sc_flags & HIFN_HAS_RNG) {
744 if (sc->sc_flags & HIFN_IS_7811) {
745 r = READ_REG_1(sc, HIFN_1_7811_RNGENA);
746 if (r & HIFN_7811_RNGENA_ENA) {
747 r &= ~HIFN_7811_RNGENA_ENA;
748 WRITE_REG_1(sc, HIFN_1_7811_RNGENA, r);
750 WRITE_REG_1(sc, HIFN_1_7811_RNGCFG,
751 HIFN_7811_RNGCFG_DEFL);
752 r |= HIFN_7811_RNGENA_ENA;
753 WRITE_REG_1(sc, HIFN_1_7811_RNGENA, r);
755 WRITE_REG_1(sc, HIFN_1_RNG_CONFIG,
756 READ_REG_1(sc, HIFN_1_RNG_CONFIG) |
761 sc->sc_rnghz = hz / 100;
764 callout_init(&sc->sc_rngto, 1);
765 callout_reset(&sc->sc_rngto, sc->sc_rnghz, hifn_rng, sc);
768 /* Enable public key engine, if available */
769 if (sc->sc_flags & HIFN_HAS_PUBLIC) {
770 WRITE_REG_1(sc, HIFN_1_PUB_IEN, HIFN_PUBIEN_DONE);
771 sc->sc_dmaier |= HIFN_DMAIER_PUBDONE;
772 WRITE_REG_1(sc, HIFN_1_DMA_IER, sc->sc_dmaier);
773 #ifdef HIFN_VULCANDEV
774 sc->sc_pkdev = make_dev(&vulcanpk_cdevsw, 0,
775 UID_ROOT, GID_WHEEL, 0666,
777 sc->sc_pkdev->si_drv1 = sc;
787 #define RANDOM_BITS(n) (n)*sizeof (u_int32_t), (n)*sizeof (u_int32_t)*NBBY, 0
788 struct hifn_softc *sc = vsc;
789 u_int32_t sts, num[2];
792 if (sc->sc_flags & HIFN_IS_7811) {
793 /* ONLY VALID ON 7811!!!! */
794 for (i = 0; i < 5; i++) {
795 sts = READ_REG_1(sc, HIFN_1_7811_RNGSTS);
796 if (sts & HIFN_7811_RNGSTS_UFL) {
797 device_printf(sc->sc_dev,
798 "RNG underflow: disabling\n");
801 if ((sts & HIFN_7811_RNGSTS_RDY) == 0)
805 * There are at least two words in the RNG FIFO
808 num[0] = READ_REG_1(sc, HIFN_1_7811_RNGDAT);
809 num[1] = READ_REG_1(sc, HIFN_1_7811_RNGDAT);
810 /* NB: discard first data read */
814 (*sc->sc_harvest)(sc->sc_rndtest,
818 num[0] = READ_REG_1(sc, HIFN_1_RNG_DATA);
820 /* NB: discard first data read */
824 (*sc->sc_harvest)(sc->sc_rndtest,
825 num, sizeof (num[0]));
828 callout_reset(&sc->sc_rngto, sc->sc_rnghz, hifn_rng, sc);
833 hifn_puc_wait(struct hifn_softc *sc)
836 int reg = HIFN_0_PUCTRL;
838 if (sc->sc_flags & HIFN_IS_7956) {
839 reg = HIFN_0_PUCTRL2;
842 for (i = 5000; i > 0; i--) {
844 if (!(READ_REG_0(sc, reg) & HIFN_PUCTRL_RESET))
848 device_printf(sc->sc_dev, "proc unit did not reset\n");
852 * Reset the processing unit.
855 hifn_reset_puc(struct hifn_softc *sc)
857 /* Reset processing unit */
858 int reg = HIFN_0_PUCTRL;
860 if (sc->sc_flags & HIFN_IS_7956) {
861 reg = HIFN_0_PUCTRL2;
863 WRITE_REG_0(sc, reg, HIFN_PUCTRL_DMAENA);
869 * Set the Retry and TRDY registers; note that we set them to
870 * zero because the 7811 locks up when forced to retry (section
871 * 3.6 of "Specification Update SU-0014-04". Not clear if we
872 * should do this for all Hifn parts, but it doesn't seem to hurt.
875 hifn_set_retry(struct hifn_softc *sc)
877 /* NB: RETRY only responds to 8-bit reads/writes */
878 pci_write_config(sc->sc_dev, HIFN_RETRY_TIMEOUT, 0, 1);
879 pci_write_config(sc->sc_dev, HIFN_TRDY_TIMEOUT, 0, 1);
883 * Resets the board. Values in the regesters are left as is
884 * from the reset (i.e. initial values are assigned elsewhere).
887 hifn_reset_board(struct hifn_softc *sc, int full)
892 * Set polling in the DMA configuration register to zero. 0x7 avoids
893 * resetting the board and zeros out the other fields.
895 WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
896 HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
899 * Now that polling has been disabled, we have to wait 1 ms
900 * before resetting the board.
904 /* Reset the DMA unit */
906 WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MODE);
909 WRITE_REG_1(sc, HIFN_1_DMA_CNFG,
910 HIFN_DMACNFG_MODE | HIFN_DMACNFG_MSTRESET);
914 KASSERT(sc->sc_dma != NULL, ("hifn_reset_board: null DMA tag!"));
915 bzero(sc->sc_dma, sizeof(*sc->sc_dma));
917 /* Bring dma unit out of reset */
918 WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
919 HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
924 if (sc->sc_flags & HIFN_IS_7811) {
925 for (reg = 0; reg < 1000; reg++) {
926 if (READ_REG_1(sc, HIFN_1_7811_MIPSRST) &
927 HIFN_MIPSRST_CRAMINIT)
932 printf(": cram init timeout\n");
934 /* set up DMA configuration register #2 */
935 /* turn off all PK and BAR0 swaps */
936 WRITE_REG_1(sc, HIFN_1_DMA_CNFG2,
937 (3 << HIFN_DMACNFG2_INIT_WRITE_BURST_SHIFT)|
938 (3 << HIFN_DMACNFG2_INIT_READ_BURST_SHIFT)|
939 (2 << HIFN_DMACNFG2_TGT_WRITE_BURST_SHIFT)|
940 (2 << HIFN_DMACNFG2_TGT_READ_BURST_SHIFT));
946 hifn_next_signature(u_int32_t a, u_int cnt)
951 for (i = 0; i < cnt; i++) {
961 a = (v & 1) ^ (a << 1);
972 static struct pci2id pci2id[] = {
975 PCI_PRODUCT_HIFN_7951,
976 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
977 0x00, 0x00, 0x00, 0x00, 0x00 }
980 PCI_PRODUCT_HIFN_7955,
981 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
982 0x00, 0x00, 0x00, 0x00, 0x00 }
985 PCI_PRODUCT_HIFN_7956,
986 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
987 0x00, 0x00, 0x00, 0x00, 0x00 }
990 PCI_PRODUCT_NETSEC_7751,
991 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
992 0x00, 0x00, 0x00, 0x00, 0x00 }
995 PCI_PRODUCT_INVERTEX_AEON,
996 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
997 0x00, 0x00, 0x00, 0x00, 0x00 }
1000 PCI_PRODUCT_HIFN_7811,
1001 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1002 0x00, 0x00, 0x00, 0x00, 0x00 }
1005 * Other vendors share this PCI ID as well, such as
1006 * http://www.powercrypt.com, and obviously they also
1010 PCI_PRODUCT_HIFN_7751,
1011 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1012 0x00, 0x00, 0x00, 0x00, 0x00 }
1017 * Checks to see if crypto is already enabled. If crypto isn't enable,
1018 * "hifn_enable_crypto" is called to enable it. The check is important,
1019 * as enabling crypto twice will lock the board.
1022 hifn_enable_crypto(struct hifn_softc *sc)
1024 u_int32_t dmacfg, ramcfg, encl, addr, i;
1025 char *offtbl = NULL;
1027 for (i = 0; i < nitems(pci2id); i++) {
1028 if (pci2id[i].pci_vendor == pci_get_vendor(sc->sc_dev) &&
1029 pci2id[i].pci_prod == pci_get_device(sc->sc_dev)) {
1030 offtbl = pci2id[i].card_id;
1034 if (offtbl == NULL) {
1035 device_printf(sc->sc_dev, "Unknown card!\n");
1039 ramcfg = READ_REG_0(sc, HIFN_0_PUCNFG);
1040 dmacfg = READ_REG_1(sc, HIFN_1_DMA_CNFG);
1043 * The RAM config register's encrypt level bit needs to be set before
1044 * every read performed on the encryption level register.
1046 WRITE_REG_0(sc, HIFN_0_PUCNFG, ramcfg | HIFN_PUCNFG_CHIPID);
1048 encl = READ_REG_0(sc, HIFN_0_PUSTAT) & HIFN_PUSTAT_CHIPENA;
1051 * Make sure we don't re-unlock. Two unlocks kills chip until the
1054 if (encl == HIFN_PUSTAT_ENA_1 || encl == HIFN_PUSTAT_ENA_2) {
1057 device_printf(sc->sc_dev,
1058 "Strong crypto already enabled!\n");
1063 if (encl != 0 && encl != HIFN_PUSTAT_ENA_0) {
1066 device_printf(sc->sc_dev,
1067 "Unknown encryption level 0x%x\n", encl);
1072 WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_UNLOCK |
1073 HIFN_DMACNFG_MSTRESET | HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
1075 addr = READ_REG_1(sc, HIFN_UNLOCK_SECRET1);
1077 WRITE_REG_1(sc, HIFN_UNLOCK_SECRET2, 0);
1080 for (i = 0; i <= 12; i++) {
1081 addr = hifn_next_signature(addr, offtbl[i] + 0x101);
1082 WRITE_REG_1(sc, HIFN_UNLOCK_SECRET2, addr);
1087 WRITE_REG_0(sc, HIFN_0_PUCNFG, ramcfg | HIFN_PUCNFG_CHIPID);
1088 encl = READ_REG_0(sc, HIFN_0_PUSTAT) & HIFN_PUSTAT_CHIPENA;
1092 if (encl != HIFN_PUSTAT_ENA_1 && encl != HIFN_PUSTAT_ENA_2)
1093 device_printf(sc->sc_dev, "Engine is permanently "
1094 "locked until next system reset!\n");
1096 device_printf(sc->sc_dev, "Engine enabled "
1102 WRITE_REG_0(sc, HIFN_0_PUCNFG, ramcfg);
1103 WRITE_REG_1(sc, HIFN_1_DMA_CNFG, dmacfg);
1106 case HIFN_PUSTAT_ENA_1:
1107 case HIFN_PUSTAT_ENA_2:
1109 case HIFN_PUSTAT_ENA_0:
1111 device_printf(sc->sc_dev, "disabled");
1119 * Give initial values to the registers listed in the "Register Space"
1120 * section of the HIFN Software Development reference manual.
1123 hifn_init_pci_registers(struct hifn_softc *sc)
1125 /* write fixed values needed by the Initialization registers */
1126 WRITE_REG_0(sc, HIFN_0_PUCTRL, HIFN_PUCTRL_DMAENA);
1127 WRITE_REG_0(sc, HIFN_0_FIFOCNFG, HIFN_FIFOCNFG_THRESHOLD);
1128 WRITE_REG_0(sc, HIFN_0_PUIER, HIFN_PUIER_DSTOVER);
1130 /* write all 4 ring address registers */
1131 WRITE_REG_1(sc, HIFN_1_DMA_CRAR, sc->sc_dma_physaddr +
1132 offsetof(struct hifn_dma, cmdr[0]));
1133 WRITE_REG_1(sc, HIFN_1_DMA_SRAR, sc->sc_dma_physaddr +
1134 offsetof(struct hifn_dma, srcr[0]));
1135 WRITE_REG_1(sc, HIFN_1_DMA_DRAR, sc->sc_dma_physaddr +
1136 offsetof(struct hifn_dma, dstr[0]));
1137 WRITE_REG_1(sc, HIFN_1_DMA_RRAR, sc->sc_dma_physaddr +
1138 offsetof(struct hifn_dma, resr[0]));
1142 /* write status register */
1143 WRITE_REG_1(sc, HIFN_1_DMA_CSR,
1144 HIFN_DMACSR_D_CTRL_DIS | HIFN_DMACSR_R_CTRL_DIS |
1145 HIFN_DMACSR_S_CTRL_DIS | HIFN_DMACSR_C_CTRL_DIS |
1146 HIFN_DMACSR_D_ABORT | HIFN_DMACSR_D_DONE | HIFN_DMACSR_D_LAST |
1147 HIFN_DMACSR_D_WAIT | HIFN_DMACSR_D_OVER |
1148 HIFN_DMACSR_R_ABORT | HIFN_DMACSR_R_DONE | HIFN_DMACSR_R_LAST |
1149 HIFN_DMACSR_R_WAIT | HIFN_DMACSR_R_OVER |
1150 HIFN_DMACSR_S_ABORT | HIFN_DMACSR_S_DONE | HIFN_DMACSR_S_LAST |
1151 HIFN_DMACSR_S_WAIT |
1152 HIFN_DMACSR_C_ABORT | HIFN_DMACSR_C_DONE | HIFN_DMACSR_C_LAST |
1153 HIFN_DMACSR_C_WAIT |
1154 HIFN_DMACSR_ENGINE |
1155 ((sc->sc_flags & HIFN_HAS_PUBLIC) ?
1156 HIFN_DMACSR_PUBDONE : 0) |
1157 ((sc->sc_flags & HIFN_IS_7811) ?
1158 HIFN_DMACSR_ILLW | HIFN_DMACSR_ILLR : 0));
1160 sc->sc_d_busy = sc->sc_r_busy = sc->sc_s_busy = sc->sc_c_busy = 0;
1161 sc->sc_dmaier |= HIFN_DMAIER_R_DONE | HIFN_DMAIER_C_ABORT |
1162 HIFN_DMAIER_D_OVER | HIFN_DMAIER_R_OVER |
1163 HIFN_DMAIER_S_ABORT | HIFN_DMAIER_D_ABORT | HIFN_DMAIER_R_ABORT |
1164 ((sc->sc_flags & HIFN_IS_7811) ?
1165 HIFN_DMAIER_ILLW | HIFN_DMAIER_ILLR : 0);
1166 sc->sc_dmaier &= ~HIFN_DMAIER_C_WAIT;
1167 WRITE_REG_1(sc, HIFN_1_DMA_IER, sc->sc_dmaier);
1170 if (sc->sc_flags & HIFN_IS_7956) {
1173 WRITE_REG_0(sc, HIFN_0_PUCNFG, HIFN_PUCNFG_COMPSING |
1174 HIFN_PUCNFG_TCALLPHASES |
1175 HIFN_PUCNFG_TCDRVTOTEM | HIFN_PUCNFG_BUS32);
1177 /* turn off the clocks and insure bypass is set */
1178 pll = READ_REG_1(sc, HIFN_1_PLL);
1179 pll = (pll &~ (HIFN_PLL_PK_CLK_SEL | HIFN_PLL_PE_CLK_SEL))
1180 | HIFN_PLL_BP | HIFN_PLL_MBSET;
1181 WRITE_REG_1(sc, HIFN_1_PLL, pll);
1182 DELAY(10*1000); /* 10ms */
1184 /* change configuration */
1185 pll = (pll &~ HIFN_PLL_CONFIG) | sc->sc_pllconfig;
1186 WRITE_REG_1(sc, HIFN_1_PLL, pll);
1187 DELAY(10*1000); /* 10ms */
1189 /* disable bypass */
1190 pll &= ~HIFN_PLL_BP;
1191 WRITE_REG_1(sc, HIFN_1_PLL, pll);
1192 /* enable clocks with new configuration */
1193 pll |= HIFN_PLL_PK_CLK_SEL | HIFN_PLL_PE_CLK_SEL;
1194 WRITE_REG_1(sc, HIFN_1_PLL, pll);
1196 WRITE_REG_0(sc, HIFN_0_PUCNFG, HIFN_PUCNFG_COMPSING |
1197 HIFN_PUCNFG_DRFR_128 | HIFN_PUCNFG_TCALLPHASES |
1198 HIFN_PUCNFG_TCDRVTOTEM | HIFN_PUCNFG_BUS32 |
1199 (sc->sc_drammodel ? HIFN_PUCNFG_DRAM : HIFN_PUCNFG_SRAM));
1202 WRITE_REG_0(sc, HIFN_0_PUISR, HIFN_PUISR_DSTOVER);
1203 WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
1204 HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE | HIFN_DMACNFG_LAST |
1205 ((HIFN_POLL_FREQUENCY << 16 ) & HIFN_DMACNFG_POLLFREQ) |
1206 ((HIFN_POLL_SCALAR << 8) & HIFN_DMACNFG_POLLINVAL));
1210 * The maximum number of sessions supported by the card
1211 * is dependent on the amount of context ram, which
1212 * encryption algorithms are enabled, and how compression
1213 * is configured. This should be configured before this
1214 * routine is called.
1217 hifn_sessions(struct hifn_softc *sc)
1222 pucnfg = READ_REG_0(sc, HIFN_0_PUCNFG);
1224 if (pucnfg & HIFN_PUCNFG_COMPSING) {
1225 if (pucnfg & HIFN_PUCNFG_ENCCNFG)
1230 * 7955/7956 has internal context memory of 32K
1232 if (sc->sc_flags & HIFN_IS_7956)
1233 sc->sc_maxses = 32768 / ctxsize;
1236 ((sc->sc_ramsize - 32768) / ctxsize);
1238 sc->sc_maxses = sc->sc_ramsize / 16384;
1240 if (sc->sc_maxses > 2048)
1241 sc->sc_maxses = 2048;
1245 * Determine ram type (sram or dram). Board should be just out of a reset
1246 * state when this is called.
1249 hifn_ramtype(struct hifn_softc *sc)
1251 u_int8_t data[8], dataexpect[8];
1254 for (i = 0; i < sizeof(data); i++)
1255 data[i] = dataexpect[i] = 0x55;
1256 if (hifn_writeramaddr(sc, 0, data))
1258 if (hifn_readramaddr(sc, 0, data))
1260 if (bcmp(data, dataexpect, sizeof(data)) != 0) {
1261 sc->sc_drammodel = 1;
1265 for (i = 0; i < sizeof(data); i++)
1266 data[i] = dataexpect[i] = 0xaa;
1267 if (hifn_writeramaddr(sc, 0, data))
1269 if (hifn_readramaddr(sc, 0, data))
1271 if (bcmp(data, dataexpect, sizeof(data)) != 0) {
1272 sc->sc_drammodel = 1;
1279 #define HIFN_SRAM_MAX (32 << 20)
1280 #define HIFN_SRAM_STEP_SIZE 16384
1281 #define HIFN_SRAM_GRANULARITY (HIFN_SRAM_MAX / HIFN_SRAM_STEP_SIZE)
1284 hifn_sramsize(struct hifn_softc *sc)
1288 u_int8_t dataexpect[sizeof(data)];
1291 for (i = 0; i < sizeof(data); i++)
1292 data[i] = dataexpect[i] = i ^ 0x5a;
1294 for (i = HIFN_SRAM_GRANULARITY - 1; i >= 0; i--) {
1295 a = i * HIFN_SRAM_STEP_SIZE;
1296 bcopy(&i, data, sizeof(i));
1297 hifn_writeramaddr(sc, a, data);
1300 for (i = 0; i < HIFN_SRAM_GRANULARITY; i++) {
1301 a = i * HIFN_SRAM_STEP_SIZE;
1302 bcopy(&i, dataexpect, sizeof(i));
1303 if (hifn_readramaddr(sc, a, data) < 0)
1305 if (bcmp(data, dataexpect, sizeof(data)) != 0)
1307 sc->sc_ramsize = a + HIFN_SRAM_STEP_SIZE;
1314 * XXX For dram boards, one should really try all of the
1315 * HIFN_PUCNFG_DSZ_*'s. This just assumes that PUCNFG
1316 * is already set up correctly.
1319 hifn_dramsize(struct hifn_softc *sc)
1323 if (sc->sc_flags & HIFN_IS_7956) {
1325 * 7955/7956 have a fixed internal ram of only 32K.
1327 sc->sc_ramsize = 32768;
1329 cnfg = READ_REG_0(sc, HIFN_0_PUCNFG) &
1330 HIFN_PUCNFG_DRAMMASK;
1331 sc->sc_ramsize = 1 << ((cnfg >> 13) + 18);
1337 hifn_alloc_slot(struct hifn_softc *sc, int *cmdp, int *srcp, int *dstp, int *resp)
1339 struct hifn_dma *dma = sc->sc_dma;
1341 if (sc->sc_cmdi == HIFN_D_CMD_RSIZE) {
1343 dma->cmdr[HIFN_D_CMD_RSIZE].l = htole32(HIFN_D_VALID |
1344 HIFN_D_JUMP | HIFN_D_MASKDONEIRQ);
1345 HIFN_CMDR_SYNC(sc, HIFN_D_CMD_RSIZE,
1346 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
1348 *cmdp = sc->sc_cmdi++;
1349 sc->sc_cmdk = sc->sc_cmdi;
1351 if (sc->sc_srci == HIFN_D_SRC_RSIZE) {
1353 dma->srcr[HIFN_D_SRC_RSIZE].l = htole32(HIFN_D_VALID |
1354 HIFN_D_JUMP | HIFN_D_MASKDONEIRQ);
1355 HIFN_SRCR_SYNC(sc, HIFN_D_SRC_RSIZE,
1356 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
1358 *srcp = sc->sc_srci++;
1359 sc->sc_srck = sc->sc_srci;
1361 if (sc->sc_dsti == HIFN_D_DST_RSIZE) {
1363 dma->dstr[HIFN_D_DST_RSIZE].l = htole32(HIFN_D_VALID |
1364 HIFN_D_JUMP | HIFN_D_MASKDONEIRQ);
1365 HIFN_DSTR_SYNC(sc, HIFN_D_DST_RSIZE,
1366 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
1368 *dstp = sc->sc_dsti++;
1369 sc->sc_dstk = sc->sc_dsti;
1371 if (sc->sc_resi == HIFN_D_RES_RSIZE) {
1373 dma->resr[HIFN_D_RES_RSIZE].l = htole32(HIFN_D_VALID |
1374 HIFN_D_JUMP | HIFN_D_MASKDONEIRQ);
1375 HIFN_RESR_SYNC(sc, HIFN_D_RES_RSIZE,
1376 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
1378 *resp = sc->sc_resi++;
1379 sc->sc_resk = sc->sc_resi;
1383 hifn_writeramaddr(struct hifn_softc *sc, int addr, u_int8_t *data)
1385 struct hifn_dma *dma = sc->sc_dma;
1386 hifn_base_command_t wc;
1387 const u_int32_t masks = HIFN_D_VALID | HIFN_D_LAST | HIFN_D_MASKDONEIRQ;
1388 int r, cmdi, resi, srci, dsti;
1390 wc.masks = htole16(3 << 13);
1391 wc.session_num = htole16(addr >> 14);
1392 wc.total_source_count = htole16(8);
1393 wc.total_dest_count = htole16(addr & 0x3fff);
1395 hifn_alloc_slot(sc, &cmdi, &srci, &dsti, &resi);
1397 WRITE_REG_1(sc, HIFN_1_DMA_CSR,
1398 HIFN_DMACSR_C_CTRL_ENA | HIFN_DMACSR_S_CTRL_ENA |
1399 HIFN_DMACSR_D_CTRL_ENA | HIFN_DMACSR_R_CTRL_ENA);
1401 /* build write command */
1402 bzero(dma->command_bufs[cmdi], HIFN_MAX_COMMAND);
1403 *(hifn_base_command_t *)dma->command_bufs[cmdi] = wc;
1404 bcopy(data, &dma->test_src, sizeof(dma->test_src));
1406 dma->srcr[srci].p = htole32(sc->sc_dma_physaddr
1407 + offsetof(struct hifn_dma, test_src));
1408 dma->dstr[dsti].p = htole32(sc->sc_dma_physaddr
1409 + offsetof(struct hifn_dma, test_dst));
1411 dma->cmdr[cmdi].l = htole32(16 | masks);
1412 dma->srcr[srci].l = htole32(8 | masks);
1413 dma->dstr[dsti].l = htole32(4 | masks);
1414 dma->resr[resi].l = htole32(4 | masks);
1416 bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
1417 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1419 for (r = 10000; r >= 0; r--) {
1421 bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
1422 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1423 if ((dma->resr[resi].l & htole32(HIFN_D_VALID)) == 0)
1425 bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
1426 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1429 device_printf(sc->sc_dev, "writeramaddr -- "
1430 "result[%d](addr %d) still valid\n", resi, addr);
1436 WRITE_REG_1(sc, HIFN_1_DMA_CSR,
1437 HIFN_DMACSR_C_CTRL_DIS | HIFN_DMACSR_S_CTRL_DIS |
1438 HIFN_DMACSR_D_CTRL_DIS | HIFN_DMACSR_R_CTRL_DIS);
1444 hifn_readramaddr(struct hifn_softc *sc, int addr, u_int8_t *data)
1446 struct hifn_dma *dma = sc->sc_dma;
1447 hifn_base_command_t rc;
1448 const u_int32_t masks = HIFN_D_VALID | HIFN_D_LAST | HIFN_D_MASKDONEIRQ;
1449 int r, cmdi, srci, dsti, resi;
1451 rc.masks = htole16(2 << 13);
1452 rc.session_num = htole16(addr >> 14);
1453 rc.total_source_count = htole16(addr & 0x3fff);
1454 rc.total_dest_count = htole16(8);
1456 hifn_alloc_slot(sc, &cmdi, &srci, &dsti, &resi);
1458 WRITE_REG_1(sc, HIFN_1_DMA_CSR,
1459 HIFN_DMACSR_C_CTRL_ENA | HIFN_DMACSR_S_CTRL_ENA |
1460 HIFN_DMACSR_D_CTRL_ENA | HIFN_DMACSR_R_CTRL_ENA);
1462 bzero(dma->command_bufs[cmdi], HIFN_MAX_COMMAND);
1463 *(hifn_base_command_t *)dma->command_bufs[cmdi] = rc;
1465 dma->srcr[srci].p = htole32(sc->sc_dma_physaddr +
1466 offsetof(struct hifn_dma, test_src));
1468 dma->dstr[dsti].p = htole32(sc->sc_dma_physaddr +
1469 offsetof(struct hifn_dma, test_dst));
1471 dma->cmdr[cmdi].l = htole32(8 | masks);
1472 dma->srcr[srci].l = htole32(8 | masks);
1473 dma->dstr[dsti].l = htole32(8 | masks);
1474 dma->resr[resi].l = htole32(HIFN_MAX_RESULT | masks);
1476 bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
1477 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1479 for (r = 10000; r >= 0; r--) {
1481 bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
1482 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1483 if ((dma->resr[resi].l & htole32(HIFN_D_VALID)) == 0)
1485 bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
1486 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1489 device_printf(sc->sc_dev, "readramaddr -- "
1490 "result[%d](addr %d) still valid\n", resi, addr);
1494 bcopy(&dma->test_dst, data, sizeof(dma->test_dst));
1497 WRITE_REG_1(sc, HIFN_1_DMA_CSR,
1498 HIFN_DMACSR_C_CTRL_DIS | HIFN_DMACSR_S_CTRL_DIS |
1499 HIFN_DMACSR_D_CTRL_DIS | HIFN_DMACSR_R_CTRL_DIS);
1505 * Initialize the descriptor rings.
1508 hifn_init_dma(struct hifn_softc *sc)
1510 struct hifn_dma *dma = sc->sc_dma;
1515 /* initialize static pointer values */
1516 for (i = 0; i < HIFN_D_CMD_RSIZE; i++)
1517 dma->cmdr[i].p = htole32(sc->sc_dma_physaddr +
1518 offsetof(struct hifn_dma, command_bufs[i][0]));
1519 for (i = 0; i < HIFN_D_RES_RSIZE; i++)
1520 dma->resr[i].p = htole32(sc->sc_dma_physaddr +
1521 offsetof(struct hifn_dma, result_bufs[i][0]));
1523 dma->cmdr[HIFN_D_CMD_RSIZE].p =
1524 htole32(sc->sc_dma_physaddr + offsetof(struct hifn_dma, cmdr[0]));
1525 dma->srcr[HIFN_D_SRC_RSIZE].p =
1526 htole32(sc->sc_dma_physaddr + offsetof(struct hifn_dma, srcr[0]));
1527 dma->dstr[HIFN_D_DST_RSIZE].p =
1528 htole32(sc->sc_dma_physaddr + offsetof(struct hifn_dma, dstr[0]));
1529 dma->resr[HIFN_D_RES_RSIZE].p =
1530 htole32(sc->sc_dma_physaddr + offsetof(struct hifn_dma, resr[0]));
1532 sc->sc_cmdu = sc->sc_srcu = sc->sc_dstu = sc->sc_resu = 0;
1533 sc->sc_cmdi = sc->sc_srci = sc->sc_dsti = sc->sc_resi = 0;
1534 sc->sc_cmdk = sc->sc_srck = sc->sc_dstk = sc->sc_resk = 0;
1538 * Writes out the raw command buffer space. Returns the
1539 * command buffer size.
1542 hifn_write_command(struct hifn_command *cmd, u_int8_t *buf)
1544 struct cryptop *crp;
1546 hifn_base_command_t *base_cmd;
1547 hifn_mac_command_t *mac_cmd;
1548 hifn_crypt_command_t *cry_cmd;
1549 int using_mac, using_crypt, ivlen;
1550 u_int32_t dlen, slen;
1554 using_mac = cmd->base_masks & HIFN_BASE_CMD_MAC;
1555 using_crypt = cmd->base_masks & HIFN_BASE_CMD_CRYPT;
1557 base_cmd = (hifn_base_command_t *)buf_pos;
1558 base_cmd->masks = htole16(cmd->base_masks);
1559 slen = cmd->src_mapsize;
1561 dlen = cmd->dst_mapsize - cmd->sloplen + sizeof(u_int32_t);
1563 dlen = cmd->dst_mapsize;
1564 base_cmd->total_source_count = htole16(slen & HIFN_BASE_CMD_LENMASK_LO);
1565 base_cmd->total_dest_count = htole16(dlen & HIFN_BASE_CMD_LENMASK_LO);
1568 base_cmd->session_num = htole16(
1569 ((slen << HIFN_BASE_CMD_SRCLEN_S) & HIFN_BASE_CMD_SRCLEN_M) |
1570 ((dlen << HIFN_BASE_CMD_DSTLEN_S) & HIFN_BASE_CMD_DSTLEN_M));
1571 buf_pos += sizeof(hifn_base_command_t);
1574 mac_cmd = (hifn_mac_command_t *)buf_pos;
1575 dlen = crp->crp_aad_length + crp->crp_payload_length;
1576 mac_cmd->source_count = htole16(dlen & 0xffff);
1578 mac_cmd->masks = htole16(cmd->mac_masks |
1579 ((dlen << HIFN_MAC_CMD_SRCLEN_S) & HIFN_MAC_CMD_SRCLEN_M));
1580 if (crp->crp_aad_length != 0)
1581 mac_cmd->header_skip = htole16(crp->crp_aad_start);
1583 mac_cmd->header_skip = htole16(crp->crp_payload_start);
1584 mac_cmd->reserved = 0;
1585 buf_pos += sizeof(hifn_mac_command_t);
1589 cry_cmd = (hifn_crypt_command_t *)buf_pos;
1590 dlen = crp->crp_payload_length;
1591 cry_cmd->source_count = htole16(dlen & 0xffff);
1593 cry_cmd->masks = htole16(cmd->cry_masks |
1594 ((dlen << HIFN_CRYPT_CMD_SRCLEN_S) & HIFN_CRYPT_CMD_SRCLEN_M));
1595 cry_cmd->header_skip = htole16(crp->crp_payload_length);
1596 cry_cmd->reserved = 0;
1597 buf_pos += sizeof(hifn_crypt_command_t);
1600 if (using_mac && cmd->mac_masks & HIFN_MAC_CMD_NEW_KEY) {
1601 bcopy(cmd->mac, buf_pos, HIFN_MAC_KEY_LENGTH);
1602 buf_pos += HIFN_MAC_KEY_LENGTH;
1605 if (using_crypt && cmd->cry_masks & HIFN_CRYPT_CMD_NEW_KEY) {
1606 switch (cmd->cry_masks & HIFN_CRYPT_CMD_ALG_MASK) {
1607 case HIFN_CRYPT_CMD_ALG_AES:
1609 * AES keys are variable 128, 192 and
1610 * 256 bits (16, 24 and 32 bytes).
1612 bcopy(cmd->ck, buf_pos, cmd->cklen);
1613 buf_pos += cmd->cklen;
1618 if (using_crypt && cmd->cry_masks & HIFN_CRYPT_CMD_NEW_IV) {
1619 switch (cmd->cry_masks & HIFN_CRYPT_CMD_ALG_MASK) {
1620 case HIFN_CRYPT_CMD_ALG_AES:
1621 ivlen = HIFN_AES_IV_LENGTH;
1624 ivlen = HIFN_IV_LENGTH;
1627 bcopy(cmd->iv, buf_pos, ivlen);
1631 if ((cmd->base_masks & (HIFN_BASE_CMD_MAC|HIFN_BASE_CMD_CRYPT)) == 0) {
1636 return (buf_pos - buf);
1640 hifn_dmamap_aligned(struct hifn_operand *op)
1644 for (i = 0; i < op->nsegs; i++) {
1645 if (op->segs[i].ds_addr & 3)
1647 if ((i != (op->nsegs - 1)) && (op->segs[i].ds_len & 3))
1654 hifn_dmamap_dstwrap(struct hifn_softc *sc, int idx)
1656 struct hifn_dma *dma = sc->sc_dma;
1658 if (++idx == HIFN_D_DST_RSIZE) {
1659 dma->dstr[idx].l = htole32(HIFN_D_VALID | HIFN_D_JUMP |
1660 HIFN_D_MASKDONEIRQ);
1661 HIFN_DSTR_SYNC(sc, idx,
1662 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1669 hifn_dmamap_load_dst(struct hifn_softc *sc, struct hifn_command *cmd)
1671 struct hifn_dma *dma = sc->sc_dma;
1672 struct hifn_operand *dst = &cmd->dst;
1674 int idx, used = 0, i;
1677 for (i = 0; i < dst->nsegs - 1; i++) {
1678 dma->dstr[idx].p = htole32(dst->segs[i].ds_addr);
1679 dma->dstr[idx].l = htole32(HIFN_D_VALID |
1680 HIFN_D_MASKDONEIRQ | dst->segs[i].ds_len);
1681 HIFN_DSTR_SYNC(sc, idx,
1682 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1685 idx = hifn_dmamap_dstwrap(sc, idx);
1688 if (cmd->sloplen == 0) {
1689 p = dst->segs[i].ds_addr;
1690 l = HIFN_D_VALID | HIFN_D_MASKDONEIRQ | HIFN_D_LAST |
1691 dst->segs[i].ds_len;
1693 p = sc->sc_dma_physaddr +
1694 offsetof(struct hifn_dma, slop[cmd->slopidx]);
1695 l = HIFN_D_VALID | HIFN_D_MASKDONEIRQ | HIFN_D_LAST |
1698 if ((dst->segs[i].ds_len - cmd->sloplen) != 0) {
1699 dma->dstr[idx].p = htole32(dst->segs[i].ds_addr);
1700 dma->dstr[idx].l = htole32(HIFN_D_VALID |
1701 HIFN_D_MASKDONEIRQ |
1702 (dst->segs[i].ds_len - cmd->sloplen));
1703 HIFN_DSTR_SYNC(sc, idx,
1704 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1707 idx = hifn_dmamap_dstwrap(sc, idx);
1710 dma->dstr[idx].p = htole32(p);
1711 dma->dstr[idx].l = htole32(l);
1712 HIFN_DSTR_SYNC(sc, idx, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1715 idx = hifn_dmamap_dstwrap(sc, idx);
1718 sc->sc_dstu += used;
1723 hifn_dmamap_srcwrap(struct hifn_softc *sc, int idx)
1725 struct hifn_dma *dma = sc->sc_dma;
1727 if (++idx == HIFN_D_SRC_RSIZE) {
1728 dma->srcr[idx].l = htole32(HIFN_D_VALID |
1729 HIFN_D_JUMP | HIFN_D_MASKDONEIRQ);
1730 HIFN_SRCR_SYNC(sc, HIFN_D_SRC_RSIZE,
1731 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
1738 hifn_dmamap_load_src(struct hifn_softc *sc, struct hifn_command *cmd)
1740 struct hifn_dma *dma = sc->sc_dma;
1741 struct hifn_operand *src = &cmd->src;
1746 for (i = 0; i < src->nsegs; i++) {
1747 if (i == src->nsegs - 1)
1750 dma->srcr[idx].p = htole32(src->segs[i].ds_addr);
1751 dma->srcr[idx].l = htole32(src->segs[i].ds_len |
1752 HIFN_D_VALID | HIFN_D_MASKDONEIRQ | last);
1753 HIFN_SRCR_SYNC(sc, idx,
1754 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
1756 idx = hifn_dmamap_srcwrap(sc, idx);
1759 sc->sc_srcu += src->nsegs;
1764 hifn_op_cb(void* arg, bus_dma_segment_t *seg, int nsegs, int error)
1766 struct hifn_operand *op = arg;
1768 KASSERT(nsegs <= MAX_SCATTER,
1769 ("hifn_op_cb: too many DMA segments (%u > %u) "
1770 "returned when mapping operand", nsegs, MAX_SCATTER));
1772 bcopy(seg, op->segs, nsegs * sizeof (seg[0]));
1777 struct hifn_softc *sc,
1778 struct hifn_command *cmd,
1779 struct cryptop *crp,
1782 struct hifn_dma *dma = sc->sc_dma;
1783 u_int32_t cmdlen, csr;
1784 int cmdi, resi, err = 0;
1787 * need 1 cmd, and 1 res
1789 * NB: check this first since it's easy.
1792 if ((sc->sc_cmdu + 1) > HIFN_D_CMD_RSIZE ||
1793 (sc->sc_resu + 1) > HIFN_D_RES_RSIZE) {
1796 device_printf(sc->sc_dev,
1797 "cmd/result exhaustion, cmdu %u resu %u\n",
1798 sc->sc_cmdu, sc->sc_resu);
1801 hifnstats.hst_nomem_cr++;
1806 if (bus_dmamap_create(sc->sc_dmat, BUS_DMA_NOWAIT, &cmd->src_map)) {
1807 hifnstats.hst_nomem_map++;
1812 if (bus_dmamap_load_crp(sc->sc_dmat, cmd->src_map, crp, hifn_op_cb,
1813 &cmd->src, BUS_DMA_NOWAIT)) {
1814 hifnstats.hst_nomem_load++;
1818 cmd->src_mapsize = crypto_buffer_len(&crp->crp_buf);
1820 if (hifn_dmamap_aligned(&cmd->src)) {
1821 cmd->sloplen = cmd->src_mapsize & 3;
1822 cmd->dst = cmd->src;
1823 } else if (crp->crp_buf.cb_type == CRYPTO_BUF_MBUF) {
1825 struct mbuf *m, *m0, *mlast;
1827 KASSERT(cmd->dst_m == NULL,
1828 ("hifn_crypto: dst_m initialized improperly"));
1829 hifnstats.hst_unaligned++;
1832 * Source is not aligned on a longword boundary.
1833 * Copy the data to insure alignment. If we fail
1834 * to allocate mbufs or clusters while doing this
1835 * we return ERESTART so the operation is requeued
1836 * at the crypto later, but only if there are
1837 * ops already posted to the hardware; otherwise we
1838 * have no guarantee that we'll be re-entered.
1840 totlen = cmd->src_mapsize;
1841 if (crp->crp_buf.cb_mbuf->m_flags & M_PKTHDR) {
1843 MGETHDR(m0, M_NOWAIT, MT_DATA);
1844 if (m0 && !m_dup_pkthdr(m0, crp->crp_buf.cb_mbuf,
1851 MGET(m0, M_NOWAIT, MT_DATA);
1854 hifnstats.hst_nomem_mbuf++;
1855 err = sc->sc_cmdu ? ERESTART : ENOMEM;
1858 if (totlen >= MINCLSIZE) {
1859 if (!(MCLGET(m0, M_NOWAIT))) {
1860 hifnstats.hst_nomem_mcl++;
1861 err = sc->sc_cmdu ? ERESTART : ENOMEM;
1868 m0->m_pkthdr.len = m0->m_len = len;
1871 while (totlen > 0) {
1872 MGET(m, M_NOWAIT, MT_DATA);
1874 hifnstats.hst_nomem_mbuf++;
1875 err = sc->sc_cmdu ? ERESTART : ENOMEM;
1880 if (totlen >= MINCLSIZE) {
1881 if (!(MCLGET(m, M_NOWAIT))) {
1882 hifnstats.hst_nomem_mcl++;
1883 err = sc->sc_cmdu ? ERESTART : ENOMEM;
1892 m0->m_pkthdr.len += len;
1900 if (bus_dmamap_create(sc->sc_dmat, BUS_DMA_NOWAIT,
1902 hifnstats.hst_nomem_map++;
1907 if (bus_dmamap_load_mbuf_sg(sc->sc_dmat, cmd->dst_map, m0,
1908 cmd->dst_segs, &cmd->dst_nsegs, 0)) {
1909 hifnstats.hst_nomem_map++;
1913 cmd->dst_mapsize = m0->m_pkthdr.len;
1921 device_printf(sc->sc_dev,
1922 "Entering cmd: stat %8x ien %8x u %d/%d/%d/%d n %d/%d\n",
1923 READ_REG_1(sc, HIFN_1_DMA_CSR),
1924 READ_REG_1(sc, HIFN_1_DMA_IER),
1925 sc->sc_cmdu, sc->sc_srcu, sc->sc_dstu, sc->sc_resu,
1926 cmd->src_nsegs, cmd->dst_nsegs);
1930 if (cmd->src_map == cmd->dst_map) {
1931 bus_dmamap_sync(sc->sc_dmat, cmd->src_map,
1932 BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
1934 bus_dmamap_sync(sc->sc_dmat, cmd->src_map,
1935 BUS_DMASYNC_PREWRITE);
1936 bus_dmamap_sync(sc->sc_dmat, cmd->dst_map,
1937 BUS_DMASYNC_PREREAD);
1941 * need N src, and N dst
1943 if ((sc->sc_srcu + cmd->src_nsegs) > HIFN_D_SRC_RSIZE ||
1944 (sc->sc_dstu + cmd->dst_nsegs + 1) > HIFN_D_DST_RSIZE) {
1947 device_printf(sc->sc_dev,
1948 "src/dst exhaustion, srcu %u+%u dstu %u+%u\n",
1949 sc->sc_srcu, cmd->src_nsegs,
1950 sc->sc_dstu, cmd->dst_nsegs);
1953 hifnstats.hst_nomem_sd++;
1958 if (sc->sc_cmdi == HIFN_D_CMD_RSIZE) {
1960 dma->cmdr[HIFN_D_CMD_RSIZE].l = htole32(HIFN_D_VALID |
1961 HIFN_D_JUMP | HIFN_D_MASKDONEIRQ);
1962 HIFN_CMDR_SYNC(sc, HIFN_D_CMD_RSIZE,
1963 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
1965 cmdi = sc->sc_cmdi++;
1966 cmdlen = hifn_write_command(cmd, dma->command_bufs[cmdi]);
1967 HIFN_CMD_SYNC(sc, cmdi, BUS_DMASYNC_PREWRITE);
1969 /* .p for command/result already set */
1970 dma->cmdr[cmdi].l = htole32(cmdlen | HIFN_D_VALID | HIFN_D_LAST |
1971 HIFN_D_MASKDONEIRQ);
1972 HIFN_CMDR_SYNC(sc, cmdi,
1973 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
1977 * We don't worry about missing an interrupt (which a "command wait"
1978 * interrupt salvages us from), unless there is more than one command
1981 if (sc->sc_cmdu > 1) {
1982 sc->sc_dmaier |= HIFN_DMAIER_C_WAIT;
1983 WRITE_REG_1(sc, HIFN_1_DMA_IER, sc->sc_dmaier);
1986 hifnstats.hst_ipackets++;
1987 hifnstats.hst_ibytes += cmd->src_mapsize;
1989 hifn_dmamap_load_src(sc, cmd);
1992 * Unlike other descriptors, we don't mask done interrupt from
1993 * result descriptor.
1997 printf("load res\n");
1999 if (sc->sc_resi == HIFN_D_RES_RSIZE) {
2001 dma->resr[HIFN_D_RES_RSIZE].l = htole32(HIFN_D_VALID |
2002 HIFN_D_JUMP | HIFN_D_MASKDONEIRQ);
2003 HIFN_RESR_SYNC(sc, HIFN_D_RES_RSIZE,
2004 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
2006 resi = sc->sc_resi++;
2007 KASSERT(sc->sc_hifn_commands[resi] == NULL,
2008 ("hifn_crypto: command slot %u busy", resi));
2009 sc->sc_hifn_commands[resi] = cmd;
2010 HIFN_RES_SYNC(sc, resi, BUS_DMASYNC_PREREAD);
2011 if ((hint & CRYPTO_HINT_MORE) && sc->sc_curbatch < hifn_maxbatch) {
2012 dma->resr[resi].l = htole32(HIFN_MAX_RESULT |
2013 HIFN_D_VALID | HIFN_D_LAST | HIFN_D_MASKDONEIRQ);
2015 if (sc->sc_curbatch > hifnstats.hst_maxbatch)
2016 hifnstats.hst_maxbatch = sc->sc_curbatch;
2017 hifnstats.hst_totbatch++;
2019 dma->resr[resi].l = htole32(HIFN_MAX_RESULT |
2020 HIFN_D_VALID | HIFN_D_LAST);
2021 sc->sc_curbatch = 0;
2023 HIFN_RESR_SYNC(sc, resi,
2024 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
2028 cmd->slopidx = resi;
2030 hifn_dmamap_load_dst(sc, cmd);
2033 if (sc->sc_c_busy == 0) {
2034 csr |= HIFN_DMACSR_C_CTRL_ENA;
2037 if (sc->sc_s_busy == 0) {
2038 csr |= HIFN_DMACSR_S_CTRL_ENA;
2041 if (sc->sc_r_busy == 0) {
2042 csr |= HIFN_DMACSR_R_CTRL_ENA;
2045 if (sc->sc_d_busy == 0) {
2046 csr |= HIFN_DMACSR_D_CTRL_ENA;
2050 WRITE_REG_1(sc, HIFN_1_DMA_CSR, csr);
2054 device_printf(sc->sc_dev, "command: stat %8x ier %8x\n",
2055 READ_REG_1(sc, HIFN_1_DMA_CSR),
2056 READ_REG_1(sc, HIFN_1_DMA_IER));
2062 KASSERT(err == 0, ("hifn_crypto: success with error %u", err));
2063 return (err); /* success */
2066 if (cmd->src_map != cmd->dst_map)
2067 bus_dmamap_unload(sc->sc_dmat, cmd->dst_map);
2069 if (cmd->src_map != cmd->dst_map)
2070 bus_dmamap_destroy(sc->sc_dmat, cmd->dst_map);
2072 if (crp->crp_buf.cb_type == CRYPTO_BUF_MBUF) {
2073 if (cmd->dst_m != NULL)
2074 m_freem(cmd->dst_m);
2076 bus_dmamap_unload(sc->sc_dmat, cmd->src_map);
2078 bus_dmamap_destroy(sc->sc_dmat, cmd->src_map);
2084 hifn_tick(void* vsc)
2086 struct hifn_softc *sc = vsc;
2089 if (sc->sc_active == 0) {
2092 if (sc->sc_cmdu == 0 && sc->sc_c_busy) {
2094 r |= HIFN_DMACSR_C_CTRL_DIS;
2096 if (sc->sc_srcu == 0 && sc->sc_s_busy) {
2098 r |= HIFN_DMACSR_S_CTRL_DIS;
2100 if (sc->sc_dstu == 0 && sc->sc_d_busy) {
2102 r |= HIFN_DMACSR_D_CTRL_DIS;
2104 if (sc->sc_resu == 0 && sc->sc_r_busy) {
2106 r |= HIFN_DMACSR_R_CTRL_DIS;
2109 WRITE_REG_1(sc, HIFN_1_DMA_CSR, r);
2113 callout_reset(&sc->sc_tickto, hz, hifn_tick, sc);
2117 hifn_intr(void *arg)
2119 struct hifn_softc *sc = arg;
2120 struct hifn_dma *dma;
2121 u_int32_t dmacsr, restart;
2124 dmacsr = READ_REG_1(sc, HIFN_1_DMA_CSR);
2126 /* Nothing in the DMA unit interrupted */
2127 if ((dmacsr & sc->sc_dmaier) == 0)
2136 device_printf(sc->sc_dev,
2137 "irq: stat %08x ien %08x damier %08x i %d/%d/%d/%d k %d/%d/%d/%d u %d/%d/%d/%d\n",
2138 dmacsr, READ_REG_1(sc, HIFN_1_DMA_IER), sc->sc_dmaier,
2139 sc->sc_cmdi, sc->sc_srci, sc->sc_dsti, sc->sc_resi,
2140 sc->sc_cmdk, sc->sc_srck, sc->sc_dstk, sc->sc_resk,
2141 sc->sc_cmdu, sc->sc_srcu, sc->sc_dstu, sc->sc_resu);
2145 WRITE_REG_1(sc, HIFN_1_DMA_CSR, dmacsr & sc->sc_dmaier);
2147 if ((sc->sc_flags & HIFN_HAS_PUBLIC) &&
2148 (dmacsr & HIFN_DMACSR_PUBDONE))
2149 WRITE_REG_1(sc, HIFN_1_PUB_STATUS,
2150 READ_REG_1(sc, HIFN_1_PUB_STATUS) | HIFN_PUBSTS_DONE);
2152 restart = dmacsr & (HIFN_DMACSR_D_OVER | HIFN_DMACSR_R_OVER);
2154 device_printf(sc->sc_dev, "overrun %x\n", dmacsr);
2156 if (sc->sc_flags & HIFN_IS_7811) {
2157 if (dmacsr & HIFN_DMACSR_ILLR)
2158 device_printf(sc->sc_dev, "illegal read\n");
2159 if (dmacsr & HIFN_DMACSR_ILLW)
2160 device_printf(sc->sc_dev, "illegal write\n");
2163 restart = dmacsr & (HIFN_DMACSR_C_ABORT | HIFN_DMACSR_S_ABORT |
2164 HIFN_DMACSR_D_ABORT | HIFN_DMACSR_R_ABORT);
2166 device_printf(sc->sc_dev, "abort, resetting.\n");
2167 hifnstats.hst_abort++;
2173 if ((dmacsr & HIFN_DMACSR_C_WAIT) && (sc->sc_cmdu == 0)) {
2175 * If no slots to process and we receive a "waiting on
2176 * command" interrupt, we disable the "waiting on command"
2179 sc->sc_dmaier &= ~HIFN_DMAIER_C_WAIT;
2180 WRITE_REG_1(sc, HIFN_1_DMA_IER, sc->sc_dmaier);
2183 /* clear the rings */
2184 i = sc->sc_resk; u = sc->sc_resu;
2186 HIFN_RESR_SYNC(sc, i,
2187 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
2188 if (dma->resr[i].l & htole32(HIFN_D_VALID)) {
2189 HIFN_RESR_SYNC(sc, i,
2190 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
2194 if (i != HIFN_D_RES_RSIZE) {
2195 struct hifn_command *cmd;
2196 u_int8_t *macbuf = NULL;
2198 HIFN_RES_SYNC(sc, i, BUS_DMASYNC_POSTREAD);
2199 cmd = sc->sc_hifn_commands[i];
2200 KASSERT(cmd != NULL,
2201 ("hifn_intr: null command slot %u", i));
2202 sc->sc_hifn_commands[i] = NULL;
2204 if (cmd->base_masks & HIFN_BASE_CMD_MAC) {
2205 macbuf = dma->result_bufs[i];
2209 hifn_callback(sc, cmd, macbuf);
2210 hifnstats.hst_opackets++;
2214 if (++i == (HIFN_D_RES_RSIZE + 1))
2217 sc->sc_resk = i; sc->sc_resu = u;
2219 i = sc->sc_srck; u = sc->sc_srcu;
2221 if (i == HIFN_D_SRC_RSIZE)
2223 HIFN_SRCR_SYNC(sc, i,
2224 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
2225 if (dma->srcr[i].l & htole32(HIFN_D_VALID)) {
2226 HIFN_SRCR_SYNC(sc, i,
2227 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
2232 sc->sc_srck = i; sc->sc_srcu = u;
2234 i = sc->sc_cmdk; u = sc->sc_cmdu;
2236 HIFN_CMDR_SYNC(sc, i,
2237 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
2238 if (dma->cmdr[i].l & htole32(HIFN_D_VALID)) {
2239 HIFN_CMDR_SYNC(sc, i,
2240 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
2243 if (i != HIFN_D_CMD_RSIZE) {
2245 HIFN_CMD_SYNC(sc, i, BUS_DMASYNC_POSTWRITE);
2247 if (++i == (HIFN_D_CMD_RSIZE + 1))
2250 sc->sc_cmdk = i; sc->sc_cmdu = u;
2254 if (sc->sc_needwakeup) { /* XXX check high watermark */
2255 int wakeup = sc->sc_needwakeup & (CRYPTO_SYMQ|CRYPTO_ASYMQ);
2258 device_printf(sc->sc_dev,
2259 "wakeup crypto (%x) u %d/%d/%d/%d\n",
2261 sc->sc_cmdu, sc->sc_srcu, sc->sc_dstu, sc->sc_resu);
2263 sc->sc_needwakeup &= ~wakeup;
2264 crypto_unblock(sc->sc_cid, wakeup);
2269 hifn_auth_supported(struct hifn_softc *sc,
2270 const struct crypto_session_params *csp)
2273 switch (sc->sc_ena) {
2274 case HIFN_PUSTAT_ENA_2:
2275 case HIFN_PUSTAT_ENA_1:
2281 switch (csp->csp_auth_alg) {
2284 case CRYPTO_SHA1_HMAC:
2285 if (csp->csp_auth_klen > HIFN_MAC_KEY_LENGTH)
2296 hifn_cipher_supported(struct hifn_softc *sc,
2297 const struct crypto_session_params *csp)
2300 if (csp->csp_cipher_klen == 0)
2302 if (csp->csp_ivlen > HIFN_MAX_IV_LENGTH)
2304 switch (sc->sc_ena) {
2305 case HIFN_PUSTAT_ENA_2:
2306 switch (csp->csp_cipher_alg) {
2307 case CRYPTO_AES_CBC:
2308 if ((sc->sc_flags & HIFN_HAS_AES) == 0)
2310 switch (csp->csp_cipher_klen) {
2325 hifn_probesession(device_t dev, const struct crypto_session_params *csp)
2327 struct hifn_softc *sc;
2329 sc = device_get_softc(dev);
2330 if (csp->csp_flags != 0)
2332 switch (csp->csp_mode) {
2333 case CSP_MODE_DIGEST:
2334 if (!hifn_auth_supported(sc, csp))
2337 case CSP_MODE_CIPHER:
2338 if (!hifn_cipher_supported(sc, csp))
2342 if (!hifn_auth_supported(sc, csp) ||
2343 !hifn_cipher_supported(sc, csp))
2350 return (CRYPTODEV_PROBE_HARDWARE);
2354 * Allocate a new 'session'.
2357 hifn_newsession(device_t dev, crypto_session_t cses,
2358 const struct crypto_session_params *csp)
2360 struct hifn_session *ses;
2362 ses = crypto_get_driver_session(cses);
2364 if (csp->csp_auth_alg != 0) {
2365 if (csp->csp_auth_mlen == 0)
2366 ses->hs_mlen = crypto_auth_hash(csp)->hashsize;
2368 ses->hs_mlen = csp->csp_auth_mlen;
2375 * XXX freesession routine should run a zero'd mac/encrypt key into context
2376 * ram. to blow away any keys already stored there.
2380 hifn_process(device_t dev, struct cryptop *crp, int hint)
2382 const struct crypto_session_params *csp;
2383 struct hifn_softc *sc = device_get_softc(dev);
2384 struct hifn_command *cmd = NULL;
2387 struct hifn_session *ses;
2389 ses = crypto_get_driver_session(crp->crp_session);
2391 cmd = malloc(sizeof(struct hifn_command), M_DEVBUF, M_NOWAIT | M_ZERO);
2393 hifnstats.hst_nomem++;
2398 csp = crypto_get_params(crp->crp_session);
2401 * The driver only supports ETA requests where there is no
2402 * gap between the AAD and payload.
2404 if (csp->csp_mode == CSP_MODE_ETA && crp->crp_aad_length != 0 &&
2405 crp->crp_aad_start + crp->crp_aad_length !=
2406 crp->crp_payload_start) {
2411 switch (csp->csp_mode) {
2412 case CSP_MODE_CIPHER:
2414 if (!CRYPTO_OP_IS_ENCRYPT(crp->crp_op))
2415 cmd->base_masks |= HIFN_BASE_CMD_DECODE;
2416 cmd->base_masks |= HIFN_BASE_CMD_CRYPT;
2417 switch (csp->csp_cipher_alg) {
2418 case CRYPTO_AES_CBC:
2419 cmd->cry_masks |= HIFN_CRYPT_CMD_ALG_AES |
2420 HIFN_CRYPT_CMD_MODE_CBC |
2421 HIFN_CRYPT_CMD_NEW_IV;
2427 crypto_read_iv(crp, cmd->iv);
2429 if (crp->crp_cipher_key != NULL)
2430 cmd->ck = crp->crp_cipher_key;
2432 cmd->ck = csp->csp_cipher_key;
2433 cmd->cklen = csp->csp_cipher_klen;
2434 cmd->cry_masks |= HIFN_CRYPT_CMD_NEW_KEY;
2437 * Need to specify the size for the AES key in the masks.
2439 if ((cmd->cry_masks & HIFN_CRYPT_CMD_ALG_MASK) ==
2440 HIFN_CRYPT_CMD_ALG_AES) {
2441 switch (cmd->cklen) {
2443 cmd->cry_masks |= HIFN_CRYPT_CMD_KSZ_128;
2446 cmd->cry_masks |= HIFN_CRYPT_CMD_KSZ_192;
2449 cmd->cry_masks |= HIFN_CRYPT_CMD_KSZ_256;
2459 switch (csp->csp_mode) {
2460 case CSP_MODE_DIGEST:
2462 cmd->base_masks |= HIFN_BASE_CMD_MAC;
2464 switch (csp->csp_auth_alg) {
2466 cmd->mac_masks |= HIFN_MAC_CMD_ALG_SHA1 |
2467 HIFN_MAC_CMD_RESULT | HIFN_MAC_CMD_MODE_HASH |
2468 HIFN_MAC_CMD_POS_IPSEC;
2470 case CRYPTO_SHA1_HMAC:
2471 cmd->mac_masks |= HIFN_MAC_CMD_ALG_SHA1 |
2472 HIFN_MAC_CMD_RESULT | HIFN_MAC_CMD_MODE_HMAC |
2473 HIFN_MAC_CMD_POS_IPSEC | HIFN_MAC_CMD_TRUNC;
2477 if (csp->csp_auth_alg == CRYPTO_SHA1_HMAC) {
2478 cmd->mac_masks |= HIFN_MAC_CMD_NEW_KEY;
2479 if (crp->crp_auth_key != NULL)
2480 mackey = crp->crp_auth_key;
2482 mackey = csp->csp_auth_key;
2483 keylen = csp->csp_auth_klen;
2484 bcopy(mackey, cmd->mac, keylen);
2485 bzero(cmd->mac + keylen, HIFN_MAC_KEY_LENGTH - keylen);
2493 err = hifn_crypto(sc, cmd, crp, hint);
2496 } else if (err == ERESTART) {
2498 * There weren't enough resources to dispatch the request
2499 * to the part. Notify the caller so they'll requeue this
2500 * request and resubmit it again soon.
2504 device_printf(sc->sc_dev, "requeue request\n");
2506 free(cmd, M_DEVBUF);
2507 sc->sc_needwakeup |= CRYPTO_SYMQ;
2513 free(cmd, M_DEVBUF);
2515 hifnstats.hst_invalid++;
2517 hifnstats.hst_nomem++;
2518 crp->crp_etype = err;
2524 hifn_abort(struct hifn_softc *sc)
2526 struct hifn_dma *dma = sc->sc_dma;
2527 struct hifn_command *cmd;
2528 struct cryptop *crp;
2531 i = sc->sc_resk; u = sc->sc_resu;
2533 cmd = sc->sc_hifn_commands[i];
2534 KASSERT(cmd != NULL, ("hifn_abort: null command slot %u", i));
2535 sc->sc_hifn_commands[i] = NULL;
2538 if ((dma->resr[i].l & htole32(HIFN_D_VALID)) == 0) {
2539 /* Salvage what we can. */
2542 if (cmd->base_masks & HIFN_BASE_CMD_MAC) {
2543 macbuf = dma->result_bufs[i];
2547 hifnstats.hst_opackets++;
2548 hifn_callback(sc, cmd, macbuf);
2550 if (cmd->src_map == cmd->dst_map) {
2551 bus_dmamap_sync(sc->sc_dmat, cmd->src_map,
2552 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
2554 bus_dmamap_sync(sc->sc_dmat, cmd->src_map,
2555 BUS_DMASYNC_POSTWRITE);
2556 bus_dmamap_sync(sc->sc_dmat, cmd->dst_map,
2557 BUS_DMASYNC_POSTREAD);
2560 if (cmd->dst_m != NULL) {
2561 m_freem(cmd->dst_m);
2564 /* non-shared buffers cannot be restarted */
2565 if (cmd->src_map != cmd->dst_map) {
2567 * XXX should be EAGAIN, delayed until
2570 crp->crp_etype = ENOMEM;
2571 bus_dmamap_unload(sc->sc_dmat, cmd->dst_map);
2572 bus_dmamap_destroy(sc->sc_dmat, cmd->dst_map);
2574 crp->crp_etype = ENOMEM;
2576 bus_dmamap_unload(sc->sc_dmat, cmd->src_map);
2577 bus_dmamap_destroy(sc->sc_dmat, cmd->src_map);
2579 free(cmd, M_DEVBUF);
2580 if (crp->crp_etype != EAGAIN)
2584 if (++i == HIFN_D_RES_RSIZE)
2588 sc->sc_resk = i; sc->sc_resu = u;
2590 hifn_reset_board(sc, 1);
2592 hifn_init_pci_registers(sc);
2596 hifn_callback(struct hifn_softc *sc, struct hifn_command *cmd, u_int8_t *macbuf)
2598 struct hifn_dma *dma = sc->sc_dma;
2599 struct cryptop *crp = cmd->crp;
2600 uint8_t macbuf2[SHA1_HASH_LEN];
2604 if (cmd->src_map == cmd->dst_map) {
2605 bus_dmamap_sync(sc->sc_dmat, cmd->src_map,
2606 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
2608 bus_dmamap_sync(sc->sc_dmat, cmd->src_map,
2609 BUS_DMASYNC_POSTWRITE);
2610 bus_dmamap_sync(sc->sc_dmat, cmd->dst_map,
2611 BUS_DMASYNC_POSTREAD);
2614 if (crp->crp_buf.cb_type == CRYPTO_BUF_MBUF) {
2615 if (cmd->dst_m != NULL) {
2616 totlen = cmd->src_mapsize;
2617 for (m = cmd->dst_m; m != NULL; m = m->m_next) {
2618 if (totlen < m->m_len) {
2624 cmd->dst_m->m_pkthdr.len =
2625 crp->crp_buf.cb_mbuf->m_pkthdr.len;
2626 m_freem(crp->crp_buf.cb_mbuf);
2627 crp->crp_buf.cb_mbuf = cmd->dst_m;
2631 if (cmd->sloplen != 0) {
2632 crypto_copyback(crp, cmd->src_mapsize - cmd->sloplen,
2633 cmd->sloplen, &dma->slop[cmd->slopidx]);
2636 i = sc->sc_dstk; u = sc->sc_dstu;
2638 if (i == HIFN_D_DST_RSIZE)
2640 bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
2641 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
2642 if (dma->dstr[i].l & htole32(HIFN_D_VALID)) {
2643 bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
2644 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
2649 sc->sc_dstk = i; sc->sc_dstu = u;
2651 hifnstats.hst_obytes += cmd->dst_mapsize;
2653 if (macbuf != NULL) {
2654 if (crp->crp_op & CRYPTO_OP_VERIFY_DIGEST) {
2655 crypto_copydata(crp, crp->crp_digest_start,
2656 cmd->session->hs_mlen, macbuf2);
2657 if (timingsafe_bcmp(macbuf, macbuf2,
2658 cmd->session->hs_mlen) != 0)
2659 crp->crp_etype = EBADMSG;
2661 crypto_copyback(crp, crp->crp_digest_start,
2662 cmd->session->hs_mlen, macbuf);
2665 if (cmd->src_map != cmd->dst_map) {
2666 bus_dmamap_unload(sc->sc_dmat, cmd->dst_map);
2667 bus_dmamap_destroy(sc->sc_dmat, cmd->dst_map);
2669 bus_dmamap_unload(sc->sc_dmat, cmd->src_map);
2670 bus_dmamap_destroy(sc->sc_dmat, cmd->src_map);
2671 free(cmd, M_DEVBUF);
2676 * 7811 PB3 rev/2 parts lock-up on burst writes to Group 0
2677 * and Group 1 registers; avoid conditions that could create
2678 * burst writes by doing a read in between the writes.
2680 * NB: The read we interpose is always to the same register;
2681 * we do this because reading from an arbitrary (e.g. last)
2682 * register may not always work.
2685 hifn_write_reg_0(struct hifn_softc *sc, bus_size_t reg, u_int32_t val)
2687 if (sc->sc_flags & HIFN_IS_7811) {
2688 if (sc->sc_bar0_lastreg == reg - 4)
2689 bus_space_read_4(sc->sc_st0, sc->sc_sh0, HIFN_0_PUCNFG);
2690 sc->sc_bar0_lastreg = reg;
2692 bus_space_write_4(sc->sc_st0, sc->sc_sh0, reg, val);
2696 hifn_write_reg_1(struct hifn_softc *sc, bus_size_t reg, u_int32_t val)
2698 if (sc->sc_flags & HIFN_IS_7811) {
2699 if (sc->sc_bar1_lastreg == reg - 4)
2700 bus_space_read_4(sc->sc_st1, sc->sc_sh1, HIFN_1_REVID);
2701 sc->sc_bar1_lastreg = reg;
2703 bus_space_write_4(sc->sc_st1, sc->sc_sh1, reg, val);
2706 #ifdef HIFN_VULCANDEV
2708 * this code provides support for mapping the PK engine's register
2709 * into a userspace program.
2713 vulcanpk_mmap(struct cdev *dev, vm_ooffset_t offset,
2714 vm_paddr_t *paddr, int nprot, vm_memattr_t *memattr)
2716 struct hifn_softc *sc;
2722 pd = rman_get_start(sc->sc_bar1res);
2723 b = rman_get_virtual(sc->sc_bar1res);
2726 printf("vpk mmap: %p(%016llx) offset=%lld\n", b,
2727 (unsigned long long)pd, offset);
2728 hexdump(b, HIFN_1_PUB_MEMEND, "vpk", 0);
2738 static struct cdevsw vulcanpk_cdevsw = {
2739 .d_version = D_VERSION,
2740 .d_mmap = vulcanpk_mmap,
2741 .d_name = "vulcanpk",
2743 #endif /* HIFN_VULCANDEV */