Skip to content

Commit 80c8c85

Browse files
Wei Fangdavem330
authored andcommitted
net: enetc: extract common ENETC PF parts for LS1028A and i.MX95 platforms
The ENETC PF driver of LS1028A (rev 1.0) is incompatible with the version used on the i.MX95 platform (rev 4.1), except for the station interface (SI) part. To reduce code redundancy and prepare for a new driver for rev 4.1 and later, extract shared interfaces from enetc_pf.c and move them to enetc_pf_common.c. This refactoring lays the groundwork for compiling enetc_pf_common.c into a shared driver for both platforms' PF drivers. Signed-off-by: Wei Fang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fe5ba6b commit 80c8c85

File tree

4 files changed

+319
-295
lines changed

4 files changed

+319
-295
lines changed

drivers/net/ethernet/freescale/enetc/Makefile

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

66
obj-$(CONFIG_FSL_ENETC) += fsl-enetc.o
7-
fsl-enetc-y := enetc_pf.o
7+
fsl-enetc-y := enetc_pf.o enetc_pf_common.o
88
fsl-enetc-$(CONFIG_PCI_IOV) += enetc_msg.o
99
fsl-enetc-$(CONFIG_FSL_ENETC_QOS) += enetc_qos.o
1010

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

Lines changed: 6 additions & 294 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22
/* Copyright 2017-2019 NXP */
33

44
#include <linux/unaligned.h>
5-
#include <linux/mdio.h>
65
#include <linux/module.h>
7-
#include <linux/fsl/enetc_mdio.h>
6+
#include <linux/of.h>
87
#include <linux/of_platform.h>
9-
#include <linux/of_mdio.h>
108
#include <linux/of_net.h>
119
#include <linux/pcs-lynx.h>
1210
#include "enetc_ierb.h"
13-
#include "enetc_pf.h"
11+
#include "enetc_pf_common.h"
1412

1513
#define ENETC_DRV_NAME_STR "ENETC PF driver"
1614

17-
static void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)
15+
void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)
1816
{
1917
u32 upper = __raw_readl(hw->port + ENETC_PSIPMAR0(si));
2018
u16 lower = __raw_readw(hw->port + ENETC_PSIPMAR1(si));
@@ -23,8 +21,8 @@ static void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)
2321
put_unaligned_le16(lower, addr + 4);
2422
}
2523

26-
static void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
27-
const u8 *addr)
24+
void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
25+
const u8 *addr)
2826
{
2927
u32 upper = get_unaligned_le32(addr);
3028
u16 lower = get_unaligned_le16(addr + 4);
@@ -33,20 +31,6 @@ static void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
3331
__raw_writew(lower, hw->port + ENETC_PSIPMAR1(si));
3432
}
3533

36-
static int enetc_pf_set_mac_addr(struct net_device *ndev, void *addr)
37-
{
38-
struct enetc_ndev_priv *priv = netdev_priv(ndev);
39-
struct sockaddr *saddr = addr;
40-
41-
if (!is_valid_ether_addr(saddr->sa_data))
42-
return -EADDRNOTAVAIL;
43-
44-
eth_hw_addr_set(ndev, saddr->sa_data);
45-
enetc_pf_set_primary_mac_addr(&priv->si->hw, 0, saddr->sa_data);
46-
47-
return 0;
48-
}
49-
5034
static void enetc_set_vlan_promisc(struct enetc_hw *hw, char si_map)
5135
{
5236
u32 val = enetc_port_rd(hw, ENETC_PSIPVMR);
@@ -393,56 +377,6 @@ static int enetc_pf_set_vf_spoofchk(struct net_device *ndev, int vf, bool en)
393377
return 0;
394378
}
395379

