[v2,14/16] bus/dpaa: enable link state interrupt

Message ID 20200306095742.18080-15-hemant.agrawal@nxp.com
State New
Headers show
Series
  • NXP DPAAx fixes and enhancements
Related show

Commit Message

Hemant Agrawal March 6, 2020, 9:57 a.m.
From: Rohit Raj <rohit.raj@nxp.com>


Enable/disable link state interrupt and get link state api is
defined using IOCTL calls.

Signed-off-by: Rohit Raj <rohit.raj@nxp.com>

---
 drivers/bus/dpaa/base/fman/fman.c         |  4 +-
 drivers/bus/dpaa/base/qbman/process.c     | 68 ++++++++++++++++++-
 drivers/bus/dpaa/dpaa_bus.c               | 28 +++++++-
 drivers/bus/dpaa/include/fman.h           |  2 +
 drivers/bus/dpaa/include/process.h        | 20 ++++++
 drivers/bus/dpaa/rte_bus_dpaa_version.map |  8 +++
 drivers/bus/dpaa/rte_dpaa_bus.h           |  6 +-
 drivers/common/dpaax/compat.h             |  5 +-
 drivers/net/dpaa/dpaa_ethdev.c            | 82 ++++++++++++++++++++++-
 9 files changed, 217 insertions(+), 6 deletions(-)

-- 
2.17.1

Patch

diff --git a/drivers/bus/dpaa/base/fman/fman.c b/drivers/bus/dpaa/base/fman/fman.c
index ae26041ca..33be9e5d7 100644
--- a/drivers/bus/dpaa/base/fman/fman.c
+++ b/drivers/bus/dpaa/base/fman/fman.c
@@ -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';
 
diff --git a/drivers/bus/dpaa/base/qbman/process.c b/drivers/bus/dpaa/base/qbman/process.c
index 2c23c98df..598b10661 100644
--- a/drivers/bus/dpaa/base/qbman/process.c
+++ b/drivers/bus/dpaa/base/qbman/process.c
@@ -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,69 @@  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 rte_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) {
+		perror("Failed to enable interrupt\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+int rte_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) {
+		perror("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 rte_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) {
+		perror("Failed to get link status\n");
+		return ret;
+	}
+
+	return args.link_status;
+}
diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c
index f27820db3..2dedb138d 100644
--- a/drivers/bus/dpaa/dpaa_bus.c
+++ b/drivers/bus/dpaa/dpaa_bus.c
@@ -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>
@@ -545,6 +546,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)
 {
@@ -592,6 +610,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_PMD_ERR("Error setting up interrupt.\n");
+		}
+	}
+
 	/* And initialize the PA->VA translation table */
 	dpaax_iova_table_populate();
 
diff --git a/drivers/bus/dpaa/include/fman.h b/drivers/bus/dpaa/include/fman.h
index 12e598b2d..d90f2f5fc 100644
--- a/drivers/bus/dpaa/include/fman.h
+++ b/drivers/bus/dpaa/include/fman.h
@@ -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;
diff --git a/drivers/bus/dpaa/include/process.h b/drivers/bus/dpaa/include/process.h
index d9ec94ee2..312da1245 100644
--- a/drivers/bus/dpaa/include/process.h
+++ b/drivers/bus/dpaa/include/process.h
@@ -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_experimental
+int rte_dpaa_intr_enable(char *if_name, int efd);
+
+__rte_experimental
+int rte_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_experimental
+int rte_dpaa_get_link_status(char *if_name);
+
 #endif	/*  __PROCESS_H */
diff --git a/drivers/bus/dpaa/rte_bus_dpaa_version.map b/drivers/bus/dpaa/rte_bus_dpaa_version.map
index ed319539c..bf70e6656 100644
--- a/drivers/bus/dpaa/rte_bus_dpaa_version.map
+++ b/drivers/bus/dpaa/rte_bus_dpaa_version.map
@@ -96,3 +96,11 @@  DPDK_20.0 {
 
 	local: *;
 };
+
+EXPERIMENTAL {
+	global:
+
+	rte_dpaa_get_link_status;
+	rte_dpaa_intr_disable;
+	rte_dpaa_intr_enable;
+};
diff --git a/drivers/bus/dpaa/rte_dpaa_bus.h b/drivers/bus/dpaa/rte_dpaa_bus.h
index 373aca978..f385f6de8 100644
--- a/drivers/bus/dpaa/rte_dpaa_bus.h
+++ b/drivers/bus/dpaa/rte_dpaa_bus.h
@@ -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)
 
@@ -88,6 +91,7 @@  struct rte_dpaa_driver {
 	TAILQ_ENTRY(rte_dpaa_driver) next;
 	struct rte_driver driver;
 	struct rte_dpaa_bus *dpaa_bus;
+	uint32_t drv_flags;                 /**< Flags for controlling device.*/
 	enum rte_dpaa_type drv_type;
 	rte_dpaa_probe_t probe;
 	rte_dpaa_remove_t remove;
diff --git a/drivers/common/dpaax/compat.h b/drivers/common/dpaax/compat.h
index 12c9d9917..78e16fa2f 100644
--- a/drivers/common/dpaax/compat.h
+++ b/drivers/common/dpaax/compat.h
@@ -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 */
diff --git a/drivers/net/dpaa/dpaa_ethdev.c b/drivers/net/dpaa/dpaa_ethdev.c
index abe247acd..28c6b1c17 100644
--- a/drivers/net/dpaa/dpaa_ethdev.c
+++ b/drivers/net/dpaa/dpaa_ethdev.c
@@ -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,18 @@  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;
 
 	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 +256,14 @@  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 &&
+	    dev->data->dev_conf.intr_conf.lsc != 0)
+		rte_intr_callback_register(intr_handle, dpaa_interrupt_handler,
+					   (void *)dev);
+
+	rte_dpaa_intr_enable(__fif->node_name, intr_handle->fd);
+
 	return 0;
 }
 
@@ -269,6 +292,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 +340,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);
+
+	rte_dpaa_intr_disable(__fif->node_name);
+
+	if (intr_handle && intr_handle->fd &&
+	    dev->data->dev_conf.intr_conf.lsc != 0)
+		rte_intr_callback_unregister(intr_handle,
+					     dpaa_interrupt_handler,
+					     (void *)dev);
 }
 
 static int
@@ -384,6 +444,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();
 
@@ -397,9 +459,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 = rte_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;
 }
 
@@ -1743,6 +1819,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) {
@@ -1770,6 +1849,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,