Release 4.12 drivers/dma/dmatest.c
  
  
  
/*
 * DMA Engine test module
 *
 * Copyright (C) 2007 Atmel Corporation
 * Copyright (C) 2013 Intel Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/delay.h>
#include <linux/dma-mapping.h>
#include <linux/dmaengine.h>
#include <linux/freezer.h>
#include <linux/init.h>
#include <linux/kthread.h>
#include <linux/sched/task.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/random.h>
#include <linux/slab.h>
#include <linux/wait.h>
static unsigned int test_buf_size = 16384;
module_param(test_buf_size, uint, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(test_buf_size, "Size of the memcpy test buffer");
static char test_channel[20];
module_param_string(channel, test_channel, sizeof(test_channel),
		S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(channel, "Bus ID of the channel to test (default: any)");
static char test_device[32];
module_param_string(device, test_device, sizeof(test_device),
		S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(device, "Bus ID of the DMA Engine to test (default: any)");
static unsigned int threads_per_chan = 1;
module_param(threads_per_chan, uint, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(threads_per_chan,
		"Number of threads to start per channel (default: 1)");
static unsigned int max_channels;
module_param(max_channels, uint, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(max_channels,
		"Maximum number of channels to use (default: all)");
static unsigned int iterations;
module_param(iterations, uint, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(iterations,
		"Iterations before stopping test (default: infinite)");
static unsigned int sg_buffers = 1;
module_param(sg_buffers, uint, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(sg_buffers,
		"Number of scatter gather buffers (default: 1)");
static unsigned int dmatest;
module_param(dmatest, uint, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(dmatest,
		"dmatest 0-memcpy 1-slave_sg (default: 0)");
static unsigned int xor_sources = 3;
module_param(xor_sources, uint, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(xor_sources,
		"Number of xor source buffers (default: 3)");
static unsigned int pq_sources = 3;
module_param(pq_sources, uint, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(pq_sources,
		"Number of p+q source buffers (default: 3)");
static int timeout = 3000;
module_param(timeout, uint, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(timeout, "Transfer Timeout in msec (default: 3000), "
		 "Pass -1 for infinite timeout");
static bool noverify;
module_param(noverify, bool, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(noverify, "Disable random data setup and verification");
static bool verbose;
module_param(verbose, bool, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(verbose, "Enable \"success\" result messages (default: off)");
/**
 * struct dmatest_params - test parameters.
 * @buf_size:           size of the memcpy test buffer
 * @channel:            bus ID of the channel to test
 * @device:             bus ID of the DMA Engine to test
 * @threads_per_chan:   number of threads to start per channel
 * @max_channels:       maximum number of channels to use
 * @iterations:         iterations before stopping test
 * @xor_sources:        number of xor source buffers
 * @pq_sources:         number of p+q source buffers
 * @timeout:            transfer timeout in msec, -1 for infinite timeout
 */
struct dmatest_params {
	
unsigned int	buf_size;
	
char		channel[20];
	
char		device[32];
	
unsigned int	threads_per_chan;
	
unsigned int	max_channels;
	
unsigned int	iterations;
	
unsigned int	xor_sources;
	
unsigned int	pq_sources;
	
int		timeout;
	
bool		noverify;
};
/**
 * struct dmatest_info - test information.
 * @params:             test parameters
 * @lock:               access protection to the fields of this structure
 */
