target_core_pscsi.c 30 KB

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