net/failsafe: use SPDX tags in 6WIND copyrighted files
[dpdk.git] / drivers / net / failsafe / failsafe_ops.c
index 5cbc591..e7bb801 100644 (file)
@@ -1,34 +1,6 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright 2017 6WIND S.A.
- *   Copyright 2017 Mellanox.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of 6WIND S.A. nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2017 6WIND S.A.
+ * Copyright 2017 Mellanox.
  */
 
 #include <stdbool.h>
@@ -213,6 +185,13 @@ fs_dev_start(struct rte_eth_dev *dev)
                                continue;
                        return ret;
                }
+               ret = failsafe_rx_intr_install_subdevice(sdev);
+               if (ret) {
+                       if (!fs_err(sdev, ret))
+                               continue;
+                       rte_eth_dev_stop(PORT_ID(sdev));
+                       return ret;
+               }
                sdev->state = DEV_STARTED;
        }
        if (PRIV(dev)->state < DEV_STARTED)
@@ -230,6 +209,7 @@ fs_dev_stop(struct rte_eth_dev *dev)
        PRIV(dev)->state = DEV_STARTED - 1;
        FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_STARTED) {
                rte_eth_dev_stop(PORT_ID(sdev));
+               failsafe_rx_intr_uninstall_subdevice(sdev);
                sdev->state = DEV_STARTED - 1;
        }
        failsafe_rx_intr_uninstall(dev);
@@ -412,6 +392,10 @@ static int
 fs_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx)
 {
        struct rxq *rxq;
+       struct sub_device *sdev;
+       uint8_t i;
+       int ret;
+       int rc = 0;
 
        if (idx >= dev->data->nb_rx_queues) {
                rte_errno = EINVAL;
@@ -422,15 +406,33 @@ fs_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx)
                rte_errno = EINVAL;
                return -rte_errno;
        }
+       /* Fail if proxy service is nor running. */
+       if (PRIV(dev)->rxp.sstate != SS_RUNNING) {
+               ERROR("failsafe interrupt services are not running");
+               rte_errno = EAGAIN;
+               return -rte_errno;
+       }
        rxq->enable_events = 1;
-       return 0;
+       FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
+               ret = rte_eth_dev_rx_intr_enable(PORT_ID(sdev), idx);
+               ret = fs_err(sdev, ret);
+               if (ret)
+                       rc = ret;
+       }
+       if (rc)
+               rte_errno = -rc;
+       return rc;
 }
 
 static int
 fs_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx)
 {
        struct rxq *rxq;
+       struct sub_device *sdev;
        uint64_t u64;
+       uint8_t i;
+       int rc = 0;
+       int ret;
 
        if (idx >= dev->data->nb_rx_queues) {
                rte_errno = EINVAL;
@@ -442,10 +444,18 @@ fs_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx)
                return -rte_errno;
        }
        rxq->enable_events = 0;
+       FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
+               ret = rte_eth_dev_rx_intr_disable(PORT_ID(sdev), idx);
+               ret = fs_err(sdev, ret);
+               if (ret)
+                       rc = ret;
+       }
        /* Clear pending events */
        while (read(rxq->event_fd, &u64, sizeof(uint64_t)) >  0)
                ;
-       return 0;
+       if (rc)
+               rte_errno = -rc;
+       return rc;
 }
 
 static bool