lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEensMz39F11FUsrsAyyy0WYZsVxL5FJB7=quR0EF_JsRkxvaQ@mail.gmail.com>
Date: Sat, 18 May 2024 18:38:39 +0800
From: yanteng si <siyanteng01@...il.com>
To: Serge Semin <fancer.lancer@...il.com>
Cc: Yanteng Si <siyanteng@...ngson.cn>, chenhuacai@...nel.org, andrew@...n.ch, 
	hkallweit1@...il.com, peppe.cavallaro@...com, alexandre.torgue@...s.st.com, 
	joabreu@...opsys.com, Jose.Abreu@...opsys.com, linux@...linux.org.uk, 
	guyinggang@...ngson.cn, netdev@...r.kernel.org, chris.chenfeiyang@...il.com
Subject: Re: [PATCH net-next v12 06/15] net: stmmac: dwmac-loongson: Split up
 the platform data initialization

Serge Semin <fancer.lancer@...il.com> 于2024年5月13日周一 22:05写道:
> > >
> > > >           /* 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;
> > > > @@ -41,6 +39,12 @@ static int loongson_default_data(struct plat_stmmacenet_data *plat)
> > > >           plat->dma_cfg->pblx8 = true;
> > > >           plat->multicast_filter_bins = 256;
> > > > +}
> > > > +
> > > > +static int loongson_gmac_data(struct plat_stmmacenet_data *plat)
> > > > +{
> > > > + loongson_default_data(plat);
> > > > +
> > > >           return 0;
> > > >   }
> > > > @@ -109,11 +113,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];
> > > > @@ -138,6 +141,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;
> > > > +
> > > You can freely move this to loongson_gmac_data() method. And then, in
> > > the patch adding the GNET-support, you'll be able to provide these fields
> > > initialization in the loongson_gnet_data() method together with the
> > > plat->tx_queues_cfg[*].coe_unsupported flag init. Thus the probe()
> > > method will get to be smaller and easier to read, and the
> > > loongson_*_data() method will be more coherent.
> >
> > As you said, at first glance, putting them in loongson_gnet_data() method is
> > fine,
> >
> > but in LS2K2000:
> >
> >         plat->rx_queues_to_use = CHANNEL_NUM;    // CHANNEL_NUM = 8;
> >         plat->tx_queues_to_use = CHANNEL_NUM;
> >
> > So we need to distinguish between them. At the same time, we have to
> > distinguish
> >
> > between LS2K2000 in probe() method. Why not put them inside probe, which
> > will
> >
> > save a lot of duplicate code, like this:
> >
> >     struct stmmac_resources res;
> >     struct loongson_data *ld;
> >
> > ...
> >
> >     memset(&res, 0, sizeof(res));
> >     res.addr = pcim_iomap_table(pdev)[0];
> >     ld->gmac_verion = readl(res.addr + GMAC_VERSION) & 0xff;
> >
> >     switch (ld->gmac_verion) {
> >     case LOONGSON_DWMAC_CORE_1_00:
> >         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_config_msi(pdev, plat, &res, np);
> >         break;
> >     default:    /* 0x35 device and 0x37 device. */
> >         plat->tx_queues_to_use = 1;
> >         plat->rx_queues_to_use = 1;
> >
> >         ret = loongson_dwmac_config_legacy(pdev, plat, &res, np);
> >         break;
> >     }
> >     if (ret)
> >         goto err_disable_device;
> >
> >
> > What do you think?
> >
> >
> > Of course, if you insist, I'm willing to repeat this in the
> >
> > loongson_gnet_data() method.
>
> Not necessarily. As Huacai earlier suggested you can keep the Loongson
> ID in the platform private data and have it utilized in the local
> sub-functions/routines. Like this:
>
> struct loongson_data {
>         u32 loongson_id;
> };
>
> static int loongson_gmac_data(struct pci_dev *pdev,
>                               struct plat_stmmacenet_data *plat)
> {
>         struct loongson_data *ld = plat->bsp_priv;
>
>         ...
>
>         plat->rx_queues_to_use = 1;
>         plat->tx_queues_to_use = 1;
>
>         return 0;
> }
>
> static int loongson_gnet_data(struct pci_dev *pdev,
>                               struct plat_stmmacenet_data *plat)
> {
>         struct loongson_data *ld = plat->bsp_priv;
>
>         ...
>
>         if (ld->loongson_id == DWMAC_CORE_LS2K2000) {
I did the test and found that at this point in time: loongson_id = 0,
it has not been initialized yet.

>
> static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> {
>         struct loongson_data *ld;
>         ...
>
>         ld = devm_kzalloc(&pdev->dev, sizeof(*ld), GFP_KERNEL);
>         if (!ld)
>                 return -ENOMEM;
>         ...
>         ld->loongson_id = readl(res.addr + GMAC_VERSION) & 0xff;
>         plat->bsp_priv = ld;
>         ...
>         if (ld->loongson_id == DWMAC_CORE_LS2K2000)
>                 ret = loongson_dwmac_config_msi(pdev, plat, &res);
>         else
>                 ret = loongson_dwmac_config_plat(pdev, plat, &res);
I'll change loongson_dwmac_config_legacy to loongson_dwmac_config_plat in the
next version. And using if-else.

>
> It's not "a lot" duplication code. Just two if-else statements, which
> is fine. But the data-init methods will get to be fully coherent. It's
> much more important.
Yes, I agree with you, but it looks like we still need to do the following again
inside loongson_gnet_data() :

memset(&res, 0, sizeof(res));
res.addr = pcim_iomap_table(pdev)[0];
ld->loongson_id = readl(res.addr + GMAC_VERSION) & 0xff;


>
> * Note switch-case is redundant since you have a single case in there,
> so if-else would be more than enough.
I see, Your single case is great!

Thanks,
Yanteng

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