Print this page
4018 mpt_sas: allow physical topology enumeration in libtopo
4019 mpt_sas: expose LED controls to libtopo
Reviewed by: Keith Wesolowski <keith.wesolowski@joyent.com>
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
Reviewed by: Albert Lee <trisk@nexenta.com>
Approved by: Albert Lee <trisk@nexenta.com>


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.

  24  */
  25 
  26 #include <libxml/parser.h>
  27 #include <libxml/xinclude.h>
  28 #include <sys/fm/protocol.h>
  29 #include <assert.h>
  30 #include <string.h>
  31 #include <strings.h>
  32 #include <ctype.h>
  33 #include <errno.h>
  34 #include <limits.h>
  35 #include <fm/libtopo.h>
  36 #include <unistd.h>
  37 #include <sys/stat.h>
  38 #include <fcntl.h>
  39 #include <topo_file.h>
  40 #include <topo_mod.h>
  41 #include <topo_subr.h>
  42 #include <topo_alloc.h>
  43 #include <topo_parse.h>


1359 
1360 
1361 static int
1362 fac_enum_process(topo_mod_t *mp, xmlNodePtr pn, tnode_t *ptn)
1363 {
1364         xmlNodePtr cn;
1365         xmlChar *fprov = NULL;
1366         int rv = 0;
1367 
1368         topo_dprintf(mp->tm_hdl, TOPO_DBG_XML,
1369             "fac_enum_process() called for %s=%d\n", topo_node_name(ptn),
1370             topo_node_instance(ptn));
1371 
1372         for (cn = pn->xmlChildrenNode; cn != NULL; cn = cn->next) {
1373 
1374                 if (xmlStrcmp(cn->name, (xmlChar *)"fac-enum") != 0)
1375                         continue;
1376 
1377                 if ((fprov = xmlGetProp(cn, (xmlChar *)Provider)) == NULL)
1378                         goto fenumdone;
1379 
1380                 if (xmlStrcmp(fprov, (xmlChar *)"fac_prov_ipmi") != 0) {
1381                         topo_dprintf(mp->tm_hdl, TOPO_DBG_XML,
1382                             "Invalid provider specified: %s\n", fprov);
1383                         goto fenumdone;
1384                 }
1385 
1386                 /*
1387                  * Invoke enum entry point in fac provider which will cause the
1388                  * facility enumeration node method to be registered.

1389                  */
1390                 if (fac_enum_run(mp, ptn, (const char *)fprov) != 0) {
1391                         topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR,
1392                             "fac_enum_process: enum entry point failed!\n");
1393                         goto fenumdone;
1394                 }
1395                 xmlFree(fprov);
1396         }
1397         return (0);
1398 fenumdone:
1399         topo_dprintf(mp->tm_hdl, TOPO_DBG_XML, "fac-enum processing failed\n");
1400 
1401         if (fprov != NULL)
1402                 xmlFree(fprov);
1403 
1404         return (rv);
1405 }
1406 
1407 
1408 static int


1423 
1424                 if (xmlStrcmp(cn->name, (xmlChar *)Facility) != 0)
1425                         continue;
1426 
1427                 if ((fname = xmlGetProp(cn, (xmlChar *)Name)) == NULL)
1428                         goto facdone;
1429 
1430                 topo_dprintf(mp->tm_hdl, TOPO_DBG_XML,
1431                     "processing facility node '%s'\n", fname);
1432 
1433                 if ((ftype = xmlGetProp(cn, (xmlChar *)Type)) == NULL)
1434                         goto facdone;
1435 
1436                 if ((provider = xmlGetProp(cn, (xmlChar *)Provider)) == NULL)
1437                         goto facdone;
1438 
1439                 if (xmlStrcmp(ftype, (xmlChar *)Sensor) != 0 &&
1440                     xmlStrcmp(ftype, (xmlChar *)Indicator) != 0)
1441                         goto facdone;
1442 
1443                 if (xmlStrcmp(provider, (xmlChar *)"fac_prov_ipmi") != 0) {
1444                         topo_dprintf(mp->tm_hdl, TOPO_DBG_XML, "fac_process: "
1445                             "Invalid provider attr value: %s\n", provider);
1446                         goto facdone;
1447                 }
1448 
1449                 if ((ntn = topo_node_facbind(mp, ptn, (char *)fname,
1450                     (char *)ftype)) == NULL)
1451                         goto facdone;
1452 
1453                 pgi.tpi_name = TOPO_PGROUP_FACILITY;
1454                 pgi.tpi_namestab = TOPO_STABILITY_PRIVATE;
1455                 pgi.tpi_datastab = TOPO_STABILITY_PRIVATE;
1456                 pgi.tpi_version = 1;
1457                 if (topo_pgroup_create(ntn, &pgi, &err) != 0) {
1458                         if (err != ETOPO_PROP_DEFD) {
1459                                 topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR,
1460                                     "pgroups create failure: %s\n",
1461                                     topo_strerror(err));
1462                                 return (-1);
1463                         }
1464                 }
1465                 /*
1466                  * Invoke enum entry point in fac_prov_ipmi module, which will
1467                  * cause the provider methods to be registered on this node

1468                  */
1469                 if (fac_enum_run(mp, ntn, (const char *)provider) != 0) {
1470                         topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR, "fac_process: "
1471                             "enum entry point failed for provider %s!\n",
1472                             provider);
1473                         goto facdone;
1474                 }
1475 
1476                 if ((newi = tf_idata_new(mp, 0, ntn)) == NULL)
1477                         goto facdone;
1478 
1479                 if (tf_idata_insert(&rd->rd_instances, newi) < 0)
1480                         goto facdone;
1481 
1482                 if (pad_process(mp, rd, cn, ntn, &newi->ti_pad) < 0)
1483                         goto facdone;
1484 
1485                 topo_dprintf(mp->tm_hdl, TOPO_DBG_XML, "done with "
1486                     "facility %s=%s.\n", ftype, fname);
1487 




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  25  */
  26 
  27 #include <libxml/parser.h>
  28 #include <libxml/xinclude.h>
  29 #include <sys/fm/protocol.h>
  30 #include <assert.h>
  31 #include <string.h>
  32 #include <strings.h>
  33 #include <ctype.h>
  34 #include <errno.h>
  35 #include <limits.h>
  36 #include <fm/libtopo.h>
  37 #include <unistd.h>
  38 #include <sys/stat.h>
  39 #include <fcntl.h>
  40 #include <topo_file.h>
  41 #include <topo_mod.h>
  42 #include <topo_subr.h>
  43 #include <topo_alloc.h>
  44 #include <topo_parse.h>


