1fcf3ce44SJohn Forte /* 2fcf3ce44SJohn Forte * CDDL HEADER START 3fcf3ce44SJohn Forte * 4fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the 5fcf3ce44SJohn Forte * Common Development and Distribution License (the "License"). 6fcf3ce44SJohn Forte * You may not use this file except in compliance with the License. 7fcf3ce44SJohn Forte * 8fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing. 10fcf3ce44SJohn Forte * See the License for the specific language governing permissions 11fcf3ce44SJohn Forte * and limitations under the License. 12fcf3ce44SJohn Forte * 13fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each 14fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the 16fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying 17fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner] 18fcf3ce44SJohn Forte * 19fcf3ce44SJohn Forte * CDDL HEADER END 20fcf3ce44SJohn Forte */ 21fcf3ce44SJohn Forte /* 223fb517f7SJames Moore * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 23b77b9231SDan McDonald * 24047c81d3SSaso Kiselkov * Copyright 2017 Nexenta Systems, Inc. All rights reserved. 25fcf3ce44SJohn Forte */ 26fcf3ce44SJohn Forte 27fcf3ce44SJohn Forte #ifndef _STMF_SBD_H 28fcf3ce44SJohn Forte #define _STMF_SBD_H 29fcf3ce44SJohn Forte 30047c81d3SSaso Kiselkov #include <sys/dkio.h> 31047c81d3SSaso Kiselkov 32fcf3ce44SJohn Forte #ifdef __cplusplus 33fcf3ce44SJohn Forte extern "C" { 34fcf3ce44SJohn Forte #endif 35fcf3ce44SJohn Forte 368fe96085Stim szeto typedef stmf_status_t sbd_status_t; 37*61dfa509SRick McNeal #include "ats_copy_mgr.h" 388fe96085Stim szeto extern char sbd_vendor_id[]; 398fe96085Stim szeto extern char sbd_product_id[]; 408fe96085Stim szeto extern char sbd_revision[]; 417beff157SJohn Forte extern char *sbd_mgmt_url; 427beff157SJohn Forte extern uint16_t sbd_mgmt_url_alloc_size; 437beff157SJohn Forte extern krwlock_t sbd_global_prop_lock; 447beff157SJohn Forte 458fe96085Stim szeto /* 468fe96085Stim szeto * Error codes 478fe96085Stim szeto */ 488fe96085Stim szeto #define SBD_SUCCESS STMF_SUCCESS 49fcf3ce44SJohn Forte #define SBD_FAILURE STMF_LU_FAILURE 508fe96085Stim szeto 518fe96085Stim szeto #define SBD_ALREADY (SBD_FAILURE | STMF_FSC(1)) 528fe96085Stim szeto #define SBD_NOT_SUPPORTED (SBD_FAILURE | STMF_FSC(2)) 538fe96085Stim szeto #define SBD_META_CORRUPTED (SBD_FAILURE | STMF_FSC(3)) 548fe96085Stim szeto #define SBD_INVALID_ARG (SBD_FAILURE | STMF_FSC(4)) 558fe96085Stim szeto #define SBD_NOT_FOUND (SBD_FAILURE | STMF_FSC(5)) 568fe96085Stim szeto #define SBD_ALLOC_FAILURE (SBD_FAILURE | STMF_FSC(6)) 578fe96085Stim szeto #define SBD_FILEIO_FAILURE (SBD_FAILURE | STMF_FSC(7)) 588fe96085Stim szeto #define SBD_IO_PAST_EOF (SBD_FAILURE | STMF_FSC(8)) 598fe96085Stim szeto #define SBD_BUSY (SBD_FAILURE | STMF_FSC(9)) 60*61dfa509SRick McNeal #define SBD_COMPARE_FAILED (SBD_FAILURE | STMF_FSC(10)) 618fe96085Stim szeto 628fe96085Stim szeto #define SHARED_META_DATA_SIZE 65536 638fe96085Stim szeto #define SBD_META_OFFSET 4096 648fe96085Stim szeto #define SBD_MIN_LU_SIZE (1024 * 1024) 65fcf3ce44SJohn Forte 66fcf3ce44SJohn Forte /* 678fe96085Stim szeto * sms endianess 68fcf3ce44SJohn Forte */ 698fe96085Stim szeto #define SMS_BIG_ENDIAN 0x00 708fe96085Stim szeto #define SMS_LITTLE_ENDIAN 0xFF 71fcf3ce44SJohn Forte 728fe96085Stim szeto #ifdef _BIG_ENDIAN 738fe96085Stim szeto #define SMS_DATA_ORDER SMS_BIG_ENDIAN 748fe96085Stim szeto #else 758fe96085Stim szeto #define SMS_DATA_ORDER SMS_LITTLE_ENDIAN 768fe96085Stim szeto #endif 77fcf3ce44SJohn Forte 788fe96085Stim szeto #define SBD_MAGIC 0x53554e5342444c55 79fcf3ce44SJohn Forte 808fe96085Stim szeto #define SBD_VER_MAJOR 1 818fe96085Stim szeto #define SBD_VER_MINOR 1 828fe96085Stim szeto #define SBD_VER_SUBMINOR 0 83fcf3ce44SJohn Forte 848fe96085Stim szeto #if 0 858fe96085Stim szeto typedef struct sbd_meta_start { 868fe96085Stim szeto uint64_t sm_magic; 878fe96085Stim szeto uint64_t sm_meta_size; 888fe96085Stim szeto uint64_t sm_meta_size_used; 898fe96085Stim szeto uint64_t sm_rsvd1; /* Defaults to zero */ 908fe96085Stim szeto uint64_t sm_rsvd2; 918fe96085Stim szeto uint16_t sm_ver_major; 928fe96085Stim szeto uint16_t sm_ver_minor; 938fe96085Stim szeto uint16_t sm_ver_subminor; 948fe96085Stim szeto uint8_t sm_flags; 958fe96085Stim szeto uint8_t sm_chksum; 968fe96085Stim szeto } sbd_meta_start_t; 978fe96085Stim szeto #endif 988fe96085Stim szeto 998fe96085Stim szeto typedef struct sm_section_hdr { 1008fe96085Stim szeto uint64_t sms_offset; /* Offset of this section */ 1018fe96085Stim szeto uint32_t sms_size; /* Includes the header and padding */ 1028fe96085Stim szeto uint16_t sms_id; /* Section identifier */ 1038fe96085Stim szeto uint8_t sms_data_order; /* 0x00 or 0xff */ 1048fe96085Stim szeto uint8_t sms_chksum; 1058fe96085Stim szeto } sm_section_hdr_t; 106fcf3ce44SJohn Forte 107fcf3ce44SJohn Forte /* 1088fe96085Stim szeto * sbd meta section identifiers 109fcf3ce44SJohn Forte */ 1108fe96085Stim szeto #define SMS_ID_LU_INFO_1_0 0 1118fe96085Stim szeto #define SMS_ID_LU_INFO_1_1 1 1128fe96085Stim szeto #define SMS_ID_PGR_INFO 2 1138fe96085Stim szeto #define SMS_ID_UNUSED 0x1000 114fcf3ce44SJohn Forte 1158fe96085Stim szeto typedef struct sbd_lu_info_1_0 { 1168fe96085Stim szeto sm_section_hdr_t sli_sms_header; 1178fe96085Stim szeto uint64_t sli_total_store_size; 1188fe96085Stim szeto uint64_t sli_total_meta_size; 1198fe96085Stim szeto uint64_t sli_lu_data_offset; 1208fe96085Stim szeto uint64_t sli_lu_data_size; 1218fe96085Stim szeto uint32_t sli_flags; 1228fe96085Stim szeto uint16_t sli_blocksize; 1238fe96085Stim szeto uint8_t sli_data_order; 1248fe96085Stim szeto uint8_t rsvd1; 1258fe96085Stim szeto uint8_t sli_lu_devid[20]; 1268fe96085Stim szeto uint32_t rsvd2; 1278fe96085Stim szeto } sbd_lu_info_1_0_t; 128fcf3ce44SJohn Forte 1298fe96085Stim szeto typedef struct sbd_lu_info_1_1 { 1308fe96085Stim szeto sm_section_hdr_t sli_sms_header; 1318fe96085Stim szeto uint32_t sli_flags; 1328fe96085Stim szeto char sli_rev[4]; 1338fe96085Stim szeto char sli_vid[8]; 1348fe96085Stim szeto char sli_pid[16]; 1358fe96085Stim szeto uint64_t sli_lu_size; /* Read capacity size */ 136fcf3ce44SJohn Forte 137fcf3ce44SJohn Forte /* 1388fe96085Stim szeto * Essetially zfs volume name for zvols to verify that the 1398fe96085Stim szeto * metadata is coming in from the correct zvol and not from a 1408fe96085Stim szeto * clone. Has no meaning in any other case. 141fcf3ce44SJohn Forte */ 142b3829613Stim szeto uint64_t sli_meta_fname_offset; 143fcf3ce44SJohn Forte 1448fe96085Stim szeto /* 1458fe96085Stim szeto * Data filename or the media filename when the metadata is in 1468fe96085Stim szeto * a separate file. Its not needed if the metadata is shared 1478fe96085Stim szeto * with data as the user supplied name is the data filename. 1488fe96085Stim szeto */ 1498fe96085Stim szeto uint64_t sli_data_fname_offset; 1508fe96085Stim szeto uint64_t sli_serial_offset; 1518fe96085Stim szeto uint64_t sli_alias_offset; 1528fe96085Stim szeto uint8_t sli_data_blocksize_shift; 1538fe96085Stim szeto uint8_t sli_data_order; 1548fe96085Stim szeto uint8_t sli_serial_size; 1558fe96085Stim szeto uint8_t sli_rsvd1; 1568fe96085Stim szeto uint8_t sli_device_id[20]; 1572f624233SNattuvetty Bhavyan uint64_t sli_mgmt_url_offset; 1582f624233SNattuvetty Bhavyan uint8_t sli_rsvd2[248]; 1598fe96085Stim szeto 1608fe96085Stim szeto /* 1618fe96085Stim szeto * In case there is no separate meta, sli_meta_fname_offset wont 1628fe96085Stim szeto * be valid. The same is true for zfs based metadata. The data_fname 1638fe96085Stim szeto * is the zvol. 1648fe96085Stim szeto */ 1658fe96085Stim szeto uint8_t sli_buf[8]; 1668fe96085Stim szeto } sbd_lu_info_1_1_t; 1678fe96085Stim szeto 1688fe96085Stim szeto /* 1698fe96085Stim szeto * sli flags 1708fe96085Stim szeto */ 1718fe96085Stim szeto #define SLI_SEPARATE_META 0x0001 1728fe96085Stim szeto #define SLI_WRITE_PROTECTED 0x0002 1738fe96085Stim szeto #define SLI_VID_VALID 0x0004 1748fe96085Stim szeto #define SLI_PID_VALID 0x0008 1758fe96085Stim szeto #define SLI_REV_VALID 0x0010 1768fe96085Stim szeto #define SLI_META_FNAME_VALID 0x0020 1778fe96085Stim szeto #define SLI_DATA_FNAME_VALID 0x0040 1788fe96085Stim szeto #define SLI_SERIAL_VALID 0x0080 1798fe96085Stim szeto #define SLI_ALIAS_VALID 0x0100 1808fe96085Stim szeto #define SLI_WRITEBACK_CACHE_DISABLE 0x0200 1818fe96085Stim szeto #define SLI_ZFS_META 0x0400 1822f624233SNattuvetty Bhavyan #define SLI_MGMT_URL_VALID 0x0800 1838fe96085Stim szeto 1848fe96085Stim szeto struct sbd_it_data; 1858fe96085Stim szeto 1868fe96085Stim szeto typedef struct sbd_lu { 1878fe96085Stim szeto struct sbd_lu *sl_next; 1888fe96085Stim szeto stmf_lu_t *sl_lu; 1898fe96085Stim szeto uint32_t sl_alloc_size; 1908fe96085Stim szeto 1918fe96085Stim szeto /* Current LU state */ 1928fe96085Stim szeto kmutex_t sl_lock; 1938fe96085Stim szeto uint32_t sl_flags; 1948fe96085Stim szeto uint8_t sl_trans_op; 1958fe96085Stim szeto uint8_t sl_state:7, 1968fe96085Stim szeto sl_state_not_acked:1; 1978fe96085Stim szeto 1988fe96085Stim szeto char *sl_name; /* refers to meta or data */ 1998fe96085Stim szeto 2008fe96085Stim szeto /* Metadata */ 20119c56d0eStim szeto kmutex_t sl_metadata_lock; 20245039663SJohn Forte krwlock_t sl_access_state_lock; 2038fe96085Stim szeto char *sl_alias; 2048fe96085Stim szeto char *sl_meta_filename; /* If applicable */ 2052f624233SNattuvetty Bhavyan char *sl_mgmt_url; 2068fe96085Stim szeto vnode_t *sl_meta_vp; 2078fe96085Stim szeto vtype_t sl_meta_vtype; 2088fe96085Stim szeto uint8_t sl_device_id[20]; /* 4(hdr) + 16(GUID) */ 2098fe96085Stim szeto uint8_t sl_meta_blocksize_shift; /* Left shift multiplier */ 2108fe96085Stim szeto uint8_t sl_data_blocksize_shift; 2118fe96085Stim szeto uint8_t sl_data_fs_nbits; 2128fe96085Stim szeto uint8_t sl_serial_no_size; 2138fe96085Stim szeto uint64_t sl_total_meta_size; 2148fe96085Stim szeto uint64_t sl_meta_size_used; 2158fe96085Stim szeto uint8_t *sl_serial_no; /* optional */ 2168fe96085Stim szeto char sl_vendor_id[8]; 2178fe96085Stim szeto char sl_product_id[16]; 2188fe96085Stim szeto char sl_revision[4]; 2198fe96085Stim szeto uint32_t sl_data_fname_alloc_size; /* for an explicit alloc */ 2202f624233SNattuvetty Bhavyan uint16_t sl_alias_alloc_size; 2212f624233SNattuvetty Bhavyan uint16_t sl_mgmt_url_alloc_size; 2228fe96085Stim szeto uint8_t sl_serial_no_alloc_size; 22345039663SJohn Forte uint8_t sl_access_state; 2249a0e8238Stim szeto uint64_t sl_meta_offset; 2258fe96085Stim szeto 2268fe96085Stim szeto /* zfs metadata */ 2279a0e8238Stim szeto krwlock_t sl_zfs_meta_lock; 2289a0e8238Stim szeto char *sl_zfs_meta; 2293fb517f7SJames Moore minor_t sl_zvol_minor; /* for direct zvol calls */ 2303fb517f7SJames Moore /* opaque handles for zvol direct calls */ 2313fb517f7SJames Moore void *sl_zvol_minor_hdl; 2323fb517f7SJames Moore void *sl_zvol_objset_hdl; 2333fb517f7SJames Moore void *sl_zvol_zil_hdl; 2343fb517f7SJames Moore void *sl_zvol_rl_hdl; 2358dfe5547SRichard Yao void *sl_zvol_dn_hdl; 2368fe96085Stim szeto 2378fe96085Stim szeto /* Backing store */ 2388fe96085Stim szeto char *sl_data_filename; 2398fe96085Stim szeto vnode_t *sl_data_vp; 2408fe96085Stim szeto vtype_t sl_data_vtype; 2418fe96085Stim szeto uint64_t sl_total_data_size; 2428fe96085Stim szeto uint64_t sl_data_readable_size; /* read() fails after this */ 2438fe96085Stim szeto uint64_t sl_data_offset; /* After the metadata,if any */ 2448fe96085Stim szeto uint64_t sl_lu_size; /* READ CAPACITY size */ 2453fb517f7SJames Moore uint64_t sl_blksize; /* used for zvols */ 2463fb517f7SJames Moore uint64_t sl_max_xfer_len; /* used for zvols */ 2478fe96085Stim szeto 2488fe96085Stim szeto struct sbd_it_data *sl_it_list; 2498fe96085Stim szeto struct sbd_pgr *sl_pgr; 2508fe96085Stim szeto uint64_t sl_rs_owner_session_id; 251*61dfa509SRick McNeal list_t sl_ats_io_list; 2528fe96085Stim szeto } sbd_lu_t; 2538fe96085Stim szeto 2548fe96085Stim szeto /* 2558fe96085Stim szeto * sl_flags 2568fe96085Stim szeto */ 257b77b9231SDan McDonald #define SL_LINKED 0x00000001 258b77b9231SDan McDonald #define SL_META_OPENED 0x00000002 259b77b9231SDan McDonald #define SL_REGISTERED 0x00000004 260b77b9231SDan McDonald #define SL_META_NEEDS_FLUSH 0x00000008 261b77b9231SDan McDonald #define SL_DATA_NEEDS_FLUSH 0x00000010 262b77b9231SDan McDonald #define SL_VID_VALID 0x00000020 263b77b9231SDan McDonald #define SL_PID_VALID 0x00000040 264b77b9231SDan McDonald #define SL_REV_VALID 0x00000080 265b77b9231SDan McDonald #define SL_WRITE_PROTECTED 0x00000100 266b77b9231SDan McDonald #define SL_MEDIA_LOADED 0x00000200 267b77b9231SDan McDonald #define SL_LU_HAS_SCSI2_RESERVATION 0x00000400 268b77b9231SDan McDonald #define SL_WRITEBACK_CACHE_DISABLE 0x00000800 269b77b9231SDan McDonald #define SL_SAVED_WRITE_CACHE_DISABLE 0x00001000 270b77b9231SDan McDonald #define SL_MEDIUM_REMOVAL_PREVENTED 0x00002000 271b77b9231SDan McDonald #define SL_NO_DATA_DKIOFLUSH 0x00004000 272b77b9231SDan McDonald #define SL_SHARED_META 0x00008000 273b77b9231SDan McDonald #define SL_ZFS_META 0x00010000 274b77b9231SDan McDonald #define SL_WRITEBACK_CACHE_SET_UNSUPPORTED 0x00020000 275b77b9231SDan McDonald #define SL_FLUSH_ON_DISABLED_WRITECACHE 0x00040000 276b77b9231SDan McDonald #define SL_CALL_ZVOL 0x00080000 277b77b9231SDan McDonald #define SL_UNMAP_ENABLED 0x00100000 2788fe96085Stim szeto 2798fe96085Stim szeto /* 2808fe96085Stim szeto * sl_trans_op. LU is undergoing some transition and this field 2818fe96085Stim szeto * tells what kind of transition that is. 2828fe96085Stim szeto */ 2838fe96085Stim szeto #define SL_OP_NONE 0 2848fe96085Stim szeto #define SL_OP_CREATE_REGISTER_LU 1 2858fe96085Stim szeto #define SL_OP_IMPORT_LU 2 2868fe96085Stim szeto #define SL_OP_DELETE_LU 3 2878fe96085Stim szeto #define SL_OP_MODIFY_LU 4 2888fe96085Stim szeto #define SL_OP_LU_PROPS 5 2898fe96085Stim szeto 290427fcaf8Stim szeto sbd_status_t sbd_data_read(sbd_lu_t *sl, scsi_task_t *task, 291427fcaf8Stim szeto uint64_t offset, uint64_t size, uint8_t *buf); 292427fcaf8Stim szeto sbd_status_t sbd_data_write(sbd_lu_t *sl, scsi_task_t *task, 293427fcaf8Stim szeto uint64_t offset, uint64_t size, uint8_t *buf); 2948fe96085Stim szeto stmf_status_t sbd_task_alloc(struct scsi_task *task); 2958fe96085Stim szeto void sbd_new_task(struct scsi_task *task, struct stmf_data_buf *initial_dbuf); 2968fe96085Stim szeto void sbd_dbuf_xfer_done(struct scsi_task *task, struct stmf_data_buf *dbuf); 2978fe96085Stim szeto void sbd_send_status_done(struct scsi_task *task); 2988fe96085Stim szeto void sbd_task_free(struct scsi_task *task); 2998fe96085Stim szeto stmf_status_t sbd_abort(struct stmf_lu *lu, int abort_cmd, void *arg, 3008fe96085Stim szeto uint32_t flags); 3018fe96085Stim szeto void sbd_ctl(struct stmf_lu *lu, int cmd, void *arg); 3028fe96085Stim szeto stmf_status_t sbd_info(uint32_t cmd, stmf_lu_t *lu, void *arg, uint8_t *buf, 3038fe96085Stim szeto uint32_t *bufsizep); 3048fe96085Stim szeto sbd_status_t sbd_write_lu_info(sbd_lu_t *sl); 3058fe96085Stim szeto sbd_status_t sbd_flush_data_cache(sbd_lu_t *sl, int fsync_done); 3068fe96085Stim szeto sbd_status_t sbd_wcd_set(int wcd, sbd_lu_t *sl); 3078fe96085Stim szeto void sbd_wcd_get(int *wcd, sbd_lu_t *sl); 308047c81d3SSaso Kiselkov int sbd_unmap(sbd_lu_t *sl, dkioc_free_list_t *dfl); 309fcf3ce44SJohn Forte 310*61dfa509SRick McNeal void sbd_handle_short_write_transfers(scsi_task_t *, stmf_data_buf_t *, 311*61dfa509SRick McNeal uint32_t); 312*61dfa509SRick McNeal void sbd_handle_short_read_transfers(scsi_task_t *, stmf_data_buf_t *, 313*61dfa509SRick McNeal uint8_t *, uint32_t, uint32_t); 314*61dfa509SRick McNeal 315fcf3ce44SJohn Forte #ifdef __cplusplus 316fcf3ce44SJohn Forte } 317fcf3ce44SJohn Forte #endif 318fcf3ce44SJohn Forte 319fcf3ce44SJohn Forte #endif /* _STMF_SBD_H */ 320