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 uint16_t trace_id; 77 78 uint64_t last_flush; 79 uint64_t last_fill; 80 uint64_t last_nopin; 81 82 /* Timer used to destroy connection after requesting logout if 83 * initiator does not send logout request. 84 */ 85 struct spdk_poller *logout_request_timer; 86 87 /* Timer used to destroy connection after logout if initiator does 88 * not close the connection. 89 */ 90 struct spdk_poller *logout_timer; 91 92 /* Timer used to wait for connection to close 93 */ 94 struct spdk_poller *shutdown_timer; 95 96 /* Timer used to destroy connection after creating this connection 97 * if login process does not complete. 98 */ 99 struct spdk_poller *login_timer; 100 101 struct spdk_iscsi_pdu *pdu_in_progress; 102 enum iscsi_pdu_recv_state pdu_recv_state; 103 104 TAILQ_HEAD(, spdk_iscsi_pdu) write_pdu_list; 105 TAILQ_HEAD(, spdk_iscsi_pdu) snack_pdu_list; 106 107 uint32_t pending_r2t; 108 109 uint16_t cid; 110 111 /* IP address */ 112 char initiator_addr[MAX_INITIATOR_ADDR]; 113 char target_addr[MAX_TARGET_ADDR]; 114 115 /* Initiator/Target port binds */ 116 char initiator_name[MAX_INITIATOR_NAME]; 117 struct spdk_scsi_port *initiator_port; 118 char target_short_name[MAX_TARGET_NAME]; 119 struct spdk_scsi_port *target_port; 120 struct spdk_iscsi_tgt_node *target; 121 struct spdk_scsi_dev *dev; 122 123 /* To handle the case that SendTargets response is split into 124 * multiple PDUs due to very small MaxRecvDataSegmentLength. 125 */ 126 uint32_t send_tgt_completed_size; 127 struct iscsi_param *params_text; 128 129 /* for fast access */ 130 int header_digest; 131 int data_digest; 132 int full_feature; 133 134 struct iscsi_param *params; 135 bool sess_param_state_negotiated[MAX_SESSION_PARAMS]; 136 bool conn_param_state_negotiated[MAX_CONNECTION_PARAMS]; 137 struct iscsi_chap_auth auth; 138 bool authenticated; 139 bool disable_chap; 140 bool require_chap; 141 bool mutual_chap; 142 int32_t chap_group; 143 uint32_t pending_task_cnt; 144 uint32_t data_out_cnt; 145 uint32_t data_in_cnt; 146 147 uint64_t timeout; 148 uint64_t nopininterval; 149 bool nop_outstanding; 150 151 /* 152 * This is the maximum data segment length that iscsi target can send 153 * to the initiator on this connection. Not to be confused with the 154 * maximum data segment length that initiators can send to iscsi target, which 155 * is statically defined as SPDK_ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH. 156 */ 157 int MaxRecvDataSegmentLength; 158 159 uint32_t StatSN; 160 uint32_t exp_statsn; 161 uint32_t ttt; /* target transfer tag */ 162 char *partial_text_parameter; 163 164 STAILQ_ENTRY(spdk_iscsi_conn) pg_link; 165 bool is_stopped; /* Set true when connection is stopped for migration */ 166 TAILQ_HEAD(queued_r2t_tasks, spdk_iscsi_task) queued_r2t_tasks; 167 TAILQ_HEAD(active_r2t_tasks, spdk_iscsi_task) active_r2t_tasks; 168 TAILQ_HEAD(queued_datain_tasks, spdk_iscsi_task) queued_datain_tasks; 169 170 TAILQ_HEAD(, spdk_iscsi_lun) luns; 171 172 TAILQ_ENTRY(spdk_iscsi_conn) conn_link; 173 }; 174 175 void iscsi_task_cpl(struct spdk_scsi_task *scsi_task); 176 void iscsi_task_mgmt_cpl(struct spdk_scsi_task *scsi_task); 177 178 int initialize_iscsi_conns(void); 179 void shutdown_iscsi_conns(void); 180 void iscsi_conns_request_logout(struct spdk_iscsi_tgt_node *target, int pg_tag); 181 int iscsi_get_active_conns(struct spdk_iscsi_tgt_node *target); 182 183 int iscsi_conn_construct(struct spdk_iscsi_portal *portal, struct spdk_sock *sock); 184 void iscsi_conn_destruct(struct spdk_iscsi_conn *conn); 185 void iscsi_conn_handle_nop(struct spdk_iscsi_conn *conn); 186 void iscsi_conn_schedule(struct spdk_iscsi_conn *conn); 187 void iscsi_conn_logout(struct spdk_iscsi_conn *conn); 188 int iscsi_drop_conns(struct spdk_iscsi_conn *conn, 189 const char *conn_match, int drop_all); 190 int iscsi_conn_handle_queued_datain_tasks(struct spdk_iscsi_conn *conn); 191 int iscsi_conn_abort_queued_datain_task(struct spdk_iscsi_conn *conn, 192 uint32_t ref_task_tag); 193 int iscsi_conn_abort_queued_datain_tasks(struct spdk_iscsi_conn *conn, 194 struct spdk_scsi_lun *lun, 195 struct spdk_iscsi_pdu *pdu); 196 197 int iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int len, void *buf); 198 int iscsi_conn_readv_data(struct spdk_iscsi_conn *conn, 199 struct iovec *iov, int iovcnt); 200 void iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu, 201 iscsi_conn_xfer_complete_cb cb_fn, 202 void *cb_arg); 203 204 void iscsi_conn_free_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu); 205 206 void iscsi_conn_info_json(struct spdk_json_write_ctx *w, struct spdk_iscsi_conn *conn); 207 void iscsi_conn_pdu_generic_complete(void *cb_arg); 208 #endif /* SPDK_ISCSI_CONN_H */ 209