vdpa/mlx5: add CPU core parameter to bind polling thread
[dpdk.git] / drivers / vdpa / mlx5 / mlx5_vdpa.h
index 5fc801e..b4dd383 100644 (file)
@@ -12,6 +12,7 @@
 #pragma GCC diagnostic ignored "-Wpedantic"
 #endif
 #include <rte_vdpa.h>
+#include <rte_vdpa_dev.h>
 #include <rte_vhost.h>
 #ifdef PEDANTIC
 #pragma GCC diagnostic error "-Wpedantic"
 #define VIRTIO_F_RING_PACKED 34
 #endif
 
+#define MLX5_VDPA_DEFAULT_TIMER_DELAY_US 0u
+#define MLX5_VDPA_DEFAULT_TIMER_STEP_US 1u
+
 struct mlx5_vdpa_cq {
        uint16_t log_desc_n;
        uint32_t cq_ci:24;
        uint32_t arm_sn:2;
+       uint32_t armed:1;
        int callfd;
        rte_spinlock_t sl;
        struct mlx5_devx_obj *cq;
@@ -69,11 +74,20 @@ struct mlx5_vdpa_query_mr {
        int is_indirect;
 };
 
+enum {
+       MLX5_VDPA_NOTIFIER_STATE_DISABLED,
+       MLX5_VDPA_NOTIFIER_STATE_ENABLED,
+       MLX5_VDPA_NOTIFIER_STATE_ERR
+};
+
 struct mlx5_vdpa_virtq {
        SLIST_ENTRY(mlx5_vdpa_virtq) next;
        uint8_t enable;
        uint16_t index;
        uint16_t vq_size;
+       uint8_t notifier_state;
+       bool stopped;
+       uint32_t version;
        struct mlx5_vdpa_priv *priv;
        struct mlx5_devx_obj *virtq;
        struct mlx5_devx_obj *counters;
@@ -84,6 +98,8 @@ struct mlx5_vdpa_virtq {
                uint32_t size;
        } umems[3];
        struct rte_intr_handle intr_handle;
+       uint64_t err_time[3]; /* RDTSC time of recent errors. */
+       uint32_t n_retry;
        struct mlx5_devx_virtio_q_couners_attr reset;
 };
 
@@ -99,11 +115,27 @@ struct mlx5_vdpa_steer {
        } rss[7];
 };
 
+enum {
+       MLX5_VDPA_EVENT_MODE_DYNAMIC_TIMER,
+       MLX5_VDPA_EVENT_MODE_FIXED_TIMER,
+       MLX5_VDPA_EVENT_MODE_ONLY_INTERRUPT
+};
+
 struct mlx5_vdpa_priv {
        TAILQ_ENTRY(mlx5_vdpa_priv) next;
        uint8_t configured;
-       uint8_t direct_notifier; /* Whether direct notifier is on or off. */
-       int id; /* vDPA device id. */
+       pthread_mutex_t vq_config_lock;
+       uint64_t last_traffic_tic;
+       pthread_t timer_tid;
+       pthread_mutex_t timer_lock;
+       pthread_cond_t timer_cond;
+       volatile uint8_t timer_on;
+       int event_mode;
+       int event_core; /* Event thread cpu affinity core. */
+       uint32_t event_us;
+       uint32_t timer_delay_us;
+       uint32_t no_traffic_time_s;
+       struct rte_vdpa_device *vdev; /* vDPA device. */
        int vid; /* vhost device id. */
        struct ibv_context *ctx; /* Device context. */
        struct rte_pci_device *pci_dev;
@@ -115,11 +147,14 @@ struct mlx5_vdpa_priv {
        struct rte_vhost_memory *vmem;
        uint32_t eqn;
        struct mlx5dv_devx_event_channel *eventc;
+       struct mlx5dv_devx_event_channel *err_chnl;
        struct mlx5dv_devx_uar *uar;
        struct rte_intr_handle intr_handle;
+       struct rte_intr_handle err_intr_handle;
        struct mlx5_devx_obj *td;
-       struct mlx5_devx_obj *tis;
+       struct mlx5_devx_obj *tiss[16]; /* TIS list for each LAG port. */
        uint16_t nr_virtqs;
+       uint8_t num_lag_ports;
        uint64_t features; /* Negotiated features. */
        uint16_t log_max_rqt_size;
        struct mlx5_vdpa_steer steer;
@@ -231,6 +266,25 @@ int mlx5_vdpa_cqe_event_setup(struct mlx5_vdpa_priv *priv);
  */
 void mlx5_vdpa_cqe_event_unset(struct mlx5_vdpa_priv *priv);
 
+/**
+ * Setup error interrupt handler.
+ *
+ * @param[in] priv
+ *   The vdpa driver private structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int mlx5_vdpa_err_event_setup(struct mlx5_vdpa_priv *priv);
+
+/**
+ * Unset error event handler.
+ *
+ * @param[in] priv
+ *   The vdpa driver private structure.
+ */
+void mlx5_vdpa_err_event_unset(struct mlx5_vdpa_priv *priv);
+
 /**
  * Release a virtq and all its related resources.
  *
@@ -364,6 +418,19 @@ int mlx5_vdpa_virtq_modify(struct mlx5_vdpa_virtq *virtq, int state);
  */
 int mlx5_vdpa_virtq_stop(struct mlx5_vdpa_priv *priv, int index);
 
+/**
+ * Query virtq information.
+ *
+ * @param[in] priv
+ *   The vdpa driver private structure.
+ * @param[in] index
+ *   The virtq index.
+ *
+ * @return
+ *   0 on success, a negative value otherwise.
+ */
+int mlx5_vdpa_virtq_query(struct mlx5_vdpa_priv *priv, int index);
+
 /**
  * Get virtq statistics.
  *