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