Skip to contentSkip to conversation

drm/amdgpu: Expose ras version & schema info

PATCH In review Asad Kamal 3 participants 3 messages Oct 11, 2023 – Oct 12, 2023

Subsystems (2)
lore
Share & tools
lore

Asad Kamal

author
#0 lore raw

PATCH v2 1/1 drm/amdgpu: Expose ras version & schema info

Expose ras table version & schema info to sysfs

v2: Updated schema to get poison support info
from ras context, removed asic specific checks

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 51 +++++++++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  3 ++
 2 files changed, 51 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +48 -3
index 9c8203e87859..cb9e48fb40d2 100644
@@ -1370,6 +1370,22 @@ static ssize_t amdgpu_ras_sysfs_features_read(struct device *dev,
 	return sysfs_emit(buf, "feature mask: 0x%x\n", con->features);
 }
 
+static ssize_t amdgpu_ras_sysfs_version_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct amdgpu_ras *con =
+		container_of(attr, struct amdgpu_ras, version_attr);
+	return sysfs_emit(buf, "table version: 0x%x\n", con->eeprom_control.tbl_hdr.version);
+}
+
+static ssize_t amdgpu_ras_sysfs_schema_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct amdgpu_ras *con =
+		container_of(attr, struct amdgpu_ras, schema_attr);
+	return sysfs_emit(buf, "schema: 0x%x\n", con->schema);
+}
+
 static void amdgpu_ras_sysfs_remove_bad_page_node(struct amdgpu_device *adev)
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
@@ -1379,11 +1395,13 @@ static void amdgpu_ras_sysfs_remove_bad_page_node(struct amdgpu_device *adev)
 				RAS_FS_NAME);
 }
 
-static int amdgpu_ras_sysfs_remove_feature_node(struct amdgpu_device *adev)
+static int amdgpu_ras_sysfs_remove_dev_attr_node(struct amdgpu_device *adev)
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
 	struct attribute *attrs[] = {
 		&con->features_attr.attr,
+		&con->version_attr.attr,
+		&con->schema_attr.attr,
 		NULL
 	};
 	struct attribute_group group = {
@@ -1459,7 +1477,7 @@ static int amdgpu_ras_sysfs_remove_all(struct amdgpu_device *adev)
 	if (amdgpu_bad_page_threshold != 0)
 		amdgpu_ras_sysfs_remove_bad_page_node(adev);
 
-	amdgpu_ras_sysfs_remove_feature_node(adev);
+	amdgpu_ras_sysfs_remove_dev_attr_node(adev);
 
 	return 0;
 }
@@ -1582,6 +1600,10 @@ static BIN_ATTR(gpu_vram_bad_pages, S_IRUGO,
 		amdgpu_ras_sysfs_badpages_read, NULL, 0);
 static DEVICE_ATTR(features, S_IRUGO,
 		amdgpu_ras_sysfs_features_read, NULL);
+static DEVICE_ATTR(version, 0444,
+		amdgpu_ras_sysfs_version_show, NULL);
+static DEVICE_ATTR(schema, 0444,
+		amdgpu_ras_sysfs_schema_show, NULL);
 static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
@@ -1590,6 +1612,8 @@ static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
 	};
 	struct attribute *attrs[] = {
 		&con->features_attr.attr,
+		&con->version_attr.attr,
+		&con->schema_attr.attr,
 		NULL
 	};
 	struct bin_attribute *bin_attrs[] = {
@@ -1598,11 +1622,20 @@ static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
 	};
 	int r;
 
+	group.attrs = attrs;
+
 	/* add features entry */
 	con->features_attr = dev_attr_features;
-	group.attrs = attrs;
 	sysfs_attr_init(attrs[0]);
 
+	/* add version entry */
+	con->version_attr = dev_attr_version;
+	sysfs_attr_init(attrs[1]);
+
+	/* add schema entry */
+	con->schema_attr = dev_attr_schema;
+	sysfs_attr_init(attrs[2]);
+
 	if (amdgpu_bad_page_threshold != 0) {
 		/* add bad_page_features entry */
 		bin_attr_gpu_vram_bad_pages.private = NULL;
@@ -2594,6 +2627,14 @@ static void amdgpu_ras_query_poison_mode(struct amdgpu_device *adev)
 	}
 }
 
+static int amdgpu_get_ras_schema(struct amdgpu_device *adev)
+{
+	return  (amdgpu_ras_is_poison_mode_supported(adev) << (ffs(AMDGPU_RAS_ERROR__POISON) - 1)) |
+			AMDGPU_RAS_ERROR__SINGLE_CORRECTABLE |
+			AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE |
+			AMDGPU_RAS_ERROR__PARITY;
+}
+
 int amdgpu_ras_init(struct amdgpu_device *adev)
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
@@ -2636,6 +2677,7 @@ int amdgpu_ras_init(struct amdgpu_device *adev)
 
 	con->update_channel_flag = false;
 	con->features = 0;
+	con->schema = 0;
 	INIT_LIST_HEAD(&con->head);
 	/* Might need get this flag from vbios. */
 	con->flags = RAS_DEFAULT_FLAGS;
@@ -2691,6 +2733,9 @@ int amdgpu_ras_init(struct amdgpu_device *adev)
 
 	amdgpu_ras_query_poison_mode(adev);
 
+	/* Get RAS schema for particular SOC */
+	con->schema = amdgpu_get_ras_schema(adev);
+
 	if (amdgpu_ras_fs_init(adev)) {
 		r = -EINVAL;
 		goto release_con;
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +3 -0
index 7999d202c9bc..728f98c6fc1c 100644
@@ -389,9 +389,12 @@ struct amdgpu_ras {
 	/* ras infrastructure */
 	/* for ras itself. */
 	uint32_t features;
+	uint32_t schema;
 	struct list_head head;
 	/* sysfs */
 	struct device_attribute features_attr;
+	struct device_attribute version_attr;
+	struct device_attribute schema_attr;
 	struct bin_attribute badpages_attr;
 	struct dentry *de_ras_eeprom_table;
 	/* block array */
Signature · 1 line
2.42.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Asad Kamal

Expose ras table version & schema info to sysfs

v2: Updated schema to get poison support info
from ras context, removed asic specific checks

One nit inline. With/without that change,

Quoted 100 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 51 +++++++++++++++++++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  3 ++
  2 files changed, 51 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +19 -1
index 9c8203e87859..cb9e48fb40d2 100644
@@ -1370,6 +1370,22 @@ static ssize_t amdgpu_ras_sysfs_features_read(struct device *dev,
  	return sysfs_emit(buf, "feature mask: 0x%x\n", con->features);
  }
 
+static ssize_t amdgpu_ras_sysfs_version_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct amdgpu_ras *con =
+		container_of(attr, struct amdgpu_ras, version_attr);
+	return sysfs_emit(buf, "table version: 0x%x\n", con->eeprom_control.tbl_hdr.version);
+}
+
+static ssize_t amdgpu_ras_sysfs_schema_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct amdgpu_ras *con =
+		container_of(attr, struct amdgpu_ras, schema_attr);
+	return sysfs_emit(buf, "schema: 0x%x\n", con->schema);
+}
+
  static void amdgpu_ras_sysfs_remove_bad_page_node(struct amdgpu_device *adev)
  {
  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
@@ -1379,11 +1395,13 @@ static void amdgpu_ras_sysfs_remove_bad_page_node(struct amdgpu_device *adev)
  				RAS_FS_NAME);
  }
 
-static int amdgpu_ras_sysfs_remove_feature_node(struct amdgpu_device *adev)
+static int amdgpu_ras_sysfs_remove_dev_attr_node(struct amdgpu_device *adev)
  {
  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
  	struct attribute *attrs[] = {
  		&con->features_attr.attr,
+		&con->version_attr.attr,
 
+		&con->schema_attr.attr,
  		NULL
  	};
  	struct attribute_group group = {
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +17 -2
@@ -1459,7 +1477,7 @@ static int amdgpu_ras_sysfs_remove_all(struct amdgpu_device *adev)
  	if (amdgpu_bad_page_threshold != 0)
  		amdgpu_ras_sysfs_remove_bad_page_node(adev);
 
-	amdgpu_ras_sysfs_remove_feature_node(adev);
+	amdgpu_ras_sysfs_remove_dev_attr_node(adev);
 
  	return 0;
  }
@@ -1582,6 +1600,10 @@ static BIN_ATTR(gpu_vram_bad_pages, S_IRUGO,
  		amdgpu_ras_sysfs_badpages_read, NULL, 0);
  static DEVICE_ATTR(features, S_IRUGO,
  		amdgpu_ras_sysfs_features_read, NULL);
+static DEVICE_ATTR(version, 0444,
+		amdgpu_ras_sysfs_version_show, NULL);
+static DEVICE_ATTR(schema, 0444,
+		amdgpu_ras_sysfs_schema_show, NULL);
  static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
  {
  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
@@ -1590,6 +1612,8 @@ static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
  	};
  	struct attribute *attrs[] = {
  		&con->features_attr.attr,
+		&con->version_attr.attr,
+		&con->schema_attr.attr,
  		NULL
  	};
  	struct bin_attribute *bin_attrs[] = {
@@ -1598,11 +1622,20 @@ static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
  	};
  	int r;
 
+	group.attrs = attrs;
+
  	/* add features entry */
  	con->features_attr = dev_attr_features;
-	group.attrs = attrs;
  	sysfs_attr_init(attrs[0]);
 
+	/* add version entry */
+	con->version_attr = dev_attr_version;
+	sysfs_attr_init(attrs[1]);
+
+	/* add schema entry */
+	con->schema_attr = dev_attr_schema;
+	sysfs_attr_init(attrs[2]);
+
  	if (amdgpu_bad_page_threshold != 0) {
  		/* add bad_page_features entry */
  		bin_attr_gpu_vram_bad_pages.private = NULL;

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c static void amdgpu_ras_query_poison_mode(struct amdgpu_device *adev) · line 2632

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +3 -0
@@ -2594,6 +2627,14 @@ static void amdgpu_ras_query_poison_mode(struct amdgpu_device *adev)
  	}
  }
 
