tcm_loop.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  1. /*******************************************************************************
  2. *
  3. * This file contains the Linux/SCSI LLD virtual SCSI initiator driver
  4. * for emulated SAS initiator ports
  5. *
  6. * © Copyright 2011-2013 Datera, Inc.
  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. #include <linux/module.h>
  23. #include <linux/moduleparam.h>
  24. #include <linux/init.h>
  25. #include <linux/slab.h>
  26. #include <linux/types.h>
  27. #include <linux/configfs.h>
  28. #include <scsi/scsi.h>
  29. #include <scsi/scsi_tcq.h>
  30. #include <scsi/scsi_host.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_cmnd.h>
  33. #include <target/target_core_base.h>
  34. #include <target/target_core_fabric.h>
  35. #include "tcm_loop.h"
  36. #define to_tcm_loop_hba(hba) container_of(hba, struct tcm_loop_hba, dev)
  37. static struct kmem_cache *tcm_loop_cmd_cache;
  38. static int tcm_loop_hba_no_cnt;
  39. static int tcm_loop_queue_status(struct se_cmd *se_cmd);
  40. static unsigned int tcm_loop_nr_hw_queues = 1;
  41. module_param_named(nr_hw_queues, tcm_loop_nr_hw_queues, uint, 0644);
  42. static unsigned int tcm_loop_can_queue = 1024;
  43. module_param_named(can_queue, tcm_loop_can_queue, uint, 0644);
  44. static unsigned int tcm_loop_cmd_per_lun = 1024;
  45. module_param_named(cmd_per_lun, tcm_loop_cmd_per_lun, uint, 0644);
  46. /*
  47. * Called from struct target_core_fabric_ops->check_stop_free()
  48. */
  49. static int tcm_loop_check_stop_free(struct se_cmd *se_cmd)
  50. {
  51. return transport_generic_free_cmd(se_cmd, 0);
  52. }
  53. static void tcm_loop_release_cmd(struct se_cmd *se_cmd)
  54. {
  55. struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
  56. struct tcm_loop_cmd, tl_se_cmd);
  57. struct scsi_cmnd *sc = tl_cmd->sc;
  58. if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)
  59. kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
  60. else
  61. scsi_done(sc);
  62. }
  63. static int tcm_loop_show_info(struct seq_file *m, struct Scsi_Host *host)
  64. {
  65. seq_puts(m, "tcm_loop_proc_info()\n");
  66. return 0;
  67. }
  68. static int tcm_loop_driver_probe(struct device *);
  69. static void tcm_loop_driver_remove(struct device *);
  70. static const struct bus_type tcm_loop_lld_bus = {
  71. .name = "tcm_loop_bus",
  72. .probe = tcm_loop_driver_probe,
  73. .remove = tcm_loop_driver_remove,
  74. };
  75. static struct device_driver tcm_loop_driverfs = {
  76. .name = "tcm_loop",
  77. .bus = &tcm_loop_lld_bus,
  78. };
  79. /*
  80. * Used with root_device_register() in tcm_loop_alloc_core_bus() below
  81. */
  82. static struct device *tcm_loop_primary;
  83. static void tcm_loop_target_queue_cmd(struct tcm_loop_cmd *tl_cmd)
  84. {
  85. struct se_cmd *se_cmd = &tl_cmd->tl_se_cmd;
  86. struct scsi_cmnd *sc = tl_cmd->sc;
  87. struct tcm_loop_nexus *tl_nexus;
  88. struct tcm_loop_hba *tl_hba;
  89. struct tcm_loop_tpg *tl_tpg;
  90. struct scatterlist *sgl_bidi = NULL;
  91. u32 sgl_bidi_count = 0, transfer_length;
  92. tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);
  93. tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];
  94. /*
  95. * Ensure that this tl_tpg reference from the incoming sc->device->id
  96. * has already been configured via tcm_loop_make_naa_tpg().
  97. */
  98. if (!tl_tpg->tl_hba) {
  99. set_host_byte(sc, DID_NO_CONNECT);
  100. goto out_done;
  101. }
  102. if (tl_tpg->tl_transport_status == TCM_TRANSPORT_OFFLINE) {
  103. set_host_byte(sc, DID_TRANSPORT_DISRUPTED);
  104. goto out_done;
  105. }
  106. tl_nexus = tl_tpg->tl_nexus;
  107. if (!tl_nexus) {
  108. scmd_printk(KERN_ERR, sc,
  109. "TCM_Loop I_T Nexus does not exist\n");
  110. set_host_byte(sc, DID_ERROR);
  111. goto out_done;
  112. }
  113. transfer_length = scsi_transfer_length(sc);
  114. if (!scsi_prot_sg_count(sc) &&
  115. scsi_get_prot_op(sc) != SCSI_PROT_NORMAL) {
  116. se_cmd->prot_pto = true;
  117. /*
  118. * loopback transport doesn't support
  119. * WRITE_GENERATE, READ_STRIP protection
  120. * information operations, go ahead unprotected.
  121. */
  122. transfer_length = scsi_bufflen(sc);
  123. }
  124. se_cmd->tag = tl_cmd->sc_cmd_tag;
  125. target_init_cmd(se_cmd, tl_nexus->se_sess, &tl_cmd->tl_sense_buf[0],
  126. tl_cmd->sc->device->lun, transfer_length,
  127. TCM_SIMPLE_TAG, sc->sc_data_direction, 0);
  128. if (target_submit_prep(se_cmd, sc->cmnd, scsi_sglist(sc),
  129. scsi_sg_count(sc), sgl_bidi, sgl_bidi_count,
  130. scsi_prot_sglist(sc), scsi_prot_sg_count(sc),
  131. GFP_ATOMIC))
  132. return;
  133. target_submit(se_cmd);
  134. return;
  135. out_done:
  136. scsi_done(sc);
  137. }
  138. /*
  139. * ->queuecommand can be and usually is called from interrupt context, so
  140. * defer the actual submission to a workqueue.
  141. */
  142. static int tcm_loop_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *sc)
  143. {
  144. struct tcm_loop_cmd *tl_cmd = scsi_cmd_priv(sc);
  145. pr_debug("%s() %d:%d:%d:%llu got CDB: 0x%02x scsi_buf_len: %u\n",
  146. __func__, sc->device->host->host_no, sc->device->id,
  147. sc->device->channel, sc->device->lun, sc->cmnd[0],
  148. scsi_bufflen(sc));
  149. memset(tl_cmd, 0, sizeof(*tl_cmd));
  150. tl_cmd->sc = sc;
  151. tl_cmd->sc_cmd_tag = scsi_cmd_to_rq(sc)->tag;
  152. tcm_loop_target_queue_cmd(tl_cmd);
  153. return 0;
  154. }
  155. /*
  156. * Called from SCSI EH process context to issue a LUN_RESET TMR
  157. * to struct scsi_device
  158. */
  159. static int tcm_loop_issue_tmr(struct tcm_loop_tpg *tl_tpg,
  160. u64 lun, int task, enum tcm_tmreq_table tmr)
  161. {
  162. struct se_cmd *se_cmd;
  163. struct se_session *se_sess;
  164. struct tcm_loop_nexus *tl_nexus;
  165. struct tcm_loop_cmd *tl_cmd;
  166. int ret = TMR_FUNCTION_FAILED, rc;
  167. /*
  168. * Locate the tl_nexus and se_sess pointers
  169. */
  170. tl_nexus = tl_tpg->tl_nexus;
  171. if (!tl_nexus) {
  172. pr_err("Unable to perform device reset without active I_T Nexus\n");
  173. return ret;
  174. }
  175. tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_KERNEL);
  176. if (!tl_cmd)
  177. return ret;
  178. init_completion(&tl_cmd->tmr_done);
  179. se_cmd = &tl_cmd->tl_se_cmd;
  180. se_sess = tl_tpg->tl_nexus->se_sess;
  181. rc = target_submit_tmr(se_cmd, se_sess, tl_cmd->tl_sense_buf, lun,
  182. NULL, tmr, GFP_KERNEL, task,
  183. TARGET_SCF_ACK_KREF);
  184. if (rc < 0)
  185. goto release;
  186. wait_for_completion(&tl_cmd->tmr_done);
  187. ret = se_cmd->se_tmr_req->response;
  188. target_put_sess_cmd(se_cmd);
  189. out:
  190. return ret;
  191. release:
  192. kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
  193. goto out;
  194. }
  195. static int tcm_loop_abort_task(struct scsi_cmnd *sc)
  196. {
  197. struct tcm_loop_hba *tl_hba;
  198. struct tcm_loop_tpg *tl_tpg;
  199. int ret;
  200. /*
  201. * Locate the tcm_loop_hba_t pointer
  202. */
  203. tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);
  204. tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];
  205. ret = tcm_loop_issue_tmr(tl_tpg, sc->device->lun,
  206. scsi_cmd_to_rq(sc)->tag, TMR_ABORT_TASK);
  207. return (ret == TMR_FUNCTION_COMPLETE) ? SUCCESS : FAILED;
  208. }
  209. /*
  210. * Called from SCSI EH process context to issue a LUN_RESET TMR
  211. * to struct scsi_device
  212. */
  213. static int tcm_loop_device_reset(struct scsi_cmnd *sc)
  214. {
  215. struct tcm_loop_hba *tl_hba;
  216. struct tcm_loop_tpg *tl_tpg;
  217. int ret;
  218. /*
  219. * Locate the tcm_loop_hba_t pointer
  220. */
  221. tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);
  222. tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];
  223. ret = tcm_loop_issue_tmr(tl_tpg, sc->device->lun,
  224. 0, TMR_LUN_RESET);
  225. return (ret == TMR_FUNCTION_COMPLETE) ? SUCCESS : FAILED;
  226. }
  227. static int tcm_loop_target_reset(struct scsi_cmnd *sc)
  228. {
  229. struct tcm_loop_hba *tl_hba;
  230. struct tcm_loop_tpg *tl_tpg;
  231. /*
  232. * Locate the tcm_loop_hba_t pointer
  233. */
  234. tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);
  235. if (!tl_hba) {
  236. pr_err("Unable to perform device reset without active I_T Nexus\n");
  237. return FAILED;
  238. }
  239. /*
  240. * Locate the tl_tpg pointer from TargetID in sc->device->id
  241. */
  242. tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];
  243. if (tl_tpg) {
  244. tl_tpg->tl_transport_status = TCM_TRANSPORT_ONLINE;
  245. return SUCCESS;
  246. }
  247. return FAILED;
  248. }
  249. static const struct scsi_host_template tcm_loop_driver_template = {
  250. .show_info = tcm_loop_show_info,
  251. .proc_name = "tcm_loopback",
  252. .name = "TCM_Loopback",
  253. .queuecommand = tcm_loop_queuecommand,
  254. .change_queue_depth = scsi_change_queue_depth,
  255. .eh_abort_handler = tcm_loop_abort_task,
  256. .eh_device_reset_handler = tcm_loop_device_reset,
  257. .eh_target_reset_handler = tcm_loop_target_reset,
  258. .this_id = -1,
  259. .sg_tablesize = 256,
  260. .max_sectors = 0xFFFF,
  261. .dma_boundary = PAGE_SIZE - 1,
  262. .module = THIS_MODULE,
  263. .track_queue_depth = 1,
  264. .cmd_size = sizeof(struct tcm_loop_cmd),
  265. };
  266. static int tcm_loop_driver_probe(struct device *dev)
  267. {
  268. struct tcm_loop_hba *tl_hba;
  269. struct Scsi_Host *sh;
  270. int error, host_prot;
  271. tl_hba = to_tcm_loop_hba(dev);
  272. sh = scsi_host_alloc(&tcm_loop_driver_template,
  273. sizeof(struct tcm_loop_hba));
  274. if (!sh) {
  275. pr_err("Unable to allocate struct scsi_host\n");
  276. return -ENODEV;
  277. }
  278. tl_hba->sh = sh;
  279. /*
  280. * Assign the struct tcm_loop_hba pointer to struct Scsi_Host->hostdata
  281. */
  282. *((struct tcm_loop_hba **)sh->hostdata) = tl_hba;
  283. /*
  284. * Setup single ID, Channel and LUN for now..
  285. */
  286. sh->max_id = 2;
  287. sh->max_lun = 0;
  288. sh->max_channel = 0;
  289. sh->max_cmd_len = SCSI_MAX_VARLEN_CDB_SIZE;
  290. sh->nr_hw_queues = tcm_loop_nr_hw_queues;
  291. sh->can_queue = tcm_loop_can_queue;
  292. sh->cmd_per_lun = tcm_loop_cmd_per_lun;
  293. host_prot = SHOST_DIF_TYPE1_PROTECTION | SHOST_DIF_TYPE2_PROTECTION |
  294. SHOST_DIF_TYPE3_PROTECTION | SHOST_DIX_TYPE1_PROTECTION |
  295. SHOST_DIX_TYPE2_PROTECTION | SHOST_DIX_TYPE3_PROTECTION;
  296. scsi_host_set_prot(sh, host_prot);
  297. scsi_host_set_guard(sh, SHOST_DIX_GUARD_CRC);
  298. error = scsi_add_host(sh, &tl_hba->dev);
  299. if (error) {
  300. pr_err("%s: scsi_add_host failed\n", __func__);
  301. scsi_host_put(sh);
  302. return -ENODEV;
  303. }
  304. return 0;
  305. }
  306. static void tcm_loop_driver_remove(struct device *dev)
  307. {
  308. struct tcm_loop_hba *tl_hba;
  309. struct Scsi_Host *sh;
  310. tl_hba = to_tcm_loop_hba(dev);
  311. sh = tl_hba->sh;
  312. scsi_remove_host(sh);
  313. scsi_host_put(sh);
  314. }
  315. static void tcm_loop_release_adapter(struct device *dev)
  316. {
  317. struct tcm_loop_hba *tl_hba = to_tcm_loop_hba(dev);
  318. kfree(tl_hba);
  319. }
  320. /*
  321. * Called from tcm_loop_make_scsi_hba() in tcm_loop_configfs.c
  322. */
  323. static int tcm_loop_setup_hba_bus(struct tcm_loop_hba *tl_hba, int tcm_loop_host_id)
  324. {
  325. int ret;
  326. tl_hba->dev.bus = &tcm_loop_lld_bus;
  327. tl_hba->dev.parent = tcm_loop_primary;
  328. tl_hba->dev.release = &tcm_loop_release_adapter;
  329. dev_set_name(&tl_hba->dev, "tcm_loop_adapter_%d", tcm_loop_host_id);
  330. ret = device_register(&tl_hba->dev);
  331. if (ret) {
  332. pr_err("device_register() failed for tl_hba->dev: %d\n", ret);
  333. put_device(&tl_hba->dev);
  334. return -ENODEV;
  335. }
  336. return 0;
  337. }
  338. /*
  339. * Called from tcm_loop_fabric_init() in tcl_loop_fabric.c to load the emulated
  340. * tcm_loop SCSI bus.
  341. */
  342. static int tcm_loop_alloc_core_bus(void)
  343. {
  344. int ret;
  345. tcm_loop_primary = root_device_register("tcm_loop_0");
  346. if (IS_ERR(tcm_loop_primary)) {
  347. pr_err("Unable to allocate tcm_loop_primary\n");
  348. return PTR_ERR(tcm_loop_primary);
  349. }
  350. ret = bus_register(&tcm_loop_lld_bus);
  351. if (ret) {
  352. pr_err("bus_register() failed for tcm_loop_lld_bus\n");
  353. goto dev_unreg;
  354. }
  355. ret = driver_register(&tcm_loop_driverfs);
  356. if (ret) {
  357. pr_err("driver_register() failed for tcm_loop_driverfs\n");
  358. goto bus_unreg;
  359. }
  360. pr_debug("Initialized TCM Loop Core Bus\n");
  361. return ret;
  362. bus_unreg:
  363. bus_unregister(&tcm_loop_lld_bus);
  364. dev_unreg:
  365. root_device_unregister(tcm_loop_primary);
  366. return ret;
  367. }
  368. static void tcm_loop_release_core_bus(void)
  369. {
  370. driver_unregister(&tcm_loop_driverfs);
  371. bus_unregister(&tcm_loop_lld_bus);
  372. root_device_unregister(tcm_loop_primary);
  373. pr_debug("Releasing TCM Loop Core BUS\n");
  374. }
  375. static inline struct tcm_loop_tpg *tl_tpg(struct se_portal_group *se_tpg)
  376. {
  377. return container_of(se_tpg, struct tcm_loop_tpg, tl_se_tpg);
  378. }
  379. static char *tcm_loop_get_endpoint_wwn(struct se_portal_group *se_tpg)
  380. {
  381. /*
  382. * Return the passed NAA identifier for the Target Port
  383. */
  384. return &tl_tpg(se_tpg)->tl_hba->tl_wwn_address[0];
  385. }
  386. static u16 tcm_loop_get_tag(struct se_portal_group *se_tpg)
  387. {
  388. /*
  389. * This Tag is used when forming SCSI Name identifier in EVPD=1 0x83
  390. * to represent the SCSI Target Port.
  391. */
  392. return tl_tpg(se_tpg)->tl_tpgt;
  393. }
  394. /*
  395. * Returning (1) here allows for target_core_mod struct se_node_acl to be generated
  396. * based upon the incoming fabric dependent SCSI Initiator Port
  397. */
  398. static int tcm_loop_check_demo_mode(struct se_portal_group *se_tpg)
  399. {
  400. return 1;
  401. }
  402. static int tcm_loop_check_prot_fabric_only(struct se_portal_group *se_tpg)
  403. {
  404. struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, struct tcm_loop_tpg,
  405. tl_se_tpg);
  406. return tl_tpg->tl_fabric_prot_type;
  407. }
  408. static u32 tcm_loop_sess_get_index(struct se_session *se_sess)
  409. {
  410. return 1;
  411. }
  412. static int tcm_loop_get_cmd_state(struct se_cmd *se_cmd)
  413. {
  414. struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
  415. struct tcm_loop_cmd, tl_se_cmd);
  416. return tl_cmd->sc_cmd_state;
  417. }
  418. static int tcm_loop_write_pending(struct se_cmd *se_cmd)
  419. {
  420. /*
  421. * Since Linux/SCSI has already sent down a struct scsi_cmnd
  422. * sc->sc_data_direction of DMA_TO_DEVICE with struct scatterlist array
  423. * memory, and memory has already been mapped to struct se_cmd->t_mem_list
  424. * format with transport_generic_map_mem_to_cmd().
  425. *
  426. * We now tell TCM to add this WRITE CDB directly into the TCM storage
  427. * object execution queue.
  428. */
  429. target_execute_cmd(se_cmd);
  430. return 0;
  431. }
  432. static int tcm_loop_queue_data_or_status(const char *func,
  433. struct se_cmd *se_cmd, u8 scsi_status)
  434. {
  435. struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
  436. struct tcm_loop_cmd, tl_se_cmd);
  437. struct scsi_cmnd *sc = tl_cmd->sc;
  438. pr_debug("%s() called for scsi_cmnd: %p cdb: 0x%02x\n",
  439. func, sc, sc->cmnd[0]);
  440. if (se_cmd->sense_buffer &&
  441. ((se_cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) ||
  442. (se_cmd->se_cmd_flags & SCF_EMULATED_TASK_SENSE))) {
  443. memcpy(sc->sense_buffer, se_cmd->sense_buffer,
  444. SCSI_SENSE_BUFFERSIZE);
  445. sc->result = SAM_STAT_CHECK_CONDITION;
  446. } else
  447. sc->result = scsi_status;
  448. set_host_byte(sc, DID_OK);
  449. if ((se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) ||
  450. (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT))
  451. scsi_set_resid(sc, se_cmd->residual_count);
  452. return 0;
  453. }
  454. static int tcm_loop_queue_data_in(struct se_cmd *se_cmd)
  455. {
  456. return tcm_loop_queue_data_or_status(__func__, se_cmd, SAM_STAT_GOOD);
  457. }
  458. static int tcm_loop_queue_status(struct se_cmd *se_cmd)
  459. {
  460. return tcm_loop_queue_data_or_status(__func__,
  461. se_cmd, se_cmd->scsi_status);
  462. }
  463. static void tcm_loop_queue_tm_rsp(struct se_cmd *se_cmd)
  464. {
  465. struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
  466. struct tcm_loop_cmd, tl_se_cmd);
  467. /* Wake up tcm_loop_issue_tmr(). */
  468. complete(&tl_cmd->tmr_done);
  469. }
  470. static void tcm_loop_aborted_task(struct se_cmd *se_cmd)
  471. {
  472. return;
  473. }
  474. static char *tcm_loop_dump_proto_id(struct tcm_loop_hba *tl_hba)
  475. {
  476. switch (tl_hba->tl_proto_id) {
  477. case SCSI_PROTOCOL_SAS:
  478. return "SAS";
  479. case SCSI_PROTOCOL_FCP:
  480. return "FCP";
  481. case SCSI_PROTOCOL_ISCSI:
  482. return "iSCSI";
  483. default:
  484. break;
  485. }
  486. return "Unknown";
  487. }
  488. /* Start items for tcm_loop_port_cit */
  489. static int tcm_loop_port_link(
  490. struct se_portal_group *se_tpg,
  491. struct se_lun *lun)
  492. {
  493. struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
  494. struct tcm_loop_tpg, tl_se_tpg);
  495. struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
  496. atomic_inc_mb(&tl_tpg->tl_tpg_port_count);
  497. /*
  498. * Add Linux/SCSI struct scsi_device by HCTL
  499. */
  500. scsi_add_device(tl_hba->sh, 0, tl_tpg->tl_tpgt, lun->unpacked_lun);
  501. pr_debug("TCM_Loop_ConfigFS: Port Link Successful\n");
  502. return 0;
  503. }
  504. static void tcm_loop_port_unlink(
  505. struct se_portal_group *se_tpg,
  506. struct se_lun *se_lun)
  507. {
  508. struct scsi_device *sd;
  509. struct tcm_loop_hba *tl_hba;
  510. struct tcm_loop_tpg *tl_tpg;
  511. tl_tpg = container_of(se_tpg, struct tcm_loop_tpg, tl_se_tpg);
  512. tl_hba = tl_tpg->tl_hba;
  513. sd = scsi_device_lookup(tl_hba->sh, 0, tl_tpg->tl_tpgt,
  514. se_lun->unpacked_lun);
  515. if (!sd) {
  516. pr_err("Unable to locate struct scsi_device for %d:%d:%llu\n",
  517. 0, tl_tpg->tl_tpgt, se_lun->unpacked_lun);
  518. return;
  519. }
  520. /*
  521. * Remove Linux/SCSI struct scsi_device by HCTL
  522. */
  523. scsi_remove_device(sd);
  524. scsi_device_put(sd);
  525. atomic_dec_mb(&tl_tpg->tl_tpg_port_count);
  526. pr_debug("TCM_Loop_ConfigFS: Port Unlink Successful\n");
  527. }
  528. /* End items for tcm_loop_port_cit */
  529. static ssize_t tcm_loop_tpg_attrib_fabric_prot_type_show(
  530. struct config_item *item, char *page)
  531. {
  532. struct se_portal_group *se_tpg = attrib_to_tpg(item);
  533. struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, struct tcm_loop_tpg,
  534. tl_se_tpg);
  535. return sprintf(page, "%d\n", tl_tpg->tl_fabric_prot_type);
  536. }
  537. static ssize_t tcm_loop_tpg_attrib_fabric_prot_type_store(
  538. struct config_item *item, const char *page, size_t count)
  539. {
  540. struct se_portal_group *se_tpg = attrib_to_tpg(item);
  541. struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, struct tcm_loop_tpg,
  542. tl_se_tpg);
  543. unsigned long val;
  544. int ret = kstrtoul(page, 0, &val);
  545. if (ret) {
  546. pr_err("kstrtoul() returned %d for fabric_prot_type\n", ret);
  547. return ret;
  548. }
  549. if (val != 0 && val != 1 && val != 3) {
  550. pr_err("Invalid qla2xxx fabric_prot_type: %lu\n", val);
  551. return -EINVAL;
  552. }
  553. tl_tpg->tl_fabric_prot_type = val;
  554. return count;
  555. }
  556. CONFIGFS_ATTR(tcm_loop_tpg_attrib_, fabric_prot_type);
  557. static struct configfs_attribute *tcm_loop_tpg_attrib_attrs[] = {
  558. &tcm_loop_tpg_attrib_attr_fabric_prot_type,
  559. NULL,
  560. };
  561. /* Start items for tcm_loop_nexus_cit */
  562. static int tcm_loop_alloc_sess_cb(struct se_portal_group *se_tpg,
  563. struct se_session *se_sess, void *p)
  564. {
  565. struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
  566. struct tcm_loop_tpg, tl_se_tpg);
  567. tl_tpg->tl_nexus = p;
  568. return 0;
  569. }
  570. static int tcm_loop_make_nexus(
  571. struct tcm_loop_tpg *tl_tpg,
  572. const char *name)
  573. {
  574. struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
  575. struct tcm_loop_nexus *tl_nexus;
  576. int ret;
  577. if (tl_tpg->tl_nexus) {
  578. pr_debug("tl_tpg->tl_nexus already exists\n");
  579. return -EEXIST;
  580. }
  581. tl_nexus = kzalloc(sizeof(*tl_nexus), GFP_KERNEL);
  582. if (!tl_nexus)
  583. return -ENOMEM;
  584. tl_nexus->se_sess = target_setup_session(&tl_tpg->tl_se_tpg, 0, 0,
  585. TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS,
  586. name, tl_nexus, tcm_loop_alloc_sess_cb);
  587. if (IS_ERR(tl_nexus->se_sess)) {
  588. ret = PTR_ERR(tl_nexus->se_sess);
  589. kfree(tl_nexus);
  590. return ret;
  591. }
  592. pr_debug("TCM_Loop_ConfigFS: Established I_T Nexus to emulated %s Initiator Port: %s\n",
  593. tcm_loop_dump_proto_id(tl_hba), name);
  594. return 0;
  595. }
  596. static int tcm_loop_drop_nexus(
  597. struct tcm_loop_tpg *tpg)
  598. {
  599. struct se_session *se_sess;
  600. struct tcm_loop_nexus *tl_nexus;
  601. tl_nexus = tpg->tl_nexus;
  602. if (!tl_nexus)
  603. return -ENODEV;
  604. se_sess = tl_nexus->se_sess;
  605. if (!se_sess)
  606. return -ENODEV;
  607. if (atomic_read(&tpg->tl_tpg_port_count)) {
  608. pr_err("Unable to remove TCM_Loop I_T Nexus with active TPG port count: %d\n",
  609. atomic_read(&tpg->tl_tpg_port_count));
  610. return -EPERM;
  611. }
  612. pr_debug("TCM_Loop_ConfigFS: Removing I_T Nexus to emulated %s Initiator Port: %s\n",
  613. tcm_loop_dump_proto_id(tpg->tl_hba),
  614. tl_nexus->se_sess->se_node_acl->initiatorname);
  615. /*
  616. * Release the SCSI I_T Nexus to the emulated Target Port
  617. */
  618. target_remove_session(se_sess);
  619. tpg->tl_nexus = NULL;
  620. kfree(tl_nexus);
  621. return 0;
  622. }
  623. /* End items for tcm_loop_nexus_cit */
  624. static ssize_t tcm_loop_tpg_nexus_show(struct config_item *item, char *page)
  625. {
  626. struct se_portal_group *se_tpg = to_tpg(item);
  627. struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
  628. struct tcm_loop_tpg, tl_se_tpg);
  629. struct tcm_loop_nexus *tl_nexus;
  630. ssize_t ret;
  631. tl_nexus = tl_tpg->tl_nexus;
  632. if (!tl_nexus)
  633. return -ENODEV;
  634. ret = snprintf(page, PAGE_SIZE, "%s\n",
  635. tl_nexus->se_sess->se_node_acl->initiatorname);
  636. return ret;
  637. }
  638. static ssize_t tcm_loop_tpg_nexus_store(struct config_item *item,
  639. const char *page, size_t count)
  640. {
  641. struct se_portal_group *se_tpg = to_tpg(item);
  642. struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
  643. struct tcm_loop_tpg, tl_se_tpg);
  644. struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
  645. unsigned char i_port[TL_WWN_ADDR_LEN], *ptr, *port_ptr;
  646. int ret;
  647. /*
  648. * Shutdown the active I_T nexus if 'NULL' is passed..
  649. */
  650. if (!strncmp(page, "NULL", 4)) {
  651. ret = tcm_loop_drop_nexus(tl_tpg);
  652. return (!ret) ? count : ret;
  653. }
  654. /*
  655. * Otherwise make sure the passed virtual Initiator port WWN matches
  656. * the fabric protocol_id set in tcm_loop_make_scsi_hba(), and call
  657. * tcm_loop_make_nexus()
  658. */
  659. if (strlen(page) >= TL_WWN_ADDR_LEN) {
  660. pr_err("Emulated NAA Sas Address: %s, exceeds max: %d\n",
  661. page, TL_WWN_ADDR_LEN);
  662. return -EINVAL;
  663. }
  664. snprintf(&i_port[0], TL_WWN_ADDR_LEN, "%s", page);
  665. ptr = strstr(i_port, "naa.");
  666. if (ptr) {
  667. if (tl_hba->tl_proto_id != SCSI_PROTOCOL_SAS) {
  668. pr_err("Passed SAS Initiator Port %s does not match target port protoid: %s\n",
  669. i_port, tcm_loop_dump_proto_id(tl_hba));
  670. return -EINVAL;
  671. }
  672. port_ptr = &i_port[0];
  673. goto check_newline;
  674. }
  675. ptr = strstr(i_port, "fc.");
  676. if (ptr) {
  677. if (tl_hba->tl_proto_id != SCSI_PROTOCOL_FCP) {
  678. pr_err("Passed FCP Initiator Port %s does not match target port protoid: %s\n",
  679. i_port, tcm_loop_dump_proto_id(tl_hba));
  680. return -EINVAL;
  681. }
  682. port_ptr = &i_port[3]; /* Skip over "fc." */
  683. goto check_newline;
  684. }
  685. ptr = strstr(i_port, "iqn.");
  686. if (ptr) {
  687. if (tl_hba->tl_proto_id != SCSI_PROTOCOL_ISCSI) {
  688. pr_err("Passed iSCSI Initiator Port %s does not match target port protoid: %s\n",
  689. i_port, tcm_loop_dump_proto_id(tl_hba));
  690. return -EINVAL;
  691. }
  692. port_ptr = &i_port[0];
  693. goto check_newline;
  694. }
  695. pr_err("Unable to locate prefix for emulated Initiator Port: %s\n",
  696. i_port);
  697. return -EINVAL;
  698. /*
  699. * Clear any trailing newline for the NAA WWN
  700. */
  701. check_newline:
  702. if (i_port[strlen(i_port)-1] == '\n')
  703. i_port[strlen(i_port)-1] = '\0';
  704. ret = tcm_loop_make_nexus(tl_tpg, port_ptr);
  705. if (ret < 0)
  706. return ret;
  707. return count;
  708. }
  709. static ssize_t tcm_loop_tpg_transport_status_show(struct config_item *item,
  710. char *page)
  711. {
  712. struct se_portal_group *se_tpg = to_tpg(item);
  713. struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
  714. struct tcm_loop_tpg, tl_se_tpg);
  715. const char *status = NULL;
  716. ssize_t ret = -EINVAL;
  717. switch (tl_tpg->tl_transport_status) {
  718. case TCM_TRANSPORT_ONLINE:
  719. status = "online";
  720. break;
  721. case TCM_TRANSPORT_OFFLINE:
  722. status = "offline";
  723. break;
  724. default:
  725. break;
  726. }
  727. if (status)
  728. ret = snprintf(page, PAGE_SIZE, "%s\n", status);
  729. return ret;
  730. }
  731. static ssize_t tcm_loop_tpg_transport_status_store(struct config_item *item,
  732. const char *page, size_t count)
  733. {
  734. struct se_portal_group *se_tpg = to_tpg(item);
  735. struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
  736. struct tcm_loop_tpg, tl_se_tpg);
  737. if (!strncmp(page, "online", 6)) {
  738. tl_tpg->tl_transport_status = TCM_TRANSPORT_ONLINE;
  739. return count;
  740. }
  741. if (!strncmp(page, "offline", 7)) {
  742. tl_tpg->tl_transport_status = TCM_TRANSPORT_OFFLINE;
  743. if (tl_tpg->tl_nexus) {
  744. struct se_session *tl_sess = tl_tpg->tl_nexus->se_sess;
  745. core_allocate_nexus_loss_ua(tl_sess->se_node_acl);
  746. }
  747. return count;
  748. }
  749. return -EINVAL;
  750. }
  751. static ssize_t tcm_loop_tpg_address_show(struct config_item *item,
  752. char *page)
  753. {
  754. struct se_portal_group *se_tpg = to_tpg(item);
  755. struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
  756. struct tcm_loop_tpg, tl_se_tpg);
  757. struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
  758. return snprintf(page, PAGE_SIZE, "%d:0:%d\n",
  759. tl_hba->sh->host_no, tl_tpg->tl_tpgt);
  760. }
  761. CONFIGFS_ATTR(tcm_loop_tpg_, nexus);
  762. CONFIGFS_ATTR(tcm_loop_tpg_, transport_status);
  763. CONFIGFS_ATTR_RO(tcm_loop_tpg_, address);
  764. static struct configfs_attribute *tcm_loop_tpg_attrs[] = {
  765. &tcm_loop_tpg_attr_nexus,
  766. &tcm_loop_tpg_attr_transport_status,
  767. &tcm_loop_tpg_attr_address,
  768. NULL,
  769. };
  770. /* Start items for tcm_loop_naa_cit */
  771. static struct se_portal_group *tcm_loop_make_naa_tpg(struct se_wwn *wwn,
  772. const char *name)
  773. {
  774. struct tcm_loop_hba *tl_hba = container_of(wwn,
  775. struct tcm_loop_hba, tl_hba_wwn);
  776. struct tcm_loop_tpg *tl_tpg;
  777. int ret;
  778. unsigned long tpgt;
  779. if (strstr(name, "tpgt_") != name) {
  780. pr_err("Unable to locate \"tpgt_#\" directory group\n");
  781. return ERR_PTR(-EINVAL);
  782. }
  783. if (kstrtoul(name+5, 10, &tpgt))
  784. return ERR_PTR(-EINVAL);
  785. if (tpgt >= TL_TPGS_PER_HBA) {
  786. pr_err("Passed tpgt: %lu exceeds TL_TPGS_PER_HBA: %u\n",
  787. tpgt, TL_TPGS_PER_HBA);
  788. return ERR_PTR(-EINVAL);
  789. }
  790. tl_tpg = &tl_hba->tl_hba_tpgs[tpgt];
  791. tl_tpg->tl_hba = tl_hba;
  792. tl_tpg->tl_tpgt = tpgt;
  793. /*
  794. * Register the tl_tpg as a emulated TCM Target Endpoint
  795. */
  796. ret = core_tpg_register(wwn, &tl_tpg->tl_se_tpg, tl_hba->tl_proto_id);
  797. if (ret < 0)
  798. return ERR_PTR(-ENOMEM);
  799. pr_debug("TCM_Loop_ConfigFS: Allocated Emulated %s Target Port %s,t,0x%04lx\n",
  800. tcm_loop_dump_proto_id(tl_hba),
  801. config_item_name(&wwn->wwn_group.cg_item), tpgt);
  802. return &tl_tpg->tl_se_tpg;
  803. }
  804. static void tcm_loop_drop_naa_tpg(
  805. struct se_portal_group *se_tpg)
  806. {
  807. struct se_wwn *wwn = se_tpg->se_tpg_wwn;
  808. struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
  809. struct tcm_loop_tpg, tl_se_tpg);
  810. struct tcm_loop_hba *tl_hba;
  811. unsigned short tpgt;
  812. tl_hba = tl_tpg->tl_hba;
  813. tpgt = tl_tpg->tl_tpgt;
  814. /*
  815. * Release the I_T Nexus for the Virtual target link if present
  816. */
  817. tcm_loop_drop_nexus(tl_tpg);
  818. /*
  819. * Deregister the tl_tpg as a emulated TCM Target Endpoint
  820. */
  821. core_tpg_deregister(se_tpg);
  822. tl_tpg->tl_hba = NULL;
  823. tl_tpg->tl_tpgt = 0;
  824. pr_debug("TCM_Loop_ConfigFS: Deallocated Emulated %s Target Port %s,t,0x%04x\n",
  825. tcm_loop_dump_proto_id(tl_hba),
  826. config_item_name(&wwn->wwn_group.cg_item), tpgt);
  827. }
  828. /* End items for tcm_loop_naa_cit */
  829. /* Start items for tcm_loop_cit */
  830. static struct se_wwn *tcm_loop_make_scsi_hba(
  831. struct target_fabric_configfs *tf,
  832. struct config_group *group,
  833. const char *name)
  834. {
  835. struct tcm_loop_hba *tl_hba;
  836. struct Scsi_Host *sh;
  837. char *ptr;
  838. int ret, off = 0;
  839. tl_hba = kzalloc(sizeof(*tl_hba), GFP_KERNEL);
  840. if (!tl_hba)
  841. return ERR_PTR(-ENOMEM);
  842. /*
  843. * Determine the emulated Protocol Identifier and Target Port Name
  844. * based on the incoming configfs directory name.
  845. */
  846. ptr = strstr(name, "naa.");
  847. if (ptr) {
  848. tl_hba->tl_proto_id = SCSI_PROTOCOL_SAS;
  849. goto check_len;
  850. }
  851. ptr = strstr(name, "fc.");
  852. if (ptr) {
  853. tl_hba->tl_proto_id = SCSI_PROTOCOL_FCP;
  854. off = 3; /* Skip over "fc." */
  855. goto check_len;
  856. }
  857. ptr = strstr(name, "iqn.");
  858. if (!ptr) {
  859. pr_err("Unable to locate prefix for emulated Target Port: %s\n",
  860. name);
  861. ret = -EINVAL;
  862. goto out;
  863. }
  864. tl_hba->tl_proto_id = SCSI_PROTOCOL_ISCSI;
  865. check_len:
  866. if (strlen(name) >= TL_WWN_ADDR_LEN) {
  867. pr_err("Emulated NAA %s Address: %s, exceeds max: %d\n",
  868. name, tcm_loop_dump_proto_id(tl_hba), TL_WWN_ADDR_LEN);
  869. ret = -EINVAL;
  870. goto out;
  871. }
  872. snprintf(&tl_hba->tl_wwn_address[0], TL_WWN_ADDR_LEN, "%s", &name[off]);
  873. /*
  874. * Call device_register(tl_hba->dev) to register the emulated
  875. * Linux/SCSI LLD of type struct Scsi_Host at tl_hba->sh after
  876. * device_register() callbacks in tcm_loop_driver_probe()
  877. */
  878. ret = tcm_loop_setup_hba_bus(tl_hba, tcm_loop_hba_no_cnt);
  879. if (ret)
  880. return ERR_PTR(ret);
  881. sh = tl_hba->sh;
  882. tcm_loop_hba_no_cnt++;
  883. pr_debug("TCM_Loop_ConfigFS: Allocated emulated Target %s Address: %s at Linux/SCSI Host ID: %d\n",
  884. tcm_loop_dump_proto_id(tl_hba), name, sh->host_no);
  885. return &tl_hba->tl_hba_wwn;
  886. out:
  887. kfree(tl_hba);
  888. return ERR_PTR(ret);
  889. }
  890. static void tcm_loop_drop_scsi_hba(
  891. struct se_wwn *wwn)
  892. {
  893. struct tcm_loop_hba *tl_hba = container_of(wwn,
  894. struct tcm_loop_hba, tl_hba_wwn);
  895. pr_debug("TCM_Loop_ConfigFS: Deallocating emulated Target %s Address: %s at Linux/SCSI Host ID: %d\n",
  896. tcm_loop_dump_proto_id(tl_hba), tl_hba->tl_wwn_address,
  897. tl_hba->sh->host_no);
  898. /*
  899. * Call device_unregister() on the original tl_hba->dev.
  900. * tcm_loop_fabric_scsi.c:tcm_loop_release_adapter() will
  901. * release *tl_hba;
  902. */
  903. device_unregister(&tl_hba->dev);
  904. }
  905. /* Start items for tcm_loop_cit */
  906. static ssize_t tcm_loop_wwn_version_show(struct config_item *item, char *page)
  907. {
  908. return sprintf(page, "TCM Loopback Fabric module %s\n", TCM_LOOP_VERSION);
  909. }
  910. CONFIGFS_ATTR_RO(tcm_loop_wwn_, version);
  911. static struct configfs_attribute *tcm_loop_wwn_attrs[] = {
  912. &tcm_loop_wwn_attr_version,
  913. NULL,
  914. };
  915. /* End items for tcm_loop_cit */
  916. static const struct target_core_fabric_ops loop_ops = {
  917. .module = THIS_MODULE,
  918. .fabric_name = "loopback",
  919. .tpg_get_wwn = tcm_loop_get_endpoint_wwn,
  920. .tpg_get_tag = tcm_loop_get_tag,
  921. .tpg_check_demo_mode = tcm_loop_check_demo_mode,
  922. .tpg_check_prot_fabric_only = tcm_loop_check_prot_fabric_only,
  923. .check_stop_free = tcm_loop_check_stop_free,
  924. .release_cmd = tcm_loop_release_cmd,
  925. .sess_get_index = tcm_loop_sess_get_index,
  926. .write_pending = tcm_loop_write_pending,
  927. .get_cmd_state = tcm_loop_get_cmd_state,
  928. .queue_data_in = tcm_loop_queue_data_in,
  929. .queue_status = tcm_loop_queue_status,
  930. .queue_tm_rsp = tcm_loop_queue_tm_rsp,
  931. .aborted_task = tcm_loop_aborted_task,
  932. .fabric_make_wwn = tcm_loop_make_scsi_hba,
  933. .fabric_drop_wwn = tcm_loop_drop_scsi_hba,
  934. .fabric_make_tpg = tcm_loop_make_naa_tpg,
  935. .fabric_drop_tpg = tcm_loop_drop_naa_tpg,
  936. .fabric_post_link = tcm_loop_port_link,
  937. .fabric_pre_unlink = tcm_loop_port_unlink,
  938. .tfc_wwn_attrs = tcm_loop_wwn_attrs,
  939. .tfc_tpg_base_attrs = tcm_loop_tpg_attrs,
  940. .tfc_tpg_attrib_attrs = tcm_loop_tpg_attrib_attrs,
  941. .default_submit_type = TARGET_QUEUE_SUBMIT,
  942. .direct_submit_supp = 0,
  943. };
  944. static int __init tcm_loop_fabric_init(void)
  945. {
  946. int ret = -ENOMEM;
  947. tcm_loop_cmd_cache = kmem_cache_create("tcm_loop_cmd_cache",
  948. sizeof(struct tcm_loop_cmd),
  949. __alignof__(struct tcm_loop_cmd),
  950. 0, NULL);
  951. if (!tcm_loop_cmd_cache) {
  952. pr_debug("kmem_cache_create() for tcm_loop_cmd_cache failed\n");
  953. goto out;
  954. }
  955. ret = tcm_loop_alloc_core_bus();
  956. if (ret)
  957. goto out_destroy_cache;
  958. ret = target_register_template(&loop_ops);
  959. if (ret)
  960. goto out_release_core_bus;
  961. return 0;
  962. out_release_core_bus:
  963. tcm_loop_release_core_bus();
  964. out_destroy_cache:
  965. kmem_cache_destroy(tcm_loop_cmd_cache);
  966. out:
  967. return ret;
  968. }
  969. static void __exit tcm_loop_fabric_exit(void)
  970. {
  971. target_unregister_template(&loop_ops);
  972. tcm_loop_release_core_bus();
  973. kmem_cache_destroy(tcm_loop_cmd_cache);
  974. }
  975. MODULE_DESCRIPTION("TCM loopback virtual Linux/SCSI fabric module");
  976. MODULE_AUTHOR("Nicholas A. Bellinger <nab@risingtidesystems.com>");
  977. MODULE_LICENSE("GPL");
  978. module_init(tcm_loop_fabric_init);
  979. module_exit(tcm_loop_fabric_exit);