2 * Copyright(c) 2004 - 2006 Intel Corporation. All rights reserved.
3 * Portions based on net/core/datagram.c and copyrighted by their authors.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59
17 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * The full GNU General Public License is included in this distribution in the
20 * file called COPYING.
24 * This code allows the net stack to make use of a DMA engine for
25 * skb to iovec copies.
28 #include <linux/dmaengine.h>
29 #include <linux/socket.h>
30 #include <linux/rtnetlink.h> /* for BUG_TRAP */
33 #define NET_DMA_DEFAULT_COPYBREAK 4096
35 int sysctl_tcp_dma_copybreak
= NET_DMA_DEFAULT_COPYBREAK
;
38 * dma_skb_copy_datagram_iovec - Copy a datagram to an iovec.
39 * @skb - buffer to copy
40 * @offset - offset in the buffer to start copying from
41 * @iovec - io vector to copy to
42 * @len - amount of data to copy from buffer to iovec
43 * @pinned_list - locked iovec buffer data
45 * Note: the iovec is modified during the copy.
47 int dma_skb_copy_datagram_iovec(struct dma_chan
*chan
,
48 struct sk_buff
*skb
, int offset
, struct iovec
*to
,
49 size_t len
, struct dma_pinned_list
*pinned_list
)
51 int start
= skb_headlen(skb
);
52 int i
, copy
= start
- offset
;
53 dma_cookie_t cookie
= 0;
59 cookie
= dma_memcpy_to_iovec(chan
, to
, pinned_list
,
60 skb
->data
+ offset
, copy
);
69 /* Copy paged appendix. Hmm... why does this look so complicated? */
70 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
73 BUG_TRAP(start
<= offset
+ len
);
75 end
= start
+ skb_shinfo(skb
)->frags
[i
].size
;
77 if ((copy
= end
- offset
) > 0) {
78 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
79 struct page
*page
= frag
->page
;
84 cookie
= dma_memcpy_pg_to_iovec(chan
, to
, pinned_list
, page
,
85 frag
->page_offset
+ offset
- start
, copy
);
96 if (skb_shinfo(skb
)->frag_list
) {
97 struct sk_buff
*list
= skb_shinfo(skb
)->frag_list
;
99 for (; list
; list
= list
->next
) {
102 BUG_TRAP(start
<= offset
+ len
);
104 end
= start
+ list
->len
;
109 cookie
= dma_skb_copy_datagram_iovec(chan
, list
,
110 offset
- start
, to
, copy
,
125 skb
->dma_cookie
= cookie
;