+static int amdgpu_get_ras_schema(struct amdgpu_device *adev)
+{
+	return  (amdgpu_ras_is_poison_mode_supported(adev) << (ffs(AMDGPU_RAS_ERROR__POISON) - 1)) |

It's simpler and more readable with a ternary operator.

Thanks,
Lijo

Quoted 43 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +9 -0
+			AMDGPU_RAS_ERROR__SINGLE_CORRECTABLE |
+			AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE |
+			AMDGPU_RAS_ERROR__PARITY;
+}
+
  int amdgpu_ras_init(struct amdgpu_device *adev)
  {
  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
@@ -2636,6 +2677,7 @@ int amdgpu_ras_init(struct amdgpu_device *adev)
 
  	con->update_channel_flag = false;
  	con->features = 0;
+	con->schema = 0;
  	INIT_LIST_HEAD(&con->head);
  	/* Might need get this flag from vbios. */
  	con->flags = RAS_DEFAULT_FLAGS;
@@ -2691,6 +2733,9 @@ int amdgpu_ras_init(struct amdgpu_device *adev)
 
  	amdgpu_ras_query_poison_mode(adev);
 
+	/* Get RAS schema for particular SOC */
+	con->schema = amdgpu_get_ras_schema(adev);
+
  	if (amdgpu_ras_fs_init(adev)) {
  		r = -EINVAL;
  		goto release_con;
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +3 -0
index 7999d202c9bc..728f98c6fc1c 100644
@@ -389,9 +389,12 @@ struct amdgpu_ras {
  	/* ras infrastructure */
  	/* for ras itself. */
  	uint32_t features;
+	uint32_t schema;
  	struct list_head head;
  	/* sysfs */
  	struct device_attribute features_attr;
+	struct device_attribute version_attr;
+	struct device_attribute schema_attr;
  	struct bin_attribute badpages_attr;
  	struct dentry *de_ras_eeprom_table;
  	/* block array */
Reviewed-by Lijo Lazar
#2 lore raw

Tip:

ffs(AMDGPU_RAS_ERROR__POISON) - 1) == __ffs(AMDGPU_RAS_ERROR__POISON) if you want to get a value which start from 0, you can use __ffs() directly.

Best Regards,
Kevin

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Lazar, Lijo
Sent: Wednesday, October 11, 2023 5:58 PM
To: Kamal, Asad <[email protected]>; [email protected]
Cc: Ma, Le <[email protected]>; Zhang, Morris <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: Expose ras version & schema info

Quoted 6 lines · Asad Kamal

Expose ras table version & schema info to sysfs

v2: Updated schema to get poison support info from ras context, removed asic specific checks

One nit inline. With/without that change,

Quoted 104 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 51 +++++++++++++++++++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  3 ++
  2 files changed, 51 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +15 -1
index 9c8203e87859..cb9e48fb40d2 100644
@@ -1370,6 +1370,22 @@ static ssize_t amdgpu_ras_sysfs_features_read(struct device *dev,
  	return sysfs_emit(buf, "feature mask: 0x%x\n", con->features);
  }
 
+static ssize_t amdgpu_ras_sysfs_version_show(struct device *dev,
+		struct device_attribute *attr, char *buf) {
+	struct amdgpu_ras *con =
+		container_of(attr, struct amdgpu_ras, version_attr);
+	return sysfs_emit(buf, "table version: 0x%x\n", 
+con->eeprom_control.tbl_hdr.version);
+}
+
+static ssize_t amdgpu_ras_sysfs_schema_show(struct device *dev,
+		struct device_attribute *attr, char *buf) {
+	struct amdgpu_ras *con =
+		container_of(attr, struct amdgpu_ras, schema_attr);
+	return sysfs_emit(buf, "schema: 0x%x\n", con->schema); }
+
  static void amdgpu_ras_sysfs_remove_bad_page_node(struct amdgpu_device *adev)
  {
  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev); @@ -1379,11 
+1395,13 @@ static void amdgpu_ras_sysfs_remove_bad_page_node(struct amdgpu_device *adev)
  				RAS_FS_NAME);
  }
 
