blob: 3f604393d89c376cb7754071946bd00dd95c0936 [file] [log] [blame]
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001/*******************************************************************************
2 * Filename: target_core_device.c (based on iscsi_target_device.c)
3 *
Andy Grovere3d6f902011-07-19 08:55:10 +00004 * This file contains the TCM Virtual Device and Disk Transport
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08005 * agnostic related functions.
6 *
Nicholas Bellingerfd9a11d2012-11-09 14:51:48 -08007 * (c) Copyright 2003-2012 RisingTide Systems LLC.
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08008 *
9 * Nicholas A. Bellinger <nab@kernel.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 *
25 ******************************************************************************/
26
27#include <linux/net.h>
28#include <linux/string.h>
29#include <linux/delay.h>
30#include <linux/timer.h>
31#include <linux/slab.h>
32#include <linux/spinlock.h>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080033#include <linux/kthread.h>
34#include <linux/in.h>
Paul Gortmakerc53181a2011-08-30 18:16:43 -040035#include <linux/export.h>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080036#include <net/sock.h>
37#include <net/tcp.h>
38#include <scsi/scsi.h>
Nicholas Bellinger1078da12011-05-19 20:19:13 -070039#include <scsi/scsi_device.h>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080040
41#include <target/target_core_base.h>
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050042#include <target/target_core_backend.h>
43#include <target/target_core_fabric.h>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080044
Christoph Hellwige26d99a2011-11-14 12:30:30 -050045#include "target_core_internal.h"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080046#include "target_core_alua.h"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080047#include "target_core_pr.h"
48#include "target_core_ua.h"
49
Andy Grovere3d6f902011-07-19 08:55:10 +000050static struct se_hba *lun0_hba;
Andy Grovere3d6f902011-07-19 08:55:10 +000051/* not static, needed by tpg.c */
52struct se_device *g_lun0_dev;
53
Christoph Hellwigde103c92012-11-06 12:24:09 -080054sense_reason_t
55transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080056{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080057 struct se_lun *se_lun = NULL;
Andy Grovere3d6f902011-07-19 08:55:10 +000058 struct se_session *se_sess = se_cmd->se_sess;
Andy Grover5951146d2011-07-19 10:26:37 +000059 struct se_device *dev;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080060 unsigned long flags;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080061
Christoph Hellwigde103c92012-11-06 12:24:09 -080062 if (unpacked_lun >= TRANSPORT_MAX_LUNS_PER_TPG)
63 return TCM_NON_EXISTENT_LUN;
Fubo Chend8144952011-02-13 15:13:42 -080064
Roland Dreier78faae32011-07-20 09:09:10 +000065 spin_lock_irqsave(&se_sess->se_node_acl->device_list_lock, flags);
Jörn Engelf2083242012-03-15 15:05:40 -040066 se_cmd->se_deve = se_sess->se_node_acl->device_list[unpacked_lun];
Andy Grover5951146d2011-07-19 10:26:37 +000067 if (se_cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) {
68 struct se_dev_entry *deve = se_cmd->se_deve;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080069
Andy Grover5951146d2011-07-19 10:26:37 +000070 deve->total_cmds++;
71 deve->total_bytes += se_cmd->data_length;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080072
Andy Grover5951146d2011-07-19 10:26:37 +000073 if ((se_cmd->data_direction == DMA_TO_DEVICE) &&
74 (deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY)) {
Andy Grover6708bb22011-06-08 10:36:43 -070075 pr_err("TARGET_CORE[%s]: Detected WRITE_PROTECTED LUN"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080076 " Access for 0x%08x\n",
Andy Grovere3d6f902011-07-19 08:55:10 +000077 se_cmd->se_tfo->get_fabric_name(),
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080078 unpacked_lun);
Roland Dreier78faae32011-07-20 09:09:10 +000079 spin_unlock_irqrestore(&se_sess->se_node_acl->device_list_lock, flags);
Christoph Hellwigde103c92012-11-06 12:24:09 -080080 return TCM_WRITE_PROTECTED;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080081 }
Andy Grover5951146d2011-07-19 10:26:37 +000082
83 if (se_cmd->data_direction == DMA_TO_DEVICE)
84 deve->write_bytes += se_cmd->data_length;
85 else if (se_cmd->data_direction == DMA_FROM_DEVICE)
86 deve->read_bytes += se_cmd->data_length;
87
88 deve->deve_cmds++;
89
90 se_lun = deve->se_lun;
91 se_cmd->se_lun = deve->se_lun;
92 se_cmd->pr_res_key = deve->pr_res_key;
93 se_cmd->orig_fe_lun = unpacked_lun;
Andy Grover5951146d2011-07-19 10:26:37 +000094 se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD;
95 }
Roland Dreier78faae32011-07-20 09:09:10 +000096 spin_unlock_irqrestore(&se_sess->se_node_acl->device_list_lock, flags);
Andy Grover5951146d2011-07-19 10:26:37 +000097
98 if (!se_lun) {
99 /*
100 * Use the se_portal_group->tpg_virt_lun0 to allow for
101 * REPORT_LUNS, et al to be returned when no active
102 * MappedLUN=0 exists for this Initiator Port.
103 */
104 if (unpacked_lun != 0) {
Andy Grover6708bb22011-06-08 10:36:43 -0700105 pr_err("TARGET_CORE[%s]: Detected NON_EXISTENT_LUN"
Andy Grover5951146d2011-07-19 10:26:37 +0000106 " Access for 0x%08x\n",
107 se_cmd->se_tfo->get_fabric_name(),
108 unpacked_lun);
Christoph Hellwigde103c92012-11-06 12:24:09 -0800109 return TCM_NON_EXISTENT_LUN;
Andy Grover5951146d2011-07-19 10:26:37 +0000110 }
111 /*
112 * Force WRITE PROTECT for virtual LUN 0
113 */
114 if ((se_cmd->data_direction != DMA_FROM_DEVICE) &&
Christoph Hellwigde103c92012-11-06 12:24:09 -0800115 (se_cmd->data_direction != DMA_NONE))
116 return TCM_WRITE_PROTECTED;
Andy Grover5951146d2011-07-19 10:26:37 +0000117
118 se_lun = &se_sess->se_tpg->tpg_virt_lun0;
119 se_cmd->se_lun = &se_sess->se_tpg->tpg_virt_lun0;
120 se_cmd->orig_fe_lun = 0;
Andy Grover5951146d2011-07-19 10:26:37 +0000121 se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800122 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800123
Andy Grover5951146d2011-07-19 10:26:37 +0000124 /* Directly associate cmd with se_dev */
125 se_cmd->se_dev = se_lun->lun_se_dev;
126
127 /* TODO: get rid of this and use atomics for stats */
128 dev = se_lun->lun_se_dev;
Roland Dreier78faae32011-07-20 09:09:10 +0000129 spin_lock_irqsave(&dev->stats_lock, flags);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800130 dev->num_cmds++;
131 if (se_cmd->data_direction == DMA_TO_DEVICE)
132 dev->write_bytes += se_cmd->data_length;
133 else if (se_cmd->data_direction == DMA_FROM_DEVICE)
134 dev->read_bytes += se_cmd->data_length;
Roland Dreier78faae32011-07-20 09:09:10 +0000135 spin_unlock_irqrestore(&dev->stats_lock, flags);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800136
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800137 spin_lock_irqsave(&se_lun->lun_cmd_lock, flags);
Andy Grover5951146d2011-07-19 10:26:37 +0000138 list_add_tail(&se_cmd->se_lun_node, &se_lun->lun_cmd_list);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800139 spin_unlock_irqrestore(&se_lun->lun_cmd_lock, flags);
140
141 return 0;
142}
Andy Grover5951146d2011-07-19 10:26:37 +0000143EXPORT_SYMBOL(transport_lookup_cmd_lun);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800144
Andy Grover5951146d2011-07-19 10:26:37 +0000145int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u32 unpacked_lun)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800146{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800147 struct se_dev_entry *deve;
148 struct se_lun *se_lun = NULL;
Andy Grovere3d6f902011-07-19 08:55:10 +0000149 struct se_session *se_sess = se_cmd->se_sess;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800150 struct se_tmr_req *se_tmr = se_cmd->se_tmr_req;
Roland Dreier5e1be912011-07-20 09:28:56 +0000151 unsigned long flags;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800152
Christoph Hellwigde103c92012-11-06 12:24:09 -0800153 if (unpacked_lun >= TRANSPORT_MAX_LUNS_PER_TPG)
Andy Grovere3d6f902011-07-19 08:55:10 +0000154 return -ENODEV;
Fubo Chend8144952011-02-13 15:13:42 -0800155
Roland Dreier5e1be912011-07-20 09:28:56 +0000156 spin_lock_irqsave(&se_sess->se_node_acl->device_list_lock, flags);
Jörn Engelf2083242012-03-15 15:05:40 -0400157 se_cmd->se_deve = se_sess->se_node_acl->device_list[unpacked_lun];
Andy Grover5951146d2011-07-19 10:26:37 +0000158 deve = se_cmd->se_deve;
159
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800160 if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) {
Andy Grover5951146d2011-07-19 10:26:37 +0000161 se_tmr->tmr_lun = deve->se_lun;
162 se_cmd->se_lun = deve->se_lun;
163 se_lun = deve->se_lun;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800164 se_cmd->pr_res_key = deve->pr_res_key;
165 se_cmd->orig_fe_lun = unpacked_lun;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800166 }
Roland Dreier5e1be912011-07-20 09:28:56 +0000167 spin_unlock_irqrestore(&se_sess->se_node_acl->device_list_lock, flags);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800168
169 if (!se_lun) {
Andy Grover6708bb22011-06-08 10:36:43 -0700170 pr_debug("TARGET_CORE[%s]: Detected NON_EXISTENT_LUN"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800171 " Access for 0x%08x\n",
Andy Grovere3d6f902011-07-19 08:55:10 +0000172 se_cmd->se_tfo->get_fabric_name(),
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800173 unpacked_lun);
Andy Grovere3d6f902011-07-19 08:55:10 +0000174 return -ENODEV;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800175 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800176
Andy Grover5951146d2011-07-19 10:26:37 +0000177 /* Directly associate cmd with se_dev */
178 se_cmd->se_dev = se_lun->lun_se_dev;
179 se_tmr->tmr_dev = se_lun->lun_se_dev;
180
Roland Dreier5e1be912011-07-20 09:28:56 +0000181 spin_lock_irqsave(&se_tmr->tmr_dev->se_tmr_lock, flags);
Andy Grover5951146d2011-07-19 10:26:37 +0000182 list_add_tail(&se_tmr->tmr_list, &se_tmr->tmr_dev->dev_tmr_list);
Roland Dreier5e1be912011-07-20 09:28:56 +0000183 spin_unlock_irqrestore(&se_tmr->tmr_dev->se_tmr_lock, flags);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800184
185 return 0;
186}
Andy Grover5951146d2011-07-19 10:26:37 +0000187EXPORT_SYMBOL(transport_lookup_tmr_lun);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800188
189/*
190 * This function is called from core_scsi3_emulate_pro_register_and_move()
191 * and core_scsi3_decode_spec_i_port(), and will increment &deve->pr_ref_count
192 * when a matching rtpi is found.
193 */
194struct se_dev_entry *core_get_se_deve_from_rtpi(
195 struct se_node_acl *nacl,
196 u16 rtpi)
197{
198 struct se_dev_entry *deve;
199 struct se_lun *lun;
200 struct se_port *port;
201 struct se_portal_group *tpg = nacl->se_tpg;
202 u32 i;
203
204 spin_lock_irq(&nacl->device_list_lock);
205 for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) {
Jörn Engelf2083242012-03-15 15:05:40 -0400206 deve = nacl->device_list[i];
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800207
208 if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS))
209 continue;
210
211 lun = deve->se_lun;
Andy Grover6708bb22011-06-08 10:36:43 -0700212 if (!lun) {
213 pr_err("%s device entries device pointer is"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800214 " NULL, but Initiator has access.\n",
Andy Grovere3d6f902011-07-19 08:55:10 +0000215 tpg->se_tpg_tfo->get_fabric_name());
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800216 continue;
217 }
218 port = lun->lun_sep;
Andy Grover6708bb22011-06-08 10:36:43 -0700219 if (!port) {
220 pr_err("%s device entries device pointer is"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800221 " NULL, but Initiator has access.\n",
Andy Grovere3d6f902011-07-19 08:55:10 +0000222 tpg->se_tpg_tfo->get_fabric_name());
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800223 continue;
224 }
225 if (port->sep_rtpi != rtpi)
226 continue;
227
228 atomic_inc(&deve->pr_ref_count);
229 smp_mb__after_atomic_inc();
230 spin_unlock_irq(&nacl->device_list_lock);
231
232 return deve;
233 }
234 spin_unlock_irq(&nacl->device_list_lock);
235
236 return NULL;
237}
238
239int core_free_device_list_for_node(
240 struct se_node_acl *nacl,
241 struct se_portal_group *tpg)
242{
243 struct se_dev_entry *deve;
244 struct se_lun *lun;
245 u32 i;
246
247 if (!nacl->device_list)
248 return 0;
249
250 spin_lock_irq(&nacl->device_list_lock);
251 for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) {
Jörn Engelf2083242012-03-15 15:05:40 -0400252 deve = nacl->device_list[i];
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800253
254 if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS))
255 continue;
256
257 if (!deve->se_lun) {
Andy Grover6708bb22011-06-08 10:36:43 -0700258 pr_err("%s device entries device pointer is"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800259 " NULL, but Initiator has access.\n",
Andy Grovere3d6f902011-07-19 08:55:10 +0000260 tpg->se_tpg_tfo->get_fabric_name());
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800261 continue;
262 }
263 lun = deve->se_lun;
264
265 spin_unlock_irq(&nacl->device_list_lock);
Andy Grovere80ac6c2012-07-12 17:34:58 -0700266 core_disable_device_list_for_node(lun, NULL, deve->mapped_lun,
267 TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800268 spin_lock_irq(&nacl->device_list_lock);
269 }
270 spin_unlock_irq(&nacl->device_list_lock);
271
Jörn Engelf2083242012-03-15 15:05:40 -0400272 array_free(nacl->device_list, TRANSPORT_MAX_LUNS_PER_TPG);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800273 nacl->device_list = NULL;
274
275 return 0;
276}
277
278void core_dec_lacl_count(struct se_node_acl *se_nacl, struct se_cmd *se_cmd)
279{
280 struct se_dev_entry *deve;
Sebastian Andrzej Siewior1dd0a062012-01-10 14:16:58 +0100281 unsigned long flags;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800282
Sebastian Andrzej Siewior1dd0a062012-01-10 14:16:58 +0100283 spin_lock_irqsave(&se_nacl->device_list_lock, flags);
Jörn Engelf2083242012-03-15 15:05:40 -0400284 deve = se_nacl->device_list[se_cmd->orig_fe_lun];
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800285 deve->deve_cmds--;
Sebastian Andrzej Siewior1dd0a062012-01-10 14:16:58 +0100286 spin_unlock_irqrestore(&se_nacl->device_list_lock, flags);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800287}
288
289void core_update_device_list_access(
290 u32 mapped_lun,
291 u32 lun_access,
292 struct se_node_acl *nacl)
293{
294 struct se_dev_entry *deve;
295
296 spin_lock_irq(&nacl->device_list_lock);
Jörn Engelf2083242012-03-15 15:05:40 -0400297 deve = nacl->device_list[mapped_lun];
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800298 if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) {
299 deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY;
300 deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE;
301 } else {
302 deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE;
303 deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY;
304 }
305 spin_unlock_irq(&nacl->device_list_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800306}
307
Andy Grovere80ac6c2012-07-12 17:34:58 -0700308/* core_enable_device_list_for_node():
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800309 *
310 *
311 */
Andy Grovere80ac6c2012-07-12 17:34:58 -0700312int core_enable_device_list_for_node(
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800313 struct se_lun *lun,
314 struct se_lun_acl *lun_acl,
315 u32 mapped_lun,
316 u32 lun_access,
317 struct se_node_acl *nacl,
Andy Grovere80ac6c2012-07-12 17:34:58 -0700318 struct se_portal_group *tpg)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800319{
320 struct se_port *port = lun->lun_sep;
Andy Grovere80ac6c2012-07-12 17:34:58 -0700321 struct se_dev_entry *deve;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800322
323 spin_lock_irq(&nacl->device_list_lock);
Andy Grovere80ac6c2012-07-12 17:34:58 -0700324
325 deve = nacl->device_list[mapped_lun];
326
327 /*
328 * Check if the call is handling demo mode -> explict LUN ACL
329 * transition. This transition must be for the same struct se_lun
330 * + mapped_lun that was setup in demo mode..
331 */
332 if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) {
333 if (deve->se_lun_acl != NULL) {
334 pr_err("struct se_dev_entry->se_lun_acl"
335 " already set for demo mode -> explict"
336 " LUN ACL transition\n");
337 spin_unlock_irq(&nacl->device_list_lock);
338 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800339 }
Andy Grovere80ac6c2012-07-12 17:34:58 -0700340 if (deve->se_lun != lun) {
341 pr_err("struct se_dev_entry->se_lun does"
342 " match passed struct se_lun for demo mode"
343 " -> explict LUN ACL transition\n");
344 spin_unlock_irq(&nacl->device_list_lock);
345 return -EINVAL;
346 }
347 deve->se_lun_acl = lun_acl;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800348
349 if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) {
350 deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY;
351 deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE;
352 } else {
353 deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE;
354 deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY;
355 }
356
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800357 spin_unlock_irq(&nacl->device_list_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800358 return 0;
359 }
Andy Grovere80ac6c2012-07-12 17:34:58 -0700360
361 deve->se_lun = lun;
362 deve->se_lun_acl = lun_acl;
363 deve->mapped_lun = mapped_lun;
364 deve->lun_flags |= TRANSPORT_LUNFLAGS_INITIATOR_ACCESS;
365
366 if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) {
367 deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY;
368 deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE;
369 } else {
370 deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE;
371 deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY;
372 }
373
374 deve->creation_time = get_jiffies_64();
375 deve->attach_count++;
376 spin_unlock_irq(&nacl->device_list_lock);
377
378 spin_lock_bh(&port->sep_alua_lock);
379 list_add_tail(&deve->alua_port_list, &port->sep_alua_list);
380 spin_unlock_bh(&port->sep_alua_lock);
381
382 return 0;
383}
384
385/* core_disable_device_list_for_node():
386 *
387 *
388 */
389int core_disable_device_list_for_node(
390 struct se_lun *lun,
391 struct se_lun_acl *lun_acl,
392 u32 mapped_lun,
393 u32 lun_access,
394 struct se_node_acl *nacl,
395 struct se_portal_group *tpg)
396{
397 struct se_port *port = lun->lun_sep;
Nicholas Bellinger77d4c742012-07-14 15:11:41 -0700398 struct se_dev_entry *deve = nacl->device_list[mapped_lun];
Andy Grovere80ac6c2012-07-12 17:34:58 -0700399
400 /*
401 * If the MappedLUN entry is being disabled, the entry in
402 * port->sep_alua_list must be removed now before clearing the
403 * struct se_dev_entry pointers below as logic in
404 * core_alua_do_transition_tg_pt() depends on these being present.
405 *
406 * deve->se_lun_acl will be NULL for demo-mode created LUNs
407 * that have not been explicitly converted to MappedLUNs ->
408 * struct se_lun_acl, but we remove deve->alua_port_list from
409 * port->sep_alua_list. This also means that active UAs and
410 * NodeACL context specific PR metadata for demo-mode
411 * MappedLUN *deve will be released below..
412 */
413 spin_lock_bh(&port->sep_alua_lock);
414 list_del(&deve->alua_port_list);
415 spin_unlock_bh(&port->sep_alua_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800416 /*
417 * Wait for any in process SPEC_I_PT=1 or REGISTER_AND_MOVE
418 * PR operation to complete.
419 */
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800420 while (atomic_read(&deve->pr_ref_count) != 0)
421 cpu_relax();
Nicholas Bellinger77d4c742012-07-14 15:11:41 -0700422
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800423 spin_lock_irq(&nacl->device_list_lock);
424 /*
425 * Disable struct se_dev_entry LUN ACL mapping
426 */
427 core_scsi3_ua_release_all(deve);
428 deve->se_lun = NULL;
429 deve->se_lun_acl = NULL;
430 deve->lun_flags = 0;
431 deve->creation_time = 0;
432 deve->attach_count--;
433 spin_unlock_irq(&nacl->device_list_lock);
434
435 core_scsi3_free_pr_reg_from_nacl(lun->lun_se_dev, nacl);
436 return 0;
437}
438
439/* core_clear_lun_from_tpg():
440 *
441 *
442 */
443void core_clear_lun_from_tpg(struct se_lun *lun, struct se_portal_group *tpg)
444{
445 struct se_node_acl *nacl;
446 struct se_dev_entry *deve;
447 u32 i;
448
Roland Dreier28638882011-08-16 09:40:01 -0700449 spin_lock_irq(&tpg->acl_node_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800450 list_for_each_entry(nacl, &tpg->acl_node_list, acl_list) {
Roland Dreier28638882011-08-16 09:40:01 -0700451 spin_unlock_irq(&tpg->acl_node_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800452
453 spin_lock_irq(&nacl->device_list_lock);
454 for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) {
Jörn Engelf2083242012-03-15 15:05:40 -0400455 deve = nacl->device_list[i];
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800456 if (lun != deve->se_lun)
457 continue;
458 spin_unlock_irq(&nacl->device_list_lock);
459
Andy Grovere80ac6c2012-07-12 17:34:58 -0700460 core_disable_device_list_for_node(lun, NULL,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800461 deve->mapped_lun, TRANSPORT_LUNFLAGS_NO_ACCESS,
Andy Grovere80ac6c2012-07-12 17:34:58 -0700462 nacl, tpg);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800463
464 spin_lock_irq(&nacl->device_list_lock);
465 }
466 spin_unlock_irq(&nacl->device_list_lock);
467
Roland Dreier28638882011-08-16 09:40:01 -0700468 spin_lock_irq(&tpg->acl_node_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800469 }
Roland Dreier28638882011-08-16 09:40:01 -0700470 spin_unlock_irq(&tpg->acl_node_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800471}
472
473static struct se_port *core_alloc_port(struct se_device *dev)
474{
475 struct se_port *port, *port_tmp;
476
477 port = kzalloc(sizeof(struct se_port), GFP_KERNEL);
Andy Grover6708bb22011-06-08 10:36:43 -0700478 if (!port) {
479 pr_err("Unable to allocate struct se_port\n");
Andy Grovere3d6f902011-07-19 08:55:10 +0000480 return ERR_PTR(-ENOMEM);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800481 }
482 INIT_LIST_HEAD(&port->sep_alua_list);
483 INIT_LIST_HEAD(&port->sep_list);
484 atomic_set(&port->sep_tg_pt_secondary_offline, 0);
485 spin_lock_init(&port->sep_alua_lock);
486 mutex_init(&port->sep_tg_pt_md_mutex);
487
488 spin_lock(&dev->se_port_lock);
489 if (dev->dev_port_count == 0x0000ffff) {
Andy Grover6708bb22011-06-08 10:36:43 -0700490 pr_warn("Reached dev->dev_port_count =="
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800491 " 0x0000ffff\n");
492 spin_unlock(&dev->se_port_lock);
Andy Grovere3d6f902011-07-19 08:55:10 +0000493 return ERR_PTR(-ENOSPC);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800494 }
495again:
496 /*
Masanari Iida35d1efe2012-08-16 22:43:13 +0900497 * Allocate the next RELATIVE TARGET PORT IDENTIFIER for this struct se_device
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800498 * Here is the table from spc4r17 section 7.7.3.8.
499 *
500 * Table 473 -- RELATIVE TARGET PORT IDENTIFIER field
501 *
502 * Code Description
503 * 0h Reserved
504 * 1h Relative port 1, historically known as port A
505 * 2h Relative port 2, historically known as port B
506 * 3h to FFFFh Relative port 3 through 65 535
507 */
508 port->sep_rtpi = dev->dev_rpti_counter++;
Andy Grover6708bb22011-06-08 10:36:43 -0700509 if (!port->sep_rtpi)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800510 goto again;
511
512 list_for_each_entry(port_tmp, &dev->dev_sep_list, sep_list) {
513 /*
Masanari Iida35d1efe2012-08-16 22:43:13 +0900514 * Make sure RELATIVE TARGET PORT IDENTIFIER is unique
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800515 * for 16-bit wrap..
516 */
517 if (port->sep_rtpi == port_tmp->sep_rtpi)
518 goto again;
519 }
520 spin_unlock(&dev->se_port_lock);
521
522 return port;
523}
524
525static void core_export_port(
526 struct se_device *dev,
527 struct se_portal_group *tpg,
528 struct se_port *port,
529 struct se_lun *lun)
530{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800531 struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem = NULL;
532
533 spin_lock(&dev->se_port_lock);
534 spin_lock(&lun->lun_sep_lock);
535 port->sep_tpg = tpg;
536 port->sep_lun = lun;
537 lun->lun_sep = port;
538 spin_unlock(&lun->lun_sep_lock);
539
540 list_add_tail(&port->sep_list, &dev->dev_sep_list);
541 spin_unlock(&dev->se_port_lock);
542
Christoph Hellwigc87fbd52012-10-10 17:37:16 -0400543 if (dev->transport->transport_type != TRANSPORT_PLUGIN_PHBA_PDEV &&
544 !(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800545 tg_pt_gp_mem = core_alua_allocate_tg_pt_gp_mem(port);
546 if (IS_ERR(tg_pt_gp_mem) || !tg_pt_gp_mem) {
Andy Grover6708bb22011-06-08 10:36:43 -0700547 pr_err("Unable to allocate t10_alua_tg_pt"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800548 "_gp_member_t\n");
549 return;
550 }
551 spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock);
552 __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem,
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400553 dev->t10_alua.default_tg_pt_gp);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800554 spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock);
Andy Grover6708bb22011-06-08 10:36:43 -0700555 pr_debug("%s/%s: Adding to default ALUA Target Port"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800556 " Group: alua/default_tg_pt_gp\n",
Andy Grovere3d6f902011-07-19 08:55:10 +0000557 dev->transport->name, tpg->se_tpg_tfo->get_fabric_name());
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800558 }
559
560 dev->dev_port_count++;
Masanari Iida35d1efe2012-08-16 22:43:13 +0900561 port->sep_index = port->sep_rtpi; /* RELATIVE TARGET PORT IDENTIFIER */
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800562}
563
564/*
565 * Called with struct se_device->se_port_lock spinlock held.
566 */
567static void core_release_port(struct se_device *dev, struct se_port *port)
Dan Carpenter5dd7ed22011-03-14 04:06:01 -0700568 __releases(&dev->se_port_lock) __acquires(&dev->se_port_lock)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800569{
570 /*
571 * Wait for any port reference for PR ALL_TG_PT=1 operation
572 * to complete in __core_scsi3_alloc_registration()
573 */
574 spin_unlock(&dev->se_port_lock);
575 if (atomic_read(&port->sep_tg_pt_ref_cnt))
576 cpu_relax();
577 spin_lock(&dev->se_port_lock);
578
579 core_alua_free_tg_pt_gp_mem(port);
580
581 list_del(&port->sep_list);
582 dev->dev_port_count--;
583 kfree(port);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800584}
585
586int core_dev_export(
587 struct se_device *dev,
588 struct se_portal_group *tpg,
589 struct se_lun *lun)
590{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400591 struct se_hba *hba = dev->se_hba;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800592 struct se_port *port;
593
594 port = core_alloc_port(dev);
Andy Grovere3d6f902011-07-19 08:55:10 +0000595 if (IS_ERR(port))
596 return PTR_ERR(port);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800597
598 lun->lun_se_dev = dev;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800599
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400600 spin_lock(&hba->device_lock);
601 dev->export_count++;
602 spin_unlock(&hba->device_lock);
603
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800604 core_export_port(dev, tpg, port, lun);
605 return 0;
606}
607
608void core_dev_unexport(
609 struct se_device *dev,
610 struct se_portal_group *tpg,
611 struct se_lun *lun)
612{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400613 struct se_hba *hba = dev->se_hba;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800614 struct se_port *port = lun->lun_sep;
615
616 spin_lock(&lun->lun_sep_lock);
617 if (lun->lun_se_dev == NULL) {
618 spin_unlock(&lun->lun_sep_lock);
619 return;
620 }
621 spin_unlock(&lun->lun_sep_lock);
622
623 spin_lock(&dev->se_port_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800624 core_release_port(dev, port);
625 spin_unlock(&dev->se_port_lock);
626
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400627 spin_lock(&hba->device_lock);
628 dev->export_count--;
629 spin_unlock(&hba->device_lock);
630
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800631 lun->lun_se_dev = NULL;
632}
633
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400634static void se_release_vpd_for_dev(struct se_device *dev)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800635{
636 struct t10_vpd *vpd, *vpd_tmp;
637
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400638 spin_lock(&dev->t10_wwn.t10_vpd_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800639 list_for_each_entry_safe(vpd, vpd_tmp,
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400640 &dev->t10_wwn.t10_vpd_list, vpd_list) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800641 list_del(&vpd->vpd_list);
642 kfree(vpd);
643 }
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400644 spin_unlock(&dev->t10_wwn.t10_vpd_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800645}
646
Roland Dreierc8045372012-07-16 15:17:12 -0700647static u32 se_dev_align_max_sectors(u32 max_sectors, u32 block_size)
Nicholas Bellinger525a48a2011-08-13 02:11:38 -0700648{
Roland Dreier3e039892012-10-31 09:16:45 -0700649 u32 aligned_max_sectors;
650 u32 alignment;
Nicholas Bellinger525a48a2011-08-13 02:11:38 -0700651 /*
652 * Limit max_sectors to a PAGE_SIZE aligned value for modern
653 * transport_allocate_data_tasks() operation.
654 */
Roland Dreier3e039892012-10-31 09:16:45 -0700655 alignment = max(1ul, PAGE_SIZE / block_size);
656 aligned_max_sectors = rounddown(max_sectors, alignment);
Nicholas Bellinger525a48a2011-08-13 02:11:38 -0700657
Roland Dreier3e039892012-10-31 09:16:45 -0700658 if (max_sectors != aligned_max_sectors)
659 pr_info("Rounding down aligned max_sectors from %u to %u\n",
660 max_sectors, aligned_max_sectors);
661
662 return aligned_max_sectors;
Nicholas Bellinger525a48a2011-08-13 02:11:38 -0700663}
664
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800665int se_dev_set_max_unmap_lba_count(
666 struct se_device *dev,
667 u32 max_unmap_lba_count)
668{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400669 dev->dev_attrib.max_unmap_lba_count = max_unmap_lba_count;
Andy Grover6708bb22011-06-08 10:36:43 -0700670 pr_debug("dev[%p]: Set max_unmap_lba_count: %u\n",
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400671 dev, dev->dev_attrib.max_unmap_lba_count);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800672 return 0;
673}
674
675int se_dev_set_max_unmap_block_desc_count(
676 struct se_device *dev,
677 u32 max_unmap_block_desc_count)
678{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400679 dev->dev_attrib.max_unmap_block_desc_count =
Andy Grovere3d6f902011-07-19 08:55:10 +0000680 max_unmap_block_desc_count;
Andy Grover6708bb22011-06-08 10:36:43 -0700681 pr_debug("dev[%p]: Set max_unmap_block_desc_count: %u\n",
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400682 dev, dev->dev_attrib.max_unmap_block_desc_count);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800683 return 0;
684}
685
686int se_dev_set_unmap_granularity(
687 struct se_device *dev,
688 u32 unmap_granularity)
689{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400690 dev->dev_attrib.unmap_granularity = unmap_granularity;
Andy Grover6708bb22011-06-08 10:36:43 -0700691 pr_debug("dev[%p]: Set unmap_granularity: %u\n",
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400692 dev, dev->dev_attrib.unmap_granularity);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800693 return 0;
694}
695
696int se_dev_set_unmap_granularity_alignment(
697 struct se_device *dev,
698 u32 unmap_granularity_alignment)
699{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400700 dev->dev_attrib.unmap_granularity_alignment = unmap_granularity_alignment;
Andy Grover6708bb22011-06-08 10:36:43 -0700701 pr_debug("dev[%p]: Set unmap_granularity_alignment: %u\n",
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400702 dev, dev->dev_attrib.unmap_granularity_alignment);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800703 return 0;
704}
705
Nicholas Bellinger773cbaf2012-11-15 11:02:49 -0800706int se_dev_set_max_write_same_len(
707 struct se_device *dev,
708 u32 max_write_same_len)
709{
710 dev->dev_attrib.max_write_same_len = max_write_same_len;
711 pr_debug("dev[%p]: Set max_write_same_len: %u\n",
712 dev, dev->dev_attrib.max_write_same_len);
713 return 0;
714}
715
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800716int se_dev_set_emulate_dpo(struct se_device *dev, int flag)
717{
Christoph Hellwigf55918f2011-10-14 07:30:17 -0400718 if (flag != 0 && flag != 1) {
Andy Grover6708bb22011-06-08 10:36:43 -0700719 pr_err("Illegal value %d\n", flag);
Andy Grovere3d6f902011-07-19 08:55:10 +0000720 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800721 }
Christoph Hellwigf55918f2011-10-14 07:30:17 -0400722
Andy Groverc6388302011-11-30 12:11:50 -0800723 if (flag) {
724 pr_err("dpo_emulated not supported\n");
725 return -EINVAL;
726 }
727
728 return 0;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800729}
730
731int se_dev_set_emulate_fua_write(struct se_device *dev, int flag)
732{
Christoph Hellwigf55918f2011-10-14 07:30:17 -0400733 if (flag != 0 && flag != 1) {
Andy Grover6708bb22011-06-08 10:36:43 -0700734 pr_err("Illegal value %d\n", flag);
Andy Grovere3d6f902011-07-19 08:55:10 +0000735 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800736 }
Christoph Hellwigf55918f2011-10-14 07:30:17 -0400737
Nicholas Bellingerfd30e932012-08-26 13:35:58 -0700738 if (flag &&
739 dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) {
740 pr_err("emulate_fua_write not supported for pSCSI\n");
Andy Grovere3d6f902011-07-19 08:55:10 +0000741 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800742 }
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400743 dev->dev_attrib.emulate_fua_write = flag;
Andy Grover6708bb22011-06-08 10:36:43 -0700744 pr_debug("dev[%p]: SE Device Forced Unit Access WRITEs: %d\n",
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400745 dev, dev->dev_attrib.emulate_fua_write);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800746 return 0;
747}
748
749int se_dev_set_emulate_fua_read(struct se_device *dev, int flag)
750{
Christoph Hellwigf55918f2011-10-14 07:30:17 -0400751 if (flag != 0 && flag != 1) {
Andy Grover6708bb22011-06-08 10:36:43 -0700752 pr_err("Illegal value %d\n", flag);
Andy Grovere3d6f902011-07-19 08:55:10 +0000753 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800754 }
Christoph Hellwigf55918f2011-10-14 07:30:17 -0400755
Andy Groverc6388302011-11-30 12:11:50 -0800756 if (flag) {
757 pr_err("ua read emulated not supported\n");
758 return -EINVAL;
759 }
760
761 return 0;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800762}
763
764int se_dev_set_emulate_write_cache(struct se_device *dev, int flag)
765{
Christoph Hellwigf55918f2011-10-14 07:30:17 -0400766 if (flag != 0 && flag != 1) {
Andy Grover6708bb22011-06-08 10:36:43 -0700767 pr_err("Illegal value %d\n", flag);
Andy Grovere3d6f902011-07-19 08:55:10 +0000768 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800769 }
Nicholas Bellingerfd30e932012-08-26 13:35:58 -0700770 if (flag &&
771 dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) {
772 pr_err("emulate_write_cache not supported for pSCSI\n");
Andy Grovere3d6f902011-07-19 08:55:10 +0000773 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800774 }
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400775 dev->dev_attrib.emulate_write_cache = flag;
Andy Grover6708bb22011-06-08 10:36:43 -0700776 pr_debug("dev[%p]: SE Device WRITE_CACHE_EMULATION flag: %d\n",
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400777 dev, dev->dev_attrib.emulate_write_cache);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800778 return 0;
779}
780
781int se_dev_set_emulate_ua_intlck_ctrl(struct se_device *dev, int flag)
782{
783 if ((flag != 0) && (flag != 1) && (flag != 2)) {
Andy Grover6708bb22011-06-08 10:36:43 -0700784 pr_err("Illegal value %d\n", flag);
Andy Grovere3d6f902011-07-19 08:55:10 +0000785 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800786 }
787
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400788 if (dev->export_count) {
Andy Grover6708bb22011-06-08 10:36:43 -0700789 pr_err("dev[%p]: Unable to change SE Device"
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400790 " UA_INTRLCK_CTRL while export_count is %d\n",
791 dev, dev->export_count);
Andy Grovere3d6f902011-07-19 08:55:10 +0000792 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800793 }
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400794 dev->dev_attrib.emulate_ua_intlck_ctrl = flag;
Andy Grover6708bb22011-06-08 10:36:43 -0700795 pr_debug("dev[%p]: SE Device UA_INTRLCK_CTRL flag: %d\n",
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400796 dev, dev->dev_attrib.emulate_ua_intlck_ctrl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800797
798 return 0;
799}
800
801int se_dev_set_emulate_tas(struct se_device *dev, int flag)
802{
803 if ((flag != 0) && (flag != 1)) {
Andy Grover6708bb22011-06-08 10:36:43 -0700804 pr_err("Illegal value %d\n", flag);
Andy Grovere3d6f902011-07-19 08:55:10 +0000805 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800806 }
807
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400808 if (dev->export_count) {
Andy Grover6708bb22011-06-08 10:36:43 -0700809 pr_err("dev[%p]: Unable to change SE Device TAS while"
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400810 " export_count is %d\n",
811 dev, dev->export_count);
Andy Grovere3d6f902011-07-19 08:55:10 +0000812 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800813 }
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400814 dev->dev_attrib.emulate_tas = flag;
Andy Grover6708bb22011-06-08 10:36:43 -0700815 pr_debug("dev[%p]: SE Device TASK_ABORTED status bit: %s\n",
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400816 dev, (dev->dev_attrib.emulate_tas) ? "Enabled" : "Disabled");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800817
818 return 0;
819}
820
821int se_dev_set_emulate_tpu(struct se_device *dev, int flag)
822{
823 if ((flag != 0) && (flag != 1)) {
Andy Grover6708bb22011-06-08 10:36:43 -0700824 pr_err("Illegal value %d\n", flag);
Andy Grovere3d6f902011-07-19 08:55:10 +0000825 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800826 }
827 /*
828 * We expect this value to be non-zero when generic Block Layer
829 * Discard supported is detected iblock_create_virtdevice().
830 */
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400831 if (flag && !dev->dev_attrib.max_unmap_block_desc_count) {
Andy Grover6708bb22011-06-08 10:36:43 -0700832 pr_err("Generic Block Discard not supported\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800833 return -ENOSYS;
834 }
835
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400836 dev->dev_attrib.emulate_tpu = flag;
Andy Grover6708bb22011-06-08 10:36:43 -0700837 pr_debug("dev[%p]: SE Device Thin Provisioning UNMAP bit: %d\n",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800838 dev, flag);
839 return 0;
840}
841
842int se_dev_set_emulate_tpws(struct se_device *dev, int flag)
843{
844 if ((flag != 0) && (flag != 1)) {
Andy Grover6708bb22011-06-08 10:36:43 -0700845 pr_err("Illegal value %d\n", flag);
Andy Grovere3d6f902011-07-19 08:55:10 +0000846 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800847 }
848 /*
849 * We expect this value to be non-zero when generic Block Layer
850 * Discard supported is detected iblock_create_virtdevice().
851 */
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400852 if (flag && !dev->dev_attrib.max_unmap_block_desc_count) {
Andy Grover6708bb22011-06-08 10:36:43 -0700853 pr_err("Generic Block Discard not supported\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800854 return -ENOSYS;
855 }
856
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400857 dev->dev_attrib.emulate_tpws = flag;
Andy Grover6708bb22011-06-08 10:36:43 -0700858 pr_debug("dev[%p]: SE Device Thin Provisioning WRITE_SAME: %d\n",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800859 dev, flag);
860 return 0;
861}
862
863int se_dev_set_enforce_pr_isids(struct se_device *dev, int flag)
864{
865 if ((flag != 0) && (flag != 1)) {
Andy Grover6708bb22011-06-08 10:36:43 -0700866 pr_err("Illegal value %d\n", flag);
Andy Grovere3d6f902011-07-19 08:55:10 +0000867 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800868 }
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400869 dev->dev_attrib.enforce_pr_isids = flag;
Andy Grover6708bb22011-06-08 10:36:43 -0700870 pr_debug("dev[%p]: SE Device enforce_pr_isids bit: %s\n", dev,
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400871 (dev->dev_attrib.enforce_pr_isids) ? "Enabled" : "Disabled");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800872 return 0;
873}
874
Roland Dreiere22a7f02011-07-05 13:34:52 -0700875int se_dev_set_is_nonrot(struct se_device *dev, int flag)
876{
877 if ((flag != 0) && (flag != 1)) {
878 printk(KERN_ERR "Illegal value %d\n", flag);
879 return -EINVAL;
880 }
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400881 dev->dev_attrib.is_nonrot = flag;
Nicholas Bellinger5de619a2011-07-17 02:57:58 -0700882 pr_debug("dev[%p]: SE Device is_nonrot bit: %d\n",
Roland Dreiere22a7f02011-07-05 13:34:52 -0700883 dev, flag);
884 return 0;
885}
886
Nicholas Bellinger5de619a2011-07-17 02:57:58 -0700887int se_dev_set_emulate_rest_reord(struct se_device *dev, int flag)
888{
889 if (flag != 0) {
890 printk(KERN_ERR "dev[%p]: SE Device emulatation of restricted"
891 " reordering not implemented\n", dev);
892 return -ENOSYS;
893 }
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400894 dev->dev_attrib.emulate_rest_reord = flag;
Nicholas Bellinger5de619a2011-07-17 02:57:58 -0700895 pr_debug("dev[%p]: SE Device emulate_rest_reord: %d\n", dev, flag);
896 return 0;
897}
898
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800899/*
900 * Note, this can only be called on unexported SE Device Object.
901 */
902int se_dev_set_queue_depth(struct se_device *dev, u32 queue_depth)
903{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400904 if (dev->export_count) {
Andy Grover6708bb22011-06-08 10:36:43 -0700905 pr_err("dev[%p]: Unable to change SE Device TCQ while"
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400906 " export_count is %d\n",
907 dev, dev->export_count);
Andy Grovere3d6f902011-07-19 08:55:10 +0000908 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800909 }
Andy Grover6708bb22011-06-08 10:36:43 -0700910 if (!queue_depth) {
911 pr_err("dev[%p]: Illegal ZERO value for queue"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800912 "_depth\n", dev);
Andy Grovere3d6f902011-07-19 08:55:10 +0000913 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800914 }
915
Andy Grovere3d6f902011-07-19 08:55:10 +0000916 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) {
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400917 if (queue_depth > dev->dev_attrib.hw_queue_depth) {
Andy Grover6708bb22011-06-08 10:36:43 -0700918 pr_err("dev[%p]: Passed queue_depth: %u"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800919 " exceeds TCM/SE_Device TCQ: %u\n",
920 dev, queue_depth,
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400921 dev->dev_attrib.hw_queue_depth);
Andy Grovere3d6f902011-07-19 08:55:10 +0000922 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800923 }
924 } else {
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400925 if (queue_depth > dev->dev_attrib.queue_depth) {
926 if (queue_depth > dev->dev_attrib.hw_queue_depth) {
Andy Grover6708bb22011-06-08 10:36:43 -0700927 pr_err("dev[%p]: Passed queue_depth:"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800928 " %u exceeds TCM/SE_Device MAX"
929 " TCQ: %u\n", dev, queue_depth,
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400930 dev->dev_attrib.hw_queue_depth);
Andy Grovere3d6f902011-07-19 08:55:10 +0000931 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800932 }
933 }
934 }
935
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400936 dev->dev_attrib.queue_depth = dev->queue_depth = queue_depth;
Andy Grover6708bb22011-06-08 10:36:43 -0700937 pr_debug("dev[%p]: SE Device TCQ Depth changed to: %u\n",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800938 dev, queue_depth);
939 return 0;
940}
941
Roland Dreier015487b2012-02-13 16:18:17 -0800942int se_dev_set_fabric_max_sectors(struct se_device *dev, u32 fabric_max_sectors)
943{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400944 if (dev->export_count) {
Roland Dreier015487b2012-02-13 16:18:17 -0800945 pr_err("dev[%p]: Unable to change SE Device"
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400946 " fabric_max_sectors while export_count is %d\n",
947 dev, dev->export_count);
Roland Dreier015487b2012-02-13 16:18:17 -0800948 return -EINVAL;
949 }
950 if (!fabric_max_sectors) {
951 pr_err("dev[%p]: Illegal ZERO value for"
952 " fabric_max_sectors\n", dev);
953 return -EINVAL;
954 }
955 if (fabric_max_sectors < DA_STATUS_MAX_SECTORS_MIN) {
956 pr_err("dev[%p]: Passed fabric_max_sectors: %u less than"
957 " DA_STATUS_MAX_SECTORS_MIN: %u\n", dev, fabric_max_sectors,
958 DA_STATUS_MAX_SECTORS_MIN);
959 return -EINVAL;
960 }
961 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) {
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400962 if (fabric_max_sectors > dev->dev_attrib.hw_max_sectors) {
Roland Dreier015487b2012-02-13 16:18:17 -0800963 pr_err("dev[%p]: Passed fabric_max_sectors: %u"
964 " greater than TCM/SE_Device max_sectors:"
965 " %u\n", dev, fabric_max_sectors,
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400966 dev->dev_attrib.hw_max_sectors);
Roland Dreier015487b2012-02-13 16:18:17 -0800967 return -EINVAL;
968 }
969 } else {
970 if (fabric_max_sectors > DA_STATUS_MAX_SECTORS_MAX) {
971 pr_err("dev[%p]: Passed fabric_max_sectors: %u"
972 " greater than DA_STATUS_MAX_SECTORS_MAX:"
973 " %u\n", dev, fabric_max_sectors,
974 DA_STATUS_MAX_SECTORS_MAX);
975 return -EINVAL;
976 }
977 }
978 /*
979 * Align max_sectors down to PAGE_SIZE to follow transport_allocate_data_tasks()
980 */
981 fabric_max_sectors = se_dev_align_max_sectors(fabric_max_sectors,
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400982 dev->dev_attrib.block_size);
Roland Dreier015487b2012-02-13 16:18:17 -0800983
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400984 dev->dev_attrib.fabric_max_sectors = fabric_max_sectors;
Roland Dreier015487b2012-02-13 16:18:17 -0800985 pr_debug("dev[%p]: SE Device max_sectors changed to %u\n",
986 dev, fabric_max_sectors);
987 return 0;
988}
989
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800990int se_dev_set_optimal_sectors(struct se_device *dev, u32 optimal_sectors)
991{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400992 if (dev->export_count) {
Andy Grover6708bb22011-06-08 10:36:43 -0700993 pr_err("dev[%p]: Unable to change SE Device"
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400994 " optimal_sectors while export_count is %d\n",
995 dev, dev->export_count);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800996 return -EINVAL;
997 }
Andy Grovere3d6f902011-07-19 08:55:10 +0000998 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) {
Andy Grover6708bb22011-06-08 10:36:43 -0700999 pr_err("dev[%p]: Passed optimal_sectors cannot be"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001000 " changed for TCM/pSCSI\n", dev);
1001 return -EINVAL;
1002 }
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001003 if (optimal_sectors > dev->dev_attrib.fabric_max_sectors) {
Andy Grover6708bb22011-06-08 10:36:43 -07001004 pr_err("dev[%p]: Passed optimal_sectors %u cannot be"
Roland Dreier015487b2012-02-13 16:18:17 -08001005 " greater than fabric_max_sectors: %u\n", dev,
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001006 optimal_sectors, dev->dev_attrib.fabric_max_sectors);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001007 return -EINVAL;
1008 }
1009
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001010 dev->dev_attrib.optimal_sectors = optimal_sectors;
Andy Grover6708bb22011-06-08 10:36:43 -07001011 pr_debug("dev[%p]: SE Device optimal_sectors changed to %u\n",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001012 dev, optimal_sectors);
1013 return 0;
1014}
1015
1016int se_dev_set_block_size(struct se_device *dev, u32 block_size)
1017{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001018 if (dev->export_count) {
Andy Grover6708bb22011-06-08 10:36:43 -07001019 pr_err("dev[%p]: Unable to change SE Device block_size"
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001020 " while export_count is %d\n",
1021 dev, dev->export_count);
Andy Grovere3d6f902011-07-19 08:55:10 +00001022 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001023 }
1024
1025 if ((block_size != 512) &&
1026 (block_size != 1024) &&
1027 (block_size != 2048) &&
1028 (block_size != 4096)) {
Andy Grover6708bb22011-06-08 10:36:43 -07001029 pr_err("dev[%p]: Illegal value for block_device: %u"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001030 " for SE device, must be 512, 1024, 2048 or 4096\n",
1031 dev, block_size);
Andy Grovere3d6f902011-07-19 08:55:10 +00001032 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001033 }
1034
Andy Grovere3d6f902011-07-19 08:55:10 +00001035 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) {
Andy Grover6708bb22011-06-08 10:36:43 -07001036 pr_err("dev[%p]: Not allowed to change block_size for"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001037 " Physical Device, use for Linux/SCSI to change"
1038 " block_size for underlying hardware\n", dev);
Andy Grovere3d6f902011-07-19 08:55:10 +00001039 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001040 }
1041
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001042 dev->dev_attrib.block_size = block_size;
Andy Grover6708bb22011-06-08 10:36:43 -07001043 pr_debug("dev[%p]: SE Device block_size changed to %u\n",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001044 dev, block_size);
1045 return 0;
1046}
1047
1048struct se_lun *core_dev_add_lun(
1049 struct se_portal_group *tpg,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001050 struct se_device *dev,
1051 u32 lun)
1052{
1053 struct se_lun *lun_p;
Sebastian Andrzej Siewior8d9efe52012-01-11 21:43:38 +01001054 int rc;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001055
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001056 lun_p = core_tpg_pre_addlun(tpg, lun);
Sebastian Andrzej Siewior8d9efe52012-01-11 21:43:38 +01001057 if (IS_ERR(lun_p))
1058 return lun_p;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001059
Nicholas Bellinger58d92612012-03-20 21:26:48 -07001060 rc = core_tpg_post_addlun(tpg, lun_p,
1061 TRANSPORT_LUNFLAGS_READ_WRITE, dev);
Sebastian Andrzej Siewior8d9efe52012-01-11 21:43:38 +01001062 if (rc < 0)
1063 return ERR_PTR(rc);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001064
Andy Grover6708bb22011-06-08 10:36:43 -07001065 pr_debug("%s_TPG[%u]_LUN[%u] - Activated %s Logical Unit from"
Andy Grovere3d6f902011-07-19 08:55:10 +00001066 " CORE HBA: %u\n", tpg->se_tpg_tfo->get_fabric_name(),
1067 tpg->se_tpg_tfo->tpg_get_tag(tpg), lun_p->unpacked_lun,
Andy Grover2dca6732012-07-12 17:34:55 -07001068 tpg->se_tpg_tfo->get_fabric_name(), dev->se_hba->hba_id);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001069 /*
1070 * Update LUN maps for dynamically added initiators when
1071 * generate_node_acl is enabled.
1072 */
Andy Grovere3d6f902011-07-19 08:55:10 +00001073 if (tpg->se_tpg_tfo->tpg_check_demo_mode(tpg)) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001074 struct se_node_acl *acl;
Roland Dreier28638882011-08-16 09:40:01 -07001075 spin_lock_irq(&tpg->acl_node_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001076 list_for_each_entry(acl, &tpg->acl_node_list, acl_list) {
Nicholas Bellinger052605c2011-07-26 17:48:43 -07001077 if (acl->dynamic_node_acl &&
1078 (!tpg->se_tpg_tfo->tpg_check_demo_mode_login_only ||
1079 !tpg->se_tpg_tfo->tpg_check_demo_mode_login_only(tpg))) {
Roland Dreier28638882011-08-16 09:40:01 -07001080 spin_unlock_irq(&tpg->acl_node_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001081 core_tpg_add_node_to_devs(acl, tpg);
Roland Dreier28638882011-08-16 09:40:01 -07001082 spin_lock_irq(&tpg->acl_node_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001083 }
1084 }
Roland Dreier28638882011-08-16 09:40:01 -07001085 spin_unlock_irq(&tpg->acl_node_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001086 }
1087
1088 return lun_p;
1089}
1090
1091/* core_dev_del_lun():
1092 *
1093 *
1094 */
1095int core_dev_del_lun(
1096 struct se_portal_group *tpg,
1097 u32 unpacked_lun)
1098{
1099 struct se_lun *lun;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001100
Sebastian Andrzej Siewior8d9efe52012-01-11 21:43:38 +01001101 lun = core_tpg_pre_dellun(tpg, unpacked_lun);
1102 if (IS_ERR(lun))
1103 return PTR_ERR(lun);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001104
1105 core_tpg_post_dellun(tpg, lun);
1106
Andy Grover6708bb22011-06-08 10:36:43 -07001107 pr_debug("%s_TPG[%u]_LUN[%u] - Deactivated %s Logical Unit from"
Andy Grovere3d6f902011-07-19 08:55:10 +00001108 " device object\n", tpg->se_tpg_tfo->get_fabric_name(),
1109 tpg->se_tpg_tfo->tpg_get_tag(tpg), unpacked_lun,
1110 tpg->se_tpg_tfo->get_fabric_name());
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001111
1112 return 0;
1113}
1114
1115struct se_lun *core_get_lun_from_tpg(struct se_portal_group *tpg, u32 unpacked_lun)
1116{
1117 struct se_lun *lun;
1118
1119 spin_lock(&tpg->tpg_lun_lock);
1120 if (unpacked_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) {
Andy Grover6708bb22011-06-08 10:36:43 -07001121 pr_err("%s LUN: %u exceeds TRANSPORT_MAX_LUNS"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001122 "_PER_TPG-1: %u for Target Portal Group: %hu\n",
Andy Grovere3d6f902011-07-19 08:55:10 +00001123 tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001124 TRANSPORT_MAX_LUNS_PER_TPG-1,
Andy Grovere3d6f902011-07-19 08:55:10 +00001125 tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001126 spin_unlock(&tpg->tpg_lun_lock);
1127 return NULL;
1128 }
Jörn Engel4a5a75f2012-03-15 15:05:12 -04001129 lun = tpg->tpg_lun_list[unpacked_lun];
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001130
1131 if (lun->lun_status != TRANSPORT_LUN_STATUS_FREE) {
Andy Grover6708bb22011-06-08 10:36:43 -07001132 pr_err("%s Logical Unit Number: %u is not free on"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001133 " Target Portal Group: %hu, ignoring request.\n",
Andy Grovere3d6f902011-07-19 08:55:10 +00001134 tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun,
1135 tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001136 spin_unlock(&tpg->tpg_lun_lock);
1137 return NULL;
1138 }
1139 spin_unlock(&tpg->tpg_lun_lock);
1140
1141 return lun;
1142}
1143
1144/* core_dev_get_lun():
1145 *
1146 *
1147 */
1148static struct se_lun *core_dev_get_lun(struct se_portal_group *tpg, u32 unpacked_lun)
1149{
1150 struct se_lun *lun;
1151
1152 spin_lock(&tpg->tpg_lun_lock);
1153 if (unpacked_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) {
Andy Grover6708bb22011-06-08 10:36:43 -07001154 pr_err("%s LUN: %u exceeds TRANSPORT_MAX_LUNS_PER"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001155 "_TPG-1: %u for Target Portal Group: %hu\n",
Andy Grovere3d6f902011-07-19 08:55:10 +00001156 tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001157 TRANSPORT_MAX_LUNS_PER_TPG-1,
Andy Grovere3d6f902011-07-19 08:55:10 +00001158 tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001159 spin_unlock(&tpg->tpg_lun_lock);
1160 return NULL;
1161 }
Jörn Engel4a5a75f2012-03-15 15:05:12 -04001162 lun = tpg->tpg_lun_list[unpacked_lun];
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001163
1164 if (lun->lun_status != TRANSPORT_LUN_STATUS_ACTIVE) {
Andy Grover6708bb22011-06-08 10:36:43 -07001165 pr_err("%s Logical Unit Number: %u is not active on"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001166 " Target Portal Group: %hu, ignoring request.\n",
Andy Grovere3d6f902011-07-19 08:55:10 +00001167 tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun,
1168 tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001169 spin_unlock(&tpg->tpg_lun_lock);
1170 return NULL;
1171 }
1172 spin_unlock(&tpg->tpg_lun_lock);
1173
1174 return lun;
1175}
1176
1177struct se_lun_acl *core_dev_init_initiator_node_lun_acl(
1178 struct se_portal_group *tpg,
1179 u32 mapped_lun,
1180 char *initiatorname,
1181 int *ret)
1182{
1183 struct se_lun_acl *lacl;
1184 struct se_node_acl *nacl;
1185
Dan Carpenter60d645a2011-06-15 10:03:05 -07001186 if (strlen(initiatorname) >= TRANSPORT_IQN_LEN) {
Andy Grover6708bb22011-06-08 10:36:43 -07001187 pr_err("%s InitiatorName exceeds maximum size.\n",
Andy Grovere3d6f902011-07-19 08:55:10 +00001188 tpg->se_tpg_tfo->get_fabric_name());
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001189 *ret = -EOVERFLOW;
1190 return NULL;
1191 }
1192 nacl = core_tpg_get_initiator_node_acl(tpg, initiatorname);
Andy Grover6708bb22011-06-08 10:36:43 -07001193 if (!nacl) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001194 *ret = -EINVAL;
1195 return NULL;
1196 }
1197 lacl = kzalloc(sizeof(struct se_lun_acl), GFP_KERNEL);
Andy Grover6708bb22011-06-08 10:36:43 -07001198 if (!lacl) {
1199 pr_err("Unable to allocate memory for struct se_lun_acl.\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001200 *ret = -ENOMEM;
1201 return NULL;
1202 }
1203
1204 INIT_LIST_HEAD(&lacl->lacl_list);
1205 lacl->mapped_lun = mapped_lun;
1206 lacl->se_lun_nacl = nacl;
1207 snprintf(lacl->initiatorname, TRANSPORT_IQN_LEN, "%s", initiatorname);
1208
1209 return lacl;
1210}
1211
1212int core_dev_add_initiator_node_lun_acl(
1213 struct se_portal_group *tpg,
1214 struct se_lun_acl *lacl,
1215 u32 unpacked_lun,
1216 u32 lun_access)
1217{
1218 struct se_lun *lun;
1219 struct se_node_acl *nacl;
1220
1221 lun = core_dev_get_lun(tpg, unpacked_lun);
Andy Grover6708bb22011-06-08 10:36:43 -07001222 if (!lun) {
1223 pr_err("%s Logical Unit Number: %u is not active on"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001224 " Target Portal Group: %hu, ignoring request.\n",
Andy Grovere3d6f902011-07-19 08:55:10 +00001225 tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun,
1226 tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001227 return -EINVAL;
1228 }
1229
1230 nacl = lacl->se_lun_nacl;
Andy Grover6708bb22011-06-08 10:36:43 -07001231 if (!nacl)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001232 return -EINVAL;
1233
1234 if ((lun->lun_access & TRANSPORT_LUNFLAGS_READ_ONLY) &&
1235 (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE))
1236 lun_access = TRANSPORT_LUNFLAGS_READ_ONLY;
1237
1238 lacl->se_lun = lun;
1239
Andy Grovere80ac6c2012-07-12 17:34:58 -07001240 if (core_enable_device_list_for_node(lun, lacl, lacl->mapped_lun,
1241 lun_access, nacl, tpg) < 0)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001242 return -EINVAL;
1243
1244 spin_lock(&lun->lun_acl_lock);
1245 list_add_tail(&lacl->lacl_list, &lun->lun_acl_list);
1246 atomic_inc(&lun->lun_acl_count);
1247 smp_mb__after_atomic_inc();
1248 spin_unlock(&lun->lun_acl_lock);
1249
Andy Grover6708bb22011-06-08 10:36:43 -07001250 pr_debug("%s_TPG[%hu]_LUN[%u->%u] - Added %s ACL for "
Andy Grovere3d6f902011-07-19 08:55:10 +00001251 " InitiatorNode: %s\n", tpg->se_tpg_tfo->get_fabric_name(),
1252 tpg->se_tpg_tfo->tpg_get_tag(tpg), unpacked_lun, lacl->mapped_lun,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001253 (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) ? "RW" : "RO",
1254 lacl->initiatorname);
1255 /*
1256 * Check to see if there are any existing persistent reservation APTPL
1257 * pre-registrations that need to be enabled for this LUN ACL..
1258 */
1259 core_scsi3_check_aptpl_registration(lun->lun_se_dev, tpg, lun, lacl);
1260 return 0;
1261}
1262
1263/* core_dev_del_initiator_node_lun_acl():
1264 *
1265 *
1266 */
1267int core_dev_del_initiator_node_lun_acl(
1268 struct se_portal_group *tpg,
1269 struct se_lun *lun,
1270 struct se_lun_acl *lacl)
1271{
1272 struct se_node_acl *nacl;
1273
1274 nacl = lacl->se_lun_nacl;
Andy Grover6708bb22011-06-08 10:36:43 -07001275 if (!nacl)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001276 return -EINVAL;
1277
1278 spin_lock(&lun->lun_acl_lock);
1279 list_del(&lacl->lacl_list);
1280 atomic_dec(&lun->lun_acl_count);
1281 smp_mb__after_atomic_dec();
1282 spin_unlock(&lun->lun_acl_lock);
1283
Andy Grovere80ac6c2012-07-12 17:34:58 -07001284 core_disable_device_list_for_node(lun, NULL, lacl->mapped_lun,
1285 TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001286
1287 lacl->se_lun = NULL;
1288
Andy Grover6708bb22011-06-08 10:36:43 -07001289 pr_debug("%s_TPG[%hu]_LUN[%u] - Removed ACL for"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001290 " InitiatorNode: %s Mapped LUN: %u\n",
Andy Grovere3d6f902011-07-19 08:55:10 +00001291 tpg->se_tpg_tfo->get_fabric_name(),
1292 tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001293 lacl->initiatorname, lacl->mapped_lun);
1294
1295 return 0;
1296}
1297
1298void core_dev_free_initiator_node_lun_acl(
1299 struct se_portal_group *tpg,
1300 struct se_lun_acl *lacl)
1301{
Andy Grover6708bb22011-06-08 10:36:43 -07001302 pr_debug("%s_TPG[%hu] - Freeing ACL for %s InitiatorNode: %s"
Andy Grovere3d6f902011-07-19 08:55:10 +00001303 " Mapped LUN: %u\n", tpg->se_tpg_tfo->get_fabric_name(),
1304 tpg->se_tpg_tfo->tpg_get_tag(tpg),
1305 tpg->se_tpg_tfo->get_fabric_name(),
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001306 lacl->initiatorname, lacl->mapped_lun);
1307
1308 kfree(lacl);
1309}
1310
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001311static void scsi_dump_inquiry(struct se_device *dev)
1312{
1313 struct t10_wwn *wwn = &dev->t10_wwn;
1314 char buf[17];
1315 int i, device_type;
1316 /*
1317 * Print Linux/SCSI style INQUIRY formatting to the kernel ring buffer
1318 */
1319 for (i = 0; i < 8; i++)
1320 if (wwn->vendor[i] >= 0x20)
1321 buf[i] = wwn->vendor[i];
1322 else
1323 buf[i] = ' ';
1324 buf[i] = '\0';
1325 pr_debug(" Vendor: %s\n", buf);
1326
1327 for (i = 0; i < 16; i++)
1328 if (wwn->model[i] >= 0x20)
1329 buf[i] = wwn->model[i];
1330 else
1331 buf[i] = ' ';
1332 buf[i] = '\0';
1333 pr_debug(" Model: %s\n", buf);
1334
1335 for (i = 0; i < 4; i++)
1336 if (wwn->revision[i] >= 0x20)
1337 buf[i] = wwn->revision[i];
1338 else
1339 buf[i] = ' ';
1340 buf[i] = '\0';
1341 pr_debug(" Revision: %s\n", buf);
1342
1343 device_type = dev->transport->get_device_type(dev);
1344 pr_debug(" Type: %s ", scsi_device_type(device_type));
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001345}
1346
1347struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
1348{
1349 struct se_device *dev;
1350
1351 dev = hba->transport->alloc_device(hba, name);
1352 if (!dev)
1353 return NULL;
1354
1355 dev->se_hba = hba;
1356 dev->transport = hba->transport;
1357
1358 INIT_LIST_HEAD(&dev->dev_list);
1359 INIT_LIST_HEAD(&dev->dev_sep_list);
1360 INIT_LIST_HEAD(&dev->dev_tmr_list);
1361 INIT_LIST_HEAD(&dev->delayed_cmd_list);
1362 INIT_LIST_HEAD(&dev->state_list);
1363 INIT_LIST_HEAD(&dev->qf_cmd_list);
1364 spin_lock_init(&dev->stats_lock);
1365 spin_lock_init(&dev->execute_task_lock);
1366 spin_lock_init(&dev->delayed_cmd_lock);
1367 spin_lock_init(&dev->dev_reservation_lock);
1368 spin_lock_init(&dev->se_port_lock);
1369 spin_lock_init(&dev->se_tmr_lock);
1370 spin_lock_init(&dev->qf_cmd_lock);
1371 atomic_set(&dev->dev_ordered_id, 0);
1372 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
1373 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
1374 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
1375 INIT_LIST_HEAD(&dev->t10_pr.aptpl_reg_list);
1376 spin_lock_init(&dev->t10_pr.registration_lock);
1377 spin_lock_init(&dev->t10_pr.aptpl_reg_lock);
1378 INIT_LIST_HEAD(&dev->t10_alua.tg_pt_gps_list);
1379 spin_lock_init(&dev->t10_alua.tg_pt_gps_lock);
1380
1381 dev->t10_pr.pr_aptpl_buf_len = PR_APTPL_BUF_LEN;
1382 dev->t10_wwn.t10_dev = dev;
1383 dev->t10_alua.t10_dev = dev;
1384
1385 dev->dev_attrib.da_dev = dev;
1386 dev->dev_attrib.emulate_dpo = DA_EMULATE_DPO;
1387 dev->dev_attrib.emulate_fua_write = DA_EMULATE_FUA_WRITE;
1388 dev->dev_attrib.emulate_fua_read = DA_EMULATE_FUA_READ;
1389 dev->dev_attrib.emulate_write_cache = DA_EMULATE_WRITE_CACHE;
1390 dev->dev_attrib.emulate_ua_intlck_ctrl = DA_EMULATE_UA_INTLLCK_CTRL;
1391 dev->dev_attrib.emulate_tas = DA_EMULATE_TAS;
1392 dev->dev_attrib.emulate_tpu = DA_EMULATE_TPU;
1393 dev->dev_attrib.emulate_tpws = DA_EMULATE_TPWS;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001394 dev->dev_attrib.enforce_pr_isids = DA_ENFORCE_PR_ISIDS;
1395 dev->dev_attrib.is_nonrot = DA_IS_NONROT;
1396 dev->dev_attrib.emulate_rest_reord = DA_EMULATE_REST_REORD;
1397 dev->dev_attrib.max_unmap_lba_count = DA_MAX_UNMAP_LBA_COUNT;
1398 dev->dev_attrib.max_unmap_block_desc_count =
1399 DA_MAX_UNMAP_BLOCK_DESC_COUNT;
1400 dev->dev_attrib.unmap_granularity = DA_UNMAP_GRANULARITY_DEFAULT;
1401 dev->dev_attrib.unmap_granularity_alignment =
1402 DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT;
Nicholas Bellinger773cbaf2012-11-15 11:02:49 -08001403 dev->dev_attrib.max_write_same_len = DA_MAX_WRITE_SAME_LEN;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001404 dev->dev_attrib.fabric_max_sectors = DA_FABRIC_MAX_SECTORS;
1405 dev->dev_attrib.optimal_sectors = DA_FABRIC_MAX_SECTORS;
1406
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001407 return dev;
1408}
1409
1410int target_configure_device(struct se_device *dev)
1411{
1412 struct se_hba *hba = dev->se_hba;
1413 int ret;
1414
1415 if (dev->dev_flags & DF_CONFIGURED) {
1416 pr_err("se_dev->se_dev_ptr already set for storage"
1417 " object\n");
1418 return -EEXIST;
1419 }
1420
1421 ret = dev->transport->configure_device(dev);
1422 if (ret)
1423 goto out;
1424 dev->dev_flags |= DF_CONFIGURED;
1425
1426 /*
1427 * XXX: there is not much point to have two different values here..
1428 */
1429 dev->dev_attrib.block_size = dev->dev_attrib.hw_block_size;
1430 dev->dev_attrib.queue_depth = dev->dev_attrib.hw_queue_depth;
1431
1432 /*
1433 * Align max_hw_sectors down to PAGE_SIZE I/O transfers
1434 */
1435 dev->dev_attrib.hw_max_sectors =
1436 se_dev_align_max_sectors(dev->dev_attrib.hw_max_sectors,
1437 dev->dev_attrib.hw_block_size);
1438
1439 dev->dev_index = scsi_get_new_index(SCSI_DEVICE_INDEX);
1440 dev->creation_time = get_jiffies_64();
1441
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001442 ret = core_setup_alua(dev);
1443 if (ret)
1444 goto out;
1445
1446 /*
1447 * Startup the struct se_device processing thread
1448 */
1449 dev->tmr_wq = alloc_workqueue("tmr-%s", WQ_MEM_RECLAIM | WQ_UNBOUND, 1,
1450 dev->transport->name);
1451 if (!dev->tmr_wq) {
1452 pr_err("Unable to create tmr workqueue for %s\n",
1453 dev->transport->name);
1454 ret = -ENOMEM;
1455 goto out_free_alua;
1456 }
1457
1458 /*
1459 * Setup work_queue for QUEUE_FULL
1460 */
1461 INIT_WORK(&dev->qf_work_queue, target_qf_do_work);
1462
1463 /*
1464 * Preload the initial INQUIRY const values if we are doing
1465 * anything virtual (IBLOCK, FILEIO, RAMDISK), but not for TCM/pSCSI
1466 * passthrough because this is being provided by the backend LLD.
1467 */
1468 if (dev->transport->transport_type != TRANSPORT_PLUGIN_PHBA_PDEV) {
1469 strncpy(&dev->t10_wwn.vendor[0], "LIO-ORG", 8);
1470 strncpy(&dev->t10_wwn.model[0],
1471 dev->transport->inquiry_prod, 16);
1472 strncpy(&dev->t10_wwn.revision[0],
1473 dev->transport->inquiry_rev, 4);
1474 }
1475
1476 scsi_dump_inquiry(dev);
1477
1478 spin_lock(&hba->device_lock);
1479 hba->dev_count++;
1480 spin_unlock(&hba->device_lock);
1481 return 0;
1482
1483out_free_alua:
1484 core_alua_free_lu_gp_mem(dev);
1485out:
1486 se_release_vpd_for_dev(dev);
1487 return ret;
1488}
1489
1490void target_free_device(struct se_device *dev)
1491{
1492 struct se_hba *hba = dev->se_hba;
1493
1494 WARN_ON(!list_empty(&dev->dev_sep_list));
1495
1496 if (dev->dev_flags & DF_CONFIGURED) {
1497 destroy_workqueue(dev->tmr_wq);
1498
1499 spin_lock(&hba->device_lock);
1500 hba->dev_count--;
1501 spin_unlock(&hba->device_lock);
1502 }
1503
1504 core_alua_free_lu_gp_mem(dev);
1505 core_scsi3_free_all_registrations(dev);
1506 se_release_vpd_for_dev(dev);
1507
1508 dev->transport->free_device(dev);
1509}
1510
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001511int core_dev_setup_virtual_lun0(void)
1512{
1513 struct se_hba *hba;
1514 struct se_device *dev;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001515 char buf[16];
1516 int ret;
1517
Andy Grover6708bb22011-06-08 10:36:43 -07001518 hba = core_alloc_hba("rd_mcp", 0, HBA_FLAGS_INTERNAL_USE);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001519 if (IS_ERR(hba))
1520 return PTR_ERR(hba);
1521
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001522 dev = target_alloc_device(hba, "virt_lun0");
1523 if (!dev) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001524 ret = -ENOMEM;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001525 goto out_free_hba;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001526 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001527
1528 memset(buf, 0, 16);
1529 sprintf(buf, "rd_pages=8");
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001530 hba->transport->set_configfs_dev_params(dev, buf, sizeof(buf));
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001531
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001532 ret = target_configure_device(dev);
1533 if (ret)
1534 goto out_free_se_dev;
1535
1536 lun0_hba = hba;
Andy Grovere3d6f902011-07-19 08:55:10 +00001537 g_lun0_dev = dev;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001538 return 0;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001539
1540out_free_se_dev:
1541 target_free_device(dev);
1542out_free_hba:
1543 core_delete_hba(hba);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001544 return ret;
1545}
1546
1547
1548void core_dev_release_virtual_lun0(void)
1549{
Andy Grovere3d6f902011-07-19 08:55:10 +00001550 struct se_hba *hba = lun0_hba;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001551
Andy Grover6708bb22011-06-08 10:36:43 -07001552 if (!hba)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001553 return;
1554
Andy Grovere3d6f902011-07-19 08:55:10 +00001555 if (g_lun0_dev)
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001556 target_free_device(g_lun0_dev);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001557 core_delete_hba(hba);
1558}