blob: 7087c736daa520fd22306e6cc39000b7c9aa08c0 [file] [log] [blame]
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001/*******************************************************************************
2 * This file contains the iSCSI Virtual Device and Disk Transport
3 * agnostic related functions.
4 *
Nicholas Bellinger4c762512013-09-05 15:29:12 -07005 * (c) Copyright 2007-2013 Datera, Inc.
Nicholas Bellingere48354c2011-07-23 06:43:04 +00006 *
7 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 ******************************************************************************/
19
20#include <scsi/scsi_device.h>
21#include <target/target_core_base.h>
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050022#include <target/target_core_fabric.h>
Nicholas Bellingere48354c2011-07-23 06:43:04 +000023
24#include "iscsi_target_core.h"
25#include "iscsi_target_device.h"
26#include "iscsi_target_tpg.h"
27#include "iscsi_target_util.h"
28
Nicholas Bellingere48354c2011-07-23 06:43:04 +000029void iscsit_determine_maxcmdsn(struct iscsi_session *sess)
30{
31 struct se_node_acl *se_nacl;
32
33 /*
34 * This is a discovery session, the single queue slot was already
35 * assigned in iscsi_login_zero_tsih(). Since only Logout and
36 * Text Opcodes are allowed during discovery we do not have to worry
37 * about the HBA's queue depth here.
38 */
39 if (sess->sess_ops->SessionType)
40 return;
41
42 se_nacl = sess->se_sess->se_node_acl;
43
44 /*
45 * This is a normal session, set the Session's CmdSN window to the
46 * struct se_node_acl->queue_depth. The value in struct se_node_acl->queue_depth
47 * has already been validated as a legal value in
48 * core_set_queue_depth_for_node().
49 */
50 sess->cmdsn_window = se_nacl->queue_depth;
51 sess->max_cmd_sn = (sess->max_cmd_sn + se_nacl->queue_depth) - 1;
52}
53
54void iscsit_increment_maxcmdsn(struct iscsi_cmd *cmd, struct iscsi_session *sess)
55{
56 if (cmd->immediate_cmd || cmd->maxcmdsn_inc)
57 return;
58
59 cmd->maxcmdsn_inc = 1;
60
Nicholas Bellinger5e8e6b42013-11-12 17:54:56 -080061 mutex_lock(&sess->cmdsn_mutex);
Nicholas Bellingere48354c2011-07-23 06:43:04 +000062 sess->max_cmd_sn += 1;
63 pr_debug("Updated MaxCmdSN to 0x%08x\n", sess->max_cmd_sn);
64 mutex_unlock(&sess->cmdsn_mutex);
65}
Nicholas Bellinger2ec5a8c2013-03-20 15:29:15 -070066EXPORT_SYMBOL(iscsit_increment_maxcmdsn);