Add a driver for the SafeXcel EIP-97.

The EIP-97 is a packet processing module found on the ESPRESSObin.  This
commit adds a crypto(9) driver for the crypto and hash engine in this
device.  An initial skeleton driver that could attach and submit
requests was written by loos and others at Netgate, and the driver was
finished by me.

Support for separate AAD and output buffers will be added in a separate
commit, to simplify merging to stable/12 (where those features don't
exist).

Reviewed by:	gnn, jhb
Feedback from:	andrew, cem, manu
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC (Netgate)
Differential Revision:	https://reviews.freebsd.org/D25417
This commit is contained in:
Mark Johnston 2020-07-14 14:09:29 +00:00
parent 189ae32695
commit b356ddf076
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=363180
9 changed files with 3613 additions and 0 deletions

View File

@ -449,6 +449,7 @@ MAN= aac.4 \
rue.4 \
sa.4 \
safe.4 \
safexcel.4 \
sbp.4 \
sbp_targ.4 \
scc.4 \

84
share/man/man4/safexcel.4 Normal file
View File

@ -0,0 +1,84 @@
.\"-
.\" Copyright (c) 2020 Rubicon Communications, LLC (Netgate)
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd June 23, 2020
.Dt SAFEXCEL 4
.Os
.Sh NAME
.Nm safexcel
.Nd Inside Secure SafeXcel-IP-97 security packet engine
.Sh SYNOPSIS
To compile this driver into the kernel,
place the following lines in your
kernel configuration file:
.Bd -ragged -offset indent
.Cd "device crypto"
.Cd "device cryptodev"
.Cd "device safexcel"
.Ed
.Pp
Alternatively, to load the driver as a
module at boot time, place the following line in
.Xr loader.conf 5 :
.Bd -literal -offset indent
safexcel_load="YES"
.Ed
.Sh DESCRIPTION
The
.Nm
driver implements
.Xr crypto 4
support for the cryptographic acceleration functions of the EIP-97 device
found on some Marvell systems-on-chip.
The driver can accelerate the following AES modes:
.Pp
.Bl -bullet -compact
.It
AES-CBC
.It
AES-CTR
.It
AES-XTS
.It
AES-GCM
.It
AES-CCM
.El
.Pp
.Nm
also implements SHA1 and SHA2 transforms, and can combine AES-CBC and AES-CTR
with SHA1-HMAC and SHA2-HMAC for encrypt-then-authenticate operations.
.Sh SEE ALSO
.Xr crypto 4 ,
.Xr ipsec 4 ,
.Xr random 4 ,
.Xr geli 8 ,
.Xr crypto 9
.Sh HISTORY
The
.Nm
driver first appeared in
.Fx 13.0 .

View File

@ -283,6 +283,9 @@ device mv_ap806_sei # Marvell AP806 SEI
device aw_rtc # Allwinner Real-time Clock
device mv_rtc # Marvell Real-time Clock
# Crypto accelerators
device safexcel # Inside Secure EIP-97
# Watchdog controllers
device aw_wdog # Allwinner Watchdog

View File

@ -324,6 +324,7 @@ dev/pci/pci_dw_if.m optional pci fdt
dev/psci/psci.c standard
dev/psci/smccc_arm64.S standard
dev/psci/smccc.c standard
dev/safexcel/safexcel.c optional safexcel fdt
dev/sdhci/sdhci_xenon.c optional sdhci_xenon sdhci fdt
dev/uart/uart_cpu_arm64.c optional uart
dev/uart/uart_dev_mu.c optional uart uart_mu

