Skip to content

Commit 3774409

Browse files
Wei Fangdavem330
authored andcommitted
net: enetc: build enetc_pf_common.c as a separate module
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 80c8c85 commit 3774409

File tree

6 files changed

+89
-16
lines changed

6 files changed

+89
-16
lines changed

drivers/net/ethernet/freescale/enetc/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,22 @@ config FSL_ENETC_CORE
77

88
If compiled as module (M), the module name is fsl-enetc-core.
99

10+
config NXP_ENETC_PF_COMMON
11+
tristate
12+
help
13+
This module supports common functionality between drivers of
14+
different versions of NXP ENETC PF controllers.
15+
16+
If compiled as module (M), the module name is nxp-enetc-pf-common.
17+
1018
config FSL_ENETC
1119
tristate "ENETC PF driver"
1220
depends on PCI_MSI
1321
select MDIO_DEVRES
1422
select FSL_ENETC_CORE
1523
select FSL_ENETC_IERB
1624
select FSL_ENETC_MDIO
25+
select NXP_ENETC_PF_COMMON
1726
select PHYLINK
1827
select PCS_LYNX
1928
select DIMLIB

drivers/net/ethernet/freescale/enetc/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
obj-$(CONFIG_FSL_ENETC_CORE) += fsl-enetc-core.o
44
fsl-enetc-core-y := enetc.o enetc_cbdr.o enetc_ethtool.o
55

6+
obj-$(CONFIG_NXP_ENETC_PF_COMMON) += nxp-enetc-pf-common.o
7+
nxp-enetc-pf-common-y := enetc_pf_common.o
8+
69
obj-$(CONFIG_FSL_ENETC) += fsl-enetc.o
7-
fsl-enetc-y := enetc_pf.o enetc_pf_common.o
10+
fsl-enetc-y := enetc_pf.o
811
fsl-enetc-$(CONFIG_PCI_IOV) += enetc_msg.o
912
fsl-enetc-$(CONFIG_FSL_ENETC_QOS) += enetc_qos.o
1013

drivers/net/ethernet/freescale/enetc/enetc_pf.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#define ENETC_DRV_NAME_STR "ENETC PF driver"
1414

15-
void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)
15+
static void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)
1616
{
1717
u32 upper = __raw_readl(hw->port + ENETC_PSIPMAR0(si));
1818
u16 lower = __raw_readw(hw->port + ENETC_PSIPMAR1(si));
@@ -21,8 +21,8 @@ void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)
2121
put_unaligned_le16(lower, addr + 4);
2222
}
2323

24-
void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
25-
const u8 *addr)
24+
static void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
25+
const u8 *addr)
2626
{
2727
u32 upper = get_unaligned_le32(addr);
2828
u16 lower = get_unaligned_le16(addr + 4);
@@ -31,6 +31,17 @@ void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
3131
__raw_writew(lower, hw->port + ENETC_PSIPMAR1(si));
3232
}
3333

34+
static struct phylink_pcs *enetc_pf_create_pcs(struct enetc_pf *pf,
35+
struct mii_bus *bus)
36+
{
37+
return lynx_pcs_create_mdiodev(bus, 0);
38+
}
39+
40+
static void enetc_pf_destroy_pcs(struct phylink_pcs *pcs)
41+
{
42+
lynx_pcs_destroy(pcs);
43+
}
44+
3445
static void enetc_set_vlan_promisc(struct enetc_hw *hw, char si_map)
3546
{
3647
u32 val = enetc_port_rd(hw, ENETC_PSIPVMR);
@@ -971,6 +982,14 @@ static void enetc_psi_destroy(struct pci_dev *pdev)
971982
enetc_pci_remove(pdev);
972983
}
973984

