target_core_pscsi.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  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 nr_vecs)
  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, nr_vecs);
  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. /*
  765. * We only have one page of data in each sg element,
  766. * we can not cross a page boundary.
  767. */
  768. if (off + len > PAGE_SIZE)
  769. goto fail;
  770. if (len > 0 && data_len > 0) {
  771. bytes = min_t(unsigned int, len, PAGE_SIZE - off);
  772. bytes = min(bytes, data_len);
  773. if (!bio) {
  774. nr_vecs = min_t(int, BIO_MAX_PAGES, nr_pages);
  775. nr_pages -= nr_vecs;
  776. /*
  777. * Calls bio_kmalloc() and sets bio->bi_end_io()
  778. */
  779. bio = pscsi_get_bio(nr_vecs);
  780. if (!bio)
  781. goto fail;
  782. if (rw)
  783. bio->bi_rw |= REQ_WRITE;
  784. pr_debug("PSCSI: Allocated bio: %p,"
  785. " dir: %s nr_vecs: %d\n", bio,
  786. (rw) ? "rw" : "r", nr_vecs);
  787. /*
  788. * Set *hbio pointer to handle the case:
  789. * nr_pages > BIO_MAX_PAGES, where additional
  790. * bios need to be added to complete a given
  791. * command.
  792. */
  793. if (!*hbio)
  794. *hbio = tbio = bio;
  795. else
  796. tbio = tbio->bi_next = bio;
  797. }
  798. pr_debug("PSCSI: Calling bio_add_pc_page() i: %d"
  799. " bio: %p page: %p len: %d off: %d\n", i, bio,
  800. page, len, off);
  801. rc = bio_add_pc_page(pdv->pdv_sd->request_queue,
  802. bio, page, bytes, off);
  803. if (rc != bytes)
  804. goto fail;
  805. pr_debug("PSCSI: bio->bi_vcnt: %d nr_vecs: %d\n",
  806. bio->bi_vcnt, nr_vecs);
  807. if (bio->bi_vcnt > nr_vecs) {
  808. pr_debug("PSCSI: Reached bio->bi_vcnt max:"
  809. " %d i: %d bio: %p, allocating another"
  810. " bio\n", bio->bi_vcnt, i, bio);
  811. /*
  812. * Clear the pointer so that another bio will
  813. * be allocated with pscsi_get_bio() above, the
  814. * current bio has already been set *tbio and
  815. * bio->bi_next.
  816. */
  817. bio = NULL;
  818. }
  819. data_len -= bytes;
  820. }
  821. }
  822. return 0;
  823. fail:
  824. while (*hbio) {
  825. bio = *hbio;
  826. *hbio = (*hbio)->bi_next;
  827. bio_endio(bio, 0); /* XXX: should be error */
  828. }
  829. return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  830. }
  831. /*
  832. * Clear a lun set in the cdb if the initiator talking to use spoke
  833. * and old standards version, as we can't assume the underlying device
  834. * won't choke up on it.
  835. */
  836. static inline void pscsi_clear_cdb_lun(unsigned char *cdb)
  837. {
  838. switch (cdb[0]) {
  839. case READ_10: /* SBC - RDProtect */
  840. case READ_12: /* SBC - RDProtect */
  841. case READ_16: /* SBC - RDProtect */
  842. case SEND_DIAGNOSTIC: /* SPC - SELF-TEST Code */
  843. case VERIFY: /* SBC - VRProtect */
  844. case VERIFY_16: /* SBC - VRProtect */
  845. case WRITE_VERIFY: /* SBC - VRProtect */
  846. case WRITE_VERIFY_12: /* SBC - VRProtect */
  847. case MAINTENANCE_IN: /* SPC - Parameter Data Format for SA RTPG */
  848. break;
  849. default:
  850. cdb[1] &= 0x1f; /* clear logical unit number */
  851. break;
  852. }
  853. }
  854. static sense_reason_t
  855. pscsi_parse_cdb(struct se_cmd *cmd)
  856. {
  857. unsigned char *cdb = cmd->t_task_cdb;
  858. if (cmd->se_cmd_flags & SCF_BIDI)
  859. return TCM_UNSUPPORTED_SCSI_OPCODE;
  860. pscsi_clear_cdb_lun(cdb);
  861. /*
  862. * For REPORT LUNS we always need to emulate the response, for everything
  863. * else the default for pSCSI is to pass the command to the underlying
  864. * LLD / physical hardware.
  865. */
  866. switch (cdb[0]) {
  867. case REPORT_LUNS:
  868. cmd->execute_cmd = spc_emulate_report_luns;
  869. return 0;
  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 sense_reason_t
  887. pscsi_execute_cmd(struct se_cmd *cmd)
  888. {
  889. struct scatterlist *sgl = cmd->t_data_sg;
  890. u32 sgl_nents = cmd->t_data_nents;
  891. enum dma_data_direction data_direction = cmd->data_direction;
  892. struct pscsi_dev_virt *pdv = PSCSI_DEV(cmd->se_dev);
  893. struct pscsi_plugin_task *pt;
  894. struct request *req;
  895. struct bio *hbio;
  896. sense_reason_t ret;
  897. /*
  898. * Dynamically alloc cdb space, since it may be larger than
  899. * TCM_MAX_COMMAND_SIZE
  900. */
  901. pt = kzalloc(sizeof(*pt) + scsi_command_size(cmd->t_task_cdb), GFP_KERNEL);
  902. if (!pt) {
  903. return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  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. ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  916. goto fail;
  917. }
  918. } else {
  919. BUG_ON(!cmd->data_length);
  920. ret = pscsi_map_sg(cmd, sgl, sgl_nents, data_direction, &hbio);
  921. if (ret)
  922. goto fail;
  923. req = blk_make_request(pdv->pdv_sd->request_queue, hbio,
  924. GFP_KERNEL);
  925. if (IS_ERR(req)) {
  926. pr_err("pSCSI: blk_make_request() failed\n");
  927. ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  928. goto fail_free_bio;
  929. }
  930. }
  931. req->cmd_type = REQ_TYPE_BLOCK_PC;
  932. req->end_io = pscsi_req_done;
  933. req->end_io_data = cmd;
  934. req->cmd_len = scsi_command_size(pt->pscsi_cdb);
  935. req->cmd = &pt->pscsi_cdb[0];
  936. req->sense = &pt->pscsi_sense[0];
  937. req->sense_len = 0;
  938. if (pdv->pdv_sd->type == TYPE_DISK)
  939. req->timeout = PS_TIMEOUT_DISK;
  940. else
  941. req->timeout = PS_TIMEOUT_OTHER;
  942. req->retries = PS_RETRY;
  943. blk_execute_rq_nowait(pdv->pdv_sd->request_queue, NULL, req,
  944. (cmd->sam_task_attr == MSG_HEAD_TAG),
  945. pscsi_req_done);
  946. return 0;
  947. fail_free_bio:
  948. while (hbio) {
  949. struct bio *bio = hbio;
  950. hbio = hbio->bi_next;
  951. bio_endio(bio, 0); /* XXX: should be error */
  952. }
  953. ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  954. fail:
  955. kfree(pt);
  956. return ret;
  957. }
  958. /* pscsi_get_device_type():
  959. *
  960. *
  961. */
  962. static u32 pscsi_get_device_type(struct se_device *dev)
  963. {
  964. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  965. struct scsi_device *sd = pdv->pdv_sd;
  966. return sd->type;
  967. }
  968. static sector_t pscsi_get_blocks(struct se_device *dev)
  969. {
  970. struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
  971. if (pdv->pdv_bd && pdv->pdv_bd->bd_part)
  972. return pdv->pdv_bd->bd_part->nr_sects;
  973. dump_stack();
  974. return 0;
  975. }
  976. static void pscsi_req_done(struct request *req, int uptodate)
  977. {
  978. struct se_cmd *cmd = req->end_io_data;
  979. struct pscsi_plugin_task *pt = cmd->priv;
  980. pt->pscsi_result = req->errors;
  981. pt->pscsi_resid = req->resid_len;
  982. cmd->scsi_status = status_byte(pt->pscsi_result) << 1;
  983. if (cmd->scsi_status) {
  984. pr_debug("PSCSI Status Byte exception at cmd: %p CDB:"
  985. " 0x%02x Result: 0x%08x\n", cmd, pt->pscsi_cdb[0],
  986. pt->pscsi_result);
  987. }
  988. switch (host_byte(pt->pscsi_result)) {
  989. case DID_OK:
  990. target_complete_cmd(cmd, cmd->scsi_status);
  991. break;
  992. default:
  993. pr_debug("PSCSI Host Byte exception at cmd: %p CDB:"
  994. " 0x%02x Result: 0x%08x\n", cmd, pt->pscsi_cdb[0],
  995. pt->pscsi_result);
  996. target_complete_cmd(cmd, SAM_STAT_CHECK_CONDITION);
  997. break;
  998. }
  999. __blk_put_request(req->q, req);
  1000. kfree(pt);
  1001. }
  1002. static struct se_subsystem_api pscsi_template = {
  1003. .name = "pscsi",
  1004. .owner = THIS_MODULE,
  1005. .transport_type = TRANSPORT_PLUGIN_PHBA_PDEV,
  1006. .attach_hba = pscsi_attach_hba,
  1007. .detach_hba = pscsi_detach_hba,
  1008. .pmode_enable_hba = pscsi_pmode_enable_hba,
  1009. .alloc_device = pscsi_alloc_device,
  1010. .configure_device = pscsi_configure_device,
  1011. .free_device = pscsi_free_device,
  1012. .transport_complete = pscsi_transport_complete,
  1013. .parse_cdb = pscsi_parse_cdb,
  1014. .set_configfs_dev_params = pscsi_set_configfs_dev_params,
  1015. .show_configfs_dev_params = pscsi_show_configfs_dev_params,
  1016. .get_device_type = pscsi_get_device_type,
  1017. .get_blocks = pscsi_get_blocks,
  1018. };
  1019. static int __init pscsi_module_init(void)
  1020. {
  1021. return transport_subsystem_register(&pscsi_template);
  1022. }
  1023. static void __exit pscsi_module_exit(void)
  1024. {
  1025. transport_subsystem_release(&pscsi_template);
  1026. }
  1027. MODULE_DESCRIPTION("TCM PSCSI subsystem plugin");
  1028. MODULE_AUTHOR("nab@Linux-iSCSI.org");
  1029. MODULE_LICENSE("GPL");
  1030. module_init(pscsi_module_init);
  1031. module_exit(pscsi_module_exit);