Skip to content

Commit f91e32d

Browse files
committed
Merge branch 'regmap-TSE-PCS'
Maxime Chevallier says: ==================== net: add a regmap-based mdio driver and drop TSE PCS This is the V4 of a series that follows-up on the work [1] aiming to drop the altera TSE PCS driver, as it turns out to be a version of the Lynx PCS exposed as a memory-mapped block, instead of living on an MDIO bus. One step of this removal involved creating a regmap-based mdio driver that translates MDIO accesses into the actual underlying bus that exposes the register. The register layout must of course match the standard MDIO layout, but we can now account for differences in stride with recent work on the regmap subsystem [2]. Sorry for repeating this, but I didn't hear anything on this matter in previous iterations, Mark, Net maintainers, this series depends on the patch e12ff28 that was recently merged into the regmap tree [3]. For this series to be usable in net-next, this patch must be applied beforehand. Should Mark create a tag that would then be merged into net-next ? Or should we just wait for the next release to merge this into net-next ? This series introduces a new MDIO driver, and uses it to convert Altera TSE from the actual TSE PCS driver to Lynx PCS. Since it turns out dwmac_socfpga also uses a TSE PCS block, port that driver to Lynx as well. Changes in V4 : - Use new pcs_lynx_create/destroy helpers added by Russell - Rework the cleanup sequence to avoid leaking data - Rework a bit KConfig to properly select dependencies - Fix a few hiccups with misplaced hunks in 2 commits Changes in V3 : - Use a dedicated struct for the mii bus's priv data, to avoid duplicating the whole struct mdio_regmap_config, from which 2 fields only are necessary after init, as suggested by Russell - Use ~0 instead of ~0UL for the no-scan bitmask, following Simon's review. Changes in V2 : - Use phy_mask to avoid unnecessarily scanning the whole mdio bus - Go one step further and completely disable scanning if users set the .autoscan flag to false, in case the mdiodevice isn't an actual PHY (a PCS for example). ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents f69de8a + 5d1f3fe commit f91e32d

19 files changed

Lines changed: 271 additions & 516 deletions

MAINTAINERS

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -909,13 +909,6 @@ L: netdev@vger.kernel.org
909909
S: Maintained
910910
F: drivers/net/ethernet/altera/
911911

912-
ALTERA TSE PCS
913-
M: Maxime Chevallier <maxime.chevallier@bootlin.com>
914-
L: netdev@vger.kernel.org
915-
S: Supported
916-
F: drivers/net/pcs/pcs-altera-tse.c
917-
F: include/linux/pcs-altera-tse.h
918-
919912
ALTERA UART/JTAG UART SERIAL DRIVERS
920913
M: Tobias Klauser <tklauser@distanz.ch>
921914
L: linux-serial@vger.kernel.org
@@ -12844,6 +12837,13 @@ F: Documentation/devicetree/bindings/net/ieee802154/mcr20a.txt
1284412837
F: drivers/net/ieee802154/mcr20a.c
1284512838
F: drivers/net/ieee802154/mcr20a.h
1284612839

12840+
MDIO REGMAP DRIVER
12841+
M: Maxime Chevallier <maxime.chevallier@bootlin.com>
12842+
L: netdev@vger.kernel.org
12843+
S: Maintained
12844+
F: drivers/net/mdio/mdio-regmap.c
12845+
F: include/linux/mdio/mdio-regmap.h
12846+
1284712847
MEASUREMENT COMPUTING CIO-DAC IIO DRIVER
1284812848
M: William Breathitt Gray <william.gray@linaro.org>
1284912849
L: linux-iio@vger.kernel.org

drivers/net/ethernet/altera/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ config ALTERA_TSE
55
select PHYLIB
66
select PHYLINK
77
select PCS_ALTERA_TSE
8+
select MDIO_REGMAP
9+
select REGMAP_MMIO
810
help
911
This driver supports the Altera Triple-Speed (TSE) Ethernet MAC.
1012

drivers/net/ethernet/altera/altera_tse_main.c

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@
2727
#include <linux/kernel.h>
2828
#include <linux/module.h>
2929
#include <linux/mii.h>
30+
#include <linux/mdio/mdio-regmap.h>
3031
#include <linux/netdevice.h>
3132
#include <linux/of_device.h>
3233
#include <linux/of_mdio.h>
3334
#include <linux/of_net.h>
3435
#include <linux/of_platform.h>
35-
#include <linux/pcs-altera-tse.h>
36+
#include <linux/pcs-lynx.h>
3637
#include <linux/phy.h>
3738
#include <linux/platform_device.h>
39+
#include <linux/regmap.h>
3840
#include <linux/skbuff.h>
3941
#include <asm/cacheflush.h>
4042

