diff options
Diffstat (limited to 'drivers/crypto/hisilicon/sgl.c')
| -rw-r--r-- | drivers/crypto/hisilicon/sgl.c | 37 | 
1 files changed, 31 insertions, 6 deletions
| diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c index 3bff6394acaf..057273769f26 100644 --- a/drivers/crypto/hisilicon/sgl.c +++ b/drivers/crypto/hisilicon/sgl.c @@ -56,7 +56,7 @@ struct hisi_acc_sgl_pool {  struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,  						   u32 count, u32 sge_nr)  { -	u32 sgl_size, block_size, sgl_num_per_block, block_num, remain_sgl = 0; +	u32 sgl_size, block_size, sgl_num_per_block, block_num, remain_sgl;  	struct hisi_acc_sgl_pool *pool;  	struct mem_block *block;  	u32 i, j; @@ -66,6 +66,11 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,  	sgl_size = sizeof(struct acc_hw_sge) * sge_nr +  		   sizeof(struct hisi_acc_hw_sgl); + +	/* +	 * the pool may allocate a block of memory of size PAGE_SIZE * 2^(MAX_ORDER - 1), +	 * block size may exceed 2^31 on ia64, so the max of block size is 2^31 +	 */  	block_size = 1 << (PAGE_SHIFT + MAX_ORDER <= 32 ?  			   PAGE_SHIFT + MAX_ORDER - 1 : 31);  	sgl_num_per_block = block_size / sgl_size; @@ -85,8 +90,10 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,  		block[i].sgl = dma_alloc_coherent(dev, block_size,  						  &block[i].sgl_dma,  						  GFP_KERNEL); -		if (!block[i].sgl) +		if (!block[i].sgl) { +			dev_err(dev, "Fail to allocate hw SG buffer!\n");  			goto err_free_mem; +		}  		block[i].size = block_size;  	} @@ -95,8 +102,10 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,  		block[i].sgl = dma_alloc_coherent(dev, remain_sgl * sgl_size,  						  &block[i].sgl_dma,  						  GFP_KERNEL); -		if (!block[i].sgl) +		if (!block[i].sgl) { +			dev_err(dev, "Fail to allocate remained hw SG buffer!\n");  			goto err_free_mem; +		}  		block[i].size = remain_sgl * sgl_size;  	} @@ -167,6 +176,7 @@ static void sg_map_to_hw_sg(struct scatterlist *sgl,  {  	hw_sge->buf = sg_dma_address(sgl);  	hw_sge->len = cpu_to_le32(sg_dma_len(sgl)); +	hw_sge->page_ctrl = sg_virt(sgl);  }  static void inc_hw_sgl_sge(struct hisi_acc_hw_sgl *hw_sgl) @@ -182,6 +192,18 @@ static void update_hw_sgl_sum_sge(struct hisi_acc_hw_sgl *hw_sgl, u16 sum)  	hw_sgl->entry_sum_in_chain = cpu_to_le16(sum);  } +static void clear_hw_sgl_sge(struct hisi_acc_hw_sgl *hw_sgl) +{ +	struct acc_hw_sge *hw_sge = hw_sgl->sge_entries; +	int i; + +	for (i = 0; i < le16_to_cpu(hw_sgl->entry_sum_in_sgl); i++) { +		hw_sge[i].page_ctrl = NULL; +		hw_sge[i].buf = 0; +		hw_sge[i].len = 0; +	} +} +  /**   * hisi_acc_sg_buf_map_to_hw_sgl - Map a scatterlist to a hw sgl.   * @dev: The device which hw sgl belongs to. @@ -211,16 +233,19 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev,  	sg_n = sg_nents(sgl);  	sg_n_mapped = dma_map_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); -	if (!sg_n_mapped) +	if (!sg_n_mapped) { +		dev_err(dev, "DMA mapping for SG error!\n");  		return ERR_PTR(-EINVAL); +	}  	if (sg_n_mapped > pool->sge_nr) { -		dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); +		dev_err(dev, "the number of entries in input scatterlist is bigger than SGL pool setting.\n");  		return ERR_PTR(-EINVAL);  	}  	curr_hw_sgl = acc_get_sgl(pool, index, &curr_sgl_dma);  	if (IS_ERR(curr_hw_sgl)) { +		dev_err(dev, "Get SGL error!\n");  		dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL);  		return ERR_PTR(-ENOMEM); @@ -256,7 +281,7 @@ void hisi_acc_sg_buf_unmap(struct device *dev, struct scatterlist *sgl,  		return;  	dma_unmap_sg(dev, sgl, sg_nents(sgl), DMA_BIDIRECTIONAL); - +	clear_hw_sgl_sge(hw_sgl);  	hw_sgl->entry_sum_in_chain = 0;  	hw_sgl->entry_sum_in_sgl = 0;  	hw_sgl->entry_length_in_sgl = 0; | 
