[PATCH 08/18] net: enetc: fix mixed module-builtin object

From: Alexander Lobakin
Date: Sat Nov 19 2022 - 18:07:21 EST


From: Masahiro Yamada <masahiroy@xxxxxxxxxx>

With CONFIG_FSL_ENETC=m and CONFIG_FSL_ENETC_VF=y (or vice versa),
$(common-objs) are linked to a module and also to vmlinux even though
the expected CFLAGS are different between builtins and modules.

This is the same situation as fixed by commit 637a642f5ca5 ("zstd:
Fixing mixed module-builtin objects").

Introduce the new module, fsl-enetc-core, to provide the common
functions to fsl-enetc and fsl-enetc-vf.

[ alobakin: add exports to common functions ]

Signed-off-by: Masahiro Yamada <masahiroy@xxxxxxxxxx>
Reviewed-by: Alexander Lobakin <alobakin@xxxxx>
Signed-off-by: Alexander Lobakin <alobakin@xxxxx>
---
drivers/net/ethernet/freescale/enetc/Kconfig | 5 +++++
drivers/net/ethernet/freescale/enetc/Makefile | 7 ++++---
drivers/net/ethernet/freescale/enetc/enetc.c | 21 +++++++++++++++++++
.../net/ethernet/freescale/enetc/enetc_cbdr.c | 7 +++++++
.../ethernet/freescale/enetc/enetc_ethtool.c | 2 ++
.../net/ethernet/freescale/enetc/enetc_pf.c | 2 ++
.../net/ethernet/freescale/enetc/enetc_vf.c | 2 ++
7 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/Kconfig b/drivers/net/ethernet/freescale/enetc/Kconfig
index cdc0ff89388a..a8a38df34760 100644
--- a/drivers/net/ethernet/freescale/enetc/Kconfig
+++ b/drivers/net/ethernet/freescale/enetc/Kconfig
@@ -1,7 +1,11 @@
# SPDX-License-Identifier: GPL-2.0
+config FSL_ENETC_CORE
+ tristate
+
config FSL_ENETC
tristate "ENETC PF driver"
depends on PCI && PCI_MSI
+ select FSL_ENETC_CORE
select FSL_ENETC_IERB
select FSL_ENETC_MDIO
select PHYLINK
@@ -17,6 +21,7 @@ config FSL_ENETC
config FSL_ENETC_VF
tristate "ENETC VF driver"
depends on PCI && PCI_MSI
+ select FSL_ENETC_CORE
select FSL_ENETC_MDIO
select PHYLINK
select DIMLIB
diff --git a/drivers/net/ethernet/freescale/enetc/Makefile b/drivers/net/ethernet/freescale/enetc/Makefile
index e0e8dfd13793..d67319e09bad 100644
--- a/drivers/net/ethernet/freescale/enetc/Makefile
+++ b/drivers/net/ethernet/freescale/enetc/Makefile
@@ -1,14 +1,15 @@
# SPDX-License-Identifier: GPL-2.0

-common-objs := enetc.o enetc_cbdr.o enetc_ethtool.o
+obj-$(CONFIG_FSL_ENETC_CORE) += fsl-enetc-core.o
+fsl-enetc-core-y += enetc.o enetc_cbdr.o enetc_ethtool.o

obj-$(CONFIG_FSL_ENETC) += fsl-enetc.o
-fsl-enetc-y := enetc_pf.o $(common-objs)
+fsl-enetc-y := enetc_pf.o
fsl-enetc-$(CONFIG_PCI_IOV) += enetc_msg.o
fsl-enetc-$(CONFIG_FSL_ENETC_QOS) += enetc_qos.o

obj-$(CONFIG_FSL_ENETC_VF) += fsl-enetc-vf.o
-fsl-enetc-vf-y := enetc_vf.o $(common-objs)
+fsl-enetc-vf-y := enetc_vf.o

obj-$(CONFIG_FSL_ENETC_IERB) += fsl-enetc-ierb.o
fsl-enetc-ierb-y := enetc_ierb.o
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index f8c06c3f9464..f13bb6b1c026 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -651,6 +651,7 @@ netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev)

return enetc_start_xmit(skb, ndev);
}
+EXPORT_SYMBOL_NS_GPL(enetc_xmit, FSL_ENETC_CORE);

static irqreturn_t enetc_msix(int irq, void *data)
{
@@ -1384,6 +1385,7 @@ int enetc_xdp_xmit(struct net_device *ndev, int num_frames,

return xdp_tx_frm_cnt;
}
+EXPORT_SYMBOL_NS_GPL(enetc_xdp_xmit, FSL_ENETC_CORE);

static void enetc_map_rx_buff_to_xdp(struct enetc_bdr *rx_ring, int i,
struct xdp_buff *xdp_buff, u16 size)
@@ -1735,6 +1737,7 @@ void enetc_get_si_caps(struct enetc_si *si)
if (val & ENETC_SIPCAPR0_PSFP)
si->hw_features |= ENETC_SI_F_PSFP;
}
+EXPORT_SYMBOL_NS_GPL(enetc_get_si_caps, FSL_ENETC_CORE);

