net/ice/base: fix null pointer dereferences for parser
[dpdk.git] / drivers / net / mlx5 / mlx5_ethdev.c
index 4f97a69..82e2284 100644 (file)
@@ -23,6 +23,8 @@
 #include <mlx5_malloc.h>
 
 #include "mlx5_rxtx.h"
+#include "mlx5_rx.h"
+#include "mlx5_tx.h"
 #include "mlx5_autoconf.h"
 
 /**
@@ -333,7 +335,7 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
        if (priv->representor) {
                uint16_t port_id;
 
-               MLX5_ETH_FOREACH_DEV(port_id, priv->pci_dev) {
+               MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
                        struct mlx5_priv *opriv =
                                rte_eth_devices[port_id].data->dev_private;
 
@@ -363,12 +365,15 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
  *
  * @param info
  *   Port switch info.
+ * @param hpf_type
+ *   Use this type if port is HPF.
  *
  * @return
  *   Encoded representor ID.
  */
 uint16_t
-mlx5_representor_id_encode(const struct mlx5_switch_info *info)
+mlx5_representor_id_encode(const struct mlx5_switch_info *info,
+                          enum rte_eth_representor_type hpf_type)
 {
        enum rte_eth_representor_type type = RTE_ETH_REPRESENTOR_VF;
        uint16_t repr = info->port_name;
@@ -377,8 +382,10 @@ mlx5_representor_id_encode(const struct mlx5_switch_info *info)
                return UINT16_MAX;
        if (info->name_type == MLX5_PHYS_PORT_NAME_TYPE_PFSF)
                type = RTE_ETH_REPRESENTOR_SF;
-       if (info->name_type == MLX5_PHYS_PORT_NAME_TYPE_PFHPF)
+       if (info->name_type == MLX5_PHYS_PORT_NAME_TYPE_PFHPF) {
+               type = hpf_type;
                repr = UINT16_MAX;
+       }
        return MLX5_REPRESENTOR_ID(info->pf_num, type, repr);
 }
 
@@ -403,12 +410,18 @@ mlx5_representor_info_get(struct rte_eth_dev *dev,
                          struct rte_eth_representor_info *info)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
-       int n_type = 3; /* Number of representor types, VF, HPF and SF. */
+       int n_type = 4; /* Representor types, VF, HPF@VF, SF and HPF@SF. */
        int n_pf = 2; /* Number of PFs. */
        int i = 0, pf;
+       int n_entries;
 
        if (info == NULL)
                goto out;
+
+       n_entries = n_type * n_pf;
+       if ((uint32_t)n_entries > info->nb_ranges_alloc)
+               n_entries = info->nb_ranges_alloc;
+
        info->controller = 0;
        info->pf = priv->pf_bond >= 0 ? priv->pf_bond : 0;
        for (pf = 0; pf < n_pf; ++pf) {
@@ -424,7 +437,9 @@ mlx5_representor_info_get(struct rte_eth_dev *dev,
                snprintf(info->ranges[i].name,
                         sizeof(info->ranges[i].name), "pf%dvf", pf);
                i++;
-               /* HPF range. */
+               if (i == n_entries)
+                       break;
+               /* HPF range of VF type. */
                info->ranges[i].type = RTE_ETH_REPRESENTOR_VF;
                info->ranges[i].controller = 0;
                info->ranges[i].pf = pf;
@@ -436,6 +451,8 @@ mlx5_representor_info_get(struct rte_eth_dev *dev,
                snprintf(info->ranges[i].name,
                         sizeof(info->ranges[i].name), "pf%dvf", pf);
                i++;
+               if (i == n_entries)
+                       break;
                /* SF range. */
                info->ranges[i].type = RTE_ETH_REPRESENTOR_SF;
                info->ranges[i].controller = 0;
@@ -448,7 +465,24 @@ mlx5_representor_info_get(struct rte_eth_dev *dev,
                snprintf(info->ranges[i].name,
                         sizeof(info->ranges[i].name), "pf%dsf", pf);
                i++;
+               if (i == n_entries)
+                       break;
+               /* HPF range of SF type. */
+               info->ranges[i].type = RTE_ETH_REPRESENTOR_SF;
+               info->ranges[i].controller = 0;
+               info->ranges[i].pf = pf;
+               info->ranges[i].vf = UINT16_MAX;
+               info->ranges[i].id_base =
+                       MLX5_REPRESENTOR_ID(pf, info->ranges[i].type, -1);
+               info->ranges[i].id_end =
+                       MLX5_REPRESENTOR_ID(pf, info->ranges[i].type, -1);
+               snprintf(info->ranges[i].name,
+                        sizeof(info->ranges[i].name), "pf%dsf", pf);
+               i++;
+               if (i == n_entries)
+                       break;
        }
+       info->nb_ranges = i;
 out:
        return n_type * n_pf;
 }