target_core_pscsi.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  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-2012 RisingTide Systems LLC.
  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 (IS_ERR(sh)) {
  117. pr_err("pSCSI: Unable to locate SCSI Host for"
  118. " phv_host_id: %d\n", phv->phv_host_id);
  119. return PTR_ERR(sh);
  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:%d"
  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:%d\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:%d\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:%d\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:%d\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:%d\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 (IS_ERR(sh)) {
  442. pr_err("pSCSI: Unable to locate"
  443. " pdv_host_id: %d\n", pdv->pdv_host_id);
  444. return PTR_ERR(sh);
  445. }
  446. }
  447. } else {
  448. if (phv->phv_mode == PHV_VIRTUAL_HOST_ID) {
  449. pr_err("pSCSI: PHV_VIRTUAL_HOST_ID set while"
  450. " struct Scsi_Host exists\n");
  451. return -EEXIST;
  452. }
  453. }
  454. spin_lock_irq(sh->host_lock);
  455. list_for_each_entry(sd, &sh->__devices, siblings) {
  456. if ((pdv->pdv_channel_id != sd->channel) ||
  457. (pdv->pdv_target_id != sd->id) ||
  458. (pdv->pdv_lun_id != sd->lun))
  459. continue;
  460. /*
  461. * Functions will release the held struct scsi_host->host_lock
  462. * before calling calling pscsi_add_device_to_list() to register
  463. * struct scsi_device with target_core_mod.
  464. */
  465. switch (sd->type) {
  466. case TYPE_DISK:
  467. ret = pscsi_create_type_disk(dev, sd);
  468. break;
  469. case TYPE_ROM:
  470. ret = pscsi_create_type_rom(dev, sd);
  471. break;
  472. default:
  473. ret = pscsi_create_type_other(dev, sd);
  474. break;
  475. }
  476. if (ret) {
  477. if (phv->phv_mode == PHV_VIRTUAL_HOST_ID)
  478. scsi_host_put(sh);
  479. else if (legacy_mode_enable) {
  480. pscsi_pmode_enable_hba(hba, 0);
  481. hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE;
  482. }
  483. pdv->pdv_sd = NULL;
  484. return ret;
  485. }
  486. return 0;
  487. }
  488. spin_unlock_irq(sh->host_lock);
  489. pr_err("pSCSI: Unable to locate %d:%d:%d:%d\n", sh->host_no,
  490. pdv->pdv_channel_id, pdv->pdv_target_id, pdv->pdv_lun_id);
  491. if (phv->phv_mode == PHV_VIRTUAL_HOST_ID)
  492. scsi_host_put(sh);
  493. else if (legacy_mode_enable) {
  494. pscsi_pmode_enable_hba(hba, 0);
  495. hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE;
  496. }
  497. return -ENODEV;
  498. }
  499. static void pscsi_free_device(struct se_device *dev)
  500. {
  501. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  502. struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr;
  503. struct scsi_device *sd = pdv->pdv_sd;
  504. if (sd) {
  505. /*
  506. * Release exclusive pSCSI internal struct block_device claim for
  507. * struct scsi_device with TYPE_DISK from pscsi_create_type_disk()
  508. */
  509. if ((sd->type == TYPE_DISK) && pdv->pdv_bd) {
  510. blkdev_put(pdv->pdv_bd,
  511. FMODE_WRITE|FMODE_READ|FMODE_EXCL);
  512. pdv->pdv_bd = NULL;
  513. }
  514. /*
  515. * For HBA mode PHV_LLD_SCSI_HOST_NO, release the reference
  516. * to struct Scsi_Host now.
  517. */
  518. if ((phv->phv_mode == PHV_LLD_SCSI_HOST_NO) &&
  519. (phv->phv_lld_host != NULL))
  520. scsi_host_put(phv->phv_lld_host);
  521. if ((sd->type == TYPE_DISK) || (sd->type == TYPE_ROM))
  522. scsi_device_put(sd);
  523. pdv->pdv_sd = NULL;
  524. }
  525. kfree(pdv);
  526. }
  527. static void pscsi_transport_complete(struct se_cmd *cmd, struct scatterlist *sg,
  528. unsigned char *sense_buffer)
  529. {
  530. struct pscsi_dev_virt *pdv = PSCSI_DEV(cmd->se_dev);
  531. struct scsi_device *sd = pdv->pdv_sd;
  532. int result;
  533. struct pscsi_plugin_task *pt = cmd->priv;
  534. unsigned char *cdb;
  535. /*
  536. * Special case for REPORT_LUNs handling where pscsi_plugin_task has
  537. * not been allocated because TCM is handling the emulation directly.
  538. */
  539. if (!pt)
  540. return;
  541. cdb = &pt->pscsi_cdb[0];
  542. result = pt->pscsi_result;
  543. /*
  544. * Hack to make sure that Write-Protect modepage is set if R/O mode is
  545. * forced.
  546. */
  547. if (!cmd->se_deve || !cmd->data_length)
  548. goto after_mode_sense;
  549. if (((cdb[0] == MODE_SENSE) || (cdb[0] == MODE_SENSE_10)) &&
  550. (status_byte(result) << 1) == SAM_STAT_GOOD) {
  551. if (cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) {
  552. unsigned char *buf;
  553. buf = transport_kmap_data_sg(cmd);
  554. if (!buf)
  555. ; /* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */
  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 sense_reason_t
  744. pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
  745. enum dma_data_direction data_direction, 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 0;
  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. return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  828. }
  829. /*
  830. * Clear a lun set in the cdb if the initiator talking to use spoke
  831. * and old standards version, as we can't assume the underlying device
  832. * won't choke up on it.
  833. */
  834. static inline void pscsi_clear_cdb_lun(unsigned char *cdb)
  835. {
  836. switch (cdb[0]) {
  837. case READ_10: /* SBC - RDProtect */
  838. case READ_12: /* SBC - RDProtect */
  839. case READ_16: /* SBC - RDProtect */
  840. case SEND_DIAGNOSTIC: /* SPC - SELF-TEST Code */
  841. case VERIFY: /* SBC - VRProtect */
  842. case VERIFY_16: /* SBC - VRProtect */
  843. case WRITE_VERIFY: /* SBC - VRProtect */
  844. case WRITE_VERIFY_12: /* SBC - VRProtect */
  845. case MAINTENANCE_IN: /* SPC - Parameter Data Format for SA RTPG */
  846. break;
  847. default:
  848. cdb[1] &= 0x1f; /* clear logical unit number */
  849. break;
  850. }
  851. }
  852. static sense_reason_t
  853. 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. return TCM_UNSUPPORTED_SCSI_OPCODE;
  858. pscsi_clear_cdb_lun(cdb);
  859. /*
  860. * For REPORT LUNS we always need to emulate the response, for everything
  861. * else the default for pSCSI is to pass the command to the underlying
  862. * LLD / physical hardware.
  863. */
  864. switch (cdb[0]) {
  865. case REPORT_LUNS:
  866. cmd->execute_cmd = spc_emulate_report_luns;
  867. return 0;
  868. case READ_6:
  869. case READ_10:
  870. case READ_12:
  871. case READ_16:
  872. case WRITE_6:
  873. case WRITE_10:
  874. case WRITE_12:
  875. case WRITE_16:
  876. case WRITE_VERIFY:
  877. cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
  878. /* FALLTHROUGH*/
  879. default:
  880. cmd->execute_cmd = pscsi_execute_cmd;
  881. return 0;
  882. }
  883. }
  884. static sense_reason_t
  885. pscsi_execute_cmd(struct se_cmd *cmd)
  886. {
  887. struct scatterlist *sgl = cmd->t_data_sg;
  888. u32 sgl_nents = cmd->t_data_nents;
  889. enum dma_data_direction data_direction = cmd->data_direction;
  890. struct pscsi_dev_virt *pdv = PSCSI_DEV(cmd->se_dev);
  891. struct pscsi_plugin_task *pt;
  892. struct request *req;
  893. struct bio *hbio;
  894. sense_reason_t ret;
  895. /*
  896. * Dynamically alloc cdb space, since it may be larger than
  897. * TCM_MAX_COMMAND_SIZE
  898. */
  899. pt = kzalloc(sizeof(*pt) + scsi_command_size(cmd->t_task_cdb), GFP_KERNEL);
  900. if (!pt) {
  901. return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  902. }
  903. cmd->priv = pt;
  904. memcpy(pt->pscsi_cdb, cmd->t_task_cdb,
  905. scsi_command_size(cmd->t_task_cdb));
  906. if (!sgl) {
  907. req = blk_get_request(pdv->pdv_sd->request_queue,
  908. (data_direction == DMA_TO_DEVICE),
  909. GFP_KERNEL);
  910. if (!req || IS_ERR(req)) {
  911. pr_err("PSCSI: blk_get_request() failed: %ld\n",
  912. req ? IS_ERR(req) : -ENOMEM);
  913. ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  914. goto fail;
  915. }
  916. } else {
  917. BUG_ON(!cmd->data_length);
  918. ret = pscsi_map_sg(cmd, sgl, sgl_nents, data_direction, &hbio);
  919. if (ret)
  920. goto fail;
  921. req = blk_make_request(pdv->pdv_sd->request_queue, hbio,
  922. GFP_KERNEL);
  923. if (IS_ERR(req)) {
  924. pr_err("pSCSI: blk_make_request() failed\n");
  925. ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  926. goto fail_free_bio;
  927. }
  928. }
  929. req->cmd_type = REQ_TYPE_BLOCK_PC;
  930. req->end_io = pscsi_req_done;
  931. req->end_io_data = cmd;
  932. req->cmd_len = scsi_command_size(pt->pscsi_cdb);
  933. req->cmd = &pt->pscsi_cdb[0];
  934. req->sense = &pt->pscsi_sense[0];
  935. req->sense_len = 0;
  936. if (pdv->pdv_sd->type == TYPE_DISK)
  937. req->timeout = PS_TIMEOUT_DISK;
  938. else
  939. req->timeout = PS_TIMEOUT_OTHER;
  940. req->retries = PS_RETRY;
  941. blk_execute_rq_nowait(pdv->pdv_sd->request_queue, NULL, req,
  942. (cmd->sam_task_attr == MSG_HEAD_TAG),
  943. pscsi_req_done);
  944. return 0;
  945. fail_free_bio:
  946. while (hbio) {
  947. struct bio *bio = hbio;
  948. hbio = hbio->bi_next;
  949. bio->bi_next = NULL;
  950. bio_endio(bio, 0); /* XXX: should be error */
  951. }
  952. ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  953. fail:
  954. kfree(pt);
  955. return ret;
  956. }
  957. /* pscsi_get_device_type():
  958. *
  959. *
  960. */
  961. static u32 pscsi_get_device_type(struct se_device *dev)
  962. {
  963. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  964. struct scsi_device *sd = pdv->pdv_sd;
  965. return sd->type;
  966. }
  967. static sector_t pscsi_get_blocks(struct se_device *dev)
  968. {
  969. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  970. if (pdv->pdv_bd && pdv->pdv_bd->bd_part)
  971. return pdv->pdv_bd->bd_part->nr_sects;
  972. dump_stack();
  973. return 0;
  974. }
  975. static void pscsi_req_done(struct request *req, int uptodate)
  976. {
  977. struct se_cmd *cmd = req->end_io_data;
  978. struct pscsi_plugin_task *pt = cmd->priv;
  979. pt->pscsi_result = req->errors;
  980. pt->pscsi_resid = req->resid_len;
  981. cmd->scsi_status = status_byte(pt->pscsi_result) << 1;
  982. if (cmd->scsi_status) {
  983. pr_debug("PSCSI Status Byte exception at cmd: %p CDB:"
  984. " 0x%02x Result: 0x%08x\n", cmd, pt->pscsi_cdb[0],
  985. pt->pscsi_result);
  986. }
  987. switch (host_byte(pt->pscsi_result)) {
  988. case DID_OK:
  989. target_complete_cmd(cmd, cmd->scsi_status);
  990. break;
  991. default:
  992. pr_debug("PSCSI Host Byte exception at cmd: %p CDB:"
  993. " 0x%02x Result: 0x%08x\n", cmd, pt->pscsi_cdb[0],
  994. pt->pscsi_result);
  995. target_complete_cmd(cmd, SAM_STAT_CHECK_CONDITION);
  996. break;
  997. }
  998. __blk_put_request(req->q, req);
  999. kfree(pt);
  1000. }
  1001. static struct se_subsystem_api pscsi_template = {
  1002. .name = "pscsi",
  1003. .owner = THIS_MODULE,
  1004. .transport_type = TRANSPORT_PLUGIN_PHBA_PDEV,
  1005. .attach_hba = pscsi_attach_hba,
  1006. .detach_hba = pscsi_detach_hba,
  1007. .pmode_enable_hba = pscsi_pmode_enable_hba,
  1008. .alloc_device = pscsi_alloc_device,
  1009. .configure_device = pscsi_configure_device,
  1010. .free_device = pscsi_free_device,
  1011. .transport_complete = pscsi_transport_complete,
  1012. .parse_cdb = pscsi_parse_cdb,
  1013. .set_configfs_dev_params = pscsi_set_configfs_dev_params,
  1014. .show_configfs_dev_params = pscsi_show_configfs_dev_params,
  1015. .get_device_type = pscsi_get_device_type,
  1016. .get_blocks = pscsi_get_blocks,
  1017. };
  1018. static int __init pscsi_module_init(void)
  1019. {
  1020. return transport_subsystem_register(&pscsi_template);
  1021. }
  1022. static void pscsi_module_exit(void)
  1023. {
  1024. transport_subsystem_release(&pscsi_template);
  1025. }
  1026. MODULE_DESCRIPTION("TCM PSCSI subsystem plugin");
  1027. MODULE_AUTHOR("nab@Linux-iSCSI.org");
  1028. MODULE_LICENSE("GPL");
  1029. module_init(pscsi_module_init);
  1030. module_exit(pscsi_module_exit);