On Mon, Nov 14, 2016 at 04:36:32PM -0700, Dave Jiang wrote: > Existing implementation does not honor the alignment restrictions imposed > by the DMA engines. Allocate buffers with built in slack for honoring > alignment restrictions. Creating new arrays to hold the aligned pointers > and use those pointers for operations. > > Signed-off-by: Dave Jiang <dave.jiang@xxxxxxxxx> > --- > drivers/dma/dmatest.c | 57 ++++++++++++++++++++++++++++++++----------------- > 1 file changed, 37 insertions(+), 20 deletions(-) > > diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c > index cf76fc6..65c2ee0 100644 > --- a/drivers/dma/dmatest.c > +++ b/drivers/dma/dmatest.c > @@ -164,7 +164,9 @@ struct dmatest_thread { > struct task_struct *task; > struct dma_chan *chan; > u8 **srcs; > + u8 **usrcs; > u8 **dsts; > + u8 **udsts; > enum dma_transaction_type type; > bool done; > }; > @@ -431,6 +433,7 @@ static int dmatest_func(void *data) > ktime_t comparetime = ktime_set(0, 0); > s64 runtime = 0; > unsigned long long total_len = 0; > + u8 align = 0; > > set_freezable(); > > @@ -441,18 +444,22 @@ static int dmatest_func(void *data) > params = &info->params; > chan = thread->chan; > dev = chan->device; > - if (thread->type == DMA_MEMCPY) > + if (thread->type == DMA_MEMCPY) { > + align = dev->copy_align; > src_cnt = dst_cnt = 1; > - else if (thread->type == DMA_SG) > + } else if (thread->type == DMA_SG) { > + align = dev->copy_align; > src_cnt = dst_cnt = sg_buffers; > - else if (thread->type == DMA_XOR) { > + } else if (thread->type == DMA_XOR) { > /* force odd to ensure dst = src */ > src_cnt = min_odd(params->xor_sources | 1, dev->max_xor); > dst_cnt = 1; > + align = dev->xor_align; > } else if (thread->type == DMA_PQ) { > /* force odd to ensure dst = src */ > src_cnt = min_odd(params->pq_sources | 1, dma_maxpq(dev, 0)); > dst_cnt = 2; > + align = dev->pq_align; > > pq_coefs = kmalloc(params->pq_sources+1, GFP_KERNEL); > if (!pq_coefs) > @@ -466,20 +473,35 @@ static int dmatest_func(void *data) > thread->srcs = kcalloc(src_cnt+1, sizeof(u8 *), GFP_KERNEL); > if (!thread->srcs) > goto err_srcs; > + > + thread->usrcs = kcalloc(src_cnt+1, sizeof(u8 *), GFP_KERNEL); spaces around + pls, here and other places > + if (!thread->usrcs) > + goto err_usrcs; > + > for (i = 0; i < src_cnt; i++) { > - thread->srcs[i] = kmalloc(params->buf_size, GFP_KERNEL); > - if (!thread->srcs[i]) > + thread->usrcs[i] = kmalloc(params->buf_size+align, GFP_KERNEL); > + if (!thread->usrcs[i]) > goto err_srcbuf; > + /* align srcs to alignment restriction */ > + thread->srcs[i] = align ? > + PTR_ALIGN(thread->usrcs[i], align) : thread->usrcs[i]; if-else would look more readable -- ~Vinod -- To unsubscribe from this list: send the line "unsubscribe dmaengine" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html