[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d9e684c5-52b3-4da3-8119-d2e3b7422db6@loongson.cn>
Date: Wed, 3 Jul 2024 17:41:55 +0800
From: Yanteng Si <siyanteng@...ngson.cn>
To: Serge Semin <fancer.lancer@...il.com>
Cc: andrew@...n.ch, hkallweit1@...il.com, peppe.cavallaro@...com,
alexandre.torgue@...s.st.com, joabreu@...opsys.com, Jose.Abreu@...opsys.com,
chenhuacai@...nel.org, linux@...linux.org.uk, guyinggang@...ngson.cn,
netdev@...r.kernel.org, chris.chenfeiyang@...il.com, si.yanteng@...ux.dev
Subject: Re: [PATCH net-next v13 06/15] net: stmmac: dwmac-loongson: Detach
GMAC-specific platform data init
>>>> - 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.
I see. I will move this to the loongson_gmac_data()/loongson_gnet_data().
>
>>
>>> 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.
Sorry, I've to take back my words.
>
>>
>> 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:
Full marks!
>
> 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);
I don't know how to write this function, it seems that there
is no obvious acpi code in the probe method.
>
> 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;
> }
It seems that we don't need if else.
If failed to allocate msi, it will fallback to intx.
so loongson_dwmac_msi_config also needs a new name. How about:
...
ret = loongson_dwmac_irq_config(pdev, plat, &res);
if (ret)
goto err_disable_device;
ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
...
>
> 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?
You are right!
Thanks,
Yanteng
>
> -Serge(y)
>
>>>> 2.31.4
>>>>
Powered by blists - more mailing lists