blob: 7cfbcb00b3c308369e1523e011885c5978f42bd3 [file] [log] [blame]
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001/*******************************************************************************
2 *
3 * This file contains the Linux/SCSI LLD virtual SCSI initiator driver
4 * for emulated SAS initiator ports
5 *
6 * © Copyright 2011 RisingTide Systems LLC.
7 *
8 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
9 *
10 * Author: Nicholas A. Bellinger <nab@risingtidesystems.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 ****************************************************************************/
22
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/types.h>
28#include <linux/configfs.h>
29#include <scsi/scsi.h>
30#include <scsi/scsi_tcq.h>
31#include <scsi/scsi_host.h>
32#include <scsi/scsi_device.h>
33#include <scsi/scsi_cmnd.h>
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -070034
35#include <target/target_core_base.h>
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050036#include <target/target_core_fabric.h>
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -070037#include <target/target_core_fabric_configfs.h>
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -070038#include <target/target_core_configfs.h>
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -070039
40#include "tcm_loop.h"
41
42#define to_tcm_loop_hba(hba) container_of(hba, struct tcm_loop_hba, dev)
43
44/* Local pointer to allocated TCM configfs fabric module */
45static struct target_fabric_configfs *tcm_loop_fabric_configfs;
46
47static struct kmem_cache *tcm_loop_cmd_cache;
48
49static int tcm_loop_hba_no_cnt;
50
51/*
52 * Allocate a tcm_loop cmd descriptor from target_core_mod code
53 *
54 * Can be called from interrupt context in tcm_loop_queuecommand() below
55 */
56static struct se_cmd *tcm_loop_allocate_core_cmd(
57 struct tcm_loop_hba *tl_hba,
58 struct se_portal_group *se_tpg,
59 struct scsi_cmnd *sc)
60{
61 struct se_cmd *se_cmd;
62 struct se_session *se_sess;
63 struct tcm_loop_nexus *tl_nexus = tl_hba->tl_nexus;
64 struct tcm_loop_cmd *tl_cmd;
65 int sam_task_attr;
66
67 if (!tl_nexus) {
68 scmd_printk(KERN_ERR, sc, "TCM_Loop I_T Nexus"
69 " does not exist\n");
70 set_host_byte(sc, DID_ERROR);
71 return NULL;
72 }
73 se_sess = tl_nexus->se_sess;
74
75 tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_ATOMIC);
76 if (!tl_cmd) {
Andy Grover6708bb22011-06-08 10:36:43 -070077 pr_err("Unable to allocate struct tcm_loop_cmd\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -070078 set_host_byte(sc, DID_ERROR);
79 return NULL;
80 }
81 se_cmd = &tl_cmd->tl_se_cmd;
82 /*
83 * Save the pointer to struct scsi_cmnd *sc
84 */
85 tl_cmd->sc = sc;
86 /*
87 * Locate the SAM Task Attr from struct scsi_cmnd *
88 */
89 if (sc->device->tagged_supported) {
90 switch (sc->tag) {
91 case HEAD_OF_QUEUE_TAG:
Nicholas Bellinger61db1802011-05-19 20:19:14 -070092 sam_task_attr = MSG_HEAD_TAG;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -070093 break;
94 case ORDERED_QUEUE_TAG:
Nicholas Bellinger61db1802011-05-19 20:19:14 -070095 sam_task_attr = MSG_ORDERED_TAG;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -070096 break;
97 default:
Nicholas Bellinger61db1802011-05-19 20:19:14 -070098 sam_task_attr = MSG_SIMPLE_TAG;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -070099 break;
100 }
101 } else
Nicholas Bellinger61db1802011-05-19 20:19:14 -0700102 sam_task_attr = MSG_SIMPLE_TAG;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700103
104 /*
105 * Initialize struct se_cmd descriptor from target_core_mod infrastructure
106 */
107 transport_init_se_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess,
108 scsi_bufflen(sc), sc->sc_data_direction, sam_task_attr,
109 &tl_cmd->tl_sense_buf[0]);
110
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700111 if (scsi_bidi_cmnd(sc))
Christoph Hellwig33c3faf2011-11-14 11:36:30 -0500112 se_cmd->se_cmd_flags |= SCF_BIDI;
113
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700114 /*
115 * Locate the struct se_lun pointer and attach it to struct se_cmd
116 */
Andy Grover5951146d2011-07-19 10:26:37 +0000117 if (transport_lookup_cmd_lun(se_cmd, tl_cmd->sc->device->lun) < 0) {
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700118 kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
119 set_host_byte(sc, DID_NO_CONNECT);
120 return NULL;
121 }
122
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700123 return se_cmd;
124}
125
126/*
127 * Called by struct target_core_fabric_ops->new_cmd_map()
128 *
129 * Always called in process context. A non zero return value
130 * here will signal to handle an exception based on the return code.
131 */
132static int tcm_loop_new_cmd_map(struct se_cmd *se_cmd)
133{
134 struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
135 struct tcm_loop_cmd, tl_se_cmd);
136 struct scsi_cmnd *sc = tl_cmd->sc;
Andy Grover5951146d2011-07-19 10:26:37 +0000137 struct scatterlist *sgl_bidi = NULL;
138 u32 sgl_bidi_count = 0;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700139 int ret;
140 /*
141 * Allocate the necessary tasks to complete the received CDB+data
142 */
Andy Grover5951146d2011-07-19 10:26:37 +0000143 ret = transport_generic_allocate_tasks(se_cmd, sc->cmnd);
Nicholas Bellinger03e98c92011-11-04 02:36:16 -0700144 if (ret != 0)
145 return ret;
Andy Grover5951146d2011-07-19 10:26:37 +0000146 /*
147 * For BIDI commands, pass in the extra READ buffer
148 * to transport_generic_map_mem_to_cmd() below..
149 */
Christoph Hellwig33c3faf2011-11-14 11:36:30 -0500150 if (se_cmd->se_cmd_flags & SCF_BIDI) {
Andy Grover5951146d2011-07-19 10:26:37 +0000151 struct scsi_data_buffer *sdb = scsi_in(sc);
152
153 sgl_bidi = sdb->table.sgl;
154 sgl_bidi_count = sdb->table.nents;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700155 }
Nicholas Bellinger8cd79f22011-10-24 13:35:37 -0700156 /*
157 * Because some userspace code via scsi-generic do not memset their
158 * associated read buffers, go ahead and do that here for type
159 * SCF_SCSI_CONTROL_SG_IO_CDB. Also note that this is currently
160 * guaranteed to be a single SGL for SCF_SCSI_CONTROL_SG_IO_CDB
161 * by target core in transport_generic_allocate_tasks() ->
162 * transport_generic_cmd_sequencer().
163 */
164 if (se_cmd->se_cmd_flags & SCF_SCSI_CONTROL_SG_IO_CDB &&
165 se_cmd->data_direction == DMA_FROM_DEVICE) {
166 struct scatterlist *sg = scsi_sglist(sc);
167 unsigned char *buf = kmap(sg_page(sg)) + sg->offset;
168
169 if (buf != NULL) {
170 memset(buf, 0, sg->length);
171 kunmap(sg_page(sg));
172 }
173 }
Andy Grover5951146d2011-07-19 10:26:37 +0000174
Andy Groverec98f782011-07-20 19:28:46 +0000175 /* Tell the core about our preallocated memory */
Nicholas Bellinger03e98c92011-11-04 02:36:16 -0700176 return transport_generic_map_mem_to_cmd(se_cmd, scsi_sglist(sc),
Andy Grover5951146d2011-07-19 10:26:37 +0000177 scsi_sg_count(sc), sgl_bidi, sgl_bidi_count);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700178}
179
180/*
181 * Called from struct target_core_fabric_ops->check_stop_free()
182 */
Nicholas Bellinger88dd9e22011-11-02 03:33:16 -0700183static int tcm_loop_check_stop_free(struct se_cmd *se_cmd)
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700184{
185 /*
186 * Do not release struct se_cmd's containing a valid TMR
187 * pointer. These will be released directly in tcm_loop_device_reset()
188 * with transport_generic_free_cmd().
189 */
Andy Groverc8e31f22012-01-19 13:39:17 -0800190 if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)
Nicholas Bellinger88dd9e22011-11-02 03:33:16 -0700191 return 0;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700192 /*
193 * Release the struct se_cmd, which will make a callback to release
194 * struct tcm_loop_cmd * in tcm_loop_deallocate_core_cmd()
195 */
Christoph Hellwig82f1c8a2011-09-13 23:09:01 +0200196 transport_generic_free_cmd(se_cmd, 0);
Nicholas Bellinger88dd9e22011-11-02 03:33:16 -0700197 return 1;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700198}
199
Christoph Hellwig35462972011-05-31 23:56:57 -0400200static void tcm_loop_release_cmd(struct se_cmd *se_cmd)
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700201{
202 struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
203 struct tcm_loop_cmd, tl_se_cmd);
204
205 kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
206}
207
208static int tcm_loop_proc_info(struct Scsi_Host *host, char *buffer,
209 char **start, off_t offset,
210 int length, int inout)
211{
212 return sprintf(buffer, "tcm_loop_proc_info()\n");
213}
214
215static int tcm_loop_driver_probe(struct device *);
216static int tcm_loop_driver_remove(struct device *);
217
218static int pseudo_lld_bus_match(struct device *dev,
219 struct device_driver *dev_driver)
220{
221 return 1;
222}
223
224static struct bus_type tcm_loop_lld_bus = {
225 .name = "tcm_loop_bus",
226 .match = pseudo_lld_bus_match,
227 .probe = tcm_loop_driver_probe,
228 .remove = tcm_loop_driver_remove,
229};
230
231static struct device_driver tcm_loop_driverfs = {
232 .name = "tcm_loop",
233 .bus = &tcm_loop_lld_bus,
234};
235/*
236 * Used with root_device_register() in tcm_loop_alloc_core_bus() below
237 */
238struct device *tcm_loop_primary;
239
240/*
241 * Copied from drivers/scsi/libfc/fc_fcp.c:fc_change_queue_depth() and
242 * drivers/scsi/libiscsi.c:iscsi_change_queue_depth()
243 */
244static int tcm_loop_change_queue_depth(
245 struct scsi_device *sdev,
246 int depth,
247 int reason)
248{
249 switch (reason) {
250 case SCSI_QDEPTH_DEFAULT:
251 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
252 break;
253 case SCSI_QDEPTH_QFULL:
254 scsi_track_queue_full(sdev, depth);
255 break;
256 case SCSI_QDEPTH_RAMP_UP:
257 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
258 break;
259 default:
260 return -EOPNOTSUPP;
261 }
262 return sdev->queue_depth;
263}
264
265/*
266 * Main entry point from struct scsi_host_template for incoming SCSI CDB+Data
267 * from Linux/SCSI subsystem for SCSI low level device drivers (LLDs)
268 */
269static int tcm_loop_queuecommand(
270 struct Scsi_Host *sh,
271 struct scsi_cmnd *sc)
272{
273 struct se_cmd *se_cmd;
274 struct se_portal_group *se_tpg;
275 struct tcm_loop_hba *tl_hba;
276 struct tcm_loop_tpg *tl_tpg;
277
Andy Grover6708bb22011-06-08 10:36:43 -0700278 pr_debug("tcm_loop_queuecommand() %d:%d:%d:%d got CDB: 0x%02x"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700279 " scsi_buf_len: %u\n", sc->device->host->host_no,
280 sc->device->id, sc->device->channel, sc->device->lun,
281 sc->cmnd[0], scsi_bufflen(sc));
282 /*
283 * Locate the tcm_loop_hba_t pointer
284 */
285 tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);
286 tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];
Nicholas Bellinger0a020432011-10-10 19:44:05 -0700287 /*
288 * Ensure that this tl_tpg reference from the incoming sc->device->id
289 * has already been configured via tcm_loop_make_naa_tpg().
290 */
291 if (!tl_tpg->tl_hba) {
292 set_host_byte(sc, DID_NO_CONNECT);
293 sc->scsi_done(sc);
294 return 0;
295 }
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700296 se_tpg = &tl_tpg->tl_se_tpg;
297 /*
298 * Determine the SAM Task Attribute and allocate tl_cmd and
299 * tl_cmd->tl_se_cmd from TCM infrastructure
300 */
301 se_cmd = tcm_loop_allocate_core_cmd(tl_hba, se_tpg, sc);
302 if (!se_cmd) {
303 sc->scsi_done(sc);
304 return 0;
305 }
306 /*
307 * Queue up the newly allocated to be processed in TCM thread context.
308 */
309 transport_generic_handle_cdb_map(se_cmd);
310 return 0;
311}
312
313/*
314 * Called from SCSI EH process context to issue a LUN_RESET TMR
315 * to struct scsi_device
316 */
317static int tcm_loop_device_reset(struct scsi_cmnd *sc)
318{
319 struct se_cmd *se_cmd = NULL;
320 struct se_portal_group *se_tpg;
321 struct se_session *se_sess;
322 struct tcm_loop_cmd *tl_cmd = NULL;
323 struct tcm_loop_hba *tl_hba;
324 struct tcm_loop_nexus *tl_nexus;
325 struct tcm_loop_tmr *tl_tmr = NULL;
326 struct tcm_loop_tpg *tl_tpg;
Andy Groverc8e31f22012-01-19 13:39:17 -0800327 int ret = FAILED, rc;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700328 /*
329 * Locate the tcm_loop_hba_t pointer
330 */
331 tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);
332 /*
333 * Locate the tl_nexus and se_sess pointers
334 */
335 tl_nexus = tl_hba->tl_nexus;
336 if (!tl_nexus) {
Andy Grover6708bb22011-06-08 10:36:43 -0700337 pr_err("Unable to perform device reset without"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700338 " active I_T Nexus\n");
339 return FAILED;
340 }
341 se_sess = tl_nexus->se_sess;
342 /*
343 * Locate the tl_tpg and se_tpg pointers from TargetID in sc->device->id
344 */
345 tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];
346 se_tpg = &tl_tpg->tl_se_tpg;
347
348 tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_KERNEL);
349 if (!tl_cmd) {
Andy Grover6708bb22011-06-08 10:36:43 -0700350 pr_err("Unable to allocate memory for tl_cmd\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700351 return FAILED;
352 }
353
354 tl_tmr = kzalloc(sizeof(struct tcm_loop_tmr), GFP_KERNEL);
355 if (!tl_tmr) {
Andy Grover6708bb22011-06-08 10:36:43 -0700356 pr_err("Unable to allocate memory for tl_tmr\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700357 goto release;
358 }
359 init_waitqueue_head(&tl_tmr->tl_tmr_wait);
360
361 se_cmd = &tl_cmd->tl_se_cmd;
362 /*
363 * Initialize struct se_cmd descriptor from target_core_mod infrastructure
364 */
365 transport_init_se_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess, 0,
Nicholas Bellinger61db1802011-05-19 20:19:14 -0700366 DMA_NONE, MSG_SIMPLE_TAG,
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700367 &tl_cmd->tl_sense_buf[0]);
Andy Groverc8e31f22012-01-19 13:39:17 -0800368
369 rc = core_tmr_alloc_req(se_cmd, tl_tmr, TMR_LUN_RESET, GFP_KERNEL);
370 if (rc < 0)
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700371 goto release;
372 /*
373 * Locate the underlying TCM struct se_lun from sc->device->lun
374 */
Andy Grover5951146d2011-07-19 10:26:37 +0000375 if (transport_lookup_tmr_lun(se_cmd, sc->device->lun) < 0)
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700376 goto release;
377 /*
378 * Queue the TMR to TCM Core and sleep waiting for tcm_loop_queue_tm_rsp()
379 * to wake us up.
380 */
381 transport_generic_handle_tmr(se_cmd);
382 wait_event(tl_tmr->tl_tmr_wait, atomic_read(&tl_tmr->tmr_complete));
383 /*
384 * The TMR LUN_RESET has completed, check the response status and
385 * then release allocations.
386 */
387 ret = (se_cmd->se_tmr_req->response == TMR_FUNCTION_COMPLETE) ?
388 SUCCESS : FAILED;
389release:
390 if (se_cmd)
Christoph Hellwig82f1c8a2011-09-13 23:09:01 +0200391 transport_generic_free_cmd(se_cmd, 1);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700392 else
393 kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
394 kfree(tl_tmr);
395 return ret;
396}
397
398static int tcm_loop_slave_alloc(struct scsi_device *sd)
399{
400 set_bit(QUEUE_FLAG_BIDI, &sd->request_queue->queue_flags);
401 return 0;
402}
403
404static int tcm_loop_slave_configure(struct scsi_device *sd)
405{
406 return 0;
407}
408
409static struct scsi_host_template tcm_loop_driver_template = {
410 .proc_info = tcm_loop_proc_info,
411 .proc_name = "tcm_loopback",
412 .name = "TCM_Loopback",
413 .queuecommand = tcm_loop_queuecommand,
414 .change_queue_depth = tcm_loop_change_queue_depth,
415 .eh_device_reset_handler = tcm_loop_device_reset,
Christoph Hellwig2e88efd2011-11-29 03:20:41 -0500416 .can_queue = 1024,
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700417 .this_id = -1,
Christoph Hellwig2e88efd2011-11-29 03:20:41 -0500418 .sg_tablesize = 256,
419 .cmd_per_lun = 1024,
420 .max_sectors = 0xFFFF,
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700421 .use_clustering = DISABLE_CLUSTERING,
422 .slave_alloc = tcm_loop_slave_alloc,
423 .slave_configure = tcm_loop_slave_configure,
424 .module = THIS_MODULE,
425};
426
427static int tcm_loop_driver_probe(struct device *dev)
428{
429 struct tcm_loop_hba *tl_hba;
430 struct Scsi_Host *sh;
431 int error;
432
433 tl_hba = to_tcm_loop_hba(dev);
434
435 sh = scsi_host_alloc(&tcm_loop_driver_template,
436 sizeof(struct tcm_loop_hba));
437 if (!sh) {
Andy Grover6708bb22011-06-08 10:36:43 -0700438 pr_err("Unable to allocate struct scsi_host\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700439 return -ENODEV;
440 }
441 tl_hba->sh = sh;
442
443 /*
444 * Assign the struct tcm_loop_hba pointer to struct Scsi_Host->hostdata
445 */
446 *((struct tcm_loop_hba **)sh->hostdata) = tl_hba;
447 /*
448 * Setup single ID, Channel and LUN for now..
449 */
450 sh->max_id = 2;
451 sh->max_lun = 0;
452 sh->max_channel = 0;
453 sh->max_cmd_len = TL_SCSI_MAX_CMD_LEN;
454
455 error = scsi_add_host(sh, &tl_hba->dev);
456 if (error) {
Andy Grover6708bb22011-06-08 10:36:43 -0700457 pr_err("%s: scsi_add_host failed\n", __func__);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700458 scsi_host_put(sh);
459 return -ENODEV;
460 }
461 return 0;
462}
463
464static int tcm_loop_driver_remove(struct device *dev)
465{
466 struct tcm_loop_hba *tl_hba;
467 struct Scsi_Host *sh;
468
469 tl_hba = to_tcm_loop_hba(dev);
470 sh = tl_hba->sh;
471
472 scsi_remove_host(sh);
473 scsi_host_put(sh);
474 return 0;
475}
476
477static void tcm_loop_release_adapter(struct device *dev)
478{
479 struct tcm_loop_hba *tl_hba = to_tcm_loop_hba(dev);
480
481 kfree(tl_hba);
482}
483
484/*
485 * Called from tcm_loop_make_scsi_hba() in tcm_loop_configfs.c
486 */
487static int tcm_loop_setup_hba_bus(struct tcm_loop_hba *tl_hba, int tcm_loop_host_id)
488{
489 int ret;
490
491 tl_hba->dev.bus = &tcm_loop_lld_bus;
492 tl_hba->dev.parent = tcm_loop_primary;
493 tl_hba->dev.release = &tcm_loop_release_adapter;
494 dev_set_name(&tl_hba->dev, "tcm_loop_adapter_%d", tcm_loop_host_id);
495
496 ret = device_register(&tl_hba->dev);
497 if (ret) {
Andy Grover6708bb22011-06-08 10:36:43 -0700498 pr_err("device_register() failed for"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700499 " tl_hba->dev: %d\n", ret);
500 return -ENODEV;
501 }
502
503 return 0;
504}
505
506/*
507 * Called from tcm_loop_fabric_init() in tcl_loop_fabric.c to load the emulated
508 * tcm_loop SCSI bus.
509 */
510static int tcm_loop_alloc_core_bus(void)
511{
512 int ret;
513
514 tcm_loop_primary = root_device_register("tcm_loop_0");
515 if (IS_ERR(tcm_loop_primary)) {
Andy Grover6708bb22011-06-08 10:36:43 -0700516 pr_err("Unable to allocate tcm_loop_primary\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700517 return PTR_ERR(tcm_loop_primary);
518 }
519
520 ret = bus_register(&tcm_loop_lld_bus);
521 if (ret) {
Andy Grover6708bb22011-06-08 10:36:43 -0700522 pr_err("bus_register() failed for tcm_loop_lld_bus\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700523 goto dev_unreg;
524 }
525
526 ret = driver_register(&tcm_loop_driverfs);
527 if (ret) {
Andy Grover6708bb22011-06-08 10:36:43 -0700528 pr_err("driver_register() failed for"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700529 "tcm_loop_driverfs\n");
530 goto bus_unreg;
531 }
532
Andy Grover6708bb22011-06-08 10:36:43 -0700533 pr_debug("Initialized TCM Loop Core Bus\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700534 return ret;
535
536bus_unreg:
537 bus_unregister(&tcm_loop_lld_bus);
538dev_unreg:
539 root_device_unregister(tcm_loop_primary);
540 return ret;
541}
542
543static void tcm_loop_release_core_bus(void)
544{
545 driver_unregister(&tcm_loop_driverfs);
546 bus_unregister(&tcm_loop_lld_bus);
547 root_device_unregister(tcm_loop_primary);
548
Andy Grover6708bb22011-06-08 10:36:43 -0700549 pr_debug("Releasing TCM Loop Core BUS\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700550}
551
552static char *tcm_loop_get_fabric_name(void)
553{
554 return "loopback";
555}
556
557static u8 tcm_loop_get_fabric_proto_ident(struct se_portal_group *se_tpg)
558{
Jörn Engel8359cf42011-11-24 02:05:51 +0100559 struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700560 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
561 /*
562 * tl_proto_id is set at tcm_loop_configfs.c:tcm_loop_make_scsi_hba()
563 * time based on the protocol dependent prefix of the passed configfs group.
564 *
565 * Based upon tl_proto_id, TCM_Loop emulates the requested fabric
566 * ProtocolID using target_core_fabric_lib.c symbols.
567 */
568 switch (tl_hba->tl_proto_id) {
569 case SCSI_PROTOCOL_SAS:
570 return sas_get_fabric_proto_ident(se_tpg);
571 case SCSI_PROTOCOL_FCP:
572 return fc_get_fabric_proto_ident(se_tpg);
573 case SCSI_PROTOCOL_ISCSI:
574 return iscsi_get_fabric_proto_ident(se_tpg);
575 default:
Andy Grover6708bb22011-06-08 10:36:43 -0700576 pr_err("Unknown tl_proto_id: 0x%02x, using"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700577 " SAS emulation\n", tl_hba->tl_proto_id);
578 break;
579 }
580
581 return sas_get_fabric_proto_ident(se_tpg);
582}
583
584static char *tcm_loop_get_endpoint_wwn(struct se_portal_group *se_tpg)
585{
Jörn Engel8359cf42011-11-24 02:05:51 +0100586 struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700587 /*
588 * Return the passed NAA identifier for the SAS Target Port
589 */
590 return &tl_tpg->tl_hba->tl_wwn_address[0];
591}
592
593static u16 tcm_loop_get_tag(struct se_portal_group *se_tpg)
594{
Jörn Engel8359cf42011-11-24 02:05:51 +0100595 struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700596 /*
597 * This Tag is used when forming SCSI Name identifier in EVPD=1 0x83
598 * to represent the SCSI Target Port.
599 */
600 return tl_tpg->tl_tpgt;
601}
602
603static u32 tcm_loop_get_default_depth(struct se_portal_group *se_tpg)
604{
605 return 1;
606}
607
608static u32 tcm_loop_get_pr_transport_id(
609 struct se_portal_group *se_tpg,
610 struct se_node_acl *se_nacl,
611 struct t10_pr_registration *pr_reg,
612 int *format_code,
613 unsigned char *buf)
614{
Jörn Engel8359cf42011-11-24 02:05:51 +0100615 struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700616 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
617
618 switch (tl_hba->tl_proto_id) {
619 case SCSI_PROTOCOL_SAS:
620 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
621 format_code, buf);
622 case SCSI_PROTOCOL_FCP:
623 return fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
624 format_code, buf);
625 case SCSI_PROTOCOL_ISCSI:
626 return iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
627 format_code, buf);
628 default:
Andy Grover6708bb22011-06-08 10:36:43 -0700629 pr_err("Unknown tl_proto_id: 0x%02x, using"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700630 " SAS emulation\n", tl_hba->tl_proto_id);
631 break;
632 }
633
634 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
635 format_code, buf);
636}
637
638static u32 tcm_loop_get_pr_transport_id_len(
639 struct se_portal_group *se_tpg,
640 struct se_node_acl *se_nacl,
641 struct t10_pr_registration *pr_reg,
642 int *format_code)
643{
Jörn Engel8359cf42011-11-24 02:05:51 +0100644 struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700645 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
646
647 switch (tl_hba->tl_proto_id) {
648 case SCSI_PROTOCOL_SAS:
649 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
650 format_code);
651 case SCSI_PROTOCOL_FCP:
652 return fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
653 format_code);
654 case SCSI_PROTOCOL_ISCSI:
655 return iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
656 format_code);
657 default:
Andy Grover6708bb22011-06-08 10:36:43 -0700658 pr_err("Unknown tl_proto_id: 0x%02x, using"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700659 " SAS emulation\n", tl_hba->tl_proto_id);
660 break;
661 }
662
663 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
664 format_code);
665}
666
667/*
668 * Used for handling SCSI fabric dependent TransportIDs in SPC-3 and above
669 * Persistent Reservation SPEC_I_PT=1 and PROUT REGISTER_AND_MOVE operations.
670 */
671static char *tcm_loop_parse_pr_out_transport_id(
672 struct se_portal_group *se_tpg,
673 const char *buf,
674 u32 *out_tid_len,
675 char **port_nexus_ptr)
676{
Jörn Engel8359cf42011-11-24 02:05:51 +0100677 struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700678 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
679
680 switch (tl_hba->tl_proto_id) {
681 case SCSI_PROTOCOL_SAS:
682 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
683 port_nexus_ptr);
684 case SCSI_PROTOCOL_FCP:
685 return fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
686 port_nexus_ptr);
687 case SCSI_PROTOCOL_ISCSI:
688 return iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
689 port_nexus_ptr);
690 default:
Andy Grover6708bb22011-06-08 10:36:43 -0700691 pr_err("Unknown tl_proto_id: 0x%02x, using"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700692 " SAS emulation\n", tl_hba->tl_proto_id);
693 break;
694 }
695
696 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
697 port_nexus_ptr);
698}
699
700/*
701 * Returning (1) here allows for target_core_mod struct se_node_acl to be generated
702 * based upon the incoming fabric dependent SCSI Initiator Port
703 */
704static int tcm_loop_check_demo_mode(struct se_portal_group *se_tpg)
705{
706 return 1;
707}
708
709static int tcm_loop_check_demo_mode_cache(struct se_portal_group *se_tpg)
710{
711 return 0;
712}
713
714/*
715 * Allow I_T Nexus full READ-WRITE access without explict Initiator Node ACLs for
716 * local virtual Linux/SCSI LLD passthrough into VM hypervisor guest
717 */
718static int tcm_loop_check_demo_mode_write_protect(struct se_portal_group *se_tpg)
719{
720 return 0;
721}
722
723/*
724 * Because TCM_Loop does not use explict ACLs and MappedLUNs, this will
725 * never be called for TCM_Loop by target_core_fabric_configfs.c code.
726 * It has been added here as a nop for target_fabric_tf_ops_check()
727 */
728static int tcm_loop_check_prod_mode_write_protect(struct se_portal_group *se_tpg)
729{
730 return 0;
731}
732
733static struct se_node_acl *tcm_loop_tpg_alloc_fabric_acl(
734 struct se_portal_group *se_tpg)
735{
736 struct tcm_loop_nacl *tl_nacl;
737
738 tl_nacl = kzalloc(sizeof(struct tcm_loop_nacl), GFP_KERNEL);
739 if (!tl_nacl) {
Andy Grover6708bb22011-06-08 10:36:43 -0700740 pr_err("Unable to allocate struct tcm_loop_nacl\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700741 return NULL;
742 }
743
744 return &tl_nacl->se_node_acl;
745}
746
747static void tcm_loop_tpg_release_fabric_acl(
748 struct se_portal_group *se_tpg,
749 struct se_node_acl *se_nacl)
750{
751 struct tcm_loop_nacl *tl_nacl = container_of(se_nacl,
752 struct tcm_loop_nacl, se_node_acl);
753
754 kfree(tl_nacl);
755}
756
757static u32 tcm_loop_get_inst_index(struct se_portal_group *se_tpg)
758{
759 return 1;
760}
761
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700762static int tcm_loop_is_state_remove(struct se_cmd *se_cmd)
763{
764 /*
765 * Assume struct scsi_cmnd is not in remove state..
766 */
767 return 0;
768}
769
770static int tcm_loop_sess_logged_in(struct se_session *se_sess)
771{
772 /*
773 * Assume that TL Nexus is always active
774 */
775 return 1;
776}
777
778static u32 tcm_loop_sess_get_index(struct se_session *se_sess)
779{
780 return 1;
781}
782
783static void tcm_loop_set_default_node_attributes(struct se_node_acl *se_acl)
784{
785 return;
786}
787
788static u32 tcm_loop_get_task_tag(struct se_cmd *se_cmd)
789{
790 return 1;
791}
792
793static int tcm_loop_get_cmd_state(struct se_cmd *se_cmd)
794{
795 struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
796 struct tcm_loop_cmd, tl_se_cmd);
797
798 return tl_cmd->sc_cmd_state;
799}
800
801static int tcm_loop_shutdown_session(struct se_session *se_sess)
802{
803 return 0;
804}
805
806static void tcm_loop_close_session(struct se_session *se_sess)
807{
808 return;
809};
810
811static void tcm_loop_stop_session(
812 struct se_session *se_sess,
813 int sess_sleep,
814 int conn_sleep)
815{
816 return;
817}
818
819static void tcm_loop_fall_back_to_erl0(struct se_session *se_sess)
820{
821 return;
822}
823
824static int tcm_loop_write_pending(struct se_cmd *se_cmd)
825{
826 /*
827 * Since Linux/SCSI has already sent down a struct scsi_cmnd
828 * sc->sc_data_direction of DMA_TO_DEVICE with struct scatterlist array
829 * memory, and memory has already been mapped to struct se_cmd->t_mem_list
830 * format with transport_generic_map_mem_to_cmd().
831 *
832 * We now tell TCM to add this WRITE CDB directly into the TCM storage
833 * object execution queue.
834 */
835 transport_generic_process_write(se_cmd);
836 return 0;
837}
838
839static int tcm_loop_write_pending_status(struct se_cmd *se_cmd)
840{
841 return 0;
842}
843
844static int tcm_loop_queue_data_in(struct se_cmd *se_cmd)
845{
846 struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
847 struct tcm_loop_cmd, tl_se_cmd);
848 struct scsi_cmnd *sc = tl_cmd->sc;
849
Andy Grover6708bb22011-06-08 10:36:43 -0700850 pr_debug("tcm_loop_queue_data_in() called for scsi_cmnd: %p"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700851 " cdb: 0x%02x\n", sc, sc->cmnd[0]);
852
853 sc->result = SAM_STAT_GOOD;
854 set_host_byte(sc, DID_OK);
855 sc->scsi_done(sc);
856 return 0;
857}
858
859static int tcm_loop_queue_status(struct se_cmd *se_cmd)
860{
861 struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
862 struct tcm_loop_cmd, tl_se_cmd);
863 struct scsi_cmnd *sc = tl_cmd->sc;
864
Andy Grover6708bb22011-06-08 10:36:43 -0700865 pr_debug("tcm_loop_queue_status() called for scsi_cmnd: %p"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700866 " cdb: 0x%02x\n", sc, sc->cmnd[0]);
867
868 if (se_cmd->sense_buffer &&
869 ((se_cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) ||
870 (se_cmd->se_cmd_flags & SCF_EMULATED_TASK_SENSE))) {
871
Andy Grover5951146d2011-07-19 10:26:37 +0000872 memcpy(sc->sense_buffer, se_cmd->sense_buffer,
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700873 SCSI_SENSE_BUFFERSIZE);
874 sc->result = SAM_STAT_CHECK_CONDITION;
875 set_driver_byte(sc, DRIVER_SENSE);
876 } else
877 sc->result = se_cmd->scsi_status;
878
879 set_host_byte(sc, DID_OK);
880 sc->scsi_done(sc);
881 return 0;
882}
883
884static int tcm_loop_queue_tm_rsp(struct se_cmd *se_cmd)
885{
886 struct se_tmr_req *se_tmr = se_cmd->se_tmr_req;
887 struct tcm_loop_tmr *tl_tmr = se_tmr->fabric_tmr_ptr;
888 /*
889 * The SCSI EH thread will be sleeping on se_tmr->tl_tmr_wait, go ahead
890 * and wake up the wait_queue_head_t in tcm_loop_device_reset()
891 */
892 atomic_set(&tl_tmr->tmr_complete, 1);
893 wake_up(&tl_tmr->tl_tmr_wait);
894 return 0;
895}
896
897static u16 tcm_loop_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length)
898{
899 return 0;
900}
901
902static u16 tcm_loop_get_fabric_sense_len(void)
903{
904 return 0;
905}
906
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700907static char *tcm_loop_dump_proto_id(struct tcm_loop_hba *tl_hba)
908{
909 switch (tl_hba->tl_proto_id) {
910 case SCSI_PROTOCOL_SAS:
911 return "SAS";
912 case SCSI_PROTOCOL_FCP:
913 return "FCP";
914 case SCSI_PROTOCOL_ISCSI:
915 return "iSCSI";
916 default:
917 break;
918 }
919
920 return "Unknown";
921}
922
923/* Start items for tcm_loop_port_cit */
924
925static int tcm_loop_port_link(
926 struct se_portal_group *se_tpg,
927 struct se_lun *lun)
928{
929 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
930 struct tcm_loop_tpg, tl_se_tpg);
931 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
932
933 atomic_inc(&tl_tpg->tl_tpg_port_count);
934 smp_mb__after_atomic_inc();
935 /*
936 * Add Linux/SCSI struct scsi_device by HCTL
937 */
938 scsi_add_device(tl_hba->sh, 0, tl_tpg->tl_tpgt, lun->unpacked_lun);
939
Andy Grover6708bb22011-06-08 10:36:43 -0700940 pr_debug("TCM_Loop_ConfigFS: Port Link Successful\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700941 return 0;
942}
943
944static void tcm_loop_port_unlink(
945 struct se_portal_group *se_tpg,
946 struct se_lun *se_lun)
947{
948 struct scsi_device *sd;
949 struct tcm_loop_hba *tl_hba;
950 struct tcm_loop_tpg *tl_tpg;
951
952 tl_tpg = container_of(se_tpg, struct tcm_loop_tpg, tl_se_tpg);
953 tl_hba = tl_tpg->tl_hba;
954
955 sd = scsi_device_lookup(tl_hba->sh, 0, tl_tpg->tl_tpgt,
956 se_lun->unpacked_lun);
957 if (!sd) {
Andy Grover6708bb22011-06-08 10:36:43 -0700958 pr_err("Unable to locate struct scsi_device for %d:%d:"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700959 "%d\n", 0, tl_tpg->tl_tpgt, se_lun->unpacked_lun);
960 return;
961 }
962 /*
963 * Remove Linux/SCSI struct scsi_device by HCTL
964 */
965 scsi_remove_device(sd);
966 scsi_device_put(sd);
967
968 atomic_dec(&tl_tpg->tl_tpg_port_count);
969 smp_mb__after_atomic_dec();
970
Andy Grover6708bb22011-06-08 10:36:43 -0700971 pr_debug("TCM_Loop_ConfigFS: Port Unlink Successful\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700972}
973
974/* End items for tcm_loop_port_cit */
975
976/* Start items for tcm_loop_nexus_cit */
977
978static int tcm_loop_make_nexus(
979 struct tcm_loop_tpg *tl_tpg,
980 const char *name)
981{
982 struct se_portal_group *se_tpg;
983 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
984 struct tcm_loop_nexus *tl_nexus;
Dan Carpenter552523d2011-06-15 09:41:33 -0700985 int ret = -ENOMEM;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700986
987 if (tl_tpg->tl_hba->tl_nexus) {
Andy Grover6708bb22011-06-08 10:36:43 -0700988 pr_debug("tl_tpg->tl_hba->tl_nexus already exists\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700989 return -EEXIST;
990 }
991 se_tpg = &tl_tpg->tl_se_tpg;
992
993 tl_nexus = kzalloc(sizeof(struct tcm_loop_nexus), GFP_KERNEL);
994 if (!tl_nexus) {
Andy Grover6708bb22011-06-08 10:36:43 -0700995 pr_err("Unable to allocate struct tcm_loop_nexus\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700996 return -ENOMEM;
997 }
998 /*
999 * Initialize the struct se_session pointer
1000 */
1001 tl_nexus->se_sess = transport_init_session();
Dan Carpenter552523d2011-06-15 09:41:33 -07001002 if (IS_ERR(tl_nexus->se_sess)) {
1003 ret = PTR_ERR(tl_nexus->se_sess);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001004 goto out;
Dan Carpenter552523d2011-06-15 09:41:33 -07001005 }
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001006 /*
1007 * Since we are running in 'demo mode' this call with generate a
1008 * struct se_node_acl for the tcm_loop struct se_portal_group with the SCSI
1009 * Initiator port name of the passed configfs group 'name'.
1010 */
1011 tl_nexus->se_sess->se_node_acl = core_tpg_check_initiator_node_acl(
1012 se_tpg, (unsigned char *)name);
1013 if (!tl_nexus->se_sess->se_node_acl) {
1014 transport_free_session(tl_nexus->se_sess);
1015 goto out;
1016 }
1017 /*
1018 * Now, register the SAS I_T Nexus as active with the call to
1019 * transport_register_session()
1020 */
1021 __transport_register_session(se_tpg, tl_nexus->se_sess->se_node_acl,
Andy Grover5951146d2011-07-19 10:26:37 +00001022 tl_nexus->se_sess, tl_nexus);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001023 tl_tpg->tl_hba->tl_nexus = tl_nexus;
Andy Grover6708bb22011-06-08 10:36:43 -07001024 pr_debug("TCM_Loop_ConfigFS: Established I_T Nexus to emulated"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001025 " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba),
1026 name);
1027 return 0;
1028
1029out:
1030 kfree(tl_nexus);
Dan Carpenter552523d2011-06-15 09:41:33 -07001031 return ret;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001032}
1033
1034static int tcm_loop_drop_nexus(
1035 struct tcm_loop_tpg *tpg)
1036{
1037 struct se_session *se_sess;
1038 struct tcm_loop_nexus *tl_nexus;
1039 struct tcm_loop_hba *tl_hba = tpg->tl_hba;
1040
1041 tl_nexus = tpg->tl_hba->tl_nexus;
1042 if (!tl_nexus)
1043 return -ENODEV;
1044
1045 se_sess = tl_nexus->se_sess;
1046 if (!se_sess)
1047 return -ENODEV;
1048
1049 if (atomic_read(&tpg->tl_tpg_port_count)) {
Andy Grover6708bb22011-06-08 10:36:43 -07001050 pr_err("Unable to remove TCM_Loop I_T Nexus with"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001051 " active TPG port count: %d\n",
1052 atomic_read(&tpg->tl_tpg_port_count));
1053 return -EPERM;
1054 }
1055
Andy Grover6708bb22011-06-08 10:36:43 -07001056 pr_debug("TCM_Loop_ConfigFS: Removing I_T Nexus to emulated"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001057 " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba),
1058 tl_nexus->se_sess->se_node_acl->initiatorname);
1059 /*
1060 * Release the SCSI I_T Nexus to the emulated SAS Target Port
1061 */
1062 transport_deregister_session(tl_nexus->se_sess);
1063 tpg->tl_hba->tl_nexus = NULL;
1064 kfree(tl_nexus);
1065 return 0;
1066}
1067
1068/* End items for tcm_loop_nexus_cit */
1069
1070static ssize_t tcm_loop_tpg_show_nexus(
1071 struct se_portal_group *se_tpg,
1072 char *page)
1073{
1074 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
1075 struct tcm_loop_tpg, tl_se_tpg);
1076 struct tcm_loop_nexus *tl_nexus;
1077 ssize_t ret;
1078
1079 tl_nexus = tl_tpg->tl_hba->tl_nexus;
1080 if (!tl_nexus)
1081 return -ENODEV;
1082
1083 ret = snprintf(page, PAGE_SIZE, "%s\n",
1084 tl_nexus->se_sess->se_node_acl->initiatorname);
1085
1086 return ret;
1087}
1088
1089static ssize_t tcm_loop_tpg_store_nexus(
1090 struct se_portal_group *se_tpg,
1091 const char *page,
1092 size_t count)
1093{
1094 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
1095 struct tcm_loop_tpg, tl_se_tpg);
1096 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
1097 unsigned char i_port[TL_WWN_ADDR_LEN], *ptr, *port_ptr;
1098 int ret;
1099 /*
1100 * Shutdown the active I_T nexus if 'NULL' is passed..
1101 */
1102 if (!strncmp(page, "NULL", 4)) {
1103 ret = tcm_loop_drop_nexus(tl_tpg);
1104 return (!ret) ? count : ret;
1105 }
1106 /*
1107 * Otherwise make sure the passed virtual Initiator port WWN matches
1108 * the fabric protocol_id set in tcm_loop_make_scsi_hba(), and call
1109 * tcm_loop_make_nexus()
1110 */
Dan Carpenter60d645a2011-06-15 10:03:05 -07001111 if (strlen(page) >= TL_WWN_ADDR_LEN) {
Andy Grover6708bb22011-06-08 10:36:43 -07001112 pr_err("Emulated NAA Sas Address: %s, exceeds"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001113 " max: %d\n", page, TL_WWN_ADDR_LEN);
1114 return -EINVAL;
1115 }
1116 snprintf(&i_port[0], TL_WWN_ADDR_LEN, "%s", page);
1117
1118 ptr = strstr(i_port, "naa.");
1119 if (ptr) {
1120 if (tl_hba->tl_proto_id != SCSI_PROTOCOL_SAS) {
Andy Grover6708bb22011-06-08 10:36:43 -07001121 pr_err("Passed SAS Initiator Port %s does not"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001122 " match target port protoid: %s\n", i_port,
1123 tcm_loop_dump_proto_id(tl_hba));
1124 return -EINVAL;
1125 }
1126 port_ptr = &i_port[0];
1127 goto check_newline;
1128 }
1129 ptr = strstr(i_port, "fc.");
1130 if (ptr) {
1131 if (tl_hba->tl_proto_id != SCSI_PROTOCOL_FCP) {
Andy Grover6708bb22011-06-08 10:36:43 -07001132 pr_err("Passed FCP Initiator Port %s does not"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001133 " match target port protoid: %s\n", i_port,
1134 tcm_loop_dump_proto_id(tl_hba));
1135 return -EINVAL;
1136 }
1137 port_ptr = &i_port[3]; /* Skip over "fc." */
1138 goto check_newline;
1139 }
1140 ptr = strstr(i_port, "iqn.");
1141 if (ptr) {
1142 if (tl_hba->tl_proto_id != SCSI_PROTOCOL_ISCSI) {
Andy Grover6708bb22011-06-08 10:36:43 -07001143 pr_err("Passed iSCSI Initiator Port %s does not"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001144 " match target port protoid: %s\n", i_port,
1145 tcm_loop_dump_proto_id(tl_hba));
1146 return -EINVAL;
1147 }
1148 port_ptr = &i_port[0];
1149 goto check_newline;
1150 }
Andy Grover6708bb22011-06-08 10:36:43 -07001151 pr_err("Unable to locate prefix for emulated Initiator Port:"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001152 " %s\n", i_port);
1153 return -EINVAL;
1154 /*
1155 * Clear any trailing newline for the NAA WWN
1156 */
1157check_newline:
1158 if (i_port[strlen(i_port)-1] == '\n')
1159 i_port[strlen(i_port)-1] = '\0';
1160
1161 ret = tcm_loop_make_nexus(tl_tpg, port_ptr);
1162 if (ret < 0)
1163 return ret;
1164
1165 return count;
1166}
1167
1168TF_TPG_BASE_ATTR(tcm_loop, nexus, S_IRUGO | S_IWUSR);
1169
1170static struct configfs_attribute *tcm_loop_tpg_attrs[] = {
1171 &tcm_loop_tpg_nexus.attr,
1172 NULL,
1173};
1174
1175/* Start items for tcm_loop_naa_cit */
1176
1177struct se_portal_group *tcm_loop_make_naa_tpg(
1178 struct se_wwn *wwn,
1179 struct config_group *group,
1180 const char *name)
1181{
1182 struct tcm_loop_hba *tl_hba = container_of(wwn,
1183 struct tcm_loop_hba, tl_hba_wwn);
1184 struct tcm_loop_tpg *tl_tpg;
1185 char *tpgt_str, *end_ptr;
1186 int ret;
1187 unsigned short int tpgt;
1188
1189 tpgt_str = strstr(name, "tpgt_");
1190 if (!tpgt_str) {
Andy Grover6708bb22011-06-08 10:36:43 -07001191 pr_err("Unable to locate \"tpgt_#\" directory"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001192 " group\n");
1193 return ERR_PTR(-EINVAL);
1194 }
1195 tpgt_str += 5; /* Skip ahead of "tpgt_" */
1196 tpgt = (unsigned short int) simple_strtoul(tpgt_str, &end_ptr, 0);
1197
Dan Carpenter12f09cc2011-04-02 14:32:47 -07001198 if (tpgt >= TL_TPGS_PER_HBA) {
Andy Grover6708bb22011-06-08 10:36:43 -07001199 pr_err("Passed tpgt: %hu exceeds TL_TPGS_PER_HBA:"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001200 " %u\n", tpgt, TL_TPGS_PER_HBA);
1201 return ERR_PTR(-EINVAL);
1202 }
1203 tl_tpg = &tl_hba->tl_hba_tpgs[tpgt];
1204 tl_tpg->tl_hba = tl_hba;
1205 tl_tpg->tl_tpgt = tpgt;
1206 /*
1207 * Register the tl_tpg as a emulated SAS TCM Target Endpoint
1208 */
1209 ret = core_tpg_register(&tcm_loop_fabric_configfs->tf_ops,
Andy Grover5951146d2011-07-19 10:26:37 +00001210 wwn, &tl_tpg->tl_se_tpg, tl_tpg,
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001211 TRANSPORT_TPG_TYPE_NORMAL);
1212 if (ret < 0)
1213 return ERR_PTR(-ENOMEM);
1214
Andy Grover6708bb22011-06-08 10:36:43 -07001215 pr_debug("TCM_Loop_ConfigFS: Allocated Emulated %s"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001216 " Target Port %s,t,0x%04x\n", tcm_loop_dump_proto_id(tl_hba),
1217 config_item_name(&wwn->wwn_group.cg_item), tpgt);
1218
1219 return &tl_tpg->tl_se_tpg;
1220}
1221
1222void tcm_loop_drop_naa_tpg(
1223 struct se_portal_group *se_tpg)
1224{
1225 struct se_wwn *wwn = se_tpg->se_tpg_wwn;
1226 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
1227 struct tcm_loop_tpg, tl_se_tpg);
1228 struct tcm_loop_hba *tl_hba;
1229 unsigned short tpgt;
1230
1231 tl_hba = tl_tpg->tl_hba;
1232 tpgt = tl_tpg->tl_tpgt;
1233 /*
1234 * Release the I_T Nexus for the Virtual SAS link if present
1235 */
1236 tcm_loop_drop_nexus(tl_tpg);
1237 /*
1238 * Deregister the tl_tpg as a emulated SAS TCM Target Endpoint
1239 */
1240 core_tpg_deregister(se_tpg);
1241
Nicholas Bellinger0a020432011-10-10 19:44:05 -07001242 tl_tpg->tl_hba = NULL;
1243 tl_tpg->tl_tpgt = 0;
1244
Andy Grover6708bb22011-06-08 10:36:43 -07001245 pr_debug("TCM_Loop_ConfigFS: Deallocated Emulated %s"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001246 " Target Port %s,t,0x%04x\n", tcm_loop_dump_proto_id(tl_hba),
1247 config_item_name(&wwn->wwn_group.cg_item), tpgt);
1248}
1249
1250/* End items for tcm_loop_naa_cit */
1251
1252/* Start items for tcm_loop_cit */
1253
1254struct se_wwn *tcm_loop_make_scsi_hba(
1255 struct target_fabric_configfs *tf,
1256 struct config_group *group,
1257 const char *name)
1258{
1259 struct tcm_loop_hba *tl_hba;
1260 struct Scsi_Host *sh;
1261 char *ptr;
1262 int ret, off = 0;
1263
1264 tl_hba = kzalloc(sizeof(struct tcm_loop_hba), GFP_KERNEL);
1265 if (!tl_hba) {
Andy Grover6708bb22011-06-08 10:36:43 -07001266 pr_err("Unable to allocate struct tcm_loop_hba\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001267 return ERR_PTR(-ENOMEM);
1268 }
1269 /*
1270 * Determine the emulated Protocol Identifier and Target Port Name
1271 * based on the incoming configfs directory name.
1272 */
1273 ptr = strstr(name, "naa.");
1274 if (ptr) {
1275 tl_hba->tl_proto_id = SCSI_PROTOCOL_SAS;
1276 goto check_len;
1277 }
1278 ptr = strstr(name, "fc.");
1279 if (ptr) {
1280 tl_hba->tl_proto_id = SCSI_PROTOCOL_FCP;
1281 off = 3; /* Skip over "fc." */
1282 goto check_len;
1283 }
1284 ptr = strstr(name, "iqn.");
Jesper Juhla57b5d32011-06-28 00:30:17 +02001285 if (!ptr) {
Andy Grover6708bb22011-06-08 10:36:43 -07001286 pr_err("Unable to locate prefix for emulated Target "
Jesper Juhla57b5d32011-06-28 00:30:17 +02001287 "Port: %s\n", name);
1288 ret = -EINVAL;
1289 goto out;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001290 }
Jesper Juhla57b5d32011-06-28 00:30:17 +02001291 tl_hba->tl_proto_id = SCSI_PROTOCOL_ISCSI;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001292
1293check_len:
Dan Carpenter60d645a2011-06-15 10:03:05 -07001294 if (strlen(name) >= TL_WWN_ADDR_LEN) {
Andy Grover6708bb22011-06-08 10:36:43 -07001295 pr_err("Emulated NAA %s Address: %s, exceeds"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001296 " max: %d\n", name, tcm_loop_dump_proto_id(tl_hba),
1297 TL_WWN_ADDR_LEN);
Jesper Juhla57b5d32011-06-28 00:30:17 +02001298 ret = -EINVAL;
1299 goto out;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001300 }
1301 snprintf(&tl_hba->tl_wwn_address[0], TL_WWN_ADDR_LEN, "%s", &name[off]);
1302
1303 /*
1304 * Call device_register(tl_hba->dev) to register the emulated
1305 * Linux/SCSI LLD of type struct Scsi_Host at tl_hba->sh after
1306 * device_register() callbacks in tcm_loop_driver_probe()
1307 */
1308 ret = tcm_loop_setup_hba_bus(tl_hba, tcm_loop_hba_no_cnt);
1309 if (ret)
1310 goto out;
1311
1312 sh = tl_hba->sh;
1313 tcm_loop_hba_no_cnt++;
Andy Grover6708bb22011-06-08 10:36:43 -07001314 pr_debug("TCM_Loop_ConfigFS: Allocated emulated Target"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001315 " %s Address: %s at Linux/SCSI Host ID: %d\n",
1316 tcm_loop_dump_proto_id(tl_hba), name, sh->host_no);
1317
1318 return &tl_hba->tl_hba_wwn;
1319out:
1320 kfree(tl_hba);
1321 return ERR_PTR(ret);
1322}
1323
1324void tcm_loop_drop_scsi_hba(
1325 struct se_wwn *wwn)
1326{
1327 struct tcm_loop_hba *tl_hba = container_of(wwn,
1328 struct tcm_loop_hba, tl_hba_wwn);
Nicholas Bellinger6297b072011-11-12 09:29:51 -08001329
1330 pr_debug("TCM_Loop_ConfigFS: Deallocating emulated Target"
1331 " SAS Address: %s at Linux/SCSI Host ID: %d\n",
1332 tl_hba->tl_wwn_address, tl_hba->sh->host_no);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001333 /*
1334 * Call device_unregister() on the original tl_hba->dev.
1335 * tcm_loop_fabric_scsi.c:tcm_loop_release_adapter() will
1336 * release *tl_hba;
1337 */
1338 device_unregister(&tl_hba->dev);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001339}
1340
1341/* Start items for tcm_loop_cit */
1342static ssize_t tcm_loop_wwn_show_attr_version(
1343 struct target_fabric_configfs *tf,
1344 char *page)
1345{
1346 return sprintf(page, "TCM Loopback Fabric module %s\n", TCM_LOOP_VERSION);
1347}
1348
1349TF_WWN_ATTR_RO(tcm_loop, version);
1350
1351static struct configfs_attribute *tcm_loop_wwn_attrs[] = {
1352 &tcm_loop_wwn_version.attr,
1353 NULL,
1354};
1355
1356/* End items for tcm_loop_cit */
1357
1358static int tcm_loop_register_configfs(void)
1359{
1360 struct target_fabric_configfs *fabric;
1361 struct config_group *tf_cg;
1362 int ret;
1363 /*
1364 * Set the TCM Loop HBA counter to zero
1365 */
1366 tcm_loop_hba_no_cnt = 0;
1367 /*
1368 * Register the top level struct config_item_type with TCM core
1369 */
1370 fabric = target_fabric_configfs_init(THIS_MODULE, "loopback");
Andy Grovere3d6f902011-07-19 08:55:10 +00001371 if (IS_ERR(fabric)) {
Andy Grover6708bb22011-06-08 10:36:43 -07001372 pr_err("tcm_loop_register_configfs() failed!\n");
Andy Grovere3d6f902011-07-19 08:55:10 +00001373 return PTR_ERR(fabric);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001374 }
1375 /*
1376 * Setup the fabric API of function pointers used by target_core_mod
1377 */
1378 fabric->tf_ops.get_fabric_name = &tcm_loop_get_fabric_name;
1379 fabric->tf_ops.get_fabric_proto_ident = &tcm_loop_get_fabric_proto_ident;
1380 fabric->tf_ops.tpg_get_wwn = &tcm_loop_get_endpoint_wwn;
1381 fabric->tf_ops.tpg_get_tag = &tcm_loop_get_tag;
1382 fabric->tf_ops.tpg_get_default_depth = &tcm_loop_get_default_depth;
1383 fabric->tf_ops.tpg_get_pr_transport_id = &tcm_loop_get_pr_transport_id;
1384 fabric->tf_ops.tpg_get_pr_transport_id_len =
1385 &tcm_loop_get_pr_transport_id_len;
1386 fabric->tf_ops.tpg_parse_pr_out_transport_id =
1387 &tcm_loop_parse_pr_out_transport_id;
1388 fabric->tf_ops.tpg_check_demo_mode = &tcm_loop_check_demo_mode;
1389 fabric->tf_ops.tpg_check_demo_mode_cache =
1390 &tcm_loop_check_demo_mode_cache;
1391 fabric->tf_ops.tpg_check_demo_mode_write_protect =
1392 &tcm_loop_check_demo_mode_write_protect;
1393 fabric->tf_ops.tpg_check_prod_mode_write_protect =
1394 &tcm_loop_check_prod_mode_write_protect;
1395 /*
1396 * The TCM loopback fabric module runs in demo-mode to a local
1397 * virtual SCSI device, so fabric dependent initator ACLs are
1398 * not required.
1399 */
1400 fabric->tf_ops.tpg_alloc_fabric_acl = &tcm_loop_tpg_alloc_fabric_acl;
1401 fabric->tf_ops.tpg_release_fabric_acl =
1402 &tcm_loop_tpg_release_fabric_acl;
1403 fabric->tf_ops.tpg_get_inst_index = &tcm_loop_get_inst_index;
1404 /*
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001405 * Used for setting up remaining TCM resources in process context
1406 */
1407 fabric->tf_ops.new_cmd_map = &tcm_loop_new_cmd_map;
1408 fabric->tf_ops.check_stop_free = &tcm_loop_check_stop_free;
Christoph Hellwig35462972011-05-31 23:56:57 -04001409 fabric->tf_ops.release_cmd = &tcm_loop_release_cmd;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001410 fabric->tf_ops.shutdown_session = &tcm_loop_shutdown_session;
1411 fabric->tf_ops.close_session = &tcm_loop_close_session;
1412 fabric->tf_ops.stop_session = &tcm_loop_stop_session;
1413 fabric->tf_ops.fall_back_to_erl0 = &tcm_loop_fall_back_to_erl0;
1414 fabric->tf_ops.sess_logged_in = &tcm_loop_sess_logged_in;
1415 fabric->tf_ops.sess_get_index = &tcm_loop_sess_get_index;
1416 fabric->tf_ops.sess_get_initiator_sid = NULL;
1417 fabric->tf_ops.write_pending = &tcm_loop_write_pending;
1418 fabric->tf_ops.write_pending_status = &tcm_loop_write_pending_status;
1419 /*
1420 * Not used for TCM loopback
1421 */
1422 fabric->tf_ops.set_default_node_attributes =
1423 &tcm_loop_set_default_node_attributes;
1424 fabric->tf_ops.get_task_tag = &tcm_loop_get_task_tag;
1425 fabric->tf_ops.get_cmd_state = &tcm_loop_get_cmd_state;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001426 fabric->tf_ops.queue_data_in = &tcm_loop_queue_data_in;
1427 fabric->tf_ops.queue_status = &tcm_loop_queue_status;
1428 fabric->tf_ops.queue_tm_rsp = &tcm_loop_queue_tm_rsp;
1429 fabric->tf_ops.set_fabric_sense_len = &tcm_loop_set_fabric_sense_len;
1430 fabric->tf_ops.get_fabric_sense_len = &tcm_loop_get_fabric_sense_len;
1431 fabric->tf_ops.is_state_remove = &tcm_loop_is_state_remove;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001432
1433 tf_cg = &fabric->tf_group;
1434 /*
1435 * Setup function pointers for generic logic in target_core_fabric_configfs.c
1436 */
1437 fabric->tf_ops.fabric_make_wwn = &tcm_loop_make_scsi_hba;
1438 fabric->tf_ops.fabric_drop_wwn = &tcm_loop_drop_scsi_hba;
1439 fabric->tf_ops.fabric_make_tpg = &tcm_loop_make_naa_tpg;
1440 fabric->tf_ops.fabric_drop_tpg = &tcm_loop_drop_naa_tpg;
1441 /*
1442 * fabric_post_link() and fabric_pre_unlink() are used for
1443 * registration and release of TCM Loop Virtual SCSI LUNs.
1444 */
1445 fabric->tf_ops.fabric_post_link = &tcm_loop_port_link;
1446 fabric->tf_ops.fabric_pre_unlink = &tcm_loop_port_unlink;
1447 fabric->tf_ops.fabric_make_np = NULL;
1448 fabric->tf_ops.fabric_drop_np = NULL;
1449 /*
1450 * Setup default attribute lists for various fabric->tf_cit_tmpl
1451 */
1452 TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = tcm_loop_wwn_attrs;
1453 TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = tcm_loop_tpg_attrs;
1454 TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = NULL;
1455 TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = NULL;
1456 TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = NULL;
1457 /*
1458 * Once fabric->tf_ops has been setup, now register the fabric for
1459 * use within TCM
1460 */
1461 ret = target_fabric_configfs_register(fabric);
1462 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -07001463 pr_err("target_fabric_configfs_register() for"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001464 " TCM_Loop failed!\n");
1465 target_fabric_configfs_free(fabric);
1466 return -1;
1467 }
1468 /*
1469 * Setup our local pointer to *fabric.
1470 */
1471 tcm_loop_fabric_configfs = fabric;
Andy Grover6708bb22011-06-08 10:36:43 -07001472 pr_debug("TCM_LOOP[0] - Set fabric ->"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001473 " tcm_loop_fabric_configfs\n");
1474 return 0;
1475}
1476
1477static void tcm_loop_deregister_configfs(void)
1478{
1479 if (!tcm_loop_fabric_configfs)
1480 return;
1481
1482 target_fabric_configfs_deregister(tcm_loop_fabric_configfs);
1483 tcm_loop_fabric_configfs = NULL;
Andy Grover6708bb22011-06-08 10:36:43 -07001484 pr_debug("TCM_LOOP[0] - Cleared"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001485 " tcm_loop_fabric_configfs\n");
1486}
1487
1488static int __init tcm_loop_fabric_init(void)
1489{
1490 int ret;
1491
1492 tcm_loop_cmd_cache = kmem_cache_create("tcm_loop_cmd_cache",
1493 sizeof(struct tcm_loop_cmd),
1494 __alignof__(struct tcm_loop_cmd),
1495 0, NULL);
1496 if (!tcm_loop_cmd_cache) {
Andy Grover6708bb22011-06-08 10:36:43 -07001497 pr_debug("kmem_cache_create() for"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001498 " tcm_loop_cmd_cache failed\n");
1499 return -ENOMEM;
1500 }
1501
1502 ret = tcm_loop_alloc_core_bus();
1503 if (ret)
1504 return ret;
1505
1506 ret = tcm_loop_register_configfs();
1507 if (ret) {
1508 tcm_loop_release_core_bus();
1509 return ret;
1510 }
1511
1512 return 0;
1513}
1514
1515static void __exit tcm_loop_fabric_exit(void)
1516{
1517 tcm_loop_deregister_configfs();
1518 tcm_loop_release_core_bus();
1519 kmem_cache_destroy(tcm_loop_cmd_cache);
1520}
1521
1522MODULE_DESCRIPTION("TCM loopback virtual Linux/SCSI fabric module");
1523MODULE_AUTHOR("Nicholas A. Bellinger <nab@risingtidesystems.com>");
1524MODULE_LICENSE("GPL");
1525module_init(tcm_loop_fabric_init);
1526module_exit(tcm_loop_fabric_exit);