Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Filename: target_core_transport.c |
| 3 | * |
| 4 | * This file contains the Generic Target Engine Core. |
| 5 | * |
| 6 | * Copyright (c) 2002, 2003, 2004, 2005 PyX Technologies, Inc. |
| 7 | * Copyright (c) 2005, 2006, 2007 SBE, Inc. |
| 8 | * Copyright (c) 2007-2010 Rising Tide Systems |
| 9 | * Copyright (c) 2008-2010 Linux-iSCSI.org |
| 10 | * |
| 11 | * Nicholas A. Bellinger <nab@kernel.org> |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 26 | * |
| 27 | ******************************************************************************/ |
| 28 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 29 | #include <linux/net.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/string.h> |
| 32 | #include <linux/timer.h> |
| 33 | #include <linux/slab.h> |
| 34 | #include <linux/blkdev.h> |
| 35 | #include <linux/spinlock.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 36 | #include <linux/kthread.h> |
| 37 | #include <linux/in.h> |
| 38 | #include <linux/cdrom.h> |
Paul Gortmaker | 827509e | 2011-08-30 14:20:44 -0400 | [diff] [blame] | 39 | #include <linux/module.h> |
Roland Dreier | 015487b | 2012-02-13 16:18:17 -0800 | [diff] [blame] | 40 | #include <linux/ratelimit.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 41 | #include <asm/unaligned.h> |
| 42 | #include <net/sock.h> |
| 43 | #include <net/tcp.h> |
| 44 | #include <scsi/scsi.h> |
| 45 | #include <scsi/scsi_cmnd.h> |
Nicholas Bellinger | e66ecd5 | 2011-05-19 20:19:14 -0700 | [diff] [blame] | 46 | #include <scsi/scsi_tcq.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 47 | |
| 48 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 49 | #include <target/target_core_backend.h> |
| 50 | #include <target/target_core_fabric.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 51 | #include <target/target_core_configfs.h> |
| 52 | |
Christoph Hellwig | e26d99a | 2011-11-14 12:30:30 -0500 | [diff] [blame] | 53 | #include "target_core_internal.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 54 | #include "target_core_alua.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 55 | #include "target_core_pr.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 56 | #include "target_core_ua.h" |
| 57 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 58 | static int sub_api_initialized; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 59 | |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 60 | static struct workqueue_struct *target_completion_wq; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 61 | static struct kmem_cache *se_sess_cache; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 62 | struct kmem_cache *se_ua_cache; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 63 | struct kmem_cache *t10_pr_reg_cache; |
| 64 | struct kmem_cache *t10_alua_lu_gp_cache; |
| 65 | struct kmem_cache *t10_alua_lu_gp_mem_cache; |
| 66 | struct kmem_cache *t10_alua_tg_pt_gp_cache; |
| 67 | struct kmem_cache *t10_alua_tg_pt_gp_mem_cache; |
| 68 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 69 | static int transport_generic_write_pending(struct se_cmd *); |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 70 | static int transport_processing_thread(void *param); |
Nicholas Bellinger | 4d2300c | 2011-11-30 18:18:33 -0800 | [diff] [blame] | 71 | static int __transport_execute_tasks(struct se_device *dev, struct se_cmd *); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 72 | static void transport_complete_task_attr(struct se_cmd *cmd); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 73 | static void transport_handle_queue_full(struct se_cmd *cmd, |
Christoph Hellwig | e057f53 | 2011-10-17 13:56:41 -0400 | [diff] [blame] | 74 | struct se_device *dev); |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 75 | static int transport_generic_get_mem(struct se_cmd *cmd); |
Nicholas Bellinger | 39c05f3 | 2011-10-08 13:59:52 -0700 | [diff] [blame] | 76 | static void transport_put_cmd(struct se_cmd *cmd); |
Christoph Hellwig | 3df8d40 | 2011-10-17 13:56:43 -0400 | [diff] [blame] | 77 | static void transport_remove_cmd_from_queue(struct se_cmd *cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 78 | static int transport_set_sense_codes(struct se_cmd *cmd, u8 asc, u8 ascq); |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 79 | static void target_complete_ok_work(struct work_struct *work); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 80 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 81 | int init_se_kmem_caches(void) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 82 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 83 | se_sess_cache = kmem_cache_create("se_sess_cache", |
| 84 | sizeof(struct se_session), __alignof__(struct se_session), |
| 85 | 0, NULL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 86 | if (!se_sess_cache) { |
| 87 | pr_err("kmem_cache_create() for struct se_session" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 88 | " failed\n"); |
Andy Grover | c8e31f2 | 2012-01-19 13:39:17 -0800 | [diff] [blame] | 89 | goto out; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 90 | } |
| 91 | se_ua_cache = kmem_cache_create("se_ua_cache", |
| 92 | sizeof(struct se_ua), __alignof__(struct se_ua), |
| 93 | 0, NULL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 94 | if (!se_ua_cache) { |
| 95 | pr_err("kmem_cache_create() for struct se_ua failed\n"); |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 96 | goto out_free_sess_cache; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 97 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 98 | t10_pr_reg_cache = kmem_cache_create("t10_pr_reg_cache", |
| 99 | sizeof(struct t10_pr_registration), |
| 100 | __alignof__(struct t10_pr_registration), 0, NULL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 101 | if (!t10_pr_reg_cache) { |
| 102 | pr_err("kmem_cache_create() for struct t10_pr_registration" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 103 | " failed\n"); |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 104 | goto out_free_ua_cache; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 105 | } |
| 106 | t10_alua_lu_gp_cache = kmem_cache_create("t10_alua_lu_gp_cache", |
| 107 | sizeof(struct t10_alua_lu_gp), __alignof__(struct t10_alua_lu_gp), |
| 108 | 0, NULL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 109 | if (!t10_alua_lu_gp_cache) { |
| 110 | pr_err("kmem_cache_create() for t10_alua_lu_gp_cache" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 111 | " failed\n"); |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 112 | goto out_free_pr_reg_cache; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 113 | } |
| 114 | t10_alua_lu_gp_mem_cache = kmem_cache_create("t10_alua_lu_gp_mem_cache", |
| 115 | sizeof(struct t10_alua_lu_gp_member), |
| 116 | __alignof__(struct t10_alua_lu_gp_member), 0, NULL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 117 | if (!t10_alua_lu_gp_mem_cache) { |
| 118 | pr_err("kmem_cache_create() for t10_alua_lu_gp_mem_" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 119 | "cache failed\n"); |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 120 | goto out_free_lu_gp_cache; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 121 | } |
| 122 | t10_alua_tg_pt_gp_cache = kmem_cache_create("t10_alua_tg_pt_gp_cache", |
| 123 | sizeof(struct t10_alua_tg_pt_gp), |
| 124 | __alignof__(struct t10_alua_tg_pt_gp), 0, NULL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 125 | if (!t10_alua_tg_pt_gp_cache) { |
| 126 | pr_err("kmem_cache_create() for t10_alua_tg_pt_gp_" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 127 | "cache failed\n"); |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 128 | goto out_free_lu_gp_mem_cache; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 129 | } |
| 130 | t10_alua_tg_pt_gp_mem_cache = kmem_cache_create( |
| 131 | "t10_alua_tg_pt_gp_mem_cache", |
| 132 | sizeof(struct t10_alua_tg_pt_gp_member), |
| 133 | __alignof__(struct t10_alua_tg_pt_gp_member), |
| 134 | 0, NULL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 135 | if (!t10_alua_tg_pt_gp_mem_cache) { |
| 136 | pr_err("kmem_cache_create() for t10_alua_tg_pt_gp_" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 137 | "mem_t failed\n"); |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 138 | goto out_free_tg_pt_gp_cache; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 141 | target_completion_wq = alloc_workqueue("target_completion", |
| 142 | WQ_MEM_RECLAIM, 0); |
| 143 | if (!target_completion_wq) |
| 144 | goto out_free_tg_pt_gp_mem_cache; |
| 145 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 146 | return 0; |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 147 | |
| 148 | out_free_tg_pt_gp_mem_cache: |
| 149 | kmem_cache_destroy(t10_alua_tg_pt_gp_mem_cache); |
| 150 | out_free_tg_pt_gp_cache: |
| 151 | kmem_cache_destroy(t10_alua_tg_pt_gp_cache); |
| 152 | out_free_lu_gp_mem_cache: |
| 153 | kmem_cache_destroy(t10_alua_lu_gp_mem_cache); |
| 154 | out_free_lu_gp_cache: |
| 155 | kmem_cache_destroy(t10_alua_lu_gp_cache); |
| 156 | out_free_pr_reg_cache: |
| 157 | kmem_cache_destroy(t10_pr_reg_cache); |
| 158 | out_free_ua_cache: |
| 159 | kmem_cache_destroy(se_ua_cache); |
| 160 | out_free_sess_cache: |
| 161 | kmem_cache_destroy(se_sess_cache); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 162 | out: |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 163 | return -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 166 | void release_se_kmem_caches(void) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 167 | { |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 168 | destroy_workqueue(target_completion_wq); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 169 | kmem_cache_destroy(se_sess_cache); |
| 170 | kmem_cache_destroy(se_ua_cache); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 171 | kmem_cache_destroy(t10_pr_reg_cache); |
| 172 | kmem_cache_destroy(t10_alua_lu_gp_cache); |
| 173 | kmem_cache_destroy(t10_alua_lu_gp_mem_cache); |
| 174 | kmem_cache_destroy(t10_alua_tg_pt_gp_cache); |
| 175 | kmem_cache_destroy(t10_alua_tg_pt_gp_mem_cache); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 178 | /* This code ensures unique mib indexes are handed out. */ |
| 179 | static DEFINE_SPINLOCK(scsi_mib_index_lock); |
| 180 | static u32 scsi_mib_index[SCSI_INDEX_TYPE_MAX]; |
Nicholas Bellinger | e89d15e | 2011-02-09 15:35:03 -0800 | [diff] [blame] | 181 | |
| 182 | /* |
| 183 | * Allocate a new row index for the entry type specified |
| 184 | */ |
| 185 | u32 scsi_get_new_index(scsi_index_t type) |
| 186 | { |
| 187 | u32 new_index; |
| 188 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 189 | BUG_ON((type < 0) || (type >= SCSI_INDEX_TYPE_MAX)); |
Nicholas Bellinger | e89d15e | 2011-02-09 15:35:03 -0800 | [diff] [blame] | 190 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 191 | spin_lock(&scsi_mib_index_lock); |
| 192 | new_index = ++scsi_mib_index[type]; |
| 193 | spin_unlock(&scsi_mib_index_lock); |
Nicholas Bellinger | e89d15e | 2011-02-09 15:35:03 -0800 | [diff] [blame] | 194 | |
| 195 | return new_index; |
| 196 | } |
| 197 | |
Christoph Hellwig | e26d99a | 2011-11-14 12:30:30 -0500 | [diff] [blame] | 198 | static void transport_init_queue_obj(struct se_queue_obj *qobj) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 199 | { |
| 200 | atomic_set(&qobj->queue_cnt, 0); |
| 201 | INIT_LIST_HEAD(&qobj->qobj_list); |
| 202 | init_waitqueue_head(&qobj->thread_wq); |
| 203 | spin_lock_init(&qobj->cmd_queue_lock); |
| 204 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 205 | |
Nicholas Bellinger | dbc5623 | 2011-10-22 01:03:54 -0700 | [diff] [blame] | 206 | void transport_subsystem_check_init(void) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 207 | { |
| 208 | int ret; |
| 209 | |
Nicholas Bellinger | dbc5623 | 2011-10-22 01:03:54 -0700 | [diff] [blame] | 210 | if (sub_api_initialized) |
| 211 | return; |
| 212 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 213 | ret = request_module("target_core_iblock"); |
| 214 | if (ret != 0) |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 215 | pr_err("Unable to load target_core_iblock\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 216 | |
| 217 | ret = request_module("target_core_file"); |
| 218 | if (ret != 0) |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 219 | pr_err("Unable to load target_core_file\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 220 | |
| 221 | ret = request_module("target_core_pscsi"); |
| 222 | if (ret != 0) |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 223 | pr_err("Unable to load target_core_pscsi\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 224 | |
| 225 | ret = request_module("target_core_stgt"); |
| 226 | if (ret != 0) |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 227 | pr_err("Unable to load target_core_stgt\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 228 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 229 | sub_api_initialized = 1; |
Nicholas Bellinger | dbc5623 | 2011-10-22 01:03:54 -0700 | [diff] [blame] | 230 | return; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | struct se_session *transport_init_session(void) |
| 234 | { |
| 235 | struct se_session *se_sess; |
| 236 | |
| 237 | se_sess = kmem_cache_zalloc(se_sess_cache, GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 238 | if (!se_sess) { |
| 239 | pr_err("Unable to allocate struct se_session from" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 240 | " se_sess_cache\n"); |
| 241 | return ERR_PTR(-ENOMEM); |
| 242 | } |
| 243 | INIT_LIST_HEAD(&se_sess->sess_list); |
| 244 | INIT_LIST_HEAD(&se_sess->sess_acl_list); |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 245 | INIT_LIST_HEAD(&se_sess->sess_cmd_list); |
| 246 | INIT_LIST_HEAD(&se_sess->sess_wait_list); |
| 247 | spin_lock_init(&se_sess->sess_cmd_lock); |
Nicholas Bellinger | 41ac82b | 2012-02-26 22:22:10 -0800 | [diff] [blame] | 248 | kref_init(&se_sess->sess_kref); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 249 | |
| 250 | return se_sess; |
| 251 | } |
| 252 | EXPORT_SYMBOL(transport_init_session); |
| 253 | |
| 254 | /* |
Nicholas Bellinger | 140854c | 2011-08-31 12:34:39 -0700 | [diff] [blame] | 255 | * Called with spin_lock_irqsave(&struct se_portal_group->session_lock called. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 256 | */ |
| 257 | void __transport_register_session( |
| 258 | struct se_portal_group *se_tpg, |
| 259 | struct se_node_acl *se_nacl, |
| 260 | struct se_session *se_sess, |
| 261 | void *fabric_sess_ptr) |
| 262 | { |
| 263 | unsigned char buf[PR_REG_ISID_LEN]; |
| 264 | |
| 265 | se_sess->se_tpg = se_tpg; |
| 266 | se_sess->fabric_sess_ptr = fabric_sess_ptr; |
| 267 | /* |
| 268 | * Used by struct se_node_acl's under ConfigFS to locate active se_session-t |
| 269 | * |
| 270 | * Only set for struct se_session's that will actually be moving I/O. |
| 271 | * eg: *NOT* discovery sessions. |
| 272 | */ |
| 273 | if (se_nacl) { |
| 274 | /* |
| 275 | * If the fabric module supports an ISID based TransportID, |
| 276 | * save this value in binary from the fabric I_T Nexus now. |
| 277 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 278 | if (se_tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 279 | memset(&buf[0], 0, PR_REG_ISID_LEN); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 280 | se_tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 281 | &buf[0], PR_REG_ISID_LEN); |
| 282 | se_sess->sess_bin_isid = get_unaligned_be64(&buf[0]); |
| 283 | } |
Nicholas Bellinger | afb999f | 2012-03-08 23:45:02 -0800 | [diff] [blame] | 284 | kref_get(&se_nacl->acl_kref); |
| 285 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 286 | spin_lock_irq(&se_nacl->nacl_sess_lock); |
| 287 | /* |
| 288 | * The se_nacl->nacl_sess pointer will be set to the |
| 289 | * last active I_T Nexus for each struct se_node_acl. |
| 290 | */ |
| 291 | se_nacl->nacl_sess = se_sess; |
| 292 | |
| 293 | list_add_tail(&se_sess->sess_acl_list, |
| 294 | &se_nacl->acl_sess_list); |
| 295 | spin_unlock_irq(&se_nacl->nacl_sess_lock); |
| 296 | } |
| 297 | list_add_tail(&se_sess->sess_list, &se_tpg->tpg_sess_list); |
| 298 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 299 | pr_debug("TARGET_CORE[%s]: Registered fabric_sess_ptr: %p\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 300 | se_tpg->se_tpg_tfo->get_fabric_name(), se_sess->fabric_sess_ptr); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 301 | } |
| 302 | EXPORT_SYMBOL(__transport_register_session); |
| 303 | |
| 304 | void transport_register_session( |
| 305 | struct se_portal_group *se_tpg, |
| 306 | struct se_node_acl *se_nacl, |
| 307 | struct se_session *se_sess, |
| 308 | void *fabric_sess_ptr) |
| 309 | { |
Nicholas Bellinger | 140854c | 2011-08-31 12:34:39 -0700 | [diff] [blame] | 310 | unsigned long flags; |
| 311 | |
| 312 | spin_lock_irqsave(&se_tpg->session_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 313 | __transport_register_session(se_tpg, se_nacl, se_sess, fabric_sess_ptr); |
Nicholas Bellinger | 140854c | 2011-08-31 12:34:39 -0700 | [diff] [blame] | 314 | spin_unlock_irqrestore(&se_tpg->session_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 315 | } |
| 316 | EXPORT_SYMBOL(transport_register_session); |
| 317 | |
Joern Engel | 4149268 | 2012-05-18 13:57:19 -0700 | [diff] [blame] | 318 | void target_release_session(struct kref *kref) |
Nicholas Bellinger | 41ac82b | 2012-02-26 22:22:10 -0800 | [diff] [blame] | 319 | { |
| 320 | struct se_session *se_sess = container_of(kref, |
| 321 | struct se_session, sess_kref); |
| 322 | struct se_portal_group *se_tpg = se_sess->se_tpg; |
| 323 | |
| 324 | se_tpg->se_tpg_tfo->close_session(se_sess); |
| 325 | } |
| 326 | |
| 327 | void target_get_session(struct se_session *se_sess) |
| 328 | { |
| 329 | kref_get(&se_sess->sess_kref); |
| 330 | } |
| 331 | EXPORT_SYMBOL(target_get_session); |
| 332 | |
Jörn Engel | 33933a0 | 2012-05-11 10:35:08 -0400 | [diff] [blame] | 333 | void target_put_session(struct se_session *se_sess) |
Nicholas Bellinger | 41ac82b | 2012-02-26 22:22:10 -0800 | [diff] [blame] | 334 | { |
Joern Engel | 4149268 | 2012-05-18 13:57:19 -0700 | [diff] [blame] | 335 | struct se_portal_group *tpg = se_sess->se_tpg; |
| 336 | |
| 337 | if (tpg->se_tpg_tfo->put_session != NULL) { |
| 338 | tpg->se_tpg_tfo->put_session(se_sess); |
| 339 | return; |
| 340 | } |
Jörn Engel | 33933a0 | 2012-05-11 10:35:08 -0400 | [diff] [blame] | 341 | kref_put(&se_sess->sess_kref, target_release_session); |
Nicholas Bellinger | 41ac82b | 2012-02-26 22:22:10 -0800 | [diff] [blame] | 342 | } |
| 343 | EXPORT_SYMBOL(target_put_session); |
| 344 | |
Nicholas Bellinger | afb999f | 2012-03-08 23:45:02 -0800 | [diff] [blame] | 345 | static void target_complete_nacl(struct kref *kref) |
| 346 | { |
| 347 | struct se_node_acl *nacl = container_of(kref, |
| 348 | struct se_node_acl, acl_kref); |
| 349 | |
| 350 | complete(&nacl->acl_free_comp); |
| 351 | } |
| 352 | |
| 353 | void target_put_nacl(struct se_node_acl *nacl) |
| 354 | { |
| 355 | kref_put(&nacl->acl_kref, target_complete_nacl); |
| 356 | } |
| 357 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 358 | void transport_deregister_session_configfs(struct se_session *se_sess) |
| 359 | { |
| 360 | struct se_node_acl *se_nacl; |
Roland Dreier | 2338886 | 2011-06-22 01:02:21 -0700 | [diff] [blame] | 361 | unsigned long flags; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 362 | /* |
| 363 | * Used by struct se_node_acl's under ConfigFS to locate active struct se_session |
| 364 | */ |
| 365 | se_nacl = se_sess->se_node_acl; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 366 | if (se_nacl) { |
Roland Dreier | 2338886 | 2011-06-22 01:02:21 -0700 | [diff] [blame] | 367 | spin_lock_irqsave(&se_nacl->nacl_sess_lock, flags); |
Nicholas Bellinger | 337c060 | 2012-03-10 14:36:21 -0800 | [diff] [blame] | 368 | if (se_nacl->acl_stop == 0) |
| 369 | list_del(&se_sess->sess_acl_list); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 370 | /* |
| 371 | * If the session list is empty, then clear the pointer. |
| 372 | * Otherwise, set the struct se_session pointer from the tail |
| 373 | * element of the per struct se_node_acl active session list. |
| 374 | */ |
| 375 | if (list_empty(&se_nacl->acl_sess_list)) |
| 376 | se_nacl->nacl_sess = NULL; |
| 377 | else { |
| 378 | se_nacl->nacl_sess = container_of( |
| 379 | se_nacl->acl_sess_list.prev, |
| 380 | struct se_session, sess_acl_list); |
| 381 | } |
Roland Dreier | 2338886 | 2011-06-22 01:02:21 -0700 | [diff] [blame] | 382 | spin_unlock_irqrestore(&se_nacl->nacl_sess_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | EXPORT_SYMBOL(transport_deregister_session_configfs); |
| 386 | |
| 387 | void transport_free_session(struct se_session *se_sess) |
| 388 | { |
| 389 | kmem_cache_free(se_sess_cache, se_sess); |
| 390 | } |
| 391 | EXPORT_SYMBOL(transport_free_session); |
| 392 | |
| 393 | void transport_deregister_session(struct se_session *se_sess) |
| 394 | { |
| 395 | struct se_portal_group *se_tpg = se_sess->se_tpg; |
Nicholas Bellinger | 0146834 | 2012-03-10 14:32:52 -0800 | [diff] [blame] | 396 | struct target_core_fabric_ops *se_tfo; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 397 | struct se_node_acl *se_nacl; |
Roland Dreier | e63a8e1 | 2011-08-12 16:01:02 -0700 | [diff] [blame] | 398 | unsigned long flags; |
Nicholas Bellinger | 0146834 | 2012-03-10 14:32:52 -0800 | [diff] [blame] | 399 | bool comp_nacl = true; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 400 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 401 | if (!se_tpg) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 402 | transport_free_session(se_sess); |
| 403 | return; |
| 404 | } |
Nicholas Bellinger | 0146834 | 2012-03-10 14:32:52 -0800 | [diff] [blame] | 405 | se_tfo = se_tpg->se_tpg_tfo; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 406 | |
Roland Dreier | e63a8e1 | 2011-08-12 16:01:02 -0700 | [diff] [blame] | 407 | spin_lock_irqsave(&se_tpg->session_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 408 | list_del(&se_sess->sess_list); |
| 409 | se_sess->se_tpg = NULL; |
| 410 | se_sess->fabric_sess_ptr = NULL; |
Roland Dreier | e63a8e1 | 2011-08-12 16:01:02 -0700 | [diff] [blame] | 411 | spin_unlock_irqrestore(&se_tpg->session_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 412 | |
| 413 | /* |
| 414 | * Determine if we need to do extra work for this initiator node's |
| 415 | * struct se_node_acl if it had been previously dynamically generated. |
| 416 | */ |
| 417 | se_nacl = se_sess->se_node_acl; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 418 | |
Nicholas Bellinger | 0146834 | 2012-03-10 14:32:52 -0800 | [diff] [blame] | 419 | spin_lock_irqsave(&se_tpg->acl_node_lock, flags); |
| 420 | if (se_nacl && se_nacl->dynamic_node_acl) { |
| 421 | if (!se_tfo->tpg_check_demo_mode_cache(se_tpg)) { |
| 422 | list_del(&se_nacl->acl_list); |
| 423 | se_tpg->num_node_acls--; |
| 424 | spin_unlock_irqrestore(&se_tpg->acl_node_lock, flags); |
| 425 | core_tpg_wait_for_nacl_pr_ref(se_nacl); |
| 426 | core_free_device_list_for_node(se_nacl, se_tpg); |
| 427 | se_tfo->tpg_release_fabric_acl(se_tpg, se_nacl); |
| 428 | |
| 429 | comp_nacl = false; |
| 430 | spin_lock_irqsave(&se_tpg->acl_node_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 431 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 432 | } |
Nicholas Bellinger | 0146834 | 2012-03-10 14:32:52 -0800 | [diff] [blame] | 433 | spin_unlock_irqrestore(&se_tpg->acl_node_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 434 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 435 | pr_debug("TARGET_CORE[%s]: Deregistered fabric_sess\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 436 | se_tpg->se_tpg_tfo->get_fabric_name()); |
Nicholas Bellinger | 0146834 | 2012-03-10 14:32:52 -0800 | [diff] [blame] | 437 | /* |
Nicholas Bellinger | afb999f | 2012-03-08 23:45:02 -0800 | [diff] [blame] | 438 | * If last kref is dropping now for an explict NodeACL, awake sleeping |
| 439 | * ->acl_free_comp caller to wakeup configfs se_node_acl->acl_group |
| 440 | * removal context. |
Nicholas Bellinger | 0146834 | 2012-03-10 14:32:52 -0800 | [diff] [blame] | 441 | */ |
| 442 | if (se_nacl && comp_nacl == true) |
Nicholas Bellinger | afb999f | 2012-03-08 23:45:02 -0800 | [diff] [blame] | 443 | target_put_nacl(se_nacl); |
Nicholas Bellinger | 0146834 | 2012-03-10 14:32:52 -0800 | [diff] [blame] | 444 | |
Nicholas Bellinger | afb999f | 2012-03-08 23:45:02 -0800 | [diff] [blame] | 445 | transport_free_session(se_sess); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 446 | } |
| 447 | EXPORT_SYMBOL(transport_deregister_session); |
| 448 | |
| 449 | /* |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 450 | * Called with cmd->t_state_lock held. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 451 | */ |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 452 | static void target_remove_from_state_list(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 453 | { |
Christoph Hellwig | 42bf829 | 2011-10-12 11:07:00 -0400 | [diff] [blame] | 454 | struct se_device *dev = cmd->se_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 455 | unsigned long flags; |
| 456 | |
Christoph Hellwig | 42bf829 | 2011-10-12 11:07:00 -0400 | [diff] [blame] | 457 | if (!dev) |
| 458 | return; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 459 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 460 | if (cmd->transport_state & CMD_T_BUSY) |
| 461 | return; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 462 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 463 | spin_lock_irqsave(&dev->execute_task_lock, flags); |
| 464 | if (cmd->state_active) { |
| 465 | list_del(&cmd->state_list); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 466 | cmd->state_active = false; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 467 | } |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 468 | spin_unlock_irqrestore(&dev->execute_task_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | /* transport_cmd_check_stop(): |
| 472 | * |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 473 | * 'transport_off = 1' determines if CMD_T_ACTIVE should be cleared. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 474 | * 'transport_off = 2' determines if task_dev_state should be removed. |
| 475 | * |
| 476 | * A non-zero u8 t_state sets cmd->t_state. |
| 477 | * Returns 1 when command is stopped, else 0. |
| 478 | */ |
| 479 | static int transport_cmd_check_stop( |
| 480 | struct se_cmd *cmd, |
| 481 | int transport_off, |
| 482 | u8 t_state) |
| 483 | { |
| 484 | unsigned long flags; |
| 485 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 486 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 487 | /* |
| 488 | * Determine if IOCTL context caller in requesting the stopping of this |
| 489 | * command for LUN shutdown purposes. |
| 490 | */ |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 491 | if (cmd->transport_state & CMD_T_LUN_STOP) { |
| 492 | pr_debug("%s:%d CMD_T_LUN_STOP for ITT: 0x%08x\n", |
| 493 | __func__, __LINE__, cmd->se_tfo->get_task_tag(cmd)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 494 | |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 495 | cmd->transport_state &= ~CMD_T_ACTIVE; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 496 | if (transport_off == 2) |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 497 | target_remove_from_state_list(cmd); |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 498 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 499 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 500 | complete(&cmd->transport_lun_stop_comp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 501 | return 1; |
| 502 | } |
| 503 | /* |
| 504 | * Determine if frontend context caller is requesting the stopping of |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 505 | * this command for frontend exceptions. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 506 | */ |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 507 | if (cmd->transport_state & CMD_T_STOP) { |
| 508 | pr_debug("%s:%d CMD_T_STOP for ITT: 0x%08x\n", |
| 509 | __func__, __LINE__, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 510 | cmd->se_tfo->get_task_tag(cmd)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 511 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 512 | if (transport_off == 2) |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 513 | target_remove_from_state_list(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 514 | |
| 515 | /* |
| 516 | * Clear struct se_cmd->se_lun before the transport_off == 2 handoff |
| 517 | * to FE. |
| 518 | */ |
| 519 | if (transport_off == 2) |
| 520 | cmd->se_lun = NULL; |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 521 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 522 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 523 | complete(&cmd->t_transport_stop_comp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 524 | return 1; |
| 525 | } |
| 526 | if (transport_off) { |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 527 | cmd->transport_state &= ~CMD_T_ACTIVE; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 528 | if (transport_off == 2) { |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 529 | target_remove_from_state_list(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 530 | /* |
| 531 | * Clear struct se_cmd->se_lun before the transport_off == 2 |
| 532 | * handoff to fabric module. |
| 533 | */ |
| 534 | cmd->se_lun = NULL; |
| 535 | /* |
| 536 | * Some fabric modules like tcm_loop can release |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 537 | * their internally allocated I/O reference now and |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 538 | * struct se_cmd now. |
Nicholas Bellinger | 88dd9e2 | 2011-11-02 03:33:16 -0700 | [diff] [blame] | 539 | * |
| 540 | * Fabric modules are expected to return '1' here if the |
| 541 | * se_cmd being passed is released at this point, |
| 542 | * or zero if not being released. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 543 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 544 | if (cmd->se_tfo->check_stop_free != NULL) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 545 | spin_unlock_irqrestore( |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 546 | &cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 547 | |
Nicholas Bellinger | 88dd9e2 | 2011-11-02 03:33:16 -0700 | [diff] [blame] | 548 | return cmd->se_tfo->check_stop_free(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 549 | } |
| 550 | } |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 551 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 552 | |
| 553 | return 0; |
| 554 | } else if (t_state) |
| 555 | cmd->t_state = t_state; |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 556 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 557 | |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | static int transport_cmd_check_stop_to_fabric(struct se_cmd *cmd) |
| 562 | { |
| 563 | return transport_cmd_check_stop(cmd, 2, 0); |
| 564 | } |
| 565 | |
| 566 | static void transport_lun_remove_cmd(struct se_cmd *cmd) |
| 567 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 568 | struct se_lun *lun = cmd->se_lun; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 569 | unsigned long flags; |
| 570 | |
| 571 | if (!lun) |
| 572 | return; |
| 573 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 574 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 575 | if (cmd->transport_state & CMD_T_DEV_ACTIVE) { |
| 576 | cmd->transport_state &= ~CMD_T_DEV_ACTIVE; |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 577 | target_remove_from_state_list(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 578 | } |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 579 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 580 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 581 | spin_lock_irqsave(&lun->lun_cmd_lock, flags); |
Christoph Hellwig | 3d26fea | 2011-12-21 14:14:05 -0500 | [diff] [blame] | 582 | if (!list_empty(&cmd->se_lun_node)) |
| 583 | list_del_init(&cmd->se_lun_node); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 584 | spin_unlock_irqrestore(&lun->lun_cmd_lock, flags); |
| 585 | } |
| 586 | |
| 587 | void transport_cmd_finish_abort(struct se_cmd *cmd, int remove) |
| 588 | { |
Andy Grover | c8e31f2 | 2012-01-19 13:39:17 -0800 | [diff] [blame] | 589 | if (!(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) |
Nicholas Bellinger | 8dc52b5 | 2011-10-09 02:02:51 -0700 | [diff] [blame] | 590 | transport_lun_remove_cmd(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 591 | |
| 592 | if (transport_cmd_check_stop_to_fabric(cmd)) |
| 593 | return; |
Nicholas Bellinger | 77039d1 | 2011-09-29 01:01:35 -0700 | [diff] [blame] | 594 | if (remove) { |
Christoph Hellwig | 3df8d40 | 2011-10-17 13:56:43 -0400 | [diff] [blame] | 595 | transport_remove_cmd_from_queue(cmd); |
Christoph Hellwig | e6a2573 | 2011-09-13 23:08:50 +0200 | [diff] [blame] | 596 | transport_put_cmd(cmd); |
Nicholas Bellinger | 77039d1 | 2011-09-29 01:01:35 -0700 | [diff] [blame] | 597 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 598 | } |
| 599 | |
Christoph Hellwig | f7a5cc0 | 2011-10-17 13:56:42 -0400 | [diff] [blame] | 600 | static void transport_add_cmd_to_queue(struct se_cmd *cmd, int t_state, |
| 601 | bool at_head) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 602 | { |
| 603 | struct se_device *dev = cmd->se_dev; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 604 | struct se_queue_obj *qobj = &dev->dev_queue_obj; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 605 | unsigned long flags; |
| 606 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 607 | if (t_state) { |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 608 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 609 | cmd->t_state = t_state; |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 610 | cmd->transport_state |= CMD_T_ACTIVE; |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 611 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | spin_lock_irqsave(&qobj->cmd_queue_lock, flags); |
Roland Dreier | 79a7fef | 2011-09-28 22:12:07 -0700 | [diff] [blame] | 615 | |
| 616 | /* If the cmd is already on the list, remove it before we add it */ |
| 617 | if (!list_empty(&cmd->se_queue_node)) |
| 618 | list_del(&cmd->se_queue_node); |
| 619 | else |
| 620 | atomic_inc(&qobj->queue_cnt); |
| 621 | |
Christoph Hellwig | f7a5cc0 | 2011-10-17 13:56:42 -0400 | [diff] [blame] | 622 | if (at_head) |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 623 | list_add(&cmd->se_queue_node, &qobj->qobj_list); |
Christoph Hellwig | f7a5cc0 | 2011-10-17 13:56:42 -0400 | [diff] [blame] | 624 | else |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 625 | list_add_tail(&cmd->se_queue_node, &qobj->qobj_list); |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 626 | cmd->transport_state |= CMD_T_QUEUED; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 627 | spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags); |
| 628 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 629 | wake_up_interruptible(&qobj->thread_wq); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 630 | } |
| 631 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 632 | static struct se_cmd * |
| 633 | transport_get_cmd_from_queue(struct se_queue_obj *qobj) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 634 | { |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 635 | struct se_cmd *cmd; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 636 | unsigned long flags; |
| 637 | |
| 638 | spin_lock_irqsave(&qobj->cmd_queue_lock, flags); |
| 639 | if (list_empty(&qobj->qobj_list)) { |
| 640 | spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags); |
| 641 | return NULL; |
| 642 | } |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 643 | cmd = list_first_entry(&qobj->qobj_list, struct se_cmd, se_queue_node); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 644 | |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 645 | cmd->transport_state &= ~CMD_T_QUEUED; |
Roland Dreier | 79a7fef | 2011-09-28 22:12:07 -0700 | [diff] [blame] | 646 | list_del_init(&cmd->se_queue_node); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 647 | atomic_dec(&qobj->queue_cnt); |
| 648 | spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags); |
| 649 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 650 | return cmd; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 651 | } |
| 652 | |
Christoph Hellwig | 3df8d40 | 2011-10-17 13:56:43 -0400 | [diff] [blame] | 653 | static void transport_remove_cmd_from_queue(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 654 | { |
Christoph Hellwig | 3df8d40 | 2011-10-17 13:56:43 -0400 | [diff] [blame] | 655 | struct se_queue_obj *qobj = &cmd->se_dev->dev_queue_obj; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 656 | unsigned long flags; |
| 657 | |
| 658 | spin_lock_irqsave(&qobj->cmd_queue_lock, flags); |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 659 | if (!(cmd->transport_state & CMD_T_QUEUED)) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 660 | spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags); |
| 661 | return; |
| 662 | } |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 663 | cmd->transport_state &= ~CMD_T_QUEUED; |
Roland Dreier | 79a7fef | 2011-09-28 22:12:07 -0700 | [diff] [blame] | 664 | atomic_dec(&qobj->queue_cnt); |
| 665 | list_del_init(&cmd->se_queue_node); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 666 | spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 667 | } |
| 668 | |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 669 | static void target_complete_failure_work(struct work_struct *work) |
| 670 | { |
| 671 | struct se_cmd *cmd = container_of(work, struct se_cmd, work); |
| 672 | |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 673 | transport_generic_request_failure(cmd); |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 674 | } |
| 675 | |
Christoph Hellwig | 5787cac | 2012-04-24 00:25:06 -0400 | [diff] [blame] | 676 | void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 677 | { |
Christoph Hellwig | 42bf829 | 2011-10-12 11:07:00 -0400 | [diff] [blame] | 678 | struct se_device *dev = cmd->se_dev; |
Christoph Hellwig | 5787cac | 2012-04-24 00:25:06 -0400 | [diff] [blame] | 679 | int success = scsi_status == GOOD; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 680 | unsigned long flags; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 681 | |
Christoph Hellwig | 5787cac | 2012-04-24 00:25:06 -0400 | [diff] [blame] | 682 | cmd->scsi_status = scsi_status; |
| 683 | |
| 684 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 685 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 686 | cmd->transport_state &= ~CMD_T_BUSY; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 687 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 688 | if (dev && dev->transport->transport_complete) { |
Christoph Hellwig | 5787cac | 2012-04-24 00:25:06 -0400 | [diff] [blame] | 689 | if (dev->transport->transport_complete(cmd, |
| 690 | cmd->t_data_sg) != 0) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 691 | cmd->se_cmd_flags |= SCF_TRANSPORT_TASK_SENSE; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 692 | success = 1; |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | /* |
Christoph Hellwig | 5787cac | 2012-04-24 00:25:06 -0400 | [diff] [blame] | 697 | * See if we are waiting to complete for an exception condition. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 698 | */ |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 699 | if (cmd->transport_state & CMD_T_REQUEST_STOP) { |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 700 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 701 | complete(&cmd->task_stop_comp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 702 | return; |
| 703 | } |
Christoph Hellwig | 2235007 | 2011-11-02 05:06:35 -0700 | [diff] [blame] | 704 | |
| 705 | if (!success) |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 706 | cmd->transport_state |= CMD_T_FAILED; |
Christoph Hellwig | 2235007 | 2011-11-02 05:06:35 -0700 | [diff] [blame] | 707 | |
Nicholas Bellinger | 3d28934 | 2012-02-13 02:38:14 -0800 | [diff] [blame] | 708 | /* |
| 709 | * Check for case where an explict ABORT_TASK has been received |
| 710 | * and transport_wait_for_tasks() will be waiting for completion.. |
| 711 | */ |
| 712 | if (cmd->transport_state & CMD_T_ABORTED && |
| 713 | cmd->transport_state & CMD_T_STOP) { |
| 714 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
| 715 | complete(&cmd->t_transport_stop_comp); |
| 716 | return; |
| 717 | } else if (cmd->transport_state & CMD_T_FAILED) { |
Christoph Hellwig | 41e16e9 | 2011-11-23 06:54:15 -0500 | [diff] [blame] | 718 | cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 719 | INIT_WORK(&cmd->work, target_complete_failure_work); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 720 | } else { |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 721 | INIT_WORK(&cmd->work, target_complete_ok_work); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 722 | } |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 723 | |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 724 | cmd->t_state = TRANSPORT_COMPLETE; |
Nicholas Bellinger | 3d28934 | 2012-02-13 02:38:14 -0800 | [diff] [blame] | 725 | cmd->transport_state |= (CMD_T_COMPLETE | CMD_T_ACTIVE); |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 726 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 727 | |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 728 | queue_work(target_completion_wq, &cmd->work); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 729 | } |
Christoph Hellwig | 6bb35e0 | 2012-04-23 11:35:33 -0400 | [diff] [blame] | 730 | EXPORT_SYMBOL(target_complete_cmd); |
| 731 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 732 | static void target_add_to_state_list(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 733 | { |
Christoph Hellwig | 42bf829 | 2011-10-12 11:07:00 -0400 | [diff] [blame] | 734 | struct se_device *dev = cmd->se_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 735 | unsigned long flags; |
| 736 | |
Nicholas Bellinger | 4d2300c | 2011-11-30 18:18:33 -0800 | [diff] [blame] | 737 | spin_lock_irqsave(&dev->execute_task_lock, flags); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 738 | if (!cmd->state_active) { |
| 739 | list_add_tail(&cmd->state_list, &dev->state_list); |
| 740 | cmd->state_active = true; |
| 741 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 742 | spin_unlock_irqrestore(&dev->execute_task_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 743 | } |
| 744 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 745 | static void __target_add_to_execute_list(struct se_cmd *cmd) |
Christoph Hellwig | 04629b7 | 2011-10-12 11:07:04 -0400 | [diff] [blame] | 746 | { |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 747 | struct se_device *dev = cmd->se_dev; |
| 748 | bool head_of_queue = false; |
| 749 | |
| 750 | if (!list_empty(&cmd->execute_list)) |
| 751 | return; |
| 752 | |
| 753 | if (dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED && |
| 754 | cmd->sam_task_attr == MSG_HEAD_TAG) |
| 755 | head_of_queue = true; |
| 756 | |
| 757 | if (head_of_queue) |
| 758 | list_add(&cmd->execute_list, &dev->execute_list); |
| 759 | else |
| 760 | list_add_tail(&cmd->execute_list, &dev->execute_list); |
| 761 | |
| 762 | atomic_inc(&dev->execute_tasks); |
| 763 | |
| 764 | if (cmd->state_active) |
| 765 | return; |
| 766 | |
| 767 | if (head_of_queue) |
| 768 | list_add(&cmd->state_list, &dev->state_list); |
| 769 | else |
| 770 | list_add_tail(&cmd->state_list, &dev->state_list); |
| 771 | |
| 772 | cmd->state_active = true; |
Christoph Hellwig | 04629b7 | 2011-10-12 11:07:04 -0400 | [diff] [blame] | 773 | } |
| 774 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 775 | static void target_add_to_execute_list(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 776 | { |
| 777 | unsigned long flags; |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 778 | struct se_device *dev = cmd->se_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 779 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 780 | spin_lock_irqsave(&dev->execute_task_lock, flags); |
| 781 | __target_add_to_execute_list(cmd); |
| 782 | spin_unlock_irqrestore(&dev->execute_task_lock, flags); |
| 783 | } |
| 784 | |
| 785 | void __target_remove_from_execute_list(struct se_cmd *cmd) |
| 786 | { |
| 787 | list_del_init(&cmd->execute_list); |
| 788 | atomic_dec(&cmd->se_dev->execute_tasks); |
| 789 | } |
| 790 | |
| 791 | static void target_remove_from_execute_list(struct se_cmd *cmd) |
| 792 | { |
| 793 | struct se_device *dev = cmd->se_dev; |
| 794 | unsigned long flags; |
| 795 | |
| 796 | if (WARN_ON(list_empty(&cmd->execute_list))) |
Nicholas Bellinger | af57c3a | 2011-05-19 20:19:12 -0700 | [diff] [blame] | 797 | return; |
Nicholas Bellinger | af57c3a | 2011-05-19 20:19:12 -0700 | [diff] [blame] | 798 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 799 | spin_lock_irqsave(&dev->execute_task_lock, flags); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 800 | __target_remove_from_execute_list(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 801 | spin_unlock_irqrestore(&dev->execute_task_lock, flags); |
| 802 | } |
| 803 | |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 804 | /* |
Nicholas Bellinger | f147abb | 2011-10-25 23:57:41 -0700 | [diff] [blame] | 805 | * Handle QUEUE_FULL / -EAGAIN and -ENOMEM status |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 806 | */ |
| 807 | |
| 808 | static void target_qf_do_work(struct work_struct *work) |
| 809 | { |
| 810 | struct se_device *dev = container_of(work, struct se_device, |
| 811 | qf_work_queue); |
Roland Dreier | bcac364 | 2011-08-27 21:33:16 -0700 | [diff] [blame] | 812 | LIST_HEAD(qf_cmd_list); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 813 | struct se_cmd *cmd, *cmd_tmp; |
| 814 | |
| 815 | spin_lock_irq(&dev->qf_cmd_lock); |
Roland Dreier | bcac364 | 2011-08-27 21:33:16 -0700 | [diff] [blame] | 816 | list_splice_init(&dev->qf_cmd_list, &qf_cmd_list); |
| 817 | spin_unlock_irq(&dev->qf_cmd_lock); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 818 | |
Roland Dreier | bcac364 | 2011-08-27 21:33:16 -0700 | [diff] [blame] | 819 | list_for_each_entry_safe(cmd, cmd_tmp, &qf_cmd_list, se_qf_node) { |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 820 | list_del(&cmd->se_qf_node); |
| 821 | atomic_dec(&dev->dev_qf_count); |
| 822 | smp_mb__after_atomic_dec(); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 823 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 824 | pr_debug("Processing %s cmd: %p QUEUE_FULL in work queue" |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 825 | " context: %s\n", cmd->se_tfo->get_fabric_name(), cmd, |
Christoph Hellwig | e057f53 | 2011-10-17 13:56:41 -0400 | [diff] [blame] | 826 | (cmd->t_state == TRANSPORT_COMPLETE_QF_OK) ? "COMPLETE_OK" : |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 827 | (cmd->t_state == TRANSPORT_COMPLETE_QF_WP) ? "WRITE_PENDING" |
| 828 | : "UNKNOWN"); |
Christoph Hellwig | f7a5cc0 | 2011-10-17 13:56:42 -0400 | [diff] [blame] | 829 | |
| 830 | transport_add_cmd_to_queue(cmd, cmd->t_state, true); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 831 | } |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 834 | unsigned char *transport_dump_cmd_direction(struct se_cmd *cmd) |
| 835 | { |
| 836 | switch (cmd->data_direction) { |
| 837 | case DMA_NONE: |
| 838 | return "NONE"; |
| 839 | case DMA_FROM_DEVICE: |
| 840 | return "READ"; |
| 841 | case DMA_TO_DEVICE: |
| 842 | return "WRITE"; |
| 843 | case DMA_BIDIRECTIONAL: |
| 844 | return "BIDI"; |
| 845 | default: |
| 846 | break; |
| 847 | } |
| 848 | |
| 849 | return "UNKNOWN"; |
| 850 | } |
| 851 | |
| 852 | void transport_dump_dev_state( |
| 853 | struct se_device *dev, |
| 854 | char *b, |
| 855 | int *bl) |
| 856 | { |
| 857 | *bl += sprintf(b + *bl, "Status: "); |
| 858 | switch (dev->dev_status) { |
| 859 | case TRANSPORT_DEVICE_ACTIVATED: |
| 860 | *bl += sprintf(b + *bl, "ACTIVATED"); |
| 861 | break; |
| 862 | case TRANSPORT_DEVICE_DEACTIVATED: |
| 863 | *bl += sprintf(b + *bl, "DEACTIVATED"); |
| 864 | break; |
| 865 | case TRANSPORT_DEVICE_SHUTDOWN: |
| 866 | *bl += sprintf(b + *bl, "SHUTDOWN"); |
| 867 | break; |
| 868 | case TRANSPORT_DEVICE_OFFLINE_ACTIVATED: |
| 869 | case TRANSPORT_DEVICE_OFFLINE_DEACTIVATED: |
| 870 | *bl += sprintf(b + *bl, "OFFLINE"); |
| 871 | break; |
| 872 | default: |
| 873 | *bl += sprintf(b + *bl, "UNKNOWN=%d", dev->dev_status); |
| 874 | break; |
| 875 | } |
| 876 | |
Nicholas Bellinger | 65586d5 | 2011-11-30 01:25:21 -0800 | [diff] [blame] | 877 | *bl += sprintf(b + *bl, " Execute/Max Queue Depth: %d/%d", |
| 878 | atomic_read(&dev->execute_tasks), dev->queue_depth); |
Nicholas Bellinger | 11e764b | 2012-05-09 12:42:09 -0700 | [diff] [blame] | 879 | *bl += sprintf(b + *bl, " SectorSize: %u HwMaxSectors: %u\n", |
| 880 | dev->se_sub_dev->se_dev_attrib.block_size, |
| 881 | dev->se_sub_dev->se_dev_attrib.hw_max_sectors); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 882 | *bl += sprintf(b + *bl, " "); |
| 883 | } |
| 884 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 885 | void transport_dump_vpd_proto_id( |
| 886 | struct t10_vpd *vpd, |
| 887 | unsigned char *p_buf, |
| 888 | int p_buf_len) |
| 889 | { |
| 890 | unsigned char buf[VPD_TMP_BUF_SIZE]; |
| 891 | int len; |
| 892 | |
| 893 | memset(buf, 0, VPD_TMP_BUF_SIZE); |
| 894 | len = sprintf(buf, "T10 VPD Protocol Identifier: "); |
| 895 | |
| 896 | switch (vpd->protocol_identifier) { |
| 897 | case 0x00: |
| 898 | sprintf(buf+len, "Fibre Channel\n"); |
| 899 | break; |
| 900 | case 0x10: |
| 901 | sprintf(buf+len, "Parallel SCSI\n"); |
| 902 | break; |
| 903 | case 0x20: |
| 904 | sprintf(buf+len, "SSA\n"); |
| 905 | break; |
| 906 | case 0x30: |
| 907 | sprintf(buf+len, "IEEE 1394\n"); |
| 908 | break; |
| 909 | case 0x40: |
| 910 | sprintf(buf+len, "SCSI Remote Direct Memory Access" |
| 911 | " Protocol\n"); |
| 912 | break; |
| 913 | case 0x50: |
| 914 | sprintf(buf+len, "Internet SCSI (iSCSI)\n"); |
| 915 | break; |
| 916 | case 0x60: |
| 917 | sprintf(buf+len, "SAS Serial SCSI Protocol\n"); |
| 918 | break; |
| 919 | case 0x70: |
| 920 | sprintf(buf+len, "Automation/Drive Interface Transport" |
| 921 | " Protocol\n"); |
| 922 | break; |
| 923 | case 0x80: |
| 924 | sprintf(buf+len, "AT Attachment Interface ATA/ATAPI\n"); |
| 925 | break; |
| 926 | default: |
| 927 | sprintf(buf+len, "Unknown 0x%02x\n", |
| 928 | vpd->protocol_identifier); |
| 929 | break; |
| 930 | } |
| 931 | |
| 932 | if (p_buf) |
| 933 | strncpy(p_buf, buf, p_buf_len); |
| 934 | else |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 935 | pr_debug("%s", buf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | void |
| 939 | transport_set_vpd_proto_id(struct t10_vpd *vpd, unsigned char *page_83) |
| 940 | { |
| 941 | /* |
| 942 | * Check if the Protocol Identifier Valid (PIV) bit is set.. |
| 943 | * |
| 944 | * from spc3r23.pdf section 7.5.1 |
| 945 | */ |
| 946 | if (page_83[1] & 0x80) { |
| 947 | vpd->protocol_identifier = (page_83[0] & 0xf0); |
| 948 | vpd->protocol_identifier_set = 1; |
| 949 | transport_dump_vpd_proto_id(vpd, NULL, 0); |
| 950 | } |
| 951 | } |
| 952 | EXPORT_SYMBOL(transport_set_vpd_proto_id); |
| 953 | |
| 954 | int transport_dump_vpd_assoc( |
| 955 | struct t10_vpd *vpd, |
| 956 | unsigned char *p_buf, |
| 957 | int p_buf_len) |
| 958 | { |
| 959 | unsigned char buf[VPD_TMP_BUF_SIZE]; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 960 | int ret = 0; |
| 961 | int len; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 962 | |
| 963 | memset(buf, 0, VPD_TMP_BUF_SIZE); |
| 964 | len = sprintf(buf, "T10 VPD Identifier Association: "); |
| 965 | |
| 966 | switch (vpd->association) { |
| 967 | case 0x00: |
| 968 | sprintf(buf+len, "addressed logical unit\n"); |
| 969 | break; |
| 970 | case 0x10: |
| 971 | sprintf(buf+len, "target port\n"); |
| 972 | break; |
| 973 | case 0x20: |
| 974 | sprintf(buf+len, "SCSI target device\n"); |
| 975 | break; |
| 976 | default: |
| 977 | sprintf(buf+len, "Unknown 0x%02x\n", vpd->association); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 978 | ret = -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 979 | break; |
| 980 | } |
| 981 | |
| 982 | if (p_buf) |
| 983 | strncpy(p_buf, buf, p_buf_len); |
| 984 | else |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 985 | pr_debug("%s", buf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 986 | |
| 987 | return ret; |
| 988 | } |
| 989 | |
| 990 | int transport_set_vpd_assoc(struct t10_vpd *vpd, unsigned char *page_83) |
| 991 | { |
| 992 | /* |
| 993 | * The VPD identification association.. |
| 994 | * |
| 995 | * from spc3r23.pdf Section 7.6.3.1 Table 297 |
| 996 | */ |
| 997 | vpd->association = (page_83[1] & 0x30); |
| 998 | return transport_dump_vpd_assoc(vpd, NULL, 0); |
| 999 | } |
| 1000 | EXPORT_SYMBOL(transport_set_vpd_assoc); |
| 1001 | |
| 1002 | int transport_dump_vpd_ident_type( |
| 1003 | struct t10_vpd *vpd, |
| 1004 | unsigned char *p_buf, |
| 1005 | int p_buf_len) |
| 1006 | { |
| 1007 | unsigned char buf[VPD_TMP_BUF_SIZE]; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1008 | int ret = 0; |
| 1009 | int len; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1010 | |
| 1011 | memset(buf, 0, VPD_TMP_BUF_SIZE); |
| 1012 | len = sprintf(buf, "T10 VPD Identifier Type: "); |
| 1013 | |
| 1014 | switch (vpd->device_identifier_type) { |
| 1015 | case 0x00: |
| 1016 | sprintf(buf+len, "Vendor specific\n"); |
| 1017 | break; |
| 1018 | case 0x01: |
| 1019 | sprintf(buf+len, "T10 Vendor ID based\n"); |
| 1020 | break; |
| 1021 | case 0x02: |
| 1022 | sprintf(buf+len, "EUI-64 based\n"); |
| 1023 | break; |
| 1024 | case 0x03: |
| 1025 | sprintf(buf+len, "NAA\n"); |
| 1026 | break; |
| 1027 | case 0x04: |
| 1028 | sprintf(buf+len, "Relative target port identifier\n"); |
| 1029 | break; |
| 1030 | case 0x08: |
| 1031 | sprintf(buf+len, "SCSI name string\n"); |
| 1032 | break; |
| 1033 | default: |
| 1034 | sprintf(buf+len, "Unsupported: 0x%02x\n", |
| 1035 | vpd->device_identifier_type); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1036 | ret = -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1037 | break; |
| 1038 | } |
| 1039 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1040 | if (p_buf) { |
| 1041 | if (p_buf_len < strlen(buf)+1) |
| 1042 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1043 | strncpy(p_buf, buf, p_buf_len); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1044 | } else { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1045 | pr_debug("%s", buf); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1046 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1047 | |
| 1048 | return ret; |
| 1049 | } |
| 1050 | |
| 1051 | int transport_set_vpd_ident_type(struct t10_vpd *vpd, unsigned char *page_83) |
| 1052 | { |
| 1053 | /* |
| 1054 | * The VPD identifier type.. |
| 1055 | * |
| 1056 | * from spc3r23.pdf Section 7.6.3.1 Table 298 |
| 1057 | */ |
| 1058 | vpd->device_identifier_type = (page_83[1] & 0x0f); |
| 1059 | return transport_dump_vpd_ident_type(vpd, NULL, 0); |
| 1060 | } |
| 1061 | EXPORT_SYMBOL(transport_set_vpd_ident_type); |
| 1062 | |
| 1063 | int transport_dump_vpd_ident( |
| 1064 | struct t10_vpd *vpd, |
| 1065 | unsigned char *p_buf, |
| 1066 | int p_buf_len) |
| 1067 | { |
| 1068 | unsigned char buf[VPD_TMP_BUF_SIZE]; |
| 1069 | int ret = 0; |
| 1070 | |
| 1071 | memset(buf, 0, VPD_TMP_BUF_SIZE); |
| 1072 | |
| 1073 | switch (vpd->device_identifier_code_set) { |
| 1074 | case 0x01: /* Binary */ |
| 1075 | sprintf(buf, "T10 VPD Binary Device Identifier: %s\n", |
| 1076 | &vpd->device_identifier[0]); |
| 1077 | break; |
| 1078 | case 0x02: /* ASCII */ |
| 1079 | sprintf(buf, "T10 VPD ASCII Device Identifier: %s\n", |
| 1080 | &vpd->device_identifier[0]); |
| 1081 | break; |
| 1082 | case 0x03: /* UTF-8 */ |
| 1083 | sprintf(buf, "T10 VPD UTF-8 Device Identifier: %s\n", |
| 1084 | &vpd->device_identifier[0]); |
| 1085 | break; |
| 1086 | default: |
| 1087 | sprintf(buf, "T10 VPD Device Identifier encoding unsupported:" |
| 1088 | " 0x%02x", vpd->device_identifier_code_set); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1089 | ret = -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1090 | break; |
| 1091 | } |
| 1092 | |
| 1093 | if (p_buf) |
| 1094 | strncpy(p_buf, buf, p_buf_len); |
| 1095 | else |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1096 | pr_debug("%s", buf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1097 | |
| 1098 | return ret; |
| 1099 | } |
| 1100 | |
| 1101 | int |
| 1102 | transport_set_vpd_ident(struct t10_vpd *vpd, unsigned char *page_83) |
| 1103 | { |
| 1104 | static const char hex_str[] = "0123456789abcdef"; |
| 1105 | int j = 0, i = 4; /* offset to start of the identifer */ |
| 1106 | |
| 1107 | /* |
| 1108 | * The VPD Code Set (encoding) |
| 1109 | * |
| 1110 | * from spc3r23.pdf Section 7.6.3.1 Table 296 |
| 1111 | */ |
| 1112 | vpd->device_identifier_code_set = (page_83[0] & 0x0f); |
| 1113 | switch (vpd->device_identifier_code_set) { |
| 1114 | case 0x01: /* Binary */ |
| 1115 | vpd->device_identifier[j++] = |
| 1116 | hex_str[vpd->device_identifier_type]; |
| 1117 | while (i < (4 + page_83[3])) { |
| 1118 | vpd->device_identifier[j++] = |
| 1119 | hex_str[(page_83[i] & 0xf0) >> 4]; |
| 1120 | vpd->device_identifier[j++] = |
| 1121 | hex_str[page_83[i] & 0x0f]; |
| 1122 | i++; |
| 1123 | } |
| 1124 | break; |
| 1125 | case 0x02: /* ASCII */ |
| 1126 | case 0x03: /* UTF-8 */ |
| 1127 | while (i < (4 + page_83[3])) |
| 1128 | vpd->device_identifier[j++] = page_83[i++]; |
| 1129 | break; |
| 1130 | default: |
| 1131 | break; |
| 1132 | } |
| 1133 | |
| 1134 | return transport_dump_vpd_ident(vpd, NULL, 0); |
| 1135 | } |
| 1136 | EXPORT_SYMBOL(transport_set_vpd_ident); |
| 1137 | |
| 1138 | static void core_setup_task_attr_emulation(struct se_device *dev) |
| 1139 | { |
| 1140 | /* |
| 1141 | * If this device is from Target_Core_Mod/pSCSI, disable the |
| 1142 | * SAM Task Attribute emulation. |
| 1143 | * |
| 1144 | * This is currently not available in upsream Linux/SCSI Target |
| 1145 | * mode code, and is assumed to be disabled while using TCM/pSCSI. |
| 1146 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1147 | if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1148 | dev->dev_task_attr_type = SAM_TASK_ATTR_PASSTHROUGH; |
| 1149 | return; |
| 1150 | } |
| 1151 | |
| 1152 | dev->dev_task_attr_type = SAM_TASK_ATTR_EMULATED; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1153 | pr_debug("%s: Using SAM_TASK_ATTR_EMULATED for SPC: 0x%02x" |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1154 | " device\n", dev->transport->name, |
| 1155 | dev->transport->get_device_rev(dev)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | static void scsi_dump_inquiry(struct se_device *dev) |
| 1159 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1160 | struct t10_wwn *wwn = &dev->se_sub_dev->t10_wwn; |
Sebastian Andrzej Siewior | e59a41b | 2012-01-10 14:16:57 +0100 | [diff] [blame] | 1161 | char buf[17]; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1162 | int i, device_type; |
| 1163 | /* |
| 1164 | * Print Linux/SCSI style INQUIRY formatting to the kernel ring buffer |
| 1165 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1166 | for (i = 0; i < 8; i++) |
| 1167 | if (wwn->vendor[i] >= 0x20) |
Sebastian Andrzej Siewior | e59a41b | 2012-01-10 14:16:57 +0100 | [diff] [blame] | 1168 | buf[i] = wwn->vendor[i]; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1169 | else |
Sebastian Andrzej Siewior | e59a41b | 2012-01-10 14:16:57 +0100 | [diff] [blame] | 1170 | buf[i] = ' '; |
| 1171 | buf[i] = '\0'; |
| 1172 | pr_debug(" Vendor: %s\n", buf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1173 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1174 | for (i = 0; i < 16; i++) |
| 1175 | if (wwn->model[i] >= 0x20) |
Sebastian Andrzej Siewior | e59a41b | 2012-01-10 14:16:57 +0100 | [diff] [blame] | 1176 | buf[i] = wwn->model[i]; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1177 | else |
Sebastian Andrzej Siewior | e59a41b | 2012-01-10 14:16:57 +0100 | [diff] [blame] | 1178 | buf[i] = ' '; |
| 1179 | buf[i] = '\0'; |
| 1180 | pr_debug(" Model: %s\n", buf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1181 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1182 | for (i = 0; i < 4; i++) |
| 1183 | if (wwn->revision[i] >= 0x20) |
Sebastian Andrzej Siewior | e59a41b | 2012-01-10 14:16:57 +0100 | [diff] [blame] | 1184 | buf[i] = wwn->revision[i]; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1185 | else |
Sebastian Andrzej Siewior | e59a41b | 2012-01-10 14:16:57 +0100 | [diff] [blame] | 1186 | buf[i] = ' '; |
| 1187 | buf[i] = '\0'; |
| 1188 | pr_debug(" Revision: %s\n", buf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1189 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1190 | device_type = dev->transport->get_device_type(dev); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1191 | pr_debug(" Type: %s ", scsi_device_type(device_type)); |
| 1192 | pr_debug(" ANSI SCSI revision: %02x\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1193 | dev->transport->get_device_rev(dev)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | struct se_device *transport_add_device_to_core_hba( |
| 1197 | struct se_hba *hba, |
| 1198 | struct se_subsystem_api *transport, |
| 1199 | struct se_subsystem_dev *se_dev, |
| 1200 | u32 device_flags, |
| 1201 | void *transport_dev, |
| 1202 | struct se_dev_limits *dev_limits, |
| 1203 | const char *inquiry_prod, |
| 1204 | const char *inquiry_rev) |
| 1205 | { |
Nicholas Bellinger | 12a18bd | 2011-03-14 04:06:06 -0700 | [diff] [blame] | 1206 | int force_pt; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1207 | struct se_device *dev; |
| 1208 | |
| 1209 | dev = kzalloc(sizeof(struct se_device), GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1210 | if (!dev) { |
| 1211 | pr_err("Unable to allocate memory for se_dev_t\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1212 | return NULL; |
| 1213 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1214 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1215 | transport_init_queue_obj(&dev->dev_queue_obj); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1216 | dev->dev_flags = device_flags; |
| 1217 | dev->dev_status |= TRANSPORT_DEVICE_DEACTIVATED; |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 1218 | dev->dev_ptr = transport_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1219 | dev->se_hba = hba; |
| 1220 | dev->se_sub_dev = se_dev; |
| 1221 | dev->transport = transport; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1222 | INIT_LIST_HEAD(&dev->dev_list); |
| 1223 | INIT_LIST_HEAD(&dev->dev_sep_list); |
| 1224 | INIT_LIST_HEAD(&dev->dev_tmr_list); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 1225 | INIT_LIST_HEAD(&dev->execute_list); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1226 | INIT_LIST_HEAD(&dev->delayed_cmd_list); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 1227 | INIT_LIST_HEAD(&dev->state_list); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 1228 | INIT_LIST_HEAD(&dev->qf_cmd_list); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1229 | spin_lock_init(&dev->execute_task_lock); |
| 1230 | spin_lock_init(&dev->delayed_cmd_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1231 | spin_lock_init(&dev->dev_reservation_lock); |
| 1232 | spin_lock_init(&dev->dev_status_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1233 | spin_lock_init(&dev->se_port_lock); |
| 1234 | spin_lock_init(&dev->se_tmr_lock); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 1235 | spin_lock_init(&dev->qf_cmd_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1236 | atomic_set(&dev->dev_ordered_id, 0); |
| 1237 | |
| 1238 | se_dev_set_default_attribs(dev, dev_limits); |
| 1239 | |
| 1240 | dev->dev_index = scsi_get_new_index(SCSI_DEVICE_INDEX); |
| 1241 | dev->creation_time = get_jiffies_64(); |
| 1242 | spin_lock_init(&dev->stats_lock); |
| 1243 | |
| 1244 | spin_lock(&hba->device_lock); |
| 1245 | list_add_tail(&dev->dev_list, &hba->hba_dev_list); |
| 1246 | hba->dev_count++; |
| 1247 | spin_unlock(&hba->device_lock); |
| 1248 | /* |
| 1249 | * Setup the SAM Task Attribute emulation for struct se_device |
| 1250 | */ |
| 1251 | core_setup_task_attr_emulation(dev); |
| 1252 | /* |
| 1253 | * Force PR and ALUA passthrough emulation with internal object use. |
| 1254 | */ |
| 1255 | force_pt = (hba->hba_flags & HBA_FLAGS_INTERNAL_USE); |
| 1256 | /* |
| 1257 | * Setup the Reservations infrastructure for struct se_device |
| 1258 | */ |
| 1259 | core_setup_reservations(dev, force_pt); |
| 1260 | /* |
| 1261 | * Setup the Asymmetric Logical Unit Assignment for struct se_device |
| 1262 | */ |
| 1263 | if (core_setup_alua(dev, force_pt) < 0) |
| 1264 | goto out; |
| 1265 | |
| 1266 | /* |
| 1267 | * Startup the struct se_device processing thread |
| 1268 | */ |
| 1269 | dev->process_thread = kthread_run(transport_processing_thread, dev, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1270 | "LIO_%s", dev->transport->name); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1271 | if (IS_ERR(dev->process_thread)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1272 | pr_err("Unable to create kthread: LIO_%s\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1273 | dev->transport->name); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1274 | goto out; |
| 1275 | } |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 1276 | /* |
| 1277 | * Setup work_queue for QUEUE_FULL |
| 1278 | */ |
| 1279 | INIT_WORK(&dev->qf_work_queue, target_qf_do_work); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1280 | /* |
| 1281 | * Preload the initial INQUIRY const values if we are doing |
| 1282 | * anything virtual (IBLOCK, FILEIO, RAMDISK), but not for TCM/pSCSI |
| 1283 | * passthrough because this is being provided by the backend LLD. |
| 1284 | * This is required so that transport_get_inquiry() copies these |
| 1285 | * originals once back into DEV_T10_WWN(dev) for the virtual device |
| 1286 | * setup. |
| 1287 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1288 | if (dev->transport->transport_type != TRANSPORT_PLUGIN_PHBA_PDEV) { |
Roland Dreier | f22c119 | 2011-05-02 22:15:37 -0700 | [diff] [blame] | 1289 | if (!inquiry_prod || !inquiry_rev) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1290 | pr_err("All non TCM/pSCSI plugins require" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1291 | " INQUIRY consts\n"); |
| 1292 | goto out; |
| 1293 | } |
| 1294 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1295 | strncpy(&dev->se_sub_dev->t10_wwn.vendor[0], "LIO-ORG", 8); |
| 1296 | strncpy(&dev->se_sub_dev->t10_wwn.model[0], inquiry_prod, 16); |
| 1297 | strncpy(&dev->se_sub_dev->t10_wwn.revision[0], inquiry_rev, 4); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1298 | } |
| 1299 | scsi_dump_inquiry(dev); |
| 1300 | |
Nicholas Bellinger | 12a18bd | 2011-03-14 04:06:06 -0700 | [diff] [blame] | 1301 | return dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1302 | out: |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1303 | kthread_stop(dev->process_thread); |
| 1304 | |
| 1305 | spin_lock(&hba->device_lock); |
| 1306 | list_del(&dev->dev_list); |
| 1307 | hba->dev_count--; |
| 1308 | spin_unlock(&hba->device_lock); |
| 1309 | |
| 1310 | se_release_vpd_for_dev(dev); |
| 1311 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1312 | kfree(dev); |
| 1313 | |
| 1314 | return NULL; |
| 1315 | } |
| 1316 | EXPORT_SYMBOL(transport_add_device_to_core_hba); |
| 1317 | |
| 1318 | /* transport_generic_prepare_cdb(): |
| 1319 | * |
| 1320 | * Since the Initiator sees iSCSI devices as LUNs, the SCSI CDB will |
| 1321 | * contain the iSCSI LUN in bits 7-5 of byte 1 as per SAM-2. |
| 1322 | * The point of this is since we are mapping iSCSI LUNs to |
| 1323 | * SCSI Target IDs having a non-zero LUN in the CDB will throw the |
| 1324 | * devices and HBAs for a loop. |
| 1325 | */ |
| 1326 | static inline void transport_generic_prepare_cdb( |
| 1327 | unsigned char *cdb) |
| 1328 | { |
| 1329 | switch (cdb[0]) { |
| 1330 | case READ_10: /* SBC - RDProtect */ |
| 1331 | case READ_12: /* SBC - RDProtect */ |
| 1332 | case READ_16: /* SBC - RDProtect */ |
| 1333 | case SEND_DIAGNOSTIC: /* SPC - SELF-TEST Code */ |
| 1334 | case VERIFY: /* SBC - VRProtect */ |
| 1335 | case VERIFY_16: /* SBC - VRProtect */ |
| 1336 | case WRITE_VERIFY: /* SBC - VRProtect */ |
| 1337 | case WRITE_VERIFY_12: /* SBC - VRProtect */ |
Nicholas Bellinger | ba53974 | 2012-05-16 21:52:10 -0700 | [diff] [blame] | 1338 | case MAINTENANCE_IN: /* SPC - Parameter Data Format for SA RTPG */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1339 | break; |
| 1340 | default: |
| 1341 | cdb[1] &= 0x1f; /* clear logical unit number */ |
| 1342 | break; |
| 1343 | } |
| 1344 | } |
| 1345 | |
Christoph Hellwig | 9b3b804 | 2012-05-20 11:59:12 -0400 | [diff] [blame] | 1346 | static int target_cmd_size_check(struct se_cmd *cmd, unsigned int size) |
| 1347 | { |
| 1348 | struct se_device *dev = cmd->se_dev; |
| 1349 | |
| 1350 | if (cmd->unknown_data_length) { |
| 1351 | cmd->data_length = size; |
| 1352 | } else if (size != cmd->data_length) { |
| 1353 | pr_warn("TARGET_CORE[%s]: Expected Transfer Length:" |
| 1354 | " %u does not match SCSI CDB Length: %u for SAM Opcode:" |
| 1355 | " 0x%02x\n", cmd->se_tfo->get_fabric_name(), |
| 1356 | cmd->data_length, size, cmd->t_task_cdb[0]); |
| 1357 | |
| 1358 | cmd->cmd_spdtl = size; |
| 1359 | |
| 1360 | if (cmd->data_direction == DMA_TO_DEVICE) { |
| 1361 | pr_err("Rejecting underflow/overflow" |
| 1362 | " WRITE data\n"); |
| 1363 | goto out_invalid_cdb_field; |
| 1364 | } |
| 1365 | /* |
| 1366 | * Reject READ_* or WRITE_* with overflow/underflow for |
| 1367 | * type SCF_SCSI_DATA_CDB. |
| 1368 | */ |
| 1369 | if (dev->se_sub_dev->se_dev_attrib.block_size != 512) { |
| 1370 | pr_err("Failing OVERFLOW/UNDERFLOW for LBA op" |
| 1371 | " CDB on non 512-byte sector setup subsystem" |
| 1372 | " plugin: %s\n", dev->transport->name); |
| 1373 | /* Returns CHECK_CONDITION + INVALID_CDB_FIELD */ |
| 1374 | goto out_invalid_cdb_field; |
| 1375 | } |
| 1376 | |
| 1377 | if (size > cmd->data_length) { |
| 1378 | cmd->se_cmd_flags |= SCF_OVERFLOW_BIT; |
| 1379 | cmd->residual_count = (size - cmd->data_length); |
| 1380 | } else { |
| 1381 | cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT; |
| 1382 | cmd->residual_count = (cmd->data_length - size); |
| 1383 | } |
| 1384 | cmd->data_length = size; |
| 1385 | } |
| 1386 | |
| 1387 | return 0; |
| 1388 | |
| 1389 | out_invalid_cdb_field: |
| 1390 | cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
| 1391 | cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD; |
| 1392 | return -EINVAL; |
| 1393 | } |
| 1394 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1395 | /* |
| 1396 | * Used by fabric modules containing a local struct se_cmd within their |
| 1397 | * fabric dependent per I/O descriptor. |
| 1398 | */ |
| 1399 | void transport_init_se_cmd( |
| 1400 | struct se_cmd *cmd, |
| 1401 | struct target_core_fabric_ops *tfo, |
| 1402 | struct se_session *se_sess, |
| 1403 | u32 data_length, |
| 1404 | int data_direction, |
| 1405 | int task_attr, |
| 1406 | unsigned char *sense_buffer) |
| 1407 | { |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 1408 | INIT_LIST_HEAD(&cmd->se_lun_node); |
| 1409 | INIT_LIST_HEAD(&cmd->se_delayed_node); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 1410 | INIT_LIST_HEAD(&cmd->se_qf_node); |
Roland Dreier | 79a7fef | 2011-09-28 22:12:07 -0700 | [diff] [blame] | 1411 | INIT_LIST_HEAD(&cmd->se_queue_node); |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 1412 | INIT_LIST_HEAD(&cmd->se_cmd_list); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 1413 | INIT_LIST_HEAD(&cmd->execute_list); |
| 1414 | INIT_LIST_HEAD(&cmd->state_list); |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 1415 | init_completion(&cmd->transport_lun_fe_stop_comp); |
| 1416 | init_completion(&cmd->transport_lun_stop_comp); |
| 1417 | init_completion(&cmd->t_transport_stop_comp); |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 1418 | init_completion(&cmd->cmd_wait_comp); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 1419 | init_completion(&cmd->task_stop_comp); |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 1420 | spin_lock_init(&cmd->t_state_lock); |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 1421 | cmd->transport_state = CMD_T_DEV_ACTIVE; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1422 | |
| 1423 | cmd->se_tfo = tfo; |
| 1424 | cmd->se_sess = se_sess; |
| 1425 | cmd->data_length = data_length; |
| 1426 | cmd->data_direction = data_direction; |
| 1427 | cmd->sam_task_attr = task_attr; |
| 1428 | cmd->sense_buffer = sense_buffer; |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 1429 | |
| 1430 | cmd->state_active = false; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1431 | } |
| 1432 | EXPORT_SYMBOL(transport_init_se_cmd); |
| 1433 | |
| 1434 | static int transport_check_alloc_task_attr(struct se_cmd *cmd) |
| 1435 | { |
| 1436 | /* |
| 1437 | * Check if SAM Task Attribute emulation is enabled for this |
| 1438 | * struct se_device storage object |
| 1439 | */ |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 1440 | if (cmd->se_dev->dev_task_attr_type != SAM_TASK_ATTR_EMULATED) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1441 | return 0; |
| 1442 | |
Nicholas Bellinger | e66ecd5 | 2011-05-19 20:19:14 -0700 | [diff] [blame] | 1443 | if (cmd->sam_task_attr == MSG_ACA_TAG) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1444 | pr_debug("SAM Task Attribute ACA" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1445 | " emulation is not supported\n"); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1446 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1447 | } |
| 1448 | /* |
| 1449 | * Used to determine when ORDERED commands should go from |
| 1450 | * Dormant to Active status. |
| 1451 | */ |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 1452 | cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1453 | smp_mb__after_atomic_inc(); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1454 | pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1455 | cmd->se_ordered_id, cmd->sam_task_attr, |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1456 | cmd->se_dev->transport->name); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1457 | return 0; |
| 1458 | } |
| 1459 | |
Andy Grover | a12f41f | 2012-04-03 15:51:20 -0700 | [diff] [blame] | 1460 | /* target_setup_cmd_from_cdb(): |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1461 | * |
| 1462 | * Called from fabric RX Thread. |
| 1463 | */ |
Andy Grover | a12f41f | 2012-04-03 15:51:20 -0700 | [diff] [blame] | 1464 | int target_setup_cmd_from_cdb( |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1465 | struct se_cmd *cmd, |
| 1466 | unsigned char *cdb) |
| 1467 | { |
Christoph Hellwig | cb4f4d3 | 2012-05-20 11:59:10 -0400 | [diff] [blame] | 1468 | struct se_subsystem_dev *su_dev = cmd->se_dev->se_sub_dev; |
| 1469 | u32 pr_reg_type = 0; |
| 1470 | u8 alua_ascq = 0; |
| 1471 | unsigned long flags; |
Christoph Hellwig | d6e0175 | 2012-05-20 11:59:14 -0400 | [diff] [blame^] | 1472 | unsigned int size; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1473 | int ret; |
| 1474 | |
| 1475 | transport_generic_prepare_cdb(cdb); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1476 | /* |
| 1477 | * Ensure that the received CDB is less than the max (252 + 8) bytes |
| 1478 | * for VARIABLE_LENGTH_CMD |
| 1479 | */ |
| 1480 | if (scsi_command_size(cdb) > SCSI_MAX_VARLEN_CDB_SIZE) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1481 | pr_err("Received SCSI CDB with command_size: %d that" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1482 | " exceeds SCSI_MAX_VARLEN_CDB_SIZE: %d\n", |
| 1483 | scsi_command_size(cdb), SCSI_MAX_VARLEN_CDB_SIZE); |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 1484 | cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
| 1485 | cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1486 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1487 | } |
| 1488 | /* |
| 1489 | * If the received CDB is larger than TCM_MAX_COMMAND_SIZE, |
| 1490 | * allocate the additional extended CDB buffer now.. Otherwise |
| 1491 | * setup the pointer from __t_task_cdb to t_task_cdb. |
| 1492 | */ |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 1493 | if (scsi_command_size(cdb) > sizeof(cmd->__t_task_cdb)) { |
| 1494 | cmd->t_task_cdb = kzalloc(scsi_command_size(cdb), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1495 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1496 | if (!cmd->t_task_cdb) { |
| 1497 | pr_err("Unable to allocate cmd->t_task_cdb" |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 1498 | " %u > sizeof(cmd->__t_task_cdb): %lu ops\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1499 | scsi_command_size(cdb), |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 1500 | (unsigned long)sizeof(cmd->__t_task_cdb)); |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 1501 | cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
| 1502 | cmd->scsi_sense_reason = |
| 1503 | TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1504 | return -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1505 | } |
| 1506 | } else |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 1507 | cmd->t_task_cdb = &cmd->__t_task_cdb[0]; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1508 | /* |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 1509 | * Copy the original CDB into cmd-> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1510 | */ |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 1511 | memcpy(cmd->t_task_cdb, cdb, scsi_command_size(cdb)); |
Christoph Hellwig | cb4f4d3 | 2012-05-20 11:59:10 -0400 | [diff] [blame] | 1512 | |
| 1513 | /* |
| 1514 | * Check for an existing UNIT ATTENTION condition |
| 1515 | */ |
| 1516 | if (core_scsi3_ua_check(cmd, cdb) < 0) { |
| 1517 | cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
| 1518 | cmd->scsi_sense_reason = TCM_CHECK_CONDITION_UNIT_ATTENTION; |
| 1519 | return -EINVAL; |
| 1520 | } |
| 1521 | |
| 1522 | ret = su_dev->t10_alua.alua_state_check(cmd, cdb, &alua_ascq); |
| 1523 | if (ret != 0) { |
| 1524 | /* |
| 1525 | * Set SCSI additional sense code (ASC) to 'LUN Not Accessible'; |
| 1526 | * The ALUA additional sense code qualifier (ASCQ) is determined |
| 1527 | * by the ALUA primary or secondary access state.. |
| 1528 | */ |
| 1529 | if (ret > 0) { |
| 1530 | pr_debug("[%s]: ALUA TG Port not available, " |
| 1531 | "SenseKey: NOT_READY, ASC/ASCQ: " |
| 1532 | "0x04/0x%02x\n", |
| 1533 | cmd->se_tfo->get_fabric_name(), alua_ascq); |
| 1534 | |
| 1535 | transport_set_sense_codes(cmd, 0x04, alua_ascq); |
| 1536 | cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
| 1537 | cmd->scsi_sense_reason = TCM_CHECK_CONDITION_NOT_READY; |
| 1538 | return -EINVAL; |
| 1539 | } |
| 1540 | cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
| 1541 | cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD; |
| 1542 | return -EINVAL; |
| 1543 | } |
| 1544 | |
| 1545 | /* |
| 1546 | * Check status for SPC-3 Persistent Reservations |
| 1547 | */ |
| 1548 | if (su_dev->t10_pr.pr_ops.t10_reservation_check(cmd, &pr_reg_type)) { |
| 1549 | if (su_dev->t10_pr.pr_ops.t10_seq_non_holder( |
| 1550 | cmd, cdb, pr_reg_type) != 0) { |
| 1551 | cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
| 1552 | cmd->se_cmd_flags |= SCF_SCSI_RESERVATION_CONFLICT; |
| 1553 | cmd->scsi_status = SAM_STAT_RESERVATION_CONFLICT; |
| 1554 | cmd->scsi_sense_reason = TCM_RESERVATION_CONFLICT; |
| 1555 | return -EBUSY; |
| 1556 | } |
| 1557 | /* |
| 1558 | * This means the CDB is allowed for the SCSI Initiator port |
| 1559 | * when said port is *NOT* holding the legacy SPC-2 or |
| 1560 | * SPC-3 Persistent Reservation. |
| 1561 | */ |
| 1562 | } |
| 1563 | |
Christoph Hellwig | d6e0175 | 2012-05-20 11:59:14 -0400 | [diff] [blame^] | 1564 | ret = cmd->se_dev->transport->parse_cdb(cmd, &size); |
| 1565 | if (ret < 0) |
| 1566 | return ret; |
| 1567 | |
| 1568 | ret = target_cmd_size_check(cmd, size); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1569 | if (ret < 0) |
| 1570 | return ret; |
Christoph Hellwig | cb4f4d3 | 2012-05-20 11:59:10 -0400 | [diff] [blame] | 1571 | |
| 1572 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
| 1573 | cmd->se_cmd_flags |= SCF_SUPPORTED_SAM_OPCODE; |
| 1574 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
| 1575 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1576 | /* |
| 1577 | * Check for SAM Task Attribute Emulation |
| 1578 | */ |
| 1579 | if (transport_check_alloc_task_attr(cmd) < 0) { |
| 1580 | cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
| 1581 | cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD; |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 1582 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1583 | } |
| 1584 | spin_lock(&cmd->se_lun->lun_sep_lock); |
| 1585 | if (cmd->se_lun->lun_sep) |
| 1586 | cmd->se_lun->lun_sep->sep_stats.cmd_pdus++; |
| 1587 | spin_unlock(&cmd->se_lun->lun_sep_lock); |
| 1588 | return 0; |
| 1589 | } |
Andy Grover | a12f41f | 2012-04-03 15:51:20 -0700 | [diff] [blame] | 1590 | EXPORT_SYMBOL(target_setup_cmd_from_cdb); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1591 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1592 | /* |
Nicholas Bellinger | 695434e1 | 2011-06-03 20:59:19 -0700 | [diff] [blame] | 1593 | * Used by fabric module frontends to queue tasks directly. |
| 1594 | * Many only be used from process context only |
| 1595 | */ |
| 1596 | int transport_handle_cdb_direct( |
| 1597 | struct se_cmd *cmd) |
| 1598 | { |
Nicholas Bellinger | dd8ae59 | 2011-07-30 05:03:58 -0700 | [diff] [blame] | 1599 | int ret; |
| 1600 | |
Nicholas Bellinger | 695434e1 | 2011-06-03 20:59:19 -0700 | [diff] [blame] | 1601 | if (!cmd->se_lun) { |
| 1602 | dump_stack(); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1603 | pr_err("cmd->se_lun is NULL\n"); |
Nicholas Bellinger | 695434e1 | 2011-06-03 20:59:19 -0700 | [diff] [blame] | 1604 | return -EINVAL; |
| 1605 | } |
| 1606 | if (in_interrupt()) { |
| 1607 | dump_stack(); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1608 | pr_err("transport_generic_handle_cdb cannot be called" |
Nicholas Bellinger | 695434e1 | 2011-06-03 20:59:19 -0700 | [diff] [blame] | 1609 | " from interrupt context\n"); |
| 1610 | return -EINVAL; |
| 1611 | } |
Nicholas Bellinger | dd8ae59 | 2011-07-30 05:03:58 -0700 | [diff] [blame] | 1612 | /* |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 1613 | * Set TRANSPORT_NEW_CMD state and CMD_T_ACTIVE following |
Nicholas Bellinger | dd8ae59 | 2011-07-30 05:03:58 -0700 | [diff] [blame] | 1614 | * transport_generic_handle_cdb*() -> transport_add_cmd_to_queue() |
| 1615 | * in existing usage to ensure that outstanding descriptors are handled |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 1616 | * correctly during shutdown via transport_wait_for_tasks() |
Nicholas Bellinger | dd8ae59 | 2011-07-30 05:03:58 -0700 | [diff] [blame] | 1617 | * |
| 1618 | * Also, we don't take cmd->t_state_lock here as we only expect |
| 1619 | * this to be called for initial descriptor submission. |
| 1620 | */ |
| 1621 | cmd->t_state = TRANSPORT_NEW_CMD; |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 1622 | cmd->transport_state |= CMD_T_ACTIVE; |
| 1623 | |
Nicholas Bellinger | dd8ae59 | 2011-07-30 05:03:58 -0700 | [diff] [blame] | 1624 | /* |
| 1625 | * transport_generic_new_cmd() is already handling QUEUE_FULL, |
| 1626 | * so follow TRANSPORT_NEW_CMD processing thread context usage |
| 1627 | * and call transport_generic_request_failure() if necessary.. |
| 1628 | */ |
| 1629 | ret = transport_generic_new_cmd(cmd); |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 1630 | if (ret < 0) |
| 1631 | transport_generic_request_failure(cmd); |
| 1632 | |
Nicholas Bellinger | dd8ae59 | 2011-07-30 05:03:58 -0700 | [diff] [blame] | 1633 | return 0; |
Nicholas Bellinger | 695434e1 | 2011-06-03 20:59:19 -0700 | [diff] [blame] | 1634 | } |
| 1635 | EXPORT_SYMBOL(transport_handle_cdb_direct); |
| 1636 | |
Nicholas Bellinger | a636078 | 2011-11-18 20:36:22 -0800 | [diff] [blame] | 1637 | /** |
| 1638 | * target_submit_cmd - lookup unpacked lun and submit uninitialized se_cmd |
| 1639 | * |
| 1640 | * @se_cmd: command descriptor to submit |
| 1641 | * @se_sess: associated se_sess for endpoint |
| 1642 | * @cdb: pointer to SCSI CDB |
| 1643 | * @sense: pointer to SCSI sense buffer |
| 1644 | * @unpacked_lun: unpacked LUN to reference for struct se_lun |
| 1645 | * @data_length: fabric expected data transfer length |
| 1646 | * @task_addr: SAM task attribute |
| 1647 | * @data_dir: DMA data direction |
| 1648 | * @flags: flags for command submission from target_sc_flags_tables |
| 1649 | * |
| 1650 | * This may only be called from process context, and also currently |
| 1651 | * assumes internal allocation of fabric payload buffer by target-core. |
| 1652 | **/ |
Andy Grover | 1edcdb4 | 2012-01-19 13:39:23 -0800 | [diff] [blame] | 1653 | void target_submit_cmd(struct se_cmd *se_cmd, struct se_session *se_sess, |
Nicholas Bellinger | a636078 | 2011-11-18 20:36:22 -0800 | [diff] [blame] | 1654 | unsigned char *cdb, unsigned char *sense, u32 unpacked_lun, |
| 1655 | u32 data_length, int task_attr, int data_dir, int flags) |
| 1656 | { |
| 1657 | struct se_portal_group *se_tpg; |
| 1658 | int rc; |
| 1659 | |
| 1660 | se_tpg = se_sess->se_tpg; |
| 1661 | BUG_ON(!se_tpg); |
| 1662 | BUG_ON(se_cmd->se_tfo || se_cmd->se_sess); |
| 1663 | BUG_ON(in_interrupt()); |
| 1664 | /* |
| 1665 | * Initialize se_cmd for target operation. From this point |
| 1666 | * exceptions are handled by sending exception status via |
| 1667 | * target_core_fabric_ops->queue_status() callback |
| 1668 | */ |
| 1669 | transport_init_se_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess, |
| 1670 | data_length, data_dir, task_attr, sense); |
Sebastian Andrzej Siewior | b0d7994 | 2012-01-10 14:16:59 +0100 | [diff] [blame] | 1671 | if (flags & TARGET_SCF_UNKNOWN_SIZE) |
| 1672 | se_cmd->unknown_data_length = 1; |
Nicholas Bellinger | a636078 | 2011-11-18 20:36:22 -0800 | [diff] [blame] | 1673 | /* |
| 1674 | * Obtain struct se_cmd->cmd_kref reference and add new cmd to |
| 1675 | * se_sess->sess_cmd_list. A second kref_get here is necessary |
| 1676 | * for fabrics using TARGET_SCF_ACK_KREF that expect a second |
| 1677 | * kref_put() to happen during fabric packet acknowledgement. |
| 1678 | */ |
| 1679 | target_get_sess_cmd(se_sess, se_cmd, (flags & TARGET_SCF_ACK_KREF)); |
| 1680 | /* |
| 1681 | * Signal bidirectional data payloads to target-core |
| 1682 | */ |
| 1683 | if (flags & TARGET_SCF_BIDI_OP) |
| 1684 | se_cmd->se_cmd_flags |= SCF_BIDI; |
| 1685 | /* |
| 1686 | * Locate se_lun pointer and attach it to struct se_cmd |
| 1687 | */ |
Nicholas Bellinger | 735703c | 2012-01-20 19:02:56 -0800 | [diff] [blame] | 1688 | if (transport_lookup_cmd_lun(se_cmd, unpacked_lun) < 0) { |
| 1689 | transport_send_check_condition_and_sense(se_cmd, |
| 1690 | se_cmd->scsi_sense_reason, 0); |
| 1691 | target_put_sess_cmd(se_sess, se_cmd); |
| 1692 | return; |
| 1693 | } |
Christoph Hellwig | d6e0175 | 2012-05-20 11:59:14 -0400 | [diff] [blame^] | 1694 | |
Andy Grover | a12f41f | 2012-04-03 15:51:20 -0700 | [diff] [blame] | 1695 | rc = target_setup_cmd_from_cdb(se_cmd, cdb); |
Nicholas Bellinger | 735703c | 2012-01-20 19:02:56 -0800 | [diff] [blame] | 1696 | if (rc != 0) { |
| 1697 | transport_generic_request_failure(se_cmd); |
| 1698 | return; |
| 1699 | } |
Andy Grover | 11e319e | 2012-04-03 15:51:28 -0700 | [diff] [blame] | 1700 | |
| 1701 | /* |
| 1702 | * Check if we need to delay processing because of ALUA |
| 1703 | * Active/NonOptimized primary access state.. |
| 1704 | */ |
| 1705 | core_alua_check_nonop_delay(se_cmd); |
| 1706 | |
Nicholas Bellinger | a636078 | 2011-11-18 20:36:22 -0800 | [diff] [blame] | 1707 | /* |
| 1708 | * Dispatch se_cmd descriptor to se_lun->lun_se_dev backend |
| 1709 | * for immediate execution of READs, otherwise wait for |
| 1710 | * transport_generic_handle_data() to be called for WRITEs |
| 1711 | * when fabric has filled the incoming buffer. |
| 1712 | */ |
| 1713 | transport_handle_cdb_direct(se_cmd); |
Andy Grover | 1edcdb4 | 2012-01-19 13:39:23 -0800 | [diff] [blame] | 1714 | return; |
Nicholas Bellinger | a636078 | 2011-11-18 20:36:22 -0800 | [diff] [blame] | 1715 | } |
| 1716 | EXPORT_SYMBOL(target_submit_cmd); |
| 1717 | |
Nicholas Bellinger | 9f0d05c | 2012-02-25 05:02:48 -0800 | [diff] [blame] | 1718 | static void target_complete_tmr_failure(struct work_struct *work) |
| 1719 | { |
| 1720 | struct se_cmd *se_cmd = container_of(work, struct se_cmd, work); |
| 1721 | |
| 1722 | se_cmd->se_tmr_req->response = TMR_LUN_DOES_NOT_EXIST; |
| 1723 | se_cmd->se_tfo->queue_tm_rsp(se_cmd); |
| 1724 | transport_generic_free_cmd(se_cmd, 0); |
| 1725 | } |
| 1726 | |
Andy Grover | ea98d7f | 2012-01-19 13:39:21 -0800 | [diff] [blame] | 1727 | /** |
| 1728 | * target_submit_tmr - lookup unpacked lun and submit uninitialized se_cmd |
| 1729 | * for TMR CDBs |
| 1730 | * |
| 1731 | * @se_cmd: command descriptor to submit |
| 1732 | * @se_sess: associated se_sess for endpoint |
| 1733 | * @sense: pointer to SCSI sense buffer |
| 1734 | * @unpacked_lun: unpacked LUN to reference for struct se_lun |
| 1735 | * @fabric_context: fabric context for TMR req |
| 1736 | * @tm_type: Type of TM request |
Nicholas Bellinger | c0974f8 | 2012-02-25 05:10:04 -0800 | [diff] [blame] | 1737 | * @gfp: gfp type for caller |
| 1738 | * @tag: referenced task tag for TMR_ABORT_TASK |
Nicholas Bellinger | c7042ca | 2012-02-25 01:40:24 -0800 | [diff] [blame] | 1739 | * @flags: submit cmd flags |
Andy Grover | ea98d7f | 2012-01-19 13:39:21 -0800 | [diff] [blame] | 1740 | * |
| 1741 | * Callable from all contexts. |
| 1742 | **/ |
| 1743 | |
Nicholas Bellinger | c7042ca | 2012-02-25 01:40:24 -0800 | [diff] [blame] | 1744 | int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess, |
Andy Grover | ea98d7f | 2012-01-19 13:39:21 -0800 | [diff] [blame] | 1745 | unsigned char *sense, u32 unpacked_lun, |
Nicholas Bellinger | c0974f8 | 2012-02-25 05:10:04 -0800 | [diff] [blame] | 1746 | void *fabric_tmr_ptr, unsigned char tm_type, |
| 1747 | gfp_t gfp, unsigned int tag, int flags) |
Andy Grover | ea98d7f | 2012-01-19 13:39:21 -0800 | [diff] [blame] | 1748 | { |
| 1749 | struct se_portal_group *se_tpg; |
| 1750 | int ret; |
| 1751 | |
| 1752 | se_tpg = se_sess->se_tpg; |
| 1753 | BUG_ON(!se_tpg); |
| 1754 | |
| 1755 | transport_init_se_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess, |
| 1756 | 0, DMA_NONE, MSG_SIMPLE_TAG, sense); |
Nicholas Bellinger | c7042ca | 2012-02-25 01:40:24 -0800 | [diff] [blame] | 1757 | /* |
| 1758 | * FIXME: Currently expect caller to handle se_cmd->se_tmr_req |
| 1759 | * allocation failure. |
| 1760 | */ |
Nicholas Bellinger | c0974f8 | 2012-02-25 05:10:04 -0800 | [diff] [blame] | 1761 | ret = core_tmr_alloc_req(se_cmd, fabric_tmr_ptr, tm_type, gfp); |
Nicholas Bellinger | c7042ca | 2012-02-25 01:40:24 -0800 | [diff] [blame] | 1762 | if (ret < 0) |
| 1763 | return -ENOMEM; |
Andy Grover | ea98d7f | 2012-01-19 13:39:21 -0800 | [diff] [blame] | 1764 | |
Nicholas Bellinger | c0974f8 | 2012-02-25 05:10:04 -0800 | [diff] [blame] | 1765 | if (tm_type == TMR_ABORT_TASK) |
| 1766 | se_cmd->se_tmr_req->ref_task_tag = tag; |
| 1767 | |
Andy Grover | ea98d7f | 2012-01-19 13:39:21 -0800 | [diff] [blame] | 1768 | /* See target_submit_cmd for commentary */ |
| 1769 | target_get_sess_cmd(se_sess, se_cmd, (flags & TARGET_SCF_ACK_KREF)); |
| 1770 | |
Andy Grover | ea98d7f | 2012-01-19 13:39:21 -0800 | [diff] [blame] | 1771 | ret = transport_lookup_tmr_lun(se_cmd, unpacked_lun); |
| 1772 | if (ret) { |
Nicholas Bellinger | 9f0d05c | 2012-02-25 05:02:48 -0800 | [diff] [blame] | 1773 | /* |
| 1774 | * For callback during failure handling, push this work off |
| 1775 | * to process context with TMR_LUN_DOES_NOT_EXIST status. |
| 1776 | */ |
| 1777 | INIT_WORK(&se_cmd->work, target_complete_tmr_failure); |
| 1778 | schedule_work(&se_cmd->work); |
Nicholas Bellinger | c7042ca | 2012-02-25 01:40:24 -0800 | [diff] [blame] | 1779 | return 0; |
Andy Grover | ea98d7f | 2012-01-19 13:39:21 -0800 | [diff] [blame] | 1780 | } |
| 1781 | transport_generic_handle_tmr(se_cmd); |
Nicholas Bellinger | c7042ca | 2012-02-25 01:40:24 -0800 | [diff] [blame] | 1782 | return 0; |
Andy Grover | ea98d7f | 2012-01-19 13:39:21 -0800 | [diff] [blame] | 1783 | } |
| 1784 | EXPORT_SYMBOL(target_submit_tmr); |
| 1785 | |
Nicholas Bellinger | 695434e1 | 2011-06-03 20:59:19 -0700 | [diff] [blame] | 1786 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1787 | * Used by fabric module frontends defining a TFO->new_cmd_map() caller |
| 1788 | * to queue up a newly setup se_cmd w/ TRANSPORT_NEW_CMD_MAP in order to |
| 1789 | * complete setup in TCM process context w/ TFO->new_cmd_map(). |
| 1790 | */ |
| 1791 | int transport_generic_handle_cdb_map( |
| 1792 | struct se_cmd *cmd) |
| 1793 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1794 | if (!cmd->se_lun) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1795 | dump_stack(); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1796 | pr_err("cmd->se_lun is NULL\n"); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1797 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1798 | } |
| 1799 | |
Christoph Hellwig | f7a5cc0 | 2011-10-17 13:56:42 -0400 | [diff] [blame] | 1800 | transport_add_cmd_to_queue(cmd, TRANSPORT_NEW_CMD_MAP, false); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1801 | return 0; |
| 1802 | } |
| 1803 | EXPORT_SYMBOL(transport_generic_handle_cdb_map); |
| 1804 | |
| 1805 | /* transport_generic_handle_data(): |
| 1806 | * |
| 1807 | * |
| 1808 | */ |
| 1809 | int transport_generic_handle_data( |
| 1810 | struct se_cmd *cmd) |
| 1811 | { |
| 1812 | /* |
| 1813 | * For the software fabric case, then we assume the nexus is being |
| 1814 | * failed/shutdown when signals are pending from the kthread context |
| 1815 | * caller, so we return a failure. For the HW target mode case running |
| 1816 | * in interrupt code, the signal_pending() check is skipped. |
| 1817 | */ |
| 1818 | if (!in_interrupt() && signal_pending(current)) |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1819 | return -EPERM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1820 | /* |
| 1821 | * If the received CDB has aleady been ABORTED by the generic |
| 1822 | * target engine, we now call transport_check_aborted_status() |
| 1823 | * to queue any delated TASK_ABORTED status for the received CDB to the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1824 | * fabric module as we are expecting no further incoming DATA OUT |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1825 | * sequences at this point. |
| 1826 | */ |
| 1827 | if (transport_check_aborted_status(cmd, 1) != 0) |
| 1828 | return 0; |
| 1829 | |
Christoph Hellwig | f7a5cc0 | 2011-10-17 13:56:42 -0400 | [diff] [blame] | 1830 | transport_add_cmd_to_queue(cmd, TRANSPORT_PROCESS_WRITE, false); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1831 | return 0; |
| 1832 | } |
| 1833 | EXPORT_SYMBOL(transport_generic_handle_data); |
| 1834 | |
| 1835 | /* transport_generic_handle_tmr(): |
| 1836 | * |
| 1837 | * |
| 1838 | */ |
| 1839 | int transport_generic_handle_tmr( |
| 1840 | struct se_cmd *cmd) |
| 1841 | { |
Christoph Hellwig | f7a5cc0 | 2011-10-17 13:56:42 -0400 | [diff] [blame] | 1842 | transport_add_cmd_to_queue(cmd, TRANSPORT_PROCESS_TMR, false); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1843 | return 0; |
| 1844 | } |
| 1845 | EXPORT_SYMBOL(transport_generic_handle_tmr); |
| 1846 | |
Christoph Hellwig | cdbb70b | 2011-10-17 13:56:46 -0400 | [diff] [blame] | 1847 | /* |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 1848 | * If the cmd is active, request it to be stopped and sleep until it |
Christoph Hellwig | cdbb70b | 2011-10-17 13:56:46 -0400 | [diff] [blame] | 1849 | * has completed. |
| 1850 | */ |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 1851 | bool target_stop_cmd(struct se_cmd *cmd, unsigned long *flags) |
Christoph Hellwig | cdbb70b | 2011-10-17 13:56:46 -0400 | [diff] [blame] | 1852 | { |
Christoph Hellwig | cdbb70b | 2011-10-17 13:56:46 -0400 | [diff] [blame] | 1853 | bool was_active = false; |
| 1854 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 1855 | if (cmd->transport_state & CMD_T_BUSY) { |
| 1856 | cmd->transport_state |= CMD_T_REQUEST_STOP; |
Christoph Hellwig | cdbb70b | 2011-10-17 13:56:46 -0400 | [diff] [blame] | 1857 | spin_unlock_irqrestore(&cmd->t_state_lock, *flags); |
| 1858 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 1859 | pr_debug("cmd %p waiting to complete\n", cmd); |
| 1860 | wait_for_completion(&cmd->task_stop_comp); |
| 1861 | pr_debug("cmd %p stopped successfully\n", cmd); |
Christoph Hellwig | cdbb70b | 2011-10-17 13:56:46 -0400 | [diff] [blame] | 1862 | |
| 1863 | spin_lock_irqsave(&cmd->t_state_lock, *flags); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 1864 | cmd->transport_state &= ~CMD_T_REQUEST_STOP; |
| 1865 | cmd->transport_state &= ~CMD_T_BUSY; |
Christoph Hellwig | cdbb70b | 2011-10-17 13:56:46 -0400 | [diff] [blame] | 1866 | was_active = true; |
| 1867 | } |
| 1868 | |
Christoph Hellwig | cdbb70b | 2011-10-17 13:56:46 -0400 | [diff] [blame] | 1869 | return was_active; |
| 1870 | } |
| 1871 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1872 | /* |
| 1873 | * Handle SAM-esque emulation for generic transport request failures. |
| 1874 | */ |
Nicholas Bellinger | 2fbff12 | 2012-02-10 16:18:11 -0800 | [diff] [blame] | 1875 | void transport_generic_request_failure(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1876 | { |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 1877 | int ret = 0; |
| 1878 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1879 | pr_debug("-----[ Storage Engine Exception for cmd: %p ITT: 0x%08x" |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1880 | " CDB: 0x%02x\n", cmd, cmd->se_tfo->get_task_tag(cmd), |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 1881 | cmd->t_task_cdb[0]); |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 1882 | pr_debug("-----[ i_state: %d t_state: %d scsi_sense_reason: %d\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1883 | cmd->se_tfo->get_cmd_state(cmd), |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 1884 | cmd->t_state, cmd->scsi_sense_reason); |
Christoph Hellwig | d43d6ae | 2012-04-24 00:25:08 -0400 | [diff] [blame] | 1885 | pr_debug("-----[ CMD_T_ACTIVE: %d CMD_T_STOP: %d CMD_T_SENT: %d\n", |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 1886 | (cmd->transport_state & CMD_T_ACTIVE) != 0, |
| 1887 | (cmd->transport_state & CMD_T_STOP) != 0, |
| 1888 | (cmd->transport_state & CMD_T_SENT) != 0); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1889 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1890 | /* |
| 1891 | * For SAM Task Attribute emulation for failed struct se_cmd |
| 1892 | */ |
| 1893 | if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED) |
| 1894 | transport_complete_task_attr(cmd); |
| 1895 | |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 1896 | switch (cmd->scsi_sense_reason) { |
| 1897 | case TCM_NON_EXISTENT_LUN: |
| 1898 | case TCM_UNSUPPORTED_SCSI_OPCODE: |
| 1899 | case TCM_INVALID_CDB_FIELD: |
| 1900 | case TCM_INVALID_PARAMETER_LIST: |
| 1901 | case TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE: |
| 1902 | case TCM_UNKNOWN_MODE_PAGE: |
| 1903 | case TCM_WRITE_PROTECTED: |
| 1904 | case TCM_CHECK_CONDITION_ABORT_CMD: |
| 1905 | case TCM_CHECK_CONDITION_UNIT_ATTENTION: |
| 1906 | case TCM_CHECK_CONDITION_NOT_READY: |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1907 | break; |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 1908 | case TCM_RESERVATION_CONFLICT: |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1909 | /* |
| 1910 | * No SENSE Data payload for this case, set SCSI Status |
| 1911 | * and queue the response to $FABRIC_MOD. |
| 1912 | * |
| 1913 | * Uses linux/include/scsi/scsi.h SAM status codes defs |
| 1914 | */ |
| 1915 | cmd->scsi_status = SAM_STAT_RESERVATION_CONFLICT; |
| 1916 | /* |
| 1917 | * For UA Interlock Code 11b, a RESERVATION CONFLICT will |
| 1918 | * establish a UNIT ATTENTION with PREVIOUS RESERVATION |
| 1919 | * CONFLICT STATUS. |
| 1920 | * |
| 1921 | * See spc4r17, section 7.4.6 Control Mode Page, Table 349 |
| 1922 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1923 | if (cmd->se_sess && |
| 1924 | cmd->se_dev->se_sub_dev->se_dev_attrib.emulate_ua_intlck_ctrl == 2) |
| 1925 | core_scsi3_ua_allocate(cmd->se_sess->se_node_acl, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1926 | cmd->orig_fe_lun, 0x2C, |
| 1927 | ASCQ_2CH_PREVIOUS_RESERVATION_CONFLICT_STATUS); |
| 1928 | |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 1929 | ret = cmd->se_tfo->queue_status(cmd); |
Nicholas Bellinger | f147abb | 2011-10-25 23:57:41 -0700 | [diff] [blame] | 1930 | if (ret == -EAGAIN || ret == -ENOMEM) |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 1931 | goto queue_full; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1932 | goto check_stop; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1933 | default: |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1934 | pr_err("Unknown transport error for CDB 0x%02x: %d\n", |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 1935 | cmd->t_task_cdb[0], cmd->scsi_sense_reason); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1936 | cmd->scsi_sense_reason = TCM_UNSUPPORTED_SCSI_OPCODE; |
| 1937 | break; |
| 1938 | } |
Nicholas Bellinger | 16ab8e6 | 2011-08-08 19:03:38 -0700 | [diff] [blame] | 1939 | /* |
| 1940 | * If a fabric does not define a cmd->se_tfo->new_cmd_map caller, |
| 1941 | * make the call to transport_send_check_condition_and_sense() |
| 1942 | * directly. Otherwise expect the fabric to make the call to |
| 1943 | * transport_send_check_condition_and_sense() after handling |
| 1944 | * possible unsoliticied write data payloads. |
| 1945 | */ |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 1946 | ret = transport_send_check_condition_and_sense(cmd, |
| 1947 | cmd->scsi_sense_reason, 0); |
| 1948 | if (ret == -EAGAIN || ret == -ENOMEM) |
| 1949 | goto queue_full; |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 1950 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1951 | check_stop: |
| 1952 | transport_lun_remove_cmd(cmd); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1953 | if (!transport_cmd_check_stop_to_fabric(cmd)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1954 | ; |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 1955 | return; |
| 1956 | |
| 1957 | queue_full: |
Christoph Hellwig | e057f53 | 2011-10-17 13:56:41 -0400 | [diff] [blame] | 1958 | cmd->t_state = TRANSPORT_COMPLETE_QF_OK; |
| 1959 | transport_handle_queue_full(cmd, cmd->se_dev); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1960 | } |
Nicholas Bellinger | 2fbff12 | 2012-02-10 16:18:11 -0800 | [diff] [blame] | 1961 | EXPORT_SYMBOL(transport_generic_request_failure); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1962 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1963 | /* |
| 1964 | * Called from Fabric Module context from transport_execute_tasks() |
| 1965 | * |
| 1966 | * The return of this function determins if the tasks from struct se_cmd |
| 1967 | * get added to the execution queue in transport_execute_tasks(), |
| 1968 | * or are added to the delayed or ordered lists here. |
| 1969 | */ |
| 1970 | static inline int transport_execute_task_attr(struct se_cmd *cmd) |
| 1971 | { |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 1972 | if (cmd->se_dev->dev_task_attr_type != SAM_TASK_ATTR_EMULATED) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1973 | return 1; |
| 1974 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1975 | * Check for the existence of HEAD_OF_QUEUE, and if true return 1 |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1976 | * to allow the passed struct se_cmd list of tasks to the front of the list. |
| 1977 | */ |
Nicholas Bellinger | e66ecd5 | 2011-05-19 20:19:14 -0700 | [diff] [blame] | 1978 | if (cmd->sam_task_attr == MSG_HEAD_TAG) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1979 | pr_debug("Added HEAD_OF_QUEUE for CDB:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1980 | " 0x%02x, se_ordered_id: %u\n", |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1981 | cmd->t_task_cdb[0], |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1982 | cmd->se_ordered_id); |
| 1983 | return 1; |
Nicholas Bellinger | e66ecd5 | 2011-05-19 20:19:14 -0700 | [diff] [blame] | 1984 | } else if (cmd->sam_task_attr == MSG_ORDERED_TAG) { |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 1985 | atomic_inc(&cmd->se_dev->dev_ordered_sync); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1986 | smp_mb__after_atomic_inc(); |
| 1987 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1988 | pr_debug("Added ORDERED for CDB: 0x%02x to ordered" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1989 | " list, se_ordered_id: %u\n", |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 1990 | cmd->t_task_cdb[0], |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1991 | cmd->se_ordered_id); |
| 1992 | /* |
| 1993 | * Add ORDERED command to tail of execution queue if |
| 1994 | * no other older commands exist that need to be |
| 1995 | * completed first. |
| 1996 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1997 | if (!atomic_read(&cmd->se_dev->simple_cmds)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1998 | return 1; |
| 1999 | } else { |
| 2000 | /* |
| 2001 | * For SIMPLE and UNTAGGED Task Attribute commands |
| 2002 | */ |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 2003 | atomic_inc(&cmd->se_dev->simple_cmds); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2004 | smp_mb__after_atomic_inc(); |
| 2005 | } |
| 2006 | /* |
| 2007 | * Otherwise if one or more outstanding ORDERED task attribute exist, |
| 2008 | * add the dormant task(s) built for the passed struct se_cmd to the |
| 2009 | * execution queue and become in Active state for this struct se_device. |
| 2010 | */ |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 2011 | if (atomic_read(&cmd->se_dev->dev_ordered_sync) != 0) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2012 | /* |
| 2013 | * Otherwise, add cmd w/ tasks to delayed cmd queue that |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2014 | * will be drained upon completion of HEAD_OF_QUEUE task. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2015 | */ |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 2016 | spin_lock(&cmd->se_dev->delayed_cmd_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2017 | cmd->se_cmd_flags |= SCF_DELAYED_CMD_FROM_SAM_ATTR; |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 2018 | list_add_tail(&cmd->se_delayed_node, |
| 2019 | &cmd->se_dev->delayed_cmd_list); |
| 2020 | spin_unlock(&cmd->se_dev->delayed_cmd_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2021 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2022 | pr_debug("Added CDB: 0x%02x Task Attr: 0x%02x to" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2023 | " delayed CMD list, se_ordered_id: %u\n", |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2024 | cmd->t_task_cdb[0], cmd->sam_task_attr, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2025 | cmd->se_ordered_id); |
| 2026 | /* |
| 2027 | * Return zero to let transport_execute_tasks() know |
| 2028 | * not to add the delayed tasks to the execution list. |
| 2029 | */ |
| 2030 | return 0; |
| 2031 | } |
| 2032 | /* |
| 2033 | * Otherwise, no ORDERED task attributes exist.. |
| 2034 | */ |
| 2035 | return 1; |
| 2036 | } |
| 2037 | |
| 2038 | /* |
| 2039 | * Called from fabric module context in transport_generic_new_cmd() and |
| 2040 | * transport_generic_process_write() |
| 2041 | */ |
Jörn Engel | d28d96d | 2012-05-11 10:33:41 -0400 | [diff] [blame] | 2042 | static void transport_execute_tasks(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2043 | { |
| 2044 | int add_tasks; |
Nicholas Bellinger | 40be67f | 2011-11-30 00:41:20 -0800 | [diff] [blame] | 2045 | struct se_device *se_dev = cmd->se_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2046 | /* |
| 2047 | * Call transport_cmd_check_stop() to see if a fabric exception |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2048 | * has occurred that prevents execution. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2049 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2050 | if (!transport_cmd_check_stop(cmd, 0, TRANSPORT_PROCESSING)) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2051 | /* |
| 2052 | * Check for SAM Task Attribute emulation and HEAD_OF_QUEUE |
| 2053 | * attribute for the tasks of the received struct se_cmd CDB |
| 2054 | */ |
| 2055 | add_tasks = transport_execute_task_attr(cmd); |
Jörn Engel | d28d96d | 2012-05-11 10:33:41 -0400 | [diff] [blame] | 2056 | if (add_tasks) { |
| 2057 | __transport_execute_tasks(se_dev, cmd); |
| 2058 | return; |
| 2059 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2060 | } |
Nicholas Bellinger | 4d2300c | 2011-11-30 18:18:33 -0800 | [diff] [blame] | 2061 | __transport_execute_tasks(se_dev, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2062 | } |
| 2063 | |
Nicholas Bellinger | 4d2300c | 2011-11-30 18:18:33 -0800 | [diff] [blame] | 2064 | static int __transport_execute_tasks(struct se_device *dev, struct se_cmd *new_cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2065 | { |
| 2066 | int error; |
| 2067 | struct se_cmd *cmd = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2068 | unsigned long flags; |
| 2069 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2070 | check_depth: |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2071 | spin_lock_irq(&dev->execute_task_lock); |
Nicholas Bellinger | 4d2300c | 2011-11-30 18:18:33 -0800 | [diff] [blame] | 2072 | if (new_cmd != NULL) |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2073 | __target_add_to_execute_list(new_cmd); |
Nicholas Bellinger | 4d2300c | 2011-11-30 18:18:33 -0800 | [diff] [blame] | 2074 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2075 | if (list_empty(&dev->execute_list)) { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2076 | spin_unlock_irq(&dev->execute_task_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2077 | return 0; |
| 2078 | } |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2079 | cmd = list_first_entry(&dev->execute_list, struct se_cmd, execute_list); |
| 2080 | __target_remove_from_execute_list(cmd); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2081 | spin_unlock_irq(&dev->execute_task_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2082 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2083 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2084 | cmd->transport_state |= CMD_T_BUSY; |
Christoph Hellwig | 785fdf7 | 2012-04-24 00:25:04 -0400 | [diff] [blame] | 2085 | cmd->transport_state |= CMD_T_SENT; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2086 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2087 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2088 | |
Christoph Hellwig | 6bb35e0 | 2012-04-23 11:35:33 -0400 | [diff] [blame] | 2089 | if (cmd->execute_cmd) |
| 2090 | error = cmd->execute_cmd(cmd); |
Christoph Hellwig | 5787cac | 2012-04-24 00:25:06 -0400 | [diff] [blame] | 2091 | else { |
| 2092 | error = dev->transport->execute_cmd(cmd, cmd->t_data_sg, |
| 2093 | cmd->t_data_nents, cmd->data_direction); |
| 2094 | } |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2095 | |
Christoph Hellwig | d29a5b6 | 2011-11-03 17:50:44 -0400 | [diff] [blame] | 2096 | if (error != 0) { |
Christoph Hellwig | d29a5b6 | 2011-11-03 17:50:44 -0400 | [diff] [blame] | 2097 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2098 | cmd->transport_state &= ~CMD_T_BUSY; |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 2099 | cmd->transport_state &= ~CMD_T_SENT; |
Christoph Hellwig | d29a5b6 | 2011-11-03 17:50:44 -0400 | [diff] [blame] | 2100 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 2101 | |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 2102 | transport_generic_request_failure(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2103 | } |
| 2104 | |
Nicholas Bellinger | 4d2300c | 2011-11-30 18:18:33 -0800 | [diff] [blame] | 2105 | new_cmd = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2106 | goto check_depth; |
| 2107 | |
| 2108 | return 0; |
| 2109 | } |
| 2110 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2111 | /* |
| 2112 | * Used to obtain Sense Data from underlying Linux/SCSI struct scsi_cmnd |
| 2113 | */ |
| 2114 | static int transport_get_sense_data(struct se_cmd *cmd) |
| 2115 | { |
| 2116 | unsigned char *buffer = cmd->sense_buffer, *sense_buffer = NULL; |
Christoph Hellwig | 42bf829 | 2011-10-12 11:07:00 -0400 | [diff] [blame] | 2117 | struct se_device *dev = cmd->se_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2118 | unsigned long flags; |
| 2119 | u32 offset = 0; |
| 2120 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2121 | WARN_ON(!cmd->se_lun); |
| 2122 | |
Christoph Hellwig | 42bf829 | 2011-10-12 11:07:00 -0400 | [diff] [blame] | 2123 | if (!dev) |
| 2124 | return 0; |
| 2125 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2126 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2127 | if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION) { |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2128 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2129 | return 0; |
| 2130 | } |
| 2131 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2132 | if (!(cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE)) |
| 2133 | goto out; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2134 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2135 | if (!dev->transport->get_sense_buffer) { |
| 2136 | pr_err("dev->transport->get_sense_buffer is NULL\n"); |
| 2137 | goto out; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2138 | } |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2139 | |
Christoph Hellwig | 5787cac | 2012-04-24 00:25:06 -0400 | [diff] [blame] | 2140 | sense_buffer = dev->transport->get_sense_buffer(cmd); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2141 | if (!sense_buffer) { |
Christoph Hellwig | 5787cac | 2012-04-24 00:25:06 -0400 | [diff] [blame] | 2142 | pr_err("ITT 0x%08x cmd %p: Unable to locate" |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2143 | " sense buffer for task with sense\n", |
Christoph Hellwig | 5787cac | 2012-04-24 00:25:06 -0400 | [diff] [blame] | 2144 | cmd->se_tfo->get_task_tag(cmd), cmd); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2145 | goto out; |
| 2146 | } |
Christoph Hellwig | 5787cac | 2012-04-24 00:25:06 -0400 | [diff] [blame] | 2147 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2148 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
| 2149 | |
| 2150 | offset = cmd->se_tfo->set_fabric_sense_len(cmd, TRANSPORT_SENSE_BUFFER); |
| 2151 | |
| 2152 | memcpy(&buffer[offset], sense_buffer, TRANSPORT_SENSE_BUFFER); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2153 | |
| 2154 | /* Automatically padded */ |
| 2155 | cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER + offset; |
| 2156 | |
| 2157 | pr_debug("HBA_[%u]_PLUG[%s]: Set SAM STATUS: 0x%02x and sense\n", |
| 2158 | dev->se_hba->hba_id, dev->transport->name, cmd->scsi_status); |
| 2159 | return 0; |
| 2160 | |
Christoph Hellwig | 785fdf7 | 2012-04-24 00:25:04 -0400 | [diff] [blame] | 2161 | out: |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2162 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2163 | return -1; |
| 2164 | } |
| 2165 | |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2166 | static inline long long transport_dev_end_lba(struct se_device *dev) |
| 2167 | { |
| 2168 | return dev->transport->get_blocks(dev) + 1; |
| 2169 | } |
| 2170 | |
| 2171 | static int transport_cmd_get_valid_sectors(struct se_cmd *cmd) |
| 2172 | { |
| 2173 | struct se_device *dev = cmd->se_dev; |
| 2174 | u32 sectors; |
| 2175 | |
| 2176 | if (dev->transport->get_device_type(dev) != TYPE_DISK) |
| 2177 | return 0; |
| 2178 | |
| 2179 | sectors = (cmd->data_length / dev->se_sub_dev->se_dev_attrib.block_size); |
| 2180 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2181 | if ((cmd->t_task_lba + sectors) > transport_dev_end_lba(dev)) { |
| 2182 | pr_err("LBA: %llu Sectors: %u exceeds" |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2183 | " transport_dev_end_lba(): %llu\n", |
| 2184 | cmd->t_task_lba, sectors, |
| 2185 | transport_dev_end_lba(dev)); |
Nicholas Bellinger | 7abbe7f3 | 2011-08-10 18:41:14 -0700 | [diff] [blame] | 2186 | return -EINVAL; |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2187 | } |
| 2188 | |
Nicholas Bellinger | 7abbe7f3 | 2011-08-10 18:41:14 -0700 | [diff] [blame] | 2189 | return 0; |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2192 | /* |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 2193 | * Called from I/O completion to determine which dormant/delayed |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2194 | * and ordered cmds need to have their tasks added to the execution queue. |
| 2195 | */ |
| 2196 | static void transport_complete_task_attr(struct se_cmd *cmd) |
| 2197 | { |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 2198 | struct se_device *dev = cmd->se_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2199 | struct se_cmd *cmd_p, *cmd_tmp; |
| 2200 | int new_active_tasks = 0; |
| 2201 | |
Nicholas Bellinger | e66ecd5 | 2011-05-19 20:19:14 -0700 | [diff] [blame] | 2202 | if (cmd->sam_task_attr == MSG_SIMPLE_TAG) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2203 | atomic_dec(&dev->simple_cmds); |
| 2204 | smp_mb__after_atomic_dec(); |
| 2205 | dev->dev_cur_ordered_id++; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2206 | pr_debug("Incremented dev->dev_cur_ordered_id: %u for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2207 | " SIMPLE: %u\n", dev->dev_cur_ordered_id, |
| 2208 | cmd->se_ordered_id); |
Nicholas Bellinger | e66ecd5 | 2011-05-19 20:19:14 -0700 | [diff] [blame] | 2209 | } else if (cmd->sam_task_attr == MSG_HEAD_TAG) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2210 | dev->dev_cur_ordered_id++; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2211 | pr_debug("Incremented dev_cur_ordered_id: %u for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2212 | " HEAD_OF_QUEUE: %u\n", dev->dev_cur_ordered_id, |
| 2213 | cmd->se_ordered_id); |
Nicholas Bellinger | e66ecd5 | 2011-05-19 20:19:14 -0700 | [diff] [blame] | 2214 | } else if (cmd->sam_task_attr == MSG_ORDERED_TAG) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2215 | atomic_dec(&dev->dev_ordered_sync); |
| 2216 | smp_mb__after_atomic_dec(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2217 | |
| 2218 | dev->dev_cur_ordered_id++; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2219 | pr_debug("Incremented dev_cur_ordered_id: %u for ORDERED:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2220 | " %u\n", dev->dev_cur_ordered_id, cmd->se_ordered_id); |
| 2221 | } |
| 2222 | /* |
| 2223 | * Process all commands up to the last received |
| 2224 | * ORDERED task attribute which requires another blocking |
| 2225 | * boundary |
| 2226 | */ |
| 2227 | spin_lock(&dev->delayed_cmd_lock); |
| 2228 | list_for_each_entry_safe(cmd_p, cmd_tmp, |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 2229 | &dev->delayed_cmd_list, se_delayed_node) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2230 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 2231 | list_del(&cmd_p->se_delayed_node); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2232 | spin_unlock(&dev->delayed_cmd_lock); |
| 2233 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2234 | pr_debug("Calling add_tasks() for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2235 | " cmd_p: 0x%02x Task Attr: 0x%02x" |
| 2236 | " Dormant -> Active, se_ordered_id: %u\n", |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2237 | cmd_p->t_task_cdb[0], |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2238 | cmd_p->sam_task_attr, cmd_p->se_ordered_id); |
| 2239 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2240 | target_add_to_execute_list(cmd_p); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2241 | new_active_tasks++; |
| 2242 | |
| 2243 | spin_lock(&dev->delayed_cmd_lock); |
Nicholas Bellinger | e66ecd5 | 2011-05-19 20:19:14 -0700 | [diff] [blame] | 2244 | if (cmd_p->sam_task_attr == MSG_ORDERED_TAG) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2245 | break; |
| 2246 | } |
| 2247 | spin_unlock(&dev->delayed_cmd_lock); |
| 2248 | /* |
| 2249 | * If new tasks have become active, wake up the transport thread |
| 2250 | * to do the processing of the Active tasks. |
| 2251 | */ |
| 2252 | if (new_active_tasks != 0) |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2253 | wake_up_interruptible(&dev->dev_queue_obj.thread_wq); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2254 | } |
| 2255 | |
Christoph Hellwig | e057f53 | 2011-10-17 13:56:41 -0400 | [diff] [blame] | 2256 | static void transport_complete_qf(struct se_cmd *cmd) |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2257 | { |
| 2258 | int ret = 0; |
| 2259 | |
Christoph Hellwig | e057f53 | 2011-10-17 13:56:41 -0400 | [diff] [blame] | 2260 | if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED) |
| 2261 | transport_complete_task_attr(cmd); |
| 2262 | |
| 2263 | if (cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) { |
| 2264 | ret = cmd->se_tfo->queue_status(cmd); |
| 2265 | if (ret) |
| 2266 | goto out; |
| 2267 | } |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2268 | |
| 2269 | switch (cmd->data_direction) { |
| 2270 | case DMA_FROM_DEVICE: |
| 2271 | ret = cmd->se_tfo->queue_data_in(cmd); |
| 2272 | break; |
| 2273 | case DMA_TO_DEVICE: |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2274 | if (cmd->t_bidi_data_sg) { |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2275 | ret = cmd->se_tfo->queue_data_in(cmd); |
| 2276 | if (ret < 0) |
Christoph Hellwig | e057f53 | 2011-10-17 13:56:41 -0400 | [diff] [blame] | 2277 | break; |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2278 | } |
| 2279 | /* Fall through for DMA_TO_DEVICE */ |
| 2280 | case DMA_NONE: |
| 2281 | ret = cmd->se_tfo->queue_status(cmd); |
| 2282 | break; |
| 2283 | default: |
| 2284 | break; |
| 2285 | } |
| 2286 | |
Christoph Hellwig | e057f53 | 2011-10-17 13:56:41 -0400 | [diff] [blame] | 2287 | out: |
| 2288 | if (ret < 0) { |
| 2289 | transport_handle_queue_full(cmd, cmd->se_dev); |
| 2290 | return; |
| 2291 | } |
| 2292 | transport_lun_remove_cmd(cmd); |
| 2293 | transport_cmd_check_stop_to_fabric(cmd); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | static void transport_handle_queue_full( |
| 2297 | struct se_cmd *cmd, |
Christoph Hellwig | e057f53 | 2011-10-17 13:56:41 -0400 | [diff] [blame] | 2298 | struct se_device *dev) |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2299 | { |
| 2300 | spin_lock_irq(&dev->qf_cmd_lock); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2301 | list_add_tail(&cmd->se_qf_node, &cmd->se_dev->qf_cmd_list); |
| 2302 | atomic_inc(&dev->dev_qf_count); |
| 2303 | smp_mb__after_atomic_inc(); |
| 2304 | spin_unlock_irq(&cmd->se_dev->qf_cmd_lock); |
| 2305 | |
| 2306 | schedule_work(&cmd->se_dev->qf_work_queue); |
| 2307 | } |
| 2308 | |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 2309 | static void target_complete_ok_work(struct work_struct *work) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2310 | { |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 2311 | struct se_cmd *cmd = container_of(work, struct se_cmd, work); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2312 | int reason = 0, ret; |
Christoph Hellwig | 35e0e75 | 2011-10-17 13:56:53 -0400 | [diff] [blame] | 2313 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2314 | /* |
| 2315 | * Check if we need to move delayed/dormant tasks from cmds on the |
| 2316 | * delayed execution list after a HEAD_OF_QUEUE or ORDERED Task |
| 2317 | * Attribute. |
| 2318 | */ |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 2319 | if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2320 | transport_complete_task_attr(cmd); |
| 2321 | /* |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2322 | * Check to schedule QUEUE_FULL work, or execute an existing |
| 2323 | * cmd->transport_qf_callback() |
| 2324 | */ |
| 2325 | if (atomic_read(&cmd->se_dev->dev_qf_count) != 0) |
| 2326 | schedule_work(&cmd->se_dev->qf_work_queue); |
| 2327 | |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2328 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2329 | * Check if we need to retrieve a sense buffer from |
| 2330 | * the struct se_cmd in question. |
| 2331 | */ |
| 2332 | if (cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) { |
| 2333 | if (transport_get_sense_data(cmd) < 0) |
| 2334 | reason = TCM_NON_EXISTENT_LUN; |
| 2335 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2336 | if (cmd->scsi_status) { |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2337 | ret = transport_send_check_condition_and_sense( |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2338 | cmd, reason, 1); |
Nicholas Bellinger | f147abb | 2011-10-25 23:57:41 -0700 | [diff] [blame] | 2339 | if (ret == -EAGAIN || ret == -ENOMEM) |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2340 | goto queue_full; |
| 2341 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2342 | transport_lun_remove_cmd(cmd); |
| 2343 | transport_cmd_check_stop_to_fabric(cmd); |
| 2344 | return; |
| 2345 | } |
| 2346 | } |
| 2347 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2348 | * Check for a callback, used by amongst other things |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2349 | * XDWRITE_READ_10 emulation. |
| 2350 | */ |
| 2351 | if (cmd->transport_complete_callback) |
| 2352 | cmd->transport_complete_callback(cmd); |
| 2353 | |
| 2354 | switch (cmd->data_direction) { |
| 2355 | case DMA_FROM_DEVICE: |
| 2356 | spin_lock(&cmd->se_lun->lun_sep_lock); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2357 | if (cmd->se_lun->lun_sep) { |
| 2358 | cmd->se_lun->lun_sep->sep_stats.tx_data_octets += |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2359 | cmd->data_length; |
| 2360 | } |
| 2361 | spin_unlock(&cmd->se_lun->lun_sep_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2362 | |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2363 | ret = cmd->se_tfo->queue_data_in(cmd); |
Nicholas Bellinger | f147abb | 2011-10-25 23:57:41 -0700 | [diff] [blame] | 2364 | if (ret == -EAGAIN || ret == -ENOMEM) |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2365 | goto queue_full; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2366 | break; |
| 2367 | case DMA_TO_DEVICE: |
| 2368 | spin_lock(&cmd->se_lun->lun_sep_lock); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2369 | if (cmd->se_lun->lun_sep) { |
| 2370 | cmd->se_lun->lun_sep->sep_stats.rx_data_octets += |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2371 | cmd->data_length; |
| 2372 | } |
| 2373 | spin_unlock(&cmd->se_lun->lun_sep_lock); |
| 2374 | /* |
| 2375 | * Check if we need to send READ payload for BIDI-COMMAND |
| 2376 | */ |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2377 | if (cmd->t_bidi_data_sg) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2378 | spin_lock(&cmd->se_lun->lun_sep_lock); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2379 | if (cmd->se_lun->lun_sep) { |
| 2380 | cmd->se_lun->lun_sep->sep_stats.tx_data_octets += |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2381 | cmd->data_length; |
| 2382 | } |
| 2383 | spin_unlock(&cmd->se_lun->lun_sep_lock); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2384 | ret = cmd->se_tfo->queue_data_in(cmd); |
Nicholas Bellinger | f147abb | 2011-10-25 23:57:41 -0700 | [diff] [blame] | 2385 | if (ret == -EAGAIN || ret == -ENOMEM) |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2386 | goto queue_full; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2387 | break; |
| 2388 | } |
| 2389 | /* Fall through for DMA_TO_DEVICE */ |
| 2390 | case DMA_NONE: |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2391 | ret = cmd->se_tfo->queue_status(cmd); |
Nicholas Bellinger | f147abb | 2011-10-25 23:57:41 -0700 | [diff] [blame] | 2392 | if (ret == -EAGAIN || ret == -ENOMEM) |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2393 | goto queue_full; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2394 | break; |
| 2395 | default: |
| 2396 | break; |
| 2397 | } |
| 2398 | |
| 2399 | transport_lun_remove_cmd(cmd); |
| 2400 | transport_cmd_check_stop_to_fabric(cmd); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2401 | return; |
| 2402 | |
| 2403 | queue_full: |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2404 | pr_debug("Handling complete_ok QUEUE_FULL: se_cmd: %p," |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2405 | " data_direction: %d\n", cmd, cmd->data_direction); |
Christoph Hellwig | e057f53 | 2011-10-17 13:56:41 -0400 | [diff] [blame] | 2406 | cmd->t_state = TRANSPORT_COMPLETE_QF_OK; |
| 2407 | transport_handle_queue_full(cmd, cmd->se_dev); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2408 | } |
| 2409 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2410 | static inline void transport_free_sgl(struct scatterlist *sgl, int nents) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2411 | { |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2412 | struct scatterlist *sg; |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2413 | int count; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2414 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2415 | for_each_sg(sgl, sg, nents, count) |
| 2416 | __free_page(sg_page(sg)); |
| 2417 | |
| 2418 | kfree(sgl); |
| 2419 | } |
| 2420 | |
| 2421 | static inline void transport_free_pages(struct se_cmd *cmd) |
| 2422 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2423 | if (cmd->se_cmd_flags & SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC) |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2424 | return; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2425 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2426 | transport_free_sgl(cmd->t_data_sg, cmd->t_data_nents); |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2427 | cmd->t_data_sg = NULL; |
| 2428 | cmd->t_data_nents = 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2429 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2430 | transport_free_sgl(cmd->t_bidi_data_sg, cmd->t_bidi_data_nents); |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2431 | cmd->t_bidi_data_sg = NULL; |
| 2432 | cmd->t_bidi_data_nents = 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2433 | } |
| 2434 | |
Christoph Hellwig | d3df782 | 2011-09-13 23:08:32 +0200 | [diff] [blame] | 2435 | /** |
Christoph Hellwig | e26d99a | 2011-11-14 12:30:30 -0500 | [diff] [blame] | 2436 | * transport_release_cmd - free a command |
| 2437 | * @cmd: command to free |
| 2438 | * |
| 2439 | * This routine unconditionally frees a command, and reference counting |
| 2440 | * or list removal must be done in the caller. |
| 2441 | */ |
| 2442 | static void transport_release_cmd(struct se_cmd *cmd) |
| 2443 | { |
| 2444 | BUG_ON(!cmd->se_tfo); |
| 2445 | |
Andy Grover | c8e31f2 | 2012-01-19 13:39:17 -0800 | [diff] [blame] | 2446 | if (cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) |
Christoph Hellwig | e26d99a | 2011-11-14 12:30:30 -0500 | [diff] [blame] | 2447 | core_tmr_release_req(cmd->se_tmr_req); |
| 2448 | if (cmd->t_task_cdb != cmd->__t_task_cdb) |
| 2449 | kfree(cmd->t_task_cdb); |
| 2450 | /* |
Nicholas Bellinger | 7481deb | 2011-11-12 00:32:17 -0800 | [diff] [blame] | 2451 | * If this cmd has been setup with target_get_sess_cmd(), drop |
| 2452 | * the kref and call ->release_cmd() in kref callback. |
Christoph Hellwig | e26d99a | 2011-11-14 12:30:30 -0500 | [diff] [blame] | 2453 | */ |
Nicholas Bellinger | 7481deb | 2011-11-12 00:32:17 -0800 | [diff] [blame] | 2454 | if (cmd->check_release != 0) { |
| 2455 | target_put_sess_cmd(cmd->se_sess, cmd); |
| 2456 | return; |
| 2457 | } |
Christoph Hellwig | e26d99a | 2011-11-14 12:30:30 -0500 | [diff] [blame] | 2458 | cmd->se_tfo->release_cmd(cmd); |
| 2459 | } |
| 2460 | |
| 2461 | /** |
Christoph Hellwig | d3df782 | 2011-09-13 23:08:32 +0200 | [diff] [blame] | 2462 | * transport_put_cmd - release a reference to a command |
| 2463 | * @cmd: command to release |
| 2464 | * |
| 2465 | * This routine releases our reference to the command and frees it if possible. |
| 2466 | */ |
Nicholas Bellinger | 39c05f3 | 2011-10-08 13:59:52 -0700 | [diff] [blame] | 2467 | static void transport_put_cmd(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2468 | { |
| 2469 | unsigned long flags; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2470 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2471 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Christoph Hellwig | 4911e3c | 2011-09-13 23:08:42 +0200 | [diff] [blame] | 2472 | if (atomic_read(&cmd->t_fe_count)) { |
| 2473 | if (!atomic_dec_and_test(&cmd->t_fe_count)) |
| 2474 | goto out_busy; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2475 | } |
Christoph Hellwig | 4911e3c | 2011-09-13 23:08:42 +0200 | [diff] [blame] | 2476 | |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 2477 | if (cmd->transport_state & CMD_T_DEV_ACTIVE) { |
| 2478 | cmd->transport_state &= ~CMD_T_DEV_ACTIVE; |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2479 | target_remove_from_state_list(cmd); |
Christoph Hellwig | 4911e3c | 2011-09-13 23:08:42 +0200 | [diff] [blame] | 2480 | } |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2481 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2482 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2483 | transport_free_pages(cmd); |
Christoph Hellwig | 31afc39 | 2011-09-13 23:08:11 +0200 | [diff] [blame] | 2484 | transport_release_cmd(cmd); |
Nicholas Bellinger | 39c05f3 | 2011-10-08 13:59:52 -0700 | [diff] [blame] | 2485 | return; |
Christoph Hellwig | 4911e3c | 2011-09-13 23:08:42 +0200 | [diff] [blame] | 2486 | out_busy: |
| 2487 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2488 | } |
| 2489 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2490 | /* |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2491 | * transport_generic_map_mem_to_cmd - Use fabric-alloced pages instead of |
| 2492 | * allocating in the core. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2493 | * @cmd: Associated se_cmd descriptor |
| 2494 | * @mem: SGL style memory for TCM WRITE / READ |
| 2495 | * @sg_mem_num: Number of SGL elements |
| 2496 | * @mem_bidi_in: SGL style memory for TCM BIDI READ |
| 2497 | * @sg_mem_bidi_num: Number of BIDI READ SGL elements |
| 2498 | * |
| 2499 | * Return: nonzero return cmd was rejected for -ENOMEM or inproper usage |
| 2500 | * of parameters. |
| 2501 | */ |
| 2502 | int transport_generic_map_mem_to_cmd( |
| 2503 | struct se_cmd *cmd, |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 2504 | struct scatterlist *sgl, |
| 2505 | u32 sgl_count, |
| 2506 | struct scatterlist *sgl_bidi, |
| 2507 | u32 sgl_bidi_count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2508 | { |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 2509 | if (!sgl || !sgl_count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2510 | return 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2511 | |
Christoph Hellwig | 64f1db3 | 2012-05-20 11:59:11 -0400 | [diff] [blame] | 2512 | /* |
| 2513 | * Reject SCSI data overflow with map_mem_to_cmd() as incoming |
| 2514 | * scatterlists already have been set to follow what the fabric |
| 2515 | * passes for the original expected data transfer length. |
| 2516 | */ |
| 2517 | if (cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { |
| 2518 | pr_warn("Rejecting SCSI DATA overflow for fabric using" |
| 2519 | " SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC\n"); |
| 2520 | cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
| 2521 | cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD; |
| 2522 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2523 | } |
| 2524 | |
Christoph Hellwig | 64f1db3 | 2012-05-20 11:59:11 -0400 | [diff] [blame] | 2525 | cmd->t_data_sg = sgl; |
| 2526 | cmd->t_data_nents = sgl_count; |
| 2527 | |
| 2528 | if (sgl_bidi && sgl_bidi_count) { |
| 2529 | cmd->t_bidi_data_sg = sgl_bidi; |
| 2530 | cmd->t_bidi_data_nents = sgl_bidi_count; |
| 2531 | } |
| 2532 | cmd->se_cmd_flags |= SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2533 | return 0; |
| 2534 | } |
| 2535 | EXPORT_SYMBOL(transport_generic_map_mem_to_cmd); |
| 2536 | |
Andy Grover | 4949314 | 2012-01-16 16:57:08 -0800 | [diff] [blame] | 2537 | void *transport_kmap_data_sg(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2538 | { |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2539 | struct scatterlist *sg = cmd->t_data_sg; |
Andy Grover | 4949314 | 2012-01-16 16:57:08 -0800 | [diff] [blame] | 2540 | struct page **pages; |
| 2541 | int i; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2542 | |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2543 | BUG_ON(!sg); |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 2544 | /* |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2545 | * We need to take into account a possible offset here for fabrics like |
| 2546 | * tcm_loop who may be using a contig buffer from the SCSI midlayer for |
| 2547 | * control CDBs passed as SGLs via transport_generic_map_mem_to_cmd() |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 2548 | */ |
Andy Grover | 4949314 | 2012-01-16 16:57:08 -0800 | [diff] [blame] | 2549 | if (!cmd->t_data_nents) |
| 2550 | return NULL; |
| 2551 | else if (cmd->t_data_nents == 1) |
| 2552 | return kmap(sg_page(sg)) + sg->offset; |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 2553 | |
Andy Grover | 4949314 | 2012-01-16 16:57:08 -0800 | [diff] [blame] | 2554 | /* >1 page. use vmap */ |
| 2555 | pages = kmalloc(sizeof(*pages) * cmd->t_data_nents, GFP_KERNEL); |
| 2556 | if (!pages) |
| 2557 | return NULL; |
| 2558 | |
| 2559 | /* convert sg[] to pages[] */ |
| 2560 | for_each_sg(cmd->t_data_sg, sg, cmd->t_data_nents, i) { |
| 2561 | pages[i] = sg_page(sg); |
| 2562 | } |
| 2563 | |
| 2564 | cmd->t_data_vmap = vmap(pages, cmd->t_data_nents, VM_MAP, PAGE_KERNEL); |
| 2565 | kfree(pages); |
| 2566 | if (!cmd->t_data_vmap) |
| 2567 | return NULL; |
| 2568 | |
| 2569 | return cmd->t_data_vmap + cmd->t_data_sg[0].offset; |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 2570 | } |
Andy Grover | 4949314 | 2012-01-16 16:57:08 -0800 | [diff] [blame] | 2571 | EXPORT_SYMBOL(transport_kmap_data_sg); |
| 2572 | |
| 2573 | void transport_kunmap_data_sg(struct se_cmd *cmd) |
| 2574 | { |
Andy Grover | a1edf9c | 2012-02-09 12:18:06 -0800 | [diff] [blame] | 2575 | if (!cmd->t_data_nents) { |
Andy Grover | 4949314 | 2012-01-16 16:57:08 -0800 | [diff] [blame] | 2576 | return; |
Andy Grover | a1edf9c | 2012-02-09 12:18:06 -0800 | [diff] [blame] | 2577 | } else if (cmd->t_data_nents == 1) { |
Andy Grover | 4949314 | 2012-01-16 16:57:08 -0800 | [diff] [blame] | 2578 | kunmap(sg_page(cmd->t_data_sg)); |
Andy Grover | a1edf9c | 2012-02-09 12:18:06 -0800 | [diff] [blame] | 2579 | return; |
| 2580 | } |
Andy Grover | 4949314 | 2012-01-16 16:57:08 -0800 | [diff] [blame] | 2581 | |
| 2582 | vunmap(cmd->t_data_vmap); |
| 2583 | cmd->t_data_vmap = NULL; |
| 2584 | } |
| 2585 | EXPORT_SYMBOL(transport_kunmap_data_sg); |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 2586 | |
| 2587 | static int |
| 2588 | transport_generic_get_mem(struct se_cmd *cmd) |
| 2589 | { |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2590 | u32 length = cmd->data_length; |
| 2591 | unsigned int nents; |
| 2592 | struct page *page; |
roland@purestorage.com | 9db9da3 | 2012-01-04 15:59:58 -0800 | [diff] [blame] | 2593 | gfp_t zero_flag; |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2594 | int i = 0; |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 2595 | |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2596 | nents = DIV_ROUND_UP(length, PAGE_SIZE); |
| 2597 | cmd->t_data_sg = kmalloc(sizeof(struct scatterlist) * nents, GFP_KERNEL); |
| 2598 | if (!cmd->t_data_sg) |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2599 | return -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2600 | |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2601 | cmd->t_data_nents = nents; |
| 2602 | sg_init_table(cmd->t_data_sg, nents); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2603 | |
Christoph Hellwig | 64f1db3 | 2012-05-20 11:59:11 -0400 | [diff] [blame] | 2604 | zero_flag = cmd->se_cmd_flags & SCF_SCSI_DATA_CDB ? 0 : __GFP_ZERO; |
roland@purestorage.com | 9db9da3 | 2012-01-04 15:59:58 -0800 | [diff] [blame] | 2605 | |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2606 | while (length) { |
| 2607 | u32 page_len = min_t(u32, length, PAGE_SIZE); |
roland@purestorage.com | 9db9da3 | 2012-01-04 15:59:58 -0800 | [diff] [blame] | 2608 | page = alloc_page(GFP_KERNEL | zero_flag); |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2609 | if (!page) |
| 2610 | goto out; |
| 2611 | |
| 2612 | sg_set_page(&cmd->t_data_sg[i], page, page_len, 0); |
| 2613 | length -= page_len; |
| 2614 | i++; |
| 2615 | } |
| 2616 | return 0; |
| 2617 | |
| 2618 | out: |
| 2619 | while (i >= 0) { |
| 2620 | __free_page(sg_page(&cmd->t_data_sg[i])); |
| 2621 | i--; |
| 2622 | } |
| 2623 | kfree(cmd->t_data_sg); |
| 2624 | cmd->t_data_sg = NULL; |
| 2625 | return -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2626 | } |
| 2627 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2628 | /* |
Andy Grover | b16a35b | 2012-04-03 15:51:21 -0700 | [diff] [blame] | 2629 | * Allocate any required resources to execute the command. For writes we |
| 2630 | * might not have the payload yet, so notify the fabric via a call to |
| 2631 | * ->write_pending instead. Otherwise place it on the execution queue. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2632 | */ |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2633 | int transport_generic_new_cmd(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2634 | { |
Christoph Hellwig | da0f761 | 2011-10-18 06:57:01 -0400 | [diff] [blame] | 2635 | struct se_device *dev = cmd->se_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2636 | int ret = 0; |
| 2637 | |
| 2638 | /* |
| 2639 | * Determine is the TCM fabric module has already allocated physical |
| 2640 | * memory, and is directly calling transport_generic_map_mem_to_cmd() |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2641 | * beforehand. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2642 | */ |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 2643 | if (!(cmd->se_cmd_flags & SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC) && |
| 2644 | cmd->data_length) { |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 2645 | ret = transport_generic_get_mem(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2646 | if (ret < 0) |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 2647 | goto out_fail; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2648 | } |
Christoph Hellwig | da0f761 | 2011-10-18 06:57:01 -0400 | [diff] [blame] | 2649 | |
Christoph Hellwig | 4101f0a | 2012-04-24 00:25:03 -0400 | [diff] [blame] | 2650 | /* Workaround for handling zero-length control CDBs */ |
Christoph Hellwig | 64f1db3 | 2012-05-20 11:59:11 -0400 | [diff] [blame] | 2651 | if (!(cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) && !cmd->data_length) { |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 2652 | spin_lock_irq(&cmd->t_state_lock); |
Roland Dreier | 410f670 | 2011-11-22 13:51:32 -0800 | [diff] [blame] | 2653 | cmd->t_state = TRANSPORT_COMPLETE; |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 2654 | cmd->transport_state |= CMD_T_ACTIVE; |
| 2655 | spin_unlock_irq(&cmd->t_state_lock); |
Nicholas Bellinger | 91ec1d3 | 2012-01-13 12:01:34 -0800 | [diff] [blame] | 2656 | |
| 2657 | if (cmd->t_task_cdb[0] == REQUEST_SENSE) { |
| 2658 | u8 ua_asc = 0, ua_ascq = 0; |
| 2659 | |
| 2660 | core_scsi3_ua_clear_for_request_sense(cmd, |
| 2661 | &ua_asc, &ua_ascq); |
| 2662 | } |
| 2663 | |
Roland Dreier | 410f670 | 2011-11-22 13:51:32 -0800 | [diff] [blame] | 2664 | INIT_WORK(&cmd->work, target_complete_ok_work); |
| 2665 | queue_work(target_completion_wq, &cmd->work); |
| 2666 | return 0; |
| 2667 | } |
Christoph Hellwig | da0f761 | 2011-10-18 06:57:01 -0400 | [diff] [blame] | 2668 | |
Christoph Hellwig | 64f1db3 | 2012-05-20 11:59:11 -0400 | [diff] [blame] | 2669 | if (cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) { |
Christoph Hellwig | 4101f0a | 2012-04-24 00:25:03 -0400 | [diff] [blame] | 2670 | struct se_dev_attrib *attr = &dev->se_sub_dev->se_dev_attrib; |
| 2671 | |
| 2672 | if (transport_cmd_get_valid_sectors(cmd) < 0) |
| 2673 | return -EINVAL; |
| 2674 | |
| 2675 | BUG_ON(cmd->data_length % attr->block_size); |
| 2676 | BUG_ON(DIV_ROUND_UP(cmd->data_length, attr->block_size) > |
Nicholas Bellinger | 11e764b | 2012-05-09 12:42:09 -0700 | [diff] [blame] | 2677 | attr->hw_max_sectors); |
Christoph Hellwig | da0f761 | 2011-10-18 06:57:01 -0400 | [diff] [blame] | 2678 | } |
| 2679 | |
Christoph Hellwig | 4101f0a | 2012-04-24 00:25:03 -0400 | [diff] [blame] | 2680 | atomic_inc(&cmd->t_fe_count); |
Christoph Hellwig | 4101f0a | 2012-04-24 00:25:03 -0400 | [diff] [blame] | 2681 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2682 | /* |
Christoph Hellwig | 5787cac | 2012-04-24 00:25:06 -0400 | [diff] [blame] | 2683 | * For WRITEs, let the fabric know its buffer is ready. |
| 2684 | * |
| 2685 | * The command will be added to the execution queue after its write |
| 2686 | * data has arrived. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2687 | */ |
| 2688 | if (cmd->data_direction == DMA_TO_DEVICE) { |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2689 | target_add_to_state_list(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2690 | return transport_generic_write_pending(cmd); |
| 2691 | } |
| 2692 | /* |
Christoph Hellwig | 5787cac | 2012-04-24 00:25:06 -0400 | [diff] [blame] | 2693 | * Everything else but a WRITE, add the command to the execution queue. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2694 | */ |
| 2695 | transport_execute_tasks(cmd); |
| 2696 | return 0; |
Christoph Hellwig | da0f761 | 2011-10-18 06:57:01 -0400 | [diff] [blame] | 2697 | |
| 2698 | out_fail: |
| 2699 | cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
| 2700 | cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; |
| 2701 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2702 | } |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2703 | EXPORT_SYMBOL(transport_generic_new_cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2704 | |
| 2705 | /* transport_generic_process_write(): |
| 2706 | * |
| 2707 | * |
| 2708 | */ |
| 2709 | void transport_generic_process_write(struct se_cmd *cmd) |
| 2710 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2711 | transport_execute_tasks(cmd); |
| 2712 | } |
| 2713 | EXPORT_SYMBOL(transport_generic_process_write); |
| 2714 | |
Christoph Hellwig | e057f53 | 2011-10-17 13:56:41 -0400 | [diff] [blame] | 2715 | static void transport_write_pending_qf(struct se_cmd *cmd) |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2716 | { |
Nicholas Bellinger | f147abb | 2011-10-25 23:57:41 -0700 | [diff] [blame] | 2717 | int ret; |
| 2718 | |
| 2719 | ret = cmd->se_tfo->write_pending(cmd); |
| 2720 | if (ret == -EAGAIN || ret == -ENOMEM) { |
Christoph Hellwig | e057f53 | 2011-10-17 13:56:41 -0400 | [diff] [blame] | 2721 | pr_debug("Handling write_pending QUEUE__FULL: se_cmd: %p\n", |
| 2722 | cmd); |
| 2723 | transport_handle_queue_full(cmd, cmd->se_dev); |
| 2724 | } |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2725 | } |
| 2726 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2727 | static int transport_generic_write_pending(struct se_cmd *cmd) |
| 2728 | { |
| 2729 | unsigned long flags; |
| 2730 | int ret; |
| 2731 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2732 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2733 | cmd->t_state = TRANSPORT_WRITE_PENDING; |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2734 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2735 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2736 | /* |
| 2737 | * Clear the se_cmd for WRITE_PENDING status in order to set |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 2738 | * CMD_T_ACTIVE so that transport_generic_handle_data can be called |
| 2739 | * from HW target mode interrupt code. This is safe to be called |
| 2740 | * with transport_off=1 before the cmd->se_tfo->write_pending |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2741 | * because the se_cmd->se_lun pointer is not being cleared. |
| 2742 | */ |
| 2743 | transport_cmd_check_stop(cmd, 1, 0); |
| 2744 | |
| 2745 | /* |
| 2746 | * Call the fabric write_pending function here to let the |
| 2747 | * frontend know that WRITE buffers are ready. |
| 2748 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2749 | ret = cmd->se_tfo->write_pending(cmd); |
Nicholas Bellinger | f147abb | 2011-10-25 23:57:41 -0700 | [diff] [blame] | 2750 | if (ret == -EAGAIN || ret == -ENOMEM) |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2751 | goto queue_full; |
| 2752 | else if (ret < 0) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2753 | return ret; |
| 2754 | |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 2755 | return 1; |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2756 | |
| 2757 | queue_full: |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2758 | pr_debug("Handling write_pending QUEUE__FULL: se_cmd: %p\n", cmd); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 2759 | cmd->t_state = TRANSPORT_COMPLETE_QF_WP; |
Christoph Hellwig | e057f53 | 2011-10-17 13:56:41 -0400 | [diff] [blame] | 2760 | transport_handle_queue_full(cmd, cmd->se_dev); |
Nicholas Bellinger | f147abb | 2011-10-25 23:57:41 -0700 | [diff] [blame] | 2761 | return 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2762 | } |
| 2763 | |
Nicholas Bellinger | 39c05f3 | 2011-10-08 13:59:52 -0700 | [diff] [blame] | 2764 | void transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2765 | { |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 2766 | if (!(cmd->se_cmd_flags & SCF_SE_LUN_CMD)) { |
Andy Grover | c8e31f2 | 2012-01-19 13:39:17 -0800 | [diff] [blame] | 2767 | if (wait_for_tasks && (cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 2768 | transport_wait_for_tasks(cmd); |
| 2769 | |
Christoph Hellwig | 3546297 | 2011-05-31 23:56:57 -0400 | [diff] [blame] | 2770 | transport_release_cmd(cmd); |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 2771 | } else { |
| 2772 | if (wait_for_tasks) |
| 2773 | transport_wait_for_tasks(cmd); |
| 2774 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2775 | core_dec_lacl_count(cmd->se_sess->se_node_acl, cmd); |
| 2776 | |
Christoph Hellwig | 82f1c8a | 2011-09-13 23:09:01 +0200 | [diff] [blame] | 2777 | if (cmd->se_lun) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2778 | transport_lun_remove_cmd(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2779 | |
Nicholas Bellinger | 39c05f3 | 2011-10-08 13:59:52 -0700 | [diff] [blame] | 2780 | transport_put_cmd(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2781 | } |
| 2782 | } |
| 2783 | EXPORT_SYMBOL(transport_generic_free_cmd); |
| 2784 | |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 2785 | /* target_get_sess_cmd - Add command to active ->sess_cmd_list |
| 2786 | * @se_sess: session to reference |
| 2787 | * @se_cmd: command descriptor to add |
Nicholas Bellinger | a636078 | 2011-11-18 20:36:22 -0800 | [diff] [blame] | 2788 | * @ack_kref: Signal that fabric will perform an ack target_put_sess_cmd() |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 2789 | */ |
Nicholas Bellinger | a636078 | 2011-11-18 20:36:22 -0800 | [diff] [blame] | 2790 | void target_get_sess_cmd(struct se_session *se_sess, struct se_cmd *se_cmd, |
| 2791 | bool ack_kref) |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 2792 | { |
| 2793 | unsigned long flags; |
| 2794 | |
Nicholas Bellinger | 7481deb | 2011-11-12 00:32:17 -0800 | [diff] [blame] | 2795 | kref_init(&se_cmd->cmd_kref); |
Nicholas Bellinger | a636078 | 2011-11-18 20:36:22 -0800 | [diff] [blame] | 2796 | /* |
| 2797 | * Add a second kref if the fabric caller is expecting to handle |
| 2798 | * fabric acknowledgement that requires two target_put_sess_cmd() |
| 2799 | * invocations before se_cmd descriptor release. |
| 2800 | */ |
Nicholas Bellinger | 8671556 | 2012-02-13 01:07:22 -0800 | [diff] [blame] | 2801 | if (ack_kref == true) { |
Nicholas Bellinger | a636078 | 2011-11-18 20:36:22 -0800 | [diff] [blame] | 2802 | kref_get(&se_cmd->cmd_kref); |
Nicholas Bellinger | 8671556 | 2012-02-13 01:07:22 -0800 | [diff] [blame] | 2803 | se_cmd->se_cmd_flags |= SCF_ACK_KREF; |
| 2804 | } |
Nicholas Bellinger | 7481deb | 2011-11-12 00:32:17 -0800 | [diff] [blame] | 2805 | |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 2806 | spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); |
| 2807 | list_add_tail(&se_cmd->se_cmd_list, &se_sess->sess_cmd_list); |
| 2808 | se_cmd->check_release = 1; |
| 2809 | spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); |
| 2810 | } |
| 2811 | EXPORT_SYMBOL(target_get_sess_cmd); |
| 2812 | |
Nicholas Bellinger | 7481deb | 2011-11-12 00:32:17 -0800 | [diff] [blame] | 2813 | static void target_release_cmd_kref(struct kref *kref) |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 2814 | { |
Nicholas Bellinger | 7481deb | 2011-11-12 00:32:17 -0800 | [diff] [blame] | 2815 | struct se_cmd *se_cmd = container_of(kref, struct se_cmd, cmd_kref); |
| 2816 | struct se_session *se_sess = se_cmd->se_sess; |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 2817 | unsigned long flags; |
| 2818 | |
| 2819 | spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); |
| 2820 | if (list_empty(&se_cmd->se_cmd_list)) { |
| 2821 | spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); |
Nicholas Bellinger | ffc32d5 | 2012-02-13 02:35:01 -0800 | [diff] [blame] | 2822 | se_cmd->se_tfo->release_cmd(se_cmd); |
Nicholas Bellinger | 7481deb | 2011-11-12 00:32:17 -0800 | [diff] [blame] | 2823 | return; |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 2824 | } |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 2825 | if (se_sess->sess_tearing_down && se_cmd->cmd_wait_set) { |
| 2826 | spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); |
| 2827 | complete(&se_cmd->cmd_wait_comp); |
Nicholas Bellinger | 7481deb | 2011-11-12 00:32:17 -0800 | [diff] [blame] | 2828 | return; |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 2829 | } |
| 2830 | list_del(&se_cmd->se_cmd_list); |
| 2831 | spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); |
| 2832 | |
Nicholas Bellinger | 7481deb | 2011-11-12 00:32:17 -0800 | [diff] [blame] | 2833 | se_cmd->se_tfo->release_cmd(se_cmd); |
| 2834 | } |
| 2835 | |
| 2836 | /* target_put_sess_cmd - Check for active I/O shutdown via kref_put |
| 2837 | * @se_sess: session to reference |
| 2838 | * @se_cmd: command descriptor to drop |
| 2839 | */ |
| 2840 | int target_put_sess_cmd(struct se_session *se_sess, struct se_cmd *se_cmd) |
| 2841 | { |
| 2842 | return kref_put(&se_cmd->cmd_kref, target_release_cmd_kref); |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 2843 | } |
| 2844 | EXPORT_SYMBOL(target_put_sess_cmd); |
| 2845 | |
| 2846 | /* target_splice_sess_cmd_list - Split active cmds into sess_wait_list |
| 2847 | * @se_sess: session to split |
| 2848 | */ |
| 2849 | void target_splice_sess_cmd_list(struct se_session *se_sess) |
| 2850 | { |
| 2851 | struct se_cmd *se_cmd; |
| 2852 | unsigned long flags; |
| 2853 | |
| 2854 | WARN_ON(!list_empty(&se_sess->sess_wait_list)); |
| 2855 | INIT_LIST_HEAD(&se_sess->sess_wait_list); |
| 2856 | |
| 2857 | spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); |
| 2858 | se_sess->sess_tearing_down = 1; |
| 2859 | |
| 2860 | list_splice_init(&se_sess->sess_cmd_list, &se_sess->sess_wait_list); |
| 2861 | |
| 2862 | list_for_each_entry(se_cmd, &se_sess->sess_wait_list, se_cmd_list) |
| 2863 | se_cmd->cmd_wait_set = 1; |
| 2864 | |
| 2865 | spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); |
| 2866 | } |
| 2867 | EXPORT_SYMBOL(target_splice_sess_cmd_list); |
| 2868 | |
| 2869 | /* target_wait_for_sess_cmds - Wait for outstanding descriptors |
| 2870 | * @se_sess: session to wait for active I/O |
| 2871 | * @wait_for_tasks: Make extra transport_wait_for_tasks call |
| 2872 | */ |
| 2873 | void target_wait_for_sess_cmds( |
| 2874 | struct se_session *se_sess, |
| 2875 | int wait_for_tasks) |
| 2876 | { |
| 2877 | struct se_cmd *se_cmd, *tmp_cmd; |
| 2878 | bool rc = false; |
| 2879 | |
| 2880 | list_for_each_entry_safe(se_cmd, tmp_cmd, |
| 2881 | &se_sess->sess_wait_list, se_cmd_list) { |
| 2882 | list_del(&se_cmd->se_cmd_list); |
| 2883 | |
| 2884 | pr_debug("Waiting for se_cmd: %p t_state: %d, fabric state:" |
| 2885 | " %d\n", se_cmd, se_cmd->t_state, |
| 2886 | se_cmd->se_tfo->get_cmd_state(se_cmd)); |
| 2887 | |
| 2888 | if (wait_for_tasks) { |
| 2889 | pr_debug("Calling transport_wait_for_tasks se_cmd: %p t_state: %d," |
| 2890 | " fabric state: %d\n", se_cmd, se_cmd->t_state, |
| 2891 | se_cmd->se_tfo->get_cmd_state(se_cmd)); |
| 2892 | |
| 2893 | rc = transport_wait_for_tasks(se_cmd); |
| 2894 | |
| 2895 | pr_debug("After transport_wait_for_tasks se_cmd: %p t_state: %d," |
| 2896 | " fabric state: %d\n", se_cmd, se_cmd->t_state, |
| 2897 | se_cmd->se_tfo->get_cmd_state(se_cmd)); |
| 2898 | } |
| 2899 | |
| 2900 | if (!rc) { |
| 2901 | wait_for_completion(&se_cmd->cmd_wait_comp); |
| 2902 | pr_debug("After cmd_wait_comp: se_cmd: %p t_state: %d" |
| 2903 | " fabric state: %d\n", se_cmd, se_cmd->t_state, |
| 2904 | se_cmd->se_tfo->get_cmd_state(se_cmd)); |
| 2905 | } |
| 2906 | |
| 2907 | se_cmd->se_tfo->release_cmd(se_cmd); |
| 2908 | } |
| 2909 | } |
| 2910 | EXPORT_SYMBOL(target_wait_for_sess_cmds); |
| 2911 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2912 | /* transport_lun_wait_for_tasks(): |
| 2913 | * |
| 2914 | * Called from ConfigFS context to stop the passed struct se_cmd to allow |
| 2915 | * an struct se_lun to be successfully shutdown. |
| 2916 | */ |
| 2917 | static int transport_lun_wait_for_tasks(struct se_cmd *cmd, struct se_lun *lun) |
| 2918 | { |
| 2919 | unsigned long flags; |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2920 | int ret = 0; |
| 2921 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2922 | /* |
| 2923 | * If the frontend has already requested this struct se_cmd to |
| 2924 | * be stopped, we can safely ignore this struct se_cmd. |
| 2925 | */ |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2926 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 2927 | if (cmd->transport_state & CMD_T_STOP) { |
| 2928 | cmd->transport_state &= ~CMD_T_LUN_STOP; |
| 2929 | |
| 2930 | pr_debug("ConfigFS ITT[0x%08x] - CMD_T_STOP, skipping\n", |
| 2931 | cmd->se_tfo->get_task_tag(cmd)); |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2932 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2933 | transport_cmd_check_stop(cmd, 1, 0); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2934 | return -EPERM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2935 | } |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 2936 | cmd->transport_state |= CMD_T_LUN_FE_STOP; |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2937 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2938 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 2939 | wake_up_interruptible(&cmd->se_dev->dev_queue_obj.thread_wq); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2940 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2941 | // XXX: audit task_flags checks. |
| 2942 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
| 2943 | if ((cmd->transport_state & CMD_T_BUSY) && |
| 2944 | (cmd->transport_state & CMD_T_SENT)) { |
| 2945 | if (!target_stop_cmd(cmd, &flags)) |
| 2946 | ret++; |
Dan Carpenter | 2301917 | 2012-05-08 13:28:59 +0300 | [diff] [blame] | 2947 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 2948 | } else { |
| 2949 | spin_unlock_irqrestore(&cmd->t_state_lock, |
| 2950 | flags); |
| 2951 | target_remove_from_execute_list(cmd); |
| 2952 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2953 | |
Christoph Hellwig | 785fdf7 | 2012-04-24 00:25:04 -0400 | [diff] [blame] | 2954 | pr_debug("ConfigFS: cmd: %p stop tasks ret:" |
| 2955 | " %d\n", cmd, ret); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2956 | if (!ret) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2957 | pr_debug("ConfigFS: ITT[0x%08x] - stopping cmd....\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2958 | cmd->se_tfo->get_task_tag(cmd)); |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2959 | wait_for_completion(&cmd->transport_lun_stop_comp); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2960 | pr_debug("ConfigFS: ITT[0x%08x] - stopped cmd....\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2961 | cmd->se_tfo->get_task_tag(cmd)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2962 | } |
Christoph Hellwig | 3df8d40 | 2011-10-17 13:56:43 -0400 | [diff] [blame] | 2963 | transport_remove_cmd_from_queue(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2964 | |
| 2965 | return 0; |
| 2966 | } |
| 2967 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2968 | static void __transport_clear_lun_from_sessions(struct se_lun *lun) |
| 2969 | { |
| 2970 | struct se_cmd *cmd = NULL; |
| 2971 | unsigned long lun_flags, cmd_flags; |
| 2972 | /* |
| 2973 | * Do exception processing and return CHECK_CONDITION status to the |
| 2974 | * Initiator Port. |
| 2975 | */ |
| 2976 | spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags); |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 2977 | while (!list_empty(&lun->lun_cmd_list)) { |
| 2978 | cmd = list_first_entry(&lun->lun_cmd_list, |
| 2979 | struct se_cmd, se_lun_node); |
Christoph Hellwig | 3d26fea | 2011-12-21 14:14:05 -0500 | [diff] [blame] | 2980 | list_del_init(&cmd->se_lun_node); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2981 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2982 | /* |
| 2983 | * This will notify iscsi_target_transport.c: |
| 2984 | * transport_cmd_check_stop() that a LUN shutdown is in |
| 2985 | * progress for the iscsi_cmd_t. |
| 2986 | */ |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2987 | spin_lock(&cmd->t_state_lock); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2988 | pr_debug("SE_LUN[%d] - Setting cmd->transport" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2989 | "_lun_stop for ITT: 0x%08x\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2990 | cmd->se_lun->unpacked_lun, |
| 2991 | cmd->se_tfo->get_task_tag(cmd)); |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 2992 | cmd->transport_state |= CMD_T_LUN_STOP; |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 2993 | spin_unlock(&cmd->t_state_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2994 | |
| 2995 | spin_unlock_irqrestore(&lun->lun_cmd_lock, lun_flags); |
| 2996 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2997 | if (!cmd->se_lun) { |
| 2998 | pr_err("ITT: 0x%08x, [i,t]_state: %u/%u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2999 | cmd->se_tfo->get_task_tag(cmd), |
| 3000 | cmd->se_tfo->get_cmd_state(cmd), cmd->t_state); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3001 | BUG(); |
| 3002 | } |
| 3003 | /* |
| 3004 | * If the Storage engine still owns the iscsi_cmd_t, determine |
| 3005 | * and/or stop its context. |
| 3006 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3007 | pr_debug("SE_LUN[%d] - ITT: 0x%08x before transport" |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3008 | "_lun_wait_for_tasks()\n", cmd->se_lun->unpacked_lun, |
| 3009 | cmd->se_tfo->get_task_tag(cmd)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3010 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3011 | if (transport_lun_wait_for_tasks(cmd, cmd->se_lun) < 0) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3012 | spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags); |
| 3013 | continue; |
| 3014 | } |
| 3015 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3016 | pr_debug("SE_LUN[%d] - ITT: 0x%08x after transport_lun" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3017 | "_wait_for_tasks(): SUCCESS\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3018 | cmd->se_lun->unpacked_lun, |
| 3019 | cmd->se_tfo->get_task_tag(cmd)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3020 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3021 | spin_lock_irqsave(&cmd->t_state_lock, cmd_flags); |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 3022 | if (!(cmd->transport_state & CMD_T_DEV_ACTIVE)) { |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3023 | spin_unlock_irqrestore(&cmd->t_state_lock, cmd_flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3024 | goto check_cond; |
| 3025 | } |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 3026 | cmd->transport_state &= ~CMD_T_DEV_ACTIVE; |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 3027 | target_remove_from_state_list(cmd); |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3028 | spin_unlock_irqrestore(&cmd->t_state_lock, cmd_flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3029 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3030 | /* |
| 3031 | * The Storage engine stopped this struct se_cmd before it was |
| 3032 | * send to the fabric frontend for delivery back to the |
| 3033 | * Initiator Node. Return this SCSI CDB back with an |
| 3034 | * CHECK_CONDITION status. |
| 3035 | */ |
| 3036 | check_cond: |
| 3037 | transport_send_check_condition_and_sense(cmd, |
| 3038 | TCM_NON_EXISTENT_LUN, 0); |
| 3039 | /* |
| 3040 | * If the fabric frontend is waiting for this iscsi_cmd_t to |
| 3041 | * be released, notify the waiting thread now that LU has |
| 3042 | * finished accessing it. |
| 3043 | */ |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3044 | spin_lock_irqsave(&cmd->t_state_lock, cmd_flags); |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 3045 | if (cmd->transport_state & CMD_T_LUN_FE_STOP) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3046 | pr_debug("SE_LUN[%d] - Detected FE stop for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3047 | " struct se_cmd: %p ITT: 0x%08x\n", |
| 3048 | lun->unpacked_lun, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3049 | cmd, cmd->se_tfo->get_task_tag(cmd)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3050 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3051 | spin_unlock_irqrestore(&cmd->t_state_lock, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3052 | cmd_flags); |
| 3053 | transport_cmd_check_stop(cmd, 1, 0); |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3054 | complete(&cmd->transport_lun_fe_stop_comp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3055 | spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags); |
| 3056 | continue; |
| 3057 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3058 | pr_debug("SE_LUN[%d] - ITT: 0x%08x finished processing\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3059 | lun->unpacked_lun, cmd->se_tfo->get_task_tag(cmd)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3060 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3061 | spin_unlock_irqrestore(&cmd->t_state_lock, cmd_flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3062 | spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags); |
| 3063 | } |
| 3064 | spin_unlock_irqrestore(&lun->lun_cmd_lock, lun_flags); |
| 3065 | } |
| 3066 | |
| 3067 | static int transport_clear_lun_thread(void *p) |
| 3068 | { |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 3069 | struct se_lun *lun = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3070 | |
| 3071 | __transport_clear_lun_from_sessions(lun); |
| 3072 | complete(&lun->lun_shutdown_comp); |
| 3073 | |
| 3074 | return 0; |
| 3075 | } |
| 3076 | |
| 3077 | int transport_clear_lun_from_sessions(struct se_lun *lun) |
| 3078 | { |
| 3079 | struct task_struct *kt; |
| 3080 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 3081 | kt = kthread_run(transport_clear_lun_thread, lun, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3082 | "tcm_cl_%u", lun->unpacked_lun); |
| 3083 | if (IS_ERR(kt)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3084 | pr_err("Unable to start clear_lun thread\n"); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3085 | return PTR_ERR(kt); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3086 | } |
| 3087 | wait_for_completion(&lun->lun_shutdown_comp); |
| 3088 | |
| 3089 | return 0; |
| 3090 | } |
| 3091 | |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 3092 | /** |
| 3093 | * transport_wait_for_tasks - wait for completion to occur |
| 3094 | * @cmd: command to wait |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3095 | * |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 3096 | * Called from frontend fabric context to wait for storage engine |
| 3097 | * to pause and/or release frontend generated struct se_cmd. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3098 | */ |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 3099 | bool transport_wait_for_tasks(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3100 | { |
| 3101 | unsigned long flags; |
| 3102 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3103 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Andy Grover | c8e31f2 | 2012-01-19 13:39:17 -0800 | [diff] [blame] | 3104 | if (!(cmd->se_cmd_flags & SCF_SE_LUN_CMD) && |
| 3105 | !(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) { |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 3106 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 3107 | return false; |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 3108 | } |
Christoph Hellwig | cb4f4d3 | 2012-05-20 11:59:10 -0400 | [diff] [blame] | 3109 | |
Andy Grover | c8e31f2 | 2012-01-19 13:39:17 -0800 | [diff] [blame] | 3110 | if (!(cmd->se_cmd_flags & SCF_SUPPORTED_SAM_OPCODE) && |
| 3111 | !(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) { |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 3112 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 3113 | return false; |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 3114 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3115 | /* |
| 3116 | * If we are already stopped due to an external event (ie: LUN shutdown) |
| 3117 | * sleep until the connection can have the passed struct se_cmd back. |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3118 | * The cmd->transport_lun_stopped_sem will be upped by |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3119 | * transport_clear_lun_from_sessions() once the ConfigFS context caller |
| 3120 | * has completed its operation on the struct se_cmd. |
| 3121 | */ |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 3122 | if (cmd->transport_state & CMD_T_LUN_STOP) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3123 | pr_debug("wait_for_tasks: Stopping" |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3124 | " wait_for_completion(&cmd->t_tasktransport_lun_fe" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3125 | "_stop_comp); for ITT: 0x%08x\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3126 | cmd->se_tfo->get_task_tag(cmd)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3127 | /* |
| 3128 | * There is a special case for WRITES where a FE exception + |
| 3129 | * LUN shutdown means ConfigFS context is still sleeping on |
| 3130 | * transport_lun_stop_comp in transport_lun_wait_for_tasks(). |
| 3131 | * We go ahead and up transport_lun_stop_comp just to be sure |
| 3132 | * here. |
| 3133 | */ |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3134 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
| 3135 | complete(&cmd->transport_lun_stop_comp); |
| 3136 | wait_for_completion(&cmd->transport_lun_fe_stop_comp); |
| 3137 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3138 | |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 3139 | target_remove_from_state_list(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3140 | /* |
| 3141 | * At this point, the frontend who was the originator of this |
| 3142 | * struct se_cmd, now owns the structure and can be released through |
| 3143 | * normal means below. |
| 3144 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3145 | pr_debug("wait_for_tasks: Stopped" |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3146 | " wait_for_completion(&cmd->t_tasktransport_lun_fe_" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3147 | "stop_comp); for ITT: 0x%08x\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3148 | cmd->se_tfo->get_task_tag(cmd)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3149 | |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 3150 | cmd->transport_state &= ~CMD_T_LUN_STOP; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3151 | } |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 3152 | |
Nicholas Bellinger | 3d28934 | 2012-02-13 02:38:14 -0800 | [diff] [blame] | 3153 | if (!(cmd->transport_state & CMD_T_ACTIVE)) { |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 3154 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 3155 | return false; |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 3156 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3157 | |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 3158 | cmd->transport_state |= CMD_T_STOP; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3159 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3160 | pr_debug("wait_for_tasks: Stopping %p ITT: 0x%08x" |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 3161 | " i_state: %d, t_state: %d, CMD_T_STOP\n", |
Christoph Hellwig | f2da9db | 2011-10-17 13:56:51 -0400 | [diff] [blame] | 3162 | cmd, cmd->se_tfo->get_task_tag(cmd), |
| 3163 | cmd->se_tfo->get_cmd_state(cmd), cmd->t_state); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3164 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3165 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3166 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 3167 | wake_up_interruptible(&cmd->se_dev->dev_queue_obj.thread_wq); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3168 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3169 | wait_for_completion(&cmd->t_transport_stop_comp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3170 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3171 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 3172 | cmd->transport_state &= ~(CMD_T_ACTIVE | CMD_T_STOP); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3173 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3174 | pr_debug("wait_for_tasks: Stopped wait_for_compltion(" |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3175 | "&cmd->t_transport_stop_comp) for ITT: 0x%08x\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3176 | cmd->se_tfo->get_task_tag(cmd)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3177 | |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 3178 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | a17f091 | 2011-11-02 21:52:08 -0700 | [diff] [blame] | 3179 | |
| 3180 | return true; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3181 | } |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 3182 | EXPORT_SYMBOL(transport_wait_for_tasks); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3183 | |
| 3184 | static int transport_get_sense_codes( |
| 3185 | struct se_cmd *cmd, |
| 3186 | u8 *asc, |
| 3187 | u8 *ascq) |
| 3188 | { |
| 3189 | *asc = cmd->scsi_asc; |
| 3190 | *ascq = cmd->scsi_ascq; |
| 3191 | |
| 3192 | return 0; |
| 3193 | } |
| 3194 | |
| 3195 | static int transport_set_sense_codes( |
| 3196 | struct se_cmd *cmd, |
| 3197 | u8 asc, |
| 3198 | u8 ascq) |
| 3199 | { |
| 3200 | cmd->scsi_asc = asc; |
| 3201 | cmd->scsi_ascq = ascq; |
| 3202 | |
| 3203 | return 0; |
| 3204 | } |
| 3205 | |
| 3206 | int transport_send_check_condition_and_sense( |
| 3207 | struct se_cmd *cmd, |
| 3208 | u8 reason, |
| 3209 | int from_transport) |
| 3210 | { |
| 3211 | unsigned char *buffer = cmd->sense_buffer; |
| 3212 | unsigned long flags; |
| 3213 | int offset; |
| 3214 | u8 asc = 0, ascq = 0; |
| 3215 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3216 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3217 | if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION) { |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3218 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3219 | return 0; |
| 3220 | } |
| 3221 | cmd->se_cmd_flags |= SCF_SENT_CHECK_CONDITION; |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3222 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3223 | |
| 3224 | if (!reason && from_transport) |
| 3225 | goto after_reason; |
| 3226 | |
| 3227 | if (!from_transport) |
| 3228 | cmd->se_cmd_flags |= SCF_EMULATED_TASK_SENSE; |
| 3229 | /* |
| 3230 | * Data Segment and SenseLength of the fabric response PDU. |
| 3231 | * |
| 3232 | * TRANSPORT_SENSE_BUFFER is now set to SCSI_SENSE_BUFFERSIZE |
| 3233 | * from include/scsi/scsi_cmnd.h |
| 3234 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3235 | offset = cmd->se_tfo->set_fabric_sense_len(cmd, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3236 | TRANSPORT_SENSE_BUFFER); |
| 3237 | /* |
| 3238 | * Actual SENSE DATA, see SPC-3 7.23.2 SPC_SENSE_KEY_OFFSET uses |
| 3239 | * SENSE KEY values from include/scsi/scsi.h |
| 3240 | */ |
| 3241 | switch (reason) { |
| 3242 | case TCM_NON_EXISTENT_LUN: |
Nicholas Bellinger | eb39d34 | 2011-07-26 16:59:00 -0700 | [diff] [blame] | 3243 | /* CURRENT ERROR */ |
| 3244 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3245 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Nicholas Bellinger | eb39d34 | 2011-07-26 16:59:00 -0700 | [diff] [blame] | 3246 | /* ILLEGAL REQUEST */ |
| 3247 | buffer[offset+SPC_SENSE_KEY_OFFSET] = ILLEGAL_REQUEST; |
| 3248 | /* LOGICAL UNIT NOT SUPPORTED */ |
| 3249 | buffer[offset+SPC_ASC_KEY_OFFSET] = 0x25; |
| 3250 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3251 | case TCM_UNSUPPORTED_SCSI_OPCODE: |
| 3252 | case TCM_SECTOR_COUNT_TOO_MANY: |
| 3253 | /* CURRENT ERROR */ |
| 3254 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3255 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3256 | /* ILLEGAL REQUEST */ |
| 3257 | buffer[offset+SPC_SENSE_KEY_OFFSET] = ILLEGAL_REQUEST; |
| 3258 | /* INVALID COMMAND OPERATION CODE */ |
| 3259 | buffer[offset+SPC_ASC_KEY_OFFSET] = 0x20; |
| 3260 | break; |
| 3261 | case TCM_UNKNOWN_MODE_PAGE: |
| 3262 | /* CURRENT ERROR */ |
| 3263 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3264 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3265 | /* ILLEGAL REQUEST */ |
| 3266 | buffer[offset+SPC_SENSE_KEY_OFFSET] = ILLEGAL_REQUEST; |
| 3267 | /* INVALID FIELD IN CDB */ |
| 3268 | buffer[offset+SPC_ASC_KEY_OFFSET] = 0x24; |
| 3269 | break; |
| 3270 | case TCM_CHECK_CONDITION_ABORT_CMD: |
| 3271 | /* CURRENT ERROR */ |
| 3272 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3273 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3274 | /* ABORTED COMMAND */ |
| 3275 | buffer[offset+SPC_SENSE_KEY_OFFSET] = ABORTED_COMMAND; |
| 3276 | /* BUS DEVICE RESET FUNCTION OCCURRED */ |
| 3277 | buffer[offset+SPC_ASC_KEY_OFFSET] = 0x29; |
| 3278 | buffer[offset+SPC_ASCQ_KEY_OFFSET] = 0x03; |
| 3279 | break; |
| 3280 | case TCM_INCORRECT_AMOUNT_OF_DATA: |
| 3281 | /* CURRENT ERROR */ |
| 3282 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3283 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3284 | /* ABORTED COMMAND */ |
| 3285 | buffer[offset+SPC_SENSE_KEY_OFFSET] = ABORTED_COMMAND; |
| 3286 | /* WRITE ERROR */ |
| 3287 | buffer[offset+SPC_ASC_KEY_OFFSET] = 0x0c; |
| 3288 | /* NOT ENOUGH UNSOLICITED DATA */ |
| 3289 | buffer[offset+SPC_ASCQ_KEY_OFFSET] = 0x0d; |
| 3290 | break; |
| 3291 | case TCM_INVALID_CDB_FIELD: |
| 3292 | /* CURRENT ERROR */ |
| 3293 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3294 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Roland Dreier | 9fbc890 | 2012-01-09 17:54:00 -0800 | [diff] [blame] | 3295 | /* ILLEGAL REQUEST */ |
| 3296 | buffer[offset+SPC_SENSE_KEY_OFFSET] = ILLEGAL_REQUEST; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3297 | /* INVALID FIELD IN CDB */ |
| 3298 | buffer[offset+SPC_ASC_KEY_OFFSET] = 0x24; |
| 3299 | break; |
| 3300 | case TCM_INVALID_PARAMETER_LIST: |
| 3301 | /* CURRENT ERROR */ |
| 3302 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3303 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Roland Dreier | 9fbc890 | 2012-01-09 17:54:00 -0800 | [diff] [blame] | 3304 | /* ILLEGAL REQUEST */ |
| 3305 | buffer[offset+SPC_SENSE_KEY_OFFSET] = ILLEGAL_REQUEST; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3306 | /* INVALID FIELD IN PARAMETER LIST */ |
| 3307 | buffer[offset+SPC_ASC_KEY_OFFSET] = 0x26; |
| 3308 | break; |
| 3309 | case TCM_UNEXPECTED_UNSOLICITED_DATA: |
| 3310 | /* CURRENT ERROR */ |
| 3311 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3312 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3313 | /* ABORTED COMMAND */ |
| 3314 | buffer[offset+SPC_SENSE_KEY_OFFSET] = ABORTED_COMMAND; |
| 3315 | /* WRITE ERROR */ |
| 3316 | buffer[offset+SPC_ASC_KEY_OFFSET] = 0x0c; |
| 3317 | /* UNEXPECTED_UNSOLICITED_DATA */ |
| 3318 | buffer[offset+SPC_ASCQ_KEY_OFFSET] = 0x0c; |
| 3319 | break; |
| 3320 | case TCM_SERVICE_CRC_ERROR: |
| 3321 | /* CURRENT ERROR */ |
| 3322 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3323 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3324 | /* ABORTED COMMAND */ |
| 3325 | buffer[offset+SPC_SENSE_KEY_OFFSET] = ABORTED_COMMAND; |
| 3326 | /* PROTOCOL SERVICE CRC ERROR */ |
| 3327 | buffer[offset+SPC_ASC_KEY_OFFSET] = 0x47; |
| 3328 | /* N/A */ |
| 3329 | buffer[offset+SPC_ASCQ_KEY_OFFSET] = 0x05; |
| 3330 | break; |
| 3331 | case TCM_SNACK_REJECTED: |
| 3332 | /* CURRENT ERROR */ |
| 3333 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3334 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3335 | /* ABORTED COMMAND */ |
| 3336 | buffer[offset+SPC_SENSE_KEY_OFFSET] = ABORTED_COMMAND; |
| 3337 | /* READ ERROR */ |
| 3338 | buffer[offset+SPC_ASC_KEY_OFFSET] = 0x11; |
| 3339 | /* FAILED RETRANSMISSION REQUEST */ |
| 3340 | buffer[offset+SPC_ASCQ_KEY_OFFSET] = 0x13; |
| 3341 | break; |
| 3342 | case TCM_WRITE_PROTECTED: |
| 3343 | /* CURRENT ERROR */ |
| 3344 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3345 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3346 | /* DATA PROTECT */ |
| 3347 | buffer[offset+SPC_SENSE_KEY_OFFSET] = DATA_PROTECT; |
| 3348 | /* WRITE PROTECTED */ |
| 3349 | buffer[offset+SPC_ASC_KEY_OFFSET] = 0x27; |
| 3350 | break; |
| 3351 | case TCM_CHECK_CONDITION_UNIT_ATTENTION: |
| 3352 | /* CURRENT ERROR */ |
| 3353 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3354 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3355 | /* UNIT ATTENTION */ |
| 3356 | buffer[offset+SPC_SENSE_KEY_OFFSET] = UNIT_ATTENTION; |
| 3357 | core_scsi3_ua_for_check_condition(cmd, &asc, &ascq); |
| 3358 | buffer[offset+SPC_ASC_KEY_OFFSET] = asc; |
| 3359 | buffer[offset+SPC_ASCQ_KEY_OFFSET] = ascq; |
| 3360 | break; |
| 3361 | case TCM_CHECK_CONDITION_NOT_READY: |
| 3362 | /* CURRENT ERROR */ |
| 3363 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3364 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3365 | /* Not Ready */ |
| 3366 | buffer[offset+SPC_SENSE_KEY_OFFSET] = NOT_READY; |
| 3367 | transport_get_sense_codes(cmd, &asc, &ascq); |
| 3368 | buffer[offset+SPC_ASC_KEY_OFFSET] = asc; |
| 3369 | buffer[offset+SPC_ASCQ_KEY_OFFSET] = ascq; |
| 3370 | break; |
| 3371 | case TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE: |
| 3372 | default: |
| 3373 | /* CURRENT ERROR */ |
| 3374 | buffer[offset] = 0x70; |
Roland Dreier | 895f302 | 2011-12-13 14:55:33 -0800 | [diff] [blame] | 3375 | buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3376 | /* ILLEGAL REQUEST */ |
| 3377 | buffer[offset+SPC_SENSE_KEY_OFFSET] = ILLEGAL_REQUEST; |
| 3378 | /* LOGICAL UNIT COMMUNICATION FAILURE */ |
| 3379 | buffer[offset+SPC_ASC_KEY_OFFSET] = 0x80; |
| 3380 | break; |
| 3381 | } |
| 3382 | /* |
| 3383 | * This code uses linux/include/scsi/scsi.h SAM status codes! |
| 3384 | */ |
| 3385 | cmd->scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3386 | /* |
| 3387 | * Automatically padded, this value is encoded in the fabric's |
| 3388 | * data_length response PDU containing the SCSI defined sense data. |
| 3389 | */ |
| 3390 | cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER + offset; |
| 3391 | |
| 3392 | after_reason: |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 3393 | return cmd->se_tfo->queue_status(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3394 | } |
| 3395 | EXPORT_SYMBOL(transport_send_check_condition_and_sense); |
| 3396 | |
| 3397 | int transport_check_aborted_status(struct se_cmd *cmd, int send_status) |
| 3398 | { |
| 3399 | int ret = 0; |
| 3400 | |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 3401 | if (cmd->transport_state & CMD_T_ABORTED) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3402 | if (!send_status || |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3403 | (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS)) |
| 3404 | return 1; |
Andy Grover | 8b1e124 | 2012-04-03 15:51:12 -0700 | [diff] [blame] | 3405 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3406 | pr_debug("Sending delayed SAM_STAT_TASK_ABORTED" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3407 | " status for CDB: 0x%02x ITT: 0x%08x\n", |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3408 | cmd->t_task_cdb[0], |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3409 | cmd->se_tfo->get_task_tag(cmd)); |
Andy Grover | 8b1e124 | 2012-04-03 15:51:12 -0700 | [diff] [blame] | 3410 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3411 | cmd->se_cmd_flags |= SCF_SENT_DELAYED_TAS; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3412 | cmd->se_tfo->queue_status(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3413 | ret = 1; |
| 3414 | } |
| 3415 | return ret; |
| 3416 | } |
| 3417 | EXPORT_SYMBOL(transport_check_aborted_status); |
| 3418 | |
| 3419 | void transport_send_task_abort(struct se_cmd *cmd) |
| 3420 | { |
Nicholas Bellinger | c252f00 | 2011-09-29 14:22:13 -0700 | [diff] [blame] | 3421 | unsigned long flags; |
| 3422 | |
| 3423 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
| 3424 | if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION) { |
| 3425 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
| 3426 | return; |
| 3427 | } |
| 3428 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
| 3429 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3430 | /* |
| 3431 | * If there are still expected incoming fabric WRITEs, we wait |
| 3432 | * until until they have completed before sending a TASK_ABORTED |
| 3433 | * response. This response with TASK_ABORTED status will be |
| 3434 | * queued back to fabric module by transport_check_aborted_status(). |
| 3435 | */ |
| 3436 | if (cmd->data_direction == DMA_TO_DEVICE) { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3437 | if (cmd->se_tfo->write_pending_status(cmd) != 0) { |
Christoph Hellwig | 7d680f3 | 2011-12-21 14:13:47 -0500 | [diff] [blame] | 3438 | cmd->transport_state |= CMD_T_ABORTED; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3439 | smp_mb__after_atomic_inc(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3440 | } |
| 3441 | } |
| 3442 | cmd->scsi_status = SAM_STAT_TASK_ABORTED; |
Andy Grover | 8b1e124 | 2012-04-03 15:51:12 -0700 | [diff] [blame] | 3443 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3444 | pr_debug("Setting SAM_STAT_TASK_ABORTED status for CDB: 0x%02x," |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 3445 | " ITT: 0x%08x\n", cmd->t_task_cdb[0], |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3446 | cmd->se_tfo->get_task_tag(cmd)); |
Andy Grover | 8b1e124 | 2012-04-03 15:51:12 -0700 | [diff] [blame] | 3447 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3448 | cmd->se_tfo->queue_status(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3449 | } |
| 3450 | |
Christoph Hellwig | e26d99a | 2011-11-14 12:30:30 -0500 | [diff] [blame] | 3451 | static int transport_generic_do_tmr(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3452 | { |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 3453 | struct se_device *dev = cmd->se_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3454 | struct se_tmr_req *tmr = cmd->se_tmr_req; |
| 3455 | int ret; |
| 3456 | |
| 3457 | switch (tmr->function) { |
Nicholas Bellinger | 5c6cd61 | 2011-03-14 04:06:04 -0700 | [diff] [blame] | 3458 | case TMR_ABORT_TASK: |
Nicholas Bellinger | 3d28934 | 2012-02-13 02:38:14 -0800 | [diff] [blame] | 3459 | core_tmr_abort_task(dev, tmr, cmd->se_sess); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3460 | break; |
Nicholas Bellinger | 5c6cd61 | 2011-03-14 04:06:04 -0700 | [diff] [blame] | 3461 | case TMR_ABORT_TASK_SET: |
| 3462 | case TMR_CLEAR_ACA: |
| 3463 | case TMR_CLEAR_TASK_SET: |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3464 | tmr->response = TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED; |
| 3465 | break; |
Nicholas Bellinger | 5c6cd61 | 2011-03-14 04:06:04 -0700 | [diff] [blame] | 3466 | case TMR_LUN_RESET: |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3467 | ret = core_tmr_lun_reset(dev, tmr, NULL, NULL); |
| 3468 | tmr->response = (!ret) ? TMR_FUNCTION_COMPLETE : |
| 3469 | TMR_FUNCTION_REJECTED; |
| 3470 | break; |
Nicholas Bellinger | 5c6cd61 | 2011-03-14 04:06:04 -0700 | [diff] [blame] | 3471 | case TMR_TARGET_WARM_RESET: |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3472 | tmr->response = TMR_FUNCTION_REJECTED; |
| 3473 | break; |
Nicholas Bellinger | 5c6cd61 | 2011-03-14 04:06:04 -0700 | [diff] [blame] | 3474 | case TMR_TARGET_COLD_RESET: |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3475 | tmr->response = TMR_FUNCTION_REJECTED; |
| 3476 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3477 | default: |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3478 | pr_err("Uknown TMR function: 0x%02x.\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3479 | tmr->function); |
| 3480 | tmr->response = TMR_FUNCTION_REJECTED; |
| 3481 | break; |
| 3482 | } |
| 3483 | |
| 3484 | cmd->t_state = TRANSPORT_ISTATE_PROCESSING; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3485 | cmd->se_tfo->queue_tm_rsp(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3486 | |
Christoph Hellwig | b7b8bef | 2011-10-17 13:56:44 -0400 | [diff] [blame] | 3487 | transport_cmd_check_stop_to_fabric(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3488 | return 0; |
| 3489 | } |
| 3490 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3491 | /* transport_processing_thread(): |
| 3492 | * |
| 3493 | * |
| 3494 | */ |
| 3495 | static int transport_processing_thread(void *param) |
| 3496 | { |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 3497 | int ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3498 | struct se_cmd *cmd; |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 3499 | struct se_device *dev = param; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3500 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3501 | while (!kthread_should_stop()) { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3502 | ret = wait_event_interruptible(dev->dev_queue_obj.thread_wq, |
| 3503 | atomic_read(&dev->dev_queue_obj.queue_cnt) || |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3504 | kthread_should_stop()); |
| 3505 | if (ret < 0) |
| 3506 | goto out; |
| 3507 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3508 | get_cmd: |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 3509 | cmd = transport_get_cmd_from_queue(&dev->dev_queue_obj); |
| 3510 | if (!cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3511 | continue; |
| 3512 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 3513 | switch (cmd->t_state) { |
Christoph Hellwig | 680b73c | 2011-09-12 21:51:14 +0200 | [diff] [blame] | 3514 | case TRANSPORT_NEW_CMD: |
| 3515 | BUG(); |
| 3516 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3517 | case TRANSPORT_NEW_CMD_MAP: |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3518 | if (!cmd->se_tfo->new_cmd_map) { |
| 3519 | pr_err("cmd->se_tfo->new_cmd_map is" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3520 | " NULL for TRANSPORT_NEW_CMD_MAP\n"); |
| 3521 | BUG(); |
| 3522 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3523 | ret = cmd->se_tfo->new_cmd_map(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3524 | if (ret < 0) { |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 3525 | transport_generic_request_failure(cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3526 | break; |
| 3527 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3528 | ret = transport_generic_new_cmd(cmd); |
Nicholas Bellinger | f147abb | 2011-10-25 23:57:41 -0700 | [diff] [blame] | 3529 | if (ret < 0) { |
Nicholas Bellinger | 03e98c9 | 2011-11-04 02:36:16 -0700 | [diff] [blame] | 3530 | transport_generic_request_failure(cmd); |
| 3531 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3532 | } |
| 3533 | break; |
| 3534 | case TRANSPORT_PROCESS_WRITE: |
| 3535 | transport_generic_process_write(cmd); |
| 3536 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3537 | case TRANSPORT_PROCESS_TMR: |
| 3538 | transport_generic_do_tmr(cmd); |
| 3539 | break; |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 3540 | case TRANSPORT_COMPLETE_QF_WP: |
Christoph Hellwig | e057f53 | 2011-10-17 13:56:41 -0400 | [diff] [blame] | 3541 | transport_write_pending_qf(cmd); |
| 3542 | break; |
| 3543 | case TRANSPORT_COMPLETE_QF_OK: |
| 3544 | transport_complete_qf(cmd); |
Nicholas Bellinger | 07bde79 | 2011-06-13 14:46:09 -0700 | [diff] [blame] | 3545 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3546 | default: |
Christoph Hellwig | f2da9db | 2011-10-17 13:56:51 -0400 | [diff] [blame] | 3547 | pr_err("Unknown t_state: %d for ITT: 0x%08x " |
| 3548 | "i_state: %d on SE LUN: %u\n", |
| 3549 | cmd->t_state, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3550 | cmd->se_tfo->get_task_tag(cmd), |
| 3551 | cmd->se_tfo->get_cmd_state(cmd), |
| 3552 | cmd->se_lun->unpacked_lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3553 | BUG(); |
| 3554 | } |
| 3555 | |
| 3556 | goto get_cmd; |
| 3557 | } |
| 3558 | |
| 3559 | out: |
Christoph Hellwig | cf572a9 | 2012-04-24 00:25:05 -0400 | [diff] [blame] | 3560 | WARN_ON(!list_empty(&dev->state_list)); |
Nicholas Bellinger | ce8762f | 2011-10-09 02:19:01 -0700 | [diff] [blame] | 3561 | WARN_ON(!list_empty(&dev->dev_queue_obj.qobj_list)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3562 | dev->process_thread = NULL; |
| 3563 | return 0; |
| 3564 | } |