summaryrefslogtreecommitdiff
path: root/sys/dev/pci
diff options
context:
space:
mode:
authorJason Wright <jason@cvs.openbsd.org>2004-01-20 21:01:56 +0000
committerJason Wright <jason@cvs.openbsd.org>2004-01-20 21:01:56 +0000
commit314a724691a0297dfd4933e2b84d891dac740483 (patch)
treeb61e2ecae68d5d0fcbf59f1459bb5368d9847567 /sys/dev/pci
parent1429df89fad8239978803f903cd05285ab37498d (diff)
don't limit the number of sessions to the onboard ram (always upload the
key and IV data). This kinda sucks for HMAC, but the alternative is a cache manager and I just don't want to go there. Tested by sturm@ (thanks!)
Diffstat (limited to 'sys/dev/pci')
-rw-r--r--sys/dev/pci/hifn7751.c78
-rw-r--r--sys/dev/pci/hifn7751var.h13
2 files changed, 47 insertions, 44 deletions
diff --git a/sys/dev/pci/hifn7751.c b/sys/dev/pci/hifn7751.c
index 41902bdf44e..11c35bb78bd 100644
--- a/sys/dev/pci/hifn7751.c
+++ b/sys/dev/pci/hifn7751.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hifn7751.c,v 1.145 2004/01/09 21:32:24 brad Exp $ */
+/* $OpenBSD: hifn7751.c,v 1.146 2004/01/20 21:01:55 jason Exp $ */
/*
* Invertex AEON / Hifn 7751 driver
@@ -1159,7 +1159,7 @@ hifn_write_command(struct hifn_command *cmd, u_int8_t *buf)
base_cmd->total_dest_count = htole16(dlen & HIFN_BASE_CMD_LENMASK_LO);
dlen >>= 16;
slen >>= 16;
- base_cmd->session_num = htole16(cmd->session_num |
+ base_cmd->session_num = htole16(
((slen << HIFN_BASE_CMD_SRCLEN_S) & HIFN_BASE_CMD_SRCLEN_M) |
((dlen << HIFN_BASE_CMD_DSTLEN_S) & HIFN_BASE_CMD_DSTLEN_M));
buf_pos += sizeof(struct hifn_base_command);
@@ -1813,7 +1813,8 @@ hifn_newsession(u_int32_t *sidp, struct cryptoini *cri)
{
struct cryptoini *c;
struct hifn_softc *sc = NULL;
- int i, mac = 0, cry = 0, comp = 0;
+ int i, mac = 0, cry = 0, comp = 0, sesn;
+ struct hifn_session *ses = NULL;
if (sidp == NULL || cri == NULL)
return (EINVAL);
@@ -1828,11 +1829,37 @@ hifn_newsession(u_int32_t *sidp, struct cryptoini *cri)
if (sc == NULL)
return (EINVAL);
- for (i = 0; i < sc->sc_maxses; i++)
- if (sc->sc_sessions[i].hs_state == HS_STATE_FREE)
- break;
- if (i == sc->sc_maxses)
- return (ENOMEM);
+ if (sc->sc_sessions == NULL) {
+ ses = sc->sc_sessions = (struct hifn_session *)malloc(
+ sizeof(*ses), M_DEVBUF, M_NOWAIT);
+ if (ses == NULL)
+ return (ENOMEM);
+ sesn = 0;
+ sc->sc_nsessions = 1;
+ } else {
+ for (sesn = 0; sesn < sc->sc_nsessions; sesn++) {
+ if (!sc->sc_sessions[sesn].hs_used) {
+ ses = &sc->sc_sessions[sesn];
+ break;
+ }
+ }
+
+ if (ses == NULL) {
+ sesn = sc->sc_nsessions;
+ ses = (struct hifn_session *)malloc((sesn + 1) *
+ sizeof(*ses), M_DEVBUF, M_NOWAIT);
+ if (ses == NULL)
+ return (ENOMEM);
+ 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];
+ sc->sc_nsessions++;
+ }
+ }
+ bzero(ses, sizeof(*ses));
+ ses->hs_used = 1;
for (c = cri; c != NULL; c = c->cri_next) {
switch (c->cri_alg) {
@@ -1847,7 +1874,7 @@ hifn_newsession(u_int32_t *sidp, struct cryptoini *cri)
case CRYPTO_DES_CBC:
case CRYPTO_3DES_CBC:
case CRYPTO_AES_CBC:
- get_random_bytes(sc->sc_sessions[i].hs_iv,
+ get_random_bytes(ses->hs_iv,
(c->cri_alg == CRYPTO_AES_CBC ?
HIFN_AES_IV_LENGTH : HIFN_IV_LENGTH));
/*FALLTHROUGH*/
@@ -1875,8 +1902,7 @@ hifn_newsession(u_int32_t *sidp, struct cryptoini *cri)
if ((comp && mac) || (comp && cry))
return (EINVAL);
- *sidp = HIFN_SID(sc->sc_dv.dv_unit, i);
- sc->sc_sessions[i].hs_state = HS_STATE_USED;
+ *sidp = HIFN_SID(sc->sc_dv.dv_unit, sesn);
return (0);
}
@@ -1899,7 +1925,7 @@ hifn_freesession(u_int64_t tid)
sc = hifn_cd.cd_devs[card];
session = HIFN_SESSION(sid);
- if (session >= sc->sc_maxses)
+ if (session >= sc->sc_nsessions)
return (EINVAL);
bzero(&sc->sc_sessions[session], sizeof(sc->sc_sessions[session]));
@@ -1927,7 +1953,7 @@ hifn_process(struct cryptop *crp)
sc = hifn_cd.cd_devs[card];
session = HIFN_SESSION(crp->crp_sid);
- if (session >= sc->sc_maxses) {
+ if (session >= sc->sc_nsessions) {
err = EINVAL;
goto errout;
}
@@ -2018,10 +2044,6 @@ hifn_process(struct cryptop *crp)
switch (enccrd->crd_alg) {
case CRYPTO_ARC4:
cmd->cry_masks |= HIFN_CRYPT_CMD_ALG_RC4;
- if ((enccrd->crd_flags & CRD_F_ENCRYPT)
- != sc->sc_sessions[session].hs_prev_op)
- sc->sc_sessions[session].hs_state =
- HS_STATE_USED;
break;
case CRYPTO_DES_CBC:
cmd->cry_masks |= HIFN_CRYPT_CMD_ALG_DES |
@@ -2079,6 +2101,7 @@ hifn_process(struct cryptop *crp)
cmd->ck = enccrd->crd_key;
cmd->cklen = enccrd->crd_klen >> 3;
+ cmd->cry_masks |= HIFN_CRYPT_CMD_NEW_KEY;
/*
* Need to specify the size for the AES key in the masks.
@@ -2100,9 +2123,6 @@ hifn_process(struct cryptop *crp)
goto errout;
}
}
-
- if (sc->sc_sessions[session].hs_state == HS_STATE_USED)
- cmd->cry_masks |= HIFN_CRYPT_CMD_NEW_KEY;
}
if (maccrd) {
@@ -2132,9 +2152,8 @@ hifn_process(struct cryptop *crp)
break;
}
- if ((maccrd->crd_alg == CRYPTO_SHA1_HMAC ||
- maccrd->crd_alg == CRYPTO_MD5_HMAC) &&
- sc->sc_sessions[session].hs_state == HS_STATE_USED) {
+ if (maccrd->crd_alg == CRYPTO_SHA1_HMAC ||
+ maccrd->crd_alg == CRYPTO_MD5_HMAC) {
cmd->mac_masks |= HIFN_MAC_CMD_NEW_KEY;
bcopy(maccrd->crd_key, cmd->mac, maccrd->crd_klen >> 3);
bzero(cmd->mac + (maccrd->crd_klen >> 3),
@@ -2147,14 +2166,8 @@ hifn_process(struct cryptop *crp)
cmd->softc = sc;
err = hifn_crypto(sc, cmd, crp);
- if (!err) {
- if(enccrd)
- sc->sc_sessions[session].hs_prev_op=enccrd->crd_flags
- & CRD_F_ENCRYPT;
- if (sc->sc_sessions[session].hs_state == HS_STATE_USED)
- sc->sc_sessions[session].hs_state = HS_STATE_KEY;
+ if (!err)
return 0;
- }
errout:
if (cmd != NULL)
@@ -2230,11 +2243,6 @@ hifn_abort(struct hifn_softc *sc)
}
dma->resk = i; dma->resu = u;
- /* Force upload of key next time */
- for (i = 0; i < sc->sc_maxses; i++)
- if (sc->sc_sessions[i].hs_state == HS_STATE_KEY)
- sc->sc_sessions[i].hs_state = HS_STATE_USED;
-
hifn_reset_board(sc, 1);
hifn_init_dma(sc);
hifn_init_pci_registers(sc);
diff --git a/sys/dev/pci/hifn7751var.h b/sys/dev/pci/hifn7751var.h
index b168afa4338..64918d472db 100644
--- a/sys/dev/pci/hifn7751var.h
+++ b/sys/dev/pci/hifn7751var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: hifn7751var.h,v 1.51 2003/10/09 03:47:20 jason Exp $ */
+/* $OpenBSD: hifn7751var.h,v 1.52 2004/01/20 21:01:55 jason Exp $ */
/*
* Invertex AEON / Hifn 7751 driver
@@ -103,16 +103,10 @@ struct hifn_dma {
};
struct hifn_session {
- int hs_state;
- int hs_prev_op; /* XXX collapse into hs_flags? */
+ int hs_used;
u_int8_t hs_iv[HIFN_MAX_IV_LENGTH];
};
-/* We use a state machine on sessions */
-#define HS_STATE_FREE 0 /* unused session entry */
-#define HS_STATE_USED 1 /* allocated, but key not on card */
-#define HS_STATE_KEY 2 /* allocated and key is on card */
-
#define HIFN_RING_SYNC(sc, r, i, f) \
bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap, \
offsetof(struct hifn_dma, r[i]), sizeof(struct hifn_desc), (f))
@@ -151,6 +145,7 @@ struct hifn_softc {
int sc_dmansegs;
int32_t sc_cid;
int sc_maxses;
+ int sc_nsessions;
int sc_ramsize;
int sc_flags;
#define HIFN_HAS_RNG 0x01 /* includes random number generator */
@@ -164,7 +159,7 @@ struct hifn_softc {
int sc_rngfirst;
int sc_rnghz;
int sc_c_busy, sc_s_busy, sc_d_busy, sc_r_busy, sc_active;
- struct hifn_session sc_sessions[2048];
+ struct hifn_session *sc_sessions;
pci_chipset_tag_t sc_pci_pc;
pcitag_t sc_pci_tag;
bus_size_t sc_waw_lastreg;