target_core_pscsi.c 31 KB

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