Commit a75edc7c authored by Marcin Wojtas's avatar Marcin Wojtas Committed by David S. Miller

net: mvpp2: enable ACPI support in the driver

This patch introduces an alternative way of obtaining resources - via
ACPI tables provided by firmware. Enabling coexistence with the DT
support, in addition to the OF_*->device_*/fwnode_* API replacement,
required following steps to be taken:

* Add mvpp2_acpi_match table
* Omit clock configuration and obtain tclk from the property - in ACPI
  world, the firmware is responsible for clock maintenance.
* Disable comphy and syscon handling as they are not available for ACPI.
* Modify way of obtaining interrupts - use newly introduced
  fwnode_irq_get() routine
* Until proper MDIO bus and PHY handling with ACPI is established in the
  kernel, use only link interrupts feature in the driver. For the RGMII
  port it results in depending on GMAC settings done during firmware
  stage.
* When booting with ACPI MVPP2_QDIST_MULTI_MODE is picked by
  default, as there is no need to keep any kind of the backward
  compatibility.

Moreover, a memory region used by mvmdio driver is usually placed in
the middle of the address space of the PP2 network controller.
The MDIO base address is obtained without requesting memory region
(by devm_ioremap() call) in mvmdio.c, later overlapping resources are
requested by the network driver, which is responsible for avoiding
a concurrent access.

