fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ksynch.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cmn_err.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/kmem.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsc_thread.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_bcache.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_ft.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_misc.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_pcu.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_io.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_bio.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_trace.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_tdaemon.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s_k.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_errors.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/safestore.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int sdbc_use_dmchain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _sd_cblock_shift = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _SD_SELF_HOST = _SD_NO_HOST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _SD_MIRROR_HOST = _SD_NO_HOST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _SD_NUM_REM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _sd_nodes_configured;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _sdbc_gateway_wblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _SD_NETS = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Normally we unregister memory at deconfig time. By setting this non-zero
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it will be delayed until unload time.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _sdbc_memtype_deconfigure_delayed = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_mem_t *sdbc_iobuf_mem, *sdbc_hash_mem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_mem_t *sdbc_local_mem, *sdbc_stats_mem, *sdbc_cache_mem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_mem_t *sdbc_info_mem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cache_param_t _sd_cache_config;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortekmutex_t _sdbc_config_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevolatile int _sd_cache_dem_cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !defined(m88k) || defined(lint)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevolatile int _sd_cache_initialized;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic blind_t sdbc_power;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_def_t _sdbc_power_def[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Power_Lost", (uintptr_t)_sdbc_power_lost, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Power_OK", (uintptr_t)_sdbc_power_ok, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Power_Down", (uintptr_t)_sdbc_power_down, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, 0, 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Forward declare all statics that are used before defined to enforce
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameter checking
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Some (if not all) of these could be removed if the code were reordered
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _sd_fill_pattern(caddr_t addr, uint_t pat, uint_t size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sdbc_nodeid_deconfigure(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sdbc_nodeid_configure(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sdbc_thread_deconfigure(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sdbc_thread_configure(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid sst_deinit();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortess_common_config_t safestore_config;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesafestore_ops_t *sdbc_safestore;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_memtype_configure - register with the sd layer the types of memory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we want to use. If any of the critical memory types can't be registered
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we return non-zero otherwise 0.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_memtype_configure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sdbc_info_mem = nsc_register_mem("sdbc:info",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MEM_GLOBAL, KM_NOSLEEP)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_local_mem = nsc_register_mem("sdbc:local", NSC_MEM_LOCAL, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_stats_mem = nsc_register_mem("sdbc:stats", NSC_MEM_LOCAL, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_iobuf_mem = nsc_register_mem("sdbc:iobuf", NSC_MEM_LOCAL, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cache_mem = nsc_register_mem("sdbc:cache", NSC_MEM_LOCAL, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_hash_mem = nsc_register_mem("sdbc:hash", NSC_MEM_LOCAL, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_memtype_deconfigure - undo the effects of _sdbc_memtype_configure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_memtype_deconfigure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_hash_mem)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_unregister_mem(sdbc_hash_mem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_iobuf_mem)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_unregister_mem(sdbc_iobuf_mem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_cache_mem)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_unregister_mem(sdbc_cache_mem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_stats_mem)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_unregister_mem(sdbc_stats_mem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_local_mem)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_unregister_mem(sdbc_local_mem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_info_mem)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_unregister_mem(sdbc_info_mem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_info_mem = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_local_mem = sdbc_stats_mem = sdbc_cache_mem = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_iobuf_mem = sdbc_hash_mem = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * figure out what kind of safe storage we need
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_determine_safestore()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (SS_M_RAM | SS_T_NONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesd_setup_ssconfig()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte safestore_config.ssc_client_psize = BLK_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_config.write_cache)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte safestore_config.ssc_wsize =
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_cache_config.write_cache * MEGABYTE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte safestore_config.ssc_wsize =
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (_sd_cache_config.cache_mem[_SD_NO_NET] * MEGABYTE)/2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte safestore_config.ssc_maxfiles = sdbc_max_devs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte safestore_config.ssc_pattern = _sd_cache_config.fill_pattern;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte safestore_config.ssc_flag = _sd_cache_config.gen_pattern ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SS_GENPATTERN : 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_configure - process the ioctl that describes the configuration
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for the cache. This is the main driver routine for cache configuration
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return 0 on success, otherwise nonzero.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_configure(_sd_cache_param_t *uptr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_config_t *mgmt, spcs_s_info_t spcs_kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cache_bytes;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_io_t *io;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char itmp[16];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char itmp2[16];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t ss_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&_sdbc_config_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_print(1, "sdbc(_sdbc_configure) _SD_MAGIC 0x%x\n", _SD_MAGIC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ioset = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_initialized) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(spcs_kstatus, SDBC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT((uptr != NULL) || (mgmt != NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uptr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (copyin(uptr, &_sd_cache_config,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (_sd_cache_param_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&_sd_cache_config, sizeof (_sd_cache_config));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy in mgmt config info */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_config.magic = mgmt->magic;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_config.threads = mgmt->threads;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < CACHE_MEM_PAD; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_config.cache_mem[i] = mgmt->cache_mem[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* fake the rest as a single node config */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_config.nodes_conf[0] = nsc_node_id();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_config.num_nodes = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check that the requested cache size doesn't break the code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This test can be refined once the cache size is stored in variables
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * larger than an int.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < MAX_CACHE_NET; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_config.cache_mem[i] < 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!_sdbc_configure: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "negative cache size (%d) for net %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_config.cache_mem[i], i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(spcs_kstatus, SDBC_ENONETMEM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_ENONETMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_config.cache_mem[i] > MAX_CACHE_SIZE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_config.cache_mem[i] = MAX_CACHE_SIZE;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!_sdbc_configure: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cache size limited to %d megabytes for net %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_CACHE_SIZE, i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_config.blk_size == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_config.blk_size = 8192;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_config.procs == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_config.procs = 16;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !defined(_SD_8K_BLKSIZE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_config.blk_size != 4096) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_config.blk_size != 8192) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(_sd_cache_config.blk_size, itmp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (itmp), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(spcs_kstatus, SDBC_ESIZE, itmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_EENABLEFAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((_sd_cblock_shift =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte get_high_bit(_sd_cache_config.blk_size)) == -1) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_sd_cache_config.blk_size != (1 << _sd_cblock_shift))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(_sd_cache_config.blk_size, itmp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (itmp), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(spcs_kstatus, SDBC_ESIZE, itmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_EENABLEFAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_config.magic != _SD_MAGIC) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_EMAGIC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_use_dmchain = (_sd_cache_config.reserved1 & CFG_USE_DMCHAIN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_static_cache = (_sd_cache_config.reserved1 & CFG_STATIC_CACHE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_nodeid_configure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_SD_SELF_HOST > nsc_max_nodeid ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_MIRROR_HOST > nsc_max_nodeid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring((_SD_SELF_HOST > nsc_max_nodeid ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_SELF_HOST : _SD_MIRROR_HOST), itmp, sizeof (itmp), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_max_nodeid, itmp2, sizeof (itmp2), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(spcs_kstatus, SDBC_EINVHOSTID, itmp, itmp2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_EENABLEFAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_SD_SELF_HOST == _SD_MIRROR_HOST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_SELF_HOST, itmp, sizeof (itmp), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_MIRROR_HOST, itmp2, sizeof (itmp2), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(spcs_kstatus, SDBC_ENOTSAME, itmp, itmp2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_EENABLEFAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize the safestore modules */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sst_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* figure out which kind of safestore we need to use */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_type = sdbc_determine_safestore();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetryss:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* open and configure the safestore module */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sdbc_safestore = sst_open(ss_type, 0)) == NULL) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!cannot open safestore module for type %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_type);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_EENABLEFAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_setup_ssconfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SSOP_CONFIGURE(sdbc_safestore, &safestore_config,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_kstatus)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!cannot configure safestore module for type %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_type);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sst_close(sdbc_safestore);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* try ram if possible, otherwise return */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ss_type & (SS_M_RAM | SS_T_NONE)) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (SS_M_RAM | SS_T_NONE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_EENABLEFAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_type = (SS_M_RAM | SS_T_NONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto tryss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SAFESTORE_LOCAL(sdbc_safestore))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_MIRROR_HOST = _SD_NO_HOST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(safestore_config.ssc_ss_psize <= UINT16_MAX); /* LINTED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_net_config.sn_psize = safestore_config.ssc_ss_psize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_net_config.sn_csize =
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_cache_config.cache_mem[_SD_NO_NET] * MEGABYTE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_net_config.sn_cpages =
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_net_config.sn_csize / BLK_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_net_config.sn_configured = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cache_bytes = _sd_net_config.sn_cpages * BLK_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_memtype_configure()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = _sdbc_iobuf_configure(_sd_cache_config.iobuf))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_ENOIOBMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == -2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_ENOIOBCB;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_handles_configure()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_ENOHANDLEMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_dem_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nvmem support:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if the cache did not shutdown properly we mark it as dirty.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this must be done before _sdbc_cache_configure() so it can
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * refresh sd_info_mem and sd_file_mem from nvmem if necsssary,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and before _sdbc_ft_configure() so the ft thread will do a recovery.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SAFESTORE_RECOVERY(sdbc_safestore)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_set_warm_start();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_ft_hold_io = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sdbc_configure) cache marked dirty after"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " incomplete shutdown");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = _sdbc_cache_configure(cache_bytes / BLK_SIZE(1),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_kstatus))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ST_ALERT trace buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_tr_configure(-1 /* SDT_INV_CD */) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_thread_configure()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_EFLUSHTHRD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_flush_configure()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc = _sdbc_dealloc_configure_dm()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_config.test_demons)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_tdaemon_configure(_sd_cache_config.test_demons)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_initialized = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_power = nsc_register_power("sdbc", _sdbc_power_def);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_ft_configure() != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * try to control the race between the ft thread
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and threads that will open the devices that the ft thread
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * may be recovering. this synchronizing with the ft thread
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prevents sd_cadmin from returning until ft has opened
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the recovery devices, so if other apps wait for sd_cadmin
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to complete the race is prevented.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sdbc_ft_hold_io_lk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (_sdbc_ft_hold_io) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&_sdbc_ft_hold_io_cv, &_sdbc_ft_hold_io_lk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io = nsc_register_io("sdbc", NSC_SDBC_ID|NSC_FILTER,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_sdbc_def);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (io) sdbc_io = io;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sdbc_ft_hold_io_lk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!sd_config: Cache has been configured");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_deconfigure - Put the cache back to the unconfigured state. Release
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * any memory we allocated as part of the configuration process (but not the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * load/init process). Put globals back to unconfigured state and shut down
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * any processes/threads we have running.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Since the cache has loaded we know that global lock/sv's are present and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we can use them to produce an orderly deconfiguration.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: this routine and its callee should always be capable of reversing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the effects of _sdbc_configure no matter what partially configured
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * state might be present.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_deconfigure(spcs_s_info_t spcs_kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pinneddata = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t saved_hint;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&_sdbc_config_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!SD cache being deconfigured.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check if there is pinned data and our mirror is down */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_files && _sd_is_mirror_down()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sdbc_max_devs; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[i]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if (!(cdi->cd_info->sh_failed))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(_SD_CD_ALL_WRITES(i)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(spcs_kstatus, SDBC_EPINNED,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cdi->cd_info->sh_filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_EDISABLEFAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remember hint setting for restoration in case shutdown fails */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_get_node_hint(&saved_hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_set_node_hint(NSC_FORCED_WRTHRU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* TODO - there is a possible race between deconfig and power hits... */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_power)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_unregister_power(sdbc_power);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_io) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_unregister_io(sdbc_io, NSC_PCATCH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_io = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == EUSERS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(spcs_kstatus, SDBC_EABUFS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(spcs_kstatus, SDBC_EUNREG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Re-register-power if it was register before. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_power) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_power = nsc_register_power("sdbc",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sdbc_power_def);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Remove NSC_FORCED_WRTHRU if we set it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_clear_node_hint(
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (~saved_hint) & _SD_HINT_MASK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_EDISABLEFAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_power = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_FAULT_RES)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_remote_disable(0); /* notify mirror to forced_wrthru */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * close devices, deconfigure processes, wait for exits
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_tdaemon_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_files) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sdbc_max_devs; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FILE_OPENED(i) && ((rc = _sd_close(i)) > 0)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_deconfigure)"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " %d not closed (%d)\n", i, rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * look for pinned data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * TODO sort this out for multinode systems.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cannot shutdown with pinned data on multinode.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the state of pinned data should be determined in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the close operation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_files) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sdbc_max_devs; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[i]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if (!(cdi->cd_info->sh_failed))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(_SD_CD_ALL_WRITES(i)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_deconfigure) Pinned Data on cd %d(%s)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i, cdi->cd_info->sh_filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pinneddata++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_initialized = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_ft_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_flush_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_thread_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (_sd_cache_dem_cnt > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_delay_sig(HZ/2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove all dynamically allocated cache data memory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * there should be no i/o at this point
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_dealloc_deconfigure_dm();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * At this point no thread of control should be active in the cache
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * but us (unless they are blocked on the config lock).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_FAULT_RES)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_remote_disable(1); /* notify mirror I/O shutdown complete */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define KEEP_TRACES 0 /* set to 1 keep traces after deconfig */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !KEEP_TRACES
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This needs to happen before we unregister the memory.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_tr_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* delete/free hash table, cache blocks, etc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_cache_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_handles_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_iobuf_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !KEEP_TRACES
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sdbc_memtype_deconfigure_delayed)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_memtype_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_memtype_deconfigure_delayed = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Call ss deconfig(),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check for valid pointer in case _sdbc_configure()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * failed before safestrore system was initialized.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_safestore)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_DECONFIGURE(sdbc_safestore, pinneddata);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* tear down safestore system */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sst_deinit();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_nodeid_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&_sd_cache_config, sizeof (_sd_cache_param_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_SELF_HOST = _SD_MIRROR_HOST = _SD_NO_HOST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_NETS = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cblock_shift = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_node_hint = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!SD cache deconfigured.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefind_low_bit(int mask, int start)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; start < 32; start++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((mask & (1 << start)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_high_bit(int size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int lowbit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int newblk = size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int highbit = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int next_high = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((lowbit = find_low_bit(newblk, 0)) != 32) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (highbit >= 0) next_high = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte highbit = lowbit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newblk &= ~(1 << highbit);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (highbit <= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(get_high_bit) invalid block size %x\n", size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (next_high) highbit++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (highbit);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_fill_pattern(caddr_t addr, uint_t pat, uint_t size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte caddr_t fmt_page;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, page_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte page_size = (int)ptob(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fmt_page = (caddr_t)nsc_kmem_alloc(ptob(1),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP, sdbc_local_mem)) == NULL) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_fill pattern) no more memory");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < page_size; i += 4)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *(int *)(void *)(fmt_page + i) = pat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (size >= page_size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(fmt_page, addr, ptob(1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addr += page_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size -= page_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_kmem_free(fmt_page, page_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_nodeid_deconfigure - merely a place holder until
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * such time as there is something to be undone w.r.t.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_nodeid_configure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_nodeid_deconfigure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* My but we're quick */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_nodeid_configure - configure the nodeid's we need to connect
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to any other nodes in the network.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_nodeid_configure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_config.num_nodes == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_nodes_configured = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_nodes_configured = _sd_cache_config.num_nodes;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_SELF_HOST = nsc_node_id();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_MIRROR_HOST = _sd_cache_config.mirror_host;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define STACK_SIZE (32*1024)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define num_spin 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenstset_t *_sd_ioset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_thread_deconfigure - cache is being deconfigure, stop any
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * thread activity.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_thread_deconfigure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&_sdbc_config_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nst_destroy(_sd_ioset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ioset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_thread_configure - cache is being configured, initialize the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * threads we need for flushing dirty cds.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_thread_configure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&_sdbc_config_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_ioset)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ioset = nst_init("sd_thr", _sd_cache_config.threads);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_ioset)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_get_config(_sdbc_config_t *config_info)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte config_info->enabled = _sd_cache_initialized;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte config_info->magic = _SD_MAGIC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < CACHE_MEM_PAD; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte config_info->cache_mem[i] = _sd_cache_config.cache_mem[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte config_info->threads = _sd_cache_config.threads;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}