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