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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 23 */ 24 25 #ifndef _SBD_IMPL_H 26 #define _SBD_IMPL_H 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 struct register_lu_cmd; 33 struct modify_lu_cmd; 34 struct sbd_lu_attr; 35 struct sbd_it_data; 36 37 /* 38 * sms endianess 39 */ 40 #define SMS_BIG_ENDIAN 0x00 41 #define SMS_LITTLE_ENDIAN 0xFF 42 43 #ifdef _BIG_ENDIAN 44 #define SMS_DATA_ORDER SMS_BIG_ENDIAN 45 #else 46 #define SMS_DATA_ORDER SMS_LITTLE_ENDIAN 47 #endif 48 49 /* Test if one of the BitOrder definitions exists */ 50 #ifdef _BIT_FIELDS_LTOH 51 #elif defined(_BIT_FIELDS_HTOL) 52 #else 53 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 54 #endif 55 56 #define SBD_V0_MAGIC 0x53554e4d4943524f 57 #define SBD_MAGIC 0x53554e5342444c55 58 59 typedef struct sbd_v0_meta_start { 60 uint64_t sm_magic; /* SBD_MAGIC */ 61 uint64_t sm_meta_size; /* Includes everything */ 62 } sbd_v0_meta_start_t; 63 64 typedef struct sbd_meta_start { 65 uint64_t sm_magic; 66 uint64_t sm_meta_size; 67 uint64_t sm_meta_size_used; 68 uint64_t sm_rsvd1; /* Defaults to zero */ 69 uint64_t sm_rsvd2; 70 uint16_t sm_ver_major; 71 uint16_t sm_ver_minor; 72 uint16_t sm_ver_subminor; 73 uint8_t sm_flags; /* None at this moment */ 74 uint8_t sm_chksum; 75 } sbd_meta_start_t; 76 77 typedef struct sm_v0_section_hdr { 78 uint64_t sms_offset; /* Offset of this section */ 79 uint64_t sms_size; /* Includes the header and padding */ 80 uint16_t sms_id; /* Section identifier */ 81 uint16_t sms_padding; /* For alignment */ 82 uint32_t sms_seqno; /* For multiple sections with same ID */ 83 uint8_t sms_hdr_data_order; /* 0x00 or 0xff */ 84 uint8_t sms_payload_data_order; 85 uint16_t rsvd2; 86 uint32_t rsvd3; /* 8 byte align */ 87 } sm_v0_section_hdr_t; 88 89 /* 90 * sbd_it_flags 91 */ 92 #define SBD_IT_HAS_SCSI2_RESERVATION 0x0001 93 #define SBD_IT_PGR_REGISTERED 0x0002 94 #define SBD_IT_PGR_EXCLUSIVE_RSV_HOLDER 0x0004 95 #define SBD_IT_PGR_CHECK_FLAG 0x0008 96 97 /* 98 * PGR flags 99 */ 100 #define SBD_PGR_APTPL 0x01 101 #define SBD_PGR_RSVD_ONE 0x02 102 #define SBD_PGR_RSVD_ALL_REGISTRANTS 0x04 103 #define SBD_PGR_ALL_KEYS_HAS_IT 0x08 104 105 #define SBD_PGR_RSVD(pgr) (((pgr)->pgr_flags) & (SBD_PGR_RSVD_ONE | \ 106 SBD_PGR_RSVD_ALL_REGISTRANTS)) 107 #define SBD_PGR_RSVD_NONE(pgr) (!(SBD_PGR_RSVD(pgr))) 108 109 /* 110 * PGR key flags 111 */ 112 #define SBD_PGR_KEY_ALL_TG_PT 0x01 113 #define SBD_PGR_KEY_TPT_ID_FLAG 0x02 114 115 typedef struct sbd_pgr_key_info { 116 uint64_t pgr_key; 117 uint16_t pgr_key_lpt_len; 118 uint16_t pgr_key_rpt_len; 119 uint8_t pgr_key_flags; 120 uint8_t pgr_key_it[1]; /* order:- initiator info followed by */ 121 /* scsi_devid_desc of local port */ 122 } sbd_pgr_key_info_t; 123 124 typedef struct sbd_pgr_info { 125 sm_section_hdr_t pgr_sms_header; 126 uint32_t pgr_rsvholder_indx; 127 uint32_t pgr_numkeys; 128 uint8_t pgr_flags; 129 uint8_t pgr_data_order; 130 #ifdef _BIT_FIELDS_LTOH 131 uint8_t pgr_rsv_type:4, 132 pgr_rsv_scope:4; 133 #else 134 uint8_t pgr_rsv_scope:4, 135 pgr_rsv_type:4; 136 #endif 137 uint8_t rsvd[5]; /* 8 byte boundary */ 138 139 } sbd_pgr_info_t; 140 141 typedef struct sbd_pgr_key { 142 uint64_t pgr_key; 143 uint16_t pgr_key_lpt_len; 144 uint16_t pgr_key_rpt_len; 145 uint8_t pgr_key_flags; 146 struct scsi_devid_desc *pgr_key_lpt_id; 147 struct scsi_transport_id *pgr_key_rpt_id; 148 struct sbd_it_data *pgr_key_it; 149 struct sbd_pgr_key *pgr_key_next; 150 struct sbd_pgr_key *pgr_key_prev; 151 } sbd_pgr_key_t; 152 153 typedef struct sbd_pgr { 154 sbd_pgr_key_t *pgr_keylist; 155 sbd_pgr_key_t *pgr_rsvholder; 156 uint32_t pgr_PRgeneration; /* PGR PRgeneration value */ 157 uint8_t pgr_flags; /* PGR flags (eg: APTPL) */ 158 uint8_t pgr_rsv_type:4, 159 pgr_rsv_scope:4; 160 krwlock_t pgr_lock; /* Lock order pgr_lock, sl_lock */ 161 } sbd_pgr_t; 162 163 164 typedef struct sbd_v0_lu_info { 165 sm_v0_section_hdr_t sli_sms_header; 166 uint64_t sli_total_store_size; 167 uint64_t sli_total_meta_size; 168 uint64_t rsvd0; 169 uint64_t sli_lu_data_offset; 170 uint64_t sli_lu_data_size; 171 uint64_t rsvd1; 172 uint32_t sli_flags; 173 uint16_t sli_blocksize; 174 uint16_t rsvd2; 175 uint8_t sli_lu_devid[20]; 176 uint32_t rsvd3; 177 } sbd_v0_lu_info_t; 178 179 typedef struct sbd_lu_info { 180 sm_section_hdr_t sli_sms_header; 181 uint64_t sli_total_store_size; 182 uint64_t sli_total_meta_size; 183 uint64_t sli_lu_data_offset; 184 uint64_t sli_lu_data_size; 185 uint32_t sli_flags; 186 uint16_t sli_blocksize; 187 uint8_t sli_data_order; 188 uint8_t rsvd1; 189 uint8_t sli_lu_devid[20]; 190 uint32_t rsvd2; 191 } sbd_lu_info_t; 192 193 /* 194 * sl_flags 195 */ 196 #define SBD_LU_HAS_SCSI2_RESERVATION 0x0001 197 198 typedef struct sbd_cmd { 199 uint8_t flags; 200 uint8_t nbufs; 201 uint16_t cmd_type; /* Type of command */ 202 uint32_t rsvd2; 203 uint64_t addr; /* current */ 204 uint32_t len; /* len left */ 205 uint32_t current_ro; /* running relative offset */ 206 } sbd_cmd_t; 207 208 /* 209 * flags for sbd_cmd 210 */ 211 #define SBD_SCSI_CMD_ACTIVE 0x01 212 #define SBD_SCSI_CMD_ABORT_REQUESTED 0x02 213 #define SBD_SCSI_CMD_XFER_FAIL 0x04 214 #define SBD_SCSI_CMD_SYNC_WRITE 0x08 215 216 /* 217 * cmd types 218 */ 219 #define SBD_CMD_SCSI_READ 0x01 220 #define SBD_CMD_SCSI_WRITE 0x02 221 #define SBD_CMD_SMALL_READ 0x03 222 #define SBD_CMD_SMALL_WRITE 0x04 223 #define SBD_CMD_SCSI_PR_OUT 0x05 224 225 typedef struct sbd_it_data { 226 struct sbd_it_data *sbd_it_next; 227 uint64_t sbd_it_session_id; 228 uint8_t sbd_it_lun[8]; 229 uint8_t sbd_it_ua_conditions; 230 uint8_t sbd_it_flags; 231 sbd_pgr_key_t *pgr_key_ptr; 232 } sbd_it_data_t; 233 234 typedef struct sbd_create_standby_lu { 235 uint32_t stlu_meta_fname_size; 236 uint32_t stlu_rsvd; 237 uint8_t stlu_guid[16]; 238 char stlu_meta_fname[8]; 239 } sbd_create_standby_lu_t; 240 241 /* 242 * Different UA conditions 243 */ 244 #define SBD_UA_POR 0x01 245 #define SBD_UA_CAPACITY_CHANGED 0x02 246 #define SBD_UA_MODE_PARAMETERS_CHANGED 0x04 247 #define SBD_UA_ACCESS_STATE_TRANSITION 0x08 248 #define SBD_UA_REGISTRATIONS_PREEMPTED 0x10 249 #define SBD_UA_RESERVATIONS_PREEMPTED 0x20 250 #define SBD_UA_RESERVATIONS_RELEASED 0x40 251 #define SBD_UA_ASYMMETRIC_ACCESS_CHANGED 0x80 252 253 /* 254 * sbd_it_flags 255 */ 256 #define SBD_IT_HAS_SCSI2_RESERVATION 0x0001 257 258 /* 259 * dbuf private data needed for direct zvol data transfers 260 * 261 * To further isolate the zvol knowledge, the object handles 262 * needed to call into zfs are declared void * here. 263 */ 264 265 typedef struct sbd_zvol_io { 266 uint64_t zvio_offset; /* offset into volume */ 267 int zvio_flags; /* flags */ 268 void *zvio_dbp; /* array of dmu buffers */ 269 void *zvio_abp; /* array of arc buffers */ 270 uio_t *zvio_uio; /* for copy operations */ 271 } sbd_zvol_io_t; 272 273 #define ZVIO_DEFAULT 0 274 #define ZVIO_COMMIT 1 275 #define ZVIO_ABORT 2 276 #define ZVIO_SYNC 4 277 #define ZVIO_ASYNC 8 278 279 /* 280 * zvol data path functions 281 */ 282 int sbd_zvol_get_volume_params(sbd_lu_t *sl); 283 uint32_t sbd_zvol_numsegs(sbd_lu_t *sl, uint64_t off, uint32_t len); 284 int sbd_zvol_alloc_read_bufs(sbd_lu_t *sl, stmf_data_buf_t *dbuf); 285 void sbd_zvol_rele_read_bufs(sbd_lu_t *sl, stmf_data_buf_t *dbuf); 286 int sbd_zvol_alloc_write_bufs(sbd_lu_t *sl, stmf_data_buf_t *dbuf); 287 void sbd_zvol_rele_write_bufs_abort(sbd_lu_t *sl, stmf_data_buf_t *dbuf); 288 int sbd_zvol_rele_write_bufs(sbd_lu_t *sl, stmf_data_buf_t *dbuf); 289 int sbd_zvol_copy_read(sbd_lu_t *sl, uio_t *uio); 290 int sbd_zvol_copy_write(sbd_lu_t *sl, uio_t *uio, int flags); 291 292 stmf_status_t sbd_task_alloc(struct scsi_task *task); 293 void sbd_new_task(struct scsi_task *task, struct stmf_data_buf *initial_dbuf); 294 void sbd_dbuf_xfer_done(struct scsi_task *task, struct stmf_data_buf *dbuf); 295 void sbd_send_status_done(struct scsi_task *task); 296 void sbd_task_free(struct scsi_task *task); 297 stmf_status_t sbd_abort(struct stmf_lu *lu, int abort_cmd, void *arg, 298 uint32_t flags); 299 void sbd_dbuf_free(struct scsi_task *task, struct stmf_data_buf *dbuf); 300 void sbd_ctl(struct stmf_lu *lu, int cmd, void *arg); 301 stmf_status_t sbd_info(uint32_t cmd, stmf_lu_t *lu, void *arg, 302 uint8_t *buf, uint32_t *bufsizep); 303 304 #ifdef __cplusplus 305 } 306 #endif 307 308 #endif /* _SBD_IMPL_H */ 309