da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski/*
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski * This file and its contents are supplied under the terms of the
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski * Common Development and Distribution License ("CDDL"), version 1.0.
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski * You may only use this file in accordance with the terms of version
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski * 1.0 of the CDDL.
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski *
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski * A full copy of the text of the CDDL should have accompanied this
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski * source. A copy of the CDDL is also available via the Internet at
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski * http://www.illumos.org/license/CDDL.
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski */
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski/*
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski * Copyright 2014 Joyent, Inc. All rights reserved.
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski */
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski#ifndef _SYS_SCSI_ADAPTERS_MPTHASH_H
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski#define _SYS_SCSI_ADAPTERS_MPTHASH_H
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski#include <sys/types.h>
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski#include <sys/list.h>
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski#define RHL_F_DEAD 0x01
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskitypedef struct refhash_link {
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski list_node_t rhl_chain_link;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski list_node_t rhl_global_link;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski uint_t rhl_flags;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski uint_t rhl_refcnt;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski} refhash_link_t;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskitypedef uint64_t (*refhash_hash_f)(const void *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskitypedef int (*refhash_cmp_f)(const void *, const void *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskitypedef void (*refhash_dtor_f)(void *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskitypedef int (*refhash_eval_f)(const void *, void *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskitypedef struct refhash {
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski list_t *rh_buckets;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski uint_t rh_bucket_count;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski list_t rh_objs;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski size_t rh_obj_size; /* used by mdb */
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski size_t rh_link_off;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski size_t rh_tag_off;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski refhash_hash_f rh_hash;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski refhash_cmp_f rh_cmp;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski refhash_dtor_f rh_dtor;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski} refhash_t;
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskiextern refhash_t *refhash_create(uint_t, refhash_hash_f, refhash_cmp_f,
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski refhash_dtor_f, size_t, size_t, size_t, int);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskiextern void refhash_destroy(refhash_t *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskiextern void refhash_insert(refhash_t *, void *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskiextern void refhash_remove(refhash_t *, void *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskiextern void *refhash_lookup(refhash_t *, const void *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskiextern void *refhash_linear_search(refhash_t *, refhash_eval_f, void *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskiextern void refhash_hold(refhash_t *, void *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskiextern void refhash_rele(refhash_t *, void *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskiextern void *refhash_first(refhash_t *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskiextern void *refhash_next(refhash_t *, void *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowskiextern boolean_t refhash_obj_valid(refhash_t *hp, const void *);
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski
da5ab83fc888325fc812733d8a54bc5eab65c65cKeith M Wesolowski#endif /* _SYS_SCSI_ADAPTERS_MPTHASH_H */