ctl.c (275889) | ctl.c (275892) |
---|---|
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: stable/10/sys/cam/ctl/ctl.c 275889 2014-12-18 08:32:56Z mav $"); | 45__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl.c 275892 2014-12-18 08:38:07Z mav $"); |
46 47#include <sys/param.h> 48#include <sys/systm.h> 49#include <sys/ctype.h> 50#include <sys/kernel.h> 51#include <sys/types.h> 52#include <sys/kthread.h> 53#include <sys/bio.h> --- 5115 unchanged lines hidden (view full) --- 5169 buf = io->scsiio.kern_data_ptr; 5170 else 5171 buf = NULL; 5172 ctl_done(io); 5173 if (buf) 5174 free(buf, M_CTL); 5175} 5176 | 46 47#include <sys/param.h> 48#include <sys/systm.h> 49#include <sys/ctype.h> 50#include <sys/kernel.h> 51#include <sys/types.h> 52#include <sys/kthread.h> 53#include <sys/bio.h> --- 5115 unchanged lines hidden (view full) --- 5169 buf = io->scsiio.kern_data_ptr; 5170 else 5171 buf = NULL; 5172 ctl_done(io); 5173 if (buf) 5174 free(buf, M_CTL); 5175} 5176 |
5177void 5178ctl_config_read_done(union ctl_io *io) 5179{ 5180 uint8_t *buf; 5181 5182 /* 5183 * If there is some error -- we are done, skip data transfer. 5184 */ 5185 if ((io->io_hdr.flags & CTL_FLAG_ABORT) != 0 || 5186 ((io->io_hdr.status & CTL_STATUS_MASK) != CTL_STATUS_NONE && 5187 (io->io_hdr.status & CTL_STATUS_MASK) != CTL_SUCCESS)) { 5188 if (io->io_hdr.flags & CTL_FLAG_ALLOCATED) 5189 buf = io->scsiio.kern_data_ptr; 5190 else 5191 buf = NULL; 5192 ctl_done(io); 5193 if (buf) 5194 free(buf, M_CTL); 5195 return; 5196 } 5197 5198 /* 5199 * If the IO_CONT flag is set, we need to call the supplied 5200 * function to continue processing the I/O, instead of completing 5201 * the I/O just yet. 5202 */ 5203 if (io->io_hdr.flags & CTL_FLAG_IO_CONT) { 5204 io->scsiio.io_cont(io); 5205 return; 5206 } 5207 5208 ctl_datamove(io); 5209} 5210 |
|
5177/* 5178 * SCSI release command. 5179 */ 5180int 5181ctl_scsi_release(struct ctl_scsiio *ctsio) 5182{ 5183 int length, longid, thirdparty_id, resv_id; 5184 struct ctl_softc *ctl_softc; --- 1985 unchanged lines hidden (view full) --- 7170 ctl_set_success(ctsio); 7171 ctsio->io_hdr.flags |= CTL_FLAG_ALLOCATED; 7172 ctsio->be_move_done = ctl_config_move_done; 7173 ctl_datamove((union ctl_io *)ctsio); 7174 return (CTL_RETVAL_COMPLETE); 7175} 7176 7177int | 5211/* 5212 * SCSI release command. 5213 */ 5214int 5215ctl_scsi_release(struct ctl_scsiio *ctsio) 5216{ 5217 int length, longid, thirdparty_id, resv_id; 5218 struct ctl_softc *ctl_softc; --- 1985 unchanged lines hidden (view full) --- 7204 ctl_set_success(ctsio); 7205 ctsio->io_hdr.flags |= CTL_FLAG_ALLOCATED; 7206 ctsio->be_move_done = ctl_config_move_done; 7207 ctl_datamove((union ctl_io *)ctsio); 7208 return (CTL_RETVAL_COMPLETE); 7209} 7210 7211int |
7212ctl_get_lba_status(struct ctl_scsiio *ctsio) 7213{ 7214 struct scsi_get_lba_status *cdb; 7215 struct scsi_get_lba_status_data *data; 7216 struct ctl_lun *lun; 7217 struct ctl_lba_len_flags *lbalen; 7218 uint64_t lba; 7219 uint32_t alloc_len, total_len; 7220 int retval; 7221 7222 CTL_DEBUG_PRINT(("ctl_get_lba_status\n")); 7223 7224 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 7225 cdb = (struct scsi_get_lba_status *)ctsio->cdb; 7226 lba = scsi_8btou64(cdb->addr); 7227 alloc_len = scsi_4btoul(cdb->alloc_len); 7228 7229 if (lba > lun->be_lun->maxlba) { 7230 ctl_set_lba_out_of_range(ctsio); 7231 ctl_done((union ctl_io *)ctsio); 7232 return (CTL_RETVAL_COMPLETE); 7233 } 7234 7235 total_len = sizeof(*data) + sizeof(data->descr[0]); 7236 ctsio->kern_data_ptr = malloc(total_len, M_CTL, M_WAITOK | M_ZERO); 7237 data = (struct scsi_get_lba_status_data *)ctsio->kern_data_ptr; 7238 7239 if (total_len < alloc_len) { 7240 ctsio->residual = alloc_len - total_len; 7241 ctsio->kern_data_len = total_len; 7242 ctsio->kern_total_len = total_len; 7243 } else { 7244 ctsio->residual = 0; 7245 ctsio->kern_data_len = alloc_len; 7246 ctsio->kern_total_len = alloc_len; 7247 } 7248 ctsio->kern_data_resid = 0; 7249 ctsio->kern_rel_offset = 0; 7250 ctsio->kern_sg_entries = 0; 7251 7252 /* Fill dummy data in case backend can't tell anything. */ 7253 scsi_ulto4b(4 + sizeof(data->descr[0]), data->length); 7254 scsi_u64to8b(lba, data->descr[0].addr); 7255 scsi_ulto4b(MIN(UINT32_MAX, lun->be_lun->maxlba + 1 - lba), 7256 data->descr[0].length); 7257 data->descr[0].status = 0; /* Mapped or unknown. */ 7258 7259 ctl_set_success(ctsio); 7260 ctsio->io_hdr.flags |= CTL_FLAG_ALLOCATED; 7261 ctsio->be_move_done = ctl_config_move_done; 7262 7263 lbalen = (struct ctl_lba_len_flags *)&ctsio->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; 7264 lbalen->lba = lba; 7265 lbalen->len = total_len; 7266 lbalen->flags = 0; 7267 retval = lun->backend->config_read((union ctl_io *)ctsio); 7268 return (CTL_RETVAL_COMPLETE); 7269} 7270 7271int |
|
7178ctl_read_defect(struct ctl_scsiio *ctsio) 7179{ 7180 struct scsi_read_defect_data_10 *ccb10; 7181 struct scsi_read_defect_data_12 *ccb12; 7182 struct scsi_read_defect_data_hdr_10 *data10; 7183 struct scsi_read_defect_data_hdr_12 *data12; 7184 uint32_t alloc_len, data_len; 7185 uint8_t format; --- 3453 unchanged lines hidden (view full) --- 10639 *len = scsi_4btoul(cdb->length); 10640 break; 10641 } 10642 case UNMAP: { 10643 *lba = 0; 10644 *len = UINT64_MAX; 10645 break; 10646 } | 7272ctl_read_defect(struct ctl_scsiio *ctsio) 7273{ 7274 struct scsi_read_defect_data_10 *ccb10; 7275 struct scsi_read_defect_data_12 *ccb12; 7276 struct scsi_read_defect_data_hdr_10 *data10; 7277 struct scsi_read_defect_data_hdr_12 *data12; 7278 uint32_t alloc_len, data_len; 7279 uint8_t format; --- 3453 unchanged lines hidden (view full) --- 10733 *len = scsi_4btoul(cdb->length); 10734 break; 10735 } 10736 case UNMAP: { 10737 *lba = 0; 10738 *len = UINT64_MAX; 10739 break; 10740 } |
10741 case SERVICE_ACTION_IN: { /* GET LBA STATUS */ 10742 struct scsi_get_lba_status *cdb; 10743 10744 cdb = (struct scsi_get_lba_status *)io->scsiio.cdb; 10745 *lba = scsi_8btou64(cdb->addr); 10746 *len = UINT32_MAX; 10747 break; 10748 } |
|
10647 default: 10648 return (1); 10649 break; /* NOTREACHED */ 10650 } 10651 10652 return (0); 10653} 10654 --- 3467 unchanged lines hidden --- | 10749 default: 10750 return (1); 10751 break; /* NOTREACHED */ 10752 } 10753 10754 return (0); 10755} 10756 --- 3467 unchanged lines hidden --- |