1 /* skb_dma_map.c: DMA mapping helpers for socket buffers.
3 * Copyright (C) David S. Miller <davem@davemloft.net>
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
);
18 map
= dma_map_single(dev
, skb
->data
,
19 skb_headlen(skb
), dir
);
20 if (dma_mapping_error(dev
, 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
,
29 if (dma_mapping_error(dev
, map
))
31 sp
->dma_maps
[i
] = map
;
38 skb_frag_t
*fp
= &sp
->frags
[i
];
40 dma_unmap_page(dev
, sp
->dma_maps
[i
],
43 dma_unmap_single(dev
, sp
->dma_head
,
44 skb_headlen(skb
), dir
);
48 EXPORT_SYMBOL(skb_dma_map
);
50 void skb_dma_unmap(struct device
*dev
, struct sk_buff
*skb
,
51 enum dma_data_direction dir
)
53 struct skb_shared_info
*sp
= skb_shinfo(skb
);
56 dma_unmap_single(dev
, sp
->dma_head
,
57 skb_headlen(skb
), dir
);
58 for (i
= 0; i
< sp
->nr_frags
; i
++) {
59 skb_frag_t
*fp
= &sp
->frags
[i
];
61 dma_unmap_page(dev
, sp
->dma_maps
[i
],
65 EXPORT_SYMBOL(skb_dma_unmap
);