1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2e48354ceSNicholas Bellinger /******************************************************************************* 3e48354ceSNicholas Bellinger * This file contains the main functions related to Initiator Node Attributes. 4e48354ceSNicholas Bellinger * 54c76251eSNicholas Bellinger * (c) Copyright 2007-2013 Datera, Inc. 6e48354ceSNicholas Bellinger * 7e48354ceSNicholas Bellinger * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> 8e48354ceSNicholas Bellinger * 9e48354ceSNicholas Bellinger ******************************************************************************/ 10e48354ceSNicholas Bellinger 11e48354ceSNicholas Bellinger #include <target/target_core_base.h> 12e48354ceSNicholas Bellinger 1367f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_core.h> 14e48354ceSNicholas Bellinger #include "iscsi_target_device.h" 15e48354ceSNicholas Bellinger #include "iscsi_target_tpg.h" 16e48354ceSNicholas Bellinger #include "iscsi_target_util.h" 17e48354ceSNicholas Bellinger #include "iscsi_target_nodeattrib.h" 18e48354ceSNicholas Bellinger 19e48354ceSNicholas Bellinger static inline char *iscsit_na_get_initiatorname( 20e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl) 21e48354ceSNicholas Bellinger { 22e48354ceSNicholas Bellinger struct se_node_acl *se_nacl = &nacl->se_node_acl; 23e48354ceSNicholas Bellinger 24e48354ceSNicholas Bellinger return &se_nacl->initiatorname[0]; 25e48354ceSNicholas Bellinger } 26e48354ceSNicholas Bellinger 27e48354ceSNicholas Bellinger void iscsit_set_default_node_attribues( 28d1fa7a1dSNicholas Bellinger struct iscsi_node_acl *acl, 29d1fa7a1dSNicholas Bellinger struct iscsi_portal_group *tpg) 30e48354ceSNicholas Bellinger { 31e48354ceSNicholas Bellinger struct iscsi_node_attrib *a = &acl->node_attrib; 32e48354ceSNicholas Bellinger 33e48354ceSNicholas Bellinger a->dataout_timeout = NA_DATAOUT_TIMEOUT; 34e48354ceSNicholas Bellinger a->dataout_timeout_retries = NA_DATAOUT_TIMEOUT_RETRIES; 35e48354ceSNicholas Bellinger a->nopin_timeout = NA_NOPIN_TIMEOUT; 36e48354ceSNicholas Bellinger a->nopin_response_timeout = NA_NOPIN_RESPONSE_TIMEOUT; 37e48354ceSNicholas Bellinger a->random_datain_pdu_offsets = NA_RANDOM_DATAIN_PDU_OFFSETS; 38e48354ceSNicholas Bellinger a->random_datain_seq_offsets = NA_RANDOM_DATAIN_SEQ_OFFSETS; 39e48354ceSNicholas Bellinger a->random_r2t_offsets = NA_RANDOM_R2T_OFFSETS; 40d1fa7a1dSNicholas Bellinger a->default_erl = tpg->tpg_attrib.default_erl; 41e48354ceSNicholas Bellinger } 42e48354ceSNicholas Bellinger 43f760903aSDan Carpenter int iscsit_na_dataout_timeout( 44e48354ceSNicholas Bellinger struct iscsi_node_acl *acl, 45e48354ceSNicholas Bellinger u32 dataout_timeout) 46e48354ceSNicholas Bellinger { 47e48354ceSNicholas Bellinger struct iscsi_node_attrib *a = &acl->node_attrib; 48e48354ceSNicholas Bellinger 49e48354ceSNicholas Bellinger if (dataout_timeout > NA_DATAOUT_TIMEOUT_MAX) { 50e48354ceSNicholas Bellinger pr_err("Requested DataOut Timeout %u larger than" 51e48354ceSNicholas Bellinger " maximum %u\n", dataout_timeout, 52e48354ceSNicholas Bellinger NA_DATAOUT_TIMEOUT_MAX); 53e48354ceSNicholas Bellinger return -EINVAL; 54e48354ceSNicholas Bellinger } else if (dataout_timeout < NA_DATAOUT_TIMEOUT_MIX) { 55e48354ceSNicholas Bellinger pr_err("Requested DataOut Timeout %u smaller than" 56e48354ceSNicholas Bellinger " minimum %u\n", dataout_timeout, 57e48354ceSNicholas Bellinger NA_DATAOUT_TIMEOUT_MIX); 58e48354ceSNicholas Bellinger return -EINVAL; 59e48354ceSNicholas Bellinger } 60e48354ceSNicholas Bellinger 61e48354ceSNicholas Bellinger a->dataout_timeout = dataout_timeout; 62e48354ceSNicholas Bellinger pr_debug("Set DataOut Timeout to %u for Initiator Node" 63e48354ceSNicholas Bellinger " %s\n", a->dataout_timeout, iscsit_na_get_initiatorname(acl)); 64e48354ceSNicholas Bellinger 65e48354ceSNicholas Bellinger return 0; 66e48354ceSNicholas Bellinger } 67e48354ceSNicholas Bellinger 68f760903aSDan Carpenter int iscsit_na_dataout_timeout_retries( 69e48354ceSNicholas Bellinger struct iscsi_node_acl *acl, 70e48354ceSNicholas Bellinger u32 dataout_timeout_retries) 71e48354ceSNicholas Bellinger { 72e48354ceSNicholas Bellinger struct iscsi_node_attrib *a = &acl->node_attrib; 73e48354ceSNicholas Bellinger 74e48354ceSNicholas Bellinger if (dataout_timeout_retries > NA_DATAOUT_TIMEOUT_RETRIES_MAX) { 75e48354ceSNicholas Bellinger pr_err("Requested DataOut Timeout Retries %u larger" 76e48354ceSNicholas Bellinger " than maximum %u", dataout_timeout_retries, 77e48354ceSNicholas Bellinger NA_DATAOUT_TIMEOUT_RETRIES_MAX); 78e48354ceSNicholas Bellinger return -EINVAL; 79e48354ceSNicholas Bellinger } else if (dataout_timeout_retries < NA_DATAOUT_TIMEOUT_RETRIES_MIN) { 80e48354ceSNicholas Bellinger pr_err("Requested DataOut Timeout Retries %u smaller" 81e48354ceSNicholas Bellinger " than minimum %u", dataout_timeout_retries, 82e48354ceSNicholas Bellinger NA_DATAOUT_TIMEOUT_RETRIES_MIN); 83e48354ceSNicholas Bellinger return -EINVAL; 84e48354ceSNicholas Bellinger } 85e48354ceSNicholas Bellinger 86e48354ceSNicholas Bellinger a->dataout_timeout_retries = dataout_timeout_retries; 87e48354ceSNicholas Bellinger pr_debug("Set DataOut Timeout Retries to %u for" 88e48354ceSNicholas Bellinger " Initiator Node %s\n", a->dataout_timeout_retries, 89e48354ceSNicholas Bellinger iscsit_na_get_initiatorname(acl)); 90e48354ceSNicholas Bellinger 91e48354ceSNicholas Bellinger return 0; 92e48354ceSNicholas Bellinger } 93e48354ceSNicholas Bellinger 94f760903aSDan Carpenter int iscsit_na_nopin_timeout( 95e48354ceSNicholas Bellinger struct iscsi_node_acl *acl, 96e48354ceSNicholas Bellinger u32 nopin_timeout) 97e48354ceSNicholas Bellinger { 98e48354ceSNicholas Bellinger struct iscsi_node_attrib *a = &acl->node_attrib; 99*0873fe44SMax Gurtovoy struct iscsit_session *sess; 100be36d683SMax Gurtovoy struct iscsit_conn *conn; 101e48354ceSNicholas Bellinger struct se_node_acl *se_nacl = &a->nacl->se_node_acl; 102e48354ceSNicholas Bellinger struct se_session *se_sess; 103e48354ceSNicholas Bellinger u32 orig_nopin_timeout = a->nopin_timeout; 104e48354ceSNicholas Bellinger 105e48354ceSNicholas Bellinger if (nopin_timeout > NA_NOPIN_TIMEOUT_MAX) { 106e48354ceSNicholas Bellinger pr_err("Requested NopIn Timeout %u larger than maximum" 107e48354ceSNicholas Bellinger " %u\n", nopin_timeout, NA_NOPIN_TIMEOUT_MAX); 108e48354ceSNicholas Bellinger return -EINVAL; 109e48354ceSNicholas Bellinger } else if ((nopin_timeout < NA_NOPIN_TIMEOUT_MIN) && 110e48354ceSNicholas Bellinger (nopin_timeout != 0)) { 111e48354ceSNicholas Bellinger pr_err("Requested NopIn Timeout %u smaller than" 112e48354ceSNicholas Bellinger " minimum %u and not 0\n", nopin_timeout, 113e48354ceSNicholas Bellinger NA_NOPIN_TIMEOUT_MIN); 114e48354ceSNicholas Bellinger return -EINVAL; 115e48354ceSNicholas Bellinger } 116e48354ceSNicholas Bellinger 117e48354ceSNicholas Bellinger a->nopin_timeout = nopin_timeout; 118e48354ceSNicholas Bellinger pr_debug("Set NopIn Timeout to %u for Initiator" 119e48354ceSNicholas Bellinger " Node %s\n", a->nopin_timeout, 120e48354ceSNicholas Bellinger iscsit_na_get_initiatorname(acl)); 121e48354ceSNicholas Bellinger /* 122e48354ceSNicholas Bellinger * Reenable disabled nopin_timeout timer for all iSCSI connections. 123e48354ceSNicholas Bellinger */ 124e48354ceSNicholas Bellinger if (!orig_nopin_timeout) { 125e48354ceSNicholas Bellinger spin_lock_bh(&se_nacl->nacl_sess_lock); 126e48354ceSNicholas Bellinger se_sess = se_nacl->nacl_sess; 127e48354ceSNicholas Bellinger if (se_sess) { 1288359cf43SJörn Engel sess = se_sess->fabric_sess_ptr; 129e48354ceSNicholas Bellinger 130e48354ceSNicholas Bellinger spin_lock(&sess->conn_lock); 131e48354ceSNicholas Bellinger list_for_each_entry(conn, &sess->sess_conn_list, 132e48354ceSNicholas Bellinger conn_list) { 133e48354ceSNicholas Bellinger if (conn->conn_state != 134e48354ceSNicholas Bellinger TARG_CONN_STATE_LOGGED_IN) 135e48354ceSNicholas Bellinger continue; 136e48354ceSNicholas Bellinger 137e48354ceSNicholas Bellinger spin_lock(&conn->nopin_timer_lock); 138e48354ceSNicholas Bellinger __iscsit_start_nopin_timer(conn); 139e48354ceSNicholas Bellinger spin_unlock(&conn->nopin_timer_lock); 140e48354ceSNicholas Bellinger } 141e48354ceSNicholas Bellinger spin_unlock(&sess->conn_lock); 142e48354ceSNicholas Bellinger } 143e48354ceSNicholas Bellinger spin_unlock_bh(&se_nacl->nacl_sess_lock); 144e48354ceSNicholas Bellinger } 145e48354ceSNicholas Bellinger 146e48354ceSNicholas Bellinger return 0; 147e48354ceSNicholas Bellinger } 148e48354ceSNicholas Bellinger 149f760903aSDan Carpenter int iscsit_na_nopin_response_timeout( 150e48354ceSNicholas Bellinger struct iscsi_node_acl *acl, 151e48354ceSNicholas Bellinger u32 nopin_response_timeout) 152e48354ceSNicholas Bellinger { 153e48354ceSNicholas Bellinger struct iscsi_node_attrib *a = &acl->node_attrib; 154e48354ceSNicholas Bellinger 155e48354ceSNicholas Bellinger if (nopin_response_timeout > NA_NOPIN_RESPONSE_TIMEOUT_MAX) { 156e48354ceSNicholas Bellinger pr_err("Requested NopIn Response Timeout %u larger" 157e48354ceSNicholas Bellinger " than maximum %u\n", nopin_response_timeout, 158e48354ceSNicholas Bellinger NA_NOPIN_RESPONSE_TIMEOUT_MAX); 159e48354ceSNicholas Bellinger return -EINVAL; 160e48354ceSNicholas Bellinger } else if (nopin_response_timeout < NA_NOPIN_RESPONSE_TIMEOUT_MIN) { 161e48354ceSNicholas Bellinger pr_err("Requested NopIn Response Timeout %u smaller" 162e48354ceSNicholas Bellinger " than minimum %u\n", nopin_response_timeout, 163e48354ceSNicholas Bellinger NA_NOPIN_RESPONSE_TIMEOUT_MIN); 164e48354ceSNicholas Bellinger return -EINVAL; 165e48354ceSNicholas Bellinger } 166e48354ceSNicholas Bellinger 167e48354ceSNicholas Bellinger a->nopin_response_timeout = nopin_response_timeout; 168e48354ceSNicholas Bellinger pr_debug("Set NopIn Response Timeout to %u for" 169e48354ceSNicholas Bellinger " Initiator Node %s\n", a->nopin_timeout, 170e48354ceSNicholas Bellinger iscsit_na_get_initiatorname(acl)); 171e48354ceSNicholas Bellinger 172e48354ceSNicholas Bellinger return 0; 173e48354ceSNicholas Bellinger } 174e48354ceSNicholas Bellinger 175f760903aSDan Carpenter int iscsit_na_random_datain_pdu_offsets( 176e48354ceSNicholas Bellinger struct iscsi_node_acl *acl, 177e48354ceSNicholas Bellinger u32 random_datain_pdu_offsets) 178e48354ceSNicholas Bellinger { 179e48354ceSNicholas Bellinger struct iscsi_node_attrib *a = &acl->node_attrib; 180e48354ceSNicholas Bellinger 181e48354ceSNicholas Bellinger if (random_datain_pdu_offsets != 0 && random_datain_pdu_offsets != 1) { 182e48354ceSNicholas Bellinger pr_err("Requested Random DataIN PDU Offsets: %u not" 183e48354ceSNicholas Bellinger " 0 or 1\n", random_datain_pdu_offsets); 184e48354ceSNicholas Bellinger return -EINVAL; 185e48354ceSNicholas Bellinger } 186e48354ceSNicholas Bellinger 187e48354ceSNicholas Bellinger a->random_datain_pdu_offsets = random_datain_pdu_offsets; 188e48354ceSNicholas Bellinger pr_debug("Set Random DataIN PDU Offsets to %u for" 189e48354ceSNicholas Bellinger " Initiator Node %s\n", a->random_datain_pdu_offsets, 190e48354ceSNicholas Bellinger iscsit_na_get_initiatorname(acl)); 191e48354ceSNicholas Bellinger 192e48354ceSNicholas Bellinger return 0; 193e48354ceSNicholas Bellinger } 194e48354ceSNicholas Bellinger 195f760903aSDan Carpenter int iscsit_na_random_datain_seq_offsets( 196e48354ceSNicholas Bellinger struct iscsi_node_acl *acl, 197e48354ceSNicholas Bellinger u32 random_datain_seq_offsets) 198e48354ceSNicholas Bellinger { 199e48354ceSNicholas Bellinger struct iscsi_node_attrib *a = &acl->node_attrib; 200e48354ceSNicholas Bellinger 201e48354ceSNicholas Bellinger if (random_datain_seq_offsets != 0 && random_datain_seq_offsets != 1) { 202e48354ceSNicholas Bellinger pr_err("Requested Random DataIN Sequence Offsets: %u" 203e48354ceSNicholas Bellinger " not 0 or 1\n", random_datain_seq_offsets); 204e48354ceSNicholas Bellinger return -EINVAL; 205e48354ceSNicholas Bellinger } 206e48354ceSNicholas Bellinger 207e48354ceSNicholas Bellinger a->random_datain_seq_offsets = random_datain_seq_offsets; 208e48354ceSNicholas Bellinger pr_debug("Set Random DataIN Sequence Offsets to %u for" 209e48354ceSNicholas Bellinger " Initiator Node %s\n", a->random_datain_seq_offsets, 210e48354ceSNicholas Bellinger iscsit_na_get_initiatorname(acl)); 211e48354ceSNicholas Bellinger 212e48354ceSNicholas Bellinger return 0; 213e48354ceSNicholas Bellinger } 214e48354ceSNicholas Bellinger 215f760903aSDan Carpenter int iscsit_na_random_r2t_offsets( 216e48354ceSNicholas Bellinger struct iscsi_node_acl *acl, 217e48354ceSNicholas Bellinger u32 random_r2t_offsets) 218e48354ceSNicholas Bellinger { 219e48354ceSNicholas Bellinger struct iscsi_node_attrib *a = &acl->node_attrib; 220e48354ceSNicholas Bellinger 221e48354ceSNicholas Bellinger if (random_r2t_offsets != 0 && random_r2t_offsets != 1) { 222e48354ceSNicholas Bellinger pr_err("Requested Random R2T Offsets: %u not" 223e48354ceSNicholas Bellinger " 0 or 1\n", random_r2t_offsets); 224e48354ceSNicholas Bellinger return -EINVAL; 225e48354ceSNicholas Bellinger } 226e48354ceSNicholas Bellinger 227e48354ceSNicholas Bellinger a->random_r2t_offsets = random_r2t_offsets; 228e48354ceSNicholas Bellinger pr_debug("Set Random R2T Offsets to %u for" 229e48354ceSNicholas Bellinger " Initiator Node %s\n", a->random_r2t_offsets, 230e48354ceSNicholas Bellinger iscsit_na_get_initiatorname(acl)); 231e48354ceSNicholas Bellinger 232e48354ceSNicholas Bellinger return 0; 233e48354ceSNicholas Bellinger } 234e48354ceSNicholas Bellinger 235f760903aSDan Carpenter int iscsit_na_default_erl( 236e48354ceSNicholas Bellinger struct iscsi_node_acl *acl, 237e48354ceSNicholas Bellinger u32 default_erl) 238e48354ceSNicholas Bellinger { 239e48354ceSNicholas Bellinger struct iscsi_node_attrib *a = &acl->node_attrib; 240e48354ceSNicholas Bellinger 241e48354ceSNicholas Bellinger if (default_erl != 0 && default_erl != 1 && default_erl != 2) { 242e48354ceSNicholas Bellinger pr_err("Requested default ERL: %u not 0, 1, or 2\n", 243e48354ceSNicholas Bellinger default_erl); 244e48354ceSNicholas Bellinger return -EINVAL; 245e48354ceSNicholas Bellinger } 246e48354ceSNicholas Bellinger 247e48354ceSNicholas Bellinger a->default_erl = default_erl; 248e48354ceSNicholas Bellinger pr_debug("Set use ERL0 flag to %u for Initiator" 249e48354ceSNicholas Bellinger " Node %s\n", a->default_erl, 250e48354ceSNicholas Bellinger iscsit_na_get_initiatorname(acl)); 251e48354ceSNicholas Bellinger 252e48354ceSNicholas Bellinger return 0; 253e48354ceSNicholas Bellinger } 254