xref: /illumos-gate/usr/src/cmd/fm/schemes/pcie/scheme.c (revision 84ceaea936ebcf122d4f0756d298adf307fd491d)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2023 Oxide Computer Company
14  */
15 
16 #include <fm/fmd_fmri.h>
17 #include <fm/libtopo.h>
18 #include <strings.h>
19 
20 ssize_t
fmd_fmri_nvl2str(nvlist_t * nvl,char * buf,size_t buflen)21 fmd_fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen)
22 {
23 	int err;
24 	ssize_t len;
25 	topo_hdl_t *thp;
26 	char *str;
27 
28 	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
29 		return (fmd_fmri_set_errno(EINVAL));
30 
31 	if (topo_fmri_nvl2str(thp, nvl, &str, &err) != 0) {
32 		fmd_fmri_topo_rele(thp);
33 		return (fmd_fmri_set_errno(EINVAL));
34 	}
35 
36 	len = snprintf(buf, buflen, "%s", str);
37 
38 	topo_hdl_strfree(thp, str);
39 	fmd_fmri_topo_rele(thp);
40 
41 	return (len);
42 }
43 
44 /*
45  * fmd_fmri_present() is called by fmadm to determine if a faulty resource
46  * is still present in the system. We just return true for now, but could
47  * extend this in the future to look at PCI configuration space.
48  */
49 int
fmd_fmri_present(nvlist_t * nvl)50 fmd_fmri_present(nvlist_t *nvl)
51 {
52 	return (1);
53 }
54 
55 /*
56  * fmd_fmri_replaced() is called by fmadm to determine if a resource has been
57  * replaced. We always return unknown for now but this should be extended in
58  * the future as it is possible to determine if devices have been replaced by,
59  * for instance, checking the serial number.
60  */
61 int
fmd_fmri_replaced(nvlist_t * nvl)62 fmd_fmri_replaced(nvlist_t *nvl)
63 {
64 	return (FMD_OBJ_STATE_UNKNOWN);
65 }
66 
67 /*
68  * fmd_fmri_unusable() is called by fmadm to determine if a faulty ASRU
69  * is unusable.
70  */
71 int
fmd_fmri_unusable(nvlist_t * nvl)72 fmd_fmri_unusable(nvlist_t *nvl)
73 {
74 	topo_hdl_t *thp;
75 	int unusable, err;
76 
77 	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
78 		return (fmd_fmri_set_errno(EINVAL));
79 	unusable = topo_fmri_unusable(thp, nvl, &err);
80 	fmd_fmri_topo_rele(thp);
81 
82 	if (err == ETOPO_METHOD_NOTSUP)
83 		return (0);
84 
85 	return (unusable);
86 }
87 
88 int
fmd_fmri_init(void)89 fmd_fmri_init(void)
90 {
91 	return (0);
92 }
93 
94 void
fmd_fmri_fini(void)95 fmd_fmri_fini(void)
96 {
97 }
98