2 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Coyote Point Systems, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
32 #include <dev/pci/pcireg.h>
33 #include <dev/pci/pcivar.h>
34 #include <dev/pci/pcidevs.h>
35 #include <dev/pci/pcidevs.h>
36 #include <opencrypto/cryptodev.h>
37 #include "n8_driver_main.h"
38 #include "n8_pub_symmetric.h"
39 #include "n8_pub_packet.h"
42 #ifndef PCI_VENDOR_NETOCTAVE
43 #define PCI_VENDOR_NETOCTAVE 0x170b
45 #ifndef PCI_PRODUCT_NETOCTAVE_NSP2000
46 #define PCI_PRODUCT_NETOCTAVE_NSP2000 0x100
49 #define NSP_BAR0 (PCI_MAPREG_START + 0) /* PUC register map */
50 #define NSP_BAR1 (PCI_MAPREG_START + 4) /* DMA register map */
51 #define NSP_TRDY_TIMEOUT 0x40 /* TRDY timeout */
52 #define NSP_RETRY_TIMEOUT 0x41 /* DMA retry timeout */
54 /* DEBUG MESSAGE BIT SELECTORS */
55 #define N8_DBG_GENERAL 1
57 #define N8_DBG_BIGALLOC 4
58 #define N8_DBG_DISPLAY_MEMORY 8
59 #define N8_DBG_DISPLAY_CONTEXT 16
60 #define N8_DBG_DISPLAY_REGISTERS 32
61 #define N8_DBG_DISPLAY_QMGR 64
63 #define DEBUG_GENERAL (N8_Debug_g & N8_DBG_GENERAL)
64 #define DEBUG_IRQ (N8_Debug_g & N8_DBG_IRQ)
65 #define DEBUG_BIGALLOC (N8_Debug_g & N8_DBG_BIGALLOC)
66 #define APRINT if (DEBUG_GENERAL) printf
68 /* The following two values are inSilicon PCI test registers that need */
69 /* to be set to the PCI standards rather than their defaults. */
70 #define INSILICON_PCI_TRDY_TIMEOUT 0x40
71 #define INSILICON_PCI_RETRY_TIMEOUT 0x41
73 #define NSP_MAX_SESSION 1024
74 #define NSP_MAX_KEY_LEN (256*8)
75 #define NSP_MAX_KEY_BYTES ((NSP_MAX_KEY_LEN+7)/8)
77 #define NSP_STATE_INIT 0
79 typedef struct nsp_session
{
83 N8_ContextHandle_t contextHandle
; /* Context memory handle */
84 int contextAllocated
; /* Boolean flag for cleanup of context */
86 N8_EncryptObject_t crypt
; /* Encrypt/Decrypt control data */
87 N8_EncryptCipher_t cipherInfo
;
95 void *crp_opaque
; /* user data to return with result */
96 struct cryptop
*crp
; /* complete crypto op */
97 struct cryptodesc
*crd
; /* active crypto op */
98 int crd_id
; /* active crd index */
100 int active
; /* Boolean: operation active on session */
113 N8_Buffer_t
*mac
; /* IOV mode means direct copy for hashes.... !? */
115 struct nsp_session
*next
; /* next free */
119 struct device device
;
120 pci_chipset_tag_t pa_pc
;
123 kmutex_t sc_intrlock
;
125 bus_space_handle_t mem_handle
;
126 bus_space_tag_t mem_tag
;
128 bus_dma_tag_t dma_tag
;
134 int sc_needwakeup
; /* notify crypto layer */
135 u_int32_t sc_statmask
; /* interrupt status mask */
136 int32_t cid
; /* crypto tag */
139 nsp_session_t session
[NSP_MAX_SESSION
];
140 nsp_session_t
*freesession
; /* first free session */