Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * This file contains the Linux/SCSI LLD virtual SCSI initiator driver |
| 4 | * for emulated SAS initiator ports |
| 5 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 6 | * © Copyright 2011-2013 Datera, Inc. |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 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 Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 34 | |
| 35 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 36 | #include <target/target_core_fabric.h> |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 37 | |
| 38 | #include "tcm_loop.h" |
| 39 | |
| 40 | #define to_tcm_loop_hba(hba) container_of(hba, struct tcm_loop_hba, dev) |
| 41 | |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 42 | static struct workqueue_struct *tcm_loop_workqueue; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 43 | static struct kmem_cache *tcm_loop_cmd_cache; |
| 44 | |
| 45 | static int tcm_loop_hba_no_cnt; |
| 46 | |
Christoph Hellwig | 16786454 | 2012-02-02 17:04:42 -0500 | [diff] [blame] | 47 | static int tcm_loop_queue_status(struct se_cmd *se_cmd); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * Called from struct target_core_fabric_ops->check_stop_free() |
| 51 | */ |
Nicholas Bellinger | 88dd9e2 | 2011-11-02 03:33:16 -0700 | [diff] [blame] | 52 | static int tcm_loop_check_stop_free(struct se_cmd *se_cmd) |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 53 | { |
Bart Van Assche | 4c1f0e6 | 2017-05-23 16:48:42 -0700 | [diff] [blame] | 54 | return transport_generic_free_cmd(se_cmd, 0); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Christoph Hellwig | 3546297 | 2011-05-31 23:56:57 -0400 | [diff] [blame] | 57 | static void tcm_loop_release_cmd(struct se_cmd *se_cmd) |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 58 | { |
| 59 | struct tcm_loop_cmd *tl_cmd = container_of(se_cmd, |
| 60 | struct tcm_loop_cmd, tl_se_cmd); |
| 61 | |
| 62 | kmem_cache_free(tcm_loop_cmd_cache, tl_cmd); |
| 63 | } |
| 64 | |
Al Viro | 8946b07 | 2013-03-31 02:01:55 -0400 | [diff] [blame] | 65 | static int tcm_loop_show_info(struct seq_file *m, struct Scsi_Host *host) |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 66 | { |
Al Viro | 8946b07 | 2013-03-31 02:01:55 -0400 | [diff] [blame] | 67 | seq_printf(m, "tcm_loop_proc_info()\n"); |
| 68 | return 0; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static int tcm_loop_driver_probe(struct device *); |
| 72 | static int tcm_loop_driver_remove(struct device *); |
| 73 | |
| 74 | static int pseudo_lld_bus_match(struct device *dev, |
| 75 | struct device_driver *dev_driver) |
| 76 | { |
| 77 | return 1; |
| 78 | } |
| 79 | |
| 80 | static struct bus_type tcm_loop_lld_bus = { |
| 81 | .name = "tcm_loop_bus", |
| 82 | .match = pseudo_lld_bus_match, |
| 83 | .probe = tcm_loop_driver_probe, |
| 84 | .remove = tcm_loop_driver_remove, |
| 85 | }; |
| 86 | |
| 87 | static struct device_driver tcm_loop_driverfs = { |
| 88 | .name = "tcm_loop", |
| 89 | .bus = &tcm_loop_lld_bus, |
| 90 | }; |
| 91 | /* |
| 92 | * Used with root_device_register() in tcm_loop_alloc_core_bus() below |
| 93 | */ |
Christoph Hellwig | 6e1a27b | 2015-03-26 12:27:32 +0100 | [diff] [blame] | 94 | static struct device *tcm_loop_primary; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 95 | |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 96 | static void tcm_loop_submission_work(struct work_struct *work) |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 97 | { |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 98 | struct tcm_loop_cmd *tl_cmd = |
| 99 | container_of(work, struct tcm_loop_cmd, work); |
| 100 | struct se_cmd *se_cmd = &tl_cmd->tl_se_cmd; |
| 101 | struct scsi_cmnd *sc = tl_cmd->sc; |
| 102 | struct tcm_loop_nexus *tl_nexus; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 103 | struct tcm_loop_hba *tl_hba; |
| 104 | struct tcm_loop_tpg *tl_tpg; |
Christoph Hellwig | 16786454 | 2012-02-02 17:04:42 -0500 | [diff] [blame] | 105 | struct scatterlist *sgl_bidi = NULL; |
Sagi Grimberg | e2a4f55 | 2014-06-11 12:09:59 +0300 | [diff] [blame] | 106 | u32 sgl_bidi_count = 0, transfer_length; |
Nicholas Bellinger | 8f9f44f | 2012-10-01 23:29:49 -0700 | [diff] [blame] | 107 | int rc; |
Christoph Hellwig | f872c9f | 2012-02-02 17:04:40 -0500 | [diff] [blame] | 108 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 109 | tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host); |
| 110 | tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id]; |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 111 | |
Nicholas Bellinger | 0a02043 | 2011-10-10 19:44:05 -0700 | [diff] [blame] | 112 | /* |
| 113 | * Ensure that this tl_tpg reference from the incoming sc->device->id |
| 114 | * has already been configured via tcm_loop_make_naa_tpg(). |
| 115 | */ |
| 116 | if (!tl_tpg->tl_hba) { |
| 117 | set_host_byte(sc, DID_NO_CONNECT); |
Christoph Hellwig | f872c9f | 2012-02-02 17:04:40 -0500 | [diff] [blame] | 118 | goto out_done; |
Nicholas Bellinger | 0a02043 | 2011-10-10 19:44:05 -0700 | [diff] [blame] | 119 | } |
Hannes Reinecke | fb2b284 | 2013-10-16 09:12:53 +0200 | [diff] [blame] | 120 | if (tl_tpg->tl_transport_status == TCM_TRANSPORT_OFFLINE) { |
| 121 | set_host_byte(sc, DID_TRANSPORT_DISRUPTED); |
| 122 | goto out_done; |
| 123 | } |
Hannes Reinecke | 506787a | 2014-11-26 14:58:57 +0100 | [diff] [blame] | 124 | tl_nexus = tl_tpg->tl_nexus; |
Christoph Hellwig | f872c9f | 2012-02-02 17:04:40 -0500 | [diff] [blame] | 125 | if (!tl_nexus) { |
| 126 | scmd_printk(KERN_ERR, sc, "TCM_Loop I_T Nexus" |
| 127 | " does not exist\n"); |
| 128 | set_host_byte(sc, DID_ERROR); |
| 129 | goto out_done; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 130 | } |
Christoph Hellwig | 16786454 | 2012-02-02 17:04:42 -0500 | [diff] [blame] | 131 | if (scsi_bidi_cmnd(sc)) { |
| 132 | struct scsi_data_buffer *sdb = scsi_in(sc); |
| 133 | |
| 134 | sgl_bidi = sdb->table.sgl; |
| 135 | sgl_bidi_count = sdb->table.nents; |
Christoph Hellwig | f872c9f | 2012-02-02 17:04:40 -0500 | [diff] [blame] | 136 | se_cmd->se_cmd_flags |= SCF_BIDI; |
| 137 | |
Christoph Hellwig | 16786454 | 2012-02-02 17:04:42 -0500 | [diff] [blame] | 138 | } |
Sagi Grimberg | b5b8e29 | 2014-02-19 17:50:17 +0200 | [diff] [blame] | 139 | |
Sagi Grimberg | e2a4f55 | 2014-06-11 12:09:59 +0300 | [diff] [blame] | 140 | transfer_length = scsi_transfer_length(sc); |
| 141 | if (!scsi_prot_sg_count(sc) && |
| 142 | scsi_get_prot_op(sc) != SCSI_PROT_NORMAL) { |
Sagi Grimberg | b5b8e29 | 2014-02-19 17:50:17 +0200 | [diff] [blame] | 143 | se_cmd->prot_pto = true; |
Sagi Grimberg | e2a4f55 | 2014-06-11 12:09:59 +0300 | [diff] [blame] | 144 | /* |
| 145 | * loopback transport doesn't support |
| 146 | * WRITE_GENERATE, READ_STRIP protection |
| 147 | * information operations, go ahead unprotected. |
| 148 | */ |
| 149 | transfer_length = scsi_bufflen(sc); |
| 150 | } |
Sagi Grimberg | b5b8e29 | 2014-02-19 17:50:17 +0200 | [diff] [blame] | 151 | |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 152 | se_cmd->tag = tl_cmd->sc_cmd_tag; |
Nicholas Bellinger | 8f9f44f | 2012-10-01 23:29:49 -0700 | [diff] [blame] | 153 | rc = target_submit_cmd_map_sgls(se_cmd, tl_nexus->se_sess, sc->cmnd, |
| 154 | &tl_cmd->tl_sense_buf[0], tl_cmd->sc->device->lun, |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 155 | transfer_length, TCM_SIMPLE_TAG, |
Nicholas Bellinger | 8f9f44f | 2012-10-01 23:29:49 -0700 | [diff] [blame] | 156 | sc->sc_data_direction, 0, |
| 157 | scsi_sglist(sc), scsi_sg_count(sc), |
Nicholas Bellinger | 59dedde | 2013-12-23 20:39:23 +0000 | [diff] [blame] | 158 | sgl_bidi, sgl_bidi_count, |
| 159 | scsi_prot_sglist(sc), scsi_prot_sg_count(sc)); |
Nicholas Bellinger | 8f9f44f | 2012-10-01 23:29:49 -0700 | [diff] [blame] | 160 | if (rc < 0) { |
Christoph Hellwig | f872c9f | 2012-02-02 17:04:40 -0500 | [diff] [blame] | 161 | set_host_byte(sc, DID_NO_CONNECT); |
| 162 | goto out_done; |
| 163 | } |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 164 | return; |
Christoph Hellwig | f872c9f | 2012-02-02 17:04:40 -0500 | [diff] [blame] | 165 | |
| 166 | out_done: |
Nicholas Bellinger | b43f188 | 2014-06-17 22:23:03 +0000 | [diff] [blame] | 167 | kmem_cache_free(tcm_loop_cmd_cache, tl_cmd); |
Christoph Hellwig | f872c9f | 2012-02-02 17:04:40 -0500 | [diff] [blame] | 168 | sc->scsi_done(sc); |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 169 | return; |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | * ->queuecommand can be and usually is called from interrupt context, so |
| 174 | * defer the actual submission to a workqueue. |
| 175 | */ |
| 176 | static int tcm_loop_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *sc) |
| 177 | { |
| 178 | struct tcm_loop_cmd *tl_cmd; |
| 179 | |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 180 | pr_debug("tcm_loop_queuecommand() %d:%d:%d:%llu got CDB: 0x%02x" |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 181 | " scsi_buf_len: %u\n", sc->device->host->host_no, |
| 182 | sc->device->id, sc->device->channel, sc->device->lun, |
| 183 | sc->cmnd[0], scsi_bufflen(sc)); |
| 184 | |
| 185 | tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_ATOMIC); |
| 186 | if (!tl_cmd) { |
| 187 | pr_err("Unable to allocate struct tcm_loop_cmd\n"); |
| 188 | set_host_byte(sc, DID_ERROR); |
| 189 | sc->scsi_done(sc); |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | tl_cmd->sc = sc; |
Hannes Reinecke | 6375f89 | 2014-10-02 09:30:55 +0200 | [diff] [blame] | 194 | tl_cmd->sc_cmd_tag = sc->request->tag; |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 195 | INIT_WORK(&tl_cmd->work, tcm_loop_submission_work); |
| 196 | queue_work(tcm_loop_workqueue, &tl_cmd->work); |
Christoph Hellwig | f872c9f | 2012-02-02 17:04:40 -0500 | [diff] [blame] | 197 | return 0; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* |
| 201 | * Called from SCSI EH process context to issue a LUN_RESET TMR |
| 202 | * to struct scsi_device |
| 203 | */ |
Hannes Reinecke | a314d70 | 2013-10-16 09:12:54 +0200 | [diff] [blame] | 204 | static int tcm_loop_issue_tmr(struct tcm_loop_tpg *tl_tpg, |
Hannes Reinecke | f2d3068 | 2015-06-10 08:41:22 +0200 | [diff] [blame] | 205 | u64 lun, int task, enum tcm_tmreq_table tmr) |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 206 | { |
| 207 | struct se_cmd *se_cmd = NULL; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 208 | struct se_session *se_sess; |
Hannes Reinecke | 506787a | 2014-11-26 14:58:57 +0100 | [diff] [blame] | 209 | struct tcm_loop_nexus *tl_nexus; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 210 | struct tcm_loop_cmd *tl_cmd = NULL; |
Hannes Reinecke | a314d70 | 2013-10-16 09:12:54 +0200 | [diff] [blame] | 211 | int ret = TMR_FUNCTION_FAILED, rc; |
| 212 | |
Hannes Reinecke | 506787a | 2014-11-26 14:58:57 +0100 | [diff] [blame] | 213 | /* |
| 214 | * Locate the tl_nexus and se_sess pointers |
| 215 | */ |
| 216 | tl_nexus = tl_tpg->tl_nexus; |
| 217 | if (!tl_nexus) { |
| 218 | pr_err("Unable to perform device reset without" |
| 219 | " active I_T Nexus\n"); |
| 220 | return ret; |
| 221 | } |
| 222 | |
Hannes Reinecke | a314d70 | 2013-10-16 09:12:54 +0200 | [diff] [blame] | 223 | tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_KERNEL); |
| 224 | if (!tl_cmd) { |
| 225 | pr_err("Unable to allocate memory for tl_cmd\n"); |
| 226 | return ret; |
| 227 | } |
| 228 | |
Bart Van Assche | d17203c | 2017-05-23 16:48:40 -0700 | [diff] [blame] | 229 | init_completion(&tl_cmd->tmr_done); |
Hannes Reinecke | a314d70 | 2013-10-16 09:12:54 +0200 | [diff] [blame] | 230 | |
| 231 | se_cmd = &tl_cmd->tl_se_cmd; |
Hannes Reinecke | 506787a | 2014-11-26 14:58:57 +0100 | [diff] [blame] | 232 | se_sess = tl_tpg->tl_nexus->se_sess; |
Hannes Reinecke | a314d70 | 2013-10-16 09:12:54 +0200 | [diff] [blame] | 233 | |
Bart Van Assche | 75f141a | 2017-05-23 16:48:41 -0700 | [diff] [blame] | 234 | rc = target_submit_tmr(se_cmd, se_sess, tl_cmd->tl_sense_buf, lun, |
Bart Van Assche | 4c1f0e6 | 2017-05-23 16:48:42 -0700 | [diff] [blame] | 235 | NULL, tmr, GFP_KERNEL, task, |
| 236 | TARGET_SCF_ACK_KREF); |
Hannes Reinecke | a314d70 | 2013-10-16 09:12:54 +0200 | [diff] [blame] | 237 | if (rc < 0) |
| 238 | goto release; |
Bart Van Assche | d17203c | 2017-05-23 16:48:40 -0700 | [diff] [blame] | 239 | wait_for_completion(&tl_cmd->tmr_done); |
Hannes Reinecke | a314d70 | 2013-10-16 09:12:54 +0200 | [diff] [blame] | 240 | ret = se_cmd->se_tmr_req->response; |
Bart Van Assche | 4c1f0e6 | 2017-05-23 16:48:42 -0700 | [diff] [blame] | 241 | target_put_sess_cmd(se_cmd); |
| 242 | |
| 243 | out: |
| 244 | return ret; |
Bart Van Assche | 75f141a | 2017-05-23 16:48:41 -0700 | [diff] [blame] | 245 | |
Hannes Reinecke | a314d70 | 2013-10-16 09:12:54 +0200 | [diff] [blame] | 246 | release: |
| 247 | if (se_cmd) |
Bart Van Assche | 4c1f0e6 | 2017-05-23 16:48:42 -0700 | [diff] [blame] | 248 | transport_generic_free_cmd(se_cmd, 0); |
Hannes Reinecke | a314d70 | 2013-10-16 09:12:54 +0200 | [diff] [blame] | 249 | else |
| 250 | kmem_cache_free(tcm_loop_cmd_cache, tl_cmd); |
Bart Van Assche | 4c1f0e6 | 2017-05-23 16:48:42 -0700 | [diff] [blame] | 251 | goto out; |
Hannes Reinecke | a314d70 | 2013-10-16 09:12:54 +0200 | [diff] [blame] | 252 | } |
| 253 | |
Hannes Reinecke | 969871c | 2013-10-16 09:12:55 +0200 | [diff] [blame] | 254 | static int tcm_loop_abort_task(struct scsi_cmnd *sc) |
| 255 | { |
| 256 | struct tcm_loop_hba *tl_hba; |
Hannes Reinecke | 969871c | 2013-10-16 09:12:55 +0200 | [diff] [blame] | 257 | struct tcm_loop_tpg *tl_tpg; |
| 258 | int ret = FAILED; |
| 259 | |
| 260 | /* |
| 261 | * Locate the tcm_loop_hba_t pointer |
| 262 | */ |
| 263 | tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host); |
Hannes Reinecke | 969871c | 2013-10-16 09:12:55 +0200 | [diff] [blame] | 264 | tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id]; |
Hannes Reinecke | 506787a | 2014-11-26 14:58:57 +0100 | [diff] [blame] | 265 | ret = tcm_loop_issue_tmr(tl_tpg, sc->device->lun, |
Hannes Reinecke | 6375f89 | 2014-10-02 09:30:55 +0200 | [diff] [blame] | 266 | sc->request->tag, TMR_ABORT_TASK); |
Hannes Reinecke | 969871c | 2013-10-16 09:12:55 +0200 | [diff] [blame] | 267 | return (ret == TMR_FUNCTION_COMPLETE) ? SUCCESS : FAILED; |
| 268 | } |
| 269 | |
Hannes Reinecke | a314d70 | 2013-10-16 09:12:54 +0200 | [diff] [blame] | 270 | /* |
| 271 | * Called from SCSI EH process context to issue a LUN_RESET TMR |
| 272 | * to struct scsi_device |
| 273 | */ |
| 274 | static int tcm_loop_device_reset(struct scsi_cmnd *sc) |
| 275 | { |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 276 | struct tcm_loop_hba *tl_hba; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 277 | struct tcm_loop_tpg *tl_tpg; |
Hannes Reinecke | a314d70 | 2013-10-16 09:12:54 +0200 | [diff] [blame] | 278 | int ret = FAILED; |
| 279 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 280 | /* |
| 281 | * Locate the tcm_loop_hba_t pointer |
| 282 | */ |
| 283 | tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 284 | tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id]; |
Hannes Reinecke | 506787a | 2014-11-26 14:58:57 +0100 | [diff] [blame] | 285 | |
| 286 | ret = tcm_loop_issue_tmr(tl_tpg, sc->device->lun, |
Hannes Reinecke | 969871c | 2013-10-16 09:12:55 +0200 | [diff] [blame] | 287 | 0, TMR_LUN_RESET); |
Hannes Reinecke | a314d70 | 2013-10-16 09:12:54 +0200 | [diff] [blame] | 288 | return (ret == TMR_FUNCTION_COMPLETE) ? SUCCESS : FAILED; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Hannes Reinecke | 8f4a1fb | 2013-10-16 09:12:56 +0200 | [diff] [blame] | 291 | static int tcm_loop_target_reset(struct scsi_cmnd *sc) |
| 292 | { |
| 293 | struct tcm_loop_hba *tl_hba; |
| 294 | struct tcm_loop_tpg *tl_tpg; |
| 295 | |
| 296 | /* |
| 297 | * Locate the tcm_loop_hba_t pointer |
| 298 | */ |
| 299 | tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host); |
| 300 | if (!tl_hba) { |
| 301 | pr_err("Unable to perform device reset without" |
| 302 | " active I_T Nexus\n"); |
| 303 | return FAILED; |
| 304 | } |
| 305 | /* |
| 306 | * Locate the tl_tpg pointer from TargetID in sc->device->id |
| 307 | */ |
| 308 | tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id]; |
| 309 | if (tl_tpg) { |
| 310 | tl_tpg->tl_transport_status = TCM_TRANSPORT_ONLINE; |
| 311 | return SUCCESS; |
| 312 | } |
| 313 | return FAILED; |
| 314 | } |
| 315 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 316 | static int tcm_loop_slave_alloc(struct scsi_device *sd) |
| 317 | { |
| 318 | set_bit(QUEUE_FLAG_BIDI, &sd->request_queue->queue_flags); |
| 319 | return 0; |
| 320 | } |
| 321 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 322 | static struct scsi_host_template tcm_loop_driver_template = { |
Al Viro | 8946b07 | 2013-03-31 02:01:55 -0400 | [diff] [blame] | 323 | .show_info = tcm_loop_show_info, |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 324 | .proc_name = "tcm_loopback", |
| 325 | .name = "TCM_Loopback", |
| 326 | .queuecommand = tcm_loop_queuecommand, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 327 | .change_queue_depth = scsi_change_queue_depth, |
Hannes Reinecke | 969871c | 2013-10-16 09:12:55 +0200 | [diff] [blame] | 328 | .eh_abort_handler = tcm_loop_abort_task, |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 329 | .eh_device_reset_handler = tcm_loop_device_reset, |
Hannes Reinecke | 8f4a1fb | 2013-10-16 09:12:56 +0200 | [diff] [blame] | 330 | .eh_target_reset_handler = tcm_loop_target_reset, |
Christoph Hellwig | 2e88efd | 2011-11-29 03:20:41 -0500 | [diff] [blame] | 331 | .can_queue = 1024, |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 332 | .this_id = -1, |
Christoph Hellwig | 2e88efd | 2011-11-29 03:20:41 -0500 | [diff] [blame] | 333 | .sg_tablesize = 256, |
| 334 | .cmd_per_lun = 1024, |
| 335 | .max_sectors = 0xFFFF, |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 336 | .use_clustering = DISABLE_CLUSTERING, |
| 337 | .slave_alloc = tcm_loop_slave_alloc, |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 338 | .module = THIS_MODULE, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 339 | .track_queue_depth = 1, |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 340 | }; |
| 341 | |
| 342 | static int tcm_loop_driver_probe(struct device *dev) |
| 343 | { |
| 344 | struct tcm_loop_hba *tl_hba; |
| 345 | struct Scsi_Host *sh; |
Nicholas Bellinger | 59dedde | 2013-12-23 20:39:23 +0000 | [diff] [blame] | 346 | int error, host_prot; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 347 | |
| 348 | tl_hba = to_tcm_loop_hba(dev); |
| 349 | |
| 350 | sh = scsi_host_alloc(&tcm_loop_driver_template, |
| 351 | sizeof(struct tcm_loop_hba)); |
| 352 | if (!sh) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 353 | pr_err("Unable to allocate struct scsi_host\n"); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 354 | return -ENODEV; |
| 355 | } |
| 356 | tl_hba->sh = sh; |
| 357 | |
| 358 | /* |
| 359 | * Assign the struct tcm_loop_hba pointer to struct Scsi_Host->hostdata |
| 360 | */ |
| 361 | *((struct tcm_loop_hba **)sh->hostdata) = tl_hba; |
| 362 | /* |
| 363 | * Setup single ID, Channel and LUN for now.. |
| 364 | */ |
| 365 | sh->max_id = 2; |
| 366 | sh->max_lun = 0; |
| 367 | sh->max_channel = 0; |
Ilias Tsitsimpis | 9736f4a | 2015-04-23 21:30:06 +0300 | [diff] [blame] | 368 | sh->max_cmd_len = SCSI_MAX_VARLEN_CDB_SIZE; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 369 | |
Nicholas Bellinger | 59dedde | 2013-12-23 20:39:23 +0000 | [diff] [blame] | 370 | host_prot = SHOST_DIF_TYPE1_PROTECTION | SHOST_DIF_TYPE2_PROTECTION | |
| 371 | SHOST_DIF_TYPE3_PROTECTION | SHOST_DIX_TYPE1_PROTECTION | |
| 372 | SHOST_DIX_TYPE2_PROTECTION | SHOST_DIX_TYPE3_PROTECTION; |
| 373 | |
| 374 | scsi_host_set_prot(sh, host_prot); |
| 375 | scsi_host_set_guard(sh, SHOST_DIX_GUARD_CRC); |
| 376 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 377 | error = scsi_add_host(sh, &tl_hba->dev); |
| 378 | if (error) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 379 | pr_err("%s: scsi_add_host failed\n", __func__); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 380 | scsi_host_put(sh); |
| 381 | return -ENODEV; |
| 382 | } |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static int tcm_loop_driver_remove(struct device *dev) |
| 387 | { |
| 388 | struct tcm_loop_hba *tl_hba; |
| 389 | struct Scsi_Host *sh; |
| 390 | |
| 391 | tl_hba = to_tcm_loop_hba(dev); |
| 392 | sh = tl_hba->sh; |
| 393 | |
| 394 | scsi_remove_host(sh); |
| 395 | scsi_host_put(sh); |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | static void tcm_loop_release_adapter(struct device *dev) |
| 400 | { |
| 401 | struct tcm_loop_hba *tl_hba = to_tcm_loop_hba(dev); |
| 402 | |
| 403 | kfree(tl_hba); |
| 404 | } |
| 405 | |
| 406 | /* |
| 407 | * Called from tcm_loop_make_scsi_hba() in tcm_loop_configfs.c |
| 408 | */ |
| 409 | static int tcm_loop_setup_hba_bus(struct tcm_loop_hba *tl_hba, int tcm_loop_host_id) |
| 410 | { |
| 411 | int ret; |
| 412 | |
| 413 | tl_hba->dev.bus = &tcm_loop_lld_bus; |
| 414 | tl_hba->dev.parent = tcm_loop_primary; |
| 415 | tl_hba->dev.release = &tcm_loop_release_adapter; |
| 416 | dev_set_name(&tl_hba->dev, "tcm_loop_adapter_%d", tcm_loop_host_id); |
| 417 | |
| 418 | ret = device_register(&tl_hba->dev); |
| 419 | if (ret) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 420 | pr_err("device_register() failed for" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 421 | " tl_hba->dev: %d\n", ret); |
| 422 | return -ENODEV; |
| 423 | } |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | /* |
| 429 | * Called from tcm_loop_fabric_init() in tcl_loop_fabric.c to load the emulated |
| 430 | * tcm_loop SCSI bus. |
| 431 | */ |
| 432 | static int tcm_loop_alloc_core_bus(void) |
| 433 | { |
| 434 | int ret; |
| 435 | |
| 436 | tcm_loop_primary = root_device_register("tcm_loop_0"); |
| 437 | if (IS_ERR(tcm_loop_primary)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 438 | pr_err("Unable to allocate tcm_loop_primary\n"); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 439 | return PTR_ERR(tcm_loop_primary); |
| 440 | } |
| 441 | |
| 442 | ret = bus_register(&tcm_loop_lld_bus); |
| 443 | if (ret) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 444 | pr_err("bus_register() failed for tcm_loop_lld_bus\n"); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 445 | goto dev_unreg; |
| 446 | } |
| 447 | |
| 448 | ret = driver_register(&tcm_loop_driverfs); |
| 449 | if (ret) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 450 | pr_err("driver_register() failed for" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 451 | "tcm_loop_driverfs\n"); |
| 452 | goto bus_unreg; |
| 453 | } |
| 454 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 455 | pr_debug("Initialized TCM Loop Core Bus\n"); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 456 | return ret; |
| 457 | |
| 458 | bus_unreg: |
| 459 | bus_unregister(&tcm_loop_lld_bus); |
| 460 | dev_unreg: |
| 461 | root_device_unregister(tcm_loop_primary); |
| 462 | return ret; |
| 463 | } |
| 464 | |
| 465 | static void tcm_loop_release_core_bus(void) |
| 466 | { |
| 467 | driver_unregister(&tcm_loop_driverfs); |
| 468 | bus_unregister(&tcm_loop_lld_bus); |
| 469 | root_device_unregister(tcm_loop_primary); |
| 470 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 471 | pr_debug("Releasing TCM Loop Core BUS\n"); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | static char *tcm_loop_get_fabric_name(void) |
| 475 | { |
| 476 | return "loopback"; |
| 477 | } |
| 478 | |
Christoph Hellwig | 1667a45 | 2015-05-01 17:47:54 +0200 | [diff] [blame] | 479 | static inline struct tcm_loop_tpg *tl_tpg(struct se_portal_group *se_tpg) |
| 480 | { |
| 481 | return container_of(se_tpg, struct tcm_loop_tpg, tl_se_tpg); |
| 482 | } |
| 483 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 484 | static char *tcm_loop_get_endpoint_wwn(struct se_portal_group *se_tpg) |
| 485 | { |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 486 | /* |
Hannes Reinecke | b7446ca | 2015-06-18 11:43:37 +0200 | [diff] [blame] | 487 | * Return the passed NAA identifier for the Target Port |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 488 | */ |
Christoph Hellwig | 1667a45 | 2015-05-01 17:47:54 +0200 | [diff] [blame] | 489 | return &tl_tpg(se_tpg)->tl_hba->tl_wwn_address[0]; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | static u16 tcm_loop_get_tag(struct se_portal_group *se_tpg) |
| 493 | { |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 494 | /* |
| 495 | * This Tag is used when forming SCSI Name identifier in EVPD=1 0x83 |
| 496 | * to represent the SCSI Target Port. |
| 497 | */ |
Christoph Hellwig | 1667a45 | 2015-05-01 17:47:54 +0200 | [diff] [blame] | 498 | return tl_tpg(se_tpg)->tl_tpgt; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 501 | /* |
| 502 | * Returning (1) here allows for target_core_mod struct se_node_acl to be generated |
| 503 | * based upon the incoming fabric dependent SCSI Initiator Port |
| 504 | */ |
| 505 | static int tcm_loop_check_demo_mode(struct se_portal_group *se_tpg) |
| 506 | { |
| 507 | return 1; |
| 508 | } |
| 509 | |
| 510 | static int tcm_loop_check_demo_mode_cache(struct se_portal_group *se_tpg) |
| 511 | { |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | * Allow I_T Nexus full READ-WRITE access without explict Initiator Node ACLs for |
| 517 | * local virtual Linux/SCSI LLD passthrough into VM hypervisor guest |
| 518 | */ |
| 519 | static int tcm_loop_check_demo_mode_write_protect(struct se_portal_group *se_tpg) |
| 520 | { |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | /* |
| 525 | * Because TCM_Loop does not use explict ACLs and MappedLUNs, this will |
| 526 | * never be called for TCM_Loop by target_core_fabric_configfs.c code. |
| 527 | * It has been added here as a nop for target_fabric_tf_ops_check() |
| 528 | */ |
| 529 | static int tcm_loop_check_prod_mode_write_protect(struct se_portal_group *se_tpg) |
| 530 | { |
| 531 | return 0; |
| 532 | } |
| 533 | |
Nicholas Bellinger | 436f4a0 | 2015-02-08 12:31:39 -0800 | [diff] [blame] | 534 | static int tcm_loop_check_prot_fabric_only(struct se_portal_group *se_tpg) |
| 535 | { |
| 536 | struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, struct tcm_loop_tpg, |
| 537 | tl_se_tpg); |
| 538 | return tl_tpg->tl_fabric_prot_type; |
| 539 | } |
| 540 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 541 | static u32 tcm_loop_get_inst_index(struct se_portal_group *se_tpg) |
| 542 | { |
| 543 | return 1; |
| 544 | } |
| 545 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 546 | static u32 tcm_loop_sess_get_index(struct se_session *se_sess) |
| 547 | { |
| 548 | return 1; |
| 549 | } |
| 550 | |
| 551 | static void tcm_loop_set_default_node_attributes(struct se_node_acl *se_acl) |
| 552 | { |
| 553 | return; |
| 554 | } |
| 555 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 556 | static int tcm_loop_get_cmd_state(struct se_cmd *se_cmd) |
| 557 | { |
| 558 | struct tcm_loop_cmd *tl_cmd = container_of(se_cmd, |
| 559 | struct tcm_loop_cmd, tl_se_cmd); |
| 560 | |
| 561 | return tl_cmd->sc_cmd_state; |
| 562 | } |
| 563 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 564 | static int tcm_loop_write_pending(struct se_cmd *se_cmd) |
| 565 | { |
| 566 | /* |
| 567 | * Since Linux/SCSI has already sent down a struct scsi_cmnd |
| 568 | * sc->sc_data_direction of DMA_TO_DEVICE with struct scatterlist array |
| 569 | * memory, and memory has already been mapped to struct se_cmd->t_mem_list |
| 570 | * format with transport_generic_map_mem_to_cmd(). |
| 571 | * |
| 572 | * We now tell TCM to add this WRITE CDB directly into the TCM storage |
| 573 | * object execution queue. |
| 574 | */ |
Christoph Hellwig | 70baf0a | 2012-07-08 15:58:39 -0400 | [diff] [blame] | 575 | target_execute_cmd(se_cmd); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 576 | return 0; |
| 577 | } |
| 578 | |
| 579 | static int tcm_loop_write_pending_status(struct se_cmd *se_cmd) |
| 580 | { |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | static int tcm_loop_queue_data_in(struct se_cmd *se_cmd) |
| 585 | { |
| 586 | struct tcm_loop_cmd *tl_cmd = container_of(se_cmd, |
| 587 | struct tcm_loop_cmd, tl_se_cmd); |
| 588 | struct scsi_cmnd *sc = tl_cmd->sc; |
| 589 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 590 | pr_debug("tcm_loop_queue_data_in() called for scsi_cmnd: %p" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 591 | " cdb: 0x%02x\n", sc, sc->cmnd[0]); |
| 592 | |
| 593 | sc->result = SAM_STAT_GOOD; |
| 594 | set_host_byte(sc, DID_OK); |
Roland Dreier | 6cf3fa6 | 2012-02-14 15:30:31 -0800 | [diff] [blame] | 595 | if ((se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) || |
| 596 | (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT)) |
| 597 | scsi_set_resid(sc, se_cmd->residual_count); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 598 | sc->scsi_done(sc); |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | static int tcm_loop_queue_status(struct se_cmd *se_cmd) |
| 603 | { |
| 604 | struct tcm_loop_cmd *tl_cmd = container_of(se_cmd, |
| 605 | struct tcm_loop_cmd, tl_se_cmd); |
| 606 | struct scsi_cmnd *sc = tl_cmd->sc; |
| 607 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 608 | pr_debug("tcm_loop_queue_status() called for scsi_cmnd: %p" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 609 | " cdb: 0x%02x\n", sc, sc->cmnd[0]); |
| 610 | |
| 611 | if (se_cmd->sense_buffer && |
| 612 | ((se_cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) || |
| 613 | (se_cmd->se_cmd_flags & SCF_EMULATED_TASK_SENSE))) { |
| 614 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 615 | memcpy(sc->sense_buffer, se_cmd->sense_buffer, |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 616 | SCSI_SENSE_BUFFERSIZE); |
| 617 | sc->result = SAM_STAT_CHECK_CONDITION; |
| 618 | set_driver_byte(sc, DRIVER_SENSE); |
| 619 | } else |
| 620 | sc->result = se_cmd->scsi_status; |
| 621 | |
| 622 | set_host_byte(sc, DID_OK); |
Roland Dreier | 6cf3fa6 | 2012-02-14 15:30:31 -0800 | [diff] [blame] | 623 | if ((se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) || |
| 624 | (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT)) |
| 625 | scsi_set_resid(sc, se_cmd->residual_count); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 626 | sc->scsi_done(sc); |
| 627 | return 0; |
| 628 | } |
| 629 | |
Joern Engel | b79fafa | 2013-07-03 11:22:17 -0400 | [diff] [blame] | 630 | static void tcm_loop_queue_tm_rsp(struct se_cmd *se_cmd) |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 631 | { |
Bart Van Assche | 4d3895d | 2017-05-23 16:48:39 -0700 | [diff] [blame] | 632 | struct tcm_loop_cmd *tl_cmd = container_of(se_cmd, |
| 633 | struct tcm_loop_cmd, tl_se_cmd); |
| 634 | |
Bart Van Assche | d17203c | 2017-05-23 16:48:40 -0700 | [diff] [blame] | 635 | /* Wake up tcm_loop_issue_tmr(). */ |
| 636 | complete(&tl_cmd->tmr_done); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Nicholas Bellinger | 131e6ab | 2014-03-22 14:55:56 -0700 | [diff] [blame] | 639 | static void tcm_loop_aborted_task(struct se_cmd *se_cmd) |
| 640 | { |
| 641 | return; |
| 642 | } |
| 643 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 644 | static char *tcm_loop_dump_proto_id(struct tcm_loop_hba *tl_hba) |
| 645 | { |
| 646 | switch (tl_hba->tl_proto_id) { |
| 647 | case SCSI_PROTOCOL_SAS: |
| 648 | return "SAS"; |
| 649 | case SCSI_PROTOCOL_FCP: |
| 650 | return "FCP"; |
| 651 | case SCSI_PROTOCOL_ISCSI: |
| 652 | return "iSCSI"; |
| 653 | default: |
| 654 | break; |
| 655 | } |
| 656 | |
| 657 | return "Unknown"; |
| 658 | } |
| 659 | |
| 660 | /* Start items for tcm_loop_port_cit */ |
| 661 | |
| 662 | static int tcm_loop_port_link( |
| 663 | struct se_portal_group *se_tpg, |
| 664 | struct se_lun *lun) |
| 665 | { |
| 666 | struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, |
| 667 | struct tcm_loop_tpg, tl_se_tpg); |
| 668 | struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba; |
| 669 | |
Joern Engel | 33940d0 | 2014-09-16 16:23:12 -0400 | [diff] [blame] | 670 | atomic_inc_mb(&tl_tpg->tl_tpg_port_count); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 671 | /* |
| 672 | * Add Linux/SCSI struct scsi_device by HCTL |
| 673 | */ |
| 674 | scsi_add_device(tl_hba->sh, 0, tl_tpg->tl_tpgt, lun->unpacked_lun); |
| 675 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 676 | pr_debug("TCM_Loop_ConfigFS: Port Link Successful\n"); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | static void tcm_loop_port_unlink( |
| 681 | struct se_portal_group *se_tpg, |
| 682 | struct se_lun *se_lun) |
| 683 | { |
| 684 | struct scsi_device *sd; |
| 685 | struct tcm_loop_hba *tl_hba; |
| 686 | struct tcm_loop_tpg *tl_tpg; |
| 687 | |
| 688 | tl_tpg = container_of(se_tpg, struct tcm_loop_tpg, tl_se_tpg); |
| 689 | tl_hba = tl_tpg->tl_hba; |
| 690 | |
| 691 | sd = scsi_device_lookup(tl_hba->sh, 0, tl_tpg->tl_tpgt, |
| 692 | se_lun->unpacked_lun); |
| 693 | if (!sd) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 694 | pr_err("Unable to locate struct scsi_device for %d:%d:" |
Hannes Reinecke | f2d3068 | 2015-06-10 08:41:22 +0200 | [diff] [blame] | 695 | "%llu\n", 0, tl_tpg->tl_tpgt, se_lun->unpacked_lun); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 696 | return; |
| 697 | } |
| 698 | /* |
| 699 | * Remove Linux/SCSI struct scsi_device by HCTL |
| 700 | */ |
| 701 | scsi_remove_device(sd); |
| 702 | scsi_device_put(sd); |
| 703 | |
Joern Engel | 33940d0 | 2014-09-16 16:23:12 -0400 | [diff] [blame] | 704 | atomic_dec_mb(&tl_tpg->tl_tpg_port_count); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 705 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 706 | pr_debug("TCM_Loop_ConfigFS: Port Unlink Successful\n"); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | /* End items for tcm_loop_port_cit */ |
| 710 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 711 | static ssize_t tcm_loop_tpg_attrib_fabric_prot_type_show( |
| 712 | struct config_item *item, char *page) |
Nicholas Bellinger | 436f4a0 | 2015-02-08 12:31:39 -0800 | [diff] [blame] | 713 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 714 | struct se_portal_group *se_tpg = attrib_to_tpg(item); |
Nicholas Bellinger | 436f4a0 | 2015-02-08 12:31:39 -0800 | [diff] [blame] | 715 | struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, struct tcm_loop_tpg, |
| 716 | tl_se_tpg); |
| 717 | |
| 718 | return sprintf(page, "%d\n", tl_tpg->tl_fabric_prot_type); |
| 719 | } |
| 720 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 721 | static ssize_t tcm_loop_tpg_attrib_fabric_prot_type_store( |
| 722 | struct config_item *item, const char *page, size_t count) |
Nicholas Bellinger | 436f4a0 | 2015-02-08 12:31:39 -0800 | [diff] [blame] | 723 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 724 | struct se_portal_group *se_tpg = attrib_to_tpg(item); |
Nicholas Bellinger | 436f4a0 | 2015-02-08 12:31:39 -0800 | [diff] [blame] | 725 | struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, struct tcm_loop_tpg, |
| 726 | tl_se_tpg); |
| 727 | unsigned long val; |
| 728 | int ret = kstrtoul(page, 0, &val); |
| 729 | |
| 730 | if (ret) { |
| 731 | pr_err("kstrtoul() returned %d for fabric_prot_type\n", ret); |
| 732 | return ret; |
| 733 | } |
| 734 | if (val != 0 && val != 1 && val != 3) { |
| 735 | pr_err("Invalid qla2xxx fabric_prot_type: %lu\n", val); |
| 736 | return -EINVAL; |
| 737 | } |
| 738 | tl_tpg->tl_fabric_prot_type = val; |
| 739 | |
| 740 | return count; |
| 741 | } |
| 742 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 743 | CONFIGFS_ATTR(tcm_loop_tpg_attrib_, fabric_prot_type); |
Nicholas Bellinger | 436f4a0 | 2015-02-08 12:31:39 -0800 | [diff] [blame] | 744 | |
| 745 | static struct configfs_attribute *tcm_loop_tpg_attrib_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 746 | &tcm_loop_tpg_attrib_attr_fabric_prot_type, |
Nicholas Bellinger | 436f4a0 | 2015-02-08 12:31:39 -0800 | [diff] [blame] | 747 | NULL, |
| 748 | }; |
| 749 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 750 | /* Start items for tcm_loop_nexus_cit */ |
| 751 | |
Christoph Hellwig | fb444abe | 2016-01-09 05:30:45 -0800 | [diff] [blame] | 752 | static int tcm_loop_alloc_sess_cb(struct se_portal_group *se_tpg, |
| 753 | struct se_session *se_sess, void *p) |
| 754 | { |
| 755 | struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, |
| 756 | struct tcm_loop_tpg, tl_se_tpg); |
| 757 | |
| 758 | tl_tpg->tl_nexus = p; |
| 759 | return 0; |
| 760 | } |
| 761 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 762 | static int tcm_loop_make_nexus( |
| 763 | struct tcm_loop_tpg *tl_tpg, |
| 764 | const char *name) |
| 765 | { |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 766 | struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba; |
| 767 | struct tcm_loop_nexus *tl_nexus; |
Christoph Hellwig | fb444abe | 2016-01-09 05:30:45 -0800 | [diff] [blame] | 768 | int ret; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 769 | |
Hannes Reinecke | 506787a | 2014-11-26 14:58:57 +0100 | [diff] [blame] | 770 | if (tl_tpg->tl_nexus) { |
| 771 | pr_debug("tl_tpg->tl_nexus already exists\n"); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 772 | return -EEXIST; |
| 773 | } |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 774 | |
| 775 | tl_nexus = kzalloc(sizeof(struct tcm_loop_nexus), GFP_KERNEL); |
| 776 | if (!tl_nexus) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 777 | pr_err("Unable to allocate struct tcm_loop_nexus\n"); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 778 | return -ENOMEM; |
| 779 | } |
Christoph Hellwig | fb444abe | 2016-01-09 05:30:45 -0800 | [diff] [blame] | 780 | |
| 781 | tl_nexus->se_sess = target_alloc_session(&tl_tpg->tl_se_tpg, 0, 0, |
| 782 | TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS, |
| 783 | name, tl_nexus, tcm_loop_alloc_sess_cb); |
Dan Carpenter | 552523d | 2011-06-15 09:41:33 -0700 | [diff] [blame] | 784 | if (IS_ERR(tl_nexus->se_sess)) { |
| 785 | ret = PTR_ERR(tl_nexus->se_sess); |
Christoph Hellwig | fb444abe | 2016-01-09 05:30:45 -0800 | [diff] [blame] | 786 | kfree(tl_nexus); |
| 787 | return ret; |
Dan Carpenter | 552523d | 2011-06-15 09:41:33 -0700 | [diff] [blame] | 788 | } |
Christoph Hellwig | fb444abe | 2016-01-09 05:30:45 -0800 | [diff] [blame] | 789 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 790 | pr_debug("TCM_Loop_ConfigFS: Established I_T Nexus to emulated" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 791 | " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba), |
| 792 | name); |
| 793 | return 0; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | static int tcm_loop_drop_nexus( |
| 797 | struct tcm_loop_tpg *tpg) |
| 798 | { |
| 799 | struct se_session *se_sess; |
| 800 | struct tcm_loop_nexus *tl_nexus; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 801 | |
Hannes Reinecke | 506787a | 2014-11-26 14:58:57 +0100 | [diff] [blame] | 802 | tl_nexus = tpg->tl_nexus; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 803 | if (!tl_nexus) |
| 804 | return -ENODEV; |
| 805 | |
| 806 | se_sess = tl_nexus->se_sess; |
| 807 | if (!se_sess) |
| 808 | return -ENODEV; |
| 809 | |
| 810 | if (atomic_read(&tpg->tl_tpg_port_count)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 811 | pr_err("Unable to remove TCM_Loop I_T Nexus with" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 812 | " active TPG port count: %d\n", |
| 813 | atomic_read(&tpg->tl_tpg_port_count)); |
| 814 | return -EPERM; |
| 815 | } |
| 816 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 817 | pr_debug("TCM_Loop_ConfigFS: Removing I_T Nexus to emulated" |
Hannes Reinecke | 506787a | 2014-11-26 14:58:57 +0100 | [diff] [blame] | 818 | " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tpg->tl_hba), |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 819 | tl_nexus->se_sess->se_node_acl->initiatorname); |
| 820 | /* |
Hannes Reinecke | b7446ca | 2015-06-18 11:43:37 +0200 | [diff] [blame] | 821 | * Release the SCSI I_T Nexus to the emulated Target Port |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 822 | */ |
| 823 | transport_deregister_session(tl_nexus->se_sess); |
Hannes Reinecke | 506787a | 2014-11-26 14:58:57 +0100 | [diff] [blame] | 824 | tpg->tl_nexus = NULL; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 825 | kfree(tl_nexus); |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | /* End items for tcm_loop_nexus_cit */ |
| 830 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 831 | static ssize_t tcm_loop_tpg_nexus_show(struct config_item *item, char *page) |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 832 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 833 | struct se_portal_group *se_tpg = to_tpg(item); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 834 | struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, |
| 835 | struct tcm_loop_tpg, tl_se_tpg); |
| 836 | struct tcm_loop_nexus *tl_nexus; |
| 837 | ssize_t ret; |
| 838 | |
Hannes Reinecke | 506787a | 2014-11-26 14:58:57 +0100 | [diff] [blame] | 839 | tl_nexus = tl_tpg->tl_nexus; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 840 | if (!tl_nexus) |
| 841 | return -ENODEV; |
| 842 | |
| 843 | ret = snprintf(page, PAGE_SIZE, "%s\n", |
| 844 | tl_nexus->se_sess->se_node_acl->initiatorname); |
| 845 | |
| 846 | return ret; |
| 847 | } |
| 848 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 849 | static ssize_t tcm_loop_tpg_nexus_store(struct config_item *item, |
| 850 | const char *page, size_t count) |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 851 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 852 | struct se_portal_group *se_tpg = to_tpg(item); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 853 | struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, |
| 854 | struct tcm_loop_tpg, tl_se_tpg); |
| 855 | struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba; |
| 856 | unsigned char i_port[TL_WWN_ADDR_LEN], *ptr, *port_ptr; |
| 857 | int ret; |
| 858 | /* |
| 859 | * Shutdown the active I_T nexus if 'NULL' is passed.. |
| 860 | */ |
| 861 | if (!strncmp(page, "NULL", 4)) { |
| 862 | ret = tcm_loop_drop_nexus(tl_tpg); |
| 863 | return (!ret) ? count : ret; |
| 864 | } |
| 865 | /* |
| 866 | * Otherwise make sure the passed virtual Initiator port WWN matches |
| 867 | * the fabric protocol_id set in tcm_loop_make_scsi_hba(), and call |
| 868 | * tcm_loop_make_nexus() |
| 869 | */ |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 870 | if (strlen(page) >= TL_WWN_ADDR_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 871 | pr_err("Emulated NAA Sas Address: %s, exceeds" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 872 | " max: %d\n", page, TL_WWN_ADDR_LEN); |
| 873 | return -EINVAL; |
| 874 | } |
| 875 | snprintf(&i_port[0], TL_WWN_ADDR_LEN, "%s", page); |
| 876 | |
| 877 | ptr = strstr(i_port, "naa."); |
| 878 | if (ptr) { |
| 879 | if (tl_hba->tl_proto_id != SCSI_PROTOCOL_SAS) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 880 | pr_err("Passed SAS Initiator Port %s does not" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 881 | " match target port protoid: %s\n", i_port, |
| 882 | tcm_loop_dump_proto_id(tl_hba)); |
| 883 | return -EINVAL; |
| 884 | } |
| 885 | port_ptr = &i_port[0]; |
| 886 | goto check_newline; |
| 887 | } |
| 888 | ptr = strstr(i_port, "fc."); |
| 889 | if (ptr) { |
| 890 | if (tl_hba->tl_proto_id != SCSI_PROTOCOL_FCP) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 891 | pr_err("Passed FCP Initiator Port %s does not" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 892 | " match target port protoid: %s\n", i_port, |
| 893 | tcm_loop_dump_proto_id(tl_hba)); |
| 894 | return -EINVAL; |
| 895 | } |
| 896 | port_ptr = &i_port[3]; /* Skip over "fc." */ |
| 897 | goto check_newline; |
| 898 | } |
| 899 | ptr = strstr(i_port, "iqn."); |
| 900 | if (ptr) { |
| 901 | if (tl_hba->tl_proto_id != SCSI_PROTOCOL_ISCSI) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 902 | pr_err("Passed iSCSI Initiator Port %s does not" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 903 | " match target port protoid: %s\n", i_port, |
| 904 | tcm_loop_dump_proto_id(tl_hba)); |
| 905 | return -EINVAL; |
| 906 | } |
| 907 | port_ptr = &i_port[0]; |
| 908 | goto check_newline; |
| 909 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 910 | pr_err("Unable to locate prefix for emulated Initiator Port:" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 911 | " %s\n", i_port); |
| 912 | return -EINVAL; |
| 913 | /* |
| 914 | * Clear any trailing newline for the NAA WWN |
| 915 | */ |
| 916 | check_newline: |
| 917 | if (i_port[strlen(i_port)-1] == '\n') |
| 918 | i_port[strlen(i_port)-1] = '\0'; |
| 919 | |
| 920 | ret = tcm_loop_make_nexus(tl_tpg, port_ptr); |
| 921 | if (ret < 0) |
| 922 | return ret; |
| 923 | |
| 924 | return count; |
| 925 | } |
| 926 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 927 | static ssize_t tcm_loop_tpg_transport_status_show(struct config_item *item, |
| 928 | char *page) |
Hannes Reinecke | fb2b284 | 2013-10-16 09:12:53 +0200 | [diff] [blame] | 929 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 930 | struct se_portal_group *se_tpg = to_tpg(item); |
Hannes Reinecke | fb2b284 | 2013-10-16 09:12:53 +0200 | [diff] [blame] | 931 | struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, |
| 932 | struct tcm_loop_tpg, tl_se_tpg); |
| 933 | const char *status = NULL; |
| 934 | ssize_t ret = -EINVAL; |
| 935 | |
| 936 | switch (tl_tpg->tl_transport_status) { |
| 937 | case TCM_TRANSPORT_ONLINE: |
| 938 | status = "online"; |
| 939 | break; |
| 940 | case TCM_TRANSPORT_OFFLINE: |
| 941 | status = "offline"; |
| 942 | break; |
| 943 | default: |
| 944 | break; |
| 945 | } |
| 946 | |
| 947 | if (status) |
| 948 | ret = snprintf(page, PAGE_SIZE, "%s\n", status); |
| 949 | |
| 950 | return ret; |
| 951 | } |
| 952 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 953 | static ssize_t tcm_loop_tpg_transport_status_store(struct config_item *item, |
| 954 | const char *page, size_t count) |
Hannes Reinecke | fb2b284 | 2013-10-16 09:12:53 +0200 | [diff] [blame] | 955 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 956 | struct se_portal_group *se_tpg = to_tpg(item); |
Hannes Reinecke | fb2b284 | 2013-10-16 09:12:53 +0200 | [diff] [blame] | 957 | struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, |
| 958 | struct tcm_loop_tpg, tl_se_tpg); |
| 959 | |
| 960 | if (!strncmp(page, "online", 6)) { |
| 961 | tl_tpg->tl_transport_status = TCM_TRANSPORT_ONLINE; |
| 962 | return count; |
| 963 | } |
| 964 | if (!strncmp(page, "offline", 7)) { |
| 965 | tl_tpg->tl_transport_status = TCM_TRANSPORT_OFFLINE; |
Hannes Reinecke | e986a35 | 2015-06-18 11:43:38 +0200 | [diff] [blame] | 966 | if (tl_tpg->tl_nexus) { |
| 967 | struct se_session *tl_sess = tl_tpg->tl_nexus->se_sess; |
| 968 | |
| 969 | core_allocate_nexus_loss_ua(tl_sess->se_node_acl); |
| 970 | } |
Hannes Reinecke | fb2b284 | 2013-10-16 09:12:53 +0200 | [diff] [blame] | 971 | return count; |
| 972 | } |
| 973 | return -EINVAL; |
| 974 | } |
| 975 | |
Sheng Yang | 2628b35 | 2015-11-14 14:17:16 -0800 | [diff] [blame] | 976 | static ssize_t tcm_loop_tpg_address_show(struct config_item *item, |
| 977 | char *page) |
| 978 | { |
| 979 | struct se_portal_group *se_tpg = to_tpg(item); |
| 980 | struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, |
| 981 | struct tcm_loop_tpg, tl_se_tpg); |
| 982 | struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba; |
| 983 | |
| 984 | return snprintf(page, PAGE_SIZE, "%d:0:%d\n", |
| 985 | tl_hba->sh->host_no, tl_tpg->tl_tpgt); |
| 986 | } |
| 987 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 988 | CONFIGFS_ATTR(tcm_loop_tpg_, nexus); |
| 989 | CONFIGFS_ATTR(tcm_loop_tpg_, transport_status); |
Sheng Yang | 2628b35 | 2015-11-14 14:17:16 -0800 | [diff] [blame] | 990 | CONFIGFS_ATTR_RO(tcm_loop_tpg_, address); |
Hannes Reinecke | fb2b284 | 2013-10-16 09:12:53 +0200 | [diff] [blame] | 991 | |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 992 | static struct configfs_attribute *tcm_loop_tpg_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 993 | &tcm_loop_tpg_attr_nexus, |
| 994 | &tcm_loop_tpg_attr_transport_status, |
Sheng Yang | 2628b35 | 2015-11-14 14:17:16 -0800 | [diff] [blame] | 995 | &tcm_loop_tpg_attr_address, |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 996 | NULL, |
| 997 | }; |
| 998 | |
| 999 | /* Start items for tcm_loop_naa_cit */ |
| 1000 | |
Rashika Kheria | f0a6c69 | 2013-12-19 00:02:54 +0530 | [diff] [blame] | 1001 | static struct se_portal_group *tcm_loop_make_naa_tpg( |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1002 | struct se_wwn *wwn, |
| 1003 | struct config_group *group, |
| 1004 | const char *name) |
| 1005 | { |
| 1006 | struct tcm_loop_hba *tl_hba = container_of(wwn, |
| 1007 | struct tcm_loop_hba, tl_hba_wwn); |
| 1008 | struct tcm_loop_tpg *tl_tpg; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1009 | int ret; |
Ming Lin | 2e1cd90 | 2015-03-29 23:11:30 -0700 | [diff] [blame] | 1010 | unsigned long tpgt; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1011 | |
Ming Lin | 2e1cd90 | 2015-03-29 23:11:30 -0700 | [diff] [blame] | 1012 | if (strstr(name, "tpgt_") != name) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1013 | pr_err("Unable to locate \"tpgt_#\" directory" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1014 | " group\n"); |
| 1015 | return ERR_PTR(-EINVAL); |
| 1016 | } |
Ming Lin | 2e1cd90 | 2015-03-29 23:11:30 -0700 | [diff] [blame] | 1017 | if (kstrtoul(name+5, 10, &tpgt)) |
| 1018 | return ERR_PTR(-EINVAL); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1019 | |
Dan Carpenter | 12f09cc | 2011-04-02 14:32:47 -0700 | [diff] [blame] | 1020 | if (tpgt >= TL_TPGS_PER_HBA) { |
Ming Lin | 2e1cd90 | 2015-03-29 23:11:30 -0700 | [diff] [blame] | 1021 | pr_err("Passed tpgt: %lu exceeds TL_TPGS_PER_HBA:" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1022 | " %u\n", tpgt, TL_TPGS_PER_HBA); |
| 1023 | return ERR_PTR(-EINVAL); |
| 1024 | } |
| 1025 | tl_tpg = &tl_hba->tl_hba_tpgs[tpgt]; |
| 1026 | tl_tpg->tl_hba = tl_hba; |
| 1027 | tl_tpg->tl_tpgt = tpgt; |
| 1028 | /* |
Hannes Reinecke | b7446ca | 2015-06-18 11:43:37 +0200 | [diff] [blame] | 1029 | * Register the tl_tpg as a emulated TCM Target Endpoint |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1030 | */ |
Nicholas Bellinger | bc0c94b | 2015-05-20 21:48:03 -0700 | [diff] [blame] | 1031 | ret = core_tpg_register(wwn, &tl_tpg->tl_se_tpg, tl_hba->tl_proto_id); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1032 | if (ret < 0) |
| 1033 | return ERR_PTR(-ENOMEM); |
| 1034 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1035 | pr_debug("TCM_Loop_ConfigFS: Allocated Emulated %s" |
Ming Lin | 2e1cd90 | 2015-03-29 23:11:30 -0700 | [diff] [blame] | 1036 | " Target Port %s,t,0x%04lx\n", tcm_loop_dump_proto_id(tl_hba), |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1037 | config_item_name(&wwn->wwn_group.cg_item), tpgt); |
| 1038 | |
| 1039 | return &tl_tpg->tl_se_tpg; |
| 1040 | } |
| 1041 | |
Rashika Kheria | f0a6c69 | 2013-12-19 00:02:54 +0530 | [diff] [blame] | 1042 | static void tcm_loop_drop_naa_tpg( |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1043 | struct se_portal_group *se_tpg) |
| 1044 | { |
| 1045 | struct se_wwn *wwn = se_tpg->se_tpg_wwn; |
| 1046 | struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, |
| 1047 | struct tcm_loop_tpg, tl_se_tpg); |
| 1048 | struct tcm_loop_hba *tl_hba; |
| 1049 | unsigned short tpgt; |
| 1050 | |
| 1051 | tl_hba = tl_tpg->tl_hba; |
| 1052 | tpgt = tl_tpg->tl_tpgt; |
| 1053 | /* |
Hannes Reinecke | b7446ca | 2015-06-18 11:43:37 +0200 | [diff] [blame] | 1054 | * Release the I_T Nexus for the Virtual target link if present |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1055 | */ |
| 1056 | tcm_loop_drop_nexus(tl_tpg); |
| 1057 | /* |
Hannes Reinecke | b7446ca | 2015-06-18 11:43:37 +0200 | [diff] [blame] | 1058 | * Deregister the tl_tpg as a emulated TCM Target Endpoint |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1059 | */ |
| 1060 | core_tpg_deregister(se_tpg); |
| 1061 | |
Nicholas Bellinger | 0a02043 | 2011-10-10 19:44:05 -0700 | [diff] [blame] | 1062 | tl_tpg->tl_hba = NULL; |
| 1063 | tl_tpg->tl_tpgt = 0; |
| 1064 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1065 | pr_debug("TCM_Loop_ConfigFS: Deallocated Emulated %s" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1066 | " Target Port %s,t,0x%04x\n", tcm_loop_dump_proto_id(tl_hba), |
| 1067 | config_item_name(&wwn->wwn_group.cg_item), tpgt); |
| 1068 | } |
| 1069 | |
| 1070 | /* End items for tcm_loop_naa_cit */ |
| 1071 | |
| 1072 | /* Start items for tcm_loop_cit */ |
| 1073 | |
Rashika Kheria | f0a6c69 | 2013-12-19 00:02:54 +0530 | [diff] [blame] | 1074 | static struct se_wwn *tcm_loop_make_scsi_hba( |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1075 | struct target_fabric_configfs *tf, |
| 1076 | struct config_group *group, |
| 1077 | const char *name) |
| 1078 | { |
| 1079 | struct tcm_loop_hba *tl_hba; |
| 1080 | struct Scsi_Host *sh; |
| 1081 | char *ptr; |
| 1082 | int ret, off = 0; |
| 1083 | |
| 1084 | tl_hba = kzalloc(sizeof(struct tcm_loop_hba), GFP_KERNEL); |
| 1085 | if (!tl_hba) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1086 | pr_err("Unable to allocate struct tcm_loop_hba\n"); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1087 | return ERR_PTR(-ENOMEM); |
| 1088 | } |
| 1089 | /* |
| 1090 | * Determine the emulated Protocol Identifier and Target Port Name |
| 1091 | * based on the incoming configfs directory name. |
| 1092 | */ |
| 1093 | ptr = strstr(name, "naa."); |
| 1094 | if (ptr) { |
| 1095 | tl_hba->tl_proto_id = SCSI_PROTOCOL_SAS; |
| 1096 | goto check_len; |
| 1097 | } |
| 1098 | ptr = strstr(name, "fc."); |
| 1099 | if (ptr) { |
| 1100 | tl_hba->tl_proto_id = SCSI_PROTOCOL_FCP; |
| 1101 | off = 3; /* Skip over "fc." */ |
| 1102 | goto check_len; |
| 1103 | } |
| 1104 | ptr = strstr(name, "iqn."); |
Jesper Juhl | a57b5d3 | 2011-06-28 00:30:17 +0200 | [diff] [blame] | 1105 | if (!ptr) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1106 | pr_err("Unable to locate prefix for emulated Target " |
Jesper Juhl | a57b5d3 | 2011-06-28 00:30:17 +0200 | [diff] [blame] | 1107 | "Port: %s\n", name); |
| 1108 | ret = -EINVAL; |
| 1109 | goto out; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1110 | } |
Jesper Juhl | a57b5d3 | 2011-06-28 00:30:17 +0200 | [diff] [blame] | 1111 | tl_hba->tl_proto_id = SCSI_PROTOCOL_ISCSI; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1112 | |
| 1113 | check_len: |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 1114 | if (strlen(name) >= TL_WWN_ADDR_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1115 | pr_err("Emulated NAA %s Address: %s, exceeds" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1116 | " max: %d\n", name, tcm_loop_dump_proto_id(tl_hba), |
| 1117 | TL_WWN_ADDR_LEN); |
Jesper Juhl | a57b5d3 | 2011-06-28 00:30:17 +0200 | [diff] [blame] | 1118 | ret = -EINVAL; |
| 1119 | goto out; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1120 | } |
| 1121 | snprintf(&tl_hba->tl_wwn_address[0], TL_WWN_ADDR_LEN, "%s", &name[off]); |
| 1122 | |
| 1123 | /* |
| 1124 | * Call device_register(tl_hba->dev) to register the emulated |
| 1125 | * Linux/SCSI LLD of type struct Scsi_Host at tl_hba->sh after |
| 1126 | * device_register() callbacks in tcm_loop_driver_probe() |
| 1127 | */ |
| 1128 | ret = tcm_loop_setup_hba_bus(tl_hba, tcm_loop_hba_no_cnt); |
| 1129 | if (ret) |
| 1130 | goto out; |
| 1131 | |
| 1132 | sh = tl_hba->sh; |
| 1133 | tcm_loop_hba_no_cnt++; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1134 | pr_debug("TCM_Loop_ConfigFS: Allocated emulated Target" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1135 | " %s Address: %s at Linux/SCSI Host ID: %d\n", |
| 1136 | tcm_loop_dump_proto_id(tl_hba), name, sh->host_no); |
| 1137 | |
| 1138 | return &tl_hba->tl_hba_wwn; |
| 1139 | out: |
| 1140 | kfree(tl_hba); |
| 1141 | return ERR_PTR(ret); |
| 1142 | } |
| 1143 | |
Rashika Kheria | f0a6c69 | 2013-12-19 00:02:54 +0530 | [diff] [blame] | 1144 | static void tcm_loop_drop_scsi_hba( |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1145 | struct se_wwn *wwn) |
| 1146 | { |
| 1147 | struct tcm_loop_hba *tl_hba = container_of(wwn, |
| 1148 | struct tcm_loop_hba, tl_hba_wwn); |
Nicholas Bellinger | 6297b07 | 2011-11-12 09:29:51 -0800 | [diff] [blame] | 1149 | |
| 1150 | pr_debug("TCM_Loop_ConfigFS: Deallocating emulated Target" |
Hannes Reinecke | b7446ca | 2015-06-18 11:43:37 +0200 | [diff] [blame] | 1151 | " %s Address: %s at Linux/SCSI Host ID: %d\n", |
| 1152 | tcm_loop_dump_proto_id(tl_hba), tl_hba->tl_wwn_address, |
| 1153 | tl_hba->sh->host_no); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1154 | /* |
| 1155 | * Call device_unregister() on the original tl_hba->dev. |
| 1156 | * tcm_loop_fabric_scsi.c:tcm_loop_release_adapter() will |
| 1157 | * release *tl_hba; |
| 1158 | */ |
| 1159 | device_unregister(&tl_hba->dev); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | /* Start items for tcm_loop_cit */ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1163 | static ssize_t tcm_loop_wwn_version_show(struct config_item *item, char *page) |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1164 | { |
| 1165 | return sprintf(page, "TCM Loopback Fabric module %s\n", TCM_LOOP_VERSION); |
| 1166 | } |
| 1167 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1168 | CONFIGFS_ATTR_RO(tcm_loop_wwn_, version); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1169 | |
| 1170 | static struct configfs_attribute *tcm_loop_wwn_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1171 | &tcm_loop_wwn_attr_version, |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1172 | NULL, |
| 1173 | }; |
| 1174 | |
| 1175 | /* End items for tcm_loop_cit */ |
| 1176 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1177 | static const struct target_core_fabric_ops loop_ops = { |
| 1178 | .module = THIS_MODULE, |
| 1179 | .name = "loopback", |
| 1180 | .get_fabric_name = tcm_loop_get_fabric_name, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1181 | .tpg_get_wwn = tcm_loop_get_endpoint_wwn, |
| 1182 | .tpg_get_tag = tcm_loop_get_tag, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1183 | .tpg_check_demo_mode = tcm_loop_check_demo_mode, |
| 1184 | .tpg_check_demo_mode_cache = tcm_loop_check_demo_mode_cache, |
| 1185 | .tpg_check_demo_mode_write_protect = |
| 1186 | tcm_loop_check_demo_mode_write_protect, |
| 1187 | .tpg_check_prod_mode_write_protect = |
| 1188 | tcm_loop_check_prod_mode_write_protect, |
| 1189 | .tpg_check_prot_fabric_only = tcm_loop_check_prot_fabric_only, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1190 | .tpg_get_inst_index = tcm_loop_get_inst_index, |
| 1191 | .check_stop_free = tcm_loop_check_stop_free, |
| 1192 | .release_cmd = tcm_loop_release_cmd, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1193 | .sess_get_index = tcm_loop_sess_get_index, |
| 1194 | .write_pending = tcm_loop_write_pending, |
| 1195 | .write_pending_status = tcm_loop_write_pending_status, |
| 1196 | .set_default_node_attributes = tcm_loop_set_default_node_attributes, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1197 | .get_cmd_state = tcm_loop_get_cmd_state, |
| 1198 | .queue_data_in = tcm_loop_queue_data_in, |
| 1199 | .queue_status = tcm_loop_queue_status, |
| 1200 | .queue_tm_rsp = tcm_loop_queue_tm_rsp, |
| 1201 | .aborted_task = tcm_loop_aborted_task, |
| 1202 | .fabric_make_wwn = tcm_loop_make_scsi_hba, |
| 1203 | .fabric_drop_wwn = tcm_loop_drop_scsi_hba, |
| 1204 | .fabric_make_tpg = tcm_loop_make_naa_tpg, |
| 1205 | .fabric_drop_tpg = tcm_loop_drop_naa_tpg, |
| 1206 | .fabric_post_link = tcm_loop_port_link, |
| 1207 | .fabric_pre_unlink = tcm_loop_port_unlink, |
| 1208 | .tfc_wwn_attrs = tcm_loop_wwn_attrs, |
| 1209 | .tfc_tpg_base_attrs = tcm_loop_tpg_attrs, |
| 1210 | .tfc_tpg_attrib_attrs = tcm_loop_tpg_attrib_attrs, |
| 1211 | }; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1212 | |
| 1213 | static int __init tcm_loop_fabric_init(void) |
| 1214 | { |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 1215 | int ret = -ENOMEM; |
| 1216 | |
| 1217 | tcm_loop_workqueue = alloc_workqueue("tcm_loop", 0, 0); |
| 1218 | if (!tcm_loop_workqueue) |
| 1219 | goto out; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1220 | |
| 1221 | tcm_loop_cmd_cache = kmem_cache_create("tcm_loop_cmd_cache", |
| 1222 | sizeof(struct tcm_loop_cmd), |
| 1223 | __alignof__(struct tcm_loop_cmd), |
| 1224 | 0, NULL); |
| 1225 | if (!tcm_loop_cmd_cache) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1226 | pr_debug("kmem_cache_create() for" |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1227 | " tcm_loop_cmd_cache failed\n"); |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 1228 | goto out_destroy_workqueue; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | ret = tcm_loop_alloc_core_bus(); |
| 1232 | if (ret) |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 1233 | goto out_destroy_cache; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1234 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1235 | ret = target_register_template(&loop_ops); |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 1236 | if (ret) |
| 1237 | goto out_release_core_bus; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1238 | |
| 1239 | return 0; |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 1240 | |
| 1241 | out_release_core_bus: |
| 1242 | tcm_loop_release_core_bus(); |
| 1243 | out_destroy_cache: |
| 1244 | kmem_cache_destroy(tcm_loop_cmd_cache); |
| 1245 | out_destroy_workqueue: |
| 1246 | destroy_workqueue(tcm_loop_workqueue); |
| 1247 | out: |
| 1248 | return ret; |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | static void __exit tcm_loop_fabric_exit(void) |
| 1252 | { |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1253 | target_unregister_template(&loop_ops); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1254 | tcm_loop_release_core_bus(); |
| 1255 | kmem_cache_destroy(tcm_loop_cmd_cache); |
Christoph Hellwig | afe2cb7 | 2012-02-02 17:04:41 -0500 | [diff] [blame] | 1256 | destroy_workqueue(tcm_loop_workqueue); |
Nicholas Bellinger | 3703b2c | 2011-03-18 15:39:17 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | MODULE_DESCRIPTION("TCM loopback virtual Linux/SCSI fabric module"); |
| 1260 | MODULE_AUTHOR("Nicholas A. Bellinger <nab@risingtidesystems.com>"); |
| 1261 | MODULE_LICENSE("GPL"); |
| 1262 | module_init(tcm_loop_fabric_init); |
| 1263 | module_exit(tcm_loop_fabric_exit); |