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 _SBD_IMPL_H 27 #define _SBD_IMPL_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 struct register_lu_cmd; 34 struct modify_lu_cmd; 35 struct sbd_lu_attr; 36 struct sbd_it_data; 37 38 /* 39 * sms endianess 40 */ 41 #define SMS_BIG_ENDIAN 0x00 42 #define SMS_LITTLE_ENDIAN 0xFF 43 44 #ifdef _BIG_ENDIAN 45 #define SMS_DATA_ORDER SMS_BIG_ENDIAN 46 #else 47 #define SMS_DATA_ORDER SMS_LITTLE_ENDIAN 48 #endif 49 50 #define SBD_V0_MAGIC 0x53554e4d4943524f 51 #define SBD_MAGIC 0x53554e5342444c55 52 53 typedef struct sbd_v0_meta_start { 54 uint64_t sm_magic; /* SBD_MAGIC */ 55 uint64_t sm_meta_size; /* Includes everything */ 56 } sbd_v0_meta_start_t; 57 58 typedef struct sbd_meta_start { 59 uint64_t sm_magic; 60 uint64_t sm_meta_size; 61 uint64_t sm_meta_size_used; 62 uint64_t sm_rsvd1; /* Defaults to zero */ 63 uint64_t sm_rsvd2; 64 uint16_t sm_ver_major; 65 uint16_t sm_ver_minor; 66 uint16_t sm_ver_subminor; 67 uint8_t sm_flags; /* None at this moment */ 68 uint8_t sm_chksum; 69 } sbd_meta_start_t; 70 71 typedef struct sm_v0_section_hdr { 72 uint64_t sms_offset; /* Offset of this section */ 73 uint64_t sms_size; /* Includes the header and padding */ 74 uint16_t sms_id; /* Section identifier */ 75 uint16_t sms_padding; /* For alignment */ 76 uint32_t sms_seqno; /* For multiple sections with same ID */ 77 uint8_t sms_hdr_data_order; /* 0x00 or 0xff */ 78 uint8_t sms_payload_data_order; 79 uint16_t rsvd2; 80 uint32_t rsvd3; /* 8 byte align */ 81 } sm_v0_section_hdr_t; 82 83 typedef struct sm_section_hdr { 84 uint64_t sms_offset; /* Offset of this section */ 85 uint32_t sms_size; /* Includes the header and padding */ 86 uint16_t sms_id; /* Section identifier */ 87 uint8_t sms_data_order; /* 0x00 or 0xff */ 88 uint8_t sms_chksum; 89 } sm_section_hdr_t; 90 91 /* 92 * sbd meta section identifiers 93 */ 94 #define SMS_ID_LU_INFO 0 95 96 typedef struct sbd_v0_lu_info { 97 sm_v0_section_hdr_t sli_sms_header; 98 uint64_t sli_total_store_size; 99 uint64_t sli_total_meta_size; 100 uint64_t rsvd0; 101 uint64_t sli_lu_data_offset; 102 uint64_t sli_lu_data_size; 103 uint64_t rsvd1; 104 uint32_t sli_flags; 105 uint16_t sli_blocksize; 106 uint16_t rsvd2; 107 uint8_t sli_lu_devid[20]; 108 uint32_t rsvd3; 109 } sbd_v0_lu_info_t; 110 111 typedef struct sbd_lu_info { 112 sm_section_hdr_t sli_sms_header; 113 uint64_t sli_total_store_size; 114 uint64_t sli_total_meta_size; 115 uint64_t sli_lu_data_offset; 116 uint64_t sli_lu_data_size; 117 uint32_t sli_flags; 118 uint16_t sli_blocksize; 119 uint8_t sli_data_order; 120 uint8_t rsvd1; 121 uint8_t sli_lu_devid[20]; 122 uint32_t rsvd2; 123 } sbd_lu_info_t; 124 125 typedef struct sbd_lu { 126 sbd_store_t *sl_sst; 127 uint32_t sl_total_allocation_size; 128 uint8_t sl_shift_count; 129 uint8_t sl_state:7, 130 sl_state_not_acked:1; 131 uint8_t sl_flags; 132 kmutex_t sl_it_list_lock; 133 struct sbd_it_data *sl_it_list; 134 uint64_t sl_rs_owner_session_id; 135 stmf_lu_t *sl_lu; 136 struct sbd_lu *sl_next; /* for int. tracking */ 137 138 sbd_meta_start_t sl_sm; 139 sbd_lu_info_t *sl_sli; 140 uint64_t sl_meta_offset; 141 } sbd_lu_t; 142 143 extern sbd_lu_t *sbd_lu_list; 144 145 /* 146 * sl_flags 147 */ 148 #define SBD_LU_HAS_SCSI2_RESERVATION 0x0001 149 150 typedef struct sbd_cmd { 151 uint8_t flags; 152 uint8_t nbufs; 153 uint16_t cmd_type; /* Type of command */ 154 uint32_t rsvd2; 155 uint64_t addr; /* current */ 156 uint32_t len; /* len left */ 157 uint32_t current_ro; /* running relative offset */ 158 } sbd_cmd_t; 159 160 /* 161 * flags for sbd_cmd 162 */ 163 #define SBD_SCSI_CMD_ACTIVE 0x01 164 #define SBD_SCSI_CMD_ABORT_REQUESTED 0x02 165 #define SBD_SCSI_CMD_XFER_FAIL 0x04 166 167 /* 168 * cmd types 169 */ 170 #define SBD_CMD_SCSI_READ 0x01 171 #define SBD_CMD_SCSI_WRITE 0x02 172 #define SBD_CMD_SMALL_READ 0x03 173 #define SBD_CMD_SMALL_WRITE 0x04 174 175 typedef struct sbd_it_data { 176 struct sbd_it_data *sbd_it_next; 177 uint64_t sbd_it_session_id; 178 uint8_t sbd_it_lun[8]; 179 uint8_t sbd_it_ua_conditions; 180 uint8_t sbd_it_flags; 181 } sbd_it_data_t; 182 183 /* 184 * Different UA conditions 185 */ 186 #define SBD_UA_POR 0x01 187 #define SBD_UA_CAPACITY_CHANGED 0x02 188 189 /* 190 * sbd_it_flags 191 */ 192 #define SBD_IT_HAS_SCSI2_RESERVATION 0x0001 193 194 stmf_status_t sbd_task_alloc(struct scsi_task *task); 195 void sbd_new_task(struct scsi_task *task, struct stmf_data_buf *initial_dbuf); 196 void sbd_dbuf_xfer_done(struct scsi_task *task, struct stmf_data_buf *dbuf); 197 void sbd_send_status_done(struct scsi_task *task); 198 void sbd_task_free(struct scsi_task *task); 199 stmf_status_t sbd_abort(struct stmf_lu *lu, int abort_cmd, void *arg, 200 uint32_t flags); 201 void sbd_ctl(struct stmf_lu *lu, int cmd, void *arg); 202 stmf_status_t sbd_info(uint32_t cmd, stmf_lu_t *lu, void *arg, 203 uint8_t *buf, uint32_t *bufsizep); 204 205 stmf_status_t memdisk_register_lu(struct register_lu_cmd *rlc); 206 stmf_status_t memdisk_deregister_lu(sbd_store_t *sst); 207 stmf_status_t filedisk_register_lu(struct register_lu_cmd *rlc); 208 stmf_status_t filedisk_deregister_lu(sbd_store_t *sst); 209 stmf_status_t filedisk_modify_lu(sbd_store_t *sst, struct modify_lu_cmd *mlc); 210 void filedisk_fillout_attr(struct sbd_store *sst, struct sbd_lu_attr *sla); 211 void memdisk_fillout_attr(struct sbd_store *sst, struct sbd_lu_attr *sla); 212 213 #ifdef __cplusplus 214 } 215 #endif 216 217 #endif /* _SBD_IMPL_H */ 218