diff mbox series

[13/37] bus/dpaa: enable link state interrupt

Message ID 20200527132326.1382-14-hemant.agrawal@nxp.com
State Superseded
Headers show
Series NXP DPAAx enhancements | expand

Commit Message

Hemant Agrawal May 27, 2020, 1:23 p.m. UTC
From: Rohit Raj <rohit.raj@nxp.com>


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>

---
 drivers/bus/dpaa/base/fman/fman.c         |  4 +-
 drivers/bus/dpaa/base/qbman/process.c     | 72 ++++++++++++++++-
 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 |  3 +
 drivers/bus/dpaa/rte_dpaa_bus.h           |  6 +-
 drivers/common/dpaax/compat.h             |  5 +-
 drivers/net/dpaa/dpaa_ethdev.c            | 97 ++++++++++++++++++++++-
 9 files changed, 231 insertions(+), 6 deletions(-)

-- 
2.17.1
diff mbox series

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..68b7af243 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,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;
+}
diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c
index 68d47be37..c66962d92 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>
@@ -544,6 +545,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)
 {
@@ -591,6 +609,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();
 
diff --git a/drivers/bus/dpaa/include/fman.h b/drivers/bus/dpaa/include/fman.h
index b6293b61c..7a0a7d405 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..7305762c2 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_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 */
diff --git a/drivers/bus/dpaa/rte_bus_dpaa_version.map b/drivers/bus/dpaa/rte_bus_dpaa_version.map
index 2defa7992..96662d7be 100644
--- a/drivers/bus/dpaa/rte_bus_dpaa_version.map
+++ b/drivers/bus/dpaa/rte_bus_dpaa_version.map
@@ -15,6 +15,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;
diff --git a/drivers/bus/dpaa/rte_dpaa_bus.h b/drivers/bus/dpaa/rte_dpaa_bus.h
index 25aff2d30..fdaa63a09 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)
 
@@ -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 */
diff --git a/drivers/common/dpaax/compat.h b/drivers/common/dpaax/compat.h
index 90db68ce7..6793cb256 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 074079185..5c5e62871 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>
 
 int dpaa_logtype_pmd;
 
@@ -133,6 +134,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)
 {
@@ -197,9 +203,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(
@@ -243,6 +259,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;
 }
 
@@ -271,6 +309,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;
@@ -300,9 +357,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
@@ -390,6 +465,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();
 
@@ -403,9 +480,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;
 }
 
@@ -1736,6 +1827,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) {
@@ -1763,6 +1857,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,