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 114 typedef struct sbd_pgr_key_info { 115 uint64_t pgr_key; 116 uint16_t pgr_key_lpt_len; 117 uint16_t pgr_key_rpt_len; 118 uint8_t pgr_key_flags; 119 uint8_t pgr_key_it[1]; /* devid_desc of initiator will be */ 120 /* followed by devid_desc of target */ 121 } sbd_pgr_key_info_t; 122 123 typedef struct sbd_pgr_info { 124 sm_section_hdr_t pgr_sms_header; 125 uint32_t pgr_rsvholder_indx; 126 uint32_t pgr_numkeys; 127 uint8_t pgr_flags; 128 uint8_t pgr_data_order; 129 #ifdef _BIT_FIELDS_LTOH 130 uint8_t pgr_rsv_type:4, 131 pgr_rsv_scope:4; 132 #else 133 uint8_t pgr_rsv_scope:4, 134 pgr_rsv_type:4; 135 #endif 136 uint8_t rsvd[5]; /* 8 byte boundary */ 137 138 } sbd_pgr_info_t; 139 140 typedef struct sbd_pgr_key { 141 uint64_t pgr_key; 142 uint16_t pgr_key_lpt_len; 143 uint16_t pgr_key_rpt_len; 144 uint8_t pgr_key_flags; 145 struct scsi_devid_desc *pgr_key_lpt_id; 146 struct scsi_devid_desc *pgr_key_rpt_id; 147 struct sbd_it_data *pgr_key_it; 148 struct sbd_pgr_key *pgr_key_next; 149 struct sbd_pgr_key *pgr_key_prev; 150 } sbd_pgr_key_t; 151 152 typedef struct sbd_pgr { 153 sbd_pgr_key_t *pgr_keylist; 154 sbd_pgr_key_t *pgr_rsvholder; 155 uint32_t pgr_PRgeneration; /* PGR PRgeneration value */ 156 uint8_t pgr_flags; /* PGR flags (eg: APTPL) */ 157 uint8_t pgr_rsv_type:4, 158 pgr_rsv_scope:4; 159 krwlock_t pgr_lock; /* Lock order pgr_lock, sl_lock */ 160 } sbd_pgr_t; 161 162 163 typedef struct sbd_v0_lu_info { 164 sm_v0_section_hdr_t sli_sms_header; 165 uint64_t sli_total_store_size; 166 uint64_t sli_total_meta_size; 167 uint64_t rsvd0; 168 uint64_t sli_lu_data_offset; 169 uint64_t sli_lu_data_size; 170 uint64_t rsvd1; 171 uint32_t sli_flags; 172 uint16_t sli_blocksize; 173 uint16_t rsvd2; 174 uint8_t sli_lu_devid[20]; 175 uint32_t rsvd3; 176 } sbd_v0_lu_info_t; 177 178 typedef struct sbd_lu_info { 179 sm_section_hdr_t sli_sms_header; 180 uint64_t sli_total_store_size; 181 uint64_t sli_total_meta_size; 182 uint64_t sli_lu_data_offset; 183 uint64_t sli_lu_data_size; 184 uint32_t sli_flags; 185 uint16_t sli_blocksize; 186 uint8_t sli_data_order; 187 uint8_t rsvd1; 188 uint8_t sli_lu_devid[20]; 189 uint32_t rsvd2; 190 } sbd_lu_info_t; 191 192 /* 193 * sl_flags 194 */ 195 #define SBD_LU_HAS_SCSI2_RESERVATION 0x0001 196 197 typedef struct sbd_cmd { 198 uint8_t flags; 199 uint8_t nbufs; 200 uint16_t cmd_type; /* Type of command */ 201 uint32_t rsvd2; 202 uint64_t addr; /* current */ 203 uint32_t len; /* len left */ 204 uint32_t current_ro; /* running relative offset */ 205 } sbd_cmd_t; 206 207 /* 208 * flags for sbd_cmd 209 */ 210 #define SBD_SCSI_CMD_ACTIVE 0x01 211 #define SBD_SCSI_CMD_ABORT_REQUESTED 0x02 212 #define SBD_SCSI_CMD_XFER_FAIL 0x04 213 #define SBD_SCSI_CMD_SYNC_WRITE 0x08 214 215 /* 216 * cmd types 217 */ 218 #define SBD_CMD_SCSI_READ 0x01 219 #define SBD_CMD_SCSI_WRITE 0x02 220 #define SBD_CMD_SMALL_READ 0x03 221 #define SBD_CMD_SMALL_WRITE 0x04 222 #define SBD_CMD_SCSI_PR_OUT 0x05 223 224 typedef struct sbd_it_data { 225 struct sbd_it_data *sbd_it_next; 226 uint64_t sbd_it_session_id; 227 uint8_t sbd_it_lun[8]; 228 uint8_t sbd_it_ua_conditions; 229 uint8_t sbd_it_flags; 230 sbd_pgr_key_t *pgr_key_ptr; 231 } sbd_it_data_t; 232 233 typedef struct sbd_create_standby_lu { 234 uint32_t stlu_meta_fname_size; 235 uint32_t stlu_rsvd; 236 uint8_t stlu_guid[16]; 237 char stlu_meta_fname[8]; 238 } sbd_create_standby_lu_t; 239 240 /* 241 * Different UA conditions 242 */ 243 #define SBD_UA_POR 0x01 244 #define SBD_UA_CAPACITY_CHANGED 0x02 245 #define SBD_UA_MODE_PARAMETERS_CHANGED 0x04 246 #define SBD_UA_ACCESS_STATE_TRANSITION 0x08 247 #define SBD_UA_REGISTRATIONS_PREEMPTED 0x10 248 #define SBD_UA_RESERVATIONS_PREEMPTED 0x20 249 #define SBD_UA_RESERVATIONS_RELEASED 0x40 250 #define SBD_UA_ASYMMETRIC_ACCESS_CHANGED 0x80 251 252 /* 253 * sbd_it_flags 254 */ 255 #define SBD_IT_HAS_SCSI2_RESERVATION 0x0001 256 257 stmf_status_t sbd_task_alloc(struct scsi_task *task); 258 void sbd_new_task(struct scsi_task *task, struct stmf_data_buf *initial_dbuf); 259 void sbd_dbuf_xfer_done(struct scsi_task *task, struct stmf_data_buf *dbuf); 260 void sbd_send_status_done(struct scsi_task *task); 261 void sbd_task_free(struct scsi_task *task); 262 stmf_status_t sbd_abort(struct stmf_lu *lu, int abort_cmd, void *arg, 263 uint32_t flags); 264 void sbd_ctl(struct stmf_lu *lu, int cmd, void *arg); 265 stmf_status_t sbd_info(uint32_t cmd, stmf_lu_t *lu, void *arg, 266 uint8_t *buf, uint32_t *bufsizep); 267 268 #ifdef __cplusplus 269 } 270 #endif 271 272 #endif /* _SBD_IMPL_H */ 273