2637
sys/dev/safexcel/safexcel.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,457 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2020 Rubicon Communications, LLC (Netgate)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _SAFEXCEL_REGS_H_
#define _SAFEXCEL_REGS_H_
#define SAFEXCEL_HIA_VERSION_LE 0x35ca
#define SAFEXCEL_HIA_VERSION_BE 0xca35
#define EIP201_VERSION_LE 0x36c9
#define SAFEXCEL_REG_LO16(_reg) ((_reg) & 0xffff)
#define SAFEXCEL_REG_HI16(_reg) (((_reg) >> 16) & 0xffff)
/* HIA, Command Descriptor Ring Manager */
#define CDR_BASE_ADDR_LO(x) (0x0 + ((x) << 12))
#define CDR_BASE_ADDR_HI(x) (0x4 + ((x) << 12))
#define CDR_DATA_BASE_ADDR_LO(x) (0x8 + ((x) << 12))
#define CDR_DATA_BASE_ADDR_HI(x) (0xC + ((x) << 12))
#define CDR_ACD_BASE_ADDR_LO(x) (0x10 + ((x) << 12))
#define CDR_ACD_BASE_ADDR_HI(x) (0x14 + ((x) << 12))
#define CDR_RING_SIZE(x) (0x18 + ((x) << 12))
#define CDR_DESC_SIZE(x) (0x1C + ((x) << 12))
#define CDR_CFG(x) (0x20 + ((x) << 12))
#define CDR_DMA_CFG(x) (0x24 + ((x) << 12))
#define CDR_THR(x) (0x28 + ((x) << 12))
#define CDR_PREP_COUNT(x) (0x2C + ((x) << 12))
#define CDR_PROC_COUNT(x) (0x30 + ((x) << 12))
#define CDR_PREP_PNTR(x) (0x34 + ((x) << 12))
#define CDR_PROC_PNTR(x) (0x38 + ((x) << 12))
#define CDR_STAT(x) (0x3C + ((x) << 12))
/* HIA, Result Descriptor Ring Manager */
#define RDR_BASE_ADDR_LO(x) (0x800 + ((x) << 12))
#define RDR_BASE_ADDR_HI(x) (0x804 + ((x) << 12))
#define RDR_DATA_BASE_ADDR_LO(x) (0x808 + ((x) << 12))
#define RDR_DATA_BASE_ADDR_HI(x) (0x80C + ((x) << 12))
#define RDR_ACD_BASE_ADDR_LO(x) (0x810 + ((x) << 12))
#define RDR_ACD_BASE_ADDR_HI(x) (0x814 + ((x) << 12))
#define RDR_RING_SIZE(x) (0x818 + ((x) << 12))
#define RDR_DESC_SIZE(x) (0x81C + ((x) << 12))
#define RDR_CFG(x) (0x820 + ((x) << 12))
#define RDR_DMA_CFG(x) (0x824 + ((x) << 12))
#define RDR_THR(x) (0x828 + ((x) << 12))
#define RDR_PREP_COUNT(x) (0x82C + ((x) << 12))
#define RDR_PROC_COUNT(x) (0x830 + ((x) << 12))
#define RDR_PREP_PNTR(x) (0x834 + ((x) << 12))
#define RDR_PROC_PNTR(x) (0x838 + ((x) << 12))
#define RDR_STAT(x) (0x83C + ((x) << 12))
/* HIA, Ring AIC */
#define AIC_POL_CTRL(x) (0xE000 - ((x) << 12))
#define AIC_TYPE_CTRL(x) (0xE004 - ((x) << 12))
#define AIC_ENABLE_CTRL(x) (0xE008 - ((x) << 12))
#define AIC_RAW_STAL(x) (0xE00C - ((x) << 12))
#define AIC_ENABLE_SET(x) (0xE00C - ((x) << 12))
#define AIC_ENABLED_STAT(x) (0xE010 - ((x) << 12))
#define AIC_ACK(x) (0xE010 - ((x) << 12))
#define AIC_ENABLE_CLR(x) (0xE014 - ((x) << 12))
#define AIC_OPTIONS(x) (0xE018 - ((x) << 12))
#define AIC_VERSION(x) (0xE01C - ((x) << 12))
/* HIA, Global AIC */
#define AIC_G_POL_CTRL 0xF800
#define AIC_G_TYPE_CTRL 0xF804
#define AIC_G_ENABLE_CTRL 0xF808
#define AIC_G_RAW_STAT 0xF80C
#define AIC_G_ENABLE_SET 0xF80C
#define AIC_G_ENABLED_STAT 0xF810
#define AIC_G_ACK 0xF810
#define AIC_G_ENABLE_CLR 0xF814
#define AIC_G_OPTIONS 0xF818
#define AIC_G_VERSION 0xF81C
/* HIA, Data Fetch Engine */
#define DFE_CFG 0xF000
#define DFE_PRIO_0 0xF010
#define DFE_PRIO_1 0xF014
#define DFE_PRIO_2 0xF018
#define DFE_PRIO_3 0xF01C
/* HIA, Data Fetch Engine access monitoring for CDR */
#define DFE_RING_REGION_LO(x) (0xF080 + ((x) << 3))
#define DFE_RING_REGION_HI(x) (0xF084 + ((x) << 3))
/* HIA, Data Fetch Engine thread control and status for thread */
#define DFE_THR_CTRL 0xF200
#define DFE_THR_STAT 0xF204
#define DFE_THR_DESC_CTRL 0xF208
#define DFE_THR_DESC_DPTR_LO 0xF210
#define DFE_THR_DESC_DPTR_HI 0xF214
#define DFE_THR_DESC_ACDPTR_LO 0xF218
#define DFE_THR_DESC_ACDPTR_HI 0xF21C
/* HIA, Data Store Engine */
#define DSE_CFG 0xF400
#define DSE_PRIO_0 0xF410
#define DSE_PRIO_1 0xF414
#define DSE_PRIO_2 0xF418
#define DSE_PRIO_3 0xF41C
/* HIA, Data Store Engine access monitoring for RDR */
#define DSE_RING_REGION_LO(x) (0xF480 + ((x) << 3))
#define DSE_RING_REGION_HI(x) (0xF484 + ((x) << 3))
/* HIA, Data Store Engine thread control and status for thread */
#define DSE_THR_CTRL 0xF600
#define DSE_THR_STAT 0xF604
#define DSE_THR_DESC_CTRL 0xF608
#define DSE_THR_DESC_DPTR_LO 0xF610
#define DSE_THR_DESC_DPTR_HI 0xF614
#define DSE_THR_DESC_S_DPTR_LO 0xF618
#define DSE_THR_DESC_S_DPTR_HI 0xF61C
#define DSE_THR_ERROR_STAT 0xF620
/* HIA Global */
#define HIA_MST_CTRL 0xFFF4
#define HIA_OPTIONS 0xFFF8
#define HIA_VERSION 0xFFFC
/* Processing Engine Input Side, Processing Engine */
#define PE_IN_DBUF_THRESH 0x10000
#define PE_IN_TBUF_THRESH 0x10100
/* Packet Engine Configuration / Status Registers */
#define PE_TOKEN_CTRL_STAT 0x11000
#define PE_FUNCTION_EN 0x11004
#define PE_CONTEXT_CTRL 0x11008
#define PE_INTERRUPT_CTRL_STAT 0x11010
#define PE_CONTEXT_STAT 0x1100C
#define PE_OUT_TRANS_CTRL_STAT 0x11018
#define PE_OUT_BUF_CTRL 0x1101C
/* Packet Engine AIC */
#define PE_EIP96_AIC_POL_CTRL 0x113C0
#define PE_EIP96_AIC_TYPE_CTRL 0x113C4
#define PE_EIP96_AIC_ENABLE_CTRL 0x113C8
#define PE_EIP96_AIC_RAW_STAT 0x113CC
#define PE_EIP96_AIC_ENABLE_SET 0x113CC
#define PE_EIP96_AIC_ENABLED_STAT 0x113D0
#define PE_EIP96_AIC_ACK 0x113D0
#define PE_EIP96_AIC_ENABLE_CLR 0x113D4
#define PE_EIP96_AIC_OPTIONS 0x113D8
#define PE_EIP96_AIC_VERSION 0x113DC
/* Packet Engine Options & Version Registers */
#define PE_EIP96_OPTIONS 0x113F8
#define PE_EIP96_VERSION 0x113FC
#define SAFEXCEL_OPT
/* Processing Engine Output Side */
#define PE_OUT_DBUF_THRESH 0x11C00
#define PE_OUT_TBUF_THRESH 0x11D00
/* Processing Engine Local AIC */
#define PE_AIC_POL_CTRL 0x11F00
#define PE_AIC_TYPE_CTRL 0x11F04
#define PE_AIC_ENABLE_CTRL 0x11F08
#define PE_AIC_RAW_STAT 0x11F0C
#define PE_AIC_ENABLE_SET 0x11F0C
#define PE_AIC_ENABLED_STAT 0x11F10
#define PE_AIC_ENABLE_CLR 0x11F14
#define PE_AIC_OPTIONS 0x11F18
#define PE_AIC_VERSION 0x11F1C
/* Processing Engine General Configuration and Version */
#define PE_IN_FLIGHT 0x11FF0
#define PE_OPTIONS 0x11FF8
#define PE_VERSION 0x11FFC
/* EIP-97 - Global */
#define EIP97_CLOCK_STATE 0x1FFE4
#define EIP97_FORCE_CLOCK_ON 0x1FFE8
#define EIP97_FORCE_CLOCK_OFF 0x1FFEC
#define EIP97_MST_CTRL 0x1FFF4
#define EIP97_OPTIONS 0x1FFF8
#define EIP97_VERSION 0x1FFFC
/* Register base offsets */
#define SAFEXCEL_HIA_AIC(_sc) ((_sc)->sc_offsets.hia_aic)
#define SAFEXCEL_HIA_AIC_G(_sc) ((_sc)->sc_offsets.hia_aic_g)
#define SAFEXCEL_HIA_AIC_R(_sc) ((_sc)->sc_offsets.hia_aic_r)
#define SAFEXCEL_HIA_AIC_xDR(_sc) ((_sc)->sc_offsets.hia_aic_xdr)
#define SAFEXCEL_HIA_DFE(_sc) ((_sc)->sc_offsets.hia_dfe)
#define SAFEXCEL_HIA_DFE_THR(_sc) ((_sc)->sc_offsets.hia_dfe_thr)
#define SAFEXCEL_HIA_DSE(_sc) ((_sc)->sc_offsets.hia_dse)
#define SAFEXCEL_HIA_DSE_THR(_sc) ((_sc)->sc_offsets.hia_dse_thr)
#define SAFEXCEL_HIA_GEN_CFG(_sc) ((_sc)->sc_offsets.hia_gen_cfg)
#define SAFEXCEL_PE(_sc) ((_sc)->sc_offsets.pe)
/* EIP197 base offsets */
#define SAFEXCEL_EIP197_HIA_AIC_BASE 0x90000
#define SAFEXCEL_EIP197_HIA_AIC_G_BASE 0x90000
#define SAFEXCEL_EIP197_HIA_AIC_R_BASE 0x90800
#define SAFEXCEL_EIP197_HIA_AIC_xDR_BASE 0x80000
#define SAFEXCEL_EIP197_HIA_DFE_BASE 0x8c000
#define SAFEXCEL_EIP197_HIA_DFE_THR_BASE 0x8c040
#define SAFEXCEL_EIP197_HIA_DSE_BASE 0x8d000
#define SAFEXCEL_EIP197_HIA_DSE_THR_BASE 0x8d040
#define SAFEXCEL_EIP197_HIA_GEN_CFG_BASE 0xf0000
#define SAFEXCEL_EIP197_PE_BASE 0xa0000
/* EIP97 base offsets */
#define SAFEXCEL_EIP97_HIA_AIC_BASE 0x0
#define SAFEXCEL_EIP97_HIA_AIC_G_BASE 0x0
#define SAFEXCEL_EIP97_HIA_AIC_R_BASE 0x0
#define SAFEXCEL_EIP97_HIA_AIC_xDR_BASE 0x0
#define SAFEXCEL_EIP97_HIA_DFE_BASE 0xf000
#define SAFEXCEL_EIP97_HIA_DFE_THR_BASE 0xf200
#define SAFEXCEL_EIP97_HIA_DSE_BASE 0xf400
#define SAFEXCEL_EIP97_HIA_DSE_THR_BASE 0xf600
#define SAFEXCEL_EIP97_HIA_GEN_CFG_BASE 0x10000
#define SAFEXCEL_EIP97_PE_BASE 0x10000
/* CDR/RDR register offsets */
#define SAFEXCEL_HIA_xDR_OFF(priv, r) (SAFEXCEL_HIA_AIC_xDR(priv) + (r) * 0x1000)
#define SAFEXCEL_HIA_CDR(priv, r) (SAFEXCEL_HIA_xDR_OFF(priv, r))
#define SAFEXCEL_HIA_RDR(priv, r) (SAFEXCEL_HIA_xDR_OFF(priv, r) + 0x800)
#define SAFEXCEL_HIA_xDR_RING_BASE_ADDR_LO 0x0000
#define SAFEXCEL_HIA_xDR_RING_BASE_ADDR_HI 0x0004
#define SAFEXCEL_HIA_xDR_RING_SIZE 0x0018
#define SAFEXCEL_HIA_xDR_DESC_SIZE 0x001c
#define SAFEXCEL_HIA_xDR_CFG 0x0020
#define SAFEXCEL_HIA_xDR_DMA_CFG 0x0024
#define SAFEXCEL_HIA_xDR_THRESH 0x0028
#define SAFEXCEL_HIA_xDR_PREP_COUNT 0x002c
#define SAFEXCEL_HIA_xDR_PROC_COUNT 0x0030
#define SAFEXCEL_HIA_xDR_PREP_PNTR 0x0034
#define SAFEXCEL_HIA_xDR_PROC_PNTR 0x0038
#define SAFEXCEL_HIA_xDR_STAT 0x003c
/* register offsets */
#define SAFEXCEL_HIA_DFE_CFG(n) (0x000 + (128 * (n)))
#define SAFEXCEL_HIA_DFE_THR_CTRL(n) (0x000 + (128 * (n)))
#define SAFEXCEL_HIA_DFE_THR_STAT(n) (0x004 + (128 * (n)))
#define SAFEXCEL_HIA_DSE_CFG(n) (0x000 + (128 * (n)))
#define SAFEXCEL_HIA_DSE_THR_CTRL(n) (0x000 + (128 * (n)))
#define SAFEXCEL_HIA_DSE_THR_STAT(n) (0x004 + (128 * (n)))
#define SAFEXCEL_HIA_RA_PE_CTRL(n) (0x010 + (8 * (n)))
#define SAFEXCEL_HIA_RA_PE_STAT 0x0014
#define SAFEXCEL_HIA_AIC_R_OFF(r) ((r) * 0x1000)
#define SAFEXCEL_HIA_AIC_R_ENABLE_CTRL(r) (0xe008 - SAFEXCEL_HIA_AIC_R_OFF(r))
#define SAFEXCEL_HIA_AIC_R_ENABLED_STAT(r) (0xe010 - SAFEXCEL_HIA_AIC_R_OFF(r))
#define SAFEXCEL_HIA_AIC_R_ACK(r) (0xe010 - SAFEXCEL_HIA_AIC_R_OFF(r))
#define SAFEXCEL_HIA_AIC_R_ENABLE_CLR(r) (0xe014 - SAFEXCEL_HIA_AIC_R_OFF(r))
#define SAFEXCEL_HIA_AIC_R_VERSION(r) (0xe01c - SAFEXCEL_HIA_AIC_R_OFF(r))
#define SAFEXCEL_HIA_AIC_G_ENABLE_CTRL 0xf808
#define SAFEXCEL_HIA_AIC_G_ENABLED_STAT 0xf810
#define SAFEXCEL_HIA_AIC_G_ACK 0xf810
#define SAFEXCEL_HIA_MST_CTRL 0xfff4
#define SAFEXCEL_HIA_OPTIONS 0xfff8
#define SAFEXCEL_HIA_VERSION 0xfffc
#define SAFEXCEL_PE_IN_DBUF_THRES(n) (0x0000 + (0x2000 * (n)))
#define SAFEXCEL_PE_IN_TBUF_THRES(n) (0x0100 + (0x2000 * (n)))
#define SAFEXCEL_PE_ICE_SCRATCH_RAM(x, n) ((0x800 + (x) * 4) + 0x2000 * (n))
#define SAFEXCEL_PE_ICE_PUE_CTRL(n) (0xc80 + (0x2000 * (n)))
#define SAFEXCEL_PE_ICE_SCRATCH_CTRL 0x0d04
#define SAFEXCEL_PE_ICE_FPP_CTRL(n) (0xd80 + (0x2000 * (n)))
#define SAFEXCEL_PE_ICE_RAM_CTRL(n) (0xff0 + (0x2000 * (n)))
#define SAFEXCEL_PE_EIP96_FUNCTION_EN(n) (0x1004 + (0x2000 * (n)))
#define SAFEXCEL_PE_EIP96_CONTEXT_CTRL(n) (0x1008 + (0x2000 * (n)))
#define SAFEXCEL_PE_EIP96_CONTEXT_STAT(n) (0x100c + (0x2000 * (n)))
#define SAFEXCEL_PE_EIP96_FUNCTION2_EN(n) (0x1030 + (0x2000 * (n)))
#define SAFEXCEL_PE_OUT_DBUF_THRES(n) (0x1c00 + (0x2000 * (n)))
#define SAFEXCEL_PE_OUT_TBUF_THRES(n) (0x1d00 + (0x2000 * (n)))
/* EIP-197 Classification Engine */
/* Classification regs */
#define SAFEXCEL_CS_RAM_CTRL 0xf7ff0
/* SAFEXCEL_HIA_xDR_DESC_SIZE */
#define SAFEXCEL_xDR_DESC_MODE_64BIT (1U << 31)
#define SAFEXCEL_CDR_DESC_MODE_ADCP (1 << 30)
#define SAFEXCEL_xDR_DESC_xD_OFFSET 16
/* SAFEXCEL_DIA_xDR_CFG */
#define SAFEXCEL_xDR_xD_FETCH_THRESH 16
/* SAFEXCEL_HIA_xDR_DMA_CFG */
#define SAFEXCEL_HIA_xDR_WR_RES_BUF (1 << 22)
#define SAFEXCEL_HIA_xDR_WR_CTRL_BUF (1 << 23)
#define SAFEXCEL_HIA_xDR_WR_OWN_BUF (1 << 24)
#define SAFEXCEL_HIA_xDR_CFG_xD_PROT(n) (((n) & 0xf) << 4)
#define SAFEXCEL_HIA_xDR_CFG_DATA_PROT(n) (((n) & 0xf) << 12)
#define SAFEXCEL_HIA_xDR_CFG_ACD_PROT(n) (((n) & 0xf) << 20)
#define SAFEXCEL_HIA_xDR_CFG_WR_CACHE(n) (((n) & 0x7) << 25)
#define SAFEXCEL_HIA_xDR_CFG_RD_CACHE(n) (((n) & 0x7) << 29)
/* SAFEXCEL_HIA_CDR_THRESH */
#define SAFEXCEL_HIA_CDR_THRESH_PROC_PKT(n) ((n) & 0xffff)
#define SAFEXCEL_HIA_CDR_THRESH_PROC_MODE (1 << 22)
#define SAFEXCEL_HIA_CDR_THRESH_PKT_MODE (1 << 23)
/* x256 clk cycles */
#define SAFEXCEL_HIA_CDR_THRESH_TIMEOUT(n) (((n) & 0xff) << 24)
/* SAFEXCEL_HIA_RDR_THRESH */
#define SAFEXCEL_HIA_RDR_THRESH_PROC_PKT(n) ((n) & 0xffff)
#define SAFEXCEL_HIA_RDR_THRESH_PKT_MODE (1 << 23)
/* x256 clk cycles */
#define SAFEXCEL_HIA_RDR_THRESH_TIMEOUT(n) (((n) & 0xff) << 24)
/* SAFEXCEL_HIA_xDR_PREP_COUNT */
#define SAFEXCEL_xDR_PREP_CLR_COUNT (1U << 31)
#define SAFEXCEL_xDR_PREP_xD_COUNT_INCR_OFFSET 2
#define SAFEXCEL_xDR_PREP_RD_COUNT_INCR_MASK 0x3fff
/* SAFEXCEL_HIA_xDR_PROC_COUNT */
#define SAFEXCEL_xDR_PROC_xD_PKT_OFFSET 24
#define SAFEXCEL_xDR_PROC_xD_PKT_MASK 0x7f
#define SAFEXCEL_xDR_PROC_xD_COUNT(n) ((n) << 2)
#define SAFEXCEL_xDR_PROC_xD_PKT(n) \
(((n) & SAFEXCEL_xDR_PROC_xD_PKT_MASK) << SAFEXCEL_xDR_PROC_xD_PKT_OFFSET)
#define SAFEXCEL_xDR_PROC_CLR_COUNT (1U << 31)
/* SAFEXCEL_HIA_xDR_STAT */
#define SAFEXCEL_xDR_DMA_ERR (1 << 0)
#define SAFEXCEL_xDR_PREP_CMD_THRES (1 << 1)
#define SAFEXCEL_xDR_ERR (1 << 2)
#define SAFEXCEL_xDR_THRESH (1 << 4)
#define SAFEXCEL_xDR_TIMEOUT (1 << 5)
#define SAFEXCEL_CDR_INTR_MASK 0x3f
#define SAFEXCEL_RDR_INTR_MASK 0xff
#define SAFEXCEL_HIA_RA_PE_CTRL_RESET (1U << 31)
#define SAFEXCEL_HIA_RA_PE_CTRL_EN (1 << 30)
/* Register offsets */
/* SAFEXCEL_HIA_DSE_THR_STAT */
#define SAFEXCEL_DSE_THR_RDR_ID_MASK 0xf000
/* SAFEXCEL_HIA_OPTIONS */
#define SAFEXCEL_OPT_ADDR_64 (1U << 31)
#define SAFEXCEL_OPT_TGT_ALIGN_OFFSET 28
#define SAFEXCEL_OPT_TGT_ALIGN_MASK 0x70000000
#define SAFEXCEL_xDR_HDW_OFFSET 25
#define SAFEXCEL_xDR_HDW_MASK 0x6000000
#define SAFEXCEL_N_RINGS_MASK 0xf
#define SAFEXCEL_N_PES_OFFSET 4
#define SAFEXCEL_N_PES_MASK 0x1f0
#define EIP97_N_PES_MASK 0x70
/* SAFEXCEL_HIA_AIC_R_ENABLE_CTRL */
#define SAFEXCEL_CDR_IRQ(n) (1 << ((n) * 2))
#define SAFEXCEL_RDR_IRQ(n) (1 << ((n) * 2 + 1))
/* SAFEXCEL_HIA_DFE/DSE_CFG */
#define SAFEXCEL_HIA_DxE_CFG_MIN_DATA_SIZE(n) ((n) << 0)
#define SAFEXCEL_HIA_DxE_CFG_DATA_CACHE_CTRL(n) (((n) & 0x7) << 4)
#define SAFEXCEL_HIA_DxE_CFG_MAX_DATA_SIZE(n) ((n) << 8)
#define SAFEXCEL_HIA_DSE_CFG_ALLWAYS_BUFFERABLE 0xc000
#define SAFEXCEL_HIA_DxE_CFG_MIN_CTRL_SIZE(n) ((n) << 16)
#define SAFEXCEL_HIA_DxE_CFG_CTRL_CACHE_CTRL(n) (((n) & 0x7) << 20)
#define SAFEXCEL_HIA_DxE_CFG_MAX_CTRL_SIZE(n) ((n) << 24)
#define SAFEXCEL_HIA_DFE_CFG_DIS_DEBUG 0xe0000000
#define SAFEXCEL_HIA_DSE_CFG_EN_SINGLE_WR (1 << 29)
#define SAFEXCEL_HIA_DSE_CFG_DIS_DEBUG 0xc0000000
/* SAFEXCEL_HIA_DFE/DSE_THR_CTRL */
#define SAFEXCEL_DxE_THR_CTRL_EN (1 << 30)
#define SAFEXCEL_DxE_THR_CTRL_RESET_PE (1U << 31)
/* SAFEXCEL_HIA_AIC_G_ENABLED_STAT */
#define SAFEXCEL_G_IRQ_DFE(n) (1 << ((n) << 1))
#define SAFEXCEL_G_IRQ_DSE(n) (1 << (((n) << 1) + 1))
#define SAFEXCEL_G_IRQ_RING (1 << 16)
#define SAFEXCEL_G_IRQ_PE(n) (1 << ((n) + 20))
/* SAFEXCEL_HIA_MST_CTRL */
#define RD_CACHE_3BITS 0x5U
#define WR_CACHE_3BITS 0x3U
#define RD_CACHE_4BITS (RD_CACHE_3BITS << 1 | (1 << 0))
#define WR_CACHE_4BITS (WR_CACHE_3BITS << 1 | (1 << 0))
#define SAFEXCEL_MST_CTRL_RD_CACHE(n) (((n) & 0xf) << 0)
#define SAFEXCEL_MST_CTRL_WD_CACHE(n) (((n) & 0xf) << 4)
#define MST_CTRL_SUPPORT_PROT(n) (((n) & 0xf) << 12)
#define SAFEXCEL_MST_CTRL_BYTE_SWAP (1 << 24)
#define SAFEXCEL_MST_CTRL_NO_BYTE_SWAP (1 << 25)
/* SAFEXCEL_PE_IN_DBUF/TBUF_THRES */
#define SAFEXCEL_PE_IN_xBUF_THRES_MIN(n) ((n) << 8)
#define SAFEXCEL_PE_IN_xBUF_THRES_MAX(n) ((n) << 12)
/* SAFEXCEL_PE_OUT_DBUF_THRES */
#define SAFEXCEL_PE_OUT_DBUF_THRES_MIN(n) ((n) << 0)
#define SAFEXCEL_PE_OUT_DBUF_THRES_MAX(n) ((n) << 4)
/* SAFEXCEL_HIA_AIC_G_ACK */
#define SAFEXCEL_AIC_G_ACK_ALL_MASK 0xffffffff
#define SAFEXCEL_AIC_G_ACK_HIA_MASK 0x7ff00000
/* SAFEXCEL_HIA_AIC_R_ENABLE_CLR */
#define SAFEXCEL_HIA_AIC_R_ENABLE_CLR_ALL_MASK 0xffffffff
/* SAFEXCEL_PE_EIP96_CONTEXT_CTRL */
#define SAFEXCEL_CONTEXT_SIZE(n) (n)
#define SAFEXCEL_ADDRESS_MODE (1 << 8)
#define SAFEXCEL_CONTROL_MODE (1 << 9)
/* SAFEXCEL_PE_EIP96_FUNCTION_EN */
#define SAFEXCEL_FUNCTION_RSVD ((1U << 6) | (1U << 15) | (1U << 20) | (1U << 23))
#define SAFEXCEL_PROTOCOL_HASH_ONLY (1U << 0)
#define SAFEXCEL_PROTOCOL_ENCRYPT_ONLY (1U << 1)
#define SAFEXCEL_PROTOCOL_HASH_ENCRYPT (1U << 2)
#define SAFEXCEL_PROTOCOL_HASH_DECRYPT (1U << 3)
#define SAFEXCEL_PROTOCOL_ENCRYPT_HASH (1U << 4)
#define SAFEXCEL_PROTOCOL_DECRYPT_HASH (1U << 5)
#define SAFEXCEL_ALG_ARC4 (1U << 7)
#define SAFEXCEL_ALG_AES_ECB (1U << 8)
#define SAFEXCEL_ALG_AES_CBC (1U << 9)
#define SAFEXCEL_ALG_AES_CTR_ICM (1U << 10)
#define SAFEXCEL_ALG_AES_OFB (1U << 11)
#define SAFEXCEL_ALG_AES_CFB (1U << 12)
#define SAFEXCEL_ALG_DES_ECB (1U << 13)
#define SAFEXCEL_ALG_DES_CBC (1U << 14)
#define SAFEXCEL_ALG_DES_OFB (1U << 16)
#define SAFEXCEL_ALG_DES_CFB (1U << 17)
#define SAFEXCEL_ALG_3DES_ECB (1U << 18)
#define SAFEXCEL_ALG_3DES_CBC (1U << 19)
#define SAFEXCEL_ALG_3DES_OFB (1U << 21)
#define SAFEXCEL_ALG_3DES_CFB (1U << 22)
#define SAFEXCEL_ALG_MD5 (1U << 24)
#define SAFEXCEL_ALG_HMAC_MD5 (1U << 25)
#define SAFEXCEL_ALG_SHA1 (1U << 26)
#define SAFEXCEL_ALG_HMAC_SHA1 (1U << 27)
#define SAFEXCEL_ALG_SHA2 (1U << 28)
#define SAFEXCEL_ALG_HMAC_SHA2 (1U << 29)
#define SAFEXCEL_ALG_AES_XCBC_MAC (1U << 30)
#define SAFEXCEL_ALG_GCM_HASH (1U << 31)
#endif /* _SAFEXCEL_REGS_H_ */

