diff options
author | Jason Wright <jason@cvs.openbsd.org> | 2001-06-22 23:53:53 +0000 |
---|---|---|
committer | Jason Wright <jason@cvs.openbsd.org> | 2001-06-22 23:53:53 +0000 |
commit | 8baaab2c26a195784fa8b47805ab634a25adb158 (patch) | |
tree | ef49bcfac4f2661099e902da823fdcba1befa437 /sys/dev | |
parent | 46ddffab2646372ea2b2da6815397809abe58c77 (diff) |
Fix lotsa bugs:
- Hi/Fn length fields in command structures are 18 bits (feature!), but
descriptor lengths are 16 bits.
- define dmamap maximum lengths correctly (2^18 for total length, 2^16
for segments).
- Make the defines more consistent, and add other modes
- split source_count in command descriptors into a 16 bit length, and 16bit reserved part
upshot: blocks as large as 2^18 - 8 work now for userland crypto
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/pci/hifn7751.c | 31 | ||||
-rw-r--r-- | sys/dev/pci/hifn7751reg.h | 63 | ||||
-rw-r--r-- | sys/dev/pci/hifn7751var.h | 6 |
3 files changed, 67 insertions, 33 deletions
diff --git a/sys/dev/pci/hifn7751.c b/sys/dev/pci/hifn7751.c index 2c7488028b8..adca99cc31b 100644 --- a/sys/dev/pci/hifn7751.c +++ b/sys/dev/pci/hifn7751.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hifn7751.c,v 1.70 2001/06/22 19:02:44 jason Exp $ */ +/* $OpenBSD: hifn7751.c,v 1.71 2001/06/22 23:53:52 jason Exp $ */ /* * Invertex AEON / Hi/fn 7751 driver @@ -883,6 +883,7 @@ hifn_write_command(cmd, buf) hifn_mac_command_t *mac_cmd; hifn_crypt_command_t *cry_cmd; int using_mac, using_crypt, len; + u_int32_t dlen; buf_pos = buf; using_mac = cmd->base_masks & HIFN_BASE_CMD_MAC; @@ -890,24 +891,34 @@ hifn_write_command(cmd, buf) base_cmd = (hifn_base_command_t *)buf_pos; base_cmd->masks = cmd->base_masks; - base_cmd->total_source_count = cmd->src_map->dm_mapsize; - base_cmd->total_dest_count = cmd->dst_map->dm_mapsize; - base_cmd->session_num = cmd->session_num; + dlen = cmd->src_map->dm_mapsize; + base_cmd->total_source_count = dlen & HIFN_BASE_CMD_LENMASK_LO; + base_cmd->total_dest_count = dlen & HIFN_BASE_CMD_LENMASK_HI; + dlen >>= 16; + base_cmd->session_num = cmd->session_num | + ((dlen << HIFN_BASE_CMD_SRCLEN_S) & HIFN_BASE_CMD_SRCLEN_M) | + ((dlen << HIFN_BASE_CMD_DSTLEN_S) & HIFN_BASE_CMD_DSTLEN_M); buf_pos += sizeof(hifn_base_command_t); if (using_mac) { mac_cmd = (hifn_mac_command_t *)buf_pos; - mac_cmd->masks = cmd->mac_masks; + dlen = cmd->mac_process_len; + mac_cmd->source_count = dlen & 0xffff; + dlen >>= 16; + mac_cmd->masks = cmd->mac_masks | + ((dlen << HIFN_MAC_CMD_SRCLEN_S) & HIFN_MAC_CMD_SRCLEN_M); mac_cmd->header_skip = cmd->mac_header_skip; - mac_cmd->source_count = cmd->mac_process_len; buf_pos += sizeof(hifn_mac_command_t); } if (using_crypt) { cry_cmd = (hifn_crypt_command_t *)buf_pos; - cry_cmd->masks = cmd->cry_masks; + dlen = cmd->crypt_process_len; + cry_cmd->source_count = dlen & 0xffff; + dlen >>= 16; + cry_cmd->masks = cmd->cry_masks | + ((dlen << HIFN_CRYPT_CMD_SRCLEN_S) & HIFN_CRYPT_CMD_SRCLEN_M); cry_cmd->header_skip = cmd->crypt_header_skip; - cry_cmd->source_count = cmd->crypt_process_len; buf_pos += sizeof(hifn_crypt_command_t); } @@ -986,8 +997,8 @@ hifn_crypto(sc, cmd, crp) u_int32_t cmdlen; int cmdi, resi, s; - if (bus_dmamap_create(sc->sc_dmat, HIFN_MAX_SEGLEN * MAX_SCATTER, - MAX_SCATTER, HIFN_MAX_SEGLEN, 0, BUS_DMA_NOWAIT, &cmd->src_map)) + if (bus_dmamap_create(sc->sc_dmat, HIFN_MAX_DMALEN, MAX_SCATTER, + HIFN_MAX_SEGLEN, 0, BUS_DMA_NOWAIT, &cmd->src_map)) return (-1); if (crp->crp_flags & CRYPTO_F_IMBUF) { diff --git a/sys/dev/pci/hifn7751reg.h b/sys/dev/pci/hifn7751reg.h index 3bec8ae4335..2d902a7b010 100644 --- a/sys/dev/pci/hifn7751reg.h +++ b/sys/dev/pci/hifn7751reg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hifn7751reg.h,v 1.20 2001/06/22 19:02:43 jason Exp $ */ +/* $OpenBSD: hifn7751reg.h,v 1.21 2001/06/22 23:53:52 jason Exp $ */ /* * Invertex AEON / Hi/fn 7751 driver @@ -375,9 +375,15 @@ typedef struct hifn_base_command { volatile u_int16_t total_dest_count; } hifn_base_command_t; -#define HIFN_BASE_CMD_MAC (0x1 << 10) -#define HIFN_BASE_CMD_CRYPT (0x1 << 11) -#define HIFN_BASE_CMD_DECODE (0x1 << 13) +#define HIFN_BASE_CMD_MAC 0x0400 +#define HIFN_BASE_CMD_CRYPT 0x0800 +#define HIFN_BASE_CMD_DECODE 0x2000 +#define HIFN_BASE_CMD_SRCLEN_M 0xc000 +#define HIFN_BASE_CMD_SRCLEN_S 14 +#define HIFN_BASE_CMD_DSTLEN_M 0x3000 +#define HIFN_BASE_CMD_DSTLEN_S 12 +#define HIFN_BASE_CMD_LENMASK_HI 0x30000 +#define HIFN_BASE_CMD_LENMASK_LO 0x0ffff /* * Structure to help build up the command data structure. @@ -385,15 +391,25 @@ typedef struct hifn_base_command { typedef struct hifn_crypt_command { volatile u_int16_t masks; volatile u_int16_t header_skip; - volatile u_int32_t source_count; + volatile u_int16_t source_count; + volatile u_int16_t reserved; } hifn_crypt_command_t; -#define HIFN_CRYPT_CMD_ALG_MASK (0x3 << 0) -#define HIFN_CRYPT_CMD_ALG_DES (0x0 << 0) -#define HIFN_CRYPT_CMD_ALG_3DES (0x1 << 0) -#define HIFN_CRYPT_CMD_MODE_CBC (0x1 << 3) -#define HIFN_CRYPT_CMD_NEW_KEY (0x1 << 11) -#define HIFN_CRYPT_CMD_NEW_IV (0x1 << 12) +#define HIFN_CRYPT_CMD_ALG_MASK 0x0003 /* algorithm: */ +#define HIFN_CRYPT_CMD_ALG_DES 0x0000 /* DES */ +#define HIFN_CRYPT_CMD_ALG_3DES 0x0001 /* 3DES */ +#define HIFN_CRYPT_CMD_ALG_RC4 0x0002 /* RC4 */ +#define HIFN_CRYPT_CMD_MODE_MASK 0x0018 /* DES mode: */ +#define HIFN_CRYPT_CMD_MODE_ECB 0x0000 /* ECB */ +#define HIFN_CRYPT_CMD_MODE_CBC 0x0008 /* CBC */ +#define HIFN_CRYPT_CMD_MODE_CFB 0x0010 /* CFB */ +#define HIFN_CRYPT_CMD_MODE_OFB 0x0018 /* OFB */ +#define HIFN_CRYPT_CMD_CLR_CTX 0x0040 /* clear context */ +#define HIFN_CRYPT_CMD_NEW_KEY 0x0800 /* expect new key */ +#define HIFN_CRYPT_CMD_NEW_IV 0x1000 /* expect new iv */ + +#define HIFN_CRYPT_CMD_SRCLEN_M 0xc000 +#define HIFN_CRYPT_CMD_SRCLEN_S 14 /* * Structure to help build up the command data structure. @@ -401,15 +417,22 @@ typedef struct hifn_crypt_command { typedef struct hifn_mac_command { volatile u_int16_t masks; volatile u_int16_t header_skip; - volatile u_int32_t source_count; + volatile u_int16_t source_count; + volatile u_int16_t reserved; } hifn_mac_command_t; -#define HIFN_MAC_CMD_ALG_MD5 (0x1 << 0) -#define HIFN_MAC_CMD_ALG_SHA1 (0x0 << 0) -#define HIFN_MAC_CMD_MODE_HMAC (0x0 << 2) -#define HIFN_MAC_CMD_TRUNC (0x1 << 4) -#define HIFN_MAC_CMD_RESULT (0x1 << 5) -#define HIFN_MAC_CMD_APPEND (0x1 << 6) +#define HIFN_MAC_CMD_ALG_MASK 0x0001 +#define HIFN_MAC_CMD_ALG_SHA1 0x0000 +#define HIFN_MAC_CMD_ALG_MD5 0x0001 +#define HIFN_MAC_CMD_MODE_MASK 0x0004 +#define HIFN_MAC_CMD_MODE_HMAC 0x0000 +#define HIFN_MAC_CMD_MODE_FULL 0x0004 +#define HIFN_MAC_CMD_TRUNC 0x0010 +#define HIFN_MAC_CMD_RESULT 0x0020 +#define HIFN_MAC_CMD_APPEND 0x0040 +#define HIFN_MAC_CMD_SRCLEN_M 0xc000 +#define HIFN_MAC_CMD_SRCLEN_S 14 + /* * MAC POS IPSec initiates authentication after encryption on encodes * and before decryption on decodes. @@ -429,6 +452,6 @@ typedef struct hifn_mac_command { #define HIFN_POLL_SCALAR 0x0 #endif -#define HIFN_MAX_SEGLEN 0xfffc - +#define HIFN_MAX_SEGLEN 0xffff /* maximum dma segment len */ +#define HIFN_MAX_DMALEN 0x3ffff /* maximum dma length */ #endif /* __HIFN_H__ */ diff --git a/sys/dev/pci/hifn7751var.h b/sys/dev/pci/hifn7751var.h index c6294829e9d..ea5e185a770 100644 --- a/sys/dev/pci/hifn7751var.h +++ b/sys/dev/pci/hifn7751var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hifn7751var.h,v 1.21 2001/05/14 02:45:19 deraadt Exp $ */ +/* $OpenBSD: hifn7751var.h,v 1.22 2001/06/22 23:53:52 jason Exp $ */ /* * Invertex AEON / Hi/fn 7751 driver @@ -183,8 +183,8 @@ typedef struct hifn_command { struct uio *dst_io; bus_dmamap_t dst_map; - u_short mac_header_skip, mac_process_len; - u_short crypt_header_skip, crypt_process_len; + u_int16_t crypt_header_skip, mac_header_skip; + u_int32_t crypt_process_len, mac_process_len; u_long private_data; struct hifn_softc *softc; |