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