提交 755f04f7 编写于 作者: Y Yu'an Wang 提交者: Yang Yingliang

qm: fix wrong number of sg elements after dma map

driver inclusion
category: bugfix
bugzilla: NA
CVE: NA

1. use sgl API to get sgl dma addr and len
Use sgl API to get sgl dma addr and len, this will help to avoid compile
error in some platforms. So NEED_SG_DMA_LENGTH can be removed here, which
can only be selected by arch code.
2. Fix issue with wrong number of sg elements after dma map
We fill the hardware scatter gather list assuming it will need the same
number of elements at the original scatterlist. If an IOMMU is involved,
then it may well need fewer. The return value of dma_map_sg tells us how
many.
Probably never caused visible problems as the hardware won't get to
the elements that are incorrect before it finds enough space.
3.Remove useless MODULE macros
As we already merge hardware sgl into hisi_qm module, remove useless
MODULE macros
Signed-off-by: NYu'an Wang <wangyuan46@huawei.com>
Reviewed-by: NCheng Hu <hucheng.hu@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 e6fae7ff
...@@ -56,11 +56,7 @@ struct hisi_acc_sgl_pool { ...@@ -56,11 +56,7 @@ struct hisi_acc_sgl_pool {
struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev, struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
u32 count, u32 sge_nr) u32 count, u32 sge_nr)
{ {
u32 sgl_size; u32 sgl_size, block_size, sgl_num_per_block, block_num, remain_sgl;
u32 block_size;
u32 sgl_num_per_block;
u32 block_num;
u32 remain_sgl;
struct hisi_acc_sgl_pool *pool; struct hisi_acc_sgl_pool *pool;
struct mem_block *block; struct mem_block *block;
u32 i, j; u32 i, j;
...@@ -172,8 +168,8 @@ static struct hisi_acc_hw_sgl *acc_get_sgl(struct hisi_acc_sgl_pool *pool, ...@@ -172,8 +168,8 @@ static struct hisi_acc_hw_sgl *acc_get_sgl(struct hisi_acc_sgl_pool *pool,
static void sg_map_to_hw_sg(struct scatterlist *sgl, static void sg_map_to_hw_sg(struct scatterlist *sgl,
struct acc_hw_sge *hw_sge) struct acc_hw_sge *hw_sge)
{ {
hw_sge->buf = sgl->dma_address; hw_sge->buf = sg_dma_address(sgl);
hw_sge->len = cpu_to_le32(sgl->dma_length); hw_sge->len = cpu_to_le32(sg_dma_len(sgl));
} }
static void inc_hw_sgl_sge(struct hisi_acc_hw_sgl *hw_sgl) static void inc_hw_sgl_sge(struct hisi_acc_hw_sgl *hw_sgl)
...@@ -210,20 +206,21 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev, ...@@ -210,20 +206,21 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev,
dma_addr_t curr_sgl_dma = 0; dma_addr_t curr_sgl_dma = 0;
struct acc_hw_sge *curr_hw_sge; struct acc_hw_sge *curr_hw_sge;
struct scatterlist *sg; struct scatterlist *sg;
int i, ret, sg_n; int i, sg_n, sg_n_mapped;
if (!dev || !sgl || !pool || !hw_sgl_dma) if (!dev || !sgl || !pool || !hw_sgl_dma)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
sg_n = sg_nents(sgl); sg_n = sg_nents(sgl);
if (sg_n > pool->sge_nr) {
dev_err(dev, "the number of entries in input scatterlist is bigger than SGL pool setting.\n"); sg_n_mapped = dma_map_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL);
if (!sg_n_mapped) {
dev_err(dev, "DMA mapping for SG error!\n");
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
ret = dma_map_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); if (sg_n_mapped > pool->sge_nr) {
if (!ret) { dev_err(dev, "the number of entries in input scatterlist is bigger than SGL pool setting.\n");
dev_err(dev, "DMA mapping for SG error!\n");
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
...@@ -236,7 +233,7 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev, ...@@ -236,7 +233,7 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev,
curr_hw_sgl->entry_length_in_sgl = cpu_to_le16(pool->sge_nr); curr_hw_sgl->entry_length_in_sgl = cpu_to_le16(pool->sge_nr);
curr_hw_sge = curr_hw_sgl->sge_entries; curr_hw_sge = curr_hw_sgl->sge_entries;
for_each_sg(sgl, sg, sg_n, i) { for_each_sg(sgl, sg, sg_n_mapped, i) {
sg_map_to_hw_sg(sg, curr_hw_sge); sg_map_to_hw_sg(sg, curr_hw_sge);
inc_hw_sgl_sge(curr_hw_sgl); inc_hw_sgl_sge(curr_hw_sgl);
curr_hw_sge++; curr_hw_sge++;
...@@ -272,7 +269,3 @@ void hisi_acc_sg_buf_unmap(struct device *dev, struct scatterlist *sgl, ...@@ -272,7 +269,3 @@ void hisi_acc_sg_buf_unmap(struct device *dev, struct scatterlist *sgl,
hw_sgl->entry_length_in_sgl = 0; hw_sgl->entry_length_in_sgl = 0;
} }
EXPORT_SYMBOL_GPL(hisi_acc_sg_buf_unmap); EXPORT_SYMBOL_GPL(hisi_acc_sg_buf_unmap);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Zhou Wang <wangzhou1@hisilicon.com>");
MODULE_DESCRIPTION("HiSilicon Accelerator SGL support");
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册