Home | History | Annotate | Line # | Download | only in pci
ubsecvar.h revision 1.7
      1  1.6       bad /*	$NetBSD: ubsecvar.h,v 1.7 2013/11/17 23:20:18 bad Exp $	*/
      2  1.1  jonathan /*	$OpenBSD: ubsecvar.h,v 1.36 2003/06/04 16:02:41 jason Exp $	*/
      3  1.1  jonathan 
      4  1.1  jonathan /*
      5  1.1  jonathan  * Copyright (c) 2000 Theo de Raadt
      6  1.1  jonathan  * Copyright (c) 2001 Patrik Lindergren (patrik (at) ipunplugged.com)
      7  1.1  jonathan  *
      8  1.1  jonathan  * Redistribution and use in source and binary forms, with or without
      9  1.1  jonathan  * modification, are permitted provided that the following conditions
     10  1.1  jonathan  * are met:
     11  1.1  jonathan  *
     12  1.1  jonathan  * 1. Redistributions of source code must retain the above copyright
     13  1.1  jonathan  *    notice, this list of conditions and the following disclaimer.
     14  1.1  jonathan  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  jonathan  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  jonathan  *    documentation and/or other materials provided with the distribution.
     17  1.1  jonathan  *
     18  1.1  jonathan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1  jonathan  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1  jonathan  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1  jonathan  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1  jonathan  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.1  jonathan  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.1  jonathan  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.1  jonathan  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.1  jonathan  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  1.1  jonathan  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.1  jonathan  *
     29  1.1  jonathan  * Effort sponsored in part by the Defense Advanced Research Projects
     30  1.1  jonathan  * Agency (DARPA) and Air Force Research Laboratory, Air Force
     31  1.1  jonathan  * Materiel Command, USAF, under agreement number F30602-01-2-0537.
     32  1.1  jonathan  *
     33  1.1  jonathan  */
     34  1.1  jonathan 
     35  1.1  jonathan /* Maximum queue length */
     36  1.1  jonathan #ifndef UBS_MAX_NQUEUE
     37  1.1  jonathan #define UBS_MAX_NQUEUE		60
     38  1.1  jonathan #endif
     39  1.1  jonathan 
     40  1.1  jonathan #define	UBS_MAX_SCATTER		64	/* Maximum scatter/gather depth */
     41  1.1  jonathan 
     42  1.1  jonathan #ifndef UBS_MAX_AGGR
     43  1.7       bad #define	UBS_MAX_AGGR		17	/* Maximum aggregation count */
     44  1.7       bad #endif
     45  1.7       bad 
     46  1.7       bad #ifndef UBS_MIN_AGGR
     47  1.7       bad #define	UBS_MIN_AGGR		5	/* < 5827, Maximum aggregation count */
     48  1.1  jonathan #endif
     49  1.1  jonathan 
     50  1.1  jonathan #define	UBSEC_CARD(sid)		(((sid) & 0xf0000000) >> 28)
     51  1.1  jonathan #define	UBSEC_SESSION(sid)	( (sid) & 0x0fffffff)
     52  1.1  jonathan #define	UBSEC_SID(crd, sesn)	(((crd) << 28) | ((sesn) & 0x0fffffff))
     53  1.1  jonathan 
     54  1.1  jonathan #define UBS_DEF_RTY		0xff	/* PCI Retry Timeout */
     55  1.1  jonathan #define UBS_DEF_TOUT		0xff	/* PCI TRDY Timeout */
     56  1.1  jonathan #define UBS_DEF_CACHELINE	0x01	/* Cache Line setting */
     57  1.1  jonathan 
     58  1.1  jonathan struct ubsec_dma_alloc {
     59  1.1  jonathan 	u_int32_t		dma_paddr;
     60  1.3  christos 	void *			dma_vaddr;
     61  1.1  jonathan 	bus_dmamap_t		dma_map;
     62  1.1  jonathan 	bus_dma_segment_t	dma_seg;
     63  1.1  jonathan 	bus_size_t		dma_size;
     64  1.1  jonathan 	int			dma_nseg;
     65  1.1  jonathan };
     66  1.1  jonathan 
     67  1.1  jonathan struct ubsec_q2 {
     68  1.1  jonathan 	SIMPLEQ_ENTRY(ubsec_q2)		q_next;
     69  1.1  jonathan 	struct ubsec_dma_alloc		q_mcr;
     70  1.1  jonathan 	struct ubsec_dma_alloc		q_ctx;
     71  1.1  jonathan 	u_int				q_type;
     72  1.1  jonathan };
     73  1.1  jonathan 
     74  1.1  jonathan struct ubsec_q2_rng {
     75  1.1  jonathan 	struct ubsec_q2			rng_q;
     76  1.1  jonathan 	struct ubsec_dma_alloc		rng_buf;
     77  1.1  jonathan 	int				rng_used;
     78  1.1  jonathan };
     79  1.1  jonathan 
     80  1.1  jonathan /* C = (M ^ E) mod N */
     81  1.1  jonathan #define	UBS_MODEXP_PAR_M	0
     82  1.1  jonathan #define	UBS_MODEXP_PAR_E	1
     83  1.1  jonathan #define	UBS_MODEXP_PAR_N	2
     84  1.1  jonathan struct ubsec_q2_modexp {
     85  1.1  jonathan 	struct ubsec_q2			me_q;
     86  1.1  jonathan 	struct cryptkop *		me_krp;
     87  1.1  jonathan 	struct ubsec_dma_alloc		me_M;
     88  1.1  jonathan 	struct ubsec_dma_alloc		me_E;
     89  1.1  jonathan 	struct ubsec_dma_alloc		me_C;
     90  1.1  jonathan 	struct ubsec_dma_alloc		me_epb;
     91  1.1  jonathan 	int				me_modbits;
     92  1.1  jonathan 	int				me_shiftbits;
     93  1.1  jonathan 	int				me_normbits;
     94  1.1  jonathan };
     95  1.1  jonathan 
     96  1.1  jonathan #define	UBS_RSAPRIV_PAR_P	0
     97  1.1  jonathan #define	UBS_RSAPRIV_PAR_Q	1
     98  1.1  jonathan #define	UBS_RSAPRIV_PAR_DP	2
     99  1.1  jonathan #define	UBS_RSAPRIV_PAR_DQ	3
    100  1.1  jonathan #define	UBS_RSAPRIV_PAR_PINV	4
    101  1.1  jonathan #define	UBS_RSAPRIV_PAR_MSGIN	5
    102  1.1  jonathan #define	UBS_RSAPRIV_PAR_MSGOUT	6
    103  1.1  jonathan struct ubsec_q2_rsapriv {
    104  1.1  jonathan 	struct ubsec_q2			rpr_q;
    105  1.1  jonathan 	struct cryptkop *		rpr_krp;
    106  1.1  jonathan 	struct ubsec_dma_alloc		rpr_msgin;
    107  1.1  jonathan 	struct ubsec_dma_alloc		rpr_msgout;
    108  1.1  jonathan };
    109  1.1  jonathan 
    110  1.1  jonathan #define	UBSEC_RNG_BUFSIZ	16		/* measured in 32bit words */
    111  1.1  jonathan 
    112  1.1  jonathan struct ubsec_dmachunk {
    113  1.1  jonathan 	struct ubsec_mcr	d_mcr;
    114  1.1  jonathan 	struct ubsec_mcr_add	d_mcradd[UBS_MAX_AGGR-1];
    115  1.1  jonathan 	struct ubsec_pktbuf	d_sbuf[UBS_MAX_SCATTER-1];
    116  1.1  jonathan 	struct ubsec_pktbuf	d_dbuf[UBS_MAX_SCATTER-1];
    117  1.1  jonathan 	u_int32_t		d_macbuf[5];
    118  1.1  jonathan 	union {
    119  1.1  jonathan 		struct ubsec_pktctx_long	ctxl;
    120  1.1  jonathan 		struct ubsec_pktctx		ctx;
    121  1.1  jonathan 	} d_ctx;
    122  1.1  jonathan };
    123  1.1  jonathan 
    124  1.1  jonathan struct ubsec_dma {
    125  1.1  jonathan 	SIMPLEQ_ENTRY(ubsec_dma)	d_next;
    126  1.1  jonathan 	struct ubsec_dmachunk		*d_dma;
    127  1.1  jonathan 	struct ubsec_dma_alloc		d_alloc;
    128  1.1  jonathan };
    129  1.1  jonathan 
    130  1.1  jonathan #define	UBS_FLAGS_KEY		0x01		/* has key accelerator */
    131  1.1  jonathan #define	UBS_FLAGS_LONGCTX	0x02		/* uses long ipsec ctx */
    132  1.1  jonathan #define	UBS_FLAGS_BIGKEY	0x04		/* 2048bit keys */
    133  1.1  jonathan #define	UBS_FLAGS_HWNORM	0x08		/* hardware normalization */
    134  1.1  jonathan #define	UBS_FLAGS_RNG		0x10		/* hardware rng */
    135  1.7       bad #define UBS_FLAGS_AES		0x20		/* supports AES */
    136  1.7       bad #define UBS_FLAGS_MULTIMCR	0x40		/* 5827+ with 4 MCRs */
    137  1.7       bad #define UBS_FLAGS_RNG4		0x80		/* 5827+ RNG on MCR4 */
    138  1.1  jonathan 
    139  1.1  jonathan struct ubsec_q {
    140  1.1  jonathan 	SIMPLEQ_ENTRY(ubsec_q)		q_next;
    141  1.1  jonathan 	int				q_nstacked_mcrs;
    142  1.1  jonathan 	struct ubsec_q			*q_stacked_mcr[UBS_MAX_AGGR-1];
    143  1.1  jonathan 	struct cryptop			*q_crp;
    144  1.1  jonathan 	struct ubsec_dma		*q_dma;
    145  1.1  jonathan 
    146  1.1  jonathan 	struct mbuf			*q_src_m, *q_dst_m;
    147  1.1  jonathan 	struct uio			*q_src_io, *q_dst_io;
    148  1.1  jonathan 
    149  1.1  jonathan 	bus_dmamap_t			q_src_map;
    150  1.1  jonathan 	bus_dmamap_t			q_dst_map;
    151  1.1  jonathan 
    152  1.1  jonathan 	int				q_sesn;
    153  1.1  jonathan 	int				q_flags;
    154  1.1  jonathan };
    155  1.1  jonathan 
    156  1.1  jonathan struct ubsec_softc {
    157  1.4       chs 	device_t		sc_dev;		/* generic device */
    158  1.1  jonathan 	void			*sc_ih;		/* interrupt handler cookie */
    159  1.5       tls 	kmutex_t		sc_mtx;
    160  1.6       bad 	pci_chipset_tag_t	sc_pct;		/* pci chipset tag */
    161  1.1  jonathan 	bus_space_handle_t	sc_sh;		/* memory handle */
    162  1.1  jonathan 	bus_space_tag_t		sc_st;		/* memory tag */
    163  1.1  jonathan 	bus_dma_tag_t		sc_dmat;	/* dma tag */
    164  1.1  jonathan 	int			sc_flags;	/* device specific flags */
    165  1.1  jonathan 	int			sc_suspended;
    166  1.1  jonathan 	int			sc_needwakeup;	/* notify crypto layer */
    167  1.1  jonathan 	u_int32_t		sc_statmask;	/* interrupt status mask */
    168  1.1  jonathan 	int32_t			sc_cid;		/* crypto tag */
    169  1.7       bad 	int			sc_maxaggr;	/* max pkt aggregation */
    170  1.1  jonathan 	SIMPLEQ_HEAD(,ubsec_q)	sc_queue;	/* packet queue, mcr1 */
    171  1.1  jonathan 	int			sc_nqueue;	/* count enqueued, mcr1 */
    172  1.1  jonathan 	SIMPLEQ_HEAD(,ubsec_q)	sc_qchip;	/* on chip, mcr1 */
    173  1.1  jonathan 	int			sc_nqchip;	/* count on chip, mcr1 */
    174  1.1  jonathan 	SIMPLEQ_HEAD(,ubsec_q)	sc_freequeue;	/* list of free queue elements */
    175  1.1  jonathan 	SIMPLEQ_HEAD(,ubsec_q2)	sc_queue2;	/* packet queue, mcr2 */
    176  1.1  jonathan 	int			sc_nqueue2;	/* count enqueued, mcr2 */
    177  1.1  jonathan 	SIMPLEQ_HEAD(,ubsec_q2)	sc_qchip2;	/* on chip, mcr2 */
    178  1.7       bad 	SIMPLEQ_HEAD(,ubsec_q2)	sc_queue4;	/* packet queue, mcr4 */
    179  1.7       bad 	int			sc_nqueue4;	/* count enqueued, mcr4 */
    180  1.7       bad 	SIMPLEQ_HEAD(,ubsec_q2)	sc_qchip4;	/* on chip, mcr4 */
    181  1.1  jonathan 	int			sc_nsessions;	/* # of sessions */
    182  1.1  jonathan 	struct ubsec_session	*sc_sessions;	/* sessions */
    183  1.1  jonathan 	struct callout		sc_rngto;	/* rng timeout */
    184  1.1  jonathan 	int			sc_rnghz;	/* rng poll time */
    185  1.1  jonathan 	struct ubsec_q2_rng	sc_rng;
    186  1.5       tls 	krndsource_t		sc_rnd_source;
    187  1.5       tls 	int			sc_rng_need;	/* how many bytes wanted */
    188  1.1  jonathan 	struct ubsec_dma	sc_dmaa[UBS_MAX_NQUEUE];
    189  1.1  jonathan 	struct ubsec_q		*sc_queuea[UBS_MAX_NQUEUE];
    190  1.1  jonathan 	SIMPLEQ_HEAD(,ubsec_q2)	sc_q2free;	/* free list */
    191  1.6       bad 	bus_size_t		sc_memsize;	/* size mapped by sc_sh */
    192  1.1  jonathan };
    193  1.1  jonathan 
    194  1.1  jonathan #define	UBSEC_QFLAGS_COPYOUTIV		0x1
    195  1.1  jonathan 
    196  1.1  jonathan struct ubsec_session {
    197  1.1  jonathan 	u_int32_t	ses_used;
    198  1.1  jonathan 	u_int32_t	ses_deskey[6];		/* 3DES key */
    199  1.1  jonathan 	u_int32_t	ses_hminner[5];		/* hmac inner state */
    200  1.1  jonathan 	u_int32_t	ses_hmouter[5];		/* hmac outer state */
    201  1.1  jonathan 	u_int32_t	ses_iv[2];		/* [3]DES iv */
    202  1.1  jonathan };
    203  1.1  jonathan 
    204  1.1  jonathan struct ubsec_stats {
    205  1.1  jonathan 	u_int64_t hst_ibytes;
    206  1.1  jonathan 	u_int64_t hst_obytes;
    207  1.1  jonathan 	u_int32_t hst_ipackets;
    208  1.1  jonathan 	u_int32_t hst_opackets;
    209  1.1  jonathan 	u_int32_t hst_invalid;		/* invalid argument */
    210  1.1  jonathan 	u_int32_t hst_badsession;	/* invalid session id */
    211  1.1  jonathan 	u_int32_t hst_badflags;		/* flags indicate !(mbuf | uio) */
    212  1.1  jonathan 	u_int32_t hst_nodesc;		/* op submitted w/o descriptors */
    213  1.1  jonathan 	u_int32_t hst_badalg;		/* unsupported algorithm */
    214  1.1  jonathan 
    215  1.1  jonathan 	u_int32_t hst_nomem;
    216  1.1  jonathan 	u_int32_t hst_queuefull;
    217  1.1  jonathan 	u_int32_t hst_dmaerr;
    218  1.1  jonathan 	u_int32_t hst_mcrerr;
    219  1.1  jonathan 	u_int32_t hst_nodmafree;
    220  1.1  jonathan 
    221  1.1  jonathan 	u_int32_t hst_lenmismatch;	/* enc/auth lengths different */
    222  1.1  jonathan 	u_int32_t hst_skipmismatch;	/* enc part begins before auth part */
    223  1.1  jonathan 	u_int32_t hst_iovmisaligned;	/* iov op not aligned */
    224  1.1  jonathan 	u_int32_t hst_noirq;		/* IRQ for no reason */
    225  1.1  jonathan 	u_int32_t hst_unaligned;	/* unaligned src caused copy */
    226  1.1  jonathan 	u_int32_t hst_nomap;		/* bus_dmamap_create failed */
    227  1.1  jonathan 	u_int32_t hst_noload;		/* bus_dmamap_load_* failed */
    228  1.1  jonathan 	u_int32_t hst_nombuf;		/* MGET* failed */
    229  1.1  jonathan 	u_int32_t hst_nomcl;		/* MCLGET* failed */
    230  1.1  jonathan 	u_int32_t hst_totbatch;		/* ops submitted w/o interrupt */
    231  1.1  jonathan 	u_int32_t hst_maxbatch;		/* max ops submitted together */
    232  1.1  jonathan 	u_int32_t hst_maxqueue;		/* max ops queued for submission */
    233  1.1  jonathan 	u_int32_t hst_maxqchip;		/* max mcr1 ops out for processing */
    234  1.1  jonathan 	u_int32_t hst_mcr1full;		/* MCR1 too busy to take ops */
    235  1.1  jonathan 	u_int32_t hst_rng;		/* RNG requests */
    236  1.1  jonathan 	u_int32_t hst_modexp;		/* MOD EXP requests */
    237  1.1  jonathan 	u_int32_t hst_modexpcrt;	/* MOD EXP CRT requests */
    238  1.1  jonathan };
    239