1360 
1361 
1362 static int
1363 fac_enum_process(topo_mod_t *mp, xmlNodePtr pn, tnode_t *ptn)
1364 {
1365         xmlNodePtr cn;
1366         xmlChar *fprov = NULL;
1367         int rv = 0;
1368 
1369         topo_dprintf(mp->tm_hdl, TOPO_DBG_XML,
1370             "fac_enum_process() called for %s=%d\n", topo_node_name(ptn),
1371             topo_node_instance(ptn));
1372 
1373         for (cn = pn->xmlChildrenNode; cn != NULL; cn = cn->next) {
1374 
1375                 if (xmlStrcmp(cn->name, (xmlChar *)"fac-enum") != 0)
1376                         continue;
1377 
1378                 if ((fprov = xmlGetProp(cn, (xmlChar *)Provider)) == NULL)
1379                         goto fenumdone;







1380                 /*
1381                  * Invoke enum entry point in facility provider which will
1382                  * cause the facility enumeration node method to be
1383                  * registered.
1384                  */
1385                 if (fac_enum_run(mp, ptn, (const char *)fprov) != 0) {
1386                         topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR,
1387                             "fac_enum_process: enum entry point failed!\n");
1388                         goto fenumdone;
1389                 }
1390                 xmlFree(fprov);
1391         }
1392         return (0);
1393 fenumdone:
1394         topo_dprintf(mp->tm_hdl, TOPO_DBG_XML, "fac-enum processing failed\n");
1395 
1396         if (fprov != NULL)
1397                 xmlFree(fprov);
1398 
1399         return (rv);
1400 }
1401 
1402 
1403 static int


1418 
1419                 if (xmlStrcmp(cn->name, (xmlChar *)Facility) != 0)
1420                         continue;
1421 
1422                 if ((fname = xmlGetProp(cn, (xmlChar *)Name)) == NULL)
1423                         goto facdone;
1424 
1425                 topo_dprintf(mp->tm_hdl, TOPO_DBG_XML,
1426                     "processing facility node '%s'\n", fname);
1427 
1428                 if ((ftype = xmlGetProp(cn, (xmlChar *)Type)) == NULL)
1429                         goto facdone;
1430 
1431                 if ((provider = xmlGetProp(cn, (xmlChar *)Provider)) == NULL)
1432                         goto facdone;
1433 
1434                 if (xmlStrcmp(ftype, (xmlChar *)Sensor) != 0 &&
1435                     xmlStrcmp(ftype, (xmlChar *)Indicator) != 0)
1436                         goto facdone;
1437 






1438                 if ((ntn = topo_node_facbind(mp, ptn, (char *)fname,
1439                     (char *)ftype)) == NULL)
1440                         goto facdone;
1441 
1442                 pgi.tpi_name = TOPO_PGROUP_FACILITY;
1443                 pgi.tpi_namestab = TOPO_STABILITY_PRIVATE;
1444                 pgi.tpi_datastab = TOPO_STABILITY_PRIVATE;
1445                 pgi.tpi_version = 1;
1446                 if (topo_pgroup_create(ntn, &pgi, &err) != 0) {
1447                         if (err != ETOPO_PROP_DEFD) {
1448                                 topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR,
1449                                     "pgroups create failure: %s\n",
1450                                     topo_strerror(err));
1451                                 return (-1);
1452                         }
1453                 }
1454                 /*
1455                  * Invoke enum entry point in the facility provider module,
1456                  * which will cause the provider methods to be registered on
1457                  * this node
1458                  */
1459                 if (fac_enum_run(mp, ntn, (const char *)provider) != 0) {
1460                         topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR, "fac_process: "
1461                             "enum entry point failed for provider %s!\n",
1462                             provider);
1463                         goto facdone;
1464                 }
1465 
1466                 if ((newi = tf_idata_new(mp, 0, ntn)) == NULL)
1467                         goto facdone;
1468 
1469                 if (tf_idata_insert(&rd->rd_instances, newi) < 0)
1470                         goto facdone;
1471 
1472                 if (pad_process(mp, rd, cn, ntn, &newi->ti_pad) < 0)
1473                         goto facdone;
1474 
1475                 topo_dprintf(mp->tm_hdl, TOPO_DBG_XML, "done with "
1476                     "facility %s=%s.\n", ftype, fname);
1477