1*45039663SJohn Forte /* 2*45039663SJohn Forte * CDDL HEADER START 3*45039663SJohn Forte * 4*45039663SJohn Forte * The contents of this file are subject to the terms of the 5*45039663SJohn Forte * Common Development and Distribution License (the "License"). 6*45039663SJohn Forte * You may not use this file except in compliance with the License. 7*45039663SJohn Forte * 8*45039663SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*45039663SJohn Forte * or http://www.opensolaris.org/os/licensing. 10*45039663SJohn Forte * See the License for the specific language governing permissions 11*45039663SJohn Forte * and limitations under the License. 12*45039663SJohn Forte * 13*45039663SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each 14*45039663SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*45039663SJohn Forte * If applicable, add the following below this CDDL HEADER, with the 16*45039663SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying 17*45039663SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner] 18*45039663SJohn Forte * 19*45039663SJohn Forte * CDDL HEADER END 20*45039663SJohn Forte */ 21*45039663SJohn Forte /* 22*45039663SJohn Forte * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23*45039663SJohn Forte * Use is subject to license terms. 24*45039663SJohn Forte */ 25*45039663SJohn Forte #ifndef _PPPT_H 26*45039663SJohn Forte #define _PPPT_H 27*45039663SJohn Forte 28*45039663SJohn Forte #include <sys/pppt_ic_if.h> 29*45039663SJohn Forte 30*45039663SJohn Forte #ifdef __cplusplus 31*45039663SJohn Forte extern "C" { 32*45039663SJohn Forte #endif 33*45039663SJohn Forte 34*45039663SJohn Forte #define PPPT_GLOBAL_LOCK() mutex_enter(&pppt_global.global_lock) 35*45039663SJohn Forte #define PPPT_GLOBAL_UNLOCK() mutex_exit(&pppt_global.global_lock) 36*45039663SJohn Forte 37*45039663SJohn Forte extern int pppt_logging; 38*45039663SJohn Forte 39*45039663SJohn Forte #define PPPT_LOG if (pppt_logging) cmn_err 40*45039663SJohn Forte 41*45039663SJohn Forte #define TGT_DEREG_RETRY_SECONDS 1 42*45039663SJohn Forte 43*45039663SJohn Forte typedef enum { 44*45039663SJohn Forte PPPT_STATUS_SUCCESS = 0, 45*45039663SJohn Forte PPPT_STATUS_FAIL, 46*45039663SJohn Forte PPPT_STATUS_ABORTED, 47*45039663SJohn Forte PPPT_STATUS_DONE 48*45039663SJohn Forte } pppt_status_t; 49*45039663SJohn Forte 50*45039663SJohn Forte #define PPPT_MODNAME "pppt" 51*45039663SJohn Forte 52*45039663SJohn Forte /* Target states and events, update pppt_ts_name table whenever modified */ 53*45039663SJohn Forte typedef enum { 54*45039663SJohn Forte TS_UNDEFINED = 0, 55*45039663SJohn Forte TS_CREATED, 56*45039663SJohn Forte TS_ONLINING, 57*45039663SJohn Forte TS_ONLINE, 58*45039663SJohn Forte TS_STMF_ONLINE, 59*45039663SJohn Forte TS_DELETING_NEED_OFFLINE, 60*45039663SJohn Forte TS_OFFLINING, 61*45039663SJohn Forte TS_OFFLINE, 62*45039663SJohn Forte TS_STMF_OFFLINE, 63*45039663SJohn Forte TS_DELETING_STMF_DEREG, 64*45039663SJohn Forte TS_DELETING_STMF_DEREG_FAIL, 65*45039663SJohn Forte TS_DELETING, 66*45039663SJohn Forte TS_MAX_STATE 67*45039663SJohn Forte } pppt_tgt_state_t; 68*45039663SJohn Forte 69*45039663SJohn Forte #ifdef PPPT_TGT_SM_STRINGS 70*45039663SJohn Forte static const char *pppt_ts_name[TS_MAX_STATE+1] = { 71*45039663SJohn Forte "TS_UNDEFINED", 72*45039663SJohn Forte "TS_CREATED", 73*45039663SJohn Forte "TS_ONLINING", 74*45039663SJohn Forte "TS_ONLINE", 75*45039663SJohn Forte "TS_STMF_ONLINE", 76*45039663SJohn Forte "TS_DELETING_NEED_OFFLINE", 77*45039663SJohn Forte "TS_OFFLINING", 78*45039663SJohn Forte "TS_OFFLINE", 79*45039663SJohn Forte "TS_STMF_OFFLINE", 80*45039663SJohn Forte "TS_DELETING_STMF_DEREG", 81*45039663SJohn Forte "TS_DELETING_STMF_DEREG_FAIL", 82*45039663SJohn Forte "TS_DELETING", 83*45039663SJohn Forte "TS_MAX_STATE" 84*45039663SJohn Forte }; 85*45039663SJohn Forte #endif 86*45039663SJohn Forte 87*45039663SJohn Forte typedef enum { 88*45039663SJohn Forte TE_UNDEFINED = 0, 89*45039663SJohn Forte TE_STMF_ONLINE_REQ, 90*45039663SJohn Forte TE_ONLINE_SUCCESS, 91*45039663SJohn Forte TE_ONLINE_FAIL, 92*45039663SJohn Forte TE_STMF_ONLINE_COMPLETE_ACK, 93*45039663SJohn Forte TE_STMF_OFFLINE_REQ, 94*45039663SJohn Forte TE_OFFLINE_COMPLETE, 95*45039663SJohn Forte TE_STMF_OFFLINE_COMPLETE_ACK, 96*45039663SJohn Forte TE_DELETE, 97*45039663SJohn Forte TE_STMF_DEREG_SUCCESS, 98*45039663SJohn Forte TE_STMF_DEREG_FAIL, 99*45039663SJohn Forte TE_STMF_DEREG_RETRY, 100*45039663SJohn Forte TE_WAIT_REF_COMPLETE, /* XXX */ 101*45039663SJohn Forte TE_MAX_EVENT 102*45039663SJohn Forte } pppt_tgt_event_t; 103*45039663SJohn Forte 104*45039663SJohn Forte #ifdef PPPT_TGT_SM_STRINGS 105*45039663SJohn Forte static const char *pppt_te_name[TE_MAX_EVENT+1] = { 106*45039663SJohn Forte "TE_UNDEFINED", 107*45039663SJohn Forte "TE_STMF_ONLINE_REQ", 108*45039663SJohn Forte "TE_ONLINE_SUCCESS", 109*45039663SJohn Forte "TE_ONLINE_FAIL", 110*45039663SJohn Forte "TE_STMF_ONLINE_COMPLETE_ACK", 111*45039663SJohn Forte "TE_STMF_OFFLINE_REQ", 112*45039663SJohn Forte "TE_OFFLINE_COMPLETE", 113*45039663SJohn Forte "TE_STMF_OFFLINE_COMPLETE_ACK", 114*45039663SJohn Forte "TE_DELETE", 115*45039663SJohn Forte "TE_STMF_DEREG_SUCCESS", 116*45039663SJohn Forte "TE_STMF_DEREG_FAIL", 117*45039663SJohn Forte "TE_STMF_DEREG_RETRY", 118*45039663SJohn Forte "TE_WAIT_REF_COMPLETE", 119*45039663SJohn Forte "TE_MAX_EVENT" 120*45039663SJohn Forte }; 121*45039663SJohn Forte #endif 122*45039663SJohn Forte 123*45039663SJohn Forte typedef struct pppt_tgt_s { 124*45039663SJohn Forte kmutex_t target_mutex; 125*45039663SJohn Forte kcondvar_t target_cv; 126*45039663SJohn Forte avl_node_t target_global_ln; 127*45039663SJohn Forte scsi_devid_desc_t *target_devid; 128*45039663SJohn Forte stmf_local_port_t *target_stmf_lport; 129*45039663SJohn Forte avl_tree_t target_sess_list; 130*45039663SJohn Forte 131*45039663SJohn Forte /* Target state */ 132*45039663SJohn Forte boolean_t target_sm_busy; 133*45039663SJohn Forte boolean_t target_deleting; 134*45039663SJohn Forte pppt_tgt_state_t target_state; 135*45039663SJohn Forte pppt_tgt_state_t target_last_state; 136*45039663SJohn Forte int target_refcount; 137*45039663SJohn Forte list_t target_events; 138*45039663SJohn Forte } pppt_tgt_t; 139*45039663SJohn Forte 140*45039663SJohn Forte typedef struct { 141*45039663SJohn Forte struct pppt_tgt_s *ps_target; 142*45039663SJohn Forte uint64_t ps_session_id; 143*45039663SJohn Forte int ps_refcnt; 144*45039663SJohn Forte kmutex_t ps_mutex; 145*45039663SJohn Forte kcondvar_t ps_cv; 146*45039663SJohn Forte boolean_t ps_closed; 147*45039663SJohn Forte avl_node_t ps_global_ln; 148*45039663SJohn Forte avl_node_t ps_target_ln; 149*45039663SJohn Forte avl_tree_t ps_task_list; 150*45039663SJohn Forte stmf_scsi_session_t *ps_stmf_sess; 151*45039663SJohn Forte } pppt_sess_t; 152*45039663SJohn Forte 153*45039663SJohn Forte typedef struct { 154*45039663SJohn Forte stmf_data_buf_t *pbuf_stmf_buf; 155*45039663SJohn Forte boolean_t pbuf_is_immed; 156*45039663SJohn Forte stmf_ic_msg_t *pbuf_immed_msg; 157*45039663SJohn Forte } pppt_buf_t; 158*45039663SJohn Forte 159*45039663SJohn Forte typedef enum { 160*45039663SJohn Forte PTS_INIT = 0, 161*45039663SJohn Forte PTS_ACTIVE, 162*45039663SJohn Forte PTS_DONE, 163*45039663SJohn Forte PTS_SENT_STATUS, 164*45039663SJohn Forte PTS_ABORTED 165*45039663SJohn Forte } pppt_task_state_t; 166*45039663SJohn Forte 167*45039663SJohn Forte typedef struct { 168*45039663SJohn Forte pppt_sess_t *pt_sess; 169*45039663SJohn Forte avl_node_t pt_sess_ln; 170*45039663SJohn Forte int pt_refcnt; 171*45039663SJohn Forte kmutex_t pt_mutex; 172*45039663SJohn Forte kcondvar_t pt_cv; 173*45039663SJohn Forte stmf_ic_msgid_t pt_task_id; 174*45039663SJohn Forte uint8_t pt_lun_id[16]; 175*45039663SJohn Forte pppt_task_state_t pt_state; 176*45039663SJohn Forte scsi_task_t *pt_stmf_task; 177*45039663SJohn Forte pppt_buf_t *pt_immed_data; 178*45039663SJohn Forte pppt_buf_t *pt_read_buf; 179*45039663SJohn Forte stmf_ic_msgid_t pt_read_xfer_msgid; 180*45039663SJohn Forte } pppt_task_t; 181*45039663SJohn Forte 182*45039663SJohn Forte /* 183*45039663SJohn Forte * Error statistics 184*45039663SJohn Forte */ 185*45039663SJohn Forte typedef struct { 186*45039663SJohn Forte uint64_t es_tgt_reg_svc_disabled; 187*45039663SJohn Forte uint64_t es_tgt_reg_duplicate; 188*45039663SJohn Forte uint64_t es_tgt_reg_create_fail; 189*45039663SJohn Forte uint64_t es_tgt_dereg_svc_disabled; 190*45039663SJohn Forte uint64_t es_tgt_dereg_not_found; 191*45039663SJohn Forte uint64_t es_sess_destroy_no_session; 192*45039663SJohn Forte uint64_t es_sess_lookup_no_session; 193*45039663SJohn Forte uint64_t es_sess_lookup_ident_mismatch; 194*45039663SJohn Forte uint64_t es_sess_lookup_bad_tgt_state; 195*45039663SJohn Forte uint64_t es_scmd_ptask_alloc_fail; 196*45039663SJohn Forte uint64_t es_scmd_sess_create_fail; 197*45039663SJohn Forte uint64_t es_scmd_stask_alloc_fail; 198*45039663SJohn Forte uint64_t es_scmd_dup_task_count; 199*45039663SJohn Forte } pppt_error_stats_t; 200*45039663SJohn Forte 201*45039663SJohn Forte #define PPPT_INC_STAT(stat_field) \ 202*45039663SJohn Forte atomic_inc_64(&pppt_global.global_error_stats.stat_field); 203*45039663SJohn Forte 204*45039663SJohn Forte /* 205*45039663SJohn Forte * State values for the iscsit service 206*45039663SJohn Forte */ 207*45039663SJohn Forte typedef enum { 208*45039663SJohn Forte PSS_UNDEFINED = 0, 209*45039663SJohn Forte PSS_DETACHED, 210*45039663SJohn Forte PSS_DISABLED, 211*45039663SJohn Forte PSS_ENABLING, 212*45039663SJohn Forte PSS_ENABLED, 213*45039663SJohn Forte PSS_BUSY, 214*45039663SJohn Forte PSS_DISABLING 215*45039663SJohn Forte } pppt_service_state_t; 216*45039663SJohn Forte 217*45039663SJohn Forte 218*45039663SJohn Forte typedef struct { 219*45039663SJohn Forte pppt_service_state_t global_svc_state; 220*45039663SJohn Forte dev_info_t *global_dip; 221*45039663SJohn Forte stmf_port_provider_t *global_pp; 222*45039663SJohn Forte stmf_dbuf_store_t *global_dbuf_store; 223*45039663SJohn Forte taskq_t *global_dispatch_taskq; 224*45039663SJohn Forte taskq_t *global_sess_taskq; 225*45039663SJohn Forte avl_tree_t global_sess_list; 226*45039663SJohn Forte avl_tree_t global_target_list; 227*45039663SJohn Forte kmutex_t global_lock; 228*45039663SJohn Forte door_handle_t global_door; 229*45039663SJohn Forte kmutex_t global_door_lock; 230*45039663SJohn Forte pppt_error_stats_t global_error_stats; 231*45039663SJohn Forte } pppt_global_t; 232*45039663SJohn Forte 233*45039663SJohn Forte extern pppt_global_t pppt_global; 234*45039663SJohn Forte 235*45039663SJohn Forte stmf_status_t pppt_lport_xfer_data(scsi_task_t *task, stmf_data_buf_t *dbuf, 236*45039663SJohn Forte uint32_t ioflags); 237*45039663SJohn Forte 238*45039663SJohn Forte void pppt_xfer_read_complete(pppt_task_t *pppt_task, stmf_status_t status); 239*45039663SJohn Forte 240*45039663SJohn Forte stmf_status_t pppt_lport_send_status(scsi_task_t *task, uint32_t ioflags); 241*45039663SJohn Forte 242*45039663SJohn Forte void pppt_lport_task_free(scsi_task_t *task); 243*45039663SJohn Forte 244*45039663SJohn Forte stmf_status_t pppt_lport_abort(stmf_local_port_t *lport, int abort_cmd, 245*45039663SJohn Forte void *arg, uint32_t flags); 246*45039663SJohn Forte 247*45039663SJohn Forte void pppt_lport_ctl(stmf_local_port_t *lport, int cmd, void *arg); 248*45039663SJohn Forte 249*45039663SJohn Forte pppt_sess_t *pppt_sess_lookup_locked(uint64_t session_id, 250*45039663SJohn Forte scsi_devid_desc_t *lport_devid, 251*45039663SJohn Forte scsi_devid_desc_t *rport_devid); 252*45039663SJohn Forte 253*45039663SJohn Forte pppt_sess_t *pppt_sess_lookup_by_id_locked(uint64_t session_id); 254*45039663SJohn Forte 255*45039663SJohn Forte pppt_sess_t *pppt_sess_lookup_create(scsi_devid_desc_t *lport_devid, 256*45039663SJohn Forte scsi_devid_desc_t *rport_devid, uint64_t session_id, 257*45039663SJohn Forte stmf_status_t *statusp); 258*45039663SJohn Forte 259*45039663SJohn Forte void pppt_sess_rele(pppt_sess_t *sks); 260*45039663SJohn Forte 261*45039663SJohn Forte void pppt_sess_rele_locked(pppt_sess_t *sks); 262*45039663SJohn Forte 263*45039663SJohn Forte void pppt_sess_close_locked(pppt_sess_t *ps); 264*45039663SJohn Forte 265*45039663SJohn Forte int pppt_sess_avl_compare_by_id(const void *void_sess1, 266*45039663SJohn Forte const void *void_sess2); 267*45039663SJohn Forte 268*45039663SJohn Forte int pppt_sess_avl_compare_by_name(const void *void_sess1, 269*45039663SJohn Forte const void *void_sess2); 270*45039663SJohn Forte 271*45039663SJohn Forte pppt_task_t *pppt_task_alloc(void); 272*45039663SJohn Forte 273*45039663SJohn Forte void pppt_task_free(pppt_task_t *ptask); 274*45039663SJohn Forte 275*45039663SJohn Forte pppt_status_t pppt_task_start(pppt_task_t *ptask); 276*45039663SJohn Forte 277*45039663SJohn Forte pppt_status_t pppt_task_done(pppt_task_t *ptask); 278*45039663SJohn Forte 279*45039663SJohn Forte pppt_task_t *pppt_task_lookup(stmf_ic_msgid_t msgid); 280*45039663SJohn Forte 281*45039663SJohn Forte void pppt_msg_rx(stmf_ic_msg_t *msg); 282*45039663SJohn Forte 283*45039663SJohn Forte void pppt_msg_tx_status(stmf_ic_msg_t *orig_msg, stmf_status_t status); 284*45039663SJohn Forte 285*45039663SJohn Forte pppt_tgt_t *pppt_tgt_lookup(scsi_devid_desc_t *tgt_devid); 286*45039663SJohn Forte 287*45039663SJohn Forte pppt_tgt_t *pppt_tgt_lookup_locked(scsi_devid_desc_t *tgt_devid); 288*45039663SJohn Forte 289*45039663SJohn Forte pppt_tgt_t *pppt_tgt_create(stmf_ic_reg_port_msg_t *reg_port, 290*45039663SJohn Forte stmf_status_t *errcode); 291*45039663SJohn Forte 292*45039663SJohn Forte void pppt_tgt_async_delete(pppt_tgt_t *tgt); 293*45039663SJohn Forte 294*45039663SJohn Forte void pppt_tgt_destroy(pppt_tgt_t *tgt); 295*45039663SJohn Forte 296*45039663SJohn Forte int pppt_tgt_avl_compare(const void *void_tgt1, const void *void_tgt2); 297*45039663SJohn Forte 298*45039663SJohn Forte void pppt_tgt_sm_ctl(stmf_local_port_t *lport, int cmd, void *arg); 299*45039663SJohn Forte 300*45039663SJohn Forte #ifdef __cplusplus 301*45039663SJohn Forte } 302*45039663SJohn Forte #endif 303*45039663SJohn Forte 304*45039663SJohn Forte #endif /* _PPPT_H */ 305