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

tools/testing/cxl: Add partition support

In support of testing DPA allocation mechanisms in the CXL core, the
cxl_test environment needs to support establishing and retrieving the
'pmem partition boundary.

Replace the platform_device_add_resources() method for delineating DPA
within an endpoint with an emulated DEV_SIZE amount of partitionable
capacity. Set DEV_SIZE such that an endpoint has enough capacity to
simultaneously participate in 8 distinct regions.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/165603887411.551046.13234212587991192347.stgit@dwillia2-xfh
Signed-off-by: Dan Williams <dan.j.williams@intel.com>

+39 -72
+1 -6
drivers/cxl/core/mbox.c
··· 718 718 */ 719 719 static int cxl_mem_get_partition_info(struct cxl_dev_state *cxlds) 720 720 { 721 - struct cxl_mbox_get_partition_info { 722 - __le64 active_volatile_cap; 723 - __le64 active_persistent_cap; 724 - __le64 next_volatile_cap; 725 - __le64 next_persistent_cap; 726 - } __packed pi; 721 + struct cxl_mbox_get_partition_info pi; 727 722 int rc; 728 723 729 724 rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_GET_PARTITION_INFO, NULL, 0,
+7
drivers/cxl/cxlmem.h
··· 301 301 u8 qos_telemetry_caps; 302 302 } __packed; 303 303 304 + struct cxl_mbox_get_partition_info { 305 + __le64 active_volatile_cap; 306 + __le64 active_persistent_cap; 307 + __le64 next_volatile_cap; 308 + __le64 next_persistent_cap; 309 + } __packed; 310 + 304 311 struct cxl_mbox_get_lsa { 305 312 __le32 offset; 306 313 __le32 length;
+1 -39
tools/testing/cxl/test/cxl.c
··· 569 569 #define SZ_512G (SZ_64G * 8) 570 570 #endif 571 571 572 - static struct platform_device *alloc_memdev(int id) 573 - { 574 - struct resource res[] = { 575 - [0] = { 576 - .flags = IORESOURCE_MEM, 577 - }, 578 - [1] = { 579 - .flags = IORESOURCE_MEM, 580 - .desc = IORES_DESC_PERSISTENT_MEMORY, 581 - }, 582 - }; 583 - struct platform_device *pdev; 584 - int i, rc; 585 - 586 - for (i = 0; i < ARRAY_SIZE(res); i++) { 587 - struct cxl_mock_res *r = alloc_mock_res(SZ_256M); 588 - 589 - if (!r) 590 - return NULL; 591 - res[i].start = r->range.start; 592 - res[i].end = r->range.end; 593 - } 594 - 595 - pdev = platform_device_alloc("cxl_mem", id); 596 - if (!pdev) 597 - return NULL; 598 - 599 - rc = platform_device_add_resources(pdev, res, ARRAY_SIZE(res)); 600 - if (rc) 601 - goto err; 602 - 603 - return pdev; 604 - 605 - err: 606 - platform_device_put(pdev); 607 - return NULL; 608 - } 609 - 610 572 static __init int cxl_test_init(void) 611 573 { 612 574 int rc, i; ··· 671 709 struct platform_device *dport = cxl_switch_dport[i]; 672 710 struct platform_device *pdev; 673 711 674 - pdev = alloc_memdev(i); 712 + pdev = platform_device_alloc("cxl_mem", i); 675 713 if (!pdev) 676 714 goto err_mem; 677 715 pdev->dev.parent = &dport->dev;
+30 -27
tools/testing/cxl/test/mem.c
··· 10 10 #include <cxlmem.h> 11 11 12 12 #define LSA_SIZE SZ_128K 13 + #define DEV_SIZE SZ_2G 13 14 #define EFFECT(x) (1U << x) 14 15 15 16 static struct cxl_cel_entry mock_cel[] = { ··· 24 23 }, 25 24 { 26 25 .opcode = cpu_to_le16(CXL_MBOX_OP_GET_LSA), 26 + .effect = cpu_to_le16(0), 27 + }, 28 + { 29 + .opcode = cpu_to_le16(CXL_MBOX_OP_GET_PARTITION_INFO), 27 30 .effect = cpu_to_le16(0), 28 31 }, 29 32 { ··· 102 97 103 98 static int mock_id(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) 104 99 { 105 - struct platform_device *pdev = to_platform_device(cxlds->dev); 106 100 struct cxl_mbox_identify id = { 107 101 .fw_revision = { "mock fw v1 " }, 108 102 .lsa_size = cpu_to_le32(LSA_SIZE), 109 - /* FIXME: Add partition support */ 110 - .partition_align = cpu_to_le64(0), 103 + .partition_align = 104 + cpu_to_le64(SZ_256M / CXL_CAPACITY_MULTIPLIER), 105 + .total_capacity = 106 + cpu_to_le64(DEV_SIZE / CXL_CAPACITY_MULTIPLIER), 111 107 }; 112 - u64 capacity = 0; 113 - int i; 114 108 115 109 if (cmd->size_out < sizeof(id)) 116 110 return -EINVAL; 117 111 118 - for (i = 0; i < 2; i++) { 119 - struct resource *res; 120 - 121 - res = platform_get_resource(pdev, IORESOURCE_MEM, i); 122 - if (!res) 123 - break; 124 - 125 - capacity += resource_size(res) / CXL_CAPACITY_MULTIPLIER; 126 - 127 - if (le64_to_cpu(id.partition_align)) 128 - continue; 129 - 130 - if (res->desc == IORES_DESC_PERSISTENT_MEMORY) 131 - id.persistent_capacity = cpu_to_le64( 132 - resource_size(res) / CXL_CAPACITY_MULTIPLIER); 133 - else 134 - id.volatile_capacity = cpu_to_le64( 135 - resource_size(res) / CXL_CAPACITY_MULTIPLIER); 136 - } 137 - 138 - id.total_capacity = cpu_to_le64(capacity); 139 - 140 112 memcpy(cmd->payload_out, &id, sizeof(id)); 113 + 114 + return 0; 115 + } 116 + 117 + static int mock_partition_info(struct cxl_dev_state *cxlds, 118 + struct cxl_mbox_cmd *cmd) 119 + { 120 + struct cxl_mbox_get_partition_info pi = { 121 + .active_volatile_cap = 122 + cpu_to_le64(DEV_SIZE / 2 / CXL_CAPACITY_MULTIPLIER), 123 + .active_persistent_cap = 124 + cpu_to_le64(DEV_SIZE / 2 / CXL_CAPACITY_MULTIPLIER), 125 + }; 126 + 127 + if (cmd->size_out < sizeof(pi)) 128 + return -EINVAL; 129 + 130 + memcpy(cmd->payload_out, &pi, sizeof(pi)); 141 131 142 132 return 0; 143 133 } ··· 220 220 break; 221 221 case CXL_MBOX_OP_GET_LSA: 222 222 rc = mock_get_lsa(cxlds, cmd); 223 + break; 224 + case CXL_MBOX_OP_GET_PARTITION_INFO: 225 + rc = mock_partition_info(cxlds, cmd); 223 226 break; 224 227 case CXL_MBOX_OP_SET_LSA: 225 228 rc = mock_set_lsa(cxlds, cmd);