/*
* Copyright (c) 2002, 2003 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
typedef union {
dmover_buf_linear dmbuf_linear;
struct uio *dmbuf_uio;
} dmover_buffer;
/*
* dmover_algdesc:
*
* This structure describes a dmover algorithm.
*
* All members of this structure are public.
*/
struct dmover_algdesc {
const char *dad_name; /* algorithm name */
void *dad_data; /* opaque algorithm description */
int dad_ninputs; /* number of inputs */
};
/*
* dmover_assignment:
*
* This structure contains the information necessary to assign
* a request to a back-end.
*
* All members of this structure are public.
*/
struct dmover_assignment {
struct dmover_backend *das_backend;
const struct dmover_algdesc *das_algdesc;
};
/*
* dmover_session:
*
* State for a dmover session.
*/
struct dmover_session {
/*
* PUBLIC MEMBERS
*/
void *dses_cookie; /* for client */
int dses_ninputs; /* number of inputs for function */
/*
* PRIVATE MEMBERS
*/
LIST_ENTRY(dmover_session) __dses_list;
/*
* XXX Assignment is static when a session is
* XXX created, for now.
*/
struct dmover_assignment __dses_assignment;
/* List of active requests on this session. */
TAILQ_HEAD(, dmover_request) __dses_pendreqs;
int __dses_npendreqs;
};
#define dmover_session_insque(dses, dreq) \
do { \
TAILQ_INSERT_TAIL(&(dses)->__dses_pendreqs, (dreq), dreq_sesq); \
(dses)->__dses_npendreqs++; \
} while (/*CONSTCOND*/0)
#define dmover_session_remque(dses, dreq) \
do { \
TAILQ_REMOVE(&(dses)->__dses_pendreqs, (dreq), dreq_sesq); \
(dses)->__dses_npendreqs--; \
} while (/*CONSTCOND*/0)
/*
* dmover_request:
*
* A data dmover request.
*/
struct dmover_request {
/*
* PUBLIC MEMBERS
*/
/* Links on session and back-end queues. */
TAILQ_ENTRY(dmover_request) dreq_sesq;
TAILQ_ENTRY(dmover_request) dreq_dmbq;
/* Pointer to our session. */
struct dmover_session *dreq_session;
/* Our current back-end assignment. */
struct dmover_assignment *dreq_assignment;
/* Function to call when processing is complete. */
void (*dreq_callback)(struct dmover_request *);
void *dreq_cookie; /* for client */
volatile int dreq_flags; /* flags; see below */
int dreq_error; /* valid if DMOVER_REQ_ERROR is set */
/*
* General purpose immediate value. Can be used as an
* input, output, or both, depending on the function.
*/
uint8_t dreq_immediate[8];
/*
* dmover_backend:
*
* Glue between the dmover-api middle layer and the dmover
* backends.
*
* All members of this structure are public.
*/
struct dmover_backend {
TAILQ_ENTRY(dmover_backend) dmb_list;
const char *dmb_name; /* name of back-end */
u_int dmb_speed; /* est. KB/s throughput */
void *dmb_cookie; /* for back-end */
/* List of algorithms this back-ends supports. */
const struct dmover_algdesc *dmb_algdescs;
int dmb_nalgdescs;
/* List of sessions currently on this back-end. */
LIST_HEAD(, dmover_session) dmb_sessions;
int dmb_nsessions; /* current number of sessions */
/* List of active requests on this back-end. */
TAILQ_HEAD(, dmover_request) dmb_pendreqs;
int dmb_npendreqs;
};
#define dmover_backend_insque(dmb, dreq) \
do { \
TAILQ_INSERT_TAIL(&(dmb)->dmb_pendreqs, (dreq), dreq_dmbq); \
(dmb)->dmb_npendreqs++; \
} while (/*CONSTCOND*/0)
#define dmover_backend_remque(dmb, dreq) \
do { \
TAILQ_REMOVE(&(dmb)->dmb_pendreqs, (dreq), dreq_dmbq); \
(dmb)->dmb_npendreqs--; \
} while (/*CONSTCOND*/0)
/*
* Well-known data mover functions. Using these for the function name
* saves space.
*/
extern const char dmover_funcname_zero[];
#define DMOVER_FUNC_ZERO dmover_funcname_zero