static struct dmatest_info {
	/* Test parameters */
	
struct dmatest_params	params;
	/* Internal state */
	
struct list_head	channels;
	
unsigned int		nr_channels;
	
struct mutex		lock;
	
bool			did_init;
} test_info = {
	.channels = LIST_HEAD_INIT(test_info.channels),
	.lock = __MUTEX_INITIALIZER(test_info.lock),
};
static int dmatest_run_set(const char *val, const struct kernel_param *kp);
static int dmatest_run_get(char *val, const struct kernel_param *kp);
static const struct kernel_param_ops run_ops = {
	.set = dmatest_run_set,
	.get = dmatest_run_get,
};
static bool dmatest_run;
module_param_cb(run, &run_ops, &dmatest_run, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(run, "Run the test (default: false)");
/* Maximum amount of mismatched bytes in buffer to print */
#define MAX_ERROR_COUNT		32
/*
 * Initialization patterns. All bytes in the source buffer has bit 7
 * set, all bytes in the destination buffer has bit 7 cleared.
 *
 * Bit 6 is set for all bytes which are to be copied by the DMA
 * engine. Bit 5 is set for all bytes which are to be overwritten by
 * the DMA engine.
 *
 * The remaining bits are the inverse of a counter which increments by
 * one for each byte address.
 */
#define PATTERN_SRC		0x80
#define PATTERN_DST		0x00
#define PATTERN_COPY		0x40
#define PATTERN_OVERWRITE	0x20
#define PATTERN_COUNT_MASK	0x1f
struct dmatest_thread {
	
struct list_head	node;
	
struct dmatest_info	*info;
	
struct task_struct	*task;
	
struct dma_chan		*chan;
	
u8			**srcs;
	
u8			**usrcs;
	
u8			**dsts;
	
u8			**udsts;
	
enum dma_transaction_type type;
	
bool			done;
};
struct dmatest_chan {
	
struct list_head	node;
	
struct dma_chan		*chan;
	
struct list_head	threads;
};
static DECLARE_WAIT_QUEUE_HEAD(thread_wait);
static bool wait;
static bool is_threaded_test_run(struct dmatest_info *info)
{
	struct dmatest_chan *dtc;
	list_for_each_entry(dtc, &info->channels, node) {
		struct dmatest_thread *thread;
		list_for_each_entry(thread, &dtc->threads, node) {
			if (!thread->done)
				return true;
		}
	}
	return false;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dan J Williams | 48 | 88.89% | 1 | 25.00% | 
| Andy Shevchenko | 6 | 11.11% | 3 | 75.00% | 
| Total | 54 | 100.00% | 4 | 100.00% | 
static int dmatest_wait_get(char *val, const struct kernel_param *kp)
{
	struct dmatest_info *info = &test_info;
	struct dmatest_params *params = &info->params;
	if (params->iterations)
		wait_event(thread_wait, !is_threaded_test_run(info));
	wait = true;
	return param_get_bool(val, kp);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dan J Williams | 56 | 88.89% | 1 | 25.00% | 
| Andy Shevchenko | 7 | 11.11% | 3 | 75.00% | 
| Total | 63 | 100.00% | 4 | 100.00% | 
static const struct kernel_param_ops wait_ops = {
	.get = dmatest_wait_get,
	.set = param_set_bool,
};
module_param_cb(wait, &wait_ops, &wait, S_IRUGO);
MODULE_PARM_DESC(wait, "Wait for tests to complete (default: false)");
static bool dmatest_match_channel(struct dmatest_params *params,
		struct dma_chan *chan)
{
	if (params->channel[0] == '\0')
		return true;
	return strcmp(dma_chan_name(chan), params->channel) == 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Håvard Skinnemoen | 31 | 68.89% | 1 | 20.00% | 
| Andy Shevchenko | 11 | 24.44% | 2 | 40.00% | 
| Kay Sievers | 2 | 4.44% | 1 | 20.00% | 
| Dan J Williams | 1 | 2.22% | 1 | 20.00% | 
| Total | 45 | 100.00% | 5 | 100.00% | 
static bool dmatest_match_device(struct dmatest_params *params,
		struct dma_device *device)
{
	if (params->device[0] == '\0')
		return true;
	return strcmp(dev_name(device->dev), params->device) == 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Håvard Skinnemoen | 33 | 70.21% | 1 | 25.00% | 
| Andy Shevchenko | 11 | 23.40% | 2 | 50.00% | 
| Kay Sievers | 3 | 6.38% | 1 | 25.00% | 
| Total | 47 | 100.00% | 4 | 100.00% | 
static unsigned long dmatest_random(void)
{
	unsigned long buf;
	prandom_bytes(&buf, sizeof(buf));
	return buf;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Håvard Skinnemoen | 26 | 96.30% | 1 | 50.00% | 
| Dan J Williams | 1 | 3.70% | 1 | 50.00% | 
| Total | 27 | 100.00% | 2 | 100.00% | 
static void dmatest_init_srcs(u8 **bufs, unsigned int start, unsigned int len,
		unsigned int buf_size)
{
	unsigned int i;
	u8 *buf;
	for (; (buf = *bufs); bufs++) {
		for (i = 0; i < start; i++)
			buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK);
		for ( ; i < start + len; i++)
			buf[i] = PATTERN_SRC | PATTERN_COPY
				| (~i & PATTERN_COUNT_MASK);
		for ( ; i < buf_size; i++)
			buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK);
		buf++;
	}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Håvard Skinnemoen | 98 | 76.56% | 1 | 33.33% | 
| Dan J Williams | 25 | 19.53% | 1 | 33.33% | 
| Andy Shevchenko | 5 | 3.91% | 1 | 33.33% | 
| Total | 128 | 100.00% | 3 | 100.00% | 
static void dmatest_init_dsts(u8 **bufs, unsigned int start, unsigned int len,
		unsigned int buf_size)
{
	unsigned int i;
	u8 *buf;
	for (; (buf = *bufs); bufs++) {
		for (i = 0; i < start; i++)
			buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK);
		for ( ; i < start + len; i++)
			buf[i] = PATTERN_DST | PATTERN_OVERWRITE
				| (~i & PATTERN_COUNT_MASK);
		for ( ; i < buf_size; i++)
			buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK);
	}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Håvard Skinnemoen | 98 | 78.40% | 1 | 33.33% | 
| Dan J Williams | 22 | 17.60% | 1 | 33.33% | 
| Andy Shevchenko | 5 | 4.00% | 1 | 33.33% | 
| Total | 125 | 100.00% | 3 | 100.00% | 
static void dmatest_mismatch(u8 actual, u8 pattern, unsigned int index,
		unsigned int counter, bool is_srcbuf)
{
	u8		diff = actual ^ pattern;
	u8		expected = pattern | (~counter & PATTERN_COUNT_MASK);
	const char	*thread_name = current->comm;
	if (is_srcbuf)
		pr_warn("%s: srcbuf[0x%x] overwritten! Expected %02x, got %02x\n",
			thread_name, index, expected, actual);
	else if ((pattern & PATTERN_COPY)
			&& (diff & (PATTERN_COPY | PATTERN_OVERWRITE)))
		pr_warn("%s: dstbuf[0x%x] not copied! Expected %02x, got %02x\n",
			thread_name, index, expected, actual);
	else if (diff & PATTERN_SRC)
		pr_warn("%s: dstbuf[0x%x] was copied! Expected %02x, got %02x\n",
			thread_name, index, expected, actual);
	else
		pr_warn("%s: dstbuf[0x%x] mismatch! Expected %02x, got %02x\n",
			thread_name, index, expected, actual);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dan J Williams | 101 | 75.37% | 2 | 50.00% | 
| Håvard Skinnemoen | 30 | 22.39% | 1 | 25.00% | 
| Andy Shevchenko | 3 | 2.24% | 1 | 25.00% | 
| Total | 134 | 100.00% | 4 | 100.00% | 
static unsigned int dmatest_verify(u8 **bufs, unsigned int start,
		unsigned int end, unsigned int counter, u8 pattern,
		bool is_srcbuf)
{
	unsigned int i;
	unsigned int error_count = 0;
	u8 actual;
	u8 expected;
	u8 *buf;
	unsigned int counter_orig = counter;
	for (; (buf = *bufs); bufs++) {
		counter = counter_orig;
		for (i = start; i < end; i++) {
			actual = buf[i];
			expected = pattern | (~counter & PATTERN_COUNT_MASK);
			if (actual != expected) {
				if (error_count < MAX_ERROR_COUNT)
					dmatest_mismatch(actual, pattern, i,
							 counter, is_srcbuf);
				error_count++;
			}
			counter++;
		}
	}
	if (error_count > MAX_ERROR_COUNT)
		pr_warn("%s: %u errors suppressed\n",
			current->comm, error_count - MAX_ERROR_COUNT);
	return error_count;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Håvard Skinnemoen | 103 | 63.19% | 1 | 20.00% | 
| Dan J Williams | 50 | 30.67% | 2 | 40.00% | 
| Andy Shevchenko | 10 | 6.13% | 2 | 40.00% | 
| Total | 163 | 100.00% | 5 | 100.00% | 
/* poor man's completion - we want to use wait_event_freezable() on it */
struct dmatest_done {
	
bool			done;
	
wait_queue_head_t	*wait;
};
static void dmatest_callback(void *arg)
{
	struct dmatest_done *done = arg;
	done->done = true;
	wake_up_all(done->wait);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Tejun Heo | 18 | 60.00% | 1 | 50.00% | 
| Dan J Williams | 12 | 40.00% | 1 | 50.00% | 
| Total | 30 | 100.00% | 2 | 100.00% | 
static unsigned int min_odd(unsigned int x, unsigned int y)
{
	unsigned int val = min(x, y);
	return val % 2 ? val : val - 1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Akinobu Mita | 26 | 70.27% | 1 | 50.00% | 
| Andy Shevchenko | 11 | 29.73% | 1 | 50.00% | 
| Total | 37 | 100.00% | 2 | 100.00% | 
static void result(const char *err, unsigned int n, unsigned int src_off,
		   unsigned int dst_off, unsigned int len, unsigned long data)
{
	pr_info("%s: result #%u: '%s' with src_off=0x%x dst_off=0x%x len=0x%x (%lu)\n",
		current->comm, n, err, src_off, dst_off, len, data);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dan J Williams | 26 | 50.00% | 2 | 40.00% | 
| Andy Shevchenko | 25 | 48.08% | 2 | 40.00% | 
| Jerome Blin | 1 | 1.92% | 1 | 20.00% | 
| Total | 52 | 100.00% | 5 | 100.00% | 
static void dbg_result(const char *err, unsigned int n, unsigned int src_off,
		       unsigned int dst_off, unsigned int len,
		       unsigned long data)
{
	pr_debug("%s: result #%u: '%s' with src_off=0x%x dst_off=0x%x len=0x%x (%lu)\n",
		 current->comm, n, err, src_off, dst_off, len, data);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Andy Shevchenko | 22 | 42.31% | 1 | 16.67% | 
| Dan J Williams | 14 | 26.92% | 2 | 33.33% | 
| Akinobu Mita | 14 | 26.92% | 1 | 16.67% | 
| Jerome Blin | 1 | 1.92% | 1 | 16.67% | 
| Håvard Skinnemoen | 1 | 1.92% | 1 | 16.67% | 
| Total | 52 | 100.00% | 6 | 100.00% | 
#define verbose_result(err, n, src_off, dst_off, len, data) ({      \
        if (verbose)                                            \
                result(err, n, src_off, dst_off, len, data);    \
        else                                                    \
                dbg_result(err, n, src_off, dst_off, len, data);\
})
static unsigned long long dmatest_persec(s64 runtime, unsigned int val)
{
	unsigned long long per_sec = 1000000;
	if (runtime <= 0)
		return 0;
	/* drop precision until runtime is 32-bits */
	while (runtime > UINT_MAX) {
		runtime >>= 1;
		per_sec <<= 1;
	}
	per_sec *= val;
	do_div(per_sec, runtime);
	return per_sec;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dan J Williams | 38 | 61.29% | 1 | 33.33% | 
| Andy Shevchenko | 20 | 32.26% | 1 | 33.33% | 
| Håvard Skinnemoen | 4 | 6.45% | 1 | 33.33% | 
| Total | 62 | 100.00% | 3 | 100.00% | 
static unsigned long long dmatest_KBs(s64 runtime, unsigned long long len)
{
	return dmatest_persec(runtime, len >> 10);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dan J Williams | 18 | 69.23% | 1 | 33.33% | 
| Andy Shevchenko | 8 | 30.77% | 2 | 66.67% | 
| Total | 26 | 100.00% | 3 | 100.00% | 
/*
 * This function repeatedly tests DMA transfers of various lengths and
 * offsets for a given operation type until it is told to exit by
 * kthread_stop(). There may be multiple threads running this function
 * in parallel for a single channel, and there may be multiple channels
 * being tested in parallel.
 *
 * Before each test, the source and destination buffer is initialized
 * with a known pattern. This pattern is different depending on
 * whether it's in an area which is supposed to be copied or
 * overwritten, and different in the source and destination buffers.
 * So if the DMA engine doesn't copy exactly what we tell it to copy,
 * we'll notice.
 */
static int dmatest_func(void *data)
{
	DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_wait);
	struct dmatest_thread	*thread = data;
	struct dmatest_done	done = { .wait = &done_wait };
	struct dmatest_info	*info;
	struct dmatest_params	*params;
	struct dma_chan		*chan;
	struct dma_device	*dev;
	unsigned int		error_count;
	unsigned int		failed_tests = 0;
	unsigned int		total_tests = 0;
	dma_cookie_t		cookie;
	enum dma_status		status;
	enum dma_ctrl_flags 	flags;
	u8			*pq_coefs = NULL;
	int			ret;
	int			src_cnt;
	int			dst_cnt;
	int			i;
	ktime_t			ktime, start, diff;
	ktime_t			filltime = 0;
	ktime_t			comparetime = 0;
	s64			runtime = 0;
	unsigned long long	total_len = 0;
	u8			align = 0;
	set_freezable();
	ret = -ENOMEM;
	smp_rmb();
	info = thread->info;
	params = &info->params;
	chan = thread->chan;
	dev = chan->device;
	if (thread->type == DMA_MEMCPY) {
		align = dev->copy_align;
		src_cnt = dst_cnt = 1;
	} else if (thread->type == DMA_SG) {
		align = dev->copy_align;
		src_cnt = dst_cnt = sg_buffers;
	} 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)
			goto err_thread_type;
		for (i = 0; i < src_cnt; i++)
			pq_coefs[i] = 1;
	} else
		goto err_thread_type;
	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);
	if (!thread->usrcs)
		goto err_usrcs;
	for (i = 0; i < src_cnt; i++) {
		thread->usrcs[i] = kmalloc(params->buf_size + align,
					   GFP_KERNEL);
		if (!thread->usrcs[i])
			goto err_srcbuf;
		/* align srcs to alignment restriction */
		if (align)
			thread->srcs[i] = PTR_ALIGN(thread->usrcs[i], align);
		else
			thread->srcs[i] = thread->usrcs[i];
	}
	thread->srcs[i] = NULL;
	thread->dsts = kcalloc(dst_cnt + 1, sizeof(u8 *), GFP_KERNEL);
	if (!thread->dsts)
		goto err_dsts;
	thread->udsts = kcalloc(dst_cnt + 1, sizeof(u8 *), GFP_KERNEL);
	if (!thread->udsts)
		goto err_udsts;
	for (i = 0; i < dst_cnt; i++) {
		thread->udsts[i] = kmalloc(params->buf_size + align,
					   GFP_KERNEL);
		if (!thread->udsts[i])
			goto err_dstbuf;
		/* align dsts to alignment restriction */
		if (align)
			thread->dsts[i] = PTR_ALIGN(thread->udsts[i], align);
		else
			thread->dsts[i] = thread->udsts[i];
	}
	thread->dsts[i] = NULL;
	set_user_nice(current, 10);
	/*
         * src and dst buffers are freed by ourselves below
         */
	flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
	ktime = ktime_get();
	while (!kthread_should_stop()
	       && !(params->iterations && total_tests >= params->iterations)) {
		struct dma_async_tx_descriptor *tx = NULL;
		struct dmaengine_unmap_data *um;
		dma_addr_t srcs[src_cnt];
		dma_addr_t *dsts;
		unsigned int src_off, dst_off, len;
		struct scatterlist tx_sg[src_cnt];
		struct scatterlist rx_sg[src_cnt];
		total_tests++;
		/* Check if buffer count fits into map count variable (u8) */
		if ((src_cnt + dst_cnt) >= 255) {
			pr_err("too many buffers (%d of 255 supported)\n",
			       src_cnt + dst_cnt);
			break;
		}
		if (1 << align > params->buf_size) {
			pr_err("%u-byte buffer too small for %d-byte alignment\n",
			       params->buf_size, 1 << align);
			break;
		}
		if (params->noverify)
			len = params->buf_size;
		else
			len = dmatest_random() % params->buf_size + 1;
		len = (len >> align) << align;
		if (!len)
			len = 1 << align;
		total_len += len;
		if (params->noverify) {
			src_off = 0;
			dst_off = 0;
		} else {
			start = ktime_get();
			src_off = dmatest_random() % (params->buf_size - len + 1);
			dst_off = dmatest_random() % (params->buf_size - len + 1);
			src_off = (src_off >> align) << align;
			dst_off = (dst_off >> align) << align;
			dmatest_init_srcs(thread->srcs, src_off, len,
					  params->buf_size);
			dmatest_init_dsts(thread->dsts, dst_off, len,
					  params->buf_size);
			diff = ktime_sub(ktime_get(), start);
			filltime = ktime_add(filltime, diff);
		}
		um = dmaengine_get_unmap_data(dev->dev, src_cnt + dst_cnt,
					      GFP_KERNEL);
		if (!um) {
			failed_tests++;
			result("unmap data NULL", total_tests,
			       src_off, dst_off, len, ret);
			continue;
		}
		um->len = params->buf_size;
		for (i = 0; i < src_cnt; i++) {
			void *buf = thread->srcs[i];
			struct page *pg = virt_to_page(buf);
			unsigned long pg_off = offset_in_page(buf);
			um->addr[i] = dma_map_page(dev->dev, pg, pg_off,
						   um->len, DMA_TO_DEVICE);
			srcs[i] = um->addr[i] + src_off;
			ret = dma_mapping_error(dev->dev, um->addr[i]);
			if (ret) {
				dmaengine_unmap_put(um);
				result("src mapping error", total_tests,
				       src_off, dst_off, len, ret);
				failed_tests++;
				continue;
			}
			um->to_cnt++;
		}
		/* map with DMA_BIDIRECTIONAL to force writeback/invalidate */
		dsts = &um->addr[src_cnt];
		for (i = 0; i < dst_cnt; i++) {
			void *buf = thread->dsts[i];
			struct page *pg = virt_to_page(buf);
			unsigned long pg_off = offset_in_page(buf);
			dsts[i] = dma_map_page(dev->dev, pg, pg_off, um->len,
					       DMA_BIDIRECTIONAL);
			ret = dma_mapping_error(dev->dev, dsts[i]);
			if (ret) {
				dmaengine_unmap_put(um);
				result("dst mapping error", total_tests,
				       src_off, dst_off, len, ret);
				failed_tests++;
				continue;
			}
			um->bidi_cnt++;
		}
		sg_init_table(tx_sg, src_cnt);
		sg_init_table(rx_sg, src_cnt);
		for (i = 0; i < src_cnt; i++) {
			sg_dma_address(&rx_sg[i]) = srcs[i];
			sg_dma_address(&tx_sg[i]) = dsts[i] + dst_off;
			sg_dma_len(&tx_sg[i]) = len;
			sg_dma_len(&rx_sg[i]) = len;
		}
		if (thread->type == DMA_MEMCPY)
			tx = dev->device_prep_dma_memcpy(chan,
							 dsts[0] + dst_off,
							 srcs[0], len, flags);
		else if (thread->type == DMA_SG)
			tx = dev->device_prep_dma_sg(chan, tx_sg, src_cnt,
						     rx_sg, src_cnt, flags);
		else if (thread->type == DMA_XOR)
			tx = dev->device_prep_dma_xor(chan,
						      dsts[0] + dst_off,
						      srcs, src_cnt,
						      len, flags);
		else if (thread->type == DMA_PQ) {
			dma_addr_t dma_pq[dst_cnt];
			for (i = 0; i < dst_cnt; i++)
				dma_pq[i] = dsts[i] + dst_off;
			tx = dev->device_prep_dma_pq(chan, dma_pq, srcs,
						     src_cnt, pq_coefs,
						     len, flags);
		}
		if (!tx) {
			dmaengine_unmap_put(um);
			result("prep error", total_tests, src_off,
			       dst_off, len, ret);
			msleep(100);
			failed_tests++;
			continue;
		}
		done.done = false;
		tx->callback = dmatest_callback;
		tx->callback_param = &done;
		cookie = tx->tx_submit(tx);
		if (dma_submit_error(cookie)) {
			dmaengine_unmap_put(um);
			result("submit error", total_tests, src_off,
			       dst_off, len, ret);
			msleep(100);
			failed_tests++;
			continue;
		}
		dma_async_issue_pending(chan);
		wait_event_freezable_timeout(done_wait, done.done,
					     msecs_to_jiffies(params->timeout));
		status = dma_async_is_tx_complete(chan, cookie, NULL, NULL);
		if (!done.done) {
			/*
                         * We're leaving the timed out dma operation with
                         * dangling pointer to done_wait.  To make this
                         * correct, we'll need to allocate wait_done for
                         * each test iteration and perform "who's gonna
                         * free it this time?" dancing.  For now, just
                         * leave it dangling.
                         */
			dmaengine_unmap_put(um);
			result("test timed out", total_tests, src_off, dst_off,
			       len, 0);
			failed_tests++;
			continue;
		} else if (status != DMA_COMPLETE) {
			dmaengine_unmap_put(um);
			result(status == DMA_ERROR ?
			       "completion error status" :
			       "completion busy status", total_tests, src_off,
			       dst_off, len, ret);
			failed_tests++;
			continue;
		}
		dmaengine_unmap_put(um);
		if (params->noverify) {
			verbose_result("test passed", total_tests, src_off,
				       dst_off, len, 0);
			continue;
		}
		start = ktime_get();
		pr_debug("%s: verifying source buffer...\n", current->comm);
		error_count = dmatest_verify(thread->srcs, 0, src_off,
				0, PATTERN_SRC, true);
		error_count += dmatest_verify(thread->srcs, src_off,
				src_off + len, src_off,
				PATTERN_SRC | PATTERN_COPY, true);
		error_count += dmatest_verify(thread->srcs, src_off + len,
				params->buf_size, src_off + len,
				PATTERN_SRC, true);
		pr_debug("%s: verifying dest buffer...\n", current->comm);
		error_count += dmatest_verify(thread->dsts, 0, dst_off,
				0, PATTERN_DST, false);
		error_count += dmatest_verify(thread->dsts, dst_off,
				dst_off + len, src_off,
				PATTERN_SRC | PATTERN_COPY, false);
		error_count += dmatest_verify(thread->dsts, dst_off + len,
				params->buf_size, dst_off + len,
				PATTERN_DST, false);
		diff = ktime_sub(ktime_get(), start);
		comparetime = ktime_add(comparetime, diff);
		if (error_count) {
			result("data error", total_tests, src_off, dst_off,
			       len, error_count);
			failed_tests++;
		} else {
			verbose_result("test passed", total_tests, src_off,
				       dst_off, len, 0);
		}
	}
	ktime = ktime_sub(ktime_get(), ktime);
	ktime = ktime_sub(ktime, comparetime);
	ktime = ktime_sub(ktime, filltime);
	runtime = ktime_to_us(ktime);
	ret = 0;
err_dstbuf:
	for (i = 0; thread->udsts[i]; i++)
		kfree(thread->udsts[i]);
	kfree(thread->udsts);
err_udsts:
	kfree(thread->dsts);
err_dsts:
err_srcbuf:
	for (i = 0; thread->usrcs[i]; i++)
		kfree(thread->usrcs[i]);
	kfree(thread->usrcs);
err_usrcs:
	kfree(thread->srcs);
err_srcs:
	kfree(pq_coefs);
err_thread_type:
	pr_info("%s: summary %u tests, %u failures %llu iops %llu KB/s (%d)\n",
		current->comm, total_tests, failed_tests,
		dmatest_persec(runtime, total_tests),
		dmatest_KBs(runtime, total_len), ret);
	/* terminate all transfers on specified channels */
	if (ret)
		dmaengine_terminate_all(chan);
	thread->done = true;
	wake_up(&thread_wait);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dan J Williams | 836 | 38.99% | 13 | 31.71% | 
| Andy Shevchenko | 321 | 14.97% | 9 | 21.95% | 
| Håvard Skinnemoen | 304 | 14.18% | 1 | 2.44% | 
| Dave Jiang | 199 | 9.28% | 1 | 2.44% | 
| Appana Durga Kedareswara Rao | 138 | 6.44% | 1 | 2.44% | 
| Sinan Kaya | 89 | 4.15% | 1 | 2.44% | 
| Atsushi Nemoto | 84 | 3.92% | 1 | 2.44% | 
| Guennadi Liakhovetski | 69 | 3.22% | 2 | 4.88% | 
| Akinobu Mita | 25 | 1.17% | 1 | 2.44% | 
| Stefan Roese | 23 | 1.07% | 1 | 2.44% | 
| Tejun Heo | 20 | 0.93% | 1 | 2.44% | 
| Nicolas Ferre | 13 | 0.61% | 1 | 2.44% | 
| Geliang Tang | 8 | 0.37% | 1 | 2.44% | 
| Viresh Kumar | 5 | 0.23% | 1 | 2.44% | 
| Shiraz Hashim | 4 | 0.19% | 1 | 2.44% | 
| Anatolij Gustschin | 2 | 0.09% | 1 | 2.44% | 
| Jon Mason | 1 | 0.05% | 1 | 2.44% | 
| Vinod Koul | 1 | 0.05% | 1 | 2.44% | 
| Ira W. Snyder | 1 | 0.05% | 1 | 2.44% | 
| Bartlomiej Zolnierkiewicz | 1 | 0.05% | 1 | 2.44% | 
| Total | 2144 | 100.00% | 41 | 100.00% | 
static void dmatest_cleanup_channel(struct dmatest_chan *dtc)
{
	struct dmatest_thread	*thread;
	struct dmatest_thread	*_thread;
	int			ret;
	list_for_each_entry_safe(thread, _thread, &dtc->threads, node) {
		ret = kthread_stop(thread->task);
		pr_debug("thread %s exited with status %d\n",
			 thread->task->comm, ret);
		list_del(&thread->node);
		put_task_struct(thread->task);
		kfree(thread);
	}
	/* terminate all transfers on specified channels */
	dmaengine_terminate_all(dtc->chan);
	kfree(dtc);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Håvard Skinnemoen | 75 | 82.42% | 1 | 20.00% | 
| Dan J Williams | 8 | 8.79% | 2 | 40.00% | 
| Viresh Kumar | 7 | 7.69% | 1 | 20.00% | 
| Jon Mason | 1 | 1.10% | 1 | 20.00% | 
| Total | 91 | 100.00% | 5 | 100.00% | 
static int dmatest_add_threads(struct dmatest_info *info,
		struct dmatest_chan *dtc, enum dma_transaction_type type)
{
	struct dmatest_params *params = &info->params;
	struct dmatest_thread *thread;
	struct dma_chan *chan = dtc->chan;
	char *op;
	unsigned int i;
	if (type == DMA_MEMCPY)
		op = "copy";
	else if (type == DMA_SG)
		op = "sg";
	else if (type == DMA_XOR)
		op = "xor";
	else if (type == DMA_PQ)
		op = "pq";
	else
		return -EINVAL;
	for (i = 0; i < params->threads_per_chan; i++) {
		thread = kzalloc(sizeof(struct dmatest_thread), GFP_KERNEL);
		if (!thread) {
			pr_warn("No memory for %s-%s%u\n",
				dma_chan_name(chan), op, i);
			break;
		}
		thread->info = info;
		thread->chan = dtc->chan;
		thread->type = type;
		smp_wmb();
		thread->task = kthread_create(dmatest_func, thread, "%s-%s%u",
				dma_chan_name(chan), op, i);
		if (IS_ERR(thread->task)) {
			pr_warn("Failed to create thread %s-%s%u\n",
				dma_chan_name(chan), op, i);
			kfree(thread);
			break;
		}
		/* srcbuf and dstbuf are allocated by the thread itself */
		get_task_struct(thread->task);
		list_add_tail(&thread->node, &dtc->threads);
		wake_up_process(thread->task);
	}
	return i;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Håvard Skinnemoen | 131 | 50.58% | 1 | 9.09% | 
| Dan J Williams | 88 | 33.98% | 6 | 54.55% | 
| Andy Shevchenko | 23 | 8.88% | 2 | 18.18% | 
| Appana Durga Kedareswara Rao | 11 | 4.25% | 1 | 9.09% | 
| Kay Sievers | 6 | 2.32% | 1 | 9.09% | 
| Total | 259 | 100.00% | 11 | 100.00% | 
static int dmatest_add_channel(struct dmatest_info *info,
		struct dma_chan *chan)
{
	struct dmatest_chan	*dtc;
	struct dma_device	*dma_dev = chan->device;
	unsigned int		thread_count = 0;
	int cnt;
	dtc = kmalloc(sizeof(struct dmatest_chan), GFP_KERNEL);
	if (!dtc) {
		pr_warn("No memory for %s\n", dma_chan_name(chan));
		return -ENOMEM;
	}
	dtc->chan = chan;
	INIT_LIST_HEAD(&dtc->threads);
	if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
		if (dmatest == 0) {
			cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY);
			thread_count += cnt > 0 ? cnt : 0;
		}
	}
	if (dma_has_cap(DMA_SG, dma_dev->cap_mask)) {
		if (dmatest == 1) {
			cnt = dmatest_add_threads(info, dtc, DMA_SG);
			thread_count += cnt > 0 ? cnt : 0;
		}
	}
	if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
		cnt = dmatest_add_threads(info, dtc, DMA_XOR);
		thread_count += cnt > 0 ? cnt : 0;
	}
	if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
		cnt = dmatest_add_threads(info, dtc, DMA_PQ);
		thread_count += cnt > 0 ? cnt : 0;
	}
	pr_info("Started %u threads using %s\n",
		thread_count, dma_chan_name(chan));
	list_add_tail(&dtc->node, &info->channels);
	info->nr_channels++;
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dan J Williams | 178 | 65.44% | 5 | 41.67% | 
| Appana Durga Kedareswara Rao | 50 | 18.38% | 1 | 8.33% | 
| Håvard Skinnemoen | 23 | 8.46% | 1 | 8.33% | 
| Andy Shevchenko | 16 | 5.88% | 2 | 16.67% | 
| Kay Sievers | 2 | 0.74% | 1 | 8.33% | 
| Nicolas Ferre | 2 | 0.74% | 1 | 8.33% | 
| David Alan Gilbert | 1 | 0.37% | 1 | 8.33% | 
| Total | 272 | 100.00% | 12 | 100.00% | 
static bool filter(struct dma_chan *chan, void *param)
{
	struct dmatest_params *params = param;
	if (!dmatest_match_channel(params, chan) ||
	    !dmatest_match_device(params, chan->device))
		return false;
	else
		return true;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Håvard Skinnemoen | 30 | 61.22% | 1 | 20.00% | 
| Andy Shevchenko | 11 | 22.45% | 2 | 40.00% | 
| Dan J Williams | 8 | 16.33% | 2 | 40.00% | 
| Total | 49 | 100.00% | 5 | 100.00% | 
static void request_channels(struct dmatest_info *info,
			     enum dma_transaction_type type)
{
	dma_cap_mask_t mask;
	dma_cap_zero(mask);
	dma_cap_set(type, mask);
	for (;;) {
		struct dmatest_params *params = &info->params;
		struct dma_chan *chan;
		chan = dma_request_channel(mask, filter, params);
		if (chan) {
			if (dmatest_add_channel(info, chan)) {
				dma_release_channel(chan);
				break; /* add_channel failed, punt */
			}
		} else
			break; /* no more channels available */
		if (params->max_channels &&
		    info->nr_channels >= params->max_channels)
			break; /* we have all we need */
	}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dan J Williams | 83 | 78.30% | 3 | 37.50% | 
| Andy Shevchenko | 13 | 12.26% | 4 | 50.00% | 
| Håvard Skinnemoen | 10 | 9.43% | 1 | 12.50% | 
| Total | 106 | 100.00% | 8 | 100.00% | 
static void run_threaded_test(struct dmatest_info *info)
{
	struct dmatest_params *params = &info->params;
	/* Copy test parameters */
	params->buf_size = test_buf_size;
	strlcpy(params->channel, strim(test_channel), sizeof(params->channel));
	strlcpy(params->device, strim(test_device), sizeof(params->device));
	params->threads_per_chan = threads_per_chan;
	params->max_channels = max_channels;
	params->iterations = iterations;
	params->xor_sources = xor_sources;
	params->pq_sources = pq_sources;
	params->timeout = timeout;
	params->noverify = noverify;
	request_channels(info, DMA_MEMCPY);
	request_channels(info, DMA_XOR);
	request_channels(info, DMA_SG);
	request_channels(info, DMA_PQ);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Andy Shevchenko | 97 | 71.32% | 4 | 40.00% | 
| Dan J Williams | 26 | 19.12% | 4 | 40.00% | 
| Appana Durga Kedareswara Rao | 7 | 5.15% | 1 | 10.00% | 
| Håvard Skinnemoen | 6 | 4.41% | 1 | 10.00% | 
| Total | 136 | 100.00% | 10 | 100.00% | 
static void stop_threaded_test(struct dmatest_info *info)
{
	struct dmatest_chan *dtc, *_dtc;
	struct dma_chan *chan;
	list_for_each_entry_safe(dtc, _dtc, &info->channels, node) {
		list_del(&dtc->node);
		chan = dtc->chan;
		dmatest_cleanup_channel(dtc);
		pr_debug("dropped channel %s\n", dma_chan_name(chan));
		dma_release_channel(chan);
	}
	info->nr_channels = 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Andy Shevchenko | 42 | 55.26% | 4 | 40.00% | 
| Dan J Williams | 33 | 43.42% | 5 | 50.00% | 
| Håvard Skinnemoen | 1 | 1.32% | 1 | 10.00% | 
| Total | 76 | 100.00% | 10 | 100.00% | 
static void restart_threaded_test(struct dmatest_info *info, bool run)
{
	/* we might be called early to set run=, defer running until all
         * parameters have been evaluated
         */
	if (!info->did_init)
		return;
	/* Stop any running test first */
	stop_threaded_test(info);
	/* Run test with new parameters */
	run_threaded_test(info);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Andy Shevchenko | 19 | 54.29% | 4 | 66.67% | 
| Dan J Williams | 16 | 45.71% | 2 | 33.33% | 
| Total | 35 | 100.00% | 6 | 100.00% | 
static int dmatest_run_get(char *val, const struct kernel_param *kp)
{
	struct dmatest_info *info = &test_info;
	mutex_lock(&info->lock);
	if (is_threaded_test_run(info)) {
		dmatest_run = true;
	} else {
		stop_threaded_test(info);
		dmatest_run = false;
	}
	mutex_unlock(&info->lock);
	return param_get_bool(val, kp);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Andy Shevchenko | 56 | 76.71% | 2 | 66.67% | 
| Dan J Williams | 17 | 23.29% | 1 | 33.33% | 
| Total | 73 | 100.00% | 3 | 100.00% | 
static int dmatest_run_set(const char *val, const struct kernel_param *kp)
{
	struct dmatest_info *info = &test_info;
	int ret;
	mutex_lock(&info->lock);
	ret = param_set_bool(val, kp);
	if (ret) {
		mutex_unlock(&info->lock);
		return ret;
	}
	if (is_threaded_test_run(info))
		ret = -EBUSY;
	else if (dmatest_run)
		restart_threaded_test(info, dmatest_run);
	mutex_unlock(&info->lock);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Andy Shevchenko | 73 | 75.26% | 3 | 75.00% | 
| Dan J Williams | 24 | 24.74% | 1 | 25.00% | 
| Total | 97 | 100.00% | 4 | 100.00% | 
static int __init dmatest_init(void)
{
	struct dmatest_info *info = &test_info;
	struct dmatest_params *params = &info->params;
	if (dmatest_run) {
		mutex_lock(&info->lock);
		run_threaded_test(info);
		mutex_unlock(&info->lock);
	}
	if (params->iterations && wait)
		wait_event(thread_wait, !is_threaded_test_run(info));
	/* module parameters are stable, inittime tests are started,
         * let userspace take over 'run' control
         */
	info->did_init = true;
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Andy Shevchenko | 47 | 56.63% | 2 | 50.00% | 
| Dan J Williams | 36 | 43.37% | 2 | 50.00% | 
| Total | 83 | 100.00% | 4 | 100.00% | 
/* when compiled-in wait for drivers to load first */
late_initcall(dmatest_init);
static void __exit dmatest_exit(void)
{
	struct dmatest_info *info = &test_info;
	mutex_lock(&info->lock);
	stop_threaded_test(info);
	mutex_unlock(&info->lock);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Andy Shevchenko | 31 | 81.58% | 3 | 75.00% | 
| Dan J Williams | 7 | 18.42% | 1 | 25.00% | 
| Total | 38 | 100.00% | 4 | 100.00% | 
module_exit(dmatest_exit);
MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
MODULE_LICENSE("GPL v2");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dan J Williams | 2073 | 39.56% | 21 | 30.43% | 
| Håvard Skinnemoen | 1226 | 23.40% | 1 | 1.45% | 
| Andy Shevchenko | 973 | 18.57% | 16 | 23.19% | 
| Appana Durga Kedareswara Rao | 253 | 4.83% | 1 | 1.45% | 
| Dave Jiang | 209 | 3.99% | 1 | 1.45% | 
| Sinan Kaya | 89 | 1.70% | 1 | 1.45% | 
| Atsushi Nemoto | 84 | 1.60% | 1 | 1.45% | 
| Guennadi Liakhovetski | 74 | 1.41% | 3 | 4.35% | 
| Akinobu Mita | 65 | 1.24% | 1 | 1.45% | 
| Tejun Heo | 54 | 1.03% | 2 | 2.90% | 
| Nicolas Ferre | 36 | 0.69% | 2 | 2.90% | 
| Viresh Kumar | 33 | 0.63% | 2 | 2.90% | 
| Stefan Roese | 23 | 0.44% | 1 | 1.45% | 
| Kay Sievers | 14 | 0.27% | 1 | 1.45% | 
| Geliang Tang | 8 | 0.15% | 1 | 1.45% | 
| Shiraz Hashim | 4 | 0.08% | 1 | 1.45% | 
| Ingo Molnar | 3 | 0.06% | 1 | 1.45% | 
| Alexey Dobriyan | 3 | 0.06% | 1 | 1.45% | 
| Joe Perches | 2 | 0.04% | 1 | 1.45% | 
| Anatolij Gustschin | 2 | 0.04% | 1 | 1.45% | 
| Luis R. Rodriguez | 2 | 0.04% | 1 | 1.45% | 
| Jerome Blin | 2 | 0.04% | 1 | 1.45% | 
| Jon Mason | 2 | 0.04% | 1 | 1.45% | 
| Jean Delvare | 1 | 0.02% | 1 | 1.45% | 
| Bartlomiej Zolnierkiewicz | 1 | 0.02% | 1 | 1.45% | 
| Eugeniy Paltsev | 1 | 0.02% | 1 | 1.45% | 
| Ira W. Snyder | 1 | 0.02% | 1 | 1.45% | 
| Vinod Koul | 1 | 0.02% | 1 | 1.45% | 
| David Alan Gilbert | 1 | 0.02% | 1 | 1.45% | 
| Total | 5240 | 100.00% | 69 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.