Home | History | Annotate | Line # | Download | only in sunxi
      1  1.2  riastrad /*	$NetBSD: sun8i_crypto.h,v 1.2 2020/06/13 18:57:54 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*-
      4  1.1  riastrad  * Copyright (c) 2019 The NetBSD Foundation, Inc.
      5  1.1  riastrad  * All rights reserved.
      6  1.1  riastrad  *
      7  1.1  riastrad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  riastrad  * by Taylor R. Campbell.
      9  1.1  riastrad  *
     10  1.1  riastrad  * Redistribution and use in source and binary forms, with or without
     11  1.1  riastrad  * modification, are permitted provided that the following conditions
     12  1.1  riastrad  * are met:
     13  1.1  riastrad  * 1. Redistributions of source code must retain the above copyright
     14  1.1  riastrad  *    notice, this list of conditions and the following disclaimer.
     15  1.1  riastrad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  riastrad  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  riastrad  *    documentation and/or other materials provided with the distribution.
     18  1.1  riastrad  *
     19  1.1  riastrad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  riastrad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  riastrad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  riastrad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  riastrad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  riastrad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  riastrad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  riastrad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  riastrad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  riastrad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  riastrad  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  riastrad  */
     31  1.1  riastrad 
     32  1.1  riastrad #ifndef	_ARM_SUN8I_CRYPTO_H
     33  1.1  riastrad #define	_ARM_SUN8I_CRYPTO_H
     34  1.1  riastrad 
     35  1.1  riastrad #include <sys/cdefs.h>
     36  1.1  riastrad 
     37  1.1  riastrad #define	SUN8I_CRYPTO_NCHAN	4
     38  1.1  riastrad 
     39  1.1  riastrad /* task_descriptor_queue common control bitmap (32bit), p. 234 */
     40  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_INTR_EN	__BIT(31)
     41  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_IV_MODE	__BIT(16) /* MD5/SHA-1/SHA-2 IV */
     42  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_IV_MODE_CONST		0 /* standard constants */
     43  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_IV_MODE_ARBITRARY	1 /* arbitrary */
     44  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_HMAC_PT_LAST	__BIT(15)
     45  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_OP_DIR	__BIT(8)
     46  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_OP_DIR_ENC		0
     47  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_OP_DIR_DEC		1
     48  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_METHOD	__BITS(6,0)
     49  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_METHOD_AES		0
     50  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_METHOD_DES		1
     51  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_METHOD_3DES		2
     52  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_METHOD_MD5		16
     53  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_METHOD_SHA1		17
     54  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_METHOD_SHA224		18
     55  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_METHOD_SHA256		19
     56  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_METHOD_HMAC_SHA1	22
     57  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_METHOD_HMAC_SHA256	23
     58  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_METHOD_RSA		32
     59  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_METHOD_TRNG		48
     60  1.1  riastrad #define	SUN8I_CRYPTO_TDQC_METHOD_PRNG		49
     61  1.1  riastrad 
     62  1.1  riastrad /* task_descriptor_queue symmetric control (32bit), p. 235 */
     63  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_SKEY_SELECT	__BITS(23,20)
     64  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_SKEY_SELECT_SS_KEYx	0
     65  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_SKEY_SELECT_SSK	1
     66  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_SKEY_SELECT_HUK	2
     67  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_SKEY_SELECT_RSSK	3
     68  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_SKEY_SELECT_INTERNAL(n)	(8 + (n))
     69  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_AES_CTS_LAST	__BIT(16)
     70  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_OP_MODE	__BITS(11,8)
     71  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_OP_MODE_ECB		0
     72  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_OP_MODE_CBC		1
     73  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_OP_MODE_CTR		2
     74  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_OP_MODE_CTS		3
     75  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_CTR_WIDTH	__BITS(3,2)
     76  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_CTR_WIDTH_16		0
     77  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_CTR_WIDTH_32		1
     78  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_CTR_WIDTH_64		2
     79  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_CTR_WIDTH_128		3
     80  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_AES_KEYSIZE	__BITS(1,0)
     81  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_AES_KEYSIZE_128	0
     82  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_AES_KEYSIZE_192	1
     83  1.1  riastrad #define	SUN8I_CRYPTO_TDQS_AES_KEYSIZE_256	2
     84  1.1  riastrad 
     85  1.1  riastrad /* task_descriptor_queue asymmetric control (32bit), p. 236 */
     86  1.1  riastrad #define	SUN8I_CRYPTO_TDQA_RSA_MODSIZE	__BITS(30,28)
     87  1.1  riastrad #define	SUN8I_CRYPTO_TDQA_RSA_MODSIZE_512	0
     88  1.1  riastrad #define	SUN8I_CRYPTO_TDQA_RSA_MODSIZE_1024	1
     89  1.1  riastrad #define	SUN8I_CRYPTO_TDQA_RSA_MODSIZE_2048	2
     90  1.1  riastrad 
     91  1.1  riastrad /* Crypto Engine Register List */
     92  1.1  riastrad 
     93  1.1  riastrad /* Module */
     94  1.1  riastrad #define	SUN8I_CRYPTO_NS		0x01c15000
     95  1.1  riastrad #define	SUN8I_CRYPTO_S		0x01c15800
     96  1.1  riastrad 
     97  1.1  riastrad /* Register */
     98  1.1  riastrad #define	SUN8I_CRYPTO_TDQ	0x00 /* Task Descriptor Queue Address */
     99  1.1  riastrad #define	SUN8I_CRYPTO_CTR	0x04 /* Gating Control Register */
    100  1.1  riastrad #define	SUN8I_CRYPTO_ICR	0x08 /* Interrupt Control Register */
    101  1.1  riastrad #define	SUN8I_CRYPTO_ISR	0x0c /* Interrupt Status Register */
    102  1.1  riastrad #define	SUN8I_CRYPTO_TLR	0x10 /* Task Load Register */
    103  1.1  riastrad #define	SUN8I_CRYPTO_TSR	0x14 /* Task Status Register */
    104  1.1  riastrad #define	SUN8I_CRYPTO_ESR	0x18 /* Task Error type Register */
    105  1.1  riastrad #define	SUN8I_CRYPTO_CSAR	0x24 /* Current Source Address Register */
    106  1.1  riastrad #define	SUN8I_CRYPTO_CDAR	0x28 /* Current Destination Address Register */
    107  1.1  riastrad #define	SUN8I_CRYPTO_TPR	0x2c /* Throughput Register */
    108  1.1  riastrad 
    109  1.1  riastrad #define	SUN8I_CRYPTO_CTR_RSA_CLK_EN	__BIT(3)
    110  1.1  riastrad #define	SUN8I_CRYPTO_CTR_DIE_ID		__BITS(2,0)
    111  1.1  riastrad 
    112  1.1  riastrad #define	SUN8I_CRYPTO_ICR_INTR_EN	__BITS(3,0)
    113  1.1  riastrad #define	SUN8I_CRYPTO_ICR_INTR_EN_CHAN(n)	(__BIT(0) << (n))
    114  1.1  riastrad 
    115  1.1  riastrad #define	SUN8I_CRYPTO_ISR_DONE		__BITS(3,0)
    116  1.1  riastrad #define	SUN8I_CRYPTO_ISR_DONE_CHAN(n)		(__BIT(0) << (n))
    117  1.1  riastrad 
    118  1.1  riastrad #define	SUN8I_CRYPTO_TLR_LOAD		__BIT(0)
    119  1.1  riastrad 
    120  1.1  riastrad #define	SUN8I_CRYPTO_TSR_TASK		__BITS(1,0)
    121  1.1  riastrad /* task number, 0-3 */
    122  1.1  riastrad 
    123  1.1  riastrad #define	SUN8I_CRYPTO_ESR_CHAN(n)	(__BITS(3,0) << (n))
    124  1.1  riastrad #define	SUN8I_CRYPTO_ESR_CHAN_ALGNOTSUP		__BIT(0)
    125  1.1  riastrad #define	SUN8I_CRYPTO_ESR_CHAN_DATALENERR	__BIT(1)
    126  1.1  riastrad #define	SUN8I_CRYPTO_ESR_CHAN_KEYSRAMERR	__BIT(2)
    127  1.1  riastrad 
    128  1.2  riastrad #define	SUN8I_CRYPTO_MAXKEYBYTES	256	/* e.g. 2048-bit RSA */
    129  1.2  riastrad #define	SUN8I_CRYPTO_MAXIVBYTES		64	/* e.g. SHA-512 */
    130  1.2  riastrad #define	SUN8I_CRYPTO_MAXCTRBYTES	16	/* e.g. AES */
    131  1.2  riastrad 
    132  1.2  riastrad /*
    133  1.2  riastrad  * Eight src segments and eight dst segments per task.  The datalen
    134  1.2  riastrad  * field, measured either in bytes or words, is 32 bits.  Each segment
    135  1.2  riastrad  * length is measured in words and is also 32 bits.  We never do very
    136  1.2  riastrad  * long transfers anyway so rounding the maximum size down to 2^32 - 1
    137  1.2  riastrad  * is not a real limitation.
    138  1.2  riastrad  */
    139  1.1  riastrad #define	SUN8I_CRYPTO_MAXSEGS		8
    140  1.2  riastrad #define	SUN8I_CRYPTO_MAXSEGLEN		UINT32_MAX
    141  1.2  riastrad #define	SUN8I_CRYPTO_MAXDATALEN		UINT32_MAX
    142  1.1  riastrad 
    143  1.1  riastrad struct sun8i_crypto_taskdesc {
    144  1.1  riastrad 	uint32_t	td_cid;		/* task channel id */
    145  1.1  riastrad 	uint32_t	td_tdqc;	/* task descriptor queue common */
    146  1.1  riastrad 	uint32_t	td_tdqs;	/* task descriptor queue symmetric */
    147  1.1  riastrad 	uint32_t	td_tdqa;	/* task descriptor queue asymmetric */
    148  1.1  riastrad 	uint32_t	td_keydesc;	/* key descriptor */
    149  1.1  riastrad 	uint32_t	td_ivdesc;	/* IV descriptor */
    150  1.1  riastrad 	uint32_t	td_ctrdesc;	/* CTR descriptor */
    151  1.1  riastrad 	uint32_t	td_datalen;	/* data length */
    152  1.1  riastrad 	struct sun8i_crypto_adrlen {
    153  1.1  riastrad 		uint32_t	adr;
    154  1.1  riastrad 		uint32_t	len;
    155  1.1  riastrad 	}		td_src[SUN8I_CRYPTO_MAXSEGS],
    156  1.1  riastrad 			td_dst[SUN8I_CRYPTO_MAXSEGS];
    157  1.1  riastrad 	uint32_t	td_nextdesc;	/* next descriptor */
    158  1.1  riastrad 	uint32_t	td_reserved[3];
    159  1.1  riastrad } __packed;
    160  1.1  riastrad 
    161  1.1  riastrad CTASSERT(sizeof(struct sun8i_crypto_taskdesc) == 44*4);
    162  1.1  riastrad 
    163  1.1  riastrad #endif	/* _ARM_SUN8I_CRYPTO_H */
    164