static int enetc_dma_alloc_bdr(struct enetc_bdr *r, size_t bd_size)
{
@@ -1999,6 +2002,7 @@ int enetc_configure_si(struct enetc_ndev_priv *priv)

return 0;
}
+EXPORT_SYMBOL_NS_GPL(enetc_configure_si, FSL_ENETC_CORE);

void enetc_init_si_rings_params(struct enetc_ndev_priv *priv)
{
@@ -2018,6 +2022,7 @@ void enetc_init_si_rings_params(struct enetc_ndev_priv *priv)
priv->ic_mode = ENETC_IC_RX_ADAPTIVE | ENETC_IC_TX_MANUAL;
priv->tx_ictt = ENETC_TXIC_TIMETHR;
}
+EXPORT_SYMBOL_NS_GPL(enetc_init_si_rings_params, FSL_ENETC_CORE);

int enetc_alloc_si_resources(struct enetc_ndev_priv *priv)
{
@@ -2030,11 +2035,13 @@ int enetc_alloc_si_resources(struct enetc_ndev_priv *priv)

return 0;
}
+EXPORT_SYMBOL_NS_GPL(enetc_alloc_si_resources, FSL_ENETC_CORE);

void enetc_free_si_resources(struct enetc_ndev_priv *priv)
{
kfree(priv->cls_rules);
}
+EXPORT_SYMBOL_NS_GPL(enetc_free_si_resources, FSL_ENETC_CORE);

static void enetc_setup_txbdr(struct enetc_hw *hw, struct enetc_bdr *tx_ring)
{
@@ -2398,6 +2405,7 @@ int enetc_open(struct net_device *ndev)

return err;
}
+EXPORT_SYMBOL_NS_GPL(enetc_open, FSL_ENETC_CORE);

void enetc_stop(struct net_device *ndev)
{
@@ -2439,6 +2447,7 @@ int enetc_close(struct net_device *ndev)

return 0;
}
+EXPORT_SYMBOL_NS_GPL(enetc_close, FSL_ENETC_CORE);

int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data)
{
@@ -2494,6 +2503,7 @@ int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data)

return 0;
}
+EXPORT_SYMBOL_NS_GPL(enetc_setup_tc_mqprio, FSL_ENETC_CORE);

static int enetc_setup_xdp_prog(struct net_device *dev, struct bpf_prog *prog,
struct netlink_ext_ack *extack)
@@ -2542,6 +2552,7 @@ int enetc_setup_bpf(struct net_device *dev, struct netdev_bpf *xdp)

return 0;
}
+EXPORT_SYMBOL_NS_GPL(enetc_setup_bpf, FSL_ENETC_CORE);

struct net_device_stats *enetc_get_stats(struct net_device *ndev)
{
@@ -2573,6 +2584,7 @@ struct net_device_stats *enetc_get_stats(struct net_device *ndev)

return stats;
}
+EXPORT_SYMBOL_NS_GPL(enetc_get_stats, FSL_ENETC_CORE);

static int enetc_set_rss(struct net_device *ndev, int en)
{
@@ -2625,6 +2637,7 @@ void enetc_set_features(struct net_device *ndev, netdev_features_t features)
enetc_enable_txvlan(ndev,
!!(features & NETIF_F_HW_VLAN_CTAG_TX));
}
+EXPORT_SYMBOL_NS_GPL(enetc_set_features, FSL_ENETC_CORE);

#ifdef CONFIG_FSL_ENETC_PTP_CLOCK
static int enetc_hwtstamp_set(struct net_device *ndev, struct ifreq *ifr)
@@ -2708,6 +2721,7 @@ int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)

return phylink_mii_ioctl(priv->phylink, rq, cmd);
}
+EXPORT_SYMBOL_NS_GPL(enetc_ioctl, FSL_ENETC_CORE);

int enetc_alloc_msix(struct enetc_ndev_priv *priv)
{
@@ -2809,6 +2823,7 @@ int enetc_alloc_msix(struct enetc_ndev_priv *priv)

return err;
}
+EXPORT_SYMBOL_NS_GPL(enetc_alloc_msix, FSL_ENETC_CORE);

void enetc_free_msix(struct enetc_ndev_priv *priv)
{
@@ -2838,6 +2853,7 @@ void enetc_free_msix(struct enetc_ndev_priv *priv)
/* disable all MSIX for this device */
pci_free_irq_vectors(priv->si->pdev);
}
+EXPORT_SYMBOL_NS_GPL(enetc_free_msix, FSL_ENETC_CORE);

static void enetc_kfree_si(struct enetc_si *si)
{
@@ -2927,6 +2943,7 @@ int enetc_pci_probe(struct pci_dev *pdev, const char *name, int sizeof_priv)

return err;
}
+EXPORT_SYMBOL_NS_GPL(enetc_pci_probe, FSL_ENETC_CORE);

