bus/dpaa: enable link state interrupt
authorRohit Raj <rohit.raj@nxp.com>
Tue, 7 Jul 2020 09:22:28 +0000 (14:52 +0530)
committerFerruh Yigit <ferruh.yigit@intel.com>
Sat, 11 Jul 2020 04:18:52 +0000 (06:18 +0200)
Enable/disable link state interrupt and get link state api is
defined using IOCTL calls from kernel driver

Signed-off-by: Rohit Raj <rohit.raj@nxp.com>
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
doc/guides/nics/features/dpaa.ini
doc/guides/rel_notes/release_20_08.rst
drivers/bus/dpaa/base/fman/fman.c
drivers/bus/dpaa/base/qbman/process.c
drivers/bus/dpaa/dpaa_bus.c
drivers/bus/dpaa/include/fman.h
drivers/bus/dpaa/include/process.h
drivers/bus/dpaa/rte_bus_dpaa_version.map
drivers/bus/dpaa/rte_dpaa_bus.h
drivers/common/dpaax/compat.h
drivers/net/dpaa/dpaa_ethdev.c

index b00f46a..816a6e0 100644 (file)
@@ -6,6 +6,7 @@
 [Features]
 Speed capabilities   = Y
 Link status          = Y
+Link status event    = Y
 Jumbo frame          = Y
 MTU update           = Y
 Scattered Rx         = Y
index 24cb2ce..14c8386 100644 (file)
@@ -146,6 +146,7 @@ New Features
 
   Updated the NXP dpaa ethdev with new features and improvements, including:
 
+  * Added support for link status and interrupt
   * Added support to use datapath APIs from non-EAL pthread
 
 * **Updated NXP dpaa2 ethdev PMD.**
index ae26041..33be9e5 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
  *
  * Copyright 2010-2016 Freescale Semiconductor Inc.
- * Copyright 2017-2019 NXP
+ * Copyright 2017-2020 NXP
  *
  */
 
@@ -185,6 +185,8 @@ fman_if_init(const struct device_node *dpa_node)
        }
        memset(__if, 0, sizeof(*__if));
        INIT_LIST_HEAD(&__if->__if.bpool_list);
+       strlcpy(__if->node_name, dpa_node->name, IF_NAME_MAX_LEN - 1);
+       __if->node_name[IF_NAME_MAX_LEN - 1] = '\0';
        strlcpy(__if->node_path, dpa_node->full_name, PATH_MAX - 1);
        __if->node_path[PATH_MAX - 1] = '\0';
 
index 2c23c98..68b7af2 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
  *
  * Copyright 2011-2016 Freescale Semiconductor Inc.
- * Copyright 2017 NXP
+ * Copyright 2017,2020 NXP
  *
  */
 #include <assert.h>
@@ -296,3 +296,73 @@ int bman_free_raw_portal(struct dpaa_raw_portal *portal)
 
        return process_portal_free(&input);
 }
+
+#define DPAA_IOCTL_ENABLE_LINK_STATUS_INTERRUPT \
+       _IOW(DPAA_IOCTL_MAGIC, 0x0E, struct usdpaa_ioctl_link_status)
+
+#define DPAA_IOCTL_DISABLE_LINK_STATUS_INTERRUPT \
+       _IOW(DPAA_IOCTL_MAGIC, 0x0F, char*)
+
+int dpaa_intr_enable(char *if_name, int efd)
+{
+       struct usdpaa_ioctl_link_status args;
+
+       int ret = check_fd();
+
+       if (ret)
+               return ret;
+
+       args.efd = (uint32_t)efd;
+       strcpy(args.if_name, if_name);
+
+       ret = ioctl(fd, DPAA_IOCTL_ENABLE_LINK_STATUS_INTERRUPT, &args);
+       if (ret)
+               return errno;
+
+       return 0;
+}
+
+int dpaa_intr_disable(char *if_name)
+{
+       int ret = check_fd();
+
+       if (ret)
+               return ret;
+
+       ret = ioctl(fd, DPAA_IOCTL_DISABLE_LINK_STATUS_INTERRUPT, &if_name);
+       if (ret) {
+               if (errno == EINVAL)
+                       printf("Failed to disable interrupt: Not Supported\n");
+               else
+                       printf("Failed to disable interrupt\n");
+               return ret;
+       }
+
+       return 0;
+}
+
+#define DPAA_IOCTL_GET_LINK_STATUS \
+       _IOWR(DPAA_IOCTL_MAGIC, 0x10, struct usdpaa_ioctl_link_status_args)
+
+int dpaa_get_link_status(char *if_name)
+{
+       int ret = check_fd();
+       struct usdpaa_ioctl_link_status_args args;
+
+       if (ret)
+               return ret;
+
+       strcpy(args.if_name, if_name);
+       args.link_status = 0;
+
+       ret = ioctl(fd, DPAA_IOCTL_GET_LINK_STATUS, &args);
+       if (ret) {
+               if (errno == EINVAL)
+                       printf("Failed to get link status: Not Supported\n");
+               else
+                       printf("Failed to get link status\n");
+               return ret;
+       }
+
+       return args.link_status;
+}
index aa906c3..32e872d 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  *
- *   Copyright 2017-2019 NXP
+ *   Copyright 2017-2020 NXP
  *
  */
 /* System headers */