View File

@ -0,0 +1,420 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2020 Rubicon Communications, LLC (Netgate)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _SAFEXCEL_VAR_H_
#define _SAFEXCEL_VAR_H_
#define SAFEXCEL_MAX_RINGS 4
#define SAFEXCEL_MAX_BATCH_SIZE 64
#define SAFEXCEL_MAX_FRAGMENTS 64
#define SAFEXCEL_MAX_IV_LEN 16
#define SAFEXCEL_MAX_REQUEST_SIZE 65535
#define SAFEXCEL_RING_SIZE 512
#define SAFEXCEL_REQUESTS_PER_RING 64
#define SAFEXCEL_MAX_ITOKENS 4
#define SAFEXCEL_MAX_ATOKENS 16
#define SAFEXCEL_FETCH_COUNT 1
#define SAFEXCEL_MAX_KEY_LEN 32
#define SAFEXCEL_MAX_RING_AIC 14
/*
* Context Record format.
*
* In this driver the context control words are always set in the control data.
* This is configured by setting SAFEXCEL_OPTION_CTX_CTRL_IN_CMD.
*/
struct safexcel_context_record {
uint32_t control0; /* Unused. */
uint32_t control1; /* Unused. */
uint32_t data[40]; /* Key material. */
} __packed;
/* Processing Engine Control Data format. */
struct safexcel_control_data {
uint32_t packet_length : 17;
uint32_t options : 13;
uint32_t type : 2;
uint16_t application_id;
uint16_t rsvd;
uint32_t context_lo;
uint32_t context_hi;
uint32_t control0;
uint32_t control1;
/* Inline instructions or IV. */
uint32_t token[SAFEXCEL_MAX_ITOKENS];
} __packed;
/*
* Basic Command Descriptor.
*
* The Processing Engine and driver cooperate to maintain a set of command
* rings, representing outstanding crypto operation requests. Each descriptor
* corresponds to an input data segment, and thus a single crypto(9) request may
* span several contiguous command descriptors.
*
* The first command descriptor for a request stores the input token, which
* encodes data specific to the requested operation, such as the encryption
* mode. For some operations data is passed outside the descriptor, in a
* context record (e.g., encryption keys), or in an "additional token data"
* region (e.g., instructions).
*/
struct safexcel_cmd_descr {
uint32_t particle_size : 17;
uint32_t rsvd0 : 5;
uint32_t last_seg : 1;
uint32_t first_seg : 1;
uint32_t additional_cdata_size : 8;
uint32_t rsvd1;
uint32_t data_lo;
uint32_t data_hi;
uint32_t atok_lo;
uint32_t atok_hi;
struct safexcel_control_data control_data;
} __packed;
/* Context control word 0 fields. */
#define SAFEXCEL_CONTROL0_TYPE_NULL_OUT 0x0
#define SAFEXCEL_CONTROL0_TYPE_NULL_IN 0x1
#define SAFEXCEL_CONTROL0_TYPE_HASH_OUT 0x2
#define SAFEXCEL_CONTROL0_TYPE_HASH_IN 0x3
#define SAFEXCEL_CONTROL0_TYPE_CRYPTO_OUT 0x4
#define SAFEXCEL_CONTROL0_TYPE_CRYPTO_IN 0x5
#define SAFEXCEL_CONTROL0_TYPE_ENCRYPT_HASH_OUT 0x6
#define SAFEXCEL_CONTROL0_TYPE_DECRYPT_HASH_IN 0x7
#define SAFEXCEL_CONTROL0_TYPE_HASH_ENCRYPT_OUT 0xe
#define SAFEXCEL_CONTROL0_TYPE_HASH_DECRYPT_IN 0xf
#define SAFEXCEL_CONTROL0_RESTART_HASH (1 << 4)
#define SAFEXCEL_CONTROL0_NO_FINISH_HASH (1 << 5)
#define SAFEXCEL_CONTROL0_SIZE(n) (((n) & 0xff) << 8)
#define SAFEXCEL_CONTROL0_KEY_EN (1 << 16)
#define SAFEXCEL_CONTROL0_CRYPTO_ALG_AES128 (0x5 << 17)
#define SAFEXCEL_CONTROL0_CRYPTO_ALG_AES192 (0x6 << 17)
#define SAFEXCEL_CONTROL0_CRYPTO_ALG_AES256 (0x7 << 17)
#define SAFEXCEL_CONTROL0_DIGEST_PRECOMPUTED (0x1 << 21)
#define SAFEXCEL_CONTROL0_DIGEST_CCM (0x2 << 21)
#define SAFEXCEL_CONTROL0_DIGEST_GMAC (0x2 << 21)
#define SAFEXCEL_CONTROL0_DIGEST_HMAC (0x3 << 21)
#define SAFEXCEL_CONTROL0_HASH_ALG_SHA1 (0x2 << 23)
#define SAFEXCEL_CONTROL0_HASH_ALG_SHA224 (0x4 << 23)
#define SAFEXCEL_CONTROL0_HASH_ALG_SHA256 (0x3 << 23)
#define SAFEXCEL_CONTROL0_HASH_ALG_SHA384 (0x6 << 23)
#define SAFEXCEL_CONTROL0_HASH_ALG_SHA512 (0x5 << 23)
#define SAFEXCEL_CONTROL0_HASH_ALG_XCBC128 (0x1 << 23)
#define SAFEXCEL_CONTROL0_HASH_ALG_XCBC192 (0x2 << 23)
#define SAFEXCEL_CONTROL0_HASH_ALG_XCBC256 (0x3 << 23)
#define SAFEXCEL_CONTROL0_HASH_ALG_GHASH (0x4 << 23)
#define SAFEXCEL_CONTROL0_INV_FR (0x5 << 24)
#define SAFEXCEL_CONTROL0_INV_TR (0x6 << 24)
/* Context control word 1 fields. */
#define SAFEXCEL_CONTROL1_CRYPTO_MODE_ECB 0x0
#define SAFEXCEL_CONTROL1_CRYPTO_MODE_CBC 0x1
#define SAFEXCEL_CONTROL1_CRYPTO_MODE_ICM 0x3
#define SAFEXCEL_CONTROL1_CRYPTO_MODE_OFB 0x4
#define SAFEXCEL_CONTROL1_CRYPTO_MODE_CFB128 0x5
#define SAFEXCEL_CONTROL1_CRYPTO_MODE_CTR 0x6
#define SAFEXCEL_CONTROL1_CRYPTO_MODE_XTS 0x7
#define SAFEXCEL_CONTROL1_CRYPTO_MODE_CCM (0x6 | (1 << 17))
#define SAFEXCEL_CONTROL1_CRYPTO_MODE_GCM (0x6 | (1 << 17))
#define SAFEXCEL_CONTROL1_IV0 (1u << 5)
#define SAFEXCEL_CONTROL1_IV1 (1u << 6)
#define SAFEXCEL_CONTROL1_IV2 (1u << 7)
#define SAFEXCEL_CONTROL1_IV3 (1u << 8)
#define SAFEXCEL_CONTROL1_DIGEST_CNT (1u << 9)
#define SAFEXCEL_CONTROL1_COUNTER_MODE (1u << 10)
#define SAFEXCEL_CONTROL1_ENCRYPT_HASH_RES (1u << 17)
#define SAFEXCEL_CONTROL1_HASH_STORE (1u << 19)
/* Control options. */
#define SAFEXCEL_OPTION_IP (1u << 0) /* must be set */
#define SAFEXCEL_OPTION_CP (1u << 1) /* 64-bit ctx addr */
#define SAFEXCEL_OPTION_RC_AUTO (2u << 3) /* auto ctx reuse */
#define SAFEXCEL_OPTION_CTX_CTRL_IN_CMD (1u << 8) /* ctx ctrl */
#define SAFEXCEL_OPTION_4_TOKEN_IV_CMD 0xe00 /* IV in bypass */
struct safexcel_res_data {
uint32_t packet_length : 17;
uint32_t error_code : 15;
uint32_t bypass_length : 4;
uint32_t e15 : 1;
uint32_t rsvd0 : 16;
uint32_t hash_bytes : 1;
uint32_t hash_length : 6;
uint32_t generic_bytes : 1;
uint32_t checksum : 1;
uint32_t next_header : 1;
uint32_t length : 1;
uint16_t application_id;
uint16_t rsvd1;
uint32_t rsvd2;
};
/* Basic Result Descriptor format */
struct safexcel_res_descr {
uint32_t particle_size : 17;
uint32_t rsvd0 : 3;
uint32_t descriptor_overflow : 1;
uint32_t buffer_overflow : 1;
uint32_t last_seg : 1;
uint32_t first_seg : 1;
uint32_t result_size : 8;
uint32_t rsvd1;
uint32_t data_lo;
uint32_t data_hi;
struct safexcel_res_data result_data;
} __packed;
/* Result data error codes. */
#define SAFEXCEL_RESULT_ERR_PACKET_LEN (1u << 0)
#define SAFEXCEL_RESULT_ERR_TOKEN_ERROR (1u << 1)
#define SAFEXCEL_RESULT_ERR_BYPASS (1u << 2)
#define SAFEXCEL_RESULT_ERR_CRYPTO_BLOCK_SIZE (1u << 3)
#define SAFEXCEL_RESULT_ERR_HASH_BLOCK_SIZE (1u << 4)
#define SAFEXCEL_RESULT_ERR_INVALID_CMD (1u << 5)
#define SAFEXCEL_RESULT_ERR_PROHIBITED_ALGO (1u << 6)
#define SAFEXCEL_RESULT_ERR_HASH_INPUT_OVERFLOW (1u << 7)
#define SAFEXCEL_RESULT_ERR_TTL_UNDERFLOW (1u << 8)
#define SAFEXCEL_RESULT_ERR_AUTH_FAILED (1u << 9)
#define SAFEXCEL_RESULT_ERR_SEQNO_CHECK_FAILED (1u << 10)
#define SAFEXCEL_RESULT_ERR_SPI_CHECK (1u << 11)
#define SAFEXCEL_RESULT_ERR_CHECKSUM (1u << 12)
#define SAFEXCEL_RESULT_ERR_PAD_VERIFICATION (1u << 13)
#define SAFEXCEL_RESULT_ERR_TIMEOUT (1u << 14)
#define SAFEXCEL_RESULT_ERR_OUTPUT_DMA (1u << 15)
/*
* The EIP-96 (crypto transform engine) is programmed using a set of
* data processing instructions with the encodings defined below.
*/
struct safexcel_instr {
uint32_t length : 17; /* bytes to be processed */
uint32_t status : 2; /* stream status */
uint32_t instructions : 9;
uint32_t opcode : 4;
} __packed;
/* Type 1, operational data instructions. */
#define SAFEXCEL_INSTR_OPCODE_DIRECTION 0x0
#define SAFEXCEL_INSTR_OPCODE_PRE_CHECKSUM 0x1
#define SAFEXCEL_INSTR_OPCODE_INSERT 0x2
#define SAFEXCEL_INSTR_OPCODE_INSERT_CTX 0x9
#define SAFEXCEL_INSTR_OPCODE_REPLACE 0x3
#define SAFEXCEL_INSTR_OPCODE_RETRIEVE 0x4
#define SAFEXCEL_INSTR_OPCODE_MUTE 0x5
/* Type 2, IP header instructions. */
#define SAFEXCEL_INSTR_OPCODE_IPV4 0x7
#define SAFEXCEL_INSTR_OPCODE_IPV4_CHECKSUM 0x6
#define SAFEXCEL_INSTR_OPCODE_IPV6 0x8
/* Type 3, postprocessing instructions. */
#define SAFEXCEL_INSTR_OPCODE_INSERT_REMOVE_RESULT 0xa
#define SAFEXCEL_INSTR_OPCODE_REPLACE_BYTE 0xb
/* Type 4, result instructions. */
#define SAFEXCEL_INSTR_OPCODE_VERIFY_FIELDS 0xd
/* Type 5, context control instructions. */
#define SAFEXCEL_INSTR_OPCODE_CONTEXT_ACCESS 0xe
/* Type 6, context control instructions. */
#define SAFEXCEL_INSTR_OPCODE_BYPASS_TOKEN_DATA 0xf
/* Status bits for type 1 and 2 instructions. */
#define SAFEXCEL_INSTR_STATUS_LAST_HASH (1u << 0)
#define SAFEXCEL_INSTR_STATUS_LAST_PACKET (1u << 1)
/* Status bits for type 3 instructions. */
#define SAFEXCEL_INSTR_STATUS_NO_CKSUM_MOD (1u << 0)
/* Instruction-dependent flags. */
#define SAFEXCEL_INSTR_INSERT_HASH_DIGEST 0x1c
#define SAFEXCEL_INSTR_INSERT_IMMEDIATE 0x1b
#define SAFEXCEL_INSTR_DEST_OUTPUT (1u << 5)
#define SAFEXCEL_INSTR_DEST_HASH (1u << 6)
#define SAFEXCEL_INSTR_DEST_CRYPTO (1u << 7)
#define SAFEXCEL_INSTR_INS_LAST (1u << 8)
#define SAFEXCEL_INSTR_VERIFY_HASH (1u << 16)
#define SAFEXCEL_INSTR_VERIFY_PADDING (1u << 5)
#define SAFEXCEL_TOKEN_TYPE_BYPASS 0x0
#define SAFEXCEL_TOKEN_TYPE_AUTONOMOUS 0x3
#define SAFEXCEL_CONTEXT_SMALL 0x2
#define SAFEXCEL_CONTEXT_LARGE 0x3
struct safexcel_reg_offsets {
uint32_t hia_aic;
uint32_t hia_aic_g;
uint32_t hia_aic_r;
uint32_t hia_aic_xdr;
uint32_t hia_dfe;
uint32_t hia_dfe_thr;
uint32_t hia_dse;
uint32_t hia_dse_thr;
uint32_t hia_gen_cfg;
uint32_t pe;
};
struct safexcel_config {
uint32_t hdw; /* Host interface Data Width. */
uint32_t aic_rings; /* Number of AIC rings. */
uint32_t pes; /* Number of PEs. */
uint32_t rings; /* Number of rings. */
uint32_t cd_size; /* CDR descriptor size. */
uint32_t cd_offset; /* CDR offset (size + alignment). */
uint32_t rd_size; /* RDR descriptor size. */
uint32_t rd_offset; /* RDR offset. */
uint32_t atok_offset; /* Additional token offset. */
uint32_t caps; /* Device capabilities. */
};
#define SAFEXCEL_DPRINTF(sc, lvl, ...) do { \
if ((sc)->sc_debug >= (lvl)) \
device_printf((sc)->sc_dev, __VA_ARGS__); \
} while (0)
struct safexcel_dma_mem {
caddr_t vaddr;
bus_addr_t paddr;
bus_dma_tag_t tag;
bus_dmamap_t map;
};
struct safexcel_cmd_descr_ring {
struct safexcel_dma_mem dma;
struct safexcel_cmd_descr *desc;
int write;
int read;
};
struct safexcel_res_descr_ring {
struct safexcel_dma_mem dma;
struct safexcel_res_descr *desc;
int write;
int read;
};
struct safexcel_session {
int ringidx;
uint32_t alg; /* cipher algorithm */
uint32_t digest; /* digest type */
uint32_t hash; /* hash algorithm */
uint32_t mode; /* cipher mode of operation */
unsigned int digestlen; /* digest length */
unsigned int statelen; /* HMAC hash state length */
unsigned int klen; /* cipher key length */
union {
uint32_t ghash_key[AES_BLOCK_LEN / sizeof(uint32_t)];
uint32_t xcbc_key[(AES_BLOCK_LEN * 2 + AES_MAX_KEY) /
sizeof(uint32_t)];
uint8_t tweak_key[AES_MAX_KEY];
};
struct {
uint8_t hmac_ipad[HMAC_MAX_BLOCK_LEN];
uint8_t hmac_opad[HMAC_MAX_BLOCK_LEN];
};
};
struct safexcel_softc;
struct safexcel_request {
STAILQ_ENTRY(safexcel_request) link;
bool dmap_loaded;
bus_dmamap_t dmap;
int error;
int cdescs, rdescs;
uint8_t iv[SAFEXCEL_MAX_IV_LEN];
struct safexcel_cmd_descr *cdesc;
struct safexcel_dma_mem ctx;
struct safexcel_session *sess;
struct cryptop *crp;
struct safexcel_softc *sc;
};
struct safexcel_ring {
struct mtx mtx;
struct sglist *cmd_data;
struct safexcel_cmd_descr_ring cdr;
struct sglist *res_data;
struct safexcel_res_descr_ring rdr;
struct safexcel_request *requests;
STAILQ_HEAD(, safexcel_request) ready_requests;
STAILQ_HEAD(, safexcel_request) queued_requests;
STAILQ_HEAD(, safexcel_request) free_requests;
struct safexcel_dma_mem dma_atok;
bus_dma_tag_t data_dtag;
};
struct safexcel_intr_handle {
struct safexcel_softc *sc;
void *handle;
int ring;
};
struct safexcel_softc {
device_t sc_dev;
uint32_t sc_type; /* EIP-97 or 197 */
int sc_debug;
struct resource *sc_res;
struct resource *sc_intr[SAFEXCEL_MAX_RINGS];
struct safexcel_intr_handle sc_ih[SAFEXCEL_MAX_RINGS];
struct safexcel_ring sc_ring[SAFEXCEL_MAX_RINGS];
int sc_ringidx;
struct mtx sc_mtx;
int sc_blocked;
int32_t sc_cid;
struct safexcel_reg_offsets sc_offsets;
struct safexcel_config sc_config;
};
#define SAFEXCEL_WRITE(sc, off, val) bus_write_4((sc)->sc_res, (off), (val))
#define SAFEXCEL_READ(sc, off) bus_read_4((sc)->sc_res, (off))
#define SAFEXCEL_ADDR_LO(addr) ((uint64_t)(addr) & 0xffffffffu)
#define SAFEXCEL_ADDR_HI(addr) (((uint64_t)(addr) >> 32) & 0xffffffffu)
#endif /* _SAFEXCEL_VAR_H_ */

View File

@ -317,6 +317,7 @@ SUBDIR= \
${_rtwnfw} \
${_s3} \
${_safe} \
safexcel \
${_sbni} \
scc \
${_sctp} \

View File

@ -0,0 +1,9 @@
# $FreeBSD$
.PATH: ${SRCTOP}/sys/dev/safexcel
KMOD= safexcel
SRCS= safexcel.c
SRCS+= bus_if.h cryptodev_if.h device_if.h ofw_bus_if.h
.include <bsd.kmod.mk>