1 /* 2 * iSCSI User/Kernel Shares (Defines, Constants, Protocol definitions, etc) 3 * 4 * Copyright (C) 2005 Dmitry Yusupov 5 * Copyright (C) 2005 Alex Aizman 6 * maintained by open-iscsi@googlegroups.com 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published 10 * by the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * See the file COPYING included with this distribution for more details. 19 */ 20 21 #ifndef ISCSI_IF_H 22 #define ISCSI_IF_H 23 24 #include <scsi/iscsi_proto.h> 25 26 #define UEVENT_BASE 10 27 #define KEVENT_BASE 100 28 #define ISCSI_ERR_BASE 1000 29 30 enum iscsi_uevent_e { 31 ISCSI_UEVENT_UNKNOWN = 0, 32 33 /* down events */ 34 ISCSI_UEVENT_CREATE_SESSION = UEVENT_BASE + 1, 35 ISCSI_UEVENT_DESTROY_SESSION = UEVENT_BASE + 2, 36 ISCSI_UEVENT_CREATE_CONN = UEVENT_BASE + 3, 37 ISCSI_UEVENT_DESTROY_CONN = UEVENT_BASE + 4, 38 ISCSI_UEVENT_BIND_CONN = UEVENT_BASE + 5, 39 ISCSI_UEVENT_SET_PARAM = UEVENT_BASE + 6, 40 ISCSI_UEVENT_START_CONN = UEVENT_BASE + 7, 41 ISCSI_UEVENT_STOP_CONN = UEVENT_BASE + 8, 42 ISCSI_UEVENT_SEND_PDU = UEVENT_BASE + 9, 43 ISCSI_UEVENT_GET_STATS = UEVENT_BASE + 10, 44 ISCSI_UEVENT_GET_PARAM = UEVENT_BASE + 11, 45 46 ISCSI_UEVENT_TRANSPORT_EP_CONNECT = UEVENT_BASE + 12, 47 ISCSI_UEVENT_TRANSPORT_EP_POLL = UEVENT_BASE + 13, 48 ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT = UEVENT_BASE + 14, 49 50 /* up events */ 51 ISCSI_KEVENT_RECV_PDU = KEVENT_BASE + 1, 52 ISCSI_KEVENT_CONN_ERROR = KEVENT_BASE + 2, 53 ISCSI_KEVENT_IF_ERROR = KEVENT_BASE + 3, 54 }; 55 56 struct iscsi_uevent { 57 uint32_t type; /* k/u events type */ 58 uint32_t iferror; /* carries interface or resource errors */ 59 uint64_t transport_handle; 60 61 union { 62 /* messages u -> k */ 63 struct msg_create_session { 64 uint32_t initial_cmdsn; 65 } c_session; 66 struct msg_destroy_session { 67 uint32_t sid; 68 } d_session; 69 struct msg_create_conn { 70 uint32_t sid; 71 uint32_t cid; 72 } c_conn; 73 struct msg_bind_conn { 74 uint32_t sid; 75 uint32_t cid; 76 uint64_t transport_eph; 77 uint32_t is_leading; 78 } b_conn; 79 struct msg_destroy_conn { 80 uint32_t sid; 81 uint32_t cid; 82 } d_conn; 83 struct msg_send_pdu { 84 uint32_t sid; 85 uint32_t cid; 86 uint32_t hdr_size; 87 uint32_t data_size; 88 } send_pdu; 89 struct msg_set_param { 90 uint32_t sid; 91 uint32_t cid; 92 uint32_t param; /* enum iscsi_param */ 93 uint32_t len; 94 } set_param; 95 struct msg_start_conn { 96 uint32_t sid; 97 uint32_t cid; 98 } start_conn; 99 struct msg_stop_conn { 100 uint32_t sid; 101 uint32_t cid; 102 uint64_t conn_handle; 103 uint32_t flag; 104 } stop_conn; 105 struct msg_get_stats { 106 uint32_t sid; 107 uint32_t cid; 108 } get_stats; 109 struct msg_transport_connect { 110 uint32_t non_blocking; 111 } ep_connect; 112 struct msg_transport_poll { 113 uint64_t ep_handle; 114 uint32_t timeout_ms; 115 } ep_poll; 116 struct msg_transport_disconnect { 117 uint64_t ep_handle; 118 } ep_disconnect; 119 } u; 120 union { 121 /* messages k -> u */ 122 int retcode; 123 struct msg_create_session_ret { 124 uint32_t sid; 125 uint32_t host_no; 126 } c_session_ret; 127 struct msg_create_conn_ret { 128 uint32_t sid; 129 uint32_t cid; 130 } c_conn_ret; 131 struct msg_recv_req { 132 uint32_t sid; 133 uint32_t cid; 134 uint64_t recv_handle; 135 } recv_req; 136 struct msg_conn_error { 137 uint32_t sid; 138 uint32_t cid; 139 uint32_t error; /* enum iscsi_err */ 140 } connerror; 141 struct msg_transport_connect_ret { 142 uint64_t handle; 143 } ep_connect_ret; 144 } r; 145 } __attribute__ ((aligned (sizeof(uint64_t)))); 146 147 /* 148 * Common error codes 149 */ 150 enum iscsi_err { 151 ISCSI_OK = 0, 152 153 ISCSI_ERR_DATASN = ISCSI_ERR_BASE + 1, 154 ISCSI_ERR_DATA_OFFSET = ISCSI_ERR_BASE + 2, 155 ISCSI_ERR_MAX_CMDSN = ISCSI_ERR_BASE + 3, 156 ISCSI_ERR_EXP_CMDSN = ISCSI_ERR_BASE + 4, 157 ISCSI_ERR_BAD_OPCODE = ISCSI_ERR_BASE + 5, 158 ISCSI_ERR_DATALEN = ISCSI_ERR_BASE + 6, 159 ISCSI_ERR_AHSLEN = ISCSI_ERR_BASE + 7, 160 ISCSI_ERR_PROTO = ISCSI_ERR_BASE + 8, 161 ISCSI_ERR_LUN = ISCSI_ERR_BASE + 9, 162 ISCSI_ERR_BAD_ITT = ISCSI_ERR_BASE + 10, 163 ISCSI_ERR_CONN_FAILED = ISCSI_ERR_BASE + 11, 164 ISCSI_ERR_R2TSN = ISCSI_ERR_BASE + 12, 165 ISCSI_ERR_SESSION_FAILED = ISCSI_ERR_BASE + 13, 166 ISCSI_ERR_HDR_DGST = ISCSI_ERR_BASE + 14, 167 ISCSI_ERR_DATA_DGST = ISCSI_ERR_BASE + 15, 168 ISCSI_ERR_PARAM_NOT_FOUND = ISCSI_ERR_BASE + 16, 169 ISCSI_ERR_NO_SCSI_CMD = ISCSI_ERR_BASE + 17, 170 }; 171 172 /* 173 * iSCSI Parameters (RFC3720) 174 */ 175 enum iscsi_param { 176 /* passed in using netlink set param */ 177 ISCSI_PARAM_MAX_RECV_DLENGTH, 178 ISCSI_PARAM_MAX_XMIT_DLENGTH, 179 ISCSI_PARAM_HDRDGST_EN, 180 ISCSI_PARAM_DATADGST_EN, 181 ISCSI_PARAM_INITIAL_R2T_EN, 182 ISCSI_PARAM_MAX_R2T, 183 ISCSI_PARAM_IMM_DATA_EN, 184 ISCSI_PARAM_FIRST_BURST, 185 ISCSI_PARAM_MAX_BURST, 186 ISCSI_PARAM_PDU_INORDER_EN, 187 ISCSI_PARAM_DATASEQ_INORDER_EN, 188 ISCSI_PARAM_ERL, 189 ISCSI_PARAM_IFMARKER_EN, 190 ISCSI_PARAM_OFMARKER_EN, 191 ISCSI_PARAM_EXP_STATSN, 192 ISCSI_PARAM_TARGET_NAME, 193 ISCSI_PARAM_TPGT, 194 ISCSI_PARAM_PERSISTENT_ADDRESS, 195 ISCSI_PARAM_PERSISTENT_PORT, 196 ISCSI_PARAM_SESS_RECOVERY_TMO, 197 198 /* pased in through bind conn using transport_fd */ 199 ISCSI_PARAM_CONN_PORT, 200 ISCSI_PARAM_CONN_ADDRESS, 201 202 /* must always be last */ 203 ISCSI_PARAM_MAX, 204 }; 205 206 #define ISCSI_MAX_RECV_DLENGTH (1 << ISCSI_PARAM_MAX_RECV_DLENGTH) 207 #define ISCSI_MAX_XMIT_DLENGTH (1 << ISCSI_PARAM_MAX_XMIT_DLENGTH) 208 #define ISCSI_HDRDGST_EN (1 << ISCSI_PARAM_HDRDGST_EN) 209 #define ISCSI_DATADGST_EN (1 << ISCSI_PARAM_DATADGST_EN) 210 #define ISCSI_INITIAL_R2T_EN (1 << ISCSI_PARAM_INITIAL_R2T_EN) 211 #define ISCSI_MAX_R2T (1 << ISCSI_PARAM_MAX_R2T) 212 #define ISCSI_IMM_DATA_EN (1 << ISCSI_PARAM_IMM_DATA_EN) 213 #define ISCSI_FIRST_BURST (1 << ISCSI_PARAM_FIRST_BURST) 214 #define ISCSI_MAX_BURST (1 << ISCSI_PARAM_MAX_BURST) 215 #define ISCSI_PDU_INORDER_EN (1 << ISCSI_PARAM_PDU_INORDER_EN) 216 #define ISCSI_DATASEQ_INORDER_EN (1 << ISCSI_PARAM_DATASEQ_INORDER_EN) 217 #define ISCSI_ERL (1 << ISCSI_PARAM_ERL) 218 #define ISCSI_IFMARKER_EN (1 << ISCSI_PARAM_IFMARKER_EN) 219 #define ISCSI_OFMARKER_EN (1 << ISCSI_PARAM_OFMARKER_EN) 220 #define ISCSI_EXP_STATSN (1 << ISCSI_PARAM_EXP_STATSN) 221 #define ISCSI_TARGET_NAME (1 << ISCSI_PARAM_TARGET_NAME) 222 #define ISCSI_TPGT (1 << ISCSI_PARAM_TPGT) 223 #define ISCSI_PERSISTENT_ADDRESS (1 << ISCSI_PARAM_PERSISTENT_ADDRESS) 224 #define ISCSI_PERSISTENT_PORT (1 << ISCSI_PARAM_PERSISTENT_PORT) 225 #define ISCSI_SESS_RECOVERY_TMO (1 << ISCSI_PARAM_SESS_RECOVERY_TMO) 226 #define ISCSI_CONN_PORT (1 << ISCSI_PARAM_CONN_PORT) 227 #define ISCSI_CONN_ADDRESS (1 << ISCSI_PARAM_CONN_ADDRESS) 228 229 #define iscsi_ptr(_handle) ((void*)(unsigned long)_handle) 230 #define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr) 231 #define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata)) 232 233 /** 234 * iscsi_hostdata - get LLD hostdata from scsi_host 235 * @_hostdata: pointer to scsi host's hostdata 236 **/ 237 #define iscsi_hostdata(_hostdata) ((void*)_hostdata + sizeof(unsigned long)) 238 239 /* 240 * These flags presents iSCSI Data-Path capabilities. 241 */ 242 #define CAP_RECOVERY_L0 0x1 243 #define CAP_RECOVERY_L1 0x2 244 #define CAP_RECOVERY_L2 0x4 245 #define CAP_MULTI_R2T 0x8 246 #define CAP_HDRDGST 0x10 247 #define CAP_DATADGST 0x20 248 #define CAP_MULTI_CONN 0x40 249 #define CAP_TEXT_NEGO 0x80 250 #define CAP_MARKERS 0x100 251 252 /* 253 * These flags describes reason of stop_conn() call 254 */ 255 #define STOP_CONN_TERM 0x1 256 #define STOP_CONN_SUSPEND 0x2 257 #define STOP_CONN_RECOVER 0x3 258 259 #define ISCSI_STATS_CUSTOM_MAX 32 260 #define ISCSI_STATS_CUSTOM_DESC_MAX 64 261 struct iscsi_stats_custom { 262 char desc[ISCSI_STATS_CUSTOM_DESC_MAX]; 263 uint64_t value; 264 }; 265 266 /* 267 * struct iscsi_stats - iSCSI Statistics (iSCSI MIB) 268 * 269 * Note: this structure contains counters collected on per-connection basis. 270 */ 271 struct iscsi_stats { 272 /* octets */ 273 uint64_t txdata_octets; 274 uint64_t rxdata_octets; 275 276 /* xmit pdus */ 277 uint32_t noptx_pdus; 278 uint32_t scsicmd_pdus; 279 uint32_t tmfcmd_pdus; 280 uint32_t login_pdus; 281 uint32_t text_pdus; 282 uint32_t dataout_pdus; 283 uint32_t logout_pdus; 284 uint32_t snack_pdus; 285 286 /* recv pdus */ 287 uint32_t noprx_pdus; 288 uint32_t scsirsp_pdus; 289 uint32_t tmfrsp_pdus; 290 uint32_t textrsp_pdus; 291 uint32_t datain_pdus; 292 uint32_t logoutrsp_pdus; 293 uint32_t r2t_pdus; 294 uint32_t async_pdus; 295 uint32_t rjt_pdus; 296 297 /* errors */ 298 uint32_t digest_err; 299 uint32_t timeout_err; 300 301 /* 302 * iSCSI Custom Statistics support, i.e. Transport could 303 * extend existing MIB statistics with its own specific statistics 304 * up to ISCSI_STATS_CUSTOM_MAX 305 */ 306 uint32_t custom_length; 307 struct iscsi_stats_custom custom[0] 308 __attribute__ ((aligned (sizeof(uint64_t)))); 309 }; 310 311 #endif 312