985+
static const struct enetc_pf_ops enetc_pf_ops = {
986+
.set_si_primary_mac = enetc_pf_set_primary_mac_addr,
987+
.get_si_primary_mac = enetc_pf_get_primary_mac_addr,
988+
.create_pcs = enetc_pf_create_pcs,
989+
.destroy_pcs = enetc_pf_destroy_pcs,
990+
.enable_psfp = enetc_psfp_enable,
991+
};
992+
974993
static int enetc_pf_probe(struct pci_dev *pdev,
975994
const struct pci_device_id *ent)
976995
{
@@ -998,6 +1017,7 @@ static int enetc_pf_probe(struct pci_dev *pdev,
9981017
pf = enetc_si_priv(si);
9991018
pf->si = si;
10001019
pf->total_vfs = pci_sriov_get_totalvfs(pdev);
1020+
pf->ops = &enetc_pf_ops;
10011021

10021022
err = enetc_setup_mac_addresses(node, pf);
10031023
if (err)

drivers/net/ethernet/freescale/enetc/enetc_pf.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ struct enetc_vf_state {
2828
enum enetc_vf_flags flags;
2929
};
3030

31+
struct enetc_pf;
32+
33+
struct enetc_pf_ops {
34+
void (*set_si_primary_mac)(struct enetc_hw *hw, int si, const u8 *addr);
35+
void (*get_si_primary_mac)(struct enetc_hw *hw, int si, u8 *addr);
36+
struct phylink_pcs *(*create_pcs)(struct enetc_pf *pf, struct mii_bus *bus);
37+
void (*destroy_pcs)(struct phylink_pcs *pcs);
38+
int (*enable_psfp)(struct enetc_ndev_priv *priv);
39+
};
40+
3141
struct enetc_pf {
3242
struct enetc_si *si;
3343
int num_vfs; /* number of active VFs, after sriov_init */
@@ -50,6 +60,8 @@ struct enetc_pf {
5060

5161
phy_interface_t if_mode;
5262
struct phylink_config phylink_config;
63+
64+
const struct enetc_pf_ops *ops;
5365
};
5466

5567
#define phylink_to_enetc_pf(config) \

drivers/net/ethernet/freescale/enetc/enetc_pf_common.c

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,44 @@
44
#include <linux/fsl/enetc_mdio.h>
55
#include <linux/of_mdio.h>
66
#include <linux/of_net.h>
7-
#include <linux/pcs-lynx.h>
87

98
#include "enetc_pf_common.h"
109

10+
static void enetc_set_si_hw_addr(struct enetc_pf *pf, int si,
11+
const u8 *mac_addr)
12+
{
13+
struct enetc_hw *hw = &pf->si->hw;
14+
15+
pf->ops->set_si_primary_mac(hw, si, mac_addr);
16+
}
17+
18+
static void enetc_get_si_hw_addr(struct enetc_pf *pf, int si, u8 *mac_addr)
19+
{
20+
struct enetc_hw *hw = &pf->si->hw;
21+
22+
pf->ops->get_si_primary_mac(hw, si, mac_addr);
23+
}
24+
1125
int enetc_pf_set_mac_addr(struct net_device *ndev, void *addr)
1226
{
1327
struct enetc_ndev_priv *priv = netdev_priv(ndev);
28+
struct enetc_pf *pf = enetc_si_priv(priv->si);
1429
struct sockaddr *saddr = addr;
1530

1631
if (!is_valid_ether_addr(saddr->sa_data))
1732
return -EADDRNOTAVAIL;
1833

1934
eth_hw_addr_set(ndev, saddr->sa_data);
20-
enetc_pf_set_primary_mac_addr(&priv->si->hw, 0, saddr->sa_data);
35+
enetc_set_si_hw_addr(pf, 0, saddr->sa_data);
2136

2237
return 0;
2338
}
39+
EXPORT_SYMBOL_GPL(enetc_pf_set_mac_addr);
2440

2541
static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf,
2642
int si)
2743
{
2844
struct device *dev = &pf->si->pdev->dev;
29-
struct enetc_hw *hw = &pf->si->hw;
3045
u8 mac_addr[ETH_ALEN] = { 0 };
3146
int err;
3247

@@ -39,7 +54,7 @@ static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf,
3954

4055
/* (2) bootloader supplied MAC address */
4156
if (is_zero_ether_addr(mac_addr))
42-
enetc_pf_get_primary_mac_addr(hw, si, mac_addr);
57+
enetc_get_si_hw_addr(pf, si, mac_addr);
4358

4459
/* (3) choose a random one */
4560
if (is_zero_ether_addr(mac_addr)) {
@@ -48,7 +63,7 @@ static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf,
4863
si, mac_addr);
4964
}
5065

51-
enetc_pf_set_primary_mac_addr(hw, si, mac_addr);
66+
enetc_set_si_hw_addr(pf, si, mac_addr);
5267

5368
return 0;
5469
}
@@ -70,11 +85,13 @@ int enetc_setup_mac_addresses(struct device_node *np, struct enetc_pf *pf)
7085

7186
return 0;
7287
}
88+
EXPORT_SYMBOL_GPL(enetc_setup_mac_addresses);
7389

