1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>. 3 * Copyright (C) 2016 Intel Corporation. 4 * All rights reserved. 5 */ 6 7 #ifndef SPDK_ISCSI_CONN_H 8 #define SPDK_ISCSI_CONN_H 9 10 #include "spdk/stdinc.h" 11 12 #include "iscsi/iscsi.h" 13 #include "spdk/queue.h" 14 #include "spdk/cpuset.h" 15 #include "spdk/scsi.h" 16 17 #include "spdk_internal/trace_defs.h" 18 19 /* 20 * MAX_CONNECTION_PARAMS: The numbers of the params in conn_param_table 21 * MAX_SESSION_PARAMS: The numbers of the params in sess_param_table 22 */ 23 #define MAX_CONNECTION_PARAMS 14 24 #define MAX_SESSION_PARAMS 19 25 26 #define MAX_ADDRBUF 64 27 #define MAX_INITIATOR_ADDR (MAX_ADDRBUF) 28 #define MAX_TARGET_ADDR (MAX_ADDRBUF) 29 30 enum iscsi_pdu_recv_state { 31 /* Ready to wait for PDU */ 32 ISCSI_PDU_RECV_STATE_AWAIT_PDU_READY, 33 34 /* Active connection waiting for any PDU header */ 35 ISCSI_PDU_RECV_STATE_AWAIT_PDU_HDR, 36 37 /* Active connection waiting for payload */ 38 ISCSI_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD, 39 40 /* Active connection does not wait for payload */ 41 ISCSI_PDU_RECV_STATE_ERROR, 42 }; 43 44 struct spdk_poller; 45 struct spdk_iscsi_conn; 46 47 struct spdk_iscsi_lun { 48 struct spdk_iscsi_conn *conn; 49 struct spdk_scsi_lun *lun; 50 struct spdk_scsi_lun_desc *desc; 51 struct spdk_poller *remove_poller; 52 TAILQ_ENTRY(spdk_iscsi_lun) tailq; 53 }; 54 55 struct spdk_iscsi_conn { 56 int id; 57 int is_valid; 58 /* 59 * All fields below this point are reinitialized each time the 60 * connection object is allocated. Make sure to update the 61 * SPDK_ISCSI_CONNECTION_MEMSET() macro if changing which fields 62 * are initialized when allocated. 63 */ 64 struct spdk_iscsi_portal *portal; 65 int pg_tag; 66 char portal_host[MAX_PORTAL_ADDR + 1]; 67 char portal_port[MAX_PORTAL_ADDR + 1]; 68 struct spdk_iscsi_poll_group *pg; 69 struct spdk_sock *sock; 70 struct spdk_iscsi_sess *sess; 71 72 enum iscsi_connection_state state; 73 int login_phase; 74 bool is_logged_out; 75 struct spdk_iscsi_pdu *login_rsp_pdu; 76 77 uint64_t last_flush; 78 uint64_t last_fill; 79 uint64_t last_nopin; 80 81 /* Timer used to destroy connection after requesting logout if 82 * initiator does not send logout request. 83 */ 84 struct spdk_poller *logout_request_timer; 85 86 /* Timer used to destroy connection after logout if initiator does 87 * not close the connection. 88 */ 89 struct spdk_poller *logout_timer; 90 91 /* Timer used to wait for connection to close 92 */ 93 struct spdk_poller *shutdown_timer; 94 95 /* Timer used to destroy connection after creating this connection 96 * if login process does not complete. 97 */ 98 struct spdk_poller *login_timer; 99 100 struct spdk_iscsi_pdu *pdu_in_progress; 101 enum iscsi_pdu_recv_state pdu_recv_state; 102 103 TAILQ_HEAD(, spdk_iscsi_pdu) write_pdu_list; 104 TAILQ_HEAD(, spdk_iscsi_pdu) snack_pdu_list; 105 106 uint32_t pending_r2t; 107 108 uint16_t cid; 109 110 /* IP address */ 111 char initiator_addr[MAX_INITIATOR_ADDR]; 112 char target_addr[MAX_TARGET_ADDR]; 113 114 /* Initiator/Target port binds */ 115 char initiator_name[MAX_INITIATOR_NAME]; 116 struct spdk_scsi_port *initiator_port; 117 char target_short_name[MAX_TARGET_NAME]; 118 struct spdk_scsi_port *target_port; 119 struct spdk_iscsi_tgt_node *target; 120 struct spdk_scsi_dev *dev; 121 122 /* To handle the case that SendTargets response is split into 123 * multiple PDUs due to very small MaxRecvDataSegmentLength. 124 */ 125 uint32_t send_tgt_completed_size; 126 struct iscsi_param *params_text; 127 128 /* for fast access */ 129 int header_digest; 130 int data_digest; 131 int full_feature; 132 133 struct iscsi_param *params; 134 bool sess_param_state_negotiated[MAX_SESSION_PARAMS]; 135 bool conn_param_state_negotiated[MAX_CONNECTION_PARAMS]; 136 struct iscsi_chap_auth auth; 137 bool authenticated; 138 bool disable_chap; 139 bool require_chap; 140 bool mutual_chap; 141 int32_t chap_group; 142 uint32_t pending_task_cnt; 143 uint32_t data_out_cnt; 144 uint32_t data_in_cnt; 145 146 uint64_t timeout; 147 uint64_t nopininterval; 148 bool nop_outstanding; 149 150 /* 151 * This is the maximum data segment length that iscsi target can send 152 * to the initiator on this connection. Not to be confused with the 153 * maximum data segment length that initiators can send to iscsi target, which 154 * is statically defined as SPDK_ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH. 155 */ 156 int MaxRecvDataSegmentLength; 157 158 uint32_t StatSN; 159 uint32_t exp_statsn; 160 uint32_t ttt; /* target transfer tag */ 161 char *partial_text_parameter; 162 163 STAILQ_ENTRY(spdk_iscsi_conn) pg_link; 164 bool is_stopped; /* Set true when connection is stopped for migration */ 165 TAILQ_HEAD(queued_r2t_tasks, spdk_iscsi_task) queued_r2t_tasks; 166 TAILQ_HEAD(active_r2t_tasks, spdk_iscsi_task) active_r2t_tasks; 167 TAILQ_HEAD(queued_datain_tasks, spdk_iscsi_task) queued_datain_tasks; 168 169 TAILQ_HEAD(, spdk_iscsi_lun) luns; 170 171 TAILQ_ENTRY(spdk_iscsi_conn) conn_link; 172 }; 173 174 void iscsi_task_cpl(struct spdk_scsi_task *scsi_task); 175 void iscsi_task_mgmt_cpl(struct spdk_scsi_task *scsi_task); 176 177 int initialize_iscsi_conns(void); 178 void shutdown_iscsi_conns(void); 179 void iscsi_conns_request_logout(struct spdk_iscsi_tgt_node *target, int pg_tag); 180 int iscsi_get_active_conns(struct spdk_iscsi_tgt_node *target); 181 182 int iscsi_conn_construct(struct spdk_iscsi_portal *portal, struct spdk_sock *sock); 183 void iscsi_conn_destruct(struct spdk_iscsi_conn *conn); 184 void iscsi_conn_handle_nop(struct spdk_iscsi_conn *conn); 185 void iscsi_conn_schedule(struct spdk_iscsi_conn *conn); 186 void iscsi_conn_logout(struct spdk_iscsi_conn *conn); 187 int iscsi_drop_conns(struct spdk_iscsi_conn *conn, 188 const char *conn_match, int drop_all); 189 int iscsi_conn_handle_queued_datain_tasks(struct spdk_iscsi_conn *conn); 190 int iscsi_conn_abort_queued_datain_task(struct spdk_iscsi_conn *conn, 191 uint32_t ref_task_tag); 192 int iscsi_conn_abort_queued_datain_tasks(struct spdk_iscsi_conn *conn, 193 struct spdk_scsi_lun *lun, 194 struct spdk_iscsi_pdu *pdu); 195 196 int iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int len, void *buf); 197 int iscsi_conn_readv_data(struct spdk_iscsi_conn *conn, 198 struct iovec *iov, int iovcnt); 199 void iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu, 200 iscsi_conn_xfer_complete_cb cb_fn, 201 void *cb_arg); 202 203 void iscsi_conn_free_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu); 204 205 void iscsi_conn_info_json(struct spdk_json_write_ctx *w, struct spdk_iscsi_conn *conn); 206 void iscsi_conn_pdu_generic_complete(void *cb_arg); 207 #endif /* SPDK_ISCSI_CONN_H */ 208