blob: c47ff7f59e5733226702004617327a28b566f7f1 [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 Grover59511462011-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 Grover59511462011-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 Grover59511462011-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 Grover59511462011-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 Grover59511462011-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 Grover59511462011-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 Grover59511462011-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 */
190 if (se_cmd->se_tmr_req)
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;
327 int ret = FAILED;
328 /*
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]);
368 /*
369 * Allocate the LUN_RESET TMR
370 */
Andy Grover59511462011-07-19 10:26:37 +0000371 se_cmd->se_tmr_req = core_tmr_alloc_req(se_cmd, tl_tmr,
Roland Dreierdd503a52011-10-06 09:56:16 -0700372 TMR_LUN_RESET, GFP_KERNEL);
Dan Carpenter552523d2011-06-15 09:41:33 -0700373 if (IS_ERR(se_cmd->se_tmr_req))
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700374 goto release;
375 /*
376 * Locate the underlying TCM struct se_lun from sc->device->lun
377 */
Andy Grover59511462011-07-19 10:26:37 +0000378 if (transport_lookup_tmr_lun(se_cmd, sc->device->lun) < 0)
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700379 goto release;
380 /*
381 * Queue the TMR to TCM Core and sleep waiting for tcm_loop_queue_tm_rsp()
382 * to wake us up.
383 */
384 transport_generic_handle_tmr(se_cmd);
385 wait_event(tl_tmr->tl_tmr_wait, atomic_read(&tl_tmr->tmr_complete));
386 /*
387 * The TMR LUN_RESET has completed, check the response status and
388 * then release allocations.
389 */
390 ret = (se_cmd->se_tmr_req->response == TMR_FUNCTION_COMPLETE) ?
391 SUCCESS : FAILED;
392release:
393 if (se_cmd)
Christoph Hellwig82f1c8a2011-09-13 23:09:01 +0200394 transport_generic_free_cmd(se_cmd, 1);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700395 else
396 kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
397 kfree(tl_tmr);
398 return ret;
399}
400
401static int tcm_loop_slave_alloc(struct scsi_device *sd)
402{
403 set_bit(QUEUE_FLAG_BIDI, &sd->request_queue->queue_flags);
404 return 0;
405}
406
407static int tcm_loop_slave_configure(struct scsi_device *sd)
408{
409 return 0;
410}
411
412static struct scsi_host_template tcm_loop_driver_template = {
413 .proc_info = tcm_loop_proc_info,
414 .proc_name = "tcm_loopback",
415 .name = "TCM_Loopback",
416 .queuecommand = tcm_loop_queuecommand,
417 .change_queue_depth = tcm_loop_change_queue_depth,
418 .eh_device_reset_handler = tcm_loop_device_reset,
Christoph Hellwig2e88efd2011-11-29 03:20:41 -0500419 .can_queue = 1024,
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700420 .this_id = -1,
Christoph Hellwig2e88efd2011-11-29 03:20:41 -0500421 .sg_tablesize = 256,
422 .cmd_per_lun = 1024,
423 .max_sectors = 0xFFFF,
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700424 .use_clustering = DISABLE_CLUSTERING,
425 .slave_alloc = tcm_loop_slave_alloc,
426 .slave_configure = tcm_loop_slave_configure,
427 .module = THIS_MODULE,
428};
429
430static int tcm_loop_driver_probe(struct device *dev)
431{
432 struct tcm_loop_hba *tl_hba;
433 struct Scsi_Host *sh;
434 int error;
435
436 tl_hba = to_tcm_loop_hba(dev);
437
438 sh = scsi_host_alloc(&tcm_loop_driver_template,
439 sizeof(struct tcm_loop_hba));
440 if (!sh) {
Andy Grover6708bb22011-06-08 10:36:43 -0700441 pr_err("Unable to allocate struct scsi_host\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700442 return -ENODEV;
443 }
444 tl_hba->sh = sh;
445
446 /*
447 * Assign the struct tcm_loop_hba pointer to struct Scsi_Host->hostdata
448 */
449 *((struct tcm_loop_hba **)sh->hostdata) = tl_hba;
450 /*
451 * Setup single ID, Channel and LUN for now..
452 */
453 sh->max_id = 2;
454 sh->max_lun = 0;
455 sh->max_channel = 0;
456 sh->max_cmd_len = TL_SCSI_MAX_CMD_LEN;
457
458 error = scsi_add_host(sh, &tl_hba->dev);
459 if (error) {
Andy Grover6708bb22011-06-08 10:36:43 -0700460 pr_err("%s: scsi_add_host failed\n", __func__);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700461 scsi_host_put(sh);
462 return -ENODEV;
463 }
464 return 0;
465}
466
467static int tcm_loop_driver_remove(struct device *dev)
468{
469 struct tcm_loop_hba *tl_hba;
470 struct Scsi_Host *sh;
471
472 tl_hba = to_tcm_loop_hba(dev);
473 sh = tl_hba->sh;
474
475 scsi_remove_host(sh);
476 scsi_host_put(sh);
477 return 0;
478}
479
480static void tcm_loop_release_adapter(struct device *dev)
481{
482 struct tcm_loop_hba *tl_hba = to_tcm_loop_hba(dev);
483
484 kfree(tl_hba);
485}
486
487/*
488 * Called from tcm_loop_make_scsi_hba() in tcm_loop_configfs.c
489 */
490static int tcm_loop_setup_hba_bus(struct tcm_loop_hba *tl_hba, int tcm_loop_host_id)
491{
492 int ret;
493
494 tl_hba->dev.bus = &tcm_loop_lld_bus;
495 tl_hba->dev.parent = tcm_loop_primary;
496 tl_hba->dev.release = &tcm_loop_release_adapter;
497 dev_set_name(&tl_hba->dev, "tcm_loop_adapter_%d", tcm_loop_host_id);
498
499 ret = device_register(&tl_hba->dev);
500 if (ret) {
Andy Grover6708bb22011-06-08 10:36:43 -0700501 pr_err("device_register() failed for"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700502 " tl_hba->dev: %d\n", ret);
503 return -ENODEV;
504 }
505
506 return 0;
507}
508
509/*
510 * Called from tcm_loop_fabric_init() in tcl_loop_fabric.c to load the emulated
511 * tcm_loop SCSI bus.
512 */
513static int tcm_loop_alloc_core_bus(void)
514{
515 int ret;
516
517 tcm_loop_primary = root_device_register("tcm_loop_0");
518 if (IS_ERR(tcm_loop_primary)) {
Andy Grover6708bb22011-06-08 10:36:43 -0700519 pr_err("Unable to allocate tcm_loop_primary\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700520 return PTR_ERR(tcm_loop_primary);
521 }
522
523 ret = bus_register(&tcm_loop_lld_bus);
524 if (ret) {
Andy Grover6708bb22011-06-08 10:36:43 -0700525 pr_err("bus_register() failed for tcm_loop_lld_bus\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700526 goto dev_unreg;
527 }
528
529 ret = driver_register(&tcm_loop_driverfs);
530 if (ret) {
Andy Grover6708bb22011-06-08 10:36:43 -0700531 pr_err("driver_register() failed for"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700532 "tcm_loop_driverfs\n");
533 goto bus_unreg;
534 }
535
Andy Grover6708bb22011-06-08 10:36:43 -0700536 pr_debug("Initialized TCM Loop Core Bus\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700537 return ret;
538
539bus_unreg:
540 bus_unregister(&tcm_loop_lld_bus);
541dev_unreg:
542 root_device_unregister(tcm_loop_primary);
543 return ret;
544}
545
546static void tcm_loop_release_core_bus(void)
547{
548 driver_unregister(&tcm_loop_driverfs);
549 bus_unregister(&tcm_loop_lld_bus);
550 root_device_unregister(tcm_loop_primary);
551
Andy Grover6708bb22011-06-08 10:36:43 -0700552 pr_debug("Releasing TCM Loop Core BUS\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700553}
554
555static char *tcm_loop_get_fabric_name(void)
556{
557 return "loopback";
558}
559
560static u8 tcm_loop_get_fabric_proto_ident(struct se_portal_group *se_tpg)
561{
Jörn Engel8359cf42011-11-24 02:05:51 +0100562 struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700563 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
564 /*
565 * tl_proto_id is set at tcm_loop_configfs.c:tcm_loop_make_scsi_hba()
566 * time based on the protocol dependent prefix of the passed configfs group.
567 *
568 * Based upon tl_proto_id, TCM_Loop emulates the requested fabric
569 * ProtocolID using target_core_fabric_lib.c symbols.
570 */
571 switch (tl_hba->tl_proto_id) {
572 case SCSI_PROTOCOL_SAS:
573 return sas_get_fabric_proto_ident(se_tpg);
574 case SCSI_PROTOCOL_FCP:
575 return fc_get_fabric_proto_ident(se_tpg);
576 case SCSI_PROTOCOL_ISCSI:
577 return iscsi_get_fabric_proto_ident(se_tpg);
578 default:
Andy Grover6708bb22011-06-08 10:36:43 -0700579 pr_err("Unknown tl_proto_id: 0x%02x, using"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700580 " SAS emulation\n", tl_hba->tl_proto_id);
581 break;
582 }
583
584 return sas_get_fabric_proto_ident(se_tpg);
585}
586
587static char *tcm_loop_get_endpoint_wwn(struct se_portal_group *se_tpg)
588{
Jörn Engel8359cf42011-11-24 02:05:51 +0100589 struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700590 /*
591 * Return the passed NAA identifier for the SAS Target Port
592 */
593 return &tl_tpg->tl_hba->tl_wwn_address[0];
594}
595
596static u16 tcm_loop_get_tag(struct se_portal_group *se_tpg)
597{
Jörn Engel8359cf42011-11-24 02:05:51 +0100598 struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700599 /*
600 * This Tag is used when forming SCSI Name identifier in EVPD=1 0x83
601 * to represent the SCSI Target Port.
602 */
603 return tl_tpg->tl_tpgt;
604}
605
606static u32 tcm_loop_get_default_depth(struct se_portal_group *se_tpg)
607{
608 return 1;
609}
610
611static u32 tcm_loop_get_pr_transport_id(
612 struct se_portal_group *se_tpg,
613 struct se_node_acl *se_nacl,
614 struct t10_pr_registration *pr_reg,
615 int *format_code,
616 unsigned char *buf)
617{
Jörn Engel8359cf42011-11-24 02:05:51 +0100618 struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700619 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
620
621 switch (tl_hba->tl_proto_id) {
622 case SCSI_PROTOCOL_SAS:
623 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
624 format_code, buf);
625 case SCSI_PROTOCOL_FCP:
626 return fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
627 format_code, buf);
628 case SCSI_PROTOCOL_ISCSI:
629 return iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
630 format_code, buf);
631 default:
Andy Grover6708bb22011-06-08 10:36:43 -0700632 pr_err("Unknown tl_proto_id: 0x%02x, using"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700633 " SAS emulation\n", tl_hba->tl_proto_id);
634 break;
635 }
636
637 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
638 format_code, buf);
639}
640
641static u32 tcm_loop_get_pr_transport_id_len(
642 struct se_portal_group *se_tpg,
643 struct se_node_acl *se_nacl,
644 struct t10_pr_registration *pr_reg,
645 int *format_code)
646{
Jörn Engel8359cf42011-11-24 02:05:51 +0100647 struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700648 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
649
650 switch (tl_hba->tl_proto_id) {
651 case SCSI_PROTOCOL_SAS:
652 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
653 format_code);
654 case SCSI_PROTOCOL_FCP:
655 return fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
656 format_code);
657 case SCSI_PROTOCOL_ISCSI:
658 return iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
659 format_code);
660 default:
Andy Grover6708bb22011-06-08 10:36:43 -0700661 pr_err("Unknown tl_proto_id: 0x%02x, using"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700662 " SAS emulation\n", tl_hba->tl_proto_id);
663 break;
664 }
665
666 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
667 format_code);
668}
669
670/*
671 * Used for handling SCSI fabric dependent TransportIDs in SPC-3 and above
672 * Persistent Reservation SPEC_I_PT=1 and PROUT REGISTER_AND_MOVE operations.
673 */
674static char *tcm_loop_parse_pr_out_transport_id(
675 struct se_portal_group *se_tpg,
676 const char *buf,
677 u32 *out_tid_len,
678 char **port_nexus_ptr)
679{
Jörn Engel8359cf42011-11-24 02:05:51 +0100680 struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700681 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
682
683 switch (tl_hba->tl_proto_id) {
684 case SCSI_PROTOCOL_SAS:
685 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
686 port_nexus_ptr);
687 case SCSI_PROTOCOL_FCP:
688 return fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
689 port_nexus_ptr);
690 case SCSI_PROTOCOL_ISCSI:
691 return iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
692 port_nexus_ptr);
693 default:
Andy Grover6708bb22011-06-08 10:36:43 -0700694 pr_err("Unknown tl_proto_id: 0x%02x, using"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700695 " SAS emulation\n", tl_hba->tl_proto_id);
696 break;
697 }
698
699 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
700 port_nexus_ptr);
701}
702
703/*
704 * Returning (1) here allows for target_core_mod struct se_node_acl to be generated
705 * based upon the incoming fabric dependent SCSI Initiator Port
706 */
707static int tcm_loop_check_demo_mode(struct se_portal_group *se_tpg)
708{
709 return 1;
710}
711
712static int tcm_loop_check_demo_mode_cache(struct se_portal_group *se_tpg)
713{
714 return 0;
715}
716
717/*
718 * Allow I_T Nexus full READ-WRITE access without explict Initiator Node ACLs for
719 * local virtual Linux/SCSI LLD passthrough into VM hypervisor guest
720 */
721static int tcm_loop_check_demo_mode_write_protect(struct se_portal_group *se_tpg)
722{
723 return 0;
724}
725
726/*
727 * Because TCM_Loop does not use explict ACLs and MappedLUNs, this will
728 * never be called for TCM_Loop by target_core_fabric_configfs.c code.
729 * It has been added here as a nop for target_fabric_tf_ops_check()
730 */
731static int tcm_loop_check_prod_mode_write_protect(struct se_portal_group *se_tpg)
732{
733 return 0;
734}
735
736static struct se_node_acl *tcm_loop_tpg_alloc_fabric_acl(
737 struct se_portal_group *se_tpg)
738{
739 struct tcm_loop_nacl *tl_nacl;
740
741 tl_nacl = kzalloc(sizeof(struct tcm_loop_nacl), GFP_KERNEL);
742 if (!tl_nacl) {
Andy Grover6708bb22011-06-08 10:36:43 -0700743 pr_err("Unable to allocate struct tcm_loop_nacl\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700744 return NULL;
745 }
746
747 return &tl_nacl->se_node_acl;
748}
749
750static void tcm_loop_tpg_release_fabric_acl(
751 struct se_portal_group *se_tpg,
752 struct se_node_acl *se_nacl)
753{
754 struct tcm_loop_nacl *tl_nacl = container_of(se_nacl,
755 struct tcm_loop_nacl, se_node_acl);
756
757 kfree(tl_nacl);
758}
759
760static u32 tcm_loop_get_inst_index(struct se_portal_group *se_tpg)
761{
762 return 1;
763}
764
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700765static int tcm_loop_is_state_remove(struct se_cmd *se_cmd)
766{
767 /*
768 * Assume struct scsi_cmnd is not in remove state..
769 */
770 return 0;
771}
772
773static int tcm_loop_sess_logged_in(struct se_session *se_sess)
774{
775 /*
776 * Assume that TL Nexus is always active
777 */
778 return 1;
779}
780
781static u32 tcm_loop_sess_get_index(struct se_session *se_sess)
782{
783 return 1;
784}
785
786static void tcm_loop_set_default_node_attributes(struct se_node_acl *se_acl)
787{
788 return;
789}
790
791static u32 tcm_loop_get_task_tag(struct se_cmd *se_cmd)
792{
793 return 1;
794}
795
796static int tcm_loop_get_cmd_state(struct se_cmd *se_cmd)
797{
798 struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
799 struct tcm_loop_cmd, tl_se_cmd);
800
801 return tl_cmd->sc_cmd_state;
802}
803
804static int tcm_loop_shutdown_session(struct se_session *se_sess)
805{
806 return 0;
807}
808
809static void tcm_loop_close_session(struct se_session *se_sess)
810{
811 return;
812};
813
814static void tcm_loop_stop_session(
815 struct se_session *se_sess,
816 int sess_sleep,
817 int conn_sleep)
818{
819 return;
820}
821
822static void tcm_loop_fall_back_to_erl0(struct se_session *se_sess)
823{
824 return;
825}
826
827static int tcm_loop_write_pending(struct se_cmd *se_cmd)
828{
829 /*
830 * Since Linux/SCSI has already sent down a struct scsi_cmnd
831 * sc->sc_data_direction of DMA_TO_DEVICE with struct scatterlist array
832 * memory, and memory has already been mapped to struct se_cmd->t_mem_list
833 * format with transport_generic_map_mem_to_cmd().
834 *
835 * We now tell TCM to add this WRITE CDB directly into the TCM storage
836 * object execution queue.
837 */
838 transport_generic_process_write(se_cmd);
839 return 0;
840}
841
842static int tcm_loop_write_pending_status(struct se_cmd *se_cmd)
843{
844 return 0;
845}
846
847static int tcm_loop_queue_data_in(struct se_cmd *se_cmd)
848{
849 struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
850 struct tcm_loop_cmd, tl_se_cmd);
851 struct scsi_cmnd *sc = tl_cmd->sc;
852
Andy Grover6708bb22011-06-08 10:36:43 -0700853 pr_debug("tcm_loop_queue_data_in() called for scsi_cmnd: %p"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700854 " cdb: 0x%02x\n", sc, sc->cmnd[0]);
855
856 sc->result = SAM_STAT_GOOD;
857 set_host_byte(sc, DID_OK);
858 sc->scsi_done(sc);
859 return 0;
860}
861
862static int tcm_loop_queue_status(struct se_cmd *se_cmd)
863{
864 struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
865 struct tcm_loop_cmd, tl_se_cmd);
866 struct scsi_cmnd *sc = tl_cmd->sc;
867
Andy Grover6708bb22011-06-08 10:36:43 -0700868 pr_debug("tcm_loop_queue_status() called for scsi_cmnd: %p"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700869 " cdb: 0x%02x\n", sc, sc->cmnd[0]);
870
871 if (se_cmd->sense_buffer &&
872 ((se_cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) ||
873 (se_cmd->se_cmd_flags & SCF_EMULATED_TASK_SENSE))) {
874
Andy Grover59511462011-07-19 10:26:37 +0000875 memcpy(sc->sense_buffer, se_cmd->sense_buffer,
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700876 SCSI_SENSE_BUFFERSIZE);
877 sc->result = SAM_STAT_CHECK_CONDITION;
878 set_driver_byte(sc, DRIVER_SENSE);
879 } else
880 sc->result = se_cmd->scsi_status;
881
882 set_host_byte(sc, DID_OK);
883 sc->scsi_done(sc);
884 return 0;
885}
886
887static int tcm_loop_queue_tm_rsp(struct se_cmd *se_cmd)
888{
889 struct se_tmr_req *se_tmr = se_cmd->se_tmr_req;
890 struct tcm_loop_tmr *tl_tmr = se_tmr->fabric_tmr_ptr;
891 /*
892 * The SCSI EH thread will be sleeping on se_tmr->tl_tmr_wait, go ahead
893 * and wake up the wait_queue_head_t in tcm_loop_device_reset()
894 */
895 atomic_set(&tl_tmr->tmr_complete, 1);
896 wake_up(&tl_tmr->tl_tmr_wait);
897 return 0;
898}
899
900static u16 tcm_loop_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length)
901{
902 return 0;
903}
904
905static u16 tcm_loop_get_fabric_sense_len(void)
906{
907 return 0;
908}
909
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700910static char *tcm_loop_dump_proto_id(struct tcm_loop_hba *tl_hba)
911{
912 switch (tl_hba->tl_proto_id) {
913 case SCSI_PROTOCOL_SAS:
914 return "SAS";
915 case SCSI_PROTOCOL_FCP:
916 return "FCP";
917 case SCSI_PROTOCOL_ISCSI:
918 return "iSCSI";
919 default:
920 break;
921 }
922
923 return "Unknown";
924}
925
926/* Start items for tcm_loop_port_cit */
927
928static int tcm_loop_port_link(
929 struct se_portal_group *se_tpg,
930 struct se_lun *lun)
931{
932 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
933 struct tcm_loop_tpg, tl_se_tpg);
934 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
935
936 atomic_inc(&tl_tpg->tl_tpg_port_count);
937 smp_mb__after_atomic_inc();
938 /*
939 * Add Linux/SCSI struct scsi_device by HCTL
940 */
941 scsi_add_device(tl_hba->sh, 0, tl_tpg->tl_tpgt, lun->unpacked_lun);
942
Andy Grover6708bb22011-06-08 10:36:43 -0700943 pr_debug("TCM_Loop_ConfigFS: Port Link Successful\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700944 return 0;
945}
946
947static void tcm_loop_port_unlink(
948 struct se_portal_group *se_tpg,
949 struct se_lun *se_lun)
950{
951 struct scsi_device *sd;
952 struct tcm_loop_hba *tl_hba;
953 struct tcm_loop_tpg *tl_tpg;
954
955 tl_tpg = container_of(se_tpg, struct tcm_loop_tpg, tl_se_tpg);
956 tl_hba = tl_tpg->tl_hba;
957
958 sd = scsi_device_lookup(tl_hba->sh, 0, tl_tpg->tl_tpgt,
959 se_lun->unpacked_lun);
960 if (!sd) {
Andy Grover6708bb22011-06-08 10:36:43 -0700961 pr_err("Unable to locate struct scsi_device for %d:%d:"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700962 "%d\n", 0, tl_tpg->tl_tpgt, se_lun->unpacked_lun);
963 return;
964 }
965 /*
966 * Remove Linux/SCSI struct scsi_device by HCTL
967 */
968 scsi_remove_device(sd);
969 scsi_device_put(sd);
970
971 atomic_dec(&tl_tpg->tl_tpg_port_count);
972 smp_mb__after_atomic_dec();
973
Andy Grover6708bb22011-06-08 10:36:43 -0700974 pr_debug("TCM_Loop_ConfigFS: Port Unlink Successful\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700975}
976
977/* End items for tcm_loop_port_cit */
978
979/* Start items for tcm_loop_nexus_cit */
980
981static int tcm_loop_make_nexus(
982 struct tcm_loop_tpg *tl_tpg,
983 const char *name)
984{
985 struct se_portal_group *se_tpg;
986 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
987 struct tcm_loop_nexus *tl_nexus;
Dan Carpenter552523d2011-06-15 09:41:33 -0700988 int ret = -ENOMEM;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700989
990 if (tl_tpg->tl_hba->tl_nexus) {
Andy Grover6708bb22011-06-08 10:36:43 -0700991 pr_debug("tl_tpg->tl_hba->tl_nexus already exists\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700992 return -EEXIST;
993 }
994 se_tpg = &tl_tpg->tl_se_tpg;
995
996 tl_nexus = kzalloc(sizeof(struct tcm_loop_nexus), GFP_KERNEL);
997 if (!tl_nexus) {
Andy Grover6708bb22011-06-08 10:36:43 -0700998 pr_err("Unable to allocate struct tcm_loop_nexus\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700999 return -ENOMEM;
1000 }
1001 /*
1002 * Initialize the struct se_session pointer
1003 */
1004 tl_nexus->se_sess = transport_init_session();
Dan Carpenter552523d2011-06-15 09:41:33 -07001005 if (IS_ERR(tl_nexus->se_sess)) {
1006 ret = PTR_ERR(tl_nexus->se_sess);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001007 goto out;
Dan Carpenter552523d2011-06-15 09:41:33 -07001008 }
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001009 /*
1010 * Since we are running in 'demo mode' this call with generate a
1011 * struct se_node_acl for the tcm_loop struct se_portal_group with the SCSI
1012 * Initiator port name of the passed configfs group 'name'.
1013 */
1014 tl_nexus->se_sess->se_node_acl = core_tpg_check_initiator_node_acl(
1015 se_tpg, (unsigned char *)name);
1016 if (!tl_nexus->se_sess->se_node_acl) {
1017 transport_free_session(tl_nexus->se_sess);
1018 goto out;
1019 }
1020 /*
1021 * Now, register the SAS I_T Nexus as active with the call to
1022 * transport_register_session()
1023 */
1024 __transport_register_session(se_tpg, tl_nexus->se_sess->se_node_acl,
Andy Grover59511462011-07-19 10:26:37 +00001025 tl_nexus->se_sess, tl_nexus);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001026 tl_tpg->tl_hba->tl_nexus = tl_nexus;
Andy Grover6708bb22011-06-08 10:36:43 -07001027 pr_debug("TCM_Loop_ConfigFS: Established I_T Nexus to emulated"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001028 " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba),
1029 name);
1030 return 0;
1031
1032out:
1033 kfree(tl_nexus);
Dan Carpenter552523d2011-06-15 09:41:33 -07001034 return ret;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001035}
1036
1037static int tcm_loop_drop_nexus(
1038 struct tcm_loop_tpg *tpg)
1039{
1040 struct se_session *se_sess;
1041 struct tcm_loop_nexus *tl_nexus;
1042 struct tcm_loop_hba *tl_hba = tpg->tl_hba;
1043
1044 tl_nexus = tpg->tl_hba->tl_nexus;
1045 if (!tl_nexus)
1046 return -ENODEV;
1047
1048 se_sess = tl_nexus->se_sess;
1049 if (!se_sess)
1050 return -ENODEV;
1051
1052 if (atomic_read(&tpg->tl_tpg_port_count)) {
Andy Grover6708bb22011-06-08 10:36:43 -07001053 pr_err("Unable to remove TCM_Loop I_T Nexus with"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001054 " active TPG port count: %d\n",
1055 atomic_read(&tpg->tl_tpg_port_count));
1056 return -EPERM;
1057 }
1058
Andy Grover6708bb22011-06-08 10:36:43 -07001059 pr_debug("TCM_Loop_ConfigFS: Removing I_T Nexus to emulated"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001060 " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba),
1061 tl_nexus->se_sess->se_node_acl->initiatorname);
1062 /*
1063 * Release the SCSI I_T Nexus to the emulated SAS Target Port
1064 */
1065 transport_deregister_session(tl_nexus->se_sess);
1066 tpg->tl_hba->tl_nexus = NULL;
1067 kfree(tl_nexus);
1068 return 0;
1069}
1070
1071/* End items for tcm_loop_nexus_cit */
1072
1073static ssize_t tcm_loop_tpg_show_nexus(
1074 struct se_portal_group *se_tpg,
1075 char *page)
1076{
1077 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
1078 struct tcm_loop_tpg, tl_se_tpg);
1079 struct tcm_loop_nexus *tl_nexus;
1080 ssize_t ret;
1081
1082 tl_nexus = tl_tpg->tl_hba->tl_nexus;
1083 if (!tl_nexus)
1084 return -ENODEV;
1085
1086 ret = snprintf(page, PAGE_SIZE, "%s\n",
1087 tl_nexus->se_sess->se_node_acl->initiatorname);
1088
1089 return ret;
1090}
1091
1092static ssize_t tcm_loop_tpg_store_nexus(
1093 struct se_portal_group *se_tpg,
1094 const char *page,
1095 size_t count)
1096{
1097 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
1098 struct tcm_loop_tpg, tl_se_tpg);
1099 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
1100 unsigned char i_port[TL_WWN_ADDR_LEN], *ptr, *port_ptr;
1101 int ret;
1102 /*
1103 * Shutdown the active I_T nexus if 'NULL' is passed..
1104 */
1105 if (!strncmp(page, "NULL", 4)) {
1106 ret = tcm_loop_drop_nexus(tl_tpg);
1107 return (!ret) ? count : ret;
1108 }
1109 /*
1110 * Otherwise make sure the passed virtual Initiator port WWN matches
1111 * the fabric protocol_id set in tcm_loop_make_scsi_hba(), and call
1112 * tcm_loop_make_nexus()
1113 */
Dan Carpenter60d645a2011-06-15 10:03:05 -07001114 if (strlen(page) >= TL_WWN_ADDR_LEN) {
Andy Grover6708bb22011-06-08 10:36:43 -07001115 pr_err("Emulated NAA Sas Address: %s, exceeds"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001116 " max: %d\n", page, TL_WWN_ADDR_LEN);
1117 return -EINVAL;
1118 }
1119 snprintf(&i_port[0], TL_WWN_ADDR_LEN, "%s", page);
1120
1121 ptr = strstr(i_port, "naa.");
1122 if (ptr) {
1123 if (tl_hba->tl_proto_id != SCSI_PROTOCOL_SAS) {
Andy Grover6708bb22011-06-08 10:36:43 -07001124 pr_err("Passed SAS Initiator Port %s does not"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001125 " match target port protoid: %s\n", i_port,
1126 tcm_loop_dump_proto_id(tl_hba));
1127 return -EINVAL;
1128 }
1129 port_ptr = &i_port[0];
1130 goto check_newline;
1131 }
1132 ptr = strstr(i_port, "fc.");
1133 if (ptr) {
1134 if (tl_hba->tl_proto_id != SCSI_PROTOCOL_FCP) {
Andy Grover6708bb22011-06-08 10:36:43 -07001135 pr_err("Passed FCP Initiator Port %s does not"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001136 " match target port protoid: %s\n", i_port,
1137 tcm_loop_dump_proto_id(tl_hba));
1138 return -EINVAL;
1139 }
1140 port_ptr = &i_port[3]; /* Skip over "fc." */
1141 goto check_newline;
1142 }
1143 ptr = strstr(i_port, "iqn.");
1144 if (ptr) {
1145 if (tl_hba->tl_proto_id != SCSI_PROTOCOL_ISCSI) {
Andy Grover6708bb22011-06-08 10:36:43 -07001146 pr_err("Passed iSCSI Initiator Port %s does not"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001147 " match target port protoid: %s\n", i_port,
1148 tcm_loop_dump_proto_id(tl_hba));
1149 return -EINVAL;
1150 }
1151 port_ptr = &i_port[0];
1152 goto check_newline;
1153 }
Andy Grover6708bb22011-06-08 10:36:43 -07001154 pr_err("Unable to locate prefix for emulated Initiator Port:"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001155 " %s\n", i_port);
1156 return -EINVAL;
1157 /*
1158 * Clear any trailing newline for the NAA WWN
1159 */
1160check_newline:
1161 if (i_port[strlen(i_port)-1] == '\n')
1162 i_port[strlen(i_port)-1] = '\0';
1163
1164 ret = tcm_loop_make_nexus(tl_tpg, port_ptr);
1165 if (ret < 0)
1166 return ret;
1167
1168 return count;
1169}
1170
1171TF_TPG_BASE_ATTR(tcm_loop, nexus, S_IRUGO | S_IWUSR);
1172
1173static struct configfs_attribute *tcm_loop_tpg_attrs[] = {
1174 &tcm_loop_tpg_nexus.attr,
1175 NULL,
1176};
1177
1178/* Start items for tcm_loop_naa_cit */
1179
1180struct se_portal_group *tcm_loop_make_naa_tpg(
1181 struct se_wwn *wwn,
1182 struct config_group *group,
1183 const char *name)
1184{
1185 struct tcm_loop_hba *tl_hba = container_of(wwn,
1186 struct tcm_loop_hba, tl_hba_wwn);
1187 struct tcm_loop_tpg *tl_tpg;
1188 char *tpgt_str, *end_ptr;
1189 int ret;
1190 unsigned short int tpgt;
1191
1192 tpgt_str = strstr(name, "tpgt_");
1193 if (!tpgt_str) {
Andy Grover6708bb22011-06-08 10:36:43 -07001194 pr_err("Unable to locate \"tpgt_#\" directory"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001195 " group\n");
1196 return ERR_PTR(-EINVAL);
1197 }
1198 tpgt_str += 5; /* Skip ahead of "tpgt_" */
1199 tpgt = (unsigned short int) simple_strtoul(tpgt_str, &end_ptr, 0);
1200
Dan Carpenter12f09cc2011-04-02 14:32:47 -07001201 if (tpgt >= TL_TPGS_PER_HBA) {
Andy Grover6708bb22011-06-08 10:36:43 -07001202 pr_err("Passed tpgt: %hu exceeds TL_TPGS_PER_HBA:"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001203 " %u\n", tpgt, TL_TPGS_PER_HBA);
1204 return ERR_PTR(-EINVAL);
1205 }
1206 tl_tpg = &tl_hba->tl_hba_tpgs[tpgt];
1207 tl_tpg->tl_hba = tl_hba;
1208 tl_tpg->tl_tpgt = tpgt;
1209 /*
1210 * Register the tl_tpg as a emulated SAS TCM Target Endpoint
1211 */
1212 ret = core_tpg_register(&tcm_loop_fabric_configfs->tf_ops,
Andy Grover59511462011-07-19 10:26:37 +00001213 wwn, &tl_tpg->tl_se_tpg, tl_tpg,
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001214 TRANSPORT_TPG_TYPE_NORMAL);
1215 if (ret < 0)
1216 return ERR_PTR(-ENOMEM);
1217
Andy Grover6708bb22011-06-08 10:36:43 -07001218 pr_debug("TCM_Loop_ConfigFS: Allocated Emulated %s"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001219 " Target Port %s,t,0x%04x\n", tcm_loop_dump_proto_id(tl_hba),
1220 config_item_name(&wwn->wwn_group.cg_item), tpgt);
1221
1222 return &tl_tpg->tl_se_tpg;
1223}
1224
1225void tcm_loop_drop_naa_tpg(
1226 struct se_portal_group *se_tpg)
1227{
1228 struct se_wwn *wwn = se_tpg->se_tpg_wwn;
1229 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
1230 struct tcm_loop_tpg, tl_se_tpg);
1231 struct tcm_loop_hba *tl_hba;
1232 unsigned short tpgt;
1233
1234 tl_hba = tl_tpg->tl_hba;
1235 tpgt = tl_tpg->tl_tpgt;
1236 /*
1237 * Release the I_T Nexus for the Virtual SAS link if present
1238 */
1239 tcm_loop_drop_nexus(tl_tpg);
1240 /*
1241 * Deregister the tl_tpg as a emulated SAS TCM Target Endpoint
1242 */
1243 core_tpg_deregister(se_tpg);
1244
Nicholas Bellinger0a020432011-10-10 19:44:05 -07001245 tl_tpg->tl_hba = NULL;
1246 tl_tpg->tl_tpgt = 0;
1247
Andy Grover6708bb22011-06-08 10:36:43 -07001248 pr_debug("TCM_Loop_ConfigFS: Deallocated Emulated %s"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001249 " Target Port %s,t,0x%04x\n", tcm_loop_dump_proto_id(tl_hba),
1250 config_item_name(&wwn->wwn_group.cg_item), tpgt);
1251}
1252
1253/* End items for tcm_loop_naa_cit */
1254
1255/* Start items for tcm_loop_cit */
1256
1257struct se_wwn *tcm_loop_make_scsi_hba(
1258 struct target_fabric_configfs *tf,
1259 struct config_group *group,
1260 const char *name)
1261{
1262 struct tcm_loop_hba *tl_hba;
1263 struct Scsi_Host *sh;
1264 char *ptr;
1265 int ret, off = 0;
1266
1267 tl_hba = kzalloc(sizeof(struct tcm_loop_hba), GFP_KERNEL);
1268 if (!tl_hba) {
Andy Grover6708bb22011-06-08 10:36:43 -07001269 pr_err("Unable to allocate struct tcm_loop_hba\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001270 return ERR_PTR(-ENOMEM);
1271 }
1272 /*
1273 * Determine the emulated Protocol Identifier and Target Port Name
1274 * based on the incoming configfs directory name.
1275 */
1276 ptr = strstr(name, "naa.");
1277 if (ptr) {
1278 tl_hba->tl_proto_id = SCSI_PROTOCOL_SAS;
1279 goto check_len;
1280 }
1281 ptr = strstr(name, "fc.");
1282 if (ptr) {
1283 tl_hba->tl_proto_id = SCSI_PROTOCOL_FCP;
1284 off = 3; /* Skip over "fc." */
1285 goto check_len;
1286 }
1287 ptr = strstr(name, "iqn.");
Jesper Juhla57b5d32011-06-28 00:30:17 +02001288 if (!ptr) {
Andy Grover6708bb22011-06-08 10:36:43 -07001289 pr_err("Unable to locate prefix for emulated Target "
Jesper Juhla57b5d32011-06-28 00:30:17 +02001290 "Port: %s\n", name);
1291 ret = -EINVAL;
1292 goto out;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001293 }
Jesper Juhla57b5d32011-06-28 00:30:17 +02001294 tl_hba->tl_proto_id = SCSI_PROTOCOL_ISCSI;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001295
1296check_len:
Dan Carpenter60d645a2011-06-15 10:03:05 -07001297 if (strlen(name) >= TL_WWN_ADDR_LEN) {
Andy Grover6708bb22011-06-08 10:36:43 -07001298 pr_err("Emulated NAA %s Address: %s, exceeds"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001299 " max: %d\n", name, tcm_loop_dump_proto_id(tl_hba),
1300 TL_WWN_ADDR_LEN);
Jesper Juhla57b5d32011-06-28 00:30:17 +02001301 ret = -EINVAL;
1302 goto out;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001303 }
1304 snprintf(&tl_hba->tl_wwn_address[0], TL_WWN_ADDR_LEN, "%s", &name[off]);
1305
1306 /*
1307 * Call device_register(tl_hba->dev) to register the emulated
1308 * Linux/SCSI LLD of type struct Scsi_Host at tl_hba->sh after
1309 * device_register() callbacks in tcm_loop_driver_probe()
1310 */
1311 ret = tcm_loop_setup_hba_bus(tl_hba, tcm_loop_hba_no_cnt);
1312 if (ret)
1313 goto out;
1314
1315 sh = tl_hba->sh;
1316 tcm_loop_hba_no_cnt++;
Andy Grover6708bb22011-06-08 10:36:43 -07001317 pr_debug("TCM_Loop_ConfigFS: Allocated emulated Target"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001318 " %s Address: %s at Linux/SCSI Host ID: %d\n",
1319 tcm_loop_dump_proto_id(tl_hba), name, sh->host_no);
1320
1321 return &tl_hba->tl_hba_wwn;
1322out:
1323 kfree(tl_hba);
1324 return ERR_PTR(ret);
1325}
1326
1327void tcm_loop_drop_scsi_hba(
1328 struct se_wwn *wwn)
1329{
1330 struct tcm_loop_hba *tl_hba = container_of(wwn,
1331 struct tcm_loop_hba, tl_hba_wwn);
Nicholas Bellinger6297b072011-11-12 09:29:51 -08001332
1333 pr_debug("TCM_Loop_ConfigFS: Deallocating emulated Target"
1334 " SAS Address: %s at Linux/SCSI Host ID: %d\n",
1335 tl_hba->tl_wwn_address, tl_hba->sh->host_no);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001336 /*
1337 * Call device_unregister() on the original tl_hba->dev.
1338 * tcm_loop_fabric_scsi.c:tcm_loop_release_adapter() will
1339 * release *tl_hba;
1340 */
1341 device_unregister(&tl_hba->dev);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001342}
1343
1344/* Start items for tcm_loop_cit */
1345static ssize_t tcm_loop_wwn_show_attr_version(
1346 struct target_fabric_configfs *tf,
1347 char *page)
1348{
1349 return sprintf(page, "TCM Loopback Fabric module %s\n", TCM_LOOP_VERSION);
1350}
1351
1352TF_WWN_ATTR_RO(tcm_loop, version);
1353
1354static struct configfs_attribute *tcm_loop_wwn_attrs[] = {
1355 &tcm_loop_wwn_version.attr,
1356 NULL,
1357};
1358
1359/* End items for tcm_loop_cit */
1360
1361static int tcm_loop_register_configfs(void)
1362{
1363 struct target_fabric_configfs *fabric;
1364 struct config_group *tf_cg;
1365 int ret;
1366 /*
1367 * Set the TCM Loop HBA counter to zero
1368 */
1369 tcm_loop_hba_no_cnt = 0;
1370 /*
1371 * Register the top level struct config_item_type with TCM core
1372 */
1373 fabric = target_fabric_configfs_init(THIS_MODULE, "loopback");
Andy Grovere3d6f902011-07-19 08:55:10 +00001374 if (IS_ERR(fabric)) {
Andy Grover6708bb22011-06-08 10:36:43 -07001375 pr_err("tcm_loop_register_configfs() failed!\n");
Andy Grovere3d6f902011-07-19 08:55:10 +00001376 return PTR_ERR(fabric);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001377 }
1378 /*
1379 * Setup the fabric API of function pointers used by target_core_mod
1380 */
1381 fabric->tf_ops.get_fabric_name = &tcm_loop_get_fabric_name;
1382 fabric->tf_ops.get_fabric_proto_ident = &tcm_loop_get_fabric_proto_ident;
1383 fabric->tf_ops.tpg_get_wwn = &tcm_loop_get_endpoint_wwn;
1384 fabric->tf_ops.tpg_get_tag = &tcm_loop_get_tag;
1385 fabric->tf_ops.tpg_get_default_depth = &tcm_loop_get_default_depth;
1386 fabric->tf_ops.tpg_get_pr_transport_id = &tcm_loop_get_pr_transport_id;
1387 fabric->tf_ops.tpg_get_pr_transport_id_len =
1388 &tcm_loop_get_pr_transport_id_len;
1389 fabric->tf_ops.tpg_parse_pr_out_transport_id =
1390 &tcm_loop_parse_pr_out_transport_id;
1391 fabric->tf_ops.tpg_check_demo_mode = &tcm_loop_check_demo_mode;
1392 fabric->tf_ops.tpg_check_demo_mode_cache =
1393 &tcm_loop_check_demo_mode_cache;
1394 fabric->tf_ops.tpg_check_demo_mode_write_protect =
1395 &tcm_loop_check_demo_mode_write_protect;
1396 fabric->tf_ops.tpg_check_prod_mode_write_protect =
1397 &tcm_loop_check_prod_mode_write_protect;
1398 /*
1399 * The TCM loopback fabric module runs in demo-mode to a local
1400 * virtual SCSI device, so fabric dependent initator ACLs are
1401 * not required.
1402 */
1403 fabric->tf_ops.tpg_alloc_fabric_acl = &tcm_loop_tpg_alloc_fabric_acl;
1404 fabric->tf_ops.tpg_release_fabric_acl =
1405 &tcm_loop_tpg_release_fabric_acl;
1406 fabric->tf_ops.tpg_get_inst_index = &tcm_loop_get_inst_index;
1407 /*
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001408 * Used for setting up remaining TCM resources in process context
1409 */
1410 fabric->tf_ops.new_cmd_map = &tcm_loop_new_cmd_map;
1411 fabric->tf_ops.check_stop_free = &tcm_loop_check_stop_free;
Christoph Hellwig35462972011-05-31 23:56:57 -04001412 fabric->tf_ops.release_cmd = &tcm_loop_release_cmd;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001413 fabric->tf_ops.shutdown_session = &tcm_loop_shutdown_session;
1414 fabric->tf_ops.close_session = &tcm_loop_close_session;
1415 fabric->tf_ops.stop_session = &tcm_loop_stop_session;
1416 fabric->tf_ops.fall_back_to_erl0 = &tcm_loop_fall_back_to_erl0;
1417 fabric->tf_ops.sess_logged_in = &tcm_loop_sess_logged_in;
1418 fabric->tf_ops.sess_get_index = &tcm_loop_sess_get_index;
1419 fabric->tf_ops.sess_get_initiator_sid = NULL;
1420 fabric->tf_ops.write_pending = &tcm_loop_write_pending;
1421 fabric->tf_ops.write_pending_status = &tcm_loop_write_pending_status;
1422 /*
1423 * Not used for TCM loopback
1424 */
1425 fabric->tf_ops.set_default_node_attributes =
1426 &tcm_loop_set_default_node_attributes;
1427 fabric->tf_ops.get_task_tag = &tcm_loop_get_task_tag;
1428 fabric->tf_ops.get_cmd_state = &tcm_loop_get_cmd_state;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001429 fabric->tf_ops.queue_data_in = &tcm_loop_queue_data_in;
1430 fabric->tf_ops.queue_status = &tcm_loop_queue_status;
1431 fabric->tf_ops.queue_tm_rsp = &tcm_loop_queue_tm_rsp;
1432 fabric->tf_ops.set_fabric_sense_len = &tcm_loop_set_fabric_sense_len;
1433 fabric->tf_ops.get_fabric_sense_len = &tcm_loop_get_fabric_sense_len;
1434 fabric->tf_ops.is_state_remove = &tcm_loop_is_state_remove;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001435
1436 tf_cg = &fabric->tf_group;
1437 /*
1438 * Setup function pointers for generic logic in target_core_fabric_configfs.c
1439 */
1440 fabric->tf_ops.fabric_make_wwn = &tcm_loop_make_scsi_hba;
1441 fabric->tf_ops.fabric_drop_wwn = &tcm_loop_drop_scsi_hba;
1442 fabric->tf_ops.fabric_make_tpg = &tcm_loop_make_naa_tpg;
1443 fabric->tf_ops.fabric_drop_tpg = &tcm_loop_drop_naa_tpg;
1444 /*
1445 * fabric_post_link() and fabric_pre_unlink() are used for
1446 * registration and release of TCM Loop Virtual SCSI LUNs.
1447 */
1448 fabric->tf_ops.fabric_post_link = &tcm_loop_port_link;
1449 fabric->tf_ops.fabric_pre_unlink = &tcm_loop_port_unlink;
1450 fabric->tf_ops.fabric_make_np = NULL;
1451 fabric->tf_ops.fabric_drop_np = NULL;
1452 /*
1453 * Setup default attribute lists for various fabric->tf_cit_tmpl
1454 */
1455 TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = tcm_loop_wwn_attrs;
1456 TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = tcm_loop_tpg_attrs;
1457 TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = NULL;
1458 TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = NULL;
1459 TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = NULL;
1460 /*
1461 * Once fabric->tf_ops has been setup, now register the fabric for
1462 * use within TCM
1463 */
1464 ret = target_fabric_configfs_register(fabric);
1465 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -07001466 pr_err("target_fabric_configfs_register() for"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001467 " TCM_Loop failed!\n");
1468 target_fabric_configfs_free(fabric);
1469 return -1;
1470 }
1471 /*
1472 * Setup our local pointer to *fabric.
1473 */
1474 tcm_loop_fabric_configfs = fabric;
Andy Grover6708bb22011-06-08 10:36:43 -07001475 pr_debug("TCM_LOOP[0] - Set fabric ->"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001476 " tcm_loop_fabric_configfs\n");
1477 return 0;
1478}
1479
1480static void tcm_loop_deregister_configfs(void)
1481{
1482 if (!tcm_loop_fabric_configfs)
1483 return;
1484
1485 target_fabric_configfs_deregister(tcm_loop_fabric_configfs);
1486 tcm_loop_fabric_configfs = NULL;
Andy Grover6708bb22011-06-08 10:36:43 -07001487 pr_debug("TCM_LOOP[0] - Cleared"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001488 " tcm_loop_fabric_configfs\n");
1489}
1490
1491static int __init tcm_loop_fabric_init(void)
1492{
1493 int ret;
1494
1495 tcm_loop_cmd_cache = kmem_cache_create("tcm_loop_cmd_cache",
1496 sizeof(struct tcm_loop_cmd),
1497 __alignof__(struct tcm_loop_cmd),
1498 0, NULL);
1499 if (!tcm_loop_cmd_cache) {
Andy Grover6708bb22011-06-08 10:36:43 -07001500 pr_debug("kmem_cache_create() for"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001501 " tcm_loop_cmd_cache failed\n");
1502 return -ENOMEM;
1503 }
1504
1505 ret = tcm_loop_alloc_core_bus();
1506 if (ret)
1507 return ret;
1508
1509 ret = tcm_loop_register_configfs();
1510 if (ret) {
1511 tcm_loop_release_core_bus();
1512 return ret;
1513 }
1514
1515 return 0;
1516}
1517
1518static void __exit tcm_loop_fabric_exit(void)
1519{
1520 tcm_loop_deregister_configfs();
1521 tcm_loop_release_core_bus();
1522 kmem_cache_destroy(tcm_loop_cmd_cache);
1523}
1524
1525MODULE_DESCRIPTION("TCM loopback virtual Linux/SCSI fabric module");
1526MODULE_AUTHOR("Nicholas A. Bellinger <nab@risingtidesystems.com>");
1527MODULE_LICENSE("GPL");
1528module_init(tcm_loop_fabric_init);
1529module_exit(tcm_loop_fabric_exit);