2019-05-27 08:55:06 +02:00
/* SPDX-License-Identifier: GPL-2.0-or-later */
crypto: amcc - fix incorrect kernel-doc comment syntax in files
The opening comment mark '/**' is used for highlighting the beginning of
kernel-doc comments.
There are certain files in drivers/crypto/amcc, which follow this syntax,
but the content inside does not comply with kernel-doc.
Such lines were probably not meant for kernel-doc parsing, but are parsed
due to the presence of kernel-doc like comment syntax(i.e, '/**'), which
causes unexpected warnings from kernel-doc.
E.g., presence of kernel-doc like comment in
drivers/crypto/amcc/crypto4xx_alg.c at header, and some other lines,
causes these warnings by kernel-doc:
"warning: expecting prototype for AMCC SoC PPC4xx Crypto Driver(). Prototype was for set_dynamic_sa_command_0() instead"
"warning: Function parameter or member 'dir' not described in 'set_dynamic_sa_command_0'"
etc..
Provide a simple fix by replacing such occurrences with general comment
format, i.e. '/*', to prevent kernel-doc from parsing it.
Signed-off-by: Aditya Srivastava <yashsri421@gmail.com>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-03-21 17:38:32 +05:30
/*
2009-02-05 16:18:13 +11:00
* AMCC SoC PPC4xx Crypto Driver
*
* Copyright ( c ) 2008 Applied Micro Circuits Corporation .
* All rights reserved . James Hsiao < jhsiao @ amcc . com >
*
* This is the header file for AMCC Crypto offload Linux device driver for
* use with Linux CryptoAPI .
*/
# ifndef __CRYPTO4XX_CORE_H__
# define __CRYPTO4XX_CORE_H__
2017-10-04 01:00:15 +02:00
# include <linux/ratelimit.h>
2018-12-23 02:16:13 +01:00
# include <linux/mutex.h>
2020-08-19 21:58:20 +10:00
# include <linux/scatterlist.h>
2009-07-14 20:21:46 +08:00
# include <crypto/internal/hash.h>
2017-10-04 01:00:15 +02:00
# include <crypto/internal/aead.h>
2018-12-23 02:16:13 +01:00
# include <crypto/internal/rng.h>
2018-04-19 18:41:52 +02:00
# include <crypto/internal/skcipher.h>
2017-08-25 15:47:25 +02:00
# include "crypto4xx_reg_def.h"
# include "crypto4xx_sa.h"
2009-07-14 20:21:46 +08:00
2009-02-05 16:18:13 +11:00
# define PPC460SX_SDR0_SRST 0x201
# define PPC405EX_SDR0_SRST 0x200
# define PPC460EX_SDR0_SRST 0x201
# define PPC460EX_CE_RESET 0x08000000
# define PPC460SX_CE_RESET 0x20000000
# define PPC405EX_CE_RESET 0x00000008
# define CRYPTO4XX_CRYPTO_PRIORITY 300
2017-10-04 01:00:08 +02:00
# define PPC4XX_NUM_PD 256
# define PPC4XX_LAST_PD (PPC4XX_NUM_PD - 1)
2009-02-05 16:18:13 +11:00
# define PPC4XX_NUM_GD 1024
2017-10-04 01:00:08 +02:00
# define PPC4XX_LAST_GD (PPC4XX_NUM_GD - 1)
# define PPC4XX_NUM_SD 256
# define PPC4XX_LAST_SD (PPC4XX_NUM_SD - 1)
2009-02-05 16:18:13 +11:00
# define PPC4XX_SD_BUFFER_SIZE 2048
crypto: crypto4xx - add backlog queue support
Previously, If the crypto4xx driver used all available
security contexts, it would simply refuse new requests
with -EAGAIN. CRYPTO_TFM_REQ_MAY_BACKLOG was ignored.
in case of dm-crypt.c's crypt_convert() function this was
causing the following errors to manifest, if the system was
pushed hard enough:
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| JBD2: Detected IO errors while flushing file data on dm-1-8
| Aborting journal on device dm-1-8.
| EXT4-fs error : ext4_journal_check_start:56: Detected aborted journal
| EXT4-fs (dm-1): Remounting filesystem read-only
| EXT4-fs : ext4_writepages: jbd2_start: 2048 pages, inode 498...; err -30
(This did cause corruptions due to failed writes)
To fix this mess, the crypto4xx driver needs to notifiy the
user to slow down. This can be achieved by returning -EBUSY
on requests, once the crypto hardware was falling behind.
Note: -EBUSY has two different meanings. Setting the flag
CRYPTO_TFM_REQ_MAY_BACKLOG implies that the request was
successfully queued, by the crypto driver. To achieve this
requirement, the implementation introduces a threshold check and
adds logic to the completion routines in much the same way as
AMD's Cryptographic Coprocessor (CCP) driver do.
Note2: Tests showed that dm-crypt starved ipsec traffic.
Under load, ipsec links dropped to 0 Kbits/s. This is because
dm-crypt's callback would instantly queue the next request.
In order to not starve ipsec, the driver reserves a small
portion of the available crypto contexts for this purpose.
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-10-04 01:00:09 +02:00
# define PD_ENTRY_BUSY BIT(1)
# define PD_ENTRY_INUSE BIT(0)
2009-02-05 16:18:13 +11:00
# define PD_ENTRY_FREE 0
# define ERING_WAS_FULL 0xffffffff
struct crypto4xx_device ;
2017-08-25 15:47:25 +02:00
union shadow_sa_buf {
struct dynamic_sa_ctl sa ;
/* alloc 256 bytes which is enough for any kind of dynamic sa */
u8 buf [ 256 ] ;
} __packed ;
2009-02-05 16:18:13 +11:00
struct pd_uinfo {
struct crypto4xx_device * dev ;
u32 state ;
u32 first_gd ; /* first gather discriptor
used by this packet */
u32 num_gd ; /* number of gather discriptor
used by this packet */
u32 first_sd ; /* first scatter discriptor
used by this packet */
u32 num_sd ; /* number of scatter discriptors
used by this packet */
2017-08-25 15:47:25 +02:00
struct dynamic_sa_ctl * sa_va ; /* shadow sa */
struct sa_state_record * sr_va ; /* state record for shadow sa */
2009-02-05 16:18:13 +11:00
u32 sr_pa ;
struct scatterlist * dest_va ;
struct crypto_async_request * async_req ; /* base crypto request
for this packet */
} ;
struct crypto4xx_device {
struct crypto4xx_core_device * core_dev ;
void __iomem * ce_base ;
2016-04-18 12:57:41 +02:00
void __iomem * trng_base ;
2009-02-05 16:18:13 +11:00
2017-08-25 15:47:25 +02:00
struct ce_pd * pdr ; /* base address of packet descriptor ring */
dma_addr_t pdr_pa ; /* physical address of pdr_base_register */
struct ce_gd * gdr ; /* gather descriptor ring */
dma_addr_t gdr_pa ; /* physical address of gdr_base_register */
struct ce_sd * sdr ; /* scatter descriptor ring */
dma_addr_t sdr_pa ; /* physical address of sdr_base_register */
2009-02-05 16:18:13 +11:00
void * scatter_buffer_va ;
dma_addr_t scatter_buffer_pa ;
2017-08-25 15:47:25 +02:00
union shadow_sa_buf * shadow_sa_pool ;
2009-02-05 16:18:13 +11:00
dma_addr_t shadow_sa_pool_pa ;
2017-08-25 15:47:25 +02:00
struct sa_state_record * shadow_sr_pool ;
2009-02-05 16:18:13 +11:00
dma_addr_t shadow_sr_pool_pa ;
u32 pdr_tail ;
u32 pdr_head ;
u32 gdr_tail ;
u32 gdr_head ;
u32 sdr_tail ;
u32 sdr_head ;
2017-08-25 15:47:25 +02:00
struct pd_uinfo * pdr_uinfo ;
2009-02-05 16:18:13 +11:00
struct list_head alg_list ; /* List of algorithm supported
by this device */
2017-10-04 01:00:15 +02:00
struct ratelimit_state aead_ratelimit ;
2017-12-22 21:18:36 +01:00
bool is_revb ;
2009-02-05 16:18:13 +11:00
} ;
struct crypto4xx_core_device {
struct device * device ;
2010-08-06 09:25:50 -06:00
struct platform_device * ofdev ;
2009-02-05 16:18:13 +11:00
struct crypto4xx_device * dev ;
2016-04-18 12:57:41 +02:00
struct hwrng * trng ;
2009-02-05 16:18:13 +11:00
u32 int_status ;
u32 irq ;
struct tasklet_struct tasklet ;
spinlock_t lock ;
2018-12-23 02:16:13 +01:00
struct mutex rng_lock ;
2009-02-05 16:18:13 +11:00
} ;
struct crypto4xx_ctx {
struct crypto4xx_device * dev ;
2017-08-25 15:47:25 +02:00
struct dynamic_sa_ctl * sa_in ;
struct dynamic_sa_ctl * sa_out ;
2017-10-04 01:00:14 +02:00
__le32 iv_nonce ;
2009-02-05 16:18:13 +11:00
u32 sa_len ;
2017-10-04 01:00:15 +02:00
union {
2019-04-22 13:26:00 +02:00
struct crypto_sync_skcipher * cipher ;
2017-10-04 01:00:15 +02:00
struct crypto_aead * aead ;
} sw_cipher ;
2009-02-05 16:18:13 +11:00
} ;
2018-04-19 18:41:57 +02:00
struct crypto4xx_aead_reqctx {
struct scatterlist dst [ 2 ] ;
} ;
2009-07-14 20:21:46 +08:00
struct crypto4xx_alg_common {
u32 type ;
union {
2018-04-19 18:41:52 +02:00
struct skcipher_alg cipher ;
2009-07-14 20:21:46 +08:00
struct ahash_alg hash ;
2017-10-04 01:00:15 +02:00
struct aead_alg aead ;
2018-12-23 02:16:13 +01:00
struct rng_alg rng ;
2009-07-14 20:21:46 +08:00
} u ;
} ;
2009-02-05 16:18:13 +11:00
struct crypto4xx_alg {
struct list_head entry ;
2009-07-14 20:21:46 +08:00
struct crypto4xx_alg_common alg ;
2009-02-05 16:18:13 +11:00
struct crypto4xx_device * dev ;
} ;
2017-08-25 15:47:17 +02:00
int crypto4xx_alloc_sa ( struct crypto4xx_ctx * ctx , u32 size ) ;
void crypto4xx_free_sa ( struct crypto4xx_ctx * ctx ) ;
void crypto4xx_free_ctx ( struct crypto4xx_ctx * ctx ) ;
2017-10-04 01:00:10 +02:00
int crypto4xx_build_pd ( struct crypto_async_request * req ,
2017-08-25 15:47:17 +02:00
struct crypto4xx_ctx * ctx ,
struct scatterlist * src ,
struct scatterlist * dst ,
2017-10-04 01:00:11 +02:00
const unsigned int datalen ,
const __le32 * iv , const u32 iv_len ,
const struct dynamic_sa_ctl * sa ,
2017-10-04 01:00:15 +02:00
const unsigned int sa_len ,
2018-04-19 18:41:57 +02:00
const unsigned int assoclen ,
struct scatterlist * dst_tmp ) ;
2018-04-19 18:41:52 +02:00
int crypto4xx_setkey_aes_cbc ( struct crypto_skcipher * cipher ,
2017-08-25 15:47:17 +02:00
const u8 * key , unsigned int keylen ) ;
2018-04-19 18:41:52 +02:00
int crypto4xx_setkey_aes_cfb ( struct crypto_skcipher * cipher ,
2017-08-25 15:47:21 +02:00
const u8 * key , unsigned int keylen ) ;
2018-04-19 18:41:54 +02:00
int crypto4xx_setkey_aes_ctr ( struct crypto_skcipher * cipher ,
const u8 * key , unsigned int keylen ) ;
2018-04-19 18:41:52 +02:00
int crypto4xx_setkey_aes_ecb ( struct crypto_skcipher * cipher ,
2017-08-25 15:47:21 +02:00
const u8 * key , unsigned int keylen ) ;
2018-04-19 18:41:52 +02:00
int crypto4xx_setkey_aes_ofb ( struct crypto_skcipher * cipher ,
2017-08-25 15:47:21 +02:00
const u8 * key , unsigned int keylen ) ;
2018-04-19 18:41:52 +02:00
int crypto4xx_setkey_rfc3686 ( struct crypto_skcipher * cipher ,
2017-08-25 15:47:21 +02:00
const u8 * key , unsigned int keylen ) ;
2018-04-19 18:41:54 +02:00
int crypto4xx_encrypt_ctr ( struct skcipher_request * req ) ;
int crypto4xx_decrypt_ctr ( struct skcipher_request * req ) ;
2019-05-18 23:28:12 +02:00
int crypto4xx_encrypt_iv_stream ( struct skcipher_request * req ) ;
int crypto4xx_decrypt_iv_stream ( struct skcipher_request * req ) ;
int crypto4xx_encrypt_iv_block ( struct skcipher_request * req ) ;
int crypto4xx_decrypt_iv_block ( struct skcipher_request * req ) ;
int crypto4xx_encrypt_noiv_block ( struct skcipher_request * req ) ;
int crypto4xx_decrypt_noiv_block ( struct skcipher_request * req ) ;
2018-04-19 18:41:52 +02:00
int crypto4xx_rfc3686_encrypt ( struct skcipher_request * req ) ;
int crypto4xx_rfc3686_decrypt ( struct skcipher_request * req ) ;
2017-08-25 15:47:17 +02:00
int crypto4xx_sha1_alg_init ( struct crypto_tfm * tfm ) ;
int crypto4xx_hash_digest ( struct ahash_request * req ) ;
int crypto4xx_hash_final ( struct ahash_request * req ) ;
int crypto4xx_hash_update ( struct ahash_request * req ) ;
int crypto4xx_hash_init ( struct ahash_request * req ) ;
2017-10-04 01:00:10 +02:00
crypto: amcc - fix incorrect kernel-doc comment syntax in files
The opening comment mark '/**' is used for highlighting the beginning of
kernel-doc comments.
There are certain files in drivers/crypto/amcc, which follow this syntax,
but the content inside does not comply with kernel-doc.
Such lines were probably not meant for kernel-doc parsing, but are parsed
due to the presence of kernel-doc like comment syntax(i.e, '/**'), which
causes unexpected warnings from kernel-doc.
E.g., presence of kernel-doc like comment in
drivers/crypto/amcc/crypto4xx_alg.c at header, and some other lines,
causes these warnings by kernel-doc:
"warning: expecting prototype for AMCC SoC PPC4xx Crypto Driver(). Prototype was for set_dynamic_sa_command_0() instead"
"warning: Function parameter or member 'dir' not described in 'set_dynamic_sa_command_0'"
etc..
Provide a simple fix by replacing such occurrences with general comment
format, i.e. '/*', to prevent kernel-doc from parsing it.
Signed-off-by: Aditya Srivastava <yashsri421@gmail.com>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-03-21 17:38:32 +05:30
/*
2017-10-04 01:00:10 +02:00
* Note : Only use this function to copy items that is word aligned .
*/
static inline void crypto4xx_memcpy_swab32 ( u32 * dst , const void * buf ,
size_t len )
{
for ( ; len > = 4 ; buf + = 4 , len - = 4 )
* dst + + = __swab32p ( ( u32 * ) buf ) ;
if ( len ) {
const u8 * tmp = ( u8 * ) buf ;
switch ( len ) {
case 3 :
* dst = ( tmp [ 2 ] < < 16 ) |
( tmp [ 1 ] < < 8 ) |
tmp [ 0 ] ;
break ;
case 2 :
* dst = ( tmp [ 1 ] < < 8 ) |
tmp [ 0 ] ;
break ;
case 1 :
* dst = tmp [ 0 ] ;
break ;
default :
break ;
}
}
}
static inline void crypto4xx_memcpy_from_le32 ( u32 * dst , const void * buf ,
size_t len )
{
crypto4xx_memcpy_swab32 ( dst , buf , len ) ;
}
static inline void crypto4xx_memcpy_to_le32 ( __le32 * dst , const void * buf ,
size_t len )
{
crypto4xx_memcpy_swab32 ( ( u32 * ) dst , buf , len ) ;
}
2017-10-04 01:00:16 +02:00
int crypto4xx_setauthsize_aead ( struct crypto_aead * ciper ,
unsigned int authsize ) ;
int crypto4xx_setkey_aes_ccm ( struct crypto_aead * cipher ,
const u8 * key , unsigned int keylen ) ;
int crypto4xx_encrypt_aes_ccm ( struct aead_request * req ) ;
int crypto4xx_decrypt_aes_ccm ( struct aead_request * req ) ;
2017-10-04 01:00:17 +02:00
int crypto4xx_setkey_aes_gcm ( struct crypto_aead * cipher ,
const u8 * key , unsigned int keylen ) ;
int crypto4xx_encrypt_aes_gcm ( struct aead_request * req ) ;
int crypto4xx_decrypt_aes_gcm ( struct aead_request * req ) ;
2017-10-04 01:00:16 +02:00
2009-02-05 16:18:13 +11:00
# endif