Re: [PATCH v4 1/7] powerpc/pseries/iommu: Create defines for operations in ibm, ddw-applicable

2020-08-04 Thread David Dai
gt;addr_lo);
>  
>   return ret;
>  }
> @@ -996,7 +1005,7 @@ static u64 enable_ddw(struct pci_dev *dev,
> struct device_node *pdn)
>   int page_shift;
>   u64 dma_addr, max_addr;
>   struct device_node *dn;
> - u32 ddw_avail[3];
> + u32 ddw_avail[DDW_APPLICABLE_SIZE];
>   struct direct_window *window;
>   struct property *win64;
>   struct dynamic_dma_window_prop *ddwprop;
> @@ -1029,7 +1038,7 @@ static u64 enable_ddw(struct pci_dev *dev,
> struct device_node *pdn)
>* the property is actually in the parent, not the PE
>*/
>   ret = of_property_read_u32_array(pdn, "ibm,ddw-applicable",
> -  _avail[0], 3);
> +  _avail[0],
> DDW_APPLICABLE_SIZE);
>   if (ret)
>   goto out_failed;
>  
Tested-by: David Dai 



Re: [PATCH v4 4/7] powerpc/pseries/iommu: Remove default DMA window before creating DDW

2020-08-04 Thread David Dai
> + default_win_removed = true;
> +
> + /* Query again, to check if the window is available */
> + ret = query_ddw(dev, ddw_avail, , pdn);
> + if (ret != 0)
> + goto out_failed;
> +
> + if (query.windows_available == 0) {
> + /* no windows are available for this device. */
> +     dev_dbg(>dev, "no free dynamic windows");
> + goto out_failed;
> + }
>   }
>   if (query.page_size & 4) {
>   page_shift = 24; /* 16MB */
> @@ -1231,6 +1288,8 @@ static u64 enable_ddw(struct pci_dev *dev,
> struct device_node *pdn)
>   kfree(win64);
>  
>  out_failed:
> + if (default_win_removed)
> + reset_dma_window(dev, pdn);
>  
>   fpdn = kzalloc(sizeof(*fpdn), GFP_KERNEL);
>   if (!fpdn)
Tested-by: David Dai 



Re: [PATCH v4 3/7] powerpc/pseries/iommu: Move window-removing part of remove_ddw into remove_dma_window

2020-08-04 Thread David Dai
On Thu, 2020-07-16 at 04:16 -0300, Leonardo Bras wrote:
> Move the window-removing part of remove_ddw into a new function
> (remove_dma_window), so it can be used to remove other DMA windows.
> 
> It's useful for removing DMA windows that don't create
> DIRECT64_PROPNAME
> property, like the default DMA window from the device, which uses
> "ibm,dma-window".
> 
> Signed-off-by: Leonardo Bras 
> ---
>  arch/powerpc/platforms/pseries/iommu.c | 45 +++-
> --
>  1 file changed, 27 insertions(+), 18 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/pseries/iommu.c
> b/arch/powerpc/platforms/pseries/iommu.c
> index 1a933c4e8bba..4e33147825cc 100644
> --- a/arch/powerpc/platforms/pseries/iommu.c
> +++ b/arch/powerpc/platforms/pseries/iommu.c
> @@ -781,25 +781,14 @@ static int __init disable_ddw_setup(char *str)
>  
>  early_param("disable_ddw", disable_ddw_setup);
>  
> -static void remove_ddw(struct device_node *np, bool remove_prop)
> +static void remove_dma_window(struct device_node *np, u32
> *ddw_avail,
> +   struct property *win)
>  {
>   struct dynamic_dma_window_prop *dwp;
> - struct property *win64;
> - u32 ddw_avail[DDW_APPLICABLE_SIZE];
>   u64 liobn;
> - int ret = 0;
> -
> - ret = of_property_read_u32_array(np, "ibm,ddw-applicable",
> -  _avail[0],
> DDW_APPLICABLE_SIZE);
> -
> - win64 = of_find_property(np, DIRECT64_PROPNAME, NULL);
> - if (!win64)
> - return;
> -
> - if (ret || win64->length < sizeof(*dwp))
> - goto delprop;
> + int ret;
>  
> - dwp = win64->value;
> + dwp = win->value;
>   liobn = (u64)be32_to_cpu(dwp->liobn);
>  
>   /* clear the whole window, note the arg is in kernel pages */
> @@ -821,10 +810,30 @@ static void remove_ddw(struct device_node *np,
> bool remove_prop)
>   pr_debug("%pOF: successfully removed direct window:
> rtas returned "
>   "%d to ibm,remove-pe-dma-window(%x) %llx\n",
>   np, ret, ddw_avail[DDW_REMOVE_PE_DMA_WIN],
> liobn);
> +}
> +
> +static void remove_ddw(struct device_node *np, bool remove_prop)
> +{
> + struct property *win;
> + u32 ddw_avail[DDW_APPLICABLE_SIZE];
> + int ret = 0;
> +
> + ret = of_property_read_u32_array(np, "ibm,ddw-applicable",
> +  _avail[0],
> DDW_APPLICABLE_SIZE);
> + if (ret)
> + return;
> +
> + win = of_find_property(np, DIRECT64_PROPNAME, NULL);
> + if (!win)
> + return;
> +
> + if (win->length >= sizeof(struct dynamic_dma_window_prop))
> + remove_dma_window(np, ddw_avail, win);
> +
> + if (!remove_prop)
> + return;
>  
> -delprop:
> - if (remove_prop)
> - ret = of_remove_property(np, win64);
> + ret = of_remove_property(np, win);
>   if (ret)
>   pr_warn("%pOF: failed to remove direct window property:
> %d\n",
>   np, ret);
Tested-by: David Dai 



Re: [PATCH v4 2/7] powerpc/pseries/iommu: Update call to ibm, query-pe-dma-windows

2020-08-04 Thread David Dai
> query_out,
>   cfg_addr, BUID_HI(buid), BUID_LO(buid));
> - dev_info(>dev, "ibm,query-pe-dma-windows(%x) %x %x %x"
> - " returned %d\n", ddw_avail[DDW_QUERY_PE_DMA_WIN],
> cfg_addr,
> -  BUID_HI(buid), BUID_LO(buid), ret);
> + dev_info(>dev, "ibm,query-pe-dma-windows(%x) %x %x %x
> returned %d\n",
> +  ddw_avail[DDW_QUERY_PE_DMA_WIN], cfg_addr,
> BUID_HI(buid),
> +  BUID_LO(buid), ret);
> +
> + switch (out_sz) {
> + case 5:
> + query->windows_available = query_out[0];
> + query->largest_available_block = query_out[1];
> + query->page_size = query_out[2];
> + query->migration_capable = query_out[3];
> + break;
> + case 6:
> + query->windows_available = query_out[0];
> + query->largest_available_block = ((u64)query_out[1] <<
> 32) |
> +  query_out[2];
> + query->page_size = query_out[3];
> + query->migration_capable = query_out[4];
> + break;
> + }
> +
>   return ret;
>  }
>  
> @@ -1049,7 +1120,7 @@ static u64 enable_ddw(struct pci_dev *dev,
> struct device_node *pdn)
>* of page sizes: supported and supported for migrate-dma.
>*/
>   dn = pci_device_to_OF_node(dev);
> - ret = query_ddw(dev, ddw_avail, );
> +     ret = query_ddw(dev, ddw_avail, , pdn);
>   if (ret != 0)
>   goto out_failed;
>  
> @@ -1077,7 +1148,7 @@ static u64 enable_ddw(struct pci_dev *dev,
> struct device_node *pdn)
>   /* check largest block * page size > max memory hotplug addr */
>   max_addr = ddw_memory_hotplug_max();
>   if (query.largest_available_block < (max_addr >> page_shift)) {
> - dev_dbg(>dev, "can't map partition max 0x%llx with
> %u "
> + dev_dbg(>dev, "can't map partition max 0x%llx with
> %llu "
> "%llu-sized pages\n",
> max_addr,  query.largest_available_block,
> 1ULL << page_shift);
>   goto out_failed;
Tested-by: David Dai 



Re: [PATCH v4 1/7] powerpc/pseries/iommu: Create defines for operations in ibm, ddw-applicable

2020-08-04 Thread David Dai
gt;addr_lo);
>  
>   return ret;
>  }
> @@ -996,7 +1005,7 @@ static u64 enable_ddw(struct pci_dev *dev,
> struct device_node *pdn)
>   int page_shift;
>   u64 dma_addr, max_addr;
>   struct device_node *dn;
> - u32 ddw_avail[3];
> + u32 ddw_avail[DDW_APPLICABLE_SIZE];
>   struct direct_window *window;
>   struct property *win64;
>   struct dynamic_dma_window_prop *ddwprop;
> @@ -1029,7 +1038,7 @@ static u64 enable_ddw(struct pci_dev *dev,
> struct device_node *pdn)
>* the property is actually in the parent, not the PE
>*/
>   ret = of_property_read_u32_array(pdn, "ibm,ddw-applicable",
> -  _avail[0], 3);
> +  _avail[0],
> DDW_APPLICABLE_SIZE);
>   if (ret)
>   goto out_failed;
>  
Tested-by: David Dai