-static int amdgpu_ras_sysfs_remove_feature_node(struct amdgpu_device 

*adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +12 -1
+static int amdgpu_ras_sysfs_remove_dev_attr_node(struct amdgpu_device 
+*adev)
  {
  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
  	struct attribute *attrs[] = {
  		&con->features_attr.attr,
+		&con->version_attr.attr,
 
+		&con->schema_attr.attr,
  		NULL
  	};
  	struct attribute_group group = {
@@ -1459,7 +1477,7 @@ static int amdgpu_ras_sysfs_remove_all(struct amdgpu_device *adev)
  	if (amdgpu_bad_page_threshold != 0)
  		amdgpu_ras_sysfs_remove_bad_page_node(adev);
 
-	amdgpu_ras_sysfs_remove_feature_node(adev);
+	amdgpu_ras_sysfs_remove_dev_attr_node(adev);
 
  	return 0;
  }
@@ -1582,6 +1600,10 @@ static BIN_ATTR(gpu_vram_bad_pages, S_IRUGO,
  		amdgpu_ras_sysfs_badpages_read, NULL, 0);
  static DEVICE_ATTR(features, S_IRUGO,
  		amdgpu_ras_sysfs_features_read, NULL);
+static DEVICE_ATTR(version, 0444,
+		amdgpu_ras_sysfs_version_show, NULL); static DEVICE_ATTR(schema, 
+0444,
+		amdgpu_ras_sysfs_schema_show, NULL);
  static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
  {
  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev); @@ -1590,6 
+1612,8 @@ static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
  	};
  	struct attribute *attrs[] = {
  		&con->features_attr.attr,
+		&con->version_attr.attr,
+		&con->schema_attr.attr,
  		NULL
  	};
  	struct bin_attribute *bin_attrs[] = { @@ -1598,11 +1622,20 @@ 

static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
};
int r;

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +10 -1
+	group.attrs = attrs;
+
  	/* add features entry */
  	con->features_attr = dev_attr_features;
-	group.attrs = attrs;
  	sysfs_attr_init(attrs[0]);
 
+	/* add version entry */
+	con->version_attr = dev_attr_version;
+	sysfs_attr_init(attrs[1]);
+
+	/* add schema entry */
+	con->schema_attr = dev_attr_schema;
+	sysfs_attr_init(attrs[2]);
+
  	if (amdgpu_bad_page_threshold != 0) {
  		/* add bad_page_features entry */
  		bin_attr_gpu_vram_bad_pages.private = NULL; @@ -2594,6 +2627,14 @@ 

static void amdgpu_ras_query_poison_mode(struct amdgpu_device *adev)
}
}

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +3 -0
+static int amdgpu_get_ras_schema(struct amdgpu_device *adev) {
+	return  (amdgpu_ras_is_poison_mode_supported(adev) << 
+(ffs(AMDGPU_RAS_ERROR__POISON) - 1)) |

It's simpler and more readable with a ternary operator.

Thanks,
Lijo

Quoted 44 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +10 -0
+			AMDGPU_RAS_ERROR__SINGLE_CORRECTABLE |
+			AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE |
+			AMDGPU_RAS_ERROR__PARITY;
+}
+
  int amdgpu_ras_init(struct amdgpu_device *adev)
  {
  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev); @@ -2636,6 
+2677,7 @@ int amdgpu_ras_init(struct amdgpu_device *adev)
 
  	con->update_channel_flag = false;
  	con->features = 0;
+	con->schema = 0;
  	INIT_LIST_HEAD(&con->head);
  	/* Might need get this flag from vbios. */
  	con->flags = RAS_DEFAULT_FLAGS;
@@ -2691,6 +2733,9 @@ int amdgpu_ras_init(struct amdgpu_device *adev)
 
  	amdgpu_ras_query_poison_mode(adev);
 
+	/* Get RAS schema for particular SOC */
+	con->schema = amdgpu_get_ras_schema(adev);
+
  	if (amdgpu_ras_fs_init(adev)) {
  		r = -EINVAL;
  		goto release_con;
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +3 -0
index 7999d202c9bc..728f98c6fc1c 100644
@@ -389,9 +389,12 @@ struct amdgpu_ras {
  	/* ras infrastructure */
  	/* for ras itself. */
  	uint32_t features;
+	uint32_t schema;
  	struct list_head head;
  	/* sysfs */
  	struct device_attribute features_attr;
+	struct device_attribute version_attr;
+	struct device_attribute schema_attr;
  	struct bin_attribute badpages_attr;
  	struct dentry *de_ras_eeprom_table;
  	/* block array */