From 03117a1e7db4cd3d745c663c697e446695ebb8e1 Mon Sep 17 00:00:00 2001
From: Camelia Groza <camelia.groza@nxp.com>
Date: Wed, 8 Jan 2020 18:41:33 +0200
Subject: [PATCH] sdk_dpaa: ceetm: fix recursive dependencies

Due to dependencies between the fsl_ceetm and fsl_dpa modules, remove
the module support for the ceetm driver and integrate it into the main
DPAA Ethernet driver.

The registration of the CEETM Qdisc was the only operation done at
module init. Pass the management of the Qdisc register and unregister
operations to the loading and unloading of the DPAA driver.

Signed-off-by: Camelia Groza <camelia.groza@nxp.com>
---
 drivers/net/ethernet/freescale/sdk_dpaa/Makefile   |  3 +-
 drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth.c | 19 +++++++++++++
 .../ethernet/freescale/sdk_dpaa/dpaa_eth_ceetm.c   | 32 +---------------------
 3 files changed, 21 insertions(+), 33 deletions(-)

--- a/drivers/net/ethernet/freescale/sdk_dpaa/Makefile
+++ b/drivers/net/ethernet/freescale/sdk_dpaa/Makefile
@@ -20,8 +20,7 @@ endif
 
 ifeq ($(CONFIG_FSL_DPAA_CEETM),y)
 ccflags-y += -I$(srctree)/drivers/net/ethernet/freescale/sdk_fman/src/wrapper
-obj-$(CONFIG_FSL_SDK_DPAA_ETH) += fsl_ceetm.o
-fsl_ceetm-objs += dpaa_eth_ceetm.o
+fsl_dpa-objs += dpaa_eth_ceetm.o
 endif
 
 fsl_mac-objs += mac.o mac-api.o
--- a/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth.c
@@ -72,6 +72,9 @@
 #ifdef CONFIG_FSL_DPAA_DBG_LOOP
 #include "dpaa_debugfs.h"
 #endif /* CONFIG_FSL_DPAA_DBG_LOOP */
+#ifdef CONFIG_FSL_DPAA_CEETM
+#include "dpaa_eth_ceetm.h"
+#endif
 
 /* CREATE_TRACE_POINTS only needs to be defined once. Other dpa files
  * using trace events only need to #include <trace/events/sched.h>
@@ -116,6 +119,10 @@ static uint8_t dpa_priv_common_bpid;
 struct net_device *dpa_loop_netdevs[20];
 #endif
 
+#ifdef CONFIG_FSL_DPAA_CEETM
+extern struct Qdisc_ops ceetm_qdisc_ops;
+#endif
+
 #ifdef CONFIG_PM
 
 static int dpaa_suspend(struct device *dev)
@@ -1158,6 +1165,14 @@ static int __init __cold dpa_load(void)
 	pr_debug(KBUILD_MODNAME ": %s:%s() ->\n",
 		KBUILD_BASENAME".c", __func__);
 
+#ifdef CONFIG_FSL_DPAA_CEETM
+	_errno = register_qdisc(&ceetm_qdisc_ops);
+	if (unlikely(_errno))
+		pr_err(KBUILD_MODNAME
+		       ": %s:%hu:%s(): register_qdisc() = %d\n",
+		       KBUILD_BASENAME ".c", __LINE__, __func__, _errno);
+#endif
+
 	return _errno;
 }
 module_init(dpa_load);
@@ -1167,6 +1182,10 @@ static void __exit __cold dpa_unload(voi
 	pr_debug(KBUILD_MODNAME ": -> %s:%s()\n",
 		KBUILD_BASENAME".c", __func__);
 
+#ifdef CONFIG_FSL_DPAA_CEETM
+	unregister_qdisc(&ceetm_qdisc_ops);
+#endif
+
 	platform_driver_unregister(&dpa_driver);
 
 #ifdef CONFIG_FSL_DPAA_DBG_LOOP
--- a/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_ceetm.c
+++ b/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_ceetm.c
@@ -33,16 +33,13 @@
 #include <linux/init.h>
 #include "dpaa_eth_ceetm.h"
 
-#define DPA_CEETM_DESCRIPTION "FSL DPAA CEETM qdisc"
-MODULE_LICENSE("Dual BSD/GPL");
-MODULE_DESCRIPTION(DPA_CEETM_DESCRIPTION);
-
 const struct nla_policy ceetm_policy[TCA_CEETM_MAX + 1] = {
 	[TCA_CEETM_COPT] = { .len = sizeof(struct tc_ceetm_copt) },
 	[TCA_CEETM_QOPS] = { .len = sizeof(struct tc_ceetm_qopt) },
 };
 
 struct Qdisc_ops ceetm_qdisc_ops;
+EXPORT_SYMBOL(ceetm_qdisc_ops);
 
 /* Obtain the DCP and the SP ids from the FMan port */
 static void get_dcp_and_sp(struct net_device *dev, enum qm_dc_portal *dcp_id,
@@ -2086,30 +2083,3 @@ drop:
 	dev_kfree_skb_any(skb);
 	return NET_XMIT_SUCCESS;
 }
-EXPORT_SYMBOL(ceetm_tx);
-
-static int __init ceetm_register(void)
-{
-	int _errno = 0;
-
-	pr_info(KBUILD_MODNAME ": " DPA_CEETM_DESCRIPTION "\n");
-
-	_errno = register_qdisc(&ceetm_qdisc_ops);
-	if (unlikely(_errno))
-		pr_err(KBUILD_MODNAME
-		       ": %s:%hu:%s(): register_qdisc() = %d\n",
-		       KBUILD_BASENAME ".c", __LINE__, __func__, _errno);
-
-	return _errno;
-}
-
-static void __exit ceetm_unregister(void)
-{
-	pr_debug(KBUILD_MODNAME ": %s:%s() ->\n",
-		 KBUILD_BASENAME ".c", __func__);
-
-	unregister_qdisc(&ceetm_qdisc_ops);
-}
-
-module_init(ceetm_register);
-module_exit(ceetm_unregister);
