ctl.c (264264) | ctl.c (264274) |
---|---|
1/*- 2 * Copyright (c) 2003-2009 Silicon Graphics International Corp. 3 * Copyright (c) 2012 The FreeBSD Foundation 4 * All rights reserved. 5 * 6 * Portions of this software were developed by Edward Tomasz Napierala 7 * under sponsorship from the FreeBSD Foundation. 8 * --- 28 unchanged lines hidden (view full) --- 37 * CAM Target Layer, a SCSI device emulation subsystem. 38 * 39 * Author: Ken Merry <ken@FreeBSD.org> 40 */ 41 42#define _CTL_C 43 44#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003-2009 Silicon Graphics International Corp. 3 * Copyright (c) 2012 The FreeBSD Foundation 4 * All rights reserved. 5 * 6 * Portions of this software were developed by Edward Tomasz Napierala 7 * under sponsorship from the FreeBSD Foundation. 8 * --- 28 unchanged lines hidden (view full) --- 37 * CAM Target Layer, a SCSI device emulation subsystem. 38 * 39 * Author: Ken Merry <ken@FreeBSD.org> 40 */ 41 42#define _CTL_C 43 44#include <sys/cdefs.h> |
45__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl.c 264264 2014-04-08 18:22:03Z mav $"); | 45__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl.c 264274 2014-04-08 20:50:48Z mav $"); |
46 47#include <sys/param.h> 48#include <sys/systm.h> 49#include <sys/kernel.h> 50#include <sys/types.h> 51#include <sys/kthread.h> 52#include <sys/bio.h> 53#include <sys/fcntl.h> --- 272 unchanged lines hidden (view full) --- 326SYSCTL_INT(_kern_cam_ctl, OID_AUTO, worker_threads, CTLFLAG_RDTUN, 327 &worker_threads, 1, "Number of worker threads"); 328static int verbose = 0; 329TUNABLE_INT("kern.cam.ctl.verbose", &verbose); 330SYSCTL_INT(_kern_cam_ctl, OID_AUTO, verbose, CTLFLAG_RWTUN, 331 &verbose, 0, "Show SCSI errors returned to initiator"); 332 333/* | 46 47#include <sys/param.h> 48#include <sys/systm.h> 49#include <sys/kernel.h> 50#include <sys/types.h> 51#include <sys/kthread.h> 52#include <sys/bio.h> 53#include <sys/fcntl.h> --- 272 unchanged lines hidden (view full) --- 326SYSCTL_INT(_kern_cam_ctl, OID_AUTO, worker_threads, CTLFLAG_RDTUN, 327 &worker_threads, 1, "Number of worker threads"); 328static int verbose = 0; 329TUNABLE_INT("kern.cam.ctl.verbose", &verbose); 330SYSCTL_INT(_kern_cam_ctl, OID_AUTO, verbose, CTLFLAG_RWTUN, 331 &verbose, 0, "Show SCSI errors returned to initiator"); 332 333/* |
334 * Serial number (0x80), device id (0x83), and supported pages (0x00) | 334 * Serial number (0x80), device id (0x83), supported pages (0x00), 335 * Block limits (0xB0) and Logical Block Provisioning (0xB2) |
335 */ | 336 */ |
336#define SCSI_EVPD_NUM_SUPPORTED_PAGES 3 | 337#define SCSI_EVPD_NUM_SUPPORTED_PAGES 5 |
337 338static void ctl_isc_event_handler(ctl_ha_channel chanel, ctl_ha_event event, 339 int param); 340static void ctl_copy_sense_data(union ctl_ha_msg *src, union ctl_io *dest); 341static int ctl_init(void); 342void ctl_shutdown(void); 343static int ctl_open(struct cdev *dev, int flags, int fmt, struct thread *td); 344static int ctl_close(struct cdev *dev, int flags, int fmt, struct thread *td); --- 41 unchanged lines hidden (view full) --- 386 struct scsi_per_res_out *cdb, 387 struct scsi_per_res_out_parms* param); 388static void ctl_pro_preempt_other(struct ctl_lun *lun, 389 union ctl_ha_msg *msg); 390static void ctl_hndl_per_res_out_on_other_sc(union ctl_ha_msg *msg); 391static int ctl_inquiry_evpd_supported(struct ctl_scsiio *ctsio, int alloc_len); 392static int ctl_inquiry_evpd_serial(struct ctl_scsiio *ctsio, int alloc_len); 393static int ctl_inquiry_evpd_devid(struct ctl_scsiio *ctsio, int alloc_len); | 338 339static void ctl_isc_event_handler(ctl_ha_channel chanel, ctl_ha_event event, 340 int param); 341static void ctl_copy_sense_data(union ctl_ha_msg *src, union ctl_io *dest); 342static int ctl_init(void); 343void ctl_shutdown(void); 344static int ctl_open(struct cdev *dev, int flags, int fmt, struct thread *td); 345static int ctl_close(struct cdev *dev, int flags, int fmt, struct thread *td); --- 41 unchanged lines hidden (view full) --- 387 struct scsi_per_res_out *cdb, 388 struct scsi_per_res_out_parms* param); 389static void ctl_pro_preempt_other(struct ctl_lun *lun, 390 union ctl_ha_msg *msg); 391static void ctl_hndl_per_res_out_on_other_sc(union ctl_ha_msg *msg); 392static int ctl_inquiry_evpd_supported(struct ctl_scsiio *ctsio, int alloc_len); 393static int ctl_inquiry_evpd_serial(struct ctl_scsiio *ctsio, int alloc_len); 394static int ctl_inquiry_evpd_devid(struct ctl_scsiio *ctsio, int alloc_len); |
395static int ctl_inquiry_evpd_block_limits(struct ctl_scsiio *ctsio, 396 int alloc_len); 397static int ctl_inquiry_evpd_lbp(struct ctl_scsiio *ctsio, int alloc_len); |
|
394static int ctl_inquiry_evpd(struct ctl_scsiio *ctsio); 395static int ctl_inquiry_std(struct ctl_scsiio *ctsio); 396static int ctl_get_lba_len(union ctl_io *io, uint64_t *lba, uint32_t *len); 397static ctl_action ctl_extent_check(union ctl_io *io1, union ctl_io *io2); 398static ctl_action ctl_check_for_blockage(union ctl_io *pending_io, 399 union ctl_io *ooa_io); 400static ctl_action ctl_check_ooa(struct ctl_lun *lun, union ctl_io *pending_io, 401 union ctl_io *starting_io); --- 5380 unchanged lines hidden (view full) --- 5782 return (CTL_RETVAL_COMPLETE); 5783 } 5784 5785 ctl_done((union ctl_io *)ctsio); 5786 5787 return (CTL_RETVAL_COMPLETE); 5788} 5789 | 398static int ctl_inquiry_evpd(struct ctl_scsiio *ctsio); 399static int ctl_inquiry_std(struct ctl_scsiio *ctsio); 400static int ctl_get_lba_len(union ctl_io *io, uint64_t *lba, uint32_t *len); 401static ctl_action ctl_extent_check(union ctl_io *io1, union ctl_io *io2); 402static ctl_action ctl_check_for_blockage(union ctl_io *pending_io, 403 union ctl_io *ooa_io); 404static ctl_action ctl_check_ooa(struct ctl_lun *lun, union ctl_io *pending_io, 405 union ctl_io *starting_io); --- 5380 unchanged lines hidden (view full) --- 5786 return (CTL_RETVAL_COMPLETE); 5787 } 5788 5789 ctl_done((union ctl_io *)ctsio); 5790 5791 return (CTL_RETVAL_COMPLETE); 5792} 5793 |
5794int 5795ctl_write_same(struct ctl_scsiio *ctsio) 5796{ 5797 struct ctl_lun *lun; 5798 struct ctl_lba_len_flags lbalen; 5799 uint64_t lba; 5800 uint32_t num_blocks; 5801 int len, retval; 5802 uint8_t byte2; 5803 5804 retval = CTL_RETVAL_COMPLETE; 5805 5806 CTL_DEBUG_PRINT(("ctl_write_same\n")); 5807 5808 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 5809 5810 switch (ctsio->cdb[0]) { 5811 case WRITE_SAME_10: { 5812 struct scsi_write_same_10 *cdb; 5813 5814 cdb = (struct scsi_write_same_10 *)ctsio->cdb; 5815 5816 lba = scsi_4btoul(cdb->addr); 5817 num_blocks = scsi_2btoul(cdb->length); 5818 byte2 = cdb->byte2; 5819 break; 5820 } 5821 case WRITE_SAME_16: { 5822 struct scsi_write_same_16 *cdb; 5823 5824 cdb = (struct scsi_write_same_16 *)ctsio->cdb; 5825 5826 lba = scsi_8btou64(cdb->addr); 5827 num_blocks = scsi_4btoul(cdb->length); 5828 byte2 = cdb->byte2; 5829 break; 5830 } 5831 default: 5832 /* 5833 * We got a command we don't support. This shouldn't 5834 * happen, commands should be filtered out above us. 5835 */ 5836 ctl_set_invalid_opcode(ctsio); 5837 ctl_done((union ctl_io *)ctsio); 5838 5839 return (CTL_RETVAL_COMPLETE); 5840 break; /* NOTREACHED */ 5841 } 5842 5843 /* 5844 * The first check is to make sure we're in bounds, the second 5845 * check is to catch wrap-around problems. If the lba + num blocks 5846 * is less than the lba, then we've wrapped around and the block 5847 * range is invalid anyway. 5848 */ 5849 if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) 5850 || ((lba + num_blocks) < lba)) { 5851 ctl_set_lba_out_of_range(ctsio); 5852 ctl_done((union ctl_io *)ctsio); 5853 return (CTL_RETVAL_COMPLETE); 5854 } 5855 5856 /* Zero number of blocks means "to the last logical block" */ 5857 if (num_blocks == 0) { 5858 if ((lun->be_lun->maxlba + 1) - lba > UINT32_MAX) { 5859 ctl_set_invalid_field(ctsio, 5860 /*sks_valid*/ 0, 5861 /*command*/ 1, 5862 /*field*/ 0, 5863 /*bit_valid*/ 0, 5864 /*bit*/ 0); 5865 ctl_done((union ctl_io *)ctsio); 5866 return (CTL_RETVAL_COMPLETE); 5867 } 5868 num_blocks = (lun->be_lun->maxlba + 1) - lba; 5869 } 5870 5871 len = lun->be_lun->blocksize; 5872 5873 /* 5874 * If we've got a kernel request that hasn't been malloced yet, 5875 * malloc it and tell the caller the data buffer is here. 5876 */ 5877 if ((ctsio->io_hdr.flags & CTL_FLAG_ALLOCATED) == 0) { 5878 ctsio->kern_data_ptr = malloc(len, M_CTL, M_WAITOK);; 5879 ctsio->kern_data_len = len; 5880 ctsio->kern_total_len = len; 5881 ctsio->kern_data_resid = 0; 5882 ctsio->kern_rel_offset = 0; 5883 ctsio->kern_sg_entries = 0; 5884 ctsio->io_hdr.flags |= CTL_FLAG_ALLOCATED; 5885 ctsio->be_move_done = ctl_config_move_done; 5886 ctl_datamove((union ctl_io *)ctsio); 5887 5888 return (CTL_RETVAL_COMPLETE); 5889 } 5890 5891 lbalen.lba = lba; 5892 lbalen.len = num_blocks; 5893 lbalen.flags = byte2; 5894 memcpy(ctsio->io_hdr.ctl_private[CTL_PRIV_LBA_LEN].bytes, &lbalen, 5895 sizeof(lbalen)); 5896 retval = lun->backend->config_write((union ctl_io *)ctsio); 5897 5898 return (retval); 5899} 5900 5901int 5902ctl_unmap(struct ctl_scsiio *ctsio) 5903{ 5904 struct ctl_lun *lun; 5905 struct scsi_unmap *cdb; 5906 struct ctl_ptr_len_flags ptrlen; 5907 struct scsi_unmap_header *hdr; 5908 struct scsi_unmap_desc *buf, *end; 5909 uint64_t lba; 5910 uint32_t num_blocks; 5911 int len, retval; 5912 uint8_t byte2; 5913 5914 retval = CTL_RETVAL_COMPLETE; 5915 5916 CTL_DEBUG_PRINT(("ctl_unmap\n")); 5917 5918 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 5919 cdb = (struct scsi_unmap *)ctsio->cdb; 5920 5921 len = scsi_2btoul(cdb->length); 5922 byte2 = cdb->byte2; 5923 5924 /* 5925 * If we've got a kernel request that hasn't been malloced yet, 5926 * malloc it and tell the caller the data buffer is here. 5927 */ 5928 if ((ctsio->io_hdr.flags & CTL_FLAG_ALLOCATED) == 0) { 5929 ctsio->kern_data_ptr = malloc(len, M_CTL, M_WAITOK);; 5930 ctsio->kern_data_len = len; 5931 ctsio->kern_total_len = len; 5932 ctsio->kern_data_resid = 0; 5933 ctsio->kern_rel_offset = 0; 5934 ctsio->kern_sg_entries = 0; 5935 ctsio->io_hdr.flags |= CTL_FLAG_ALLOCATED; 5936 ctsio->be_move_done = ctl_config_move_done; 5937 ctl_datamove((union ctl_io *)ctsio); 5938 5939 return (CTL_RETVAL_COMPLETE); 5940 } 5941 5942 len = ctsio->kern_total_len - ctsio->kern_data_resid; 5943 hdr = (struct scsi_unmap_header *)ctsio->kern_data_ptr; 5944 if (len < sizeof (*hdr) || 5945 len < (scsi_2btoul(hdr->length) + sizeof(hdr->length)) || 5946 len < (scsi_2btoul(hdr->desc_length) + sizeof (*hdr)) || 5947 scsi_2btoul(hdr->desc_length) % sizeof(*buf) != 0) { 5948 ctl_set_invalid_field(ctsio, 5949 /*sks_valid*/ 0, 5950 /*command*/ 0, 5951 /*field*/ 0, 5952 /*bit_valid*/ 0, 5953 /*bit*/ 0); 5954 ctl_done((union ctl_io *)ctsio); 5955 return (CTL_RETVAL_COMPLETE); 5956 } 5957 len = scsi_2btoul(hdr->desc_length); 5958 buf = (struct scsi_unmap_desc *)(hdr + 1); 5959 end = buf + len / sizeof(*buf); 5960 5961 ptrlen.ptr = (void *)buf; 5962 ptrlen.len = len; 5963 ptrlen.flags = byte2; 5964 memcpy(ctsio->io_hdr.ctl_private[CTL_PRIV_LBA_LEN].bytes, &ptrlen, 5965 sizeof(ptrlen)); 5966 5967 for (; buf < end; buf++) { 5968 lba = scsi_8btou64(buf->lba); 5969 num_blocks = scsi_4btoul(buf->length); 5970 if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) 5971 || ((lba + num_blocks) < lba)) { 5972 ctl_set_lba_out_of_range(ctsio); 5973 ctl_done((union ctl_io *)ctsio); 5974 return (CTL_RETVAL_COMPLETE); 5975 } 5976 } 5977 5978 retval = lun->backend->config_write((union ctl_io *)ctsio); 5979 5980 return (retval); 5981} 5982 |
|
5790/* 5791 * Note that this function currently doesn't actually do anything inside 5792 * CTL to enforce things if the DQue bit is turned on. 5793 * 5794 * Also note that this function can't be used in the default case, because 5795 * the DQue bit isn't set in the changeable mask for the control mode page 5796 * anyway. This is just here as an example for how to implement a page 5797 * handler, and a placeholder in case we want to allow the user to turn --- 1106 unchanged lines hidden (view full) --- 6904 ctsio->kern_rel_offset = 0; 6905 ctsio->kern_sg_entries = 0; 6906 6907 scsi_u64to8b(lun->be_lun->maxlba, data->addr); 6908 /* XXX KDM this may not be 512 bytes... */ 6909 scsi_ulto4b(lun->be_lun->blocksize, data->length); 6910 data->prot_lbppbe = lun->be_lun->pblockexp & SRC16_LBPPBE; 6911 scsi_ulto2b(lun->be_lun->pblockoff & SRC16_LALBA_A, data->lalba_lbp); | 5983/* 5984 * Note that this function currently doesn't actually do anything inside 5985 * CTL to enforce things if the DQue bit is turned on. 5986 * 5987 * Also note that this function can't be used in the default case, because 5988 * the DQue bit isn't set in the changeable mask for the control mode page 5989 * anyway. This is just here as an example for how to implement a page 5990 * handler, and a placeholder in case we want to allow the user to turn --- 1106 unchanged lines hidden (view full) --- 7097 ctsio->kern_rel_offset = 0; 7098 ctsio->kern_sg_entries = 0; 7099 7100 scsi_u64to8b(lun->be_lun->maxlba, data->addr); 7101 /* XXX KDM this may not be 512 bytes... */ 7102 scsi_ulto4b(lun->be_lun->blocksize, data->length); 7103 data->prot_lbppbe = lun->be_lun->pblockexp & SRC16_LBPPBE; 7104 scsi_ulto2b(lun->be_lun->pblockoff & SRC16_LALBA_A, data->lalba_lbp); |
7105 if (lun->be_lun->flags & CTL_LUN_FLAG_UNMAP) 7106 data->lalba_lbp[0] |= SRC16_LBPME; |
|
6912 6913 ctsio->scsi_status = SCSI_STATUS_OK; 6914 6915 ctsio->be_move_done = ctl_config_move_done; 6916 ctl_datamove((union ctl_io *)ctsio); 6917 6918 return (CTL_RETVAL_COMPLETE); 6919} --- 2070 unchanged lines hidden (view full) --- 8990ctl_inquiry_evpd_supported(struct ctl_scsiio *ctsio, int alloc_len) 8991{ 8992 struct scsi_vpd_supported_pages *pages; 8993 int sup_page_size; 8994 struct ctl_lun *lun; 8995 8996 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 8997 | 7107 7108 ctsio->scsi_status = SCSI_STATUS_OK; 7109 7110 ctsio->be_move_done = ctl_config_move_done; 7111 ctl_datamove((union ctl_io *)ctsio); 7112 7113 return (CTL_RETVAL_COMPLETE); 7114} --- 2070 unchanged lines hidden (view full) --- 9185ctl_inquiry_evpd_supported(struct ctl_scsiio *ctsio, int alloc_len) 9186{ 9187 struct scsi_vpd_supported_pages *pages; 9188 int sup_page_size; 9189 struct ctl_lun *lun; 9190 9191 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 9192 |
8998 sup_page_size = sizeof(struct scsi_vpd_supported_pages) + 8999 SCSI_EVPD_NUM_SUPPORTED_PAGES; | 9193 sup_page_size = sizeof(struct scsi_vpd_supported_pages) * 9194 SCSI_EVPD_NUM_SUPPORTED_PAGES; |
9000 ctsio->kern_data_ptr = malloc(sup_page_size, M_CTL, M_WAITOK | M_ZERO); 9001 pages = (struct scsi_vpd_supported_pages *)ctsio->kern_data_ptr; 9002 ctsio->kern_sg_entries = 0; 9003 9004 if (sup_page_size < alloc_len) { 9005 ctsio->residual = alloc_len - sup_page_size; 9006 ctsio->kern_data_len = sup_page_size; 9007 ctsio->kern_total_len = sup_page_size; --- 19 unchanged lines hidden (view full) --- 9027 9028 pages->length = SCSI_EVPD_NUM_SUPPORTED_PAGES; 9029 /* Supported VPD pages */ 9030 pages->page_list[0] = SVPD_SUPPORTED_PAGES; 9031 /* Serial Number */ 9032 pages->page_list[1] = SVPD_UNIT_SERIAL_NUMBER; 9033 /* Device Identification */ 9034 pages->page_list[2] = SVPD_DEVICE_ID; | 9195 ctsio->kern_data_ptr = malloc(sup_page_size, M_CTL, M_WAITOK | M_ZERO); 9196 pages = (struct scsi_vpd_supported_pages *)ctsio->kern_data_ptr; 9197 ctsio->kern_sg_entries = 0; 9198 9199 if (sup_page_size < alloc_len) { 9200 ctsio->residual = alloc_len - sup_page_size; 9201 ctsio->kern_data_len = sup_page_size; 9202 ctsio->kern_total_len = sup_page_size; --- 19 unchanged lines hidden (view full) --- 9222 9223 pages->length = SCSI_EVPD_NUM_SUPPORTED_PAGES; 9224 /* Supported VPD pages */ 9225 pages->page_list[0] = SVPD_SUPPORTED_PAGES; 9226 /* Serial Number */ 9227 pages->page_list[1] = SVPD_UNIT_SERIAL_NUMBER; 9228 /* Device Identification */ 9229 pages->page_list[2] = SVPD_DEVICE_ID; |
9230 /* Block limits */ 9231 pages->page_list[3] = SVPD_BLOCK_LIMITS; 9232 /* Logical Block Provisioning */ 9233 pages->page_list[4] = SVPD_LBP; |
|
9035 9036 ctsio->scsi_status = SCSI_STATUS_OK; 9037 9038 ctsio->be_move_done = ctl_config_move_done; 9039 ctl_datamove((union ctl_io *)ctsio); 9040 9041 return (CTL_RETVAL_COMPLETE); 9042} --- 248 unchanged lines hidden (view full) --- 9291 9292 ctsio->be_move_done = ctl_config_move_done; 9293 ctl_datamove((union ctl_io *)ctsio); 9294 9295 return (CTL_RETVAL_COMPLETE); 9296} 9297 9298static int | 9234 9235 ctsio->scsi_status = SCSI_STATUS_OK; 9236 9237 ctsio->be_move_done = ctl_config_move_done; 9238 ctl_datamove((union ctl_io *)ctsio); 9239 9240 return (CTL_RETVAL_COMPLETE); 9241} --- 248 unchanged lines hidden (view full) --- 9490 9491 ctsio->be_move_done = ctl_config_move_done; 9492 ctl_datamove((union ctl_io *)ctsio); 9493 9494 return (CTL_RETVAL_COMPLETE); 9495} 9496 9497static int |
9498ctl_inquiry_evpd_block_limits(struct ctl_scsiio *ctsio, int alloc_len) 9499{ 9500 struct scsi_vpd_block_limits *bl_ptr; 9501 struct ctl_lun *lun; 9502 int bs; 9503 9504 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 9505 bs = lun->be_lun->blocksize; 9506 9507 ctsio->kern_data_ptr = malloc(sizeof(*bl_ptr), M_CTL, M_WAITOK | M_ZERO); 9508 bl_ptr = (struct scsi_vpd_block_limits *)ctsio->kern_data_ptr; 9509 ctsio->kern_sg_entries = 0; 9510 9511 if (sizeof(*bl_ptr) < alloc_len) { 9512 ctsio->residual = alloc_len - sizeof(*bl_ptr); 9513 ctsio->kern_data_len = sizeof(*bl_ptr); 9514 ctsio->kern_total_len = sizeof(*bl_ptr); 9515 } else { 9516 ctsio->residual = 0; 9517 ctsio->kern_data_len = alloc_len; 9518 ctsio->kern_total_len = alloc_len; 9519 } 9520 ctsio->kern_data_resid = 0; 9521 ctsio->kern_rel_offset = 0; 9522 ctsio->kern_sg_entries = 0; 9523 9524 /* 9525 * The control device is always connected. The disk device, on the 9526 * other hand, may not be online all the time. Need to change this 9527 * to figure out whether the disk device is actually online or not. 9528 */ 9529 if (lun != NULL) 9530 bl_ptr->device = (SID_QUAL_LU_CONNECTED << 5) | 9531 lun->be_lun->lun_type; 9532 else 9533 bl_ptr->device = (SID_QUAL_LU_OFFLINE << 5) | T_DIRECT; 9534 9535 bl_ptr->page_code = SVPD_BLOCK_LIMITS; 9536 scsi_ulto2b(sizeof(*bl_ptr), bl_ptr->page_length); 9537 scsi_ulto4b((16 * 1024 * 1024) / bs, bl_ptr->max_txfer_len); 9538 scsi_ulto4b(MAXPHYS / bs, bl_ptr->opt_txfer_len); 9539 if (lun->be_lun->flags & CTL_LUN_FLAG_UNMAP) { 9540 scsi_ulto4b(0xffffffff, bl_ptr->max_unmap_lba_cnt); 9541 scsi_ulto4b(0xffffffff, bl_ptr->max_unmap_blk_cnt); 9542 } 9543 scsi_u64to8b(UINT64_MAX, bl_ptr->max_write_same_length); 9544 9545 ctsio->scsi_status = SCSI_STATUS_OK; 9546 ctsio->be_move_done = ctl_config_move_done; 9547 ctl_datamove((union ctl_io *)ctsio); 9548 9549 return (CTL_RETVAL_COMPLETE); 9550} 9551 9552static int 9553ctl_inquiry_evpd_lbp(struct ctl_scsiio *ctsio, int alloc_len) 9554{ 9555 struct scsi_vpd_logical_block_prov *lbp_ptr; 9556 struct ctl_lun *lun; 9557 int bs; 9558 9559 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 9560 bs = lun->be_lun->blocksize; 9561 9562 ctsio->kern_data_ptr = malloc(sizeof(*lbp_ptr), M_CTL, M_WAITOK | M_ZERO); 9563 lbp_ptr = (struct scsi_vpd_logical_block_prov *)ctsio->kern_data_ptr; 9564 ctsio->kern_sg_entries = 0; 9565 9566 if (sizeof(*lbp_ptr) < alloc_len) { 9567 ctsio->residual = alloc_len - sizeof(*lbp_ptr); 9568 ctsio->kern_data_len = sizeof(*lbp_ptr); 9569 ctsio->kern_total_len = sizeof(*lbp_ptr); 9570 } else { 9571 ctsio->residual = 0; 9572 ctsio->kern_data_len = alloc_len; 9573 ctsio->kern_total_len = alloc_len; 9574 } 9575 ctsio->kern_data_resid = 0; 9576 ctsio->kern_rel_offset = 0; 9577 ctsio->kern_sg_entries = 0; 9578 9579 /* 9580 * The control device is always connected. The disk device, on the 9581 * other hand, may not be online all the time. Need to change this 9582 * to figure out whether the disk device is actually online or not. 9583 */ 9584 if (lun != NULL) 9585 lbp_ptr->device = (SID_QUAL_LU_CONNECTED << 5) | 9586 lun->be_lun->lun_type; 9587 else 9588 lbp_ptr->device = (SID_QUAL_LU_OFFLINE << 5) | T_DIRECT; 9589 9590 lbp_ptr->page_code = SVPD_LBP; 9591 if (lun->be_lun->flags & CTL_LUN_FLAG_UNMAP) 9592 lbp_ptr->flags = SVPD_LBP_UNMAP | SVPD_LBP_WS16 | SVPD_LBP_WS10; 9593 9594 ctsio->scsi_status = SCSI_STATUS_OK; 9595 ctsio->be_move_done = ctl_config_move_done; 9596 ctl_datamove((union ctl_io *)ctsio); 9597 9598 return (CTL_RETVAL_COMPLETE); 9599} 9600 9601static int |
|
9299ctl_inquiry_evpd(struct ctl_scsiio *ctsio) 9300{ 9301 struct scsi_inquiry *cdb; | 9602ctl_inquiry_evpd(struct ctl_scsiio *ctsio) 9603{ 9604 struct scsi_inquiry *cdb; |
9605 struct ctl_lun *lun; |
|
9302 int alloc_len, retval; 9303 | 9606 int alloc_len, retval; 9607 |
9608 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; |
|
9304 cdb = (struct scsi_inquiry *)ctsio->cdb; 9305 9306 retval = CTL_RETVAL_COMPLETE; 9307 9308 alloc_len = scsi_2btoul(cdb->length); 9309 9310 switch (cdb->page_code) { 9311 case SVPD_SUPPORTED_PAGES: 9312 retval = ctl_inquiry_evpd_supported(ctsio, alloc_len); 9313 break; 9314 case SVPD_UNIT_SERIAL_NUMBER: 9315 retval = ctl_inquiry_evpd_serial(ctsio, alloc_len); 9316 break; 9317 case SVPD_DEVICE_ID: 9318 retval = ctl_inquiry_evpd_devid(ctsio, alloc_len); 9319 break; | 9609 cdb = (struct scsi_inquiry *)ctsio->cdb; 9610 9611 retval = CTL_RETVAL_COMPLETE; 9612 9613 alloc_len = scsi_2btoul(cdb->length); 9614 9615 switch (cdb->page_code) { 9616 case SVPD_SUPPORTED_PAGES: 9617 retval = ctl_inquiry_evpd_supported(ctsio, alloc_len); 9618 break; 9619 case SVPD_UNIT_SERIAL_NUMBER: 9620 retval = ctl_inquiry_evpd_serial(ctsio, alloc_len); 9621 break; 9622 case SVPD_DEVICE_ID: 9623 retval = ctl_inquiry_evpd_devid(ctsio, alloc_len); 9624 break; |
9625 case SVPD_BLOCK_LIMITS: 9626 retval = ctl_inquiry_evpd_block_limits(ctsio, alloc_len); 9627 break; 9628 case SVPD_LBP: 9629 retval = ctl_inquiry_evpd_lbp(ctsio, alloc_len); 9630 break; |
|
9320 default: 9321 ctl_set_invalid_field(ctsio, 9322 /*sks_valid*/ 1, 9323 /*command*/ 1, 9324 /*field*/ 2, 9325 /*bit_valid*/ 0, 9326 /*bit*/ 0); 9327 ctl_done((union ctl_io *)ctsio); --- 354 unchanged lines hidden (view full) --- 9682 9683 cdb = (struct scsi_write_verify_16 *)io->scsiio.cdb; 9684 9685 9686 *lba = scsi_8btou64(cdb->addr); 9687 *len = scsi_4btoul(cdb->length); 9688 break; 9689 } | 9631 default: 9632 ctl_set_invalid_field(ctsio, 9633 /*sks_valid*/ 1, 9634 /*command*/ 1, 9635 /*field*/ 2, 9636 /*bit_valid*/ 0, 9637 /*bit*/ 0); 9638 ctl_done((union ctl_io *)ctsio); --- 354 unchanged lines hidden (view full) --- 9993 9994 cdb = (struct scsi_write_verify_16 *)io->scsiio.cdb; 9995 9996 9997 *lba = scsi_8btou64(cdb->addr); 9998 *len = scsi_4btoul(cdb->length); 9999 break; 10000 } |
10001 case WRITE_SAME_10: { 10002 struct scsi_write_same_10 *cdb; 10003 10004 cdb = (struct scsi_write_same_10 *)io->scsiio.cdb; 10005 10006 *lba = scsi_4btoul(cdb->addr); 10007 *len = scsi_2btoul(cdb->length); 10008 break; 10009 } 10010 case WRITE_SAME_16: { 10011 struct scsi_write_same_16 *cdb; 10012 10013 cdb = (struct scsi_write_same_16 *)io->scsiio.cdb; 10014 10015 *lba = scsi_8btou64(cdb->addr); 10016 *len = scsi_4btoul(cdb->length); 10017 break; 10018 } |
|
9690 default: 9691 return (1); 9692 break; /* NOTREACHED */ 9693 } 9694 9695 return (0); 9696} 9697 --- 3476 unchanged lines hidden --- | 10019 default: 10020 return (1); 10021 break; /* NOTREACHED */ 10022 } 10023 10024 return (0); 10025} 10026 --- 3476 unchanged lines hidden --- |