Commit 4752876c authored by Christophe Lombard's avatar Christophe Lombard Committed by Michael Ellerman

cxl: sysfs support for guests

Filter out a few adapter parameters which don't make sense in a guest.
Document the changes.
Co-authored-by: default avatarFrederic Barrat <fbarrat@linux.vnet.ibm.com>
Signed-off-by: default avatarFrederic Barrat <fbarrat@linux.vnet.ibm.com>
Signed-off-by: default avatarChristophe Lombard <clombard@linux.vnet.ibm.com>
Reviewed-by: default avatarManoj Kumar <manoj@linux.vnet.ibm.com>
Acked-by: default avatarIan Munsie <imunsie@au1.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 14baf4d9
...@@ -159,7 +159,7 @@ Description: read only ...@@ -159,7 +159,7 @@ Description: read only
Decimal value of the Per Process MMIO space length. Decimal value of the Per Process MMIO space length.
Users: https://github.com/ibm-capi/libcxl Users: https://github.com/ibm-capi/libcxl
What: /sys/class/cxl/<afu>m/pp_mmio_off What: /sys/class/cxl/<afu>m/pp_mmio_off (not in a guest)
Date: September 2014 Date: September 2014
Contact: linuxppc-dev@lists.ozlabs.org Contact: linuxppc-dev@lists.ozlabs.org
Description: read only Description: read only
...@@ -183,7 +183,7 @@ Description: read only ...@@ -183,7 +183,7 @@ Description: read only
Identifies the revision level of the PSL. Identifies the revision level of the PSL.
Users: https://github.com/ibm-capi/libcxl Users: https://github.com/ibm-capi/libcxl
What: /sys/class/cxl/<card>/base_image What: /sys/class/cxl/<card>/base_image (not in a guest)
Date: September 2014 Date: September 2014
Contact: linuxppc-dev@lists.ozlabs.org Contact: linuxppc-dev@lists.ozlabs.org
Description: read only Description: read only
...@@ -193,7 +193,7 @@ Description: read only ...@@ -193,7 +193,7 @@ Description: read only
during the initial program load. during the initial program load.
Users: https://github.com/ibm-capi/libcxl Users: https://github.com/ibm-capi/libcxl
What: /sys/class/cxl/<card>/image_loaded What: /sys/class/cxl/<card>/image_loaded (not in a guest)
Date: September 2014 Date: September 2014
Contact: linuxppc-dev@lists.ozlabs.org Contact: linuxppc-dev@lists.ozlabs.org
Description: read only Description: read only
...@@ -201,7 +201,7 @@ Description: read only ...@@ -201,7 +201,7 @@ Description: read only
onto the card. onto the card.
Users: https://github.com/ibm-capi/libcxl Users: https://github.com/ibm-capi/libcxl
What: /sys/class/cxl/<card>/load_image_on_perst What: /sys/class/cxl/<card>/load_image_on_perst (not in a guest)
Date: December 2014 Date: December 2014
Contact: linuxppc-dev@lists.ozlabs.org Contact: linuxppc-dev@lists.ozlabs.org
Description: read/write Description: read/write
...@@ -224,7 +224,7 @@ Description: write only ...@@ -224,7 +224,7 @@ Description: write only
to reload the FPGA depending on load_image_on_perst. to reload the FPGA depending on load_image_on_perst.
Users: https://github.com/ibm-capi/libcxl Users: https://github.com/ibm-capi/libcxl
What: /sys/class/cxl/<card>/perst_reloads_same_image What: /sys/class/cxl/<card>/perst_reloads_same_image (not in a guest)
Date: July 2015 Date: July 2015
Contact: linuxppc-dev@lists.ozlabs.org Contact: linuxppc-dev@lists.ozlabs.org
Description: read/write Description: read/write
......
...@@ -336,6 +336,12 @@ enum prefault_modes { ...@@ -336,6 +336,12 @@ enum prefault_modes {
CXL_PREFAULT_ALL, CXL_PREFAULT_ALL,
}; };
enum cxl_attrs {
CXL_ADAPTER_ATTRS,
CXL_AFU_MASTER_ATTRS,
CXL_AFU_ATTRS,
};
struct cxl_sste { struct cxl_sste {
__be64 esid_data; __be64 esid_data;
__be64 vsid_data; __be64 vsid_data;
...@@ -844,6 +850,7 @@ struct cxl_backend_ops { ...@@ -844,6 +850,7 @@ struct cxl_backend_ops {
int (*attach_process)(struct cxl_context *ctx, bool kernel, int (*attach_process)(struct cxl_context *ctx, bool kernel,
u64 wed, u64 amr); u64 wed, u64 amr);
int (*detach_process)(struct cxl_context *ctx); int (*detach_process)(struct cxl_context *ctx);
bool (*support_attributes)(const char *attr_name, enum cxl_attrs type);
bool (*link_ok)(struct cxl *cxl); bool (*link_ok)(struct cxl *cxl);
void (*release_afu)(struct device *dev); void (*release_afu)(struct device *dev);
ssize_t (*afu_read_err_buffer)(struct cxl_afu *afu, char *buf, ssize_t (*afu_read_err_buffer)(struct cxl_afu *afu, char *buf,
......
...@@ -596,6 +596,30 @@ static int guest_afu_check_and_enable(struct cxl_afu *afu) ...@@ -596,6 +596,30 @@ static int guest_afu_check_and_enable(struct cxl_afu *afu)
return 0; return 0;
} }
static bool guest_support_attributes(const char *attr_name,
enum cxl_attrs type)
{
switch (type) {
case CXL_ADAPTER_ATTRS:
if ((strcmp(attr_name, "base_image") == 0) ||
(strcmp(attr_name, "load_image_on_perst") == 0) ||
(strcmp(attr_name, "perst_reloads_same_image") == 0) ||
(strcmp(attr_name, "image_loaded") == 0))
return false;
break;
case CXL_AFU_MASTER_ATTRS:
if ((strcmp(attr_name, "pp_mmio_off") == 0))
return false;
break;
case CXL_AFU_ATTRS:
break;
default:
break;
}
return true;
}
static int activate_afu_directed(struct cxl_afu *afu) static int activate_afu_directed(struct cxl_afu *afu)
{ {
int rc; int rc;
...@@ -936,6 +960,7 @@ const struct cxl_backend_ops cxl_guest_ops = { ...@@ -936,6 +960,7 @@ const struct cxl_backend_ops cxl_guest_ops = {
.ack_irq = guest_ack_irq, .ack_irq = guest_ack_irq,
.attach_process = guest_attach_process, .attach_process = guest_attach_process,
.detach_process = guest_detach_process, .detach_process = guest_detach_process,
.support_attributes = guest_support_attributes,
.link_ok = guest_link_ok, .link_ok = guest_link_ok,
.release_afu = guest_release_afu, .release_afu = guest_release_afu,
.afu_read_err_buffer = guest_afu_read_err_buffer, .afu_read_err_buffer = guest_afu_read_err_buffer,
......
...@@ -967,6 +967,12 @@ int cxl_check_error(struct cxl_afu *afu) ...@@ -967,6 +967,12 @@ int cxl_check_error(struct cxl_afu *afu)
return (cxl_p1n_read(afu, CXL_PSL_SCNTL_An) == ~0ULL); return (cxl_p1n_read(afu, CXL_PSL_SCNTL_An) == ~0ULL);
} }
static bool native_support_attributes(const char *attr_name,
enum cxl_attrs type)
{
return true;
}
static int native_afu_cr_read64(struct cxl_afu *afu, int cr, u64 off, u64 *out) static int native_afu_cr_read64(struct cxl_afu *afu, int cr, u64 off, u64 *out)
{ {
if (unlikely(!cxl_ops->link_ok(afu->adapter))) if (unlikely(!cxl_ops->link_ok(afu->adapter)))
...@@ -1026,6 +1032,7 @@ const struct cxl_backend_ops cxl_native_ops = { ...@@ -1026,6 +1032,7 @@ const struct cxl_backend_ops cxl_native_ops = {
.ack_irq = native_ack_irq, .ack_irq = native_ack_irq,
.attach_process = native_attach_process, .attach_process = native_attach_process,
.detach_process = native_detach_process, .detach_process = native_detach_process,
.support_attributes = native_support_attributes,
.link_ok = cxl_adapter_link_ok, .link_ok = cxl_adapter_link_ok,
.release_afu = cxl_pci_release_afu, .release_afu = cxl_pci_release_afu,
.afu_read_err_buffer = cxl_pci_afu_read_err_buffer, .afu_read_err_buffer = cxl_pci_afu_read_err_buffer,
......
...@@ -253,8 +253,14 @@ static ssize_t irqs_max_store(struct device *device, ...@@ -253,8 +253,14 @@ static ssize_t irqs_max_store(struct device *device,
if (irqs_max < afu->pp_irqs) if (irqs_max < afu->pp_irqs)
return -EINVAL; return -EINVAL;
if (irqs_max > afu->adapter->user_irqs) if (cpu_has_feature(CPU_FTR_HVMODE)) {
return -EINVAL; if (irqs_max > afu->adapter->user_irqs)
return -EINVAL;
} else {
/* pHyp sets a per-AFU limit */
if (irqs_max > afu->guest->max_ints)
return -EINVAL;
}
afu->irqs_max = irqs_max; afu->irqs_max = irqs_max;
return count; return count;
...@@ -406,24 +412,39 @@ static struct device_attribute afu_attrs[] = { ...@@ -406,24 +412,39 @@ static struct device_attribute afu_attrs[] = {
int cxl_sysfs_adapter_add(struct cxl *adapter) int cxl_sysfs_adapter_add(struct cxl *adapter)
{ {
struct device_attribute *dev_attr;
int i, rc; int i, rc;
for (i = 0; i < ARRAY_SIZE(adapter_attrs); i++) { for (i = 0; i < ARRAY_SIZE(adapter_attrs); i++) {
if ((rc = device_create_file(&adapter->dev, &adapter_attrs[i]))) dev_attr = &adapter_attrs[i];
goto err; if (cxl_ops->support_attributes(dev_attr->attr.name,
CXL_ADAPTER_ATTRS)) {
if ((rc = device_create_file(&adapter->dev, dev_attr)))
goto err;
}
} }
return 0; return 0;
err: err:
for (i--; i >= 0; i--) for (i--; i >= 0; i--) {
device_remove_file(&adapter->dev, &adapter_attrs[i]); dev_attr = &adapter_attrs[i];
if (cxl_ops->support_attributes(dev_attr->attr.name,
CXL_ADAPTER_ATTRS))
device_remove_file(&adapter->dev, dev_attr);
}
return rc; return rc;
} }
void cxl_sysfs_adapter_remove(struct cxl *adapter) void cxl_sysfs_adapter_remove(struct cxl *adapter)
{ {
struct device_attribute *dev_attr;
int i; int i;
for (i = 0; i < ARRAY_SIZE(adapter_attrs); i++) for (i = 0; i < ARRAY_SIZE(adapter_attrs); i++) {
device_remove_file(&adapter->dev, &adapter_attrs[i]); dev_attr = &adapter_attrs[i];
if (cxl_ops->support_attributes(dev_attr->attr.name,
CXL_ADAPTER_ATTRS))
device_remove_file(&adapter->dev, dev_attr);
}
} }
struct afu_config_record { struct afu_config_record {
...@@ -534,7 +555,7 @@ static struct afu_config_record *cxl_sysfs_afu_new_cr(struct cxl_afu *afu, int c ...@@ -534,7 +555,7 @@ static struct afu_config_record *cxl_sysfs_afu_new_cr(struct cxl_afu *afu, int c
/* /*
* Export raw AFU PCIe like config record. For now this is read only by * Export raw AFU PCIe like config record. For now this is read only by
* root - we can expand that later to be readable by non-root and maybe * root - we can expand that later to be readable by non-root and maybe
* even writable provided we have a good use-case. Once we suport * even writable provided we have a good use-case. Once we support
* exposing AFUs through a virtual PHB they will get that for free from * exposing AFUs through a virtual PHB they will get that for free from
* Linux' PCI infrastructure, but until then it's not clear that we * Linux' PCI infrastructure, but until then it's not clear that we
* need it for anything since the main use case is just identifying * need it for anything since the main use case is just identifying
...@@ -572,6 +593,7 @@ static struct afu_config_record *cxl_sysfs_afu_new_cr(struct cxl_afu *afu, int c ...@@ -572,6 +593,7 @@ static struct afu_config_record *cxl_sysfs_afu_new_cr(struct cxl_afu *afu, int c
void cxl_sysfs_afu_remove(struct cxl_afu *afu) void cxl_sysfs_afu_remove(struct cxl_afu *afu)
{ {
struct device_attribute *dev_attr;
struct afu_config_record *cr, *tmp; struct afu_config_record *cr, *tmp;
int i; int i;
...@@ -579,8 +601,12 @@ void cxl_sysfs_afu_remove(struct cxl_afu *afu) ...@@ -579,8 +601,12 @@ void cxl_sysfs_afu_remove(struct cxl_afu *afu)
if (afu->eb_len) if (afu->eb_len)
device_remove_bin_file(&afu->dev, &afu->attr_eb); device_remove_bin_file(&afu->dev, &afu->attr_eb);
for (i = 0; i < ARRAY_SIZE(afu_attrs); i++) for (i = 0; i < ARRAY_SIZE(afu_attrs); i++) {
device_remove_file(&afu->dev, &afu_attrs[i]); dev_attr = &afu_attrs[i];
if (cxl_ops->support_attributes(dev_attr->attr.name,
CXL_AFU_ATTRS))
device_remove_file(&afu->dev, &afu_attrs[i]);
}
list_for_each_entry_safe(cr, tmp, &afu->crs, list) { list_for_each_entry_safe(cr, tmp, &afu->crs, list) {
sysfs_remove_bin_file(&cr->kobj, &cr->config_attr); sysfs_remove_bin_file(&cr->kobj, &cr->config_attr);
...@@ -590,14 +616,19 @@ void cxl_sysfs_afu_remove(struct cxl_afu *afu) ...@@ -590,14 +616,19 @@ void cxl_sysfs_afu_remove(struct cxl_afu *afu)
int cxl_sysfs_afu_add(struct cxl_afu *afu) int cxl_sysfs_afu_add(struct cxl_afu *afu)
{ {
struct device_attribute *dev_attr;
struct afu_config_record *cr; struct afu_config_record *cr;
int i, rc; int i, rc;
INIT_LIST_HEAD(&afu->crs); INIT_LIST_HEAD(&afu->crs);
for (i = 0; i < ARRAY_SIZE(afu_attrs); i++) { for (i = 0; i < ARRAY_SIZE(afu_attrs); i++) {
if ((rc = device_create_file(&afu->dev, &afu_attrs[i]))) dev_attr = &afu_attrs[i];
goto err; if (cxl_ops->support_attributes(dev_attr->attr.name,
CXL_AFU_ATTRS)) {
if ((rc = device_create_file(&afu->dev, &afu_attrs[i])))
goto err;
}
} }
/* conditionally create the add the binary file for error info buffer */ /* conditionally create the add the binary file for error info buffer */
...@@ -636,32 +667,50 @@ int cxl_sysfs_afu_add(struct cxl_afu *afu) ...@@ -636,32 +667,50 @@ int cxl_sysfs_afu_add(struct cxl_afu *afu)
/* reset the eb_len as we havent created the bin attr */ /* reset the eb_len as we havent created the bin attr */
afu->eb_len = 0; afu->eb_len = 0;
for (i--; i >= 0; i--) for (i--; i >= 0; i--) {
dev_attr = &afu_attrs[i];
if (cxl_ops->support_attributes(dev_attr->attr.name,
CXL_AFU_ATTRS))
device_remove_file(&afu->dev, &afu_attrs[i]); device_remove_file(&afu->dev, &afu_attrs[i]);
}
return rc; return rc;
} }
int cxl_sysfs_afu_m_add(struct cxl_afu *afu) int cxl_sysfs_afu_m_add(struct cxl_afu *afu)
{ {
struct device_attribute *dev_attr;
int i, rc; int i, rc;
for (i = 0; i < ARRAY_SIZE(afu_master_attrs); i++) { for (i = 0; i < ARRAY_SIZE(afu_master_attrs); i++) {
if ((rc = device_create_file(afu->chardev_m, &afu_master_attrs[i]))) dev_attr = &afu_master_attrs[i];
goto err; if (cxl_ops->support_attributes(dev_attr->attr.name,
CXL_AFU_MASTER_ATTRS)) {
if ((rc = device_create_file(afu->chardev_m, &afu_master_attrs[i])))
goto err;
}
} }
return 0; return 0;
err: err:
for (i--; i >= 0; i--) for (i--; i >= 0; i--) {
device_remove_file(afu->chardev_m, &afu_master_attrs[i]); dev_attr = &afu_master_attrs[i];
if (cxl_ops->support_attributes(dev_attr->attr.name,
CXL_AFU_MASTER_ATTRS))
device_remove_file(afu->chardev_m, &afu_master_attrs[i]);
}
return rc; return rc;
} }
void cxl_sysfs_afu_m_remove(struct cxl_afu *afu) void cxl_sysfs_afu_m_remove(struct cxl_afu *afu)
{ {
struct device_attribute *dev_attr;
int i; int i;
for (i = 0; i < ARRAY_SIZE(afu_master_attrs); i++) for (i = 0; i < ARRAY_SIZE(afu_master_attrs); i++) {
device_remove_file(afu->chardev_m, &afu_master_attrs[i]); dev_attr = &afu_master_attrs[i];
if (cxl_ops->support_attributes(dev_attr->attr.name,
CXL_AFU_MASTER_ATTRS))
device_remove_file(afu->chardev_m, &afu_master_attrs[i]);
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment