target_core_pscsi.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. /*******************************************************************************
  2. * Filename: target_core_pscsi.c
  3. *
  4. * This file contains the generic target mode <-> Linux SCSI subsystem plugin.
  5. *
  6. * Copyright (c) 2003, 2004, 2005 PyX Technologies, Inc.
  7. * Copyright (c) 2005, 2006, 2007 SBE, Inc.
  8. * Copyright (c) 2007-2010 Rising Tide Systems
  9. * Copyright (c) 2008-2010 Linux-iSCSI.org
  10. *
  11. * Nicholas A. Bellinger <nab@kernel.org>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  26. *
  27. ******************************************************************************/
  28. #include <linux/string.h>
  29. #include <linux/parser.h>
  30. #include <linux/timer.h>
  31. #include <linux/blkdev.h>
  32. #include <linux/blk_types.h>
  33. #include <linux/slab.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/genhd.h>
  36. #include <linux/cdrom.h>
  37. #include <linux/ratelimit.h>
  38. #include <linux/module.h>
  39. #include <asm/unaligned.h>
  40. #include <scsi/scsi.h>
  41. #include <scsi/scsi_device.h>
  42. #include <scsi/scsi_cmnd.h>
  43. #include <scsi/scsi_host.h>
  44. #include <scsi/scsi_tcq.h>
  45. #include <target/target_core_base.h>
  46. #include <target/target_core_backend.h>
  47. #include "target_core_alua.h"
  48. #include "target_core_pscsi.h"
  49. #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
  50. static inline struct pscsi_dev_virt *PSCSI_DEV(struct se_device *dev)
  51. {
  52. return container_of(dev, struct pscsi_dev_virt, dev);
  53. }
  54. static struct se_subsystem_api pscsi_template;
  55. static int pscsi_execute_cmd(struct se_cmd *cmd);
  56. static void pscsi_req_done(struct request *, int);
  57. /* pscsi_attach_hba():
  58. *
  59. * pscsi_get_sh() used scsi_host_lookup() to locate struct Scsi_Host.
  60. * from the passed SCSI Host ID.
  61. */
  62. static int pscsi_attach_hba(struct se_hba *hba, u32 host_id)
  63. {
  64. struct pscsi_hba_virt *phv;
  65. phv = kzalloc(sizeof(struct pscsi_hba_virt), GFP_KERNEL);
  66. if (!phv) {
  67. pr_err("Unable to allocate struct pscsi_hba_virt\n");
  68. return -ENOMEM;
  69. }
  70. phv->phv_host_id = host_id;
  71. phv->phv_mode = PHV_VIRTUAL_HOST_ID;
  72. hba->hba_ptr = phv;
  73. pr_debug("CORE_HBA[%d] - TCM SCSI HBA Driver %s on"
  74. " Generic Target Core Stack %s\n", hba->hba_id,
  75. PSCSI_VERSION, TARGET_CORE_MOD_VERSION);
  76. pr_debug("CORE_HBA[%d] - Attached SCSI HBA to Generic\n",
  77. hba->hba_id);
  78. return 0;
  79. }
  80. static void pscsi_detach_hba(struct se_hba *hba)
  81. {
  82. struct pscsi_hba_virt *phv = hba->hba_ptr;
  83. struct Scsi_Host *scsi_host = phv->phv_lld_host;
  84. if (scsi_host) {
  85. scsi_host_put(scsi_host);
  86. pr_debug("CORE_HBA[%d] - Detached SCSI HBA: %s from"
  87. " Generic Target Core\n", hba->hba_id,
  88. (scsi_host->hostt->name) ? (scsi_host->hostt->name) :
  89. "Unknown");
  90. } else
  91. pr_debug("CORE_HBA[%d] - Detached Virtual SCSI HBA"
  92. " from Generic Target Core\n", hba->hba_id);
  93. kfree(phv);
  94. hba->hba_ptr = NULL;
  95. }
  96. static int pscsi_pmode_enable_hba(struct se_hba *hba, unsigned long mode_flag)
  97. {
  98. struct pscsi_hba_virt *phv = hba->hba_ptr;
  99. struct Scsi_Host *sh = phv->phv_lld_host;
  100. /*
  101. * Release the struct Scsi_Host
  102. */
  103. if (!mode_flag) {
  104. if (!sh)
  105. return 0;
  106. phv->phv_lld_host = NULL;
  107. phv->phv_mode = PHV_VIRTUAL_HOST_ID;
  108. pr_debug("CORE_HBA[%d] - Disabled pSCSI HBA Passthrough"
  109. " %s\n", hba->hba_id, (sh->hostt->name) ?
  110. (sh->hostt->name) : "Unknown");
  111. scsi_host_put(sh);
  112. return 0;
  113. }
  114. /*
  115. * Otherwise, locate struct Scsi_Host from the original passed
  116. * pSCSI Host ID and enable for phba mode
  117. */
  118. sh = scsi_host_lookup(phv->phv_host_id);
  119. if (IS_ERR(sh)) {
  120. pr_err("pSCSI: Unable to locate SCSI Host for"
  121. " phv_host_id: %d\n", phv->phv_host_id);
  122. return PTR_ERR(sh);
  123. }
  124. phv->phv_lld_host = sh;
  125. phv->phv_mode = PHV_LLD_SCSI_HOST_NO;
  126. pr_debug("CORE_HBA[%d] - Enabled pSCSI HBA Passthrough %s\n",
  127. hba->hba_id, (sh->hostt->name) ? (sh->hostt->name) : "Unknown");
  128. return 1;
  129. }
  130. static void pscsi_tape_read_blocksize(struct se_device *dev,
  131. struct scsi_device *sdev)
  132. {
  133. unsigned char cdb[MAX_COMMAND_SIZE], *buf;
  134. int ret;
  135. buf = kzalloc(12, GFP_KERNEL);
  136. if (!buf)
  137. return;
  138. memset(cdb, 0, MAX_COMMAND_SIZE);
  139. cdb[0] = MODE_SENSE;
  140. cdb[4] = 0x0c; /* 12 bytes */
  141. ret = scsi_execute_req(sdev, cdb, DMA_FROM_DEVICE, buf, 12, NULL,
  142. HZ, 1, NULL);
  143. if (ret)
  144. goto out_free;
  145. /*
  146. * If MODE_SENSE still returns zero, set the default value to 1024.
  147. */
  148. sdev->sector_size = (buf[9] << 16) | (buf[10] << 8) | (buf[11]);
  149. if (!sdev->sector_size)
  150. sdev->sector_size = 1024;
  151. out_free:
  152. kfree(buf);
  153. }
  154. static void
  155. pscsi_set_inquiry_info(struct scsi_device *sdev, struct t10_wwn *wwn)
  156. {
  157. unsigned char *buf;
  158. if (sdev->inquiry_len < INQUIRY_LEN)
  159. return;
  160. buf = sdev->inquiry;
  161. if (!buf)
  162. return;
  163. /*
  164. * Use sdev->inquiry from drivers/scsi/scsi_scan.c:scsi_alloc_sdev()
  165. */
  166. memcpy(&wwn->vendor[0], &buf[8], sizeof(wwn->vendor));
  167. memcpy(&wwn->model[0], &buf[16], sizeof(wwn->model));
  168. memcpy(&wwn->revision[0], &buf[32], sizeof(wwn->revision));
  169. }
  170. static int
  171. pscsi_get_inquiry_vpd_serial(struct scsi_device *sdev, struct t10_wwn *wwn)
  172. {
  173. unsigned char cdb[MAX_COMMAND_SIZE], *buf;
  174. int ret;
  175. buf = kzalloc(INQUIRY_VPD_SERIAL_LEN, GFP_KERNEL);
  176. if (!buf)
  177. return -ENOMEM;
  178. memset(cdb, 0, MAX_COMMAND_SIZE);
  179. cdb[0] = INQUIRY;
  180. cdb[1] = 0x01; /* Query VPD */
  181. cdb[2] = 0x80; /* Unit Serial Number */
  182. cdb[3] = (INQUIRY_VPD_SERIAL_LEN >> 8) & 0xff;
  183. cdb[4] = (INQUIRY_VPD_SERIAL_LEN & 0xff);
  184. ret = scsi_execute_req(sdev, cdb, DMA_FROM_DEVICE, buf,
  185. INQUIRY_VPD_SERIAL_LEN, NULL, HZ, 1, NULL);
  186. if (ret)
  187. goto out_free;
  188. snprintf(&wwn->unit_serial[0], INQUIRY_VPD_SERIAL_LEN, "%s", &buf[4]);
  189. wwn->t10_dev->dev_flags |= DF_FIRMWARE_VPD_UNIT_SERIAL;
  190. kfree(buf);
  191. return 0;
  192. out_free:
  193. kfree(buf);
  194. return -EPERM;
  195. }
  196. static void
  197. pscsi_get_inquiry_vpd_device_ident(struct scsi_device *sdev,
  198. struct t10_wwn *wwn)
  199. {
  200. unsigned char cdb[MAX_COMMAND_SIZE], *buf, *page_83;
  201. int ident_len, page_len, off = 4, ret;
  202. struct t10_vpd *vpd;
  203. buf = kzalloc(INQUIRY_VPD_SERIAL_LEN, GFP_KERNEL);
  204. if (!buf)
  205. return;
  206. memset(cdb, 0, MAX_COMMAND_SIZE);
  207. cdb[0] = INQUIRY;
  208. cdb[1] = 0x01; /* Query VPD */
  209. cdb[2] = 0x83; /* Device Identifier */
  210. cdb[3] = (INQUIRY_VPD_DEVICE_IDENTIFIER_LEN >> 8) & 0xff;
  211. cdb[4] = (INQUIRY_VPD_DEVICE_IDENTIFIER_LEN & 0xff);
  212. ret = scsi_execute_req(sdev, cdb, DMA_FROM_DEVICE, buf,
  213. INQUIRY_VPD_DEVICE_IDENTIFIER_LEN,
  214. NULL, HZ, 1, NULL);
  215. if (ret)
  216. goto out;
  217. page_len = (buf[2] << 8) | buf[3];
  218. while (page_len > 0) {
  219. /* Grab a pointer to the Identification descriptor */
  220. page_83 = &buf[off];
  221. ident_len = page_83[3];
  222. if (!ident_len) {
  223. pr_err("page_83[3]: identifier"
  224. " length zero!\n");
  225. break;
  226. }
  227. pr_debug("T10 VPD Identifier Length: %d\n", ident_len);
  228. vpd = kzalloc(sizeof(struct t10_vpd), GFP_KERNEL);
  229. if (!vpd) {
  230. pr_err("Unable to allocate memory for"
  231. " struct t10_vpd\n");
  232. goto out;
  233. }
  234. INIT_LIST_HEAD(&vpd->vpd_list);
  235. transport_set_vpd_proto_id(vpd, page_83);
  236. transport_set_vpd_assoc(vpd, page_83);
  237. if (transport_set_vpd_ident_type(vpd, page_83) < 0) {
  238. off += (ident_len + 4);
  239. page_len -= (ident_len + 4);
  240. kfree(vpd);
  241. continue;
  242. }
  243. if (transport_set_vpd_ident(vpd, page_83) < 0) {
  244. off += (ident_len + 4);
  245. page_len -= (ident_len + 4);
  246. kfree(vpd);
  247. continue;
  248. }
  249. list_add_tail(&vpd->vpd_list, &wwn->t10_vpd_list);
  250. off += (ident_len + 4);
  251. page_len -= (ident_len + 4);
  252. }
  253. out:
  254. kfree(buf);
  255. }
  256. static int pscsi_add_device_to_list(struct se_device *dev,
  257. struct scsi_device *sd)
  258. {
  259. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  260. struct request_queue *q = sd->request_queue;
  261. pdv->pdv_sd = sd;
  262. if (!sd->queue_depth) {
  263. sd->queue_depth = PSCSI_DEFAULT_QUEUEDEPTH;
  264. pr_err("Set broken SCSI Device %d:%d:%d"
  265. " queue_depth to %d\n", sd->channel, sd->id,
  266. sd->lun, sd->queue_depth);
  267. }
  268. dev->dev_attrib.hw_block_size = sd->sector_size;
  269. dev->dev_attrib.hw_max_sectors =
  270. min_t(int, sd->host->max_sectors, queue_max_hw_sectors(q));
  271. dev->dev_attrib.hw_queue_depth = sd->queue_depth;
  272. /*
  273. * Setup our standard INQUIRY info into se_dev->t10_wwn
  274. */
  275. pscsi_set_inquiry_info(sd, &dev->t10_wwn);
  276. /*
  277. * Locate VPD WWN Information used for various purposes within
  278. * the Storage Engine.
  279. */
  280. if (!pscsi_get_inquiry_vpd_serial(sd, &dev->t10_wwn)) {
  281. /*
  282. * If VPD Unit Serial returned GOOD status, try
  283. * VPD Device Identification page (0x83).
  284. */
  285. pscsi_get_inquiry_vpd_device_ident(sd, &dev->t10_wwn);
  286. }
  287. /*
  288. * For TYPE_TAPE, attempt to determine blocksize with MODE_SENSE.
  289. */
  290. if (sd->type == TYPE_TAPE)
  291. pscsi_tape_read_blocksize(dev, sd);
  292. return 0;
  293. }
  294. static struct se_device *pscsi_alloc_device(struct se_hba *hba,
  295. const char *name)
  296. {
  297. struct pscsi_dev_virt *pdv;
  298. pdv = kzalloc(sizeof(struct pscsi_dev_virt), GFP_KERNEL);
  299. if (!pdv) {
  300. pr_err("Unable to allocate memory for struct pscsi_dev_virt\n");
  301. return NULL;
  302. }
  303. pr_debug("PSCSI: Allocated pdv: %p for %s\n", pdv, name);
  304. return &pdv->dev;
  305. }
  306. /*
  307. * Called with struct Scsi_Host->host_lock called.
  308. */
  309. static int pscsi_create_type_disk(struct se_device *dev, struct scsi_device *sd)
  310. __releases(sh->host_lock)
  311. {
  312. struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr;
  313. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  314. struct Scsi_Host *sh = sd->host;
  315. struct block_device *bd;
  316. int ret;
  317. if (scsi_device_get(sd)) {
  318. pr_err("scsi_device_get() failed for %d:%d:%d:%d\n",
  319. sh->host_no, sd->channel, sd->id, sd->lun);
  320. spin_unlock_irq(sh->host_lock);
  321. return -EIO;
  322. }
  323. spin_unlock_irq(sh->host_lock);
  324. /*
  325. * Claim exclusive struct block_device access to struct scsi_device
  326. * for TYPE_DISK using supplied udev_path
  327. */
  328. bd = blkdev_get_by_path(dev->udev_path,
  329. FMODE_WRITE|FMODE_READ|FMODE_EXCL, pdv);
  330. if (IS_ERR(bd)) {
  331. pr_err("pSCSI: blkdev_get_by_path() failed\n");
  332. scsi_device_put(sd);
  333. return PTR_ERR(bd);
  334. }
  335. pdv->pdv_bd = bd;
  336. ret = pscsi_add_device_to_list(dev, sd);
  337. if (ret) {
  338. blkdev_put(pdv->pdv_bd, FMODE_WRITE|FMODE_READ|FMODE_EXCL);
  339. scsi_device_put(sd);
  340. return ret;
  341. }
  342. pr_debug("CORE_PSCSI[%d] - Added TYPE_DISK for %d:%d:%d:%d\n",
  343. phv->phv_host_id, sh->host_no, sd->channel, sd->id, sd->lun);
  344. return 0;
  345. }
  346. /*
  347. * Called with struct Scsi_Host->host_lock called.
  348. */
  349. static int pscsi_create_type_rom(struct se_device *dev, struct scsi_device *sd)
  350. __releases(sh->host_lock)
  351. {
  352. struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr;
  353. struct Scsi_Host *sh = sd->host;
  354. int ret;
  355. if (scsi_device_get(sd)) {
  356. pr_err("scsi_device_get() failed for %d:%d:%d:%d\n",
  357. sh->host_no, sd->channel, sd->id, sd->lun);
  358. spin_unlock_irq(sh->host_lock);
  359. return -EIO;
  360. }
  361. spin_unlock_irq(sh->host_lock);
  362. ret = pscsi_add_device_to_list(dev, sd);
  363. if (ret) {
  364. scsi_device_put(sd);
  365. return ret;
  366. }
  367. pr_debug("CORE_PSCSI[%d] - Added Type: %s for %d:%d:%d:%d\n",
  368. phv->phv_host_id, scsi_device_type(sd->type), sh->host_no,
  369. sd->channel, sd->id, sd->lun);
  370. return 0;
  371. }
  372. /*
  373. * Called with struct Scsi_Host->host_lock called.
  374. */
  375. static int pscsi_create_type_other(struct se_device *dev,
  376. struct scsi_device *sd)
  377. __releases(sh->host_lock)
  378. {
  379. struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr;
  380. struct Scsi_Host *sh = sd->host;
  381. int ret;
  382. spin_unlock_irq(sh->host_lock);
  383. ret = pscsi_add_device_to_list(dev, sd);
  384. if (ret)
  385. return ret;
  386. pr_debug("CORE_PSCSI[%d] - Added Type: %s for %d:%d:%d:%d\n",
  387. phv->phv_host_id, scsi_device_type(sd->type), sh->host_no,
  388. sd->channel, sd->id, sd->lun);
  389. return 0;
  390. }
  391. static int pscsi_configure_device(struct se_device *dev)
  392. {
  393. struct se_hba *hba = dev->se_hba;
  394. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  395. struct scsi_device *sd;
  396. struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr;
  397. struct Scsi_Host *sh = phv->phv_lld_host;
  398. int legacy_mode_enable = 0;
  399. int ret;
  400. if (!(pdv->pdv_flags & PDF_HAS_CHANNEL_ID) ||
  401. !(pdv->pdv_flags & PDF_HAS_TARGET_ID) ||
  402. !(pdv->pdv_flags & PDF_HAS_LUN_ID)) {
  403. pr_err("Missing scsi_channel_id=, scsi_target_id= and"
  404. " scsi_lun_id= parameters\n");
  405. return -EINVAL;
  406. }
  407. /*
  408. * If not running in PHV_LLD_SCSI_HOST_NO mode, locate the
  409. * struct Scsi_Host we will need to bring the TCM/pSCSI object online
  410. */
  411. if (!sh) {
  412. if (phv->phv_mode == PHV_LLD_SCSI_HOST_NO) {
  413. pr_err("pSCSI: Unable to locate struct"
  414. " Scsi_Host for PHV_LLD_SCSI_HOST_NO\n");
  415. return -ENODEV;
  416. }
  417. /*
  418. * For the newer PHV_VIRTUAL_HOST_ID struct scsi_device
  419. * reference, we enforce that udev_path has been set
  420. */
  421. if (!(dev->dev_flags & DF_USING_UDEV_PATH)) {
  422. pr_err("pSCSI: udev_path attribute has not"
  423. " been set before ENABLE=1\n");
  424. return -EINVAL;
  425. }
  426. /*
  427. * If no scsi_host_id= was passed for PHV_VIRTUAL_HOST_ID,
  428. * use the original TCM hba ID to reference Linux/SCSI Host No
  429. * and enable for PHV_LLD_SCSI_HOST_NO mode.
  430. */
  431. if (!(pdv->pdv_flags & PDF_HAS_VIRT_HOST_ID)) {
  432. if (hba->dev_count) {
  433. pr_err("pSCSI: Unable to set hba_mode"
  434. " with active devices\n");
  435. return -EEXIST;
  436. }
  437. if (pscsi_pmode_enable_hba(hba, 1) != 1)
  438. return -ENODEV;
  439. legacy_mode_enable = 1;
  440. hba->hba_flags |= HBA_FLAGS_PSCSI_MODE;
  441. sh = phv->phv_lld_host;
  442. } else {
  443. sh = scsi_host_lookup(pdv->pdv_host_id);
  444. if (IS_ERR(sh)) {
  445. pr_err("pSCSI: Unable to locate"
  446. " pdv_host_id: %d\n", pdv->pdv_host_id);
  447. return PTR_ERR(sh);
  448. }
  449. }
  450. } else {
  451. if (phv->phv_mode == PHV_VIRTUAL_HOST_ID) {
  452. pr_err("pSCSI: PHV_VIRTUAL_HOST_ID set while"
  453. " struct Scsi_Host exists\n");
  454. return -EEXIST;
  455. }
  456. }
  457. spin_lock_irq(sh->host_lock);
  458. list_for_each_entry(sd, &sh->__devices, siblings) {
  459. if ((pdv->pdv_channel_id != sd->channel) ||
  460. (pdv->pdv_target_id != sd->id) ||
  461. (pdv->pdv_lun_id != sd->lun))
  462. continue;
  463. /*
  464. * Functions will release the held struct scsi_host->host_lock
  465. * before calling calling pscsi_add_device_to_list() to register
  466. * struct scsi_device with target_core_mod.
  467. */
  468. switch (sd->type) {
  469. case TYPE_DISK:
  470. ret = pscsi_create_type_disk(dev, sd);
  471. break;
  472. case TYPE_ROM:
  473. ret = pscsi_create_type_rom(dev, sd);
  474. break;
  475. default:
  476. ret = pscsi_create_type_other(dev, sd);
  477. break;
  478. }
  479. if (ret) {
  480. if (phv->phv_mode == PHV_VIRTUAL_HOST_ID)
  481. scsi_host_put(sh);
  482. else if (legacy_mode_enable) {
  483. pscsi_pmode_enable_hba(hba, 0);
  484. hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE;
  485. }
  486. pdv->pdv_sd = NULL;
  487. return ret;
  488. }
  489. return 0;
  490. }
  491. spin_unlock_irq(sh->host_lock);
  492. pr_err("pSCSI: Unable to locate %d:%d:%d:%d\n", sh->host_no,
  493. pdv->pdv_channel_id, pdv->pdv_target_id, pdv->pdv_lun_id);
  494. if (phv->phv_mode == PHV_VIRTUAL_HOST_ID)
  495. scsi_host_put(sh);
  496. else if (legacy_mode_enable) {
  497. pscsi_pmode_enable_hba(hba, 0);
  498. hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE;
  499. }
  500. return -ENODEV;
  501. }
  502. static void pscsi_free_device(struct se_device *dev)
  503. {
  504. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  505. struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr;
  506. struct scsi_device *sd = pdv->pdv_sd;
  507. if (sd) {
  508. /*
  509. * Release exclusive pSCSI internal struct block_device claim for
  510. * struct scsi_device with TYPE_DISK from pscsi_create_type_disk()
  511. */
  512. if ((sd->type == TYPE_DISK) && pdv->pdv_bd) {
  513. blkdev_put(pdv->pdv_bd,
  514. FMODE_WRITE|FMODE_READ|FMODE_EXCL);
  515. pdv->pdv_bd = NULL;
  516. }
  517. /*
  518. * For HBA mode PHV_LLD_SCSI_HOST_NO, release the reference
  519. * to struct Scsi_Host now.
  520. */
  521. if ((phv->phv_mode == PHV_LLD_SCSI_HOST_NO) &&
  522. (phv->phv_lld_host != NULL))
  523. scsi_host_put(phv->phv_lld_host);
  524. if ((sd->type == TYPE_DISK) || (sd->type == TYPE_ROM))
  525. scsi_device_put(sd);
  526. pdv->pdv_sd = NULL;
  527. }
  528. kfree(pdv);
  529. }
  530. static void pscsi_transport_complete(struct se_cmd *cmd, struct scatterlist *sg,
  531. unsigned char *sense_buffer)
  532. {
  533. struct pscsi_dev_virt *pdv = PSCSI_DEV(cmd->se_dev);
  534. struct scsi_device *sd = pdv->pdv_sd;
  535. int result;
  536. struct pscsi_plugin_task *pt = cmd->priv;
  537. unsigned char *cdb;
  538. /*
  539. * Special case for REPORT_LUNs handling where pscsi_plugin_task has
  540. * not been allocated because TCM is handling the emulation directly.
  541. */
  542. if (!pt)
  543. return;
  544. cdb = &pt->pscsi_cdb[0];
  545. result = pt->pscsi_result;
  546. /*
  547. * Hack to make sure that Write-Protect modepage is set if R/O mode is
  548. * forced.
  549. */
  550. if (!cmd->se_deve || !cmd->data_length)
  551. goto after_mode_sense;
  552. if (((cdb[0] == MODE_SENSE) || (cdb[0] == MODE_SENSE_10)) &&
  553. (status_byte(result) << 1) == SAM_STAT_GOOD) {
  554. if (cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) {
  555. unsigned char *buf = transport_kmap_data_sg(cmd);
  556. if (cdb[0] == MODE_SENSE_10) {
  557. if (!(buf[3] & 0x80))
  558. buf[3] |= 0x80;
  559. } else {
  560. if (!(buf[2] & 0x80))
  561. buf[2] |= 0x80;
  562. }
  563. transport_kunmap_data_sg(cmd);
  564. }
  565. }
  566. after_mode_sense:
  567. if (sd->type != TYPE_TAPE || !cmd->data_length)
  568. goto after_mode_select;
  569. /*
  570. * Hack to correctly obtain the initiator requested blocksize for
  571. * TYPE_TAPE. Since this value is dependent upon each tape media,
  572. * struct scsi_device->sector_size will not contain the correct value
  573. * by default, so we go ahead and set it so
  574. * TRANSPORT(dev)->get_blockdev() returns the correct value to the
  575. * storage engine.
  576. */
  577. if (((cdb[0] == MODE_SELECT) || (cdb[0] == MODE_SELECT_10)) &&
  578. (status_byte(result) << 1) == SAM_STAT_GOOD) {
  579. unsigned char *buf;
  580. u16 bdl;
  581. u32 blocksize;
  582. buf = sg_virt(&sg[0]);
  583. if (!buf) {
  584. pr_err("Unable to get buf for scatterlist\n");
  585. goto after_mode_select;
  586. }
  587. if (cdb[0] == MODE_SELECT)
  588. bdl = (buf[3]);
  589. else
  590. bdl = (buf[6] << 8) | (buf[7]);
  591. if (!bdl)
  592. goto after_mode_select;
  593. if (cdb[0] == MODE_SELECT)
  594. blocksize = (buf[9] << 16) | (buf[10] << 8) |
  595. (buf[11]);
  596. else
  597. blocksize = (buf[13] << 16) | (buf[14] << 8) |
  598. (buf[15]);
  599. sd->sector_size = blocksize;
  600. }
  601. after_mode_select:
  602. if (sense_buffer && (status_byte(result) & CHECK_CONDITION)) {
  603. memcpy(sense_buffer, pt->pscsi_sense, TRANSPORT_SENSE_BUFFER);
  604. cmd->se_cmd_flags |= SCF_TRANSPORT_TASK_SENSE;
  605. }
  606. }
  607. enum {
  608. Opt_scsi_host_id, Opt_scsi_channel_id, Opt_scsi_target_id,
  609. Opt_scsi_lun_id, Opt_err
  610. };
  611. static match_table_t tokens = {
  612. {Opt_scsi_host_id, "scsi_host_id=%d"},
  613. {Opt_scsi_channel_id, "scsi_channel_id=%d"},
  614. {Opt_scsi_target_id, "scsi_target_id=%d"},
  615. {Opt_scsi_lun_id, "scsi_lun_id=%d"},
  616. {Opt_err, NULL}
  617. };
  618. static ssize_t pscsi_set_configfs_dev_params(struct se_device *dev,
  619. const char *page, ssize_t count)
  620. {
  621. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  622. struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr;
  623. char *orig, *ptr, *opts;
  624. substring_t args[MAX_OPT_ARGS];
  625. int ret = 0, arg, token;
  626. opts = kstrdup(page, GFP_KERNEL);
  627. if (!opts)
  628. return -ENOMEM;
  629. orig = opts;
  630. while ((ptr = strsep(&opts, ",\n")) != NULL) {
  631. if (!*ptr)
  632. continue;
  633. token = match_token(ptr, tokens, args);
  634. switch (token) {
  635. case Opt_scsi_host_id:
  636. if (phv->phv_mode == PHV_LLD_SCSI_HOST_NO) {
  637. pr_err("PSCSI[%d]: Unable to accept"
  638. " scsi_host_id while phv_mode =="
  639. " PHV_LLD_SCSI_HOST_NO\n",
  640. phv->phv_host_id);
  641. ret = -EINVAL;
  642. goto out;
  643. }
  644. match_int(args, &arg);
  645. pdv->pdv_host_id = arg;
  646. pr_debug("PSCSI[%d]: Referencing SCSI Host ID:"
  647. " %d\n", phv->phv_host_id, pdv->pdv_host_id);
  648. pdv->pdv_flags |= PDF_HAS_VIRT_HOST_ID;
  649. break;
  650. case Opt_scsi_channel_id:
  651. match_int(args, &arg);
  652. pdv->pdv_channel_id = arg;
  653. pr_debug("PSCSI[%d]: Referencing SCSI Channel"
  654. " ID: %d\n", phv->phv_host_id,
  655. pdv->pdv_channel_id);
  656. pdv->pdv_flags |= PDF_HAS_CHANNEL_ID;
  657. break;
  658. case Opt_scsi_target_id:
  659. match_int(args, &arg);
  660. pdv->pdv_target_id = arg;
  661. pr_debug("PSCSI[%d]: Referencing SCSI Target"
  662. " ID: %d\n", phv->phv_host_id,
  663. pdv->pdv_target_id);
  664. pdv->pdv_flags |= PDF_HAS_TARGET_ID;
  665. break;
  666. case Opt_scsi_lun_id:
  667. match_int(args, &arg);
  668. pdv->pdv_lun_id = arg;
  669. pr_debug("PSCSI[%d]: Referencing SCSI LUN ID:"
  670. " %d\n", phv->phv_host_id, pdv->pdv_lun_id);
  671. pdv->pdv_flags |= PDF_HAS_LUN_ID;
  672. break;
  673. default:
  674. break;
  675. }
  676. }
  677. out:
  678. kfree(orig);
  679. return (!ret) ? count : ret;
  680. }
  681. static ssize_t pscsi_show_configfs_dev_params(struct se_device *dev, char *b)
  682. {
  683. struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr;
  684. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  685. struct scsi_device *sd = pdv->pdv_sd;
  686. unsigned char host_id[16];
  687. ssize_t bl;
  688. int i;
  689. if (phv->phv_mode == PHV_VIRTUAL_HOST_ID)
  690. snprintf(host_id, 16, "%d", pdv->pdv_host_id);
  691. else
  692. snprintf(host_id, 16, "PHBA Mode");
  693. bl = sprintf(b, "SCSI Device Bus Location:"
  694. " Channel ID: %d Target ID: %d LUN: %d Host ID: %s\n",
  695. pdv->pdv_channel_id, pdv->pdv_target_id, pdv->pdv_lun_id,
  696. host_id);
  697. if (sd) {
  698. bl += sprintf(b + bl, " ");
  699. bl += sprintf(b + bl, "Vendor: ");
  700. for (i = 0; i < 8; i++) {
  701. if (ISPRINT(sd->vendor[i])) /* printable character? */
  702. bl += sprintf(b + bl, "%c", sd->vendor[i]);
  703. else
  704. bl += sprintf(b + bl, " ");
  705. }
  706. bl += sprintf(b + bl, " Model: ");
  707. for (i = 0; i < 16; i++) {
  708. if (ISPRINT(sd->model[i])) /* printable character ? */
  709. bl += sprintf(b + bl, "%c", sd->model[i]);
  710. else
  711. bl += sprintf(b + bl, " ");
  712. }
  713. bl += sprintf(b + bl, " Rev: ");
  714. for (i = 0; i < 4; i++) {
  715. if (ISPRINT(sd->rev[i])) /* printable character ? */
  716. bl += sprintf(b + bl, "%c", sd->rev[i]);
  717. else
  718. bl += sprintf(b + bl, " ");
  719. }
  720. bl += sprintf(b + bl, "\n");
  721. }
  722. return bl;
  723. }
  724. static void pscsi_bi_endio(struct bio *bio, int error)
  725. {
  726. bio_put(bio);
  727. }
  728. static inline struct bio *pscsi_get_bio(int sg_num)
  729. {
  730. struct bio *bio;
  731. /*
  732. * Use bio_malloc() following the comment in for bio -> struct request
  733. * in block/blk-core.c:blk_make_request()
  734. */
  735. bio = bio_kmalloc(GFP_KERNEL, sg_num);
  736. if (!bio) {
  737. pr_err("PSCSI: bio_kmalloc() failed\n");
  738. return NULL;
  739. }
  740. bio->bi_end_io = pscsi_bi_endio;
  741. return bio;
  742. }
  743. static int pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl,
  744. u32 sgl_nents, enum dma_data_direction data_direction,
  745. struct bio **hbio)
  746. {
  747. struct pscsi_dev_virt *pdv = PSCSI_DEV(cmd->se_dev);
  748. struct bio *bio = NULL, *tbio = NULL;
  749. struct page *page;
  750. struct scatterlist *sg;
  751. u32 data_len = cmd->data_length, i, len, bytes, off;
  752. int nr_pages = (cmd->data_length + sgl[0].offset +
  753. PAGE_SIZE - 1) >> PAGE_SHIFT;
  754. int nr_vecs = 0, rc;
  755. int rw = (data_direction == DMA_TO_DEVICE);
  756. *hbio = NULL;
  757. pr_debug("PSCSI: nr_pages: %d\n", nr_pages);
  758. for_each_sg(sgl, sg, sgl_nents, i) {
  759. page = sg_page(sg);
  760. off = sg->offset;
  761. len = sg->length;
  762. pr_debug("PSCSI: i: %d page: %p len: %d off: %d\n", i,
  763. page, len, off);
  764. while (len > 0 && data_len > 0) {
  765. bytes = min_t(unsigned int, len, PAGE_SIZE - off);
  766. bytes = min(bytes, data_len);
  767. if (!bio) {
  768. nr_vecs = min_t(int, BIO_MAX_PAGES, nr_pages);
  769. nr_pages -= nr_vecs;
  770. /*
  771. * Calls bio_kmalloc() and sets bio->bi_end_io()
  772. */
  773. bio = pscsi_get_bio(nr_vecs);
  774. if (!bio)
  775. goto fail;
  776. if (rw)
  777. bio->bi_rw |= REQ_WRITE;
  778. pr_debug("PSCSI: Allocated bio: %p,"
  779. " dir: %s nr_vecs: %d\n", bio,
  780. (rw) ? "rw" : "r", nr_vecs);
  781. /*
  782. * Set *hbio pointer to handle the case:
  783. * nr_pages > BIO_MAX_PAGES, where additional
  784. * bios need to be added to complete a given
  785. * command.
  786. */
  787. if (!*hbio)
  788. *hbio = tbio = bio;
  789. else
  790. tbio = tbio->bi_next = bio;
  791. }
  792. pr_debug("PSCSI: Calling bio_add_pc_page() i: %d"
  793. " bio: %p page: %p len: %d off: %d\n", i, bio,
  794. page, len, off);
  795. rc = bio_add_pc_page(pdv->pdv_sd->request_queue,
  796. bio, page, bytes, off);
  797. if (rc != bytes)
  798. goto fail;
  799. pr_debug("PSCSI: bio->bi_vcnt: %d nr_vecs: %d\n",
  800. bio->bi_vcnt, nr_vecs);
  801. if (bio->bi_vcnt > nr_vecs) {
  802. pr_debug("PSCSI: Reached bio->bi_vcnt max:"
  803. " %d i: %d bio: %p, allocating another"
  804. " bio\n", bio->bi_vcnt, i, bio);
  805. /*
  806. * Clear the pointer so that another bio will
  807. * be allocated with pscsi_get_bio() above, the
  808. * current bio has already been set *tbio and
  809. * bio->bi_next.
  810. */
  811. bio = NULL;
  812. }
  813. page++;
  814. len -= bytes;
  815. data_len -= bytes;
  816. off = 0;
  817. }
  818. }
  819. return sgl_nents;
  820. fail:
  821. while (*hbio) {
  822. bio = *hbio;
  823. *hbio = (*hbio)->bi_next;
  824. bio->bi_next = NULL;
  825. bio_endio(bio, 0); /* XXX: should be error */
  826. }
  827. cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  828. return -ENOMEM;
  829. }
  830. /*
  831. * Clear a lun set in the cdb if the initiator talking to use spoke
  832. * and old standards version, as we can't assume the underlying device
  833. * won't choke up on it.
  834. */
  835. static inline void pscsi_clear_cdb_lun(unsigned char *cdb)
  836. {
  837. switch (cdb[0]) {
  838. case READ_10: /* SBC - RDProtect */
  839. case READ_12: /* SBC - RDProtect */
  840. case READ_16: /* SBC - RDProtect */
  841. case SEND_DIAGNOSTIC: /* SPC - SELF-TEST Code */
  842. case VERIFY: /* SBC - VRProtect */
  843. case VERIFY_16: /* SBC - VRProtect */
  844. case WRITE_VERIFY: /* SBC - VRProtect */
  845. case WRITE_VERIFY_12: /* SBC - VRProtect */
  846. case MAINTENANCE_IN: /* SPC - Parameter Data Format for SA RTPG */
  847. break;
  848. default:
  849. cdb[1] &= 0x1f; /* clear logical unit number */
  850. break;
  851. }
  852. }
  853. static int pscsi_parse_cdb(struct se_cmd *cmd)
  854. {
  855. unsigned char *cdb = cmd->t_task_cdb;
  856. if (cmd->se_cmd_flags & SCF_BIDI) {
  857. cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION;
  858. cmd->scsi_sense_reason = TCM_UNSUPPORTED_SCSI_OPCODE;
  859. return -EINVAL;
  860. }
  861. pscsi_clear_cdb_lun(cdb);
  862. /*
  863. * For REPORT LUNS we always need to emulate the response, for everything
  864. * else the default for pSCSI is to pass the command to the underlying
  865. * LLD / physical hardware.
  866. */
  867. switch (cdb[0]) {
  868. case REPORT_LUNS:
  869. cmd->execute_cmd = spc_emulate_report_luns;
  870. return 0;
  871. case READ_6:
  872. case READ_10:
  873. case READ_12:
  874. case READ_16:
  875. case WRITE_6:
  876. case WRITE_10:
  877. case WRITE_12:
  878. case WRITE_16:
  879. case WRITE_VERIFY:
  880. cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
  881. /* FALLTHROUGH*/
  882. default:
  883. cmd->execute_cmd = pscsi_execute_cmd;
  884. return 0;
  885. }
  886. }
  887. static int pscsi_execute_cmd(struct se_cmd *cmd)
  888. {
  889. struct scatterlist *sgl = cmd->t_data_sg;
  890. u32 sgl_nents = cmd->t_data_nents;
  891. enum dma_data_direction data_direction = cmd->data_direction;
  892. struct pscsi_dev_virt *pdv = PSCSI_DEV(cmd->se_dev);
  893. struct pscsi_plugin_task *pt;
  894. struct request *req;
  895. struct bio *hbio;
  896. int ret;
  897. /*
  898. * Dynamically alloc cdb space, since it may be larger than
  899. * TCM_MAX_COMMAND_SIZE
  900. */
  901. pt = kzalloc(sizeof(*pt) + scsi_command_size(cmd->t_task_cdb), GFP_KERNEL);
  902. if (!pt) {
  903. cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  904. return -ENOMEM;
  905. }
  906. cmd->priv = pt;
  907. memcpy(pt->pscsi_cdb, cmd->t_task_cdb,
  908. scsi_command_size(cmd->t_task_cdb));
  909. if (!sgl) {
  910. req = blk_get_request(pdv->pdv_sd->request_queue,
  911. (data_direction == DMA_TO_DEVICE),
  912. GFP_KERNEL);
  913. if (!req || IS_ERR(req)) {
  914. pr_err("PSCSI: blk_get_request() failed: %ld\n",
  915. req ? IS_ERR(req) : -ENOMEM);
  916. cmd->scsi_sense_reason =
  917. TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  918. goto fail;
  919. }
  920. } else {
  921. BUG_ON(!cmd->data_length);
  922. ret = pscsi_map_sg(cmd, sgl, sgl_nents, data_direction, &hbio);
  923. if (ret < 0) {
  924. cmd->scsi_sense_reason =
  925. TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  926. goto fail;
  927. }
  928. req = blk_make_request(pdv->pdv_sd->request_queue, hbio,
  929. GFP_KERNEL);
  930. if (IS_ERR(req)) {
  931. pr_err("pSCSI: blk_make_request() failed\n");
  932. goto fail_free_bio;
  933. }
  934. }
  935. req->cmd_type = REQ_TYPE_BLOCK_PC;
  936. req->end_io = pscsi_req_done;
  937. req->end_io_data = cmd;
  938. req->cmd_len = scsi_command_size(pt->pscsi_cdb);
  939. req->cmd = &pt->pscsi_cdb[0];
  940. req->sense = &pt->pscsi_sense[0];
  941. req->sense_len = 0;
  942. if (pdv->pdv_sd->type == TYPE_DISK)
  943. req->timeout = PS_TIMEOUT_DISK;
  944. else
  945. req->timeout = PS_TIMEOUT_OTHER;
  946. req->retries = PS_RETRY;
  947. blk_execute_rq_nowait(pdv->pdv_sd->request_queue, NULL, req,
  948. (cmd->sam_task_attr == MSG_HEAD_TAG),
  949. pscsi_req_done);
  950. return 0;
  951. fail_free_bio:
  952. while (hbio) {
  953. struct bio *bio = hbio;
  954. hbio = hbio->bi_next;
  955. bio->bi_next = NULL;
  956. bio_endio(bio, 0); /* XXX: should be error */
  957. }
  958. cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  959. fail:
  960. kfree(pt);
  961. return -ENOMEM;
  962. }
  963. /* pscsi_get_device_rev():
  964. *
  965. *
  966. */
  967. static u32 pscsi_get_device_rev(struct se_device *dev)
  968. {
  969. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  970. struct scsi_device *sd = pdv->pdv_sd;
  971. return (sd->scsi_level - 1) ? sd->scsi_level - 1 : 1;
  972. }
  973. /* pscsi_get_device_type():
  974. *
  975. *
  976. */
  977. static u32 pscsi_get_device_type(struct se_device *dev)
  978. {
  979. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  980. struct scsi_device *sd = pdv->pdv_sd;
  981. return sd->type;
  982. }
  983. static sector_t pscsi_get_blocks(struct se_device *dev)
  984. {
  985. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  986. if (pdv->pdv_bd && pdv->pdv_bd->bd_part)
  987. return pdv->pdv_bd->bd_part->nr_sects;
  988. dump_stack();
  989. return 0;
  990. }
  991. static void pscsi_req_done(struct request *req, int uptodate)
  992. {
  993. struct se_cmd *cmd = req->end_io_data;
  994. struct pscsi_plugin_task *pt = cmd->priv;
  995. pt->pscsi_result = req->errors;
  996. pt->pscsi_resid = req->resid_len;
  997. cmd->scsi_status = status_byte(pt->pscsi_result) << 1;
  998. if (cmd->scsi_status) {
  999. pr_debug("PSCSI Status Byte exception at cmd: %p CDB:"
  1000. " 0x%02x Result: 0x%08x\n", cmd, pt->pscsi_cdb[0],
  1001. pt->pscsi_result);
  1002. }
  1003. switch (host_byte(pt->pscsi_result)) {
  1004. case DID_OK:
  1005. target_complete_cmd(cmd, cmd->scsi_status);
  1006. break;
  1007. default:
  1008. pr_debug("PSCSI Host Byte exception at cmd: %p CDB:"
  1009. " 0x%02x Result: 0x%08x\n", cmd, pt->pscsi_cdb[0],
  1010. pt->pscsi_result);
  1011. cmd->scsi_sense_reason = TCM_UNSUPPORTED_SCSI_OPCODE;
  1012. target_complete_cmd(cmd, SAM_STAT_CHECK_CONDITION);
  1013. break;
  1014. }
  1015. __blk_put_request(req->q, req);
  1016. kfree(pt);
  1017. }
  1018. static struct se_subsystem_api pscsi_template = {
  1019. .name = "pscsi",
  1020. .owner = THIS_MODULE,
  1021. .transport_type = TRANSPORT_PLUGIN_PHBA_PDEV,
  1022. .attach_hba = pscsi_attach_hba,
  1023. .detach_hba = pscsi_detach_hba,
  1024. .pmode_enable_hba = pscsi_pmode_enable_hba,
  1025. .alloc_device = pscsi_alloc_device,
  1026. .configure_device = pscsi_configure_device,
  1027. .free_device = pscsi_free_device,
  1028. .transport_complete = pscsi_transport_complete,
  1029. .parse_cdb = pscsi_parse_cdb,
  1030. .set_configfs_dev_params = pscsi_set_configfs_dev_params,
  1031. .show_configfs_dev_params = pscsi_show_configfs_dev_params,
  1032. .get_device_rev = pscsi_get_device_rev,
  1033. .get_device_type = pscsi_get_device_type,
  1034. .get_blocks = pscsi_get_blocks,
  1035. };
  1036. static int __init pscsi_module_init(void)
  1037. {
  1038. return transport_subsystem_register(&pscsi_template);
  1039. }
  1040. static void pscsi_module_exit(void)
  1041. {
  1042. transport_subsystem_release(&pscsi_template);
  1043. }
  1044. MODULE_DESCRIPTION("TCM PSCSI subsystem plugin");
  1045. MODULE_AUTHOR("nab@Linux-iSCSI.org");
  1046. MODULE_LICENSE("GPL");
  1047. module_init(pscsi_module_init);
  1048. module_exit(pscsi_module_exit);