In case the MDIO memory region is declared in the ACPI, it can
already appear as 'in-use' in the OS. Because it is overlapped by second
region of the network controller, make sure it is released, before
requesting it again. The care is taken by mvpp2 driver to avoid
concurrent access to this memory region.
Signed-off-by: default avatarMarcin Wojtas <mw@semihalf.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 24812221
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
* warranty of any kind, whether express or implied. * warranty of any kind, whether express or implied.
*/ */
#include <linux/acpi.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
...@@ -7502,7 +7503,10 @@ static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port, ...@@ -7502,7 +7503,10 @@ static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port,
strncpy(irqname, "rx-shared", sizeof(irqname)); strncpy(irqname, "rx-shared", sizeof(irqname));
} }
if (port_node)
v->irq = of_irq_get_byname(port_node, irqname); v->irq = of_irq_get_byname(port_node, irqname);
else
v->irq = fwnode_irq_get(port->fwnode, i);
if (v->irq <= 0) { if (v->irq <= 0) {
ret = -EINVAL; ret = -EINVAL;
goto err; goto err;
...@@ -7746,7 +7750,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, ...@@ -7746,7 +7750,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
struct mvpp2 *priv) struct mvpp2 *priv)
{ {
struct device_node *phy_node; struct device_node *phy_node;
struct phy *comphy; struct phy *comphy = NULL;
struct mvpp2_port *port; struct mvpp2_port *port;
struct mvpp2_port_pcpu *port_pcpu; struct mvpp2_port_pcpu *port_pcpu;
struct device_node *port_node = to_of_node(port_fwnode); struct device_node *port_node = to_of_node(port_fwnode);
...@@ -7760,7 +7764,12 @@ static int mvpp2_port_probe(struct platform_device *pdev, ...@@ -7760,7 +7764,12 @@ static int mvpp2_port_probe(struct platform_device *pdev,
int phy_mode; int phy_mode;
int err, i, cpu; int err, i, cpu;
if (port_node) {
has_tx_irqs = mvpp2_port_has_tx_irqs(priv, port_node); has_tx_irqs = mvpp2_port_has_tx_irqs(priv, port_node);
} else {
has_tx_irqs = true;
queue_mode = MVPP2_QDIST_MULTI_MODE;
}
if (!has_tx_irqs) if (!has_tx_irqs)
queue_mode = MVPP2_QDIST_SINGLE_MODE; queue_mode = MVPP2_QDIST_SINGLE_MODE;
...@@ -7775,7 +7784,11 @@ static int mvpp2_port_probe(struct platform_device *pdev, ...@@ -7775,7 +7784,11 @@ static int mvpp2_port_probe(struct platform_device *pdev,
if (!dev) if (!dev)
return -ENOMEM; return -ENOMEM;
if (port_node)
phy_node = of_parse_phandle(port_node, "phy", 0); phy_node = of_parse_phandle(port_node, "phy", 0);
else
phy_node = NULL;
phy_mode = fwnode_get_phy_mode(port_fwnode); phy_mode = fwnode_get_phy_mode(port_fwnode);
if (phy_mode < 0) { if (phy_mode < 0) {
dev_err(&pdev->dev, "incorrect phy mode\n"); dev_err(&pdev->dev, "incorrect phy mode\n");
...@@ -7783,6 +7796,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, ...@@ -7783,6 +7796,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
goto err_free_netdev; goto err_free_netdev;
} }
if (port_node) {
comphy = devm_of_phy_get(&pdev->dev, port_node, NULL); comphy = devm_of_phy_get(&pdev->dev, port_node, NULL);
if (IS_ERR(comphy)) { if (IS_ERR(comphy)) {
if (PTR_ERR(comphy) == -EPROBE_DEFER) { if (PTR_ERR(comphy) == -EPROBE_DEFER) {
...@@ -7791,6 +7805,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, ...@@ -7791,6 +7805,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
} }
comphy = NULL; comphy = NULL;
} }
}
if (fwnode_property_read_u32(port_fwnode, "port-id", &id)) { if (fwnode_property_read_u32(port_fwnode, "port-id", &id)) {
err = -EINVAL; err = -EINVAL;
...@@ -7805,6 +7820,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, ...@@ -7805,6 +7820,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
port = netdev_priv(dev); port = netdev_priv(dev);
port->dev = dev; port->dev = dev;
port->fwnode = port_fwnode;
port->ntxqs = ntxqs; port->ntxqs = ntxqs;
port->nrxqs = nrxqs; port->nrxqs = nrxqs;
port->priv = priv; port->priv = priv;
...@@ -7814,7 +7830,10 @@ static int mvpp2_port_probe(struct platform_device *pdev, ...@@ -7814,7 +7830,10 @@ static int mvpp2_port_probe(struct platform_device *pdev,
if (err) if (err)
goto err_free_netdev; goto err_free_netdev;
if (port_node)
port->link_irq = of_irq_get_byname(port_node, "link"); port->link_irq = of_irq_get_byname(port_node, "link");
else
port->link_irq = fwnode_irq_get(port_fwnode, port->nqvecs + 1);
if (port->link_irq == -EPROBE_DEFER) { if (port->link_irq == -EPROBE_DEFER) {
err = -EPROBE_DEFER; err = -EPROBE_DEFER;
goto err_deinit_qvecs; goto err_deinit_qvecs;
...@@ -8197,6 +8216,7 @@ static int mvpp2_init(struct platform_device *pdev, struct mvpp2 *priv) ...@@ -8197,6 +8216,7 @@ static int mvpp2_init(struct platform_device *pdev, struct mvpp2 *priv)
static int mvpp2_probe(struct platform_device *pdev) static int mvpp2_probe(struct platform_device *pdev)
{ {
const struct acpi_device_id *acpi_id;
struct fwnode_handle *fwnode = pdev->dev.fwnode; struct fwnode_handle *fwnode = pdev->dev.fwnode;
struct fwnode_handle *port_fwnode; struct fwnode_handle *port_fwnode;
struct mvpp2 *priv; struct mvpp2 *priv;
...@@ -8209,8 +8229,14 @@ static int mvpp2_probe(struct platform_device *pdev) ...@@ -8209,8 +8229,14 @@ static int mvpp2_probe(struct platform_device *pdev)
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
if (has_acpi_companion(&pdev->dev)) {
acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table,
&pdev->dev);
priv->hw_version = (unsigned long)acpi_id->driver_data;
} else {
priv->hw_version = priv->hw_version =
(unsigned long)of_device_get_match_data(&pdev->dev); (unsigned long)of_device_get_match_data(&pdev->dev);
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
base = devm_ioremap_resource(&pdev->dev, res); base = devm_ioremap_resource(&pdev->dev, res);
...@@ -8224,10 +8250,23 @@ static int mvpp2_probe(struct platform_device *pdev) ...@@ -8224,10 +8250,23 @@ static int mvpp2_probe(struct platform_device *pdev)
return PTR_ERR(priv->lms_base); return PTR_ERR(priv->lms_base);
} else { } else {
res = platform_get_resource(pdev, IORESOURCE_MEM, 1); res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
if (has_acpi_companion(&pdev->dev)) {
/* In case the MDIO memory region is declared in
* the ACPI, it can already appear as 'in-use'
* in the OS. Because it is overlapped by second
* region of the network controller, make
* sure it is released, before requesting it again.
* The care is taken by mvpp2 driver to avoid
* concurrent access to this memory region.
*/
release_resource(res);
}
priv->iface_base = devm_ioremap_resource(&pdev->dev, res); priv->iface_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(priv->iface_base)) if (IS_ERR(priv->iface_base))
return PTR_ERR(priv->iface_base); return PTR_ERR(priv->iface_base);
}
if (priv->hw_version == MVPP22 && dev_of_node(&pdev->dev)) {
priv->sysctrl_base = priv->sysctrl_base =
syscon_regmap_lookup_by_phandle(pdev->dev.of_node, syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
"marvell,system-controller"); "marvell,system-controller");
...@@ -8253,6 +8292,7 @@ static int mvpp2_probe(struct platform_device *pdev) ...@@ -8253,6 +8292,7 @@ static int mvpp2_probe(struct platform_device *pdev)
else else
priv->max_port_rxqs = 32; priv->max_port_rxqs = 32;
if (dev_of_node(&pdev->dev)) {
priv->pp_clk = devm_clk_get(&pdev->dev, "pp_clk"); priv->pp_clk = devm_clk_get(&pdev->dev, "pp_clk");
if (IS_ERR(priv->pp_clk)) if (IS_ERR(priv->pp_clk))
return PTR_ERR(priv->pp_clk); return PTR_ERR(priv->pp_clk);
...@@ -8279,6 +8319,7 @@ static int mvpp2_probe(struct platform_device *pdev) ...@@ -8279,6 +8319,7 @@ static int mvpp2_probe(struct platform_device *pdev)
err = clk_prepare_enable(priv->mg_clk); err = clk_prepare_enable(priv->mg_clk);
if (err < 0) if (err < 0)
goto err_gop_clk; goto err_gop_clk;
}
priv->axi_clk = devm_clk_get(&pdev->dev, "axi_clk"); priv->axi_clk = devm_clk_get(&pdev->dev, "axi_clk");
if (IS_ERR(priv->axi_clk)) { if (IS_ERR(priv->axi_clk)) {
...@@ -8291,10 +8332,14 @@ static int mvpp2_probe(struct platform_device *pdev) ...@@ -8291,10 +8332,14 @@ static int mvpp2_probe(struct platform_device *pdev)
if (err < 0) if (err < 0)
goto err_gop_clk; goto err_gop_clk;
} }
}
/* Get system's tclk rate */ /* Get system's tclk rate */
priv->tclk = clk_get_rate(priv->pp_clk); priv->tclk = clk_get_rate(priv->pp_clk);
} else if (device_property_read_u32(&pdev->dev, "clock-frequency",
&priv->tclk)) {
dev_err(&pdev->dev, "missing clock-frequency value\n");
return -EINVAL;
}
if (priv->hw_version == MVPP22) { if (priv->hw_version == MVPP22) {
err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(40)); err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(40));
...@@ -8399,6 +8444,9 @@ static int mvpp2_remove(struct platform_device *pdev) ...@@ -8399,6 +8444,9 @@ static int mvpp2_remove(struct platform_device *pdev)
aggr_txq->descs_dma); aggr_txq->descs_dma);
} }
if (is_acpi_node(port_fwnode))
return 0;
clk_disable_unprepare(priv->axi_clk); clk_disable_unprepare(priv->axi_clk);
clk_disable_unprepare(priv->mg_clk); clk_disable_unprepare(priv->mg_clk);
clk_disable_unprepare(priv->pp_clk); clk_disable_unprepare(priv->pp_clk);
...@@ -8420,12 +8468,19 @@ static const struct of_device_id mvpp2_match[] = { ...@@ -8420,12 +8468,19 @@ static const struct of_device_id mvpp2_match[] = {
}; };
MODULE_DEVICE_TABLE(of, mvpp2_match); MODULE_DEVICE_TABLE(of, mvpp2_match);
static const struct acpi_device_id mvpp2_acpi_match[] = {
{ "MRVL0110", MVPP22 },
{ },
};
MODULE_DEVICE_TABLE(acpi, mvpp2_acpi_match);
static struct platform_driver mvpp2_driver = { static struct platform_driver mvpp2_driver = {
.probe = mvpp2_probe, .probe = mvpp2_probe,
.remove = mvpp2_remove, .remove = mvpp2_remove,
.driver = { .driver = {
.name = MVPP2_DRIVER_NAME, .name = MVPP2_DRIVER_NAME,
.of_match_table = mvpp2_match, .of_match_table = mvpp2_match,
.acpi_match_table = ACPI_PTR(mvpp2_acpi_match),
}, },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment