Re: [PATCH v2 1/4] PCI: designware-ep: Allow pci_epc_set_bar() update inbound map address

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Dec 14, 2023 at 03:52:43PM -0500, Frank Li wrote:
> On Thu, Dec 14, 2023 at 08:23:14PM +0000, Niklas Cassel wrote:
> > On Thu, Dec 14, 2023 at 10:19:03AM -0500, Frank Li wrote:
> > > On Thu, Dec 14, 2023 at 02:31:04PM +0000, Niklas Cassel wrote:
> > > > Hello Frank,
> > > > 
> > > > On Tue, Feb 22, 2022 at 10:23:52AM -0600, Frank Li wrote:
> > > > > ntb_mw_set_trans() will set memory map window after endpoint function
> > > > > driver bind. The inbound map address need be updated dynamically when
> > > > > using NTB by PCIe Root Port and PCIe Endpoint connection.
> > > > > 
> > > > > Checking if iatu already assigned to the BAR, if yes, using assigned iatu
> > > > > number to update inbound address map and skip set BAR's register.
> > > > > 
> > > > > Signed-off-by: Frank Li <Frank.Li@xxxxxxx>
> > > > > ---
> > > > > 
> > > > > Change from V1:
> > > > >  - improve commit message
> > > > > 
> > > > >  drivers/pci/controller/dwc/pcie-designware-ep.c | 10 +++++++++-
> > > > >  1 file changed, 9 insertions(+), 1 deletion(-)
> > > > > 
> > > > > diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c
> > > > > index 998b698f40858..cad5d9ea7cc6c 100644
> > > > > --- a/drivers/pci/controller/dwc/pcie-designware-ep.c
> > > > > +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c
> > > > > @@ -161,7 +161,11 @@ static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, u8 func_no,
> > > > >  	u32 free_win;
> > > > >  	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
> > > > >  
> > > > > -	free_win = find_first_zero_bit(ep->ib_window_map, pci->num_ib_windows);
> > > > 
> > > > find_first_zero_bit() can return 0, representing bit 0,
> > > > which is a perfectly valid return value.
> > > > 
> > > > > +	if (!ep->bar_to_atu[bar])
> > > > 
> > > > so this check is not correct.
> > > > 
> > > 
> > > Please sent out your fixed patch. If want to me fix it, please tell me
> > > reproduce steps.
> > 
> > Reproduce steps are simple:
> > 1) Add debug messages to dw_pcie_ep_inbound_atu() to see the iATU index for
> > each BAR.
> > 2) Boot an EP platform with a core_init_notifier.
> > 3) Boot the RC.
> > 4) Reboot the RC, which will assert + deassert PERST, and will call
> >    pci_epc_init_notify(), which will call .core_init (pci_epf_test_core_init())
> >    which will set the BARs.
> > 
> > 
> > In step 3) BAR0 will use iATU0.
> > 
> > In step 4) BAR0 will use iATU6 instead of iATU0.
> > There is no reason for this, as it should really reuse the same
> > iATU index as before, just like all the other BARs do.
> > (This is because of find_first_zero_bit() misusage.)
> > 
> > 
> > I could send out my patch, but from inspecting the code, it looks like:
> > 
> > > > > + if (ep->epf_bar[bar])
> > > > > +         return 0;
> 
> I checked current code. 
> 
> dw_pcie_ep_inbound_atu()
> {
>  	if (!ep->bar_to_atu[bar])                                                                   
>                 free_win = find_first_zero_bit(ep->ib_window_map, pci->num_ib_windows);             
>         else                                                                                        
>                 free_win = ep->bar_to_atu[bar]; 
> }
> 
> I missed conside '0' is validate windows number. I think we should init
> bar_to_atu to -1. 
> 
> 	if (ep->bar_to_atu[bar] < 0)
> 
> 
> Origial change want dw_pcie_ep_inbound_atu() can be call twice to update
> bar map address. vntb use "bar3" as memory map windows, so have not trigger
> this problem.

Feel free to send out a patch, I just wanted to inform people about the
problem.


I can understand that the point of the patch in $subject was to re-use the
exact same iATU for a specific BAR, however, does the change:

if (ep->epf_bar[bar])
	return 0;

to dw_pcie_ep_set_bar(), really provide any value?

I guess it will avoid clearing the BAR_REG, if the RC has assigned an
PCI address to that BAR, which I guess was important for vntb?

If so, I don't see any alternative but to let DWC drivers with a
core_init_notifier to call dw_pcie_ep_clear_bar() when asserting perst,
or to modify dw_pcie_ep_init_notify() to call dw_pcie_ep_clear_bar().


Kind regards,
Niklas




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux