1130f4520SKenneth D. Merry /*- 2130f4520SKenneth D. Merry * Copyright (c) 2003 Silicon Graphics International Corp. 3130f4520SKenneth D. Merry * All rights reserved. 4130f4520SKenneth D. Merry * 5130f4520SKenneth D. Merry * Redistribution and use in source and binary forms, with or without 6130f4520SKenneth D. Merry * modification, are permitted provided that the following conditions 7130f4520SKenneth D. Merry * are met: 8130f4520SKenneth D. Merry * 1. Redistributions of source code must retain the above copyright 9130f4520SKenneth D. Merry * notice, this list of conditions, and the following disclaimer, 10130f4520SKenneth D. Merry * without modification. 11130f4520SKenneth D. Merry * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12130f4520SKenneth D. Merry * substantially similar to the "NO WARRANTY" disclaimer below 13130f4520SKenneth D. Merry * ("Disclaimer") and any redistribution must be conditioned upon 14130f4520SKenneth D. Merry * including a substantially similar Disclaimer requirement for further 15130f4520SKenneth D. Merry * binary redistribution. 16130f4520SKenneth D. Merry * 17130f4520SKenneth D. Merry * NO WARRANTY 18130f4520SKenneth D. Merry * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19130f4520SKenneth D. Merry * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20130f4520SKenneth D. Merry * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 21130f4520SKenneth D. Merry * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22130f4520SKenneth D. Merry * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23130f4520SKenneth D. Merry * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24130f4520SKenneth D. Merry * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25130f4520SKenneth D. Merry * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26130f4520SKenneth D. Merry * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27130f4520SKenneth D. Merry * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28130f4520SKenneth D. Merry * POSSIBILITY OF SUCH DAMAGES. 29130f4520SKenneth D. Merry * 30130f4520SKenneth D. Merry * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl.h#5 $ 31130f4520SKenneth D. Merry * $FreeBSD$ 32130f4520SKenneth D. Merry */ 33130f4520SKenneth D. Merry /* 34130f4520SKenneth D. Merry * Function definitions used both within CTL and potentially in various CTL 35130f4520SKenneth D. Merry * clients. 36130f4520SKenneth D. Merry * 37130f4520SKenneth D. Merry * Author: Ken Merry <ken@FreeBSD.org> 38130f4520SKenneth D. Merry */ 39130f4520SKenneth D. Merry 40130f4520SKenneth D. Merry #ifndef _CTL_H_ 41130f4520SKenneth D. Merry #define _CTL_H_ 42130f4520SKenneth D. Merry 43130f4520SKenneth D. Merry #define ctl_min(x,y) (((x) < (y)) ? (x) : (y)) 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, 57130f4520SKenneth D. Merry CTL_PORT_ALL = 0xff, 58130f4520SKenneth D. Merry CTL_PORT_ISC = 0x100 // FC port for inter-shelf communication 59130f4520SKenneth D. Merry } ctl_port_type; 60130f4520SKenneth D. Merry 61130f4520SKenneth D. Merry struct ctl_port_entry { 62130f4520SKenneth D. Merry ctl_port_type port_type; 63130f4520SKenneth D. Merry char port_name[64]; 64130f4520SKenneth D. Merry int32_t targ_port; 65130f4520SKenneth D. Merry int physical_port; 66130f4520SKenneth D. Merry int virtual_port; 67130f4520SKenneth D. Merry u_int flags; 68130f4520SKenneth D. Merry #define CTL_PORT_WWNN_VALID 0x01 69130f4520SKenneth D. Merry #define CTL_PORT_WWPN_VALID 0x02 70130f4520SKenneth D. Merry uint64_t wwnn; 71130f4520SKenneth D. Merry uint64_t wwpn; 72130f4520SKenneth D. Merry int online; 73130f4520SKenneth D. Merry }; 74130f4520SKenneth D. Merry 75130f4520SKenneth D. Merry struct ctl_modepage_header { 76130f4520SKenneth D. Merry uint8_t page_code; 77130f4520SKenneth D. Merry uint8_t subpage; 78130f4520SKenneth D. Merry int32_t len_used; 79130f4520SKenneth D. Merry int32_t len_left; 80130f4520SKenneth D. Merry }; 81130f4520SKenneth D. Merry 82130f4520SKenneth D. Merry struct ctl_modepage_aps { 83130f4520SKenneth D. Merry struct ctl_modepage_header header; 84130f4520SKenneth D. Merry uint8_t lock_active; 85130f4520SKenneth D. Merry }; 86130f4520SKenneth D. Merry 87130f4520SKenneth D. Merry union ctl_modepage_info { 88130f4520SKenneth D. Merry struct ctl_modepage_header header; 89130f4520SKenneth D. Merry struct ctl_modepage_aps aps; 90130f4520SKenneth D. Merry }; 91130f4520SKenneth D. Merry 92130f4520SKenneth D. Merry /* 93130f4520SKenneth D. Merry * Serial number length, for VPD page 0x80. 94130f4520SKenneth D. Merry */ 95130f4520SKenneth D. Merry #define CTL_SN_LEN 16 96130f4520SKenneth D. Merry 97130f4520SKenneth D. Merry /* 98130f4520SKenneth D. Merry * Device ID length, for VPD page 0x83. 99130f4520SKenneth D. Merry */ 10028b9e53bSAlexander Motin #define CTL_DEVID_LEN 64 10128b9e53bSAlexander Motin #define CTL_DEVID_MIN_LEN 16 102130f4520SKenneth D. Merry /* 103130f4520SKenneth D. Merry * WWPN length, for VPD page 0x83. 104130f4520SKenneth D. Merry */ 105130f4520SKenneth D. Merry #define CTL_WWPN_LEN 8 106130f4520SKenneth D. Merry 107917d38fbSAlexander Motin #define CTL_DRIVER_NAME_LEN 32 108917d38fbSAlexander Motin 109130f4520SKenneth D. Merry /* 110130f4520SKenneth D. Merry * Unit attention types. ASC/ASCQ values for these should be placed in 111130f4520SKenneth D. Merry * ctl_build_ua. These are also listed in order of reporting priority. 112130f4520SKenneth D. Merry * i.e. a poweron UA is reported first, bus reset second, etc. 113130f4520SKenneth D. Merry */ 114130f4520SKenneth D. Merry typedef enum { 115130f4520SKenneth D. Merry CTL_UA_NONE = 0x0000, 116130f4520SKenneth D. Merry CTL_UA_POWERON = 0x0001, 117130f4520SKenneth D. Merry CTL_UA_BUS_RESET = 0x0002, 118130f4520SKenneth D. Merry CTL_UA_TARG_RESET = 0x0004, 1190020682bSAlexander Motin CTL_UA_I_T_NEXUS_LOSS = 0x0008, 1200020682bSAlexander Motin CTL_UA_LUN_RESET = 0x0010, 1210020682bSAlexander Motin CTL_UA_LUN_CHANGE = 0x0020, 1228f07b2d5SAlexander Motin CTL_UA_MODE_CHANGE = 0x0040, 1230020682bSAlexander Motin CTL_UA_LOG_CHANGE = 0x0080, 1240020682bSAlexander Motin CTL_UA_LVD = 0x0100, 1250020682bSAlexander Motin CTL_UA_SE = 0x0200, 1260020682bSAlexander Motin CTL_UA_RES_PREEMPT = 0x0400, 1270020682bSAlexander Motin CTL_UA_RES_RELEASE = 0x0800, 1280020682bSAlexander Motin CTL_UA_REG_PREEMPT = 0x1000, 1290020682bSAlexander Motin CTL_UA_ASYM_ACC_CHANGE = 0x2000, 1300020682bSAlexander Motin CTL_UA_CAPACITY_CHANGED = 0x4000 131130f4520SKenneth D. Merry } ctl_ua_type; 132130f4520SKenneth D. Merry 133130f4520SKenneth D. Merry #ifdef _KERNEL 134130f4520SKenneth D. Merry 135130f4520SKenneth D. Merry MALLOC_DECLARE(M_CTL); 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 143130f4520SKenneth D. Merry /* 144130f4520SKenneth D. Merry * Call these routines to enable or disable front end ports. 145130f4520SKenneth D. Merry */ 146130f4520SKenneth D. Merry int ctl_port_enable(ctl_port_type port_type); 147130f4520SKenneth D. Merry int ctl_port_disable(ctl_port_type port_type); 148130f4520SKenneth D. Merry /* 149130f4520SKenneth D. Merry * This routine grabs a list of frontend ports. 150130f4520SKenneth D. Merry */ 151130f4520SKenneth D. Merry int ctl_port_list(struct ctl_port_entry *entries, int num_entries_alloced, 152130f4520SKenneth D. Merry int *num_entries_filled, int *num_entries_dropped, 153130f4520SKenneth D. Merry ctl_port_type port_type, int no_virtual); 154130f4520SKenneth D. Merry 155130f4520SKenneth D. Merry /* 156130f4520SKenneth D. Merry * Put a string into an sbuf, escaping characters that are illegal or not 157130f4520SKenneth D. Merry * recommended in XML. Note this doesn't escape everything, just > < and &. 158130f4520SKenneth D. Merry */ 159*fd86d880SAlexander Motin int ctl_sbuf_printf_esc(struct sbuf *sb, char *str, int size); 160130f4520SKenneth D. Merry 161130f4520SKenneth D. Merry int ctl_ffz(uint32_t *mask, uint32_t size); 162130f4520SKenneth D. Merry int ctl_set_mask(uint32_t *mask, uint32_t bit); 163130f4520SKenneth D. Merry int ctl_clear_mask(uint32_t *mask, uint32_t bit); 164130f4520SKenneth D. Merry int ctl_is_set(uint32_t *mask, uint32_t bit); 16555551d05SAlexander Motin int ctl_caching_sp_handler(struct ctl_scsiio *ctsio, 16655551d05SAlexander Motin struct ctl_page_index *page_index, uint8_t *page_ptr); 167130f4520SKenneth D. Merry int ctl_control_page_handler(struct ctl_scsiio *ctsio, 168130f4520SKenneth D. Merry struct ctl_page_index *page_index, 169130f4520SKenneth D. Merry uint8_t *page_ptr); 170130f4520SKenneth D. Merry /** 171130f4520SKenneth D. Merry int ctl_failover_sp_handler(struct ctl_scsiio *ctsio, 172130f4520SKenneth D. Merry struct ctl_page_index *page_index, 173130f4520SKenneth D. Merry uint8_t *page_ptr); 174130f4520SKenneth D. Merry **/ 175130f4520SKenneth D. Merry int ctl_debugconf_sp_sense_handler(struct ctl_scsiio *ctsio, 176130f4520SKenneth D. Merry struct ctl_page_index *page_index, 177130f4520SKenneth D. Merry int pc); 178130f4520SKenneth D. Merry int ctl_debugconf_sp_select_handler(struct ctl_scsiio *ctsio, 179130f4520SKenneth D. Merry struct ctl_page_index *page_index, 180130f4520SKenneth D. Merry uint8_t *page_ptr); 181130f4520SKenneth D. Merry int ctl_config_move_done(union ctl_io *io); 182130f4520SKenneth D. Merry void ctl_datamove(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); 185130f4520SKenneth D. Merry void ctl_config_write_done(union ctl_io *io); 186130f4520SKenneth D. Merry void ctl_portDB_changed(int portnum); 187130f4520SKenneth D. Merry void ctl_init_isc_msg(void); 188130f4520SKenneth D. Merry 18943fb3a65SAlexander Motin /* 19043fb3a65SAlexander Motin * KPI to manipulate LUN/port options 19143fb3a65SAlexander Motin */ 19243fb3a65SAlexander Motin 19343fb3a65SAlexander Motin struct ctl_option { 19443fb3a65SAlexander Motin STAILQ_ENTRY(ctl_option) links; 19543fb3a65SAlexander Motin char *name; 19643fb3a65SAlexander Motin char *value; 19743fb3a65SAlexander Motin }; 19843fb3a65SAlexander Motin typedef STAILQ_HEAD(ctl_options, ctl_option) ctl_options_t; 19943fb3a65SAlexander Motin 20043fb3a65SAlexander Motin struct ctl_be_arg; 20143fb3a65SAlexander Motin void ctl_init_opts(ctl_options_t *opts, int num_args, struct ctl_be_arg *args); 20243fb3a65SAlexander Motin void ctl_free_opts(ctl_options_t *opts); 20343fb3a65SAlexander Motin char * ctl_get_opt(ctl_options_t *opts, const char *name); 20443fb3a65SAlexander Motin 205130f4520SKenneth D. Merry #endif /* _KERNEL */ 206130f4520SKenneth D. Merry 207130f4520SKenneth D. Merry #endif /* _CTL_H_ */ 208130f4520SKenneth D. Merry 209130f4520SKenneth D. Merry /* 210130f4520SKenneth D. Merry * vim: ts=8 211130f4520SKenneth D. Merry */ 212