1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #ifndef _NSC_DEV_H
  27 #define _NSC_DEV_H
  28 
  29 #ifdef __cplusplus
  30 extern "C" {
  31 #endif
  32 
  33 #ifndef __NSC_GEN__
  34 Error: Illegal #include - private file.
  35 #endif
  36 
  37 
  38 #include <sys/nsctl/nsc_gen.h>
  39 #include <sys/nsc_ddi.h>
  40 
  41 /*
  42  * Interface to I/O module.
  43  */
  44 
  45 typedef struct nsc_io_s {
  46         struct nsc_io_s *next;          /* Link to next I/O module */
  47         kcondvar_t      cv;             /* Blocking variable */
  48         int     id;                     /* Module id */
  49         int     flag;                   /* Flags */
  50         char    *name;                  /* Module name */
  51         int     refcnt;                 /* Reference count */
  52         int     abufcnt;                /* # of allocated anonymous buffers */
  53         int     pend;                   /* Unregister pending */
  54         int     (*open)();              /* Open device */
  55         int     (*close)();             /* Close device */
  56         int     (*attach)();            /* Attach device */
  57         int     (*detach)();            /* Detach device */
  58         int     (*flush)();             /* Flush device */
  59         int     (*alloc_buf)();         /* Allocate buffer */
  60         int     (*free_buf)();          /* Free buffer */
  61         int     (*read)();              /* Read buffer */
  62         int     (*write)();             /* Write buffer */
  63         int     (*zero)();              /* Zero buffer */
  64         int     (*copy)();              /* Copy buffer between handles */
  65         int     (*copy_direct)();       /* Copy buffer between handle & disk */
  66         int     (*uncommit)();          /* Uncommit buffer */
  67         struct nsc_buf_s *(*alloc_h)(); /* Allocate handle */
  68         int     (*free_h)();            /* Free handle */
  69         int     (*uread)();             /* User read */
  70         int     (*uwrite)();            /* User write */
  71         int     (*trksize)();           /* Set track size */
  72         int     (*discard)();           /* Discard pinned data */
  73         int     (*sizes)();             /* Return size of cache */
  74         int     (*getpin)();            /* Get pinned info */
  75         int     (*nodehints)();         /* Return current node hints */
  76         int     (*partsize)();          /* Partition size */
  77         int     (*maxfbas)();           /* Maximum I/O size */
  78         int     (*control)();           /* Module control function */
  79         long    provide;                /* Interface provided */
  80 } nsc_io_t;
  81 
  82 
  83 typedef struct nsc_path_s {
  84         struct nsc_path_s *sp_next;     /* Link to next path */
  85         char    *sp_path;               /* Pathname */
  86         int     sp_type;                /* Open type */
  87         nsc_io_t        *sp_io;                 /* I/O module */
  88         int     sp_pend;                /* Unregister pending */
  89 } nsc_path_t;
  90 
  91 
  92 /*
  93  * Note: NSC_MAXPATH currently defined here and in nsctl.h
  94  */
  95 #if !defined(NSC_MAXPATH)
  96 #define NSC_MAXPATH     64
  97 #endif
  98 
  99 
 100 #define NSC_SETVAL_MAX  32
 101 
 102 typedef struct nsc_val_s {
 103         struct nsc_val_s *sv_next;      /* Link to next value */
 104         char    sv_name[NSC_SETVAL_MAX]; /* Name of value */
 105         int     sv_value;               /* Value of name */
 106 } nsc_val_t;
 107 
 108 
 109 typedef struct nsc_devval_s {
 110         struct nsc_devval_s *dv_next;           /* Next dev/val header */
 111         nsc_val_t       *dv_values;             /* The values */
 112         char            dv_path[NSC_MAXPATH];   /* Path name of device */
 113         uint64_t        dv_phash;               /* Hash of pathname */
 114 } nsc_devval_t;
 115 
 116 
 117 /* used for ncall */
 118 typedef struct nsc_rval_s {
 119         char    path[NSC_MAXPATH];      /* Path name of dev */
 120         char    name[NSC_SETVAL_MAX];   /* Name of value */
 121         int     value;                  /* Value of name */
 122 } nsc_rval_t;
 123 
 124 
 125 extern int _nsc_maxdev;
 126 
 127 #define _NSC_OPEN       0x0004          /* Open in progress */
 128 #define _NSC_CLOSE      0x0008          /* Close in progress */
 129 #define _NSC_PINNED     0x0010          /* Pinned data reported */
 130 #define _NSC_ATTACH     0x0020          /* Available for I/O */
 131 #define _NSC_DETACH     0x0040          /* Detach in progress */
 132 #define _NSC_OWNER      0x0080          /* Owner detach in progress */
 133 
 134 
 135 typedef struct nsc_iodev_s {
 136         struct nsc_iodev_s *si_next;    /* Link to next I/O device */
 137         struct nsc_fd_s *si_open;       /* Open file descriptors */
 138         kmutex_t        si_lock;        /* Lock to protect I/O chain */
 139         kcondvar_t      si_cv;          /* Blocking variable */
 140         int     si_refcnt;              /* Reference count */
 141         int     si_busy;                /* Callback in progress */
 142         int     si_pend;                /* Operation is pending */
 143         int     si_rpend;               /* Reserve is pending */
 144         int     si_avail;               /* Available for I/O */
 145         nsc_io_t *si_io;                        /* Interface to I/O module */
 146         void    *si_active;             /* Active I/O chain */
 147         struct nsc_dev_s *si_dev;       /* Device structure */
 148 } nsc_iodev_t;
 149 
 150 
 151 typedef struct nsc_dev_s {
 152         struct nsc_dev_s *nsc_next;     /* Link to next device */
 153         struct nsc_fd_s *nsc_close;     /* Closed file descriptors */
 154         nsc_iodev_t *nsc_list;          /* Active I/O modules */
 155         char    *nsc_path;              /* Pathname */
 156         uint64_t        nsc_phash;      /* Pathname hash */
 157         kmutex_t        nsc_lock;       /* Lock to protect state */
 158         int     nsc_refcnt;             /* Reference count */
 159         kcondvar_t      nsc_cv;         /* Blocking variable */
 160         int     nsc_wait;               /* Count of waiters */
 161         int     nsc_pend;               /* Operation is pending */
 162         int     nsc_rpend;              /* Reserve is pending */
 163         int     nsc_drop;               /* Detach on release */
 164         int     nsc_reopen;             /* Doing reopen */
 165         nsc_devval_t *nsc_values;       /* Values - see nsc_setval() */
 166 } nsc_dev_t;
 167 
 168 
 169 /*
 170  * Storage file descriptor.
 171  */
 172 
 173 typedef struct nsc_fd_s {
 174         struct nsc_fd_s *sf_next;       /* Link to next descriptor */
 175         nsc_iodev_t *sf_iodev;          /* I/O device structure */
 176         nsc_iodev_t *sf_owner;          /* Parent I/O device */
 177         nsc_dev_t *sf_dev;              /* Device structure */
 178         nsc_io_t *sf_aio;               /* Active I/O module */
 179         int     sf_avail;               /* Availability for I/O */
 180         int     sf_pend;                /* Operation is pending */
 181         int     sf_type;                /* Open type */
 182         int     sf_flag;                /* Open flags */
 183         clock_t sf_lbolt;               /* Open timestamp */
 184         int     sf_reopen;              /* Re-open required */
 185         blind_t sf_cd;                  /* Underlying I/O descriptor */
 186         blind_t sf_arg;                 /* Argument for callbacks */
 187         int     sf_reserve;             /* Device is reserved */
 188         int     sf_mode;                /* Type of reserve */
 189         void    (*sf_pinned)();         /* Callback - Data pinned */
 190         void    (*sf_unpinned)();       /* Callback - Data unpinned */
 191         int     (*sf_attach)();         /* Callback - Attach */
 192         int     (*sf_detach)();         /* Callback - Detach */
 193         int     (*sf_flush)();          /* Callback - Flush */
 194 } nsc_fd_t;
 195 
 196 
 197 /*
 198  * External definitions.
 199  */
 200 
 201 extern nsc_io_t *_nsc_null_io;
 202 
 203 #ifdef _KERNEL
 204 extern int _nsc_open_fd(nsc_fd_t *, int);
 205 extern int _nsc_close_fd(nsc_fd_t *, int);
 206 extern int _nsc_detach_fd(nsc_fd_t *, int);
 207 extern int _nsc_detach_iodev(nsc_iodev_t *, nsc_fd_t *, int);
 208 extern int _nsc_detach_dev(nsc_dev_t *, nsc_iodev_t *, int);
 209 extern int _nsc_call_io(long, blind_t, blind_t, blind_t);
 210 extern int _nsc_wait_dev(nsc_dev_t *, int);
 211 extern void _nsc_wake_dev(nsc_dev_t *, int *);
 212 #endif /* _KERNEL */
 213 
 214 #ifdef __cplusplus
 215 }
 216 #endif
 217 
 218 #endif /* _NSC_DEV_H */