crypto: hisilicon - Add HiSilicon ADVCA Subsystem
Subsystems (2)
v3 cover crypto: hisilicon - Add HiSilicon ADVCA Subsystem
HiSilicon ADVCA Subsystem contains various cryptographic devices, including symmetric key ciphers, hash functions, RSA algorithms, as well as key ladder and OTP memory.
This series adds symmetric key cipher and SHA algorithm family driver.
This series is based on Hi3798Mv100.
v2: sorry, I accidentally skipped v1.
v3:
* use devm_reset_control_get_optional_exclusive
* disable clocks if init failed
* put device reset when removal
* implement import function for sha device
* fix typo reported by test bot
David Yang (2):
crypto: hisilicon - Add HiSilicon ADVCA Subsystem
crypto: hisilicon/advca - Add SHA support
drivers/crypto/hisilicon/Kconfig | 11 + drivers/crypto/hisilicon/Makefile | 1 + drivers/crypto/hisilicon/advca/Makefile | 2 + .../crypto/hisilicon/advca/hisi-advca-muc.c | 1536 +++++++++++++++++ .../crypto/hisilicon/advca/hisi-advca-sha.c | 658 +++++++ 5 files changed, 2208 insertions(+) create mode 100644 drivers/crypto/hisilicon/advca/Makefile create mode 100644 drivers/crypto/hisilicon/advca/hisi-advca-muc.c create mode 100644 drivers/crypto/hisilicon/advca/hisi-advca-sha.c
base-commit: 44c026a73be8038f03dbdeef028b642880cf1511
Signature · 1 line
2.39.2
PATCH v3 1/2 crypto: hisilicon - Add HiSilicon ADVCA Subsystem
HiSilicon ADVCA Subsystem contains various cryptographic devices, including symmetric key ciphers, hash functions, RSA algorithms, as well as key ladder and OTP memory.
This patch adds symmetric key cipher driver.
--- drivers/crypto/hisilicon/Kconfig | 8 + drivers/crypto/hisilicon/Makefile | 1 + drivers/crypto/hisilicon/advca/Makefile | 1 + .../crypto/hisilicon/advca/hisi-advca-muc.c | 1536 +++++++++++++++++ 4 files changed, 1546 insertions(+) create mode 100644 drivers/crypto/hisilicon/advca/Makefile create mode 100644 drivers/crypto/hisilicon/advca/hisi-advca-muc.c
drivers/crypto/hisilicon/Kconfig +8 -0
@@ -1,5 +1,13 @@ # SPDX-License-Identifier: GPL-2.0 +config CRYPTO_DEV_HISI_ADVCA + tristate "Support for Hisilicon ADVCA Subsystem" + depends on ARCH_HISI || COMPILE_TEST + select CRYPTO_SKCIPHER + help + Support for Hisilicon ADVCA (Advanced Conditional Access) Subsystem, + which can be found on HiSilicon STB SoCs, such as Hi37xx. + config CRYPTO_DEV_HISI_SEC tristate "Support for Hisilicon SEC crypto block cipher accelerator" select CRYPTO_SKCIPHER
drivers/crypto/hisilicon/Makefile +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_CRYPTO_DEV_HISI_ADVCA) += advca/ obj-$(CONFIG_CRYPTO_DEV_HISI_HPRE) += hpre/ obj-$(CONFIG_CRYPTO_DEV_HISI_SEC) += sec/ obj-$(CONFIG_CRYPTO_DEV_HISI_SEC2) += sec2/
drivers/crypto/hisilicon/advca/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_CRYPTO_DEV_HISI_ADVCA) += hisi-advca-muc.o
drivers/crypto/hisilicon/advca/hisi-advca-muc.c new file +1536 -0
1,536 lines not on this page · raw message
Signature · 1 line
2.39.2
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi David,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 44c026a73be8038f03dbdeef028b642880cf1511]
url: https://github.com/intel-lab-lkp/linux/commits/David-Yang/crypto-hisilicon-Add-HiSilicon-ADVCA-Subsystem/20230526-002048 base: 44c026a73be8038f03dbdeef028b642880cf1511 patch link: https://lore.kernel.org/r/20230525160446.43800-2-mmyangfl%40gmail.com patch subject: [PATCH v3 1/2] crypto: hisilicon - Add HiSilicon ADVCA Subsystem config: alpha-randconfig-s033-20230526 (https://download.01.org/0day-ci/archive/20230527/[email protected]/config) compiler: alpha-linux-gcc (GCC) 12.1.0
reproduce:
mkdir -p ~/bin
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-39-gce1a6720-dirty
# https://github.com/intel-lab-lkp/linux/commit/ae9280d4724511425d7fc2ad1119eba4e52f70b5
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review David-Yang/crypto-hisilicon-Add-HiSilicon-ADVCA-Subsystem/20230526-002048
git checkout ae9280d4724511425d7fc2ad1119eba4e52f70b5
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 ~/bin/make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=alpha olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 ~/bin/make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=alpha SHELL=/bin/bash drivers/crypto/hisilicon/advca/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> drivers/crypto/hisilicon/advca/hisi-advca-muc.c:149:3: sparse: sparse: symbol 'hica_muc_key_maps' was not declared. Should it be static?
vim +/hica_muc_key_maps +149 drivers/crypto/hisilicon/advca/hisi-advca-muc.c
144
145 struct hica_muc_key_map {
146 unsigned int alg;
147 unsigned int key;
148 unsigned int len;
> 149 } hica_muc_key_maps[] = {
150 { MUC_ALG_AES, MUC_KEY_AES_256B, AES_KEYSIZE_256 },
151 { MUC_ALG_AES, MUC_KEY_AES_192B, AES_KEYSIZE_192 },
152 { MUC_ALG_AES, MUC_KEY_AES_128B, AES_KEYSIZE_128 },
153 { MUC_ALG_DES, MUC_KEY_DES, DES_KEY_SIZE }, 154 { MUC_ALG_DES3_EDE, MUC_KEY_DES3_EDE_3KEY, DES3_EDE_KEY_SIZE },
155 { MUC_ALG_DES3_EDE, MUC_KEY_DES3_EDE_2KEY, 2 * DES_KEY_SIZE },
156 { }
157 };
158
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v3 2/2 crypto: hisilicon/advca - Add SHA support
In reply to David YangAdd driver for SHA algorithm family.
Support for state injection was not tested due to lack of such device.
--- drivers/crypto/hisilicon/Kconfig | 3 + drivers/crypto/hisilicon/advca/Makefile | 1 + .../crypto/hisilicon/advca/hisi-advca-sha.c | 658 ++++++++++++++++++ 3 files changed, 662 insertions(+) create mode 100644 drivers/crypto/hisilicon/advca/hisi-advca-sha.c
drivers/crypto/hisilicon/Kconfig +3 -0
@@ -4,6 +4,9 @@ config CRYPTO_DEV_HISI_ADVCA tristate "Support for Hisilicon ADVCA Subsystem" depends on ARCH_HISI || COMPILE_TEST select CRYPTO_SKCIPHER + select CRYPTO_HASH + select CRYPTO_SHA1 + select CRYPTO_SHA256 help Support for Hisilicon ADVCA (Advanced Conditional Access) Subsystem, which can be found on HiSilicon STB SoCs, such as Hi37xx.
drivers/crypto/hisilicon/advca/Makefile +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_CRYPTO_DEV_HISI_ADVCA) += hisi-advca-muc.o +obj-$(CONFIG_CRYPTO_DEV_HISI_ADVCA) += hisi-advca-sha.o
drivers/crypto/hisilicon/advca/hisi-advca-sha.c new file +658 -0
658 lines not on this page · raw message
Signature · 1 line
2.39.2
kernel test robot
build botRe: [PATCH v3 2/2] crypto: hisilicon/advca - Add SHA support
kernel test robot noticed the following build warnings:
Hi David,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 44c026a73be8038f03dbdeef028b642880cf1511]
url: https://github.com/intel-lab-lkp/linux/commits/David-Yang/crypto-hisilicon-Add-HiSilicon-ADVCA-Subsystem/20230526-002048 base: 44c026a73be8038f03dbdeef028b642880cf1511 patch link: https://lore.kernel.org/r/20230525160446.43800-3-mmyangfl%40gmail.com patch subject: [PATCH v3 2/2] crypto: hisilicon/advca - Add SHA support config: alpha-randconfig-s033-20230526 (https://download.01.org/0day-ci/archive/20230527/[email protected]/config) compiler: alpha-linux-gcc (GCC) 12.1.0
reproduce:
mkdir -p ~/bin
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-39-gce1a6720-dirty
# https://github.com/intel-lab-lkp/linux/commit/e564a62a5be87775c20a4de84d42b8be79be9d11
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review David-Yang/crypto-hisilicon-Add-HiSilicon-ADVCA-Subsystem/20230526-002048
git checkout e564a62a5be87775c20a4de84d42b8be79be9d11
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 ~/bin/make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=alpha olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 ~/bin/make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=alpha SHELL=/bin/bash drivers/crypto/hisilicon/advca/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> drivers/crypto/hisilicon/advca/hisi-advca-sha.c:163:32: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int [usertype] b @@ got restricted __be32 [usertype] @@ drivers/crypto/hisilicon/advca/hisi-advca-sha.c:163:32: sparse: expected unsigned int [usertype] b drivers/crypto/hisilicon/advca/hisi-advca-sha.c:163:32: sparse: got restricted __be32 [usertype] >> drivers/crypto/hisilicon/advca/hisi-advca-sha.c:269:25: sparse: sparse: cast to restricted __be32 >> drivers/crypto/hisilicon/advca/hisi-advca-sha.c:269:25: sparse: sparse: cast to restricted __be32 >> drivers/crypto/hisilicon/advca/hisi-advca-sha.c:269:25: sparse: sparse: cast to restricted __be32 >> drivers/crypto/hisilicon/advca/hisi-advca-sha.c:269:25: sparse: sparse: cast to restricted __be32 >> drivers/crypto/hisilicon/advca/hisi-advca-sha.c:269:25: sparse: sparse: cast to restricted __be32 >> drivers/crypto/hisilicon/advca/hisi-advca-sha.c:269:25: sparse: sparse: cast to restricted __be32
vim +163 drivers/crypto/hisilicon/advca/hisi-advca-sha.c
152
153 /*
154 * must be called before setting SHA_START
155 * does nothing if import is not supported (SHA_TYPE_HASH)
156 */
157 static void hica_sha_import(const struct hica_sha_priv *priv, const void *state)
158 {
159 if (priv->type != SHA_TYPE_MHASH)
160 return;
161
162 for (unsigned int i = 0; i < SHA_DIGEST_SIZE; i += sizeof(u32))
> 163 writel_relaxed(cpu_to_be32(*(const u32 *) (state + i)),
164 priv->base + SHA_INIT0 + i);
165 }
166
167 static int hica_sha_init(const struct hica_sha_priv *priv,
168 const struct hica_sha_ctrl *ctrl, bool state)
169 {
170 u32 val;
171 int ret;
172
173 /* re-enable SHA_START */
174 ret = reset_control_assert(priv->rst) ?:
175 reset_control_deassert(priv->rst);
176 if (ret)
177 return ret;
178
179 /* config SHA_CTRL */
180 val = readl_relaxed(priv->base + SHA_CTRL);
181
182 val &= ~SHA_SINGLE_READ;
183 val &= ~SHA_ALG;
184 val |= (ctrl->alg << 1) & SHA_ALG;
185 val &= ~SHA_HMAC;
186 val |= SHA_ENDIAN;
187
188 if (priv->type == SHA_TYPE_HASH)
189 val |= SHA_USED_BY_ARM;
190 else if (state)
191 val |= SHA_SET_INIT;
192
193 writel(val, priv->base + SHA_CTRL);
194
195 /* test SHA_CTRL */
196 val = readl_relaxed(priv->base + SHA_CTRL);
197 if (val & SHA_USED_BY_C51)
198 return -EBUSY;
199
200 /* wait ready */
201 if (hica_sha_wait(priv, SHA_HASH_READY))
202 return -ETIMEDOUT;
203
204 /* ask device to set state */
205 writel(SHA_START_BIT, priv->base + SHA_START);
206
207 pr_debug("%s: alg %u\n", __func__, ctrl->alg);
208 return 0;
209 }
210
211 static int hica_sha_update(const struct hica_sha_priv *priv, const void *data,
212 unsigned int len, bool may_sleep)
213 {
214 struct device *dev = priv->dev;
215 bool inplace = !((uintptr_t) data & 3);
216 u8 *buf = NULL;
217 dma_addr_t addr;
218 int ret;
219
220 if (!len)
221 return 0;
222
223 if (WARN_ON(len % SHA_BLOCK_SIZE))
224 return -EINVAL;
225
226 if (inplace) {
227 addr = dma_map_single(dev, (void *) data, len, DMA_TO_DEVICE);
228 if (dma_mapping_error(dev, addr)) {
229 dev_err(dev, "error mapping src\n");
230 return -EIO;
231 }
232
233 inplace = !(addr & 3);
234 if (!inplace)
235 dma_unmap_single(dev, addr, len, DMA_TO_DEVICE);
236 }
237
238 if (!inplace) {
239 buf = dma_alloc_attrs(dev, len, &addr,
240 may_sleep ? GFP_KERNEL : GFP_ATOMIC, 0);
241 if (!buf)
242 return -ENOMEM;
243 memcpy(buf, data, len);
244 }
245
246 dma_sync_single_for_device(dev, addr, len, DMA_TO_DEVICE);
247 ret = hica_sha_record(priv, addr, len) ?:
248 hica_sha_wait(priv, SHA_RECORD_READY);
249
250 if (!buf)
251 dma_unmap_single(dev, addr, len, DMA_TO_DEVICE);
252 else {
253 memzero_explicit(buf, len);
254 dma_free_attrs(dev, len, buf, addr, 0);
255 }
256
257 pr_debug("%s: read %u\n", __func__, len);
258 return ret;
259 }
260
261 static int hica_sha_export(const struct hica_sha_priv *priv, void *out,
262 unsigned int digestsize)
263 {
264 if (hica_sha_wait(priv, SHA_RECORD_READY))
265 return -ETIMEDOUT;
266
267 for (unsigned int i = 0; i < digestsize; i += sizeof(u32))
268 *(u32 *) (out + i) =
> 269 be32_to_cpu(readl_relaxed(priv->base + SHA_OUT0 + i)); 270
271 return 0;
272 }
273
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki