drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:412:28: sparse: sparse: invalid assignment: &=

From: kernel test robot
Date: Sun Sep 06 2020 - 04:29:27 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: dd9fb9bb3340c791a2be106fdc895db75f177343
commit: d1d787bcebfe122a5bd443ae565696661e2e9656 crypto: sun4i-ss - fix big endian issues
date: 10 months ago
config: arm64-randconfig-s031-20200906 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce:
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.2-191-g10164920-dirty
git checkout d1d787bcebfe122a5bd443ae565696661e2e9656
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=arm64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>


sparse warnings: (new ones prefixed by >>)

>> drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:412:28: sparse: sparse: invalid assignment: &=
>> drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:412:28: sparse: left side has type restricted __le32
>> drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:412:28: sparse: right side has type unsigned long
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:419:12: sparse: sparse: invalid assignment: |=
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:419:12: sparse: left side has type restricted __le32
>> drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:419:12: sparse: right side has type int
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:482:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [assigned] [usertype] v @@ got restricted __be32 [usertype] @@
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:482:27: sparse: expected unsigned int [assigned] [usertype] v
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:482:27: sparse: got restricted __be32 [usertype]
>> drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:487:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [addressable] [assigned] [usertype] v @@ got restricted __le32 [usertype] @@
>> drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:487:27: sparse: expected unsigned int [addressable] [assigned] [usertype] v
>> drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:487:27: sparse: got restricted __le32 [usertype]

# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d1d787bcebfe122a5bd443ae565696661e2e9656
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout d1d787bcebfe122a5bd443ae565696661e2e9656
vim +412 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c

