* [PATCH 1/4] dmaengine: enable mutliple clients and operations
@ 2006-07-27 0:07 Dan Williams
2006-07-27 0:07 ` [PATCH 2/4] dmaengine: reduce backend address permutations Dan Williams
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Dan Williams @ 2006-07-27 0:07 UTC (permalink / raw)
To: linux-kernel; +Cc: neilb, galak, christopher.leech, alan, dan.j.williams
From: Dan Williams <dan.j.williams@intel.com>
Enable the dmaengine interface to allow multiple clients to share a
channel, and enable clients to request channels based on an operations
capability mask. This prepares the interface for use with the RAID5 client
and the future RAID6 client.
Multi-client support is achieved by modifying channels to maintain a list
of peer clients.
Multi-operation support is achieved by modifying clients to maintain lists
of channel references. Channel references in a given request list satisfy
a client specified capability mask.
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
drivers/dma/dmaengine.c | 338 +++++++++++++++++++++++++++++++++++++--------
drivers/dma/ioatdma.c | 12 +-
include/linux/dmaengine.h | 166 +++++++++++++++++++---
net/core/dev.c | 21 +--
net/ipv4/tcp.c | 4 -
5 files changed, 436 insertions(+), 105 deletions(-)
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 1527804..3a5d353 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -37,8 +37,13 @@
* Each device has a channels list, which runs unlocked but is never modified
* once the device is registered, it's just setup by the driver.
*
- * Each client has a channels list, it's only modified under the client->lock
- * and in an RCU callback, so it's safe to read under rcu_read_lock().
+ * Each client has 'n' lists of channel references where
+ * n == DMA_MAX_CHAN_TYPE_REQ. These lists are only modified under the
+ * client->lock and in an RCU callback, so they are safe to read under
+ * rcu_read_lock().
+ *
+ * Each channel has a list of peer clients, it's only modified under the
+ * chan->lock. This allows a channel to be shared amongst several clients
*
* Each device has a kref, which is initialized to 1 when the device is
* registered. A kref_put is done for each class_device registered. When the
@@ -85,6 +90,18 @@ static ssize_t show_memcpy_count(struct
return sprintf(buf, "%lu\n", count);
}
+static ssize_t show_xor_count(struct class_device *cd, char *buf)
+{
+ struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev);
+ unsigned long count = 0;
+ int i;
+
+ for_each_possible_cpu(i)
+ count += per_cpu_ptr(chan->local, i)->xor_count;
+
+ return sprintf(buf, "%lu\n", count);
+}
+
static ssize_t show_bytes_transferred(struct class_device *cd, char *buf)
{
struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev);
@@ -97,16 +114,37 @@ static ssize_t show_bytes_transferred(st
return sprintf(buf, "%lu\n", count);
}
+static ssize_t show_bytes_xor(struct class_device *cd, char *buf)
+{
+ struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev);
+ unsigned long count = 0;
+ int i;
+
+ for_each_possible_cpu(i)
+ count += per_cpu_ptr(chan->local, i)->bytes_xor;
+
+ return sprintf(buf, "%lu\n", count);
+}
+
static ssize_t show_in_use(struct class_device *cd, char *buf)
{
+ unsigned int clients = 0;
+ struct list_head *peer;
struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev);
- return sprintf(buf, "%d\n", (chan->client ? 1 : 0));
+ rcu_read_lock();
+ list_for_each_rcu(peer, &chan->peers)
+ clients++;
+ rcu_read_unlock();
+
+ return sprintf(buf, "%d\n", clients);
}
static struct class_device_attribute dma_class_attrs[] = {
__ATTR(memcpy_count, S_IRUGO, show_memcpy_count, NULL),
+ __ATTR(xor_count, S_IRUGO, show_xor_count, NULL),
__ATTR(bytes_transferred, S_IRUGO, show_bytes_transferred, NULL),
+ __ATTR(bytes_xor, S_IRUGO, show_bytes_xor, NULL),
__ATTR(in_use, S_IRUGO, show_in_use, NULL),
__ATTR_NULL
};
@@ -130,34 +168,79 @@ static struct class dma_devclass = {
/**
* dma_client_chan_alloc - try to allocate a channel to a client
* @client: &dma_client
+ * @req: request descriptor
*
* Called with dma_list_mutex held.
*/
-static struct dma_chan *dma_client_chan_alloc(struct dma_client *client)
+static struct dma_chan *dma_client_chan_alloc(struct dma_client *client,
+ struct dma_req *req)
{
struct dma_device *device;
struct dma_chan *chan;
+ struct dma_client_chan_peer *peer;
+ struct dma_chan_client_ref *chan_ref;
unsigned long flags;
int desc; /* allocated descriptor count */
+ int allocated; /* flag re-allocations */
- /* Find a channel, any DMA engine will do */
+ /* Find a channel */
list_for_each_entry(device, &dma_device_list, global_node) {
+ if ((req->cap_mask & device->capabilities)
+ != req->cap_mask)
+ continue;
list_for_each_entry(chan, &device->channels, device_node) {
- if (chan->client)
+ allocated = 0;
+ rcu_read_lock();
+ list_for_each_entry_rcu(chan_ref, &req->channels, req_node) {
+ if (chan_ref->chan == chan) {
+ allocated = 1;
+ break;
+ }
+ }
+ rcu_read_unlock();
+
+ if (allocated)
continue;
+ /* can the channel be shared between multiple clients */
+ if ((req->exclusive && !list_empty(&chan->peers)) ||
+ chan->exclusive)
+ continue;
+
+ chan_ref = kmalloc(sizeof(*chan_ref), GFP_KERNEL);
+ if (!chan_ref)
+ continue;
+
+ peer = kmalloc(sizeof(*peer), GFP_KERNEL);
+ if (!peer) {
+ kfree(chan_ref);
+ continue;
+ }
+
desc = chan->device->device_alloc_chan_resources(chan);
- if (desc >= 0) {
+ if (desc) {
kref_get(&device->refcount);
- kref_init(&chan->refcount);
- chan->slow_ref = 0;
- INIT_RCU_HEAD(&chan->rcu);
- chan->client = client;
+ kref_get(&chan->refcount);
+ INIT_RCU_HEAD(&peer->rcu);
+ INIT_RCU_HEAD(&chan_ref->rcu);
+ INIT_LIST_HEAD(&peer->peer_node);
+ INIT_LIST_HEAD(&chan_ref->req_node);
+ peer->client = client;
+ chan_ref->chan = chan;
+
+ spin_lock_irqsave(&chan->lock, flags);
+ list_add_tail_rcu(&peer->peer_node, &chan->peers);
+ spin_unlock_irqrestore(&chan->lock, flags);
+
spin_lock_irqsave(&client->lock, flags);
- list_add_tail_rcu(&chan->client_node,
- &client->channels);
+ chan->exclusive = req->exclusive ? client : NULL;
+ list_add_tail_rcu(&chan_ref->req_node,
+ &req->channels);
spin_unlock_irqrestore(&client->lock, flags);
return chan;
+ } else {
+ kfree(peer);
+ kfree(chan_ref);
}
}
}
@@ -173,7 +256,6 @@ void dma_chan_cleanup(struct kref *kref)
{
struct dma_chan *chan = container_of(kref, struct dma_chan, refcount);
chan->device->device_free_chan_resources(chan);
- chan->client = NULL;
kref_put(&chan->device->refcount, dma_async_device_cleanup);
}
@@ -186,51 +268,93 @@ static void dma_chan_free_rcu(struct rcu
bias -= local_read(&per_cpu_ptr(chan->local, i)->refcount);
atomic_sub(bias, &chan->refcount.refcount);
kref_put(&chan->refcount, dma_chan_cleanup);
+ kref_put(&chan->device->refcount, dma_async_device_cleanup);
+}
+
+static void dma_peer_free_rcu(struct rcu_head *rcu)
+{
+ struct dma_client_chan_peer *peer =
+ container_of(rcu, struct dma_client_chan_peer, rcu);
+
+ kfree(peer);
+}
+
+static void dma_chan_ref_free_rcu(struct rcu_head *rcu)
+{
+ struct dma_chan_client_ref *chan_ref =
+ container_of(rcu, struct dma_chan_client_ref, rcu);
+
+ kfree(chan_ref);
}
-static void dma_client_chan_free(struct dma_chan *chan)
+static void dma_client_chan_free(struct dma_client *client,
+ struct dma_chan_client_ref *chan_ref)
{
+ struct dma_client_chan_peer *peer;
+ struct dma_chan *chan = chan_ref->chan;
atomic_add(0x7FFFFFFF, &chan->refcount.refcount);
chan->slow_ref = 1;
- call_rcu(&chan->rcu, dma_chan_free_rcu);
+ rcu_read_lock();
+ list_for_each_entry_rcu(peer, &chan->peers, peer_node)
+ if (peer->client == client) {
+ unsigned long flags;
+
+ spin_lock_irqsave(&chan->lock, flags);
+ list_del_rcu(&peer->peer_node);
+ if (list_empty(&chan->peers))
+ chan->exclusive = NULL;
+ spin_unlock_irqrestore(&chan->lock, flags);
+ call_rcu(&peer->rcu, dma_peer_free_rcu);
+ call_rcu(&chan_ref->rcu, dma_chan_ref_free_rcu);
+ call_rcu(&chan->rcu, dma_chan_free_rcu);
+ break;
+ }
+ rcu_read_unlock();
}
/**
* dma_chans_rebalance - reallocate channels to clients
*
- * When the number of DMA channel in the system changes,
- * channels need to be rebalanced among clients.
+ * When the number of DMA channels in the system changes,
+ * channels need to be rebalanced among clients
*/
static void dma_chans_rebalance(void)
{
struct dma_client *client;
struct dma_chan *chan;
+ struct dma_chan_client_ref *chan_ref;
+
unsigned long flags;
+ int i;
mutex_lock(&dma_list_mutex);
list_for_each_entry(client, &dma_client_list, global_node) {
- while (client->chans_desired > client->chan_count) {
- chan = dma_client_chan_alloc(client);
- if (!chan)
- break;
- client->chan_count++;
- client->event_callback(client,
- chan,
- DMA_RESOURCE_ADDED);
- }
- while (client->chans_desired < client->chan_count) {
- spin_lock_irqsave(&client->lock, flags);
- chan = list_entry(client->channels.next,
- struct dma_chan,
- client_node);
- list_del_rcu(&chan->client_node);
- spin_unlock_irqrestore(&client->lock, flags);
- client->chan_count--;
- client->event_callback(client,
- chan,
- DMA_RESOURCE_REMOVED);
- dma_client_chan_free(chan);
+ for (i = 0; i < DMA_MAX_CHAN_TYPE_REQ; i++) {
+ struct dma_req *req = &client->req[i];
+ while (req->chans_desired > atomic_read(&req->chan_count)) {
+ chan = dma_client_chan_alloc(client, req);
+ if (!chan)
+ break;
+ atomic_inc(&req->chan_count);
+ client->event_callback(client,
+ chan,
+ DMA_RESOURCE_ADDED);
+ }
+ while (req->chans_desired < atomic_read(&req->chan_count)) {
+ spin_lock_irqsave(&client->lock, flags);
+ chan_ref = list_entry(req->channels.next,
+ struct dma_chan_client_ref,
+ req_node);
+ list_del_rcu(&chan_ref->req_node);
+ spin_unlock_irqrestore(&client->lock, flags);
+ atomic_dec(&req->chan_count);
+
+ client->event_callback(client,
+ chan_ref->chan,
+ DMA_RESOURCE_REMOVED);
+ dma_client_chan_free(client, chan_ref);
+ }
}
}
@@ -244,15 +368,18 @@ static void dma_chans_rebalance(void)
struct dma_client *dma_async_client_register(dma_event_callback event_callback)
{
struct dma_client *client;
+ int i;
client = kzalloc(sizeof(*client), GFP_KERNEL);
if (!client)
return NULL;
- INIT_LIST_HEAD(&client->channels);
+ for (i = 0; i < DMA_MAX_CHAN_TYPE_REQ; i++) {
+ INIT_LIST_HEAD(&client->req[i].channels);
+ atomic_set(&client->req[i].chan_count, 0);
+ }
+
spin_lock_init(&client->lock);
- client->chans_desired = 0;
- client->chan_count = 0;
client->event_callback = event_callback;
mutex_lock(&dma_list_mutex);
@@ -270,14 +397,16 @@ struct dma_client *dma_async_client_regi
*/
void dma_async_client_unregister(struct dma_client *client)
{
- struct dma_chan *chan;
+ struct dma_chan_client_ref *chan_ref;
+ int i;
if (!client)
return;
rcu_read_lock();
- list_for_each_entry_rcu(chan, &client->channels, client_node)
- dma_client_chan_free(chan);
+ for (i = 0; i < DMA_MAX_CHAN_TYPE_REQ; i++)
+ list_for_each_entry_rcu(chan_ref, &client->req[i].channels, req_node)
+ dma_client_chan_free(client, chan_ref);
rcu_read_unlock();
mutex_lock(&dma_list_mutex);
@@ -292,17 +421,46 @@ void dma_async_client_unregister(struct
* dma_async_client_chan_request - request DMA channels
* @client: &dma_client
* @number: count of DMA channels requested
+ * @mask: limits the DMA channels returned to those that
+ * have the requisite capabilities
*
* Clients call dma_async_client_chan_request() to specify how many
* DMA channels they need, 0 to free all currently allocated.
* The resulting allocations/frees are indicated to the client via the
- * event callback.
+ * event callback. If the client has exhausted the number of distinct
+ * requests allowed (DMA_MAX_CHAN_TYPE_REQ) this function will return 0.
*/
-void dma_async_client_chan_request(struct dma_client *client,
- unsigned int number)
+int dma_async_client_chan_request(struct dma_client *client,
+ unsigned int number, unsigned int mask)
{
- client->chans_desired = number;
- dma_chans_rebalance();
+ int request_slot_found = 0, i;
+
+ /* adjust an outstanding request */
+ for (i = 0; i < DMA_MAX_CHAN_TYPE_REQ; i++) {
+ struct dma_req *req = &client->req[i];
+ if (req->cap_mask == mask) {
+ req->chans_desired = number;
+ request_slot_found = 1;
+ break;
+ }
+ }
+
+ /* start a new request */
+ if (!request_slot_found)
+ for (i = 0; i < DMA_MAX_CHAN_TYPE_REQ; i++) {
+ struct dma_req *req = &client->req[i];
+ if (!req->chans_desired) {
+ req->chans_desired = number;
+ req->cap_mask = mask;
+ request_slot_found = 1;
+ break;
+ }
+ }
+
+ if (request_slot_found)
+ dma_chans_rebalance();
+
+ return request_slot_found;
}
/**
@@ -335,6 +493,7 @@ int dma_async_device_register(struct dma
device->dev_id, chan->chan_id);
kref_get(&device->refcount);
+ kref_init(&chan->refcount);
class_device_register(&chan->class_dev);
}
@@ -348,6 +507,20 @@ int dma_async_device_register(struct dma
}
/**
+ * dma_async_chan_init - common channel initialization
+ * @chan: &dma_chan
+ * @device: &dma_device
+ */
+void dma_async_chan_init(struct dma_chan *chan, struct dma_device *device)
+{
+ INIT_LIST_HEAD(&chan->peers);
+ INIT_RCU_HEAD(&chan->rcu);
+ spin_lock_init(&chan->lock);
+ chan->device = device;
+ list_add_tail(&chan->device_node, &device->channels);
+}
+
+/**
* dma_async_device_cleanup - function called when all references are released
* @kref: kernel reference object
*/
@@ -366,31 +539,70 @@ static void dma_async_device_cleanup(str
void dma_async_device_unregister(struct dma_device *device)
{
struct dma_chan *chan;
+ struct dma_client_chan_peer *peer;
+ struct dma_req *req;
+ struct dma_chan_client_ref *chan_ref;
+ struct dma_client *client;
+ int i;
unsigned long flags;
mutex_lock(&dma_list_mutex);
list_del(&device->global_node);
mutex_unlock(&dma_list_mutex);
+ /* look up and free each reference to a channel
+ * note: a channel can be allocated to a client once per
+ * request type (DMA_MAX_CHAN_TYPE_REQ)
+ */
list_for_each_entry(chan, &device->channels, device_node) {
- if (chan->client) {
- spin_lock_irqsave(&chan->client->lock, flags);
- list_del(&chan->client_node);
- chan->client->chan_count--;
- spin_unlock_irqrestore(&chan->client->lock, flags);
- chan->client->event_callback(chan->client,
- chan,
- DMA_RESOURCE_REMOVED);
- dma_client_chan_free(chan);
+ rcu_read_lock();
+ list_for_each_entry_rcu(peer, &chan->peers, peer_node) {
+ client = peer->client;
+ for (i = 0; i < DMA_MAX_CHAN_TYPE_REQ; i++) {
+ req = &client->req[i];
+ list_for_each_entry_rcu(chan_ref,
+ &req->channels,
+ req_node) {
+ if (chan_ref->chan == chan) {
+ spin_lock_irqsave(&client->lock, flags);
+ list_del_rcu(&chan_ref->req_node);
+ spin_unlock_irqrestore(&client->lock, flags);
+ atomic_dec(&req->chan_count);
+ client->event_callback(
+ client,
+ chan,
+ DMA_RESOURCE_REMOVED);
+ dma_client_chan_free(client,
+ chan_ref);
+ break;
+ }
+ }
+ }
}
- class_device_unregister(&chan->class_dev);
+ rcu_read_unlock();
+ kref_put(&chan->refcount, dma_chan_cleanup);
+ kref_put(&device->refcount, dma_async_device_cleanup);
}
+
+ class_device_unregister(&chan->class_dev);
+
dma_chans_rebalance();
kref_put(&device->refcount, dma_async_device_cleanup);
wait_for_completion(&device->done);
}
+/**
+ * dma_async_xor_pgs_to_pg_err - default function for dma devices that
+ * do not support xor
+ */
+dma_cookie_t dma_async_xor_pgs_to_pg_err(struct dma_chan *chan,
+ struct page *dest_pg, unsigned int dest_off, struct page *src_pgs,
+ unsigned int src_cnt, unsigned int src_off, size_t len, u32 *result)
+{
+ return -ENXIO;
+}
+
static int __init dma_bus_init(void)
{
mutex_init(&dma_list_mutex);
@@ -405,8 +617,10 @@ EXPORT_SYMBOL(dma_async_client_chan_requ
EXPORT_SYMBOL(dma_async_memcpy_buf_to_buf);
EXPORT_SYMBOL(dma_async_memcpy_buf_to_pg);
EXPORT_SYMBOL(dma_async_memcpy_pg_to_pg);
-EXPORT_SYMBOL(dma_async_memcpy_complete);
-EXPORT_SYMBOL(dma_async_memcpy_issue_pending);
+EXPORT_SYMBOL(dma_async_operation_complete);
+EXPORT_SYMBOL(dma_async_issue_pending);
EXPORT_SYMBOL(dma_async_device_register);
EXPORT_SYMBOL(dma_async_device_unregister);
EXPORT_SYMBOL(dma_chan_cleanup);
+EXPORT_SYMBOL(dma_async_xor_pgs_to_pg_err);
+EXPORT_SYMBOL(dma_async_chan_init);
diff --git a/drivers/dma/ioatdma.c b/drivers/dma/ioatdma.c
index dbd4d6c..415de03 100644
--- a/drivers/dma/ioatdma.c
+++ b/drivers/dma/ioatdma.c
@@ -69,11 +69,7 @@ static int enumerate_dma_channels(struct
spin_lock_init(&ioat_chan->desc_lock);
INIT_LIST_HEAD(&ioat_chan->free_desc);
INIT_LIST_HEAD(&ioat_chan->used_desc);
- /* This should be made common somewhere in dmaengine.c */
- ioat_chan->common.device = &device->common;
- ioat_chan->common.client = NULL;
- list_add_tail(&ioat_chan->common.device_node,
- &device->common.channels);
+ dma_async_chan_init(&ioat_chan->common, &device->common);
}
return device->common.chancnt;
}
@@ -759,8 +755,10 @@ #endif
device->common.device_memcpy_buf_to_buf = ioat_dma_memcpy_buf_to_buf;
device->common.device_memcpy_buf_to_pg = ioat_dma_memcpy_buf_to_pg;
device->common.device_memcpy_pg_to_pg = ioat_dma_memcpy_pg_to_pg;
- device->common.device_memcpy_complete = ioat_dma_is_complete;
- device->common.device_memcpy_issue_pending = ioat_dma_memcpy_issue_pending;
+ device->common.device_operation_complete = ioat_dma_is_complete;
+ device->common.device_xor_pgs_to_pg = dma_async_xor_pgs_to_pg_err;
+ device->common.device_issue_pending = ioat_dma_memcpy_issue_pending;
+ device->common.capabilities = DMA_MEMCPY;
printk(KERN_INFO "Intel(R) I/OAT DMA Engine found, %d channels\n",
device->common.chancnt);
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index c94d8f1..dad909a 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -20,7 +20,7 @@
*/
#ifndef DMAENGINE_H
#define DMAENGINE_H
-
+#include <linux/config.h>
#ifdef CONFIG_DMA_ENGINE
#include <linux/device.h>
@@ -65,6 +65,27 @@ enum dma_status {
};
/**
+ * enum dma_capabilities - DMA operational capabilities
+ * @DMA_MEMCPY: src to dest copy
+ * @DMA_XOR: src*n to dest xor
+ * @DMA_DUAL_XOR: src*n to dest_diag and dest_horiz xor
+ * @DMA_PQ_XOR: src*n to dest_q and dest_p gf/xor
+ * @DMA_MEMCPY_CRC32C: src to dest copy and crc-32c sum
+ * @DMA_SHARE: multiple clients can use this channel
+ */
+enum dma_capabilities {
+ DMA_MEMCPY = 0x1,
+ DMA_XOR = 0x2,
+ DMA_PQ_XOR = 0x4,
+ DMA_DUAL_XOR = 0x8,
+ DMA_PQ_UPDATE = 0x10,
+ DMA_XOR_CHECK = 0x20,
+ DMA_PQ_XOR_CHECK = 0x40,
+ DMA_MEMSET = 0x80,
+ DMA_MEMCPY_CRC32C = 0x100,
+};
+
+/**
* struct dma_chan_percpu - the per-CPU part of struct dma_chan
* @refcount: local_t used for open-coded "bigref" counting
* @memcpy_count: transaction counter
@@ -75,27 +96,32 @@ struct dma_chan_percpu {
local_t refcount;
/* stats */
unsigned long memcpy_count;
+ unsigned long xor_count;
unsigned long bytes_transferred;
+ unsigned long bytes_xor;
};
/**
* struct dma_chan - devices supply DMA channels, clients use them
- * @client: ptr to the client user of this chan, will be %NULL when unused
+ * @peers: list of the clients of this chan, will be 'empty' when unused
* @device: ptr to the dma device who supplies this channel, always !%NULL
* @cookie: last cookie value returned to client
+ * @exclusive: ptr to the client that is exclusively using this channel
+ * @lock: protects access to the peer list
* @chan_id: channel ID for sysfs
* @class_dev: class device for sysfs
* @refcount: kref, used in "bigref" slow-mode
* @slow_ref: indicates that the DMA channel is free
* @rcu: the DMA channel's RCU head
- * @client_node: used to add this to the client chan list
* @device_node: used to add this to the device chan list
* @local: per-cpu pointer to a struct dma_chan_percpu
*/
struct dma_chan {
- struct dma_client *client;
+ struct list_head peers;
struct dma_device *device;
dma_cookie_t cookie;
+ struct dma_client *exclusive;
+ spinlock_t lock;
/* sysfs */
int chan_id;
@@ -105,7 +131,6 @@ struct dma_chan {
int slow_ref;
struct rcu_head rcu;
- struct list_head client_node;
struct list_head device_node;
struct dma_chan_percpu *local;
};
@@ -139,29 +164,66 @@ typedef void (*dma_event_callback) (stru
struct dma_chan *chan, enum dma_event event);
/**
- * struct dma_client - info on the entity making use of DMA services
- * @event_callback: func ptr to call when something happens
+ * struct dma_req - info on the type and number of channels allocated to a client
* @chan_count: number of chans allocated
* @chans_desired: number of chans requested. Can be +/- chan_count
+ * @cap_mask: DMA capabilities required to satisfy this request
+ * @exclusive: Whether this client would like exclusive use of the channel(s)
+ */
+struct dma_req {
+ atomic_t chan_count;
+ unsigned int chans_desired;
+ unsigned int cap_mask;
+ int exclusive;
+ struct list_head channels;
+};
+
+/**
+ * struct dma_client - info on the entity making use of DMA services
+ * @event_callback: func ptr to call when something happens
+ * @dma_req: tracks client channel requests per capability mask
* @lock: protects access to the channels list
* @channels: the list of DMA channels allocated
* @global_node: list_head for global dma_client_list
*/
+#define DMA_MAX_CHAN_TYPE_REQ 2
struct dma_client {
dma_event_callback event_callback;
- unsigned int chan_count;
- unsigned int chans_desired;
-
+ struct dma_req req[DMA_MAX_CHAN_TYPE_REQ];
spinlock_t lock;
- struct list_head channels;
struct list_head global_node;
};
/**
+ * struct dma_client_chan_peer - info on the entities sharing a DMA channel
+ * @client: &dma_client
+ * @peer_node: node list of other clients on the channel
+ * @rcu: rcu head for the peer object
+ */
+struct dma_client_chan_peer {
+ struct dma_client *client;
+ struct list_head peer_node;
+ struct rcu_head rcu;
+};
+
+/**
+ * struct dma_chan_client_ref - reference object for clients to track channels
+ * @chan: channel reference
+ * @chan_node: node in the list of other channels on the client
+ * @rcu: rcu head for the chan_ref object
+ */
+struct dma_chan_client_ref {
+ struct dma_chan *chan;
+ struct list_head req_node;
+ struct rcu_head rcu;
+};
+
+/**
* struct dma_device - info on the entity supplying DMA services
* @chancnt: how many DMA channels are supported
* @channels: the list of struct dma_chan
* @global_node: list_head for global dma_device_list
+ * @capabilities: channel operations capabilities
* @refcount: reference count
* @done: IO completion struct
* @dev_id: unique device ID
@@ -179,6 +241,7 @@ struct dma_device {
unsigned int chancnt;
struct list_head channels;
struct list_head global_node;
+ unsigned long capabilities;
struct kref refcount;
struct completion done;
@@ -195,18 +258,27 @@ struct dma_device {
dma_cookie_t (*device_memcpy_pg_to_pg)(struct dma_chan *chan,
struct page *dest_pg, unsigned int dest_off,
struct page *src_pg, unsigned int src_off, size_t len);
- enum dma_status (*device_memcpy_complete)(struct dma_chan *chan,
+ dma_cookie_t (*device_xor_pgs_to_pg)(struct dma_chan *chan,
+ struct page *dest_pg, unsigned int dest_off,
+ struct page **src_pgs, unsigned int src_cnt,
+ unsigned int src_off, size_t len, u32 *result);
+ enum dma_status (*device_operation_complete)(struct dma_chan *chan,
dma_cookie_t cookie, dma_cookie_t *last,
dma_cookie_t *used);
- void (*device_memcpy_issue_pending)(struct dma_chan *chan);
+ void (*device_issue_pending)(struct dma_chan *chan);
};
/* --- public DMA engine API --- */
struct dma_client *dma_async_client_register(dma_event_callback event_callback);
void dma_async_client_unregister(struct dma_client *client);
-void dma_async_client_chan_request(struct dma_client *client,
- unsigned int number);
+int dma_async_client_chan_request(struct dma_client *client,
+ unsigned int number, unsigned int mask);
+void dma_async_chan_init(struct dma_chan *chan, struct dma_device *device);
+dma_cookie_t dma_async_xor_pgs_to_pg_err(struct dma_chan *chan,
+ struct page *dest_pg, unsigned int dest_off, struct page *src_pgs,
+ unsigned int src_cnt, unsigned int src_off, size_t len, u32 *result);
+
/**
* dma_async_memcpy_buf_to_buf - offloaded copy between virtual addresses
@@ -284,19 +356,67 @@ static inline dma_cookie_t dma_async_mem
}
/**
- * dma_async_memcpy_issue_pending - flush pending copies to HW
+ * dma_async_xor_pgs_to_pg - offloaded xor from pages to page
+ * @chan: DMA channel to offload xor to
+ * @dest_page: destination page
+ * @dest_off: offset in page to xor to
+ * @src_pgs: array of source pages
+ * @src_cnt: number of source pages
+ * @src_off: offset in pages to xor from
+ * @len: length
+ * @result: optionally returns whether the xor resulted in a zero sum
+ *
+ * Both @dest_page/@dest_off and @src_page/@src_off must be mappable to a bus
+ * address according to the DMA mapping API rules for streaming mappings.
+ * Both @dest_page/@dest_off and @src_page/@src_off must stay memory resident
+ * (kernel memory or locked user space pages)
+ */
+static inline dma_cookie_t dma_async_xor_pgs_to_pg(struct dma_chan *chan,
+ struct page *dest_pg, unsigned int dest_off, struct page **src_pgs,
+ unsigned int src_cnt, unsigned int src_off, size_t len, u32 *result)
+{
+ int cpu = get_cpu();
+ per_cpu_ptr(chan->local, cpu)->bytes_xor += len * src_cnt;
+ per_cpu_ptr(chan->local, cpu)->xor_count++;
+ put_cpu();
+
+ return chan->device->device_xor_pgs_to_pg(chan, dest_pg, dest_off,
+ src_pgs, src_cnt, src_off, len, result);
+}
+
+
+/**
+ * dma_async_issue_pending - flush pending copies to HW
* @chan: target DMA channel
*
- * This allows drivers to push copies to HW in batches,
+ * This allows drivers to push operations to HW in batches,
* reducing MMIO writes where possible.
*/
-static inline void dma_async_memcpy_issue_pending(struct dma_chan *chan)
+static inline void dma_async_issue_pending(struct dma_chan *chan)
{
- return chan->device->device_memcpy_issue_pending(chan);
+ return chan->device->device_issue_pending(chan);
+}
+
+/**
+ * dma_async_issue_all - call dma_async_issue_pending on all channels
+ * @client: &dma_client
+ */
+static inline void dma_async_issue_all(struct dma_client *client)
+{
+ int i;
+ struct dma_chan_client_ref *chan_ref;
+ struct dma_req *req;
+ for (i = 0; i < DMA_MAX_CHAN_TYPE_REQ; i++) {
+ req = &client->req[i];
+ rcu_read_lock();
+ list_for_each_entry_rcu(chan_ref, &req->channels, req_node)
+ dma_async_issue_pending(chan_ref->chan);
+ rcu_read_unlock();
+ }
}
/**
- * dma_async_memcpy_complete - poll for transaction completion
+ * dma_async_operations_complete - poll for transaction completion
* @chan: DMA channel
* @cookie: transaction identifier to check status of
* @last: returns last completed cookie, can be NULL
@@ -306,10 +426,10 @@ static inline void dma_async_memcpy_issu
* internal state and can be used with dma_async_is_complete() to check
* the status of multiple cookies without re-checking hardware state.
*/
-static inline enum dma_status dma_async_memcpy_complete(struct dma_chan *chan,
+static inline enum dma_status dma_async_operation_complete(struct dma_chan *chan,
dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used)
{
- return chan->device->device_memcpy_complete(chan, cookie, last, used);
+ return chan->device->device_operation_complete(chan, cookie, last, used);
}
/**
@@ -318,7 +438,7 @@ static inline enum dma_status dma_async_
* @last_complete: last know completed transaction
* @last_used: last cookie value handed out
*
- * dma_async_is_complete() is used in dma_async_memcpy_complete()
+ * dma_async_is_complete() is used in dma_async_operation_complete()
* the test logic is seperated for lightweight testing of multiple cookies
*/
static inline enum dma_status dma_async_is_complete(dma_cookie_t cookie,
diff --git a/net/core/dev.c b/net/core/dev.c
index 4d2b516..a72c088 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1958,13 +1958,8 @@ #ifdef CONFIG_NET_DMA
* There may not be any more sk_buffs coming right now, so push
* any pending DMA copies to hardware
*/
- if (net_dma_client) {
- struct dma_chan *chan;
- rcu_read_lock();
- list_for_each_entry_rcu(chan, &net_dma_client->channels, client_node)
- dma_async_memcpy_issue_pending(chan);
- rcu_read_unlock();
- }
+ if (net_dma_client)
+ dma_async_issue_all(net_dma_client);
#endif
local_irq_enable();
return;
@@ -3427,7 +3422,8 @@ #ifdef CONFIG_NET_DMA
static void net_dma_rebalance(void)
{
unsigned int cpu, i, n;
- struct dma_chan *chan;
+ struct dma_chan_client_ref *chan_ref;
+ struct dma_req *req;
lock_cpu_hotplug();
@@ -3441,13 +3437,16 @@ static void net_dma_rebalance(void)
i = 0;
cpu = first_cpu(cpu_online_map);
+ /* NET_DMA only requests one type of dma channel (memcpy) */
+ req = &net_dma_client->req[0];
+
rcu_read_lock();
- list_for_each_entry(chan, &net_dma_client->channels, client_node) {
+ list_for_each_entry(chan_ref, &req->channels, req_node) {
n = ((num_online_cpus() / net_dma_count)
+ (i < (num_online_cpus() % net_dma_count) ? 1 : 0));
while(n) {
- per_cpu(softnet_data.net_dma, cpu) = chan;
+ per_cpu(softnet_data.net_dma, cpu) = chan_ref->chan;
cpu = next_cpu(cpu, cpu_online_map);
n--;
}
@@ -3493,7 +3492,7 @@ static int __init netdev_dma_register(vo
if (net_dma_client == NULL)
return -ENOMEM;
- dma_async_client_chan_request(net_dma_client, num_online_cpus());
+ dma_async_client_chan_request(net_dma_client, num_online_cpus(), DMA_MEMCPY);
return 0;
}
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index f6a2d92..51c5410 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1431,9 +1431,9 @@ #ifdef CONFIG_NET_DMA
struct sk_buff *skb;
dma_cookie_t done, used;
- dma_async_memcpy_issue_pending(tp->ucopy.dma_chan);
+ dma_async_issue_pending(tp->ucopy.dma_chan);
- while (dma_async_memcpy_complete(tp->ucopy.dma_chan,
+ while (dma_async_operation_complete(tp->ucopy.dma_chan,
tp->ucopy.dma_cookie, &done,
&used) == DMA_IN_PROGRESS) {
/* do partial cleanup of sk_async_wait_queue */
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/4] dmaengine: reduce backend address permutations 2006-07-27 0:07 [PATCH 1/4] dmaengine: enable mutliple clients and operations Dan Williams @ 2006-07-27 0:07 ` Dan Williams 2006-07-27 0:07 ` [PATCH 3/4] dmaengine: expose per channel dma mapping characteristics to clients Dan Williams 2006-07-27 0:07 ` [PATCH 4/4] dmaengine: add memset as an asynchronous dma operation Dan Williams 2 siblings, 0 replies; 4+ messages in thread From: Dan Williams @ 2006-07-27 0:07 UTC (permalink / raw) To: linux-kernel; +Cc: neilb, galak, christopher.leech, alan, dan.j.williams From: Dan Williams <dan.j.williams@intel.com> Change the backend dma driver API to accept a 'union dmaengine_addr'. The intent is to be able to support a wide range of frontend address type permutations without needing an equal number of function type permutations on the backend. Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- drivers/dma/dmaengine.c | 12 ++- drivers/dma/ioatdma.c | 187 +++++++++++++++++-------------------------- include/linux/dmaengine.h | 195 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 146 deletions(-) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 3a5d353..8ca4ad5 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -593,12 +593,14 @@ void dma_async_device_unregister(struct } /** - * dma_async_xor_pgs_to_pg_err - default function for dma devices that + * dma_async_do_xor_err - default function for dma devices that * do not support xor */ -dma_cookie_t dma_async_xor_pgs_to_pg_err(struct dma_chan *chan, - struct page *dest_pg, unsigned int dest_off, struct page *src_pgs, - unsigned int src_cnt, unsigned int src_off, size_t len, u32 *result) +dma_cookie_t dma_async_do_xor_err(struct dma_chan *chan, + union dmaengine_addr dest, unsigned int dest_off, + union dmaengine_addr src, unsigned int src_cnt, + unsigned int src_off, size_t len, u32 *result, + unsigned long flags) { return -ENXIO; } @@ -622,5 +624,5 @@ EXPORT_SYMBOL(dma_async_issue_pending); EXPORT_SYMBOL(dma_async_device_register); EXPORT_SYMBOL(dma_async_device_unregister); EXPORT_SYMBOL(dma_chan_cleanup); -EXPORT_SYMBOL(dma_async_xor_pgs_to_pg_err); +EXPORT_SYMBOL(dma_async_do_xor_err); EXPORT_SYMBOL(dma_async_chan_init); diff --git a/drivers/dma/ioatdma.c b/drivers/dma/ioatdma.c index 415de03..511e8c1 100644 --- a/drivers/dma/ioatdma.c +++ b/drivers/dma/ioatdma.c @@ -213,20 +213,25 @@ static void ioat_dma_free_chan_resources /** * do_ioat_dma_memcpy - actual function that initiates a IOAT DMA transaction - * @ioat_chan: IOAT DMA channel handle - * @dest: DMA destination address - * @src: DMA source address + * @chan: IOAT DMA channel handle + * @dest: DMAENGINE destination address + * @dest_off: Page offset + * @src: DMAENGINE source address + * @src_off: Page offset * @len: transaction length in bytes */ -static dma_cookie_t do_ioat_dma_memcpy(struct ioat_dma_chan *ioat_chan, - dma_addr_t dest, - dma_addr_t src, - size_t len) +static dma_cookie_t do_ioat_dma_memcpy(struct dma_chan *dma_chan, + union dmaengine_addr dest, + unsigned int dest_off, + union dmaengine_addr src, + unsigned int src_off, + size_t len, + unsigned long flags) { struct ioat_desc_sw *first; struct ioat_desc_sw *prev; - struct ioat_desc_sw *new; + struct ioat_desc_sw *new = 0; dma_cookie_t cookie; LIST_HEAD(new_chain); u32 copy; @@ -234,16 +239,47 @@ static dma_cookie_t do_ioat_dma_memcpy(s dma_addr_t orig_src, orig_dst; unsigned int desc_count = 0; unsigned int append = 0; + struct ioat_dma_chan *ioat_chan = to_ioat_chan(dma_chan); - if (!ioat_chan || !dest || !src) + if (!dma_chan || !dest.dma || !src.dma) return -EFAULT; if (!len) return ioat_chan->common.cookie; + switch (flags & (DMA_SRC_BUF | DMA_SRC_PAGE | DMA_SRC_DMA)) { + case DMA_SRC_BUF: + src.dma = pci_map_single(ioat_chan->device->pdev, + src.buf, len, PCI_DMA_TODEVICE); + break; + case DMA_SRC_PAGE: + src.dma = pci_map_page(ioat_chan->device->pdev, + src.pg, src_off, len, PCI_DMA_TODEVICE); + break; + case DMA_SRC_DMA: + break; + default: + return -EFAULT; + } + + switch (flags & (DMA_DEST_BUF | DMA_DEST_PAGE | DMA_DEST_DMA)) { + case DMA_DEST_BUF: + dest.dma = pci_map_single(ioat_chan->device->pdev, + dest.buf, len, PCI_DMA_FROMDEVICE); + break; + case DMA_DEST_PAGE: + dest.dma = pci_map_page(ioat_chan->device->pdev, + dest.pg, dest_off, len, PCI_DMA_FROMDEVICE); + break; + case DMA_DEST_DMA: + break; + default: + return -EFAULT; + } + orig_len = len; - orig_src = src; - orig_dst = dest; + orig_src = src.dma; + orig_dst = dest.dma; first = NULL; prev = NULL; @@ -266,8 +302,8 @@ static dma_cookie_t do_ioat_dma_memcpy(s new->hw->size = copy; new->hw->ctl = 0; - new->hw->src_addr = src; - new->hw->dst_addr = dest; + new->hw->src_addr = src.dma; + new->hw->dst_addr = dest.dma; new->cookie = 0; /* chain together the physical address list for the HW */ @@ -279,8 +315,8 @@ static dma_cookie_t do_ioat_dma_memcpy(s prev = new; len -= copy; - dest += copy; - src += copy; + dest.dma += copy; + src.dma += copy; list_add_tail(&new->node, &new_chain); desc_count++; @@ -321,89 +357,7 @@ static dma_cookie_t do_ioat_dma_memcpy(s } /** - * ioat_dma_memcpy_buf_to_buf - wrapper that takes src & dest bufs - * @chan: IOAT DMA channel handle - * @dest: DMA destination address - * @src: DMA source address - * @len: transaction length in bytes - */ - -static dma_cookie_t ioat_dma_memcpy_buf_to_buf(struct dma_chan *chan, - void *dest, - void *src, - size_t len) -{ - dma_addr_t dest_addr; - dma_addr_t src_addr; - struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan); - - dest_addr = pci_map_single(ioat_chan->device->pdev, - dest, len, PCI_DMA_FROMDEVICE); - src_addr = pci_map_single(ioat_chan->device->pdev, - src, len, PCI_DMA_TODEVICE); - - return do_ioat_dma_memcpy(ioat_chan, dest_addr, src_addr, len); -} - -/** - * ioat_dma_memcpy_buf_to_pg - wrapper, copying from a buf to a page - * @chan: IOAT DMA channel handle - * @page: pointer to the page to copy to - * @offset: offset into that page - * @src: DMA source address - * @len: transaction length in bytes - */ - -static dma_cookie_t ioat_dma_memcpy_buf_to_pg(struct dma_chan *chan, - struct page *page, - unsigned int offset, - void *src, - size_t len) -{ - dma_addr_t dest_addr; - dma_addr_t src_addr; - struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan); - - dest_addr = pci_map_page(ioat_chan->device->pdev, - page, offset, len, PCI_DMA_FROMDEVICE); - src_addr = pci_map_single(ioat_chan->device->pdev, - src, len, PCI_DMA_TODEVICE); - - return do_ioat_dma_memcpy(ioat_chan, dest_addr, src_addr, len); -} - -/** - * ioat_dma_memcpy_pg_to_pg - wrapper, copying between two pages - * @chan: IOAT DMA channel handle - * @dest_pg: pointer to the page to copy to - * @dest_off: offset into that page - * @src_pg: pointer to the page to copy from - * @src_off: offset into that page - * @len: transaction length in bytes. This is guaranteed not to make a copy - * across a page boundary. - */ - -static dma_cookie_t ioat_dma_memcpy_pg_to_pg(struct dma_chan *chan, - struct page *dest_pg, - unsigned int dest_off, - struct page *src_pg, - unsigned int src_off, - size_t len) -{ - dma_addr_t dest_addr; - dma_addr_t src_addr; - struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan); - - dest_addr = pci_map_page(ioat_chan->device->pdev, - dest_pg, dest_off, len, PCI_DMA_FROMDEVICE); - src_addr = pci_map_page(ioat_chan->device->pdev, - src_pg, src_off, len, PCI_DMA_TODEVICE); - - return do_ioat_dma_memcpy(ioat_chan, dest_addr, src_addr, len); -} - -/** - * ioat_dma_memcpy_issue_pending - push potentially unrecognized appended descriptors to hw + * ioat_dma_memcpy_issue_pending - push potentially unrecognoized appended descriptors to hw * @chan: DMA channel handle */ @@ -626,24 +580,24 @@ #define IOAT_TEST_SIZE 2000 static int ioat_self_test(struct ioat_device *device) { int i; - u8 *src; - u8 *dest; + union dmaengine_addr src; + union dmaengine_addr dest; struct dma_chan *dma_chan; dma_cookie_t cookie; int err = 0; - src = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, SLAB_KERNEL); - if (!src) + src.buf = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, SLAB_KERNEL); + if (!src.buf) return -ENOMEM; - dest = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, SLAB_KERNEL); - if (!dest) { - kfree(src); + dest.buf = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, SLAB_KERNEL); + if (!dest.buf) { + kfree(src.buf); return -ENOMEM; } /* Fill in src buffer */ for (i = 0; i < IOAT_TEST_SIZE; i++) - src[i] = (u8)i; + ((u8 *) src.buf)[i] = (u8)i; /* Start copy, using first DMA channel */ dma_chan = container_of(device->common.channels.next, @@ -654,7 +608,8 @@ static int ioat_self_test(struct ioat_de goto out; } - cookie = ioat_dma_memcpy_buf_to_buf(dma_chan, dest, src, IOAT_TEST_SIZE); + cookie = do_ioat_dma_memcpy(dma_chan, dest, 0, src, 0, + IOAT_TEST_SIZE, DMA_SRC_BUF | DMA_DEST_BUF); ioat_dma_memcpy_issue_pending(dma_chan); msleep(1); @@ -663,7 +618,7 @@ static int ioat_self_test(struct ioat_de err = -ENODEV; goto free_resources; } - if (memcmp(src, dest, IOAT_TEST_SIZE)) { + if (memcmp(src.buf, dest.buf, IOAT_TEST_SIZE)) { printk(KERN_ERR "ioatdma: Self-test copy failed compare, disabling\n"); err = -ENODEV; goto free_resources; @@ -672,11 +627,17 @@ static int ioat_self_test(struct ioat_de free_resources: ioat_dma_free_chan_resources(dma_chan); out: - kfree(src); - kfree(dest); + kfree(src.buf); + kfree(dest.buf); return err; } +extern dma_cookie_t dma_async_do_xor_err(struct dma_chan *chan, + union dmaengine_addr dest, unsigned int dest_off, + union dmaengine_addr src, unsigned int src_cnt, + unsigned int src_off, size_t len, u32 *result, + unsigned long flags); + static int __devinit ioat_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { @@ -752,13 +713,11 @@ #endif device->common.device_alloc_chan_resources = ioat_dma_alloc_chan_resources; device->common.device_free_chan_resources = ioat_dma_free_chan_resources; - device->common.device_memcpy_buf_to_buf = ioat_dma_memcpy_buf_to_buf; - device->common.device_memcpy_buf_to_pg = ioat_dma_memcpy_buf_to_pg; - device->common.device_memcpy_pg_to_pg = ioat_dma_memcpy_pg_to_pg; device->common.device_operation_complete = ioat_dma_is_complete; - device->common.device_xor_pgs_to_pg = dma_async_xor_pgs_to_pg_err; device->common.device_issue_pending = ioat_dma_memcpy_issue_pending; device->common.capabilities = DMA_MEMCPY; + device->common.device_do_dma_memcpy = do_ioat_dma_memcpy; + device->common.device_do_dma_xor = dma_async_do_xor_err; printk(KERN_INFO "Intel(R) I/OAT DMA Engine found, %d channels\n", device->common.chancnt); diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h index dad909a..7174ad5 100644 --- a/include/linux/dmaengine.h +++ b/include/linux/dmaengine.h @@ -86,6 +86,32 @@ enum dma_capabilities { }; /** + * union dmaengine_addr - Private address types + * -passing a dma address to the hardware engine + * implies skipping the dma_map* operation + */ +union dmaengine_addr { + void *buf; + struct page *pg; + struct page **pgs; + dma_addr_t dma; + dma_addr_t *dma_list; +}; + +enum dmaengine_flags { + DMA_SRC_BUF = 0x1, + DMA_SRC_PAGE = 0x2, + DMA_SRC_PAGES = 0x4, + DMA_SRC_DMA = 0x8, + DMA_SRC_DMA_LIST = 0x10, + DMA_DEST_BUF = 0x20, + DMA_DEST_PAGE = 0x40, + DMA_DEST_PAGES = 0x80, + DMA_DEST_DMA = 0x100, + DMA_DEST_DMA_LIST = 0x200, +}; + +/** * struct dma_chan_percpu - the per-CPU part of struct dma_chan * @refcount: local_t used for open-coded "bigref" counting * @memcpy_count: transaction counter @@ -230,11 +256,10 @@ struct dma_chan_client_ref { * @device_alloc_chan_resources: allocate resources and return the * number of allocated descriptors * @device_free_chan_resources: release DMA channel's resources - * @device_memcpy_buf_to_buf: memcpy buf pointer to buf pointer - * @device_memcpy_buf_to_pg: memcpy buf pointer to struct page - * @device_memcpy_pg_to_pg: memcpy struct page/offset to struct page/offset * @device_memcpy_complete: poll the status of an IOAT DMA transaction - * @device_memcpy_issue_pending: push appended descriptors to hardware + * @device_issue_pending: push appended descriptors to hardware + * @device_do_dma_memcpy: perform memcpy with a dma engine + * @device_do_dma_xor: perform block xor with a dma engine */ struct dma_device { @@ -250,18 +275,15 @@ struct dma_device { int (*device_alloc_chan_resources)(struct dma_chan *chan); void (*device_free_chan_resources)(struct dma_chan *chan); - dma_cookie_t (*device_memcpy_buf_to_buf)(struct dma_chan *chan, - void *dest, void *src, size_t len); - dma_cookie_t (*device_memcpy_buf_to_pg)(struct dma_chan *chan, - struct page *page, unsigned int offset, void *kdata, - size_t len); - dma_cookie_t (*device_memcpy_pg_to_pg)(struct dma_chan *chan, - struct page *dest_pg, unsigned int dest_off, - struct page *src_pg, unsigned int src_off, size_t len); - dma_cookie_t (*device_xor_pgs_to_pg)(struct dma_chan *chan, - struct page *dest_pg, unsigned int dest_off, - struct page **src_pgs, unsigned int src_cnt, - unsigned int src_off, size_t len, u32 *result); + dma_cookie_t (*device_do_dma_memcpy)(struct dma_chan *chan, + union dmaengine_addr dest, unsigned int dest_off, + union dmaengine_addr src, unsigned int src_off, + size_t len, unsigned long flags); + dma_cookie_t (*device_do_dma_xor)(struct dma_chan *chan, + union dmaengine_addr dest, unsigned int dest_off, + union dmaengine_addr src, unsigned int src_cnt, + unsigned int src_off, size_t len, u32 *result, + unsigned long flags); enum dma_status (*device_operation_complete)(struct dma_chan *chan, dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used); @@ -275,10 +297,6 @@ void dma_async_client_unregister(struct int dma_async_client_chan_request(struct dma_client *client, unsigned int number, unsigned int mask); void dma_async_chan_init(struct dma_chan *chan, struct dma_device *device); -dma_cookie_t dma_async_xor_pgs_to_pg_err(struct dma_chan *chan, - struct page *dest_pg, unsigned int dest_off, struct page *src_pgs, - unsigned int src_cnt, unsigned int src_off, size_t len, u32 *result); - /** * dma_async_memcpy_buf_to_buf - offloaded copy between virtual addresses @@ -295,12 +313,16 @@ dma_cookie_t dma_async_xor_pgs_to_pg_err static inline dma_cookie_t dma_async_memcpy_buf_to_buf(struct dma_chan *chan, void *dest, void *src, size_t len) { + unsigned long flags = DMA_DEST_BUF | DMA_SRC_BUF; + union dmaengine_addr dest_addr = { .buf = dest }; + union dmaengine_addr src_addr = { .buf = src }; int cpu = get_cpu(); per_cpu_ptr(chan->local, cpu)->bytes_transferred += len; per_cpu_ptr(chan->local, cpu)->memcpy_count++; put_cpu(); - return chan->device->device_memcpy_buf_to_buf(chan, dest, src, len); + return chan->device->device_do_dma_memcpy(chan, dest_addr, 0, + src_addr, 0, len, flags); } /** @@ -319,13 +341,16 @@ static inline dma_cookie_t dma_async_mem static inline dma_cookie_t dma_async_memcpy_buf_to_pg(struct dma_chan *chan, struct page *page, unsigned int offset, void *kdata, size_t len) { + unsigned long flags = DMA_DEST_PAGE | DMA_SRC_BUF; + union dmaengine_addr dest_addr = { .pg = page }; + union dmaengine_addr src_addr = { .buf = kdata }; int cpu = get_cpu(); per_cpu_ptr(chan->local, cpu)->bytes_transferred += len; per_cpu_ptr(chan->local, cpu)->memcpy_count++; put_cpu(); - return chan->device->device_memcpy_buf_to_pg(chan, page, offset, - kdata, len); + return chan->device->device_do_dma_memcpy(chan, dest_addr, offset, + src_addr, 0, len, flags); } /** @@ -346,13 +371,101 @@ static inline dma_cookie_t dma_async_mem struct page *dest_pg, unsigned int dest_off, struct page *src_pg, unsigned int src_off, size_t len) { + unsigned long flags = DMA_DEST_PAGE | DMA_SRC_PAGE; + union dmaengine_addr dest_addr = { .pg = dest_pg }; + union dmaengine_addr src_addr = { .pg = src_pg }; + int cpu = get_cpu(); + per_cpu_ptr(chan->local, cpu)->bytes_transferred += len; + per_cpu_ptr(chan->local, cpu)->memcpy_count++; + put_cpu(); + + return chan->device->device_do_dma_memcpy(chan, dest_addr, dest_off, + src_addr, src_off, len, flags); +} + +/** + * dma_async_memcpy_dma_to_dma - offloaded copy from dma to dma + * @chan: DMA channel to offload copy to + * @dest: destination already mapped and consistent + * @src: source already mapped and consistent + * @len: length + * + * Both @dest_page/@dest_off and @src_page/@src_off must be mappable to a bus + * address according to the DMA mapping API rules for streaming mappings. + * Both @dest_page/@dest_off and @src_page/@src_off must stay memory resident + * (kernel memory or locked user space pages) + */ +static inline dma_cookie_t dma_async_memcpy_dma_to_dma(struct dma_chan *chan, + dma_addr_t dest, dma_addr_t src, size_t len) +{ + unsigned long flags = DMA_DEST_DMA | DMA_SRC_DMA; + union dmaengine_addr dest_addr = { .dma = dest }; + union dmaengine_addr src_addr = { .dma = src }; + int cpu = get_cpu(); + per_cpu_ptr(chan->local, cpu)->bytes_transferred += len; + per_cpu_ptr(chan->local, cpu)->memcpy_count++; + put_cpu(); + + return chan->device->device_do_dma_memcpy(chan, dest_addr, 0, + src_addr, 0, len, flags); +} + +/** + * dma_async_memcpy_pg_to_dma - offloaded copy from page to dma + * @chan: DMA channel to offload copy to + * @dest: destination already mapped and consistent + * @src_pg: source page + * @src_off: offset in page to copy from + * @len: length + * + * Both @dest_page/@dest_off and @src_page/@src_off must be mappable to a bus + * address according to the DMA mapping API rules for streaming mappings. + * Both @dest_page/@dest_off and @src_page/@src_off must stay memory resident + * (kernel memory or locked user space pages) + */ +static inline dma_cookie_t dma_async_memcpy_pg_to_dma(struct dma_chan *chan, + dma_addr_t dest, struct page *src_pg, + unsigned int src_off, size_t len) +{ + unsigned long flags = DMA_DEST_DMA | DMA_SRC_PAGE; + union dmaengine_addr dest_addr = { .dma = dest }; + union dmaengine_addr src_addr = { .pg = src_pg }; int cpu = get_cpu(); per_cpu_ptr(chan->local, cpu)->bytes_transferred += len; per_cpu_ptr(chan->local, cpu)->memcpy_count++; put_cpu(); - return chan->device->device_memcpy_pg_to_pg(chan, dest_pg, dest_off, - src_pg, src_off, len); + return chan->device->device_do_dma_memcpy(chan, dest_addr, 0, + src_addr, src_off, len, flags); +} + +/** + * dma_async_memcpy_dma_to_pg - offloaded copy from dma to page + * @chan: DMA channel to offload copy to + * @dest_page: destination page + * @dest_off: offset in page to copy to + * @src: source already mapped and consistent + * @len: length + * + * Both @dest_page/@dest_off and @src_page/@src_off must be mappable to a bus + * address according to the DMA mapping API rules for streaming mappings. + * Both @dest_page/@dest_off and @src_page/@src_off must stay memory resident + * (kernel memory or locked user space pages) + */ +static inline dma_cookie_t dma_async_memcpy_dma_to_pg(struct dma_chan *chan, + struct page *dest_pg, unsigned int dest_off, dma_addr_t src, + size_t len) +{ + unsigned long flags = DMA_DEST_PAGE | DMA_SRC_DMA; + union dmaengine_addr dest_addr = { .pg = dest_pg }; + union dmaengine_addr src_addr = { .dma = src }; + int cpu = get_cpu(); + per_cpu_ptr(chan->local, cpu)->bytes_transferred += len; + per_cpu_ptr(chan->local, cpu)->memcpy_count++; + put_cpu(); + + return chan->device->device_do_dma_memcpy(chan, dest_addr, dest_off, + src_addr, 0, len, flags); } /** @@ -375,15 +488,43 @@ static inline dma_cookie_t dma_async_xor struct page *dest_pg, unsigned int dest_off, struct page **src_pgs, unsigned int src_cnt, unsigned int src_off, size_t len, u32 *result) { + unsigned long flags = DMA_DEST_PAGE | DMA_SRC_PAGES; + union dmaengine_addr dest_addr = { .pg = dest_pg }; + union dmaengine_addr src_addr = { .pgs = src_pgs }; int cpu = get_cpu(); per_cpu_ptr(chan->local, cpu)->bytes_xor += len * src_cnt; per_cpu_ptr(chan->local, cpu)->xor_count++; put_cpu(); - return chan->device->device_xor_pgs_to_pg(chan, dest_pg, dest_off, - src_pgs, src_cnt, src_off, len, result); + return chan->device->device_do_dma_xor(chan, dest_addr, dest_off, + src_addr, src_cnt, src_off, len, result, flags); } +/** + * dma_async_xor_dma_list_to_dma - offloaded xor of dma blocks + * @chan: DMA channel to offload xor to + * @dest: destination already mapped and consistent + * @src_list: array of sources already mapped and consistent + * @src_cnt: number of sources + * @len: length + * @result: optionally returns whether the xor resulted + * in a zero sum + */ +static inline dma_cookie_t dma_async_xor_dma_list_to_dma(struct dma_chan *chan, + dma_addr_t dest, dma_addr_t *src_list, unsigned int src_cnt, + size_t len, u32 *result) +{ + unsigned long flags = DMA_DEST_DMA | DMA_SRC_DMA_LIST; + union dmaengine_addr dest_addr = { .dma = dest }; + union dmaengine_addr src_addr = { .dma_list = src_list }; + int cpu = get_cpu(); + per_cpu_ptr(chan->local, cpu)->bytes_xor += len * src_cnt; + per_cpu_ptr(chan->local, cpu)->xor_count++; + put_cpu(); + + return chan->device->device_do_dma_xor(chan, dest_addr, 0, + src_addr, src_cnt, 0, len, result, flags); +} /** * dma_async_issue_pending - flush pending copies to HW ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/4] dmaengine: expose per channel dma mapping characteristics to clients 2006-07-27 0:07 [PATCH 1/4] dmaengine: enable mutliple clients and operations Dan Williams 2006-07-27 0:07 ` [PATCH 2/4] dmaengine: reduce backend address permutations Dan Williams @ 2006-07-27 0:07 ` Dan Williams 2006-07-27 0:07 ` [PATCH 4/4] dmaengine: add memset as an asynchronous dma operation Dan Williams 2 siblings, 0 replies; 4+ messages in thread From: Dan Williams @ 2006-07-27 0:07 UTC (permalink / raw) To: linux-kernel; +Cc: neilb, galak, christopher.leech, alan, dan.j.williams From: Dan Williams <dan.j.williams@intel.com> Allow a client to ensure that the dma channel it has selected can dma to the specified buffer or page address. Also allow the client to pre-map address ranges to be passed to the operations API. Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- drivers/dma/ioatdma.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/dmaengine.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 0 deletions(-) diff --git a/drivers/dma/ioatdma.c b/drivers/dma/ioatdma.c index 511e8c1..c7bae96 100644 --- a/drivers/dma/ioatdma.c +++ b/drivers/dma/ioatdma.c @@ -638,6 +638,37 @@ extern dma_cookie_t dma_async_do_xor_err unsigned int src_off, size_t len, u32 *result, unsigned long flags); +static dma_addr_t ioat_map_page(struct dma_chan *chan, struct page *page, + unsigned long offset, size_t size, + int direction) +{ + struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan); + return pci_map_page(ioat_chan->device->pdev, page, offset, size, + direction); +} + +static dma_addr_t ioat_map_single(struct dma_chan *chan, void *cpu_addr, + size_t size, int direction) +{ + struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan); + return pci_map_single(ioat_chan->device->pdev, cpu_addr, size, + direction); +} + +static void ioat_unmap_page(struct dma_chan *chan, dma_addr_t handle, + size_t size, int direction) +{ + struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan); + pci_unmap_page(ioat_chan->device->pdev, handle, size, direction); +} + +static void ioat_unmap_single(struct dma_chan *chan, dma_addr_t handle, + size_t size, int direction) +{ + struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan); + pci_unmap_single(ioat_chan->device->pdev, handle, size, direction); +} + static int __devinit ioat_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { @@ -718,6 +749,10 @@ #endif device->common.capabilities = DMA_MEMCPY; device->common.device_do_dma_memcpy = do_ioat_dma_memcpy; device->common.device_do_dma_xor = dma_async_do_xor_err; + device->common.map_page = ioat_map_page; + device->common.map_single = ioat_map_single; + device->common.unmap_page = ioat_unmap_page; + device->common.unmap_single = ioat_unmap_single; printk(KERN_INFO "Intel(R) I/OAT DMA Engine found, %d channels\n", device->common.chancnt); diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h index 7174ad5..991c438 100644 --- a/include/linux/dmaengine.h +++ b/include/linux/dmaengine.h @@ -287,6 +287,15 @@ struct dma_device { enum dma_status (*device_operation_complete)(struct dma_chan *chan, dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used); + dma_addr_t (*map_page)(struct dma_chan *chan, struct page *page, + unsigned long offset, size_t size, + int direction); + dma_addr_t (*map_single)(struct dma_chan *chan, void *cpu_addr, + size_t size, int direction); + void (*unmap_page)(struct dma_chan *chan, dma_addr_t handle, + size_t size, int direction); + void (*unmap_single)(struct dma_chan *chan, dma_addr_t handle, + size_t size, int direction); void (*device_issue_pending)(struct dma_chan *chan); }; @@ -596,6 +605,31 @@ static inline enum dma_status dma_async_ } +static inline dma_addr_t dma_async_map_page(struct dma_chan *chan, + struct page *page, unsigned long offset, size_t size, + int direction) +{ + return chan->device->map_page(chan, page, offset, size, direction); +} + +static inline dma_addr_t dma_async_map_single(struct dma_chan *chan, + void *cpu_addr, size_t size, int direction) +{ + return chan->device->map_single(chan, cpu_addr, size, direction); +} + +static inline void dma_async_unmap_page(struct dma_chan *chan, + dma_addr_t handle, size_t size, int direction) +{ + chan->device->unmap_page(chan, handle, size, direction); +} + +static inline void dma_async_unmap_single(struct dma_chan *chan, + dma_addr_t handle, size_t size, int direction) +{ + chan->device->unmap_single(chan, handle, size, direction); +} + /* --- DMA device --- */ int dma_async_device_register(struct dma_device *device); ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 4/4] dmaengine: add memset as an asynchronous dma operation 2006-07-27 0:07 [PATCH 1/4] dmaengine: enable mutliple clients and operations Dan Williams 2006-07-27 0:07 ` [PATCH 2/4] dmaengine: reduce backend address permutations Dan Williams 2006-07-27 0:07 ` [PATCH 3/4] dmaengine: expose per channel dma mapping characteristics to clients Dan Williams @ 2006-07-27 0:07 ` Dan Williams 2 siblings, 0 replies; 4+ messages in thread From: Dan Williams @ 2006-07-27 0:07 UTC (permalink / raw) To: linux-kernel; +Cc: neilb, galak, christopher.leech, alan, dan.j.williams From: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- drivers/dma/dmaengine.c | 12 ++++++++ drivers/dma/ioatdma.c | 5 +++ include/linux/dmaengine.h | 68 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 0 deletions(-) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 8ca4ad5..ac27fd3 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -605,6 +605,17 @@ dma_cookie_t dma_async_do_xor_err(struct return -ENXIO; } +/** + * dma_async_do_memset_err - default function for dma devices that + * do not support memset + */ +dma_cookie_t dma_async_do_memset_err(struct dma_chan *chan, + union dmaengine_addr dest, unsigned int dest_off, + int val, size_t len, unsigned long flags) +{ + return -ENXIO; +} + static int __init dma_bus_init(void) { mutex_init(&dma_list_mutex); @@ -625,4 +636,5 @@ EXPORT_SYMBOL(dma_async_device_register) EXPORT_SYMBOL(dma_async_device_unregister); EXPORT_SYMBOL(dma_chan_cleanup); EXPORT_SYMBOL(dma_async_do_xor_err); +EXPORT_SYMBOL(dma_async_do_memset_err); EXPORT_SYMBOL(dma_async_chan_init); diff --git a/drivers/dma/ioatdma.c b/drivers/dma/ioatdma.c index c7bae96..5133e3d 100644 --- a/drivers/dma/ioatdma.c +++ b/drivers/dma/ioatdma.c @@ -638,6 +638,10 @@ extern dma_cookie_t dma_async_do_xor_err unsigned int src_off, size_t len, u32 *result, unsigned long flags); +extern dma_cookie_t dma_async_do_memset_err(struct dma_chan *chan, + union dmaengine_addr dest, unsigned int dest_off, + int val, size_t size, unsigned long flags); + static dma_addr_t ioat_map_page(struct dma_chan *chan, struct page *page, unsigned long offset, size_t size, int direction) @@ -749,6 +753,7 @@ #endif device->common.capabilities = DMA_MEMCPY; device->common.device_do_dma_memcpy = do_ioat_dma_memcpy; device->common.device_do_dma_xor = dma_async_do_xor_err; + device->common.device_do_dma_memset = dma_async_do_memset_err; device->common.map_page = ioat_map_page; device->common.map_single = ioat_map_single; device->common.unmap_page = ioat_unmap_page; diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h index 991c438..e75d706 100644 --- a/include/linux/dmaengine.h +++ b/include/linux/dmaengine.h @@ -260,6 +260,7 @@ struct dma_chan_client_ref { * @device_issue_pending: push appended descriptors to hardware * @device_do_dma_memcpy: perform memcpy with a dma engine * @device_do_dma_xor: perform block xor with a dma engine + * @device_do_dma_memset: perform block fill with a dma engine */ struct dma_device { @@ -284,6 +285,9 @@ struct dma_device { union dmaengine_addr src, unsigned int src_cnt, unsigned int src_off, size_t len, u32 *result, unsigned long flags); + dma_cookie_t (*device_do_dma_memset)(struct dma_chan *chan, + union dmaengine_addr dest, unsigned int dest_off, + int value, size_t len, unsigned long flags); enum dma_status (*device_operation_complete)(struct dma_chan *chan, dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used); @@ -478,6 +482,70 @@ static inline dma_cookie_t dma_async_mem } /** + * dma_async_memset_buf - offloaded memset + * @chan: DMA channel to offload memset to + * @buf: destination buffer + * @val: value to initialize the buffer + * @len: length + */ +static inline dma_cookie_t dma_async_memset_buf(struct dma_chan *chan, + void *buf, int val, size_t len) +{ + unsigned long flags = DMA_DEST_BUF; + union dmaengine_addr dest_addr = { .buf = buf }; + int cpu = get_cpu(); + per_cpu_ptr(chan->local, cpu)->bytes_transferred += len; + per_cpu_ptr(chan->local, cpu)->memcpy_count++; + put_cpu(); + + return chan->device->device_do_dma_memset(chan, dest_addr, 0, val, + len, flags); +} + +/** + * dma_async_memset_page - offloaded memset + * @chan: DMA channel to offload memset to + * @page: destination page + * @offset: offset into the destination + * @val: value to initialize the buffer + * @len: length + */ +static inline dma_cookie_t dma_async_memset_page(struct dma_chan *chan, + struct page *page, unsigned int offset, int val, size_t len) +{ + unsigned long flags = DMA_DEST_PAGE; + union dmaengine_addr dest_addr = { .pg = page }; + int cpu = get_cpu(); + per_cpu_ptr(chan->local, cpu)->bytes_transferred += len; + per_cpu_ptr(chan->local, cpu)->memcpy_count++; + put_cpu(); + + return chan->device->device_do_dma_memset(chan, dest_addr, offset, val, + len, flags); +} + +/** + * dma_async_memset_dma - offloaded memset + * @chan: DMA channel to offload memset to + * @page: destination dma address + * @val: value to initialize the buffer + * @len: length + */ +static inline dma_cookie_t dma_async_memset_dma(struct dma_chan *chan, + dma_addr_t dma, int val, size_t len) +{ + unsigned long flags = DMA_DEST_DMA; + union dmaengine_addr dest_addr = { .dma = dma }; + int cpu = get_cpu(); + per_cpu_ptr(chan->local, cpu)->bytes_transferred += len; + per_cpu_ptr(chan->local, cpu)->memcpy_count++; + put_cpu(); + + return chan->device->device_do_dma_memset(chan, dest_addr, 0, val, + len, flags); +} + +/** * dma_async_xor_pgs_to_pg - offloaded xor from pages to page * @chan: DMA channel to offload xor to * @dest_page: destination page ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-07-27 0:10 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-07-27 0:07 [PATCH 1/4] dmaengine: enable mutliple clients and operations Dan Williams 2006-07-27 0:07 ` [PATCH 2/4] dmaengine: reduce backend address permutations Dan Williams 2006-07-27 0:07 ` [PATCH 3/4] dmaengine: expose per channel dma mapping characteristics to clients Dan Williams 2006-07-27 0:07 ` [PATCH 4/4] dmaengine: add memset as an asynchronous dma operation Dan Williams
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox