blob: 8bf36ec86e3fe52453d0f322e41f26f87c3963b2 [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Nicholas Bellingere48354c2011-07-23 06:43:04 +00002/*******************************************************************************
3 * This file contains the iSCSI Virtual Device and Disk Transport
4 * agnostic related functions.
5 *
Nicholas Bellinger4c762512013-09-05 15:29:12 -07006 * (c) Copyright 2007-2013 Datera, Inc.
Nicholas Bellingere48354c2011-07-23 06:43:04 +00007 *
8 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
9 *
Nicholas Bellingere48354c2011-07-23 06:43:04 +000010 ******************************************************************************/
11
Nicholas Bellingere48354c2011-07-23 06:43:04 +000012#include <target/target_core_base.h>
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050013#include <target/target_core_fabric.h>
Nicholas Bellingere48354c2011-07-23 06:43:04 +000014
Sagi Grimberg67f091f2015-01-07 14:57:31 +020015#include <target/iscsi/iscsi_target_core.h>
Nicholas Bellingere48354c2011-07-23 06:43:04 +000016#include "iscsi_target_device.h"
17#include "iscsi_target_tpg.h"
18#include "iscsi_target_util.h"
19
Nicholas Bellingere48354c2011-07-23 06:43:04 +000020void iscsit_determine_maxcmdsn(struct iscsi_session *sess)
21{
22 struct se_node_acl *se_nacl;
23
24 /*
25 * This is a discovery session, the single queue slot was already
26 * assigned in iscsi_login_zero_tsih(). Since only Logout and
27 * Text Opcodes are allowed during discovery we do not have to worry
28 * about the HBA's queue depth here.
29 */
30 if (sess->sess_ops->SessionType)
31 return;
32
33 se_nacl = sess->se_sess->se_node_acl;
34
35 /*
36 * This is a normal session, set the Session's CmdSN window to the
37 * struct se_node_acl->queue_depth. The value in struct se_node_acl->queue_depth
38 * has already been validated as a legal value in
39 * core_set_queue_depth_for_node().
40 */
41 sess->cmdsn_window = se_nacl->queue_depth;
Roland Dreier7dd03ac2015-09-08 06:14:18 -070042 atomic_add(se_nacl->queue_depth - 1, &sess->max_cmd_sn);
Nicholas Bellingere48354c2011-07-23 06:43:04 +000043}
44
45void iscsit_increment_maxcmdsn(struct iscsi_cmd *cmd, struct iscsi_session *sess)
46{
Roland Dreier7dd03ac2015-09-08 06:14:18 -070047 u32 max_cmd_sn;
48
Nicholas Bellingere48354c2011-07-23 06:43:04 +000049 if (cmd->immediate_cmd || cmd->maxcmdsn_inc)
50 return;
51
52 cmd->maxcmdsn_inc = 1;
53
Roland Dreier7dd03ac2015-09-08 06:14:18 -070054 max_cmd_sn = atomic_inc_return(&sess->max_cmd_sn);
55 pr_debug("Updated MaxCmdSN to 0x%08x\n", max_cmd_sn);
Nicholas Bellingere48354c2011-07-23 06:43:04 +000056}
Nicholas Bellinger2ec5a8c2013-03-20 15:29:15 -070057EXPORT_SYMBOL(iscsit_increment_maxcmdsn);