void enetc_pci_remove(struct pci_dev *pdev)
{
@@ -2938,3 +2955,7 @@ void enetc_pci_remove(struct pci_dev *pdev)
pci_release_mem_regions(pdev);
pci_disable_device(pdev);
}
+EXPORT_SYMBOL_NS_GPL(enetc_pci_remove, FSL_ENETC_CORE);
+
+MODULE_DESCRIPTION("ENETC Core");
+MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c b/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c
index af68dc46a795..acb48ceef760 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c
@@ -44,6 +44,7 @@ int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, int bd_count,

return 0;
}
+EXPORT_SYMBOL_NS_GPL(enetc_setup_cbdr, FSL_ENETC_CORE);

void enetc_teardown_cbdr(struct enetc_cbdr *cbdr)
{
@@ -57,6 +58,7 @@ void enetc_teardown_cbdr(struct enetc_cbdr *cbdr)
cbdr->bd_base = NULL;
cbdr->dma_dev = NULL;
}
+EXPORT_SYMBOL_NS_GPL(enetc_teardown_cbdr, FSL_ENETC_CORE);

static void enetc_clean_cbdr(struct enetc_cbdr *ring)
{
@@ -127,6 +129,7 @@ int enetc_send_cmd(struct enetc_si *si, struct enetc_cbd *cbd)

return 0;
}
+EXPORT_SYMBOL_NS_GPL(enetc_send_cmd, FSL_ENETC_CORE);

int enetc_clear_mac_flt_entry(struct enetc_si *si, int index)
{
@@ -140,6 +143,7 @@ int enetc_clear_mac_flt_entry(struct enetc_si *si, int index)

return enetc_send_cmd(si, &cbd);
}
+EXPORT_SYMBOL_NS_GPL(enetc_clear_mac_flt_entry, FSL_ENETC_CORE);

int enetc_set_mac_flt_entry(struct enetc_si *si, int index,
char *mac_addr, int si_map)
@@ -165,6 +169,7 @@ int enetc_set_mac_flt_entry(struct enetc_si *si, int index,

return enetc_send_cmd(si, &cbd);
}
+EXPORT_SYMBOL_NS_GPL(enetc_set_mac_flt_entry, FSL_ENETC_CORE);

/* Set entry in RFS table */
int enetc_set_fs_entry(struct enetc_si *si, struct enetc_cmd_rfse *rfse,
@@ -197,6 +202,7 @@ int enetc_set_fs_entry(struct enetc_si *si, struct enetc_cmd_rfse *rfse,

return err;
}
+EXPORT_SYMBOL_NS_GPL(enetc_set_fs_entry, FSL_ENETC_CORE);

static int enetc_cmd_rss_table(struct enetc_si *si, u32 *table, int count,
bool read)
@@ -248,3 +254,4 @@ int enetc_set_rss_table(struct enetc_si *si, const u32 *table, int count)
{
return enetc_cmd_rss_table(si, (u32 *)table, count, false);
}
+EXPORT_SYMBOL_NS_GPL(enetc_set_rss_table, FSL_ENETC_CORE);
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
index c8369e3752b0..e3d3a34fc96b 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
@@ -651,6 +651,7 @@ void enetc_set_rss_key(struct enetc_hw *hw, const u8 *bytes)
for (i = 0; i < ENETC_RSSHASH_KEY_SIZE / 4; i++)
enetc_port_wr(hw, ENETC_PRSSK(i), ((u32 *)bytes)[i]);
}
+EXPORT_SYMBOL_NS_GPL(enetc_set_rss_key, FSL_ENETC_CORE);

static int enetc_set_rxfh(struct net_device *ndev, const u32 *indir,
const u8 *key, const u8 hfunc)
@@ -926,3 +927,4 @@ void enetc_set_ethtool_ops(struct net_device *ndev)
else
ndev->ethtool_ops = &enetc_vf_ethtool_ops;
}
+EXPORT_SYMBOL_NS_GPL(enetc_set_ethtool_ops, FSL_ENETC_CORE);
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
index bdf94335ee99..b767b6a28e8b 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
@@ -1410,5 +1410,7 @@ static struct pci_driver enetc_pf_driver = {
};
module_pci_driver(enetc_pf_driver);

+MODULE_IMPORT_NS(FSL_ENETC_CORE);
+
MODULE_DESCRIPTION(ENETC_DRV_NAME_STR);
MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_vf.c b/drivers/net/ethernet/freescale/enetc/enetc_vf.c
index dfcaac302e24..ab53799618c7 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_vf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_vf.c
@@ -259,5 +259,7 @@ static struct pci_driver enetc_vf_driver = {
};
module_pci_driver(enetc_vf_driver);

+MODULE_IMPORT_NS(FSL_ENETC_CORE);
+
MODULE_DESCRIPTION(ENETC_DRV_NAME_STR);
MODULE_LICENSE("Dual BSD/GPL");
--
2.38.1