Lines Matching full:rx
26 static void gve_rx_unfill_pages(struct gve_priv *priv, struct gve_rx_ring *rx) in gve_rx_unfill_pages() argument
28 u32 slots = rx->mask + 1; in gve_rx_unfill_pages()
31 if (rx->data.raw_addressing) { in gve_rx_unfill_pages()
33 gve_rx_free_buffer(&priv->pdev->dev, &rx->data.page_info[i], in gve_rx_unfill_pages()
34 &rx->data.data_ring[i]); in gve_rx_unfill_pages()
37 page_ref_sub(rx->data.page_info[i].page, in gve_rx_unfill_pages()
38 rx->data.page_info[i].pagecnt_bias - 1); in gve_rx_unfill_pages()
39 gve_unassign_qpl(priv, rx->data.qpl->id); in gve_rx_unfill_pages()
40 rx->data.qpl = NULL; in gve_rx_unfill_pages()
42 for (i = 0; i < rx->qpl_copy_pool_mask + 1; i++) { in gve_rx_unfill_pages()
43 page_ref_sub(rx->qpl_copy_pool[i].page, in gve_rx_unfill_pages()
44 rx->qpl_copy_pool[i].pagecnt_bias - 1); in gve_rx_unfill_pages()
45 put_page(rx->qpl_copy_pool[i].page); in gve_rx_unfill_pages()
48 kvfree(rx->data.page_info); in gve_rx_unfill_pages()
49 rx->data.page_info = NULL; in gve_rx_unfill_pages()
54 struct gve_rx_ring *rx = &priv->rx[idx]; in gve_rx_free_ring() local
56 u32 slots = rx->mask + 1; in gve_rx_free_ring()
62 dma_free_coherent(dev, bytes, rx->desc.desc_ring, rx->desc.bus); in gve_rx_free_ring()
63 rx->desc.desc_ring = NULL; in gve_rx_free_ring()
65 dma_free_coherent(dev, sizeof(*rx->q_resources), in gve_rx_free_ring()
66 rx->q_resources, rx->q_resources_bus); in gve_rx_free_ring()
67 rx->q_resources = NULL; in gve_rx_free_ring()
69 gve_rx_unfill_pages(priv, rx); in gve_rx_free_ring()
71 bytes = sizeof(*rx->data.data_ring) * slots; in gve_rx_free_ring()
72 dma_free_coherent(dev, bytes, rx->data.data_ring, in gve_rx_free_ring()
73 rx->data.data_bus); in gve_rx_free_ring()
74 rx->data.data_ring = NULL; in gve_rx_free_ring()
76 kvfree(rx->qpl_copy_pool); in gve_rx_free_ring()
77 rx->qpl_copy_pool = NULL; in gve_rx_free_ring()
79 netif_dbg(priv, drv, priv->dev, "freed rx ring %d\n", idx); in gve_rx_free_ring()
111 static int gve_prefill_rx_pages(struct gve_rx_ring *rx) in gve_prefill_rx_pages() argument
113 struct gve_priv *priv = rx->gve; in gve_prefill_rx_pages()
119 /* Allocate one page per Rx queue slot. Each page is split into two in gve_prefill_rx_pages()
122 slots = rx->mask + 1; in gve_prefill_rx_pages()
124 rx->data.page_info = kvzalloc(slots * in gve_prefill_rx_pages()
125 sizeof(*rx->data.page_info), GFP_KERNEL); in gve_prefill_rx_pages()
126 if (!rx->data.page_info) in gve_prefill_rx_pages()
129 if (!rx->data.raw_addressing) { in gve_prefill_rx_pages()
130 rx->data.qpl = gve_assign_rx_qpl(priv, rx->q_num); in gve_prefill_rx_pages()
131 if (!rx->data.qpl) { in gve_prefill_rx_pages()
132 kvfree(rx->data.page_info); in gve_prefill_rx_pages()
133 rx->data.page_info = NULL; in gve_prefill_rx_pages()
138 if (!rx->data.raw_addressing) { in gve_prefill_rx_pages()
139 struct page *page = rx->data.qpl->pages[i]; in gve_prefill_rx_pages()
142 gve_setup_rx_buffer(&rx->data.page_info[i], addr, page, in gve_prefill_rx_pages()
143 &rx->data.data_ring[i].qpl_offset); in gve_prefill_rx_pages()
146 err = gve_rx_alloc_buffer(priv, &priv->pdev->dev, &rx->data.page_info[i], in gve_prefill_rx_pages()
147 &rx->data.data_ring[i]); in gve_prefill_rx_pages()
152 if (!rx->data.raw_addressing) { in gve_prefill_rx_pages()
153 for (j = 0; j < rx->qpl_copy_pool_mask + 1; j++) { in gve_prefill_rx_pages()
161 rx->qpl_copy_pool[j].page = page; in gve_prefill_rx_pages()
162 rx->qpl_copy_pool[j].page_offset = 0; in gve_prefill_rx_pages()
163 rx->qpl_copy_pool[j].page_address = page_address(page); in gve_prefill_rx_pages()
167 rx->qpl_copy_pool[j].pagecnt_bias = INT_MAX; in gve_prefill_rx_pages()
176 page_ref_sub(rx->qpl_copy_pool[j].page, in gve_prefill_rx_pages()
177 rx->qpl_copy_pool[j].pagecnt_bias - 1); in gve_prefill_rx_pages()
178 put_page(rx->qpl_copy_pool[j].page); in gve_prefill_rx_pages()
185 page_ref_sub(rx->data.page_info[i].page, in gve_prefill_rx_pages()
186 rx->data.page_info[i].pagecnt_bias - 1); in gve_prefill_rx_pages()
188 gve_unassign_qpl(priv, rx->data.qpl->id); in gve_prefill_rx_pages()
189 rx->data.qpl = NULL; in gve_prefill_rx_pages()
196 &rx->data.page_info[i], in gve_prefill_rx_pages()
197 &rx->data.data_ring[i]); in gve_prefill_rx_pages()
212 struct gve_rx_ring *rx = &priv->rx[idx]; in gve_rx_alloc_ring() local
219 netif_dbg(priv, drv, priv->dev, "allocating rx ring\n"); in gve_rx_alloc_ring()
221 memset(rx, 0, sizeof(*rx)); in gve_rx_alloc_ring()
223 rx->gve = priv; in gve_rx_alloc_ring()
224 rx->q_num = idx; in gve_rx_alloc_ring()
227 rx->mask = slots - 1; in gve_rx_alloc_ring()
228 rx->data.raw_addressing = priv->queue_format == GVE_GQI_RDA_FORMAT; in gve_rx_alloc_ring()
230 /* alloc rx data ring */ in gve_rx_alloc_ring()
231 bytes = sizeof(*rx->data.data_ring) * slots; in gve_rx_alloc_ring()
232 rx->data.data_ring = dma_alloc_coherent(hdev, bytes, in gve_rx_alloc_ring()
233 &rx->data.data_bus, in gve_rx_alloc_ring()
235 if (!rx->data.data_ring) in gve_rx_alloc_ring()
238 rx->qpl_copy_pool_mask = min_t(u32, U32_MAX, slots * 2) - 1; in gve_rx_alloc_ring()
239 rx->qpl_copy_pool_head = 0; in gve_rx_alloc_ring()
240 rx->qpl_copy_pool = kvcalloc(rx->qpl_copy_pool_mask + 1, in gve_rx_alloc_ring()
241 sizeof(rx->qpl_copy_pool[0]), in gve_rx_alloc_ring()
244 if (!rx->qpl_copy_pool) { in gve_rx_alloc_ring()
249 filled_pages = gve_prefill_rx_pages(rx); in gve_rx_alloc_ring()
254 rx->fill_cnt = filled_pages; in gve_rx_alloc_ring()
259 rx->q_resources = in gve_rx_alloc_ring()
261 sizeof(*rx->q_resources), in gve_rx_alloc_ring()
262 &rx->q_resources_bus, in gve_rx_alloc_ring()
264 if (!rx->q_resources) { in gve_rx_alloc_ring()
268 netif_dbg(priv, drv, priv->dev, "rx[%d]->data.data_bus=%lx\n", idx, in gve_rx_alloc_ring()
269 (unsigned long)rx->data.data_bus); in gve_rx_alloc_ring()
271 /* alloc rx desc ring */ in gve_rx_alloc_ring()
273 rx->desc.desc_ring = dma_alloc_coherent(hdev, bytes, &rx->desc.bus, in gve_rx_alloc_ring()
275 if (!rx->desc.desc_ring) { in gve_rx_alloc_ring()
279 rx->cnt = 0; in gve_rx_alloc_ring()
280 rx->db_threshold = priv->rx_desc_cnt / 2; in gve_rx_alloc_ring()
281 rx->desc.seqno = 1; in gve_rx_alloc_ring()
286 rx->packet_buffer_size = GVE_DEFAULT_RX_BUFFER_SIZE; in gve_rx_alloc_ring()
287 gve_rx_ctx_clear(&rx->ctx); in gve_rx_alloc_ring()
293 dma_free_coherent(hdev, sizeof(*rx->q_resources), in gve_rx_alloc_ring()
294 rx->q_resources, rx->q_resources_bus); in gve_rx_alloc_ring()
295 rx->q_resources = NULL; in gve_rx_alloc_ring()
297 gve_rx_unfill_pages(priv, rx); in gve_rx_alloc_ring()
299 kvfree(rx->qpl_copy_pool); in gve_rx_alloc_ring()
300 rx->qpl_copy_pool = NULL; in gve_rx_alloc_ring()
302 bytes = sizeof(*rx->data.data_ring) * slots; in gve_rx_alloc_ring()
303 dma_free_coherent(hdev, bytes, rx->data.data_ring, rx->data.data_bus); in gve_rx_alloc_ring()
304 rx->data.data_ring = NULL; in gve_rx_alloc_ring()
318 "Failed to alloc rx ring=%d: err=%d\n", in gve_rx_alloc_rings()
341 void gve_rx_write_doorbell(struct gve_priv *priv, struct gve_rx_ring *rx) in gve_rx_write_doorbell() argument
343 u32 db_idx = be32_to_cpu(rx->q_resources->db_index); in gve_rx_write_doorbell()
345 iowrite32be(rx->fill_cnt, &priv->db_bar2[db_idx]); in gve_rx_write_doorbell()
445 static struct sk_buff *gve_rx_copy_to_pool(struct gve_rx_ring *rx, in gve_rx_copy_to_pool() argument
449 u32 pool_idx = rx->qpl_copy_pool_head & rx->qpl_copy_pool_mask; in gve_rx_copy_to_pool()
452 struct gve_rx_ctx *ctx = &rx->ctx; in gve_rx_copy_to_pool()
457 copy_page_info = &rx->qpl_copy_pool[pool_idx]; in gve_rx_copy_to_pool()
462 gve_schedule_reset(rx->gve); in gve_rx_copy_to_pool()
476 rx->qpl_copy_pool_head++; in gve_rx_copy_to_pool()
492 u64_stats_update_begin(&rx->statss); in gve_rx_copy_to_pool()
493 rx->rx_frag_copy_cnt++; in gve_rx_copy_to_pool()
494 rx->rx_frag_alloc_cnt++; in gve_rx_copy_to_pool()
495 u64_stats_update_end(&rx->statss); in gve_rx_copy_to_pool()
505 rx->packet_buffer_size, len, ctx); in gve_rx_copy_to_pool()
517 rx->qpl_copy_pool_head++; in gve_rx_copy_to_pool()
518 prefetch(rx->qpl_copy_pool[rx->qpl_copy_pool_head & rx->qpl_copy_pool_mask].page); in gve_rx_copy_to_pool()
523 u64_stats_update_begin(&rx->statss); in gve_rx_copy_to_pool()
524 rx->rx_frag_copy_cnt++; in gve_rx_copy_to_pool()
525 u64_stats_update_end(&rx->statss); in gve_rx_copy_to_pool()
532 struct gve_rx_ring *rx, struct gve_rx_slot_page_info *page_info, in gve_rx_qpl() argument
536 struct gve_rx_ctx *ctx = &rx->ctx; in gve_rx_qpl()
545 skb = gve_rx_add_frags(napi, page_info, rx->packet_buffer_size, len, ctx); in gve_rx_qpl()
553 skb = gve_rx_copy_to_pool(rx, page_info, len, napi); in gve_rx_qpl()
558 static struct sk_buff *gve_rx_skb(struct gve_priv *priv, struct gve_rx_ring *rx, in gve_rx_skb() argument
564 struct gve_rx_ctx *ctx = &rx->ctx; in gve_rx_skb()
571 u64_stats_update_begin(&rx->statss); in gve_rx_skb()
572 rx->rx_copied_pkt++; in gve_rx_skb()
573 rx->rx_frag_copy_cnt++; in gve_rx_skb()
574 rx->rx_copybreak_pkt++; in gve_rx_skb()
575 u64_stats_update_end(&rx->statss); in gve_rx_skb()
586 u64_stats_update_begin(&rx->statss); in gve_rx_skb()
587 rx->rx_frag_flip_cnt++; in gve_rx_skb()
588 u64_stats_update_end(&rx->statss); in gve_rx_skb()
591 if (rx->data.raw_addressing) { in gve_rx_skb()
595 rx->packet_buffer_size, ctx); in gve_rx_skb()
597 skb = gve_rx_qpl(&priv->pdev->dev, netdev, rx, in gve_rx_skb()
605 struct gve_rx_ring *rx, in gve_xsk_pool_redirect() argument
612 if (rx->xsk_pool->frame_len < len) in gve_xsk_pool_redirect()
614 xdp = xsk_buff_alloc(rx->xsk_pool); in gve_xsk_pool_redirect()
616 u64_stats_update_begin(&rx->statss); in gve_xsk_pool_redirect()
617 rx->xdp_alloc_fails++; in gve_xsk_pool_redirect()
618 u64_stats_update_end(&rx->statss); in gve_xsk_pool_redirect()
629 static int gve_xdp_redirect(struct net_device *dev, struct gve_rx_ring *rx, in gve_xdp_redirect() argument
638 if (rx->xsk_pool) in gve_xdp_redirect()
639 return gve_xsk_pool_redirect(dev, rx, orig->data, in gve_xdp_redirect()
644 frame = page_frag_alloc(&rx->page_cache, total_len, GFP_ATOMIC); in gve_xdp_redirect()
646 u64_stats_update_begin(&rx->statss); in gve_xdp_redirect()
647 rx->xdp_alloc_fails++; in gve_xdp_redirect()
648 u64_stats_update_end(&rx->statss); in gve_xdp_redirect()
651 xdp_init_buff(&new, total_len, &rx->xdp_rxq); in gve_xdp_redirect()
662 static void gve_xdp_done(struct gve_priv *priv, struct gve_rx_ring *rx, in gve_xdp_done() argument
676 tx_qid = gve_xdp_tx_queue_id(priv, rx->q_num); in gve_xdp_done()
684 u64_stats_update_begin(&rx->statss); in gve_xdp_done()
685 rx->xdp_tx_errors++; in gve_xdp_done()
686 u64_stats_update_end(&rx->statss); in gve_xdp_done()
690 err = gve_xdp_redirect(priv->dev, rx, xdp, xprog); in gve_xdp_done()
693 u64_stats_update_begin(&rx->statss); in gve_xdp_done()
694 rx->xdp_redirect_errors++; in gve_xdp_done()
695 u64_stats_update_end(&rx->statss); in gve_xdp_done()
699 u64_stats_update_begin(&rx->statss); in gve_xdp_done()
701 rx->xdp_actions[xdp_act]++; in gve_xdp_done()
702 u64_stats_update_end(&rx->statss); in gve_xdp_done()
706 static void gve_rx(struct gve_rx_ring *rx, netdev_features_t feat, in gve_rx() argument
713 struct gve_rx_ctx *ctx = &rx->ctx; in gve_rx()
715 struct gve_priv *priv = rx->gve; in gve_rx()
723 struct napi_struct *napi = &priv->ntfy_blocks[rx->ntfy_id].napi; in gve_rx()
738 if (unlikely(frag_size > rx->packet_buffer_size)) { in gve_rx()
740 frag_size, rx->packet_buffer_size); in gve_rx()
743 gve_schedule_reset(rx->gve); in gve_rx()
748 page_info = &rx->data.page_info[(idx + 2) & rx->mask]; in gve_rx()
754 page_info = &rx->data.page_info[idx]; in gve_rx()
755 data_slot = &rx->data.data_ring[idx]; in gve_rx()
756 page_bus = (rx->data.raw_addressing) ? in gve_rx()
758 rx->data.qpl->page_buses[idx]; in gve_rx()
770 xdp_init_buff(&xdp, rx->packet_buffer_size, &rx->xdp_rxq); in gve_rx()
777 gve_xdp_done(priv, rx, &xdp, xprog, xdp_act); in gve_rx()
785 u64_stats_update_begin(&rx->statss); in gve_rx()
786 rx->xdp_actions[XDP_PASS]++; in gve_rx()
787 u64_stats_update_end(&rx->statss); in gve_rx()
790 skb = gve_rx_skb(priv, rx, page_info, napi, len, in gve_rx()
793 u64_stats_update_begin(&rx->statss); in gve_rx()
794 rx->rx_skb_alloc_fail++; in gve_rx()
795 u64_stats_update_end(&rx->statss); in gve_rx()
821 skb_record_rx_queue(skb, rx->q_num); in gve_rx()
843 bool gve_rx_work_pending(struct gve_rx_ring *rx) in gve_rx_work_pending() argument
849 next_idx = rx->cnt & rx->mask; in gve_rx_work_pending()
850 desc = rx->desc.desc_ring + next_idx; in gve_rx_work_pending()
854 return (GVE_SEQNO(flags_seq) == rx->desc.seqno); in gve_rx_work_pending()
857 static bool gve_rx_refill_buffers(struct gve_priv *priv, struct gve_rx_ring *rx) in gve_rx_refill_buffers() argument
859 int refill_target = rx->mask + 1; in gve_rx_refill_buffers()
860 u32 fill_cnt = rx->fill_cnt; in gve_rx_refill_buffers()
862 while (fill_cnt - rx->cnt < refill_target) { in gve_rx_refill_buffers()
864 u32 idx = fill_cnt & rx->mask; in gve_rx_refill_buffers()
866 page_info = &rx->data.page_info[idx]; in gve_rx_refill_buffers()
872 &rx->data.data_ring[idx]; in gve_rx_refill_buffers()
887 if (!rx->data.raw_addressing) in gve_rx_refill_buffers()
894 &rx->data.data_ring[idx]; in gve_rx_refill_buffers()
900 u64_stats_update_begin(&rx->statss); in gve_rx_refill_buffers()
901 rx->rx_buf_alloc_fail++; in gve_rx_refill_buffers()
902 u64_stats_update_end(&rx->statss); in gve_rx_refill_buffers()
909 rx->fill_cnt = fill_cnt; in gve_rx_refill_buffers()
913 static int gve_clean_rx_done(struct gve_rx_ring *rx, int budget, in gve_clean_rx_done() argument
916 u64 xdp_redirects = rx->xdp_actions[XDP_REDIRECT]; in gve_clean_rx_done()
917 u64 xdp_txs = rx->xdp_actions[XDP_TX]; in gve_clean_rx_done()
918 struct gve_rx_ctx *ctx = &rx->ctx; in gve_clean_rx_done()
919 struct gve_priv *priv = rx->gve; in gve_clean_rx_done()
922 u32 idx = rx->cnt & rx->mask; in gve_clean_rx_done()
925 struct gve_rx_desc *desc = &rx->desc.desc_ring[idx]; in gve_clean_rx_done()
928 while ((GVE_SEQNO(desc->flags_seq) == rx->desc.seqno) && in gve_clean_rx_done()
930 next_desc = &rx->desc.desc_ring[(idx + 1) & rx->mask]; in gve_clean_rx_done()
933 gve_rx(rx, feat, desc, idx, &cnts); in gve_clean_rx_done()
935 rx->cnt++; in gve_clean_rx_done()
936 idx = rx->cnt & rx->mask; in gve_clean_rx_done()
937 desc = &rx->desc.desc_ring[idx]; in gve_clean_rx_done()
938 rx->desc.seqno = gve_next_seqno(rx->desc.seqno); in gve_clean_rx_done()
944 struct napi_struct *napi = &priv->ntfy_blocks[rx->ntfy_id].napi; in gve_clean_rx_done()
947 gve_rx_ctx_clear(&rx->ctx); in gve_clean_rx_done()
949 GVE_SEQNO(desc->flags_seq), rx->desc.seqno); in gve_clean_rx_done()
950 gve_schedule_reset(rx->gve); in gve_clean_rx_done()
953 if (!work_done && rx->fill_cnt - rx->cnt > rx->db_threshold) in gve_clean_rx_done()
957 u64_stats_update_begin(&rx->statss); in gve_clean_rx_done()
958 rx->rpackets += cnts.ok_pkt_cnt; in gve_clean_rx_done()
959 rx->rbytes += cnts.ok_pkt_bytes; in gve_clean_rx_done()
960 rx->rx_cont_packet_cnt += cnts.cont_pkt_cnt; in gve_clean_rx_done()
961 rx->rx_desc_err_dropped_pkt += cnts.desc_err_pkt_cnt; in gve_clean_rx_done()
962 u64_stats_update_end(&rx->statss); in gve_clean_rx_done()
965 if (xdp_txs != rx->xdp_actions[XDP_TX]) in gve_clean_rx_done()
966 gve_xdp_tx_flush(priv, rx->q_num); in gve_clean_rx_done()
968 if (xdp_redirects != rx->xdp_actions[XDP_REDIRECT]) in gve_clean_rx_done()
972 if (!rx->data.raw_addressing) { in gve_clean_rx_done()
974 rx->fill_cnt += work_done; in gve_clean_rx_done()
975 } else if (rx->fill_cnt - rx->cnt <= rx->db_threshold) { in gve_clean_rx_done()
979 if (!gve_rx_refill_buffers(priv, rx)) in gve_clean_rx_done()
985 if (rx->fill_cnt - rx->cnt <= rx->db_threshold) { in gve_clean_rx_done()
986 gve_rx_write_doorbell(priv, rx); in gve_clean_rx_done()
991 gve_rx_write_doorbell(priv, rx); in gve_clean_rx_done()
997 struct gve_rx_ring *rx = block->rx; in gve_rx_poll() local
1004 work_done = gve_clean_rx_done(rx, budget, feat); in gve_rx_poll()