Lines Matching +full:num +full:- +full:rxq
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
44 apc->port_is_up = true; in mana_open()
59 if (!apc->port_is_up) in mana_close()
72 if (skb->protocol == htons(ETH_P_IP)) { in mana_checksum_info()
75 if (ip->protocol == IPPROTO_TCP) in mana_checksum_info()
78 if (ip->protocol == IPPROTO_UDP) in mana_checksum_info()
80 } else if (skb->protocol == htons(ETH_P_IPV6)) { in mana_checksum_info()
83 if (ip6->nexthdr == IPPROTO_TCP) in mana_checksum_info()
86 if (ip6->nexthdr == IPPROTO_UDP) in mana_checksum_info()
97 ash->dma_handle[sg_i] = da; in mana_add_sge()
98 ash->size[sg_i] = sge_len; in mana_add_sge()
100 tp->wqe_req.sgl[sg_i].address = da; in mana_add_sge()
101 tp->wqe_req.sgl[sg_i].mem_key = gpa_mkey; in mana_add_sge()
102 tp->wqe_req.sgl[sg_i].size = sge_len; in mana_add_sge()
108 struct mana_skb_head *ash = (struct mana_skb_head *)skb->head; in mana_map_skb()
109 int hsg = 1; /* num of SGEs of linear part */ in mana_map_skb()
110 struct gdma_dev *gd = apc->ac->gdma_dev; in mana_map_skb()
120 gc = gd->gdma_context; in mana_map_skb()
121 dev = gc->dev; in mana_map_skb()
125 sge1_len = skb_hlen - gso_hs; in mana_map_skb()
130 da = dma_map_single(dev, skb->data, sge0_len, DMA_TO_DEVICE); in mana_map_skb()
132 return -ENOMEM; in mana_map_skb()
134 mana_add_sge(tp, ash, 0, da, sge0_len, gd->gpa_mkey); in mana_map_skb()
138 da = dma_map_single(dev, skb->data + sge0_len, sge1_len, in mana_map_skb()
143 mana_add_sge(tp, ash, sg_i, da, sge1_len, gd->gpa_mkey); in mana_map_skb()
147 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in mana_map_skb()
150 frag = &skb_shinfo(skb)->frags[i]; in mana_map_skb()
157 gd->gpa_mkey); in mana_map_skb()
163 for (i = sg_i - 1; i >= hsg; i--) in mana_map_skb()
164 dma_unmap_page(dev, ash->dma_handle[i], ash->size[i], in mana_map_skb()
167 for (i = hsg - 1; i >= 0; i--) in mana_map_skb()
168 dma_unmap_single(dev, ash->dma_handle[i], ash->size[i], in mana_map_skb()
171 return -ENOMEM; in mana_map_skb()
184 int num_sge = 1 + skb_shinfo(skb)->nr_frags; in mana_fix_skb_head()
195 return -EINVAL; in mana_fix_skb_head()
206 if (skb->encapsulation) { in mana_get_gso_hs()
209 if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) { in mana_get_gso_hs()
224 int gso_hs = 0; /* zero for non-GSO pkts */ in mana_start_xmit()
226 struct gdma_dev *gd = apc->ac->gdma_dev; in mana_start_xmit()
237 if (unlikely(!apc->port_is_up)) in mana_start_xmit()
243 txq = &apc->tx_qp[txq_idx].txq; in mana_start_xmit()
244 gdma_sq = txq->gdma_sq; in mana_start_xmit()
245 cq = &apc->tx_qp[txq_idx].tx_cq; in mana_start_xmit()
246 tx_stats = &txq->stats; in mana_start_xmit()
248 pkg.tx_oob.s_oob.vcq_num = cq->gdma_id; in mana_start_xmit()
249 pkg.tx_oob.s_oob.vsq_frame = txq->vsq_frame; in mana_start_xmit()
251 if (txq->vp_offset > MANA_SHORT_VPORT_OFFSET_MAX) { in mana_start_xmit()
252 pkg.tx_oob.l_oob.long_vp_offset = txq->vp_offset; in mana_start_xmit()
255 pkg.tx_oob.s_oob.short_vp_offset = txq->vp_offset; in mana_start_xmit()
270 u64_stats_update_begin(&tx_stats->syncp); in mana_start_xmit()
271 tx_stats->short_pkt_fmt++; in mana_start_xmit()
272 u64_stats_update_end(&tx_stats->syncp); in mana_start_xmit()
275 u64_stats_update_begin(&tx_stats->syncp); in mana_start_xmit()
276 tx_stats->long_pkt_fmt++; in mana_start_xmit()
277 u64_stats_update_end(&tx_stats->syncp); in mana_start_xmit()
284 pkg.wqe_req.num_sge = 1 + skb_shinfo(skb)->nr_frags; in mana_start_xmit()
286 if (skb->protocol == htons(ETH_P_IP)) in mana_start_xmit()
288 else if (skb->protocol == htons(ETH_P_IPV6)) in mana_start_xmit()
302 u64_stats_update_begin(&tx_stats->syncp); in mana_start_xmit()
303 if (skb->encapsulation) { in mana_start_xmit()
304 tx_stats->tso_inner_packets++; in mana_start_xmit()
305 tx_stats->tso_inner_bytes += skb->len - gso_hs; in mana_start_xmit()
307 tx_stats->tso_packets++; in mana_start_xmit()
308 tx_stats->tso_bytes += skb->len - gso_hs; in mana_start_xmit()
310 u64_stats_update_end(&tx_stats->syncp); in mana_start_xmit()
319 pkg.wqe_req.client_data_unit = skb_shinfo(skb)->gso_size; in mana_start_xmit()
322 ip_hdr(skb)->tot_len = 0; in mana_start_xmit()
323 ip_hdr(skb)->check = 0; in mana_start_xmit()
324 tcp_hdr(skb)->check = in mana_start_xmit()
325 ~csum_tcpudp_magic(ip_hdr(skb)->saddr, in mana_start_xmit()
326 ip_hdr(skb)->daddr, 0, in mana_start_xmit()
329 ipv6_hdr(skb)->payload_len = 0; in mana_start_xmit()
330 tcp_hdr(skb)->check = in mana_start_xmit()
331 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, in mana_start_xmit()
332 &ipv6_hdr(skb)->daddr, 0, in mana_start_xmit()
335 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { in mana_start_xmit()
338 u64_stats_update_begin(&tx_stats->syncp); in mana_start_xmit()
339 tx_stats->csum_partial++; in mana_start_xmit()
340 u64_stats_update_end(&tx_stats->syncp); in mana_start_xmit()
376 u64_stats_update_begin(&tx_stats->syncp); in mana_start_xmit()
377 tx_stats->mana_map_err++; in mana_start_xmit()
378 u64_stats_update_end(&tx_stats->syncp); in mana_start_xmit()
382 skb_queue_tail(&txq->pending_skbs, skb); in mana_start_xmit()
384 len = skb->len; in mana_start_xmit()
388 (struct gdma_posted_wqe_info *)skb->cb); in mana_start_xmit()
391 apc->eth_stats.stop_queue++; in mana_start_xmit()
395 (void)skb_dequeue_tail(&txq->pending_skbs); in mana_start_xmit()
402 atomic_inc(&txq->pending_sends); in mana_start_xmit()
404 mana_gd_wq_ring_doorbell(gd->gdma_context, gdma_sq); in mana_start_xmit()
409 tx_stats = &txq->stats; in mana_start_xmit()
410 u64_stats_update_begin(&tx_stats->syncp); in mana_start_xmit()
411 tx_stats->packets++; in mana_start_xmit()
412 tx_stats->bytes += len; in mana_start_xmit()
413 u64_stats_update_end(&tx_stats->syncp); in mana_start_xmit()
418 apc->eth_stats.wake_queue++; in mana_start_xmit()
427 ndev->stats.tx_dropped++; in mana_start_xmit()
437 unsigned int num_queues = apc->num_queues; in mana_get_stats64()
444 if (!apc->port_is_up) in mana_get_stats64()
447 netdev_stats_to_stats64(st, &ndev->stats); in mana_get_stats64()
450 rx_stats = &apc->rxqs[q]->stats; in mana_get_stats64()
453 start = u64_stats_fetch_begin(&rx_stats->syncp); in mana_get_stats64()
454 packets = rx_stats->packets; in mana_get_stats64()
455 bytes = rx_stats->bytes; in mana_get_stats64()
456 } while (u64_stats_fetch_retry(&rx_stats->syncp, start)); in mana_get_stats64()
458 st->rx_packets += packets; in mana_get_stats64()
459 st->rx_bytes += bytes; in mana_get_stats64()
463 tx_stats = &apc->tx_qp[q].txq.stats; in mana_get_stats64()
466 start = u64_stats_fetch_begin(&tx_stats->syncp); in mana_get_stats64()
467 packets = tx_stats->packets; in mana_get_stats64()
468 bytes = tx_stats->bytes; in mana_get_stats64()
469 } while (u64_stats_fetch_retry(&tx_stats->syncp, start)); in mana_get_stats64()
471 st->tx_packets += packets; in mana_get_stats64()
472 st->tx_bytes += bytes; in mana_get_stats64()
481 struct sock *sk = skb->sk; in mana_get_tx_queue()
484 txq = apc->indir_table[hash & (apc->indir_table_sz - 1)]; in mana_get_tx_queue()
487 rcu_access_pointer(sk->sk_dst_cache)) in mana_get_tx_queue()
498 if (ndev->real_num_tx_queues == 1) in mana_select_queue()
501 txq = sk_tx_queue_get(skb->sk); in mana_select_queue()
503 if (txq < 0 || skb->ooo_okay || txq >= ndev->real_num_tx_queues) { in mana_select_queue()
513 /* Release pre-allocated RX buffers */
519 dev = mpc->ac->gdma_dev->gdma_context->dev; in mana_pre_dealloc_rxbufs()
521 if (!mpc->rxbufs_pre) in mana_pre_dealloc_rxbufs()
524 if (!mpc->das_pre) in mana_pre_dealloc_rxbufs()
527 while (mpc->rxbpre_total) { in mana_pre_dealloc_rxbufs()
528 i = --mpc->rxbpre_total; in mana_pre_dealloc_rxbufs()
529 dma_unmap_single(dev, mpc->das_pre[i], mpc->rxbpre_datasize, in mana_pre_dealloc_rxbufs()
531 put_page(virt_to_head_page(mpc->rxbufs_pre[i])); in mana_pre_dealloc_rxbufs()
534 kfree(mpc->das_pre); in mana_pre_dealloc_rxbufs()
535 mpc->das_pre = NULL; in mana_pre_dealloc_rxbufs()
538 kfree(mpc->rxbufs_pre); in mana_pre_dealloc_rxbufs()
539 mpc->rxbufs_pre = NULL; in mana_pre_dealloc_rxbufs()
542 mpc->rxbpre_datasize = 0; in mana_pre_dealloc_rxbufs()
543 mpc->rxbpre_alloc_size = 0; in mana_pre_dealloc_rxbufs()
544 mpc->rxbpre_headroom = 0; in mana_pre_dealloc_rxbufs()
547 /* Get a buffer from the pre-allocated RX buffers */
548 static void *mana_get_rxbuf_pre(struct mana_rxq *rxq, dma_addr_t *da) in mana_get_rxbuf_pre() argument
550 struct net_device *ndev = rxq->ndev; in mana_get_rxbuf_pre()
556 if (!mpc->rxbufs_pre || !mpc->das_pre || !mpc->rxbpre_total) { in mana_get_rxbuf_pre()
557 netdev_err(ndev, "No RX pre-allocated bufs\n"); in mana_get_rxbuf_pre()
562 if (mpc->rxbpre_datasize != rxq->datasize) { in mana_get_rxbuf_pre()
564 mpc->rxbpre_datasize, rxq->datasize); in mana_get_rxbuf_pre()
568 if (mpc->rxbpre_alloc_size != rxq->alloc_size) { in mana_get_rxbuf_pre()
570 mpc->rxbpre_alloc_size, rxq->alloc_size); in mana_get_rxbuf_pre()
574 if (mpc->rxbpre_headroom != rxq->headroom) { in mana_get_rxbuf_pre()
576 mpc->rxbpre_headroom, rxq->headroom); in mana_get_rxbuf_pre()
580 mpc->rxbpre_total--; in mana_get_rxbuf_pre()
582 *da = mpc->das_pre[mpc->rxbpre_total]; in mana_get_rxbuf_pre()
583 va = mpc->rxbufs_pre[mpc->rxbpre_total]; in mana_get_rxbuf_pre()
584 mpc->rxbufs_pre[mpc->rxbpre_total] = NULL; in mana_get_rxbuf_pre()
587 if (!mpc->rxbpre_total) in mana_get_rxbuf_pre()
620 mana_get_rxbuf_cfg(new_mtu, &mpc->rxbpre_datasize, in mana_pre_alloc_rxbufs()
621 &mpc->rxbpre_alloc_size, &mpc->rxbpre_headroom); in mana_pre_alloc_rxbufs()
623 dev = mpc->ac->gdma_dev->gdma_context->dev; in mana_pre_alloc_rxbufs()
625 num_rxb = num_queues * mpc->rx_queue_size; in mana_pre_alloc_rxbufs()
627 WARN(mpc->rxbufs_pre, "mana rxbufs_pre exists\n"); in mana_pre_alloc_rxbufs()
628 mpc->rxbufs_pre = kmalloc_array(num_rxb, sizeof(void *), GFP_KERNEL); in mana_pre_alloc_rxbufs()
629 if (!mpc->rxbufs_pre) in mana_pre_alloc_rxbufs()
632 mpc->das_pre = kmalloc_array(num_rxb, sizeof(dma_addr_t), GFP_KERNEL); in mana_pre_alloc_rxbufs()
633 if (!mpc->das_pre) in mana_pre_alloc_rxbufs()
636 mpc->rxbpre_total = 0; in mana_pre_alloc_rxbufs()
639 if (mpc->rxbpre_alloc_size > PAGE_SIZE) { in mana_pre_alloc_rxbufs()
640 va = netdev_alloc_frag(mpc->rxbpre_alloc_size); in mana_pre_alloc_rxbufs()
647 get_order(mpc->rxbpre_alloc_size)) { in mana_pre_alloc_rxbufs()
659 da = dma_map_single(dev, va + mpc->rxbpre_headroom, in mana_pre_alloc_rxbufs()
660 mpc->rxbpre_datasize, DMA_FROM_DEVICE); in mana_pre_alloc_rxbufs()
666 mpc->rxbufs_pre[i] = va; in mana_pre_alloc_rxbufs()
667 mpc->das_pre[i] = da; in mana_pre_alloc_rxbufs()
668 mpc->rxbpre_total = i + 1; in mana_pre_alloc_rxbufs()
675 return -ENOMEM; in mana_pre_alloc_rxbufs()
681 unsigned int old_mtu = ndev->mtu; in mana_change_mtu()
684 /* Pre-allocate buffers to prevent failure in mana_attach later */ in mana_change_mtu()
685 err = mana_pre_alloc_rxbufs(mpc, new_mtu, mpc->num_queues); in mana_change_mtu()
697 WRITE_ONCE(ndev->mtu, new_mtu); in mana_change_mtu()
702 WRITE_ONCE(ndev->mtu, old_mtu); in mana_change_mtu()
724 kfree(apc->rxqs); in mana_cleanup_port_context()
725 apc->rxqs = NULL; in mana_cleanup_port_context()
730 apc->indir_table_sz = 0; in mana_cleanup_indir_table()
731 kfree(apc->indir_table); in mana_cleanup_indir_table()
732 kfree(apc->rxobj_table); in mana_cleanup_indir_table()
737 apc->rxqs = kcalloc(apc->num_queues, sizeof(struct mana_rxq *), in mana_init_port_context()
740 return !apc->rxqs ? -ENOMEM : 0; in mana_init_port_context()
746 struct gdma_context *gc = ac->gdma_dev->gdma_context; in mana_send_request()
749 struct device *dev = gc->dev; in mana_send_request()
753 req->dev_id = gc->mana.dev_id; in mana_send_request()
754 req->activity_id = atomic_inc_return(&activity_id); in mana_send_request()
758 if (err || resp->status) { in mana_send_request()
760 err, resp->status); in mana_send_request()
761 return err ? err : -EPROTO; in mana_send_request()
764 if (req->dev_id.as_uint32 != resp->dev_id.as_uint32 || in mana_send_request()
765 req->activity_id != resp->activity_id) { in mana_send_request()
767 req->dev_id.as_uint32, resp->dev_id.as_uint32, in mana_send_request()
768 req->activity_id, resp->activity_id); in mana_send_request()
769 return -EPROTO; in mana_send_request()
779 if (resp_hdr->response.msg_type != expected_code) in mana_verify_resp_hdr()
780 return -EPROTO; in mana_verify_resp_hdr()
782 if (resp_hdr->response.msg_version < GDMA_MESSAGE_V1) in mana_verify_resp_hdr()
783 return -EPROTO; in mana_verify_resp_hdr()
785 if (resp_hdr->response.msg_size < min_size) in mana_verify_resp_hdr()
786 return -EPROTO; in mana_verify_resp_hdr()
803 err = mana_send_request(apc->ac, &req, sizeof(req), &resp, in mana_pf_register_hw_vport()
806 netdev_err(apc->ndev, "Failed to register hw vPort: %d\n", err); in mana_pf_register_hw_vport()
813 netdev_err(apc->ndev, "Failed to register hw vPort: %d, 0x%x\n", in mana_pf_register_hw_vport()
815 return err ? err : -EPROTO; in mana_pf_register_hw_vport()
818 apc->port_handle = resp.hw_vport_handle; in mana_pf_register_hw_vport()
830 req.hw_vport_handle = apc->port_handle; in mana_pf_deregister_hw_vport()
832 err = mana_send_request(apc->ac, &req, sizeof(req), &resp, in mana_pf_deregister_hw_vport()
835 netdev_err(apc->ndev, "Failed to unregister hw vPort: %d\n", in mana_pf_deregister_hw_vport()
843 netdev_err(apc->ndev, in mana_pf_deregister_hw_vport()
856 req.vport = apc->port_handle; in mana_pf_register_filter()
857 memcpy(req.mac_addr, apc->mac_addr, ETH_ALEN); in mana_pf_register_filter()
859 err = mana_send_request(apc->ac, &req, sizeof(req), &resp, in mana_pf_register_filter()
862 netdev_err(apc->ndev, "Failed to register filter: %d\n", err); in mana_pf_register_filter()
869 netdev_err(apc->ndev, "Failed to register filter: %d, 0x%x\n", in mana_pf_register_filter()
871 return err ? err : -EPROTO; in mana_pf_register_filter()
874 apc->pf_filter_handle = resp.filter_handle; in mana_pf_register_filter()
886 req.filter_handle = apc->pf_filter_handle; in mana_pf_deregister_filter()
888 err = mana_send_request(apc->ac, &req, sizeof(req), &resp, in mana_pf_deregister_filter()
891 netdev_err(apc->ndev, "Failed to unregister filter: %d\n", in mana_pf_deregister_filter()
899 netdev_err(apc->ndev, in mana_pf_deregister_filter()
908 struct gdma_context *gc = ac->gdma_dev->gdma_context; in mana_query_device_cfg()
911 struct device *dev = gc->dev; in mana_query_device_cfg()
935 err = -EPROTO; in mana_query_device_cfg()
942 gc->adapter_mtu = resp.adapter_mtu; in mana_query_device_cfg()
944 gc->adapter_mtu = ETH_FRAME_LEN; in mana_query_device_cfg()
961 err = mana_send_request(apc->ac, &req, sizeof(req), &resp, in mana_query_vport_cfg()
972 return -EPROTO; in mana_query_vport_cfg()
981 netdev_warn(apc->ndev, in mana_query_vport_cfg()
983 MANA_INDIRECT_TABLE_DEF_SIZE, apc->port_idx); in mana_query_vport_cfg()
987 apc->port_handle = resp.vport; in mana_query_vport_cfg()
988 ether_addr_copy(apc->mac_addr, resp.mac_addr); in mana_query_vport_cfg()
995 mutex_lock(&apc->vport_mutex); in mana_uncfg_vport()
996 apc->vport_use_count--; in mana_uncfg_vport()
997 WARN_ON(apc->vport_use_count < 0); in mana_uncfg_vport()
998 mutex_unlock(&apc->vport_mutex); in mana_uncfg_vport()
1027 mutex_lock(&apc->vport_mutex); in mana_cfg_vport()
1028 if (apc->vport_use_count > 0) { in mana_cfg_vport()
1029 mutex_unlock(&apc->vport_mutex); in mana_cfg_vport()
1030 return -EBUSY; in mana_cfg_vport()
1032 apc->vport_use_count++; in mana_cfg_vport()
1033 mutex_unlock(&apc->vport_mutex); in mana_cfg_vport()
1037 req.vport = apc->port_handle; in mana_cfg_vport()
1041 err = mana_send_request(apc->ac, &req, sizeof(req), &resp, in mana_cfg_vport()
1044 netdev_err(apc->ndev, "Failed to configure vPort: %d\n", err); in mana_cfg_vport()
1051 netdev_err(apc->ndev, "Failed to configure vPort: %d, 0x%x\n", in mana_cfg_vport()
1054 err = -EPROTO; in mana_cfg_vport()
1059 apc->tx_shortform_allowed = resp.short_form_allowed; in mana_cfg_vport()
1060 apc->tx_vp_offset = resp.tx_vport_offset; in mana_cfg_vport()
1062 netdev_info(apc->ndev, "Configured vPort %llu PD %u DB %u\n", in mana_cfg_vport()
1063 apc->port_handle, protection_dom_id, doorbell_pg_id); in mana_cfg_vport()
1079 struct net_device *ndev = apc->ndev; in mana_cfg_vport_steering()
1083 req_buf_size = struct_size(req, indir_tab, apc->indir_table_sz); in mana_cfg_vport_steering()
1086 return -ENOMEM; in mana_cfg_vport_steering()
1088 mana_gd_init_req_hdr(&req->hdr, MANA_CONFIG_VPORT_RX, req_buf_size, in mana_cfg_vport_steering()
1091 req->hdr.req.msg_version = GDMA_MESSAGE_V2; in mana_cfg_vport_steering()
1093 req->vport = apc->port_handle; in mana_cfg_vport_steering()
1094 req->num_indir_entries = apc->indir_table_sz; in mana_cfg_vport_steering()
1095 req->indir_tab_offset = offsetof(struct mana_cfg_rx_steer_req_v2, in mana_cfg_vport_steering()
1097 req->rx_enable = rx; in mana_cfg_vport_steering()
1098 req->rss_enable = apc->rss_state; in mana_cfg_vport_steering()
1099 req->update_default_rxobj = update_default_rxobj; in mana_cfg_vport_steering()
1100 req->update_hashkey = update_key; in mana_cfg_vport_steering()
1101 req->update_indir_tab = update_tab; in mana_cfg_vport_steering()
1102 req->default_rxobj = apc->default_rxobj; in mana_cfg_vport_steering()
1103 req->cqe_coalescing_enable = 0; in mana_cfg_vport_steering()
1106 memcpy(&req->hashkey, apc->hashkey, MANA_HASH_KEY_SIZE); in mana_cfg_vport_steering()
1109 memcpy(req->indir_tab, apc->rxobj_table, in mana_cfg_vport_steering()
1110 flex_array_size(req, indir_tab, req->num_indir_entries)); in mana_cfg_vport_steering()
1112 err = mana_send_request(apc->ac, req, req_buf_size, &resp, in mana_cfg_vport_steering()
1129 err = -EPROTO; in mana_cfg_vport_steering()
1133 apc->port_handle, apc->indir_table_sz); in mana_cfg_vport_steering()
1147 struct net_device *ndev = apc->ndev; in mana_create_wq_obj()
1154 req.wq_gdma_region = wq_spec->gdma_region; in mana_create_wq_obj()
1155 req.cq_gdma_region = cq_spec->gdma_region; in mana_create_wq_obj()
1156 req.wq_size = wq_spec->queue_size; in mana_create_wq_obj()
1157 req.cq_size = cq_spec->queue_size; in mana_create_wq_obj()
1158 req.cq_moderation_ctx_id = cq_spec->modr_ctx_id; in mana_create_wq_obj()
1159 req.cq_parent_qid = cq_spec->attached_eq; in mana_create_wq_obj()
1161 err = mana_send_request(apc->ac, &req, sizeof(req), &resp, in mana_create_wq_obj()
1174 err = -EPROTO; in mana_create_wq_obj()
1180 err = -EPROTO; in mana_create_wq_obj()
1185 wq_spec->queue_index = resp.wq_id; in mana_create_wq_obj()
1186 cq_spec->queue_index = resp.cq_id; in mana_create_wq_obj()
1199 struct net_device *ndev = apc->ndev; in mana_destroy_wq_obj()
1207 err = mana_send_request(apc->ac, &req, sizeof(req), &resp, in mana_destroy_wq_obj()
1224 struct gdma_context *gc = ac->gdma_dev->gdma_context; in mana_destroy_eq()
1228 if (!ac->eqs) in mana_destroy_eq()
1231 for (i = 0; i < gc->max_num_queues; i++) { in mana_destroy_eq()
1232 eq = ac->eqs[i].eq; in mana_destroy_eq()
1239 kfree(ac->eqs); in mana_destroy_eq()
1240 ac->eqs = NULL; in mana_destroy_eq()
1245 struct gdma_dev *gd = ac->gdma_dev; in mana_create_eq()
1246 struct gdma_context *gc = gd->gdma_context; in mana_create_eq()
1251 ac->eqs = kcalloc(gc->max_num_queues, sizeof(struct mana_eq), in mana_create_eq()
1253 if (!ac->eqs) in mana_create_eq()
1254 return -ENOMEM; in mana_create_eq()
1260 spec.eq.context = ac->eqs; in mana_create_eq()
1263 for (i = 0; i < gc->max_num_queues; i++) { in mana_create_eq()
1264 spec.eq.msix_index = (i + 1) % gc->num_msix_usable; in mana_create_eq()
1265 err = mana_gd_create_mana_eq(gd, &spec, &ac->eqs[i].eq); in mana_create_eq()
1276 static int mana_fence_rq(struct mana_port_context *apc, struct mana_rxq *rxq) in mana_fence_rq() argument
1282 init_completion(&rxq->fence_event); in mana_fence_rq()
1286 req.wq_obj_handle = rxq->rxobj; in mana_fence_rq()
1288 err = mana_send_request(apc->ac, &req, sizeof(req), &resp, in mana_fence_rq()
1291 netdev_err(apc->ndev, "Failed to fence RQ %u: %d\n", in mana_fence_rq()
1292 rxq->rxq_idx, err); in mana_fence_rq()
1298 netdev_err(apc->ndev, "Failed to fence RQ %u: %d, 0x%x\n", in mana_fence_rq()
1299 rxq->rxq_idx, err, resp.hdr.status); in mana_fence_rq()
1301 err = -EPROTO; in mana_fence_rq()
1306 if (wait_for_completion_timeout(&rxq->fence_event, 10 * HZ) == 0) { in mana_fence_rq()
1307 netdev_err(apc->ndev, "Failed to fence RQ %u: timed out\n", in mana_fence_rq()
1308 rxq->rxq_idx); in mana_fence_rq()
1309 return -ETIMEDOUT; in mana_fence_rq()
1318 struct mana_rxq *rxq; in mana_fence_rqs() local
1321 for (rxq_idx = 0; rxq_idx < apc->num_queues; rxq_idx++) { in mana_fence_rqs()
1322 rxq = apc->rxqs[rxq_idx]; in mana_fence_rqs()
1323 err = mana_fence_rq(apc, rxq); in mana_fence_rqs()
1336 used_space_old = wq->head - wq->tail; in mana_move_wq_tail()
1337 used_space_new = wq->head - (wq->tail + num_units); in mana_move_wq_tail()
1340 return -ERANGE; in mana_move_wq_tail()
1342 wq->tail += num_units; in mana_move_wq_tail()
1348 struct mana_skb_head *ash = (struct mana_skb_head *)skb->head; in mana_unmap_skb()
1349 struct gdma_context *gc = apc->ac->gdma_dev->gdma_context; in mana_unmap_skb()
1350 struct device *dev = gc->dev; in mana_unmap_skb()
1354 hsg = (skb_is_gso(skb) && skb_headlen(skb) > ash->size[0]) ? 2 : 1; in mana_unmap_skb()
1357 dma_unmap_single(dev, ash->dma_handle[i], ash->size[i], in mana_unmap_skb()
1360 for (i = hsg; i < skb_shinfo(skb)->nr_frags + hsg; i++) in mana_unmap_skb()
1361 dma_unmap_page(dev, ash->dma_handle[i], ash->size[i], in mana_unmap_skb()
1367 struct gdma_comp *completions = cq->gdma_comp_buf; in mana_poll_tx_cq()
1371 struct mana_txq *txq = cq->txq; in mana_poll_tx_cq()
1382 ndev = txq->ndev; in mana_poll_tx_cq()
1385 comp_read = mana_gd_poll_cq(cq->gdma_cq, completions, in mana_poll_tx_cq()
1398 if (WARN_ON_ONCE(cqe_oob->cqe_hdr.client_type != in mana_poll_tx_cq()
1402 switch (cqe_oob->cqe_hdr.cqe_type) { in mana_poll_tx_cq()
1417 cqe_oob->cqe_hdr.cqe_type); in mana_poll_tx_cq()
1419 apc->eth_stats.tx_cqe_err++; in mana_poll_tx_cq()
1428 cqe_oob->cqe_hdr.cqe_type); in mana_poll_tx_cq()
1430 apc->eth_stats.tx_cqe_unknown_type++; in mana_poll_tx_cq()
1434 if (WARN_ON_ONCE(txq->gdma_txq_id != completions[i].wq_num)) in mana_poll_tx_cq()
1437 skb = skb_dequeue(&txq->pending_skbs); in mana_poll_tx_cq()
1441 wqe_info = (struct gdma_posted_wqe_info *)skb->cb; in mana_poll_tx_cq()
1442 wqe_unit_cnt += wqe_info->wqe_size_in_bu; in mana_poll_tx_cq()
1446 napi_consume_skb(skb, cq->budget); in mana_poll_tx_cq()
1454 mana_move_wq_tail(txq->gdma_sq, wqe_unit_cnt); in mana_poll_tx_cq()
1456 gdma_wq = txq->gdma_sq; in mana_poll_tx_cq()
1462 net_txq = txq->net_txq; in mana_poll_tx_cq()
1465 /* Ensure checking txq_stopped before apc->port_is_up. */ in mana_poll_tx_cq()
1468 if (txq_stopped && apc->port_is_up && avail_space >= MAX_TX_WQE_SIZE) { in mana_poll_tx_cq()
1470 apc->eth_stats.wake_queue++; in mana_poll_tx_cq()
1473 if (atomic_sub_return(pkt_transmitted, &txq->pending_sends) < 0) in mana_poll_tx_cq()
1476 cq->work_done = pkt_transmitted; in mana_poll_tx_cq()
1479 static void mana_post_pkt_rxq(struct mana_rxq *rxq) in mana_post_pkt_rxq() argument
1485 curr_index = rxq->buf_index++; in mana_post_pkt_rxq()
1486 if (rxq->buf_index == rxq->num_rx_buf) in mana_post_pkt_rxq()
1487 rxq->buf_index = 0; in mana_post_pkt_rxq()
1489 recv_buf_oob = &rxq->rx_oobs[curr_index]; in mana_post_pkt_rxq()
1491 err = mana_gd_post_work_request(rxq->gdma_rq, &recv_buf_oob->wqe_req, in mana_post_pkt_rxq()
1492 &recv_buf_oob->wqe_inf); in mana_post_pkt_rxq()
1496 WARN_ON_ONCE(recv_buf_oob->wqe_inf.wqe_size_in_bu != 1); in mana_post_pkt_rxq()
1499 static struct sk_buff *mana_build_skb(struct mana_rxq *rxq, void *buf_va, in mana_build_skb() argument
1502 struct sk_buff *skb = napi_build_skb(buf_va, rxq->alloc_size); in mana_build_skb()
1507 if (xdp->data_hard_start) { in mana_build_skb()
1508 skb_reserve(skb, xdp->data - xdp->data_hard_start); in mana_build_skb()
1509 skb_put(skb, xdp->data_end - xdp->data); in mana_build_skb()
1513 skb_reserve(skb, rxq->headroom); in mana_build_skb()
1520 struct mana_rxcomp_oob *cqe, struct mana_rxq *rxq) in mana_rx_skb() argument
1522 struct mana_stats_rx *rx_stats = &rxq->stats; in mana_rx_skb()
1523 struct net_device *ndev = rxq->ndev; in mana_rx_skb()
1524 uint pkt_len = cqe->ppi[0].pkt_len; in mana_rx_skb()
1525 u16 rxq_idx = rxq->rxq_idx; in mana_rx_skb()
1532 rxq->rx_cq.work_done++; in mana_rx_skb()
1533 napi = &rxq->rx_cq.napi; in mana_rx_skb()
1536 ++ndev->stats.rx_dropped; in mana_rx_skb()
1540 act = mana_run_xdp(ndev, rxq, &xdp, buf_va, pkt_len); in mana_rx_skb()
1542 if (act == XDP_REDIRECT && !rxq->xdp_rc) in mana_rx_skb()
1548 skb = mana_build_skb(rxq, buf_va, pkt_len, &xdp); in mana_rx_skb()
1556 skb->dev = napi->dev; in mana_rx_skb()
1558 skb->protocol = eth_type_trans(skb, ndev); in mana_rx_skb()
1562 if ((ndev->features & NETIF_F_RXCSUM) && cqe->rx_iphdr_csum_succeed) { in mana_rx_skb()
1563 if (cqe->rx_tcp_csum_succeed || cqe->rx_udp_csum_succeed) in mana_rx_skb()
1564 skb->ip_summed = CHECKSUM_UNNECESSARY; in mana_rx_skb()
1567 if (cqe->rx_hashtype != 0 && (ndev->features & NETIF_F_RXHASH)) { in mana_rx_skb()
1568 hash_value = cqe->ppi[0].pkt_hash; in mana_rx_skb()
1570 if (cqe->rx_hashtype & MANA_HASH_L4) in mana_rx_skb()
1576 if (cqe->rx_vlantag_present) { in mana_rx_skb()
1577 u16 vlan_tci = cqe->rx_vlan_id; in mana_rx_skb()
1582 u64_stats_update_begin(&rx_stats->syncp); in mana_rx_skb()
1583 rx_stats->packets++; in mana_rx_skb()
1584 rx_stats->bytes += pkt_len; in mana_rx_skb()
1587 rx_stats->xdp_tx++; in mana_rx_skb()
1588 u64_stats_update_end(&rx_stats->syncp); in mana_rx_skb()
1601 u64_stats_update_begin(&rx_stats->syncp); in mana_rx_skb()
1602 rx_stats->xdp_drop++; in mana_rx_skb()
1603 u64_stats_update_end(&rx_stats->syncp); in mana_rx_skb()
1607 page_pool_recycle_direct(rxq->page_pool, in mana_rx_skb()
1610 WARN_ON_ONCE(rxq->xdp_save_va); in mana_rx_skb()
1612 rxq->xdp_save_va = buf_va; in mana_rx_skb()
1615 ++ndev->stats.rx_dropped; in mana_rx_skb()
1620 static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev, in mana_get_rxfrag() argument
1629 if (rxq->xdp_save_va) { in mana_get_rxfrag()
1630 va = rxq->xdp_save_va; in mana_get_rxfrag()
1631 rxq->xdp_save_va = NULL; in mana_get_rxfrag()
1632 } else if (rxq->alloc_size > PAGE_SIZE) { in mana_get_rxfrag()
1634 va = napi_alloc_frag(rxq->alloc_size); in mana_get_rxfrag()
1636 va = netdev_alloc_frag(rxq->alloc_size); in mana_get_rxfrag()
1643 if (compound_order(page) < get_order(rxq->alloc_size)) { in mana_get_rxfrag()
1648 page = page_pool_dev_alloc_pages(rxq->page_pool); in mana_get_rxfrag()
1656 *da = dma_map_single(dev, va + rxq->headroom, rxq->datasize, in mana_get_rxfrag()
1660 page_pool_put_full_page(rxq->page_pool, page, false); in mana_get_rxfrag()
1671 static void mana_refill_rx_oob(struct device *dev, struct mana_rxq *rxq, in mana_refill_rx_oob() argument
1679 va = mana_get_rxfrag(rxq, dev, &da, &from_pool, true); in mana_refill_rx_oob()
1683 dma_unmap_single(dev, rxoob->sgl[0].address, rxq->datasize, in mana_refill_rx_oob()
1685 *old_buf = rxoob->buf_va; in mana_refill_rx_oob()
1686 *old_fp = rxoob->from_pool; in mana_refill_rx_oob()
1688 rxoob->buf_va = va; in mana_refill_rx_oob()
1689 rxoob->sgl[0].address = da; in mana_refill_rx_oob()
1690 rxoob->from_pool = from_pool; in mana_refill_rx_oob()
1693 static void mana_process_rx_cqe(struct mana_rxq *rxq, struct mana_cq *cq, in mana_process_rx_cqe() argument
1696 struct mana_rxcomp_oob *oob = (struct mana_rxcomp_oob *)cqe->cqe_data; in mana_process_rx_cqe()
1697 struct gdma_context *gc = rxq->gdma_rq->gdma_dev->gdma_context; in mana_process_rx_cqe()
1698 struct net_device *ndev = rxq->ndev; in mana_process_rx_cqe()
1701 struct device *dev = gc->dev; in mana_process_rx_cqe()
1708 switch (oob->cqe_hdr.cqe_type) { in mana_process_rx_cqe()
1713 ++ndev->stats.rx_dropped; in mana_process_rx_cqe()
1714 rxbuf_oob = &rxq->rx_oobs[rxq->buf_index]; in mana_process_rx_cqe()
1720 apc->eth_stats.rx_coalesced_err++; in mana_process_rx_cqe()
1724 complete(&rxq->fence_event); in mana_process_rx_cqe()
1729 oob->cqe_hdr.cqe_type); in mana_process_rx_cqe()
1730 apc->eth_stats.rx_cqe_unknown_type++; in mana_process_rx_cqe()
1734 pktlen = oob->ppi[0].pkt_len; in mana_process_rx_cqe()
1739 rxq->gdma_id, cq->gdma_id, rxq->rxobj); in mana_process_rx_cqe()
1743 curr = rxq->buf_index; in mana_process_rx_cqe()
1744 rxbuf_oob = &rxq->rx_oobs[curr]; in mana_process_rx_cqe()
1745 WARN_ON_ONCE(rxbuf_oob->wqe_inf.wqe_size_in_bu != 1); in mana_process_rx_cqe()
1747 mana_refill_rx_oob(dev, rxq, rxbuf_oob, &old_buf, &old_fp); in mana_process_rx_cqe()
1752 mana_rx_skb(old_buf, old_fp, oob, rxq); in mana_process_rx_cqe()
1755 mana_move_wq_tail(rxq->gdma_rq, rxbuf_oob->wqe_inf.wqe_size_in_bu); in mana_process_rx_cqe()
1757 mana_post_pkt_rxq(rxq); in mana_process_rx_cqe()
1762 struct gdma_comp *comp = cq->gdma_comp_buf; in mana_poll_rx_cq()
1763 struct mana_rxq *rxq = cq->rxq; in mana_poll_rx_cq() local
1766 comp_read = mana_gd_poll_cq(cq->gdma_cq, comp, CQE_POLLING_BUFFER); in mana_poll_rx_cq()
1769 rxq->xdp_flush = false; in mana_poll_rx_cq()
1775 /* verify recv cqe references the right rxq */ in mana_poll_rx_cq()
1776 if (WARN_ON_ONCE(comp[i].wq_num != cq->rxq->gdma_id)) in mana_poll_rx_cq()
1779 mana_process_rx_cqe(rxq, cq, &comp[i]); in mana_poll_rx_cq()
1783 struct gdma_context *gc = rxq->gdma_rq->gdma_dev->gdma_context; in mana_poll_rx_cq()
1785 mana_gd_wq_ring_doorbell(gc, rxq->gdma_rq); in mana_poll_rx_cq()
1788 if (rxq->xdp_flush) in mana_poll_rx_cq()
1797 WARN_ON_ONCE(cq->gdma_cq != gdma_queue); in mana_cq_handler()
1799 if (cq->type == MANA_CQ_TYPE_RX) in mana_cq_handler()
1804 w = cq->work_done; in mana_cq_handler()
1805 cq->work_done_since_doorbell += w; in mana_cq_handler()
1807 if (w < cq->budget) { in mana_cq_handler()
1809 cq->work_done_since_doorbell = 0; in mana_cq_handler()
1810 napi_complete_done(&cq->napi, w); in mana_cq_handler()
1811 } else if (cq->work_done_since_doorbell > in mana_cq_handler()
1812 cq->gdma_cq->queue_size / COMP_ENTRY_SIZE * 4) { in mana_cq_handler()
1819 cq->work_done_since_doorbell = 0; in mana_cq_handler()
1830 cq->work_done = 0; in mana_poll()
1831 cq->budget = budget; in mana_poll()
1833 w = mana_cq_handler(cq, cq->gdma_cq); in mana_poll()
1842 napi_schedule_irqoff(&cq->napi); in mana_schedule_napi()
1847 struct gdma_dev *gd = apc->ac->gdma_dev; in mana_deinit_cq()
1849 if (!cq->gdma_cq) in mana_deinit_cq()
1852 mana_gd_destroy_queue(gd->gdma_context, cq->gdma_cq); in mana_deinit_cq()
1857 struct gdma_dev *gd = apc->ac->gdma_dev; in mana_deinit_txq()
1859 if (!txq->gdma_sq) in mana_deinit_txq()
1862 mana_gd_destroy_queue(gd->gdma_context, txq->gdma_sq); in mana_deinit_txq()
1870 if (!apc->tx_qp) in mana_destroy_txq()
1873 for (i = 0; i < apc->num_queues; i++) { in mana_destroy_txq()
1874 napi = &apc->tx_qp[i].tx_cq.napi; in mana_destroy_txq()
1875 if (apc->tx_qp[i].txq.napi_initialized) { in mana_destroy_txq()
1879 apc->tx_qp[i].txq.napi_initialized = false; in mana_destroy_txq()
1881 mana_destroy_wq_obj(apc, GDMA_SQ, apc->tx_qp[i].tx_object); in mana_destroy_txq()
1883 mana_deinit_cq(apc, &apc->tx_qp[i].tx_cq); in mana_destroy_txq()
1885 mana_deinit_txq(apc, &apc->tx_qp[i].txq); in mana_destroy_txq()
1888 kfree(apc->tx_qp); in mana_destroy_txq()
1889 apc->tx_qp = NULL; in mana_destroy_txq()
1895 struct mana_context *ac = apc->ac; in mana_create_txq()
1896 struct gdma_dev *gd = ac->gdma_dev; in mana_create_txq()
1908 apc->tx_qp = kcalloc(apc->num_queues, sizeof(struct mana_tx_qp), in mana_create_txq()
1910 if (!apc->tx_qp) in mana_create_txq()
1911 return -ENOMEM; in mana_create_txq()
1914 * apc->tx_queue_size represents the maximum number of WQEs in mana_create_txq()
1918 * as min val of apc->tx_queue_size is 128 and that would make in mana_create_txq()
1919 * txq_size 128*32 = 4096 and the other higher values of apc->tx_queue_size in mana_create_txq()
1922 txq_size = apc->tx_queue_size * 32; in mana_create_txq()
1924 cq_size = apc->tx_queue_size * COMP_ENTRY_SIZE; in mana_create_txq()
1926 gc = gd->gdma_context; in mana_create_txq()
1928 for (i = 0; i < apc->num_queues; i++) { in mana_create_txq()
1929 apc->tx_qp[i].tx_object = INVALID_MANA_HANDLE; in mana_create_txq()
1932 txq = &apc->tx_qp[i].txq; in mana_create_txq()
1934 u64_stats_init(&txq->stats.syncp); in mana_create_txq()
1935 txq->ndev = net; in mana_create_txq()
1936 txq->net_txq = netdev_get_tx_queue(net, i); in mana_create_txq()
1937 txq->vp_offset = apc->tx_vp_offset; in mana_create_txq()
1938 txq->napi_initialized = false; in mana_create_txq()
1939 skb_queue_head_init(&txq->pending_skbs); in mana_create_txq()
1945 err = mana_gd_create_mana_wq_cq(gd, &spec, &txq->gdma_sq); in mana_create_txq()
1950 cq = &apc->tx_qp[i].tx_cq; in mana_create_txq()
1951 cq->type = MANA_CQ_TYPE_TX; in mana_create_txq()
1953 cq->txq = txq; in mana_create_txq()
1960 spec.cq.parent_eq = ac->eqs[i].eq; in mana_create_txq()
1962 err = mana_gd_create_mana_wq_cq(gd, &spec, &cq->gdma_cq); in mana_create_txq()
1969 wq_spec.gdma_region = txq->gdma_sq->mem_info.dma_region_handle; in mana_create_txq()
1970 wq_spec.queue_size = txq->gdma_sq->queue_size; in mana_create_txq()
1972 cq_spec.gdma_region = cq->gdma_cq->mem_info.dma_region_handle; in mana_create_txq()
1973 cq_spec.queue_size = cq->gdma_cq->queue_size; in mana_create_txq()
1975 cq_spec.attached_eq = cq->gdma_cq->cq.parent->id; in mana_create_txq()
1977 err = mana_create_wq_obj(apc, apc->port_handle, GDMA_SQ, in mana_create_txq()
1979 &apc->tx_qp[i].tx_object); in mana_create_txq()
1984 txq->gdma_sq->id = wq_spec.queue_index; in mana_create_txq()
1985 cq->gdma_cq->id = cq_spec.queue_index; in mana_create_txq()
1987 txq->gdma_sq->mem_info.dma_region_handle = in mana_create_txq()
1989 cq->gdma_cq->mem_info.dma_region_handle = in mana_create_txq()
1992 txq->gdma_txq_id = txq->gdma_sq->id; in mana_create_txq()
1994 cq->gdma_id = cq->gdma_cq->id; in mana_create_txq()
1996 if (WARN_ON(cq->gdma_id >= gc->max_num_cqs)) { in mana_create_txq()
1997 err = -EINVAL; in mana_create_txq()
2001 gc->cq_table[cq->gdma_id] = cq->gdma_cq; in mana_create_txq()
2003 netif_napi_add_tx(net, &cq->napi, mana_poll); in mana_create_txq()
2004 napi_enable(&cq->napi); in mana_create_txq()
2005 txq->napi_initialized = true; in mana_create_txq()
2007 mana_gd_ring_cq(cq->gdma_cq, SET_ARM_BIT); in mana_create_txq()
2017 struct mana_rxq *rxq, bool napi_initialized) in mana_destroy_rxq() argument
2020 struct gdma_context *gc = apc->ac->gdma_dev->gdma_context; in mana_destroy_rxq()
2022 struct device *dev = gc->dev; in mana_destroy_rxq()
2027 if (!rxq) in mana_destroy_rxq()
2030 napi = &rxq->rx_cq.napi; in mana_destroy_rxq()
2039 xdp_rxq_info_unreg(&rxq->xdp_rxq); in mana_destroy_rxq()
2041 mana_destroy_wq_obj(apc, GDMA_RQ, rxq->rxobj); in mana_destroy_rxq()
2043 mana_deinit_cq(apc, &rxq->rx_cq); in mana_destroy_rxq()
2045 if (rxq->xdp_save_va) in mana_destroy_rxq()
2046 put_page(virt_to_head_page(rxq->xdp_save_va)); in mana_destroy_rxq()
2048 for (i = 0; i < rxq->num_rx_buf; i++) { in mana_destroy_rxq()
2049 rx_oob = &rxq->rx_oobs[i]; in mana_destroy_rxq()
2051 if (!rx_oob->buf_va) in mana_destroy_rxq()
2054 dma_unmap_single(dev, rx_oob->sgl[0].address, in mana_destroy_rxq()
2055 rx_oob->sgl[0].size, DMA_FROM_DEVICE); in mana_destroy_rxq()
2057 page = virt_to_head_page(rx_oob->buf_va); in mana_destroy_rxq()
2059 if (rx_oob->from_pool) in mana_destroy_rxq()
2060 page_pool_put_full_page(rxq->page_pool, page, false); in mana_destroy_rxq()
2064 rx_oob->buf_va = NULL; in mana_destroy_rxq()
2067 page_pool_destroy(rxq->page_pool); in mana_destroy_rxq()
2069 if (rxq->gdma_rq) in mana_destroy_rxq()
2070 mana_gd_destroy_queue(gc, rxq->gdma_rq); in mana_destroy_rxq()
2072 kfree(rxq); in mana_destroy_rxq()
2076 struct mana_rxq *rxq, struct device *dev) in mana_fill_rx_oob() argument
2078 struct mana_port_context *mpc = netdev_priv(rxq->ndev); in mana_fill_rx_oob()
2083 if (mpc->rxbufs_pre) in mana_fill_rx_oob()
2084 va = mana_get_rxbuf_pre(rxq, &da); in mana_fill_rx_oob()
2086 va = mana_get_rxfrag(rxq, dev, &da, &from_pool, false); in mana_fill_rx_oob()
2089 return -ENOMEM; in mana_fill_rx_oob()
2091 rx_oob->buf_va = va; in mana_fill_rx_oob()
2092 rx_oob->from_pool = from_pool; in mana_fill_rx_oob()
2094 rx_oob->sgl[0].address = da; in mana_fill_rx_oob()
2095 rx_oob->sgl[0].size = rxq->datasize; in mana_fill_rx_oob()
2096 rx_oob->sgl[0].mem_key = mem_key; in mana_fill_rx_oob()
2105 struct mana_rxq *rxq, u32 *rxq_size, u32 *cq_size) in mana_alloc_rx_wqe() argument
2107 struct gdma_context *gc = apc->ac->gdma_dev->gdma_context; in mana_alloc_rx_wqe()
2109 struct device *dev = gc->dev; in mana_alloc_rx_wqe()
2113 WARN_ON(rxq->datasize == 0); in mana_alloc_rx_wqe()
2118 for (buf_idx = 0; buf_idx < rxq->num_rx_buf; buf_idx++) { in mana_alloc_rx_wqe()
2119 rx_oob = &rxq->rx_oobs[buf_idx]; in mana_alloc_rx_wqe()
2122 rx_oob->num_sge = 1; in mana_alloc_rx_wqe()
2124 ret = mana_fill_rx_oob(rx_oob, apc->ac->gdma_dev->gpa_mkey, rxq, in mana_alloc_rx_wqe()
2129 rx_oob->wqe_req.sgl = rx_oob->sgl; in mana_alloc_rx_wqe()
2130 rx_oob->wqe_req.num_sge = rx_oob->num_sge; in mana_alloc_rx_wqe()
2131 rx_oob->wqe_req.inline_oob_size = 0; in mana_alloc_rx_wqe()
2132 rx_oob->wqe_req.inline_oob_data = NULL; in mana_alloc_rx_wqe()
2133 rx_oob->wqe_req.flags = 0; in mana_alloc_rx_wqe()
2134 rx_oob->wqe_req.client_data_unit = 0; in mana_alloc_rx_wqe()
2137 MANA_WQE_SGE_SIZE * rx_oob->num_sge, 32); in mana_alloc_rx_wqe()
2144 static int mana_push_wqe(struct mana_rxq *rxq) in mana_push_wqe() argument
2150 for (buf_idx = 0; buf_idx < rxq->num_rx_buf; buf_idx++) { in mana_push_wqe()
2151 rx_oob = &rxq->rx_oobs[buf_idx]; in mana_push_wqe()
2153 err = mana_gd_post_and_ring(rxq->gdma_rq, &rx_oob->wqe_req, in mana_push_wqe()
2154 &rx_oob->wqe_inf); in mana_push_wqe()
2156 return -ENOSPC; in mana_push_wqe()
2162 static int mana_create_page_pool(struct mana_rxq *rxq, struct gdma_context *gc) in mana_create_page_pool() argument
2164 struct mana_port_context *mpc = netdev_priv(rxq->ndev); in mana_create_page_pool()
2168 pprm.pool_size = mpc->rx_queue_size; in mana_create_page_pool()
2169 pprm.nid = gc->numa_node; in mana_create_page_pool()
2170 pprm.napi = &rxq->rx_cq.napi; in mana_create_page_pool()
2171 pprm.netdev = rxq->ndev; in mana_create_page_pool()
2173 rxq->page_pool = page_pool_create(&pprm); in mana_create_page_pool()
2175 if (IS_ERR(rxq->page_pool)) { in mana_create_page_pool()
2176 ret = PTR_ERR(rxq->page_pool); in mana_create_page_pool()
2177 rxq->page_pool = NULL; in mana_create_page_pool()
2188 struct gdma_dev *gd = apc->ac->gdma_dev; in mana_create_rxq()
2195 struct mana_rxq *rxq; in mana_create_rxq() local
2198 gc = gd->gdma_context; in mana_create_rxq()
2200 rxq = kzalloc(struct_size(rxq, rx_oobs, apc->rx_queue_size), in mana_create_rxq()
2202 if (!rxq) in mana_create_rxq()
2205 rxq->ndev = ndev; in mana_create_rxq()
2206 rxq->num_rx_buf = apc->rx_queue_size; in mana_create_rxq()
2207 rxq->rxq_idx = rxq_idx; in mana_create_rxq()
2208 rxq->rxobj = INVALID_MANA_HANDLE; in mana_create_rxq()
2210 mana_get_rxbuf_cfg(ndev->mtu, &rxq->datasize, &rxq->alloc_size, in mana_create_rxq()
2211 &rxq->headroom); in mana_create_rxq()
2214 err = mana_create_page_pool(rxq, gc); in mana_create_rxq()
2220 err = mana_alloc_rx_wqe(apc, rxq, &rq_size, &cq_size); in mana_create_rxq()
2232 err = mana_gd_create_mana_wq_cq(gd, &spec, &rxq->gdma_rq); in mana_create_rxq()
2237 cq = &rxq->rx_cq; in mana_create_rxq()
2238 cq->type = MANA_CQ_TYPE_RX; in mana_create_rxq()
2239 cq->rxq = rxq; in mana_create_rxq()
2246 spec.cq.parent_eq = eq->eq; in mana_create_rxq()
2248 err = mana_gd_create_mana_wq_cq(gd, &spec, &cq->gdma_cq); in mana_create_rxq()
2254 wq_spec.gdma_region = rxq->gdma_rq->mem_info.dma_region_handle; in mana_create_rxq()
2255 wq_spec.queue_size = rxq->gdma_rq->queue_size; in mana_create_rxq()
2257 cq_spec.gdma_region = cq->gdma_cq->mem_info.dma_region_handle; in mana_create_rxq()
2258 cq_spec.queue_size = cq->gdma_cq->queue_size; in mana_create_rxq()
2260 cq_spec.attached_eq = cq->gdma_cq->cq.parent->id; in mana_create_rxq()
2262 err = mana_create_wq_obj(apc, apc->port_handle, GDMA_RQ, in mana_create_rxq()
2263 &wq_spec, &cq_spec, &rxq->rxobj); in mana_create_rxq()
2267 rxq->gdma_rq->id = wq_spec.queue_index; in mana_create_rxq()
2268 cq->gdma_cq->id = cq_spec.queue_index; in mana_create_rxq()
2270 rxq->gdma_rq->mem_info.dma_region_handle = GDMA_INVALID_DMA_REGION; in mana_create_rxq()
2271 cq->gdma_cq->mem_info.dma_region_handle = GDMA_INVALID_DMA_REGION; in mana_create_rxq()
2273 rxq->gdma_id = rxq->gdma_rq->id; in mana_create_rxq()
2274 cq->gdma_id = cq->gdma_cq->id; in mana_create_rxq()
2276 err = mana_push_wqe(rxq); in mana_create_rxq()
2280 if (WARN_ON(cq->gdma_id >= gc->max_num_cqs)) { in mana_create_rxq()
2281 err = -EINVAL; in mana_create_rxq()
2285 gc->cq_table[cq->gdma_id] = cq->gdma_cq; in mana_create_rxq()
2287 netif_napi_add_weight(ndev, &cq->napi, mana_poll, 1); in mana_create_rxq()
2289 WARN_ON(xdp_rxq_info_reg(&rxq->xdp_rxq, ndev, rxq_idx, in mana_create_rxq()
2290 cq->napi.napi_id)); in mana_create_rxq()
2291 WARN_ON(xdp_rxq_info_reg_mem_model(&rxq->xdp_rxq, MEM_TYPE_PAGE_POOL, in mana_create_rxq()
2292 rxq->page_pool)); in mana_create_rxq()
2294 napi_enable(&cq->napi); in mana_create_rxq()
2296 mana_gd_ring_cq(cq->gdma_cq, SET_ARM_BIT); in mana_create_rxq()
2299 return rxq; in mana_create_rxq()
2301 netdev_err(ndev, "Failed to create RXQ: err = %d\n", err); in mana_create_rxq()
2303 mana_destroy_rxq(apc, rxq, false); in mana_create_rxq()
2314 struct mana_context *ac = apc->ac; in mana_add_rx_queues()
2315 struct mana_rxq *rxq; in mana_add_rx_queues() local
2319 for (i = 0; i < apc->num_queues; i++) { in mana_add_rx_queues()
2320 rxq = mana_create_rxq(apc, i, &ac->eqs[i], ndev); in mana_add_rx_queues()
2321 if (!rxq) { in mana_add_rx_queues()
2322 err = -ENOMEM; in mana_add_rx_queues()
2326 u64_stats_init(&rxq->stats.syncp); in mana_add_rx_queues()
2328 apc->rxqs[i] = rxq; in mana_add_rx_queues()
2331 apc->default_rxobj = apc->rxqs[0]->rxobj; in mana_add_rx_queues()
2338 struct gdma_dev *gd = apc->ac->gdma_dev; in mana_destroy_vport()
2339 struct mana_rxq *rxq; in mana_destroy_vport() local
2342 for (rxq_idx = 0; rxq_idx < apc->num_queues; rxq_idx++) { in mana_destroy_vport()
2343 rxq = apc->rxqs[rxq_idx]; in mana_destroy_vport()
2344 if (!rxq) in mana_destroy_vport()
2347 mana_destroy_rxq(apc, rxq, true); in mana_destroy_vport()
2348 apc->rxqs[rxq_idx] = NULL; in mana_destroy_vport()
2354 if (gd->gdma_context->is_pf) in mana_destroy_vport()
2361 struct gdma_dev *gd = apc->ac->gdma_dev; in mana_create_vport()
2364 apc->default_rxobj = INVALID_MANA_HANDLE; in mana_create_vport()
2366 if (gd->gdma_context->is_pf) { in mana_create_vport()
2372 err = mana_cfg_vport(apc, gd->pdid, gd->doorbell); in mana_create_vport()
2381 if (!apc->indir_table_sz) { in mana_rss_table_alloc()
2382 netdev_err(apc->ndev, in mana_rss_table_alloc()
2384 apc->port_idx); in mana_rss_table_alloc()
2385 return -EINVAL; in mana_rss_table_alloc()
2388 apc->indir_table = kcalloc(apc->indir_table_sz, sizeof(u32), GFP_KERNEL); in mana_rss_table_alloc()
2389 if (!apc->indir_table) in mana_rss_table_alloc()
2390 return -ENOMEM; in mana_rss_table_alloc()
2392 apc->rxobj_table = kcalloc(apc->indir_table_sz, sizeof(mana_handle_t), GFP_KERNEL); in mana_rss_table_alloc()
2393 if (!apc->rxobj_table) { in mana_rss_table_alloc()
2394 kfree(apc->indir_table); in mana_rss_table_alloc()
2395 return -ENOMEM; in mana_rss_table_alloc()
2405 for (i = 0; i < apc->indir_table_sz; i++) in mana_rss_table_init()
2406 apc->indir_table[i] = in mana_rss_table_init()
2407 ethtool_rxfh_indir_default(i, apc->num_queues); in mana_rss_table_init()
2418 for (i = 0; i < apc->indir_table_sz; i++) { in mana_config_rss()
2419 queue_idx = apc->indir_table[i]; in mana_config_rss()
2420 apc->rxobj_table[i] = apc->rxqs[queue_idx]->rxobj; in mana_config_rss()
2437 struct net_device *ndev = apc->ndev; in mana_query_gf_stats()
2470 err = mana_send_request(apc->ac, &req, sizeof(req), &resp, in mana_query_gf_stats()
2484 apc->eth_stats.hc_rx_discards_no_wqe = resp.rx_discards_nowqe; in mana_query_gf_stats()
2485 apc->eth_stats.hc_rx_err_vport_disabled = resp.rx_err_vport_disabled; in mana_query_gf_stats()
2486 apc->eth_stats.hc_rx_bytes = resp.hc_rx_bytes; in mana_query_gf_stats()
2487 apc->eth_stats.hc_rx_ucast_pkts = resp.hc_rx_ucast_pkts; in mana_query_gf_stats()
2488 apc->eth_stats.hc_rx_ucast_bytes = resp.hc_rx_ucast_bytes; in mana_query_gf_stats()
2489 apc->eth_stats.hc_rx_bcast_pkts = resp.hc_rx_bcast_pkts; in mana_query_gf_stats()
2490 apc->eth_stats.hc_rx_bcast_bytes = resp.hc_rx_bcast_bytes; in mana_query_gf_stats()
2491 apc->eth_stats.hc_rx_mcast_pkts = resp.hc_rx_mcast_pkts; in mana_query_gf_stats()
2492 apc->eth_stats.hc_rx_mcast_bytes = resp.hc_rx_mcast_bytes; in mana_query_gf_stats()
2493 apc->eth_stats.hc_tx_err_gf_disabled = resp.tx_err_gf_disabled; in mana_query_gf_stats()
2494 apc->eth_stats.hc_tx_err_vport_disabled = resp.tx_err_vport_disabled; in mana_query_gf_stats()
2495 apc->eth_stats.hc_tx_err_inval_vportoffset_pkt = in mana_query_gf_stats()
2497 apc->eth_stats.hc_tx_err_vlan_enforcement = in mana_query_gf_stats()
2499 apc->eth_stats.hc_tx_err_eth_type_enforcement = in mana_query_gf_stats()
2501 apc->eth_stats.hc_tx_err_sa_enforcement = resp.tx_err_SA_enforcement; in mana_query_gf_stats()
2502 apc->eth_stats.hc_tx_err_sqpdid_enforcement = in mana_query_gf_stats()
2504 apc->eth_stats.hc_tx_err_cqpdid_enforcement = in mana_query_gf_stats()
2506 apc->eth_stats.hc_tx_err_mtu_violation = resp.tx_err_mtu_violation; in mana_query_gf_stats()
2507 apc->eth_stats.hc_tx_err_inval_oob = resp.tx_err_inval_oob; in mana_query_gf_stats()
2508 apc->eth_stats.hc_tx_bytes = resp.hc_tx_bytes; in mana_query_gf_stats()
2509 apc->eth_stats.hc_tx_ucast_pkts = resp.hc_tx_ucast_pkts; in mana_query_gf_stats()
2510 apc->eth_stats.hc_tx_ucast_bytes = resp.hc_tx_ucast_bytes; in mana_query_gf_stats()
2511 apc->eth_stats.hc_tx_bcast_pkts = resp.hc_tx_bcast_pkts; in mana_query_gf_stats()
2512 apc->eth_stats.hc_tx_bcast_bytes = resp.hc_tx_bcast_bytes; in mana_query_gf_stats()
2513 apc->eth_stats.hc_tx_mcast_pkts = resp.hc_tx_mcast_pkts; in mana_query_gf_stats()
2514 apc->eth_stats.hc_tx_mcast_bytes = resp.hc_tx_mcast_bytes; in mana_query_gf_stats()
2515 apc->eth_stats.hc_tx_err_gdma = resp.tx_err_gdma; in mana_query_gf_stats()
2522 int port_idx = apc->port_idx; in mana_init_port()
2530 &apc->indir_table_sz); in mana_init_port()
2538 if (apc->max_queues > max_queues) in mana_init_port()
2539 apc->max_queues = max_queues; in mana_init_port()
2541 if (apc->num_queues > apc->max_queues) in mana_init_port()
2542 apc->num_queues = apc->max_queues; in mana_init_port()
2544 eth_hw_addr_set(ndev, apc->mac_addr); in mana_init_port()
2556 struct gdma_dev *gd = apc->ac->gdma_dev; in mana_alloc_queues()
2563 err = netif_set_real_num_tx_queues(ndev, apc->num_queues); in mana_alloc_queues()
2571 apc->rss_state = apc->num_queues > 1 ? TRI_STATE_TRUE : TRI_STATE_FALSE; in mana_alloc_queues()
2573 err = netif_set_real_num_rx_queues(ndev, apc->num_queues); in mana_alloc_queues()
2583 if (gd->gdma_context->is_pf) { in mana_alloc_queues()
2609 if (apc->port_st_save) { in mana_attach()
2617 apc->port_is_up = apc->port_st_save; in mana_attach()
2622 if (apc->port_is_up) in mana_attach()
2634 struct gdma_dev *gd = apc->ac->gdma_dev; in mana_dealloc_queues()
2640 if (apc->port_is_up) in mana_dealloc_queues()
2641 return -EINVAL; in mana_dealloc_queues()
2645 if (gd->gdma_context->is_pf) in mana_dealloc_queues()
2648 /* No packet can be transmitted now since apc->port_is_up is false. in mana_dealloc_queues()
2649 * There is still a tiny chance that mana_poll_tx_cq() can re-enable in mana_dealloc_queues()
2650 * a txq because it may not timely see apc->port_is_up being cleared in mana_dealloc_queues()
2652 * new packets due to apc->port_is_up being false. in mana_dealloc_queues()
2654 * Drain all the in-flight TX packets. in mana_dealloc_queues()
2661 for (i = 0; i < apc->num_queues; i++) { in mana_dealloc_queues()
2662 txq = &apc->tx_qp[i].txq; in mana_dealloc_queues()
2664 while (atomic_read(&txq->pending_sends) > 0 && in mana_dealloc_queues()
2669 if (atomic_read(&txq->pending_sends)) { in mana_dealloc_queues()
2670 err = pcie_flr(to_pci_dev(gd->gdma_context->dev)); in mana_dealloc_queues()
2673 err, atomic_read(&txq->pending_sends), in mana_dealloc_queues()
2674 txq->gdma_txq_id); in mana_dealloc_queues()
2680 for (i = 0; i < apc->num_queues; i++) { in mana_dealloc_queues()
2681 txq = &apc->tx_qp[i].txq; in mana_dealloc_queues()
2682 while ((skb = skb_dequeue(&txq->pending_skbs))) { in mana_dealloc_queues()
2686 atomic_set(&txq->pending_sends, 0); in mana_dealloc_queues()
2692 apc->rss_state = TRI_STATE_FALSE; in mana_dealloc_queues()
2711 apc->port_st_save = apc->port_is_up; in mana_detach()
2712 apc->port_is_up = false; in mana_detach()
2720 if (apc->port_st_save) { in mana_detach()
2737 struct gdma_context *gc = ac->gdma_dev->gdma_context; in mana_probe_port()
2743 gc->max_num_queues); in mana_probe_port()
2745 return -ENOMEM; in mana_probe_port()
2750 apc->ac = ac; in mana_probe_port()
2751 apc->ndev = ndev; in mana_probe_port()
2752 apc->max_queues = gc->max_num_queues; in mana_probe_port()
2753 apc->num_queues = gc->max_num_queues; in mana_probe_port()
2754 apc->tx_queue_size = DEF_TX_BUFFERS_PER_QUEUE; in mana_probe_port()
2755 apc->rx_queue_size = DEF_RX_BUFFERS_PER_QUEUE; in mana_probe_port()
2756 apc->port_handle = INVALID_MANA_HANDLE; in mana_probe_port()
2757 apc->pf_filter_handle = INVALID_MANA_HANDLE; in mana_probe_port()
2758 apc->port_idx = port_idx; in mana_probe_port()
2760 mutex_init(&apc->vport_mutex); in mana_probe_port()
2761 apc->vport_use_count = 0; in mana_probe_port()
2763 ndev->netdev_ops = &mana_devops; in mana_probe_port()
2764 ndev->ethtool_ops = &mana_ethtool_ops; in mana_probe_port()
2765 ndev->mtu = ETH_DATA_LEN; in mana_probe_port()
2766 ndev->max_mtu = gc->adapter_mtu - ETH_HLEN; in mana_probe_port()
2767 ndev->min_mtu = ETH_MIN_MTU; in mana_probe_port()
2768 ndev->needed_headroom = MANA_HEADROOM; in mana_probe_port()
2769 ndev->dev_port = port_idx; in mana_probe_port()
2770 SET_NETDEV_DEV(ndev, gc->dev); in mana_probe_port()
2774 netdev_rss_key_fill(apc->hashkey, MANA_HASH_KEY_SIZE); in mana_probe_port()
2786 ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; in mana_probe_port()
2787 ndev->hw_features |= NETIF_F_RXCSUM; in mana_probe_port()
2788 ndev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6; in mana_probe_port()
2789 ndev->hw_features |= NETIF_F_RXHASH; in mana_probe_port()
2790 ndev->features = ndev->hw_features | NETIF_F_HW_VLAN_CTAG_TX | in mana_probe_port()
2792 ndev->vlan_features = ndev->features; in mana_probe_port()
2825 struct auxiliary_device *adev = gd->adev; in remove_adev()
2826 int id = adev->id; in remove_adev()
2832 gd->adev = NULL; in remove_adev()
2843 return -ENOMEM; in add_adev()
2845 adev = &madev->adev; in add_adev()
2849 adev->id = ret; in add_adev()
2851 adev->name = "rdma"; in add_adev()
2852 adev->dev.parent = gd->gdma_context->dev; in add_adev()
2853 adev->dev.release = adev_release; in add_adev()
2854 madev->mdev = gd; in add_adev()
2866 gd->adev = adev; in add_adev()
2873 mana_adev_idx_free(adev->id); in add_adev()
2883 struct gdma_context *gc = gd->gdma_context; in mana_probe()
2884 struct mana_context *ac = gd->driver_data; in mana_probe()
2885 struct device *dev = gc->dev; in mana_probe()
2901 return -ENOMEM; in mana_probe()
2903 ac->gdma_dev = gd; in mana_probe()
2904 gd->driver_data = ac; in mana_probe()
2917 ac->num_ports = num_ports; in mana_probe()
2919 if (ac->num_ports != num_ports) { in mana_probe()
2920 dev_err(dev, "The number of vPorts changed: %d->%d\n", in mana_probe()
2921 ac->num_ports, num_ports); in mana_probe()
2922 err = -EPROTO; in mana_probe()
2927 if (ac->num_ports == 0) in mana_probe()
2930 if (ac->num_ports > MAX_PORTS_IN_MANA_DEV) in mana_probe()
2931 ac->num_ports = MAX_PORTS_IN_MANA_DEV; in mana_probe()
2934 for (i = 0; i < ac->num_ports; i++) { in mana_probe()
2935 err = mana_probe_port(ac, i, &ac->ports[i]); in mana_probe()
2947 for (i = 0; i < ac->num_ports; i++) { in mana_probe()
2949 err = mana_attach(ac->ports[i]); in mana_probe()
2973 struct gdma_context *gc = gd->gdma_context; in mana_remove()
2974 struct mana_context *ac = gd->driver_data; in mana_remove()
2976 struct device *dev = gc->dev; in mana_remove()
2982 if (gd->adev) in mana_remove()
2985 for (i = 0; i < ac->num_ports; i++) { in mana_remove()
2986 ndev = ac->ports[i]; in mana_remove()
3025 gd->driver_data = NULL; in mana_remove()
3026 gd->gdma_context = NULL; in mana_remove()
3036 if (port_index >= ac->num_ports) in mana_get_primary_netdev_rcu()
3040 if (ac->ports[port_index]->flags & IFF_SLAVE) in mana_get_primary_netdev_rcu()
3041 ndev = netdev_master_upper_dev_get_rcu(ac->ports[port_index]); in mana_get_primary_netdev_rcu()
3043 ndev = ac->ports[port_index]; in mana_get_primary_netdev_rcu()