Skip to content

Commit 52c01b0

Browse files
mhaimovskiogabbay
authored andcommitted
habanalabs: expose reset counters via existing INFO IOCTL
Expose both soft and hard reset counts via INFO IOCTL. This will allow system management applications to easily check if the device has undergone reset. Signed-off-by: Moti Haimovski <[email protected]> Reviewed-by: Oded Gabbay <[email protected]> Signed-off-by: Oded Gabbay <[email protected]>
1 parent e16ee41 commit 52c01b0

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

drivers/misc/habanalabs/habanalabs_ioctl.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,22 @@ static int get_clk_rate(struct hl_device *hdev, struct hl_info_args *args)
242242
min((size_t) max_size, sizeof(clk_rate))) ? -EFAULT : 0;
243243
}
244244

245+
static int get_reset_count(struct hl_device *hdev, struct hl_info_args *args)
246+
{
247+
struct hl_info_reset_count reset_count = {0};
248+
u32 max_size = args->return_size;
249+
void __user *out = (void __user *) (uintptr_t) args->return_pointer;
250+
251+
if ((!max_size) || (!out))
252+
return -EINVAL;
253+
254+
reset_count.hard_reset_cnt = hdev->hard_reset_cnt;
255+
reset_count.soft_reset_cnt = hdev->soft_reset_cnt;
256+
257+
return copy_to_user(out, &reset_count,
258+
min((size_t) max_size, sizeof(reset_count))) ? -EFAULT : 0;
259+
}
260+
245261
static int _hl_info_ioctl(struct hl_fpriv *hpriv, void *data,
246262
struct device *dev)
247263
{
@@ -260,6 +276,9 @@ static int _hl_info_ioctl(struct hl_fpriv *hpriv, void *data,
260276
case HL_INFO_DEVICE_STATUS:
261277
return device_status_info(hdev, args);
262278

279+
case HL_INFO_RESET_COUNT:
280+
return get_reset_count(hdev, args);
281+
263282
default:
264283
break;
265284
}

include/uapi/misc/habanalabs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ enum hl_device_status {
9898
* HL_INFO_CLK_RATE - Retrieve the current and maximum clock rate
9999
* of the device in MHz. The maximum clock rate is
100100
* configurable via sysfs parameter
101+
* HL_INFO_RESET_COUNT - Retrieve the counts of the soft and hard reset
102+
* operations performed on the device since the last
103+
* time the driver was loaded.
101104
*/
102105
#define HL_INFO_HW_IP_INFO 0
103106
#define HL_INFO_HW_EVENTS 1
@@ -107,6 +110,7 @@ enum hl_device_status {
107110
#define HL_INFO_DEVICE_UTILIZATION 6
108111
#define HL_INFO_HW_EVENTS_AGGREGATE 7
109112
#define HL_INFO_CLK_RATE 8
113+
#define HL_INFO_RESET_COUNT 9
110114

111115
#define HL_INFO_VERSION_MAX_LEN 128
112116
#define HL_INFO_CARD_NAME_MAX_LEN 16
@@ -160,6 +164,11 @@ struct hl_info_clk_rate {
160164
__u32 max_clk_rate_mhz;
161165
};
162166

167+
struct hl_info_reset_count {
168+
__u32 hard_reset_cnt;
169+
__u32 soft_reset_cnt;
170+
};
171+
163172
struct hl_info_args {
164173
/* Location of relevant struct in userspace */
165174
__u64 return_pointer;

0 commit comments

Comments
 (0)