target_core_pscsi.c 31 KB

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