diff mbox series

[v3,net-next,06/13] net: enetc: build enetc_pf_common.c as a separate module

Message ID 20241017074637.1265584-7-wei.fang@nxp.com (mailing list archive)
State Superseded
Headers show
Series add basic support for i.MX95 NETC | expand

Commit Message

Wei Fang Oct. 17, 2024, 7:46 a.m. UTC
Compile enetc_pf_common.c as a standalone module to allow shared usage
between ENETC v1 and v4 PF drivers. Add struct enetc_pf_ops to register
different hardware operation interfaces for both ENETC v1 and v4 PF
drivers.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
v2 changes:
This patch is separated from v1 patch 5 ("net: enetc: add enetc-pf-common
driver support"), only the changes to compile enetc_pf_common.c into a
separated driver are kept.
v3 changes:
Refactor the commit message.
---
 drivers/net/ethernet/freescale/enetc/Kconfig  |  9 ++++
 drivers/net/ethernet/freescale/enetc/Makefile |  5 +-
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 26 ++++++++--
 .../net/ethernet/freescale/enetc/enetc_pf.h   | 21 ++++++--
 .../freescale/enetc/enetc_pf_common.c         | 50 ++++++++++++++++---
 5 files changed, 96 insertions(+), 15 deletions(-)

Comments

Frank Li Oct. 17, 2024, 4:39 p.m. UTC | #1
On Thu, Oct 17, 2024 at 03:46:30PM +0800, Wei Fang wrote:
> Compile enetc_pf_common.c as a standalone module to allow shared usage
> between ENETC v1 and v4 PF drivers. Add struct enetc_pf_ops to register
> different hardware operation interfaces for both ENETC v1 and v4 PF
> drivers.
>
> Signed-off-by: Wei Fang <wei.fang@nxp.com>
> ---
> v2 changes:
> This patch is separated from v1 patch 5 ("net: enetc: add enetc-pf-common
> driver support"), only the changes to compile enetc_pf_common.c into a
> separated driver are kept.
> v3 changes:
> Refactor the commit message.
> ---
>  drivers/net/ethernet/freescale/enetc/Kconfig  |  9 ++++
>  drivers/net/ethernet/freescale/enetc/Makefile |  5 +-
>  .../net/ethernet/freescale/enetc/enetc_pf.c   | 26 ++++++++--
>  .../net/ethernet/freescale/enetc/enetc_pf.h   | 21 ++++++--
>  .../freescale/enetc/enetc_pf_common.c         | 50 ++++++++++++++++---
>  5 files changed, 96 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/net/ethernet/freescale/enetc/Kconfig b/drivers/net/ethernet/freescale/enetc/Kconfig
> index 51d80ea959d4..fdd3ecbd1dbf 100644
> --- a/drivers/net/ethernet/freescale/enetc/Kconfig
> +++ b/drivers/net/ethernet/freescale/enetc/Kconfig
> @@ -7,6 +7,14 @@ config FSL_ENETC_CORE
>
>  	  If compiled as module (M), the module name is fsl-enetc-core.
>
> +config NXP_ENETC_PF_COMMON
> +	tristate "ENETC PF common functionality driver"
> +	help
> +	  This module supports common functionality between drivers of
> +	  different versions of NXP ENETC PF controllers.
> +
> +	  If compiled as module (M), the module name is nxp-enetc-pf-common.
> +
>  config FSL_ENETC
>  	tristate "ENETC PF driver"
>  	depends on PCI_MSI
> @@ -14,6 +22,7 @@ config FSL_ENETC
>  	select FSL_ENETC_CORE
>  	select FSL_ENETC_IERB
>  	select FSL_ENETC_MDIO
> +	select NXP_ENETC_PF_COMMON
>  	select PHYLINK
>  	select PCS_LYNX
>  	select DIMLIB
> diff --git a/drivers/net/ethernet/freescale/enetc/Makefile b/drivers/net/ethernet/freescale/enetc/Makefile
> index 39675e9ff39d..b81ca462e358 100644
> --- a/drivers/net/ethernet/freescale/enetc/Makefile
> +++ b/drivers/net/ethernet/freescale/enetc/Makefile
> @@ -3,8 +3,11 @@
>  obj-$(CONFIG_FSL_ENETC_CORE) += fsl-enetc-core.o
>  fsl-enetc-core-y := enetc.o enetc_cbdr.o enetc_ethtool.o
>
> +obj-$(CONFIG_NXP_ENETC_PF_COMMON) += nxp-enetc-pf-common.o
> +nxp-enetc-pf-common-y := enetc_pf_common.o
> +
>  obj-$(CONFIG_FSL_ENETC) += fsl-enetc.o
> -fsl-enetc-y := enetc_pf.o enetc_pf_common.o
> +fsl-enetc-y := enetc_pf.o
>  fsl-enetc-$(CONFIG_PCI_IOV) += enetc_msg.o
>  fsl-enetc-$(CONFIG_FSL_ENETC_QOS) += enetc_qos.o
>
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> index 3cdd149056f9..7522316ddfea 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> @@ -11,7 +11,7 @@
>
>  #define ENETC_DRV_NAME_STR "ENETC PF driver"
>
> -void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)
> +static void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)
>  {
>  	u32 upper = __raw_readl(hw->port + ENETC_PSIPMAR0(si));
>  	u16 lower = __raw_readw(hw->port + ENETC_PSIPMAR1(si));
> @@ -20,8 +20,8 @@ void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)
>  	put_unaligned_le16(lower, addr + 4);
>  }
>
> -void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
> -				   const u8 *addr)
> +static void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
> +					  const u8 *addr)
>  {
>  	u32 upper = get_unaligned_le32(addr);
>  	u16 lower = get_unaligned_le16(addr + 4);
> @@ -30,6 +30,17 @@ void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
>  	__raw_writew(lower, hw->port + ENETC_PSIPMAR1(si));
>  }
>
> +static struct phylink_pcs *enetc_pf_create_pcs(struct enetc_pf *pf,
> +					       struct mii_bus *bus)
> +{
> +	return lynx_pcs_create_mdiodev(bus, 0);
> +}
> +
> +static void enetc_pf_destroy_pcs(struct phylink_pcs *pcs)
> +{
> +	lynx_pcs_destroy(pcs);
> +}
> +
>  static void enetc_set_vlan_promisc(struct enetc_hw *hw, char si_map)
>  {
>  	u32 val = enetc_port_rd(hw, ENETC_PSIPVMR);
> @@ -970,6 +981,14 @@ static void enetc_psi_destroy(struct pci_dev *pdev)
>  	enetc_pci_remove(pdev);
>  }
>
> +static const struct enetc_pf_ops enetc_pf_ops = {
> +	.set_si_primary_mac = enetc_pf_set_primary_mac_addr,
> +	.get_si_primary_mac = enetc_pf_get_primary_mac_addr,
> +	.create_pcs = enetc_pf_create_pcs,
> +	.destroy_pcs = enetc_pf_destroy_pcs,
> +	.enable_psfp = enetc_psfp_enable,
> +};
> +
>  static int enetc_pf_probe(struct pci_dev *pdev,
>  			  const struct pci_device_id *ent)
>  {
> @@ -997,6 +1016,7 @@ static int enetc_pf_probe(struct pci_dev *pdev,
>  	pf = enetc_si_priv(si);
>  	pf->si = si;
>  	pf->total_vfs = pci_sriov_get_totalvfs(pdev);
> +	enetc_pf_ops_register(pf, &enetc_pf_ops);
>
>  	err = enetc_setup_mac_addresses(node, pf);
>  	if (err)
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.h b/drivers/net/ethernet/freescale/enetc/enetc_pf.h
> index 92a26b09cf57..39db9d5c2e50 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h
> +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h
> @@ -28,6 +28,16 @@ struct enetc_vf_state {
>  	enum enetc_vf_flags flags;
>  };
>
> +struct enetc_pf;
> +
> +struct enetc_pf_ops {
> +	void (*set_si_primary_mac)(struct enetc_hw *hw, int si, const u8 *addr);
> +	void (*get_si_primary_mac)(struct enetc_hw *hw, int si, u8 *addr);

Is it possible get_si_primary_mac() return failure?

Frank

> +	struct phylink_pcs *(*create_pcs)(struct enetc_pf *pf, struct mii_bus *bus);
> +	void (*destroy_pcs)(struct phylink_pcs *pcs);
> +	int (*enable_psfp)(struct enetc_ndev_priv *priv);
> +};
> +
>  struct enetc_pf {
>  	struct enetc_si *si;
>  	int num_vfs; /* number of active VFs, after sriov_init */
> @@ -50,6 +60,8 @@ struct enetc_pf {
>
>  	phy_interface_t if_mode;
>  	struct phylink_config phylink_config;
> +
> +	const struct enetc_pf_ops *ops;
>  };
>
>  #define phylink_to_enetc_pf(config) \
> @@ -59,9 +71,6 @@ int enetc_msg_psi_init(struct enetc_pf *pf);
>  void enetc_msg_psi_free(struct enetc_pf *pf);
>  void enetc_msg_handle_rxmsg(struct enetc_pf *pf, int mbox_id, u16 *status);
>
> -void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr);
> -void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
> -				   const u8 *addr);
>  int enetc_pf_set_mac_addr(struct net_device *ndev, void *addr);
>  int enetc_setup_mac_addresses(struct device_node *np, struct enetc_pf *pf);
>  void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
> @@ -71,3 +80,9 @@ void enetc_mdiobus_destroy(struct enetc_pf *pf);
>  int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node *node,
>  			 const struct phylink_mac_ops *ops);
>  void enetc_phylink_destroy(struct enetc_ndev_priv *priv);
> +
> +static inline void enetc_pf_ops_register(struct enetc_pf *pf,
> +					 const struct enetc_pf_ops *ops)
> +{
> +	pf->ops = ops;
> +}
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
> index bce81a4f6f88..94690ed92e3f 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
> +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
> @@ -8,19 +8,37 @@
>
>  #include "enetc_pf.h"
>
> +static int enetc_set_si_hw_addr(struct enetc_pf *pf, int si, u8 *mac_addr)
> +{
> +	struct enetc_hw *hw = &pf->si->hw;
> +
> +	if (pf->ops->set_si_primary_mac)
> +		pf->ops->set_si_primary_mac(hw, si, mac_addr);
> +	else
> +		return -EOPNOTSUPP;
> +
> +	return 0;
> +}
> +
>  int enetc_pf_set_mac_addr(struct net_device *ndev, void *addr)
>  {
>  	struct enetc_ndev_priv *priv = netdev_priv(ndev);
> +	struct enetc_pf *pf = enetc_si_priv(priv->si);
>  	struct sockaddr *saddr = addr;
> +	int err;
>
>  	if (!is_valid_ether_addr(saddr->sa_data))
>  		return -EADDRNOTAVAIL;
>
> +	err = enetc_set_si_hw_addr(pf, 0, saddr->sa_data);
> +	if (err)
> +		return err;
> +
>  	eth_hw_addr_set(ndev, saddr->sa_data);
> -	enetc_pf_set_primary_mac_addr(&priv->si->hw, 0, saddr->sa_data);
>
>  	return 0;
>  }
> +EXPORT_SYMBOL_GPL(enetc_pf_set_mac_addr);
>
>  static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf,
>  				   int si)
> @@ -38,8 +56,8 @@ static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf,
>  	}
>
>  	/* (2) bootloader supplied MAC address */
> -	if (is_zero_ether_addr(mac_addr))
> -		enetc_pf_get_primary_mac_addr(hw, si, mac_addr);
> +	if (is_zero_ether_addr(mac_addr) && pf->ops->get_si_primary_mac)
> +		pf->ops->get_si_primary_mac(hw, si, mac_addr);
>
>  	/* (3) choose a random one */
>  	if (is_zero_ether_addr(mac_addr)) {
> @@ -48,7 +66,9 @@ static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf,
>  			 si, mac_addr);
>  	}
>
> -	enetc_pf_set_primary_mac_addr(hw, si, mac_addr);
> +	err = enetc_set_si_hw_addr(pf, si, mac_addr);
> +	if (err)
> +		return err;
>
>  	return 0;
>  }
> @@ -70,11 +90,13 @@ int enetc_setup_mac_addresses(struct device_node *np, struct enetc_pf *pf)
>
>  	return 0;
>  }
> +EXPORT_SYMBOL_GPL(enetc_setup_mac_addresses);
>
>  void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
>  			   const struct net_device_ops *ndev_ops)
>  {
>  	struct enetc_ndev_priv *priv = netdev_priv(ndev);
> +	struct enetc_pf *pf = enetc_si_priv(si);
>
>  	SET_NETDEV_DEV(ndev, &si->pdev->dev);
>  	priv->ndev = ndev;
> @@ -107,7 +129,8 @@ void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
>  			     NETDEV_XDP_ACT_NDO_XMIT | NETDEV_XDP_ACT_RX_SG |
>  			     NETDEV_XDP_ACT_NDO_XMIT_SG;
>
> -	if (si->hw_features & ENETC_SI_F_PSFP && !enetc_psfp_enable(priv)) {
> +	if (si->hw_features & ENETC_SI_F_PSFP && pf->ops->enable_psfp &&
> +	    !pf->ops->enable_psfp(priv)) {
>  		priv->active_offloads |= ENETC_F_QCI;
>  		ndev->features |= NETIF_F_HW_TC;
>  		ndev->hw_features |= NETIF_F_HW_TC;
> @@ -116,6 +139,7 @@ void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
>  	/* pick up primary MAC address from SI */
>  	enetc_load_primary_mac_addr(&si->hw, ndev);
>  }
> +EXPORT_SYMBOL_GPL(enetc_pf_netdev_setup);
>
>  static int enetc_mdio_probe(struct enetc_pf *pf, struct device_node *np)
>  {
> @@ -162,6 +186,9 @@ static int enetc_imdio_create(struct enetc_pf *pf)
>  	struct mii_bus *bus;
>  	int err;
>
> +	if (!pf->ops->create_pcs)
> +		return -EOPNOTSUPP;
> +
>  	bus = mdiobus_alloc_size(sizeof(*mdio_priv));
>  	if (!bus)
>  		return -ENOMEM;
> @@ -184,7 +211,7 @@ static int enetc_imdio_create(struct enetc_pf *pf)
>  		goto free_mdio_bus;
>  	}
>
> -	phylink_pcs = lynx_pcs_create_mdiodev(bus, 0);
> +	phylink_pcs = pf->ops->create_pcs(pf, bus);
>  	if (IS_ERR(phylink_pcs)) {
>  		err = PTR_ERR(phylink_pcs);
>  		dev_err(dev, "cannot create lynx pcs (%d)\n", err);
> @@ -205,8 +232,8 @@ static int enetc_imdio_create(struct enetc_pf *pf)
>
>  static void enetc_imdio_remove(struct enetc_pf *pf)
>  {
> -	if (pf->pcs)
> -		lynx_pcs_destroy(pf->pcs);
> +	if (pf->pcs && pf->ops->destroy_pcs)
> +		pf->ops->destroy_pcs(pf->pcs);
>
>  	if (pf->imdio) {
>  		mdiobus_unregister(pf->imdio);
> @@ -246,12 +273,14 @@ int enetc_mdiobus_create(struct enetc_pf *pf, struct device_node *node)
>
>  	return 0;
>  }
> +EXPORT_SYMBOL_GPL(enetc_mdiobus_create);
>
>  void enetc_mdiobus_destroy(struct enetc_pf *pf)
>  {
>  	enetc_mdio_remove(pf);
>  	enetc_imdio_remove(pf);
>  }
> +EXPORT_SYMBOL_GPL(enetc_mdiobus_destroy);
>
>  int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node *node,
>  			 const struct phylink_mac_ops *ops)
> @@ -288,8 +317,13 @@ int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node *node,
>
>  	return 0;
>  }
> +EXPORT_SYMBOL_GPL(enetc_phylink_create);
>
>  void enetc_phylink_destroy(struct enetc_ndev_priv *priv)
>  {
>  	phylink_destroy(priv->phylink);
>  }
> +EXPORT_SYMBOL_GPL(enetc_phylink_destroy);
> +
> +MODULE_DESCRIPTION("NXP ENETC PF common functionality driver");
> +MODULE_LICENSE("Dual BSD/GPL");
> --
> 2.34.1
>
Wei Fang Oct. 18, 2024, 1:30 a.m. UTC | #2
> -----Original Message-----
> From: Frank Li <frank.li@nxp.com>
> Sent: 2024年10月18日 0:40
> To: Wei Fang <wei.fang@nxp.com>
> Cc: davem@davemloft.net; edumazet@google.com; kuba@kernel.org;
> pabeni@redhat.com; robh@kernel.org; krzk+dt@kernel.org;
> conor+dt@kernel.org; Vladimir Oltean <vladimir.oltean@nxp.com>; Claudiu
> Manoil <claudiu.manoil@nxp.com>; Clark Wang <xiaoning.wang@nxp.com>;
> christophe.leroy@csgroup.eu; linux@armlinux.org.uk; bhelgaas@google.com;
> horms@kernel.org; imx@lists.linux.dev; netdev@vger.kernel.org;
> devicetree@vger.kernel.org; linux-kernel@vger.kernel.org;
> linux-pci@vger.kernel.org
> Subject: Re: [PATCH v3 net-next 06/13] net: enetc: build enetc_pf_common.c
> as a separate module
> 
> On Thu, Oct 17, 2024 at 03:46:30PM +0800, Wei Fang wrote:
> > Compile enetc_pf_common.c as a standalone module to allow shared usage
> > between ENETC v1 and v4 PF drivers. Add struct enetc_pf_ops to
> > register different hardware operation interfaces for both ENETC v1 and
> > v4 PF drivers.
> >
> > Signed-off-by: Wei Fang <wei.fang@nxp.com>
> > ---
> > v2 changes:
> > This patch is separated from v1 patch 5 ("net: enetc: add
> > enetc-pf-common driver support"), only the changes to compile
> > enetc_pf_common.c into a separated driver are kept.
> > v3 changes:
> > Refactor the commit message.
> > ---
> >  drivers/net/ethernet/freescale/enetc/Kconfig  |  9 ++++
> > drivers/net/ethernet/freescale/enetc/Makefile |  5 +-
> >  .../net/ethernet/freescale/enetc/enetc_pf.c   | 26 ++++++++--
> >  .../net/ethernet/freescale/enetc/enetc_pf.h   | 21 ++++++--
> >  .../freescale/enetc/enetc_pf_common.c         | 50
> ++++++++++++++++---
> >  5 files changed, 96 insertions(+), 15 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/freescale/enetc/Kconfig
> > b/drivers/net/ethernet/freescale/enetc/Kconfig
> > index 51d80ea959d4..fdd3ecbd1dbf 100644
> > --- a/drivers/net/ethernet/freescale/enetc/Kconfig
> > +++ b/drivers/net/ethernet/freescale/enetc/Kconfig
> > @@ -7,6 +7,14 @@ config FSL_ENETC_CORE
> >
> >  	  If compiled as module (M), the module name is fsl-enetc-core.
> >
> > +config NXP_ENETC_PF_COMMON
> > +	tristate "ENETC PF common functionality driver"
> > +	help
> > +	  This module supports common functionality between drivers of
> > +	  different versions of NXP ENETC PF controllers.
> > +
> > +	  If compiled as module (M), the module name is nxp-enetc-pf-common.
> > +
> >  config FSL_ENETC
> >  	tristate "ENETC PF driver"
> >  	depends on PCI_MSI
> > @@ -14,6 +22,7 @@ config FSL_ENETC
> >  	select FSL_ENETC_CORE
> >  	select FSL_ENETC_IERB
> >  	select FSL_ENETC_MDIO
> > +	select NXP_ENETC_PF_COMMON
> >  	select PHYLINK
> >  	select PCS_LYNX
> >  	select DIMLIB
> > diff --git a/drivers/net/ethernet/freescale/enetc/Makefile
> > b/drivers/net/ethernet/freescale/enetc/Makefile
> > index 39675e9ff39d..b81ca462e358 100644
> > --- a/drivers/net/ethernet/freescale/enetc/Makefile
> > +++ b/drivers/net/ethernet/freescale/enetc/Makefile
> > @@ -3,8 +3,11 @@
> >  obj-$(CONFIG_FSL_ENETC_CORE) += fsl-enetc-core.o  fsl-enetc-core-y :=
> > enetc.o enetc_cbdr.o enetc_ethtool.o
> >
> > +obj-$(CONFIG_NXP_ENETC_PF_COMMON) += nxp-enetc-pf-common.o
> > +nxp-enetc-pf-common-y := enetc_pf_common.o
> > +
> >  obj-$(CONFIG_FSL_ENETC) += fsl-enetc.o -fsl-enetc-y := enetc_pf.o
> > enetc_pf_common.o
> > +fsl-enetc-y := enetc_pf.o
> >  fsl-enetc-$(CONFIG_PCI_IOV) += enetc_msg.o
> >  fsl-enetc-$(CONFIG_FSL_ENETC_QOS) += enetc_qos.o
> >
> > diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> > b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> > index 3cdd149056f9..7522316ddfea 100644
> > --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> > +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> > @@ -11,7 +11,7 @@
> >
> >  #define ENETC_DRV_NAME_STR "ENETC PF driver"
> >
> > -void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8
> > *addr)
> > +static void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int
> > +si, u8 *addr)
> >  {
> >  	u32 upper = __raw_readl(hw->port + ENETC_PSIPMAR0(si));
> >  	u16 lower = __raw_readw(hw->port + ENETC_PSIPMAR1(si)); @@ -20,8
> > +20,8 @@ void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si,
> u8 *addr)
> >  	put_unaligned_le16(lower, addr + 4);  }
> >
> > -void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
> > -				   const u8 *addr)
> > +static void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
> > +					  const u8 *addr)
> >  {
> >  	u32 upper = get_unaligned_le32(addr);
> >  	u16 lower = get_unaligned_le16(addr + 4); @@ -30,6 +30,17 @@ void
> > enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
> >  	__raw_writew(lower, hw->port + ENETC_PSIPMAR1(si));  }
> >
> > +static struct phylink_pcs *enetc_pf_create_pcs(struct enetc_pf *pf,
> > +					       struct mii_bus *bus)
> > +{
> > +	return lynx_pcs_create_mdiodev(bus, 0); }
> > +
> > +static void enetc_pf_destroy_pcs(struct phylink_pcs *pcs) {
> > +	lynx_pcs_destroy(pcs);
> > +}
> > +
> >  static void enetc_set_vlan_promisc(struct enetc_hw *hw, char si_map)
> > {
> >  	u32 val = enetc_port_rd(hw, ENETC_PSIPVMR); @@ -970,6 +981,14 @@
> > static void enetc_psi_destroy(struct pci_dev *pdev)
> >  	enetc_pci_remove(pdev);
> >  }
> >
> > +static const struct enetc_pf_ops enetc_pf_ops = {
> > +	.set_si_primary_mac = enetc_pf_set_primary_mac_addr,
> > +	.get_si_primary_mac = enetc_pf_get_primary_mac_addr,
> > +	.create_pcs = enetc_pf_create_pcs,
> > +	.destroy_pcs = enetc_pf_destroy_pcs,
> > +	.enable_psfp = enetc_psfp_enable,
> > +};
> > +
> >  static int enetc_pf_probe(struct pci_dev *pdev,
> >  			  const struct pci_device_id *ent)  { @@ -997,6 +1016,7 @@
> static
> > int enetc_pf_probe(struct pci_dev *pdev,
> >  	pf = enetc_si_priv(si);
> >  	pf->si = si;
> >  	pf->total_vfs = pci_sriov_get_totalvfs(pdev);
> > +	enetc_pf_ops_register(pf, &enetc_pf_ops);
> >
> >  	err = enetc_setup_mac_addresses(node, pf);
> >  	if (err)
> > diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.h
> > b/drivers/net/ethernet/freescale/enetc/enetc_pf.h
> > index 92a26b09cf57..39db9d5c2e50 100644
> > --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h
> > +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h
> > @@ -28,6 +28,16 @@ struct enetc_vf_state {
> >  	enum enetc_vf_flags flags;
> >  };
> >
> > +struct enetc_pf;
> > +
> > +struct enetc_pf_ops {
> > +	void (*set_si_primary_mac)(struct enetc_hw *hw, int si, const u8 *addr);
> > +	void (*get_si_primary_mac)(struct enetc_hw *hw, int si, u8 *addr);
> 
> Is it possible get_si_primary_mac() return failure?
> 

get_si_primary_mac() get the MAC by reading registers, and we will check
the MAC address. See below code snippet. So there is no need to return
error.

if (is_zero_ether_addr(mac_addr) && pf->ops->get_si_primary_mac)
	pf->ops->get_si_primary_mac(hw, si, mac_addr);

/* (3) choose a random one */
if (is_zero_ether_addr(mac_addr)) {
	eth_random_addr(mac_addr);
	dev_info(dev, "no MAC address specified for SI%d, using %pM\n",
			si, mac_addr);
}

> 
> > +	struct phylink_pcs *(*create_pcs)(struct enetc_pf *pf, struct mii_bus
> *bus);
> > +	void (*destroy_pcs)(struct phylink_pcs *pcs);
> > +	int (*enable_psfp)(struct enetc_ndev_priv *priv); };
> > +
> >  struct enetc_pf {
> >  	struct enetc_si *si;
> >  	int num_vfs; /* number of active VFs, after sriov_init */ @@ -50,6
> > +60,8 @@ struct enetc_pf {
> >
> >  	phy_interface_t if_mode;
> >  	struct phylink_config phylink_config;
> > +
> > +	const struct enetc_pf_ops *ops;
> >  };
> >
> >  #define phylink_to_enetc_pf(config) \ @@ -59,9 +71,6 @@ int
> > enetc_msg_psi_init(struct enetc_pf *pf);  void
> > enetc_msg_psi_free(struct enetc_pf *pf);  void
> > enetc_msg_handle_rxmsg(struct enetc_pf *pf, int mbox_id, u16 *status);
> >
> > -void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8
> > *addr); -void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
> > -				   const u8 *addr);
> >  int enetc_pf_set_mac_addr(struct net_device *ndev, void *addr);  int
> > enetc_setup_mac_addresses(struct device_node *np, struct enetc_pf
> > *pf);  void enetc_pf_netdev_setup(struct enetc_si *si, struct
> > net_device *ndev, @@ -71,3 +80,9 @@ void enetc_mdiobus_destroy(struct
> > enetc_pf *pf);  int enetc_phylink_create(struct enetc_ndev_priv *priv, struct
> device_node *node,
> >  			 const struct phylink_mac_ops *ops);  void
> > enetc_phylink_destroy(struct enetc_ndev_priv *priv);
> > +
> > +static inline void enetc_pf_ops_register(struct enetc_pf *pf,
> > +					 const struct enetc_pf_ops *ops) {
> > +	pf->ops = ops;
> > +}
> > diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
> > b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
> > index bce81a4f6f88..94690ed92e3f 100644
> > --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
> > +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
> > @@ -8,19 +8,37 @@
> >
> >  #include "enetc_pf.h"
> >
> > +static int enetc_set_si_hw_addr(struct enetc_pf *pf, int si, u8
> > +*mac_addr) {
> > +	struct enetc_hw *hw = &pf->si->hw;
> > +
> > +	if (pf->ops->set_si_primary_mac)
> > +		pf->ops->set_si_primary_mac(hw, si, mac_addr);
> > +	else
> > +		return -EOPNOTSUPP;
> > +
> > +	return 0;
> > +}
> > +
> >  int enetc_pf_set_mac_addr(struct net_device *ndev, void *addr)  {
> >  	struct enetc_ndev_priv *priv = netdev_priv(ndev);
> > +	struct enetc_pf *pf = enetc_si_priv(priv->si);
> >  	struct sockaddr *saddr = addr;
> > +	int err;
> >
> >  	if (!is_valid_ether_addr(saddr->sa_data))
> >  		return -EADDRNOTAVAIL;
> >
> > +	err = enetc_set_si_hw_addr(pf, 0, saddr->sa_data);
> > +	if (err)
> > +		return err;
> > +
> >  	eth_hw_addr_set(ndev, saddr->sa_data);
> > -	enetc_pf_set_primary_mac_addr(&priv->si->hw, 0, saddr->sa_data);
> >
> >  	return 0;
> >  }
> > +EXPORT_SYMBOL_GPL(enetc_pf_set_mac_addr);
> >
> >  static int enetc_setup_mac_address(struct device_node *np, struct
> enetc_pf *pf,
> >  				   int si)
> > @@ -38,8 +56,8 @@ static int enetc_setup_mac_address(struct
> device_node *np, struct enetc_pf *pf,
> >  	}
> >
> >  	/* (2) bootloader supplied MAC address */
> > -	if (is_zero_ether_addr(mac_addr))
> > -		enetc_pf_get_primary_mac_addr(hw, si, mac_addr);
> > +	if (is_zero_ether_addr(mac_addr) && pf->ops->get_si_primary_mac)
> > +		pf->ops->get_si_primary_mac(hw, si, mac_addr);
> >
> >  	/* (3) choose a random one */
> >  	if (is_zero_ether_addr(mac_addr)) {
> > @@ -48,7 +66,9 @@ static int enetc_setup_mac_address(struct
> device_node *np, struct enetc_pf *pf,
> >  			 si, mac_addr);
> >  	}
> >
> > -	enetc_pf_set_primary_mac_addr(hw, si, mac_addr);
> > +	err = enetc_set_si_hw_addr(pf, si, mac_addr);
> > +	if (err)
> > +		return err;
> >
> >  	return 0;
> >  }
> > @@ -70,11 +90,13 @@ int enetc_setup_mac_addresses(struct device_node
> > *np, struct enetc_pf *pf)
> >
> >  	return 0;
> >  }
> > +EXPORT_SYMBOL_GPL(enetc_setup_mac_addresses);
> >
> >  void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
> >  			   const struct net_device_ops *ndev_ops)  {
> >  	struct enetc_ndev_priv *priv = netdev_priv(ndev);
> > +	struct enetc_pf *pf = enetc_si_priv(si);
> >
> >  	SET_NETDEV_DEV(ndev, &si->pdev->dev);
> >  	priv->ndev = ndev;
> > @@ -107,7 +129,8 @@ void enetc_pf_netdev_setup(struct enetc_si *si,
> struct net_device *ndev,
> >  			     NETDEV_XDP_ACT_NDO_XMIT |
> NETDEV_XDP_ACT_RX_SG |
> >  			     NETDEV_XDP_ACT_NDO_XMIT_SG;
> >
> > -	if (si->hw_features & ENETC_SI_F_PSFP && !enetc_psfp_enable(priv)) {
> > +	if (si->hw_features & ENETC_SI_F_PSFP && pf->ops->enable_psfp &&
> > +	    !pf->ops->enable_psfp(priv)) {
> >  		priv->active_offloads |= ENETC_F_QCI;
> >  		ndev->features |= NETIF_F_HW_TC;
> >  		ndev->hw_features |= NETIF_F_HW_TC;
> > @@ -116,6 +139,7 @@ void enetc_pf_netdev_setup(struct enetc_si *si,
> struct net_device *ndev,
> >  	/* pick up primary MAC address from SI */
> >  	enetc_load_primary_mac_addr(&si->hw, ndev);
> >  }
> > +EXPORT_SYMBOL_GPL(enetc_pf_netdev_setup);
> >
> >  static int enetc_mdio_probe(struct enetc_pf *pf, struct device_node *np)
> >  {
> > @@ -162,6 +186,9 @@ static int enetc_imdio_create(struct enetc_pf *pf)
> >  	struct mii_bus *bus;
> >  	int err;
> >
> > +	if (!pf->ops->create_pcs)
> > +		return -EOPNOTSUPP;
> > +
> >  	bus = mdiobus_alloc_size(sizeof(*mdio_priv));
> >  	if (!bus)
> >  		return -ENOMEM;
> > @@ -184,7 +211,7 @@ static int enetc_imdio_create(struct enetc_pf *pf)
> >  		goto free_mdio_bus;
> >  	}
> >
> > -	phylink_pcs = lynx_pcs_create_mdiodev(bus, 0);
> > +	phylink_pcs = pf->ops->create_pcs(pf, bus);
> >  	if (IS_ERR(phylink_pcs)) {
> >  		err = PTR_ERR(phylink_pcs);
> >  		dev_err(dev, "cannot create lynx pcs (%d)\n", err);
> > @@ -205,8 +232,8 @@ static int enetc_imdio_create(struct enetc_pf *pf)
> >
> >  static void enetc_imdio_remove(struct enetc_pf *pf)
> >  {
> > -	if (pf->pcs)
> > -		lynx_pcs_destroy(pf->pcs);
> > +	if (pf->pcs && pf->ops->destroy_pcs)
> > +		pf->ops->destroy_pcs(pf->pcs);
> >
> >  	if (pf->imdio) {
> >  		mdiobus_unregister(pf->imdio);
> > @@ -246,12 +273,14 @@ int enetc_mdiobus_create(struct enetc_pf *pf,
> struct device_node *node)
> >
> >  	return 0;
> >  }
> > +EXPORT_SYMBOL_GPL(enetc_mdiobus_create);
> >
> >  void enetc_mdiobus_destroy(struct enetc_pf *pf)
> >  {
> >  	enetc_mdio_remove(pf);
> >  	enetc_imdio_remove(pf);
> >  }
> > +EXPORT_SYMBOL_GPL(enetc_mdiobus_destroy);
> >
> >  int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node
> *node,
> >  			 const struct phylink_mac_ops *ops)
> > @@ -288,8 +317,13 @@ int enetc_phylink_create(struct enetc_ndev_priv
> *priv, struct device_node *node,
> >
> >  	return 0;
> >  }
> > +EXPORT_SYMBOL_GPL(enetc_phylink_create);
> >
> >  void enetc_phylink_destroy(struct enetc_ndev_priv *priv)
> >  {
> >  	phylink_destroy(priv->phylink);
> >  }
> > +EXPORT_SYMBOL_GPL(enetc_phylink_destroy);
> > +
> > +MODULE_DESCRIPTION("NXP ENETC PF common functionality driver");
> > +MODULE_LICENSE("Dual BSD/GPL");
> > --
> > 2.34.1
> >
kernel test robot Oct. 18, 2024, 9:09 p.m. UTC | #3
Hi Wei,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Wei-Fang/dt-bindings-net-add-compatible-string-for-i-MX95-EMDIO/20241017-160848
base:   net-next/main
patch link:    https://lore.kernel.org/r/20241017074637.1265584-7-wei.fang%40nxp.com
patch subject: [PATCH v3 net-next 06/13] net: enetc: build enetc_pf_common.c as a separate module
config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20241019/202410190431.wiCDZy8G-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241019/202410190431.wiCDZy8G-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410190431.wiCDZy8G-lkp@intel.com/

All errors (new ones prefixed by >>, old ones prefixed by <<):

ERROR: modpost: "__delay" [drivers/net/mdio/mdio-cavium.ko] undefined!
>> ERROR: modpost: "enetc_set_ethtool_ops" [drivers/net/ethernet/freescale/enetc/nxp-enetc-pf-common.ko] undefined!
ERROR: modpost: "devm_of_clk_add_hw_provider" [drivers/media/i2c/tc358746.ko] undefined!
ERROR: modpost: "devm_clk_hw_register" [drivers/media/i2c/tc358746.ko] undefined!
ERROR: modpost: "of_clk_hw_simple_get" [drivers/media/i2c/tc358746.ko] undefined!
kernel test robot Oct. 19, 2024, 9:43 a.m. UTC | #4
Hi Wei,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Wei-Fang/dt-bindings-net-add-compatible-string-for-i-MX95-EMDIO/20241017-160848
base:   net-next/main
patch link:    https://lore.kernel.org/r/20241017074637.1265584-7-wei.fang%40nxp.com
patch subject: [PATCH v3 net-next 06/13] net: enetc: build enetc_pf_common.c as a separate module
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20241019/202410191715.TQmESUy9-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241019/202410191715.TQmESUy9-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410191715.TQmESUy9-lkp@intel.com/

All errors (new ones prefixed by >>):

   m68k-linux-ld: drivers/net/ethernet/freescale/enetc/enetc_pf_common.o: in function `enetc_pf_netdev_setup':
>> enetc_pf_common.c:(.text+0x55e): undefined reference to `enetc_set_ethtool_ops'

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for GET_FREE_REGION
   Depends on [n]: SPARSEMEM [=n]
   Selected by [y]:
   - RESOURCE_KUNIT_TEST [=y] && RUNTIME_TESTING_MENU [=y] && KUNIT [=y]
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/enetc/Kconfig b/drivers/net/ethernet/freescale/enetc/Kconfig
index 51d80ea959d4..fdd3ecbd1dbf 100644
--- a/drivers/net/ethernet/freescale/enetc/Kconfig
+++ b/drivers/net/ethernet/freescale/enetc/Kconfig
@@ -7,6 +7,14 @@  config FSL_ENETC_CORE
 
 	  If compiled as module (M), the module name is fsl-enetc-core.
 
+config NXP_ENETC_PF_COMMON
+	tristate "ENETC PF common functionality driver"
+	help
+	  This module supports common functionality between drivers of
+	  different versions of NXP ENETC PF controllers.
+
+	  If compiled as module (M), the module name is nxp-enetc-pf-common.
+
 config FSL_ENETC
 	tristate "ENETC PF driver"
 	depends on PCI_MSI
@@ -14,6 +22,7 @@  config FSL_ENETC
 	select FSL_ENETC_CORE
 	select FSL_ENETC_IERB
 	select FSL_ENETC_MDIO
+	select NXP_ENETC_PF_COMMON
 	select PHYLINK
 	select PCS_LYNX
 	select DIMLIB
diff --git a/drivers/net/ethernet/freescale/enetc/Makefile b/drivers/net/ethernet/freescale/enetc/Makefile
index 39675e9ff39d..b81ca462e358 100644
--- a/drivers/net/ethernet/freescale/enetc/Makefile
+++ b/drivers/net/ethernet/freescale/enetc/Makefile
@@ -3,8 +3,11 @@ 
 obj-$(CONFIG_FSL_ENETC_CORE) += fsl-enetc-core.o
 fsl-enetc-core-y := enetc.o enetc_cbdr.o enetc_ethtool.o
 
+obj-$(CONFIG_NXP_ENETC_PF_COMMON) += nxp-enetc-pf-common.o
+nxp-enetc-pf-common-y := enetc_pf_common.o
+
 obj-$(CONFIG_FSL_ENETC) += fsl-enetc.o
-fsl-enetc-y := enetc_pf.o enetc_pf_common.o
+fsl-enetc-y := enetc_pf.o
 fsl-enetc-$(CONFIG_PCI_IOV) += enetc_msg.o
 fsl-enetc-$(CONFIG_FSL_ENETC_QOS) += enetc_qos.o
 
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
index 3cdd149056f9..7522316ddfea 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
@@ -11,7 +11,7 @@ 
 
 #define ENETC_DRV_NAME_STR "ENETC PF driver"
 
-void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)
+static void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)
 {
 	u32 upper = __raw_readl(hw->port + ENETC_PSIPMAR0(si));
 	u16 lower = __raw_readw(hw->port + ENETC_PSIPMAR1(si));
@@ -20,8 +20,8 @@  void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)
 	put_unaligned_le16(lower, addr + 4);
 }
 
-void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
-				   const u8 *addr)
+static void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
+					  const u8 *addr)
 {
 	u32 upper = get_unaligned_le32(addr);
 	u16 lower = get_unaligned_le16(addr + 4);
@@ -30,6 +30,17 @@  void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
 	__raw_writew(lower, hw->port + ENETC_PSIPMAR1(si));
 }
 
