net/mlx5: enhance SR-IOV detection
[dpdk.git] / drivers / net / mlx5 / mlx5_ethdev.c
index 47d0862..0a881b6 100644 (file)
@@ -361,6 +361,38 @@ priv_ifreq(const struct priv *priv, int req, struct ifreq *ifr)
        return ret;
 }
 
+/**
+ * Return the number of active VFs for the current device.
+ *
+ * @param[in] priv
+ *   Pointer to private structure.
+ * @param[out] num_vfs
+ *   Number of active VFs.
+ *
+ * @return
+ *   0 on success, -1 on failure and errno is set.
+ */
+int
+priv_get_num_vfs(struct priv *priv, uint16_t *num_vfs)
+{
+       /* The sysfs entry name depends on the operating system. */
+       const char **name = (const char *[]){
+               "device/sriov_numvfs",
+               "device/mlx5_num_vfs",
+               NULL,
+       };
+       int ret;
+
+       do {
+               unsigned long ulong_num_vfs;
+
+               ret = priv_get_sysfs_ulong(priv, *name, &ulong_num_vfs);
+               if (!ret)
+                       *num_vfs = ulong_num_vfs;
+       } while (*(++name) && ret);
+       return ret;
+}
+
 /**
  * Get device MTU.
  *