> -----Original Message-----
> From: Xing, Beilei <beilei.x...@intel.com>
> Sent: Friday, May 19, 2023 3:31 PM
> To: Wu, Jingjing <jingjing...@intel.com>
> Cc: dev@dpdk.org; Liu, Mingxia <mingxia....@intel.com>; Xing, Beilei
> <beilei.x...@intel.com>; Wang, Xiao W <xiao.w.w...@intel.com>
> Subject: [PATCH v3 09/10] net/cpfl: support peer ports get
> 
> From: Beilei Xing <beilei.x...@intel.com>
> 
> This patch supports get hairpin peer ports.
> 
> Signed-off-by: Xiao Wang <xiao.w.w...@intel.com>
> Signed-off-by: Beilei Xing <beilei.x...@intel.com>
> ---
>  drivers/net/cpfl/cpfl_ethdev.c | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/drivers/net/cpfl/cpfl_ethdev.c b/drivers/net/cpfl/cpfl_ethdev.c
> index 3b480178c0..59c7e75d2a 100644
> --- a/drivers/net/cpfl/cpfl_ethdev.c
> +++ b/drivers/net/cpfl/cpfl_ethdev.c
> @@ -1069,6 +1069,39 @@ cpfl_dev_close(struct rte_eth_dev *dev)
>       return 0;
>  }
> 
> +static int
> +cpfl_hairpin_get_peer_ports(struct rte_eth_dev *dev, uint16_t *peer_ports,
> +                         __rte_unused size_t len, uint32_t tx)
> +{

Param len is used to identify the size of the peer ports array.
You should use it, and check if peer_ports is null. Otherwise will cause 
invalid access.

 *   array length
> +     struct cpfl_vport *cpfl_vport =
> +             (struct cpfl_vport *)dev->data->dev_private;
> +     struct idpf_tx_queue *txq;
> +     struct idpf_rx_queue *rxq;
> +     struct cpfl_tx_queue *cpfl_txq;
> +     struct cpfl_rx_queue *cpfl_rxq;
> +     int i, j;
> +
> +     if (tx > 0) {
> +             for (i = cpfl_vport->nb_data_txq, j = 0; i < 
> dev->data->nb_tx_queues; i++,
> j++) {
> +                     txq = dev->data->tx_queues[i];
> +                     if (txq == NULL)
> +                             return -EINVAL;
> +                     cpfl_txq = (struct cpfl_tx_queue *)txq;
> +                     peer_ports[j] = cpfl_txq->hairpin_info.peer_rxp;
> +             }
> +     } else if (tx == 0) {
> +             for (i = cpfl_vport->nb_data_rxq, j = 0; i < 
> dev->data->nb_rx_queues; i++,
> j++) {
> +                     rxq = dev->data->rx_queues[i];
> +                     if (rxq == NULL)
> +                             return -EINVAL;
> +                     cpfl_rxq = (struct cpfl_rx_queue *)rxq;
> +                     peer_ports[j] = cpfl_rxq->hairpin_info.peer_txp;
> +             }
> +     }
> +
> +     return j;
> +}
> +
>  static const struct eth_dev_ops cpfl_eth_dev_ops = {
>       .dev_configure                  = cpfl_dev_configure,
>       .dev_close                      = cpfl_dev_close,
> @@ -1098,6 +1131,7 @@ static const struct eth_dev_ops cpfl_eth_dev_ops = {
>       .hairpin_cap_get                = cpfl_hairpin_cap_get,
>       .rx_hairpin_queue_setup         = cpfl_rx_hairpin_queue_setup,
>       .tx_hairpin_queue_setup         = cpfl_tx_hairpin_queue_setup,
> +     .hairpin_get_peer_ports         = cpfl_hairpin_get_peer_ports,
>  };
> 
>  static int
> --
> 2.26.2

Reply via email to