+static struct phylink_pcs *enetc_pf_create_pcs(struct enetc_pf *pf,
+					       struct mii_bus *bus)
+{
+	return lynx_pcs_create_mdiodev(bus, 0);
+}
+
+static void enetc_pf_destroy_pcs(struct phylink_pcs *pcs)
+{
+	lynx_pcs_destroy(pcs);
+}
+
 static void enetc_set_vlan_promisc(struct enetc_hw *hw, char si_map)
 {
 	u32 val = enetc_port_rd(hw, ENETC_PSIPVMR);
@@ -970,6 +981,14 @@  static void enetc_psi_destroy(struct pci_dev *pdev)
 	enetc_pci_remove(pdev);
 }
 
+static const struct enetc_pf_ops enetc_pf_ops = {
+	.set_si_primary_mac = enetc_pf_set_primary_mac_addr,
+	.get_si_primary_mac = enetc_pf_get_primary_mac_addr,
+	.create_pcs = enetc_pf_create_pcs,
+	.destroy_pcs = enetc_pf_destroy_pcs,
+	.enable_psfp = enetc_psfp_enable,
+};
+
 static int enetc_pf_probe(struct pci_dev *pdev,
 			  const struct pci_device_id *ent)
 {
@@ -997,6 +1016,7 @@  static int enetc_pf_probe(struct pci_dev *pdev,
 	pf = enetc_si_priv(si);
 	pf->si = si;
 	pf->total_vfs = pci_sriov_get_totalvfs(pdev);
+	enetc_pf_ops_register(pf, &enetc_pf_ops);
 
 	err = enetc_setup_mac_addresses(node, pf);
 	if (err)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.h b/drivers/net/ethernet/freescale/enetc/enetc_pf.h
index 92a26b09cf57..39db9d5c2e50 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h
@@ -28,6 +28,16 @@  struct enetc_vf_state {
 	enum enetc_vf_flags flags;
 };
 
+struct enetc_pf;
+
+struct enetc_pf_ops {
+	void (*set_si_primary_mac)(struct enetc_hw *hw, int si, const u8 *addr);
+	void (*get_si_primary_mac)(struct enetc_hw *hw, int si, u8 *addr);
+	struct phylink_pcs *(*create_pcs)(struct enetc_pf *pf, struct mii_bus *bus);
+	void (*destroy_pcs)(struct phylink_pcs *pcs);
+	int (*enable_psfp)(struct enetc_ndev_priv *priv);
+};
+
 struct enetc_pf {
 	struct enetc_si *si;
 	int num_vfs; /* number of active VFs, after sriov_init */
@@ -50,6 +60,8 @@  struct enetc_pf {
 
 	phy_interface_t if_mode;
 	struct phylink_config phylink_config;
+
+	const struct enetc_pf_ops *ops;
 };
 
 #define phylink_to_enetc_pf(config) \
@@ -59,9 +71,6 @@  int enetc_msg_psi_init(struct enetc_pf *pf);
 void enetc_msg_psi_free(struct enetc_pf *pf);
 void enetc_msg_handle_rxmsg(struct enetc_pf *pf, int mbox_id, u16 *status);
 
-void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr);
-void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
-				   const u8 *addr);
 int enetc_pf_set_mac_addr(struct net_device *ndev, void *addr);
 int enetc_setup_mac_addresses(struct device_node *np, struct enetc_pf *pf);
 void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
@@ -71,3 +80,9 @@  void enetc_mdiobus_destroy(struct enetc_pf *pf);
 int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node *node,
 			 const struct phylink_mac_ops *ops);
 void enetc_phylink_destroy(struct enetc_ndev_priv *priv);
+
+static inline void enetc_pf_ops_register(struct enetc_pf *pf,
+					 const struct enetc_pf_ops *ops)
+{
+	pf->ops = ops;
+}
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
index bce81a4f6f88..94690ed92e3f 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
@@ -8,19 +8,37 @@ 
 
 #include "enetc_pf.h"
 
+static int enetc_set_si_hw_addr(struct enetc_pf *pf, int si, u8 *mac_addr)
+{
+	struct enetc_hw *hw = &pf->si->hw;
+
+	if (pf->ops->set_si_primary_mac)
+		pf->ops->set_si_primary_mac(hw, si, mac_addr);
+	else
+		return -EOPNOTSUPP;
+
+	return 0;
+}
+
 int enetc_pf_set_mac_addr(struct net_device *ndev, void *addr)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
+	struct enetc_pf *pf = enetc_si_priv(priv->si);
 	struct sockaddr *saddr = addr;
+	int err;
 
 	if (!is_valid_ether_addr(saddr->sa_data))
 		return -EADDRNOTAVAIL;
 
+	err = enetc_set_si_hw_addr(pf, 0, saddr->sa_data);
+	if (err)
+		return err;
+
 	eth_hw_addr_set(ndev, saddr->sa_data);
-	enetc_pf_set_primary_mac_addr(&priv->si->hw, 0, saddr->sa_data);
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(enetc_pf_set_mac_addr);
 
 static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf,
 				   int si)
