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