damap_impl.h revision 4c06356b0f0fffb4fc1b6eccc8e5d8e2254a84d6
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SYS_DAMAP_IMPL_H
#define _SYS_DAMAP_IMPL_H
#include <sys/isa_defs.h>
#include <sys/dditypes.h>
#include <sys/time.h>
#include <sys/cmn_err.h>
#include <sys/ddi_impldefs.h>
#include <sys/ddi_implfuncs.h>
#include <sys/ddi_isa.h>
#include <sys/model.h>
#include <sys/devctl.h>
#include <sys/nvpair.h>
#include <sys/sysevent.h>
#include <sys/bitset.h>
#include <sys/sdt.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct dam dam_t;
/*
* activate_cb: Provider callback when reported address is activated
* deactivate_cb: Provider callback when address has been released
*
* configure_cb: Class callout to configure newly activated addresses
* unconfig_cb: Class callout to unconfigure deactivated addresses
*/
typedef void (*activate_cb_t)(void *, char *addr, int idx, void **privp);
typedef void (*deactivate_cb_t)(void *, char *addr, int idx, void *priv);
typedef void (*configure_cb_t)(void *, dam_t *mapp, bitset_t *config_ids);
typedef void (*unconfig_cb_t)(void *, dam_t *mapp, bitset_t *unconfig_ids);
struct dam {
char *dam_name;
int dam_flags; /* state and locks */
int dam_options; /* options at map creation */
int dam_rptmode; /* report mode */
clock_t dam_stabletmo; /* stabilization (ticks) */
uint_t dam_size; /* max index for addr hash */
id_t dam_high; /* highest index allocated */
timeout_id_t dam_tid; /* timeout(9F) ID */
void *dam_activate_arg; /* activation private */
activate_cb_t dam_activate_cb; /* activation callback */
deactivate_cb_t dam_deactivate_cb; /* deactivation callback */
void *dam_config_arg; /* config-private */
configure_cb_t dam_configure_cb; /* configure callout */
unconfig_cb_t dam_unconfig_cb; /* unconfigure callout */
ddi_strid *dam_addr_hash; /* addresss to ID hash */
bitset_t dam_active_set; /* activated address set */
bitset_t dam_stable_set; /* stable address set */
bitset_t dam_report_set; /* reported address set */
void *dam_da; /* per-address soft state */
ddi_taskq_t *dam_taskqp; /* taskq for map activation */
hrtime_t dam_last_update; /* last map update */
hrtime_t dam_last_stable; /* last map stable */
int dam_stable_cnt; /* # of times map stabilized */
int dam_stable_overrun;
kcondvar_t dam_cv;
kmutex_t dam_lock;
kstat_t *dam_kstatsp;
};
/*
* damap.dam_flags
*/
#define ADDR_LOCK 0x1000 /* per-addr lock */
#define MAP_LOCK 0x2000 /* global map lock */
#define DAM_LOCK(m, l) { \
mutex_enter(&(m)->dam_lock); \
while ((m)->dam_flags & (l)) \
cv_wait(&(m)->dam_cv, &(m)->dam_lock); \
(m)->dam_flags |= (l); \
mutex_exit(&(m)->dam_lock); \
}
#define DAM_UNLOCK(m, l) { \
mutex_enter(&(m)->dam_lock); \
(m)->dam_flags &= ~(l); \
cv_signal(&(m)->dam_cv); \
mutex_exit(&(m)->dam_lock); \
}
#define DAM_ASSERT_LOCKED(m, l) ASSERT((m)->dam_flags & (l))
#define DAM_SPEND 0x10 /* stable pending */
#define DAM_DESTROYPEND 0x20 /* in process of being destroyed */
#define DAM_SETADD 0x100 /* fullset update pending */
#define DAM_FLAG_SET(m, f) { \
mutex_enter(&(m)->dam_lock); \
(m)->dam_flags |= f; \
mutex_exit(&(m)->dam_lock); \
}
#define DAM_FLAG_CLR(m, f) { \
mutex_enter(&(m)->dam_lock); \
(m)->dam_flags &= ~f; \
mutex_exit(&(m)->dam_lock); \
}
/*
* per address softstate stucture
*/
typedef struct {
uint_t da_flags; /* flags */
int da_jitter; /* address report count */
int da_ref; /* refcount on address */
void *da_ppriv; /* stable provider private */
void *da_cfg_priv; /* config/unconfig private */
nvlist_t *da_nvl; /* stable nvlist */
void *da_ppriv_rpt; /* reported provider-private */
nvlist_t *da_nvl_rpt; /* reported nvlist */
int64_t da_deadline; /* lbolt64 value when stable */
hrtime_t da_last_report; /* timestamp of last report */
int da_report_cnt; /* # of times address reported */
hrtime_t da_last_stable; /* timestamp of last stable address */
int da_stable_cnt; /* # of times address has stabilized */
char *da_addr; /* string in dam_addr_hash (for mdb) */
} dam_da_t;
/*
* dam_da_t.da_flags
*/
#define DA_INIT 0x1 /* address initizized */
#define DA_ACTIVE 0x2 /* address stable */
#define DA_RELE 0x4 /* adddress released */
/*
* report type
*/
#define RPT_ADDR_ADD 0
#define RPT_ADDR_DEL 1
#define DAM_IN_REPORT(m, i) (bitset_in_set(&(m)->dam_report_set, (i)))
#define DAM_IS_STABLE(m, i) (bitset_in_set(&(m)->dam_active_set, (i)))
/*
* DAM statistics
*/
struct dam_kstats {
struct kstat_named dam_stable;
struct kstat_named dam_stable_blocked;
struct kstat_named dam_rereport;
struct kstat_named dam_numstable;
};
#ifdef __cplusplus
}
#endif
#endif /* _SYS_DAMAP_IMPL_H */