1f6ad3f23SAlexander Motin /*- 2f6ad3f23SAlexander Motin * Copyright (c) 2000 Matthew Jacob 3f6ad3f23SAlexander Motin * All rights reserved. 4f6ad3f23SAlexander Motin * 5f6ad3f23SAlexander Motin * Redistribution and use in source and binary forms, with or without 6f6ad3f23SAlexander Motin * modification, are permitted provided that the following conditions 7f6ad3f23SAlexander Motin * are met: 8f6ad3f23SAlexander Motin * 1. Redistributions of source code must retain the above copyright 9f6ad3f23SAlexander Motin * notice, this list of conditions, and the following disclaimer, 10f6ad3f23SAlexander Motin * without modification, immediately at the beginning of the file. 11f6ad3f23SAlexander Motin * 2. The name of the author may not be used to endorse or promote products 12f6ad3f23SAlexander Motin * derived from this software without specific prior written permission. 13f6ad3f23SAlexander Motin * 14f6ad3f23SAlexander Motin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15f6ad3f23SAlexander Motin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16f6ad3f23SAlexander Motin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17f6ad3f23SAlexander Motin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 18f6ad3f23SAlexander Motin * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19f6ad3f23SAlexander Motin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20f6ad3f23SAlexander Motin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21f6ad3f23SAlexander Motin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22f6ad3f23SAlexander Motin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23f6ad3f23SAlexander Motin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24f6ad3f23SAlexander Motin * SUCH DAMAGE. 25f6ad3f23SAlexander Motin * 26f6ad3f23SAlexander Motin * $FreeBSD$ 27f6ad3f23SAlexander Motin */ 28f6ad3f23SAlexander Motin 29f6ad3f23SAlexander Motin /* 30f6ad3f23SAlexander Motin * This file contains definitions only intended for use within 31f6ad3f23SAlexander Motin * sys/cam/scsi/scsi_enc*.c, and not in other kernel components. 32f6ad3f23SAlexander Motin */ 33f6ad3f23SAlexander Motin 34f6ad3f23SAlexander Motin #ifndef __SCSI_ENC_INTERNAL_H__ 35f6ad3f23SAlexander Motin #define __SCSI_ENC_INTERNAL_H__ 36f6ad3f23SAlexander Motin 37f6ad3f23SAlexander Motin typedef struct enc_element { 38f6ad3f23SAlexander Motin uint32_t 39f6ad3f23SAlexander Motin enctype : 8, /* enclosure type */ 40f6ad3f23SAlexander Motin subenclosure : 8, /* subenclosure id */ 41f6ad3f23SAlexander Motin svalid : 1, /* enclosure information valid */ 42f6ad3f23SAlexander Motin overall_status_elem: 1,/* 43f6ad3f23SAlexander Motin * This object represents generic 44f6ad3f23SAlexander Motin * status about all objects of this 45f6ad3f23SAlexander Motin * type. 46f6ad3f23SAlexander Motin */ 47f6ad3f23SAlexander Motin priv : 14; /* private data, per object */ 48f6ad3f23SAlexander Motin uint8_t encstat[4]; /* state && stats */ 49f6ad3f23SAlexander Motin uint8_t *physical_path; /* Device physical path data. */ 50f6ad3f23SAlexander Motin u_int physical_path_len; /* Length of device path data. */ 51f6ad3f23SAlexander Motin void *elm_private; /* per-type object data */ 52f6ad3f23SAlexander Motin } enc_element_t; 53f6ad3f23SAlexander Motin 54f6ad3f23SAlexander Motin typedef enum { 55f6ad3f23SAlexander Motin ENC_NONE, 56f6ad3f23SAlexander Motin ENC_SES_SCSI2, 57f6ad3f23SAlexander Motin ENC_SES, 58f6ad3f23SAlexander Motin ENC_SES_PASSTHROUGH, 59f6ad3f23SAlexander Motin ENC_SEN, 60f6ad3f23SAlexander Motin ENC_SAFT, 61f6ad3f23SAlexander Motin ENC_SEMB_SES, 62f6ad3f23SAlexander Motin ENC_SEMB_SAFT 63f6ad3f23SAlexander Motin } enctyp; 64f6ad3f23SAlexander Motin 65f6ad3f23SAlexander Motin /* Platform Independent Driver Internal Definitions for enclosure devices. */ 66f6ad3f23SAlexander Motin typedef struct enc_softc enc_softc_t; 67f6ad3f23SAlexander Motin 68f6ad3f23SAlexander Motin struct enc_fsm_state; 69f6ad3f23SAlexander Motin typedef int fsm_fill_handler_t(enc_softc_t *ssc, 70f6ad3f23SAlexander Motin struct enc_fsm_state *state, 71f6ad3f23SAlexander Motin union ccb *ccb, 72f6ad3f23SAlexander Motin uint8_t *buf); 73f6ad3f23SAlexander Motin typedef int fsm_error_handler_t(union ccb *ccb, uint32_t cflags, 74f6ad3f23SAlexander Motin uint32_t sflags); 75f6ad3f23SAlexander Motin typedef int fsm_done_handler_t(enc_softc_t *ssc, 76f6ad3f23SAlexander Motin struct enc_fsm_state *state, union ccb *ccb, 77f6ad3f23SAlexander Motin uint8_t **bufp, int error, int xfer_len); 78f6ad3f23SAlexander Motin 79f6ad3f23SAlexander Motin struct enc_fsm_state { 80f6ad3f23SAlexander Motin const char *name; 81f6ad3f23SAlexander Motin int page_code; 82f6ad3f23SAlexander Motin size_t buf_size; 83f6ad3f23SAlexander Motin uint32_t timeout; 84f6ad3f23SAlexander Motin fsm_fill_handler_t *fill; 85f6ad3f23SAlexander Motin fsm_done_handler_t *done; 86f6ad3f23SAlexander Motin fsm_error_handler_t *error; 87f6ad3f23SAlexander Motin }; 88f6ad3f23SAlexander Motin 89f6ad3f23SAlexander Motin typedef int (enc_softc_init_t)(enc_softc_t *); 90f6ad3f23SAlexander Motin typedef void (enc_softc_invalidate_t)(enc_softc_t *); 91f6ad3f23SAlexander Motin typedef void (enc_softc_cleanup_t)(enc_softc_t *); 92f6ad3f23SAlexander Motin typedef int (enc_init_enc_t)(enc_softc_t *); 93f6ad3f23SAlexander Motin typedef int (enc_get_enc_status_t)(enc_softc_t *, int); 94f6ad3f23SAlexander Motin typedef int (enc_set_enc_status_t)(enc_softc_t *, encioc_enc_status_t, int); 95f6ad3f23SAlexander Motin typedef int (enc_get_elm_status_t)(enc_softc_t *, encioc_elm_status_t *, int); 96f6ad3f23SAlexander Motin typedef int (enc_set_elm_status_t)(enc_softc_t *, encioc_elm_status_t *, int); 97f6ad3f23SAlexander Motin typedef int (enc_get_elm_desc_t)(enc_softc_t *, encioc_elm_desc_t *); 98f6ad3f23SAlexander Motin typedef int (enc_get_elm_devnames_t)(enc_softc_t *, encioc_elm_devnames_t *); 99f6ad3f23SAlexander Motin typedef int (enc_handle_string_t)(enc_softc_t *, encioc_string_t *, int); 100f6ad3f23SAlexander Motin typedef void (enc_device_found_t)(enc_softc_t *); 101f6ad3f23SAlexander Motin typedef void (enc_poll_status_t)(enc_softc_t *); 102f6ad3f23SAlexander Motin 103f6ad3f23SAlexander Motin struct enc_vec { 104f6ad3f23SAlexander Motin enc_softc_invalidate_t *softc_invalidate; 105f6ad3f23SAlexander Motin enc_softc_cleanup_t *softc_cleanup; 106f6ad3f23SAlexander Motin enc_init_enc_t *init_enc; 107f6ad3f23SAlexander Motin enc_get_enc_status_t *get_enc_status; 108f6ad3f23SAlexander Motin enc_set_enc_status_t *set_enc_status; 109f6ad3f23SAlexander Motin enc_get_elm_status_t *get_elm_status; 110f6ad3f23SAlexander Motin enc_set_elm_status_t *set_elm_status; 111f6ad3f23SAlexander Motin enc_get_elm_desc_t *get_elm_desc; 112f6ad3f23SAlexander Motin enc_get_elm_devnames_t *get_elm_devnames; 113f6ad3f23SAlexander Motin enc_handle_string_t *handle_string; 114f6ad3f23SAlexander Motin enc_device_found_t *device_found; 115f6ad3f23SAlexander Motin enc_poll_status_t *poll_status; 116f6ad3f23SAlexander Motin }; 117f6ad3f23SAlexander Motin 118f6ad3f23SAlexander Motin typedef struct enc_cache { 119f6ad3f23SAlexander Motin enc_element_t *elm_map; /* objects */ 120f6ad3f23SAlexander Motin int nelms; /* number of objects */ 121f6ad3f23SAlexander Motin encioc_enc_status_t enc_status; /* overall status */ 122f6ad3f23SAlexander Motin void *private; /* per-type private data */ 123f6ad3f23SAlexander Motin } enc_cache_t; 124f6ad3f23SAlexander Motin 125f6ad3f23SAlexander Motin /* Enclosure instance toplevel structure */ 126f6ad3f23SAlexander Motin struct enc_softc { 127f6ad3f23SAlexander Motin enctyp enc_type; /* type of enclosure */ 128f6ad3f23SAlexander Motin struct enc_vec enc_vec; /* vector to handlers */ 129f6ad3f23SAlexander Motin void *enc_private; /* per-type private data */ 130f6ad3f23SAlexander Motin 131f6ad3f23SAlexander Motin /** 132f6ad3f23SAlexander Motin * "Published" configuration and state data available to 133f6ad3f23SAlexander Motin * external consumers. 134f6ad3f23SAlexander Motin */ 135f6ad3f23SAlexander Motin enc_cache_t enc_cache; 136f6ad3f23SAlexander Motin 137f6ad3f23SAlexander Motin /** 138f6ad3f23SAlexander Motin * Configuration and state data being actively updated 139f6ad3f23SAlexander Motin * by the enclosure daemon. 140f6ad3f23SAlexander Motin */ 141f6ad3f23SAlexander Motin enc_cache_t enc_daemon_cache; 142f6ad3f23SAlexander Motin 143f6ad3f23SAlexander Motin struct sx enc_cache_lock; 144f6ad3f23SAlexander Motin uint8_t enc_flags; 145f6ad3f23SAlexander Motin #define ENC_FLAG_INVALID 0x01 146f6ad3f23SAlexander Motin #define ENC_FLAG_INITIALIZED 0x02 147f6ad3f23SAlexander Motin #define ENC_FLAG_SHUTDOWN 0x04 148f6ad3f23SAlexander Motin union ccb saved_ccb; 149f6ad3f23SAlexander Motin struct cdev *enc_dev; 150f6ad3f23SAlexander Motin struct cam_periph *periph; 15186d45c7fSKenneth D. Merry int open_count; 152f6ad3f23SAlexander Motin 153f6ad3f23SAlexander Motin /* Bitmap of pending operations. */ 154f6ad3f23SAlexander Motin uint32_t pending_actions; 155f6ad3f23SAlexander Motin 156f6ad3f23SAlexander Motin /* The action on which the state machine is currently working. */ 157f6ad3f23SAlexander Motin uint32_t current_action; 158f6ad3f23SAlexander Motin #define ENC_UPDATE_NONE 0x00 159f6ad3f23SAlexander Motin #define ENC_UPDATE_INVALID 0xff 160f6ad3f23SAlexander Motin 161f6ad3f23SAlexander Motin /* Callout for auto-updating enclosure status */ 162f6ad3f23SAlexander Motin struct callout status_updater; 163f6ad3f23SAlexander Motin 164f6ad3f23SAlexander Motin struct proc *enc_daemon; 165f6ad3f23SAlexander Motin 166f6ad3f23SAlexander Motin struct enc_fsm_state *enc_fsm_states; 167f6ad3f23SAlexander Motin 168f6ad3f23SAlexander Motin struct intr_config_hook enc_boot_hold_ch; 169f6ad3f23SAlexander Motin }; 170f6ad3f23SAlexander Motin 171f6ad3f23SAlexander Motin static inline enc_cache_t * 172f6ad3f23SAlexander Motin enc_other_cache(enc_softc_t *enc, enc_cache_t *primary) 173f6ad3f23SAlexander Motin { 174f6ad3f23SAlexander Motin return (primary == &enc->enc_cache 175f6ad3f23SAlexander Motin ? &enc->enc_daemon_cache : &enc->enc_cache); 176f6ad3f23SAlexander Motin } 177f6ad3f23SAlexander Motin 178f6ad3f23SAlexander Motin /* SES Management mode page - SES2r20 Table 59 */ 179f6ad3f23SAlexander Motin struct ses_mgmt_mode_page { 180f6ad3f23SAlexander Motin struct scsi_mode_header_6 header; 181f6ad3f23SAlexander Motin struct scsi_mode_blk_desc blk_desc; 182f6ad3f23SAlexander Motin uint8_t byte0; /* ps : 1, spf : 1, page_code : 6 */ 183f6ad3f23SAlexander Motin #define SES_MGMT_MODE_PAGE_CODE 0x14 184f6ad3f23SAlexander Motin uint8_t length; 185f6ad3f23SAlexander Motin #define SES_MGMT_MODE_PAGE_LEN 6 186f6ad3f23SAlexander Motin uint8_t reserved[3]; 187f6ad3f23SAlexander Motin uint8_t byte5; /* reserved : 7, enbltc : 1 */ 188f6ad3f23SAlexander Motin #define SES_MGMT_TIMED_COMP_EN 0x1 189f6ad3f23SAlexander Motin uint8_t max_comp_time[2]; 190f6ad3f23SAlexander Motin }; 191f6ad3f23SAlexander Motin 192f6ad3f23SAlexander Motin /* Enclosure core interface for sub-drivers */ 193f6ad3f23SAlexander Motin int enc_runcmd(struct enc_softc *, char *, int, char *, int *); 194f6ad3f23SAlexander Motin void enc_log(struct enc_softc *, const char *, ...); 195f6ad3f23SAlexander Motin void enc_done(struct cam_periph *, union ccb *); 196f6ad3f23SAlexander Motin int enc_error(union ccb *, uint32_t, uint32_t); 197f6ad3f23SAlexander Motin void enc_update_request(enc_softc_t *, uint32_t); 198f6ad3f23SAlexander Motin 199f6ad3f23SAlexander Motin /* SES Native interface */ 200f6ad3f23SAlexander Motin enc_softc_init_t ses_softc_init; 201f6ad3f23SAlexander Motin 202f6ad3f23SAlexander Motin /* SAF-TE interface */ 203f6ad3f23SAlexander Motin enc_softc_init_t safte_softc_init; 204f6ad3f23SAlexander Motin 205f6ad3f23SAlexander Motin /* Helper macros */ 206f6ad3f23SAlexander Motin MALLOC_DECLARE(M_SCSIENC); 207f6ad3f23SAlexander Motin #define ENC_CFLAGS CAM_RETRY_SELTO 208f6ad3f23SAlexander Motin #define ENC_FLAGS SF_NO_PRINT | SF_RETRY_UA 209f6ad3f23SAlexander Motin #define STRNCMP strncmp 210f6ad3f23SAlexander Motin #define PRINTF printf 211f6ad3f23SAlexander Motin #define ENC_LOG enc_log 212f6ad3f23SAlexander Motin #if defined(DEBUG) || defined(ENC_DEBUG) 213f6ad3f23SAlexander Motin #define ENC_DLOG enc_log 214f6ad3f23SAlexander Motin #else 215f6ad3f23SAlexander Motin #define ENC_DLOG if (0) enc_log 216f6ad3f23SAlexander Motin #endif 217f6ad3f23SAlexander Motin #define ENC_VLOG if (bootverbose) enc_log 218f6ad3f23SAlexander Motin #define ENC_MALLOC(amt) malloc(amt, M_SCSIENC, M_NOWAIT) 219f6ad3f23SAlexander Motin #define ENC_MALLOCZ(amt) malloc(amt, M_SCSIENC, M_ZERO|M_NOWAIT) 220f6ad3f23SAlexander Motin /* Cast away const avoiding GCC warnings. */ 221f6ad3f23SAlexander Motin #define ENC_FREE(ptr) free((void *)((uintptr_t)ptr), M_SCSIENC) 222f6ad3f23SAlexander Motin #define ENC_FREE_AND_NULL(ptr) do { \ 223f6ad3f23SAlexander Motin if (ptr != NULL) { \ 224f6ad3f23SAlexander Motin ENC_FREE(ptr); \ 225f6ad3f23SAlexander Motin ptr = NULL; \ 226f6ad3f23SAlexander Motin } \ 227f6ad3f23SAlexander Motin } while(0) 228f6ad3f23SAlexander Motin #define MEMZERO bzero 229f6ad3f23SAlexander Motin #define MEMCPY(dest, src, amt) bcopy(src, dest, amt) 230f6ad3f23SAlexander Motin 231f6ad3f23SAlexander Motin #endif /* __SCSI_ENC_INTERNAL_H__ */ 232