RMI security accelerator driver update.
- Compile fixes for 9.0, the previous version of this driver was for FreeBSD 6. - Add virtual address field in OperationDescriptor_t, we cannot use MIPS_PHYS_TO_KSEG0 on physical address. - Fixes for new message ring API - Remove unused sys/mips/rmi/dev/sec/stats.h - Whitespace fixes
This commit is contained in:
parent
01b36cb089
commit
bb15db8f16
@ -26,6 +26,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
* RMI_BSD */
|
||||
#ifndef _DESC_H_
|
||||
#define _DESC_H_
|
||||
@ -2320,7 +2321,7 @@ typedef struct OperationDescriptor_s {
|
||||
uint32_t flags;
|
||||
uint32_t cpu;
|
||||
uint32_t seq_num;
|
||||
uint64_t reserved;
|
||||
uint64_t vaddr;
|
||||
} OperationDescriptor_t, *OperationDescriptor_pt;
|
||||
|
||||
|
||||
|
@ -41,7 +41,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/bus.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/md_var.h>
|
||||
#include <machine/mips-exts.h>
|
||||
#include <machine/cpuregs.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
@ -49,20 +48,19 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <opencrypto/cryptodev.h>
|
||||
|
||||
|
||||
#include <mips/xlr/iomap.h>
|
||||
#include <mips/xlr/pic.h>
|
||||
#include <mips/xlr/shared_structs.h>
|
||||
#include <mips/xlr/iomap.h>
|
||||
#include <mips/xlr/msgring.h>
|
||||
#include <mips/xlr/board.h>
|
||||
#include <mips/rmi/rmi_mips_exts.h>
|
||||
#include <mips/rmi/iomap.h>
|
||||
#include <mips/rmi/pic.h>
|
||||
#include <mips/rmi/rmi_boot_info.h>
|
||||
#include <mips/rmi/msgring.h>
|
||||
#include <mips/rmi/board.h>
|
||||
#include <mips/rmi/dev/sec/rmilib.h>
|
||||
#include <mips/rmi/dev/sec/desc.h>
|
||||
|
||||
|
||||
// static int msgrng_stnid_pk0 = MSGRNG_STNID_PK0;
|
||||
/* static int msgrng_stnid_pk0 = MSGRNG_STNID_PK0; */
|
||||
|
||||
/*#define RMI_SEC_DEBUG */
|
||||
/* #define RMI_SEC_DEBUG */
|
||||
|
||||
#define SMP_CACHE_BYTES XLR_CACHELINE_SIZE
|
||||
#define NUM_CHUNKS(size, bits) ( ((size)>>(bits)) + (((size)&((1<<(bits))-1))?1:0) )
|
||||
@ -72,86 +70,44 @@ symkey_desc_pt g_desc;
|
||||
struct xlr_sec_command *g_cmd;
|
||||
|
||||
#ifdef XLR_SEC_CMD_DEBUG
|
||||
static void
|
||||
decode_symkey_desc(symkey_desc_pt desc, uint32_t cfg_vector);
|
||||
|
||||
static void decode_symkey_desc(symkey_desc_pt desc, uint32_t cfg_vector);
|
||||
#endif
|
||||
|
||||
void print_buf(char *desc, void *data, int len);
|
||||
static int xlr_sec_cipher_hash_command(xlr_sec_io_pt op, symkey_desc_pt desc,
|
||||
uint8_t);
|
||||
static xlr_sec_error_t xlr_sec_setup_descriptor(xlr_sec_io_pt op,
|
||||
unsigned int flags, symkey_desc_pt desc, uint32_t * cfg_vector);
|
||||
|
||||
static int
|
||||
xlr_sec_cipher_hash_command(xlr_sec_io_pt op, symkey_desc_pt desc, uint8_t);
|
||||
|
||||
static xlr_sec_error_t
|
||||
xlr_sec_setup_descriptor(xlr_sec_io_pt op,
|
||||
unsigned int flags,
|
||||
symkey_desc_pt desc,
|
||||
uint32_t * cfg_vector);
|
||||
|
||||
static
|
||||
xlr_sec_error_t
|
||||
xlr_sec_setup_packet(xlr_sec_io_pt op,
|
||||
symkey_desc_pt desc,
|
||||
unsigned int flags,
|
||||
uint64_t * data,
|
||||
PacketDescriptor_pt pkt_desc,
|
||||
ControlDescriptor_pt ctl_desc,
|
||||
uint32_t vector,
|
||||
PacketDescriptor_pt next_pkt_desc,
|
||||
static xlr_sec_error_t xlr_sec_setup_packet(xlr_sec_io_pt op,
|
||||
symkey_desc_pt desc, unsigned int flags, uint64_t * data,
|
||||
PacketDescriptor_pt pkt_desc, ControlDescriptor_pt ctl_desc,
|
||||
uint32_t vector, PacketDescriptor_pt next_pkt_desc,
|
||||
uint8_t multi_frag_flag);
|
||||
|
||||
static int
|
||||
xlr_sec_submit_message(symkey_desc_pt desc, uint32_t cfg_vector);
|
||||
|
||||
static
|
||||
xlr_sec_error_t
|
||||
xlr_sec_setup_cipher(xlr_sec_io_pt op,
|
||||
ControlDescriptor_pt ctl_desc,
|
||||
uint32_t * vector);
|
||||
|
||||
static
|
||||
xlr_sec_error_t
|
||||
xlr_sec_setup_digest(xlr_sec_io_pt op,
|
||||
ControlDescriptor_pt ctl_desc,
|
||||
uint32_t * vector);
|
||||
|
||||
static
|
||||
xlr_sec_error_t
|
||||
xlr_sec_setup_cksum(xlr_sec_io_pt op,
|
||||
static int xlr_sec_submit_message(symkey_desc_pt desc, uint32_t cfg_vector);
|
||||
static xlr_sec_error_t xlr_sec_setup_cipher(xlr_sec_io_pt op,
|
||||
ControlDescriptor_pt ctl_desc, uint32_t * vector);
|
||||
static xlr_sec_error_t xlr_sec_setup_digest(xlr_sec_io_pt op,
|
||||
ControlDescriptor_pt ctl_desc, uint32_t * vector);
|
||||
static xlr_sec_error_t xlr_sec_setup_cksum(xlr_sec_io_pt op,
|
||||
ControlDescriptor_pt ctl_desc);
|
||||
static xlr_sec_error_t xlr_sec_control_setup(xlr_sec_io_pt op,
|
||||
unsigned int flags, uint64_t * control, ControlDescriptor_pt ctl_desc,
|
||||
xlr_sec_drv_user_t * user, uint32_t vector);
|
||||
static void xlr_sec_free_desc(symkey_desc_pt desc);
|
||||
|
||||
static
|
||||
xlr_sec_error_t
|
||||
xlr_sec_control_setup(xlr_sec_io_pt op,
|
||||
unsigned int flags,
|
||||
uint64_t * control,
|
||||
ControlDescriptor_pt ctl_desc,
|
||||
xlr_sec_drv_user_t * user,
|
||||
uint32_t vector);
|
||||
|
||||
|
||||
xlr_sec_error_t
|
||||
xlr_sec_submit_op(symkey_desc_pt desc);
|
||||
|
||||
static void xlr_sec_free_desc(symkey_desc_pt desc);
|
||||
|
||||
void
|
||||
xlr_sec_msgring_handler(int bucket, int size, int code, int stid,
|
||||
void print_buf(char *desc, void *data, int len);
|
||||
xlr_sec_error_t xlr_sec_submit_op(symkey_desc_pt desc);
|
||||
void xlr_sec_msgring_handler(int bucket, int size, int code, int stid,
|
||||
struct msgrng_msg *msg, void *data);
|
||||
|
||||
|
||||
void
|
||||
xlr_sec_init(struct xlr_sec_softc *sc)
|
||||
{
|
||||
unsigned int i;
|
||||
xlr_reg_t *mmio;
|
||||
|
||||
|
||||
mmio = sc->mmio = xlr_io_mmio(XLR_IO_SECURITY_OFFSET);
|
||||
|
||||
xlr_write_reg(mmio, SEC_DMA_CREDIT, SEC_DMA_CREDIT_CONFIG);
|
||||
|
||||
|
||||
xlr_write_reg(mmio, SEC_CONFIG2, SEC_CFG2_ROUND_ROBIN_ON);
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
@ -168,7 +124,6 @@ xlr_sec_init(struct xlr_sec_softc *sc)
|
||||
xls_cc_table_sec.counters[i >> 3][i & 0x07] :
|
||||
cc_table_sec.counters[i >> 3][i & 0x07]);
|
||||
|
||||
|
||||
/*
|
||||
* Register a bucket handler with the phoenix messaging subsystem
|
||||
* For now, register handler for bucket 0->5 in msg stn 0
|
||||
@ -179,30 +134,23 @@ xlr_sec_init(struct xlr_sec_softc *sc)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
xlr_sec_setup(struct xlr_sec_session *ses,
|
||||
struct xlr_sec_command *cmd,
|
||||
symkey_desc_pt desc
|
||||
)
|
||||
symkey_desc_pt desc)
|
||||
{
|
||||
xlr_sec_io_pt op;
|
||||
int size, ret_val;
|
||||
int iv_len;
|
||||
|
||||
|
||||
desc->ses = ses;
|
||||
op = &cmd->op;
|
||||
if (op == NULL)
|
||||
return (-ENOMEM);
|
||||
|
||||
|
||||
|
||||
desc->ctl_desc.instruction = 0;
|
||||
memset(&desc->ctl_desc.cipherHashInfo, 0, sizeof(CipherHashInfo_t));
|
||||
desc->control = 0;
|
||||
|
||||
desc->pkt_desc[0].srcLengthIVOffUseIVNext = 0;
|
||||
desc->pkt_desc[0].dstDataSettings = 0;
|
||||
desc->pkt_desc[0].authDstNonceLow = 0;
|
||||
@ -211,12 +159,10 @@ xlr_sec_setup(struct xlr_sec_session *ses,
|
||||
desc->pkt_desc[1].dstDataSettings = 0;
|
||||
desc->pkt_desc[1].authDstNonceLow = 0;
|
||||
desc->pkt_desc[1].ckSumDstNonceHiCFBMaskLLWMask = 0;
|
||||
|
||||
desc->data = 0;
|
||||
desc->ctl_result = 0;
|
||||
desc->data_result = 0;
|
||||
|
||||
|
||||
if (op->flags & XLR_SEC_FLAGS_HIGH_PRIORITY)
|
||||
if (!xlr_is_xls())
|
||||
desc->op_ctl.stn_id++;
|
||||
@ -225,7 +171,6 @@ xlr_sec_setup(struct xlr_sec_session *ses,
|
||||
desc->user.user_dest = (uint8_t *) (unsigned long)op->dest_buf;
|
||||
desc->user.user_auth = (uint8_t *) (unsigned long)op->auth_dest;
|
||||
|
||||
|
||||
if ((op->cipher_type == XLR_SEC_CIPHER_TYPE_ARC4) &&
|
||||
(!op->rc4_state && (op->rc4_loadstate || op->rc4_savestate))) {
|
||||
printf(" ** Load/Save State and no State **");
|
||||
@ -234,7 +179,6 @@ xlr_sec_setup(struct xlr_sec_session *ses,
|
||||
}
|
||||
desc->user.user_state = (uint8_t *) (unsigned long)op->rc4_state;
|
||||
|
||||
|
||||
switch (op->cipher_type) {
|
||||
case XLR_SEC_CIPHER_TYPE_NONE:
|
||||
iv_len = 0;
|
||||
@ -260,10 +204,6 @@ xlr_sec_setup(struct xlr_sec_session *ses,
|
||||
xlr_sec_free_desc(desc);
|
||||
return (-EINVAL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
size = op->source_buf_size + iv_len;
|
||||
|
||||
/*
|
||||
@ -276,7 +216,8 @@ xlr_sec_setup(struct xlr_sec_session *ses,
|
||||
|
||||
if (op->cipher_type == XLR_SEC_CIPHER_TYPE_NONE) {
|
||||
if (op->source_buf_size != 0) {
|
||||
memcpy(desc->user.aligned_src, (uint8_t *) (unsigned long)op->source_buf,
|
||||
memcpy(desc->user.aligned_src,
|
||||
(uint8_t *)(uintptr_t)op->source_buf,
|
||||
op->source_buf_size);
|
||||
}
|
||||
} else {
|
||||
@ -306,12 +247,9 @@ xlr_sec_setup(struct xlr_sec_session *ses,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Set source to new kernel space */
|
||||
op->source_buf = (uint64_t) (unsigned long)desc->user.aligned_src;
|
||||
|
||||
|
||||
/*
|
||||
* Build new dest buffer, for Cipher output only
|
||||
*/
|
||||
@ -324,7 +262,6 @@ xlr_sec_setup(struct xlr_sec_session *ses,
|
||||
} else {
|
||||
/* DEBUG -dpk */
|
||||
XLR_SEC_CMD_DIAG("dest_buf_size = %d \n", op->dest_buf_size);
|
||||
|
||||
size = op->dest_buf_size + iv_len;
|
||||
|
||||
/*
|
||||
@ -335,11 +272,9 @@ xlr_sec_setup(struct xlr_sec_session *ses,
|
||||
op->cipher_mode == XLR_SEC_CIPHER_MODE_CTR)
|
||||
size += XLR_SEC_AES_BLOCK_SIZE - 1;
|
||||
op->dest_buf = (uint64_t) (unsigned long)desc->user.aligned_dest;
|
||||
|
||||
}
|
||||
|
||||
ret_val = xlr_sec_cipher_hash_command(op, desc, ses->multi_frag_flag);
|
||||
|
||||
return (ret_val);
|
||||
|
||||
}
|
||||
@ -396,7 +331,6 @@ xlr_sec_cipher_hash_command(xlr_sec_io_pt op, symkey_desc_pt desc,
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static xlr_sec_error_t
|
||||
xlr_sec_setup_descriptor(xlr_sec_io_pt op,
|
||||
unsigned int flags,
|
||||
@ -407,7 +341,6 @@ xlr_sec_setup_descriptor(xlr_sec_io_pt op,
|
||||
|
||||
XLR_SEC_CMD_DIAG("xlr_sec_setup_descriptor: ENTER\n");
|
||||
|
||||
|
||||
if ((err = xlr_sec_setup_cipher(op, &desc->ctl_desc, cfg_vector)) != XLR_SEC_ERR_NONE) {
|
||||
XLR_SEC_CMD_DIAG("xlr_sec_setup_descriptor: xlr_sec_setup_cipher done err %d\n",
|
||||
(int)err);
|
||||
@ -483,7 +416,7 @@ xlr_sec_setup_packet(xlr_sec_io_pt op,
|
||||
|
||||
len = op->source_buf_size + byte_offset - global_offset;
|
||||
if (multi_frag_flag) {
|
||||
next_seg_addr = (uint64_t) vtophys((void *)(unsigned long)(desc->next_src_buf));
|
||||
next_seg_addr = (uint64_t)vtophys((void *)(uintptr_t)desc->next_src_buf);
|
||||
next_seg_addr = (next_seg_addr & ~(SMP_CACHE_BYTES - 1));
|
||||
next_len = desc->next_src_len;
|
||||
}
|
||||
@ -505,14 +438,12 @@ xlr_sec_setup_packet(xlr_sec_io_pt op,
|
||||
*/
|
||||
cipher_offset_dwords = (op->iv_offset + byte_offset) >> 3;
|
||||
|
||||
|
||||
if (op->cipher_mode == XLR_SEC_CIPHER_MODE_F8 ||
|
||||
op->cipher_mode == XLR_SEC_CIPHER_MODE_CTR) {
|
||||
if (multi_frag_flag) {
|
||||
int nlhmac = ((op->source_buf_size + global_offset + 7 - op->cipher_offset) >> 3) & 1;
|
||||
|
||||
pkt_desc->srcLengthIVOffUseIVNext =
|
||||
|
||||
FIELD_VALUE(PKT_DSC_HASHBYTES, len & 7) |
|
||||
FIELD_VALUE(PKT_DSC_IVOFF, cipher_offset_dwords) |
|
||||
FIELD_VALUE(PKT_DSC_PKTLEN, nlhmac + ((len + 7) >> 3)) |
|
||||
@ -539,7 +470,6 @@ xlr_sec_setup_packet(xlr_sec_io_pt op,
|
||||
} else {
|
||||
if (multi_frag_flag) {
|
||||
pkt_desc->srcLengthIVOffUseIVNext =
|
||||
|
||||
FIELD_VALUE(PKT_DSC_HASHBYTES, len & 7) |
|
||||
FIELD_VALUE(PKT_DSC_IVOFF, cipher_offset_dwords) |
|
||||
FIELD_VALUE(PKT_DSC_PKTLEN, (len + 7) >> 3) |
|
||||
@ -890,7 +820,6 @@ xlr_sec_setup_packet(xlr_sec_io_pt op,
|
||||
CLEAR_SET_FIELD(next_pkt_desc->ckSumDstNonceHiCFBMaskLLWMask,
|
||||
PKT_DSC_CKSUM_DST_ADDR,
|
||||
(uint64_t) vtophys((void *)(unsigned long)desc->next_cksum_dest));
|
||||
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -902,17 +831,13 @@ xlr_sec_setup_packet(xlr_sec_io_pt op,
|
||||
XLR_SEC_CMD_DIAG(" xlr_sec_setup_packet(): pkt_desc=%p phys_pkt_desc=%llx \n",
|
||||
pkt_desc, (unsigned long long)vtophys(pkt_desc));
|
||||
|
||||
|
||||
|
||||
CLEAR_SET_FIELD(*data, MSG_CMD_DATA_ADDR, ((uint64_t) vtophys(pkt_desc)));
|
||||
CLEAR_SET_FIELD(*data, MSG_CMD_DATA_CTL, SEC_EOP);
|
||||
CLEAR_SET_FIELD(*data, MSG_CMD_DATA_LEN, MSG_CMD_DATA_LEN_LOAD);
|
||||
|
||||
|
||||
XLR_SEC_CMD_DIAG("xlr_sec_setup_packet: DONE\n");
|
||||
|
||||
#ifdef RMI_SEC_DEBUG
|
||||
|
||||
{
|
||||
printf("data desc\n");
|
||||
printf("srcLengthIVOffUseIVNext = 0x%llx\n", pkt_desc->srcLengthIVOffUseIVNext);
|
||||
@ -1036,9 +961,7 @@ xlr_sec_submit_message(symkey_desc_pt desc, uint32_t cfg_vector)
|
||||
int ret_val = 0;
|
||||
|
||||
XLR_SEC_CMD_DIAG("xlr_sec_submit_message: ENTER\n");
|
||||
|
||||
err = XLR_SEC_ERR_NONE;
|
||||
|
||||
XLR_SEC_CMD_DIAG_SYM_DESC(desc, cfg_vector);
|
||||
|
||||
do {
|
||||
@ -1206,7 +1129,6 @@ xlr_sec_setup_cipher(xlr_sec_io_pt op,
|
||||
return XLR_SEC_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
xlr_sec_error_t
|
||||
xlr_sec_setup_digest(xlr_sec_io_pt op,
|
||||
@ -1304,7 +1226,6 @@ xlr_sec_setup_digest(xlr_sec_io_pt op,
|
||||
*vector |= digest_vector;
|
||||
|
||||
XLR_SEC_CMD_DIAG("xlr_sec_setup_digest: EXIT vector = %04x\n", *vector);
|
||||
|
||||
return XLR_SEC_ERR_NONE;
|
||||
}
|
||||
|
||||
@ -1350,7 +1271,6 @@ xlr_sec_control_setup(xlr_sec_io_pt op,
|
||||
XLR_SEC_CMD_DIAG(" ENTER vector = %04x\n", vector);
|
||||
#endif
|
||||
|
||||
|
||||
switch (vector) {
|
||||
case XLR_SEC_VECTOR_MAC:
|
||||
XLR_SEC_CMD_DIAG(" XLR_SEC_VECTOR_MAC \n");
|
||||
@ -1970,7 +1890,6 @@ xlr_sec_control_setup(xlr_sec_io_pt op,
|
||||
return XLR_SEC_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
xlr_sec_error_t
|
||||
xlr_sec_submit_op(symkey_desc_pt desc)
|
||||
{
|
||||
@ -2013,31 +1932,18 @@ xlr_sec_submit_op(symkey_desc_pt desc)
|
||||
XLR_SEC_CMD_DIAG("[%s]: IN_IRQ=%d msg0=0x%llx msg1=0x%llx \n",
|
||||
__FUNCTION__, desc->op_ctl.flags, send_msg.msg0, send_msg.msg1);
|
||||
|
||||
|
||||
|
||||
retries = 100;
|
||||
|
||||
while (retries--) {
|
||||
msgrng_flags_save(msgrng_flags);
|
||||
|
||||
code = message_send_retry(SEC_MSGRING_WORDSIZE,
|
||||
MSGRNG_CODE_SEC,
|
||||
desc->op_ctl.stn_id,
|
||||
&send_msg);
|
||||
|
||||
|
||||
msgrng_flags_restore(msgrng_flags);
|
||||
|
||||
msgrng_flags = msgrng_access_enable();
|
||||
code = message_send(SEC_MSGRING_WORDSIZE, MSGRNG_CODE_SEC,
|
||||
desc->op_ctl.stn_id, &send_msg);
|
||||
msgrng_restore(msgrng_flags);
|
||||
if (code == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return (XLR_SEC_ERR_NONE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
symkey_desc_pt
|
||||
xlr_sec_allocate_desc(void *session_ptr)
|
||||
{
|
||||
@ -2090,7 +1996,6 @@ xlr_sec_allocate_desc(void *session_ptr)
|
||||
new->user.kern_auth = new->user.user_auth = NULL;
|
||||
new->user.aligned_auth = new->user.user_auth = NULL;
|
||||
|
||||
|
||||
/* find cacheline alignment */
|
||||
aligned = new;
|
||||
addr = (uint64_t) vtophys(new);
|
||||
@ -2101,6 +2006,7 @@ xlr_sec_allocate_desc(void *session_ptr)
|
||||
/* setup common control info */
|
||||
aligned->op_ctl.phys_self = addr;
|
||||
aligned->op_ctl.stn_id = MSGRNG_STNID_SEC0;
|
||||
aligned->op_ctl.vaddr = (uintptr_t)aligned;
|
||||
|
||||
return (aligned);
|
||||
}
|
||||
@ -2114,8 +2020,6 @@ xlr_sec_free_desc(symkey_desc_pt desc)
|
||||
return;
|
||||
}
|
||||
contigfree(desc, sizeof(symkey_desc_t), M_DEVBUF);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2816,7 +2720,7 @@ decode_symkey_desc(symkey_desc_pt desc, uint32_t cfg_vector)
|
||||
break;
|
||||
}
|
||||
DPRINT("PACKET DESCRIPTOR: \n");
|
||||
word = desc->pkt_desc.srcLengthIVOffUseIVNext;
|
||||
word = 0; //desc->pkt_desc.srcLengthIVOffUseIVNext;
|
||||
DPRINT("\tSrcLengthIVOffsetIVNext: %llx\n", word);
|
||||
DPRINT("\t\tLoad HMAC = %lld \n",
|
||||
GET_FIELD(word, PKT_DSC_LOADHMACKEY));
|
||||
@ -2841,7 +2745,7 @@ decode_symkey_desc(symkey_desc_pt desc, uint32_t cfg_vector)
|
||||
DPRINT("\t\tGlobal Src Offset = %lld \n",
|
||||
GET_FIELD(word, PKT_DSC_SEGOFFSET));
|
||||
|
||||
word = desc->pkt_desc.dstDataSettings;
|
||||
word = 0; //desc->pkt_desc.dstDataSettings;
|
||||
DPRINT("\tdstDataSettings: %llx \n", word);
|
||||
DPRINT("\t\tArc4 Byte Count = %lld \n", GET_FIELD(word,
|
||||
PKT_DSC_ARC4BYTECOUNT));
|
||||
@ -2859,7 +2763,7 @@ decode_symkey_desc(symkey_desc_pt desc, uint32_t cfg_vector)
|
||||
PKT_DSC_CPHR_DST_DWOFFSET));
|
||||
DPRINT("\t\tCipher Dest Offset= %lld \n", GET_FIELD(word,
|
||||
PKT_DSC_CPHR_DST_OFFSET));
|
||||
word = desc->pkt_desc.authDstNonceLow;
|
||||
word = 0; //desc->pkt_desc.authDstNonceLow;
|
||||
DPRINT("\tauthDstNonceLow: %llx \n", word);
|
||||
DPRINT("\t\tNonce Low 24 = %lld \n", GET_FIELD(word,
|
||||
PKT_DSC_NONCE_LOW));
|
||||
@ -2867,7 +2771,7 @@ decode_symkey_desc(symkey_desc_pt desc, uint32_t cfg_vector)
|
||||
PKT_DSC_AUTH_DST_ADDR));
|
||||
DPRINT("\t\tCipher Offset High= %lld \n", GET_FIELD(word,
|
||||
PKT_DSC_CIPH_OFF_HI));
|
||||
word = desc->pkt_desc.ckSumDstNonceHiCFBMaskLLWMask;
|
||||
word = 0; //desc->pkt_desc.ckSumDstNonceHiCFBMaskLLWMask;
|
||||
DPRINT("\tckSumDstNonceHiCFBMaskLLWMask: %llx \n", word);
|
||||
DPRINT("\t\tHash Byte off = %lld \n", GET_FIELD(word, PKT_DSC_HASH_BYTE_OFF));
|
||||
DPRINT("\t\tPacket Len bytes = %lld \n", GET_FIELD(word, PKT_DSC_PKTLEN_BYTES));
|
||||
@ -2897,7 +2801,7 @@ xlr_sec_msgring_handler(int bucket, int size, int code, int stid,
|
||||
symkey_desc_pt desc = NULL;
|
||||
struct xlr_sec_session *ses = NULL;
|
||||
struct xlr_sec_command *cmd = NULL;
|
||||
|
||||
uint32_t flags;
|
||||
|
||||
if (code != MSGRNG_CODE_SEC) {
|
||||
panic("xlr_sec_msgring_handler: bad code = %d,"
|
||||
@ -2916,7 +2820,6 @@ xlr_sec_msgring_handler(int bucket, int size, int code, int stid,
|
||||
sec_eng = GET_FIELD(msg->msg0, MSG_CTL_OP_TYPE);
|
||||
sec_pipe = GET_FIELD(msg->msg1, MSG_CTL_OP_TYPE);
|
||||
|
||||
|
||||
error = msg->msg0 >> 40 & 0x1ff;
|
||||
if (error)
|
||||
printf("ctrl error = 0x%llx\n", error);
|
||||
@ -2938,12 +2841,11 @@ xlr_sec_msgring_handler(int bucket, int size, int code, int stid,
|
||||
* they are used for the engine and pipe Id.
|
||||
*/
|
||||
addr = GET_FIELD(msg->msg1, MSG_RSLT_DATA_DSC_ADDR);
|
||||
|
||||
addr = addr & ~((1 << 5) - 1);
|
||||
if (!addr) {
|
||||
panic("[%s:STNID_SEC]: NULL symkey addr!\n", __FUNCTION__);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The adddress points to the data descriptor. The operation
|
||||
* descriptor is defined with the 32-byte cacheline size in
|
||||
@ -2951,7 +2853,10 @@ xlr_sec_msgring_handler(int bucket, int size, int code, int stid,
|
||||
* reference the symkey descriptor. (ref: xlr_sec_desc.h)
|
||||
*/
|
||||
addr = addr - sizeof(OperationDescriptor_t);
|
||||
desc = (symkey_desc_pt) MIPS_PHYS_TO_KSEG0(addr);
|
||||
flags = xlr_enable_kx();
|
||||
desc = (symkey_desc_pt)(uintptr_t)xlr_paddr_ld(addr +
|
||||
offsetof(OperationDescriptor_t, vaddr));
|
||||
xlr_restore_kx(flags);
|
||||
|
||||
if (!desc) {
|
||||
printf("\nerror : not getting desc back correctly \n");
|
||||
@ -3099,10 +3004,8 @@ xlr_sec_msgring_handler(int bucket, int size, int code, int stid,
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Copy cipher-data to User-space */
|
||||
if (op->cipher_type != XLR_SEC_CIPHER_TYPE_NONE) {
|
||||
|
||||
size = op->dest_buf_size;
|
||||
|
||||
/* DEBUG -dpk */
|
||||
@ -3119,14 +3022,12 @@ xlr_sec_msgring_handler(int bucket, int size, int code, int stid,
|
||||
crypto_copyback(cmd->crp->crp_flags, cmd->crp->crp_buf, 0,
|
||||
cmd->op.dest_buf_size, (caddr_t)(long)desc->user.aligned_dest + op->cipher_offset);
|
||||
crypto_done(cmd->crp);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* Copy digest to User-space */
|
||||
if (op->digest_type != XLR_SEC_DIGEST_TYPE_NONE) {
|
||||
|
||||
int offset = 0;
|
||||
|
||||
switch (op->digest_type) {
|
||||
@ -3163,7 +3064,6 @@ xlr_sec_msgring_handler(int bucket, int size, int code, int stid,
|
||||
}
|
||||
if (op->cipher_type == XLR_SEC_CIPHER_TYPE_ARC4 &&
|
||||
op->rc4_savestate) {
|
||||
|
||||
size = XLR_SEC_MAX_RC4_STATE_SIZE;
|
||||
|
||||
XLR_SEC_CMD_DIAG("state: to_addr=%p from_addr=%p size=%d \n",
|
||||
|
@ -25,7 +25,8 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* $FreeBSD$
|
||||
* RMI_BSD
|
||||
*/
|
||||
|
||||
@ -33,12 +34,10 @@
|
||||
#define _RMILIB_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <mips/rmi/dev/sec/desc.h>
|
||||
#include <mips/xlr/iomap.h>
|
||||
#include <mips/rmi/iomap.h>
|
||||
|
||||
/*#define XLR_SEC_CMD_DEBUG*/
|
||||
/* #define XLR_SEC_CMD_DEBUG */
|
||||
|
||||
#ifdef XLR_SEC_CMD_DEBUG
|
||||
#define DPRINT printf
|
||||
|
@ -43,29 +43,27 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/random.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <opencrypto/cryptodev.h>
|
||||
|
||||
#include "cryptodev_if.h"
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/rman.h>
|
||||
|
||||
#include <opencrypto/cryptodev.h>
|
||||
#include <sys/random.h>
|
||||
|
||||
#include <mips/rmi/dev/sec/rmilib.h>
|
||||
|
||||
/*#define RMI_SEC_DEBUG */
|
||||
|
||||
/* #define RMI_SEC_DEBUG */
|
||||
|
||||
void xlr_sec_print_data(struct cryptop *crp);
|
||||
|
||||
static int xlr_sec_newsession(void *arg, uint32_t * sidp, struct cryptoini *cri);
|
||||
static int xlr_sec_freesession(void *arg, uint64_t tid);
|
||||
static int xlr_sec_process(void *arg, struct cryptop *crp, int hint);
|
||||
|
||||
static int xlr_sec_newsession(device_t dev, uint32_t * sidp, struct cryptoini *cri);
|
||||
static int xlr_sec_freesession(device_t dev, uint64_t tid);
|
||||
static int xlr_sec_process(device_t dev, struct cryptop *crp, int hint);
|
||||
|
||||
static int xlr_sec_probe(device_t);
|
||||
static int xlr_sec_attach(device_t);
|
||||
@ -82,6 +80,11 @@ static device_method_t xlr_sec_methods[] = {
|
||||
DEVMETHOD(bus_print_child, bus_generic_print_child),
|
||||
DEVMETHOD(bus_driver_added, bus_generic_driver_added),
|
||||
|
||||
/* crypto device methods */
|
||||
DEVMETHOD(cryptodev_newsession, xlr_sec_newsession),
|
||||
DEVMETHOD(cryptodev_freesession,xlr_sec_freesession),
|
||||
DEVMETHOD(cryptodev_process, xlr_sec_process),
|
||||
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
@ -95,81 +98,63 @@ static devclass_t xlr_sec_devclass;
|
||||
DRIVER_MODULE(rmisec, iodi, xlr_sec_driver, xlr_sec_devclass, 0, 0);
|
||||
MODULE_DEPEND(rmisec, crypto, 1, 1, 1);
|
||||
|
||||
|
||||
|
||||
static int
|
||||
xlr_sec_probe(device_t dev)
|
||||
{
|
||||
|
||||
device_set_desc(dev, "XLR Security Accelerator");
|
||||
return (BUS_PROBE_DEFAULT);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Attach an interface that successfully probed.
|
||||
*/
|
||||
static int
|
||||
xlr_sec_attach(device_t dev)
|
||||
{
|
||||
|
||||
struct xlr_sec_softc *sc = device_get_softc(dev);
|
||||
|
||||
bzero(sc, sizeof(*sc));
|
||||
sc->sc_dev = dev;
|
||||
|
||||
|
||||
mtx_init(&sc->sc_mtx, device_get_nameunit(dev), "rmi crypto driver", MTX_DEF);
|
||||
|
||||
sc->sc_cid = crypto_get_driverid(0);
|
||||
mtx_init(&sc->sc_mtx, device_get_nameunit(dev), "rmi crypto driver",
|
||||
MTX_DEF);
|
||||
sc->sc_cid = crypto_get_driverid(dev, CRYPTOCAP_F_HARDWARE);
|
||||
if (sc->sc_cid < 0) {
|
||||
printf("xlr_sec - error : could not get the driver id\n");
|
||||
goto error_exit;
|
||||
}
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_DES_CBC, 0, 0,
|
||||
xlr_sec_newsession, xlr_sec_freesession, xlr_sec_process, sc) != 0)
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_DES_CBC, 0, 0) != 0)
|
||||
printf("register failed for CRYPTO_DES_CBC\n");
|
||||
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_3DES_CBC, 0, 0,
|
||||
xlr_sec_newsession, xlr_sec_freesession, xlr_sec_process, sc) != 0)
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_3DES_CBC, 0, 0) != 0)
|
||||
printf("register failed for CRYPTO_3DES_CBC\n");
|
||||
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_AES_CBC, 0, 0,
|
||||
xlr_sec_newsession, xlr_sec_freesession,
|
||||
xlr_sec_process, sc) != 0)
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_AES_CBC, 0, 0) != 0)
|
||||
printf("register failed for CRYPTO_AES_CBC\n");
|
||||
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_ARC4, 0, 0,
|
||||
xlr_sec_newsession, xlr_sec_freesession, xlr_sec_process, sc) != 0)
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_ARC4, 0, 0) != 0)
|
||||
printf("register failed for CRYPTO_ARC4\n");
|
||||
|
||||
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_MD5, 0, 0,
|
||||
xlr_sec_newsession, xlr_sec_freesession, xlr_sec_process, sc) != 0)
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_MD5, 0, 0) != 0)
|
||||
printf("register failed for CRYPTO_MD5\n");
|
||||
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_SHA1, 0, 0,
|
||||
xlr_sec_newsession, xlr_sec_freesession, xlr_sec_process, sc) != 0)
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_SHA1, 0, 0) != 0)
|
||||
printf("register failed for CRYPTO_SHA1\n");
|
||||
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_MD5_HMAC, 0, 0,
|
||||
xlr_sec_newsession, xlr_sec_freesession, xlr_sec_process, sc) != 0)
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_MD5_HMAC, 0, 0) != 0)
|
||||
printf("register failed for CRYPTO_MD5_HMAC\n");
|
||||
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_SHA1_HMAC, 0, 0,
|
||||
xlr_sec_newsession, xlr_sec_freesession, xlr_sec_process, sc) != 0)
|
||||
if (crypto_register(sc->sc_cid, CRYPTO_SHA1_HMAC, 0, 0) != 0)
|
||||
printf("register failed for CRYPTO_SHA1_HMAC\n");
|
||||
|
||||
|
||||
xlr_sec_init(sc);
|
||||
device_printf(dev, "Initialization complete!\n");
|
||||
return (0);
|
||||
|
||||
|
||||
error_exit:
|
||||
return (ENXIO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Detach an interface that successfully probed.
|
||||
*/
|
||||
@ -194,39 +179,28 @@ xlr_sec_detach(device_t dev)
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Allocate a new 'session' and return an encoded session id. 'sidp'
|
||||
* contains our registration id, and should contain an encoded session
|
||||
* id on successful allocation.
|
||||
*/
|
||||
static int
|
||||
xlr_sec_newsession(void *arg, u_int32_t * sidp, struct cryptoini *cri)
|
||||
xlr_sec_newsession(device_t dev, u_int32_t *sidp, struct cryptoini *cri)
|
||||
{
|
||||
struct cryptoini *c;
|
||||
struct xlr_sec_softc *sc = arg;
|
||||
struct xlr_sec_softc *sc = device_get_softc(dev);
|
||||
int mac = 0, cry = 0, sesn;
|
||||
struct xlr_sec_session *ses = NULL;
|
||||
|
||||
|
||||
if (sidp == NULL || cri == NULL || sc == NULL)
|
||||
return (EINVAL);
|
||||
|
||||
|
||||
if (sc->sc_sessions == NULL) {
|
||||
ses = sc->sc_sessions = (struct xlr_sec_session *)malloc(
|
||||
sizeof(struct xlr_sec_session), M_DEVBUF, M_NOWAIT);
|
||||
if (ses == NULL)
|
||||
return (ENOMEM);
|
||||
|
||||
ses->desc_ptr = (void *)xlr_sec_allocate_desc((void *)ses);
|
||||
if (ses->desc_ptr == NULL)
|
||||
return (ENOMEM);
|
||||
|
||||
sesn = 0;
|
||||
ses->sessionid = sesn;
|
||||
sc->sc_nsessions = 1;
|
||||
} else {
|
||||
for (sesn = 0; sesn < sc->sc_nsessions; sesn++) {
|
||||
@ -242,23 +216,22 @@ xlr_sec_newsession(void *arg, u_int32_t * sidp, struct cryptoini *cri)
|
||||
sizeof(struct xlr_sec_session), M_DEVBUF, M_NOWAIT);
|
||||
if (ses == NULL)
|
||||
return (ENOMEM);
|
||||
bcopy(sc->sc_sessions, ses, sesn * sizeof(struct xlr_sec_session));
|
||||
bzero(sc->sc_sessions, sesn * sizeof(struct xlr_sec_session));
|
||||
bcopy(sc->sc_sessions, ses, sesn * sizeof(*ses));
|
||||
bzero(sc->sc_sessions, sesn * sizeof(*ses));
|
||||
free(sc->sc_sessions, M_DEVBUF);
|
||||
sc->sc_sessions = ses;
|
||||
ses = &sc->sc_sessions[sesn];
|
||||
ses->sessionid = sesn;
|
||||
ses->desc_ptr = (void *)xlr_sec_allocate_desc((void *)ses);
|
||||
if (ses->desc_ptr == NULL)
|
||||
return (ENOMEM);
|
||||
sc->sc_nsessions++;
|
||||
}
|
||||
}
|
||||
bzero(ses, sizeof(*ses));
|
||||
ses->sessionid = sesn;
|
||||
ses->desc_ptr = xlr_sec_allocate_desc(ses);
|
||||
if (ses->desc_ptr == NULL)
|
||||
return (ENOMEM);
|
||||
ses->hs_used = 1;
|
||||
|
||||
|
||||
for (c = cri; c != NULL; c = c->cri_next) {
|
||||
|
||||
switch (c->cri_alg) {
|
||||
case CRYPTO_MD5:
|
||||
case CRYPTO_SHA1:
|
||||
@ -313,9 +286,9 @@ xlr_sec_newsession(void *arg, u_int32_t * sidp, struct cryptoini *cri)
|
||||
* XXX to blow away any keys already stored there.
|
||||
*/
|
||||
static int
|
||||
xlr_sec_freesession(void *arg, u_int64_t tid)
|
||||
xlr_sec_freesession(device_t dev, u_int64_t tid)
|
||||
{
|
||||
struct xlr_sec_softc *sc = arg;
|
||||
struct xlr_sec_softc *sc = device_get_softc(dev);
|
||||
int session;
|
||||
u_int32_t sid = CRYPTO_SESID2LID(tid);
|
||||
|
||||
@ -327,7 +300,6 @@ xlr_sec_freesession(void *arg, u_int64_t tid)
|
||||
return (EINVAL);
|
||||
|
||||
sc->sc_sessions[session].hs_used = 0;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -375,11 +347,10 @@ xlr_sec_print_data(struct cryptop *crp)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
static int
|
||||
xlr_sec_process(void *arg, struct cryptop *crp, int hint)
|
||||
xlr_sec_process(device_t dev, struct cryptop *crp, int hint)
|
||||
{
|
||||
struct xlr_sec_softc *sc = arg;
|
||||
struct xlr_sec_softc *sc = device_get_softc(dev);
|
||||
struct xlr_sec_command *cmd = NULL;
|
||||
int session, err;
|
||||
struct cryptodesc *crd1, *crd2, *maccrd, *enccrd;
|
||||
@ -466,7 +437,6 @@ xlr_sec_process(void *arg, struct cryptop *crp, int hint)
|
||||
cmd->op.num_packets = 1;
|
||||
cmd->op.num_fragments = 1;
|
||||
|
||||
|
||||
if (cmd->op.source_buf_size > SEC_MAX_FRAG_LEN) {
|
||||
ses->multi_frag_flag = 1;
|
||||
} else {
|
||||
@ -499,7 +469,6 @@ xlr_sec_process(void *arg, struct cryptop *crp, int hint)
|
||||
cmd->op.pkt_iv = XLR_SEC_PKT_IV_OLD;
|
||||
cmd->op.pkt_lastword = XLR_SEC_LASTWORD_128;
|
||||
|
||||
|
||||
default:
|
||||
printf("currently not handled\n");
|
||||
}
|
||||
@ -524,8 +493,10 @@ xlr_sec_process(void *arg, struct cryptop *crp, int hint)
|
||||
memcpy(&cmd->op.crypt_key[0], enccrd->crd_key, XLR_SEC_DES_KEY_LENGTH);
|
||||
} else {
|
||||
cmd->op.cipher_type = XLR_SEC_CIPHER_TYPE_3DES;
|
||||
//if (enccrd->crd_flags & CRD_F_KEY_EXPLICIT) {
|
||||
memcpy(&cmd->op.crypt_key[0], enccrd->crd_key, XLR_SEC_3DES_KEY_LENGTH);
|
||||
//if (enccrd->crd_flags & CRD_F_KEY_EXPLICIT)
|
||||
{
|
||||
memcpy(&cmd->op.crypt_key[0], enccrd->crd_key,
|
||||
XLR_SEC_3DES_KEY_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
@ -550,16 +521,19 @@ xlr_sec_process(void *arg, struct cryptop *crp, int hint)
|
||||
cmd->op.pkt_lastword = XLR_SEC_LASTWORD_128;
|
||||
|
||||
//if ((!(enccrd->crd_flags & CRD_F_IV_PRESENT)) &&
|
||||
if ((enccrd->crd_flags & CRD_F_IV_EXPLICIT)) {
|
||||
memcpy(&cmd->op.initial_vector[0], enccrd->crd_iv, XLR_SEC_DES_IV_LENGTH);
|
||||
}
|
||||
if ((enccrd->crd_flags & CRD_F_IV_EXPLICIT)) {
|
||||
memcpy(&cmd->op.initial_vector[0], enccrd->crd_iv,
|
||||
XLR_SEC_DES_IV_LENGTH);
|
||||
}
|
||||
break;
|
||||
|
||||
case CRYPTO_AES_CBC:
|
||||
if (enccrd->crd_alg == CRYPTO_AES_CBC) {
|
||||
cmd->op.cipher_type = XLR_SEC_CIPHER_TYPE_AES128;
|
||||
//if (enccrd->crd_flags & CRD_F_KEY_EXPLICIT) {
|
||||
memcpy(&cmd->op.crypt_key[0], enccrd->crd_key, XLR_SEC_AES128_KEY_LENGTH);
|
||||
//if (enccrd->crd_flags & CRD_F_KEY_EXPLICIT)
|
||||
{
|
||||
memcpy(&cmd->op.crypt_key[0], enccrd->crd_key,
|
||||
XLR_SEC_AES128_KEY_LENGTH);
|
||||
}
|
||||
}
|
||||
cmd->op.cipher_mode = XLR_SEC_CIPHER_MODE_CBC;
|
||||
@ -583,11 +557,11 @@ xlr_sec_process(void *arg, struct cryptop *crp, int hint)
|
||||
cmd->op.pkt_lastword = XLR_SEC_LASTWORD_128;
|
||||
|
||||
//if (!(enccrd->crd_flags & CRD_F_IV_PRESENT)) {
|
||||
if ((enccrd->crd_flags & CRD_F_IV_EXPLICIT)) {
|
||||
memcpy(&cmd->op.initial_vector[0], enccrd->crd_iv, XLR_SEC_AES_BLOCK_SIZE);
|
||||
}
|
||||
//
|
||||
if ((enccrd->crd_flags & CRD_F_IV_EXPLICIT)) {
|
||||
memcpy(&cmd->op.initial_vector[0], enccrd->crd_iv,
|
||||
XLR_SEC_AES_BLOCK_SIZE);
|
||||
}
|
||||
//}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,469 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2003-2009 RMI Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of RMI Corporation, nor the names of its contributors,
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY 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.
|
||||
*
|
||||
* RMI_BSD */
|
||||
|
||||
#ifndef _STATS_H_
|
||||
#define _STATS_H_
|
||||
|
||||
typedef struct hmac_stats
|
||||
{
|
||||
unsigned long md5_count;
|
||||
unsigned long long md5_bytes;
|
||||
unsigned long sha1_count;
|
||||
unsigned long long sha1_bytes;
|
||||
unsigned long sha256_count;
|
||||
unsigned long long sha256_bytes;
|
||||
unsigned long sha384_count;
|
||||
unsigned long long sha384_bytes;
|
||||
unsigned long sha512_count;
|
||||
unsigned long long sha512_bytes;
|
||||
unsigned long gcm_count;
|
||||
unsigned long long gcm_bytes;
|
||||
unsigned long kasumi_f9_count;
|
||||
unsigned long long kasumi_f9_bytes;
|
||||
unsigned long reverts;
|
||||
unsigned long long reverts_bytes;
|
||||
} hmac_stats_t, *hmac_stats_pt;
|
||||
|
||||
typedef struct cipher_stats
|
||||
{
|
||||
unsigned long des_encrypts;
|
||||
unsigned long long des_encrypt_bytes;
|
||||
unsigned long des_decrypts;
|
||||
unsigned long long des_decrypt_bytes;
|
||||
unsigned long des3_encrypts;
|
||||
unsigned long long des3_encrypt_bytes;
|
||||
unsigned long des3_decrypts;
|
||||
unsigned long long des3_decrypt_bytes;
|
||||
unsigned long aes_encrypts;
|
||||
unsigned long long aes_encrypt_bytes;
|
||||
unsigned long aes_decrypts;
|
||||
unsigned long long aes_decrypt_bytes;
|
||||
unsigned long arc4_encrypts;
|
||||
unsigned long long arc4_encrypt_bytes;
|
||||
unsigned long arc4_decrypts;
|
||||
unsigned long long arc4_decrypt_bytes;
|
||||
unsigned long kasumi_f8_encrypts;
|
||||
unsigned long long kasumi_f8_encrypt_bytes;
|
||||
unsigned long kasumi_f8_decrypts;
|
||||
unsigned long long kasumi_f8_decrypt_bytes;
|
||||
unsigned long reverts;
|
||||
unsigned long long reverts_bytes;
|
||||
} cipher_stats_t, *cipher_stats_pt;
|
||||
|
||||
|
||||
typedef struct modexp_stats
|
||||
{
|
||||
unsigned long modexp_512s;
|
||||
unsigned long modexp_1024s;
|
||||
} modexp_stats_t, *modexp_stats_pt;
|
||||
|
||||
typedef struct ecc_stats
|
||||
{
|
||||
unsigned long ecc_mul;
|
||||
unsigned long ecc_add;
|
||||
unsigned long ecc_dbl;
|
||||
unsigned long ecc_vfy;
|
||||
unsigned long ecc_bin_mul;
|
||||
unsigned long ecc_field_bin_inv;
|
||||
unsigned long ecc_field_bin_mul;
|
||||
unsigned long ecc_field_bin_add;
|
||||
unsigned long ecc_field_add;
|
||||
unsigned long ecc_field_sub;
|
||||
unsigned long ecc_field_mul;
|
||||
unsigned long ecc_field_inv;
|
||||
unsigned long ecc_field_div;
|
||||
unsigned long ecc_field_red;
|
||||
} ecc_stats_t, *ecc_stats_pt;
|
||||
|
||||
|
||||
typedef struct opt_stats
|
||||
{
|
||||
unsigned long combined;
|
||||
unsigned long unaligned_auth_dest;
|
||||
unsigned long sym_failed;
|
||||
unsigned long modexp_failed;
|
||||
unsigned long ecc_failed;
|
||||
} opt_stats_t, *opt_stats_pt;
|
||||
|
||||
typedef struct rmisec_stats
|
||||
{
|
||||
uint32_t sent;
|
||||
uint32_t received;
|
||||
uint32_t stats_mask;
|
||||
uint32_t control_mask;
|
||||
rwlock_t rmisec_control_lock;
|
||||
rwlock_t rmisec_stats_lock;
|
||||
char clear_start[0];
|
||||
uint64_t wait_time;
|
||||
uint32_t max_wait_time;
|
||||
uint32_t maxsnd_wait_time;
|
||||
uint32_t wait_count;
|
||||
hmac_stats_t hmac;
|
||||
cipher_stats_t cipher;
|
||||
modexp_stats_t modexp;
|
||||
ecc_stats_t ecc;
|
||||
opt_stats_t opt;
|
||||
} rmisec_stats_t, *rmisec_stats_pt;
|
||||
|
||||
|
||||
/* stats routines */
|
||||
|
||||
static void inline phxdrv_record_sent(rmisec_stats_pt stats)
|
||||
{
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->sent++;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
|
||||
static void inline phxdrv_record_received(rmisec_stats_pt stats)
|
||||
{
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->received++;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
|
||||
|
||||
static void inline phxdrv_record_des(rmisec_stats_pt stats, int enc,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_DES) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
if (enc) {
|
||||
stats->cipher.des_encrypts++;
|
||||
stats->cipher.des_encrypt_bytes += nbytes;
|
||||
}
|
||||
else {
|
||||
stats->cipher.des_decrypts++;
|
||||
stats->cipher.des_decrypt_bytes += nbytes;
|
||||
}
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void inline phxdrv_record_3des(rmisec_stats_pt stats, int enc,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_3DES) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
if (enc) {
|
||||
stats->cipher.des3_encrypts++;
|
||||
stats->cipher.des3_encrypt_bytes += nbytes;
|
||||
}
|
||||
else {
|
||||
stats->cipher.des3_decrypts++;
|
||||
stats->cipher.des3_decrypt_bytes += nbytes;
|
||||
}
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void inline phxdrv_record_aes(rmisec_stats_pt stats, int enc,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_AES) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
if (enc) {
|
||||
stats->cipher.aes_encrypts++;
|
||||
stats->cipher.aes_encrypt_bytes += nbytes;
|
||||
}
|
||||
else {
|
||||
stats->cipher.aes_decrypts++;
|
||||
stats->cipher.aes_decrypt_bytes += nbytes;
|
||||
}
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void inline phxdrv_record_arc4(rmisec_stats_pt stats, int enc,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_ARC4) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
if (enc) {
|
||||
stats->cipher.arc4_encrypts++;
|
||||
stats->cipher.arc4_encrypt_bytes += nbytes;
|
||||
}
|
||||
else {
|
||||
stats->cipher.arc4_decrypts++;
|
||||
stats->cipher.arc4_decrypt_bytes += nbytes;
|
||||
}
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void inline phxdrv_record_kasumi_f8(rmisec_stats_pt stats, int enc,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_KASUMI_F8) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
if (enc) {
|
||||
stats->cipher.kasumi_f8_encrypts++;
|
||||
stats->cipher.kasumi_f8_encrypt_bytes += nbytes;
|
||||
}
|
||||
else {
|
||||
stats->cipher.kasumi_f8_decrypts++;
|
||||
stats->cipher.kasumi_f8_decrypt_bytes += nbytes;
|
||||
}
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void inline phxdrv_record_modexp(rmisec_stats_pt stats,
|
||||
int blksize)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_MODEXP) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
if (blksize == 512) {
|
||||
stats->modexp.modexp_512s++;
|
||||
}
|
||||
if (blksize == 1024) {
|
||||
stats->modexp.modexp_1024s++;
|
||||
}
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void inline phxdrv_record_ecc(rmisec_stats_pt stats, PHX_ECC_OP op)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_ECC) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
switch (op) {
|
||||
case PHX_ECC_NOP:
|
||||
break;
|
||||
case PHX_ECC_MUL:
|
||||
stats->ecc.ecc_mul++;
|
||||
break;
|
||||
case PHX_ECC_BIN_MUL:
|
||||
stats->ecc.ecc_bin_mul++;
|
||||
break;
|
||||
case PHX_ECC_ADD:
|
||||
stats->ecc.ecc_add++;
|
||||
break;
|
||||
case PHX_ECC_DBL:
|
||||
stats->ecc.ecc_dbl++;
|
||||
break;
|
||||
case PHX_ECC_VFY:
|
||||
stats->ecc.ecc_vfy++;
|
||||
break;
|
||||
case PHX_ECC_FIELD_BIN_INV:
|
||||
stats->ecc.ecc_field_bin_inv++;
|
||||
break;
|
||||
case PHX_ECC_FIELD_BIN_MUL:
|
||||
stats->ecc.ecc_field_bin_mul++;
|
||||
break;
|
||||
case PHX_ECC_FIELD_BIN_ADD:
|
||||
stats->ecc.ecc_field_bin_add++;
|
||||
break;
|
||||
case PHX_ECC_FIELD_ADD:
|
||||
stats->ecc.ecc_field_add++;
|
||||
break;
|
||||
case PHX_ECC_FIELD_SUB:
|
||||
stats->ecc.ecc_field_sub++;
|
||||
break;
|
||||
case PHX_ECC_FIELD_MUL:
|
||||
stats->ecc.ecc_field_mul++;
|
||||
break;
|
||||
case PHX_ECC_FIELD_INV:
|
||||
stats->ecc.ecc_field_inv++;
|
||||
break;
|
||||
case PHX_ECC_FIELD_DIV:
|
||||
stats->ecc.ecc_field_div++;
|
||||
break;
|
||||
case PHX_ECC_FIELD_RED:
|
||||
stats->ecc.ecc_field_red++;
|
||||
break;
|
||||
case PHX_ECC_FIELD:
|
||||
case PHX_ECC_BIN:
|
||||
break;
|
||||
}
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void inline phxdrv_record_cipher_revert(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_CPHR_REVERTS) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->cipher.reverts++;
|
||||
stats->cipher.reverts_bytes += nbytes;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void inline phxdrv_record_hmac_revert(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_HMAC_REVERTS) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->hmac.reverts++;
|
||||
stats->hmac.reverts_bytes += nbytes;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void inline phxdrv_record_md5(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_MD5) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->hmac.md5_count++;
|
||||
stats->hmac.md5_bytes += nbytes;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void inline phxdrv_record_sha1(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_SHA1) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->hmac.sha1_count++;
|
||||
stats->hmac.sha1_bytes += nbytes;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void inline phxdrv_record_sha256(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_SHA256) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->hmac.sha256_count++;
|
||||
stats->hmac.sha256_bytes += nbytes;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void inline phxdrv_record_sha384(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_SHA384) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->hmac.sha384_count++;
|
||||
stats->hmac.sha384_bytes += nbytes;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void inline phxdrv_record_sha512(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_SHA512) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->hmac.sha512_count++;
|
||||
stats->hmac.sha512_bytes += nbytes;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void inline phxdrv_record_gcm(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_GCM) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->hmac.gcm_count++;
|
||||
stats->hmac.gcm_bytes += nbytes;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void inline phxdrv_record_kasumi_f9(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_KASUMI_F9) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->hmac.kasumi_f9_count++;
|
||||
stats->hmac.kasumi_f9_bytes += nbytes;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void inline phxdrv_record_unaligned_auth_dest(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_UNALIGNED_AUTH_DEST) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->opt.unaligned_auth_dest++;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void inline phxdrv_record_combined(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_COMBINED) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->opt.combined++;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void inline phxdrv_record_sym_failed(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_COMBINED) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->opt.sym_failed++;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void inline phxdrv_record_modexp_failed(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_COMBINED) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->opt.modexp_failed++;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void inline phxdrv_record_ecc_failed(rmisec_stats_pt stats,
|
||||
int nbytes)
|
||||
{
|
||||
if (stats->stats_mask & PHXDRV_PROFILE_COMBINED) {
|
||||
write_lock(&stats->rmisec_stats_lock);
|
||||
stats->opt.ecc_failed++;
|
||||
write_unlock(&stats->rmisec_stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -213,6 +213,7 @@ iodi_attach(device_t dev)
|
||||
device_add_child(dev, "uart", 0);
|
||||
device_add_child(dev, "xlr_i2c", 0);
|
||||
device_add_child(dev, "pcib", 0);
|
||||
device_add_child(dev, "rmisec", -1);
|
||||
|
||||
if (xlr_board_info.usb)
|
||||
device_add_child(dev, "ehci", 0);
|
||||
|
Loading…
Reference in New Issue
Block a user