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
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.
13 * Copyright (c) 2017, Joyent, Inc.
16 #include <sys/fm/protocol.h>
17 #include <fm/topo_mod.h>
18 #include <fm/topo_list.h>
19 #include <fm/topo_method.h>
21 #include <topo_port.h>
24 * Common routines to create port entries in the topology tree.
27 static const topo_pgroup_info_t port_pgroup
= {
29 TOPO_STABILITY_PRIVATE
,
30 TOPO_STABILITY_PRIVATE
,
35 port_range_create(topo_mod_t
*mod
, tnode_t
*pnode
, topo_instance_t min
,
38 return (topo_node_range_create(mod
, pnode
, PORT
, min
, max
));
42 * Create a port node, specifying the type of port it is. This will create the
43 * common port property group and populate it. The caller will need to populate
44 * the port-specific property group as needed.
47 port_create_common(topo_mod_t
*mod
, tnode_t
*pnode
, topo_instance_t inst
,
52 nvlist_t
*fmri
= NULL
, *auth
= NULL
, *presource
= NULL
;
55 topo_mod_dprintf(mod
, "port_create_common missing type "
60 if ((auth
= topo_mod_auth(mod
, pnode
)) == NULL
) {
61 topo_mod_dprintf(mod
, "topo_mod_auth() failed: %s\n",
62 topo_mod_errmsg(mod
));
66 if ((fmri
= topo_mod_hcfmri(mod
, pnode
, FM_HC_SCHEME_VERSION
, PORT
,
67 inst
, NULL
, auth
, NULL
, NULL
, NULL
)) == NULL
) {
68 topo_mod_dprintf(mod
, "topo_mod_hcfmri() failed: %s\n",
69 topo_mod_errmsg(mod
));
73 if ((tn
= topo_node_bind(mod
, pnode
, PORT
, inst
, fmri
)) == NULL
) {
74 topo_mod_dprintf(mod
, "topo_node_bind() failed: %s\n",
75 topo_mod_errmsg(mod
));
80 * The FRU is always set to the FMRI of the parent device for a port.
82 if (topo_node_resource(pnode
, &presource
, &err
) != 0) {
83 topo_mod_dprintf(mod
, "topo_node_resource() failed: %s\n",
88 if (topo_node_fru_set(tn
, presource
, 0, &err
) != 0) {
89 topo_mod_dprintf(mod
, "topo_node_fru_set() failed: %s\n",
94 if (topo_pgroup_create(tn
, &port_pgroup
, &err
) != 0) {
95 topo_mod_dprintf(mod
, "failed to create property group %s: "
96 "%s\n", TOPO_PGROUP_PORT
, topo_strerror(err
));
100 if (topo_prop_set_string(tn
, TOPO_PGROUP_PORT
, TOPO_PROP_PORT_TYPE
,
101 TOPO_PROP_IMMUTABLE
, type
, &err
) != 0) {
102 topo_mod_dprintf(mod
, "failed to set %s property: %s\n",
103 TOPO_PROP_PORT_TYPE
, topo_strerror(err
));
109 nvlist_free(presource
);
112 topo_node_unbind(tn
);
115 nvlist_free(presource
);
120 port_create_sff(topo_mod_t
*mod
, tnode_t
*pnode
, topo_instance_t inst
,
125 tn
= port_create_common(mod
, pnode
, inst
, TOPO_PROP_PORT_TYPE_SFF
);