Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cxl/core/port: Remove @host argument for dport + decoder enumeration

Now that dport and decoder enumeration is centralized in the port
driver, the @host argument for these helpers can be made implicit. For
the root port the host is the port's uport device (ACPI0017 for
cxl_acpi), and for all other descendant ports the devm context is the
parent of @port.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Ben Widawsky <ben.widawsky@intel.com>
Link: https://lore.kernel.org/r/164375043390.484143.17617734732003230076.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>

+45 -54
+1 -1
drivers/cxl/acpi.c
··· 256 256 return 0; 257 257 } 258 258 259 - dport = devm_cxl_add_dport(host, root_port, match, uid, ctx.chbcr); 259 + dport = devm_cxl_add_dport(root_port, match, uid, ctx.chbcr); 260 260 if (IS_ERR(dport)) { 261 261 dev_err(host, "failed to add downstream port: %s\n", 262 262 dev_name(match));
+5 -7
drivers/cxl/core/hdm.c
··· 44 44 * are claimed and passed to the single dport. Disable the range until the first 45 45 * CXL region is enumerated / activated. 46 46 */ 47 - int devm_cxl_add_passthrough_decoder(struct device *host, struct cxl_port *port) 47 + int devm_cxl_add_passthrough_decoder(struct cxl_port *port) 48 48 { 49 49 struct cxl_decoder *cxld; 50 50 struct cxl_dport *dport; ··· 93 93 94 94 /** 95 95 * devm_cxl_setup_hdm - map HDM decoder component registers 96 - * @host: devm context for allocations 97 96 * @port: cxl_port to map 98 97 */ 99 - struct cxl_hdm *devm_cxl_setup_hdm(struct device *host, struct cxl_port *port) 98 + struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port) 100 99 { 101 100 struct device *dev = &port->dev; 102 101 void __iomem *crb, *hdm; 103 102 struct cxl_hdm *cxlhdm; 104 103 105 - cxlhdm = devm_kzalloc(host, sizeof(*cxlhdm), GFP_KERNEL); 104 + cxlhdm = devm_kzalloc(dev, sizeof(*cxlhdm), GFP_KERNEL); 106 105 if (!cxlhdm) 107 106 return ERR_PTR(-ENOMEM); 108 107 109 108 cxlhdm->port = port; 110 - crb = devm_cxl_iomap_block(host, port->component_reg_phys, 109 + crb = devm_cxl_iomap_block(dev, port->component_reg_phys, 111 110 CXL_COMPONENT_REG_BLOCK_SIZE); 112 111 if (!crb) { 113 112 dev_err(dev, "No component registers mapped\n"); ··· 194 195 195 196 /** 196 197 * devm_cxl_enumerate_decoders - add decoder objects per HDM register set 197 - * @host: devm allocation context 198 198 * @cxlhdm: Structure to populate with HDM capabilities 199 199 */ 200 - int devm_cxl_enumerate_decoders(struct device *host, struct cxl_hdm *cxlhdm) 200 + int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm) 201 201 { 202 202 void __iomem *hdm = cxlhdm->regs.hdm_decoder; 203 203 struct cxl_port *port = cxlhdm->port;
+2 -5
drivers/cxl/core/pci.c
··· 15 15 16 16 struct cxl_walk_context { 17 17 struct pci_bus *bus; 18 - struct device *host; 19 18 struct cxl_port *port; 20 19 int type; 21 20 int error; ··· 46 47 dev_dbg(&port->dev, "failed to find component registers\n"); 47 48 48 49 port_num = FIELD_GET(PCI_EXP_LNKCAP_PN, lnkcap); 49 - dport = devm_cxl_add_dport(ctx->host, port, &pdev->dev, port_num, 50 + dport = devm_cxl_add_dport(port, &pdev->dev, port_num, 50 51 cxl_regmap_to_base(pdev, &map)); 51 52 if (IS_ERR(dport)) { 52 53 ctx->error = PTR_ERR(dport); ··· 61 62 62 63 /** 63 64 * devm_cxl_port_enumerate_dports - enumerate downstream ports of the upstream port 64 - * @host: devm context 65 65 * @port: cxl_port whose ->uport is the upstream of dports to be enumerated 66 66 * 67 67 * Returns a positive number of dports enumerated or a negative error 68 68 * code. 69 69 */ 70 - int devm_cxl_port_enumerate_dports(struct device *host, struct cxl_port *port) 70 + int devm_cxl_port_enumerate_dports(struct cxl_port *port) 71 71 { 72 72 struct pci_bus *bus = cxl_port_to_pci_bus(port); 73 73 struct cxl_walk_context ctx; ··· 81 83 type = PCI_EXP_TYPE_DOWNSTREAM; 82 84 83 85 ctx = (struct cxl_walk_context) { 84 - .host = host, 85 86 .port = port, 86 87 .bus = bus, 87 88 .type = type,
+7 -2
drivers/cxl/core/port.c
··· 576 576 577 577 /** 578 578 * devm_cxl_add_dport - append downstream port data to a cxl_port 579 - * @host: devm context for allocations 580 579 * @port: the cxl_port that references this dport 581 580 * @dport_dev: firmware or PCI device representing the dport 582 581 * @port_id: identifier for this dport in a decoder's target list ··· 585 586 * either the port's host (for root ports), or the port itself (for 586 587 * switch ports) 587 588 */ 588 - struct cxl_dport *devm_cxl_add_dport(struct device *host, struct cxl_port *port, 589 + struct cxl_dport *devm_cxl_add_dport(struct cxl_port *port, 589 590 struct device *dport_dev, int port_id, 590 591 resource_size_t component_reg_phys) 591 592 { 592 593 char link_name[CXL_TARGET_STRLEN]; 593 594 struct cxl_dport *dport; 595 + struct device *host; 594 596 int rc; 597 + 598 + if (is_cxl_root(port)) 599 + host = port->uport; 600 + else 601 + host = &port->dev; 595 602 596 603 if (!host->driver) { 597 604 dev_WARN_ONCE(&port->dev, 1, "dport:%s bad devm context\n",
+4 -4
drivers/cxl/cxl.h
··· 313 313 resource_size_t component_reg_phys, 314 314 struct cxl_port *parent_port); 315 315 struct cxl_port *find_cxl_root(struct device *dev); 316 - struct cxl_dport *devm_cxl_add_dport(struct device *host, struct cxl_port *port, 316 + struct cxl_dport *devm_cxl_add_dport(struct cxl_port *port, 317 317 struct device *dport, int port_id, 318 318 resource_size_t component_reg_phys); 319 319 struct cxl_decoder *to_cxl_decoder(struct device *dev); ··· 327 327 int cxl_decoder_add_locked(struct cxl_decoder *cxld, int *target_map); 328 328 int cxl_decoder_autoremove(struct device *host, struct cxl_decoder *cxld); 329 329 struct cxl_hdm; 330 - struct cxl_hdm *devm_cxl_setup_hdm(struct device *host, struct cxl_port *port); 331 - int devm_cxl_enumerate_decoders(struct device *host, struct cxl_hdm *cxlhdm); 332 - int devm_cxl_add_passthrough_decoder(struct device *host, struct cxl_port *port); 330 + struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port); 331 + int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm); 332 + int devm_cxl_add_passthrough_decoder(struct cxl_port *port); 333 333 334 334 extern struct bus_type cxl_bus_type; 335 335
+1 -1
drivers/cxl/cxlpci.h
··· 58 58 return pci_resource_start(pdev, map->barno) + map->block_offset; 59 59 } 60 60 61 - int devm_cxl_port_enumerate_dports(struct device *host, struct cxl_port *port); 61 + int devm_cxl_port_enumerate_dports(struct cxl_port *port); 62 62 #endif /* __CXL_PCI_H__ */
+4 -4
drivers/cxl/port.c
··· 31 31 struct cxl_hdm *cxlhdm; 32 32 int rc; 33 33 34 - rc = devm_cxl_port_enumerate_dports(dev, port); 34 + rc = devm_cxl_port_enumerate_dports(port); 35 35 if (rc < 0) 36 36 return rc; 37 37 38 38 if (rc == 1) 39 - return devm_cxl_add_passthrough_decoder(dev, port); 39 + return devm_cxl_add_passthrough_decoder(port); 40 40 41 - cxlhdm = devm_cxl_setup_hdm(dev, port); 41 + cxlhdm = devm_cxl_setup_hdm(port); 42 42 if (IS_ERR(cxlhdm)) 43 43 return PTR_ERR(cxlhdm); 44 44 45 - rc = devm_cxl_enumerate_decoders(dev, cxlhdm); 45 + rc = devm_cxl_enumerate_decoders(cxlhdm); 46 46 if (rc) { 47 47 dev_err(dev, "Couldn't enumerate decoders (%d)\n", rc); 48 48 return rc;
+5 -9
tools/testing/cxl/test/cxl.c
··· 399 399 return &mock_pci_root[host_bridge_index(adev)]; 400 400 } 401 401 402 - static struct cxl_hdm *mock_cxl_setup_hdm(struct device *host, 403 - struct cxl_port *port) 402 + static struct cxl_hdm *mock_cxl_setup_hdm(struct cxl_port *port) 404 403 { 405 404 struct cxl_hdm *cxlhdm = devm_kzalloc(&port->dev, sizeof(*cxlhdm), GFP_KERNEL); 406 405 ··· 410 411 return cxlhdm; 411 412 } 412 413 413 - static int mock_cxl_add_passthrough_decoder(struct device *host, 414 - struct cxl_port *port) 414 + static int mock_cxl_add_passthrough_decoder(struct cxl_port *port) 415 415 { 416 416 dev_err(&port->dev, "unexpected passthrough decoder for cxl_test\n"); 417 417 return -EOPNOTSUPP; 418 418 } 419 419 420 - static int mock_cxl_enumerate_decoders(struct device *host, 421 - struct cxl_hdm *cxlhdm) 420 + static int mock_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm) 422 421 { 423 422 return 0; 424 423 } 425 424 426 - static int mock_cxl_port_enumerate_dports(struct device *host, 427 - struct cxl_port *port) 425 + static int mock_cxl_port_enumerate_dports(struct cxl_port *port) 428 426 { 429 427 struct device *dev = &port->dev; 430 428 int i; ··· 433 437 if (pdev->dev.parent != port->uport) 434 438 continue; 435 439 436 - dport = devm_cxl_add_dport(host, port, &pdev->dev, pdev->id, 440 + dport = devm_cxl_add_dport(port, &pdev->dev, pdev->id, 437 441 CXL_RESOURCE_NONE); 438 442 439 443 if (IS_ERR(dport)) {
+12 -16
tools/testing/cxl/test/mock.c
··· 131 131 } 132 132 EXPORT_SYMBOL_GPL(__wrap_nvdimm_bus_register); 133 133 134 - struct cxl_hdm *__wrap_devm_cxl_setup_hdm(struct device *host, 135 - struct cxl_port *port) 134 + struct cxl_hdm *__wrap_devm_cxl_setup_hdm(struct cxl_port *port) 136 135 { 137 136 int index; 138 137 struct cxl_hdm *cxlhdm; 139 138 struct cxl_mock_ops *ops = get_cxl_mock_ops(&index); 140 139 141 140 if (ops && ops->is_mock_port(port->uport)) 142 - cxlhdm = ops->devm_cxl_setup_hdm(host, port); 141 + cxlhdm = ops->devm_cxl_setup_hdm(port); 143 142 else 144 - cxlhdm = devm_cxl_setup_hdm(host, port); 143 + cxlhdm = devm_cxl_setup_hdm(port); 145 144 put_cxl_mock_ops(index); 146 145 147 146 return cxlhdm; 148 147 } 149 148 EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_setup_hdm, CXL); 150 149 151 - int __wrap_devm_cxl_add_passthrough_decoder(struct device *host, 152 - struct cxl_port *port) 150 + int __wrap_devm_cxl_add_passthrough_decoder(struct cxl_port *port) 153 151 { 154 152 int rc, index; 155 153 struct cxl_mock_ops *ops = get_cxl_mock_ops(&index); 156 154 157 155 if (ops && ops->is_mock_port(port->uport)) 158 - rc = ops->devm_cxl_add_passthrough_decoder(host, port); 156 + rc = ops->devm_cxl_add_passthrough_decoder(port); 159 157 else 160 - rc = devm_cxl_add_passthrough_decoder(host, port); 158 + rc = devm_cxl_add_passthrough_decoder(port); 161 159 put_cxl_mock_ops(index); 162 160 163 161 return rc; 164 162 } 165 163 EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_add_passthrough_decoder, CXL); 166 164 167 - int __wrap_devm_cxl_enumerate_decoders(struct device *host, 168 - struct cxl_hdm *cxlhdm) 165 + int __wrap_devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm) 169 166 { 170 167 int rc, index; 171 168 struct cxl_port *port = cxlhdm->port; 172 169 struct cxl_mock_ops *ops = get_cxl_mock_ops(&index); 173 170 174 171 if (ops && ops->is_mock_port(port->uport)) 175 - rc = ops->devm_cxl_enumerate_decoders(host, cxlhdm); 172 + rc = ops->devm_cxl_enumerate_decoders(cxlhdm); 176 173 else 177 - rc = devm_cxl_enumerate_decoders(host, cxlhdm); 174 + rc = devm_cxl_enumerate_decoders(cxlhdm); 178 175 put_cxl_mock_ops(index); 179 176 180 177 return rc; 181 178 } 182 179 EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_enumerate_decoders, CXL); 183 180 184 - int __wrap_devm_cxl_port_enumerate_dports(struct device *host, 185 - struct cxl_port *port) 181 + int __wrap_devm_cxl_port_enumerate_dports(struct cxl_port *port) 186 182 { 187 183 int rc, index; 188 184 struct cxl_mock_ops *ops = get_cxl_mock_ops(&index); 189 185 190 186 if (ops && ops->is_mock_port(port->uport)) 191 - rc = ops->devm_cxl_port_enumerate_dports(host, port); 187 + rc = ops->devm_cxl_port_enumerate_dports(port); 192 188 else 193 - rc = devm_cxl_port_enumerate_dports(host, port); 189 + rc = devm_cxl_port_enumerate_dports(port); 194 190 put_cxl_mock_ops(index); 195 191 196 192 return rc;
+4 -5
tools/testing/cxl/test/mock.h
··· 19 19 bool (*is_mock_bus)(struct pci_bus *bus); 20 20 bool (*is_mock_port)(struct device *dev); 21 21 bool (*is_mock_dev)(struct device *dev); 22 - int (*devm_cxl_port_enumerate_dports)(struct device *host, 23 - struct cxl_port *port); 24 - struct cxl_hdm *(*devm_cxl_setup_hdm)(struct device *host, struct cxl_port *port); 25 - int (*devm_cxl_add_passthrough_decoder)(struct device *host, struct cxl_port *port); 26 - int (*devm_cxl_enumerate_decoders)(struct device *host, struct cxl_hdm *hdm); 22 + int (*devm_cxl_port_enumerate_dports)(struct cxl_port *port); 23 + struct cxl_hdm *(*devm_cxl_setup_hdm)(struct cxl_port *port); 24 + int (*devm_cxl_add_passthrough_decoder)(struct cxl_port *port); 25 + int (*devm_cxl_enumerate_decoders)(struct cxl_hdm *hdm); 27 26 }; 28 27 29 28 void register_cxl_mock_ops(struct cxl_mock_ops *ops);