396-
static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf,
397-
int si)
398-
{
399-
struct device *dev = &pf->si->pdev->dev;
400-
struct enetc_hw *hw = &pf->si->hw;
401-
u8 mac_addr[ETH_ALEN] = { 0 };
402-
int err;
403-
404-
/* (1) try to get the MAC address from the device tree */
405-
if (np) {
406-
err = of_get_mac_address(np, mac_addr);
407-
if (err == -EPROBE_DEFER)
408-
return err;
409-
}
410-
411-
/* (2) bootloader supplied MAC address */
412-
if (is_zero_ether_addr(mac_addr))
413-
enetc_pf_get_primary_mac_addr(hw, si, mac_addr);
414-
415-
/* (3) choose a random one */
416-
if (is_zero_ether_addr(mac_addr)) {
417-
eth_random_addr(mac_addr);
418-
dev_info(dev, "no MAC address specified for SI%d, using %pM\n",
419-
si, mac_addr);
420-
}
421-
422-
enetc_pf_set_primary_mac_addr(hw, si, mac_addr);
423-
424-
return 0;
425-
}
426-
427-
static int enetc_setup_mac_addresses(struct device_node *np,
428-
struct enetc_pf *pf)
429-
{
430-
int err, i;
431-
432-
/* The PF might take its MAC from the device tree */
433-
err = enetc_setup_mac_address(np, pf, 0);
434-
if (err)
435-
return err;
436-
437-
for (i = 0; i < pf->total_vfs; i++) {
438-
err = enetc_setup_mac_address(NULL, pf, i + 1);
439-
if (err)
440-
return err;
441-
}
442-
443-
return 0;
444-
}
445-
446380
static void enetc_port_assign_rfs_entries(struct enetc_si *si)
447381
{
448382
struct enetc_pf *pf = enetc_si_priv(si);
@@ -775,187 +709,6 @@ static const struct net_device_ops enetc_ndev_ops = {
775709
.ndo_xdp_xmit = enetc_xdp_xmit,
776710
};
777711

778-
static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
779-
const struct net_device_ops *ndev_ops)
780-
{
781-
struct enetc_ndev_priv *priv = netdev_priv(ndev);
782-
783-
SET_NETDEV_DEV(ndev, &si->pdev->dev);
784-
priv->ndev = ndev;
785-
priv->si = si;
786-
priv->dev = &si->pdev->dev;
787-
si->ndev = ndev;
788-
789-
priv->msg_enable = (NETIF_MSG_WOL << 1) - 1;
790-
ndev->netdev_ops = ndev_ops;
791-
enetc_set_ethtool_ops(ndev);
792-
ndev->watchdog_timeo = 5 * HZ;
793-
ndev->max_mtu = ENETC_MAX_MTU;
794-
795-
ndev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM |
796-
NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
797-
NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_LOOPBACK |
798-
NETIF_F_HW_CSUM | NETIF_F_TSO | NETIF_F_TSO6;
799-
ndev->features = NETIF_F_HIGHDMA | NETIF_F_SG | NETIF_F_RXCSUM |
800-
NETIF_F_HW_VLAN_CTAG_TX |
801-
NETIF_F_HW_VLAN_CTAG_RX |
802-
NETIF_F_HW_CSUM | NETIF_F_TSO | NETIF_F_TSO6;
803-
ndev->vlan_features = NETIF_F_SG | NETIF_F_HW_CSUM |
804-
NETIF_F_TSO | NETIF_F_TSO6;
805-
806-
if (si->num_rss)
807-
ndev->hw_features |= NETIF_F_RXHASH;
808-
809-
ndev->priv_flags |= IFF_UNICAST_FLT;
810-
ndev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT |
811-
NETDEV_XDP_ACT_NDO_XMIT | NETDEV_XDP_ACT_RX_SG |
812-
NETDEV_XDP_ACT_NDO_XMIT_SG;
813-
814-
if (si->hw_features & ENETC_SI_F_PSFP && !enetc_psfp_enable(priv)) {
815-
priv->active_offloads |= ENETC_F_QCI;
816-
ndev->features |= NETIF_F_HW_TC;
817-
ndev->hw_features |= NETIF_F_HW_TC;
818-
}
819-
820-
/* pick up primary MAC address from SI */
821-
enetc_load_primary_mac_addr(&si->hw, ndev);
822-
}
823-
824-
static int enetc_mdio_probe(struct enetc_pf *pf, struct device_node *np)
825-
{
826-
struct device *dev = &pf->si->pdev->dev;
827-
struct enetc_mdio_priv *mdio_priv;
828-
struct mii_bus *bus;
829-
int err;
830-
831-
bus = devm_mdiobus_alloc_size(dev, sizeof(*mdio_priv));
832-
if (!bus)
833-
return -ENOMEM;
834-
835-
bus->name = "Freescale ENETC MDIO Bus";
836-
bus->read = enetc_mdio_read_c22;
837-
bus->write = enetc_mdio_write_c22;
838-
bus->read_c45 = enetc_mdio_read_c45;
839-
bus->write_c45 = enetc_mdio_write_c45;
840-
bus->parent = dev;
841-
mdio_priv = bus->priv;
842-
mdio_priv->hw = &pf->si->hw;
843-
mdio_priv->mdio_base = ENETC_EMDIO_BASE;
844-
snprintf(bus->id, MII_BUS_ID_SIZE, "%s", dev_name(dev));
845-
846-
err = of_mdiobus_register(bus, np);
847-
if (err)
848-
return dev_err_probe(dev, err, "cannot register MDIO bus\n");
849-
850-
pf->mdio = bus;
851-
852-
return 0;
853-
}
854-
855-
static void enetc_mdio_remove(struct enetc_pf *pf)
856-
{
857-
if (pf->mdio)
858-
mdiobus_unregister(pf->mdio);
859-
}
860-
861-
static int enetc_imdio_create(struct enetc_pf *pf)
862-
{
863-
struct device *dev = &pf->si->pdev->dev;
864-
struct enetc_mdio_priv *mdio_priv;
865-
struct phylink_pcs *phylink_pcs;
866-
struct mii_bus *bus;
867-
int err;
868-
869-
bus = mdiobus_alloc_size(sizeof(*mdio_priv));
870-
if (!bus)
871-
return -ENOMEM;
872-
873-
bus->name = "Freescale ENETC internal MDIO Bus";
874-
bus->read = enetc_mdio_read_c22;
875-
bus->write = enetc_mdio_write_c22;
876-
bus->read_c45 = enetc_mdio_read_c45;
877-
bus->write_c45 = enetc_mdio_write_c45;
878-
bus->parent = dev;
879-
bus->phy_mask = ~0;
880-
mdio_priv = bus->priv;
881-
mdio_priv->hw = &pf->si->hw;
882-
mdio_priv->mdio_base = ENETC_PM_IMDIO_BASE;
883-
snprintf(bus->id, MII_BUS_ID_SIZE, "%s-imdio", dev_name(dev));
884-
885-
err = mdiobus_register(bus);
886-
if (err) {
887-
dev_err(dev, "cannot register internal MDIO bus (%d)\n", err);
888-
goto free_mdio_bus;
889-
}
890-
891-
phylink_pcs = lynx_pcs_create_mdiodev(bus, 0);
892-
if (IS_ERR(phylink_pcs)) {
893-
err = PTR_ERR(phylink_pcs);
894-
dev_err(dev, "cannot create lynx pcs (%d)\n", err);
895-
goto unregister_mdiobus;
896-
}
897-
898-
pf->imdio = bus;
899-
pf->pcs = phylink_pcs;
900-
901-
return 0;
902-
903-
unregister_mdiobus:
904-
mdiobus_unregister(bus);
905-
free_mdio_bus:
906-
mdiobus_free(bus);
907-
return err;
908-
}
909-
910-
static void enetc_imdio_remove(struct enetc_pf *pf)
911-
{
912-
if (pf->pcs)
913-
lynx_pcs_destroy(pf->pcs);
914-
if (pf->imdio) {
915-
mdiobus_unregister(pf->imdio);
916-
mdiobus_free(pf->imdio);
917-
}
918-
}
919-
920-
static bool enetc_port_has_pcs(struct enetc_pf *pf)
921-
{
922-
return (pf->if_mode == PHY_INTERFACE_MODE_SGMII ||
923-
pf->if_mode == PHY_INTERFACE_MODE_1000BASEX ||
924-
pf->if_mode == PHY_INTERFACE_MODE_2500BASEX ||
925-
pf->if_mode == PHY_INTERFACE_MODE_USXGMII);
926-
}
927-
928-
static int enetc_mdiobus_create(struct enetc_pf *pf, struct device_node *node)
929-
{
930-
struct device_node *mdio_np;
931-
int err;
932-
933-
mdio_np = of_get_child_by_name(node, "mdio");
934-
if (mdio_np) {
935-
err = enetc_mdio_probe(pf, mdio_np);
936-
937-
of_node_put(mdio_np);
938-
if (err)
939-
return err;
940-
}
941-
942-
if (enetc_port_has_pcs(pf)) {
943-
err = enetc_imdio_create(pf);
944-
if (err) {
945-
enetc_mdio_remove(pf);
946-
return err;
947-
}
948-
}
949-
950-
return 0;
951-
}
952-
953-
static void enetc_mdiobus_destroy(struct enetc_pf *pf)
954-
{
955-
enetc_mdio_remove(pf);
956-
enetc_imdio_remove(pf);
957-
}
958-
959712
static struct phylink_pcs *
960713
enetc_pl_mac_select_pcs(struct phylink_config *config, phy_interface_t iface)
961714
{
@@ -1101,47 +854,6 @@ static const struct phylink_mac_ops enetc_mac_phylink_ops = {
1101854
.mac_link_down = enetc_pl_mac_link_down,
1102855
};
1103856

1104-
static int enetc_phylink_create(struct enetc_ndev_priv *priv,
1105-
struct device_node *node)
1106-
{
1107-
struct enetc_pf *pf = enetc_si_priv(priv->si);
1108-
struct phylink *phylink;
1109-
int err;
1110-
1111-
pf->phylink_config.dev = &priv->ndev->dev;
1112-
pf->phylink_config.type = PHYLINK_NETDEV;
1113-
pf->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
1114-
MAC_10 | MAC_100 | MAC_1000 | MAC_2500FD;
1115-
1116-
__set_bit(PHY_INTERFACE_MODE_INTERNAL,
1117-
pf->phylink_config.supported_interfaces);
1118-
__set_bit(PHY_INTERFACE_MODE_SGMII,
1119-
pf->phylink_config.supported_interfaces);
1120-
__set_bit(PHY_INTERFACE_MODE_1000BASEX,
1121-
pf->phylink_config.supported_interfaces);
1122-
__set_bit(PHY_INTERFACE_MODE_2500BASEX,
1123-
pf->phylink_config.supported_interfaces);
1124-
__set_bit(PHY_INTERFACE_MODE_USXGMII,
1125-
pf->phylink_config.supported_interfaces);
1126-
phy_interface_set_rgmii(pf->phylink_config.supported_interfaces);
1127-
1128-
phylink = phylink_create(&pf->phylink_config, of_fwnode_handle(node),
1129-
pf->if_mode, &enetc_mac_phylink_ops);
1130-
if (IS_ERR(phylink)) {
1131-
err = PTR_ERR(phylink);
1132-
return err;
1133-
}
1134-
1135-
priv->phylink = phylink;
1136-
1137-
return 0;
1138-
}
1139-
1140-
static void enetc_phylink_destroy(struct enetc_ndev_priv *priv)
1141-
{
1142-
phylink_destroy(priv->phylink);
1143-
}
1144-
1145857
/* Initialize the entire shared memory for the flow steering entries
1146858
* of this port (PF + VFs)
1147859
*/
@@ -1338,7 +1050,7 @@ static int enetc_pf_probe(struct pci_dev *pdev,
13381050
if (err)
13391051
goto err_mdiobus_create;
13401052

1341-
err = enetc_phylink_create(priv, node);
1053+
err = enetc_phylink_create(priv, node, &enetc_mac_phylink_ops);
13421054
if (err)
13431055
goto err_phylink_create;
13441056

0 commit comments

Comments
 (0)