blob: 3c9c318f66ed4d2f3890e339d0938bb60ca0a2e9 [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>
36#include <target/target_core_transport.h>
37#include <target/target_core_fabric_ops.h>
38#include <target/target_core_fabric_configfs.h>
39#include <target/target_core_fabric_lib.h>
40#include <target/target_core_configfs.h>
41#include <target/target_core_device.h>
42#include <target/target_core_tpg.h>
43#include <target/target_core_tmr.h>
44
45#include "tcm_loop.h"
46
47#define to_tcm_loop_hba(hba) container_of(hba, struct tcm_loop_hba, dev)
48
49/* Local pointer to allocated TCM configfs fabric module */
50static struct target_fabric_configfs *tcm_loop_fabric_configfs;
51
52static struct kmem_cache *tcm_loop_cmd_cache;
53
54static int tcm_loop_hba_no_cnt;
55
56/*
57 * Allocate a tcm_loop cmd descriptor from target_core_mod code
58 *
59 * Can be called from interrupt context in tcm_loop_queuecommand() below
60 */
61static struct se_cmd *tcm_loop_allocate_core_cmd(
62 struct tcm_loop_hba *tl_hba,
63 struct se_portal_group *se_tpg,
64 struct scsi_cmnd *sc)
65{
66 struct se_cmd *se_cmd;
67 struct se_session *se_sess;
68 struct tcm_loop_nexus *tl_nexus = tl_hba->tl_nexus;
69 struct tcm_loop_cmd *tl_cmd;
70 int sam_task_attr;
71
72 if (!tl_nexus) {
73 scmd_printk(KERN_ERR, sc, "TCM_Loop I_T Nexus"
74 " does not exist\n");
75 set_host_byte(sc, DID_ERROR);
76 return NULL;
77 }
78 se_sess = tl_nexus->se_sess;
79
80 tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_ATOMIC);
81 if (!tl_cmd) {
Andy Grover6708bb22011-06-08 10:36:43 -070082 pr_err("Unable to allocate struct tcm_loop_cmd\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -070083 set_host_byte(sc, DID_ERROR);
84 return NULL;
85 }
86 se_cmd = &tl_cmd->tl_se_cmd;
87 /*
88 * Save the pointer to struct scsi_cmnd *sc
89 */
90 tl_cmd->sc = sc;
91 /*
92 * Locate the SAM Task Attr from struct scsi_cmnd *
93 */
94 if (sc->device->tagged_supported) {
95 switch (sc->tag) {
96 case HEAD_OF_QUEUE_TAG:
Nicholas Bellinger61db1802011-05-19 20:19:14 -070097 sam_task_attr = MSG_HEAD_TAG;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -070098 break;
99 case ORDERED_QUEUE_TAG:
Nicholas Bellinger61db1802011-05-19 20:19:14 -0700100 sam_task_attr = MSG_ORDERED_TAG;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700101 break;
102 default:
Nicholas Bellinger61db1802011-05-19 20:19:14 -0700103 sam_task_attr = MSG_SIMPLE_TAG;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700104 break;
105 }
106 } else
Nicholas Bellinger61db1802011-05-19 20:19:14 -0700107 sam_task_attr = MSG_SIMPLE_TAG;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700108
109 /*
110 * Initialize struct se_cmd descriptor from target_core_mod infrastructure
111 */
112 transport_init_se_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess,
113 scsi_bufflen(sc), sc->sc_data_direction, sam_task_attr,
114 &tl_cmd->tl_sense_buf[0]);
115
116 /*
117 * Signal BIDI usage with T_TASK(cmd)->t_tasks_bidi
118 */
119 if (scsi_bidi_cmnd(sc))
Andy Grovera1d8b492011-05-02 17:12:10 -0700120 se_cmd->t_tasks_bidi = 1;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700121 /*
122 * Locate the struct se_lun pointer and attach it to struct se_cmd
123 */
Andy Grover59511462011-07-19 10:26:37 +0000124 if (transport_lookup_cmd_lun(se_cmd, tl_cmd->sc->device->lun) < 0) {
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700125 kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
126 set_host_byte(sc, DID_NO_CONNECT);
127 return NULL;
128 }
129
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700130 return se_cmd;
131}
132
133/*
134 * Called by struct target_core_fabric_ops->new_cmd_map()
135 *
136 * Always called in process context. A non zero return value
137 * here will signal to handle an exception based on the return code.
138 */
139static int tcm_loop_new_cmd_map(struct se_cmd *se_cmd)
140{
141 struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
142 struct tcm_loop_cmd, tl_se_cmd);
143 struct scsi_cmnd *sc = tl_cmd->sc;
Andy Grover59511462011-07-19 10:26:37 +0000144 struct scatterlist *sgl_bidi = NULL;
145 u32 sgl_bidi_count = 0;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700146 int ret;
147 /*
148 * Allocate the necessary tasks to complete the received CDB+data
149 */
Andy Grover59511462011-07-19 10:26:37 +0000150 ret = transport_generic_allocate_tasks(se_cmd, sc->cmnd);
151 if (ret == -ENOMEM) {
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700152 /* Out of Resources */
153 return PYX_TRANSPORT_LU_COMM_FAILURE;
Andy Grover59511462011-07-19 10:26:37 +0000154 } else if (ret == -EINVAL) {
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700155 /*
156 * Handle case for SAM_STAT_RESERVATION_CONFLICT
157 */
158 if (se_cmd->se_cmd_flags & SCF_SCSI_RESERVATION_CONFLICT)
159 return PYX_TRANSPORT_RESERVATION_CONFLICT;
160 /*
161 * Otherwise, return SAM_STAT_CHECK_CONDITION and return
162 * sense data.
163 */
164 return PYX_TRANSPORT_USE_SENSE_REASON;
165 }
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700166
Andy Grover59511462011-07-19 10:26:37 +0000167 /*
168 * For BIDI commands, pass in the extra READ buffer
169 * to transport_generic_map_mem_to_cmd() below..
170 */
Andy Grovera1d8b492011-05-02 17:12:10 -0700171 if (se_cmd->t_tasks_bidi) {
Andy Grover59511462011-07-19 10:26:37 +0000172 struct scsi_data_buffer *sdb = scsi_in(sc);
173
174 sgl_bidi = sdb->table.sgl;
175 sgl_bidi_count = sdb->table.nents;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700176 }
Nicholas Bellinger8cd79f22011-10-24 13:35:37 -0700177 /*
178 * Because some userspace code via scsi-generic do not memset their
179 * associated read buffers, go ahead and do that here for type
180 * SCF_SCSI_CONTROL_SG_IO_CDB. Also note that this is currently
181 * guaranteed to be a single SGL for SCF_SCSI_CONTROL_SG_IO_CDB
182 * by target core in transport_generic_allocate_tasks() ->
183 * transport_generic_cmd_sequencer().
184 */
185 if (se_cmd->se_cmd_flags & SCF_SCSI_CONTROL_SG_IO_CDB &&
186 se_cmd->data_direction == DMA_FROM_DEVICE) {
187 struct scatterlist *sg = scsi_sglist(sc);
188 unsigned char *buf = kmap(sg_page(sg)) + sg->offset;
189
190 if (buf != NULL) {
191 memset(buf, 0, sg->length);
192 kunmap(sg_page(sg));
193 }
194 }
Andy Grover59511462011-07-19 10:26:37 +0000195
Andy Groverec98f782011-07-20 19:28:46 +0000196 /* Tell the core about our preallocated memory */
Andy Grover59511462011-07-19 10:26:37 +0000197 ret = transport_generic_map_mem_to_cmd(se_cmd, scsi_sglist(sc),
198 scsi_sg_count(sc), sgl_bidi, sgl_bidi_count);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700199 if (ret < 0)
200 return PYX_TRANSPORT_LU_COMM_FAILURE;
201
202 return 0;
203}
204
205/*
206 * Called from struct target_core_fabric_ops->check_stop_free()
207 */
208static void tcm_loop_check_stop_free(struct se_cmd *se_cmd)
209{
210 /*
211 * Do not release struct se_cmd's containing a valid TMR
212 * pointer. These will be released directly in tcm_loop_device_reset()
213 * with transport_generic_free_cmd().
214 */
215 if (se_cmd->se_tmr_req)
216 return;
217 /*
218 * Release the struct se_cmd, which will make a callback to release
219 * struct tcm_loop_cmd * in tcm_loop_deallocate_core_cmd()
220 */
Christoph Hellwig82f1c8a2011-09-13 23:09:01 +0200221 transport_generic_free_cmd(se_cmd, 0);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700222}
223
Christoph Hellwig35462972011-05-31 23:56:57 -0400224static void tcm_loop_release_cmd(struct se_cmd *se_cmd)
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700225{
226 struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
227 struct tcm_loop_cmd, tl_se_cmd);
228
229 kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
230}
231
232static int tcm_loop_proc_info(struct Scsi_Host *host, char *buffer,
233 char **start, off_t offset,
234 int length, int inout)
235{
236 return sprintf(buffer, "tcm_loop_proc_info()\n");
237}
238
239static int tcm_loop_driver_probe(struct device *);
240static int tcm_loop_driver_remove(struct device *);
241
242static int pseudo_lld_bus_match(struct device *dev,
243 struct device_driver *dev_driver)
244{
245 return 1;
246}
247
248static struct bus_type tcm_loop_lld_bus = {
249 .name = "tcm_loop_bus",
250 .match = pseudo_lld_bus_match,
251 .probe = tcm_loop_driver_probe,
252 .remove = tcm_loop_driver_remove,
253};
254
255static struct device_driver tcm_loop_driverfs = {
256 .name = "tcm_loop",
257 .bus = &tcm_loop_lld_bus,
258};
259/*
260 * Used with root_device_register() in tcm_loop_alloc_core_bus() below
261 */
262struct device *tcm_loop_primary;
263
264/*
265 * Copied from drivers/scsi/libfc/fc_fcp.c:fc_change_queue_depth() and
266 * drivers/scsi/libiscsi.c:iscsi_change_queue_depth()
267 */
268static int tcm_loop_change_queue_depth(
269 struct scsi_device *sdev,
270 int depth,
271 int reason)
272{
273 switch (reason) {
274 case SCSI_QDEPTH_DEFAULT:
275 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
276 break;
277 case SCSI_QDEPTH_QFULL:
278 scsi_track_queue_full(sdev, depth);
279 break;
280 case SCSI_QDEPTH_RAMP_UP:
281 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
282 break;
283 default:
284 return -EOPNOTSUPP;
285 }
286 return sdev->queue_depth;
287}
288
289/*
290 * Main entry point from struct scsi_host_template for incoming SCSI CDB+Data
291 * from Linux/SCSI subsystem for SCSI low level device drivers (LLDs)
292 */
293static int tcm_loop_queuecommand(
294 struct Scsi_Host *sh,
295 struct scsi_cmnd *sc)
296{
297 struct se_cmd *se_cmd;
298 struct se_portal_group *se_tpg;
299 struct tcm_loop_hba *tl_hba;
300 struct tcm_loop_tpg *tl_tpg;
301
Andy Grover6708bb22011-06-08 10:36:43 -0700302 pr_debug("tcm_loop_queuecommand() %d:%d:%d:%d got CDB: 0x%02x"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700303 " scsi_buf_len: %u\n", sc->device->host->host_no,
304 sc->device->id, sc->device->channel, sc->device->lun,
305 sc->cmnd[0], scsi_bufflen(sc));
306 /*
307 * Locate the tcm_loop_hba_t pointer
308 */
309 tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);
310 tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];
Nicholas Bellinger0a020432011-10-10 19:44:05 -0700311 /*
312 * Ensure that this tl_tpg reference from the incoming sc->device->id
313 * has already been configured via tcm_loop_make_naa_tpg().
314 */
315 if (!tl_tpg->tl_hba) {
316 set_host_byte(sc, DID_NO_CONNECT);
317 sc->scsi_done(sc);
318 return 0;
319 }
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700320 se_tpg = &tl_tpg->tl_se_tpg;
321 /*
322 * Determine the SAM Task Attribute and allocate tl_cmd and
323 * tl_cmd->tl_se_cmd from TCM infrastructure
324 */
325 se_cmd = tcm_loop_allocate_core_cmd(tl_hba, se_tpg, sc);
326 if (!se_cmd) {
327 sc->scsi_done(sc);
328 return 0;
329 }
330 /*
331 * Queue up the newly allocated to be processed in TCM thread context.
332 */
333 transport_generic_handle_cdb_map(se_cmd);
334 return 0;
335}
336
337/*
338 * Called from SCSI EH process context to issue a LUN_RESET TMR
339 * to struct scsi_device
340 */
341static int tcm_loop_device_reset(struct scsi_cmnd *sc)
342{
343 struct se_cmd *se_cmd = NULL;
344 struct se_portal_group *se_tpg;
345 struct se_session *se_sess;
346 struct tcm_loop_cmd *tl_cmd = NULL;
347 struct tcm_loop_hba *tl_hba;
348 struct tcm_loop_nexus *tl_nexus;
349 struct tcm_loop_tmr *tl_tmr = NULL;
350 struct tcm_loop_tpg *tl_tpg;
351 int ret = FAILED;
352 /*
353 * Locate the tcm_loop_hba_t pointer
354 */
355 tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);
356 /*
357 * Locate the tl_nexus and se_sess pointers
358 */
359 tl_nexus = tl_hba->tl_nexus;
360 if (!tl_nexus) {
Andy Grover6708bb22011-06-08 10:36:43 -0700361 pr_err("Unable to perform device reset without"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700362 " active I_T Nexus\n");
363 return FAILED;
364 }
365 se_sess = tl_nexus->se_sess;
366 /*
367 * Locate the tl_tpg and se_tpg pointers from TargetID in sc->device->id
368 */
369 tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];
370 se_tpg = &tl_tpg->tl_se_tpg;
371
372 tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_KERNEL);
373 if (!tl_cmd) {
Andy Grover6708bb22011-06-08 10:36:43 -0700374 pr_err("Unable to allocate memory for tl_cmd\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700375 return FAILED;
376 }
377
378 tl_tmr = kzalloc(sizeof(struct tcm_loop_tmr), GFP_KERNEL);
379 if (!tl_tmr) {
Andy Grover6708bb22011-06-08 10:36:43 -0700380 pr_err("Unable to allocate memory for tl_tmr\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700381 goto release;
382 }
383 init_waitqueue_head(&tl_tmr->tl_tmr_wait);
384
385 se_cmd = &tl_cmd->tl_se_cmd;
386 /*
387 * Initialize struct se_cmd descriptor from target_core_mod infrastructure
388 */
389 transport_init_se_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess, 0,
Nicholas Bellinger61db1802011-05-19 20:19:14 -0700390 DMA_NONE, MSG_SIMPLE_TAG,
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700391 &tl_cmd->tl_sense_buf[0]);
392 /*
393 * Allocate the LUN_RESET TMR
394 */
Andy Grover59511462011-07-19 10:26:37 +0000395 se_cmd->se_tmr_req = core_tmr_alloc_req(se_cmd, tl_tmr,
Roland Dreierdd503a52011-10-06 09:56:16 -0700396 TMR_LUN_RESET, GFP_KERNEL);
Dan Carpenter552523d2011-06-15 09:41:33 -0700397 if (IS_ERR(se_cmd->se_tmr_req))
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700398 goto release;
399 /*
400 * Locate the underlying TCM struct se_lun from sc->device->lun
401 */
Andy Grover59511462011-07-19 10:26:37 +0000402 if (transport_lookup_tmr_lun(se_cmd, sc->device->lun) < 0)
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700403 goto release;
404 /*
405 * Queue the TMR to TCM Core and sleep waiting for tcm_loop_queue_tm_rsp()
406 * to wake us up.
407 */
408 transport_generic_handle_tmr(se_cmd);
409 wait_event(tl_tmr->tl_tmr_wait, atomic_read(&tl_tmr->tmr_complete));
410 /*
411 * The TMR LUN_RESET has completed, check the response status and
412 * then release allocations.
413 */
414 ret = (se_cmd->se_tmr_req->response == TMR_FUNCTION_COMPLETE) ?
415 SUCCESS : FAILED;
416release:
417 if (se_cmd)
Christoph Hellwig82f1c8a2011-09-13 23:09:01 +0200418 transport_generic_free_cmd(se_cmd, 1);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700419 else
420 kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
421 kfree(tl_tmr);
422 return ret;
423}
424
425static int tcm_loop_slave_alloc(struct scsi_device *sd)
426{
427 set_bit(QUEUE_FLAG_BIDI, &sd->request_queue->queue_flags);
428 return 0;
429}
430
431static int tcm_loop_slave_configure(struct scsi_device *sd)
432{
433 return 0;
434}
435
436static struct scsi_host_template tcm_loop_driver_template = {
437 .proc_info = tcm_loop_proc_info,
438 .proc_name = "tcm_loopback",
439 .name = "TCM_Loopback",
440 .queuecommand = tcm_loop_queuecommand,
441 .change_queue_depth = tcm_loop_change_queue_depth,
442 .eh_device_reset_handler = tcm_loop_device_reset,
443 .can_queue = TL_SCSI_CAN_QUEUE,
444 .this_id = -1,
445 .sg_tablesize = TL_SCSI_SG_TABLESIZE,
446 .cmd_per_lun = TL_SCSI_CMD_PER_LUN,
447 .max_sectors = TL_SCSI_MAX_SECTORS,
448 .use_clustering = DISABLE_CLUSTERING,
449 .slave_alloc = tcm_loop_slave_alloc,
450 .slave_configure = tcm_loop_slave_configure,
451 .module = THIS_MODULE,
452};
453
454static int tcm_loop_driver_probe(struct device *dev)
455{
456 struct tcm_loop_hba *tl_hba;
457 struct Scsi_Host *sh;
458 int error;
459
460 tl_hba = to_tcm_loop_hba(dev);
461
462 sh = scsi_host_alloc(&tcm_loop_driver_template,
463 sizeof(struct tcm_loop_hba));
464 if (!sh) {
Andy Grover6708bb22011-06-08 10:36:43 -0700465 pr_err("Unable to allocate struct scsi_host\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700466 return -ENODEV;
467 }
468 tl_hba->sh = sh;
469
470 /*
471 * Assign the struct tcm_loop_hba pointer to struct Scsi_Host->hostdata
472 */
473 *((struct tcm_loop_hba **)sh->hostdata) = tl_hba;
474 /*
475 * Setup single ID, Channel and LUN for now..
476 */
477 sh->max_id = 2;
478 sh->max_lun = 0;
479 sh->max_channel = 0;
480 sh->max_cmd_len = TL_SCSI_MAX_CMD_LEN;
481
482 error = scsi_add_host(sh, &tl_hba->dev);
483 if (error) {
Andy Grover6708bb22011-06-08 10:36:43 -0700484 pr_err("%s: scsi_add_host failed\n", __func__);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700485 scsi_host_put(sh);
486 return -ENODEV;
487 }
488 return 0;
489}
490
491static int tcm_loop_driver_remove(struct device *dev)
492{
493 struct tcm_loop_hba *tl_hba;
494 struct Scsi_Host *sh;
495
496 tl_hba = to_tcm_loop_hba(dev);
497 sh = tl_hba->sh;
498
499 scsi_remove_host(sh);
500 scsi_host_put(sh);
501 return 0;
502}
503
504static void tcm_loop_release_adapter(struct device *dev)
505{
506 struct tcm_loop_hba *tl_hba = to_tcm_loop_hba(dev);
507
508 kfree(tl_hba);
509}
510
511/*
512 * Called from tcm_loop_make_scsi_hba() in tcm_loop_configfs.c
513 */
514static int tcm_loop_setup_hba_bus(struct tcm_loop_hba *tl_hba, int tcm_loop_host_id)
515{
516 int ret;
517
518 tl_hba->dev.bus = &tcm_loop_lld_bus;
519 tl_hba->dev.parent = tcm_loop_primary;
520 tl_hba->dev.release = &tcm_loop_release_adapter;
521 dev_set_name(&tl_hba->dev, "tcm_loop_adapter_%d", tcm_loop_host_id);
522
523 ret = device_register(&tl_hba->dev);
524 if (ret) {
Andy Grover6708bb22011-06-08 10:36:43 -0700525 pr_err("device_register() failed for"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700526 " tl_hba->dev: %d\n", ret);
527 return -ENODEV;
528 }
529
530 return 0;
531}
532
533/*
534 * Called from tcm_loop_fabric_init() in tcl_loop_fabric.c to load the emulated
535 * tcm_loop SCSI bus.
536 */
537static int tcm_loop_alloc_core_bus(void)
538{
539 int ret;
540
541 tcm_loop_primary = root_device_register("tcm_loop_0");
542 if (IS_ERR(tcm_loop_primary)) {
Andy Grover6708bb22011-06-08 10:36:43 -0700543 pr_err("Unable to allocate tcm_loop_primary\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700544 return PTR_ERR(tcm_loop_primary);
545 }
546
547 ret = bus_register(&tcm_loop_lld_bus);
548 if (ret) {
Andy Grover6708bb22011-06-08 10:36:43 -0700549 pr_err("bus_register() failed for tcm_loop_lld_bus\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700550 goto dev_unreg;
551 }
552
553 ret = driver_register(&tcm_loop_driverfs);
554 if (ret) {
Andy Grover6708bb22011-06-08 10:36:43 -0700555 pr_err("driver_register() failed for"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700556 "tcm_loop_driverfs\n");
557 goto bus_unreg;
558 }
559
Andy Grover6708bb22011-06-08 10:36:43 -0700560 pr_debug("Initialized TCM Loop Core Bus\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700561 return ret;
562
563bus_unreg:
564 bus_unregister(&tcm_loop_lld_bus);
565dev_unreg:
566 root_device_unregister(tcm_loop_primary);
567 return ret;
568}
569
570static void tcm_loop_release_core_bus(void)
571{
572 driver_unregister(&tcm_loop_driverfs);
573 bus_unregister(&tcm_loop_lld_bus);
574 root_device_unregister(tcm_loop_primary);
575
Andy Grover6708bb22011-06-08 10:36:43 -0700576 pr_debug("Releasing TCM Loop Core BUS\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700577}
578
579static char *tcm_loop_get_fabric_name(void)
580{
581 return "loopback";
582}
583
584static u8 tcm_loop_get_fabric_proto_ident(struct se_portal_group *se_tpg)
585{
586 struct tcm_loop_tpg *tl_tpg =
587 (struct tcm_loop_tpg *)se_tpg->se_tpg_fabric_ptr;
588 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
589 /*
590 * tl_proto_id is set at tcm_loop_configfs.c:tcm_loop_make_scsi_hba()
591 * time based on the protocol dependent prefix of the passed configfs group.
592 *
593 * Based upon tl_proto_id, TCM_Loop emulates the requested fabric
594 * ProtocolID using target_core_fabric_lib.c symbols.
595 */
596 switch (tl_hba->tl_proto_id) {
597 case SCSI_PROTOCOL_SAS:
598 return sas_get_fabric_proto_ident(se_tpg);
599 case SCSI_PROTOCOL_FCP:
600 return fc_get_fabric_proto_ident(se_tpg);
601 case SCSI_PROTOCOL_ISCSI:
602 return iscsi_get_fabric_proto_ident(se_tpg);
603 default:
Andy Grover6708bb22011-06-08 10:36:43 -0700604 pr_err("Unknown tl_proto_id: 0x%02x, using"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700605 " SAS emulation\n", tl_hba->tl_proto_id);
606 break;
607 }
608
609 return sas_get_fabric_proto_ident(se_tpg);
610}
611
612static char *tcm_loop_get_endpoint_wwn(struct se_portal_group *se_tpg)
613{
614 struct tcm_loop_tpg *tl_tpg =
615 (struct tcm_loop_tpg *)se_tpg->se_tpg_fabric_ptr;
616 /*
617 * Return the passed NAA identifier for the SAS Target Port
618 */
619 return &tl_tpg->tl_hba->tl_wwn_address[0];
620}
621
622static u16 tcm_loop_get_tag(struct se_portal_group *se_tpg)
623{
624 struct tcm_loop_tpg *tl_tpg =
625 (struct tcm_loop_tpg *)se_tpg->se_tpg_fabric_ptr;
626 /*
627 * This Tag is used when forming SCSI Name identifier in EVPD=1 0x83
628 * to represent the SCSI Target Port.
629 */
630 return tl_tpg->tl_tpgt;
631}
632
633static u32 tcm_loop_get_default_depth(struct se_portal_group *se_tpg)
634{
635 return 1;
636}
637
638static u32 tcm_loop_get_pr_transport_id(
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 unsigned char *buf)
644{
645 struct tcm_loop_tpg *tl_tpg =
646 (struct tcm_loop_tpg *)se_tpg->se_tpg_fabric_ptr;
647 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
648
649 switch (tl_hba->tl_proto_id) {
650 case SCSI_PROTOCOL_SAS:
651 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
652 format_code, buf);
653 case SCSI_PROTOCOL_FCP:
654 return fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
655 format_code, buf);
656 case SCSI_PROTOCOL_ISCSI:
657 return iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
658 format_code, buf);
659 default:
Andy Grover6708bb22011-06-08 10:36:43 -0700660 pr_err("Unknown tl_proto_id: 0x%02x, using"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700661 " SAS emulation\n", tl_hba->tl_proto_id);
662 break;
663 }
664
665 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
666 format_code, buf);
667}
668
669static u32 tcm_loop_get_pr_transport_id_len(
670 struct se_portal_group *se_tpg,
671 struct se_node_acl *se_nacl,
672 struct t10_pr_registration *pr_reg,
673 int *format_code)
674{
675 struct tcm_loop_tpg *tl_tpg =
676 (struct tcm_loop_tpg *)se_tpg->se_tpg_fabric_ptr;
677 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
678
679 switch (tl_hba->tl_proto_id) {
680 case SCSI_PROTOCOL_SAS:
681 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
682 format_code);
683 case SCSI_PROTOCOL_FCP:
684 return fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
685 format_code);
686 case SCSI_PROTOCOL_ISCSI:
687 return iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
688 format_code);
689 default:
Andy Grover6708bb22011-06-08 10:36:43 -0700690 pr_err("Unknown tl_proto_id: 0x%02x, using"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700691 " SAS emulation\n", tl_hba->tl_proto_id);
692 break;
693 }
694
695 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
696 format_code);
697}
698
699/*
700 * Used for handling SCSI fabric dependent TransportIDs in SPC-3 and above
701 * Persistent Reservation SPEC_I_PT=1 and PROUT REGISTER_AND_MOVE operations.
702 */
703static char *tcm_loop_parse_pr_out_transport_id(
704 struct se_portal_group *se_tpg,
705 const char *buf,
706 u32 *out_tid_len,
707 char **port_nexus_ptr)
708{
709 struct tcm_loop_tpg *tl_tpg =
710 (struct tcm_loop_tpg *)se_tpg->se_tpg_fabric_ptr;
711 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
712
713 switch (tl_hba->tl_proto_id) {
714 case SCSI_PROTOCOL_SAS:
715 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
716 port_nexus_ptr);
717 case SCSI_PROTOCOL_FCP:
718 return fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
719 port_nexus_ptr);
720 case SCSI_PROTOCOL_ISCSI:
721 return iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
722 port_nexus_ptr);
723 default:
Andy Grover6708bb22011-06-08 10:36:43 -0700724 pr_err("Unknown tl_proto_id: 0x%02x, using"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700725 " SAS emulation\n", tl_hba->tl_proto_id);
726 break;
727 }
728
729 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
730 port_nexus_ptr);
731}
732
733/*
734 * Returning (1) here allows for target_core_mod struct se_node_acl to be generated
735 * based upon the incoming fabric dependent SCSI Initiator Port
736 */
737static int tcm_loop_check_demo_mode(struct se_portal_group *se_tpg)
738{
739 return 1;
740}
741
742static int tcm_loop_check_demo_mode_cache(struct se_portal_group *se_tpg)
743{
744 return 0;
745}
746
747/*
748 * Allow I_T Nexus full READ-WRITE access without explict Initiator Node ACLs for
749 * local virtual Linux/SCSI LLD passthrough into VM hypervisor guest
750 */
751static int tcm_loop_check_demo_mode_write_protect(struct se_portal_group *se_tpg)
752{
753 return 0;
754}
755
756/*
757 * Because TCM_Loop does not use explict ACLs and MappedLUNs, this will
758 * never be called for TCM_Loop by target_core_fabric_configfs.c code.
759 * It has been added here as a nop for target_fabric_tf_ops_check()
760 */
761static int tcm_loop_check_prod_mode_write_protect(struct se_portal_group *se_tpg)
762{
763 return 0;
764}
765
766static struct se_node_acl *tcm_loop_tpg_alloc_fabric_acl(
767 struct se_portal_group *se_tpg)
768{
769 struct tcm_loop_nacl *tl_nacl;
770
771 tl_nacl = kzalloc(sizeof(struct tcm_loop_nacl), GFP_KERNEL);
772 if (!tl_nacl) {
Andy Grover6708bb22011-06-08 10:36:43 -0700773 pr_err("Unable to allocate struct tcm_loop_nacl\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700774 return NULL;
775 }
776
777 return &tl_nacl->se_node_acl;
778}
779
780static void tcm_loop_tpg_release_fabric_acl(
781 struct se_portal_group *se_tpg,
782 struct se_node_acl *se_nacl)
783{
784 struct tcm_loop_nacl *tl_nacl = container_of(se_nacl,
785 struct tcm_loop_nacl, se_node_acl);
786
787 kfree(tl_nacl);
788}
789
790static u32 tcm_loop_get_inst_index(struct se_portal_group *se_tpg)
791{
792 return 1;
793}
794
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700795static int tcm_loop_is_state_remove(struct se_cmd *se_cmd)
796{
797 /*
798 * Assume struct scsi_cmnd is not in remove state..
799 */
800 return 0;
801}
802
803static int tcm_loop_sess_logged_in(struct se_session *se_sess)
804{
805 /*
806 * Assume that TL Nexus is always active
807 */
808 return 1;
809}
810
811static u32 tcm_loop_sess_get_index(struct se_session *se_sess)
812{
813 return 1;
814}
815
816static void tcm_loop_set_default_node_attributes(struct se_node_acl *se_acl)
817{
818 return;
819}
820
821static u32 tcm_loop_get_task_tag(struct se_cmd *se_cmd)
822{
823 return 1;
824}
825
826static int tcm_loop_get_cmd_state(struct se_cmd *se_cmd)
827{
828 struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
829 struct tcm_loop_cmd, tl_se_cmd);
830
831 return tl_cmd->sc_cmd_state;
832}
833
834static int tcm_loop_shutdown_session(struct se_session *se_sess)
835{
836 return 0;
837}
838
839static void tcm_loop_close_session(struct se_session *se_sess)
840{
841 return;
842};
843
844static void tcm_loop_stop_session(
845 struct se_session *se_sess,
846 int sess_sleep,
847 int conn_sleep)
848{
849 return;
850}
851
852static void tcm_loop_fall_back_to_erl0(struct se_session *se_sess)
853{
854 return;
855}
856
857static int tcm_loop_write_pending(struct se_cmd *se_cmd)
858{
859 /*
860 * Since Linux/SCSI has already sent down a struct scsi_cmnd
861 * sc->sc_data_direction of DMA_TO_DEVICE with struct scatterlist array
862 * memory, and memory has already been mapped to struct se_cmd->t_mem_list
863 * format with transport_generic_map_mem_to_cmd().
864 *
865 * We now tell TCM to add this WRITE CDB directly into the TCM storage
866 * object execution queue.
867 */
868 transport_generic_process_write(se_cmd);
869 return 0;
870}
871
872static int tcm_loop_write_pending_status(struct se_cmd *se_cmd)
873{
874 return 0;
875}
876
877static int tcm_loop_queue_data_in(struct se_cmd *se_cmd)
878{
879 struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
880 struct tcm_loop_cmd, tl_se_cmd);
881 struct scsi_cmnd *sc = tl_cmd->sc;
882
Andy Grover6708bb22011-06-08 10:36:43 -0700883 pr_debug("tcm_loop_queue_data_in() called for scsi_cmnd: %p"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700884 " cdb: 0x%02x\n", sc, sc->cmnd[0]);
885
886 sc->result = SAM_STAT_GOOD;
887 set_host_byte(sc, DID_OK);
888 sc->scsi_done(sc);
889 return 0;
890}
891
892static int tcm_loop_queue_status(struct se_cmd *se_cmd)
893{
894 struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
895 struct tcm_loop_cmd, tl_se_cmd);
896 struct scsi_cmnd *sc = tl_cmd->sc;
897
Andy Grover6708bb22011-06-08 10:36:43 -0700898 pr_debug("tcm_loop_queue_status() called for scsi_cmnd: %p"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700899 " cdb: 0x%02x\n", sc, sc->cmnd[0]);
900
901 if (se_cmd->sense_buffer &&
902 ((se_cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) ||
903 (se_cmd->se_cmd_flags & SCF_EMULATED_TASK_SENSE))) {
904
Andy Grover59511462011-07-19 10:26:37 +0000905 memcpy(sc->sense_buffer, se_cmd->sense_buffer,
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700906 SCSI_SENSE_BUFFERSIZE);
907 sc->result = SAM_STAT_CHECK_CONDITION;
908 set_driver_byte(sc, DRIVER_SENSE);
909 } else
910 sc->result = se_cmd->scsi_status;
911
912 set_host_byte(sc, DID_OK);
913 sc->scsi_done(sc);
914 return 0;
915}
916
917static int tcm_loop_queue_tm_rsp(struct se_cmd *se_cmd)
918{
919 struct se_tmr_req *se_tmr = se_cmd->se_tmr_req;
920 struct tcm_loop_tmr *tl_tmr = se_tmr->fabric_tmr_ptr;
921 /*
922 * The SCSI EH thread will be sleeping on se_tmr->tl_tmr_wait, go ahead
923 * and wake up the wait_queue_head_t in tcm_loop_device_reset()
924 */
925 atomic_set(&tl_tmr->tmr_complete, 1);
926 wake_up(&tl_tmr->tl_tmr_wait);
927 return 0;
928}
929
930static u16 tcm_loop_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length)
931{
932 return 0;
933}
934
935static u16 tcm_loop_get_fabric_sense_len(void)
936{
937 return 0;
938}
939
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700940static char *tcm_loop_dump_proto_id(struct tcm_loop_hba *tl_hba)
941{
942 switch (tl_hba->tl_proto_id) {
943 case SCSI_PROTOCOL_SAS:
944 return "SAS";
945 case SCSI_PROTOCOL_FCP:
946 return "FCP";
947 case SCSI_PROTOCOL_ISCSI:
948 return "iSCSI";
949 default:
950 break;
951 }
952
953 return "Unknown";
954}
955
956/* Start items for tcm_loop_port_cit */
957
958static int tcm_loop_port_link(
959 struct se_portal_group *se_tpg,
960 struct se_lun *lun)
961{
962 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
963 struct tcm_loop_tpg, tl_se_tpg);
964 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
965
966 atomic_inc(&tl_tpg->tl_tpg_port_count);
967 smp_mb__after_atomic_inc();
968 /*
969 * Add Linux/SCSI struct scsi_device by HCTL
970 */
971 scsi_add_device(tl_hba->sh, 0, tl_tpg->tl_tpgt, lun->unpacked_lun);
972
Andy Grover6708bb22011-06-08 10:36:43 -0700973 pr_debug("TCM_Loop_ConfigFS: Port Link Successful\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700974 return 0;
975}
976
977static void tcm_loop_port_unlink(
978 struct se_portal_group *se_tpg,
979 struct se_lun *se_lun)
980{
981 struct scsi_device *sd;
982 struct tcm_loop_hba *tl_hba;
983 struct tcm_loop_tpg *tl_tpg;
984
985 tl_tpg = container_of(se_tpg, struct tcm_loop_tpg, tl_se_tpg);
986 tl_hba = tl_tpg->tl_hba;
987
988 sd = scsi_device_lookup(tl_hba->sh, 0, tl_tpg->tl_tpgt,
989 se_lun->unpacked_lun);
990 if (!sd) {
Andy Grover6708bb22011-06-08 10:36:43 -0700991 pr_err("Unable to locate struct scsi_device for %d:%d:"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -0700992 "%d\n", 0, tl_tpg->tl_tpgt, se_lun->unpacked_lun);
993 return;
994 }
995 /*
996 * Remove Linux/SCSI struct scsi_device by HCTL
997 */
998 scsi_remove_device(sd);
999 scsi_device_put(sd);
1000
1001 atomic_dec(&tl_tpg->tl_tpg_port_count);
1002 smp_mb__after_atomic_dec();
1003
Andy Grover6708bb22011-06-08 10:36:43 -07001004 pr_debug("TCM_Loop_ConfigFS: Port Unlink Successful\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001005}
1006
1007/* End items for tcm_loop_port_cit */
1008
1009/* Start items for tcm_loop_nexus_cit */
1010
1011static int tcm_loop_make_nexus(
1012 struct tcm_loop_tpg *tl_tpg,
1013 const char *name)
1014{
1015 struct se_portal_group *se_tpg;
1016 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
1017 struct tcm_loop_nexus *tl_nexus;
Dan Carpenter552523d2011-06-15 09:41:33 -07001018 int ret = -ENOMEM;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001019
1020 if (tl_tpg->tl_hba->tl_nexus) {
Andy Grover6708bb22011-06-08 10:36:43 -07001021 pr_debug("tl_tpg->tl_hba->tl_nexus already exists\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001022 return -EEXIST;
1023 }
1024 se_tpg = &tl_tpg->tl_se_tpg;
1025
1026 tl_nexus = kzalloc(sizeof(struct tcm_loop_nexus), GFP_KERNEL);
1027 if (!tl_nexus) {
Andy Grover6708bb22011-06-08 10:36:43 -07001028 pr_err("Unable to allocate struct tcm_loop_nexus\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001029 return -ENOMEM;
1030 }
1031 /*
1032 * Initialize the struct se_session pointer
1033 */
1034 tl_nexus->se_sess = transport_init_session();
Dan Carpenter552523d2011-06-15 09:41:33 -07001035 if (IS_ERR(tl_nexus->se_sess)) {
1036 ret = PTR_ERR(tl_nexus->se_sess);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001037 goto out;
Dan Carpenter552523d2011-06-15 09:41:33 -07001038 }
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001039 /*
1040 * Since we are running in 'demo mode' this call with generate a
1041 * struct se_node_acl for the tcm_loop struct se_portal_group with the SCSI
1042 * Initiator port name of the passed configfs group 'name'.
1043 */
1044 tl_nexus->se_sess->se_node_acl = core_tpg_check_initiator_node_acl(
1045 se_tpg, (unsigned char *)name);
1046 if (!tl_nexus->se_sess->se_node_acl) {
1047 transport_free_session(tl_nexus->se_sess);
1048 goto out;
1049 }
1050 /*
1051 * Now, register the SAS I_T Nexus as active with the call to
1052 * transport_register_session()
1053 */
1054 __transport_register_session(se_tpg, tl_nexus->se_sess->se_node_acl,
Andy Grover59511462011-07-19 10:26:37 +00001055 tl_nexus->se_sess, tl_nexus);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001056 tl_tpg->tl_hba->tl_nexus = tl_nexus;
Andy Grover6708bb22011-06-08 10:36:43 -07001057 pr_debug("TCM_Loop_ConfigFS: Established I_T Nexus to emulated"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001058 " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba),
1059 name);
1060 return 0;
1061
1062out:
1063 kfree(tl_nexus);
Dan Carpenter552523d2011-06-15 09:41:33 -07001064 return ret;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001065}
1066
1067static int tcm_loop_drop_nexus(
1068 struct tcm_loop_tpg *tpg)
1069{
1070 struct se_session *se_sess;
1071 struct tcm_loop_nexus *tl_nexus;
1072 struct tcm_loop_hba *tl_hba = tpg->tl_hba;
1073
1074 tl_nexus = tpg->tl_hba->tl_nexus;
1075 if (!tl_nexus)
1076 return -ENODEV;
1077
1078 se_sess = tl_nexus->se_sess;
1079 if (!se_sess)
1080 return -ENODEV;
1081
1082 if (atomic_read(&tpg->tl_tpg_port_count)) {
Andy Grover6708bb22011-06-08 10:36:43 -07001083 pr_err("Unable to remove TCM_Loop I_T Nexus with"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001084 " active TPG port count: %d\n",
1085 atomic_read(&tpg->tl_tpg_port_count));
1086 return -EPERM;
1087 }
1088
Andy Grover6708bb22011-06-08 10:36:43 -07001089 pr_debug("TCM_Loop_ConfigFS: Removing I_T Nexus to emulated"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001090 " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba),
1091 tl_nexus->se_sess->se_node_acl->initiatorname);
1092 /*
1093 * Release the SCSI I_T Nexus to the emulated SAS Target Port
1094 */
1095 transport_deregister_session(tl_nexus->se_sess);
1096 tpg->tl_hba->tl_nexus = NULL;
1097 kfree(tl_nexus);
1098 return 0;
1099}
1100
1101/* End items for tcm_loop_nexus_cit */
1102
1103static ssize_t tcm_loop_tpg_show_nexus(
1104 struct se_portal_group *se_tpg,
1105 char *page)
1106{
1107 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
1108 struct tcm_loop_tpg, tl_se_tpg);
1109 struct tcm_loop_nexus *tl_nexus;
1110 ssize_t ret;
1111
1112 tl_nexus = tl_tpg->tl_hba->tl_nexus;
1113 if (!tl_nexus)
1114 return -ENODEV;
1115
1116 ret = snprintf(page, PAGE_SIZE, "%s\n",
1117 tl_nexus->se_sess->se_node_acl->initiatorname);
1118
1119 return ret;
1120}
1121
1122static ssize_t tcm_loop_tpg_store_nexus(
1123 struct se_portal_group *se_tpg,
1124 const char *page,
1125 size_t count)
1126{
1127 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
1128 struct tcm_loop_tpg, tl_se_tpg);
1129 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
1130 unsigned char i_port[TL_WWN_ADDR_LEN], *ptr, *port_ptr;
1131 int ret;
1132 /*
1133 * Shutdown the active I_T nexus if 'NULL' is passed..
1134 */
1135 if (!strncmp(page, "NULL", 4)) {
1136 ret = tcm_loop_drop_nexus(tl_tpg);
1137 return (!ret) ? count : ret;
1138 }
1139 /*
1140 * Otherwise make sure the passed virtual Initiator port WWN matches
1141 * the fabric protocol_id set in tcm_loop_make_scsi_hba(), and call
1142 * tcm_loop_make_nexus()
1143 */
Dan Carpenter60d645a2011-06-15 10:03:05 -07001144 if (strlen(page) >= TL_WWN_ADDR_LEN) {
Andy Grover6708bb22011-06-08 10:36:43 -07001145 pr_err("Emulated NAA Sas Address: %s, exceeds"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001146 " max: %d\n", page, TL_WWN_ADDR_LEN);
1147 return -EINVAL;
1148 }
1149 snprintf(&i_port[0], TL_WWN_ADDR_LEN, "%s", page);
1150
1151 ptr = strstr(i_port, "naa.");
1152 if (ptr) {
1153 if (tl_hba->tl_proto_id != SCSI_PROTOCOL_SAS) {
Andy Grover6708bb22011-06-08 10:36:43 -07001154 pr_err("Passed SAS Initiator Port %s does not"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001155 " match target port protoid: %s\n", i_port,
1156 tcm_loop_dump_proto_id(tl_hba));
1157 return -EINVAL;
1158 }
1159 port_ptr = &i_port[0];
1160 goto check_newline;
1161 }
1162 ptr = strstr(i_port, "fc.");
1163 if (ptr) {
1164 if (tl_hba->tl_proto_id != SCSI_PROTOCOL_FCP) {
Andy Grover6708bb22011-06-08 10:36:43 -07001165 pr_err("Passed FCP Initiator Port %s does not"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001166 " match target port protoid: %s\n", i_port,
1167 tcm_loop_dump_proto_id(tl_hba));
1168 return -EINVAL;
1169 }
1170 port_ptr = &i_port[3]; /* Skip over "fc." */
1171 goto check_newline;
1172 }
1173 ptr = strstr(i_port, "iqn.");
1174 if (ptr) {
1175 if (tl_hba->tl_proto_id != SCSI_PROTOCOL_ISCSI) {
Andy Grover6708bb22011-06-08 10:36:43 -07001176 pr_err("Passed iSCSI Initiator Port %s does not"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001177 " match target port protoid: %s\n", i_port,
1178 tcm_loop_dump_proto_id(tl_hba));
1179 return -EINVAL;
1180 }
1181 port_ptr = &i_port[0];
1182 goto check_newline;
1183 }
Andy Grover6708bb22011-06-08 10:36:43 -07001184 pr_err("Unable to locate prefix for emulated Initiator Port:"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001185 " %s\n", i_port);
1186 return -EINVAL;
1187 /*
1188 * Clear any trailing newline for the NAA WWN
1189 */
1190check_newline:
1191 if (i_port[strlen(i_port)-1] == '\n')
1192 i_port[strlen(i_port)-1] = '\0';
1193
1194 ret = tcm_loop_make_nexus(tl_tpg, port_ptr);
1195 if (ret < 0)
1196 return ret;
1197
1198 return count;
1199}
1200
1201TF_TPG_BASE_ATTR(tcm_loop, nexus, S_IRUGO | S_IWUSR);
1202
1203static struct configfs_attribute *tcm_loop_tpg_attrs[] = {
1204 &tcm_loop_tpg_nexus.attr,
1205 NULL,
1206};
1207
1208/* Start items for tcm_loop_naa_cit */
1209
1210struct se_portal_group *tcm_loop_make_naa_tpg(
1211 struct se_wwn *wwn,
1212 struct config_group *group,
1213 const char *name)
1214{
1215 struct tcm_loop_hba *tl_hba = container_of(wwn,
1216 struct tcm_loop_hba, tl_hba_wwn);
1217 struct tcm_loop_tpg *tl_tpg;
1218 char *tpgt_str, *end_ptr;
1219 int ret;
1220 unsigned short int tpgt;
1221
1222 tpgt_str = strstr(name, "tpgt_");
1223 if (!tpgt_str) {
Andy Grover6708bb22011-06-08 10:36:43 -07001224 pr_err("Unable to locate \"tpgt_#\" directory"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001225 " group\n");
1226 return ERR_PTR(-EINVAL);
1227 }
1228 tpgt_str += 5; /* Skip ahead of "tpgt_" */
1229 tpgt = (unsigned short int) simple_strtoul(tpgt_str, &end_ptr, 0);
1230
Dan Carpenter12f09cc2011-04-02 14:32:47 -07001231 if (tpgt >= TL_TPGS_PER_HBA) {
Andy Grover6708bb22011-06-08 10:36:43 -07001232 pr_err("Passed tpgt: %hu exceeds TL_TPGS_PER_HBA:"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001233 " %u\n", tpgt, TL_TPGS_PER_HBA);
1234 return ERR_PTR(-EINVAL);
1235 }
1236 tl_tpg = &tl_hba->tl_hba_tpgs[tpgt];
1237 tl_tpg->tl_hba = tl_hba;
1238 tl_tpg->tl_tpgt = tpgt;
1239 /*
1240 * Register the tl_tpg as a emulated SAS TCM Target Endpoint
1241 */
1242 ret = core_tpg_register(&tcm_loop_fabric_configfs->tf_ops,
Andy Grover59511462011-07-19 10:26:37 +00001243 wwn, &tl_tpg->tl_se_tpg, tl_tpg,
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001244 TRANSPORT_TPG_TYPE_NORMAL);
1245 if (ret < 0)
1246 return ERR_PTR(-ENOMEM);
1247
Andy Grover6708bb22011-06-08 10:36:43 -07001248 pr_debug("TCM_Loop_ConfigFS: Allocated 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 return &tl_tpg->tl_se_tpg;
1253}
1254
1255void tcm_loop_drop_naa_tpg(
1256 struct se_portal_group *se_tpg)
1257{
1258 struct se_wwn *wwn = se_tpg->se_tpg_wwn;
1259 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
1260 struct tcm_loop_tpg, tl_se_tpg);
1261 struct tcm_loop_hba *tl_hba;
1262 unsigned short tpgt;
1263
1264 tl_hba = tl_tpg->tl_hba;
1265 tpgt = tl_tpg->tl_tpgt;
1266 /*
1267 * Release the I_T Nexus for the Virtual SAS link if present
1268 */
1269 tcm_loop_drop_nexus(tl_tpg);
1270 /*
1271 * Deregister the tl_tpg as a emulated SAS TCM Target Endpoint
1272 */
1273 core_tpg_deregister(se_tpg);
1274
Nicholas Bellinger0a020432011-10-10 19:44:05 -07001275 tl_tpg->tl_hba = NULL;
1276 tl_tpg->tl_tpgt = 0;
1277
Andy Grover6708bb22011-06-08 10:36:43 -07001278 pr_debug("TCM_Loop_ConfigFS: Deallocated Emulated %s"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001279 " Target Port %s,t,0x%04x\n", tcm_loop_dump_proto_id(tl_hba),
1280 config_item_name(&wwn->wwn_group.cg_item), tpgt);
1281}
1282
1283/* End items for tcm_loop_naa_cit */
1284
1285/* Start items for tcm_loop_cit */
1286
1287struct se_wwn *tcm_loop_make_scsi_hba(
1288 struct target_fabric_configfs *tf,
1289 struct config_group *group,
1290 const char *name)
1291{
1292 struct tcm_loop_hba *tl_hba;
1293 struct Scsi_Host *sh;
1294 char *ptr;
1295 int ret, off = 0;
1296
1297 tl_hba = kzalloc(sizeof(struct tcm_loop_hba), GFP_KERNEL);
1298 if (!tl_hba) {
Andy Grover6708bb22011-06-08 10:36:43 -07001299 pr_err("Unable to allocate struct tcm_loop_hba\n");
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001300 return ERR_PTR(-ENOMEM);
1301 }
1302 /*
1303 * Determine the emulated Protocol Identifier and Target Port Name
1304 * based on the incoming configfs directory name.
1305 */
1306 ptr = strstr(name, "naa.");
1307 if (ptr) {
1308 tl_hba->tl_proto_id = SCSI_PROTOCOL_SAS;
1309 goto check_len;
1310 }
1311 ptr = strstr(name, "fc.");
1312 if (ptr) {
1313 tl_hba->tl_proto_id = SCSI_PROTOCOL_FCP;
1314 off = 3; /* Skip over "fc." */
1315 goto check_len;
1316 }
1317 ptr = strstr(name, "iqn.");
Jesper Juhla57b5d32011-06-28 00:30:17 +02001318 if (!ptr) {
Andy Grover6708bb22011-06-08 10:36:43 -07001319 pr_err("Unable to locate prefix for emulated Target "
Jesper Juhla57b5d32011-06-28 00:30:17 +02001320 "Port: %s\n", name);
1321 ret = -EINVAL;
1322 goto out;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001323 }
Jesper Juhla57b5d32011-06-28 00:30:17 +02001324 tl_hba->tl_proto_id = SCSI_PROTOCOL_ISCSI;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001325
1326check_len:
Dan Carpenter60d645a2011-06-15 10:03:05 -07001327 if (strlen(name) >= TL_WWN_ADDR_LEN) {
Andy Grover6708bb22011-06-08 10:36:43 -07001328 pr_err("Emulated NAA %s Address: %s, exceeds"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001329 " max: %d\n", name, tcm_loop_dump_proto_id(tl_hba),
1330 TL_WWN_ADDR_LEN);
Jesper Juhla57b5d32011-06-28 00:30:17 +02001331 ret = -EINVAL;
1332 goto out;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001333 }
1334 snprintf(&tl_hba->tl_wwn_address[0], TL_WWN_ADDR_LEN, "%s", &name[off]);
1335
1336 /*
1337 * Call device_register(tl_hba->dev) to register the emulated
1338 * Linux/SCSI LLD of type struct Scsi_Host at tl_hba->sh after
1339 * device_register() callbacks in tcm_loop_driver_probe()
1340 */
1341 ret = tcm_loop_setup_hba_bus(tl_hba, tcm_loop_hba_no_cnt);
1342 if (ret)
1343 goto out;
1344
1345 sh = tl_hba->sh;
1346 tcm_loop_hba_no_cnt++;
Andy Grover6708bb22011-06-08 10:36:43 -07001347 pr_debug("TCM_Loop_ConfigFS: Allocated emulated Target"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001348 " %s Address: %s at Linux/SCSI Host ID: %d\n",
1349 tcm_loop_dump_proto_id(tl_hba), name, sh->host_no);
1350
1351 return &tl_hba->tl_hba_wwn;
1352out:
1353 kfree(tl_hba);
1354 return ERR_PTR(ret);
1355}
1356
1357void tcm_loop_drop_scsi_hba(
1358 struct se_wwn *wwn)
1359{
1360 struct tcm_loop_hba *tl_hba = container_of(wwn,
1361 struct tcm_loop_hba, tl_hba_wwn);
1362 int host_no = tl_hba->sh->host_no;
1363 /*
1364 * Call device_unregister() on the original tl_hba->dev.
1365 * tcm_loop_fabric_scsi.c:tcm_loop_release_adapter() will
1366 * release *tl_hba;
1367 */
1368 device_unregister(&tl_hba->dev);
1369
Andy Grover6708bb22011-06-08 10:36:43 -07001370 pr_debug("TCM_Loop_ConfigFS: Deallocated emulated Target"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001371 " SAS Address: %s at Linux/SCSI Host ID: %d\n",
1372 config_item_name(&wwn->wwn_group.cg_item), host_no);
1373}
1374
1375/* Start items for tcm_loop_cit */
1376static ssize_t tcm_loop_wwn_show_attr_version(
1377 struct target_fabric_configfs *tf,
1378 char *page)
1379{
1380 return sprintf(page, "TCM Loopback Fabric module %s\n", TCM_LOOP_VERSION);
1381}
1382
1383TF_WWN_ATTR_RO(tcm_loop, version);
1384
1385static struct configfs_attribute *tcm_loop_wwn_attrs[] = {
1386 &tcm_loop_wwn_version.attr,
1387 NULL,
1388};
1389
1390/* End items for tcm_loop_cit */
1391
1392static int tcm_loop_register_configfs(void)
1393{
1394 struct target_fabric_configfs *fabric;
1395 struct config_group *tf_cg;
1396 int ret;
1397 /*
1398 * Set the TCM Loop HBA counter to zero
1399 */
1400 tcm_loop_hba_no_cnt = 0;
1401 /*
1402 * Register the top level struct config_item_type with TCM core
1403 */
1404 fabric = target_fabric_configfs_init(THIS_MODULE, "loopback");
Andy Grovere3d6f902011-07-19 08:55:10 +00001405 if (IS_ERR(fabric)) {
Andy Grover6708bb22011-06-08 10:36:43 -07001406 pr_err("tcm_loop_register_configfs() failed!\n");
Andy Grovere3d6f902011-07-19 08:55:10 +00001407 return PTR_ERR(fabric);
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001408 }
1409 /*
1410 * Setup the fabric API of function pointers used by target_core_mod
1411 */
1412 fabric->tf_ops.get_fabric_name = &tcm_loop_get_fabric_name;
1413 fabric->tf_ops.get_fabric_proto_ident = &tcm_loop_get_fabric_proto_ident;
1414 fabric->tf_ops.tpg_get_wwn = &tcm_loop_get_endpoint_wwn;
1415 fabric->tf_ops.tpg_get_tag = &tcm_loop_get_tag;
1416 fabric->tf_ops.tpg_get_default_depth = &tcm_loop_get_default_depth;
1417 fabric->tf_ops.tpg_get_pr_transport_id = &tcm_loop_get_pr_transport_id;
1418 fabric->tf_ops.tpg_get_pr_transport_id_len =
1419 &tcm_loop_get_pr_transport_id_len;
1420 fabric->tf_ops.tpg_parse_pr_out_transport_id =
1421 &tcm_loop_parse_pr_out_transport_id;
1422 fabric->tf_ops.tpg_check_demo_mode = &tcm_loop_check_demo_mode;
1423 fabric->tf_ops.tpg_check_demo_mode_cache =
1424 &tcm_loop_check_demo_mode_cache;
1425 fabric->tf_ops.tpg_check_demo_mode_write_protect =
1426 &tcm_loop_check_demo_mode_write_protect;
1427 fabric->tf_ops.tpg_check_prod_mode_write_protect =
1428 &tcm_loop_check_prod_mode_write_protect;
1429 /*
1430 * The TCM loopback fabric module runs in demo-mode to a local
1431 * virtual SCSI device, so fabric dependent initator ACLs are
1432 * not required.
1433 */
1434 fabric->tf_ops.tpg_alloc_fabric_acl = &tcm_loop_tpg_alloc_fabric_acl;
1435 fabric->tf_ops.tpg_release_fabric_acl =
1436 &tcm_loop_tpg_release_fabric_acl;
1437 fabric->tf_ops.tpg_get_inst_index = &tcm_loop_get_inst_index;
1438 /*
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001439 * Used for setting up remaining TCM resources in process context
1440 */
1441 fabric->tf_ops.new_cmd_map = &tcm_loop_new_cmd_map;
1442 fabric->tf_ops.check_stop_free = &tcm_loop_check_stop_free;
Christoph Hellwig35462972011-05-31 23:56:57 -04001443 fabric->tf_ops.release_cmd = &tcm_loop_release_cmd;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001444 fabric->tf_ops.shutdown_session = &tcm_loop_shutdown_session;
1445 fabric->tf_ops.close_session = &tcm_loop_close_session;
1446 fabric->tf_ops.stop_session = &tcm_loop_stop_session;
1447 fabric->tf_ops.fall_back_to_erl0 = &tcm_loop_fall_back_to_erl0;
1448 fabric->tf_ops.sess_logged_in = &tcm_loop_sess_logged_in;
1449 fabric->tf_ops.sess_get_index = &tcm_loop_sess_get_index;
1450 fabric->tf_ops.sess_get_initiator_sid = NULL;
1451 fabric->tf_ops.write_pending = &tcm_loop_write_pending;
1452 fabric->tf_ops.write_pending_status = &tcm_loop_write_pending_status;
1453 /*
1454 * Not used for TCM loopback
1455 */
1456 fabric->tf_ops.set_default_node_attributes =
1457 &tcm_loop_set_default_node_attributes;
1458 fabric->tf_ops.get_task_tag = &tcm_loop_get_task_tag;
1459 fabric->tf_ops.get_cmd_state = &tcm_loop_get_cmd_state;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001460 fabric->tf_ops.queue_data_in = &tcm_loop_queue_data_in;
1461 fabric->tf_ops.queue_status = &tcm_loop_queue_status;
1462 fabric->tf_ops.queue_tm_rsp = &tcm_loop_queue_tm_rsp;
1463 fabric->tf_ops.set_fabric_sense_len = &tcm_loop_set_fabric_sense_len;
1464 fabric->tf_ops.get_fabric_sense_len = &tcm_loop_get_fabric_sense_len;
1465 fabric->tf_ops.is_state_remove = &tcm_loop_is_state_remove;
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001466
1467 tf_cg = &fabric->tf_group;
1468 /*
1469 * Setup function pointers for generic logic in target_core_fabric_configfs.c
1470 */
1471 fabric->tf_ops.fabric_make_wwn = &tcm_loop_make_scsi_hba;
1472 fabric->tf_ops.fabric_drop_wwn = &tcm_loop_drop_scsi_hba;
1473 fabric->tf_ops.fabric_make_tpg = &tcm_loop_make_naa_tpg;
1474 fabric->tf_ops.fabric_drop_tpg = &tcm_loop_drop_naa_tpg;
1475 /*
1476 * fabric_post_link() and fabric_pre_unlink() are used for
1477 * registration and release of TCM Loop Virtual SCSI LUNs.
1478 */
1479 fabric->tf_ops.fabric_post_link = &tcm_loop_port_link;
1480 fabric->tf_ops.fabric_pre_unlink = &tcm_loop_port_unlink;
1481 fabric->tf_ops.fabric_make_np = NULL;
1482 fabric->tf_ops.fabric_drop_np = NULL;
1483 /*
1484 * Setup default attribute lists for various fabric->tf_cit_tmpl
1485 */
1486 TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = tcm_loop_wwn_attrs;
1487 TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = tcm_loop_tpg_attrs;
1488 TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = NULL;
1489 TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = NULL;
1490 TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = NULL;
1491 /*
1492 * Once fabric->tf_ops has been setup, now register the fabric for
1493 * use within TCM
1494 */
1495 ret = target_fabric_configfs_register(fabric);
1496 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -07001497 pr_err("target_fabric_configfs_register() for"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001498 " TCM_Loop failed!\n");
1499 target_fabric_configfs_free(fabric);
1500 return -1;
1501 }
1502 /*
1503 * Setup our local pointer to *fabric.
1504 */
1505 tcm_loop_fabric_configfs = fabric;
Andy Grover6708bb22011-06-08 10:36:43 -07001506 pr_debug("TCM_LOOP[0] - Set fabric ->"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001507 " tcm_loop_fabric_configfs\n");
1508 return 0;
1509}
1510
1511static void tcm_loop_deregister_configfs(void)
1512{
1513 if (!tcm_loop_fabric_configfs)
1514 return;
1515
1516 target_fabric_configfs_deregister(tcm_loop_fabric_configfs);
1517 tcm_loop_fabric_configfs = NULL;
Andy Grover6708bb22011-06-08 10:36:43 -07001518 pr_debug("TCM_LOOP[0] - Cleared"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001519 " tcm_loop_fabric_configfs\n");
1520}
1521
1522static int __init tcm_loop_fabric_init(void)
1523{
1524 int ret;
1525
1526 tcm_loop_cmd_cache = kmem_cache_create("tcm_loop_cmd_cache",
1527 sizeof(struct tcm_loop_cmd),
1528 __alignof__(struct tcm_loop_cmd),
1529 0, NULL);
1530 if (!tcm_loop_cmd_cache) {
Andy Grover6708bb22011-06-08 10:36:43 -07001531 pr_debug("kmem_cache_create() for"
Nicholas Bellinger3703b2c2011-03-18 15:39:17 -07001532 " tcm_loop_cmd_cache failed\n");
1533 return -ENOMEM;
1534 }
1535
1536 ret = tcm_loop_alloc_core_bus();
1537 if (ret)
1538 return ret;
1539
1540 ret = tcm_loop_register_configfs();
1541 if (ret) {
1542 tcm_loop_release_core_bus();
1543 return ret;
1544 }
1545
1546 return 0;
1547}
1548
1549static void __exit tcm_loop_fabric_exit(void)
1550{
1551 tcm_loop_deregister_configfs();
1552 tcm_loop_release_core_bus();
1553 kmem_cache_destroy(tcm_loop_cmd_cache);
1554}
1555
1556MODULE_DESCRIPTION("TCM loopback virtual Linux/SCSI fabric module");
1557MODULE_AUTHOR("Nicholas A. Bellinger <nab@risingtidesystems.com>");
1558MODULE_LICENSE("GPL");
1559module_init(tcm_loop_fabric_init);
1560module_exit(tcm_loop_fabric_exit);