aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/xen-netback/netback.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/xen-netback/netback.c')
-rw-r--r--drivers/net/xen-netback/netback.c537
1 files changed, 108 insertions, 429 deletions
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index 78425554a537..438d0c09b7e6 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -39,7 +39,6 @@
39#include <linux/udp.h> 39#include <linux/udp.h>
40 40
41#include <net/tcp.h> 41#include <net/tcp.h>
42#include <net/ip6_checksum.h>
43 42
44#include <xen/xen.h> 43#include <xen/xen.h>
45#include <xen/events.h> 44#include <xen/events.h>
@@ -138,36 +137,26 @@ static inline pending_ring_idx_t nr_pending_reqs(struct xenvif *vif)
138 vif->pending_prod + vif->pending_cons; 137 vif->pending_prod + vif->pending_cons;
139} 138}
140 139
141static int max_required_rx_slots(struct xenvif *vif) 140bool xenvif_rx_ring_slots_available(struct xenvif *vif, int needed)
142{ 141{
143 int max = DIV_ROUND_UP(vif->dev->mtu, PAGE_SIZE); 142 RING_IDX prod, cons;
144 143
145 /* XXX FIXME: RX path dependent on MAX_SKB_FRAGS */ 144 do {
146 if (vif->can_sg || vif->gso_mask || vif->gso_prefix_mask) 145 prod = vif->rx.sring->req_prod;
147 max += MAX_SKB_FRAGS + 1; /* extra_info + frags */ 146 cons = vif->rx.req_cons;
148
149 return max;
150}
151 147
152int xenvif_rx_ring_full(struct xenvif *vif) 148 if (prod - cons >= needed)
153{ 149 return true;
154 RING_IDX peek = vif->rx_req_cons_peek;
155 RING_IDX needed = max_required_rx_slots(vif);
156 150
157 return ((vif->rx.sring->req_prod - peek) < needed) || 151 vif->rx.sring->req_event = prod + 1;
158 ((vif->rx.rsp_prod_pvt + XEN_NETIF_RX_RING_SIZE - peek) < needed);
159}
160 152
161int xenvif_must_stop_queue(struct xenvif *vif) 153 /* Make sure event is visible before we check prod
162{ 154 * again.
163 if (!xenvif_rx_ring_full(vif)) 155 */
164 return 0; 156 mb();
165 157 } while (vif->rx.sring->req_prod != prod);
166 vif->rx.sring->req_event = vif->rx_req_cons_peek +
167 max_required_rx_slots(vif);
168 mb(); /* request notification /then/ check the queue */
169 158
170 return xenvif_rx_ring_full(vif); 159 return false;
171} 160}
172 161
173/* 162/*
@@ -210,93 +199,6 @@ static bool start_new_rx_buffer(int offset, unsigned long size, int head)
210 return false; 199 return false;
211} 200}
212 201
213struct xenvif_count_slot_state {
214 unsigned long copy_off;
215 bool head;
216};
217
218unsigned int xenvif_count_frag_slots(struct xenvif *vif,
219 unsigned long offset, unsigned long size,
220 struct xenvif_count_slot_state *state)
221{
222 unsigned count = 0;
223
224 offset &= ~PAGE_MASK;
225
226 while (size > 0) {
227 unsigned long bytes;
228
229 bytes = PAGE_SIZE - offset;
230
231 if (bytes > size)
232 bytes = size;
233
234 if (start_new_rx_buffer(state->copy_off, bytes, state->head)) {
235 count++;
236 state->copy_off = 0;
237 }
238
239 if (state->copy_off + bytes > MAX_BUFFER_OFFSET)
240 bytes = MAX_BUFFER_OFFSET - state->copy_off;
241
242 state->copy_off += bytes;
243
244 offset += bytes;
245 size -= bytes;
246
247 if (offset == PAGE_SIZE)
248 offset = 0;
249
250 state->head = false;
251 }
252
253 return count;
254}
255
256/*
257 * Figure out how many ring slots we're going to need to send @skb to
258 * the guest. This function is essentially a dry run of
259 * xenvif_gop_frag_copy.
260 */
261unsigned int xenvif_count_skb_slots(struct xenvif *vif, struct sk_buff *skb)
262{
263 struct xenvif_count_slot_state state;
264 unsigned int count;
265 unsigned char *data;
266 unsigned i;
267
268 state.head = true;
269 state.copy_off = 0;
270
271 /* Slot for the first (partial) page of data. */
272 count = 1;
273
274 /* Need a slot for the GSO prefix for GSO extra data? */
275 if (skb_shinfo(skb)->gso_size)
276 count++;
277
278 data = skb->data;
279 while (data < skb_tail_pointer(skb)) {
280 unsigned long offset = offset_in_page(data);
281 unsigned long size = PAGE_SIZE - offset;
282
283 if (data + size > skb_tail_pointer(skb))
284 size = skb_tail_pointer(skb) - data;
285
286 count += xenvif_count_frag_slots(vif, offset, size, &state);
287
288 data += size;
289 }
290
291 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
292 unsigned long size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
293 unsigned long offset = skb_shinfo(skb)->frags[i].page_offset;
294
295 count += xenvif_count_frag_slots(vif, offset, size, &state);
296 }
297 return count;
298}
299
300struct netrx_pending_operations { 202struct netrx_pending_operations {
301 unsigned copy_prod, copy_cons; 203 unsigned copy_prod, copy_cons;
302 unsigned meta_prod, meta_cons; 204 unsigned meta_prod, meta_cons;
@@ -338,7 +240,7 @@ static void xenvif_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb,
338 struct gnttab_copy *copy_gop; 240 struct gnttab_copy *copy_gop;
339 struct xenvif_rx_meta *meta; 241 struct xenvif_rx_meta *meta;
340 unsigned long bytes; 242 unsigned long bytes;
341 int gso_type; 243 int gso_type = XEN_NETIF_GSO_TYPE_NONE;
342 244
343 /* Data must not cross a page boundary. */ 245 /* Data must not cross a page boundary. */
344 BUG_ON(size + offset > PAGE_SIZE<<compound_order(page)); 246 BUG_ON(size + offset > PAGE_SIZE<<compound_order(page));
@@ -397,12 +299,12 @@ static void xenvif_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb,
397 } 299 }
398 300
399 /* Leave a gap for the GSO descriptor. */ 301 /* Leave a gap for the GSO descriptor. */
400 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) 302 if (skb_is_gso(skb)) {
401 gso_type = XEN_NETIF_GSO_TYPE_TCPV4; 303 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
402 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) 304 gso_type = XEN_NETIF_GSO_TYPE_TCPV4;
403 gso_type = XEN_NETIF_GSO_TYPE_TCPV6; 305 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
404 else 306 gso_type = XEN_NETIF_GSO_TYPE_TCPV6;
405 gso_type = XEN_NETIF_GSO_TYPE_NONE; 307 }
406 308
407 if (*head && ((1 << gso_type) & vif->gso_mask)) 309 if (*head && ((1 << gso_type) & vif->gso_mask))
408 vif->rx.req_cons++; 310 vif->rx.req_cons++;
@@ -436,19 +338,15 @@ static int xenvif_gop_skb(struct sk_buff *skb,
436 int head = 1; 338 int head = 1;
437 int old_meta_prod; 339 int old_meta_prod;
438 int gso_type; 340 int gso_type;
439 int gso_size;
440 341
441 old_meta_prod = npo->meta_prod; 342 old_meta_prod = npo->meta_prod;
442 343
443 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) { 344 gso_type = XEN_NETIF_GSO_TYPE_NONE;
444 gso_type = XEN_NETIF_GSO_TYPE_TCPV4; 345 if (skb_is_gso(skb)) {
445 gso_size = skb_shinfo(skb)->gso_size; 346 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
446 } else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) { 347 gso_type = XEN_NETIF_GSO_TYPE_TCPV4;
447 gso_type = XEN_NETIF_GSO_TYPE_TCPV6; 348 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
448 gso_size = skb_shinfo(skb)->gso_size; 349 gso_type = XEN_NETIF_GSO_TYPE_TCPV6;
449 } else {
450 gso_type = XEN_NETIF_GSO_TYPE_NONE;
451 gso_size = 0;
452 } 350 }
453 351
454 /* Set up a GSO prefix descriptor, if necessary */ 352 /* Set up a GSO prefix descriptor, if necessary */
@@ -456,7 +354,7 @@ static int xenvif_gop_skb(struct sk_buff *skb,
456 req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++); 354 req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++);
457 meta = npo->meta + npo->meta_prod++; 355 meta = npo->meta + npo->meta_prod++;
458 meta->gso_type = gso_type; 356 meta->gso_type = gso_type;
459 meta->gso_size = gso_size; 357 meta->gso_size = skb_shinfo(skb)->gso_size;
460 meta->size = 0; 358 meta->size = 0;
461 meta->id = req->id; 359 meta->id = req->id;
462 } 360 }
@@ -466,7 +364,7 @@ static int xenvif_gop_skb(struct sk_buff *skb,
466 364
467 if ((1 << gso_type) & vif->gso_mask) { 365 if ((1 << gso_type) & vif->gso_mask) {
468 meta->gso_type = gso_type; 366 meta->gso_type = gso_type;
469 meta->gso_size = gso_size; 367 meta->gso_size = skb_shinfo(skb)->gso_size;
470 } else { 368 } else {
471 meta->gso_type = XEN_NETIF_GSO_TYPE_NONE; 369 meta->gso_type = XEN_NETIF_GSO_TYPE_NONE;
472 meta->gso_size = 0; 370 meta->gso_size = 0;
@@ -557,12 +455,12 @@ struct skb_cb_overlay {
557 int meta_slots_used; 455 int meta_slots_used;
558}; 456};
559 457
560static void xenvif_kick_thread(struct xenvif *vif) 458void xenvif_kick_thread(struct xenvif *vif)
561{ 459{
562 wake_up(&vif->wq); 460 wake_up(&vif->wq);
563} 461}
564 462
565void xenvif_rx_action(struct xenvif *vif) 463static void xenvif_rx_action(struct xenvif *vif)
566{ 464{
567 s8 status; 465 s8 status;
568 u16 flags; 466 u16 flags;
@@ -571,11 +469,9 @@ void xenvif_rx_action(struct xenvif *vif)
571 struct sk_buff *skb; 469 struct sk_buff *skb;
572 LIST_HEAD(notify); 470 LIST_HEAD(notify);
573 int ret; 471 int ret;
574 int nr_frags;
575 int count;
576 unsigned long offset; 472 unsigned long offset;
577 struct skb_cb_overlay *sco; 473 struct skb_cb_overlay *sco;
578 int need_to_notify = 0; 474 bool need_to_notify = false;
579 475
580 struct netrx_pending_operations npo = { 476 struct netrx_pending_operations npo = {
581 .copy = vif->grant_copy_op, 477 .copy = vif->grant_copy_op,
@@ -584,29 +480,47 @@ void xenvif_rx_action(struct xenvif *vif)
584 480
585 skb_queue_head_init(&rxq); 481 skb_queue_head_init(&rxq);
586 482
587 count = 0;
588
589 while ((skb = skb_dequeue(&vif->rx_queue)) != NULL) { 483 while ((skb = skb_dequeue(&vif->rx_queue)) != NULL) {
590 vif = netdev_priv(skb->dev); 484 RING_IDX max_slots_needed;
591 nr_frags = skb_shinfo(skb)->nr_frags; 485 int i;
486
487 /* We need a cheap worse case estimate for the number of
488 * slots we'll use.
489 */
490
491 max_slots_needed = DIV_ROUND_UP(offset_in_page(skb->data) +
492 skb_headlen(skb),
493 PAGE_SIZE);
494 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
495 unsigned int size;
496 size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
497 max_slots_needed += DIV_ROUND_UP(size, PAGE_SIZE);
498 }
499 if (skb_is_gso(skb) &&
500 (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 ||
501 skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6))
502 max_slots_needed++;
503
504 /* If the skb may not fit then bail out now */
505 if (!xenvif_rx_ring_slots_available(vif, max_slots_needed)) {
506 skb_queue_head(&vif->rx_queue, skb);
507 need_to_notify = true;
508 vif->rx_last_skb_slots = max_slots_needed;
509 break;
510 } else
511 vif->rx_last_skb_slots = 0;
592 512
593 sco = (struct skb_cb_overlay *)skb->cb; 513 sco = (struct skb_cb_overlay *)skb->cb;
594 sco->meta_slots_used = xenvif_gop_skb(skb, &npo); 514 sco->meta_slots_used = xenvif_gop_skb(skb, &npo);
595 515 BUG_ON(sco->meta_slots_used > max_slots_needed);
596 count += nr_frags + 1;
597 516
598 __skb_queue_tail(&rxq, skb); 517 __skb_queue_tail(&rxq, skb);
599
600 /* Filled the batch queue? */
601 /* XXX FIXME: RX path dependent on MAX_SKB_FRAGS */
602 if (count + MAX_SKB_FRAGS >= XEN_NETIF_RX_RING_SIZE)
603 break;
604 } 518 }
605 519
606 BUG_ON(npo.meta_prod > ARRAY_SIZE(vif->meta)); 520 BUG_ON(npo.meta_prod > ARRAY_SIZE(vif->meta));
607 521
608 if (!npo.copy_prod) 522 if (!npo.copy_prod)
609 return; 523 goto done;
610 524
611 BUG_ON(npo.copy_prod > MAX_GRANT_COPY_OPS); 525 BUG_ON(npo.copy_prod > MAX_GRANT_COPY_OPS);
612 gnttab_batch_copy(vif->grant_copy_op, npo.copy_prod); 526 gnttab_batch_copy(vif->grant_copy_op, npo.copy_prod);
@@ -614,8 +528,6 @@ void xenvif_rx_action(struct xenvif *vif)
614 while ((skb = __skb_dequeue(&rxq)) != NULL) { 528 while ((skb = __skb_dequeue(&rxq)) != NULL) {
615 sco = (struct skb_cb_overlay *)skb->cb; 529 sco = (struct skb_cb_overlay *)skb->cb;
616 530
617 vif = netdev_priv(skb->dev);
618
619 if ((1 << vif->meta[npo.meta_cons].gso_type) & 531 if ((1 << vif->meta[npo.meta_cons].gso_type) &
620 vif->gso_prefix_mask) { 532 vif->gso_prefix_mask) {
621 resp = RING_GET_RESPONSE(&vif->rx, 533 resp = RING_GET_RESPONSE(&vif->rx,
@@ -678,28 +590,15 @@ void xenvif_rx_action(struct xenvif *vif)
678 590
679 RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&vif->rx, ret); 591 RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&vif->rx, ret);
680 592
681 if (ret) 593 need_to_notify |= !!ret;
682 need_to_notify = 1;
683
684 xenvif_notify_tx_completion(vif);
685 594
686 npo.meta_cons += sco->meta_slots_used; 595 npo.meta_cons += sco->meta_slots_used;
687 dev_kfree_skb(skb); 596 dev_kfree_skb(skb);
688 } 597 }
689 598
599done:
690 if (need_to_notify) 600 if (need_to_notify)
691 notify_remote_via_irq(vif->rx_irq); 601 notify_remote_via_irq(vif->rx_irq);
692
693 /* More work to do? */
694 if (!skb_queue_empty(&vif->rx_queue))
695 xenvif_kick_thread(vif);
696}
697
698void xenvif_queue_tx_skb(struct xenvif *vif, struct sk_buff *skb)
699{
700 skb_queue_tail(&vif->rx_queue, skb);
701
702 xenvif_kick_thread(vif);
703} 602}
704 603
705void xenvif_check_rx_xenvif(struct xenvif *vif) 604void xenvif_check_rx_xenvif(struct xenvif *vif)
@@ -1141,265 +1040,14 @@ static int xenvif_set_skb_gso(struct xenvif *vif,
1141 } 1040 }
1142 1041
1143 skb_shinfo(skb)->gso_size = gso->u.gso.size; 1042 skb_shinfo(skb)->gso_size = gso->u.gso.size;
1144 1043 /* gso_segs will be calculated later */
1145 /* Header must be checked, and gso_segs computed. */
1146 skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
1147 skb_shinfo(skb)->gso_segs = 0;
1148 1044
1149 return 0; 1045 return 0;
1150} 1046}
1151 1047
1152static inline int maybe_pull_tail(struct sk_buff *skb, unsigned int len,
1153 unsigned int max)
1154{
1155 if (skb_headlen(skb) >= len)
1156 return 0;
1157
1158 /* If we need to pullup then pullup to the max, so we
1159 * won't need to do it again.
1160 */
1161 if (max > skb->len)
1162 max = skb->len;
1163
1164 if (__pskb_pull_tail(skb, max - skb_headlen(skb)) == NULL)
1165 return -ENOMEM;
1166
1167 if (skb_headlen(skb) < len)
1168 return -EPROTO;
1169
1170 return 0;
1171}
1172
1173/* This value should be large enough to cover a tagged ethernet header plus
1174 * maximally sized IP and TCP or UDP headers.
1175 */
1176#define MAX_IP_HDR_LEN 128
1177
1178static int checksum_setup_ip(struct xenvif *vif, struct sk_buff *skb,
1179 int recalculate_partial_csum)
1180{
1181 unsigned int off;
1182 bool fragment;
1183 int err;
1184
1185 fragment = false;
1186
1187 err = maybe_pull_tail(skb,
1188 sizeof(struct iphdr),
1189 MAX_IP_HDR_LEN);
1190 if (err < 0)
1191 goto out;
1192
1193 if (ip_hdr(skb)->frag_off & htons(IP_OFFSET | IP_MF))
1194 fragment = true;
1195
1196 off = ip_hdrlen(skb);
1197
1198 err = -EPROTO;
1199
1200 if (fragment)
1201 goto out;
1202
1203 switch (ip_hdr(skb)->protocol) {
1204 case IPPROTO_TCP:
1205 err = maybe_pull_tail(skb,
1206 off + sizeof(struct tcphdr),
1207 MAX_IP_HDR_LEN);
1208 if (err < 0)
1209 goto out;
1210
1211 if (!skb_partial_csum_set(skb, off,
1212 offsetof(struct tcphdr, check))) {
1213 err = -EPROTO;
1214 goto out;
1215 }
1216
1217 if (recalculate_partial_csum)
1218 tcp_hdr(skb)->check =
1219 ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
1220 ip_hdr(skb)->daddr,
1221 skb->len - off,
1222 IPPROTO_TCP, 0);
1223 break;
1224 case IPPROTO_UDP:
1225 err = maybe_pull_tail(skb,
1226 off + sizeof(struct udphdr),
1227 MAX_IP_HDR_LEN);
1228 if (err < 0)
1229 goto out;
1230
1231 if (!skb_partial_csum_set(skb, off,
1232 offsetof(struct udphdr, check))) {
1233 err = -EPROTO;
1234 goto out;
1235 }
1236
1237 if (recalculate_partial_csum)
1238 udp_hdr(skb)->check =
1239 ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
1240 ip_hdr(skb)->daddr,
1241 skb->len - off,
1242 IPPROTO_UDP, 0);
1243 break;
1244 default:
1245 goto out;
1246 }
1247
1248 err = 0;
1249
1250out:
1251 return err;
1252}
1253
1254/* This value should be large enough to cover a tagged ethernet header plus
1255 * an IPv6 header, all options, and a maximal TCP or UDP header.
1256 */
1257#define MAX_IPV6_HDR_LEN 256
1258
1259#define OPT_HDR(type, skb, off) \
1260 (type *)(skb_network_header(skb) + (off))
1261
1262static int checksum_setup_ipv6(struct xenvif *vif, struct sk_buff *skb,
1263 int recalculate_partial_csum)
1264{
1265 int err;
1266 u8 nexthdr;
1267 unsigned int off;
1268 unsigned int len;
1269 bool fragment;
1270 bool done;
1271
1272 fragment = false;
1273 done = false;
1274
1275 off = sizeof(struct ipv6hdr);
1276
1277 err = maybe_pull_tail(skb, off, MAX_IPV6_HDR_LEN);
1278 if (err < 0)
1279 goto out;
1280
1281 nexthdr = ipv6_hdr(skb)->nexthdr;
1282
1283 len = sizeof(struct ipv6hdr) + ntohs(ipv6_hdr(skb)->payload_len);
1284 while (off <= len && !done) {
1285 switch (nexthdr) {
1286 case IPPROTO_DSTOPTS:
1287 case IPPROTO_HOPOPTS:
1288 case IPPROTO_ROUTING: {
1289 struct ipv6_opt_hdr *hp;
1290
1291 err = maybe_pull_tail(skb,
1292 off +
1293 sizeof(struct ipv6_opt_hdr),
1294 MAX_IPV6_HDR_LEN);
1295 if (err < 0)
1296 goto out;
1297
1298 hp = OPT_HDR(struct ipv6_opt_hdr, skb, off);
1299 nexthdr = hp->nexthdr;
1300 off += ipv6_optlen(hp);
1301 break;
1302 }
1303 case IPPROTO_AH: {
1304 struct ip_auth_hdr *hp;
1305
1306 err = maybe_pull_tail(skb,
1307 off +
1308 sizeof(struct ip_auth_hdr),
1309 MAX_IPV6_HDR_LEN);
1310 if (err < 0)
1311 goto out;
1312
1313 hp = OPT_HDR(struct ip_auth_hdr, skb, off);
1314 nexthdr = hp->nexthdr;
1315 off += ipv6_authlen(hp);
1316 break;
1317 }
1318 case IPPROTO_FRAGMENT: {
1319 struct frag_hdr *hp;
1320
1321 err = maybe_pull_tail(skb,
1322 off +
1323 sizeof(struct frag_hdr),
1324 MAX_IPV6_HDR_LEN);
1325 if (err < 0)
1326 goto out;
1327
1328 hp = OPT_HDR(struct frag_hdr, skb, off);
1329
1330 if (hp->frag_off & htons(IP6_OFFSET | IP6_MF))
1331 fragment = true;
1332
1333 nexthdr = hp->nexthdr;
1334 off += sizeof(struct frag_hdr);
1335 break;
1336 }
1337 default:
1338 done = true;
1339 break;
1340 }
1341 }
1342
1343 err = -EPROTO;
1344
1345 if (!done || fragment)
1346 goto out;
1347
1348 switch (nexthdr) {
1349 case IPPROTO_TCP:
1350 err = maybe_pull_tail(skb,
1351 off + sizeof(struct tcphdr),
1352 MAX_IPV6_HDR_LEN);
1353 if (err < 0)
1354 goto out;
1355
1356 if (!skb_partial_csum_set(skb, off,
1357 offsetof(struct tcphdr, check))) {
1358 err = -EPROTO;
1359 goto out;
1360 }
1361
1362 if (recalculate_partial_csum)
1363 tcp_hdr(skb)->check =
1364 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
1365 &ipv6_hdr(skb)->daddr,
1366 skb->len - off,
1367 IPPROTO_TCP, 0);
1368 break;
1369 case IPPROTO_UDP:
1370 err = maybe_pull_tail(skb,
1371 off + sizeof(struct udphdr),
1372 MAX_IPV6_HDR_LEN);
1373 if (err < 0)
1374 goto out;
1375
1376 if (!skb_partial_csum_set(skb, off,
1377 offsetof(struct udphdr, check))) {
1378 err = -EPROTO;
1379 goto out;
1380 }
1381
1382 if (recalculate_partial_csum)
1383 udp_hdr(skb)->check =
1384 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
1385 &ipv6_hdr(skb)->daddr,
1386 skb->len - off,
1387 IPPROTO_UDP, 0);
1388 break;
1389 default:
1390 goto out;
1391 }
1392
1393 err = 0;
1394
1395out:
1396 return err;
1397}
1398
1399static int checksum_setup(struct xenvif *vif, struct sk_buff *skb) 1048static int checksum_setup(struct xenvif *vif, struct sk_buff *skb)
1400{ 1049{
1401 int err = -EPROTO; 1050 bool recalculate_partial_csum = false;
1402 int recalculate_partial_csum = 0;
1403 1051
1404 /* A GSO SKB must be CHECKSUM_PARTIAL. However some buggy 1052 /* A GSO SKB must be CHECKSUM_PARTIAL. However some buggy
1405 * peers can fail to set NETRXF_csum_blank when sending a GSO 1053 * peers can fail to set NETRXF_csum_blank when sending a GSO
@@ -1409,19 +1057,14 @@ static int checksum_setup(struct xenvif *vif, struct sk_buff *skb)
1409 if (skb->ip_summed != CHECKSUM_PARTIAL && skb_is_gso(skb)) { 1057 if (skb->ip_summed != CHECKSUM_PARTIAL && skb_is_gso(skb)) {
1410 vif->rx_gso_checksum_fixup++; 1058 vif->rx_gso_checksum_fixup++;
1411 skb->ip_summed = CHECKSUM_PARTIAL; 1059 skb->ip_summed = CHECKSUM_PARTIAL;
1412 recalculate_partial_csum = 1; 1060 recalculate_partial_csum = true;
1413 } 1061 }
1414 1062
1415 /* A non-CHECKSUM_PARTIAL SKB does not require setup. */ 1063 /* A non-CHECKSUM_PARTIAL SKB does not require setup. */
1416 if (skb->ip_summed != CHECKSUM_PARTIAL) 1064 if (skb->ip_summed != CHECKSUM_PARTIAL)
1417 return 0; 1065 return 0;
1418 1066
1419 if (skb->protocol == htons(ETH_P_IP)) 1067 return skb_checksum_setup(skb, recalculate_partial_csum);
1420 err = checksum_setup_ip(vif, skb, recalculate_partial_csum);
1421 else if (skb->protocol == htons(ETH_P_IPV6))
1422 err = checksum_setup_ipv6(vif, skb, recalculate_partial_csum);
1423
1424 return err;
1425} 1068}
1426 1069
1427static bool tx_credit_exceeded(struct xenvif *vif, unsigned size) 1070static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)
@@ -1687,6 +1330,20 @@ static int xenvif_tx_submit(struct xenvif *vif)
1687 1330
1688 skb_probe_transport_header(skb, 0); 1331 skb_probe_transport_header(skb, 0);
1689 1332
1333 /* If the packet is GSO then we will have just set up the
1334 * transport header offset in checksum_setup so it's now
1335 * straightforward to calculate gso_segs.
1336 */
1337 if (skb_is_gso(skb)) {
1338 int mss = skb_shinfo(skb)->gso_size;
1339 int hdrlen = skb_transport_header(skb) -
1340 skb_mac_header(skb) +
1341 tcp_hdrlen(skb);
1342
1343 skb_shinfo(skb)->gso_segs =
1344 DIV_ROUND_UP(skb->len - hdrlen, mss);
1345 }
1346
1690 vif->dev->stats.rx_bytes += skb->len; 1347 vif->dev->stats.rx_bytes += skb->len;
1691 vif->dev->stats.rx_packets++; 1348 vif->dev->stats.rx_packets++;
1692 1349
@@ -1811,7 +1468,8 @@ static struct xen_netif_rx_response *make_rx_response(struct xenvif *vif,
1811 1468
1812static inline int rx_work_todo(struct xenvif *vif) 1469static inline int rx_work_todo(struct xenvif *vif)
1813{ 1470{
1814 return !skb_queue_empty(&vif->rx_queue); 1471 return !skb_queue_empty(&vif->rx_queue) &&
1472 xenvif_rx_ring_slots_available(vif, vif->rx_last_skb_slots);
1815} 1473}
1816 1474
1817static inline int tx_work_todo(struct xenvif *vif) 1475static inline int tx_work_todo(struct xenvif *vif)
@@ -1861,8 +1519,6 @@ int xenvif_map_frontend_rings(struct xenvif *vif,
1861 rxs = (struct xen_netif_rx_sring *)addr; 1519 rxs = (struct xen_netif_rx_sring *)addr;
1862 BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE); 1520 BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE);
1863 1521
1864 vif->rx_req_cons_peek = 0;
1865
1866 return 0; 1522 return 0;
1867 1523
1868err: 1524err:
@@ -1870,9 +1526,24 @@ err:
1870 return err; 1526 return err;
1871} 1527}
1872 1528
1529void xenvif_stop_queue(struct xenvif *vif)
1530{
1531 if (!vif->can_queue)
1532 return;
1533
1534 netif_stop_queue(vif->dev);
1535}
1536
1537static void xenvif_start_queue(struct xenvif *vif)
1538{
1539 if (xenvif_schedulable(vif))
1540 netif_wake_queue(vif->dev);
1541}
1542
1873int xenvif_kthread(void *data) 1543int xenvif_kthread(void *data)
1874{ 1544{
1875 struct xenvif *vif = data; 1545 struct xenvif *vif = data;
1546 struct sk_buff *skb;
1876 1547
1877 while (!kthread_should_stop()) { 1548 while (!kthread_should_stop()) {
1878 wait_event_interruptible(vif->wq, 1549 wait_event_interruptible(vif->wq,
@@ -1881,12 +1552,20 @@ int xenvif_kthread(void *data)
1881 if (kthread_should_stop()) 1552 if (kthread_should_stop())
1882 break; 1553 break;
1883 1554
1884 if (rx_work_todo(vif)) 1555 if (!skb_queue_empty(&vif->rx_queue))
1885 xenvif_rx_action(vif); 1556 xenvif_rx_action(vif);
1886 1557
1558 if (skb_queue_empty(&vif->rx_queue) &&
1559 netif_queue_stopped(vif->dev))
1560 xenvif_start_queue(vif);
1561
1887 cond_resched(); 1562 cond_resched();
1888 } 1563 }
1889 1564
1565 /* Bin any remaining skbs */
1566 while ((skb = skb_dequeue(&vif->rx_queue)) != NULL)
1567 dev_kfree_skb(skb);
1568
1890 return 0; 1569 return 0;
1891} 1570}
1892 1571