1*5b28f239Srillig /* $NetBSD: dmovervar.h,v 1.11 2024/09/08 09:36:50 rillig Exp $ */ 25d06c0e8Sthorpej 35d06c0e8Sthorpej /* 45f35784bSthorpej * Copyright (c) 2002, 2003 Wasabi Systems, Inc. 55d06c0e8Sthorpej * All rights reserved. 65d06c0e8Sthorpej * 75d06c0e8Sthorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc. 85d06c0e8Sthorpej * 95d06c0e8Sthorpej * Redistribution and use in source and binary forms, with or without 105d06c0e8Sthorpej * modification, are permitted provided that the following conditions 115d06c0e8Sthorpej * are met: 125d06c0e8Sthorpej * 1. Redistributions of source code must retain the above copyright 135d06c0e8Sthorpej * notice, this list of conditions and the following disclaimer. 145d06c0e8Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 155d06c0e8Sthorpej * notice, this list of conditions and the following disclaimer in the 165d06c0e8Sthorpej * documentation and/or other materials provided with the distribution. 175d06c0e8Sthorpej * 3. All advertising materials mentioning features or use of this software 185d06c0e8Sthorpej * must display the following acknowledgement: 195d06c0e8Sthorpej * This product includes software developed for the NetBSD Project by 205d06c0e8Sthorpej * Wasabi Systems, Inc. 215d06c0e8Sthorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse 225d06c0e8Sthorpej * or promote products derived from this software without specific prior 235d06c0e8Sthorpej * written permission. 245d06c0e8Sthorpej * 255d06c0e8Sthorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 265d06c0e8Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 275d06c0e8Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 285d06c0e8Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 295d06c0e8Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 305d06c0e8Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 315d06c0e8Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 325d06c0e8Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 335d06c0e8Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 345d06c0e8Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 355d06c0e8Sthorpej * POSSIBILITY OF SUCH DAMAGE. 365d06c0e8Sthorpej */ 375d06c0e8Sthorpej 385d06c0e8Sthorpej #ifndef _DMOVER_DMOVERVAR_H_ 395d06c0e8Sthorpej #define _DMOVER_DMOVERVAR_H_ 405d06c0e8Sthorpej 415d06c0e8Sthorpej #include <sys/lock.h> 425d06c0e8Sthorpej #include <sys/queue.h> 435d06c0e8Sthorpej 445d06c0e8Sthorpej /* 455d06c0e8Sthorpej * Types of buffers the dmover-api can handle. 465d06c0e8Sthorpej */ 475d06c0e8Sthorpej typedef enum { 485f35784bSthorpej DMOVER_BUF_NONE = 0, 495f35784bSthorpej DMOVER_BUF_LINEAR = 1, 505f35784bSthorpej DMOVER_BUF_UIO = 2 515d06c0e8Sthorpej } dmover_buffer_type; 525d06c0e8Sthorpej 535d06c0e8Sthorpej typedef struct { 545d06c0e8Sthorpej void *l_addr; 555d06c0e8Sthorpej size_t l_len; 565d06c0e8Sthorpej } dmover_buf_linear; 575d06c0e8Sthorpej 585d06c0e8Sthorpej typedef union { 595d06c0e8Sthorpej dmover_buf_linear dmbuf_linear; 605d06c0e8Sthorpej struct uio *dmbuf_uio; 615d06c0e8Sthorpej } dmover_buffer; 625d06c0e8Sthorpej 635d06c0e8Sthorpej /* 645d06c0e8Sthorpej * dmover_algdesc: 655d06c0e8Sthorpej * 66*5b28f239Srillig * This structure describes a dmover algorithm. 675d06c0e8Sthorpej * 685d06c0e8Sthorpej * All members of this structure are public. 695d06c0e8Sthorpej */ 705d06c0e8Sthorpej struct dmover_algdesc { 715d06c0e8Sthorpej const char *dad_name; /* algorithm name */ 725d06c0e8Sthorpej void *dad_data; /* opaque algorithm description */ 735d06c0e8Sthorpej int dad_ninputs; /* number of inputs */ 745d06c0e8Sthorpej }; 755d06c0e8Sthorpej 765d06c0e8Sthorpej /* 775d06c0e8Sthorpej * dmover_assignment: 785d06c0e8Sthorpej * 795d06c0e8Sthorpej * This structure contains the information necessary to assign 805d06c0e8Sthorpej * a request to a back-end. 815d06c0e8Sthorpej * 825d06c0e8Sthorpej * All members of this structure are public. 835d06c0e8Sthorpej */ 845d06c0e8Sthorpej struct dmover_assignment { 855d06c0e8Sthorpej struct dmover_backend *das_backend; 865d06c0e8Sthorpej const struct dmover_algdesc *das_algdesc; 875d06c0e8Sthorpej }; 885d06c0e8Sthorpej 895d06c0e8Sthorpej /* 905d06c0e8Sthorpej * dmover_session: 915d06c0e8Sthorpej * 925d06c0e8Sthorpej * State for a dmover session. 935d06c0e8Sthorpej */ 945d06c0e8Sthorpej struct dmover_session { 955d06c0e8Sthorpej /* 965d06c0e8Sthorpej * PUBLIC MEMBERS 975d06c0e8Sthorpej */ 985d06c0e8Sthorpej void *dses_cookie; /* for client */ 995d06c0e8Sthorpej int dses_ninputs; /* number of inputs for function */ 1005d06c0e8Sthorpej 1015d06c0e8Sthorpej /* 1025d06c0e8Sthorpej * PRIVATE MEMBERS 1035d06c0e8Sthorpej */ 1045d06c0e8Sthorpej LIST_ENTRY(dmover_session) __dses_list; 1055d06c0e8Sthorpej 1065d06c0e8Sthorpej /* 1075d06c0e8Sthorpej * XXX Assignment is static when a session is 1085d06c0e8Sthorpej * XXX created, for now. 1095d06c0e8Sthorpej */ 1105d06c0e8Sthorpej struct dmover_assignment __dses_assignment; 1115d06c0e8Sthorpej 1125d06c0e8Sthorpej /* List of active requests on this session. */ 1135d06c0e8Sthorpej TAILQ_HEAD(, dmover_request) __dses_pendreqs; 1145d06c0e8Sthorpej int __dses_npendreqs; 1155d06c0e8Sthorpej }; 1165d06c0e8Sthorpej 1175d06c0e8Sthorpej #define dmover_session_insque(dses, dreq) \ 1185d06c0e8Sthorpej do { \ 1195d06c0e8Sthorpej TAILQ_INSERT_TAIL(&(dses)->__dses_pendreqs, (dreq), dreq_sesq); \ 1205d06c0e8Sthorpej (dses)->__dses_npendreqs++; \ 1215d06c0e8Sthorpej } while (/*CONSTCOND*/0) 1225d06c0e8Sthorpej 1235d06c0e8Sthorpej #define dmover_session_remque(dses, dreq) \ 1245d06c0e8Sthorpej do { \ 1255d06c0e8Sthorpej TAILQ_REMOVE(&(dses)->__dses_pendreqs, (dreq), dreq_sesq); \ 1265d06c0e8Sthorpej (dses)->__dses_npendreqs--; \ 1275d06c0e8Sthorpej } while (/*CONSTCOND*/0) 1285d06c0e8Sthorpej 1295d06c0e8Sthorpej /* 1305d06c0e8Sthorpej * dmover_request: 1315d06c0e8Sthorpej * 1325d06c0e8Sthorpej * A data dmover request. 1335d06c0e8Sthorpej */ 1345d06c0e8Sthorpej struct dmover_request { 1355d06c0e8Sthorpej /* 1365d06c0e8Sthorpej * PUBLIC MEMBERS 1375d06c0e8Sthorpej */ 1385d06c0e8Sthorpej 1395d06c0e8Sthorpej /* Links on session and back-end queues. */ 1405d06c0e8Sthorpej TAILQ_ENTRY(dmover_request) dreq_sesq; 1415d06c0e8Sthorpej TAILQ_ENTRY(dmover_request) dreq_dmbq; 1425d06c0e8Sthorpej 1435d06c0e8Sthorpej /* Pointer to our session. */ 1445d06c0e8Sthorpej struct dmover_session *dreq_session; 1455d06c0e8Sthorpej 1465d06c0e8Sthorpej /* Our current back-end assignment. */ 1475d06c0e8Sthorpej struct dmover_assignment *dreq_assignment; 1485d06c0e8Sthorpej 1495d06c0e8Sthorpej /* Function to call when processing is complete. */ 1505d06c0e8Sthorpej void (*dreq_callback)(struct dmover_request *); 1515d06c0e8Sthorpej void *dreq_cookie; /* for client */ 1525d06c0e8Sthorpej 15393124077Sperry volatile int dreq_flags; /* flags; see below */ 1545d06c0e8Sthorpej int dreq_error; /* valid if DMOVER_REQ_ERROR is set */ 1555d06c0e8Sthorpej 156d0e1416bSthorpej /* 157d0e1416bSthorpej * General purpose immediate value. Can be used as an 158d0e1416bSthorpej * input, output, or both, depending on the function. 159d0e1416bSthorpej */ 160d0e1416bSthorpej uint8_t dreq_immediate[8]; 161d0e1416bSthorpej 1625d06c0e8Sthorpej /* Output buffer. */ 1635d06c0e8Sthorpej dmover_buffer_type dreq_outbuf_type; 1645d06c0e8Sthorpej dmover_buffer dreq_outbuf; 1655d06c0e8Sthorpej 1665d06c0e8Sthorpej /* Input buffer. */ 1675d06c0e8Sthorpej dmover_buffer_type dreq_inbuf_type; 168792ce8feSthorpej dmover_buffer *dreq_inbuf; 1695d06c0e8Sthorpej }; 1705d06c0e8Sthorpej 1715d06c0e8Sthorpej /* dreq_flags */ 1725d06c0e8Sthorpej #define DMOVER_REQ_DONE 0x0001 /* request is completed */ 1735d06c0e8Sthorpej #define DMOVER_REQ_ERROR 0x0002 /* error occurred */ 1745d06c0e8Sthorpej #define DMOVER_REQ_RUNNING 0x0004 /* request is being executed */ 1755d06c0e8Sthorpej #define DMOVER_REQ_WAIT 0x0008 /* wait for completion */ 1765d06c0e8Sthorpej 1775d06c0e8Sthorpej #define __DMOVER_REQ_INBUF_FREE 0x01000000 /* need to free input buffer */ 1785d06c0e8Sthorpej 1795d06c0e8Sthorpej #define __DMOVER_REQ_FLAGS_PRESERVE \ 1805d06c0e8Sthorpej (DMOVER_REQ_WAIT | __DMOVER_REQ_INBUF_FREE) 1815d06c0e8Sthorpej 1825d06c0e8Sthorpej /* 1835d06c0e8Sthorpej * dmover_backend: 1845d06c0e8Sthorpej * 1855d06c0e8Sthorpej * Glue between the dmover-api middle layer and the dmover 1865d06c0e8Sthorpej * backends. 1875d06c0e8Sthorpej * 1885d06c0e8Sthorpej * All members of this structure are public. 1895d06c0e8Sthorpej */ 1905d06c0e8Sthorpej struct dmover_backend { 1915d06c0e8Sthorpej TAILQ_ENTRY(dmover_backend) dmb_list; 1925d06c0e8Sthorpej 1935d06c0e8Sthorpej const char *dmb_name; /* name of back-end */ 1945d06c0e8Sthorpej u_int dmb_speed; /* est. KB/s throughput */ 1955d06c0e8Sthorpej 1965d06c0e8Sthorpej void *dmb_cookie; /* for back-end */ 1975d06c0e8Sthorpej 1985d06c0e8Sthorpej /* List of algorithms this back-ends supports. */ 1995d06c0e8Sthorpej const struct dmover_algdesc *dmb_algdescs; 2005d06c0e8Sthorpej int dmb_nalgdescs; 2015d06c0e8Sthorpej 2025d06c0e8Sthorpej /* Back-end functions. */ 2035d06c0e8Sthorpej void (*dmb_process)(struct dmover_backend *); 2045d06c0e8Sthorpej 2055d06c0e8Sthorpej /* List of sessions currently on this back-end. */ 2065d06c0e8Sthorpej LIST_HEAD(, dmover_session) dmb_sessions; 2075d06c0e8Sthorpej int dmb_nsessions; /* current number of sessions */ 2085d06c0e8Sthorpej 2095d06c0e8Sthorpej /* List of active requests on this back-end. */ 2105d06c0e8Sthorpej TAILQ_HEAD(, dmover_request) dmb_pendreqs; 2115d06c0e8Sthorpej int dmb_npendreqs; 2125d06c0e8Sthorpej }; 2135d06c0e8Sthorpej 2145d06c0e8Sthorpej #define dmover_backend_insque(dmb, dreq) \ 2155d06c0e8Sthorpej do { \ 2165d06c0e8Sthorpej TAILQ_INSERT_TAIL(&(dmb)->dmb_pendreqs, (dreq), dreq_dmbq); \ 2175d06c0e8Sthorpej (dmb)->dmb_npendreqs++; \ 2185d06c0e8Sthorpej } while (/*CONSTCOND*/0) 2195d06c0e8Sthorpej 2205d06c0e8Sthorpej #define dmover_backend_remque(dmb, dreq) \ 2215d06c0e8Sthorpej do { \ 2225d06c0e8Sthorpej TAILQ_REMOVE(&(dmb)->dmb_pendreqs, (dreq), dreq_dmbq); \ 2235d06c0e8Sthorpej (dmb)->dmb_npendreqs--; \ 2245d06c0e8Sthorpej } while (/*CONSTCOND*/0) 2255d06c0e8Sthorpej 2265d06c0e8Sthorpej /* 2275d06c0e8Sthorpej * Well-known data mover functions. Using these for the function name 2285d06c0e8Sthorpej * saves space. 2295d06c0e8Sthorpej */ 2305d06c0e8Sthorpej extern const char dmover_funcname_zero[]; 2315d06c0e8Sthorpej #define DMOVER_FUNC_ZERO dmover_funcname_zero 2325d06c0e8Sthorpej 2335d06c0e8Sthorpej extern const char dmover_funcname_fill8[]; 2345d06c0e8Sthorpej #define DMOVER_FUNC_FILL8 dmover_funcname_fill8 2355d06c0e8Sthorpej 2365d06c0e8Sthorpej extern const char dmover_funcname_copy[]; 2375d06c0e8Sthorpej #define DMOVER_FUNC_COPY dmover_funcname_copy 2385d06c0e8Sthorpej 239a2a587d6Sthorpej extern const char dmover_funcname_iscsi_crc32c[]; 240a2a587d6Sthorpej #define DMOVER_FUNC_ISCSI_CRC32C dmover_funcname_iscsi_crc32c 241a2a587d6Sthorpej 24232ff9181Sthorpej extern const char dmover_funcname_xor2[]; 24332ff9181Sthorpej #define DMOVER_FUNC_XOR2 dmover_funcname_xor2 24432ff9181Sthorpej 24532ff9181Sthorpej extern const char dmover_funcname_xor3[]; 24632ff9181Sthorpej #define DMOVER_FUNC_XOR3 dmover_funcname_xor3 24732ff9181Sthorpej 24832ff9181Sthorpej extern const char dmover_funcname_xor4[]; 24932ff9181Sthorpej #define DMOVER_FUNC_XOR4 dmover_funcname_xor4 25032ff9181Sthorpej 25116003abdSthorpej extern const char dmover_funcname_xor5[]; 25216003abdSthorpej #define DMOVER_FUNC_XOR5 dmover_funcname_xor5 25316003abdSthorpej 25416003abdSthorpej extern const char dmover_funcname_xor6[]; 25516003abdSthorpej #define DMOVER_FUNC_XOR6 dmover_funcname_xor6 25616003abdSthorpej 25716003abdSthorpej extern const char dmover_funcname_xor7[]; 25816003abdSthorpej #define DMOVER_FUNC_XOR7 dmover_funcname_xor7 25916003abdSthorpej 26016003abdSthorpej extern const char dmover_funcname_xor8[]; 26116003abdSthorpej #define DMOVER_FUNC_XOR8 dmover_funcname_xor8 26216003abdSthorpej 26390824326Sbriggs extern const char dmover_funcname_xor9[]; 26490824326Sbriggs #define DMOVER_FUNC_XOR9 dmover_funcname_xor9 26590824326Sbriggs 26690824326Sbriggs extern const char dmover_funcname_xor10[]; 26790824326Sbriggs #define DMOVER_FUNC_XOR10 dmover_funcname_xor10 26890824326Sbriggs 26990824326Sbriggs extern const char dmover_funcname_xor11[]; 27090824326Sbriggs #define DMOVER_FUNC_XOR11 dmover_funcname_xor11 27190824326Sbriggs 27290824326Sbriggs extern const char dmover_funcname_xor12[]; 27390824326Sbriggs #define DMOVER_FUNC_XOR12 dmover_funcname_xor12 27490824326Sbriggs 27590824326Sbriggs extern const char dmover_funcname_xor13[]; 27690824326Sbriggs #define DMOVER_FUNC_XOR13 dmover_funcname_xor13 27790824326Sbriggs 27890824326Sbriggs extern const char dmover_funcname_xor14[]; 27990824326Sbriggs #define DMOVER_FUNC_XOR14 dmover_funcname_xor14 28090824326Sbriggs 28190824326Sbriggs extern const char dmover_funcname_xor15[]; 28290824326Sbriggs #define DMOVER_FUNC_XOR15 dmover_funcname_xor15 28390824326Sbriggs 28490824326Sbriggs extern const char dmover_funcname_xor16[]; 28590824326Sbriggs #define DMOVER_FUNC_XOR16 dmover_funcname_xor16 28690824326Sbriggs 2875d06c0e8Sthorpej /* Back-end management functions. */ 2885d06c0e8Sthorpej void dmover_backend_register(struct dmover_backend *); 2895d06c0e8Sthorpej void dmover_backend_unregister(struct dmover_backend *); 2905d06c0e8Sthorpej int dmover_backend_alloc(struct dmover_session *, const char *); 2915d06c0e8Sthorpej void dmover_backend_release(struct dmover_session *); 2925d06c0e8Sthorpej 2935d06c0e8Sthorpej /* Session management functions. */ 2945d06c0e8Sthorpej void dmover_session_initialize(void); 2955d06c0e8Sthorpej int dmover_session_create(const char *, struct dmover_session **); 2965d06c0e8Sthorpej void dmover_session_destroy(struct dmover_session *); 2975d06c0e8Sthorpej 2985d06c0e8Sthorpej /* Request management functions. */ 2995d06c0e8Sthorpej void dmover_request_initialize(void); 3005d06c0e8Sthorpej struct dmover_request *dmover_request_alloc(struct dmover_session *, 3015d06c0e8Sthorpej dmover_buffer *); 3025d06c0e8Sthorpej void dmover_request_free(struct dmover_request *); 3035d06c0e8Sthorpej 3045d06c0e8Sthorpej /* Processing engine functions. */ 3055d06c0e8Sthorpej void dmover_process_initialize(void); 3065d06c0e8Sthorpej void dmover_process(struct dmover_request *); 3075d06c0e8Sthorpej void dmover_done(struct dmover_request *); 3085d06c0e8Sthorpej 3095d06c0e8Sthorpej /* Utility functions. */ 3105d06c0e8Sthorpej const struct dmover_algdesc * 3115d06c0e8Sthorpej dmover_algdesc_lookup(const struct dmover_algdesc *, int, 3125d06c0e8Sthorpej const char *); 3135d06c0e8Sthorpej 3145d06c0e8Sthorpej #endif /* _DMOVER_DMOVERVAR_H_ */ 315