Lines Matching refs: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()
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()
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
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()
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()
269 (unsigned long)rx->data.data_bus); in gve_rx_alloc_ring()
279 rx->desc.desc_ring = dma_alloc_coherent(hdev, bytes, &rx->desc.bus, in gve_rx_alloc_ring()
281 if (!rx->desc.desc_ring) { in gve_rx_alloc_ring()
285 rx->cnt = 0; in gve_rx_alloc_ring()
286 rx->db_threshold = priv->rx_desc_cnt / 2; in gve_rx_alloc_ring()
287 rx->desc.seqno = 1; in gve_rx_alloc_ring()
292 rx->packet_buffer_size = PAGE_SIZE / 2; in gve_rx_alloc_ring()
293 gve_rx_ctx_clear(&rx->ctx); in gve_rx_alloc_ring()
299 dma_free_coherent(hdev, sizeof(*rx->q_resources), in gve_rx_alloc_ring()
300 rx->q_resources, rx->q_resources_bus); in gve_rx_alloc_ring()
301 rx->q_resources = NULL; in gve_rx_alloc_ring()
303 gve_rx_unfill_pages(priv, rx); in gve_rx_alloc_ring()
305 kvfree(rx->qpl_copy_pool); in gve_rx_alloc_ring()
306 rx->qpl_copy_pool = NULL; in gve_rx_alloc_ring()
308 bytes = sizeof(*rx->data.data_ring) * slots; in gve_rx_alloc_ring()
309 dma_free_coherent(hdev, bytes, rx->data.data_ring, rx->data.data_bus); in gve_rx_alloc_ring()
310 rx->data.data_ring = NULL; in gve_rx_alloc_ring()
347 void gve_rx_write_doorbell(struct gve_priv *priv, struct gve_rx_ring *rx) in gve_rx_write_doorbell() argument
349 u32 db_idx = be32_to_cpu(rx->q_resources->db_index); in gve_rx_write_doorbell()
351 iowrite32be(rx->fill_cnt, &priv->db_bar2[db_idx]); in gve_rx_write_doorbell()
451 static struct sk_buff *gve_rx_copy_to_pool(struct gve_rx_ring *rx, in gve_rx_copy_to_pool() argument
455 u32 pool_idx = rx->qpl_copy_pool_head & rx->qpl_copy_pool_mask; in gve_rx_copy_to_pool()
458 struct gve_rx_ctx *ctx = &rx->ctx; in gve_rx_copy_to_pool()
463 copy_page_info = &rx->qpl_copy_pool[pool_idx]; in gve_rx_copy_to_pool()
468 gve_schedule_reset(rx->gve); in gve_rx_copy_to_pool()
482 rx->qpl_copy_pool_head++; in gve_rx_copy_to_pool()
498 u64_stats_update_begin(&rx->statss); in gve_rx_copy_to_pool()
499 rx->rx_frag_copy_cnt++; in gve_rx_copy_to_pool()
500 rx->rx_frag_alloc_cnt++; in gve_rx_copy_to_pool()
501 u64_stats_update_end(&rx->statss); in gve_rx_copy_to_pool()
511 rx->packet_buffer_size, len, ctx); in gve_rx_copy_to_pool()
516 copy_page_info->page_offset += rx->packet_buffer_size; in gve_rx_copy_to_pool()
524 rx->qpl_copy_pool_head++; in gve_rx_copy_to_pool()
525 prefetch(rx->qpl_copy_pool[rx->qpl_copy_pool_head & rx->qpl_copy_pool_mask].page); in gve_rx_copy_to_pool()
530 u64_stats_update_begin(&rx->statss); in gve_rx_copy_to_pool()
531 rx->rx_frag_copy_cnt++; in gve_rx_copy_to_pool()
532 u64_stats_update_end(&rx->statss); in gve_rx_copy_to_pool()
539 struct gve_rx_ring *rx, struct gve_rx_slot_page_info *page_info, in gve_rx_qpl() argument
543 struct gve_rx_ctx *ctx = &rx->ctx; in gve_rx_qpl()
552 skb = gve_rx_add_frags(napi, page_info, rx->packet_buffer_size, len, ctx); in gve_rx_qpl()
560 skb = gve_rx_copy_to_pool(rx, page_info, len, napi); in gve_rx_qpl()
565 static struct sk_buff *gve_rx_skb(struct gve_priv *priv, struct gve_rx_ring *rx, in gve_rx_skb() argument
571 struct gve_rx_ctx *ctx = &rx->ctx; in gve_rx_skb()
578 u64_stats_update_begin(&rx->statss); in gve_rx_skb()
579 rx->rx_copied_pkt++; in gve_rx_skb()
580 rx->rx_frag_copy_cnt++; in gve_rx_skb()
581 rx->rx_copybreak_pkt++; in gve_rx_skb()
582 u64_stats_update_end(&rx->statss); in gve_rx_skb()
593 u64_stats_update_begin(&rx->statss); in gve_rx_skb()
594 rx->rx_frag_flip_cnt++; in gve_rx_skb()
595 u64_stats_update_end(&rx->statss); in gve_rx_skb()
598 if (rx->data.raw_addressing) { in gve_rx_skb()
602 rx->packet_buffer_size, ctx); in gve_rx_skb()
604 skb = gve_rx_qpl(&priv->pdev->dev, netdev, rx, in gve_rx_skb()
612 struct gve_rx_ring *rx, in gve_xsk_pool_redirect() argument
619 if (rx->xsk_pool->frame_len < len) in gve_xsk_pool_redirect()
621 xdp = xsk_buff_alloc(rx->xsk_pool); in gve_xsk_pool_redirect()
623 u64_stats_update_begin(&rx->statss); in gve_xsk_pool_redirect()
624 rx->xdp_alloc_fails++; in gve_xsk_pool_redirect()
625 u64_stats_update_end(&rx->statss); in gve_xsk_pool_redirect()
636 static int gve_xdp_redirect(struct net_device *dev, struct gve_rx_ring *rx, in gve_xdp_redirect() argument
645 if (rx->xsk_pool) in gve_xdp_redirect()
646 return gve_xsk_pool_redirect(dev, rx, orig->data, in gve_xdp_redirect()
651 frame = page_frag_alloc(&rx->page_cache, total_len, GFP_ATOMIC); in gve_xdp_redirect()
653 u64_stats_update_begin(&rx->statss); in gve_xdp_redirect()
654 rx->xdp_alloc_fails++; in gve_xdp_redirect()
655 u64_stats_update_end(&rx->statss); in gve_xdp_redirect()
658 xdp_init_buff(&new, total_len, &rx->xdp_rxq); in gve_xdp_redirect()
669 static void gve_xdp_done(struct gve_priv *priv, struct gve_rx_ring *rx, in gve_xdp_done() argument
683 tx_qid = gve_xdp_tx_queue_id(priv, rx->q_num); in gve_xdp_done()
691 u64_stats_update_begin(&rx->statss); in gve_xdp_done()
692 rx->xdp_tx_errors++; in gve_xdp_done()
693 u64_stats_update_end(&rx->statss); in gve_xdp_done()
697 err = gve_xdp_redirect(priv->dev, rx, xdp, xprog); in gve_xdp_done()
700 u64_stats_update_begin(&rx->statss); in gve_xdp_done()
701 rx->xdp_redirect_errors++; in gve_xdp_done()
702 u64_stats_update_end(&rx->statss); in gve_xdp_done()
706 u64_stats_update_begin(&rx->statss); in gve_xdp_done()
708 rx->xdp_actions[xdp_act]++; in gve_xdp_done()
709 u64_stats_update_end(&rx->statss); in gve_xdp_done()
713 static void gve_rx(struct gve_rx_ring *rx, netdev_features_t feat, in gve_rx() argument
720 struct gve_rx_ctx *ctx = &rx->ctx; in gve_rx()
722 struct gve_priv *priv = rx->gve; in gve_rx()
730 struct napi_struct *napi = &priv->ntfy_blocks[rx->ntfy_id].napi; in gve_rx()
745 if (unlikely(frag_size > rx->packet_buffer_size)) { in gve_rx()
747 frag_size, rx->packet_buffer_size); in gve_rx()
750 gve_schedule_reset(rx->gve); in gve_rx()
755 page_info = &rx->data.page_info[(idx + 2) & rx->mask]; in gve_rx()
761 page_info = &rx->data.page_info[idx]; in gve_rx()
762 data_slot = &rx->data.data_ring[idx]; in gve_rx()
763 page_bus = (rx->data.raw_addressing) ? in gve_rx()
765 rx->data.qpl->page_buses[idx]; in gve_rx()
777 xdp_init_buff(&xdp, rx->packet_buffer_size, &rx->xdp_rxq); in gve_rx()
784 gve_xdp_done(priv, rx, &xdp, xprog, xdp_act); in gve_rx()
792 u64_stats_update_begin(&rx->statss); in gve_rx()
793 rx->xdp_actions[XDP_PASS]++; in gve_rx()
794 u64_stats_update_end(&rx->statss); in gve_rx()
797 skb = gve_rx_skb(priv, rx, page_info, napi, len, in gve_rx()
800 u64_stats_update_begin(&rx->statss); in gve_rx()
801 rx->rx_skb_alloc_fail++; in gve_rx()
802 u64_stats_update_end(&rx->statss); in gve_rx()
828 skb_record_rx_queue(skb, rx->q_num); in gve_rx()
850 bool gve_rx_work_pending(struct gve_rx_ring *rx) in gve_rx_work_pending() argument
856 next_idx = rx->cnt & rx->mask; in gve_rx_work_pending()
857 desc = rx->desc.desc_ring + next_idx; in gve_rx_work_pending()
861 return (GVE_SEQNO(flags_seq) == rx->desc.seqno); in gve_rx_work_pending()
864 static bool gve_rx_refill_buffers(struct gve_priv *priv, struct gve_rx_ring *rx) in gve_rx_refill_buffers() argument
866 int refill_target = rx->mask + 1; in gve_rx_refill_buffers()
867 u32 fill_cnt = rx->fill_cnt; in gve_rx_refill_buffers()
869 while (fill_cnt - rx->cnt < refill_target) { in gve_rx_refill_buffers()
871 u32 idx = fill_cnt & rx->mask; in gve_rx_refill_buffers()
873 page_info = &rx->data.page_info[idx]; in gve_rx_refill_buffers()
879 &rx->data.data_ring[idx]; in gve_rx_refill_buffers()
894 if (!rx->data.raw_addressing) in gve_rx_refill_buffers()
901 &rx->data.data_ring[idx]; in gve_rx_refill_buffers()
907 u64_stats_update_begin(&rx->statss); in gve_rx_refill_buffers()
908 rx->rx_buf_alloc_fail++; in gve_rx_refill_buffers()
909 u64_stats_update_end(&rx->statss); in gve_rx_refill_buffers()
916 rx->fill_cnt = fill_cnt; in gve_rx_refill_buffers()
920 static int gve_clean_rx_done(struct gve_rx_ring *rx, int budget, in gve_clean_rx_done() argument
923 u64 xdp_redirects = rx->xdp_actions[XDP_REDIRECT]; in gve_clean_rx_done()
924 u64 xdp_txs = rx->xdp_actions[XDP_TX]; in gve_clean_rx_done()
925 struct gve_rx_ctx *ctx = &rx->ctx; in gve_clean_rx_done()
926 struct gve_priv *priv = rx->gve; in gve_clean_rx_done()
929 u32 idx = rx->cnt & rx->mask; in gve_clean_rx_done()
932 struct gve_rx_desc *desc = &rx->desc.desc_ring[idx]; in gve_clean_rx_done()
935 while ((GVE_SEQNO(desc->flags_seq) == rx->desc.seqno) && in gve_clean_rx_done()
937 next_desc = &rx->desc.desc_ring[(idx + 1) & rx->mask]; in gve_clean_rx_done()
940 gve_rx(rx, feat, desc, idx, &cnts); in gve_clean_rx_done()
942 rx->cnt++; in gve_clean_rx_done()
943 idx = rx->cnt & rx->mask; in gve_clean_rx_done()
944 desc = &rx->desc.desc_ring[idx]; in gve_clean_rx_done()
945 rx->desc.seqno = gve_next_seqno(rx->desc.seqno); in gve_clean_rx_done()
951 struct napi_struct *napi = &priv->ntfy_blocks[rx->ntfy_id].napi; in gve_clean_rx_done()
954 gve_rx_ctx_clear(&rx->ctx); in gve_clean_rx_done()
956 GVE_SEQNO(desc->flags_seq), rx->desc.seqno); in gve_clean_rx_done()
957 gve_schedule_reset(rx->gve); in gve_clean_rx_done()
960 if (!work_done && rx->fill_cnt - rx->cnt > rx->db_threshold) in gve_clean_rx_done()
964 u64_stats_update_begin(&rx->statss); in gve_clean_rx_done()
965 rx->rpackets += cnts.ok_pkt_cnt; in gve_clean_rx_done()
966 rx->rbytes += cnts.ok_pkt_bytes; in gve_clean_rx_done()
967 rx->rx_cont_packet_cnt += cnts.cont_pkt_cnt; in gve_clean_rx_done()
968 rx->rx_desc_err_dropped_pkt += cnts.desc_err_pkt_cnt; in gve_clean_rx_done()
969 u64_stats_update_end(&rx->statss); in gve_clean_rx_done()
972 if (xdp_txs != rx->xdp_actions[XDP_TX]) in gve_clean_rx_done()
973 gve_xdp_tx_flush(priv, rx->q_num); in gve_clean_rx_done()
975 if (xdp_redirects != rx->xdp_actions[XDP_REDIRECT]) in gve_clean_rx_done()
979 if (!rx->data.raw_addressing) { in gve_clean_rx_done()
981 rx->fill_cnt += work_done; in gve_clean_rx_done()
982 } else if (rx->fill_cnt - rx->cnt <= rx->db_threshold) { in gve_clean_rx_done()
986 if (!gve_rx_refill_buffers(priv, rx)) in gve_clean_rx_done()
992 if (rx->fill_cnt - rx->cnt <= rx->db_threshold) { in gve_clean_rx_done()
993 gve_rx_write_doorbell(priv, rx); in gve_clean_rx_done()
998 gve_rx_write_doorbell(priv, rx); in gve_clean_rx_done()
1004 struct gve_rx_ring *rx = block->rx; in gve_rx_poll() local
1011 work_done = gve_clean_rx_done(rx, budget, feat); in gve_rx_poll()