2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <stdlib.h>
2N/A#include <errno.h>
2N/A#include <sys/types.h>
2N/A#include <libnvpair.h>
2N/A#include <sys/devfm.h>
2N/A#include <sys/fm/protocol.h>
2N/A#include <fmd_agent_impl.h>
2N/A
2N/Astatic int
2N/Acleanup_set_errno(fmd_agent_hdl_t *hdl, nvlist_t *innvl, nvlist_t *outnvl,
2N/A int err)
2N/A{
2N/A if (innvl != NULL)
2N/A nvlist_free(innvl);
2N/A if (outnvl != NULL)
2N/A nvlist_free(outnvl);
2N/A return (fmd_agent_seterrno(hdl, err));
2N/A}
2N/A
2N/Astatic int
2N/Afmd_agent_cacheop_v1(fmd_agent_hdl_t *hdl, int cmd, uint32_t strandid,
2N/A nvlist_t *fmri, int *statusp)
2N/A{
2N/A int err;
2N/A nvlist_t *nvl = NULL, *outnvl = NULL;
2N/A nvlist_t *hcsp;
2N/A uint64_t cache, cachetype, cachelevel, cacheindex, cacheway;
2N/A
2N/A if ((err = nvlist_lookup_nvlist(fmri, FM_FMRI_HC_SPECIFIC, &hcsp))
2N/A != 0 || (err = nvlist_alloc(&nvl, NV_UNIQUE_NAME_TYPE, 0)) != 0)
2N/A return (cleanup_set_errno(hdl, NULL, NULL, err));
2N/A
2N/A /* Get the cache type and level */
2N/A if (nvlist_lookup_uint64(hcsp, FM_FMRI_HC_SPECIFIC_L2CACHE, &cache)
2N/A == 0) {
2N/A cachelevel = FM_CLR_L2_CACHE;
2N/A cachetype = FM_CLR_UNIFIED_CACHE;
2N/A } else if (nvlist_lookup_uint64(hcsp, FM_FMRI_HC_SPECIFIC_L3CACHE,
2N/A &cache) == 0) {
2N/A cachelevel = FM_CLR_L3_CACHE;
2N/A cachetype = FM_CLR_UNIFIED_CACHE;
2N/A } else {
2N/A return (cleanup_set_errno(hdl, nvl, NULL, ENOTSUP));
2N/A }
2N/A
2N/A /* Set strandid, cachetype, and cachelevel */
2N/A if ((err = nvlist_add_uint64(nvl, FM_CLR_STRAND_ID, strandid)) != 0 ||
2N/A (err = nvlist_add_uint64(nvl, FM_CLR_CACHE_TYPE, cachetype)) != 0 ||
2N/A (err = nvlist_add_uint64(nvl, FM_CLR_CACHE_LEVEL, cachelevel)) != 0)
2N/A return (cleanup_set_errno(hdl, nvl, NULL, err));
2N/A
2N/A /* And cacheindex, cacheway */
2N/A if (nvlist_lookup_uint64(hcsp, FM_FMRI_HC_SPECIFIC_CACHEINDEX,
2N/A &cacheindex) == 0 &&
2N/A ((err = nvlist_add_uint64(nvl, FM_CLR_CACHE_INDEX,
2N/A cacheindex)) != 0))
2N/A return (cleanup_set_errno(hdl, nvl, NULL, err));
2N/A
2N/A if (nvlist_lookup_uint64(hcsp, FM_FMRI_HC_SPECIFIC_CACHEWAY,
2N/A &cacheway) == 0 &&
2N/A ((err = nvlist_add_uint64(nvl, FM_CLR_CACHE_WAY,
2N/A cacheway)) != 0))
2N/A return (cleanup_set_errno(hdl, nvl, NULL, err));
2N/A
2N/A if ((err = fmd_agent_nvl_ioctl(hdl, cmd, 1, nvl,
2N/A statusp != NULL ? &outnvl : NULL)) != 0)
2N/A return (cleanup_set_errno(hdl, nvl, NULL, err));
2N/A
2N/A nvlist_free(nvl);
2N/A if (outnvl != NULL) {
2N/A if (statusp != NULL)
2N/A (void) nvlist_lookup_int32(outnvl,
2N/A FM_CLR_STATUS, statusp);
2N/A nvlist_free(outnvl);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/Astatic int
2N/Afmd_agent_cacheop(fmd_agent_hdl_t *hdl, int cmd, uint32_t strandid,
2N/A nvlist_t *fmri, int *status)
2N/A{
2N/A uint32_t ver;
2N/A
2N/A if (fmd_agent_version(hdl, FM_CACHE_OP_VERSION, &ver) == -1)
2N/A return (cleanup_set_errno(hdl, NULL, NULL, errno));
2N/A
2N/A switch (ver) {
2N/A case 1:
2N/A return (fmd_agent_cacheop_v1(hdl, cmd, strandid, fmri, status));
2N/A
2N/A default:
2N/A return (fmd_agent_seterrno(hdl, ENOTSUP));
2N/A }
2N/A}
2N/A
2N/Aint
2N/Afmd_agent_cache_retire(fmd_agent_hdl_t *hdl, uint32_t strandid, nvlist_t *fmri)
2N/A{
2N/A int ret;
2N/A
2N/A ret = fmd_agent_cacheop(hdl, FM_IOC_CACHE_RETIRE, strandid, fmri, NULL);
2N/A
2N/A if (ret == 0)
2N/A return (FMD_AGENT_RETIRE_DONE);
2N/A else if (fmd_agent_errno(hdl) == EAGAIN)
2N/A return (FMD_AGENT_RETIRE_ASYNC);
2N/A else
2N/A return (FMD_AGENT_RETIRE_FAIL);
2N/A}
2N/A
2N/Aint
2N/Afmd_agent_cache_unretire(fmd_agent_hdl_t *hdl, uint32_t strandid,
2N/A nvlist_t *fmri)
2N/A{
2N/A int ret;
2N/A
2N/A ret = fmd_agent_cacheop(hdl, FM_IOC_CACHE_UNRETIRE,
2N/A strandid, fmri, NULL);
2N/A
2N/A return (ret == 0 ? FMD_AGENT_RETIRE_DONE : FMD_AGENT_RETIRE_FAIL);
2N/A}
2N/A
2N/Aint
2N/Afmd_agent_cache_isretired(fmd_agent_hdl_t *hdl, uint32_t strandid,
2N/A nvlist_t *fmri)
2N/A{
2N/A int status;
2N/A
2N/A if (fmd_agent_cacheop(hdl, FM_IOC_CACHE_STATUS,
2N/A strandid, fmri, &status) != 0)
2N/A return (-1);
2N/A
2N/A return (status == FM_CLR_STATUS_RETIRED ? FMD_AGENT_RETIRE_DONE :
2N/A FMD_AGENT_RETIRE_FAIL);
2N/A}