efct_lio.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2021 Broadcom. All Rights Reserved. The term
  4. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
  5. */
  6. #include <target/target_core_base.h>
  7. #include <target/target_core_fabric.h>
  8. #include "efct_driver.h"
  9. #include "efct_lio.h"
  10. /*
  11. * lio_wq is used to call the LIO backed during creation or deletion of
  12. * sessions. This brings serialization to the session management as we create
  13. * single threaded work queue.
  14. */
  15. static struct workqueue_struct *lio_wq;
  16. static int
  17. efct_format_wwn(char *str, size_t len, const char *pre, u64 wwn)
  18. {
  19. u8 a[8];
  20. put_unaligned_be64(wwn, a);
  21. return snprintf(str, len, "%s%8phC", pre, a);
  22. }
  23. static int
  24. efct_lio_parse_wwn(const char *name, u64 *wwp, u8 npiv)
  25. {
  26. int num;
  27. u8 b[8];
  28. if (npiv) {
  29. num = sscanf(name,
  30. "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
  31. &b[0], &b[1], &b[2], &b[3], &b[4], &b[5], &b[6],
  32. &b[7]);
  33. } else {
  34. num = sscanf(name,
  35. "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
  36. &b[0], &b[1], &b[2], &b[3], &b[4], &b[5], &b[6],
  37. &b[7]);
  38. }
  39. if (num != 8)
  40. return -EINVAL;
  41. *wwp = get_unaligned_be64(b);
  42. return 0;
  43. }
  44. static int
  45. efct_lio_parse_npiv_wwn(const char *name, size_t size, u64 *wwpn, u64 *wwnn)
  46. {
  47. unsigned int cnt = size;
  48. int rc;
  49. *wwpn = *wwnn = 0;
  50. if (name[cnt - 1] == '\n' || name[cnt - 1] == 0)
  51. cnt--;
  52. /* validate we have enough characters for WWPN */
  53. if ((cnt != (16 + 1 + 16)) || (name[16] != ':'))
  54. return -EINVAL;
  55. rc = efct_lio_parse_wwn(&name[0], wwpn, 1);
  56. if (rc)
  57. return rc;
  58. rc = efct_lio_parse_wwn(&name[17], wwnn, 1);
  59. if (rc)
  60. return rc;
  61. return 0;
  62. }
  63. static ssize_t
  64. efct_lio_tpg_enable_show(struct config_item *item, char *page)
  65. {
  66. struct se_portal_group *se_tpg = to_tpg(item);
  67. struct efct_lio_tpg *tpg =
  68. container_of(se_tpg, struct efct_lio_tpg, tpg);
  69. return snprintf(page, PAGE_SIZE, "%d\n", tpg->enabled);
  70. }
  71. static ssize_t
  72. efct_lio_tpg_enable_store(struct config_item *item, const char *page,
  73. size_t count)
  74. {
  75. struct se_portal_group *se_tpg = to_tpg(item);
  76. struct efct_lio_tpg *tpg =
  77. container_of(se_tpg, struct efct_lio_tpg, tpg);
  78. struct efct *efct;
  79. struct efc *efc;
  80. unsigned long op;
  81. if (!tpg->nport || !tpg->nport->efct) {
  82. pr_err("%s: Unable to find EFCT device\n", __func__);
  83. return -EINVAL;
  84. }
  85. efct = tpg->nport->efct;
  86. efc = efct->efcport;
  87. if (kstrtoul(page, 0, &op) < 0)
  88. return -EINVAL;
  89. if (op == 1) {
  90. int ret;
  91. tpg->enabled = true;
  92. efc_log_debug(efct, "enable portal group %d\n", tpg->tpgt);
  93. ret = efct_xport_control(efct->xport, EFCT_XPORT_PORT_ONLINE);
  94. if (ret) {
  95. efct->tgt_efct.lio_nport = NULL;
  96. efc_log_debug(efct, "cannot bring port online\n");
  97. return ret;
  98. }
  99. } else if (op == 0) {
  100. efc_log_debug(efct, "disable portal group %d\n", tpg->tpgt);
  101. if (efc->domain && efc->domain->nport)
  102. efct_scsi_tgt_del_nport(efc, efc->domain->nport);
  103. tpg->enabled = false;
  104. } else {
  105. return -EINVAL;
  106. }
  107. return count;
  108. }
  109. static ssize_t
  110. efct_lio_npiv_tpg_enable_show(struct config_item *item, char *page)
  111. {
  112. struct se_portal_group *se_tpg = to_tpg(item);
  113. struct efct_lio_tpg *tpg =
  114. container_of(se_tpg, struct efct_lio_tpg, tpg);
  115. return snprintf(page, PAGE_SIZE, "%d\n", tpg->enabled);
  116. }
  117. static ssize_t
  118. efct_lio_npiv_tpg_enable_store(struct config_item *item, const char *page,
  119. size_t count)
  120. {
  121. struct se_portal_group *se_tpg = to_tpg(item);
  122. struct efct_lio_tpg *tpg =
  123. container_of(se_tpg, struct efct_lio_tpg, tpg);
  124. struct efct_lio_vport *lio_vport = tpg->vport;
  125. struct efct *efct;
  126. struct efc *efc;
  127. unsigned long op;
  128. if (kstrtoul(page, 0, &op) < 0)
  129. return -EINVAL;
  130. if (!lio_vport) {
  131. pr_err("Unable to find vport\n");
  132. return -EINVAL;
  133. }
  134. efct = lio_vport->efct;
  135. efc = efct->efcport;
  136. if (op == 1) {
  137. tpg->enabled = true;
  138. efc_log_debug(efct, "enable portal group %d\n", tpg->tpgt);
  139. if (efc->domain) {
  140. int ret;
  141. ret = efc_nport_vport_new(efc->domain,
  142. lio_vport->npiv_wwpn,
  143. lio_vport->npiv_wwnn,
  144. U32_MAX, false, true,
  145. NULL, NULL);
  146. if (ret != 0) {
  147. efc_log_err(efct, "Failed to create Vport\n");
  148. return ret;
  149. }
  150. return count;
  151. }
  152. if (!(efc_vport_create_spec(efc, lio_vport->npiv_wwnn,
  153. lio_vport->npiv_wwpn, U32_MAX,
  154. false, true, NULL, NULL)))
  155. return -ENOMEM;
  156. } else if (op == 0) {
  157. efc_log_debug(efct, "disable portal group %d\n", tpg->tpgt);
  158. tpg->enabled = false;
  159. /* only physical nport should exist, free lio_nport
  160. * allocated in efct_lio_make_nport
  161. */
  162. if (efc->domain) {
  163. efc_nport_vport_del(efct->efcport, efc->domain,
  164. lio_vport->npiv_wwpn,
  165. lio_vport->npiv_wwnn);
  166. return count;
  167. }
  168. } else {
  169. return -EINVAL;
  170. }
  171. return count;
  172. }
  173. static char *efct_lio_get_fabric_wwn(struct se_portal_group *se_tpg)
  174. {
  175. struct efct_lio_tpg *tpg =
  176. container_of(se_tpg, struct efct_lio_tpg, tpg);
  177. return tpg->nport->wwpn_str;
  178. }
  179. static char *efct_lio_get_npiv_fabric_wwn(struct se_portal_group *se_tpg)
  180. {
  181. struct efct_lio_tpg *tpg =
  182. container_of(se_tpg, struct efct_lio_tpg, tpg);
  183. return tpg->vport->wwpn_str;
  184. }
  185. static u16 efct_lio_get_tag(struct se_portal_group *se_tpg)
  186. {
  187. struct efct_lio_tpg *tpg =
  188. container_of(se_tpg, struct efct_lio_tpg, tpg);
  189. return tpg->tpgt;
  190. }
  191. static u16 efct_lio_get_npiv_tag(struct se_portal_group *se_tpg)
  192. {
  193. struct efct_lio_tpg *tpg =
  194. container_of(se_tpg, struct efct_lio_tpg, tpg);
  195. return tpg->tpgt;
  196. }
  197. static int efct_lio_check_demo_mode(struct se_portal_group *se_tpg)
  198. {
  199. return 1;
  200. }
  201. static int efct_lio_check_demo_mode_cache(struct se_portal_group *se_tpg)
  202. {
  203. return 1;
  204. }
  205. static int efct_lio_check_demo_write_protect(struct se_portal_group *se_tpg)
  206. {
  207. struct efct_lio_tpg *tpg =
  208. container_of(se_tpg, struct efct_lio_tpg, tpg);
  209. return tpg->tpg_attrib.demo_mode_write_protect;
  210. }
  211. static int
  212. efct_lio_npiv_check_demo_write_protect(struct se_portal_group *se_tpg)
  213. {
  214. struct efct_lio_tpg *tpg =
  215. container_of(se_tpg, struct efct_lio_tpg, tpg);
  216. return tpg->tpg_attrib.demo_mode_write_protect;
  217. }
  218. static int efct_lio_check_prod_write_protect(struct se_portal_group *se_tpg)
  219. {
  220. struct efct_lio_tpg *tpg =
  221. container_of(se_tpg, struct efct_lio_tpg, tpg);
  222. return tpg->tpg_attrib.prod_mode_write_protect;
  223. }
  224. static int
  225. efct_lio_npiv_check_prod_write_protect(struct se_portal_group *se_tpg)
  226. {
  227. struct efct_lio_tpg *tpg =
  228. container_of(se_tpg, struct efct_lio_tpg, tpg);
  229. return tpg->tpg_attrib.prod_mode_write_protect;
  230. }
  231. static int efct_lio_check_stop_free(struct se_cmd *se_cmd)
  232. {
  233. struct efct_scsi_tgt_io *ocp =
  234. container_of(se_cmd, struct efct_scsi_tgt_io, cmd);
  235. struct efct_io *io = container_of(ocp, struct efct_io, tgt_io);
  236. efct_set_lio_io_state(io, EFCT_LIO_STATE_TFO_CHK_STOP_FREE);
  237. return target_put_sess_cmd(se_cmd);
  238. }
  239. static int
  240. efct_lio_abort_tgt_cb(struct efct_io *io,
  241. enum efct_scsi_io_status scsi_status,
  242. u32 flags, void *arg)
  243. {
  244. efct_lio_io_printf(io, "Abort done, status:%d\n", scsi_status);
  245. return 0;
  246. }
  247. static void
  248. efct_lio_aborted_task(struct se_cmd *se_cmd)
  249. {
  250. struct efct_scsi_tgt_io *ocp =
  251. container_of(se_cmd, struct efct_scsi_tgt_io, cmd);
  252. struct efct_io *io = container_of(ocp, struct efct_io, tgt_io);
  253. efct_set_lio_io_state(io, EFCT_LIO_STATE_TFO_ABORTED_TASK);
  254. if (ocp->rsp_sent)
  255. return;
  256. /* command has been aborted, cleanup here */
  257. ocp->aborting = true;
  258. ocp->err = EFCT_SCSI_STATUS_ABORTED;
  259. /* terminate the exchange */
  260. efct_scsi_tgt_abort_io(io, efct_lio_abort_tgt_cb, NULL);
  261. }
  262. static void efct_lio_release_cmd(struct se_cmd *se_cmd)
  263. {
  264. struct efct_scsi_tgt_io *ocp =
  265. container_of(se_cmd, struct efct_scsi_tgt_io, cmd);
  266. struct efct_io *io = container_of(ocp, struct efct_io, tgt_io);
  267. struct efct *efct = io->efct;
  268. efct_set_lio_io_state(io, EFCT_LIO_STATE_TFO_RELEASE_CMD);
  269. efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_CMPL_CMD);
  270. efct_scsi_io_complete(io);
  271. atomic_sub_return(1, &efct->tgt_efct.ios_in_use);
  272. }
  273. static void efct_lio_close_session(struct se_session *se_sess)
  274. {
  275. struct efc_node *node = se_sess->fabric_sess_ptr;
  276. pr_debug("se_sess=%p node=%p", se_sess, node);
  277. if (!node) {
  278. pr_debug("node is NULL");
  279. return;
  280. }
  281. efc_node_post_shutdown(node, NULL);
  282. }
  283. static int efct_lio_get_cmd_state(struct se_cmd *cmd)
  284. {
  285. struct efct_scsi_tgt_io *ocp =
  286. container_of(cmd, struct efct_scsi_tgt_io, cmd);
  287. struct efct_io *io = container_of(ocp, struct efct_io, tgt_io);
  288. return io->tgt_io.state;
  289. }
  290. static int
  291. efct_lio_sg_map(struct efct_io *io)
  292. {
  293. struct efct_scsi_tgt_io *ocp = &io->tgt_io;
  294. struct se_cmd *cmd = &ocp->cmd;
  295. ocp->seg_map_cnt = dma_map_sg(&io->efct->pci->dev, cmd->t_data_sg,
  296. cmd->t_data_nents, cmd->data_direction);
  297. if (ocp->seg_map_cnt == 0)
  298. return -EFAULT;
  299. return 0;
  300. }
  301. static void
  302. efct_lio_sg_unmap(struct efct_io *io)
  303. {
  304. struct efct_scsi_tgt_io *ocp = &io->tgt_io;
  305. struct se_cmd *cmd = &ocp->cmd;
  306. if (WARN_ON(!ocp->seg_map_cnt || !cmd->t_data_sg))
  307. return;
  308. dma_unmap_sg(&io->efct->pci->dev, cmd->t_data_sg,
  309. cmd->t_data_nents, cmd->data_direction);
  310. ocp->seg_map_cnt = 0;
  311. }
  312. static int
  313. efct_lio_status_done(struct efct_io *io,
  314. enum efct_scsi_io_status scsi_status,
  315. u32 flags, void *arg)
  316. {
  317. struct efct_scsi_tgt_io *ocp = &io->tgt_io;
  318. efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_RSP_DONE);
  319. if (scsi_status != EFCT_SCSI_STATUS_GOOD) {
  320. efct_lio_io_printf(io, "callback completed with error=%d\n",
  321. scsi_status);
  322. ocp->err = scsi_status;
  323. }
  324. if (ocp->seg_map_cnt)
  325. efct_lio_sg_unmap(io);
  326. efct_lio_io_printf(io, "status=%d, err=%d flags=0x%x, dir=%d\n",
  327. scsi_status, ocp->err, flags, ocp->ddir);
  328. efct_set_lio_io_state(io, EFCT_LIO_STATE_TGT_GENERIC_FREE);
  329. transport_generic_free_cmd(&io->tgt_io.cmd, 0);
  330. return 0;
  331. }
  332. static int
  333. efct_lio_datamove_done(struct efct_io *io, enum efct_scsi_io_status scsi_status,
  334. u32 flags, void *arg);
  335. static int
  336. efct_lio_write_pending(struct se_cmd *cmd)
  337. {
  338. struct efct_scsi_tgt_io *ocp =
  339. container_of(cmd, struct efct_scsi_tgt_io, cmd);
  340. struct efct_io *io = container_of(ocp, struct efct_io, tgt_io);
  341. struct efct_scsi_sgl *sgl = io->sgl;
  342. struct scatterlist *sg;
  343. u32 flags = 0, cnt, curcnt;
  344. u64 length = 0;
  345. efct_set_lio_io_state(io, EFCT_LIO_STATE_TFO_WRITE_PENDING);
  346. efct_lio_io_printf(io, "trans_state=0x%x se_cmd_flags=0x%x\n",
  347. cmd->transport_state, cmd->se_cmd_flags);
  348. if (ocp->seg_cnt == 0) {
  349. ocp->seg_cnt = cmd->t_data_nents;
  350. ocp->cur_seg = 0;
  351. if (efct_lio_sg_map(io)) {
  352. efct_lio_io_printf(io, "efct_lio_sg_map failed\n");
  353. return -EFAULT;
  354. }
  355. }
  356. curcnt = (ocp->seg_map_cnt - ocp->cur_seg);
  357. curcnt = (curcnt < io->sgl_allocated) ? curcnt : io->sgl_allocated;
  358. /* find current sg */
  359. for (cnt = 0, sg = cmd->t_data_sg; cnt < ocp->cur_seg; cnt++,
  360. sg = sg_next(sg))
  361. ;/* do nothing */
  362. for (cnt = 0; cnt < curcnt; cnt++, sg = sg_next(sg)) {
  363. sgl[cnt].addr = sg_dma_address(sg);
  364. sgl[cnt].dif_addr = 0;
  365. sgl[cnt].len = sg_dma_len(sg);
  366. length += sgl[cnt].len;
  367. ocp->cur_seg++;
  368. }
  369. if (ocp->cur_seg == ocp->seg_cnt)
  370. flags = EFCT_SCSI_LAST_DATAPHASE;
  371. return efct_scsi_recv_wr_data(io, flags, sgl, curcnt, length,
  372. efct_lio_datamove_done, NULL);
  373. }
  374. static int
  375. efct_lio_queue_data_in(struct se_cmd *cmd)
  376. {
  377. struct efct_scsi_tgt_io *ocp =
  378. container_of(cmd, struct efct_scsi_tgt_io, cmd);
  379. struct efct_io *io = container_of(ocp, struct efct_io, tgt_io);
  380. struct efct_scsi_sgl *sgl = io->sgl;
  381. struct scatterlist *sg = NULL;
  382. uint flags = 0, cnt = 0, curcnt = 0;
  383. u64 length = 0;
  384. efct_set_lio_io_state(io, EFCT_LIO_STATE_TFO_QUEUE_DATA_IN);
  385. if (ocp->seg_cnt == 0) {
  386. if (cmd->data_length) {
  387. ocp->seg_cnt = cmd->t_data_nents;
  388. ocp->cur_seg = 0;
  389. if (efct_lio_sg_map(io)) {
  390. efct_lio_io_printf(io,
  391. "efct_lio_sg_map failed\n");
  392. return -EAGAIN;
  393. }
  394. } else {
  395. /* If command length is 0, send the response status */
  396. struct efct_scsi_cmd_resp rsp;
  397. memset(&rsp, 0, sizeof(rsp));
  398. efct_lio_io_printf(io,
  399. "cmd : %p length 0, send status\n",
  400. cmd);
  401. return efct_scsi_send_resp(io, 0, &rsp,
  402. efct_lio_status_done, NULL);
  403. }
  404. }
  405. curcnt = min(ocp->seg_map_cnt - ocp->cur_seg, io->sgl_allocated);
  406. while (cnt < curcnt) {
  407. sg = &cmd->t_data_sg[ocp->cur_seg];
  408. sgl[cnt].addr = sg_dma_address(sg);
  409. sgl[cnt].dif_addr = 0;
  410. if (ocp->transferred_len + sg_dma_len(sg) >= cmd->data_length)
  411. sgl[cnt].len = cmd->data_length - ocp->transferred_len;
  412. else
  413. sgl[cnt].len = sg_dma_len(sg);
  414. ocp->transferred_len += sgl[cnt].len;
  415. length += sgl[cnt].len;
  416. ocp->cur_seg++;
  417. cnt++;
  418. if (ocp->transferred_len == cmd->data_length)
  419. break;
  420. }
  421. if (ocp->transferred_len == cmd->data_length) {
  422. flags = EFCT_SCSI_LAST_DATAPHASE;
  423. ocp->seg_cnt = ocp->cur_seg;
  424. }
  425. /* If there is residual, disable Auto Good Response */
  426. if (cmd->residual_count)
  427. flags |= EFCT_SCSI_NO_AUTO_RESPONSE;
  428. efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_SEND_RD_DATA);
  429. return efct_scsi_send_rd_data(io, flags, sgl, curcnt, length,
  430. efct_lio_datamove_done, NULL);
  431. }
  432. static void
  433. efct_lio_send_resp(struct efct_io *io, enum efct_scsi_io_status scsi_status,
  434. u32 flags)
  435. {
  436. struct efct_scsi_cmd_resp rsp;
  437. struct efct_scsi_tgt_io *ocp = &io->tgt_io;
  438. struct se_cmd *cmd = &io->tgt_io.cmd;
  439. int rc;
  440. if (flags & EFCT_SCSI_IO_CMPL_RSP_SENT) {
  441. ocp->rsp_sent = true;
  442. efct_set_lio_io_state(io, EFCT_LIO_STATE_TGT_GENERIC_FREE);
  443. transport_generic_free_cmd(&io->tgt_io.cmd, 0);
  444. return;
  445. }
  446. /* send check condition if an error occurred */
  447. memset(&rsp, 0, sizeof(rsp));
  448. rsp.scsi_status = cmd->scsi_status;
  449. rsp.sense_data = (uint8_t *)io->tgt_io.sense_buffer;
  450. rsp.sense_data_length = cmd->scsi_sense_length;
  451. /* Check for residual underrun or overrun */
  452. if (cmd->se_cmd_flags & SCF_OVERFLOW_BIT)
  453. rsp.residual = -cmd->residual_count;
  454. else if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT)
  455. rsp.residual = cmd->residual_count;
  456. rc = efct_scsi_send_resp(io, 0, &rsp, efct_lio_status_done, NULL);
  457. efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_SEND_RSP);
  458. if (rc != 0) {
  459. efct_lio_io_printf(io, "Read done, send rsp failed %d\n", rc);
  460. efct_set_lio_io_state(io, EFCT_LIO_STATE_TGT_GENERIC_FREE);
  461. transport_generic_free_cmd(&io->tgt_io.cmd, 0);
  462. } else {
  463. ocp->rsp_sent = true;
  464. }
  465. }
  466. static int
  467. efct_lio_datamove_done(struct efct_io *io, enum efct_scsi_io_status scsi_status,
  468. u32 flags, void *arg)
  469. {
  470. struct efct_scsi_tgt_io *ocp = &io->tgt_io;
  471. efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_DATA_DONE);
  472. if (scsi_status != EFCT_SCSI_STATUS_GOOD) {
  473. efct_lio_io_printf(io, "callback completed with error=%d\n",
  474. scsi_status);
  475. ocp->err = scsi_status;
  476. }
  477. efct_lio_io_printf(io, "seg_map_cnt=%d\n", ocp->seg_map_cnt);
  478. if (ocp->seg_map_cnt) {
  479. if (ocp->err == EFCT_SCSI_STATUS_GOOD &&
  480. ocp->cur_seg < ocp->seg_cnt) {
  481. int rc;
  482. efct_lio_io_printf(io, "continuing cmd at segm=%d\n",
  483. ocp->cur_seg);
  484. if (ocp->ddir == DMA_TO_DEVICE)
  485. rc = efct_lio_write_pending(&ocp->cmd);
  486. else
  487. rc = efct_lio_queue_data_in(&ocp->cmd);
  488. if (!rc)
  489. return 0;
  490. ocp->err = EFCT_SCSI_STATUS_ERROR;
  491. efct_lio_io_printf(io, "could not continue command\n");
  492. }
  493. efct_lio_sg_unmap(io);
  494. }
  495. if (io->tgt_io.aborting) {
  496. efct_lio_io_printf(io, "IO done aborted\n");
  497. return 0;
  498. }
  499. if (ocp->ddir == DMA_TO_DEVICE) {
  500. efct_lio_io_printf(io, "Write done, trans_state=0x%x\n",
  501. io->tgt_io.cmd.transport_state);
  502. if (scsi_status != EFCT_SCSI_STATUS_GOOD) {
  503. transport_generic_request_failure(&io->tgt_io.cmd,
  504. TCM_CHECK_CONDITION_ABORT_CMD);
  505. efct_set_lio_io_state(io,
  506. EFCT_LIO_STATE_TGT_GENERIC_REQ_FAILURE);
  507. } else {
  508. efct_set_lio_io_state(io,
  509. EFCT_LIO_STATE_TGT_EXECUTE_CMD);
  510. target_execute_cmd(&io->tgt_io.cmd);
  511. }
  512. } else {
  513. efct_lio_send_resp(io, scsi_status, flags);
  514. }
  515. return 0;
  516. }
  517. static int
  518. efct_lio_tmf_done(struct efct_io *io, enum efct_scsi_io_status scsi_status,
  519. u32 flags, void *arg)
  520. {
  521. efct_lio_tmfio_printf(io, "cmd=%p status=%d, flags=0x%x\n",
  522. &io->tgt_io.cmd, scsi_status, flags);
  523. efct_set_lio_io_state(io, EFCT_LIO_STATE_TGT_GENERIC_FREE);
  524. transport_generic_free_cmd(&io->tgt_io.cmd, 0);
  525. return 0;
  526. }
  527. static int
  528. efct_lio_null_tmf_done(struct efct_io *tmfio,
  529. enum efct_scsi_io_status scsi_status,
  530. u32 flags, void *arg)
  531. {
  532. efct_lio_tmfio_printf(tmfio, "cmd=%p status=%d, flags=0x%x\n",
  533. &tmfio->tgt_io.cmd, scsi_status, flags);
  534. /* free struct efct_io only, no active se_cmd */
  535. efct_scsi_io_complete(tmfio);
  536. return 0;
  537. }
  538. static int
  539. efct_lio_queue_status(struct se_cmd *cmd)
  540. {
  541. struct efct_scsi_cmd_resp rsp;
  542. struct efct_scsi_tgt_io *ocp =
  543. container_of(cmd, struct efct_scsi_tgt_io, cmd);
  544. struct efct_io *io = container_of(ocp, struct efct_io, tgt_io);
  545. int rc = 0;
  546. efct_set_lio_io_state(io, EFCT_LIO_STATE_TFO_QUEUE_STATUS);
  547. efct_lio_io_printf(io,
  548. "status=0x%x trans_state=0x%x se_cmd_flags=0x%x sns_len=%d\n",
  549. cmd->scsi_status, cmd->transport_state, cmd->se_cmd_flags,
  550. cmd->scsi_sense_length);
  551. memset(&rsp, 0, sizeof(rsp));
  552. rsp.scsi_status = cmd->scsi_status;
  553. rsp.sense_data = (u8 *)io->tgt_io.sense_buffer;
  554. rsp.sense_data_length = cmd->scsi_sense_length;
  555. /* Check for residual underrun or overrun, mark negitive value for
  556. * underrun to recognize in HW
  557. */
  558. if (cmd->se_cmd_flags & SCF_OVERFLOW_BIT)
  559. rsp.residual = -cmd->residual_count;
  560. else if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT)
  561. rsp.residual = cmd->residual_count;
  562. rc = efct_scsi_send_resp(io, 0, &rsp, efct_lio_status_done, NULL);
  563. efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_SEND_RSP);
  564. if (rc == 0)
  565. ocp->rsp_sent = true;
  566. return rc;
  567. }
  568. static void efct_lio_queue_tm_rsp(struct se_cmd *cmd)
  569. {
  570. struct efct_scsi_tgt_io *ocp =
  571. container_of(cmd, struct efct_scsi_tgt_io, cmd);
  572. struct efct_io *tmfio = container_of(ocp, struct efct_io, tgt_io);
  573. struct se_tmr_req *se_tmr = cmd->se_tmr_req;
  574. u8 rspcode;
  575. efct_lio_tmfio_printf(tmfio, "cmd=%p function=0x%x tmr->response=%d\n",
  576. cmd, se_tmr->function, se_tmr->response);
  577. switch (se_tmr->response) {
  578. case TMR_FUNCTION_COMPLETE:
  579. rspcode = EFCT_SCSI_TMF_FUNCTION_COMPLETE;
  580. break;
  581. case TMR_TASK_DOES_NOT_EXIST:
  582. rspcode = EFCT_SCSI_TMF_FUNCTION_IO_NOT_FOUND;
  583. break;
  584. case TMR_LUN_DOES_NOT_EXIST:
  585. rspcode = EFCT_SCSI_TMF_INCORRECT_LOGICAL_UNIT_NUMBER;
  586. break;
  587. case TMR_FUNCTION_REJECTED:
  588. default:
  589. rspcode = EFCT_SCSI_TMF_FUNCTION_REJECTED;
  590. break;
  591. }
  592. efct_scsi_send_tmf_resp(tmfio, rspcode, NULL, efct_lio_tmf_done, NULL);
  593. }
  594. static struct efct *efct_find_wwpn(u64 wwpn)
  595. {
  596. struct efct *efct;
  597. /* Search for the HBA that has this WWPN */
  598. list_for_each_entry(efct, &efct_devices, list_entry) {
  599. if (wwpn == efct_get_wwpn(&efct->hw))
  600. return efct;
  601. }
  602. return NULL;
  603. }
  604. static struct se_wwn *
  605. efct_lio_make_nport(struct target_fabric_configfs *tf,
  606. struct config_group *group, const char *name)
  607. {
  608. struct efct_lio_nport *lio_nport;
  609. struct efct *efct;
  610. int ret;
  611. u64 wwpn;
  612. ret = efct_lio_parse_wwn(name, &wwpn, 0);
  613. if (ret)
  614. return ERR_PTR(ret);
  615. efct = efct_find_wwpn(wwpn);
  616. if (!efct) {
  617. pr_err("cannot find EFCT for base wwpn %s\n", name);
  618. return ERR_PTR(-ENXIO);
  619. }
  620. lio_nport = kzalloc_obj(*lio_nport);
  621. if (!lio_nport)
  622. return ERR_PTR(-ENOMEM);
  623. lio_nport->efct = efct;
  624. lio_nport->wwpn = wwpn;
  625. efct_format_wwn(lio_nport->wwpn_str, sizeof(lio_nport->wwpn_str),
  626. "naa.", wwpn);
  627. efct->tgt_efct.lio_nport = lio_nport;
  628. return &lio_nport->nport_wwn;
  629. }
  630. static struct se_wwn *
  631. efct_lio_npiv_make_nport(struct target_fabric_configfs *tf,
  632. struct config_group *group, const char *name)
  633. {
  634. struct efct_lio_vport *lio_vport;
  635. struct efct *efct;
  636. int ret;
  637. u64 p_wwpn, npiv_wwpn, npiv_wwnn;
  638. char *p, *pbuf, tmp[128];
  639. struct efct_lio_vport_list_t *vport_list;
  640. struct fc_vport *new_fc_vport;
  641. struct fc_vport_identifiers vport_id;
  642. unsigned long flags = 0;
  643. snprintf(tmp, sizeof(tmp), "%s", name);
  644. pbuf = &tmp[0];
  645. p = strsep(&pbuf, "@");
  646. if (!p || !pbuf) {
  647. pr_err("Unable to find separator operator(@)\n");
  648. return ERR_PTR(-EINVAL);
  649. }
  650. ret = efct_lio_parse_wwn(p, &p_wwpn, 0);
  651. if (ret)
  652. return ERR_PTR(ret);
  653. ret = efct_lio_parse_npiv_wwn(pbuf, strlen(pbuf), &npiv_wwpn,
  654. &npiv_wwnn);
  655. if (ret)
  656. return ERR_PTR(ret);
  657. efct = efct_find_wwpn(p_wwpn);
  658. if (!efct) {
  659. pr_err("cannot find EFCT for base wwpn %s\n", name);
  660. return ERR_PTR(-ENXIO);
  661. }
  662. lio_vport = kzalloc_obj(*lio_vport);
  663. if (!lio_vport)
  664. return ERR_PTR(-ENOMEM);
  665. lio_vport->efct = efct;
  666. lio_vport->wwpn = p_wwpn;
  667. lio_vport->npiv_wwpn = npiv_wwpn;
  668. lio_vport->npiv_wwnn = npiv_wwnn;
  669. efct_format_wwn(lio_vport->wwpn_str, sizeof(lio_vport->wwpn_str),
  670. "naa.", npiv_wwpn);
  671. vport_list = kzalloc_obj(*vport_list);
  672. if (!vport_list) {
  673. kfree(lio_vport);
  674. return ERR_PTR(-ENOMEM);
  675. }
  676. vport_list->lio_vport = lio_vport;
  677. memset(&vport_id, 0, sizeof(vport_id));
  678. vport_id.port_name = npiv_wwpn;
  679. vport_id.node_name = npiv_wwnn;
  680. vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
  681. vport_id.vport_type = FC_PORTTYPE_NPIV;
  682. vport_id.disable = false;
  683. new_fc_vport = fc_vport_create(efct->shost, 0, &vport_id);
  684. if (!new_fc_vport) {
  685. efc_log_err(efct, "fc_vport_create failed\n");
  686. kfree(lio_vport);
  687. kfree(vport_list);
  688. return ERR_PTR(-ENOMEM);
  689. }
  690. lio_vport->fc_vport = new_fc_vport;
  691. spin_lock_irqsave(&efct->tgt_efct.efct_lio_lock, flags);
  692. INIT_LIST_HEAD(&vport_list->list_entry);
  693. list_add_tail(&vport_list->list_entry, &efct->tgt_efct.vport_list);
  694. spin_unlock_irqrestore(&efct->tgt_efct.efct_lio_lock, flags);
  695. return &lio_vport->vport_wwn;
  696. }
  697. static void
  698. efct_lio_drop_nport(struct se_wwn *wwn)
  699. {
  700. struct efct_lio_nport *lio_nport =
  701. container_of(wwn, struct efct_lio_nport, nport_wwn);
  702. struct efct *efct = lio_nport->efct;
  703. /* only physical nport should exist, free lio_nport allocated
  704. * in efct_lio_make_nport.
  705. */
  706. kfree(efct->tgt_efct.lio_nport);
  707. efct->tgt_efct.lio_nport = NULL;
  708. }
  709. static void
  710. efct_lio_npiv_drop_nport(struct se_wwn *wwn)
  711. {
  712. struct efct_lio_vport *lio_vport =
  713. container_of(wwn, struct efct_lio_vport, vport_wwn);
  714. struct efct_lio_vport_list_t *vport, *next_vport;
  715. struct efct *efct = lio_vport->efct;
  716. unsigned long flags = 0;
  717. if (lio_vport->fc_vport)
  718. fc_vport_terminate(lio_vport->fc_vport);
  719. spin_lock_irqsave(&efct->tgt_efct.efct_lio_lock, flags);
  720. list_for_each_entry_safe(vport, next_vport, &efct->tgt_efct.vport_list,
  721. list_entry) {
  722. if (vport->lio_vport == lio_vport) {
  723. list_del(&vport->list_entry);
  724. kfree(vport->lio_vport);
  725. kfree(vport);
  726. break;
  727. }
  728. }
  729. spin_unlock_irqrestore(&efct->tgt_efct.efct_lio_lock, flags);
  730. }
  731. static struct se_portal_group *
  732. efct_lio_make_tpg(struct se_wwn *wwn, const char *name)
  733. {
  734. struct efct_lio_nport *lio_nport =
  735. container_of(wwn, struct efct_lio_nport, nport_wwn);
  736. struct efct_lio_tpg *tpg;
  737. struct efct *efct;
  738. unsigned long n;
  739. int ret;
  740. if (strstr(name, "tpgt_") != name)
  741. return ERR_PTR(-EINVAL);
  742. if (kstrtoul(name + 5, 10, &n) || n > USHRT_MAX)
  743. return ERR_PTR(-EINVAL);
  744. tpg = kzalloc_obj(*tpg);
  745. if (!tpg)
  746. return ERR_PTR(-ENOMEM);
  747. tpg->nport = lio_nport;
  748. tpg->tpgt = n;
  749. tpg->enabled = false;
  750. tpg->tpg_attrib.generate_node_acls = 1;
  751. tpg->tpg_attrib.demo_mode_write_protect = 1;
  752. tpg->tpg_attrib.cache_dynamic_acls = 1;
  753. tpg->tpg_attrib.demo_mode_login_only = 1;
  754. tpg->tpg_attrib.session_deletion_wait = 1;
  755. ret = core_tpg_register(wwn, &tpg->tpg, SCSI_PROTOCOL_FCP);
  756. if (ret < 0) {
  757. kfree(tpg);
  758. return NULL;
  759. }
  760. efct = lio_nport->efct;
  761. efct->tgt_efct.tpg = tpg;
  762. efc_log_debug(efct, "create portal group %d\n", tpg->tpgt);
  763. xa_init(&efct->lookup);
  764. return &tpg->tpg;
  765. }
  766. static void
  767. efct_lio_drop_tpg(struct se_portal_group *se_tpg)
  768. {
  769. struct efct_lio_tpg *tpg =
  770. container_of(se_tpg, struct efct_lio_tpg, tpg);
  771. struct efct *efct = tpg->nport->efct;
  772. efc_log_debug(efct, "drop portal group %d\n", tpg->tpgt);
  773. tpg->nport->efct->tgt_efct.tpg = NULL;
  774. core_tpg_deregister(se_tpg);
  775. xa_destroy(&efct->lookup);
  776. kfree(tpg);
  777. }
  778. static struct se_portal_group *
  779. efct_lio_npiv_make_tpg(struct se_wwn *wwn, const char *name)
  780. {
  781. struct efct_lio_vport *lio_vport =
  782. container_of(wwn, struct efct_lio_vport, vport_wwn);
  783. struct efct_lio_tpg *tpg;
  784. struct efct *efct;
  785. unsigned long n;
  786. int ret;
  787. efct = lio_vport->efct;
  788. if (strstr(name, "tpgt_") != name)
  789. return ERR_PTR(-EINVAL);
  790. if (kstrtoul(name + 5, 10, &n) || n > USHRT_MAX)
  791. return ERR_PTR(-EINVAL);
  792. if (n != 1) {
  793. efc_log_err(efct, "Invalid tpgt index: %ld provided\n", n);
  794. return ERR_PTR(-EINVAL);
  795. }
  796. tpg = kzalloc_obj(*tpg);
  797. if (!tpg)
  798. return ERR_PTR(-ENOMEM);
  799. tpg->vport = lio_vport;
  800. tpg->tpgt = n;
  801. tpg->enabled = false;
  802. tpg->tpg_attrib.generate_node_acls = 1;
  803. tpg->tpg_attrib.demo_mode_write_protect = 1;
  804. tpg->tpg_attrib.cache_dynamic_acls = 1;
  805. tpg->tpg_attrib.demo_mode_login_only = 1;
  806. tpg->tpg_attrib.session_deletion_wait = 1;
  807. ret = core_tpg_register(wwn, &tpg->tpg, SCSI_PROTOCOL_FCP);
  808. if (ret < 0) {
  809. kfree(tpg);
  810. return NULL;
  811. }
  812. lio_vport->tpg = tpg;
  813. efc_log_debug(efct, "create vport portal group %d\n", tpg->tpgt);
  814. return &tpg->tpg;
  815. }
  816. static void
  817. efct_lio_npiv_drop_tpg(struct se_portal_group *se_tpg)
  818. {
  819. struct efct_lio_tpg *tpg =
  820. container_of(se_tpg, struct efct_lio_tpg, tpg);
  821. efc_log_debug(tpg->vport->efct, "drop npiv portal group %d\n",
  822. tpg->tpgt);
  823. core_tpg_deregister(se_tpg);
  824. kfree(tpg);
  825. }
  826. static int
  827. efct_lio_init_nodeacl(struct se_node_acl *se_nacl, const char *name)
  828. {
  829. struct efct_lio_nacl *nacl;
  830. u64 wwnn;
  831. if (efct_lio_parse_wwn(name, &wwnn, 0) < 0)
  832. return -EINVAL;
  833. nacl = container_of(se_nacl, struct efct_lio_nacl, se_node_acl);
  834. nacl->nport_wwnn = wwnn;
  835. efct_format_wwn(nacl->nport_name, sizeof(nacl->nport_name), "", wwnn);
  836. return 0;
  837. }
  838. static int efct_lio_check_demo_mode_login_only(struct se_portal_group *stpg)
  839. {
  840. struct efct_lio_tpg *tpg = container_of(stpg, struct efct_lio_tpg, tpg);
  841. return tpg->tpg_attrib.demo_mode_login_only;
  842. }
  843. static int
  844. efct_lio_npiv_check_demo_mode_login_only(struct se_portal_group *stpg)
  845. {
  846. struct efct_lio_tpg *tpg = container_of(stpg, struct efct_lio_tpg, tpg);
  847. return tpg->tpg_attrib.demo_mode_login_only;
  848. }
  849. static struct efct_lio_tpg *
  850. efct_get_vport_tpg(struct efc_node *node)
  851. {
  852. struct efct *efct;
  853. u64 wwpn = node->nport->wwpn;
  854. struct efct_lio_vport_list_t *vport, *next;
  855. struct efct_lio_vport *lio_vport = NULL;
  856. struct efct_lio_tpg *tpg = NULL;
  857. unsigned long flags = 0;
  858. efct = node->efc->base;
  859. spin_lock_irqsave(&efct->tgt_efct.efct_lio_lock, flags);
  860. list_for_each_entry_safe(vport, next, &efct->tgt_efct.vport_list,
  861. list_entry) {
  862. lio_vport = vport->lio_vport;
  863. if (wwpn && lio_vport && lio_vport->npiv_wwpn == wwpn) {
  864. efc_log_debug(efct, "found tpg on vport\n");
  865. tpg = lio_vport->tpg;
  866. break;
  867. }
  868. }
  869. spin_unlock_irqrestore(&efct->tgt_efct.efct_lio_lock, flags);
  870. return tpg;
  871. }
  872. static void
  873. _efct_tgt_node_free(struct kref *arg)
  874. {
  875. struct efct_node *tgt_node = container_of(arg, struct efct_node, ref);
  876. struct efc_node *node = tgt_node->node;
  877. efc_scsi_del_initiator_complete(node->efc, node);
  878. kfree(tgt_node);
  879. }
  880. static int efct_session_cb(struct se_portal_group *se_tpg,
  881. struct se_session *se_sess, void *private)
  882. {
  883. struct efc_node *node = private;
  884. struct efct_node *tgt_node;
  885. struct efct *efct = node->efc->base;
  886. tgt_node = kzalloc_obj(*tgt_node);
  887. if (!tgt_node)
  888. return -ENOMEM;
  889. kref_init(&tgt_node->ref);
  890. tgt_node->release = _efct_tgt_node_free;
  891. tgt_node->session = se_sess;
  892. node->tgt_node = tgt_node;
  893. tgt_node->efct = efct;
  894. tgt_node->node = node;
  895. tgt_node->node_fc_id = node->rnode.fc_id;
  896. tgt_node->port_fc_id = node->nport->fc_id;
  897. tgt_node->vpi = node->nport->indicator;
  898. tgt_node->rpi = node->rnode.indicator;
  899. spin_lock_init(&tgt_node->active_ios_lock);
  900. INIT_LIST_HEAD(&tgt_node->active_ios);
  901. return 0;
  902. }
  903. int efct_scsi_tgt_new_device(struct efct *efct)
  904. {
  905. u32 total_ios;
  906. /* Get the max settings */
  907. efct->tgt_efct.max_sge = sli_get_max_sge(&efct->hw.sli);
  908. efct->tgt_efct.max_sgl = sli_get_max_sgl(&efct->hw.sli);
  909. /* initialize IO watermark fields */
  910. atomic_set(&efct->tgt_efct.ios_in_use, 0);
  911. total_ios = efct->hw.config.n_io;
  912. efc_log_debug(efct, "total_ios=%d\n", total_ios);
  913. efct->tgt_efct.watermark_min =
  914. (total_ios * EFCT_WATERMARK_LOW_PCT) / 100;
  915. efct->tgt_efct.watermark_max =
  916. (total_ios * EFCT_WATERMARK_HIGH_PCT) / 100;
  917. atomic_set(&efct->tgt_efct.io_high_watermark,
  918. efct->tgt_efct.watermark_max);
  919. atomic_set(&efct->tgt_efct.watermark_hit, 0);
  920. atomic_set(&efct->tgt_efct.initiator_count, 0);
  921. lio_wq = alloc_ordered_workqueue("%s", WQ_MEM_RECLAIM,
  922. "efct_lio_worker");
  923. if (!lio_wq) {
  924. efc_log_err(efct, "workqueue create failed\n");
  925. return -EIO;
  926. }
  927. spin_lock_init(&efct->tgt_efct.efct_lio_lock);
  928. INIT_LIST_HEAD(&efct->tgt_efct.vport_list);
  929. return 0;
  930. }
  931. int efct_scsi_tgt_del_device(struct efct *efct)
  932. {
  933. flush_workqueue(lio_wq);
  934. return 0;
  935. }
  936. int
  937. efct_scsi_tgt_new_nport(struct efc *efc, struct efc_nport *nport)
  938. {
  939. struct efct *efct = nport->efc->base;
  940. efc_log_debug(efct, "New SPORT: %s bound to %s\n", nport->display_name,
  941. efct->tgt_efct.lio_nport->wwpn_str);
  942. return 0;
  943. }
  944. void
  945. efct_scsi_tgt_del_nport(struct efc *efc, struct efc_nport *nport)
  946. {
  947. efc_log_debug(efc, "Del SPORT: %s\n", nport->display_name);
  948. }
  949. static void efct_lio_setup_session(struct work_struct *work)
  950. {
  951. struct efct_lio_wq_data *wq_data =
  952. container_of(work, struct efct_lio_wq_data, work);
  953. struct efct *efct = wq_data->efct;
  954. struct efc_node *node = wq_data->ptr;
  955. char wwpn[WWN_NAME_LEN];
  956. struct efct_lio_tpg *tpg;
  957. struct efct_node *tgt_node;
  958. struct se_portal_group *se_tpg;
  959. struct se_session *se_sess;
  960. int watermark;
  961. int ini_count;
  962. u64 id;
  963. /* Check to see if it's belongs to vport,
  964. * if not get physical port
  965. */
  966. tpg = efct_get_vport_tpg(node);
  967. if (tpg) {
  968. se_tpg = &tpg->tpg;
  969. } else if (efct->tgt_efct.tpg) {
  970. tpg = efct->tgt_efct.tpg;
  971. se_tpg = &tpg->tpg;
  972. } else {
  973. efc_log_err(efct, "failed to init session\n");
  974. return;
  975. }
  976. /*
  977. * Format the FCP Initiator port_name into colon
  978. * separated values to match the format by our explicit
  979. * ConfigFS NodeACLs.
  980. */
  981. efct_format_wwn(wwpn, sizeof(wwpn), "", efc_node_get_wwpn(node));
  982. se_sess = target_setup_session(se_tpg, 0, 0, TARGET_PROT_NORMAL, wwpn,
  983. node, efct_session_cb);
  984. if (IS_ERR(se_sess)) {
  985. efc_log_err(efct, "failed to setup session\n");
  986. kfree(wq_data);
  987. efc_scsi_sess_reg_complete(node, -EIO);
  988. return;
  989. }
  990. tgt_node = node->tgt_node;
  991. id = (u64) tgt_node->port_fc_id << 32 | tgt_node->node_fc_id;
  992. efc_log_debug(efct, "new initiator sess=%p node=%p id: %llx\n",
  993. se_sess, node, id);
  994. if (xa_err(xa_store(&efct->lookup, id, tgt_node, GFP_KERNEL)))
  995. efc_log_err(efct, "Node lookup store failed\n");
  996. efc_scsi_sess_reg_complete(node, 0);
  997. /* update IO watermark: increment initiator count */
  998. ini_count = atomic_add_return(1, &efct->tgt_efct.initiator_count);
  999. watermark = efct->tgt_efct.watermark_max -
  1000. ini_count * EFCT_IO_WATERMARK_PER_INITIATOR;
  1001. watermark = (efct->tgt_efct.watermark_min > watermark) ?
  1002. efct->tgt_efct.watermark_min : watermark;
  1003. atomic_set(&efct->tgt_efct.io_high_watermark, watermark);
  1004. kfree(wq_data);
  1005. }
  1006. int efct_scsi_new_initiator(struct efc *efc, struct efc_node *node)
  1007. {
  1008. struct efct *efct = node->efc->base;
  1009. struct efct_lio_wq_data *wq_data;
  1010. /*
  1011. * Since LIO only supports initiator validation at thread level,
  1012. * we are open minded and accept all callers.
  1013. */
  1014. wq_data = kzalloc_obj(*wq_data, GFP_ATOMIC);
  1015. if (!wq_data)
  1016. return -ENOMEM;
  1017. wq_data->ptr = node;
  1018. wq_data->efct = efct;
  1019. INIT_WORK(&wq_data->work, efct_lio_setup_session);
  1020. queue_work(lio_wq, &wq_data->work);
  1021. return EFC_SCSI_CALL_ASYNC;
  1022. }
  1023. static void efct_lio_remove_session(struct work_struct *work)
  1024. {
  1025. struct efct_lio_wq_data *wq_data =
  1026. container_of(work, struct efct_lio_wq_data, work);
  1027. struct efct *efct = wq_data->efct;
  1028. struct efc_node *node = wq_data->ptr;
  1029. struct efct_node *tgt_node;
  1030. struct se_session *se_sess;
  1031. tgt_node = node->tgt_node;
  1032. if (!tgt_node) {
  1033. /* base driver has sent back-to-back requests
  1034. * to unreg session with no intervening
  1035. * register
  1036. */
  1037. efc_log_err(efct, "unreg session for NULL session\n");
  1038. efc_scsi_del_initiator_complete(node->efc, node);
  1039. return;
  1040. }
  1041. se_sess = tgt_node->session;
  1042. efc_log_debug(efct, "unreg session se_sess=%p node=%p\n",
  1043. se_sess, node);
  1044. /* first flag all session commands to complete */
  1045. target_stop_session(se_sess);
  1046. /* now wait for session commands to complete */
  1047. target_wait_for_sess_cmds(se_sess);
  1048. target_remove_session(se_sess);
  1049. tgt_node->session = NULL;
  1050. node->tgt_node = NULL;
  1051. kref_put(&tgt_node->ref, tgt_node->release);
  1052. kfree(wq_data);
  1053. }
  1054. int efct_scsi_del_initiator(struct efc *efc, struct efc_node *node, int reason)
  1055. {
  1056. struct efct *efct = node->efc->base;
  1057. struct efct_node *tgt_node = node->tgt_node;
  1058. struct efct_lio_wq_data *wq_data;
  1059. int watermark;
  1060. int ini_count;
  1061. u64 id;
  1062. if (reason == EFCT_SCSI_INITIATOR_MISSING)
  1063. return EFC_SCSI_CALL_COMPLETE;
  1064. if (!tgt_node) {
  1065. efc_log_err(efct, "tgt_node is NULL\n");
  1066. return -EIO;
  1067. }
  1068. wq_data = kzalloc_obj(*wq_data, GFP_ATOMIC);
  1069. if (!wq_data)
  1070. return -ENOMEM;
  1071. id = (u64) tgt_node->port_fc_id << 32 | tgt_node->node_fc_id;
  1072. xa_erase(&efct->lookup, id);
  1073. wq_data->ptr = node;
  1074. wq_data->efct = efct;
  1075. INIT_WORK(&wq_data->work, efct_lio_remove_session);
  1076. queue_work(lio_wq, &wq_data->work);
  1077. /*
  1078. * update IO watermark: decrement initiator count
  1079. */
  1080. ini_count = atomic_sub_return(1, &efct->tgt_efct.initiator_count);
  1081. watermark = efct->tgt_efct.watermark_max -
  1082. ini_count * EFCT_IO_WATERMARK_PER_INITIATOR;
  1083. watermark = (efct->tgt_efct.watermark_min > watermark) ?
  1084. efct->tgt_efct.watermark_min : watermark;
  1085. atomic_set(&efct->tgt_efct.io_high_watermark, watermark);
  1086. return EFC_SCSI_CALL_ASYNC;
  1087. }
  1088. void efct_scsi_recv_cmd(struct efct_io *io, uint64_t lun, u8 *cdb,
  1089. u32 cdb_len, u32 flags)
  1090. {
  1091. struct efct_scsi_tgt_io *ocp = &io->tgt_io;
  1092. struct se_cmd *se_cmd = &io->tgt_io.cmd;
  1093. struct efct *efct = io->efct;
  1094. char *ddir;
  1095. struct efct_node *tgt_node;
  1096. struct se_session *se_sess;
  1097. int rc = 0;
  1098. memset(ocp, 0, sizeof(struct efct_scsi_tgt_io));
  1099. efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_RECV_CMD);
  1100. atomic_add_return(1, &efct->tgt_efct.ios_in_use);
  1101. /* set target timeout */
  1102. io->timeout = efct->target_io_timer_sec;
  1103. if (flags & EFCT_SCSI_CMD_SIMPLE)
  1104. ocp->task_attr = TCM_SIMPLE_TAG;
  1105. else if (flags & EFCT_SCSI_CMD_HEAD_OF_QUEUE)
  1106. ocp->task_attr = TCM_HEAD_TAG;
  1107. else if (flags & EFCT_SCSI_CMD_ORDERED)
  1108. ocp->task_attr = TCM_ORDERED_TAG;
  1109. else if (flags & EFCT_SCSI_CMD_ACA)
  1110. ocp->task_attr = TCM_ACA_TAG;
  1111. switch (flags & (EFCT_SCSI_CMD_DIR_IN | EFCT_SCSI_CMD_DIR_OUT)) {
  1112. case EFCT_SCSI_CMD_DIR_IN:
  1113. ddir = "FROM_INITIATOR";
  1114. ocp->ddir = DMA_TO_DEVICE;
  1115. break;
  1116. case EFCT_SCSI_CMD_DIR_OUT:
  1117. ddir = "TO_INITIATOR";
  1118. ocp->ddir = DMA_FROM_DEVICE;
  1119. break;
  1120. case EFCT_SCSI_CMD_DIR_IN | EFCT_SCSI_CMD_DIR_OUT:
  1121. ddir = "BIDIR";
  1122. ocp->ddir = DMA_BIDIRECTIONAL;
  1123. break;
  1124. default:
  1125. ddir = "NONE";
  1126. ocp->ddir = DMA_NONE;
  1127. break;
  1128. }
  1129. ocp->lun = lun;
  1130. efct_lio_io_printf(io, "new cmd=0x%x ddir=%s dl=%u\n",
  1131. cdb[0], ddir, io->exp_xfer_len);
  1132. tgt_node = io->node;
  1133. se_sess = tgt_node->session;
  1134. if (!se_sess) {
  1135. efc_log_err(efct, "No session found to submit IO se_cmd: %p\n",
  1136. &ocp->cmd);
  1137. efct_scsi_io_free(io);
  1138. return;
  1139. }
  1140. efct_set_lio_io_state(io, EFCT_LIO_STATE_TGT_SUBMIT_CMD);
  1141. rc = target_init_cmd(se_cmd, se_sess, &io->tgt_io.sense_buffer[0],
  1142. ocp->lun, io->exp_xfer_len, ocp->task_attr,
  1143. ocp->ddir, TARGET_SCF_ACK_KREF);
  1144. if (rc) {
  1145. efc_log_err(efct, "failed to init cmd se_cmd: %p\n", se_cmd);
  1146. efct_scsi_io_free(io);
  1147. return;
  1148. }
  1149. if (target_submit_prep(se_cmd, cdb, NULL, 0, NULL, 0,
  1150. NULL, 0, GFP_ATOMIC))
  1151. return;
  1152. target_submit(se_cmd);
  1153. }
  1154. int
  1155. efct_scsi_recv_tmf(struct efct_io *tmfio, u32 lun, enum efct_scsi_tmf_cmd cmd,
  1156. struct efct_io *io_to_abort, u32 flags)
  1157. {
  1158. unsigned char tmr_func;
  1159. struct efct *efct = tmfio->efct;
  1160. struct efct_scsi_tgt_io *ocp = &tmfio->tgt_io;
  1161. struct efct_node *tgt_node;
  1162. struct se_session *se_sess;
  1163. int rc;
  1164. memset(ocp, 0, sizeof(struct efct_scsi_tgt_io));
  1165. efct_set_lio_io_state(tmfio, EFCT_LIO_STATE_SCSI_RECV_TMF);
  1166. atomic_add_return(1, &efct->tgt_efct.ios_in_use);
  1167. efct_lio_tmfio_printf(tmfio, "%s: new tmf %x lun=%u\n",
  1168. tmfio->display_name, cmd, lun);
  1169. switch (cmd) {
  1170. case EFCT_SCSI_TMF_ABORT_TASK:
  1171. tmr_func = TMR_ABORT_TASK;
  1172. break;
  1173. case EFCT_SCSI_TMF_ABORT_TASK_SET:
  1174. tmr_func = TMR_ABORT_TASK_SET;
  1175. break;
  1176. case EFCT_SCSI_TMF_CLEAR_TASK_SET:
  1177. tmr_func = TMR_CLEAR_TASK_SET;
  1178. break;
  1179. case EFCT_SCSI_TMF_LOGICAL_UNIT_RESET:
  1180. tmr_func = TMR_LUN_RESET;
  1181. break;
  1182. case EFCT_SCSI_TMF_CLEAR_ACA:
  1183. tmr_func = TMR_CLEAR_ACA;
  1184. break;
  1185. case EFCT_SCSI_TMF_TARGET_RESET:
  1186. tmr_func = TMR_TARGET_WARM_RESET;
  1187. break;
  1188. case EFCT_SCSI_TMF_QUERY_ASYNCHRONOUS_EVENT:
  1189. case EFCT_SCSI_TMF_QUERY_TASK_SET:
  1190. default:
  1191. goto tmf_fail;
  1192. }
  1193. tmfio->tgt_io.tmf = tmr_func;
  1194. tmfio->tgt_io.lun = lun;
  1195. tmfio->tgt_io.io_to_abort = io_to_abort;
  1196. tgt_node = tmfio->node;
  1197. se_sess = tgt_node->session;
  1198. if (!se_sess)
  1199. return 0;
  1200. rc = target_submit_tmr(&ocp->cmd, se_sess, NULL, lun, ocp, tmr_func,
  1201. GFP_ATOMIC, tmfio->init_task_tag, TARGET_SCF_ACK_KREF);
  1202. efct_set_lio_io_state(tmfio, EFCT_LIO_STATE_TGT_SUBMIT_TMR);
  1203. if (rc)
  1204. goto tmf_fail;
  1205. return 0;
  1206. tmf_fail:
  1207. efct_scsi_send_tmf_resp(tmfio, EFCT_SCSI_TMF_FUNCTION_REJECTED,
  1208. NULL, efct_lio_null_tmf_done, NULL);
  1209. return 0;
  1210. }
  1211. /* Start items for efct_lio_tpg_attrib_cit */
  1212. #define DEF_EFCT_TPG_ATTRIB(name) \
  1213. \
  1214. static ssize_t efct_lio_tpg_attrib_##name##_show( \
  1215. struct config_item *item, char *page) \
  1216. { \
  1217. struct se_portal_group *se_tpg = to_tpg(item); \
  1218. struct efct_lio_tpg *tpg = container_of(se_tpg, \
  1219. struct efct_lio_tpg, tpg); \
  1220. \
  1221. return sprintf(page, "%u\n", tpg->tpg_attrib.name); \
  1222. } \
  1223. \
  1224. static ssize_t efct_lio_tpg_attrib_##name##_store( \
  1225. struct config_item *item, const char *page, size_t count) \
  1226. { \
  1227. struct se_portal_group *se_tpg = to_tpg(item); \
  1228. struct efct_lio_tpg *tpg = container_of(se_tpg, \
  1229. struct efct_lio_tpg, tpg); \
  1230. struct efct_lio_tpg_attrib *a = &tpg->tpg_attrib; \
  1231. unsigned long val; \
  1232. int ret; \
  1233. \
  1234. ret = kstrtoul(page, 0, &val); \
  1235. if (ret < 0) { \
  1236. pr_err("kstrtoul() failed with ret: %d\n", ret); \
  1237. return ret; \
  1238. } \
  1239. \
  1240. if (val != 0 && val != 1) { \
  1241. pr_err("Illegal boolean value %lu\n", val); \
  1242. return -EINVAL; \
  1243. } \
  1244. \
  1245. a->name = val; \
  1246. \
  1247. return count; \
  1248. } \
  1249. CONFIGFS_ATTR(efct_lio_tpg_attrib_, name)
  1250. DEF_EFCT_TPG_ATTRIB(generate_node_acls);
  1251. DEF_EFCT_TPG_ATTRIB(cache_dynamic_acls);
  1252. DEF_EFCT_TPG_ATTRIB(demo_mode_write_protect);
  1253. DEF_EFCT_TPG_ATTRIB(prod_mode_write_protect);
  1254. DEF_EFCT_TPG_ATTRIB(demo_mode_login_only);
  1255. DEF_EFCT_TPG_ATTRIB(session_deletion_wait);
  1256. static struct configfs_attribute *efct_lio_tpg_attrib_attrs[] = {
  1257. &efct_lio_tpg_attrib_attr_generate_node_acls,
  1258. &efct_lio_tpg_attrib_attr_cache_dynamic_acls,
  1259. &efct_lio_tpg_attrib_attr_demo_mode_write_protect,
  1260. &efct_lio_tpg_attrib_attr_prod_mode_write_protect,
  1261. &efct_lio_tpg_attrib_attr_demo_mode_login_only,
  1262. &efct_lio_tpg_attrib_attr_session_deletion_wait,
  1263. NULL,
  1264. };
  1265. #define DEF_EFCT_NPIV_TPG_ATTRIB(name) \
  1266. \
  1267. static ssize_t efct_lio_npiv_tpg_attrib_##name##_show( \
  1268. struct config_item *item, char *page) \
  1269. { \
  1270. struct se_portal_group *se_tpg = to_tpg(item); \
  1271. struct efct_lio_tpg *tpg = container_of(se_tpg, \
  1272. struct efct_lio_tpg, tpg); \
  1273. \
  1274. return sprintf(page, "%u\n", tpg->tpg_attrib.name); \
  1275. } \
  1276. \
  1277. static ssize_t efct_lio_npiv_tpg_attrib_##name##_store( \
  1278. struct config_item *item, const char *page, size_t count) \
  1279. { \
  1280. struct se_portal_group *se_tpg = to_tpg(item); \
  1281. struct efct_lio_tpg *tpg = container_of(se_tpg, \
  1282. struct efct_lio_tpg, tpg); \
  1283. struct efct_lio_tpg_attrib *a = &tpg->tpg_attrib; \
  1284. unsigned long val; \
  1285. int ret; \
  1286. \
  1287. ret = kstrtoul(page, 0, &val); \
  1288. if (ret < 0) { \
  1289. pr_err("kstrtoul() failed with ret: %d\n", ret); \
  1290. return ret; \
  1291. } \
  1292. \
  1293. if (val != 0 && val != 1) { \
  1294. pr_err("Illegal boolean value %lu\n", val); \
  1295. return -EINVAL; \
  1296. } \
  1297. \
  1298. a->name = val; \
  1299. \
  1300. return count; \
  1301. } \
  1302. CONFIGFS_ATTR(efct_lio_npiv_tpg_attrib_, name)
  1303. DEF_EFCT_NPIV_TPG_ATTRIB(generate_node_acls);
  1304. DEF_EFCT_NPIV_TPG_ATTRIB(cache_dynamic_acls);
  1305. DEF_EFCT_NPIV_TPG_ATTRIB(demo_mode_write_protect);
  1306. DEF_EFCT_NPIV_TPG_ATTRIB(prod_mode_write_protect);
  1307. DEF_EFCT_NPIV_TPG_ATTRIB(demo_mode_login_only);
  1308. DEF_EFCT_NPIV_TPG_ATTRIB(session_deletion_wait);
  1309. static struct configfs_attribute *efct_lio_npiv_tpg_attrib_attrs[] = {
  1310. &efct_lio_npiv_tpg_attrib_attr_generate_node_acls,
  1311. &efct_lio_npiv_tpg_attrib_attr_cache_dynamic_acls,
  1312. &efct_lio_npiv_tpg_attrib_attr_demo_mode_write_protect,
  1313. &efct_lio_npiv_tpg_attrib_attr_prod_mode_write_protect,
  1314. &efct_lio_npiv_tpg_attrib_attr_demo_mode_login_only,
  1315. &efct_lio_npiv_tpg_attrib_attr_session_deletion_wait,
  1316. NULL,
  1317. };
  1318. CONFIGFS_ATTR(efct_lio_tpg_, enable);
  1319. static struct configfs_attribute *efct_lio_tpg_attrs[] = {
  1320. &efct_lio_tpg_attr_enable, NULL };
  1321. CONFIGFS_ATTR(efct_lio_npiv_tpg_, enable);
  1322. static struct configfs_attribute *efct_lio_npiv_tpg_attrs[] = {
  1323. &efct_lio_npiv_tpg_attr_enable, NULL };
  1324. static const struct target_core_fabric_ops efct_lio_ops = {
  1325. .module = THIS_MODULE,
  1326. .fabric_name = "efct",
  1327. .node_acl_size = sizeof(struct efct_lio_nacl),
  1328. .max_data_sg_nents = 65535,
  1329. .tpg_get_wwn = efct_lio_get_fabric_wwn,
  1330. .tpg_get_tag = efct_lio_get_tag,
  1331. .fabric_init_nodeacl = efct_lio_init_nodeacl,
  1332. .tpg_check_demo_mode = efct_lio_check_demo_mode,
  1333. .tpg_check_demo_mode_cache = efct_lio_check_demo_mode_cache,
  1334. .tpg_check_demo_mode_write_protect = efct_lio_check_demo_write_protect,
  1335. .tpg_check_prod_mode_write_protect = efct_lio_check_prod_write_protect,
  1336. .check_stop_free = efct_lio_check_stop_free,
  1337. .aborted_task = efct_lio_aborted_task,
  1338. .release_cmd = efct_lio_release_cmd,
  1339. .close_session = efct_lio_close_session,
  1340. .write_pending = efct_lio_write_pending,
  1341. .get_cmd_state = efct_lio_get_cmd_state,
  1342. .queue_data_in = efct_lio_queue_data_in,
  1343. .queue_status = efct_lio_queue_status,
  1344. .queue_tm_rsp = efct_lio_queue_tm_rsp,
  1345. .fabric_make_wwn = efct_lio_make_nport,
  1346. .fabric_drop_wwn = efct_lio_drop_nport,
  1347. .fabric_make_tpg = efct_lio_make_tpg,
  1348. .fabric_drop_tpg = efct_lio_drop_tpg,
  1349. .tpg_check_demo_mode_login_only = efct_lio_check_demo_mode_login_only,
  1350. .tpg_check_prot_fabric_only = NULL,
  1351. .sess_get_initiator_sid = NULL,
  1352. .tfc_tpg_base_attrs = efct_lio_tpg_attrs,
  1353. .tfc_tpg_attrib_attrs = efct_lio_tpg_attrib_attrs,
  1354. .default_submit_type = TARGET_DIRECT_SUBMIT,
  1355. .direct_submit_supp = 1,
  1356. };
  1357. static const struct target_core_fabric_ops efct_lio_npiv_ops = {
  1358. .module = THIS_MODULE,
  1359. .fabric_name = "efct_npiv",
  1360. .node_acl_size = sizeof(struct efct_lio_nacl),
  1361. .max_data_sg_nents = 65535,
  1362. .tpg_get_wwn = efct_lio_get_npiv_fabric_wwn,
  1363. .tpg_get_tag = efct_lio_get_npiv_tag,
  1364. .fabric_init_nodeacl = efct_lio_init_nodeacl,
  1365. .tpg_check_demo_mode = efct_lio_check_demo_mode,
  1366. .tpg_check_demo_mode_cache = efct_lio_check_demo_mode_cache,
  1367. .tpg_check_demo_mode_write_protect =
  1368. efct_lio_npiv_check_demo_write_protect,
  1369. .tpg_check_prod_mode_write_protect =
  1370. efct_lio_npiv_check_prod_write_protect,
  1371. .check_stop_free = efct_lio_check_stop_free,
  1372. .aborted_task = efct_lio_aborted_task,
  1373. .release_cmd = efct_lio_release_cmd,
  1374. .close_session = efct_lio_close_session,
  1375. .write_pending = efct_lio_write_pending,
  1376. .get_cmd_state = efct_lio_get_cmd_state,
  1377. .queue_data_in = efct_lio_queue_data_in,
  1378. .queue_status = efct_lio_queue_status,
  1379. .queue_tm_rsp = efct_lio_queue_tm_rsp,
  1380. .fabric_make_wwn = efct_lio_npiv_make_nport,
  1381. .fabric_drop_wwn = efct_lio_npiv_drop_nport,
  1382. .fabric_make_tpg = efct_lio_npiv_make_tpg,
  1383. .fabric_drop_tpg = efct_lio_npiv_drop_tpg,
  1384. .tpg_check_demo_mode_login_only =
  1385. efct_lio_npiv_check_demo_mode_login_only,
  1386. .tpg_check_prot_fabric_only = NULL,
  1387. .sess_get_initiator_sid = NULL,
  1388. .tfc_tpg_base_attrs = efct_lio_npiv_tpg_attrs,
  1389. .tfc_tpg_attrib_attrs = efct_lio_npiv_tpg_attrib_attrs,
  1390. .default_submit_type = TARGET_DIRECT_SUBMIT,
  1391. .direct_submit_supp = 1,
  1392. };
  1393. int efct_scsi_tgt_driver_init(void)
  1394. {
  1395. int rc;
  1396. /* Register the top level struct config_item_type with TCM core */
  1397. rc = target_register_template(&efct_lio_ops);
  1398. if (rc < 0) {
  1399. pr_err("target_fabric_configfs_register failed with %d\n", rc);
  1400. return rc;
  1401. }
  1402. rc = target_register_template(&efct_lio_npiv_ops);
  1403. if (rc < 0) {
  1404. pr_err("target_fabric_configfs_register failed with %d\n", rc);
  1405. target_unregister_template(&efct_lio_ops);
  1406. return rc;
  1407. }
  1408. return 0;
  1409. }
  1410. int efct_scsi_tgt_driver_exit(void)
  1411. {
  1412. target_unregister_template(&efct_lio_ops);
  1413. target_unregister_template(&efct_lio_npiv_ops);
  1414. return 0;
  1415. }