lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Sun, 6 Sep 2020 16:10:23 +0800
From:   kernel test robot <lkp@...el.com>
To:     Corentin Labbe <clabbe.montjoie@...il.com>
Cc:     kbuild-all@...ts.01.org, linux-kernel@...r.kernel.org,
        Herbert Xu <herbert@...dor.apana.org.au>
Subject: drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:481:27: sparse:
 sparse: incorrect type in assignment (different base types)

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   dd9fb9bb3340c791a2be106fdc895db75f177343
commit: 7ca2a71d177f51d1d0d339657d3b0cc988d1518e crypto: sun4i-ss - remove dependency on not 64BIT
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 7ca2a71d177f51d1d0d339657d3b0cc988d1518e
        # 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@...el.com>


sparse warnings: (new ones prefixed by >>)

   drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:439:27: sparse: sparse: cast from restricted __be64
   drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:440:27: sparse: sparse: restricted __be64 degrades to integer
   drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:442:46: sparse: sparse: incorrect type in initializer (different base types) @@     expected restricted __le64 [usertype] bits @@     got unsigned long long @@
   drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:442:46: sparse:     expected restricted __le64 [usertype] bits
   drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:442:46: sparse:     got unsigned long long
   drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:443:27: sparse: sparse: cast from restricted __le64
   drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:444:27: sparse: sparse: restricted __le64 degrades to integer
>> drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:481: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:481:27: sparse:     expected unsigned int [assigned] [usertype] v
>> drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c:481:27: sparse:     got restricted __be32 [usertype]

# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7ca2a71d177f51d1d0d339657d3b0cc988d1518e
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout 7ca2a71d177f51d1d0d339657d3b0cc988d1518e
vim +481 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;
7e6df1f7a3a5f3 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  190  	u32 spaces, rx_cnt = SS_RX_DEFAULT, bf[32] = {0}, wb = 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;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  199  
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  200  	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  201  		__func__, crypto_tfm_alg_name(areq->base.tfm),
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  202  		op->byte_count, areq->nbytes, op->mode,
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  203  		op->len, op->hash[0]);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  204  
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  205  	if (unlikely(!areq->nbytes) && !(op->flags & SS_HASH_FINAL))
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  206  		return 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  207  
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  208  	/* protect against overflow */
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  209  	if (unlikely(areq->nbytes > UINT_MAX - op->len)) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  210  		dev_err(ss->dev, "Cannot process too large request\n");
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  211  		return -EINVAL;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  212  	}
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  213  
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  214  	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  215  		/* linearize data to op->buf */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  216  		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  217  					    op->buf + op->len, areq->nbytes, 0);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  218  		op->len += copied;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  219  		return 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  220  	}
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  	spin_lock_bh(&ss->slock);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  223  
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  	 * if some data have been processed before,
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  226  	 * we need to restore the partial hash state
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  227  	 */
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  228  	if (op->byte_count) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  229  		ivmode = SS_IV_ARBITRARY;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  230  		for (i = 0; i < 5; i++)
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  231  			writel(op->hash[i], ss->base + SS_IV0 + i * 4);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  232  	}
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  233  	/* Enable the device */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  234  	writel(op->mode | SS_ENABLED | ivmode, ss->base + SS_CTL);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  235  
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  236  	if (!(op->flags & SS_HASH_UPDATE))
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  237  		goto hash_final;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  238  
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  239  	/* start of handling data */
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  240  	if (!(op->flags & SS_HASH_FINAL)) {
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  241  		end = ((areq->nbytes + op->len) / 64) * 64 - op->len;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  242  
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  243  		if (end > areq->nbytes || areq->nbytes - end > 63) {
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  244  			dev_err(ss->dev, "ERROR: Bound error %u %u\n",
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  245  				end, areq->nbytes);
b46b9d1aadf7f3 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Wei Yongjun    2016-08-20  246  			err = -EINVAL;
b46b9d1aadf7f3 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Wei Yongjun    2016-08-20  247  			goto release_ss;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  248  		}
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  249  	} else {
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  250  		/* 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  251  		if (areq->nbytes < 4)
f87391558acf81 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin Labbe 2019-04-18  252  			end = 0;
f87391558acf81 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin Labbe 2019-04-18  253  		else
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  254  			end = ((areq->nbytes + op->len) / 4) * 4 - op->len;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  255  	}
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  256  
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  257  	/* TODO if SGlen % 4 and !op->len then DMA */
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  258  	i = 1;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  259  	while (in_sg && i == 1) {
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  260  		if (in_sg->length % 4)
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  261  			i = 0;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  262  		in_sg = sg_next(in_sg);
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  263  	}
0f52ddaed6500d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  264  	if (i == 1 && !op->len && areq->nbytes)
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  265  		dev_dbg(ss->dev, "We can DMA\n");
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  266  
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  267  	i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  268  	sg_miter_start(&mi, areq->src, sg_nents(areq->src),
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  269  		       SG_MITER_FROM_SG | SG_MITER_ATOMIC);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  270  	sg_miter_next(&mi);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  271  	in_i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  272  
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  273  	do {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  274  		/*
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  275  		 * we need to linearize in two case:
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  276  		 * - the buffer is already used
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  277  		 * - the SG does not have enough byte remaining ( < 4)
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  278  		 */
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  279  		if (op->len || (mi.length - in_i) < 4) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  280  			/*
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  281  			 * 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  282  			 * - the buffer is full
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  283  			 * - reach the end
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  284  			 */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  285  			while (op->len < 64 && i < end) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  286  				/* how many bytes we can read from current SG */
a7126603d46fe8 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14  287  				in_r = min(end - i, 64 - op->len);
a7126603d46fe8 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14  288  				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  289  				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  290  				op->len += in_r;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  291  				i += in_r;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  292  				in_i += in_r;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  293  				if (in_i == mi.length) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  294  					sg_miter_next(&mi);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  295  					in_i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  296  				}
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  297  			}
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  298  			if (op->len > 3 && !(op->len % 4)) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  299  				/* write buf to the device */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  300  				writesl(ss->base + SS_RXFIFO, op->buf,
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  301  					op->len / 4);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  302  				op->byte_count += op->len;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  303  				op->len = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  304  			}
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  		if (mi.length - in_i > 3 && i < end) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  307  			/* how many bytes we can read from current SG */
a7126603d46fe8 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14  308  			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  309  			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  310  			/* how many bytes we can write in the device*/
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  311  			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  312  			writesl(ss->base + SS_RXFIFO, mi.addr + in_i, todo);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  313  			op->byte_count += todo * 4;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  314  			i += todo * 4;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  315  			in_i += todo * 4;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  316  			rx_cnt -= todo;
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  317  			if (!rx_cnt) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  318  				spaces = readl(ss->base + SS_FCSR);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  319  				rx_cnt = SS_RXFIFO_SPACES(spaces);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  320  			}
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  321  			if (in_i == mi.length) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  322  				sg_miter_next(&mi);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  323  				in_i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  324  			}
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  	} while (i < end);
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  327  
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  	 * 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  330  	 * store the remaining bytes in op->buf
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  331  	 */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  332  	if ((areq->nbytes - i) < 64) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  333  		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  334  			/* how many bytes we can read from current SG */
a7126603d46fe8 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14  335  			in_r = min(areq->nbytes - i, 64 - op->len);
a7126603d46fe8 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c Corentin Labbe 2019-11-14  336  			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  337  			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  338  			op->len += in_r;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  339  			i += in_r;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  340  			in_i += in_r;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  341  			if (in_i == mi.length) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  342  				sg_miter_next(&mi);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  343  				in_i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  344  			}
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  	sg_miter_stop(&mi);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  349  
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  350  	/*
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  351  	 * End of data process
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  352  	 * 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  353  	 * If not, store the partial hash
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  354  	 */
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  355  	if (op->flags & SS_HASH_FINAL)
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  356  		goto hash_final;
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  357  
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  358  	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  359  	i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  360  	do {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  361  		v = readl(ss->base + SS_CTL);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  362  		i++;
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  363  	} while (i < SS_TIMEOUT && (v & SS_DATA_END));
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  364  	if (unlikely(i >= SS_TIMEOUT)) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  365  		dev_err_ratelimited(ss->dev,
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  366  				    "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  367  				    i, SS_TIMEOUT, v, areq->nbytes);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  368  		err = -EIO;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  369  		goto release_ss;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  370  	}
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  371  
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  372  	/*
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  373  	 * 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  374  	 * 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  375  	 * 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  376  	 * 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  377  	 * read it.
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  378  	 */
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  379  	ndelay(1);
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  380  
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  381  	for (i = 0; i < crypto_ahash_digestsize(tfm) / 4; i++)
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  382  		op->hash[i] = readl(ss->base + SS_MD0 + i * 4);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  383  
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  384  	goto release_ss;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  385  
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  386  /*
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  387   * hash_final: finalize hashing operation
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  388   *
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  389   * If we have some remaining bytes, we write them.
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  390   * Then ask the SS for finalizing the hashing operation
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  391   *
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  392   * 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  393   * 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  394   * 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  395   * 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  396   */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  397  
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  398  hash_final:
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  399  
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  400  	/* write the remaining words of the wait buffer */
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  401  	if (op->len) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  402  		nwait = op->len / 4;
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  403  		if (nwait) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  404  			writesl(ss->base + SS_RXFIFO, op->buf, nwait);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  405  			op->byte_count += 4 * nwait;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  406  		}
d78867a94ea74b drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  407  
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  408  		nbw = op->len - 4 * nwait;
d78867a94ea74b drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  409  		if (nbw) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  410  			wb = *(u32 *)(op->buf + nwait * 4);
d78867a94ea74b drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  411  			wb &= GENMASK((nbw * 8) - 1, 0);
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  412  
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  413  			op->byte_count += nbw;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  414  		}
d78867a94ea74b drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  415  	}
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  416  
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  417  	/* write the remaining bytes of the nbw buffer */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  418  	wb |= ((1 << 7) << (nbw * 8));
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  419  	bf[j++] = wb;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  420  
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  	 * 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  423  	 * I take the operations from other MD5/SHA1 implementations
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  424  	 */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  425  
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  426  	/* last block size */
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  427  	fill = 64 - (op->byte_count % 64);
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  428  	min_fill = 2 * sizeof(u32) + (nbw ? 0 : sizeof(u32));
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  429  
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  430  	/* 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  431  	if (fill < min_fill)
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  432  		fill += 64;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  433  
214a9bd0f8dec4 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  434  	j += (fill - min_fill) / sizeof(u32);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  435  
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  436  	/* write the length of data */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  437  	if (op->mode == SS_OP_SHA1) {
11be0107ab1a89 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  438  		__be64 bits = cpu_to_be64(op->byte_count << 3);
11be0107ab1a89 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01 @439  		bf[j++] = lower_32_bits(bits);
11be0107ab1a89 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  440  		bf[j++] = upper_32_bits(bits);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  441  	} else {
11be0107ab1a89 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  442  		__le64 bits = op->byte_count << 3;
11be0107ab1a89 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  443  		bf[j++] = lower_32_bits(bits);
11be0107ab1a89 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  444  		bf[j++] = upper_32_bits(bits);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  445  	}
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  446  	writesl(ss->base + SS_RXFIFO, bf, j);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  447  
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  448  	/* Tell the SS to stop the hashing */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  449  	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  450  
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  	 * Wait for SS to finish the hash.
933e7e3ab239fe drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  453  	 * The timeout could happen only in case of bad overclocking
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  454  	 * or driver bug.
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  455  	 */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  456  	i = 0;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  457  	do {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  458  		v = readl(ss->base + SS_CTL);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  459  		i++;
a595e60a70c0d0 drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  460  	} while (i < SS_TIMEOUT && (v & SS_DATA_END));
477d9b2e591b8d drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Corentin LABBE 2016-08-10  461  	if (unlikely(i >= SS_TIMEOUT)) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  462  		dev_err_ratelimited(ss->dev,
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  463  				    "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  464  				    i, SS_TIMEOUT, v, areq->nbytes);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  465  		err = -EIO;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  466  		goto release_ss;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  467  	}
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  468  
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  469  	/*
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  470  	 * 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  471  	 * 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  472  	 * 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  473  	 * 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  474  	 * read it.
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  475  	 */
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  476  	ndelay(1);
049655499e2ecc drivers/crypto/sunxi-ss/sun4i-ss-hash.c           Antoine Tenart 2017-06-01  477  
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  478  	/* Get the hash from the device */
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  479  	if (op->mode == SS_OP_SHA1) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  480  		for (i = 0; i < 5; i++) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17 @481  			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  482  			memcpy(areq->result + i * 4, &v, 4);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  483  		}
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  484  	} else {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  485  		for (i = 0; i < 4; i++) {
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  486  			v = readl(ss->base + SS_MD0 + i * 4);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  487  			memcpy(areq->result + i * 4, &v, 4);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  488  		}
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  release_ss:
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  492  	writel(0, ss->base + SS_CTL);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  493  	spin_unlock_bh(&ss->slock);
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  494  	return err;
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  495  }
6298e948215f2a drivers/crypto/sunxi-ss/sun4i-ss-hash.c           LABBE Corentin 2015-07-17  496  

:::::: The code at line 481 was first introduced by commit
:::::: 6298e948215f2a3eb8a9af5c490d025deb66f179 crypto: sunxi-ss - Add Allwinner Security System crypto accelerator

:::::: TO: LABBE Corentin <clabbe.montjoie@...il.com>
:::::: CC: Herbert Xu <herbert@...dor.apana.org.au>

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

Download attachment ".config.gz" of type "application/gzip" (42805 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