@@ -13,6 +13,7 @@
 #include <pthread.h>
 #include <sys/types.h>
 #include <sys/syscall.h>
+#include <sys/eventfd.h>
 
 #include <rte_byteorder.h>
 #include <rte_common.h>
@@ -542,6 +543,23 @@ rte_dpaa_bus_dev_build(void)
        return 0;
 }
 
+static int rte_dpaa_setup_intr(struct rte_intr_handle *intr_handle)
+{
+       int fd;
+
+       fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
+       if (fd < 0) {
+               DPAA_BUS_ERR("Cannot set up eventfd, error %i (%s)",
+                            errno, strerror(errno));
+               return errno;
+       }
+
+       intr_handle->fd = fd;
+       intr_handle->type = RTE_INTR_HANDLE_EXT;
+
+       return 0;
+}
+
 static int
 rte_dpaa_bus_probe(void)
 {
@@ -589,6 +607,14 @@ rte_dpaa_bus_probe(void)
                fclose(svr_file);
        }
 
+       TAILQ_FOREACH(dev, &rte_dpaa_bus.device_list, next) {
+               if (dev->device_type == FSL_DPAA_ETH) {
+                       ret = rte_dpaa_setup_intr(&dev->intr_handle);
+                       if (ret)
+                               DPAA_BUS_ERR("Error setting up interrupt.\n");
+               }
+       }
+
        /* And initialize the PA->VA translation table */
        dpaax_iova_table_populate();
 
index b6293b6..7a0a7d4 100644 (file)
@@ -2,6 +2,7 @@
  *
  * Copyright 2010-2012 Freescale Semiconductor, Inc.
  * All rights reserved.
+ * Copyright 2019-2020 NXP
  *
  */
 