477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 148
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 149 /*
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 150 * sun4i_hash_update: update hash engine
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 151 *
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 152 * Could be used for both SHA1 and MD5
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 153 * Write data by step of 32bits and put then in the SS.
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 154 *
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 155 * Since we cannot leave partial data and hash state in the engine,
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 156 * we need to get the hash state at the end of this function.
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 157 * We can get the hash state every 64 bytes
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 158 *
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 159 * So the first work is to get the number of bytes to write to SS modulo 64
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 160 * The extra bytes will go to a temporary buffer op->buf storing op->len bytes
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 161 *
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 162 * So at the begin of update()
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 163 * if op->len + areq->nbytes < 64
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 164 * => all data will be written to wait buffer (op->buf) and end=0
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 165 * if not, write all data from op->buf to the device and position end to
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 166 * complete to 64bytes
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 167 *
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 168 * example 1:
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 169 * update1 60o => op->len=60
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 170 * update2 60o => need one more word to have 64 bytes
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 171 * end=4
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 172 * so write all data from op->buf and one word of SGs
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 173 * write remaining data in op->buf
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 174 * final state op->len=56
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 175 */
8d46a5c872946a drivers/crypto/sunxi-ss/sun4i-ss-hash.c Baoyou Xie 2016-09-18 176 static int sun4i_hash(struct ahash_request *areq)
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 177 {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 178 /*
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 179 * i is the total bytes read from SGs, to be compared to areq->nbytes
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 180 * i is important because we cannot rely on SG length since the sum of
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 181 * SG->length could be greater than areq->nbytes
e3f9490e89c224 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 182 *
e3f9490e89c224 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 183 * end is the position when we need to stop writing to the device,
e3f9490e89c224 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 184 * to be compared to i
e3f9490e89c224 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 185 *
e3f9490e89c224 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 186 * in_i: advancement in the current SG
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 187 */
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 188 unsigned int i = 0, end, fill, min_fill, nwait, nbw = 0, j = 0, todo;
e3f9490e89c224 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 189 unsigned int in_i = 0;
d1d787bcebfe12 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 190 u32 spaces, rx_cnt = SS_RX_DEFAULT, bf[32] = {0}, v, ivmode = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 191 struct sun4i_req_ctx *op = ahash_request_ctx(areq);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 192 struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
9b17e5ad7831cd drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 193 struct sun4i_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
9b17e5ad7831cd drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 194 struct sun4i_ss_ctx *ss = tfmctx->ss;
e3f9490e89c224 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 195 struct scatterlist *in_sg = areq->src;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 196 struct sg_mapping_iter mi;
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 197 int in_r, err = 0;
e3f9490e89c224 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 198 size_t copied = 0;
d1d787bcebfe12 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 199 __le32 wb = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 200
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 201 dev_dbg(ss->dev, "%s %s bc=%llu len=%u mode=%x wl=%u h0=%0x",
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 202 __func__, crypto_tfm_alg_name(areq->base.tfm),
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 203 op->byte_count, areq->nbytes, op->mode,
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 204 op->len, op->hash[0]);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 205
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 206 if (unlikely(!areq->nbytes) && !(op->flags & SS_HASH_FINAL))
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 207 return 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 208
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 209 /* protect against overflow */
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 210 if (unlikely(areq->nbytes > UINT_MAX - op->len)) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 211 dev_err(ss->dev, "Cannot process too large request\n");
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 212 return -EINVAL;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 213 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 214
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 215 if (op->len + areq->nbytes < 64 && !(op->flags & SS_HASH_FINAL)) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 216 /* linearize data to op->buf */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 217 copied = sg_pcopy_to_buffer(areq->src, sg_nents(areq->src),
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 218 op->buf + op->len, areq->nbytes, 0);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 219 op->len += copied;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 220 return 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 221 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 222
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 223 spin_lock_bh(&ss->slock);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 224
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 225 /*
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 226 * if some data have been processed before,
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 227 * we need to restore the partial hash state
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 228 */
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 229 if (op->byte_count) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 230 ivmode = SS_IV_ARBITRARY;
626abd3125e02d drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 231 for (i = 0; i < crypto_ahash_digestsize(tfm) / 4; i++)
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 232 writel(op->hash[i], ss->base + SS_IV0 + i * 4);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 233 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 234 /* Enable the device */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 235 writel(op->mode | SS_ENABLED | ivmode, ss->base + SS_CTL);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 236
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 237 if (!(op->flags & SS_HASH_UPDATE))
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 238 goto hash_final;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 239
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 240 /* start of handling data */
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 241 if (!(op->flags & SS_HASH_FINAL)) {
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 242 end = ((areq->nbytes + op->len) / 64) * 64 - op->len;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 243
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 244 if (end > areq->nbytes || areq->nbytes - end > 63) {
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 245 dev_err(ss->dev, "ERROR: Bound error %u %u\n",
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 246 end, areq->nbytes);
b46b9d1aadf7f3 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Wei Yongjun 2016-08-20 247 err = -EINVAL;
b46b9d1aadf7f3 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Wei Yongjun 2016-08-20 248 goto release_ss;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 249 }
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 250 } else {
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 251 /* Since we have the flag final, we can go up to modulo 4 */
f87391558acf81 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin Labbe 2019-04-18 252 if (areq->nbytes < 4)
f87391558acf81 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin Labbe 2019-04-18 253 end = 0;
f87391558acf81 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin Labbe 2019-04-18 254 else
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 255 end = ((areq->nbytes + op->len) / 4) * 4 - op->len;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 256 }
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 257
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 258 /* TODO if SGlen % 4 and !op->len then DMA */
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 259 i = 1;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 260 while (in_sg && i == 1) {
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 261 if (in_sg->length % 4)
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 262 i = 0;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 263 in_sg = sg_next(in_sg);
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 264 }
0f52ddaed6500d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 265 if (i == 1 && !op->len && areq->nbytes)
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 266 dev_dbg(ss->dev, "We can DMA\n");
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 267
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 268 i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 269 sg_miter_start(&mi, areq->src, sg_nents(areq->src),
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 270 SG_MITER_FROM_SG | SG_MITER_ATOMIC);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 271 sg_miter_next(&mi);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 272 in_i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 273
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 274 do {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 275 /*
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 276 * we need to linearize in two case:
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 277 * - the buffer is already used
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 278 * - the SG does not have enough byte remaining ( < 4)
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 279 */
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 280 if (op->len || (mi.length - in_i) < 4) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 281 /*
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 282 * if we have entered here we have two reason to stop
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 283 * - the buffer is full
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 284 * - reach the end
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 285 */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 286 while (op->len < 64 && i < end) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 287 /* how many bytes we can read from current SG */
a7126603d46fe8 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 288 in_r = min(end - i, 64 - op->len);
a7126603d46fe8 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 289 in_r = min_t(size_t, mi.length - in_i, in_r);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 290 memcpy(op->buf + op->len, mi.addr + in_i, in_r);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 291 op->len += in_r;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 292 i += in_r;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 293 in_i += in_r;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 294 if (in_i == mi.length) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 295 sg_miter_next(&mi);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 296 in_i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 297 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 298 }
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 299 if (op->len > 3 && !(op->len % 4)) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 300 /* write buf to the device */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 301 writesl(ss->base + SS_RXFIFO, op->buf,
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 302 op->len / 4);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 303 op->byte_count += op->len;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 304 op->len = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 305 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 306 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 307 if (mi.length - in_i > 3 && i < end) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 308 /* how many bytes we can read from current SG */
a7126603d46fe8 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 309 in_r = min_t(size_t, mi.length - in_i, areq->nbytes - i);
a7126603d46fe8 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 310 in_r = min_t(size_t, ((mi.length - in_i) / 4) * 4, in_r);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 311 /* how many bytes we can write in the device*/
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 312 todo = min3((u32)(end - i) / 4, rx_cnt, (u32)in_r / 4);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 313 writesl(ss->base + SS_RXFIFO, mi.addr + in_i, todo);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 314 op->byte_count += todo * 4;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 315 i += todo * 4;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 316 in_i += todo * 4;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 317 rx_cnt -= todo;
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 318 if (!rx_cnt) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 319 spaces = readl(ss->base + SS_FCSR);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 320 rx_cnt = SS_RXFIFO_SPACES(spaces);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 321 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 322 if (in_i == mi.length) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 323 sg_miter_next(&mi);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 324 in_i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 325 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 326 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 327 } while (i < end);
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 328
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 329 /*
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 330 * Now we have written to the device all that we can,
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 331 * store the remaining bytes in op->buf
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 332 */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 333 if ((areq->nbytes - i) < 64) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 334 while (i < areq->nbytes && in_i < mi.length && op->len < 64) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 335 /* how many bytes we can read from current SG */
a7126603d46fe8 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 336 in_r = min(areq->nbytes - i, 64 - op->len);
a7126603d46fe8 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 337 in_r = min_t(size_t, mi.length - in_i, in_r);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 338 memcpy(op->buf + op->len, mi.addr + in_i, in_r);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 339 op->len += in_r;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 340 i += in_r;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 341 in_i += in_r;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 342 if (in_i == mi.length) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 343 sg_miter_next(&mi);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 344 in_i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 345 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 346 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 347 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 348
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 349 sg_miter_stop(&mi);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 350
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 351 /*
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 352 * End of data process
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 353 * Now if we have the flag final go to finalize part
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 354 * If not, store the partial hash
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 355 */
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 356 if (op->flags & SS_HASH_FINAL)
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 357 goto hash_final;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 358
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 359 writel(op->mode | SS_ENABLED | SS_DATA_END, ss->base + SS_CTL);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 360 i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 361 do {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 362 v = readl(ss->base + SS_CTL);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 363 i++;
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 364 } while (i < SS_TIMEOUT && (v & SS_DATA_END));
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 365 if (unlikely(i >= SS_TIMEOUT)) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 366 dev_err_ratelimited(ss->dev,
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 367 "ERROR: hash end timeout %d>%d ctl=%x len=%u\n",
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 368 i, SS_TIMEOUT, v, areq->nbytes);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 369 err = -EIO;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 370 goto release_ss;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 371 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 372
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 373 /*
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 374 * The datasheet isn't very clear about when to retrieve the digest. The
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 375 * bit SS_DATA_END is cleared when the engine has processed the data and
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 376 * when the digest is computed *but* it doesn't mean the digest is
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 377 * available in the digest registers. Hence the delay to be sure we can
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 378 * read it.
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 379 */
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 380 ndelay(1);
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 381
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 382 for (i = 0; i < crypto_ahash_digestsize(tfm) / 4; i++)
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 383 op->hash[i] = readl(ss->base + SS_MD0 + i * 4);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 384
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 385 goto release_ss;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 386
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 387 /*
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 388 * hash_final: finalize hashing operation
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 389 *
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 390 * If we have some remaining bytes, we write them.
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 391 * Then ask the SS for finalizing the hashing operation
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 392 *
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 393 * I do not check RX FIFO size in this function since the size is 32
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 394 * after each enabling and this function neither write more than 32 words.
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 395 * If we come from the update part, we cannot have more than
933e7e3ab239fe drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 396 * 3 remaining bytes to write and SS is fast enough to not care about it.
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 397 */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 398
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 399 hash_final:
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 400
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 401 /* write the remaining words of the wait buffer */
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 402 if (op->len) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 403 nwait = op->len / 4;
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 404 if (nwait) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 405 writesl(ss->base + SS_RXFIFO, op->buf, nwait);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 406 op->byte_count += 4 * nwait;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 407 }
d78867a94ea74b drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 408
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 409 nbw = op->len - 4 * nwait;
d78867a94ea74b drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 410 if (nbw) {
d1d787bcebfe12 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 411 wb = cpu_to_le32(*(u32 *)(op->buf + nwait * 4));
d78867a94ea74b drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 @412 wb &= GENMASK((nbw * 8) - 1, 0);
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 413
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 414 op->byte_count += nbw;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 415 }
d78867a94ea74b drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 416 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 417
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 418 /* write the remaining bytes of the nbw buffer */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 @419 wb |= ((1 << 7) << (nbw * 8));
d1d787bcebfe12 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 420 bf[j++] = le32_to_cpu(wb);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 421
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 422 /*
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 423 * number of space to pad to obtain 64o minus 8(size) minus 4 (final 1)
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 424 * I take the operations from other MD5/SHA1 implementations
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 425 */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 426
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 427 /* last block size */
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 428 fill = 64 - (op->byte_count % 64);
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 429 min_fill = 2 * sizeof(u32) + (nbw ? 0 : sizeof(u32));
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 430
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 431 /* if we can't fill all data, jump to the next 64 block */
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 432 if (fill < min_fill)
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 433 fill += 64;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 434
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 435 j += (fill - min_fill) / sizeof(u32);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 436
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 437 /* write the length of data */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 438 if (op->mode == SS_OP_SHA1) {
d1d787bcebfe12 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 439 __be64 *bits = (__be64 *)&bf[j];
d1d787bcebfe12 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 440 *bits = cpu_to_be64(op->byte_count << 3);
d1d787bcebfe12 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 441 j += 2;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 442 } else {
d1d787bcebfe12 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 443 __le64 *bits = (__le64 *)&bf[j];
d1d787bcebfe12 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 444 *bits = cpu_to_le64(op->byte_count << 3);
d1d787bcebfe12 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 445 j += 2;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 446 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 447 writesl(ss->base + SS_RXFIFO, bf, j);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 448
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 449 /* Tell the SS to stop the hashing */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 450 writel(op->mode | SS_ENABLED | SS_DATA_END, ss->base + SS_CTL);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 451
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 452 /*
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 453 * Wait for SS to finish the hash.
933e7e3ab239fe drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 454 * The timeout could happen only in case of bad overclocking
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 455 * or driver bug.
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 456 */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 457 i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 458 do {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 459 v = readl(ss->base + SS_CTL);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 460 i++;
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 461 } while (i < SS_TIMEOUT && (v & SS_DATA_END));
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c Corentin LABBE 2016-08-10 462 if (unlikely(i >= SS_TIMEOUT)) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 463 dev_err_ratelimited(ss->dev,
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 464 "ERROR: hash end timeout %d>%d ctl=%x len=%u\n",
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 465 i, SS_TIMEOUT, v, areq->nbytes);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 466 err = -EIO;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 467 goto release_ss;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 468 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 469
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 470 /*
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 471 * The datasheet isn't very clear about when to retrieve the digest. The
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 472 * bit SS_DATA_END is cleared when the engine has processed the data and
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 473 * when the digest is computed *but* it doesn't mean the digest is
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 474 * available in the digest registers. Hence the delay to be sure we can
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 475 * read it.
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 476 */
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 477 ndelay(1);
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c Antoine Tenart 2017-06-01 478
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 479 /* Get the hash from the device */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 480 if (op->mode == SS_OP_SHA1) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 481 for (i = 0; i < 5; i++) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 482 v = cpu_to_be32(readl(ss->base + SS_MD0 + i * 4));
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 483 memcpy(areq->result + i * 4, &v, 4);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 484 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 485 } else {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 486 for (i = 0; i < 4; i++) {
d1d787bcebfe12 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14 @487 v = cpu_to_le32(readl(ss->base + SS_MD0 + i * 4));
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 488 memcpy(areq->result + i * 4, &v, 4);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 489 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 490 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 491
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 492 release_ss:
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 493 writel(0, ss->base + SS_CTL);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 494 spin_unlock_bh(&ss->slock);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 495 return err;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 496 }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c LABBE Corentin 2015-07-17 497

:::::: The code at line 412 was first introduced by commit
:::::: d78867a94ea74b8d2dafdbf370e0707f37a58f4a crypto: sun4i-ss - use GENMASK to generate masks

:::::: TO: Antoine Ténart <antoine.tenart@xxxxxxxxxxxxxxxxxx>
:::::: CC: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip