Lines Matching full:rx
23 static void gve_rx_unfill_pages(struct gve_priv *priv, struct gve_rx_ring *rx) in gve_rx_unfill_pages() argument
25 u32 slots = rx->mask + 1; in gve_rx_unfill_pages()
28 if (rx->data.raw_addressing) { in gve_rx_unfill_pages()
30 gve_rx_free_buffer(&priv->pdev->dev, &rx->data.page_info[i], in gve_rx_unfill_pages()
31 &rx->data.data_ring[i]); in gve_rx_unfill_pages()
34 page_ref_sub(rx->data.page_info[i].page, in gve_rx_unfill_pages()
35 rx->data.page_info[i].pagecnt_bias - 1); in gve_rx_unfill_pages()
36 gve_unassign_qpl(priv, rx->data.qpl->id); in gve_rx_unfill_pages()
37 rx->data.qpl = NULL; in gve_rx_unfill_pages()
39 kvfree(rx->data.page_info); in gve_rx_unfill_pages()
40 rx->data.page_info = NULL; in gve_rx_unfill_pages()
45 struct gve_rx_ring *rx = &priv->rx[idx]; in gve_rx_free_ring() local
47 u32 slots = rx->mask + 1; in gve_rx_free_ring()
53 dma_free_coherent(dev, bytes, rx->desc.desc_ring, rx->desc.bus); in gve_rx_free_ring()
54 rx->desc.desc_ring = NULL; in gve_rx_free_ring()
56 dma_free_coherent(dev, sizeof(*rx->q_resources), in gve_rx_free_ring()
57 rx->q_resources, rx->q_resources_bus); in gve_rx_free_ring()
58 rx->q_resources = NULL; in gve_rx_free_ring()
60 gve_rx_unfill_pages(priv, rx); in gve_rx_free_ring()
62 bytes = sizeof(*rx->data.data_ring) * slots; in gve_rx_free_ring()
63 dma_free_coherent(dev, bytes, rx->data.data_ring, in gve_rx_free_ring()
64 rx->data.data_bus); in gve_rx_free_ring()
65 rx->data.data_ring = NULL; in gve_rx_free_ring()
66 netif_dbg(priv, drv, priv->dev, "freed rx ring %d\n", idx); in gve_rx_free_ring()
98 static int gve_prefill_rx_pages(struct gve_rx_ring *rx) in gve_prefill_rx_pages() argument
100 struct gve_priv *priv = rx->gve; in gve_prefill_rx_pages()
105 /* Allocate one page per Rx queue slot. Each page is split into two in gve_prefill_rx_pages()
108 slots = rx->mask + 1; in gve_prefill_rx_pages()
110 rx->data.page_info = kvzalloc(slots * in gve_prefill_rx_pages()
111 sizeof(*rx->data.page_info), GFP_KERNEL); in gve_prefill_rx_pages()
112 if (!rx->data.page_info) in gve_prefill_rx_pages()
115 if (!rx->data.raw_addressing) { in gve_prefill_rx_pages()
116 rx->data.qpl = gve_assign_rx_qpl(priv); in gve_prefill_rx_pages()
117 if (!rx->data.qpl) { in gve_prefill_rx_pages()
118 kvfree(rx->data.page_info); in gve_prefill_rx_pages()
119 rx->data.page_info = NULL; in gve_prefill_rx_pages()
124 if (!rx->data.raw_addressing) { in gve_prefill_rx_pages()
125 struct page *page = rx->data.qpl->pages[i]; in gve_prefill_rx_pages()
128 gve_setup_rx_buffer(&rx->data.page_info[i], addr, page, in gve_prefill_rx_pages()
129 &rx->data.data_ring[i].qpl_offset); in gve_prefill_rx_pages()
132 err = gve_rx_alloc_buffer(priv, &priv->pdev->dev, &rx->data.page_info[i], in gve_prefill_rx_pages()
133 &rx->data.data_ring[i]); in gve_prefill_rx_pages()
142 &rx->data.page_info[i], in gve_prefill_rx_pages()
143 &rx->data.data_ring[i]); in gve_prefill_rx_pages()
159 struct gve_rx_ring *rx = &priv->rx[idx]; in gve_rx_alloc_ring() local
166 netif_dbg(priv, drv, priv->dev, "allocating rx ring\n"); in gve_rx_alloc_ring()
168 memset(rx, 0, sizeof(*rx)); in gve_rx_alloc_ring()
170 rx->gve = priv; in gve_rx_alloc_ring()
171 rx->q_num = idx; in gve_rx_alloc_ring()
174 rx->mask = slots - 1; in gve_rx_alloc_ring()
175 rx->data.raw_addressing = priv->queue_format == GVE_GQI_RDA_FORMAT; in gve_rx_alloc_ring()
177 /* alloc rx data ring */ in gve_rx_alloc_ring()
178 bytes = sizeof(*rx->data.data_ring) * slots; in gve_rx_alloc_ring()
179 rx->data.data_ring = dma_alloc_coherent(hdev, bytes, in gve_rx_alloc_ring()
180 &rx->data.data_bus, in gve_rx_alloc_ring()
182 if (!rx->data.data_ring) in gve_rx_alloc_ring()
184 filled_pages = gve_prefill_rx_pages(rx); in gve_rx_alloc_ring()
189 rx->fill_cnt = filled_pages; in gve_rx_alloc_ring()
194 rx->q_resources = in gve_rx_alloc_ring()
196 sizeof(*rx->q_resources), in gve_rx_alloc_ring()
197 &rx->q_resources_bus, in gve_rx_alloc_ring()
199 if (!rx->q_resources) { in gve_rx_alloc_ring()
203 netif_dbg(priv, drv, priv->dev, "rx[%d]->data.data_bus=%lx\n", idx, in gve_rx_alloc_ring()
204 (unsigned long)rx->data.data_bus); in gve_rx_alloc_ring()
206 /* alloc rx desc ring */ in gve_rx_alloc_ring()
214 rx->desc.desc_ring = dma_alloc_coherent(hdev, bytes, &rx->desc.bus, in gve_rx_alloc_ring()
216 if (!rx->desc.desc_ring) { in gve_rx_alloc_ring()
220 rx->cnt = 0; in gve_rx_alloc_ring()
221 rx->db_threshold = priv->rx_desc_cnt / 2; in gve_rx_alloc_ring()
222 rx->desc.seqno = 1; in gve_rx_alloc_ring()
227 rx->packet_buffer_size = PAGE_SIZE / 2; in gve_rx_alloc_ring()
228 gve_rx_ctx_clear(&rx->ctx); in gve_rx_alloc_ring()
234 dma_free_coherent(hdev, sizeof(*rx->q_resources), in gve_rx_alloc_ring()
235 rx->q_resources, rx->q_resources_bus); in gve_rx_alloc_ring()
236 rx->q_resources = NULL; in gve_rx_alloc_ring()
238 gve_rx_unfill_pages(priv, rx); in gve_rx_alloc_ring()
240 bytes = sizeof(*rx->data.data_ring) * slots; in gve_rx_alloc_ring()
241 dma_free_coherent(hdev, bytes, rx->data.data_ring, rx->data.data_bus); in gve_rx_alloc_ring()
242 rx->data.data_ring = NULL; in gve_rx_alloc_ring()
256 "Failed to alloc rx ring=%d: err=%d\n", in gve_rx_alloc_rings()
279 void gve_rx_write_doorbell(struct gve_priv *priv, struct gve_rx_ring *rx) in gve_rx_write_doorbell() argument
281 u32 db_idx = be32_to_cpu(rx->q_resources->db_index); in gve_rx_write_doorbell()
283 iowrite32be(rx->fill_cnt, &priv->db_bar2[db_idx]); in gve_rx_write_doorbell()
368 struct gve_rx_ring *rx, struct gve_rx_slot_page_info *page_info, in gve_rx_qpl() argument
372 struct gve_rx_ctx *ctx = &rx->ctx; in gve_rx_qpl()
381 skb = gve_rx_add_frags(napi, page_info, rx->packet_buffer_size, len, ctx); in gve_rx_qpl()
393 u64_stats_update_begin(&rx->statss); in gve_rx_qpl()
394 rx->rx_frag_copy_cnt++; in gve_rx_qpl()
395 u64_stats_update_end(&rx->statss); in gve_rx_qpl()
407 static bool gve_rx_ctx_init(struct gve_rx_ctx *ctx, struct gve_rx_ring *rx) in gve_rx_ctx_init() argument
409 bool qpl_mode = !rx->data.raw_addressing, packet_size_error = false; in gve_rx_ctx_init()
412 struct gve_priv *priv = rx->gve; in gve_rx_ctx_init()
413 u32 idx = rx->cnt & rx->mask; in gve_rx_ctx_init()
429 desc = &rx->desc.desc_ring[idx]; in gve_rx_ctx_init()
431 if (GVE_SEQNO(desc->flags_seq) != rx->desc.seqno) { in gve_rx_ctx_init()
434 "RX seqno error: want=%d, got=%d, dropping packet and scheduling reset.", in gve_rx_ctx_init()
435 rx->desc.seqno, GVE_SEQNO(desc->flags_seq)); in gve_rx_ctx_init()
439 if (frag_size > rx->packet_buffer_size) { in gve_rx_ctx_init()
442 "RX fragment error: packet_buffer_size=%d, frag_size=%d, dropping packet.", in gve_rx_ctx_init()
443 rx->packet_buffer_size, be16_to_cpu(desc->len)); in gve_rx_ctx_init()
445 page_info = &rx->data.page_info[idx]; in gve_rx_ctx_init()
451 idx = (idx + 1) & rx->mask; in gve_rx_ctx_init()
452 rx->desc.seqno = gve_next_seqno(rx->desc.seqno); in gve_rx_ctx_init()
455 prefetch(rx->desc.desc_ring + idx); in gve_rx_ctx_init()
464 u64_stats_update_begin(&rx->statss); in gve_rx_ctx_init()
465 rx->rx_cont_packet_cnt++; in gve_rx_ctx_init()
466 u64_stats_update_end(&rx->statss); in gve_rx_ctx_init()
469 u64_stats_update_begin(&rx->statss); in gve_rx_ctx_init()
470 rx->rx_copied_pkt++; in gve_rx_ctx_init()
471 u64_stats_update_end(&rx->statss); in gve_rx_ctx_init()
480 u64_stats_update_begin(&rx->statss); in gve_rx_ctx_init()
481 rx->rx_desc_err_dropped_pkt++; in gve_rx_ctx_init()
482 u64_stats_update_end(&rx->statss); in gve_rx_ctx_init()
488 static struct sk_buff *gve_rx_skb(struct gve_priv *priv, struct gve_rx_ring *rx, in gve_rx_skb() argument
493 struct gve_rx_ctx *ctx = &rx->ctx; in gve_rx_skb()
500 u64_stats_update_begin(&rx->statss); in gve_rx_skb()
501 rx->rx_copied_pkt++; in gve_rx_skb()
502 rx->rx_frag_copy_cnt++; in gve_rx_skb()
503 rx->rx_copybreak_pkt++; in gve_rx_skb()
504 u64_stats_update_end(&rx->statss); in gve_rx_skb()
507 if (rx->data.raw_addressing) { in gve_rx_skb()
516 u64_stats_update_begin(&rx->statss); in gve_rx_skb()
517 rx->rx_frag_flip_cnt++; in gve_rx_skb()
518 u64_stats_update_end(&rx->statss); in gve_rx_skb()
523 rx->packet_buffer_size, ctx); in gve_rx_skb()
526 u64_stats_update_begin(&rx->statss); in gve_rx_skb()
527 rx->rx_frag_flip_cnt++; in gve_rx_skb()
528 u64_stats_update_end(&rx->statss); in gve_rx_skb()
530 skb = gve_rx_qpl(&priv->pdev->dev, netdev, rx, in gve_rx_skb()
537 static bool gve_rx(struct gve_rx_ring *rx, netdev_features_t feat, in gve_rx() argument
541 struct gve_rx_ctx *ctx = &rx->ctx; in gve_rx()
543 struct gve_priv *priv = rx->gve; in gve_rx()
554 idx = rx->cnt & rx->mask; in gve_rx()
555 first_desc = &rx->desc.desc_ring[idx]; in gve_rx()
557 napi = &priv->ntfy_blocks[rx->ntfy_id].napi; in gve_rx()
559 if (unlikely(!gve_rx_ctx_init(ctx, rx))) in gve_rx()
564 page_info = &rx->data.page_info[(idx + 2) & rx->mask]; in gve_rx()
573 page_info = &rx->data.page_info[idx]; in gve_rx()
574 data_slot = &rx->data.data_ring[idx]; in gve_rx()
575 page_bus = rx->data.raw_addressing ? in gve_rx()
577 rx->data.qpl->page_buses[idx]; in gve_rx()
580 skb = gve_rx_skb(priv, rx, page_info, napi, len, data_slot); in gve_rx()
582 u64_stats_update_begin(&rx->statss); in gve_rx()
583 rx->rx_skb_alloc_fail++; in gve_rx()
584 u64_stats_update_end(&rx->statss); in gve_rx()
589 rx->cnt++; in gve_rx()
590 idx = rx->cnt & rx->mask; in gve_rx()
592 desc = &rx->desc.desc_ring[idx]; in gve_rx()
612 skb_record_rx_queue(skb, rx->q_num); in gve_rx()
627 rx->cnt++; in gve_rx()
634 bool gve_rx_work_pending(struct gve_rx_ring *rx) in gve_rx_work_pending() argument
640 next_idx = rx->cnt & rx->mask; in gve_rx_work_pending()
641 desc = rx->desc.desc_ring + next_idx; in gve_rx_work_pending()
645 return (GVE_SEQNO(flags_seq) == rx->desc.seqno); in gve_rx_work_pending()
648 static bool gve_rx_refill_buffers(struct gve_priv *priv, struct gve_rx_ring *rx) in gve_rx_refill_buffers() argument
650 int refill_target = rx->mask + 1; in gve_rx_refill_buffers()
651 u32 fill_cnt = rx->fill_cnt; in gve_rx_refill_buffers()
653 while (fill_cnt - rx->cnt < refill_target) { in gve_rx_refill_buffers()
655 u32 idx = fill_cnt & rx->mask; in gve_rx_refill_buffers()
657 page_info = &rx->data.page_info[idx]; in gve_rx_refill_buffers()
663 &rx->data.data_ring[idx]; in gve_rx_refill_buffers()
678 if (!rx->data.raw_addressing) in gve_rx_refill_buffers()
685 &rx->data.data_ring[idx]; in gve_rx_refill_buffers()
691 u64_stats_update_begin(&rx->statss); in gve_rx_refill_buffers()
692 rx->rx_buf_alloc_fail++; in gve_rx_refill_buffers()
693 u64_stats_update_end(&rx->statss); in gve_rx_refill_buffers()
700 rx->fill_cnt = fill_cnt; in gve_rx_refill_buffers()
704 static int gve_clean_rx_done(struct gve_rx_ring *rx, int budget, in gve_clean_rx_done() argument
708 struct gve_priv *priv = rx->gve; in gve_clean_rx_done()
709 u32 idx = rx->cnt & rx->mask; in gve_clean_rx_done()
713 desc = &rx->desc.desc_ring[idx]; in gve_clean_rx_done()
714 while ((GVE_SEQNO(desc->flags_seq) == rx->desc.seqno) && in gve_clean_rx_done()
722 rx->q_num, idx, desc, desc->flags_seq); in gve_clean_rx_done()
724 "[%d] seqno=%d rx->desc.seqno=%d\n", in gve_clean_rx_done()
725 rx->q_num, GVE_SEQNO(desc->flags_seq), in gve_clean_rx_done()
726 rx->desc.seqno); in gve_clean_rx_done()
728 dropped = !gve_rx(rx, feat, &packet_size_bytes, &work_cnt); in gve_clean_rx_done()
734 idx = rx->cnt & rx->mask; in gve_clean_rx_done()
735 desc = &rx->desc.desc_ring[idx]; in gve_clean_rx_done()
739 if (!work_done && rx->fill_cnt - rx->cnt > rx->db_threshold) in gve_clean_rx_done()
743 u64_stats_update_begin(&rx->statss); in gve_clean_rx_done()
744 rx->rpackets += ok_packet_cnt; in gve_clean_rx_done()
745 rx->rbytes += bytes; in gve_clean_rx_done()
746 u64_stats_update_end(&rx->statss); in gve_clean_rx_done()
750 if (!rx->data.raw_addressing) { in gve_clean_rx_done()
752 rx->fill_cnt += work_done; in gve_clean_rx_done()
753 } else if (rx->fill_cnt - rx->cnt <= rx->db_threshold) { in gve_clean_rx_done()
757 if (!gve_rx_refill_buffers(priv, rx)) in gve_clean_rx_done()
763 if (rx->fill_cnt - rx->cnt <= rx->db_threshold) { in gve_clean_rx_done()
764 gve_rx_write_doorbell(priv, rx); in gve_clean_rx_done()
769 gve_rx_write_doorbell(priv, rx); in gve_clean_rx_done()
775 struct gve_rx_ring *rx = block->rx; in gve_rx_poll() local
786 work_done = gve_clean_rx_done(rx, budget, feat); in gve_rx_poll()