ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim/*
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * CDDL HEADER START
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim *
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * The contents of this file are subject to the terms of the
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * Common Development and Distribution License (the "License").
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * You may not use this file except in compliance with the License.
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim *
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * or http://www.opensolaris.org/os/licensing.
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * See the License for the specific language governing permissions
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * and limitations under the License.
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim *
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * When distributing Covered Code, include this CDDL HEADER in each
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * If applicable, add the following below this CDDL HEADER, with the
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * fields enclosed by brackets "[]" replaced with your own identifying
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * information: Portions Copyright [yyyy] [name of copyright owner]
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim *
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * CDDL HEADER END
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim */
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim/*
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim */
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#ifndef _LIBSMP_PLUGIN_H
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#define _LIBSMP_PLUGIN_H
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#ifdef __cplusplus
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern "C" {
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#endif
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#include <sys/scsi/generic/smp_frames.h>
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#include <scsi/libsmp.h>
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#include <stddef.h>
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#define LIBSMP_PLUGIN_VERSION 1
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#define LIBSMP_ENGINE_VERSION 1
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#ifndef SMP_REQ_MINLEN
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#define SMP_REQ_MINLEN \
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim (offsetof(smp_request_frame_t, srf_data[0]) + sizeof (smp_crc_t))
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#endif
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#ifndef SMP_RESP_MINLEN
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#define SMP_RESP_MINLEN \
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim (offsetof(smp_response_frame_t, srf_data[0]) + sizeof (smp_crc_t))
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#endif
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#define VERIFY(x) ((void)((x) || smp_assert(#x, __FILE__, __LINE__)))
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#ifdef DEBUG
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#define ASSERT(x) VERIFY(x)
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#else
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#define ASSERT(x)
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#endif
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimstruct smp_engine;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimtypedef struct smp_engine smp_engine_t;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimstruct smp_plugin;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimtypedef struct smp_plugin smp_plugin_t;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimtypedef struct smp_engine_ops {
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim void *(*seo_open)(const void *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim void (*seo_close)(void *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim int (*seo_exec)(void *, smp_action_t *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim void (*seo_target_name)(void *, char *, size_t);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim uint64_t (*seo_target_addr)(void *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim} smp_engine_ops_t;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimtypedef struct smp_engine_config {
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim const char *sec_name;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim const smp_engine_ops_t *sec_ops;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim} smp_engine_config_t;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#define SMP_FD_F_NEEDS_CHANGE_COUNT 0x0001
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#define SMP_FD_F_PROVIDES_CHANGE_COUNT 0x0002
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#define SMP_FD_F_READ 0x0004
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#define SMP_FD_F_WRITE 0x0008
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimtypedef struct smp_function_def {
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim smp_function_t sfd_function;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim uint_t sfd_capmask;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim uint_t sfd_capset;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim uint_t sfd_flags;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim size_t (*sfd_rq_len)(size_t, smp_target_t *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim off_t (*sfd_rq_dataoff)(smp_action_t *, smp_target_t *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim void (*sfd_rq_setframe)(smp_action_t *, smp_target_t *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim size_t (*sfd_rs_datalen)(smp_action_t *, smp_target_t *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim off_t (*sfd_rs_dataoff)(smp_action_t *, smp_target_t *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim void (*sfd_rs_getparams)(smp_action_t *, smp_target_t *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim} smp_function_def_t;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimtypedef struct smp_plugin_config {
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim const char *spc_name;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim smp_function_def_t *spc_functions;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim} smp_plugin_config_t;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern int smp_assert(const char *, const char *, int);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern void *smp_alloc(size_t);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern void *smp_zalloc(size_t);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern char *smp_strdup(const char *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern void smp_free(void *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern int smp_set_errno(smp_errno_t);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern int smp_verror(smp_errno_t, const char *, va_list);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern int smp_error(smp_errno_t, const char *, ...);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern void smp_action_get_request_frame(const smp_action_t *,
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim void **, size_t *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern void smp_action_get_response_frame(const smp_action_t *,
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim void **, size_t *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern void smp_action_set_response_len(smp_action_t *, size_t);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern void smp_action_set_result(smp_action_t *, smp_result_t);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern const smp_function_def_t *smp_action_get_function_def(
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim const smp_action_t *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern int smp_engine_register(smp_engine_t *, int,
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim const smp_engine_config_t *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern int smp_plugin_register(smp_plugin_t *, int,
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim const smp_plugin_config_t *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern void smp_plugin_setspecific(smp_plugin_t *, void *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kimextern void *smp_plugin_getspecific(smp_plugin_t *);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#ifdef __cplusplus
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim}
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#endif
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim#endif /* _LIBSMP_PLUGIN_H */