@@ -361,6 +362,7 @@ struct fman_if_ic_params {
  */
 struct __fman_if {
        struct fman_if __if;
+       char node_name[IF_NAME_MAX_LEN];
        char node_path[PATH_MAX];
        uint64_t regs_size;
        void *ccsr_map;
index d9ec94e..7305762 100644 (file)
@@ -2,6 +2,7 @@
  *
  * Copyright 2010-2011 Freescale Semiconductor, Inc.
  * All rights reserved.
+ * Copyright 2020 NXP
  *
  */
 
@@ -74,4 +75,23 @@ struct dpaa_ioctl_irq_map {
 int process_portal_irq_map(int fd,  struct dpaa_ioctl_irq_map *irq);
 int process_portal_irq_unmap(int fd);
 
+struct usdpaa_ioctl_link_status {
+       char            if_name[IF_NAME_MAX_LEN];
+       uint32_t        efd;
+};
+
+__rte_internal
+int dpaa_intr_enable(char *if_name, int efd);
+
+__rte_internal
+int dpaa_intr_disable(char *if_name);
+
+struct usdpaa_ioctl_link_status_args {
+       /* network device node name */
+       char    if_name[IF_NAME_MAX_LEN];
+       int     link_status;
+};
+__rte_internal
+int dpaa_get_link_status(char *if_name);
+
 #endif /*  __PROCESS_H */
index f593a76..2e8b440 100644 (file)
@@ -11,6 +11,9 @@ INTERNAL {
        dpaa_get_eth_port_cfg;
        dpaa_get_qm_channel_caam;
        dpaa_get_qm_channel_pool;
+       dpaa_get_link_status;
+       dpaa_intr_disable;
+       dpaa_intr_enable;
        dpaa_svr_family;
        fman_dealloc_bufs_mask_hi;
        fman_dealloc_bufs_mask_lo;
index 25aff2d..fdaa63a 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  *
- *   Copyright 2017-2019 NXP
+ *   Copyright 2017-2020 NXP
  *
  */
 #ifndef __RTE_DPAA_BUS_H__
@@ -30,6 +30,9 @@
 #define SVR_LS1046A_FAMILY     0x87070000
 #define SVR_MASK               0xffff0000
 
+/** Device driver supports link state interrupt */
+#define RTE_DPAA_DRV_INTR_LSC  0x0008
+
 #define RTE_DEV_TO_DPAA_CONST(ptr) \
        container_of(ptr, const struct rte_dpaa_device, device)
 
@@ -86,6 +89,7 @@ struct rte_dpaa_driver {
        enum rte_dpaa_type drv_type;
        rte_dpaa_probe_t probe;
        rte_dpaa_remove_t remove;
+       uint32_t drv_flags;                 /**< Flags for controlling device.*/
 };
 
 /* Create storage for dqrr entries per lcore */
index 90db68c..6793cb2 100644 (file)
@@ -2,7 +2,7 @@
  *
  * Copyright 2011 Freescale Semiconductor, Inc.
  * All rights reserved.
- * Copyright 2019 NXP
+ * Copyright 2019-2020 NXP
  *
  */
 
@@ -390,4 +390,7 @@ static inline unsigned long get_zeroed_page(gfp_t __foo __rte_unused)
 #define atomic_dec_return(v)    rte_atomic32_sub_return(v, 1)
 #define atomic_sub_and_test(i, v) (rte_atomic32_sub_return(v, i) == 0)
 
+/* Interface name len*/
+#define IF_NAME_MAX_LEN 16
+
 #endif /* __COMPAT_H */
index c9f828a..3f805b2 100644 (file)
@@ -45,6 +45,7 @@
 #include <fsl_qman.h>
 #include <fsl_bman.h>
 #include <fsl_fman.h>
+#include <process.h>
 
 /* Supported Rx offloads */
 static uint64_t dev_rx_offloads_sup =
@@ -131,6 +132,11 @@ static struct rte_dpaa_driver rte_dpaa_pmd;
 static int
 dpaa_eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info);
 
+static int dpaa_eth_link_update(struct rte_eth_dev *dev,
+                               int wait_to_complete __rte_unused);
+
+static void dpaa_interrupt_handler(void *param);
+
 static inline void
 dpaa_poll_queue_default_config(struct qm_mcc_initfq *opts)
 {
@@ -195,9 +201,19 @@ dpaa_eth_dev_configure(struct rte_eth_dev *dev)
        struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
        uint64_t rx_offloads = eth_conf->rxmode.offloads;
        uint64_t tx_offloads = eth_conf->txmode.offloads;
+       struct rte_device *rdev = dev->device;
+       struct rte_dpaa_device *dpaa_dev;
+       struct fman_if *fif = dev->process_private;
+       struct __fman_if *__fif;
+       struct rte_intr_handle *intr_handle;
+       int ret;
 
        PMD_INIT_FUNC_TRACE();
 
+       dpaa_dev = container_of(rdev, struct rte_dpaa_device, device);
+       intr_handle = &dpaa_dev->intr_handle;
+       __fif = container_of(fif, struct __fman_if, __if);
+
        /* Rx offloads which are enabled by default */
        if (dev_rx_offloads_nodis & ~rx_offloads) {
                DPAA_PMD_INFO(
@@ -241,6 +257,28 @@ dpaa_eth_dev_configure(struct rte_eth_dev *dev)
                dev->data->scattered_rx = 1;
        }
 
+       /* if the interrupts were configured on this devices*/
+       if (intr_handle && intr_handle->fd) {
+               if (dev->data->dev_conf.intr_conf.lsc != 0)
+                       rte_intr_callback_register(intr_handle,
+                                          dpaa_interrupt_handler,
+                                          (void *)dev);
+
+               ret = dpaa_intr_enable(__fif->node_name, intr_handle->fd);
+               if (ret) {
+                       if (dev->data->dev_conf.intr_conf.lsc != 0) {
+                               rte_intr_callback_unregister(intr_handle,
+                                       dpaa_interrupt_handler,
+                                       (void *)dev);
+                               if (ret == EINVAL)
+                                       printf("Failed to enable interrupt: Not Supported\n");
+                               else
+                                       printf("Failed to enable interrupt\n");
+                       }
+                       dev->data->dev_conf.intr_conf.lsc = 0;
+                       dev->data->dev_flags &= ~RTE_ETH_DEV_INTR_LSC;
+               }
+       }
        return 0;
 }
 
@@ -269,6 +307,25 @@ dpaa_supported_ptypes_get(struct rte_eth_dev *dev)
        return NULL;
 }
 
+static void dpaa_interrupt_handler(void *param)
+{
+       struct rte_eth_dev *dev = param;
+       struct rte_device *rdev = dev->device;
+       struct rte_dpaa_device *dpaa_dev;
+       struct rte_intr_handle *intr_handle;
+       uint64_t buf;
+       int bytes_read;
+
+       dpaa_dev = container_of(rdev, struct rte_dpaa_device, device);
+       intr_handle = &dpaa_dev->intr_handle;
+
+       bytes_read = read(intr_handle->fd, &buf, sizeof(uint64_t));
+       if (bytes_read < 0)
+               DPAA_PMD_ERR("Error reading eventfd\n");
+       dpaa_eth_link_update(dev, 0);
+       _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
+}
+
 static int dpaa_eth_dev_start(struct rte_eth_dev *dev)
 {
        struct dpaa_if *dpaa_intf = dev->data->dev_private;
@@ -298,9 +355,27 @@ static void dpaa_eth_dev_stop(struct rte_eth_dev *dev)
 
 static void dpaa_eth_dev_close(struct rte_eth_dev *dev)
 {
+       struct fman_if *fif = dev->process_private;
+       struct __fman_if *__fif;
+       struct rte_device *rdev = dev->device;
+       struct rte_dpaa_device *dpaa_dev;
+       struct rte_intr_handle *intr_handle;
+
        PMD_INIT_FUNC_TRACE();
 
+       dpaa_dev = container_of(rdev, struct rte_dpaa_device, device);
+       intr_handle = &dpaa_dev->intr_handle;
+       __fif = container_of(fif, struct __fman_if, __if);
+
        dpaa_eth_dev_stop(dev);
+
+       if (intr_handle && intr_handle->fd &&
+           dev->data->dev_conf.intr_conf.lsc != 0) {
+               dpaa_intr_disable(__fif->node_name);
+               rte_intr_callback_unregister(intr_handle,
+                                            dpaa_interrupt_handler,
+                                            (void *)dev);
+       }
 }
 
 static int
@@ -388,6 +463,8 @@ static int dpaa_eth_link_update(struct rte_eth_dev *dev,
        struct dpaa_if *dpaa_intf = dev->data->dev_private;
        struct rte_eth_link *link = &dev->data->dev_link;
        struct fman_if *fif = dev->process_private;
+       struct __fman_if *__fif = container_of(fif, struct __fman_if, __if);
+       int ret;
 
        PMD_INIT_FUNC_TRACE();
 
@@ -401,9 +478,23 @@ static int dpaa_eth_link_update(struct rte_eth_dev *dev,
                DPAA_PMD_ERR("invalid link_speed: %s, %d",
                             dpaa_intf->name, fif->mac_type);
 
-       link->link_status = dpaa_intf->valid;
+       ret = dpaa_get_link_status(__fif->node_name);
+       if (ret < 0) {
+               if (ret == -EINVAL) {
+                       DPAA_PMD_DEBUG("Using default link status-No Support");
+                       ret = 1;
+               } else {
+                       DPAA_PMD_ERR("rte_dpaa_get_link_status %d", ret);
+                       return ret;
+               }
+       }
+
+       link->link_status = ret;
        link->link_duplex = ETH_LINK_FULL_DUPLEX;
        link->link_autoneg = ETH_LINK_AUTONEG;
+
+       DPAA_PMD_INFO("Port %d Link is %s\n", dev->data->port_id,
+                     link->link_status ? "Up" : "Down");
        return 0;
 }
 
@@ -1734,6 +1825,9 @@ rte_dpaa_probe(struct rte_dpaa_driver *dpaa_drv __rte_unused,
 
        qman_ern_register_cb(dpaa_free_mbuf);
 
+       if (dpaa_drv->drv_flags & RTE_DPAA_DRV_INTR_LSC)
+               eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
+
        /* Invoke PMD device initialization function */
        diag = dpaa_dev_init(eth_dev);
        if (diag == 0) {
@@ -1761,6 +1855,7 @@ rte_dpaa_remove(struct rte_dpaa_device *dpaa_dev)
 }
 
 static struct rte_dpaa_driver rte_dpaa_pmd = {
+       .drv_flags = RTE_DPAA_DRV_INTR_LSC,
        .drv_type = FSL_DPAA_ETH,
        .probe = rte_dpaa_probe,
        .remove = rte_dpaa_remove,