target_core_pscsi.c 30 KB

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