10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 58551SPeng.L@Sun.COM * Common Development and Distribution License (the "License"). 68551SPeng.L@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 228551SPeng.L@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_SCSI_TARGETS_SD_XBUF_H 270Sstevel@tonic-gate #define _SYS_SCSI_TARGETS_SD_XBUF_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #ifdef __cplusplus 300Sstevel@tonic-gate extern "C" { 310Sstevel@tonic-gate #endif 320Sstevel@tonic-gate 330Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER) 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <sys/note.h> 360Sstevel@tonic-gate #include <sys/taskq.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate 390Sstevel@tonic-gate #if (defined(__fibre)) 400Sstevel@tonic-gate /* 410Sstevel@tonic-gate * These #defines are to avoid namespace collisions that occur because this 420Sstevel@tonic-gate * code is currently used to compile two seperate driver modules: sd and ssd. 430Sstevel@tonic-gate * All function names need to be treated this way (even if declared static) 440Sstevel@tonic-gate * in order to allow the debugger to resolve the names properly. 450Sstevel@tonic-gate * It is anticipated that in the near future the ssd module will be obsoleted, 460Sstevel@tonic-gate * at which time this ugliness should go away. 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate #define ddi_xbuf_attr_create ssd_ddi_xbuf_attr_create 490Sstevel@tonic-gate #define ddi_xbuf_attr_destroy ssd_ddi_xbuf_attr_destroy 500Sstevel@tonic-gate #define ddi_xbuf_attr_register_devinfo ssd_ddi_xbuf_attr_register_devinfo 510Sstevel@tonic-gate #define ddi_xbuf_attr_unregister_devinfo \ 520Sstevel@tonic-gate ssd_ddi_xbuf_attr_unregister_devinfo 530Sstevel@tonic-gate #define ddi_xbuf_qstrategy ssd_ddi_xbuf_qstrategy 540Sstevel@tonic-gate #define ddi_xbuf_done ssd_ddi_xbuf_done 550Sstevel@tonic-gate #define ddi_xbuf_get ssd_ddi_xbuf_get 560Sstevel@tonic-gate #define xbuf_iostart ssd_xbuf_iostart 570Sstevel@tonic-gate #define xbuf_dispatch ssd_xbuf_dispatch 580Sstevel@tonic-gate #define xbuf_restart_callback ssd_xbuf_restart_callback 590Sstevel@tonic-gate #define xbuf_tq ssd_xbuf_tq 600Sstevel@tonic-gate #define xbuf_attr_tq_minalloc ssd_xbuf_attr_tq_minalloc 610Sstevel@tonic-gate #define xbuf_attr_tq_maxalloc ssd_xbuf_attr_tq_maxalloc 620Sstevel@tonic-gate #define xbuf_mutex ssd_xbuf_mutex 630Sstevel@tonic-gate #define xbuf_refcount ssd_xbuf_refcount 640Sstevel@tonic-gate 650Sstevel@tonic-gate #define ddi_xbuf_dispatch ssd_ddi_xbuf_dispatch 660Sstevel@tonic-gate 670Sstevel@tonic-gate #define ddi_xbuf_flushq ssd_ddi_xbuf_flushq 68*8567SPeng.L@Sun.COM #define ddi_xbuf_attr_setup_brk ssd_ddi_xbuf_attr_setup_brk 690Sstevel@tonic-gate 700Sstevel@tonic-gate #endif 710Sstevel@tonic-gate 720Sstevel@tonic-gate 730Sstevel@tonic-gate typedef void * ddi_xbuf_t; 740Sstevel@tonic-gate 750Sstevel@tonic-gate 760Sstevel@tonic-gate /* 770Sstevel@tonic-gate * Primary attribute struct for buf extensions. 780Sstevel@tonic-gate */ 790Sstevel@tonic-gate struct __ddi_xbuf_attr { 800Sstevel@tonic-gate kmutex_t xa_mutex; 810Sstevel@tonic-gate size_t xa_allocsize; 820Sstevel@tonic-gate uint32_t xa_pending; /* call to xbuf_iostart() is iminent */ 830Sstevel@tonic-gate uint32_t xa_active_limit; 840Sstevel@tonic-gate uint32_t xa_active_count; 850Sstevel@tonic-gate uint32_t xa_active_lowater; 860Sstevel@tonic-gate struct buf *xa_headp; /* FIFO buf queue head ptr */ 870Sstevel@tonic-gate struct buf *xa_tailp; /* FIFO buf queue tail ptr */ 880Sstevel@tonic-gate kmutex_t xa_reserve_mutex; 890Sstevel@tonic-gate uint32_t xa_reserve_limit; 900Sstevel@tonic-gate uint32_t xa_reserve_count; 910Sstevel@tonic-gate void *xa_reserve_headp; 920Sstevel@tonic-gate void (*xa_strategy)(struct buf *, ddi_xbuf_t, void *); 930Sstevel@tonic-gate void *xa_attr_arg; 940Sstevel@tonic-gate timeout_id_t xa_timeid; 950Sstevel@tonic-gate taskq_t *xa_tq; 960Sstevel@tonic-gate struct buf *xa_flush_headp; 970Sstevel@tonic-gate struct buf *xa_flush_tailp; 988551SPeng.L@Sun.COM size_t xa_brksize; 990Sstevel@tonic-gate }; 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate typedef struct __ddi_xbuf_attr *ddi_xbuf_attr_t; 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate #define DDII 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate DDII ddi_xbuf_attr_t ddi_xbuf_attr_create(size_t xsize, 1070Sstevel@tonic-gate void (*xa_strategy)(struct buf *bp, ddi_xbuf_t xp, void *attr_arg), 1080Sstevel@tonic-gate void *attr_arg, uint32_t active_limit, uint32_t reserve_limit, 1090Sstevel@tonic-gate major_t major, int flags); 1100Sstevel@tonic-gate DDII void ddi_xbuf_attr_destroy(ddi_xbuf_attr_t xap); 1110Sstevel@tonic-gate DDII void ddi_xbuf_attr_register_devinfo(ddi_xbuf_attr_t xbuf_attr, 1120Sstevel@tonic-gate dev_info_t *dip); 1130Sstevel@tonic-gate DDII void ddi_xbuf_attr_unregister_devinfo(ddi_xbuf_attr_t xbuf_attr, 1140Sstevel@tonic-gate dev_info_t *dip); 1150Sstevel@tonic-gate DDII int ddi_xbuf_qstrategy(struct buf *bp, ddi_xbuf_attr_t xap); 1168551SPeng.L@Sun.COM DDII int ddi_xbuf_done(struct buf *bp, ddi_xbuf_attr_t xap); 1170Sstevel@tonic-gate DDII ddi_xbuf_t ddi_xbuf_get(struct buf *bp, ddi_xbuf_attr_t xap); 1180Sstevel@tonic-gate DDII void ddi_xbuf_dispatch(ddi_xbuf_attr_t xap); 1190Sstevel@tonic-gate DDII void ddi_xbuf_flushq(ddi_xbuf_attr_t xap, int (*funcp)(struct buf *)); 1208551SPeng.L@Sun.COM DDII int ddi_xbuf_attr_setup_brk(ddi_xbuf_attr_t xap, size_t size); 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate /* 1240Sstevel@tonic-gate * The buf extension facility utilizes an internal pool of threads to perform 1250Sstevel@tonic-gate * callbacks into the given xa_strategy routines. Clients of the facility 1260Sstevel@tonic-gate * do not need to be concerned with the management of these threads as this is 1270Sstevel@tonic-gate * handled by the framework. However clients may recommend certain operational 1280Sstevel@tonic-gate * parameters for the framework to consider in performing its thread mangement 1290Sstevel@tonic-gate * by specifying one of the following flags to ddi_xbuf_attr_create(): 1300Sstevel@tonic-gate * 1310Sstevel@tonic-gate * DDI_XBUF_QTHREAD_SYSTEM: This should be specified when the client driver 1320Sstevel@tonic-gate * provides an xa_strategy routine that is "well behaved", ie, does not 1330Sstevel@tonic-gate * block for memory, shared resources, or device states that may take a long 1340Sstevel@tonic-gate * or indeterminate amount of time to satisfy. The 'major' argument to 1350Sstevel@tonic-gate * ddi_xbuf_attr_create() may be zero if this flag is specified. (?) 1360Sstevel@tonic-gate * 1370Sstevel@tonic-gate * DDI_XBUF_QTHREAD_DRIVER: This should be specified when the client driver 1380Sstevel@tonic-gate * performs blocking operations within its xa_strategy routine that would 1390Sstevel@tonic-gate * make it unsuitable for being called from a shared system thread. The 1400Sstevel@tonic-gate * 'major' argument to ddi_xbuf_attr_create() must be the return value of 1410Sstevel@tonic-gate * ddi_driver_major() when this flag is specified. 1420Sstevel@tonic-gate * 1430Sstevel@tonic-gate * DDI_XBUF_QTHREAD_PRIVATE: This should be specified when the client driver 1440Sstevel@tonic-gate * would prefer to have a dedicated thread for a given ddi_xbuf_attr_t 1450Sstevel@tonic-gate * instantiation. The 'major' argument to ddi_xbuf_attr_create() must be 1460Sstevel@tonic-gate * the return value of ddi_driver_major() when this flag is specified. Note 1470Sstevel@tonic-gate * that this option ought to be used judiciously in order to avoid excessive 1480Sstevel@tonic-gate * consumption of system resources, especially if the client driver has a 1490Sstevel@tonic-gate * large number of ddi_xbuf_attr_t instantiations. 1500Sstevel@tonic-gate * 1510Sstevel@tonic-gate * Note that the above flags are mutually exclusive. Also note that the 1520Sstevel@tonic-gate * behaviors specified by these flags are merely advisory to the framework, 1530Sstevel@tonic-gate * and the framework is still free to implement its internal thread management 1540Sstevel@tonic-gate * policies as necessary and that these policies are opaque to drivers. 1550Sstevel@tonic-gate */ 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate #define DDI_XBUF_QTHREAD_SYSTEM 0x01 1580Sstevel@tonic-gate #define DDI_XBUF_QTHREAD_DRIVER 0x02 1590Sstevel@tonic-gate #define DDI_XBUF_QTHREAD_PRIVATE 0x04 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate #endif /* defined(_KERNEL) || defined(_KMEMUSER) */ 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate #ifdef __cplusplus 1660Sstevel@tonic-gate } 1670Sstevel@tonic-gate #endif 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate #endif /* _SYS_SCSI_TARGETS_SD_XBUF_H */ 171