[v14,6/7] PCI: endpoint: pci-epf-vntb: fix sparse build warning at epf_db

Message ID 20221028155703.318928-7-Frank.Li@nxp.com
State New
Headers
Series pci-epf-vntb clean up |

Commit Message

Frank Li Oct. 28, 2022, 3:57 p.m. UTC
  From: Frank Li <frank.li@nxp.com>

Using epf_db[i] instead of readl() because epf_db is in local
system memory and allocated by dma_alloc_coherent().

Signed-off-by: Frank Li <frank.li@nxp.com>
---
 drivers/pci/endpoint/functions/pci-epf-vntb.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
  

Comments

Manivannan Sadhasivam Nov. 1, 2022, 12:24 p.m. UTC | #1
On Fri, Oct 28, 2022 at 11:57:02AM -0400, Frank Li wrote:
> From: Frank Li <frank.li@nxp.com>
> 
> Using epf_db[i] instead of readl() because epf_db is in local
> system memory and allocated by dma_alloc_coherent().
> 
> Signed-off-by: Frank Li <frank.li@nxp.com>
> ---
>  drivers/pci/endpoint/functions/pci-epf-vntb.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
> index 54616281da9e..db3455c1589b 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
> @@ -136,7 +136,7 @@ struct epf_ntb {
>  
>  	struct epf_ntb_ctrl *reg;
>  
> -	void __iomem *epf_db;
> +	u32 *epf_db;
>  
>  	phys_addr_t vpci_mw_phy[MAX_MW];
>  	void __iomem *vpci_mw_addr[MAX_MW];
> @@ -257,12 +257,9 @@ static void epf_ntb_cmd_handler(struct work_struct *work)
>  	ntb = container_of(work, struct epf_ntb, cmd_handler.work);
>  
>  	for (i = 1; i < ntb->db_count; i++) {
> -		if (readl(ntb->epf_db + i * sizeof(u32))) {
> -			if (readl(ntb->epf_db + i * sizeof(u32)))
> -				ntb->db |= 1 << (i - 1);

Why did you remove above line?

Thanks,
Mani

> -
> +		if (ntb->epf_db[i]) {
>  			ntb_db_event(&ntb->ntb, i);
> -			writel(0, ntb->epf_db + i * sizeof(u32));
> +			ntb->epf_db[i] = 0;
>  		}
>  	}
>  
> -- 
> 2.34.1
>
  
kernel test robot Nov. 1, 2022, 12:47 p.m. UTC | #2
Hi Frank,

I love your patch! Perhaps something to improve:

[auto build test WARNING on jonmason-ntb/ntb-next]
[also build test WARNING on linus/master v6.1-rc3 next-20221101]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Frank-Li/pci-epf-vntb-clean-up/20221029-000245
base:   https://github.com/jonmason/ntb ntb-next
patch link:    https://lore.kernel.org/r/20221028155703.318928-7-Frank.Li%40nxp.com
patch subject: [PATCH v14 6/7] PCI: endpoint: pci-epf-vntb: fix sparse build warning at epf_db
config: ia64-randconfig-s043-20221031
compiler: ia64-linux-gcc (GCC) 12.1.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.4-39-gce1a6720-dirty
        # https://github.com/intel-lab-lkp/linux/commit/04d4831353640b04e4f670c2b30e2ed12ef647d6
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Frank-Li/pci-epf-vntb-clean-up/20221029-000245
        git checkout 04d4831353640b04e4f670c2b30e2ed12ef647d6
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=ia64 SHELL=/bin/bash drivers/pci/controller/ drivers/pci/endpoint/functions/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

sparse warnings: (new ones prefixed by >>)
   drivers/pci/endpoint/functions/pci-epf-vntb.c:552:17: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected void [noderef] __iomem *mw_addr @@     got void * @@
   drivers/pci/endpoint/functions/pci-epf-vntb.c:552:17: sparse:     expected void [noderef] __iomem *mw_addr
   drivers/pci/endpoint/functions/pci-epf-vntb.c:552:17: sparse:     got void *
>> drivers/pci/endpoint/functions/pci-epf-vntb.c:558:21: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected unsigned int [usertype] *epf_db @@     got void [noderef] __iomem *mw_addr @@
   drivers/pci/endpoint/functions/pci-epf-vntb.c:558:21: sparse:     expected unsigned int [usertype] *epf_db
   drivers/pci/endpoint/functions/pci-epf-vntb.c:558:21: sparse:     got void [noderef] __iomem *mw_addr
   drivers/pci/endpoint/functions/pci-epf-vntb.c:570:38: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *addr @@     got void [noderef] __iomem *mw_addr @@
   drivers/pci/endpoint/functions/pci-epf-vntb.c:570:38: sparse:     expected void *addr
   drivers/pci/endpoint/functions/pci-epf-vntb.c:570:38: sparse:     got void [noderef] __iomem *mw_addr
   drivers/pci/endpoint/functions/pci-epf-vntb.c:1123:33: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void [noderef] __iomem *base @@     got struct epf_ntb_ctrl *reg @@
   drivers/pci/endpoint/functions/pci-epf-vntb.c:1123:33: sparse:     expected void [noderef] __iomem *base
   drivers/pci/endpoint/functions/pci-epf-vntb.c:1123:33: sparse:     got struct epf_ntb_ctrl *reg
   drivers/pci/endpoint/functions/pci-epf-vntb.c:1134:33: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void [noderef] __iomem *base @@     got struct epf_ntb_ctrl *reg @@
   drivers/pci/endpoint/functions/pci-epf-vntb.c:1134:33: sparse:     expected void [noderef] __iomem *base
   drivers/pci/endpoint/functions/pci-epf-vntb.c:1134:33: sparse:     got struct epf_ntb_ctrl *reg
   drivers/pci/endpoint/functions/pci-epf-vntb.c:1145:33: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void [noderef] __iomem *base @@     got struct epf_ntb_ctrl *reg @@
   drivers/pci/endpoint/functions/pci-epf-vntb.c:1145:33: sparse:     expected void [noderef] __iomem *base
   drivers/pci/endpoint/functions/pci-epf-vntb.c:1145:33: sparse:     got struct epf_ntb_ctrl *reg
   drivers/pci/endpoint/functions/pci-epf-vntb.c:1157:33: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void [noderef] __iomem *base @@     got struct epf_ntb_ctrl *reg @@
   drivers/pci/endpoint/functions/pci-epf-vntb.c:1157:33: sparse:     expected void [noderef] __iomem *base
   drivers/pci/endpoint/functions/pci-epf-vntb.c:1157:33: sparse:     got struct epf_ntb_ctrl *reg

vim +558 drivers/pci/endpoint/functions/pci-epf-vntb.c

e35f56bb03304a Frank Li 2022-02-22  519  
e35f56bb03304a Frank Li 2022-02-22  520  /**
e35f56bb03304a Frank Li 2022-02-22  521   * epf_ntb_db_bar_init() - Configure Doorbell window BARs
693ca189095cb2 Frank Li 2022-10-28  522   * @ntb: NTB device that facilitates communication between HOST and VHOST
693ca189095cb2 Frank Li 2022-10-28  523   *
693ca189095cb2 Frank Li 2022-10-28  524   * Returns: Zero for success, or an error code in case of failure
e35f56bb03304a Frank Li 2022-02-22  525   */
e35f56bb03304a Frank Li 2022-02-22  526  static int epf_ntb_db_bar_init(struct epf_ntb *ntb)
e35f56bb03304a Frank Li 2022-02-22  527  {
e35f56bb03304a Frank Li 2022-02-22  528  	const struct pci_epc_features *epc_features;
e35f56bb03304a Frank Li 2022-02-22  529  	u32 align;
e35f56bb03304a Frank Li 2022-02-22  530  	struct device *dev = &ntb->epf->dev;
e35f56bb03304a Frank Li 2022-02-22  531  	int ret;
e35f56bb03304a Frank Li 2022-02-22  532  	struct pci_epf_bar *epf_bar;
e35f56bb03304a Frank Li 2022-02-22  533  	void __iomem *mw_addr;
e35f56bb03304a Frank Li 2022-02-22  534  	enum pci_barno barno;
38cb263ec6bff3 Frank Li 2022-10-28  535  	size_t size = sizeof(u32) * ntb->db_count;
e35f56bb03304a Frank Li 2022-02-22  536  
e35f56bb03304a Frank Li 2022-02-22  537  	epc_features = pci_epc_get_features(ntb->epf->epc,
e35f56bb03304a Frank Li 2022-02-22  538  					    ntb->epf->func_no,
e35f56bb03304a Frank Li 2022-02-22  539  					    ntb->epf->vfunc_no);
e35f56bb03304a Frank Li 2022-02-22  540  	align = epc_features->align;
e35f56bb03304a Frank Li 2022-02-22  541  
e35f56bb03304a Frank Li 2022-02-22  542  	if (size < 128)
e35f56bb03304a Frank Li 2022-02-22  543  		size = 128;
e35f56bb03304a Frank Li 2022-02-22  544  
e35f56bb03304a Frank Li 2022-02-22  545  	if (align)
e35f56bb03304a Frank Li 2022-02-22  546  		size = ALIGN(size, align);
e35f56bb03304a Frank Li 2022-02-22  547  	else
e35f56bb03304a Frank Li 2022-02-22  548  		size = roundup_pow_of_two(size);
e35f56bb03304a Frank Li 2022-02-22  549  
e35f56bb03304a Frank Li 2022-02-22  550  	barno = ntb->epf_ntb_bar[BAR_DB];
e35f56bb03304a Frank Li 2022-02-22  551  
e35f56bb03304a Frank Li 2022-02-22  552  	mw_addr = pci_epf_alloc_space(ntb->epf, size, barno, align, 0);
e35f56bb03304a Frank Li 2022-02-22  553  	if (!mw_addr) {
e35f56bb03304a Frank Li 2022-02-22  554  		dev_err(dev, "Failed to allocate OB address\n");
e35f56bb03304a Frank Li 2022-02-22  555  		return -ENOMEM;
e35f56bb03304a Frank Li 2022-02-22  556  	}
e35f56bb03304a Frank Li 2022-02-22  557  
e35f56bb03304a Frank Li 2022-02-22 @558  	ntb->epf_db = mw_addr;
e35f56bb03304a Frank Li 2022-02-22  559  
e35f56bb03304a Frank Li 2022-02-22  560  	epf_bar = &ntb->epf->bar[barno];
e35f56bb03304a Frank Li 2022-02-22  561  
e35f56bb03304a Frank Li 2022-02-22  562  	ret = pci_epc_set_bar(ntb->epf->epc, ntb->epf->func_no, ntb->epf->vfunc_no, epf_bar);
e35f56bb03304a Frank Li 2022-02-22  563  	if (ret) {
e35f56bb03304a Frank Li 2022-02-22  564  		dev_err(dev, "Doorbell BAR set failed\n");
e35f56bb03304a Frank Li 2022-02-22  565  			goto err_alloc_peer_mem;
e35f56bb03304a Frank Li 2022-02-22  566  	}
e35f56bb03304a Frank Li 2022-02-22  567  	return ret;
e35f56bb03304a Frank Li 2022-02-22  568  
e35f56bb03304a Frank Li 2022-02-22  569  err_alloc_peer_mem:
20ecc991a4fdac Frank Li 2022-10-28  570  	pci_epf_free_space(ntb->epf, mw_addr, barno, 0);
e35f56bb03304a Frank Li 2022-02-22  571  	return -1;
e35f56bb03304a Frank Li 2022-02-22  572  }
e35f56bb03304a Frank Li 2022-02-22  573
  

Patch

diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
index 54616281da9e..db3455c1589b 100644
--- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
+++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
@@ -136,7 +136,7 @@  struct epf_ntb {
 
 	struct epf_ntb_ctrl *reg;
 
-	void __iomem *epf_db;
+	u32 *epf_db;
 
 	phys_addr_t vpci_mw_phy[MAX_MW];
 	void __iomem *vpci_mw_addr[MAX_MW];
@@ -257,12 +257,9 @@  static void epf_ntb_cmd_handler(struct work_struct *work)
 	ntb = container_of(work, struct epf_ntb, cmd_handler.work);
 
 	for (i = 1; i < ntb->db_count; i++) {
-		if (readl(ntb->epf_db + i * sizeof(u32))) {
-			if (readl(ntb->epf_db + i * sizeof(u32)))
-				ntb->db |= 1 << (i - 1);
-
+		if (ntb->epf_db[i]) {
 			ntb_db_event(&ntb->ntb, i);
-			writel(0, ntb->epf_db + i * sizeof(u32));
+			ntb->epf_db[i] = 0;
 		}
 	}