1130f4520SKenneth D. Merry /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3bec9534dSPedro F. Giffuni * 4130f4520SKenneth D. Merry * Copyright (c) 2003 Silicon Graphics International Corp. 5130f4520SKenneth D. Merry * All rights reserved. 6130f4520SKenneth D. Merry * 7130f4520SKenneth D. Merry * Redistribution and use in source and binary forms, with or without 8130f4520SKenneth D. Merry * modification, are permitted provided that the following conditions 9130f4520SKenneth D. Merry * are met: 10130f4520SKenneth D. Merry * 1. Redistributions of source code must retain the above copyright 11130f4520SKenneth D. Merry * notice, this list of conditions, and the following disclaimer, 12130f4520SKenneth D. Merry * without modification. 13130f4520SKenneth D. Merry * 2. Redistributions in binary form must reproduce at minimum a disclaimer 14130f4520SKenneth D. Merry * substantially similar to the "NO WARRANTY" disclaimer below 15130f4520SKenneth D. Merry * ("Disclaimer") and any redistribution must be conditioned upon 16130f4520SKenneth D. Merry * including a substantially similar Disclaimer requirement for further 17130f4520SKenneth D. Merry * binary redistribution. 18130f4520SKenneth D. Merry * 19130f4520SKenneth D. Merry * NO WARRANTY 20130f4520SKenneth D. Merry * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21130f4520SKenneth D. Merry * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22130f4520SKenneth D. Merry * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 23130f4520SKenneth D. Merry * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24130f4520SKenneth D. Merry * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25130f4520SKenneth D. Merry * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26130f4520SKenneth D. Merry * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27130f4520SKenneth D. Merry * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28130f4520SKenneth D. Merry * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29130f4520SKenneth D. Merry * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30130f4520SKenneth D. Merry * POSSIBILITY OF SUCH DAMAGES. 31130f4520SKenneth D. Merry * 32130f4520SKenneth D. Merry * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl.h#5 $ 33130f4520SKenneth D. Merry */ 34130f4520SKenneth D. Merry /* 35130f4520SKenneth D. Merry * Function definitions used both within CTL and potentially in various CTL 36130f4520SKenneth D. Merry * clients. 37130f4520SKenneth D. Merry * 38130f4520SKenneth D. Merry * Author: Ken Merry <ken@FreeBSD.org> 39130f4520SKenneth D. Merry */ 40130f4520SKenneth D. Merry 41130f4520SKenneth D. Merry #ifndef _CTL_H_ 42130f4520SKenneth D. Merry #define _CTL_H_ 43130f4520SKenneth D. Merry 44130f4520SKenneth D. Merry #define CTL_RETVAL_COMPLETE 0 45130f4520SKenneth D. Merry #define CTL_RETVAL_QUEUED 1 46130f4520SKenneth D. Merry #define CTL_RETVAL_ALLOCATED 2 47130f4520SKenneth D. Merry #define CTL_RETVAL_ERROR 3 48130f4520SKenneth D. Merry 49130f4520SKenneth D. Merry typedef enum { 50130f4520SKenneth D. Merry CTL_PORT_NONE = 0x00, 51130f4520SKenneth D. Merry CTL_PORT_FC = 0x01, 52130f4520SKenneth D. Merry CTL_PORT_SCSI = 0x02, 53130f4520SKenneth D. Merry CTL_PORT_IOCTL = 0x04, 54130f4520SKenneth D. Merry CTL_PORT_INTERNAL = 0x08, 5581a2151dSEdward Tomasz Napierala CTL_PORT_ISCSI = 0x10, 561e5a8b8fSAlexander Motin CTL_PORT_SAS = 0x20, 57c6646787SEdward Tomasz Napierala CTL_PORT_UMASS = 0x40, 58*25bad5a2SJohn Baldwin CTL_PORT_NVMF = 0x80, 59130f4520SKenneth D. Merry CTL_PORT_ALL = 0xff, 60130f4520SKenneth D. Merry CTL_PORT_ISC = 0x100 // FC port for inter-shelf communication 61130f4520SKenneth D. Merry } ctl_port_type; 62130f4520SKenneth D. Merry 63130f4520SKenneth D. Merry struct ctl_port_entry { 64130f4520SKenneth D. Merry ctl_port_type port_type; 65130f4520SKenneth D. Merry char port_name[64]; 66130f4520SKenneth D. Merry int32_t targ_port; 67130f4520SKenneth D. Merry int physical_port; 68130f4520SKenneth D. Merry int virtual_port; 69130f4520SKenneth D. Merry u_int flags; 70130f4520SKenneth D. Merry #define CTL_PORT_WWNN_VALID 0x01 71130f4520SKenneth D. Merry #define CTL_PORT_WWPN_VALID 0x02 72130f4520SKenneth D. Merry uint64_t wwnn; 73130f4520SKenneth D. Merry uint64_t wwpn; 74130f4520SKenneth D. Merry int online; 75130f4520SKenneth D. Merry }; 76130f4520SKenneth D. Merry 77130f4520SKenneth D. Merry struct ctl_modepage_header { 78130f4520SKenneth D. Merry uint8_t page_code; 79130f4520SKenneth D. Merry uint8_t subpage; 802e0a1f82SAlexander Motin uint16_t len_used; 812e0a1f82SAlexander Motin uint16_t len_left; 82130f4520SKenneth D. Merry }; 83130f4520SKenneth D. Merry 84130f4520SKenneth D. Merry union ctl_modepage_info { 85130f4520SKenneth D. Merry struct ctl_modepage_header header; 86130f4520SKenneth D. Merry }; 87130f4520SKenneth D. Merry 88130f4520SKenneth D. Merry /* 89130f4520SKenneth D. Merry * Serial number length, for VPD page 0x80. 90130f4520SKenneth D. Merry */ 91130f4520SKenneth D. Merry #define CTL_SN_LEN 16 92130f4520SKenneth D. Merry 93130f4520SKenneth D. Merry /* 94130f4520SKenneth D. Merry * Device ID length, for VPD page 0x83. 95130f4520SKenneth D. Merry */ 9628b9e53bSAlexander Motin #define CTL_DEVID_LEN 64 9728b9e53bSAlexander Motin #define CTL_DEVID_MIN_LEN 16 98130f4520SKenneth D. Merry /* 99130f4520SKenneth D. Merry * WWPN length, for VPD page 0x83. 100130f4520SKenneth D. Merry */ 101130f4520SKenneth D. Merry #define CTL_WWPN_LEN 8 102130f4520SKenneth D. Merry 103917d38fbSAlexander Motin #define CTL_DRIVER_NAME_LEN 32 104917d38fbSAlexander Motin 105130f4520SKenneth D. Merry /* 106130f4520SKenneth D. Merry * Unit attention types. ASC/ASCQ values for these should be placed in 107130f4520SKenneth D. Merry * ctl_build_ua. These are also listed in order of reporting priority. 108130f4520SKenneth D. Merry * i.e. a poweron UA is reported first, bus reset second, etc. 109130f4520SKenneth D. Merry */ 110130f4520SKenneth D. Merry typedef enum { 111130f4520SKenneth D. Merry CTL_UA_NONE = 0x0000, 112130f4520SKenneth D. Merry CTL_UA_POWERON = 0x0001, 113130f4520SKenneth D. Merry CTL_UA_BUS_RESET = 0x0002, 114130f4520SKenneth D. Merry CTL_UA_TARG_RESET = 0x0004, 1150020682bSAlexander Motin CTL_UA_I_T_NEXUS_LOSS = 0x0008, 1160020682bSAlexander Motin CTL_UA_LUN_RESET = 0x0010, 1170020682bSAlexander Motin CTL_UA_LUN_CHANGE = 0x0020, 1188f07b2d5SAlexander Motin CTL_UA_MODE_CHANGE = 0x0040, 1190020682bSAlexander Motin CTL_UA_LOG_CHANGE = 0x0080, 120cfa09873SAlexander Motin CTL_UA_INQ_CHANGE = 0x0100, 1210020682bSAlexander Motin CTL_UA_RES_PREEMPT = 0x0400, 1220020682bSAlexander Motin CTL_UA_RES_RELEASE = 0x0800, 1230020682bSAlexander Motin CTL_UA_REG_PREEMPT = 0x1000, 1240020682bSAlexander Motin CTL_UA_ASYM_ACC_CHANGE = 0x2000, 125648dfc1aSAlexander Motin CTL_UA_CAPACITY_CHANGE = 0x4000, 126648dfc1aSAlexander Motin CTL_UA_THIN_PROV_THRES = 0x8000, 127d9ba4eefSAlexander Motin CTL_UA_MEDIUM_CHANGE = 0x10000, 128d9ba4eefSAlexander Motin CTL_UA_IE = 0x20000 129130f4520SKenneth D. Merry } ctl_ua_type; 130130f4520SKenneth D. Merry 131130f4520SKenneth D. Merry #ifdef _KERNEL 132130f4520SKenneth D. Merry 13355231cd1SJohn Baldwin #ifdef MALLOC_DECLARE /* from malloc.h */ 134130f4520SKenneth D. Merry MALLOC_DECLARE(M_CTL); 13555231cd1SJohn Baldwin #endif 136130f4520SKenneth D. Merry 137130f4520SKenneth D. Merry struct ctl_page_index; 138130f4520SKenneth D. Merry 139130f4520SKenneth D. Merry #ifdef SYSCTL_DECL /* from sysctl.h */ 140130f4520SKenneth D. Merry SYSCTL_DECL(_kern_cam_ctl); 141130f4520SKenneth D. Merry #endif 142130f4520SKenneth D. Merry 14355231cd1SJohn Baldwin struct cdev; 144cfa09873SAlexander Motin struct ctl_lun; 145cfa09873SAlexander Motin struct ctl_port; 146cfa09873SAlexander Motin struct ctl_softc; 14755231cd1SJohn Baldwin struct ctl_scsiio; 14855231cd1SJohn Baldwin struct sbuf; 14955231cd1SJohn Baldwin union ctl_io; 150cfa09873SAlexander Motin 151130f4520SKenneth D. Merry /* 152130f4520SKenneth D. Merry * Put a string into an sbuf, escaping characters that are illegal or not 153130f4520SKenneth D. Merry * recommended in XML. Note this doesn't escape everything, just > < and &. 154130f4520SKenneth D. Merry */ 155fd86d880SAlexander Motin int ctl_sbuf_printf_esc(struct sbuf *sb, char *str, int size); 156130f4520SKenneth D. Merry 1577ac58230SAlexander Motin int ctl_ffz(uint32_t *mask, uint32_t first, uint32_t last); 158130f4520SKenneth D. Merry int ctl_set_mask(uint32_t *mask, uint32_t bit); 159130f4520SKenneth D. Merry int ctl_clear_mask(uint32_t *mask, uint32_t bit); 160130f4520SKenneth D. Merry int ctl_is_set(uint32_t *mask, uint32_t bit); 161d9ba4eefSAlexander Motin int ctl_default_page_handler(struct ctl_scsiio *ctsio, 162130f4520SKenneth D. Merry struct ctl_page_index *page_index, 163130f4520SKenneth D. Merry uint8_t *page_ptr); 164d9ba4eefSAlexander Motin int ctl_ie_page_handler(struct ctl_scsiio *ctsio, 165130f4520SKenneth D. Merry struct ctl_page_index *page_index, 166130f4520SKenneth D. Merry uint8_t *page_ptr); 167ae8828baSAlexander Motin int ctl_temp_log_sense_handler(struct ctl_scsiio *ctsio, 168ae8828baSAlexander Motin struct ctl_page_index *page_index, 169ae8828baSAlexander Motin int pc); 170c3e7ba3eSAlexander Motin int ctl_lbp_log_sense_handler(struct ctl_scsiio *ctsio, 171c3e7ba3eSAlexander Motin struct ctl_page_index *page_index, 172c3e7ba3eSAlexander Motin int pc); 1732c8cab2aSAlexander Motin int ctl_sap_log_sense_handler(struct ctl_scsiio *ctsio, 1742c8cab2aSAlexander Motin struct ctl_page_index *page_index, 1752c8cab2aSAlexander Motin int pc); 176d9ba4eefSAlexander Motin int ctl_ie_log_sense_handler(struct ctl_scsiio *ctsio, 177d9ba4eefSAlexander Motin struct ctl_page_index *page_index, 178d9ba4eefSAlexander Motin int pc); 1792c7dc6baSAlexander Motin int ctl_config_move_done(union ctl_io *io, bool samethr); 1802c7dc6baSAlexander Motin void ctl_datamove_done(union ctl_io *io, bool samethr); 181130f4520SKenneth D. Merry void ctl_datamove(union ctl_io *io); 18275a3108eSAlexander Motin void ctl_serseq_done(union ctl_io *io); 183130f4520SKenneth D. Merry void ctl_done(union ctl_io *io); 18411b569f7SAlexander Motin void ctl_data_submit_done(union ctl_io *io); 185ef8daf3fSAlexander Motin void ctl_config_read_done(union ctl_io *io); 186130f4520SKenneth D. Merry void ctl_config_write_done(union ctl_io *io); 187130f4520SKenneth D. Merry void ctl_portDB_changed(int portnum); 18867ceb24bSAlexander Motin int ctl_ioctl_io(struct cdev *dev, u_long cmd, caddr_t addr, int flag, 18967ceb24bSAlexander Motin struct thread *td); 190cfa09873SAlexander Motin 191cfa09873SAlexander Motin void ctl_est_ua(struct ctl_lun *lun, uint32_t initidx, ctl_ua_type ua); 192cfa09873SAlexander Motin void ctl_est_ua_port(struct ctl_lun *lun, int port, uint32_t except, 193cfa09873SAlexander Motin ctl_ua_type ua); 194cfa09873SAlexander Motin void ctl_est_ua_all(struct ctl_lun *lun, uint32_t except, ctl_ua_type ua); 195cfa09873SAlexander Motin void ctl_clr_ua(struct ctl_lun *lun, uint32_t initidx, ctl_ua_type ua); 196cfa09873SAlexander Motin void ctl_clr_ua_all(struct ctl_lun *lun, uint32_t except, ctl_ua_type ua); 197cfa09873SAlexander Motin void ctl_clr_ua_allluns(struct ctl_softc *ctl_softc, uint32_t initidx, 198cfa09873SAlexander Motin ctl_ua_type ua_type); 199cfa09873SAlexander Motin 20059f063d5SAlexander Motin uint32_t ctl_decode_lun(uint64_t encoded); 20159f063d5SAlexander Motin uint64_t ctl_encode_lun(uint32_t decoded); 20259f063d5SAlexander Motin 2037ac58230SAlexander Motin void ctl_isc_announce_lun(struct ctl_lun *lun); 2047ac58230SAlexander Motin void ctl_isc_announce_port(struct ctl_port *port); 2050c05f0dcSAlexander Motin void ctl_isc_announce_iid(struct ctl_port *port, int iid); 206ca85b7c4SAlexander Motin void ctl_isc_announce_mode(struct ctl_lun *lun, uint32_t initidx, 207ca85b7c4SAlexander Motin uint8_t page, uint8_t subpage); 208130f4520SKenneth D. Merry 20934961f40SAlexander Motin int ctl_expand_number(const char *buf, uint64_t *num); 21043fb3a65SAlexander Motin 211130f4520SKenneth D. Merry #endif /* _KERNEL */ 212130f4520SKenneth D. Merry 213130f4520SKenneth D. Merry #endif /* _CTL_H_ */ 214130f4520SKenneth D. Merry 215130f4520SKenneth D. Merry /* 216130f4520SKenneth D. Merry * vim: ts=8 217130f4520SKenneth D. Merry */ 218