1e48354ceSNicholas Bellinger /******************************************************************************* 2e48354ceSNicholas Bellinger * This file contains iSCSI Target Portal Group related functions. 3e48354ceSNicholas Bellinger * 4e48354ceSNicholas Bellinger * \u00a9 Copyright 2007-2011 RisingTide Systems LLC. 5e48354ceSNicholas Bellinger * 6e48354ceSNicholas Bellinger * Licensed to the Linux Foundation under the General Public License (GPL) version 2. 7e48354ceSNicholas Bellinger * 8e48354ceSNicholas Bellinger * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> 9e48354ceSNicholas Bellinger * 10e48354ceSNicholas Bellinger * This program is free software; you can redistribute it and/or modify 11e48354ceSNicholas Bellinger * it under the terms of the GNU General Public License as published by 12e48354ceSNicholas Bellinger * the Free Software Foundation; either version 2 of the License, or 13e48354ceSNicholas Bellinger * (at your option) any later version. 14e48354ceSNicholas Bellinger * 15e48354ceSNicholas Bellinger * This program is distributed in the hope that it will be useful, 16e48354ceSNicholas Bellinger * but WITHOUT ANY WARRANTY; without even the implied warranty of 17e48354ceSNicholas Bellinger * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18e48354ceSNicholas Bellinger * GNU General Public License for more details. 19e48354ceSNicholas Bellinger ******************************************************************************/ 20e48354ceSNicholas Bellinger 21e48354ceSNicholas Bellinger #include <target/target_core_base.h> 22c4795fb2SChristoph Hellwig #include <target/target_core_fabric.h> 23e48354ceSNicholas Bellinger #include <target/target_core_configfs.h> 24e48354ceSNicholas Bellinger 25e48354ceSNicholas Bellinger #include "iscsi_target_core.h" 26e48354ceSNicholas Bellinger #include "iscsi_target_erl0.h" 27e48354ceSNicholas Bellinger #include "iscsi_target_login.h" 28e48354ceSNicholas Bellinger #include "iscsi_target_nodeattrib.h" 29e48354ceSNicholas Bellinger #include "iscsi_target_tpg.h" 30e48354ceSNicholas Bellinger #include "iscsi_target_util.h" 31e48354ceSNicholas Bellinger #include "iscsi_target.h" 32e48354ceSNicholas Bellinger #include "iscsi_target_parameters.h" 33e48354ceSNicholas Bellinger 34baa4d64bSNicholas Bellinger #include <target/iscsi/iscsi_transport.h> 35baa4d64bSNicholas Bellinger 36e48354ceSNicholas Bellinger struct iscsi_portal_group *iscsit_alloc_portal_group(struct iscsi_tiqn *tiqn, u16 tpgt) 37e48354ceSNicholas Bellinger { 38e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 39e48354ceSNicholas Bellinger 40e48354ceSNicholas Bellinger tpg = kzalloc(sizeof(struct iscsi_portal_group), GFP_KERNEL); 41e48354ceSNicholas Bellinger if (!tpg) { 42e48354ceSNicholas Bellinger pr_err("Unable to allocate struct iscsi_portal_group\n"); 43e48354ceSNicholas Bellinger return NULL; 44e48354ceSNicholas Bellinger } 45e48354ceSNicholas Bellinger 46e48354ceSNicholas Bellinger tpg->tpgt = tpgt; 47e48354ceSNicholas Bellinger tpg->tpg_state = TPG_STATE_FREE; 48e48354ceSNicholas Bellinger tpg->tpg_tiqn = tiqn; 49e48354ceSNicholas Bellinger INIT_LIST_HEAD(&tpg->tpg_gnp_list); 50e48354ceSNicholas Bellinger INIT_LIST_HEAD(&tpg->tpg_list); 51e48354ceSNicholas Bellinger mutex_init(&tpg->tpg_access_lock); 52a91eb7d9SNicholas Bellinger sema_init(&tpg->np_login_sem, 1); 53e48354ceSNicholas Bellinger spin_lock_init(&tpg->tpg_state_lock); 54e48354ceSNicholas Bellinger spin_lock_init(&tpg->tpg_np_lock); 55e48354ceSNicholas Bellinger 56e48354ceSNicholas Bellinger return tpg; 57e48354ceSNicholas Bellinger } 58e48354ceSNicholas Bellinger 59e48354ceSNicholas Bellinger static void iscsit_set_default_tpg_attribs(struct iscsi_portal_group *); 60e48354ceSNicholas Bellinger 61e48354ceSNicholas Bellinger int iscsit_load_discovery_tpg(void) 62e48354ceSNicholas Bellinger { 63e48354ceSNicholas Bellinger struct iscsi_param *param; 64e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 65e48354ceSNicholas Bellinger int ret; 66e48354ceSNicholas Bellinger 67e48354ceSNicholas Bellinger tpg = iscsit_alloc_portal_group(NULL, 1); 68e48354ceSNicholas Bellinger if (!tpg) { 69e48354ceSNicholas Bellinger pr_err("Unable to allocate struct iscsi_portal_group\n"); 70e48354ceSNicholas Bellinger return -1; 71e48354ceSNicholas Bellinger } 72e48354ceSNicholas Bellinger 73e48354ceSNicholas Bellinger ret = core_tpg_register( 74e48354ceSNicholas Bellinger &lio_target_fabric_configfs->tf_ops, 758359cf43SJörn Engel NULL, &tpg->tpg_se_tpg, tpg, 76e48354ceSNicholas Bellinger TRANSPORT_TPG_TYPE_DISCOVERY); 77e48354ceSNicholas Bellinger if (ret < 0) { 78e48354ceSNicholas Bellinger kfree(tpg); 79e48354ceSNicholas Bellinger return -1; 80e48354ceSNicholas Bellinger } 81e48354ceSNicholas Bellinger 82e48354ceSNicholas Bellinger tpg->sid = 1; /* First Assigned LIO Session ID */ 83e48354ceSNicholas Bellinger iscsit_set_default_tpg_attribs(tpg); 84e48354ceSNicholas Bellinger 85e48354ceSNicholas Bellinger if (iscsi_create_default_params(&tpg->param_list) < 0) 86e48354ceSNicholas Bellinger goto out; 87e48354ceSNicholas Bellinger /* 88e48354ceSNicholas Bellinger * By default we disable authentication for discovery sessions, 89e48354ceSNicholas Bellinger * this can be changed with: 90e48354ceSNicholas Bellinger * 91e48354ceSNicholas Bellinger * /sys/kernel/config/target/iscsi/discovery_auth/enforce_discovery_auth 92e48354ceSNicholas Bellinger */ 93e48354ceSNicholas Bellinger param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list); 94e48354ceSNicholas Bellinger if (!param) 95e48354ceSNicholas Bellinger goto out; 96e48354ceSNicholas Bellinger 97e48354ceSNicholas Bellinger if (iscsi_update_param_value(param, "CHAP,None") < 0) 98e48354ceSNicholas Bellinger goto out; 99e48354ceSNicholas Bellinger 100e48354ceSNicholas Bellinger tpg->tpg_attrib.authentication = 0; 101e48354ceSNicholas Bellinger 102e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_state_lock); 103e48354ceSNicholas Bellinger tpg->tpg_state = TPG_STATE_ACTIVE; 104e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 105e48354ceSNicholas Bellinger 106e48354ceSNicholas Bellinger iscsit_global->discovery_tpg = tpg; 107e48354ceSNicholas Bellinger pr_debug("CORE[0] - Allocated Discovery TPG\n"); 108e48354ceSNicholas Bellinger 109e48354ceSNicholas Bellinger return 0; 110e48354ceSNicholas Bellinger out: 111e48354ceSNicholas Bellinger if (tpg->sid == 1) 112e48354ceSNicholas Bellinger core_tpg_deregister(&tpg->tpg_se_tpg); 113e48354ceSNicholas Bellinger kfree(tpg); 114e48354ceSNicholas Bellinger return -1; 115e48354ceSNicholas Bellinger } 116e48354ceSNicholas Bellinger 117e48354ceSNicholas Bellinger void iscsit_release_discovery_tpg(void) 118e48354ceSNicholas Bellinger { 119e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = iscsit_global->discovery_tpg; 120e48354ceSNicholas Bellinger 121e48354ceSNicholas Bellinger if (!tpg) 122e48354ceSNicholas Bellinger return; 123e48354ceSNicholas Bellinger 124e48354ceSNicholas Bellinger core_tpg_deregister(&tpg->tpg_se_tpg); 125e48354ceSNicholas Bellinger 126e48354ceSNicholas Bellinger kfree(tpg); 127e48354ceSNicholas Bellinger iscsit_global->discovery_tpg = NULL; 128e48354ceSNicholas Bellinger } 129e48354ceSNicholas Bellinger 130e48354ceSNicholas Bellinger struct iscsi_portal_group *iscsit_get_tpg_from_np( 131e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn, 132e48354ceSNicholas Bellinger struct iscsi_np *np) 133e48354ceSNicholas Bellinger { 134e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = NULL; 135e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np; 136e48354ceSNicholas Bellinger 137e48354ceSNicholas Bellinger spin_lock(&tiqn->tiqn_tpg_lock); 138e48354ceSNicholas Bellinger list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) { 139e48354ceSNicholas Bellinger 140e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_state_lock); 141e48354ceSNicholas Bellinger if (tpg->tpg_state == TPG_STATE_FREE) { 142e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 143e48354ceSNicholas Bellinger continue; 144e48354ceSNicholas Bellinger } 145e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 146e48354ceSNicholas Bellinger 147e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_np_lock); 148e48354ceSNicholas Bellinger list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) { 149e48354ceSNicholas Bellinger if (tpg_np->tpg_np == np) { 150e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_np_lock); 151e48354ceSNicholas Bellinger spin_unlock(&tiqn->tiqn_tpg_lock); 152e48354ceSNicholas Bellinger return tpg; 153e48354ceSNicholas Bellinger } 154e48354ceSNicholas Bellinger } 155e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_np_lock); 156e48354ceSNicholas Bellinger } 157e48354ceSNicholas Bellinger spin_unlock(&tiqn->tiqn_tpg_lock); 158e48354ceSNicholas Bellinger 159e48354ceSNicholas Bellinger return NULL; 160e48354ceSNicholas Bellinger } 161e48354ceSNicholas Bellinger 162e48354ceSNicholas Bellinger int iscsit_get_tpg( 163e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg) 164e48354ceSNicholas Bellinger { 165e48354ceSNicholas Bellinger int ret; 166e48354ceSNicholas Bellinger 167e48354ceSNicholas Bellinger ret = mutex_lock_interruptible(&tpg->tpg_access_lock); 168e48354ceSNicholas Bellinger return ((ret != 0) || signal_pending(current)) ? -1 : 0; 169e48354ceSNicholas Bellinger } 170e48354ceSNicholas Bellinger 171e48354ceSNicholas Bellinger void iscsit_put_tpg(struct iscsi_portal_group *tpg) 172e48354ceSNicholas Bellinger { 173e48354ceSNicholas Bellinger mutex_unlock(&tpg->tpg_access_lock); 174e48354ceSNicholas Bellinger } 175e48354ceSNicholas Bellinger 176e48354ceSNicholas Bellinger static void iscsit_clear_tpg_np_login_thread( 177e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np, 178a91eb7d9SNicholas Bellinger struct iscsi_portal_group *tpg, 179a91eb7d9SNicholas Bellinger bool shutdown) 180e48354ceSNicholas Bellinger { 181e48354ceSNicholas Bellinger if (!tpg_np->tpg_np) { 182e48354ceSNicholas Bellinger pr_err("struct iscsi_tpg_np->tpg_np is NULL!\n"); 183e48354ceSNicholas Bellinger return; 184e48354ceSNicholas Bellinger } 185e48354ceSNicholas Bellinger 186a91eb7d9SNicholas Bellinger iscsit_reset_np_thread(tpg_np->tpg_np, tpg_np, tpg, shutdown); 187e48354ceSNicholas Bellinger } 188e48354ceSNicholas Bellinger 189e48354ceSNicholas Bellinger void iscsit_clear_tpg_np_login_threads( 190a91eb7d9SNicholas Bellinger struct iscsi_portal_group *tpg, 191a91eb7d9SNicholas Bellinger bool shutdown) 192e48354ceSNicholas Bellinger { 193e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np; 194e48354ceSNicholas Bellinger 195e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_np_lock); 196e48354ceSNicholas Bellinger list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) { 197e48354ceSNicholas Bellinger if (!tpg_np->tpg_np) { 198e48354ceSNicholas Bellinger pr_err("struct iscsi_tpg_np->tpg_np is NULL!\n"); 199e48354ceSNicholas Bellinger continue; 200e48354ceSNicholas Bellinger } 201e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_np_lock); 202a91eb7d9SNicholas Bellinger iscsit_clear_tpg_np_login_thread(tpg_np, tpg, shutdown); 203e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_np_lock); 204e48354ceSNicholas Bellinger } 205e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_np_lock); 206e48354ceSNicholas Bellinger } 207e48354ceSNicholas Bellinger 208e48354ceSNicholas Bellinger void iscsit_tpg_dump_params(struct iscsi_portal_group *tpg) 209e48354ceSNicholas Bellinger { 210e48354ceSNicholas Bellinger iscsi_print_params(tpg->param_list); 211e48354ceSNicholas Bellinger } 212e48354ceSNicholas Bellinger 213e48354ceSNicholas Bellinger static void iscsit_set_default_tpg_attribs(struct iscsi_portal_group *tpg) 214e48354ceSNicholas Bellinger { 215e48354ceSNicholas Bellinger struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; 216e48354ceSNicholas Bellinger 217e48354ceSNicholas Bellinger a->authentication = TA_AUTHENTICATION; 218e48354ceSNicholas Bellinger a->login_timeout = TA_LOGIN_TIMEOUT; 219e48354ceSNicholas Bellinger a->netif_timeout = TA_NETIF_TIMEOUT; 220e48354ceSNicholas Bellinger a->default_cmdsn_depth = TA_DEFAULT_CMDSN_DEPTH; 221e48354ceSNicholas Bellinger a->generate_node_acls = TA_GENERATE_NODE_ACLS; 222e48354ceSNicholas Bellinger a->cache_dynamic_acls = TA_CACHE_DYNAMIC_ACLS; 223e48354ceSNicholas Bellinger a->demo_mode_write_protect = TA_DEMO_MODE_WRITE_PROTECT; 224e48354ceSNicholas Bellinger a->prod_mode_write_protect = TA_PROD_MODE_WRITE_PROTECT; 225e48354ceSNicholas Bellinger } 226e48354ceSNicholas Bellinger 227e48354ceSNicholas Bellinger int iscsit_tpg_add_portal_group(struct iscsi_tiqn *tiqn, struct iscsi_portal_group *tpg) 228e48354ceSNicholas Bellinger { 229e48354ceSNicholas Bellinger if (tpg->tpg_state != TPG_STATE_FREE) { 230e48354ceSNicholas Bellinger pr_err("Unable to add iSCSI Target Portal Group: %d" 231e48354ceSNicholas Bellinger " while not in TPG_STATE_FREE state.\n", tpg->tpgt); 232e48354ceSNicholas Bellinger return -EEXIST; 233e48354ceSNicholas Bellinger } 234e48354ceSNicholas Bellinger iscsit_set_default_tpg_attribs(tpg); 235e48354ceSNicholas Bellinger 236e48354ceSNicholas Bellinger if (iscsi_create_default_params(&tpg->param_list) < 0) 237e48354ceSNicholas Bellinger goto err_out; 238e48354ceSNicholas Bellinger 239e48354ceSNicholas Bellinger ISCSI_TPG_ATTRIB(tpg)->tpg = tpg; 240e48354ceSNicholas Bellinger 241e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_state_lock); 242e48354ceSNicholas Bellinger tpg->tpg_state = TPG_STATE_INACTIVE; 243e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 244e48354ceSNicholas Bellinger 245e48354ceSNicholas Bellinger spin_lock(&tiqn->tiqn_tpg_lock); 246e48354ceSNicholas Bellinger list_add_tail(&tpg->tpg_list, &tiqn->tiqn_tpg_list); 247e48354ceSNicholas Bellinger tiqn->tiqn_ntpgs++; 248e48354ceSNicholas Bellinger pr_debug("CORE[%s]_TPG[%hu] - Added iSCSI Target Portal Group\n", 249e48354ceSNicholas Bellinger tiqn->tiqn, tpg->tpgt); 250e48354ceSNicholas Bellinger spin_unlock(&tiqn->tiqn_tpg_lock); 251e48354ceSNicholas Bellinger 252e48354ceSNicholas Bellinger return 0; 253e48354ceSNicholas Bellinger err_out: 254e48354ceSNicholas Bellinger if (tpg->param_list) { 255e48354ceSNicholas Bellinger iscsi_release_param_list(tpg->param_list); 256e48354ceSNicholas Bellinger tpg->param_list = NULL; 257e48354ceSNicholas Bellinger } 258e48354ceSNicholas Bellinger kfree(tpg); 259e48354ceSNicholas Bellinger return -ENOMEM; 260e48354ceSNicholas Bellinger } 261e48354ceSNicholas Bellinger 262e48354ceSNicholas Bellinger int iscsit_tpg_del_portal_group( 263e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn, 264e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg, 265e48354ceSNicholas Bellinger int force) 266e48354ceSNicholas Bellinger { 267e48354ceSNicholas Bellinger u8 old_state = tpg->tpg_state; 268e48354ceSNicholas Bellinger 269e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_state_lock); 270e48354ceSNicholas Bellinger tpg->tpg_state = TPG_STATE_INACTIVE; 271e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 272e48354ceSNicholas Bellinger 273a91eb7d9SNicholas Bellinger iscsit_clear_tpg_np_login_threads(tpg, true); 274a91eb7d9SNicholas Bellinger 275e48354ceSNicholas Bellinger if (iscsit_release_sessions_for_tpg(tpg, force) < 0) { 276e48354ceSNicholas Bellinger pr_err("Unable to delete iSCSI Target Portal Group:" 277e48354ceSNicholas Bellinger " %hu while active sessions exist, and force=0\n", 278e48354ceSNicholas Bellinger tpg->tpgt); 279e48354ceSNicholas Bellinger tpg->tpg_state = old_state; 280e48354ceSNicholas Bellinger return -EPERM; 281e48354ceSNicholas Bellinger } 282e48354ceSNicholas Bellinger 283e48354ceSNicholas Bellinger core_tpg_clear_object_luns(&tpg->tpg_se_tpg); 284e48354ceSNicholas Bellinger 285e48354ceSNicholas Bellinger if (tpg->param_list) { 286e48354ceSNicholas Bellinger iscsi_release_param_list(tpg->param_list); 287e48354ceSNicholas Bellinger tpg->param_list = NULL; 288e48354ceSNicholas Bellinger } 289e48354ceSNicholas Bellinger 290e48354ceSNicholas Bellinger core_tpg_deregister(&tpg->tpg_se_tpg); 291e48354ceSNicholas Bellinger 292e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_state_lock); 293e48354ceSNicholas Bellinger tpg->tpg_state = TPG_STATE_FREE; 294e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 295e48354ceSNicholas Bellinger 296e48354ceSNicholas Bellinger spin_lock(&tiqn->tiqn_tpg_lock); 297e48354ceSNicholas Bellinger tiqn->tiqn_ntpgs--; 298e48354ceSNicholas Bellinger list_del(&tpg->tpg_list); 299e48354ceSNicholas Bellinger spin_unlock(&tiqn->tiqn_tpg_lock); 300e48354ceSNicholas Bellinger 301e48354ceSNicholas Bellinger pr_debug("CORE[%s]_TPG[%hu] - Deleted iSCSI Target Portal Group\n", 302e48354ceSNicholas Bellinger tiqn->tiqn, tpg->tpgt); 303e48354ceSNicholas Bellinger 304e48354ceSNicholas Bellinger kfree(tpg); 305e48354ceSNicholas Bellinger return 0; 306e48354ceSNicholas Bellinger } 307e48354ceSNicholas Bellinger 308e48354ceSNicholas Bellinger int iscsit_tpg_enable_portal_group(struct iscsi_portal_group *tpg) 309e48354ceSNicholas Bellinger { 310e48354ceSNicholas Bellinger struct iscsi_param *param; 311e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn = tpg->tpg_tiqn; 312617a0c2eSAndy Grover int ret; 313e48354ceSNicholas Bellinger 314e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_state_lock); 315e48354ceSNicholas Bellinger if (tpg->tpg_state == TPG_STATE_ACTIVE) { 316e48354ceSNicholas Bellinger pr_err("iSCSI target portal group: %hu is already" 317e48354ceSNicholas Bellinger " active, ignoring request.\n", tpg->tpgt); 318e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 319e48354ceSNicholas Bellinger return -EINVAL; 320e48354ceSNicholas Bellinger } 321e48354ceSNicholas Bellinger /* 322e48354ceSNicholas Bellinger * Make sure that AuthMethod does not contain None as an option 323e48354ceSNicholas Bellinger * unless explictly disabled. Set the default to CHAP if authentication 324e48354ceSNicholas Bellinger * is enforced (as per default), and remove the NONE option. 325e48354ceSNicholas Bellinger */ 326e48354ceSNicholas Bellinger param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list); 327e48354ceSNicholas Bellinger if (!param) { 328e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 329617a0c2eSAndy Grover return -EINVAL; 330e48354ceSNicholas Bellinger } 331e48354ceSNicholas Bellinger 332e48354ceSNicholas Bellinger if (ISCSI_TPG_ATTRIB(tpg)->authentication) { 333617a0c2eSAndy Grover if (!strcmp(param->value, NONE)) { 334617a0c2eSAndy Grover ret = iscsi_update_param_value(param, CHAP); 335617a0c2eSAndy Grover if (ret) 336617a0c2eSAndy Grover goto err; 337e48354ceSNicholas Bellinger } 338617a0c2eSAndy Grover 339617a0c2eSAndy Grover ret = iscsit_ta_authentication(tpg, 1); 340617a0c2eSAndy Grover if (ret < 0) 341617a0c2eSAndy Grover goto err; 342e48354ceSNicholas Bellinger } 343e48354ceSNicholas Bellinger 344e48354ceSNicholas Bellinger tpg->tpg_state = TPG_STATE_ACTIVE; 345e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 346e48354ceSNicholas Bellinger 347e48354ceSNicholas Bellinger spin_lock(&tiqn->tiqn_tpg_lock); 348e48354ceSNicholas Bellinger tiqn->tiqn_active_tpgs++; 349e48354ceSNicholas Bellinger pr_debug("iSCSI_TPG[%hu] - Enabled iSCSI Target Portal Group\n", 350e48354ceSNicholas Bellinger tpg->tpgt); 351e48354ceSNicholas Bellinger spin_unlock(&tiqn->tiqn_tpg_lock); 352e48354ceSNicholas Bellinger 353e48354ceSNicholas Bellinger return 0; 354617a0c2eSAndy Grover 355617a0c2eSAndy Grover err: 356617a0c2eSAndy Grover spin_unlock(&tpg->tpg_state_lock); 357617a0c2eSAndy Grover return ret; 358e48354ceSNicholas Bellinger } 359e48354ceSNicholas Bellinger 360e48354ceSNicholas Bellinger int iscsit_tpg_disable_portal_group(struct iscsi_portal_group *tpg, int force) 361e48354ceSNicholas Bellinger { 362e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn; 363e48354ceSNicholas Bellinger u8 old_state = tpg->tpg_state; 364e48354ceSNicholas Bellinger 365e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_state_lock); 366e48354ceSNicholas Bellinger if (tpg->tpg_state == TPG_STATE_INACTIVE) { 367e48354ceSNicholas Bellinger pr_err("iSCSI Target Portal Group: %hu is already" 368e48354ceSNicholas Bellinger " inactive, ignoring request.\n", tpg->tpgt); 369e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 370e48354ceSNicholas Bellinger return -EINVAL; 371e48354ceSNicholas Bellinger } 372e48354ceSNicholas Bellinger tpg->tpg_state = TPG_STATE_INACTIVE; 373e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 374e48354ceSNicholas Bellinger 375a91eb7d9SNicholas Bellinger iscsit_clear_tpg_np_login_threads(tpg, false); 376e48354ceSNicholas Bellinger 377e48354ceSNicholas Bellinger if (iscsit_release_sessions_for_tpg(tpg, force) < 0) { 378e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_state_lock); 379e48354ceSNicholas Bellinger tpg->tpg_state = old_state; 380e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 381e48354ceSNicholas Bellinger pr_err("Unable to disable iSCSI Target Portal Group:" 382e48354ceSNicholas Bellinger " %hu while active sessions exist, and force=0\n", 383e48354ceSNicholas Bellinger tpg->tpgt); 384e48354ceSNicholas Bellinger return -EPERM; 385e48354ceSNicholas Bellinger } 386e48354ceSNicholas Bellinger 387e48354ceSNicholas Bellinger tiqn = tpg->tpg_tiqn; 388e48354ceSNicholas Bellinger if (!tiqn || (tpg == iscsit_global->discovery_tpg)) 389e48354ceSNicholas Bellinger return 0; 390e48354ceSNicholas Bellinger 391e48354ceSNicholas Bellinger spin_lock(&tiqn->tiqn_tpg_lock); 392e48354ceSNicholas Bellinger tiqn->tiqn_active_tpgs--; 393e48354ceSNicholas Bellinger pr_debug("iSCSI_TPG[%hu] - Disabled iSCSI Target Portal Group\n", 394e48354ceSNicholas Bellinger tpg->tpgt); 395e48354ceSNicholas Bellinger spin_unlock(&tiqn->tiqn_tpg_lock); 396e48354ceSNicholas Bellinger 397e48354ceSNicholas Bellinger return 0; 398e48354ceSNicholas Bellinger } 399e48354ceSNicholas Bellinger 400e48354ceSNicholas Bellinger struct iscsi_node_attrib *iscsit_tpg_get_node_attrib( 401e48354ceSNicholas Bellinger struct iscsi_session *sess) 402e48354ceSNicholas Bellinger { 403e48354ceSNicholas Bellinger struct se_session *se_sess = sess->se_sess; 404e48354ceSNicholas Bellinger struct se_node_acl *se_nacl = se_sess->se_node_acl; 405e48354ceSNicholas Bellinger struct iscsi_node_acl *acl = container_of(se_nacl, struct iscsi_node_acl, 406e48354ceSNicholas Bellinger se_node_acl); 407e48354ceSNicholas Bellinger 408e48354ceSNicholas Bellinger return &acl->node_attrib; 409e48354ceSNicholas Bellinger } 410e48354ceSNicholas Bellinger 411e48354ceSNicholas Bellinger struct iscsi_tpg_np *iscsit_tpg_locate_child_np( 412e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np, 413e48354ceSNicholas Bellinger int network_transport) 414e48354ceSNicholas Bellinger { 415e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np_child, *tpg_np_child_tmp; 416e48354ceSNicholas Bellinger 417e48354ceSNicholas Bellinger spin_lock(&tpg_np->tpg_np_parent_lock); 418e48354ceSNicholas Bellinger list_for_each_entry_safe(tpg_np_child, tpg_np_child_tmp, 419e48354ceSNicholas Bellinger &tpg_np->tpg_np_parent_list, tpg_np_child_list) { 420e48354ceSNicholas Bellinger if (tpg_np_child->tpg_np->np_network_transport == 421e48354ceSNicholas Bellinger network_transport) { 422e48354ceSNicholas Bellinger spin_unlock(&tpg_np->tpg_np_parent_lock); 423e48354ceSNicholas Bellinger return tpg_np_child; 424e48354ceSNicholas Bellinger } 425e48354ceSNicholas Bellinger } 426e48354ceSNicholas Bellinger spin_unlock(&tpg_np->tpg_np_parent_lock); 427e48354ceSNicholas Bellinger 428e48354ceSNicholas Bellinger return NULL; 429e48354ceSNicholas Bellinger } 430e48354ceSNicholas Bellinger 4316e545935SNicholas Bellinger static bool iscsit_tpg_check_network_portal( 4326e545935SNicholas Bellinger struct iscsi_tiqn *tiqn, 4336e545935SNicholas Bellinger struct __kernel_sockaddr_storage *sockaddr, 4346e545935SNicholas Bellinger int network_transport) 4356e545935SNicholas Bellinger { 4366e545935SNicholas Bellinger struct iscsi_portal_group *tpg; 4376e545935SNicholas Bellinger struct iscsi_tpg_np *tpg_np; 4386e545935SNicholas Bellinger struct iscsi_np *np; 4396e545935SNicholas Bellinger bool match = false; 4406e545935SNicholas Bellinger 4416e545935SNicholas Bellinger spin_lock(&tiqn->tiqn_tpg_lock); 4426e545935SNicholas Bellinger list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) { 4436e545935SNicholas Bellinger 4446e545935SNicholas Bellinger spin_lock(&tpg->tpg_np_lock); 4456e545935SNicholas Bellinger list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) { 4466e545935SNicholas Bellinger np = tpg_np->tpg_np; 4476e545935SNicholas Bellinger 4486e545935SNicholas Bellinger match = iscsit_check_np_match(sockaddr, np, 4496e545935SNicholas Bellinger network_transport); 4506e545935SNicholas Bellinger if (match == true) 4516e545935SNicholas Bellinger break; 4526e545935SNicholas Bellinger } 4536e545935SNicholas Bellinger spin_unlock(&tpg->tpg_np_lock); 4546e545935SNicholas Bellinger } 4556e545935SNicholas Bellinger spin_unlock(&tiqn->tiqn_tpg_lock); 4566e545935SNicholas Bellinger 4576e545935SNicholas Bellinger return match; 4586e545935SNicholas Bellinger } 4596e545935SNicholas Bellinger 460e48354ceSNicholas Bellinger struct iscsi_tpg_np *iscsit_tpg_add_network_portal( 461e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg, 462e48354ceSNicholas Bellinger struct __kernel_sockaddr_storage *sockaddr, 463e48354ceSNicholas Bellinger char *ip_str, 464e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np_parent, 465e48354ceSNicholas Bellinger int network_transport) 466e48354ceSNicholas Bellinger { 467e48354ceSNicholas Bellinger struct iscsi_np *np; 468e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np; 469e48354ceSNicholas Bellinger 4706e545935SNicholas Bellinger if (!tpg_np_parent) { 4716e545935SNicholas Bellinger if (iscsit_tpg_check_network_portal(tpg->tpg_tiqn, sockaddr, 4726e545935SNicholas Bellinger network_transport) == true) { 4736e545935SNicholas Bellinger pr_err("Network Portal: %s already exists on a" 4746e545935SNicholas Bellinger " different TPG on %s\n", ip_str, 4756e545935SNicholas Bellinger tpg->tpg_tiqn->tiqn); 4766e545935SNicholas Bellinger return ERR_PTR(-EEXIST); 4776e545935SNicholas Bellinger } 4786e545935SNicholas Bellinger } 4796e545935SNicholas Bellinger 480e48354ceSNicholas Bellinger tpg_np = kzalloc(sizeof(struct iscsi_tpg_np), GFP_KERNEL); 481e48354ceSNicholas Bellinger if (!tpg_np) { 482e48354ceSNicholas Bellinger pr_err("Unable to allocate memory for" 483e48354ceSNicholas Bellinger " struct iscsi_tpg_np.\n"); 484e48354ceSNicholas Bellinger return ERR_PTR(-ENOMEM); 485e48354ceSNicholas Bellinger } 486e48354ceSNicholas Bellinger 487e48354ceSNicholas Bellinger np = iscsit_add_np(sockaddr, ip_str, network_transport); 488e48354ceSNicholas Bellinger if (IS_ERR(np)) { 489e48354ceSNicholas Bellinger kfree(tpg_np); 490e48354ceSNicholas Bellinger return ERR_CAST(np); 491e48354ceSNicholas Bellinger } 492e48354ceSNicholas Bellinger 493e48354ceSNicholas Bellinger INIT_LIST_HEAD(&tpg_np->tpg_np_list); 494e48354ceSNicholas Bellinger INIT_LIST_HEAD(&tpg_np->tpg_np_child_list); 495e48354ceSNicholas Bellinger INIT_LIST_HEAD(&tpg_np->tpg_np_parent_list); 496e48354ceSNicholas Bellinger spin_lock_init(&tpg_np->tpg_np_parent_lock); 497e48354ceSNicholas Bellinger tpg_np->tpg_np = np; 498e48354ceSNicholas Bellinger tpg_np->tpg = tpg; 499e48354ceSNicholas Bellinger 500e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_np_lock); 501e48354ceSNicholas Bellinger list_add_tail(&tpg_np->tpg_np_list, &tpg->tpg_gnp_list); 502e48354ceSNicholas Bellinger tpg->num_tpg_nps++; 503e48354ceSNicholas Bellinger if (tpg->tpg_tiqn) 504e48354ceSNicholas Bellinger tpg->tpg_tiqn->tiqn_num_tpg_nps++; 505e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_np_lock); 506e48354ceSNicholas Bellinger 507e48354ceSNicholas Bellinger if (tpg_np_parent) { 508e48354ceSNicholas Bellinger tpg_np->tpg_np_parent = tpg_np_parent; 509e48354ceSNicholas Bellinger spin_lock(&tpg_np_parent->tpg_np_parent_lock); 510e48354ceSNicholas Bellinger list_add_tail(&tpg_np->tpg_np_child_list, 511e48354ceSNicholas Bellinger &tpg_np_parent->tpg_np_parent_list); 512e48354ceSNicholas Bellinger spin_unlock(&tpg_np_parent->tpg_np_parent_lock); 513e48354ceSNicholas Bellinger } 514e48354ceSNicholas Bellinger 515e48354ceSNicholas Bellinger pr_debug("CORE[%s] - Added Network Portal: %s:%hu,%hu on %s\n", 516e48354ceSNicholas Bellinger tpg->tpg_tiqn->tiqn, np->np_ip, np->np_port, tpg->tpgt, 517baa4d64bSNicholas Bellinger np->np_transport->name); 518e48354ceSNicholas Bellinger 519e48354ceSNicholas Bellinger return tpg_np; 520e48354ceSNicholas Bellinger } 521e48354ceSNicholas Bellinger 522e48354ceSNicholas Bellinger static int iscsit_tpg_release_np( 523e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np, 524e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg, 525e48354ceSNicholas Bellinger struct iscsi_np *np) 526e48354ceSNicholas Bellinger { 527a91eb7d9SNicholas Bellinger iscsit_clear_tpg_np_login_thread(tpg_np, tpg, true); 528e48354ceSNicholas Bellinger 529e48354ceSNicholas Bellinger pr_debug("CORE[%s] - Removed Network Portal: %s:%hu,%hu on %s\n", 530e48354ceSNicholas Bellinger tpg->tpg_tiqn->tiqn, np->np_ip, np->np_port, tpg->tpgt, 531baa4d64bSNicholas Bellinger np->np_transport->name); 532e48354ceSNicholas Bellinger 533e48354ceSNicholas Bellinger tpg_np->tpg_np = NULL; 534e48354ceSNicholas Bellinger tpg_np->tpg = NULL; 535e48354ceSNicholas Bellinger kfree(tpg_np); 536e48354ceSNicholas Bellinger /* 537e48354ceSNicholas Bellinger * iscsit_del_np() will shutdown struct iscsi_np when last TPG reference is released. 538e48354ceSNicholas Bellinger */ 539e48354ceSNicholas Bellinger return iscsit_del_np(np); 540e48354ceSNicholas Bellinger } 541e48354ceSNicholas Bellinger 542e48354ceSNicholas Bellinger int iscsit_tpg_del_network_portal( 543e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg, 544e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np) 545e48354ceSNicholas Bellinger { 546e48354ceSNicholas Bellinger struct iscsi_np *np; 547e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np_child, *tpg_np_child_tmp; 548e48354ceSNicholas Bellinger int ret = 0; 549e48354ceSNicholas Bellinger 550e48354ceSNicholas Bellinger np = tpg_np->tpg_np; 551e48354ceSNicholas Bellinger if (!np) { 552e48354ceSNicholas Bellinger pr_err("Unable to locate struct iscsi_np from" 553e48354ceSNicholas Bellinger " struct iscsi_tpg_np\n"); 554e48354ceSNicholas Bellinger return -EINVAL; 555e48354ceSNicholas Bellinger } 556e48354ceSNicholas Bellinger 557e48354ceSNicholas Bellinger if (!tpg_np->tpg_np_parent) { 558e48354ceSNicholas Bellinger /* 559e48354ceSNicholas Bellinger * We are the parent tpg network portal. Release all of the 560e48354ceSNicholas Bellinger * child tpg_np's (eg: the non ISCSI_TCP ones) on our parent 561e48354ceSNicholas Bellinger * list first. 562e48354ceSNicholas Bellinger */ 563e48354ceSNicholas Bellinger list_for_each_entry_safe(tpg_np_child, tpg_np_child_tmp, 564e48354ceSNicholas Bellinger &tpg_np->tpg_np_parent_list, 565e48354ceSNicholas Bellinger tpg_np_child_list) { 566e48354ceSNicholas Bellinger ret = iscsit_tpg_del_network_portal(tpg, tpg_np_child); 567e48354ceSNicholas Bellinger if (ret < 0) 568e48354ceSNicholas Bellinger pr_err("iscsit_tpg_del_network_portal()" 569e48354ceSNicholas Bellinger " failed: %d\n", ret); 570e48354ceSNicholas Bellinger } 571e48354ceSNicholas Bellinger } else { 572e48354ceSNicholas Bellinger /* 573e48354ceSNicholas Bellinger * We are not the parent ISCSI_TCP tpg network portal. Release 574e48354ceSNicholas Bellinger * our own network portals from the child list. 575e48354ceSNicholas Bellinger */ 576e48354ceSNicholas Bellinger spin_lock(&tpg_np->tpg_np_parent->tpg_np_parent_lock); 577e48354ceSNicholas Bellinger list_del(&tpg_np->tpg_np_child_list); 578e48354ceSNicholas Bellinger spin_unlock(&tpg_np->tpg_np_parent->tpg_np_parent_lock); 579e48354ceSNicholas Bellinger } 580e48354ceSNicholas Bellinger 581e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_np_lock); 582e48354ceSNicholas Bellinger list_del(&tpg_np->tpg_np_list); 583e48354ceSNicholas Bellinger tpg->num_tpg_nps--; 584e48354ceSNicholas Bellinger if (tpg->tpg_tiqn) 585e48354ceSNicholas Bellinger tpg->tpg_tiqn->tiqn_num_tpg_nps--; 586e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_np_lock); 587e48354ceSNicholas Bellinger 588e48354ceSNicholas Bellinger return iscsit_tpg_release_np(tpg_np, tpg, np); 589e48354ceSNicholas Bellinger } 590e48354ceSNicholas Bellinger 591e48354ceSNicholas Bellinger int iscsit_tpg_set_initiator_node_queue_depth( 592e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg, 593e48354ceSNicholas Bellinger unsigned char *initiatorname, 594e48354ceSNicholas Bellinger u32 queue_depth, 595e48354ceSNicholas Bellinger int force) 596e48354ceSNicholas Bellinger { 597e48354ceSNicholas Bellinger return core_tpg_set_initiator_node_queue_depth(&tpg->tpg_se_tpg, 598e48354ceSNicholas Bellinger initiatorname, queue_depth, force); 599e48354ceSNicholas Bellinger } 600e48354ceSNicholas Bellinger 601e48354ceSNicholas Bellinger int iscsit_ta_authentication(struct iscsi_portal_group *tpg, u32 authentication) 602e48354ceSNicholas Bellinger { 603e48354ceSNicholas Bellinger unsigned char buf1[256], buf2[256], *none = NULL; 604e48354ceSNicholas Bellinger int len; 605e48354ceSNicholas Bellinger struct iscsi_param *param; 606e48354ceSNicholas Bellinger struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; 607e48354ceSNicholas Bellinger 608e48354ceSNicholas Bellinger if ((authentication != 1) && (authentication != 0)) { 609e48354ceSNicholas Bellinger pr_err("Illegal value for authentication parameter:" 610e48354ceSNicholas Bellinger " %u, ignoring request.\n", authentication); 611617a0c2eSAndy Grover return -EINVAL; 612e48354ceSNicholas Bellinger } 613e48354ceSNicholas Bellinger 614e48354ceSNicholas Bellinger memset(buf1, 0, sizeof(buf1)); 615e48354ceSNicholas Bellinger memset(buf2, 0, sizeof(buf2)); 616e48354ceSNicholas Bellinger 617e48354ceSNicholas Bellinger param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list); 618e48354ceSNicholas Bellinger if (!param) 619e48354ceSNicholas Bellinger return -EINVAL; 620e48354ceSNicholas Bellinger 621e48354ceSNicholas Bellinger if (authentication) { 622e48354ceSNicholas Bellinger snprintf(buf1, sizeof(buf1), "%s", param->value); 623e48354ceSNicholas Bellinger none = strstr(buf1, NONE); 624e48354ceSNicholas Bellinger if (!none) 625e48354ceSNicholas Bellinger goto out; 626e48354ceSNicholas Bellinger if (!strncmp(none + 4, ",", 1)) { 627e48354ceSNicholas Bellinger if (!strcmp(buf1, none)) 628e48354ceSNicholas Bellinger sprintf(buf2, "%s", none+5); 629e48354ceSNicholas Bellinger else { 630e48354ceSNicholas Bellinger none--; 631e48354ceSNicholas Bellinger *none = '\0'; 632e48354ceSNicholas Bellinger len = sprintf(buf2, "%s", buf1); 633e48354ceSNicholas Bellinger none += 5; 634e48354ceSNicholas Bellinger sprintf(buf2 + len, "%s", none); 635e48354ceSNicholas Bellinger } 636e48354ceSNicholas Bellinger } else { 637e48354ceSNicholas Bellinger none--; 638e48354ceSNicholas Bellinger *none = '\0'; 639e48354ceSNicholas Bellinger sprintf(buf2, "%s", buf1); 640e48354ceSNicholas Bellinger } 641e48354ceSNicholas Bellinger if (iscsi_update_param_value(param, buf2) < 0) 642e48354ceSNicholas Bellinger return -EINVAL; 643e48354ceSNicholas Bellinger } else { 644e48354ceSNicholas Bellinger snprintf(buf1, sizeof(buf1), "%s", param->value); 645e48354ceSNicholas Bellinger none = strstr(buf1, NONE); 646ee1b1b9cSAndy Grover if (none) 647e48354ceSNicholas Bellinger goto out; 648e48354ceSNicholas Bellinger strncat(buf1, ",", strlen(",")); 649e48354ceSNicholas Bellinger strncat(buf1, NONE, strlen(NONE)); 650e48354ceSNicholas Bellinger if (iscsi_update_param_value(param, buf1) < 0) 651e48354ceSNicholas Bellinger return -EINVAL; 652e48354ceSNicholas Bellinger } 653e48354ceSNicholas Bellinger 654e48354ceSNicholas Bellinger out: 655e48354ceSNicholas Bellinger a->authentication = authentication; 656e48354ceSNicholas Bellinger pr_debug("%s iSCSI Authentication Methods for TPG: %hu.\n", 657e48354ceSNicholas Bellinger a->authentication ? "Enforcing" : "Disabling", tpg->tpgt); 658e48354ceSNicholas Bellinger 659e48354ceSNicholas Bellinger return 0; 660e48354ceSNicholas Bellinger } 661e48354ceSNicholas Bellinger 662e48354ceSNicholas Bellinger int iscsit_ta_login_timeout( 663e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg, 664e48354ceSNicholas Bellinger u32 login_timeout) 665e48354ceSNicholas Bellinger { 666e48354ceSNicholas Bellinger struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; 667e48354ceSNicholas Bellinger 668e48354ceSNicholas Bellinger if (login_timeout > TA_LOGIN_TIMEOUT_MAX) { 669e48354ceSNicholas Bellinger pr_err("Requested Login Timeout %u larger than maximum" 670e48354ceSNicholas Bellinger " %u\n", login_timeout, TA_LOGIN_TIMEOUT_MAX); 671e48354ceSNicholas Bellinger return -EINVAL; 672e48354ceSNicholas Bellinger } else if (login_timeout < TA_LOGIN_TIMEOUT_MIN) { 673e48354ceSNicholas Bellinger pr_err("Requested Logout Timeout %u smaller than" 674e48354ceSNicholas Bellinger " minimum %u\n", login_timeout, TA_LOGIN_TIMEOUT_MIN); 675e48354ceSNicholas Bellinger return -EINVAL; 676e48354ceSNicholas Bellinger } 677e48354ceSNicholas Bellinger 678e48354ceSNicholas Bellinger a->login_timeout = login_timeout; 679e48354ceSNicholas Bellinger pr_debug("Set Logout Timeout to %u for Target Portal Group" 680e48354ceSNicholas Bellinger " %hu\n", a->login_timeout, tpg->tpgt); 681e48354ceSNicholas Bellinger 682e48354ceSNicholas Bellinger return 0; 683e48354ceSNicholas Bellinger } 684e48354ceSNicholas Bellinger 685e48354ceSNicholas Bellinger int iscsit_ta_netif_timeout( 686e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg, 687e48354ceSNicholas Bellinger u32 netif_timeout) 688e48354ceSNicholas Bellinger { 689e48354ceSNicholas Bellinger struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; 690e48354ceSNicholas Bellinger 691e48354ceSNicholas Bellinger if (netif_timeout > TA_NETIF_TIMEOUT_MAX) { 692e48354ceSNicholas Bellinger pr_err("Requested Network Interface Timeout %u larger" 693e48354ceSNicholas Bellinger " than maximum %u\n", netif_timeout, 694e48354ceSNicholas Bellinger TA_NETIF_TIMEOUT_MAX); 695e48354ceSNicholas Bellinger return -EINVAL; 696e48354ceSNicholas Bellinger } else if (netif_timeout < TA_NETIF_TIMEOUT_MIN) { 697e48354ceSNicholas Bellinger pr_err("Requested Network Interface Timeout %u smaller" 698e48354ceSNicholas Bellinger " than minimum %u\n", netif_timeout, 699e48354ceSNicholas Bellinger TA_NETIF_TIMEOUT_MIN); 700e48354ceSNicholas Bellinger return -EINVAL; 701e48354ceSNicholas Bellinger } 702e48354ceSNicholas Bellinger 703e48354ceSNicholas Bellinger a->netif_timeout = netif_timeout; 704e48354ceSNicholas Bellinger pr_debug("Set Network Interface Timeout to %u for" 705e48354ceSNicholas Bellinger " Target Portal Group %hu\n", a->netif_timeout, tpg->tpgt); 706e48354ceSNicholas Bellinger 707e48354ceSNicholas Bellinger return 0; 708e48354ceSNicholas Bellinger } 709e48354ceSNicholas Bellinger 710e48354ceSNicholas Bellinger int iscsit_ta_generate_node_acls( 711e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg, 712e48354ceSNicholas Bellinger u32 flag) 713e48354ceSNicholas Bellinger { 714e48354ceSNicholas Bellinger struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; 715e48354ceSNicholas Bellinger 716e48354ceSNicholas Bellinger if ((flag != 0) && (flag != 1)) { 717e48354ceSNicholas Bellinger pr_err("Illegal value %d\n", flag); 718e48354ceSNicholas Bellinger return -EINVAL; 719e48354ceSNicholas Bellinger } 720e48354ceSNicholas Bellinger 721e48354ceSNicholas Bellinger a->generate_node_acls = flag; 722e48354ceSNicholas Bellinger pr_debug("iSCSI_TPG[%hu] - Generate Initiator Portal Group ACLs: %s\n", 723e48354ceSNicholas Bellinger tpg->tpgt, (a->generate_node_acls) ? "Enabled" : "Disabled"); 724e48354ceSNicholas Bellinger 72538b11baeSNicholas Bellinger if (flag == 1 && a->cache_dynamic_acls == 0) { 72638b11baeSNicholas Bellinger pr_debug("Explicitly setting cache_dynamic_acls=1 when " 72738b11baeSNicholas Bellinger "generate_node_acls=1\n"); 72838b11baeSNicholas Bellinger a->cache_dynamic_acls = 1; 72938b11baeSNicholas Bellinger } 73038b11baeSNicholas Bellinger 731e48354ceSNicholas Bellinger return 0; 732e48354ceSNicholas Bellinger } 733e48354ceSNicholas Bellinger 734e48354ceSNicholas Bellinger int iscsit_ta_default_cmdsn_depth( 735e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg, 736e48354ceSNicholas Bellinger u32 tcq_depth) 737e48354ceSNicholas Bellinger { 738e48354ceSNicholas Bellinger struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; 739e48354ceSNicholas Bellinger 740e48354ceSNicholas Bellinger if (tcq_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) { 741e48354ceSNicholas Bellinger pr_err("Requested Default Queue Depth: %u larger" 742e48354ceSNicholas Bellinger " than maximum %u\n", tcq_depth, 743e48354ceSNicholas Bellinger TA_DEFAULT_CMDSN_DEPTH_MAX); 744e48354ceSNicholas Bellinger return -EINVAL; 745e48354ceSNicholas Bellinger } else if (tcq_depth < TA_DEFAULT_CMDSN_DEPTH_MIN) { 746e48354ceSNicholas Bellinger pr_err("Requested Default Queue Depth: %u smaller" 747e48354ceSNicholas Bellinger " than minimum %u\n", tcq_depth, 748e48354ceSNicholas Bellinger TA_DEFAULT_CMDSN_DEPTH_MIN); 749e48354ceSNicholas Bellinger return -EINVAL; 750e48354ceSNicholas Bellinger } 751e48354ceSNicholas Bellinger 752e48354ceSNicholas Bellinger a->default_cmdsn_depth = tcq_depth; 753e48354ceSNicholas Bellinger pr_debug("iSCSI_TPG[%hu] - Set Default CmdSN TCQ Depth to %u\n", 754e48354ceSNicholas Bellinger tpg->tpgt, a->default_cmdsn_depth); 755e48354ceSNicholas Bellinger 756e48354ceSNicholas Bellinger return 0; 757e48354ceSNicholas Bellinger } 758e48354ceSNicholas Bellinger 759e48354ceSNicholas Bellinger int iscsit_ta_cache_dynamic_acls( 760e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg, 761e48354ceSNicholas Bellinger u32 flag) 762e48354ceSNicholas Bellinger { 763e48354ceSNicholas Bellinger struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; 764e48354ceSNicholas Bellinger 765e48354ceSNicholas Bellinger if ((flag != 0) && (flag != 1)) { 766e48354ceSNicholas Bellinger pr_err("Illegal value %d\n", flag); 767e48354ceSNicholas Bellinger return -EINVAL; 768e48354ceSNicholas Bellinger } 769e48354ceSNicholas Bellinger 77038b11baeSNicholas Bellinger if (a->generate_node_acls == 1 && flag == 0) { 77138b11baeSNicholas Bellinger pr_debug("Skipping cache_dynamic_acls=0 when" 77238b11baeSNicholas Bellinger " generate_node_acls=1\n"); 77338b11baeSNicholas Bellinger return 0; 77438b11baeSNicholas Bellinger } 77538b11baeSNicholas Bellinger 776e48354ceSNicholas Bellinger a->cache_dynamic_acls = flag; 777e48354ceSNicholas Bellinger pr_debug("iSCSI_TPG[%hu] - Cache Dynamic Initiator Portal Group" 778e48354ceSNicholas Bellinger " ACLs %s\n", tpg->tpgt, (a->cache_dynamic_acls) ? 779e48354ceSNicholas Bellinger "Enabled" : "Disabled"); 780e48354ceSNicholas Bellinger 781e48354ceSNicholas Bellinger return 0; 782e48354ceSNicholas Bellinger } 783e48354ceSNicholas Bellinger 784e48354ceSNicholas Bellinger int iscsit_ta_demo_mode_write_protect( 785e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg, 786e48354ceSNicholas Bellinger u32 flag) 787e48354ceSNicholas Bellinger { 788e48354ceSNicholas Bellinger struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; 789e48354ceSNicholas Bellinger 790e48354ceSNicholas Bellinger if ((flag != 0) && (flag != 1)) { 791e48354ceSNicholas Bellinger pr_err("Illegal value %d\n", flag); 792e48354ceSNicholas Bellinger return -EINVAL; 793e48354ceSNicholas Bellinger } 794e48354ceSNicholas Bellinger 795e48354ceSNicholas Bellinger a->demo_mode_write_protect = flag; 796e48354ceSNicholas Bellinger pr_debug("iSCSI_TPG[%hu] - Demo Mode Write Protect bit: %s\n", 797e48354ceSNicholas Bellinger tpg->tpgt, (a->demo_mode_write_protect) ? "ON" : "OFF"); 798e48354ceSNicholas Bellinger 799e48354ceSNicholas Bellinger return 0; 800e48354ceSNicholas Bellinger } 801e48354ceSNicholas Bellinger 802e48354ceSNicholas Bellinger int iscsit_ta_prod_mode_write_protect( 803e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg, 804e48354ceSNicholas Bellinger u32 flag) 805e48354ceSNicholas Bellinger { 806e48354ceSNicholas Bellinger struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; 807e48354ceSNicholas Bellinger 808e48354ceSNicholas Bellinger if ((flag != 0) && (flag != 1)) { 809e48354ceSNicholas Bellinger pr_err("Illegal value %d\n", flag); 810e48354ceSNicholas Bellinger return -EINVAL; 811e48354ceSNicholas Bellinger } 812e48354ceSNicholas Bellinger 813e48354ceSNicholas Bellinger a->prod_mode_write_protect = flag; 814e48354ceSNicholas Bellinger pr_debug("iSCSI_TPG[%hu] - Production Mode Write Protect bit:" 815e48354ceSNicholas Bellinger " %s\n", tpg->tpgt, (a->prod_mode_write_protect) ? 816e48354ceSNicholas Bellinger "ON" : "OFF"); 817e48354ceSNicholas Bellinger 818e48354ceSNicholas Bellinger return 0; 819e48354ceSNicholas Bellinger } 820