@@ -38,8 +56,8 @@  static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf,
 	}
 
 	/* (2) bootloader supplied MAC address */
-	if (is_zero_ether_addr(mac_addr))
-		enetc_pf_get_primary_mac_addr(hw, si, mac_addr);
+	if (is_zero_ether_addr(mac_addr) && pf->ops->get_si_primary_mac)
+		pf->ops->get_si_primary_mac(hw, si, mac_addr);
 
 	/* (3) choose a random one */
 	if (is_zero_ether_addr(mac_addr)) {
@@ -48,7 +66,9 @@  static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf,
 			 si, mac_addr);
 	}
 
-	enetc_pf_set_primary_mac_addr(hw, si, mac_addr);
+	err = enetc_set_si_hw_addr(pf, si, mac_addr);
+	if (err)
+		return err;
 
 	return 0;
 }
@@ -70,11 +90,13 @@  int enetc_setup_mac_addresses(struct device_node *np, struct enetc_pf *pf)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(enetc_setup_mac_addresses);
 
 void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
 			   const struct net_device_ops *ndev_ops)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
+	struct enetc_pf *pf = enetc_si_priv(si);
 
 	SET_NETDEV_DEV(ndev, &si->pdev->dev);
 	priv->ndev = ndev;
@@ -107,7 +129,8 @@  void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
 			     NETDEV_XDP_ACT_NDO_XMIT | NETDEV_XDP_ACT_RX_SG |
 			     NETDEV_XDP_ACT_NDO_XMIT_SG;
 
-	if (si->hw_features & ENETC_SI_F_PSFP && !enetc_psfp_enable(priv)) {
+	if (si->hw_features & ENETC_SI_F_PSFP && pf->ops->enable_psfp &&
+	    !pf->ops->enable_psfp(priv)) {
 		priv->active_offloads |= ENETC_F_QCI;
 		ndev->features |= NETIF_F_HW_TC;
 		ndev->hw_features |= NETIF_F_HW_TC;
@@ -116,6 +139,7 @@  void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
 	/* pick up primary MAC address from SI */
 	enetc_load_primary_mac_addr(&si->hw, ndev);
 }
+EXPORT_SYMBOL_GPL(enetc_pf_netdev_setup);
 
 static int enetc_mdio_probe(struct enetc_pf *pf, struct device_node *np)
 {
@@ -162,6 +186,9 @@  static int enetc_imdio_create(struct enetc_pf *pf)
 	struct mii_bus *bus;
 	int err;
 
+	if (!pf->ops->create_pcs)
+		return -EOPNOTSUPP;
+
 	bus = mdiobus_alloc_size(sizeof(*mdio_priv));
 	if (!bus)
 		return -ENOMEM;
@@ -184,7 +211,7 @@  static int enetc_imdio_create(struct enetc_pf *pf)
 		goto free_mdio_bus;
 	}
 
-	phylink_pcs = lynx_pcs_create_mdiodev(bus, 0);
+	phylink_pcs = pf->ops->create_pcs(pf, bus);
 	if (IS_ERR(phylink_pcs)) {
 		err = PTR_ERR(phylink_pcs);
 		dev_err(dev, "cannot create lynx pcs (%d)\n", err);
@@ -205,8 +232,8 @@  static int enetc_imdio_create(struct enetc_pf *pf)
 
 static void enetc_imdio_remove(struct enetc_pf *pf)
 {
-	if (pf->pcs)
-		lynx_pcs_destroy(pf->pcs);
+	if (pf->pcs && pf->ops->destroy_pcs)
+		pf->ops->destroy_pcs(pf->pcs);
 
 	if (pf->imdio) {
 		mdiobus_unregister(pf->imdio);
@@ -246,12 +273,14 @@  int enetc_mdiobus_create(struct enetc_pf *pf, struct device_node *node)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(enetc_mdiobus_create);
 
 void enetc_mdiobus_destroy(struct enetc_pf *pf)
 {
 	enetc_mdio_remove(pf);
 	enetc_imdio_remove(pf);
 }
+EXPORT_SYMBOL_GPL(enetc_mdiobus_destroy);
 
 int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node *node,
 			 const struct phylink_mac_ops *ops)
@@ -288,8 +317,13 @@  int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node *node,
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(enetc_phylink_create);
 
 void enetc_phylink_destroy(struct enetc_ndev_priv *priv)
 {
 	phylink_destroy(priv->phylink);
 }
+EXPORT_SYMBOL_GPL(enetc_phylink_destroy);
+
+MODULE_DESCRIPTION("NXP ENETC PF common functionality driver");
+MODULE_LICENSE("Dual BSD/GPL");