dca.h revision 436935a13231964207120b7e50a063b53b8e579c
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SYS_CRYPTO_DCA_H
#define _SYS_CRYPTO_DCA_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* Deimos - cryptographic acceleration based upon Broadcom 582x.
*
* Note: Everything in this file is private to the Deimos device
* driver! Do not include this in any other file.
*/
#define DRIVER "dca"
#define DCA_MANUFACTURER_ID "SUNWdca"
#ifdef _KERNEL
/*
* Tunables.
*/
#define MCR1HIWATER 24
#define MCR1MAXREQS 8
#define MCR2LOWATER 16
#define MCR2HIWATER 24
#define MCR2MAXREQS 4
/*
* These are constants. Do not change them.
*/
#else
#endif
#define DES_KEYSIZE 8
#define DES_IV_LEN 8
/*
* Mechanism info structure passed to KCF during registration.
*/
/*
* RSA implementation.
*/
#define DCA_RSA_ENC 0
#define DCA_RSA_DEC 1
#define DCA_RSA_SIGN 2
#define DCA_RSA_VRFY 3
#define DCA_RSA_SIGNR 4
#define DCA_RSA_VRFYR 5
/*
* DSA implementation.
*/
#define DCA_DSA_SIGN 0
#define DCA_DSA_VRFY 1
/*
* FMA eclass index definitions. Note that this enum must be consistent
* with the dca_fma_eclass_sca1000 and dca_fma_eclass_sca500 string arrays.
*/
typedef enum dca_fma_eclass {
/*
* Forward typedefs.
*/
typedef struct dca_chain dca_chain_t;
typedef struct dca_listnode dca_listnode_t;
typedef struct dca_worklist dca_worklist_t;
typedef struct dca_work dca_work_t;
typedef struct dca_request dca_request_t;
typedef struct dca_stat dca_stat_t;
typedef struct dca_cookie dca_cookie_t;
typedef struct dca_device dca_device_t;
/*
* This structure is used to identify a specific board.
*/
struct dca_device {
char *dd_model;
};
/*
* Structure representing a node in a DMA chain. (Broadcom calls
* these "Data Buffer Chain Entries".)
*
* note, this structure must be a multiple of sizeof (intptr_t)
*/
struct dca_chain {
/* the descriptor */
/* and the buffer to which it points */
/* physical addresses */
};
/*
* Linked-list linkage.
*/
struct dca_listnode {
};
typedef enum dca_mech_type {
DES_CBC_MECH_INFO_TYPE, /* SUN_CKM_DES_CBC */
DES3_CBC_MECH_INFO_TYPE, /* SUN_CKM_DES3_CBC */
DSA_MECH_INFO_TYPE, /* SUN_CKM_DSA */
RSA_X_509_MECH_INFO_TYPE, /* SUN_CKM_RSA_X_509 */
RSA_PKCS_MECH_INFO_TYPE /* SUN_CKM_RSA_PKCS */
#define SUN_CKM_DSA "CKM_DSA"
struct dca_rng {
};
union dca_parameters {
};
typedef struct dca_ctx {
/*
* The following are context fields for Deimos 2.0.
*/
int mode; /* Mode of operation */
int atomic; /* Boolean */
/* Fields for RSA and DSA */
unsigned modlen; /* RSA modulus length */
unsigned pqfix; /* RSA flag */
/* Fields for DES and 3DES */
int residlen;
int activeresidlen;
} dca_ctx_t;
/*
* Work structure. One of these per actual job submitted to an MCR.
* Contains everything we need to submit the job, and everything we
* need to notify caller and release resources when the completion
* interrupt comes.
*/
struct dca_request {
/*
* Consumer's I/O buffers.
*/
/*
* Chains and DMA structures.
*/
/*
* Scratch input buffer.
*/
/*
* Scratch output buffer.
*/
/*
* Values to program MCR with.
*/
/*
* Callback.
*/
void (*dr_callback)(dca_request_t *, int);
/*
* Other stuff.
*/
/*
* Algorithm specific parameters.
*/
void *dr_context;
union dca_parameters dr_param;
/*
* Statistics.
*/
int dr_job_stat;
int dr_byte_stat;
/* Pre-mapped input and output data buffer chain support */
/*
* User buffers are mapped to DMA handles dynamically. The physically
* contigous blocks ( >= a page) are built into a data buffer chain.
*/
/* Offset in the context page for storing dynamic buffer chains */
int dr_offset;
/* Destroy this request if true */
int destroy;
};
/*
* Request flags (dca_request_t.dr_flags).
*/
#define DR_INPLACE 0x002
#define DR_SCATTER 0x004
#define DR_GATHER 0x008
#define DR_NOCACHE 0x020
#define DR_ENCRYPT 0x040
#define DR_DECRYPT 0x080
struct dca_work {
/* DMA access to the MCR and context */
};
/*
* MCRs.
*/
#define MCR1 0x1
#define MCR2 0x2
struct dca_worklist {
char dwl_name[16];
int dwl_mcr;
int dwl_count;
int dwl_busy;
int dwl_lowater;
int dwl_hiwater;
int dwl_reqspermcr;
int dwl_drain; /* for DR (suspend) */
/* Kstats */
};
/*
* Operations for MCR1 (bulk stuff).
*/
/*
* Operations for MCR2 (key stuff).
*/
/*
* Kstats.
*/
#define DS_3DESJOBS 0
#define DS_3DESBYTES 1
#define DS_RSAPUBLIC 2
#define DS_RSAPRIVATE 3
#define DS_DSASIGN 4
#define DS_DSAVERIFY 5
#define DS_RNGJOBS 6
#define DS_RNGBYTES 7
#define DS_RNGSHA1JOBS 8
#define DS_RNGSHA1BYTES 9
#define DS_MAX 10
#if 0
/*
* note that when reenabling any of these stats, DS_MAX will need to
* be adjusted.
*/
#define DS_RC4JOBS 11
#define DS_RC4BYTES 12
#define DS_DHPUBLIC 13
#define DS_DHSECRET 14
#endif
struct dca_stat {
struct {
};
/*
* Blocking structure for ioctls.
*/
struct dca_cookie {
int dc_outstanding;
int dc_status;
};
/*
* Per instance structure.
*/
struct dca {
unsigned dca_flags; /* dev state flags */
/*
* Work requests.
*/
/*
* hardware model
*/
char *dca_model;
/*
* Kstats. There is no standard for what standards
* Cryptographic Providers should supply, so we're
* making them up for now.
*/
/* For the local random number pool used internally by the dca driver */
char *dca_buf1;
char *dca_buf2;
char *dca_buf_ptr;
int dca_index;
/* FMA capabilities */
int fm_capabilities; /* FMA capabilities */
};
/*
* Device flags (dca_t.dca_flags)
*/
#define DCA_FAILED 0x1
#define DCA_POWERMGMT 0x4
#define DCA_RNGSHA1 0x8
/*
*/
typedef enum dca_sg_param {
DCA_SG_CONTIG = 1,
#define FALSE 0
#define TRUE 1
/*
* PCI configuration registers.
*/
/*
* PCI configuration register bit values.
*/
/* Note: 5820 errata: BIST feature does not work */
/*
* Command and Status Registers.
*/
/*
* Command and status register bits.
*/
/*
* Offsets of things relative to an MCR.
*/
#define MCR_COUNT 0 /* 16 bits */
/*
* Basis for size (should be optimized by constant folding):
* 4 bytes for flags and #packets.
* for each packet:
* 2 descriptors (DESC_SIZE)
* 4 bytes for context address
* 4 bytes for packet length and reserved
*/
/*
* MCR flags.
*/
/*
* Fields within a descriptor (data buffer chain).
*/
#define DESC_BUFADDR 0 /* 32 bits */
/*
* Offsets of fields within context structures, see Broadcom spec.
*/
#define CTX_LENGTH 0 /* 16 bits */
/*
* Values for specific operations.
*/
#define CTX_DSAMSGTYPE_SHA1 0 /* Message is SHA1 */
#define CTX_DSARNG_SUPPLY 0 /* Random k is supplied */
/*
* Macros to access fields within the MCR. Note that this includes the
* context fields as well, since the context is just offset from the
* base of the MCR.
*/
/* XXX: define the GET forms for descriptors only if needed */
/*
* Register access.
*/
/*
* Used to guarantee alignment.
*/
#define ROUNDDOWN(a, n) (((a) & ~((n) - 1)))
#define LODBLWORD(x) ((x) & 0xffffffffULL)
/*
* Driver hardening related.
*/
/*
* Other utility macros.
*/
#define BITS2BYTES(b) ((b) >> 3)
/*
* Debug stuff.
*/
#ifdef DEBUG
#define DWARN 0x0001
#define DPCI 0x0002
#define DINTR 0x0004
#define DSTART 0x0008
#define DRECLAIM 0x0010
#define DCHATTY 0x0020
void dca_dprintf(dca_t *, int, const char *, ...);
#define DBG dca_dprintf
#else
#endif
/*
* Some pkcs#11 defines as there are no pkcs#11 header files included.
*/
#define CKO_PUBLIC_KEY 0x00000002
#define CKO_PRIVATE_KEY 0x00000003
#define CKA_CLASS 0x00000000
#define CKA_VALUE 0x00000011
#define CKA_KEY_TYPE 0x00000100
#define CKA_MODULUS 0x00000120
#define CKA_PUBLIC_EXPONENT 0x00000122
#define CKA_PRIVATE_EXPONENT 0x00000123
#define CKA_PRIME_1 0x00000124
#define CKA_PRIME_2 0x00000125
#define CKA_EXPONENT_1 0x00000126
#define CKA_EXPONENT_2 0x00000127
#define CKA_COEFFICIENT 0x00000128
#define CKA_PRIME 0x00000130
#define CKA_SUBPRIME 0x00000131
#define CKA_BASE 0x00000132
/*
* Driver globals.
*/
extern int dca_mindma;
extern int dca_hardening;
/*
* Prototypes.
*/
/*
*/
void dca_diperror(dev_info_t *, const char *, ...);
/*
*/
int, int);
crypto_req_handle_t, int);
crypto_req_handle_t, int);
int, crypto_req_handle_t, int);
void dca_3desctxfree(void *);
/*
*/
crypto_req_handle_t, int);
void dca_rsactxfree(void *);
int, crypto_req_handle_t, int);
/*
*/
int);
void dca_dsactxfree(void *);
int, crypto_req_handle_t, int);
/*
*/
int dca_random_init();
void dca_random_fini();
/*
*/
void dca_ksinit(dca_t *);
/*
* dca.c
*/
void dca_rmqueue(dca_listnode_t *);
void dca_freereq(dca_request_t *);
int dca_unbindchains(dca_request_t *);
void dca_done(dca_request_t *, int);
void dca_destroyreq(dca_request_t *);
int dca_length(crypto_data_t *);
int dca_gather(crypto_data_t *, char *, int, int);
int dca_resid_gather(crypto_data_t *, char *, int *, char *, int);
int dca_scatter(const char *, crypto_data_t *, int, int);
uint32_t *);
uint64_t, void **, unsigned int *);
void dca_rcoalesce(dca_request_t *, int);
void dca_runcoalesce(dca_request_t *);
int dca_bitlen(unsigned char *, int);
uint16_t dca_padhalf(int);
uint16_t dca_padfull(int);
void dca_reverse(void *, void *, int, int);
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_CRYPTO_DCA_H */