Blame view

net/core/user_dma.c 3.29 KB
de5506e15   Chris Leech   [I/OAT]: Utility ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  /*
   * Copyright(c) 2004 - 2006 Intel Corporation. All rights reserved.
   * Portions based on net/core/datagram.c and copyrighted by their authors.
   *
   * This program is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License as published by the Free
   * Software Foundation; either version 2 of the License, or (at your option)
   * any later version.
   *
   * This program is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   * more details.
   *
   * You should have received a copy of the GNU General Public License along with
   * this program; if not, write to the Free Software Foundation, Inc., 59
   * Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   *
   * The full GNU General Public License is included in this distribution in the
   * file called COPYING.
   */
  
  /*
   * This code allows the net stack to make use of a DMA engine for
   * skb to iovec copies.
   */
  
  #include <linux/dmaengine.h>
  #include <linux/socket.h>
bc3b2d7fb   Paul Gortmaker   net: Add export.h...
30
  #include <linux/export.h>
de5506e15   Chris Leech   [I/OAT]: Utility ...
31
  #include <net/tcp.h>
64d2f0855   Adrian Bunk   [I/OAT]: net/core...
32
  #include <net/netdma.h>
de5506e15   Chris Leech   [I/OAT]: Utility ...
33

959378258   Chris Leech   [I/OAT]: Add a sy...
34
35
36
  #define NET_DMA_DEFAULT_COPYBREAK 4096
  
  int sysctl_tcp_dma_copybreak = NET_DMA_DEFAULT_COPYBREAK;
16a37acaa   Maciej Sosnowski   I/OAT: tcp_dma_co...
37
  EXPORT_SYMBOL(sysctl_tcp_dma_copybreak);
959378258   Chris Leech   [I/OAT]: Add a sy...
38

de5506e15   Chris Leech   [I/OAT]: Utility ...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  /**
   *	dma_skb_copy_datagram_iovec - Copy a datagram to an iovec.
   *	@skb - buffer to copy
   *	@offset - offset in the buffer to start copying from
   *	@iovec - io vector to copy to
   *	@len - amount of data to copy from buffer to iovec
   *	@pinned_list - locked iovec buffer data
   *
   *	Note: the iovec is modified during the copy.
   */
  int dma_skb_copy_datagram_iovec(struct dma_chan *chan,
  			struct sk_buff *skb, int offset, struct iovec *to,
  			size_t len, struct dma_pinned_list *pinned_list)
  {
1a028e507   David S. Miller   [NET]: Revert sk_...
53
54
  	int start = skb_headlen(skb);
  	int i, copy = start - offset;
285e42802   David S. Miller   net/core/user_dma...
55
  	struct sk_buff *frag_iter;
de5506e15   Chris Leech   [I/OAT]: Utility ...
56
57
58
59
60
61
62
  	dma_cookie_t cookie = 0;
  
  	/* Copy header. */
  	if (copy > 0) {
  		if (copy > len)
  			copy = len;
  		cookie = dma_memcpy_to_iovec(chan, to, pinned_list,
4ec93edb1   YOSHIFUJI Hideaki   [NET] CORE: Fix w...
63
  					    skb->data + offset, copy);
de5506e15   Chris Leech   [I/OAT]: Utility ...
64
65
66
67
68
69
70
71
72
73
  		if (cookie < 0)
  			goto fault;
  		len -= copy;
  		if (len == 0)
  			goto end;
  		offset += copy;
  	}
  
  	/* Copy paged appendix. Hmm... why does this look so complicated? */
  	for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1a028e507   David S. Miller   [NET]: Revert sk_...
74
  		int end;
9e903e085   Eric Dumazet   net: add skb frag...
75
  		const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
de5506e15   Chris Leech   [I/OAT]: Utility ...
76

547b792ca   Ilpo Järvinen   net: convert BUG_...
77
  		WARN_ON(start > offset + len);
1a028e507   David S. Miller   [NET]: Revert sk_...
78

9e903e085   Eric Dumazet   net: add skb frag...
79
  		end = start + skb_frag_size(frag);
de5506e15   Chris Leech   [I/OAT]: Utility ...
80
  		copy = end - offset;
7557af251   Brice Goglin   net_dma: remove d...
81
  		if (copy > 0) {
ea2ab6937   Ian Campbell   net: convert core...
82
  			struct page *page = skb_frag_page(frag);
de5506e15   Chris Leech   [I/OAT]: Utility ...
83
84
85
  
  			if (copy > len)
  				copy = len;
1a028e507   David S. Miller   [NET]: Revert sk_...
86
87
  			cookie = dma_memcpy_pg_to_iovec(chan, to, pinned_list, page,
  					frag->page_offset + offset - start, copy);
de5506e15   Chris Leech   [I/OAT]: Utility ...
88
89
90
91
92
93
94
  			if (cookie < 0)
  				goto fault;
  			len -= copy;
  			if (len == 0)
  				goto end;
  			offset += copy;
  		}
1a028e507   David S. Miller   [NET]: Revert sk_...
95
  		start = end;
de5506e15   Chris Leech   [I/OAT]: Utility ...
96
  	}
285e42802   David S. Miller   net/core/user_dma...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  	skb_walk_frags(skb, frag_iter) {
  		int end;
  
  		WARN_ON(start > offset + len);
  
  		end = start + frag_iter->len;
  		copy = end - offset;
  		if (copy > 0) {
  			if (copy > len)
  				copy = len;
  			cookie = dma_skb_copy_datagram_iovec(chan, frag_iter,
  							     offset - start,
  							     to, copy,
  							     pinned_list);
  			if (cookie < 0)
  				goto fault;
  			len -= copy;
  			if (len == 0)
  				goto end;
  			offset += copy;
de5506e15   Chris Leech   [I/OAT]: Utility ...
117
  		}
285e42802   David S. Miller   net/core/user_dma...
118
  		start = end;
de5506e15   Chris Leech   [I/OAT]: Utility ...
119
120
121
122
123
124
125
126
127
  	}
  
  end:
  	if (!len) {
  		skb->dma_cookie = cookie;
  		return cookie;
  	}
  
  fault:
4ec93edb1   YOSHIFUJI Hideaki   [NET] CORE: Fix w...
128
  	return -EFAULT;
de5506e15   Chris Leech   [I/OAT]: Utility ...
129
  }