Re: [PATCH net-next v13 06/15] net: stmmac: dwmac-loongson: Detach GMAC-specific platform data init
From: Serge Semin <hidden>
Date: 2024-07-02 14:09:26
On Tue, Jul 02, 2024 at 09:14:07PM +0800, Yanteng Si wrote:
在 2024/7/2 16:28, Serge Semin 写道:quoted
On Wed, May 29, 2024 at 06:19:03PM +0800, Yanteng Si wrote:quoted
Loongson delivers two types of the network devices: Loongson GMAC and Loongson GNET in the framework of four CPU/Chipsets revisions: Chip Network PCI Dev ID Synopys Version DMA-channel LS2K1000 CPU GMAC 0x7a03 v3.50a/v3.73a 1 LS7A1000 Chipset GMAC 0x7a03 v3.50a/v3.73a 1 LS2K2000 CPU GNET 0x7a13 v3.73a 8 LS7A2000 Chipset GNET 0x7a13 v3.73a 1 The driver currently supports the chips with the Loongson GMAC network device. As a preparation before adding the Loongson GNET support detach the Loongson GMAC-specific platform data initializations to the loongson_gmac_data() method and preserve the common settings in the loongson_default_data(). While at it drop the return value statement from the loongson_default_data() method as redundant.Based on the last hardware setup insight Loongson GMAC with AV-feature can be found on the LS2K2000 CPU. Thus the commit log should be: "Loongson delivers two types of the network devices: Loongson GMAC and Loongson GNET in the framework of four CPU/Chipsets revisions: Chip Network PCI Dev ID Synopys Version DMA-channel LS2K1000 CPU GMAC 0x7a03 v3.50a/v3.73a 1 LS7A1000 Chipset GMAC 0x7a03 v3.50a/v3.73a 1 LS2K2000 CPU GMAC 0x7a03 v3.73a 8 LS2K2000 CPU GNET 0x7a13 v3.73a 8 LS7A2000 Chipset GNET 0x7a13 v3.73a 1 The driver currently supports the chips with the Loongson GMAC network device synthesized with a single DMA-channel available. As a preparation before adding the Loongson GNET support detach the Loongson GMAC-specific platform data initializations to the loongson_gmac_data() method and preserve the common settings in the loongson_default_data(). While at it drop the return value statement from the loongson_default_data() method as redundant."OK, Thank you very much!quoted
quoted
Signed-off-by: Feiyang Chen <redacted> Signed-off-by: Yinggang Gu <redacted> Signed-off-by: Yanteng Si <redacted> --- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c index 739b73f4fc35..ad3f44440963 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c@@ -11,7 +11,7 @@ #define PCI_DEVICE_ID_LOONGSON_GMAC 0x7a03 -static int loongson_default_data(struct plat_stmmacenet_data *plat) +static void loongson_default_data(struct plat_stmmacenet_data *plat) { plat->clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */ plat->has_gmac = 1;@@ -20,16 +20,14 @@ static int loongson_default_data(struct plat_stmmacenet_data *plat) /* Set default value for multicast hash bins */ plat->multicast_filter_bins = 256; + plat->mac_interface = PHY_INTERFACE_MODE_NA; + /* Set default value for unicast filter entries */ plat->unicast_filter_entries = 1; /* Set the maxmtu to a default of JUMBO_LEN */ plat->maxmtu = JUMBO_LEN; - /* Set default number of RX and TX queues to use */ - plat->tx_queues_to_use = 1; - plat->rx_queues_to_use = 1; - /* Disable Priority config by default */ plat->tx_queues_cfg[0].use_prio = false; plat->rx_queues_cfg[0].use_prio = false;@@ -42,6 +40,11 @@ static int loongson_default_data(struct plat_stmmacenet_data *plat) plat->dma_cfg->pbl = 32; plat->dma_cfg->pblx8 = true; +} + +static int loongson_gmac_data(struct plat_stmmacenet_data *plat) +{ + loongson_default_data(plat); return 0; }@@ -111,11 +114,10 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id } plat->phy_interface = phy_mode; - plat->mac_interface = PHY_INTERFACE_MODE_GMII; pci_set_master(pdev); - loongson_default_data(plat); + loongson_gmac_data(plat); pci_enable_msi(pdev); memset(&res, 0, sizeof(res)); res.addr = pcim_iomap_table(pdev)[0];@@ -140,6 +142,9 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id goto err_disable_msi; } + plat->tx_queues_to_use = 1; + plat->rx_queues_to_use = 1; +Please move this to the loongson_gmac_data(). Thus all the platform-data initializations would be collected in two coherent methods: loongson_default_data() and loongson_gmac_data(). It will be positive from the readability and maintainability points of view.
OK, I will move this to the loongson_default_data(), Because loongson_gmac/gnet_data() call it.
It shall also work. But the fields will be overwritten in the loongson_gmac_data()/loongson_gnet_data() methods for the multi-channels case. I don't have a strong opinion against that. But some maintainers may have.
quoted
In the patch adding the Loongson multi-channel GMAC support make sure the loongson_data::loongson_id field is initialized before the stmmac_pci_info::setup() method is called.I've tried. It's almost impossible.
Emm, why is it impossible? I don't see any significant problem with implementing that.
The only way to do this is to initialize loongson_id again in loongson_default_data(). But that will add a lot of code.
Not sure, why? What about the next probe() code snippet:
plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
if (!plat)
return -ENOMEM;
plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
sizeof(*plat->mdio_bus_data),
GFP_KERNEL);
if (!plat->mdio_bus_data)
return -ENOMEM;
plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg), GFP_KERNEL);
if (!plat->dma_cfg)
return -ENOMEM;
ld = devm_kzalloc(&pdev->dev, sizeof(*ld), GFP_KERNEL);
if (!ld)
return -ENOMEM;
/* Enable pci device */
ret = pci_enable_device(pdev);
if (ret)
return ret;
// AFAIR the bus-mastering isn't required for the normal PCIe
// IOs. So pci_set_master() can be called some place
// afterwards.
pci_set_master(pdev);
for (i = 0; i < PCI_STD_NUM_BARS; i++) {
if (pci_resource_len(pdev, i) == 0)
continue;
ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
if (ret)
goto err_disable_device;
break;
}
memset(&res, 0, sizeof(res));
res.addr = pcim_iomap_table(pdev)[0];
plat->bsp_priv = ld;
plat->setup = loongson_dwmac_setup;
ld->dev = &pdev->dev;
ld->loongson_id = readl(res.addr + GMAC_VERSION) & 0xff;
info = (struct stmmac_pci_info *)id->driver_data;
ret = info->setup(plat);
if (ret)
goto err_disable_device;
if (dev_of_node(&pdev->dev))
ret = loongson_dwmac_dt_config(pdev, plat, &res);
else
ret = loongson_dwmac_acpi_config(pdev, plat, &res);
if (ret)
goto err_disable_device;
if (ld->loongson_id == DWMAC_CORE_LS2K2000) {
ret = loongson_dwmac_msi_config(pdev, plat, &res);
if (ret)
goto err_disable_device;
}
ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
if (ret)
goto err_clear_msi;
return 0;
...
The code allocates all the data, then enables the PCIe device
and maps the PCIe device resources. After that it calls all the setup
and config methods. Do I miss something?
-Serge(y)
Hmm, how about: loongson_default_data() { plat->tx_queues_to_use = 1; plat->rx_queues_to_use = 1; ... } loongson_dwmac_probe() { ... if (ld->loongson_id == DWMAC_CORE_LS2K2000) { plat->rx_queues_to_use = CHANNEL_NUM; plat->tx_queues_to_use = CHANNEL_NUM; /* Only channel 0 supports checksum, * so turn off checksum to enable multiple channels. */ for (i = 1; i < CHANNEL_NUM; i++) plat->tx_queues_cfg[i].coe_unsupported = 1; ret = loongson_dwmac_msi_config(pdev, plat, &res); } else { ret = loongson_dwmac_intx_config(pdev, plat, &res); } ... } Thanks, Yantengquoted
-Serge(y)quoted
ret = stmmac_dvr_probe(&pdev->dev, plat, &res); if (ret) goto err_disable_msi; -- 2.31.4