7490
void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
7591
const struct net_device_ops *ndev_ops)
7692
{
7793
struct enetc_ndev_priv *priv = netdev_priv(ndev);
94+
struct enetc_pf *pf = enetc_si_priv(si);
7895

7996
SET_NETDEV_DEV(ndev, &si->pdev->dev);
8097
priv->ndev = ndev;
@@ -107,7 +124,8 @@ void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
107124
NETDEV_XDP_ACT_NDO_XMIT | NETDEV_XDP_ACT_RX_SG |
108125
NETDEV_XDP_ACT_NDO_XMIT_SG;
109126

110-
if (si->hw_features & ENETC_SI_F_PSFP && !enetc_psfp_enable(priv)) {
127+
if (si->hw_features & ENETC_SI_F_PSFP && pf->ops->enable_psfp &&
128+
!pf->ops->enable_psfp(priv)) {
111129
priv->active_offloads |= ENETC_F_QCI;
112130
ndev->features |= NETIF_F_HW_TC;
113131
ndev->hw_features |= NETIF_F_HW_TC;
@@ -116,6 +134,7 @@ void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
116134
/* pick up primary MAC address from SI */
117135
enetc_load_primary_mac_addr(&si->hw, ndev);
118136
}
137+
EXPORT_SYMBOL_GPL(enetc_pf_netdev_setup);
119138

120139
static int enetc_mdio_probe(struct enetc_pf *pf, struct device_node *np)
121140
{
@@ -162,6 +181,12 @@ static int enetc_imdio_create(struct enetc_pf *pf)
162181
struct mii_bus *bus;
163182
int err;
164183

184+
if (!pf->ops->create_pcs) {
185+
dev_err(dev, "Creating PCS is not supported\n");
186+
187+
return -EOPNOTSUPP;
188+
}
189+
165190
bus = mdiobus_alloc_size(sizeof(*mdio_priv));
166191
if (!bus)
167192
return -ENOMEM;
@@ -184,7 +209,7 @@ static int enetc_imdio_create(struct enetc_pf *pf)
184209
goto free_mdio_bus;
185210
}
186211

187-
phylink_pcs = lynx_pcs_create_mdiodev(bus, 0);
212+
phylink_pcs = pf->ops->create_pcs(pf, bus);
188213
if (IS_ERR(phylink_pcs)) {
189214
err = PTR_ERR(phylink_pcs);
190215
dev_err(dev, "cannot create lynx pcs (%d)\n", err);
@@ -205,8 +230,8 @@ static int enetc_imdio_create(struct enetc_pf *pf)
205230

206231
static void enetc_imdio_remove(struct enetc_pf *pf)
207232
{
208-
if (pf->pcs)
209-
lynx_pcs_destroy(pf->pcs);
233+
if (pf->pcs && pf->ops->destroy_pcs)
234+
pf->ops->destroy_pcs(pf->pcs);
210235

211236
if (pf->imdio) {
212237
mdiobus_unregister(pf->imdio);
@@ -246,12 +271,14 @@ int enetc_mdiobus_create(struct enetc_pf *pf, struct device_node *node)
246271

247272
return 0;
248273
}
274+
EXPORT_SYMBOL_GPL(enetc_mdiobus_create);
249275

250276
void enetc_mdiobus_destroy(struct enetc_pf *pf)
251277
{
252278
enetc_mdio_remove(pf);
253279
enetc_imdio_remove(pf);
254280
}
281+
EXPORT_SYMBOL_GPL(enetc_mdiobus_destroy);
255282

256283
int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node *node,
257284
const struct phylink_mac_ops *ops)
@@ -288,8 +315,13 @@ int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node *node,
288315

289316
return 0;
290317
}
318+
EXPORT_SYMBOL_GPL(enetc_phylink_create);
291319

292320
void enetc_phylink_destroy(struct enetc_ndev_priv *priv)
293321
{
294322
phylink_destroy(priv->phylink);
295323
}
324+
EXPORT_SYMBOL_GPL(enetc_phylink_destroy);
325+
326+
MODULE_DESCRIPTION("NXP ENETC PF common functionality driver");
327+
MODULE_LICENSE("Dual BSD/GPL");

drivers/net/ethernet/freescale/enetc/enetc_pf_common.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
#include "enetc_pf.h"
55

6-
void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr);
7-
void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
8-
const u8 *addr);
96
int enetc_pf_set_mac_addr(struct net_device *ndev, void *addr);
107
int enetc_setup_mac_addresses(struct device_node *np, struct enetc_pf *pf);
118
void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,

0 commit comments

Comments
 (0)