1 /* 2 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 3 * By downloading, copying, installing or using the software you agree 4 * to this license. If you do not agree to this license, do not 5 * download, install, copy or use the software. 6 * 7 * Intel License Agreement 8 * 9 * Copyright (c) 2000, Intel Corporation 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 16 * -Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 19 * -Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the 22 * distribution. 23 * 24 * -The name of Intel Corporation may not be used to endorse or 25 * promote products derived from this software without specific prior 26 * written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 31 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL 32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 35 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 38 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 */ 41 #ifndef _INITIATOR_H_ 42 #define _INITIATOR_H_ 43 44 #include "iscsiprotocol.h" 45 #include "parameters.h" 46 #include "defs.h" 47 48 #define CONFIG_INITIATOR_NUM_TARGETS 16 49 50 /*********** 51 * Private * 52 ***********/ 53 54 #define CONFIG_INITIATOR_QUEUE_DEPTH CONFIG_INITIATOR_NUM_TARGETS 55 #define CONFIG_INITIATOR_MAX_SESSIONS CONFIG_INITIATOR_NUM_TARGETS 56 57 enum { 58 INITIATOR_SESSION_STATE_INITIALIZING = 0x001, 59 INITIATOR_SESSION_STATE_INITIALIZED = 0x002, 60 INITIATOR_SESSION_STATE_CONNECTING = 0x004, 61 INITIATOR_SESSION_STATE_CONNECTED = 0x008, 62 INITIATOR_SESSION_STATE_LOGGING_IN = 0x010, 63 INITIATOR_SESSION_STATE_AUTHENTICATED = 0x020, 64 INITIATOR_SESSION_STATE_LOGGED_IN_NORMAL = 0x040, 65 INITIATOR_SESSION_STATE_LOGGED_IN_DISCOVERY = 0x080, 66 INITIATOR_SESSION_STATE_LOGGING_OUT = 0x100, 67 INITIATOR_SESSION_STATE_LOGGED_OUT = 0x200, 68 INITIATOR_SESSION_STATE_DESTROYING = 0x400 69 }; 70 71 enum { 72 TARGET_HOSTNAME_SIZE = 1024, 73 TARGET_IP_SIZE = 16, 74 TARGET_NAME_SIZE = 256 75 }; 76 77 #define INITIATOR_STATE_SHUTDOWN 1 78 79 typedef struct { 80 iscsi_mutex_t mutex; 81 iscsi_cond_t cond; 82 } initiator_wait_t; 83 84 typedef struct initiator_session_t { 85 int sock; 86 uint32_t CmdSN; 87 uint32_t ExpStatSN; 88 uint32_t MaxCmdSN; 89 iscsi_queue_t tx_queue; 90 iscsi_worker_t tx_worker; 91 iscsi_worker_t rx_worker; 92 uint64_t isid; 93 int tsih; 94 int cid; 95 uint32_t state; 96 iscsi_parameter_t *params; 97 struct initiator_cmd_t *cmds; 98 iscsi_spin_t cmds_spin; 99 iscsi_sess_param_t sess_params; 100 } initiator_session_t; 101 102 typedef struct initiator_cmd_t { 103 void *ptr; 104 int type; 105 int (*callback) (void *); 106 void *callback_arg; 107 uint64_t isid; 108 int tx_done; 109 int status; 110 struct initiator_cmd_t *next; 111 struct initiator_cmd_t *hash_next; 112 uint32_t key; 113 char targetname[TARGET_HOSTNAME_SIZE]; 114 } initiator_cmd_t; 115 116 typedef struct initiator_target_t { 117 char name[TARGET_HOSTNAME_SIZE]; 118 char ip[TARGET_IP_SIZE]; 119 int port; 120 char TargetName[TARGET_NAME_SIZE]; 121 initiator_session_t *sess; 122 int has_session; 123 char iqnwanted[TARGET_NAME_SIZE]; 124 } initiator_target_t; 125 126 DEFINE_ARRAY(strv_t, char *); 127 128 129 /********** 130 * Public * 131 **********/ 132 133 int initiator_command(initiator_cmd_t *); 134 int initiator_enqueue(initiator_cmd_t *); 135 int initiator_abort(initiator_cmd_t *); 136 137 void get_target_info(uint64_t, initiator_target_t *); 138 139 int ii_initiator_init(const char *, int, int, const char *, char *, int, int, int); 140 141 int iscsi_initiator_get_targets(int, strv_t *); 142 int initiator_set_target_name(int, char *); 143 144 #endif /* _INITIATOR_H_ */ 145