@@ -1132,13 +1134,16 @@ static int request_and_map(struct platform_device *pdev, const char *name,
11321134
static int altera_tse_probe(struct platform_device *pdev)
11331135
{
11341136
const struct of_device_id *of_id = NULL;
1137+
struct regmap_config pcs_regmap_cfg;
11351138
struct altera_tse_private *priv;
1139+
struct mdio_regmap_config mrc;
11361140
struct resource *control_port;
1141+
struct regmap *pcs_regmap;
11371142
struct resource *dma_res;
11381143
struct resource *pcs_res;
1144+
struct mii_bus *pcs_bus;
11391145
struct net_device *ndev;
11401146
void __iomem *descmap;
1141-
int pcs_reg_width = 2;
11421147
int ret = -ENODEV;
11431148

11441149
ndev = alloc_etherdev(sizeof(struct altera_tse_private));
@@ -1255,12 +1260,32 @@ static int altera_tse_probe(struct platform_device *pdev)
12551260
* address space, but if it's not the case, we fallback to the mdiophy0
12561261
* from the MAC's address space
12571262
*/
1258-
ret = request_and_map(pdev, "pcs", &pcs_res,
1259-
&priv->pcs_base);
1263+
ret = request_and_map(pdev, "pcs", &pcs_res, &priv->pcs_base);
12601264
if (ret) {
1265+
/* If we can't find a dedicated resource for the PCS, fallback
1266+
* to the internal PCS, that has a different address stride
1267+
*/
12611268
priv->pcs_base = priv->mac_dev + tse_csroffs(mdio_phy0);
1262-
pcs_reg_width = 4;
1269+
pcs_regmap_cfg.reg_bits = 32;
1270+
/* Values are MDIO-like values, on 16 bits */
1271+
pcs_regmap_cfg.val_bits = 16;
1272+
pcs_regmap_cfg.reg_shift = REGMAP_UPSHIFT(2);
1273+
} else {
1274+
pcs_regmap_cfg.reg_bits = 16;
1275+
pcs_regmap_cfg.val_bits = 16;
1276+
pcs_regmap_cfg.reg_shift = REGMAP_UPSHIFT(1);
1277+
}
1278+
1279+
/* Create a regmap for the PCS so that it can be used by the PCS driver */
1280+
pcs_regmap = devm_regmap_init_mmio(&pdev->dev, priv->pcs_base,
1281+
&pcs_regmap_cfg);
1282+
if (IS_ERR(pcs_regmap)) {
1283+
ret = PTR_ERR(pcs_regmap);
1284+
goto err_free_netdev;
12631285
}
1286+
mrc.regmap = pcs_regmap;
1287+
mrc.parent = &pdev->dev;
1288+
mrc.valid_addr = 0x0;
12641289

12651290
/* Rx IRQ */
12661291
priv->rx_irq = platform_get_irq_byname(pdev, "rx_irq");
@@ -1384,7 +1409,18 @@ static int altera_tse_probe(struct platform_device *pdev)
13841409
(unsigned long) control_port->start, priv->rx_irq,
13851410
priv->tx_irq);
13861411

1387-
priv->pcs = alt_tse_pcs_create(ndev, priv->pcs_base, pcs_reg_width);
1412+
snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii", ndev->name);
1413+
pcs_bus = devm_mdio_regmap_register(&pdev->dev, &mrc);
1414+
if (IS_ERR(pcs_bus)) {
1415+
ret = PTR_ERR(pcs_bus);
1416+
goto err_init_pcs;
1417+
}
1418+
1419+
priv->pcs = lynx_pcs_create_mdiodev(pcs_bus, 0);
1420+
if (IS_ERR(priv->pcs)) {
1421+
ret = PTR_ERR(priv->pcs);
1422+
goto err_init_pcs;
1423+
}
13881424

13891425
priv->phylink_config.dev = &ndev->dev;
13901426
priv->phylink_config.type = PHYLINK_NETDEV;
@@ -1407,12 +1443,13 @@ static int altera_tse_probe(struct platform_device *pdev)
14071443
if (IS_ERR(priv->phylink)) {
14081444
dev_err(&pdev->dev, "failed to create phylink\n");
14091445
ret = PTR_ERR(priv->phylink);
1410-
goto err_init_phy;
1446+
goto err_init_phylink;
14111447
}
14121448

14131449
return 0;
1414-
1415-
err_init_phy:
1450+
err_init_phylink:
1451+
lynx_pcs_destroy(priv->pcs);
1452+
err_init_pcs:
14161453
unregister_netdev(ndev);
14171454
err_register_netdev:
14181455
netif_napi_del(&priv->napi);
@@ -1433,6 +1470,8 @@ static int altera_tse_remove(struct platform_device *pdev)
14331470
altera_tse_mdio_destroy(ndev);
14341471
unregister_netdev(ndev);
14351472
phylink_destroy(priv->phylink);
1473+
lynx_pcs_destroy(priv->pcs);
1474+
14361475
free_netdev(ndev);
14371476

14381477
return 0;

drivers/net/ethernet/stmicro/stmmac/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ config DWMAC_SOCFPGA
158158
default ARCH_INTEL_SOCFPGA
159159
depends on OF && (ARCH_INTEL_SOCFPGA || COMPILE_TEST)
160160
select MFD_SYSCON
161+
select MDIO_REGMAP
162+
select REGMAP_MMIO
163+
select PCS_LYNX
161164
help
162165
Support for ethernet controller on Altera SOCFPGA
163166

drivers/net/ethernet/stmicro/stmmac/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ obj-$(CONFIG_DWMAC_IMX8) += dwmac-imx.o
3535
obj-$(CONFIG_DWMAC_TEGRA) += dwmac-tegra.o
3636
obj-$(CONFIG_DWMAC_VISCONTI) += dwmac-visconti.o
3737
stmmac-platform-objs:= stmmac_platform.o
38-
dwmac-altr-socfpga-objs := altr_tse_pcs.o dwmac-socfpga.o
38+
dwmac-altr-socfpga-objs := dwmac-socfpga.o
3939

4040
obj-$(CONFIG_STMMAC_PCI) += stmmac-pci.o
4141
obj-$(CONFIG_DWMAC_INTEL) += dwmac-intel.o

0 commit comments

Comments
 (0)