net/sfc/base: fix a typo in unicast filter insertion comment
[dpdk.git] / drivers / net / failsafe / failsafe_ether.c
index 733e95d..191f95f 100644 (file)
@@ -260,6 +260,7 @@ fs_dev_remove(struct sub_device *sdev)
                sdev->state = DEV_ACTIVE;
                /* fallthrough */
        case DEV_ACTIVE:
+               failsafe_eth_dev_unregister_callbacks(sdev);
                rte_eth_dev_close(PORT_ID(sdev));
                sdev->state = DEV_PROBED;
                /* fallthrough */
@@ -320,6 +321,35 @@ fs_rxtx_clean(struct sub_device *sdev)
        return 1;
 }
 
+void
+failsafe_eth_dev_unregister_callbacks(struct sub_device *sdev)
+{
+       int ret;
+
+       if (sdev == NULL)
+               return;
+       if (sdev->rmv_callback) {
+               ret = rte_eth_dev_callback_unregister(PORT_ID(sdev),
+                                               RTE_ETH_EVENT_INTR_RMV,
+                                               failsafe_eth_rmv_event_callback,
+                                               sdev);
+               if (ret)
+                       WARN("Failed to unregister RMV callback for sub_device"
+                            " %d", SUB_ID(sdev));
+               sdev->rmv_callback = 0;
+       }
+       if (sdev->lsc_callback) {
+               ret = rte_eth_dev_callback_unregister(PORT_ID(sdev),
+                                               RTE_ETH_EVENT_INTR_LSC,
+                                               failsafe_eth_lsc_event_callback,
+                                               sdev);
+               if (ret)
+                       WARN("Failed to unregister LSC callback for sub_device"
+                            " %d", SUB_ID(sdev));
+               sdev->lsc_callback = 0;
+       }
+}
+
 void
 failsafe_dev_remove(struct rte_eth_dev *dev)
 {
@@ -336,6 +366,88 @@ failsafe_dev_remove(struct rte_eth_dev *dev)
                }
 }
 
+static int
+failsafe_eth_dev_rx_queues_sync(struct rte_eth_dev *dev)
+{
+       struct rxq *rxq;
+       int ret;
+       uint16_t i;
+
+       for (i = 0; i < dev->data->nb_rx_queues; i++) {
+               rxq = dev->data->rx_queues[i];
+
+               if (rxq->info.conf.rx_deferred_start &&
+                   dev->data->rx_queue_state[i] ==
+                                               RTE_ETH_QUEUE_STATE_STARTED) {
+                       /*
+                        * The subdevice Rx queue does not launch on device
+                        * start if deferred start flag is set. It needs to be
+                        * started manually in case an appropriate failsafe Rx
+                        * queue has been started earlier.
+                        */
+                       ret = dev->dev_ops->rx_queue_start(dev, i);
+                       if (ret) {
+                               ERROR("Could not synchronize Rx queue %d", i);
+                               return ret;
+                       }
+               } else if (dev->data->rx_queue_state[i] ==
+                                               RTE_ETH_QUEUE_STATE_STOPPED) {
+                       /*
+                        * The subdevice Rx queue needs to be stopped manually
+                        * in case an appropriate failsafe Rx queue has been
+                        * stopped earlier.
+                        */
+                       ret = dev->dev_ops->rx_queue_stop(dev, i);
+                       if (ret) {
+                               ERROR("Could not synchronize Rx queue %d", i);
+                               return ret;
+                       }
+               }
+       }
+       return 0;
+}
+
+static int
+failsafe_eth_dev_tx_queues_sync(struct rte_eth_dev *dev)
+{
+       struct txq *txq;
+       int ret;
+       uint16_t i;
+
+       for (i = 0; i < dev->data->nb_tx_queues; i++) {
+               txq = dev->data->tx_queues[i];
+
+               if (txq->info.conf.tx_deferred_start &&
+                   dev->data->tx_queue_state[i] ==
+                                               RTE_ETH_QUEUE_STATE_STARTED) {
+                       /*
+                        * The subdevice Tx queue does not launch on device
+                        * start if deferred start flag is set. It needs to be
+                        * started manually in case an appropriate failsafe Tx
+                        * queue has been started earlier.
+                        */
+                       ret = dev->dev_ops->tx_queue_start(dev, i);
+                       if (ret) {
+                               ERROR("Could not synchronize Tx queue %d", i);
+                               return ret;
+                       }
+               } else if (dev->data->tx_queue_state[i] ==
+                                               RTE_ETH_QUEUE_STATE_STOPPED) {
+                       /*
+                        * The subdevice Tx queue needs to be stopped manually
+                        * in case an appropriate failsafe Tx queue has been
+                        * stopped earlier.
+                        */
+                       ret = dev->dev_ops->tx_queue_stop(dev, i);
+                       if (ret) {
+                               ERROR("Could not synchronize Tx queue %d", i);
+                               return ret;
+                       }
+               }
+       }
+       return 0;
+}
+
 int
 failsafe_eth_dev_state_sync(struct rte_eth_dev *dev)
 {
@@ -392,6 +504,12 @@ failsafe_eth_dev_state_sync(struct rte_eth_dev *dev)
        if (PRIV(dev)->state < DEV_STARTED)
                return 0;
        ret = dev->dev_ops->dev_start(dev);
+       if (ret)
+               goto err_remove;
+       ret = failsafe_eth_dev_rx_queues_sync(dev);
+       if (ret)
+               goto err_remove;
+       ret = failsafe_eth_dev_tx_queues_sync(dev);
        if (ret)
                goto err_remove;
        return 0;