Re: [PATCH v7 1/6] Add SPAcc Skcipher support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jul 29, 2024 at 09:43:45AM +0530, Pavitrakumar M wrote:
> +int spacc_packet_enqueue_ddt_ex(struct spacc_device *spacc, int use_jb,
> +				int job_idx, struct pdu_ddt *src_ddt,
> +				struct pdu_ddt *dst_ddt, u32 proc_sz,
> +				uint32_t aad_offset, uint32_t pre_aad_sz,
> +				u32 post_aad_sz, uint32_t iv_offset,
> +				uint32_t prio)
> +{
> +	int i;
> +	struct spacc_job *job;
> +	int ret = CRYPTO_OK, proc_len;
> +
> +	if (job_idx < 0 || job_idx > SPACC_MAX_JOBS)
> +		return -ENXIO;
> +
> +	switch (prio)  {
> +	case SPACC_SW_CTRL_PRIO_MED:
> +		if (spacc->config.cmd1_fifo_depth == 0)
> +			return -EINVAL;
> +		break;
> +	case SPACC_SW_CTRL_PRIO_LOW:
> +		if (spacc->config.cmd2_fifo_depth == 0)
> +			return -EINVAL;
> +		break;
> +	}
> +
> +	job = &spacc->job[job_idx];
> +	if (!job)
> +		return -EIO;
> +
> +	/* process any jobs in the jb*/
> +	if (use_jb && spacc_process_jb(spacc) != 0)
> +		goto fifo_full;
> +
> +	if (_spacc_fifo_full(spacc, prio)) {
> +		if (use_jb)
> +			goto fifo_full;
> +		else
> +			return -EBUSY;
> +	}
> +
> +	/* compute the length we must process, in decrypt mode
> +	 * with an ICV (hash, hmac or CCM modes)
> +	 * we must subtract the icv length from the buffer size
> +	 */
> +	if (proc_sz == SPACC_AUTO_SIZE) {
> +		proc_len = src_ddt->len;
> +
> +		if (job->op == OP_DECRYPT &&
> +		    (job->hash_mode > 0 ||
> +		     job->enc_mode == CRYPTO_MODE_AES_CCM ||
> +		     job->enc_mode == CRYPTO_MODE_AES_GCM)  &&
> +		    !(job->ctrl & SPACC_CTRL_MASK(SPACC_CTRL_ICV_ENC)))
> +			proc_len = src_ddt->len - job->icv_len;
> +	} else {
> +		proc_len = proc_sz;
> +	}
> +
> +	if (pre_aad_sz & SPACC_AADCOPY_FLAG) {
> +		job->ctrl |= SPACC_CTRL_MASK(SPACC_CTRL_AAD_COPY);
> +		pre_aad_sz &= ~(SPACC_AADCOPY_FLAG);
> +	} else {
> +		job->ctrl &= ~SPACC_CTRL_MASK(SPACC_CTRL_AAD_COPY);
> +	}
> +
> +	job->pre_aad_sz  = pre_aad_sz;
> +	job->post_aad_sz = post_aad_sz;
> +
> +	if (spacc->config.dma_type == SPACC_DMA_DDT) {
> +		pdu_io_cached_write(spacc->regmap + SPACC_REG_SRC_PTR,
> +				    (uint32_t)src_ddt->phys,
> +				    &spacc->cache.src_ptr);
> +		pdu_io_cached_write(spacc->regmap + SPACC_REG_DST_PTR,
> +				    (uint32_t)dst_ddt->phys,
> +				    &spacc->cache.dst_ptr);
> +	} else if (spacc->config.dma_type == SPACC_DMA_LINEAR) {
> +		pdu_io_cached_write(spacc->regmap + SPACC_REG_SRC_PTR,
> +				    (uint32_t)src_ddt->virt[0],
> +				    &spacc->cache.src_ptr);
> +		pdu_io_cached_write(spacc->regmap + SPACC_REG_DST_PTR,
> +				    (uint32_t)dst_ddt->virt[0],
> +				    &spacc->cache.dst_ptr);
> +	} else {
> +		return -EIO;
> +	}
> +
> +	pdu_io_cached_write(spacc->regmap + SPACC_REG_PROC_LEN,
> +			    proc_len - job->post_aad_sz,
> +			    &spacc->cache.proc_len);
> +	pdu_io_cached_write(spacc->regmap + SPACC_REG_ICV_LEN,
> +			    job->icv_len, &spacc->cache.icv_len);
> +	pdu_io_cached_write(spacc->regmap + SPACC_REG_ICV_OFFSET,
> +			    job->icv_offset, &spacc->cache.icv_offset);
> +	pdu_io_cached_write(spacc->regmap + SPACC_REG_PRE_AAD_LEN,
> +			    job->pre_aad_sz, &spacc->cache.pre_aad);
> +	pdu_io_cached_write(spacc->regmap + SPACC_REG_POST_AAD_LEN,
> +			    job->post_aad_sz, &spacc->cache.post_aad);
> +	pdu_io_cached_write(spacc->regmap + SPACC_REG_IV_OFFSET,
> +			    iv_offset, &spacc->cache.iv_offset);
> +	pdu_io_cached_write(spacc->regmap + SPACC_REG_OFFSET,
> +			    aad_offset, &spacc->cache.offset);
> +	pdu_io_cached_write(spacc->regmap + SPACC_REG_AUX_INFO,
> +			    AUX_DIR(job->auxinfo_dir) |
> +			    AUX_BIT_ALIGN(job->auxinfo_bit_align) |
> +			    AUX_CBC_CS(job->auxinfo_cs_mode),
> +			    &spacc->cache.aux);
> +
> +	if (job->first_use == 1) {
> +		writel(job->ckey_sz | SPACC_SET_KEY_CTX(job->ctx_idx),
> +		       spacc->regmap + SPACC_REG_KEY_SZ);
> +		writel(job->hkey_sz | SPACC_SET_KEY_CTX(job->ctx_idx),
> +		       spacc->regmap + SPACC_REG_KEY_SZ);
> +	}
> +
> +	job->job_swid = spacc->job_next_swid;
> +	spacc->job_lookup[job->job_swid] = job_idx;
> +	spacc->job_next_swid =
> +		(spacc->job_next_swid + 1) % SPACC_MAX_JOBS;
> +	writel(SPACC_SW_CTRL_ID_SET(job->job_swid) |
> +	       SPACC_SW_CTRL_PRIO_SET(prio),
> +	       spacc->regmap + SPACC_REG_SW_CTRL);
> +	writel(job->ctrl, spacc->regmap + SPACC_REG_CTRL);
> +
> +	/* Clear an expansion key after the first call*/
> +	if (job->first_use == 1) {
> +		job->first_use = 0;
> +		job->ctrl &= ~SPACC_CTRL_MASK(SPACC_CTRL_KEY_EXP);
> +	}
> +
> +	return ret;

Change this to return CRYPTO_OK and delete the ret variable.

> +
> +fifo_full:
> +	/* try to add a job to the job buffers*/
> +	i = spacc->jb_head + 1;
> +	if (i == SPACC_MAX_JOB_BUFFERS)
> +		i = 0;
> +
> +	if (i == spacc->jb_tail)
> +		return -EBUSY;
> +
> +	spacc->job_buffer[spacc->jb_head] = (struct spacc_job_buffer) {
> +		.active		= 1,
> +		.job_idx	= job_idx,
> +		.src		= src_ddt,
> +		.dst		= dst_ddt,
> +		.proc_sz	= proc_sz,
> +		.aad_offset	= aad_offset,
> +		.pre_aad_sz	= pre_aad_sz,
> +		.post_aad_sz	= post_aad_sz,
> +		.iv_offset	= iv_offset,
> +		.prio		= prio
> +	};
> +
> +	spacc->jb_head = i;
> +
> +	return CRYPTO_USED_JB;

What's the point of CRYPTO_USED_JB?  This is the only place it's referenced and
the callers just eventually do if (ret) ret = -EINVAL or something like that.
Nothing uses it.

regards,
dan carpenter






[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]
  Powered by Linux