Adding support for MOXA ART SoC. Testing port of linux-2.6.32.60-moxart.
[linux-3.6.7-moxart.git] / drivers / target / iscsi / iscsi_target_tpg.c
blobde9ea32b61046287eedacbc4c97c5368d5964217
1 /*******************************************************************************
2 * This file contains iSCSI Target Portal Group related functions.
4 * \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
6 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
8 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 ******************************************************************************/
21 #include <target/target_core_base.h>
22 #include <target/target_core_fabric.h>
23 #include <target/target_core_configfs.h>
25 #include "iscsi_target_core.h"
26 #include "iscsi_target_erl0.h"
27 #include "iscsi_target_login.h"
28 #include "iscsi_target_nodeattrib.h"
29 #include "iscsi_target_tpg.h"
30 #include "iscsi_target_util.h"
31 #include "iscsi_target.h"
32 #include "iscsi_target_parameters.h"
34 struct iscsi_portal_group *iscsit_alloc_portal_group(struct iscsi_tiqn *tiqn, u16 tpgt)
36 struct iscsi_portal_group *tpg;
38 tpg = kzalloc(sizeof(struct iscsi_portal_group), GFP_KERNEL);
39 if (!tpg) {
40 pr_err("Unable to allocate struct iscsi_portal_group\n");
41 return NULL;
44 tpg->tpgt = tpgt;
45 tpg->tpg_state = TPG_STATE_FREE;
46 tpg->tpg_tiqn = tiqn;
47 INIT_LIST_HEAD(&tpg->tpg_gnp_list);
48 INIT_LIST_HEAD(&tpg->tpg_list);
49 mutex_init(&tpg->tpg_access_lock);
50 mutex_init(&tpg->np_login_lock);
51 spin_lock_init(&tpg->tpg_state_lock);
52 spin_lock_init(&tpg->tpg_np_lock);
54 return tpg;
57 static void iscsit_set_default_tpg_attribs(struct iscsi_portal_group *);
59 int iscsit_load_discovery_tpg(void)
61 struct iscsi_param *param;
62 struct iscsi_portal_group *tpg;
63 int ret;
65 tpg = iscsit_alloc_portal_group(NULL, 1);
66 if (!tpg) {
67 pr_err("Unable to allocate struct iscsi_portal_group\n");
68 return -1;
71 ret = core_tpg_register(
72 &lio_target_fabric_configfs->tf_ops,
73 NULL, &tpg->tpg_se_tpg, tpg,
74 TRANSPORT_TPG_TYPE_DISCOVERY);
75 if (ret < 0) {
76 kfree(tpg);
77 return -1;
80 tpg->sid = 1; /* First Assigned LIO Session ID */
81 iscsit_set_default_tpg_attribs(tpg);
83 if (iscsi_create_default_params(&tpg->param_list) < 0)
84 goto out;
86 * By default we disable authentication for discovery sessions,
87 * this can be changed with:
89 * /sys/kernel/config/target/iscsi/discovery_auth/enforce_discovery_auth
91 param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list);
92 if (!param)
93 goto out;
95 if (iscsi_update_param_value(param, "CHAP,None") < 0)
96 goto out;
98 tpg->tpg_attrib.authentication = 0;
100 spin_lock(&tpg->tpg_state_lock);
101 tpg->tpg_state = TPG_STATE_ACTIVE;
102 spin_unlock(&tpg->tpg_state_lock);
104 iscsit_global->discovery_tpg = tpg;
105 pr_debug("CORE[0] - Allocated Discovery TPG\n");
107 return 0;
108 out:
109 if (tpg->sid == 1)
110 core_tpg_deregister(&tpg->tpg_se_tpg);
111 kfree(tpg);
112 return -1;
115 void iscsit_release_discovery_tpg(void)
117 struct iscsi_portal_group *tpg = iscsit_global->discovery_tpg;
119 if (!tpg)
120 return;
122 core_tpg_deregister(&tpg->tpg_se_tpg);
124 kfree(tpg);
125 iscsit_global->discovery_tpg = NULL;
128 struct iscsi_portal_group *iscsit_get_tpg_from_np(
129 struct iscsi_tiqn *tiqn,
130 struct iscsi_np *np)
132 struct iscsi_portal_group *tpg = NULL;
133 struct iscsi_tpg_np *tpg_np;
135 spin_lock(&tiqn->tiqn_tpg_lock);
136 list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) {
138 spin_lock(&tpg->tpg_state_lock);
139 if (tpg->tpg_state == TPG_STATE_FREE) {
140 spin_unlock(&tpg->tpg_state_lock);
141 continue;
143 spin_unlock(&tpg->tpg_state_lock);
145 spin_lock(&tpg->tpg_np_lock);
146 list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) {
147 if (tpg_np->tpg_np == np) {
148 spin_unlock(&tpg->tpg_np_lock);
149 spin_unlock(&tiqn->tiqn_tpg_lock);
150 return tpg;
153 spin_unlock(&tpg->tpg_np_lock);
155 spin_unlock(&tiqn->tiqn_tpg_lock);
157 return NULL;
160 int iscsit_get_tpg(
161 struct iscsi_portal_group *tpg)
163 int ret;
165 ret = mutex_lock_interruptible(&tpg->tpg_access_lock);
166 return ((ret != 0) || signal_pending(current)) ? -1 : 0;
169 void iscsit_put_tpg(struct iscsi_portal_group *tpg)
171 mutex_unlock(&tpg->tpg_access_lock);
174 static void iscsit_clear_tpg_np_login_thread(
175 struct iscsi_tpg_np *tpg_np,
176 struct iscsi_portal_group *tpg)
178 if (!tpg_np->tpg_np) {
179 pr_err("struct iscsi_tpg_np->tpg_np is NULL!\n");
180 return;
183 iscsit_reset_np_thread(tpg_np->tpg_np, tpg_np, tpg);
186 void iscsit_clear_tpg_np_login_threads(
187 struct iscsi_portal_group *tpg)
189 struct iscsi_tpg_np *tpg_np;
191 spin_lock(&tpg->tpg_np_lock);
192 list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) {
193 if (!tpg_np->tpg_np) {
194 pr_err("struct iscsi_tpg_np->tpg_np is NULL!\n");
195 continue;
197 spin_unlock(&tpg->tpg_np_lock);
198 iscsit_clear_tpg_np_login_thread(tpg_np, tpg);
199 spin_lock(&tpg->tpg_np_lock);
201 spin_unlock(&tpg->tpg_np_lock);
204 void iscsit_tpg_dump_params(struct iscsi_portal_group *tpg)
206 iscsi_print_params(tpg->param_list);
209 static void iscsit_set_default_tpg_attribs(struct iscsi_portal_group *tpg)
211 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
213 a->authentication = TA_AUTHENTICATION;
214 a->login_timeout = TA_LOGIN_TIMEOUT;
215 a->netif_timeout = TA_NETIF_TIMEOUT;
216 a->default_cmdsn_depth = TA_DEFAULT_CMDSN_DEPTH;
217 a->generate_node_acls = TA_GENERATE_NODE_ACLS;
218 a->cache_dynamic_acls = TA_CACHE_DYNAMIC_ACLS;
219 a->demo_mode_write_protect = TA_DEMO_MODE_WRITE_PROTECT;
220 a->prod_mode_write_protect = TA_PROD_MODE_WRITE_PROTECT;
223 int iscsit_tpg_add_portal_group(struct iscsi_tiqn *tiqn, struct iscsi_portal_group *tpg)
225 if (tpg->tpg_state != TPG_STATE_FREE) {
226 pr_err("Unable to add iSCSI Target Portal Group: %d"
227 " while not in TPG_STATE_FREE state.\n", tpg->tpgt);
228 return -EEXIST;
230 iscsit_set_default_tpg_attribs(tpg);
232 if (iscsi_create_default_params(&tpg->param_list) < 0)
233 goto err_out;
235 ISCSI_TPG_ATTRIB(tpg)->tpg = tpg;
237 spin_lock(&tpg->tpg_state_lock);
238 tpg->tpg_state = TPG_STATE_INACTIVE;
239 spin_unlock(&tpg->tpg_state_lock);
241 spin_lock(&tiqn->tiqn_tpg_lock);
242 list_add_tail(&tpg->tpg_list, &tiqn->tiqn_tpg_list);
243 tiqn->tiqn_ntpgs++;
244 pr_debug("CORE[%s]_TPG[%hu] - Added iSCSI Target Portal Group\n",
245 tiqn->tiqn, tpg->tpgt);
246 spin_unlock(&tiqn->tiqn_tpg_lock);
248 return 0;
249 err_out:
250 if (tpg->param_list) {
251 iscsi_release_param_list(tpg->param_list);
252 tpg->param_list = NULL;
254 kfree(tpg);
255 return -ENOMEM;
258 int iscsit_tpg_del_portal_group(
259 struct iscsi_tiqn *tiqn,
260 struct iscsi_portal_group *tpg,
261 int force)
263 u8 old_state = tpg->tpg_state;
265 spin_lock(&tpg->tpg_state_lock);
266 tpg->tpg_state = TPG_STATE_INACTIVE;
267 spin_unlock(&tpg->tpg_state_lock);
269 if (iscsit_release_sessions_for_tpg(tpg, force) < 0) {
270 pr_err("Unable to delete iSCSI Target Portal Group:"
271 " %hu while active sessions exist, and force=0\n",
272 tpg->tpgt);
273 tpg->tpg_state = old_state;
274 return -EPERM;
277 core_tpg_clear_object_luns(&tpg->tpg_se_tpg);
279 if (tpg->param_list) {
280 iscsi_release_param_list(tpg->param_list);
281 tpg->param_list = NULL;
284 core_tpg_deregister(&tpg->tpg_se_tpg);
286 spin_lock(&tpg->tpg_state_lock);
287 tpg->tpg_state = TPG_STATE_FREE;
288 spin_unlock(&tpg->tpg_state_lock);
290 spin_lock(&tiqn->tiqn_tpg_lock);
291 tiqn->tiqn_ntpgs--;
292 list_del(&tpg->tpg_list);
293 spin_unlock(&tiqn->tiqn_tpg_lock);
295 pr_debug("CORE[%s]_TPG[%hu] - Deleted iSCSI Target Portal Group\n",
296 tiqn->tiqn, tpg->tpgt);
298 kfree(tpg);
299 return 0;
302 int iscsit_tpg_enable_portal_group(struct iscsi_portal_group *tpg)
304 struct iscsi_param *param;
305 struct iscsi_tiqn *tiqn = tpg->tpg_tiqn;
306 int ret;
308 spin_lock(&tpg->tpg_state_lock);
309 if (tpg->tpg_state == TPG_STATE_ACTIVE) {
310 pr_err("iSCSI target portal group: %hu is already"
311 " active, ignoring request.\n", tpg->tpgt);
312 spin_unlock(&tpg->tpg_state_lock);
313 return -EINVAL;
316 * Make sure that AuthMethod does not contain None as an option
317 * unless explictly disabled. Set the default to CHAP if authentication
318 * is enforced (as per default), and remove the NONE option.
320 param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list);
321 if (!param) {
322 spin_unlock(&tpg->tpg_state_lock);
323 return -EINVAL;
326 if (ISCSI_TPG_ATTRIB(tpg)->authentication) {
327 if (!strcmp(param->value, NONE)) {
328 ret = iscsi_update_param_value(param, CHAP);
329 if (ret)
330 goto err;
333 ret = iscsit_ta_authentication(tpg, 1);
334 if (ret < 0)
335 goto err;
338 tpg->tpg_state = TPG_STATE_ACTIVE;
339 spin_unlock(&tpg->tpg_state_lock);
341 spin_lock(&tiqn->tiqn_tpg_lock);
342 tiqn->tiqn_active_tpgs++;
343 pr_debug("iSCSI_TPG[%hu] - Enabled iSCSI Target Portal Group\n",
344 tpg->tpgt);
345 spin_unlock(&tiqn->tiqn_tpg_lock);
347 return 0;
349 err:
350 spin_unlock(&tpg->tpg_state_lock);
351 return ret;
354 int iscsit_tpg_disable_portal_group(struct iscsi_portal_group *tpg, int force)
356 struct iscsi_tiqn *tiqn;
357 u8 old_state = tpg->tpg_state;
359 spin_lock(&tpg->tpg_state_lock);
360 if (tpg->tpg_state == TPG_STATE_INACTIVE) {
361 pr_err("iSCSI Target Portal Group: %hu is already"
362 " inactive, ignoring request.\n", tpg->tpgt);
363 spin_unlock(&tpg->tpg_state_lock);
364 return -EINVAL;
366 tpg->tpg_state = TPG_STATE_INACTIVE;
367 spin_unlock(&tpg->tpg_state_lock);
369 iscsit_clear_tpg_np_login_threads(tpg);
371 if (iscsit_release_sessions_for_tpg(tpg, force) < 0) {
372 spin_lock(&tpg->tpg_state_lock);
373 tpg->tpg_state = old_state;
374 spin_unlock(&tpg->tpg_state_lock);
375 pr_err("Unable to disable iSCSI Target Portal Group:"
376 " %hu while active sessions exist, and force=0\n",
377 tpg->tpgt);
378 return -EPERM;
381 tiqn = tpg->tpg_tiqn;
382 if (!tiqn || (tpg == iscsit_global->discovery_tpg))
383 return 0;
385 spin_lock(&tiqn->tiqn_tpg_lock);
386 tiqn->tiqn_active_tpgs--;
387 pr_debug("iSCSI_TPG[%hu] - Disabled iSCSI Target Portal Group\n",
388 tpg->tpgt);
389 spin_unlock(&tiqn->tiqn_tpg_lock);
391 return 0;
394 struct iscsi_node_attrib *iscsit_tpg_get_node_attrib(
395 struct iscsi_session *sess)
397 struct se_session *se_sess = sess->se_sess;
398 struct se_node_acl *se_nacl = se_sess->se_node_acl;
399 struct iscsi_node_acl *acl = container_of(se_nacl, struct iscsi_node_acl,
400 se_node_acl);
402 return &acl->node_attrib;
405 struct iscsi_tpg_np *iscsit_tpg_locate_child_np(
406 struct iscsi_tpg_np *tpg_np,
407 int network_transport)
409 struct iscsi_tpg_np *tpg_np_child, *tpg_np_child_tmp;
411 spin_lock(&tpg_np->tpg_np_parent_lock);
412 list_for_each_entry_safe(tpg_np_child, tpg_np_child_tmp,
413 &tpg_np->tpg_np_parent_list, tpg_np_child_list) {
414 if (tpg_np_child->tpg_np->np_network_transport ==
415 network_transport) {
416 spin_unlock(&tpg_np->tpg_np_parent_lock);
417 return tpg_np_child;
420 spin_unlock(&tpg_np->tpg_np_parent_lock);
422 return NULL;
425 struct iscsi_tpg_np *iscsit_tpg_add_network_portal(
426 struct iscsi_portal_group *tpg,
427 struct __kernel_sockaddr_storage *sockaddr,
428 char *ip_str,
429 struct iscsi_tpg_np *tpg_np_parent,
430 int network_transport)
432 struct iscsi_np *np;
433 struct iscsi_tpg_np *tpg_np;
435 tpg_np = kzalloc(sizeof(struct iscsi_tpg_np), GFP_KERNEL);
436 if (!tpg_np) {
437 pr_err("Unable to allocate memory for"
438 " struct iscsi_tpg_np.\n");
439 return ERR_PTR(-ENOMEM);
442 np = iscsit_add_np(sockaddr, ip_str, network_transport);
443 if (IS_ERR(np)) {
444 kfree(tpg_np);
445 return ERR_CAST(np);
448 INIT_LIST_HEAD(&tpg_np->tpg_np_list);
449 INIT_LIST_HEAD(&tpg_np->tpg_np_child_list);
450 INIT_LIST_HEAD(&tpg_np->tpg_np_parent_list);
451 spin_lock_init(&tpg_np->tpg_np_parent_lock);
452 tpg_np->tpg_np = np;
453 tpg_np->tpg = tpg;
455 spin_lock(&tpg->tpg_np_lock);
456 list_add_tail(&tpg_np->tpg_np_list, &tpg->tpg_gnp_list);
457 tpg->num_tpg_nps++;
458 if (tpg->tpg_tiqn)
459 tpg->tpg_tiqn->tiqn_num_tpg_nps++;
460 spin_unlock(&tpg->tpg_np_lock);
462 if (tpg_np_parent) {
463 tpg_np->tpg_np_parent = tpg_np_parent;
464 spin_lock(&tpg_np_parent->tpg_np_parent_lock);
465 list_add_tail(&tpg_np->tpg_np_child_list,
466 &tpg_np_parent->tpg_np_parent_list);
467 spin_unlock(&tpg_np_parent->tpg_np_parent_lock);
470 pr_debug("CORE[%s] - Added Network Portal: %s:%hu,%hu on %s\n",
471 tpg->tpg_tiqn->tiqn, np->np_ip, np->np_port, tpg->tpgt,
472 (np->np_network_transport == ISCSI_TCP) ? "TCP" : "SCTP");
474 return tpg_np;
477 static int iscsit_tpg_release_np(
478 struct iscsi_tpg_np *tpg_np,
479 struct iscsi_portal_group *tpg,
480 struct iscsi_np *np)
482 iscsit_clear_tpg_np_login_thread(tpg_np, tpg);
484 pr_debug("CORE[%s] - Removed Network Portal: %s:%hu,%hu on %s\n",
485 tpg->tpg_tiqn->tiqn, np->np_ip, np->np_port, tpg->tpgt,
486 (np->np_network_transport == ISCSI_TCP) ? "TCP" : "SCTP");
488 tpg_np->tpg_np = NULL;
489 tpg_np->tpg = NULL;
490 kfree(tpg_np);
492 * iscsit_del_np() will shutdown struct iscsi_np when last TPG reference is released.
494 return iscsit_del_np(np);
497 int iscsit_tpg_del_network_portal(
498 struct iscsi_portal_group *tpg,
499 struct iscsi_tpg_np *tpg_np)
501 struct iscsi_np *np;
502 struct iscsi_tpg_np *tpg_np_child, *tpg_np_child_tmp;
503 int ret = 0;
505 np = tpg_np->tpg_np;
506 if (!np) {
507 pr_err("Unable to locate struct iscsi_np from"
508 " struct iscsi_tpg_np\n");
509 return -EINVAL;
512 if (!tpg_np->tpg_np_parent) {
514 * We are the parent tpg network portal. Release all of the
515 * child tpg_np's (eg: the non ISCSI_TCP ones) on our parent
516 * list first.
518 list_for_each_entry_safe(tpg_np_child, tpg_np_child_tmp,
519 &tpg_np->tpg_np_parent_list,
520 tpg_np_child_list) {
521 ret = iscsit_tpg_del_network_portal(tpg, tpg_np_child);
522 if (ret < 0)
523 pr_err("iscsit_tpg_del_network_portal()"
524 " failed: %d\n", ret);
526 } else {
528 * We are not the parent ISCSI_TCP tpg network portal. Release
529 * our own network portals from the child list.
531 spin_lock(&tpg_np->tpg_np_parent->tpg_np_parent_lock);
532 list_del(&tpg_np->tpg_np_child_list);
533 spin_unlock(&tpg_np->tpg_np_parent->tpg_np_parent_lock);
536 spin_lock(&tpg->tpg_np_lock);
537 list_del(&tpg_np->tpg_np_list);
538 tpg->num_tpg_nps--;
539 if (tpg->tpg_tiqn)
540 tpg->tpg_tiqn->tiqn_num_tpg_nps--;
541 spin_unlock(&tpg->tpg_np_lock);
543 return iscsit_tpg_release_np(tpg_np, tpg, np);
546 int iscsit_tpg_set_initiator_node_queue_depth(
547 struct iscsi_portal_group *tpg,
548 unsigned char *initiatorname,
549 u32 queue_depth,
550 int force)
552 return core_tpg_set_initiator_node_queue_depth(&tpg->tpg_se_tpg,
553 initiatorname, queue_depth, force);
556 int iscsit_ta_authentication(struct iscsi_portal_group *tpg, u32 authentication)
558 unsigned char buf1[256], buf2[256], *none = NULL;
559 int len;
560 struct iscsi_param *param;
561 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
563 if ((authentication != 1) && (authentication != 0)) {
564 pr_err("Illegal value for authentication parameter:"
565 " %u, ignoring request.\n", authentication);
566 return -EINVAL;
569 memset(buf1, 0, sizeof(buf1));
570 memset(buf2, 0, sizeof(buf2));
572 param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list);
573 if (!param)
574 return -EINVAL;
576 if (authentication) {
577 snprintf(buf1, sizeof(buf1), "%s", param->value);
578 none = strstr(buf1, NONE);
579 if (!none)
580 goto out;
581 if (!strncmp(none + 4, ",", 1)) {
582 if (!strcmp(buf1, none))
583 sprintf(buf2, "%s", none+5);
584 else {
585 none--;
586 *none = '\0';
587 len = sprintf(buf2, "%s", buf1);
588 none += 5;
589 sprintf(buf2 + len, "%s", none);
591 } else {
592 none--;
593 *none = '\0';
594 sprintf(buf2, "%s", buf1);
596 if (iscsi_update_param_value(param, buf2) < 0)
597 return -EINVAL;
598 } else {
599 snprintf(buf1, sizeof(buf1), "%s", param->value);
600 none = strstr(buf1, NONE);
601 if (none)
602 goto out;
603 strncat(buf1, ",", strlen(","));
604 strncat(buf1, NONE, strlen(NONE));
605 if (iscsi_update_param_value(param, buf1) < 0)
606 return -EINVAL;
609 out:
610 a->authentication = authentication;
611 pr_debug("%s iSCSI Authentication Methods for TPG: %hu.\n",
612 a->authentication ? "Enforcing" : "Disabling", tpg->tpgt);
614 return 0;
617 int iscsit_ta_login_timeout(
618 struct iscsi_portal_group *tpg,
619 u32 login_timeout)
621 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
623 if (login_timeout > TA_LOGIN_TIMEOUT_MAX) {
624 pr_err("Requested Login Timeout %u larger than maximum"
625 " %u\n", login_timeout, TA_LOGIN_TIMEOUT_MAX);
626 return -EINVAL;
627 } else if (login_timeout < TA_LOGIN_TIMEOUT_MIN) {
628 pr_err("Requested Logout Timeout %u smaller than"
629 " minimum %u\n", login_timeout, TA_LOGIN_TIMEOUT_MIN);
630 return -EINVAL;
633 a->login_timeout = login_timeout;
634 pr_debug("Set Logout Timeout to %u for Target Portal Group"
635 " %hu\n", a->login_timeout, tpg->tpgt);
637 return 0;
640 int iscsit_ta_netif_timeout(
641 struct iscsi_portal_group *tpg,
642 u32 netif_timeout)
644 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
646 if (netif_timeout > TA_NETIF_TIMEOUT_MAX) {
647 pr_err("Requested Network Interface Timeout %u larger"
648 " than maximum %u\n", netif_timeout,
649 TA_NETIF_TIMEOUT_MAX);
650 return -EINVAL;
651 } else if (netif_timeout < TA_NETIF_TIMEOUT_MIN) {
652 pr_err("Requested Network Interface Timeout %u smaller"
653 " than minimum %u\n", netif_timeout,
654 TA_NETIF_TIMEOUT_MIN);
655 return -EINVAL;
658 a->netif_timeout = netif_timeout;
659 pr_debug("Set Network Interface Timeout to %u for"
660 " Target Portal Group %hu\n", a->netif_timeout, tpg->tpgt);
662 return 0;
665 int iscsit_ta_generate_node_acls(
666 struct iscsi_portal_group *tpg,
667 u32 flag)
669 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
671 if ((flag != 0) && (flag != 1)) {
672 pr_err("Illegal value %d\n", flag);
673 return -EINVAL;
676 a->generate_node_acls = flag;
677 pr_debug("iSCSI_TPG[%hu] - Generate Initiator Portal Group ACLs: %s\n",
678 tpg->tpgt, (a->generate_node_acls) ? "Enabled" : "Disabled");
680 if (flag == 1 && a->cache_dynamic_acls == 0) {
681 pr_debug("Explicitly setting cache_dynamic_acls=1 when "
682 "generate_node_acls=1\n");
683 a->cache_dynamic_acls = 1;
686 return 0;
689 int iscsit_ta_default_cmdsn_depth(
690 struct iscsi_portal_group *tpg,
691 u32 tcq_depth)
693 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
695 if (tcq_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
696 pr_err("Requested Default Queue Depth: %u larger"
697 " than maximum %u\n", tcq_depth,
698 TA_DEFAULT_CMDSN_DEPTH_MAX);
699 return -EINVAL;
700 } else if (tcq_depth < TA_DEFAULT_CMDSN_DEPTH_MIN) {
701 pr_err("Requested Default Queue Depth: %u smaller"
702 " than minimum %u\n", tcq_depth,
703 TA_DEFAULT_CMDSN_DEPTH_MIN);
704 return -EINVAL;
707 a->default_cmdsn_depth = tcq_depth;
708 pr_debug("iSCSI_TPG[%hu] - Set Default CmdSN TCQ Depth to %u\n",
709 tpg->tpgt, a->default_cmdsn_depth);
711 return 0;
714 int iscsit_ta_cache_dynamic_acls(
715 struct iscsi_portal_group *tpg,
716 u32 flag)
718 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
720 if ((flag != 0) && (flag != 1)) {
721 pr_err("Illegal value %d\n", flag);
722 return -EINVAL;
725 if (a->generate_node_acls == 1 && flag == 0) {
726 pr_debug("Skipping cache_dynamic_acls=0 when"
727 " generate_node_acls=1\n");
728 return 0;
731 a->cache_dynamic_acls = flag;
732 pr_debug("iSCSI_TPG[%hu] - Cache Dynamic Initiator Portal Group"
733 " ACLs %s\n", tpg->tpgt, (a->cache_dynamic_acls) ?
734 "Enabled" : "Disabled");
736 return 0;
739 int iscsit_ta_demo_mode_write_protect(
740 struct iscsi_portal_group *tpg,
741 u32 flag)
743 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
745 if ((flag != 0) && (flag != 1)) {
746 pr_err("Illegal value %d\n", flag);
747 return -EINVAL;
750 a->demo_mode_write_protect = flag;
751 pr_debug("iSCSI_TPG[%hu] - Demo Mode Write Protect bit: %s\n",
752 tpg->tpgt, (a->demo_mode_write_protect) ? "ON" : "OFF");
754 return 0;
757 int iscsit_ta_prod_mode_write_protect(
758 struct iscsi_portal_group *tpg,
759 u32 flag)
761 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
763 if ((flag != 0) && (flag != 1)) {
764 pr_err("Illegal value %d\n", flag);
765 return -EINVAL;
768 a->prod_mode_write_protect = flag;
769 pr_debug("iSCSI_TPG[%hu] - Production Mode Write Protect bit:"
770 " %s\n", tpg->tpgt, (a->prod_mode_write_protect) ?
771 "ON" : "OFF");
773 return 0;