Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 2 | /******************************************************************************* |
| 3 | * This file contains the iSCSI Virtual Device and Disk Transport |
| 4 | * agnostic related functions. |
| 5 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 6 | * (c) Copyright 2007-2013 Datera, Inc. |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 7 | * |
| 8 | * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> |
| 9 | * |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 10 | ******************************************************************************/ |
| 11 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 12 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 13 | #include <target/target_core_fabric.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 14 | |
Sagi Grimberg | 67f091f | 2015-01-07 14:57:31 +0200 | [diff] [blame] | 15 | #include <target/iscsi/iscsi_target_core.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 16 | #include "iscsi_target_device.h" |
| 17 | #include "iscsi_target_tpg.h" |
| 18 | #include "iscsi_target_util.h" |
| 19 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 20 | void 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 Dreier | 7dd03ac | 2015-09-08 06:14:18 -0700 | [diff] [blame] | 42 | atomic_add(se_nacl->queue_depth - 1, &sess->max_cmd_sn); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void iscsit_increment_maxcmdsn(struct iscsi_cmd *cmd, struct iscsi_session *sess) |
| 46 | { |
Roland Dreier | 7dd03ac | 2015-09-08 06:14:18 -0700 | [diff] [blame] | 47 | u32 max_cmd_sn; |
| 48 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 49 | if (cmd->immediate_cmd || cmd->maxcmdsn_inc) |
| 50 | return; |
| 51 | |
| 52 | cmd->maxcmdsn_inc = 1; |
| 53 | |
Roland Dreier | 7dd03ac | 2015-09-08 06:14:18 -0700 | [diff] [blame] | 54 | max_cmd_sn = atomic_inc_return(&sess->max_cmd_sn); |
| 55 | pr_debug("Updated MaxCmdSN to 0x%08x\n", max_cmd_sn); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 56 | } |
Nicholas Bellinger | 2ec5a8c | 2013-03-20 15:29:15 -0700 | [diff] [blame] | 57 | EXPORT_SYMBOL(iscsit_increment_maxcmdsn); |