diff mbox series

[v3,05/10] cxl/pci: Make more use of cxl_register_map

Message ID 163379786381.692348.10643599219049157444.stgit@dwillia2-desk3.amr.corp.intel.com
State New
Headers show
Series cxl_pci refactor for reusability | expand

Commit Message

Dan Williams Oct. 9, 2021, 4:44 p.m. UTC
From: Ben Widawsky <ben.widawsky@intel.com>

The structure exists to pass around information about register mapping.
Use it for passing @barno and @block_offset, and eliminate duplicate
local variables.

The helpers that use @map do not care about @cxlm, so just pass them a
pdev instead.

Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
[djbw: separate @base conversion]
[djbw: reorder before cxl_pci_setup_regs() refactor to improver readability]
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 drivers/cxl/pci.c |   51 +++++++++++++++++++++------------------------------
 1 file changed, 21 insertions(+), 30 deletions(-)

Comments

kernel test robot Oct. 9, 2021, 7:04 p.m. UTC | #1
Hi Dan,

I love your patch! Perhaps something to improve:

[auto build test WARNING on ed97afb53365cd03dde266c9644334a558fe5a16]

url:    https://github.com/0day-ci/linux/commits/Dan-Williams/cxl_pci-refactor-for-reusability/20211010-004521
base:   ed97afb53365cd03dde266c9644334a558fe5a16
config: parisc-randconfig-r012-20211010 (attached as .config)
compiler: hppa-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/049a2765e60ef3807f8e4b8d04f2b70d90b38c94
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Dan-Williams/cxl_pci-refactor-for-reusability/20211010-004521
        git checkout 049a2765e60ef3807f8e4b8d04f2b70d90b38c94
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=parisc 

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

All warnings (new ones prefixed by >>):

   In file included from include/linux/printk.h:555,
                    from include/linux/kernel.h:19,
                    from arch/parisc/include/asm/bug.h:5,
                    from include/linux/bug.h:5,
                    from include/linux/io.h:11,
                    from include/linux/io-64-nonatomic-lo-hi.h:5,
                    from drivers/cxl/pci.c:3:
   drivers/cxl/pci.c: In function 'cxl_pci_map_regblock':
>> drivers/cxl/pci.c:330:22: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 5 has type 'resource_size_t' {aka 'unsigned int'} [-Wformat=]
     330 |         dev_dbg(dev, "Mapped CXL Memory Device resource bar %u @ %#llx\n",
         |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:134:29: note: in definition of macro '__dynamic_func_call'
     134 |                 func(&id, ##__VA_ARGS__);               \
         |                             ^~~~~~~~~~~
   include/linux/dynamic_debug.h:166:9: note: in expansion of macro '_dynamic_func_call'
     166 |         _dynamic_func_call(fmt,__dynamic_dev_dbg,               \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:9: note: in expansion of macro 'dynamic_dev_dbg'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:30: note: in expansion of macro 'dev_fmt'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                              ^~~~~~~
   drivers/cxl/pci.c:330:9: note: in expansion of macro 'dev_dbg'
     330 |         dev_dbg(dev, "Mapped CXL Memory Device resource bar %u @ %#llx\n",
         |         ^~~~~~~
   drivers/cxl/pci.c:330:70: note: format string is defined here
     330 |         dev_dbg(dev, "Mapped CXL Memory Device resource bar %u @ %#llx\n",
         |                                                                  ~~~~^
         |                                                                      |
         |                                                                      long long unsigned int
         |                                                                  %#x


vim +330 drivers/cxl/pci.c

8adaf747c9f0b4 drivers/cxl/mem.c Ben Widawsky 2021-02-16  308  
049a2765e60ef3 drivers/cxl/pci.c Ben Widawsky 2021-10-09  309  static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev,
049a2765e60ef3 drivers/cxl/pci.c Ben Widawsky 2021-10-09  310  					  struct cxl_register_map *map)
1b0a1a2a193400 drivers/cxl/pci.c Ben Widawsky 2021-04-07  311  {
f8a7e8c29be873 drivers/cxl/pci.c Ira Weiny    2021-05-27  312  	void __iomem *addr;
049a2765e60ef3 drivers/cxl/pci.c Ben Widawsky 2021-10-09  313  	int bar = map->barno;
049a2765e60ef3 drivers/cxl/pci.c Ben Widawsky 2021-10-09  314  	struct device *dev = &pdev->dev;
049a2765e60ef3 drivers/cxl/pci.c Ben Widawsky 2021-10-09  315  	resource_size_t offset = map->block_offset;
1b0a1a2a193400 drivers/cxl/pci.c Ben Widawsky 2021-04-07  316  
8adaf747c9f0b4 drivers/cxl/mem.c Ben Widawsky 2021-02-16  317  	/* Basic sanity check that BAR is big enough */
8adaf747c9f0b4 drivers/cxl/mem.c Ben Widawsky 2021-02-16  318  	if (pci_resource_len(pdev, bar) < offset) {
8adaf747c9f0b4 drivers/cxl/mem.c Ben Widawsky 2021-02-16  319  		dev_err(dev, "BAR%d: %pr: too small (offset: %#llx)\n", bar,
8adaf747c9f0b4 drivers/cxl/mem.c Ben Widawsky 2021-02-16  320  			&pdev->resource[bar], (unsigned long long)offset);
a0270407a9b3b5 drivers/cxl/pci.c Dan Williams 2021-10-09  321  		return NULL;
8adaf747c9f0b4 drivers/cxl/mem.c Ben Widawsky 2021-02-16  322  	}
8adaf747c9f0b4 drivers/cxl/mem.c Ben Widawsky 2021-02-16  323  
30af97296f48d8 drivers/cxl/pci.c Ira Weiny    2021-06-03  324  	addr = pci_iomap(pdev, bar, 0);
f8a7e8c29be873 drivers/cxl/pci.c Ira Weiny    2021-05-27  325  	if (!addr) {
8adaf747c9f0b4 drivers/cxl/mem.c Ben Widawsky 2021-02-16  326  		dev_err(dev, "failed to map registers\n");
f8a7e8c29be873 drivers/cxl/pci.c Ira Weiny    2021-05-27  327  		return addr;
8adaf747c9f0b4 drivers/cxl/mem.c Ben Widawsky 2021-02-16  328  	}
8adaf747c9f0b4 drivers/cxl/mem.c Ben Widawsky 2021-02-16  329  
f8a7e8c29be873 drivers/cxl/pci.c Ira Weiny    2021-05-27 @330  	dev_dbg(dev, "Mapped CXL Memory Device resource bar %u @ %#llx\n",
f8a7e8c29be873 drivers/cxl/pci.c Ira Weiny    2021-05-27  331  		bar, offset);
6630d31c912ed2 drivers/cxl/pci.c Ben Widawsky 2021-05-20  332  
30af97296f48d8 drivers/cxl/pci.c Ira Weiny    2021-06-03  333  	return addr;
30af97296f48d8 drivers/cxl/pci.c Ira Weiny    2021-06-03  334  }
30af97296f48d8 drivers/cxl/pci.c Ira Weiny    2021-06-03  335  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
index 21dd10a77eb3..9f006299a0e3 100644
--- a/drivers/cxl/pci.c
+++ b/drivers/cxl/pci.c
@@ -306,12 +306,13 @@  static int cxl_pci_setup_mailbox(struct cxl_mem *cxlm)
 	return 0;
 }
 
-static void __iomem *cxl_pci_map_regblock(struct cxl_mem *cxlm,
-					  u8 bar, u64 offset)
+static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev,
+					  struct cxl_register_map *map)
 {
 	void __iomem *addr;
-	struct device *dev = cxlm->dev;
-	struct pci_dev *pdev = to_pci_dev(dev);
+	int bar = map->barno;
+	struct device *dev = &pdev->dev;
+	resource_size_t offset = map->block_offset;
 
 	/* Basic sanity check that BAR is big enough */
 	if (pci_resource_len(pdev, bar) < offset) {
@@ -332,9 +333,9 @@  static void __iomem *cxl_pci_map_regblock(struct cxl_mem *cxlm,
 	return addr;
 }
 
-static void cxl_pci_unmap_regblock(struct cxl_mem *cxlm, void __iomem *base)
+static void cxl_pci_unmap_regblock(struct pci_dev *pdev, void __iomem *base)
 {
-	pci_iounmap(to_pci_dev(cxlm->dev), base);
+	pci_iounmap(pdev, base);
 }
 
 static int cxl_pci_dvsec(struct pci_dev *pdev, int dvsec)
@@ -360,12 +361,12 @@  static int cxl_pci_dvsec(struct pci_dev *pdev, int dvsec)
 	return 0;
 }
 
-static int cxl_probe_regs(struct cxl_mem *cxlm, void __iomem *base,
+static int cxl_probe_regs(struct pci_dev *pdev, void __iomem *base,
 			  struct cxl_register_map *map)
 {
 	struct cxl_component_reg_map *comp_map;
 	struct cxl_device_reg_map *dev_map;
-	struct device *dev = cxlm->dev;
+	struct device *dev = &pdev->dev;
 
 	switch (map->reg_type) {
 	case CXL_REGLOC_RBI_COMPONENT:
@@ -420,12 +421,13 @@  static int cxl_map_regs(struct cxl_mem *cxlm, struct cxl_register_map *map)
 	return 0;
 }
 
-static void cxl_decode_register_block(u32 reg_lo, u32 reg_hi,
-				      u8 *bar, u64 *offset, u8 *reg_type)
+static void cxl_decode_regblock(u32 reg_lo, u32 reg_hi,
+				struct cxl_register_map *map)
 {
-	*offset = ((u64)reg_hi << 32) | (reg_lo & CXL_REGLOC_ADDR_MASK);
-	*bar = FIELD_GET(CXL_REGLOC_BIR_MASK, reg_lo);
-	*reg_type = FIELD_GET(CXL_REGLOC_RBI_MASK, reg_lo);
+	map->block_offset =
+		((u64)reg_hi << 32) | (reg_lo & CXL_REGLOC_ADDR_MASK);
+	map->barno = FIELD_GET(CXL_REGLOC_BIR_MASK, reg_lo);
+	map->reg_type = FIELD_GET(CXL_REGLOC_RBI_MASK, reg_lo);
 }
 
 /**
@@ -462,34 +464,23 @@  static int cxl_pci_setup_regs(struct cxl_mem *cxlm)
 
 	for (i = 0, n_maps = 0; i < regblocks; i++, regloc += 8) {
 		u32 reg_lo, reg_hi;
-		u8 reg_type;
-		u64 offset;
-		u8 bar;
 
 		pci_read_config_dword(pdev, regloc, &reg_lo);
 		pci_read_config_dword(pdev, regloc + 4, &reg_hi);
 
-		cxl_decode_register_block(reg_lo, reg_hi, &bar, &offset,
-					  &reg_type);
+		map = &maps[n_maps];
+		cxl_decode_regblock(reg_lo, reg_hi, map);
 
 		/* Ignore unknown register block types */
-		if (reg_type > CXL_REGLOC_RBI_MEMDEV)
+		if (map->reg_type > CXL_REGLOC_RBI_MEMDEV)
 			continue;
 
-		base = cxl_pci_map_regblock(cxlm, bar, offset);
+		base = cxl_pci_map_regblock(pdev, map);
 		if (!base)
 			return -ENOMEM;
 
-		map = &maps[n_maps];
-		map->barno = bar;
-		map->block_offset = offset;
-		map->reg_type = reg_type;
-
-		ret = cxl_probe_regs(cxlm, base + offset, map);
-
-		/* Always unmap the regblock regardless of probe success */
-		cxl_pci_unmap_regblock(cxlm, base);
-
+		ret = cxl_probe_regs(pdev, base + map->block_offset, map);
+		cxl_pci_unmap_regblock(pdev, base);
 		if (ret)
 			return ret;