dm raid1: separate region_hash interface part1
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / core / skb_dma_map.c
blob86234923a3b7600571d434e884fed063a318c718
1 /* skb_dma_map.c: DMA mapping helpers for socket buffers.
3 * Copyright (C) David S. Miller <davem@davemloft.net>
4 */
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/dma-mapping.h>
9 #include <linux/skbuff.h>
11 int skb_dma_map(struct device *dev, struct sk_buff *skb,
12 enum dma_data_direction dir)
14 struct skb_shared_info *sp = skb_shinfo(skb);
15 dma_addr_t map;
16 int i;
18 map = dma_map_single(dev, skb->data,
19 skb_headlen(skb), dir);
20 if (dma_mapping_error(dev, map))
21 goto out_err;
23 sp->dma_maps[0] = map;
24 for (i = 0; i < sp->nr_frags; i++) {
25 skb_frag_t *fp = &sp->frags[i];
27 map = dma_map_page(dev, fp->page, fp->page_offset,
28 fp->size, dir);
29 if (dma_mapping_error(dev, map))
30 goto unwind;
31 sp->dma_maps[i + 1] = map;
33 sp->num_dma_maps = i + 1;
35 return 0;
37 unwind:
38 while (--i >= 0) {
39 skb_frag_t *fp = &sp->frags[i];
41 dma_unmap_page(dev, sp->dma_maps[i + 1],
42 fp->size, dir);
44 dma_unmap_single(dev, sp->dma_maps[0],
45 skb_headlen(skb), dir);
46 out_err:
47 return -ENOMEM;
49 EXPORT_SYMBOL(skb_dma_map);
51 void skb_dma_unmap(struct device *dev, struct sk_buff *skb,
52 enum dma_data_direction dir)
54 struct skb_shared_info *sp = skb_shinfo(skb);
55 int i;
57 dma_unmap_single(dev, sp->dma_maps[0],
58 skb_headlen(skb), dir);
59 for (i = 0; i < sp->nr_frags; i++) {
60 skb_frag_t *fp = &sp->frags[i];
62 dma_unmap_page(dev, sp->dma_maps[i + 1],
63 fp->size, dir);
66 EXPORT_SYMBOL(skb_dma_unmap);