diff mbox series

[net-next,v11,4/6] net: stmmac: dwmac-loongson: Introduce GMAC setup

Message ID 6f0ac42c1b60db318b7d746254a9b310dd03aa32.1712917541.git.siyanteng@loongson.cn (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series stmmac: Add Loongson platform support | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 19 this patch: 19
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 7 maintainers not CCed: pabeni@redhat.com kuba@kernel.org linux-arm-kernel@lists.infradead.org edumazet@google.com linux-stm32@st-md-mailman.stormreply.com richardcochran@gmail.com mcoquelin.stm32@gmail.com
netdev/build_clang fail Errors and warnings before: 21 this patch: 21
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 19 this patch: 19
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 51 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yanteng Si April 12, 2024, 11:28 a.m. UTC
Based on IP core classification, loongson has two types of network
devices: GMAC and GNET. GMAC's ip_core id is 0x35/0x37, while GNET's
ip_core id is 0x37/0x10.

Device tables:

device    type    pci_id    ip_core
ls2k1000  gmac    7a03      0x35/0x37
ls7a1000  gmac    7a03      0x35/0x37
ls2k2000  gnet    7a13      0x10
ls7a2000  gnet    7a13      0x37

The ref/ptp clock of gmac is 125000000. gmac device only
has a MAC chip inside and needs an external PHY chip;

Signed-off-by: Feiyang Chen <chenfeiyang@loongson.cn>
Signed-off-by: Yinggang Gu <guyinggang@loongson.cn>
Signed-off-by: Yanteng Si <siyanteng@loongson.cn>
---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 21 +++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

Comments

Serge Semin April 18, 2024, 12:26 p.m. UTC | #1
On Fri, Apr 12, 2024 at 07:28:49PM +0800, Yanteng Si wrote:
> Based on IP core classification, loongson has two types of network
> devices: GMAC and GNET. GMAC's ip_core id is 0x35/0x37, while GNET's
> ip_core id is 0x37/0x10.
> 
> Device tables:
> 
> device    type    pci_id    ip_core
> ls2k1000  gmac    7a03      0x35/0x37
> ls7a1000  gmac    7a03      0x35/0x37
> ls2k2000  gnet    7a13      0x10
> ls7a2000  gnet    7a13      0x37
> 
> The ref/ptp clock of gmac is 125000000. gmac device only
> has a MAC chip inside and needs an external PHY chip;
> 
> Signed-off-by: Feiyang Chen <chenfeiyang@loongson.cn>
> Signed-off-by: Yinggang Gu <guyinggang@loongson.cn>
> Signed-off-by: Yanteng Si <siyanteng@loongson.cn>
> ---
>  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 21 +++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
> index 995c9bd144e0..ad19b4087974 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
> @@ -9,7 +9,8 @@
>  #include <linux/of_irq.h>
>  #include "stmmac.h"
>  
> -static int loongson_default_data(struct plat_stmmacenet_data *plat)
> +static void loongson_default_data(struct pci_dev *pdev,
> +				  struct plat_stmmacenet_data *plat)
>  {
>  	plat->clk_csr = 2;	/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
>  	plat->has_gmac = 1;
> @@ -24,16 +25,18 @@ static int loongson_default_data(struct plat_stmmacenet_data *plat)
>  	/* 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;
>  
>  	/* Disable RX queues routing by default */
>  	plat->rx_queues_cfg[0].pkt_route = 0x0;
> +}
> +
> +static int loongson_gmac_data(struct pci_dev *pdev,
> +			      struct plat_stmmacenet_data *plat)
> +{
> +	loongson_default_data(pdev, plat);
>  
>  	/* Default to phy auto-detection */
>  	plat->phy_addr = -1;
> @@ -42,6 +45,12 @@ static int loongson_default_data(struct plat_stmmacenet_data *plat)
>  	plat->dma_cfg->pblx8 = true;
>  

>  	plat->multicast_filter_bins = 256;
> +	plat->clk_ref_rate = 125000000;
> +	plat->clk_ptp_rate = 125000000;

This change is unrelated to the rest of the changes in this patch.
Please split the patch up into two:
1. Add ref and ptp clocks for Loongson GMAC
2. Split up the platform data initialization
First one is a new feature adding the actual ref clock rates to the
driver. The second patch is a preparation before adding the full PCI
support.

-Serge(y)

> +
> +	plat->tx_queues_to_use = 1;
> +	plat->rx_queues_to_use = 1;
> +
>  	return 0;
>  }
>  
> @@ -114,7 +123,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
>  
>  	pci_set_master(pdev);
>  
> -	loongson_default_data(plat);
> +	loongson_gmac_data(pdev, plat);
>  	pci_enable_msi(pdev);
>  	memset(&res, 0, sizeof(res));
>  	res.addr = pcim_iomap_table(pdev)[0];
> -- 
> 2.31.4
>
Yanteng Si April 19, 2024, 10:06 a.m. UTC | #2
在 2024/4/18 20:26, Serge Semin 写道:
>>   	plat->multicast_filter_bins = 256;
>> +	plat->clk_ref_rate = 125000000;
>> +	plat->clk_ptp_rate = 125000000;
> This change is unrelated to the rest of the changes in this patch.
> Please split the patch up into two:
> 1. Add ref and ptp clocks for Loongson GMAC
> 2. Split up the platform data initialization
> First one is a new feature adding the actual ref clock rates to the
> driver. The second patch is a preparation before adding the full PCI
> support.
>
Ok, but we need to reverse the order:

1. Split up the platform data initialization

2. Add ref and ptp clocks for Loongson GMAC


Since loongson_gmac_data() needs to be introduced first, then we can add the

clock rates of GMAC.


Thanks,
Yanteng
Yanteng Si April 22, 2024, 10:17 a.m. UTC | #3
Hi all

在 2024/4/12 19:28, Yanteng Si 写道:
> @@ -42,6 +45,12 @@ static int loongson_default_data(struct plat_stmmacenet_data *plat)
>   	plat->dma_cfg->pblx8 = true;
>   
>   	plat->multicast_filter_bins = 256;
> +	plat->clk_ref_rate = 125000000;
> +	plat->clk_ptp_rate = 125000000;
> +

> +	plat->tx_queues_to_use = 1;
> +	plat->rx_queues_to_use = 1;

Sorry, I forgot to delete them.


This part of the code has been moved to loongson_dwmac_probe() in this 
patch set, Why?


Because we have two different gnet devices: the 2k2000 supports multiple 
channels,

the 7a2000 only supports single channels, and all GMAC devices only 
support single channels.


If we keep this part of the code here, we will get GMAC_VERSION again in 
gnet_data()

  to distinguish them, which will make the code more complex. We can use 
GMAC_VERSION

in probe to distinguish them easily.


  so the patch will be redesigned in v12.


Thanks,

Yanteng
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
index 995c9bd144e0..ad19b4087974 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
@@ -9,7 +9,8 @@ 
 #include <linux/of_irq.h>
 #include "stmmac.h"
 
-static int loongson_default_data(struct plat_stmmacenet_data *plat)
+static void loongson_default_data(struct pci_dev *pdev,
+				  struct plat_stmmacenet_data *plat)
 {
 	plat->clk_csr = 2;	/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
 	plat->has_gmac = 1;
@@ -24,16 +25,18 @@  static int loongson_default_data(struct plat_stmmacenet_data *plat)
 	/* 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;
 
 	/* Disable RX queues routing by default */
 	plat->rx_queues_cfg[0].pkt_route = 0x0;
+}
+
+static int loongson_gmac_data(struct pci_dev *pdev,
+			      struct plat_stmmacenet_data *plat)
+{
+	loongson_default_data(pdev, plat);
 
 	/* Default to phy auto-detection */
 	plat->phy_addr = -1;
@@ -42,6 +45,12 @@  static int loongson_default_data(struct plat_stmmacenet_data *plat)
 	plat->dma_cfg->pblx8 = true;
 
 	plat->multicast_filter_bins = 256;
+	plat->clk_ref_rate = 125000000;
+	plat->clk_ptp_rate = 125000000;
+
+	plat->tx_queues_to_use = 1;
+	plat->rx_queues_to_use = 1;
+
 	return 0;
 }
 
@@ -114,7 +123,7 @@  static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
 
 	pci_set_master(pdev);
 
-	loongson_default_data(plat);
+	loongson_gmac_data(pdev, plat);
 	pci_enable_msi(pdev);
 	memset(&res, 0, sizeof(res));
 	res.addr = pcim_iomap_table(pdev)[0];