Lines Matching +full:rx +full:- +full:queues +full:- +full:to +full:- +full:use

4  * Copyright (c) 2002-2005, K A Fraser
11 * software packages, subject to the following license:
13 * Permission is hereby granted, free of charge, to any person obtaining a copy
14 * of this source file (the "Software"), to deal in the Software without
15 * restriction, including without limitation the rights to use, copy, modify,
17 * and to permit persons to whom the Software is furnished to do so, subject to
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
67 "Maximum number of queues per virtual interface");
81 #define NETFRONT_SKB_CB(skb) ((struct netfront_cb *)((skb)->cb))
88 /* Minimum number of Rx slots (includes slot for GSO metadata). */
91 /* Queue name is interface name with "-qNNN" appended */
94 /* IRQ name is queue name with "-tx" or "-rx" appended */
108 unsigned int id; /* Queue ID, 0-based */
109 char name[QUEUE_NAME_SIZE]; /* DEVNAME-qN */
122 char tx_irq_name[IRQ_NAME_SIZE]; /* DEVNAME-qN-tx */
123 char rx_irq_name[IRQ_NAME_SIZE]; /* DEVNAME-qN-rx */
130 * {tx,rx}_skbs store outstanding skbuffs. Free tx_skb entries
144 struct xen_netif_rx_front_ring rx; member
166 /* Multi-queue support */
167 struct netfront_queue *queues; member
187 struct xen_netif_rx_response rx; member
188 struct xen_netif_extra_info extras[XEN_NETIF_EXTRA_TYPE_MAX - 1];
215 return idx & (NET_RX_RING_SIZE - 1); in xennet_rxidx()
222 struct sk_buff *skb = queue->rx_skbs[i]; in xennet_get_rx_skb()
223 queue->rx_skbs[i] = NULL; in xennet_get_rx_skb()
231 grant_ref_t ref = queue->grant_rx_ref[i]; in xennet_get_rx_ref()
232 queue->grant_rx_ref[i] = INVALID_GRANT_REF; in xennet_get_rx_ref()
242 return dev->features & NETIF_F_SG; in xennet_can_sg()
249 napi_schedule(&queue->napi); in rx_refill_timeout()
254 return (queue->tx.req_prod_pvt - queue->tx.rsp_cons) < in netfront_tx_slot_available()
255 (NET_TX_RING_SIZE - XEN_NETIF_NR_SLOTS_MIN - 1); in netfront_tx_slot_available()
260 struct net_device *dev = queue->info->netdev; in xennet_maybe_wake_tx()
261 struct netdev_queue *dev_queue = netdev_get_tx_queue(dev, queue->id); in xennet_maybe_wake_tx()
266 netif_tx_wake_queue(netdev_get_tx_queue(dev, queue->id)); in xennet_maybe_wake_tx()
275 skb = __netdev_alloc_skb(queue->info->netdev, in xennet_alloc_one_rx_buffer()
281 page = page_pool_alloc_pages(queue->page_pool, in xennet_alloc_one_rx_buffer()
290 /* Align ip header to a 16 bytes boundary */ in xennet_alloc_one_rx_buffer()
292 skb->dev = queue->info->netdev; in xennet_alloc_one_rx_buffer()
300 RING_IDX req_prod = queue->rx.req_prod_pvt; in xennet_alloc_rx_buffers()
304 if (unlikely(!netif_carrier_ok(queue->info->netdev))) in xennet_alloc_rx_buffers()
307 for (req_prod = queue->rx.req_prod_pvt; in xennet_alloc_rx_buffers()
308 req_prod - queue->rx.rsp_cons < NET_RX_RING_SIZE; in xennet_alloc_rx_buffers()
318 err = -ENOMEM; in xennet_alloc_rx_buffers()
324 BUG_ON(queue->rx_skbs[id]); in xennet_alloc_rx_buffers()
325 queue->rx_skbs[id] = skb; in xennet_alloc_rx_buffers()
327 ref = gnttab_claim_grant_reference(&queue->gref_rx_head); in xennet_alloc_rx_buffers()
329 queue->grant_rx_ref[id] = ref; in xennet_alloc_rx_buffers()
331 page = skb_frag_page(&skb_shinfo(skb)->frags[0]); in xennet_alloc_rx_buffers()
333 req = RING_GET_REQUEST(&queue->rx, req_prod); in xennet_alloc_rx_buffers()
335 queue->info->xbdev->otherend_id, in xennet_alloc_rx_buffers()
338 req->id = id; in xennet_alloc_rx_buffers()
339 req->gref = ref; in xennet_alloc_rx_buffers()
342 queue->rx.req_prod_pvt = req_prod; in xennet_alloc_rx_buffers()
349 if (req_prod - queue->rx.rsp_cons < NET_RX_SLOTS_MIN || in xennet_alloc_rx_buffers()
351 mod_timer(&queue->rx_refill_timer, jiffies + (HZ/10)); in xennet_alloc_rx_buffers()
355 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&queue->rx, notify); in xennet_alloc_rx_buffers()
357 notify_remote_via_irq(queue->rx_irq); in xennet_alloc_rx_buffers()
363 unsigned int num_queues = dev->real_num_tx_queues; in xennet_open()
367 if (!np->queues || np->broken) in xennet_open()
368 return -ENODEV; in xennet_open()
371 queue = &np->queues[i]; in xennet_open()
372 napi_enable(&queue->napi); in xennet_open()
374 spin_lock_bh(&queue->rx_lock); in xennet_open()
377 queue->rx.sring->rsp_event = queue->rx.rsp_cons + 1; in xennet_open()
378 if (RING_HAS_UNCONSUMED_RESPONSES(&queue->rx)) in xennet_open()
379 napi_schedule(&queue->napi); in xennet_open()
381 spin_unlock_bh(&queue->rx_lock); in xennet_open()
396 const struct device *dev = &queue->info->netdev->dev; in xennet_tx_buf_gc()
398 BUG_ON(!netif_carrier_ok(queue->info->netdev)); in xennet_tx_buf_gc()
401 prod = queue->tx.sring->rsp_prod; in xennet_tx_buf_gc()
402 if (RING_RESPONSE_PROD_OVERFLOW(&queue->tx, prod)) { in xennet_tx_buf_gc()
404 prod - queue->tx.rsp_cons); in xennet_tx_buf_gc()
407 rmb(); /* Ensure we see responses up to 'rp'. */ in xennet_tx_buf_gc()
409 for (cons = queue->tx.rsp_cons; cons != prod; cons++) { in xennet_tx_buf_gc()
414 RING_COPY_RESPONSE(&queue->tx, cons, &txrsp); in xennet_tx_buf_gc()
419 if (id >= RING_SIZE(&queue->tx)) { in xennet_tx_buf_gc()
425 if (queue->tx_link[id] != TX_PENDING) { in xennet_tx_buf_gc()
431 queue->tx_link[id] = TX_LINK_NONE; in xennet_tx_buf_gc()
432 skb = queue->tx_skbs[id]; in xennet_tx_buf_gc()
433 queue->tx_skbs[id] = NULL; in xennet_tx_buf_gc()
435 queue->grant_tx_ref[id]))) { in xennet_tx_buf_gc()
437 "Grant still in use by backend domain\n"); in xennet_tx_buf_gc()
441 &queue->gref_tx_head, queue->grant_tx_ref[id]); in xennet_tx_buf_gc()
442 queue->grant_tx_ref[id] = INVALID_GRANT_REF; in xennet_tx_buf_gc()
443 queue->grant_tx_page[id] = NULL; in xennet_tx_buf_gc()
444 add_id_to_list(&queue->tx_skb_freelist, queue->tx_link, id); in xennet_tx_buf_gc()
448 queue->tx.rsp_cons = prod; in xennet_tx_buf_gc()
450 RING_FINAL_CHECK_FOR_RESPONSES(&queue->tx, more_to_do); in xennet_tx_buf_gc()
458 queue->info->broken = true; in xennet_tx_buf_gc()
459 dev_alert(dev, "Disabled for further use\n"); in xennet_tx_buf_gc()
481 struct page *page = info->page; in xennet_tx_setup_grant()
482 struct netfront_queue *queue = info->queue; in xennet_tx_setup_grant()
483 struct sk_buff *skb = info->skb; in xennet_tx_setup_grant()
485 id = get_id_from_list(&queue->tx_skb_freelist, queue->tx_link); in xennet_tx_setup_grant()
486 tx = RING_GET_REQUEST(&queue->tx, queue->tx.req_prod_pvt++); in xennet_tx_setup_grant()
487 ref = gnttab_claim_grant_reference(&queue->gref_tx_head); in xennet_tx_setup_grant()
490 gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id, in xennet_tx_setup_grant()
493 queue->tx_skbs[id] = skb; in xennet_tx_setup_grant()
494 queue->grant_tx_page[id] = page; in xennet_tx_setup_grant()
495 queue->grant_tx_ref[id] = ref; in xennet_tx_setup_grant()
497 info->tx_local.id = id; in xennet_tx_setup_grant()
498 info->tx_local.gref = ref; in xennet_tx_setup_grant()
499 info->tx_local.offset = offset; in xennet_tx_setup_grant()
500 info->tx_local.size = len; in xennet_tx_setup_grant()
501 info->tx_local.flags = 0; in xennet_tx_setup_grant()
503 *tx = info->tx_local; in xennet_tx_setup_grant()
506 * Put the request in the pending queue, it will be set to be pending in xennet_tx_setup_grant()
507 * when the producer index is about to be raised. in xennet_tx_setup_grant()
509 add_id_to_list(&queue->tx_pend_queue, queue->tx_link, id); in xennet_tx_setup_grant()
511 info->tx = tx; in xennet_tx_setup_grant()
512 info->size += info->tx_local.size; in xennet_tx_setup_grant()
519 info->size = 0; in xennet_make_first_txreq()
521 gnttab_for_one_grant(info->page, offset, len, xennet_tx_setup_grant, info); in xennet_make_first_txreq()
523 return info->tx; in xennet_make_first_txreq()
531 info->tx->flags |= XEN_NETTXF_more_data; in xennet_make_one_txreq()
532 skb_get(info->skb); in xennet_make_one_txreq()
546 info->page = page; in xennet_make_txreqs()
547 info->size = 0; in xennet_make_txreqs()
555 len -= info->size; in xennet_make_txreqs()
560 * Count how many ring slots are required to send this skb. Each frag
565 int i, frags = skb_shinfo(skb)->nr_frags; in xennet_count_skb_slots()
568 slots = gnttab_count_grant(offset_in_page(skb->data), in xennet_count_skb_slots()
572 skb_frag_t *frag = skb_shinfo(skb)->frags + i; in xennet_count_skb_slots()
588 unsigned int num_queues = dev->real_num_tx_queues; in xennet_select_queue()
607 while ((i = get_id_from_list(&queue->tx_pend_queue, queue->tx_link)) != in xennet_mark_tx_pending()
609 queue->tx_link[i] = TX_PENDING; in xennet_mark_tx_pending()
617 struct netfront_stats *tx_stats = this_cpu_ptr(np->tx_stats); in xennet_xdp_xmit_one()
621 .page = virt_to_page(xdpf->data), in xennet_xdp_xmit_one()
626 offset_in_page(xdpf->data), in xennet_xdp_xmit_one()
627 xdpf->len); in xennet_xdp_xmit_one()
631 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&queue->tx, notify); in xennet_xdp_xmit_one()
633 notify_remote_via_irq(queue->tx_irq); in xennet_xdp_xmit_one()
635 u64_stats_update_begin(&tx_stats->syncp); in xennet_xdp_xmit_one()
636 tx_stats->bytes += xdpf->len; in xennet_xdp_xmit_one()
637 tx_stats->packets++; in xennet_xdp_xmit_one()
638 u64_stats_update_end(&tx_stats->syncp); in xennet_xdp_xmit_one()
648 unsigned int num_queues = dev->real_num_tx_queues; in xennet_xdp_xmit()
655 if (unlikely(np->broken)) in xennet_xdp_xmit()
656 return -ENODEV; in xennet_xdp_xmit()
658 return -EINVAL; in xennet_xdp_xmit()
660 queue = &np->queues[smp_processor_id() % num_queues]; in xennet_xdp_xmit()
662 spin_lock_irqsave(&queue->tx_lock, irq_flags); in xennet_xdp_xmit()
672 spin_unlock_irqrestore(&queue->tx_lock, irq_flags); in xennet_xdp_xmit()
680 /* Align size to allocate full pages and avoid contiguous data leaks */ in bounce_skb()
681 unsigned int size = ALIGN(skb_end_offset(skb) + skb->data_len, in bounce_skb()
688 if (!IS_ALIGNED((uintptr_t)n->head, XEN_PAGE_SIZE)) { in bounce_skb()
697 skb_put(n, skb->len); in bounce_skb()
699 BUG_ON(skb_copy_bits(skb, -headerlen, n->head, headerlen + skb->len)); in bounce_skb()
710 struct netfront_stats *tx_stats = this_cpu_ptr(np->tx_stats); in xennet_start_xmit()
721 unsigned int num_queues = dev->real_num_tx_queues; in xennet_start_xmit()
725 /* Drop the packet if no queues are set up */ in xennet_start_xmit()
728 if (unlikely(np->broken)) in xennet_start_xmit()
730 /* Determine which queue to transmit this SKB on */ in xennet_start_xmit()
732 queue = &np->queues[queue_index]; in xennet_start_xmit()
734 /* If skb->len is too big for wire format, drop skb and alert in xennet_start_xmit()
737 if (unlikely(skb->len > XEN_NETIF_MAX_TX_SIZE)) { in xennet_start_xmit()
739 "xennet: skb->len = %u, too big for wire format\n", in xennet_start_xmit()
740 skb->len); in xennet_start_xmit()
747 slots, skb->len); in xennet_start_xmit()
752 page = virt_to_page(skb->data); in xennet_start_xmit()
753 offset = offset_in_page(skb->data); in xennet_start_xmit()
758 * If the backend is not trusted bounce all data to zeroed pages to in xennet_start_xmit()
759 * avoid exposing contiguous data on the granted page not belonging to in xennet_start_xmit()
762 if (np->bounce || unlikely(PAGE_SIZE - offset < ETH_HLEN)) { in xennet_start_xmit()
768 page = virt_to_page(skb->data); in xennet_start_xmit()
769 offset = offset_in_page(skb->data); in xennet_start_xmit()
774 spin_lock_irqsave(&queue->tx_lock, flags); in xennet_start_xmit()
779 spin_unlock_irqrestore(&queue->tx_lock, flags); in xennet_start_xmit()
793 len -= info.tx_local.size; in xennet_start_xmit()
795 if (skb->ip_summed == CHECKSUM_PARTIAL) in xennet_start_xmit()
797 first_tx->flags |= XEN_NETTXF_csum_blank | in xennet_start_xmit()
799 else if (skb->ip_summed == CHECKSUM_UNNECESSARY) in xennet_start_xmit()
801 first_tx->flags |= XEN_NETTXF_data_validated; in xennet_start_xmit()
804 if (skb_shinfo(skb)->gso_size) { in xennet_start_xmit()
808 RING_GET_REQUEST(&queue->tx, queue->tx.req_prod_pvt++); in xennet_start_xmit()
810 first_tx->flags |= XEN_NETTXF_extra_info; in xennet_start_xmit()
812 gso->u.gso.size = skb_shinfo(skb)->gso_size; in xennet_start_xmit()
813 gso->u.gso.type = (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) ? in xennet_start_xmit()
816 gso->u.gso.pad = 0; in xennet_start_xmit()
817 gso->u.gso.features = 0; in xennet_start_xmit()
819 gso->type = XEN_NETIF_EXTRA_TYPE_GSO; in xennet_start_xmit()
820 gso->flags = 0; in xennet_start_xmit()
827 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in xennet_start_xmit()
828 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; in xennet_start_xmit()
835 first_tx->size = skb->len; in xennet_start_xmit()
842 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&queue->tx, notify); in xennet_start_xmit()
844 notify_remote_via_irq(queue->tx_irq); in xennet_start_xmit()
846 u64_stats_update_begin(&tx_stats->syncp); in xennet_start_xmit()
847 tx_stats->bytes += skb->len; in xennet_start_xmit()
848 tx_stats->packets++; in xennet_start_xmit()
849 u64_stats_update_end(&tx_stats->syncp); in xennet_start_xmit()
851 /* Note: It is not safe to access skb after xennet_tx_buf_gc()! */ in xennet_start_xmit()
855 netif_tx_stop_queue(netdev_get_tx_queue(dev, queue->id)); in xennet_start_xmit()
857 spin_unlock_irqrestore(&queue->tx_lock, flags); in xennet_start_xmit()
862 dev->stats.tx_dropped++; in xennet_start_xmit()
870 unsigned int num_queues = dev->real_num_tx_queues; in xennet_close()
873 netif_tx_stop_all_queues(np->netdev); in xennet_close()
875 queue = &np->queues[i]; in xennet_close()
876 napi_disable(&queue->napi); in xennet_close()
885 for (i = 0; i < info->netdev->real_num_tx_queues; i++) { in xennet_destroy_queues()
886 struct netfront_queue *queue = &info->queues[i]; in xennet_destroy_queues()
888 if (netif_running(info->netdev)) in xennet_destroy_queues()
889 napi_disable(&queue->napi); in xennet_destroy_queues()
890 netif_napi_del(&queue->napi); in xennet_destroy_queues()
893 kfree(info->queues); in xennet_destroy_queues()
894 info->queues = NULL; in xennet_destroy_queues()
907 spin_lock_irqsave(&queue->rx_cons_lock, flags); in xennet_set_rx_rsp_cons()
908 queue->rx.rsp_cons = val; in xennet_set_rx_rsp_cons()
909 queue->rx_rsp_unconsumed = XEN_RING_NR_UNCONSUMED_RESPONSES(&queue->rx); in xennet_set_rx_rsp_cons()
910 spin_unlock_irqrestore(&queue->rx_cons_lock, flags); in xennet_set_rx_rsp_cons()
916 int new = xennet_rxidx(queue->rx.req_prod_pvt); in xennet_move_rx_slot()
918 BUG_ON(queue->rx_skbs[new]); in xennet_move_rx_slot()
919 queue->rx_skbs[new] = skb; in xennet_move_rx_slot()
920 queue->grant_rx_ref[new] = ref; in xennet_move_rx_slot()
921 RING_GET_REQUEST(&queue->rx, queue->rx.req_prod_pvt)->id = new; in xennet_move_rx_slot()
922 RING_GET_REQUEST(&queue->rx, queue->rx.req_prod_pvt)->gref = ref; in xennet_move_rx_slot()
923 queue->rx.req_prod_pvt++; in xennet_move_rx_slot()
932 struct device *dev = &queue->info->netdev->dev; in xennet_get_extras()
933 RING_IDX cons = queue->rx.rsp_cons; in xennet_get_extras()
943 err = -EBADR; in xennet_get_extras()
947 RING_COPY_RESPONSE(&queue->rx, ++cons, &extra); in xennet_get_extras()
954 err = -EINVAL; in xennet_get_extras()
956 extras[extra.type - 1] = extra; in xennet_get_extras()
969 struct xen_netif_rx_response *rx, struct bpf_prog *prog, in xennet_run_xdp() argument
973 u32 len = rx->status; in xennet_run_xdp()
977 xdp_init_buff(xdp, XEN_PAGE_SIZE - XDP_PACKET_HEADROOM, in xennet_run_xdp()
978 &queue->xdp_rxq); in xennet_run_xdp()
987 err = xennet_xdp_xmit(queue->info->netdev, 1, &xdpf, 0); in xennet_run_xdp()
991 trace_xdp_exception(queue->info->netdev, prog, act); in xennet_run_xdp()
995 err = xdp_do_redirect(queue->info->netdev, xdp, prog); in xennet_run_xdp()
998 trace_xdp_exception(queue->info->netdev, prog, act); in xennet_run_xdp()
1005 trace_xdp_exception(queue->info->netdev, prog, act); in xennet_run_xdp()
1009 bpf_warn_invalid_xdp_action(queue->info->netdev, prog, act); in xennet_run_xdp()
1020 struct xen_netif_rx_response *rx = &rinfo->rx, rx_local; in xennet_get_responses() local
1021 int max = XEN_NETIF_NR_SLOTS_MIN + (rx->status <= RX_COPY_THRESHOLD); in xennet_get_responses()
1022 RING_IDX cons = queue->rx.rsp_cons; in xennet_get_responses()
1024 struct xen_netif_extra_info *extras = rinfo->extras; in xennet_get_responses()
1026 struct device *dev = &queue->info->netdev->dev; in xennet_get_responses()
1033 if (rx->flags & XEN_NETRXF_extra_info) { in xennet_get_responses()
1036 if (extras[XEN_NETIF_EXTRA_TYPE_XDP - 1].type) { in xennet_get_responses()
1039 xdp = &extras[XEN_NETIF_EXTRA_TYPE_XDP - 1]; in xennet_get_responses()
1040 rx->offset = xdp->u.xdp.headroom; in xennet_get_responses()
1043 cons = queue->rx.rsp_cons; in xennet_get_responses()
1050 * situation to the system controller to reboot the backend. in xennet_get_responses()
1054 dev_warn(dev, "Bad rx response id %d.\n", in xennet_get_responses()
1055 rx->id); in xennet_get_responses()
1056 err = -EINVAL; in xennet_get_responses()
1060 if (unlikely(rx->status < 0 || in xennet_get_responses()
1061 rx->offset + rx->status > XEN_PAGE_SIZE)) { in xennet_get_responses()
1063 dev_warn(dev, "rx->offset: %u, size: %d\n", in xennet_get_responses()
1064 rx->offset, rx->status); in xennet_get_responses()
1066 err = -EINVAL; in xennet_get_responses()
1072 "Grant still in use by backend domain\n"); in xennet_get_responses()
1073 queue->info->broken = true; in xennet_get_responses()
1074 dev_alert(dev, "Disabled for further use\n"); in xennet_get_responses()
1075 return -EINVAL; in xennet_get_responses()
1078 gnttab_release_grant_reference(&queue->gref_rx_head, ref); in xennet_get_responses()
1081 xdp_prog = rcu_dereference(queue->xdp_prog); in xennet_get_responses()
1083 if (!(rx->flags & XEN_NETRXF_more_data)) { in xennet_get_responses()
1086 skb_frag_page(&skb_shinfo(skb)->frags[0]), in xennet_get_responses()
1087 rx, xdp_prog, &xdp, need_xdp_flush); in xennet_get_responses()
1089 err = -EINVAL; in xennet_get_responses()
1092 err = -EINVAL; in xennet_get_responses()
1100 if (!(rx->flags & XEN_NETRXF_more_data)) in xennet_get_responses()
1106 err = -ENOENT; in xennet_get_responses()
1110 RING_COPY_RESPONSE(&queue->rx, cons + slots, &rx_local); in xennet_get_responses()
1111 rx = &rx_local; in xennet_get_responses()
1120 err = -E2BIG; in xennet_get_responses()
1132 if (!gso->u.gso.size) { in xennet_set_skb_gso()
1135 return -EINVAL; in xennet_set_skb_gso()
1138 if (gso->u.gso.type != XEN_NETIF_GSO_TYPE_TCPV4 && in xennet_set_skb_gso()
1139 gso->u.gso.type != XEN_NETIF_GSO_TYPE_TCPV6) { in xennet_set_skb_gso()
1141 pr_warn("Bad GSO type %d\n", gso->u.gso.type); in xennet_set_skb_gso()
1142 return -EINVAL; in xennet_set_skb_gso()
1145 skb_shinfo(skb)->gso_size = gso->u.gso.size; in xennet_set_skb_gso()
1146 skb_shinfo(skb)->gso_type = in xennet_set_skb_gso()
1147 (gso->u.gso.type == XEN_NETIF_GSO_TYPE_TCPV4) ? in xennet_set_skb_gso()
1152 skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY; in xennet_set_skb_gso()
1153 skb_shinfo(skb)->gso_segs = 0; in xennet_set_skb_gso()
1162 RING_IDX cons = queue->rx.rsp_cons; in xennet_fill_frags()
1166 struct xen_netif_rx_response rx; in xennet_fill_frags() local
1167 skb_frag_t *nfrag = &skb_shinfo(nskb)->frags[0]; in xennet_fill_frags()
1169 RING_COPY_RESPONSE(&queue->rx, ++cons, &rx); in xennet_fill_frags()
1171 if (skb_shinfo(skb)->nr_frags == MAX_SKB_FRAGS) { in xennet_fill_frags()
1172 unsigned int pull_to = NETFRONT_SKB_CB(skb)->pull_to; in xennet_fill_frags()
1175 __pskb_pull_tail(skb, pull_to - skb_headlen(skb)); in xennet_fill_frags()
1177 if (unlikely(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS)) { in xennet_fill_frags()
1181 return -ENOENT; in xennet_fill_frags()
1184 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, in xennet_fill_frags()
1186 rx.offset, rx.status, PAGE_SIZE); in xennet_fill_frags()
1188 skb_shinfo(nskb)->nr_frags = 0; in xennet_fill_frags()
1203 * peers can fail to set NETRXF_csum_blank when sending a GSO in checksum_setup()
1204 * frame. In this case force the SKB to CHECKSUM_PARTIAL and in checksum_setup()
1207 if (skb->ip_summed != CHECKSUM_PARTIAL && skb_is_gso(skb)) { in checksum_setup()
1209 atomic_inc(&np->rx_gso_checksum_fixup); in checksum_setup()
1210 skb->ip_summed = CHECKSUM_PARTIAL; in checksum_setup()
1214 /* A non-CHECKSUM_PARTIAL SKB does not require setup. */ in checksum_setup()
1215 if (skb->ip_summed != CHECKSUM_PARTIAL) in checksum_setup()
1224 struct netfront_stats *rx_stats = this_cpu_ptr(queue->info->rx_stats); in handle_incoming_queue()
1229 int pull_to = NETFRONT_SKB_CB(skb)->pull_to; in handle_incoming_queue()
1232 __pskb_pull_tail(skb, pull_to - skb_headlen(skb)); in handle_incoming_queue()
1234 /* Ethernet work: Delayed to here as it peeks the header. */ in handle_incoming_queue()
1235 skb->protocol = eth_type_trans(skb, queue->info->netdev); in handle_incoming_queue()
1238 if (checksum_setup(queue->info->netdev, skb)) { in handle_incoming_queue()
1241 queue->info->netdev->stats.rx_errors++; in handle_incoming_queue()
1245 u64_stats_update_begin(&rx_stats->syncp); in handle_incoming_queue()
1246 rx_stats->packets++; in handle_incoming_queue()
1247 rx_stats->bytes += skb->len; in handle_incoming_queue()
1248 u64_stats_update_end(&rx_stats->syncp); in handle_incoming_queue()
1251 napi_gro_receive(&queue->napi, skb); in handle_incoming_queue()
1260 struct net_device *dev = queue->info->netdev; in xennet_poll()
1263 struct xen_netif_rx_response *rx = &rinfo.rx; in xennet_poll() local
1273 spin_lock(&queue->rx_lock); in xennet_poll()
1279 rp = queue->rx.sring->rsp_prod; in xennet_poll()
1280 if (RING_RESPONSE_PROD_OVERFLOW(&queue->rx, rp)) { in xennet_poll()
1281 dev_alert(&dev->dev, "Illegal number of responses %u\n", in xennet_poll()
1282 rp - queue->rx.rsp_cons); in xennet_poll()
1283 queue->info->broken = true; in xennet_poll()
1284 spin_unlock(&queue->rx_lock); in xennet_poll()
1287 rmb(); /* Ensure we see queued responses up to 'rp'. */ in xennet_poll()
1289 i = queue->rx.rsp_cons; in xennet_poll()
1292 RING_COPY_RESPONSE(&queue->rx, i, rx); in xennet_poll()
1299 if (queue->info->broken) { in xennet_poll()
1300 spin_unlock(&queue->rx_lock); in xennet_poll()
1306 dev->stats.rx_errors++; in xennet_poll()
1307 i = queue->rx.rsp_cons; in xennet_poll()
1313 if (extras[XEN_NETIF_EXTRA_TYPE_GSO - 1].type) { in xennet_poll()
1315 gso = &extras[XEN_NETIF_EXTRA_TYPE_GSO - 1]; in xennet_poll()
1320 queue->rx.rsp_cons + in xennet_poll()
1326 NETFRONT_SKB_CB(skb)->pull_to = rx->status; in xennet_poll()
1327 if (NETFRONT_SKB_CB(skb)->pull_to > RX_COPY_THRESHOLD) in xennet_poll()
1328 NETFRONT_SKB_CB(skb)->pull_to = RX_COPY_THRESHOLD; in xennet_poll()
1330 skb_frag_off_set(&skb_shinfo(skb)->frags[0], rx->offset); in xennet_poll()
1331 skb_frag_size_set(&skb_shinfo(skb)->frags[0], rx->status); in xennet_poll()
1332 skb->data_len = rx->status; in xennet_poll()
1333 skb->len += rx->status; in xennet_poll()
1338 if (rx->flags & XEN_NETRXF_csum_blank) in xennet_poll()
1339 skb->ip_summed = CHECKSUM_PARTIAL; in xennet_poll()
1340 else if (rx->flags & XEN_NETRXF_data_validated) in xennet_poll()
1341 skb->ip_summed = CHECKSUM_UNNECESSARY; in xennet_poll()
1345 i = queue->rx.rsp_cons + 1; in xennet_poll()
1354 work_done -= handle_incoming_queue(queue, &rxq); in xennet_poll()
1363 RING_FINAL_CHECK_FOR_RESPONSES(&queue->rx, more_to_do); in xennet_poll()
1368 spin_unlock(&queue->rx_lock); in xennet_poll()
1378 return -EINVAL; in xennet_change_mtu()
1379 WRITE_ONCE(dev->mtu, mtu); in xennet_change_mtu()
1390 struct netfront_stats *rx_stats = per_cpu_ptr(np->rx_stats, cpu); in xennet_get_stats64()
1391 struct netfront_stats *tx_stats = per_cpu_ptr(np->tx_stats, cpu); in xennet_get_stats64()
1396 start = u64_stats_fetch_begin(&tx_stats->syncp); in xennet_get_stats64()
1397 tx_packets = tx_stats->packets; in xennet_get_stats64()
1398 tx_bytes = tx_stats->bytes; in xennet_get_stats64()
1399 } while (u64_stats_fetch_retry(&tx_stats->syncp, start)); in xennet_get_stats64()
1402 start = u64_stats_fetch_begin(&rx_stats->syncp); in xennet_get_stats64()
1403 rx_packets = rx_stats->packets; in xennet_get_stats64()
1404 rx_bytes = rx_stats->bytes; in xennet_get_stats64()
1405 } while (u64_stats_fetch_retry(&rx_stats->syncp, start)); in xennet_get_stats64()
1407 tot->rx_packets += rx_packets; in xennet_get_stats64()
1408 tot->tx_packets += tx_packets; in xennet_get_stats64()
1409 tot->rx_bytes += rx_bytes; in xennet_get_stats64()
1410 tot->tx_bytes += tx_bytes; in xennet_get_stats64()
1413 tot->rx_errors = dev->stats.rx_errors; in xennet_get_stats64()
1414 tot->tx_dropped = dev->stats.tx_dropped; in xennet_get_stats64()
1424 if (!queue->tx_skbs[i]) in xennet_release_tx_bufs()
1427 skb = queue->tx_skbs[i]; in xennet_release_tx_bufs()
1428 queue->tx_skbs[i] = NULL; in xennet_release_tx_bufs()
1429 get_page(queue->grant_tx_page[i]); in xennet_release_tx_bufs()
1430 gnttab_end_foreign_access(queue->grant_tx_ref[i], in xennet_release_tx_bufs()
1431 queue->grant_tx_page[i]); in xennet_release_tx_bufs()
1432 queue->grant_tx_page[i] = NULL; in xennet_release_tx_bufs()
1433 queue->grant_tx_ref[i] = INVALID_GRANT_REF; in xennet_release_tx_bufs()
1434 add_id_to_list(&queue->tx_skb_freelist, queue->tx_link, i); in xennet_release_tx_bufs()
1443 spin_lock_bh(&queue->rx_lock); in xennet_release_rx_bufs()
1449 skb = queue->rx_skbs[id]; in xennet_release_rx_bufs()
1453 ref = queue->grant_rx_ref[id]; in xennet_release_rx_bufs()
1457 page = skb_frag_page(&skb_shinfo(skb)->frags[0]); in xennet_release_rx_bufs()
1464 queue->grant_rx_ref[id] = INVALID_GRANT_REF; in xennet_release_rx_bufs()
1469 spin_unlock_bh(&queue->rx_lock); in xennet_release_rx_bufs()
1478 !xenbus_read_unsigned(np->xbdev->otherend, "feature-sg", 0)) in xennet_fix_features()
1482 !xenbus_read_unsigned(np->xbdev->otherend, in xennet_fix_features()
1483 "feature-ipv6-csum-offload", 0)) in xennet_fix_features()
1487 !xenbus_read_unsigned(np->xbdev->otherend, "feature-gso-tcpv4", 0)) in xennet_fix_features()
1491 !xenbus_read_unsigned(np->xbdev->otherend, "feature-gso-tcpv6", 0)) in xennet_fix_features()
1500 if (!(features & NETIF_F_SG) && dev->mtu > ETH_DATA_LEN) { in xennet_set_features()
1502 dev->mtu = ETH_DATA_LEN; in xennet_set_features()
1512 if (unlikely(queue->info->broken)) in xennet_handle_tx()
1515 spin_lock_irqsave(&queue->tx_lock, flags); in xennet_handle_tx()
1518 spin_unlock_irqrestore(&queue->tx_lock, flags); in xennet_handle_tx()
1538 if (unlikely(queue->info->broken)) in xennet_handle_rx()
1541 spin_lock_irqsave(&queue->rx_cons_lock, flags); in xennet_handle_rx()
1542 work_queued = XEN_RING_NR_UNCONSUMED_RESPONSES(&queue->rx); in xennet_handle_rx()
1543 if (work_queued > queue->rx_rsp_unconsumed) { in xennet_handle_rx()
1544 queue->rx_rsp_unconsumed = work_queued; in xennet_handle_rx()
1546 } else if (unlikely(work_queued < queue->rx_rsp_unconsumed)) { in xennet_handle_rx()
1547 const struct device *dev = &queue->info->netdev->dev; in xennet_handle_rx()
1549 spin_unlock_irqrestore(&queue->rx_cons_lock, flags); in xennet_handle_rx()
1550 dev_alert(dev, "RX producer index going backwards\n"); in xennet_handle_rx()
1551 dev_alert(dev, "Disabled for further use\n"); in xennet_handle_rx()
1552 queue->info->broken = true; in xennet_handle_rx()
1555 spin_unlock_irqrestore(&queue->rx_cons_lock, flags); in xennet_handle_rx()
1557 if (likely(netif_carrier_ok(queue->info->netdev) && work_queued)) in xennet_handle_rx()
1558 napi_schedule(&queue->napi); in xennet_handle_rx()
1589 unsigned int num_queues = dev->real_num_tx_queues; in xennet_poll_controller()
1592 if (info->broken) in xennet_poll_controller()
1596 xennet_interrupt(0, &info->queues[i]); in xennet_poll_controller()
1609 err = xenbus_printf(XBT_NIL, np->xbdev->nodename, in talk_to_netback_xdp()
1610 "xdp-headroom", "%hu", in talk_to_netback_xdp()
1613 pr_warn("Error writing xdp-headroom\n"); in talk_to_netback_xdp()
1621 unsigned long max_mtu = XEN_PAGE_SIZE - XDP_PACKET_HEADROOM; in xennet_xdp_set()
1626 if (dev->mtu > max_mtu) { in xennet_xdp_set()
1628 return -EINVAL; in xennet_xdp_set()
1631 if (!np->netback_has_xdp_headroom) in xennet_xdp_set()
1634 xenbus_switch_state(np->xbdev, XenbusStateReconfiguring); in xennet_xdp_set()
1643 xenbus_read_driver_state(np->xbdev->otherend) == in xennet_xdp_set()
1645 np->netfront_xdp_enabled = true; in xennet_xdp_set()
1647 old_prog = rtnl_dereference(np->queues[0].xdp_prog); in xennet_xdp_set()
1650 bpf_prog_add(prog, dev->real_num_tx_queues); in xennet_xdp_set()
1652 for (i = 0; i < dev->real_num_tx_queues; ++i) in xennet_xdp_set()
1653 rcu_assign_pointer(np->queues[i].xdp_prog, prog); in xennet_xdp_set()
1656 for (i = 0; i < dev->real_num_tx_queues; ++i) in xennet_xdp_set()
1659 xenbus_switch_state(np->xbdev, XenbusStateConnected); in xennet_xdp_set()
1668 if (np->broken) in xennet_xdp()
1669 return -ENODEV; in xennet_xdp()
1671 switch (xdp->command) { in xennet_xdp()
1673 return xennet_xdp_set(dev, xdp->prog, xdp->extack); in xennet_xdp()
1675 return -EINVAL; in xennet_xdp()
1702 free_percpu(np->rx_stats); in xennet_free_netdev()
1703 free_percpu(np->tx_stats); in xennet_free_netdev()
1715 return ERR_PTR(-ENOMEM); in xennet_create_dev()
1718 np->xbdev = dev; in xennet_create_dev()
1720 np->queues = NULL; in xennet_create_dev()
1722 err = -ENOMEM; in xennet_create_dev()
1723 np->rx_stats = netdev_alloc_pcpu_stats(struct netfront_stats); in xennet_create_dev()
1724 if (np->rx_stats == NULL) in xennet_create_dev()
1726 np->tx_stats = netdev_alloc_pcpu_stats(struct netfront_stats); in xennet_create_dev()
1727 if (np->tx_stats == NULL) in xennet_create_dev()
1730 netdev->netdev_ops = &xennet_netdev_ops; in xennet_create_dev()
1732 netdev->features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM | in xennet_create_dev()
1734 netdev->hw_features = NETIF_F_SG | in xennet_create_dev()
1740 * will be adjusted by the call to netdev_update_features() in in xennet_create_dev()
1744 netdev->features |= netdev->hw_features; in xennet_create_dev()
1745 netdev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT | in xennet_create_dev()
1748 netdev->ethtool_ops = &xennet_ethtool_ops; in xennet_create_dev()
1749 netdev->min_mtu = ETH_MIN_MTU; in xennet_create_dev()
1750 netdev->max_mtu = XEN_NETIF_MAX_TX_SIZE; in xennet_create_dev()
1751 SET_NETDEV_DEV(netdev, &dev->dev); in xennet_create_dev()
1753 np->netdev = netdev; in xennet_create_dev()
1754 np->netfront_xdp_enabled = false; in xennet_create_dev()
1761 xenbus_read_driver_state(dev->otherend) != in xennet_create_dev()
1763 xenbus_read_driver_state(dev->otherend) != in xennet_create_dev()
1775 * Entry point to this code when a new device is created. Allocate the basic
1794 dev_set_drvdata(&dev->dev, info); in netfront_probe()
1796 info->netdev->sysfs_groups[0] = &xennet_dev_group; in netfront_probe()
1804 /* This frees the page as a side-effect */ in xennet_end_access()
1812 unsigned int num_queues = info->netdev->real_num_tx_queues; in xennet_disconnect_backend()
1814 netif_carrier_off(info->netdev); in xennet_disconnect_backend()
1816 for (i = 0; i < num_queues && info->queues; ++i) { in xennet_disconnect_backend()
1817 struct netfront_queue *queue = &info->queues[i]; in xennet_disconnect_backend()
1819 del_timer_sync(&queue->rx_refill_timer); in xennet_disconnect_backend()
1821 if (queue->tx_irq && (queue->tx_irq == queue->rx_irq)) in xennet_disconnect_backend()
1822 unbind_from_irqhandler(queue->tx_irq, queue); in xennet_disconnect_backend()
1823 if (queue->tx_irq && (queue->tx_irq != queue->rx_irq)) { in xennet_disconnect_backend()
1824 unbind_from_irqhandler(queue->tx_irq, queue); in xennet_disconnect_backend()
1825 unbind_from_irqhandler(queue->rx_irq, queue); in xennet_disconnect_backend()
1827 queue->tx_evtchn = queue->rx_evtchn = 0; in xennet_disconnect_backend()
1828 queue->tx_irq = queue->rx_irq = 0; in xennet_disconnect_backend()
1830 if (netif_running(info->netdev)) in xennet_disconnect_backend()
1831 napi_synchronize(&queue->napi); in xennet_disconnect_backend()
1835 gnttab_free_grant_references(queue->gref_tx_head); in xennet_disconnect_backend()
1836 gnttab_free_grant_references(queue->gref_rx_head); in xennet_disconnect_backend()
1839 xennet_end_access(queue->tx_ring_ref, queue->tx.sring); in xennet_disconnect_backend()
1840 xennet_end_access(queue->rx_ring_ref, queue->rx.sring); in xennet_disconnect_backend()
1842 queue->tx_ring_ref = INVALID_GRANT_REF; in xennet_disconnect_backend()
1843 queue->rx_ring_ref = INVALID_GRANT_REF; in xennet_disconnect_backend()
1844 queue->tx.sring = NULL; in xennet_disconnect_backend()
1845 queue->rx.sring = NULL; in xennet_disconnect_backend()
1847 page_pool_destroy(queue->page_pool); in xennet_disconnect_backend()
1852 * We are reconnecting to the backend, due to a suspend/resume, or a backend
1854 * leave the device-layer structures intact so that this is transparent to the
1859 struct netfront_info *info = dev_get_drvdata(&dev->dev); in netfront_resume()
1861 dev_dbg(&dev->dev, "%s\n", dev->nodename); in netfront_resume()
1863 netif_tx_lock_bh(info->netdev); in netfront_resume()
1864 netif_device_detach(info->netdev); in netfront_resume()
1865 netif_tx_unlock_bh(info->netdev); in netfront_resume()
1870 if (info->queues) in netfront_resume()
1882 macstr = s = xenbus_read(XBT_NIL, dev->nodename, "mac", NULL); in xen_net_read_mac()
1888 if ((s == e) || (*e != ((i == ETH_ALEN-1) ? '\0' : ':'))) { in xen_net_read_mac()
1890 return -ENOENT; in xen_net_read_mac()
1903 err = xenbus_alloc_evtchn(queue->info->xbdev, &queue->tx_evtchn); in setup_netfront_single()
1907 err = bind_evtchn_to_irqhandler_lateeoi(queue->tx_evtchn, in setup_netfront_single()
1909 queue->info->netdev->name, in setup_netfront_single()
1913 queue->rx_evtchn = queue->tx_evtchn; in setup_netfront_single()
1914 queue->rx_irq = queue->tx_irq = err; in setup_netfront_single()
1919 xenbus_free_evtchn(queue->info->xbdev, queue->tx_evtchn); in setup_netfront_single()
1920 queue->tx_evtchn = 0; in setup_netfront_single()
1929 err = xenbus_alloc_evtchn(queue->info->xbdev, &queue->tx_evtchn); in setup_netfront_split()
1932 err = xenbus_alloc_evtchn(queue->info->xbdev, &queue->rx_evtchn); in setup_netfront_split()
1936 snprintf(queue->tx_irq_name, sizeof(queue->tx_irq_name), in setup_netfront_split()
1937 "%s-tx", queue->name); in setup_netfront_split()
1938 err = bind_evtchn_to_irqhandler_lateeoi(queue->tx_evtchn, in setup_netfront_split()
1940 queue->tx_irq_name, queue); in setup_netfront_split()
1943 queue->tx_irq = err; in setup_netfront_split()
1945 snprintf(queue->rx_irq_name, sizeof(queue->rx_irq_name), in setup_netfront_split()
1946 "%s-rx", queue->name); in setup_netfront_split()
1947 err = bind_evtchn_to_irqhandler_lateeoi(queue->rx_evtchn, in setup_netfront_split()
1949 queue->rx_irq_name, queue); in setup_netfront_split()
1952 queue->rx_irq = err; in setup_netfront_split()
1957 unbind_from_irqhandler(queue->tx_irq, queue); in setup_netfront_split()
1958 queue->tx_irq = 0; in setup_netfront_split()
1960 xenbus_free_evtchn(queue->info->xbdev, queue->rx_evtchn); in setup_netfront_split()
1961 queue->rx_evtchn = 0; in setup_netfront_split()
1963 xenbus_free_evtchn(queue->info->xbdev, queue->tx_evtchn); in setup_netfront_split()
1964 queue->tx_evtchn = 0; in setup_netfront_split()
1976 queue->tx_ring_ref = INVALID_GRANT_REF; in setup_netfront()
1977 queue->rx_ring_ref = INVALID_GRANT_REF; in setup_netfront()
1978 queue->rx.sring = NULL; in setup_netfront()
1979 queue->tx.sring = NULL; in setup_netfront()
1982 1, &queue->tx_ring_ref); in setup_netfront()
1986 XEN_FRONT_RING_INIT(&queue->tx, txs, XEN_PAGE_SIZE); in setup_netfront()
1989 1, &queue->rx_ring_ref); in setup_netfront()
1993 XEN_FRONT_RING_INIT(&queue->rx, rxs, XEN_PAGE_SIZE); in setup_netfront()
1998 * a) feature-split-event-channels == 0 in setup_netfront()
1999 * b) feature-split-event-channels == 1 but failed to setup in setup_netfront()
2010 xenbus_teardown_ring((void **)&queue->rx.sring, 1, &queue->rx_ring_ref); in setup_netfront()
2011 xenbus_teardown_ring((void **)&queue->tx.sring, 1, &queue->tx_ring_ref); in setup_netfront()
2016 /* Queue-specific initialisation
2017 * This used to be done in xennet_create_dev() but must now
2018 * be run per-queue.
2026 spin_lock_init(&queue->tx_lock); in xennet_init_queue()
2027 spin_lock_init(&queue->rx_lock); in xennet_init_queue()
2028 spin_lock_init(&queue->rx_cons_lock); in xennet_init_queue()
2030 timer_setup(&queue->rx_refill_timer, rx_refill_timeout, 0); in xennet_init_queue()
2032 devid = strrchr(queue->info->xbdev->nodename, '/') + 1; in xennet_init_queue()
2033 snprintf(queue->name, sizeof(queue->name), "vif%s-q%u", in xennet_init_queue()
2034 devid, queue->id); in xennet_init_queue()
2037 queue->tx_skb_freelist = 0; in xennet_init_queue()
2038 queue->tx_pend_queue = TX_LINK_NONE; in xennet_init_queue()
2040 queue->tx_link[i] = i + 1; in xennet_init_queue()
2041 queue->grant_tx_ref[i] = INVALID_GRANT_REF; in xennet_init_queue()
2042 queue->grant_tx_page[i] = NULL; in xennet_init_queue()
2044 queue->tx_link[NET_TX_RING_SIZE - 1] = TX_LINK_NONE; in xennet_init_queue()
2048 queue->rx_skbs[i] = NULL; in xennet_init_queue()
2049 queue->grant_rx_ref[i] = INVALID_GRANT_REF; in xennet_init_queue()
2054 &queue->gref_tx_head) < 0) { in xennet_init_queue()
2056 err = -ENOMEM; in xennet_init_queue()
2060 /* A grant for every rx ring slot */ in xennet_init_queue()
2062 &queue->gref_rx_head) < 0) { in xennet_init_queue()
2063 pr_alert("can't alloc rx grant refs\n"); in xennet_init_queue()
2064 err = -ENOMEM; in xennet_init_queue()
2071 gnttab_free_grant_references(queue->gref_tx_head); in xennet_init_queue()
2079 /* Write the queue-specific keys into XenStore in the traditional in write_queue_xenstore_keys()
2081 * queues. in write_queue_xenstore_keys()
2083 struct xenbus_device *dev = queue->info->xbdev; in write_queue_xenstore_keys()
2089 /* Choose the correct place to write the keys */ in write_queue_xenstore_keys()
2091 pathsize = strlen(dev->nodename) + 10; in write_queue_xenstore_keys()
2094 err = -ENOMEM; in write_queue_xenstore_keys()
2098 snprintf(path, pathsize, "%s/queue-%u", in write_queue_xenstore_keys()
2099 dev->nodename, queue->id); in write_queue_xenstore_keys()
2101 path = (char *)dev->nodename; in write_queue_xenstore_keys()
2105 err = xenbus_printf(*xbt, path, "tx-ring-ref", "%u", in write_queue_xenstore_keys()
2106 queue->tx_ring_ref); in write_queue_xenstore_keys()
2108 message = "writing tx-ring-ref"; in write_queue_xenstore_keys()
2112 err = xenbus_printf(*xbt, path, "rx-ring-ref", "%u", in write_queue_xenstore_keys()
2113 queue->rx_ring_ref); in write_queue_xenstore_keys()
2115 message = "writing rx-ring-ref"; in write_queue_xenstore_keys()
2122 if (queue->tx_evtchn == queue->rx_evtchn) { in write_queue_xenstore_keys()
2125 "event-channel", "%u", queue->tx_evtchn); in write_queue_xenstore_keys()
2127 message = "writing event-channel"; in write_queue_xenstore_keys()
2133 "event-channel-tx", "%u", queue->tx_evtchn); in write_queue_xenstore_keys()
2135 message = "writing event-channel-tx"; in write_queue_xenstore_keys()
2140 "event-channel-rx", "%u", queue->rx_evtchn); in write_queue_xenstore_keys()
2142 message = "writing event-channel-rx"; in write_queue_xenstore_keys()
2168 .dev = &queue->info->netdev->dev, in xennet_create_page_pool()
2170 .max_len = XEN_PAGE_SIZE - XDP_PACKET_HEADROOM, in xennet_create_page_pool()
2173 queue->page_pool = page_pool_create(&pp_params); in xennet_create_page_pool()
2174 if (IS_ERR(queue->page_pool)) { in xennet_create_page_pool()
2175 err = PTR_ERR(queue->page_pool); in xennet_create_page_pool()
2176 queue->page_pool = NULL; in xennet_create_page_pool()
2180 err = xdp_rxq_info_reg(&queue->xdp_rxq, queue->info->netdev, in xennet_create_page_pool()
2181 queue->id, 0); in xennet_create_page_pool()
2183 netdev_err(queue->info->netdev, "xdp_rxq_info_reg failed\n"); in xennet_create_page_pool()
2187 err = xdp_rxq_info_reg_mem_model(&queue->xdp_rxq, in xennet_create_page_pool()
2188 MEM_TYPE_PAGE_POOL, queue->page_pool); in xennet_create_page_pool()
2190 netdev_err(queue->info->netdev, "xdp_rxq_info_reg_mem_model failed\n"); in xennet_create_page_pool()
2196 xdp_rxq_info_unreg(&queue->xdp_rxq); in xennet_create_page_pool()
2198 page_pool_destroy(queue->page_pool); in xennet_create_page_pool()
2199 queue->page_pool = NULL; in xennet_create_page_pool()
2209 info->queues = kcalloc(*num_queues, sizeof(struct netfront_queue), in xennet_create_queues()
2211 if (!info->queues) in xennet_create_queues()
2212 return -ENOMEM; in xennet_create_queues()
2215 struct netfront_queue *queue = &info->queues[i]; in xennet_create_queues()
2217 queue->id = i; in xennet_create_queues()
2218 queue->info = info; in xennet_create_queues()
2222 dev_warn(&info->xbdev->dev, in xennet_create_queues()
2223 "only created %d queues\n", i); in xennet_create_queues()
2228 /* use page pool recycling instead of buddy allocator */ in xennet_create_queues()
2231 dev_err(&info->xbdev->dev, "can't allocate page pool\n"); in xennet_create_queues()
2236 netif_napi_add(queue->info->netdev, &queue->napi, xennet_poll); in xennet_create_queues()
2237 if (netif_running(info->netdev)) in xennet_create_queues()
2238 napi_enable(&queue->napi); in xennet_create_queues()
2241 netif_set_real_num_tx_queues(info->netdev, *num_queues); in xennet_create_queues()
2244 dev_err(&info->xbdev->dev, "no queues\n"); in xennet_create_queues()
2245 return -EINVAL; in xennet_create_queues()
2264 info->netdev->irq = 0; in talk_to_netback()
2267 info->bounce = !xennet_trusted || in talk_to_netback()
2268 !xenbus_read_unsigned(dev->nodename, "trusted", 1); in talk_to_netback()
2270 /* Check if backend supports multiple queues */ in talk_to_netback()
2271 max_queues = xenbus_read_unsigned(info->xbdev->otherend, in talk_to_netback()
2272 "multi-queue-max-queues", 1); in talk_to_netback()
2275 /* Check feature-split-event-channels */ in talk_to_netback()
2276 feature_split_evtchn = xenbus_read_unsigned(info->xbdev->otherend, in talk_to_netback()
2277 "feature-split-event-channels", 0); in talk_to_netback()
2282 xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename); in talk_to_netback()
2285 eth_hw_addr_set(info->netdev, addr); in talk_to_netback()
2287 info->netback_has_xdp_headroom = xenbus_read_unsigned(info->xbdev->otherend, in talk_to_netback()
2288 "feature-xdp-headroom", 0); in talk_to_netback()
2289 if (info->netback_has_xdp_headroom) { in talk_to_netback()
2290 /* set the current xen-netfront xdp state */ in talk_to_netback()
2291 err = talk_to_netback_xdp(info, info->netfront_xdp_enabled ? in talk_to_netback()
2299 if (info->queues) in talk_to_netback()
2303 info->broken = false; in talk_to_netback()
2307 xenbus_dev_fatal(dev, err, "creating queues"); in talk_to_netback()
2308 kfree(info->queues); in talk_to_netback()
2309 info->queues = NULL; in talk_to_netback()
2314 /* Create shared ring, alloc event channel -- for each queue */ in talk_to_netback()
2316 queue = &info->queues[i]; in talk_to_netback()
2330 info->xbdev->otherend, "multi-queue-max-queues")) { in talk_to_netback()
2331 /* Write the number of queues */ in talk_to_netback()
2332 err = xenbus_printf(xbt, dev->nodename, in talk_to_netback()
2333 "multi-queue-num-queues", "%u", num_queues); in talk_to_netback()
2335 message = "writing multi-queue-num-queues"; in talk_to_netback()
2341 err = write_queue_xenstore_keys(&info->queues[0], &xbt, 0); /* flat */ in talk_to_netback()
2347 queue = &info->queues[i]; in talk_to_netback()
2354 /* The remaining keys are not queue-specific */ in talk_to_netback()
2355 err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u", in talk_to_netback()
2358 message = "writing request-rx-copy"; in talk_to_netback()
2362 err = xenbus_printf(xbt, dev->nodename, "feature-rx-notify", "%d", 1); in talk_to_netback()
2364 message = "writing feature-rx-notify"; in talk_to_netback()
2368 err = xenbus_printf(xbt, dev->nodename, "feature-sg", "%d", 1); in talk_to_netback()
2370 message = "writing feature-sg"; in talk_to_netback()
2374 err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv4", "%d", 1); in talk_to_netback()
2376 message = "writing feature-gso-tcpv4"; in talk_to_netback()
2380 err = xenbus_write(xbt, dev->nodename, "feature-gso-tcpv6", "1"); in talk_to_netback()
2382 message = "writing feature-gso-tcpv6"; in talk_to_netback()
2386 err = xenbus_write(xbt, dev->nodename, "feature-ipv6-csum-offload", in talk_to_netback()
2389 message = "writing feature-ipv6-csum-offload"; in talk_to_netback()
2395 if (err == -EAGAIN) in talk_to_netback()
2414 device_unregister(&dev->dev); in talk_to_netback()
2426 if (!xenbus_read_unsigned(np->xbdev->otherend, "feature-rx-copy", 0)) { in xennet_connect()
2427 dev_info(&dev->dev, in xennet_connect()
2429 return -ENODEV; in xennet_connect()
2432 err = talk_to_netback(np->xbdev, np); in xennet_connect()
2435 if (np->netback_has_xdp_headroom) in xennet_connect()
2437 if (np->bounce) in xennet_connect()
2438 dev_info(&np->xbdev->dev, in xennet_connect()
2439 "bouncing transmitted data to zeroed pages\n"); in xennet_connect()
2441 /* talk_to_netback() sets the correct number of queues */ in xennet_connect()
2442 num_queues = dev->real_num_tx_queues; in xennet_connect()
2444 if (dev->reg_state == NETREG_UNINITIALIZED) { in xennet_connect()
2448 device_unregister(&np->xbdev->dev); in xennet_connect()
2459 * ready to start sending and receiving packets and give the driver in xennet_connect()
2463 netif_tx_lock_bh(np->netdev); in xennet_connect()
2464 netif_device_attach(np->netdev); in xennet_connect()
2465 netif_tx_unlock_bh(np->netdev); in xennet_connect()
2467 netif_carrier_on(np->netdev); in xennet_connect()
2469 queue = &np->queues[j]; in xennet_connect()
2471 notify_remote_via_irq(queue->tx_irq); in xennet_connect()
2472 if (queue->tx_irq != queue->rx_irq) in xennet_connect()
2473 notify_remote_via_irq(queue->rx_irq); in xennet_connect()
2475 spin_lock_bh(&queue->rx_lock); in xennet_connect()
2477 spin_unlock_bh(&queue->rx_lock); in xennet_connect()
2489 struct netfront_info *np = dev_get_drvdata(&dev->dev); in netback_changed()
2490 struct net_device *netdev = np->netdev; in netback_changed()
2492 dev_dbg(&dev->dev, "%s\n", xenbus_strstate(backend_state)); in netback_changed()
2505 if (dev->state != XenbusStateInitialising) in netback_changed()
2517 if (dev->state == XenbusStateClosed) in netback_changed()
2542 return -EINVAL; in xennet_get_sset_count()
2593 return -EPERM; in store_rxbuf()
2597 return -EBADMSG; in store_rxbuf()
2624 if (xenbus_read_driver_state(dev->otherend) == XenbusStateClosed) in xennet_bus_close()
2629 xenbus_read_driver_state(dev->otherend) == in xennet_bus_close()
2631 xenbus_read_driver_state(dev->otherend) == in xennet_bus_close()
2633 xenbus_read_driver_state(dev->otherend) == in xennet_bus_close()
2638 if (xenbus_read_driver_state(dev->otherend) == XenbusStateClosed) in xennet_bus_close()
2644 xenbus_read_driver_state(dev->otherend) == in xennet_bus_close()
2646 xenbus_read_driver_state(dev->otherend) == in xennet_bus_close()
2654 struct netfront_info *info = dev_get_drvdata(&dev->dev); in xennet_remove()
2659 if (info->netdev->reg_state == NETREG_REGISTERED) in xennet_remove()
2660 unregister_netdev(info->netdev); in xennet_remove()
2662 if (info->queues) { in xennet_remove()
2667 xennet_free_netdev(info->netdev); in xennet_remove()
2686 return -ENODEV; in netif_init()
2689 return -ENODEV; in netif_init()
2693 /* Allow as many queues as there are CPUs inut max. 8 if user has not in netif_init()