Skip to contentSkip to conversation

net/iavf: handle iavf reset gracefully

RFC New Shiyang He 1 participant 1 message May 23, 2023 Network drivers

lore
Share & tools
lore

Shiyang He

author
#0 lore raw

RFC 1/1 net/iavf: handle iavf reset gracefully

Originally, when vf received PF-to-VF reset event, the iavf PMD did not perform special actions, resulting in vf being offline and unavailable. This commit handle the PF-to-VF reset event by performing all necessary actions to bring the vf back online and available.

---
 drivers/net/iavf/iavf.h        |  29 +++++++
 drivers/net/iavf/iavf_ethdev.c | 144 +++++++++++++++++++++++++++++++++
 drivers/net/iavf/iavf_rxtx.c   |  25 ++++++
 drivers/net/iavf/iavf_rxtx.h   |   1 +
 drivers/net/iavf/iavf_vchnl.c  |  12 +++
 5 files changed, 211 insertions(+)
drivers/net/iavf/iavf.h +29 -0
index aa18650ffa..79030944f7 100644
@@ -95,6 +95,24 @@
 
 #define IAVF_L2TPV2_FLAGS_LEN	0x4000
 
+#ifndef DIV_ROUND_UP
+#define DIV_ROUND_UP(n, d) (	\
+{								\
+	const typeof(d) __d = d;	\
+	(((n) + (__d) - 1) / (__d));\
+}								\
+)
+#endif
+#ifndef DELAY
+#define DELAY(x) rte_delay_us(x)
+#endif
+#ifndef msleep
+#define msleep(x) DELAY(1000 * (x))
+#endif
+#ifndef usleep_range
+#define usleep_range(min, max) msleep(DIV_ROUND_UP(min, 1000))
+#endif
+
 struct iavf_adapter;
 struct iavf_rx_queue;
 struct iavf_tx_queue;
@@ -279,6 +297,8 @@ struct iavf_info {
 
 	uint32_t ptp_caps;
 	rte_spinlock_t phc_time_aq_lock;
+
+	bool auto_reset_enabled;
 };
 
 #define IAVF_MAX_PKT_TYPE 1024
@@ -423,6 +443,14 @@ _atomic_set_async_response_cmd(struct iavf_info *vf, enum virtchnl_ops ops)
 
 	return !ret;
 }
+
+static inline bool
+iavf_is_reset(struct iavf_hw *hw)
+{
+	return !(IAVF_READ_REG(hw, IAVF_VF_ARQLEN1) &
+		 IAVF_VF_ARQLEN1_ARQENABLE_MASK);
+}
+
 int iavf_check_api_version(struct iavf_adapter *adapter);
 int iavf_get_vf_resource(struct iavf_adapter *adapter);
 void iavf_dev_event_handler_fini(void);
@@ -498,4 +526,5 @@ int iavf_flow_unsub(struct iavf_adapter *adapter,
 		    struct iavf_fsub_conf *filter);
 int iavf_flow_sub_check(struct iavf_adapter *adapter,
 			struct iavf_fsub_conf *filter);
+int iavf_handle_hw_reset(struct rte_eth_dev *dev);
 #endif /* _IAVF_ETHDEV_H_ */
drivers/net/iavf/iavf_ethdev.c +144 -0

162 lines not on this page · raw message

drivers/net/iavf/iavf_rxtx.c +25 -0
index b1d0fbceb6..cc58564461 100644
@@ -1093,6 +1093,31 @@ iavf_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 	rte_free(q);
 }
 
+void
+iavf_reset_queues(struct rte_eth_dev *dev)
+{
+	struct iavf_rx_queue *rxq;
+	struct iavf_tx_queue *txq;
+	int i;
+
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		txq = dev->data->tx_queues[i];
+		if (!txq)
+			continue;
+		iavf_txq_release_mbufs_ops[txq->rel_mbufs_type].release_mbufs(txq);
+		reset_tx_queue(txq);
+		dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
+	}
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		rxq = dev->data->rx_queues[i];
+		if (!rxq)
+			continue;
+		iavf_rxq_release_mbufs_ops[rxq->rel_mbufs_type].release_mbufs(rxq);
+		reset_rx_queue(rxq);
+		dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
+	}
+}
+
 void
 iavf_stop_queues(struct rte_eth_dev *dev)
 {
drivers/net/iavf/iavf_rxtx.h +1 -0
index 09e2127db0..622a9dbfef 100644
@@ -640,6 +640,7 @@ int iavf_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
 int iavf_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
 int iavf_dev_tx_done_cleanup(void *txq, uint32_t free_cnt);
 void iavf_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
+void iavf_reset_queues(struct rte_eth_dev *dev);
 void iavf_stop_queues(struct rte_eth_dev *dev);
 uint16_t iavf_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 		       uint16_t nb_pkts);
drivers/net/iavf/iavf_vchnl.c +12 -0
index ab721e082b..2a36526b10 100644
@@ -31,6 +31,10 @@
 
 #define MAX_EVENT_PENDING 16
 
+static void iavf_dev_event_post(struct rte_eth_dev *dev,
+		enum rte_eth_event_type event,
+		void *param, size_t param_alloc_size);
+
 struct iavf_event_element {
 	TAILQ_ENTRY(iavf_event_element) next;
 	struct rte_eth_dev *dev;
@@ -80,6 +84,14 @@ iavf_dev_event_handle(void *param __rte_unused)
 		TAILQ_FOREACH_SAFE(pos, &pending, next, save_next) {
 			TAILQ_REMOVE(&pending, pos, next);
 			rte_eth_dev_callback_process(pos->dev, pos->event, pos->param);
+
+			switch (pos->event) {
+			case RTE_ETH_EVENT_INTR_RESET:
+				iavf_handle_hw_reset(pos->dev);
+				break;
+			default:
+				break;
+			}
 			rte_free(pos);
 		}
 	}
Signature · 1 line
2.37.2