Deleted Added
full compact
ctl.c (273320) ctl.c (273323)
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 273320 2014-10-20 08:03:23Z mav $");
45__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl.c 273323 2014-10-20 08:07:29Z 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>

--- 7332 unchanged lines hidden (view full) ---

7386 ctsio->io_hdr.flags |= CTL_FLAG_ALLOCATED;
7387 ctsio->be_move_done = ctl_config_move_done;
7388 ctl_datamove((union ctl_io *)ctsio);
7389
7390 return (CTL_RETVAL_COMPLETE);
7391}
7392
7393int
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>

--- 7332 unchanged lines hidden (view full) ---

7386 ctsio->io_hdr.flags |= CTL_FLAG_ALLOCATED;
7387 ctsio->be_move_done = ctl_config_move_done;
7388 ctl_datamove((union ctl_io *)ctsio);
7389
7390 return (CTL_RETVAL_COMPLETE);
7391}
7392
7393int
7394ctl_read_defect(struct ctl_scsiio *ctsio)
7395{
7396 struct scsi_read_defect_data_10 *ccb10;
7397 struct scsi_read_defect_data_12 *ccb12;
7398 struct scsi_read_defect_data_hdr_10 *data10;
7399 struct scsi_read_defect_data_hdr_12 *data12;
7400 struct ctl_lun *lun;
7401 uint32_t alloc_len, data_len;
7402 uint8_t format;
7403
7404 CTL_DEBUG_PRINT(("ctl_read_defect\n"));
7405
7406 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
7407 if (lun->flags & CTL_LUN_PR_RESERVED) {
7408 uint32_t residx;
7409
7410 /*
7411 * XXX KDM need a lock here.
7412 */
7413 residx = ctl_get_resindex(&ctsio->io_hdr.nexus);
7414 if ((lun->res_type == SPR_TYPE_EX_AC
7415 && residx != lun->pr_res_idx)
7416 || ((lun->res_type == SPR_TYPE_EX_AC_RO
7417 || lun->res_type == SPR_TYPE_EX_AC_AR)
7418 && lun->pr_keys[residx] == 0)) {
7419 ctl_set_reservation_conflict(ctsio);
7420 ctl_done((union ctl_io *)ctsio);
7421 return (CTL_RETVAL_COMPLETE);
7422 }
7423 }
7424
7425 if (ctsio->cdb[0] == READ_DEFECT_DATA_10) {
7426 ccb10 = (struct scsi_read_defect_data_10 *)&ctsio->cdb;
7427 format = ccb10->format;
7428 alloc_len = scsi_2btoul(ccb10->alloc_length);
7429 data_len = sizeof(*data10);
7430 } else {
7431 ccb12 = (struct scsi_read_defect_data_12 *)&ctsio->cdb;
7432 format = ccb12->format;
7433 alloc_len = scsi_4btoul(ccb12->alloc_length);
7434 data_len = sizeof(*data12);
7435 }
7436 if (alloc_len == 0) {
7437 ctl_set_success(ctsio);
7438 ctl_done((union ctl_io *)ctsio);
7439 return (CTL_RETVAL_COMPLETE);
7440 }
7441
7442 ctsio->kern_data_ptr = malloc(data_len, M_CTL, M_WAITOK | M_ZERO);
7443 if (data_len < alloc_len) {
7444 ctsio->residual = alloc_len - data_len;
7445 ctsio->kern_data_len = data_len;
7446 ctsio->kern_total_len = data_len;
7447 } else {
7448 ctsio->residual = 0;
7449 ctsio->kern_data_len = alloc_len;
7450 ctsio->kern_total_len = alloc_len;
7451 }
7452 ctsio->kern_data_resid = 0;
7453 ctsio->kern_rel_offset = 0;
7454 ctsio->kern_sg_entries = 0;
7455
7456 if (ctsio->cdb[0] == READ_DEFECT_DATA_10) {
7457 data10 = (struct scsi_read_defect_data_hdr_10 *)
7458 ctsio->kern_data_ptr;
7459 data10->format = format;
7460 scsi_ulto2b(0, data10->length);
7461 } else {
7462 data12 = (struct scsi_read_defect_data_hdr_12 *)
7463 ctsio->kern_data_ptr;
7464 data12->format = format;
7465 scsi_ulto2b(0, data12->generation);
7466 scsi_ulto4b(0, data12->length);
7467 }
7468
7469 ctsio->scsi_status = SCSI_STATUS_OK;
7470 ctsio->io_hdr.flags |= CTL_FLAG_ALLOCATED;
7471 ctsio->be_move_done = ctl_config_move_done;
7472 ctl_datamove((union ctl_io *)ctsio);
7473 return (CTL_RETVAL_COMPLETE);
7474}
7475
7476int
7394ctl_report_tagret_port_groups(struct ctl_scsiio *ctsio)
7395{
7396 struct scsi_maintenance_in *cdb;
7397 int retval;
7398 int alloc_len, ext, total_len = 0, g, p, pc, pg;
7399 int num_target_port_groups, num_target_ports, single;
7400 struct ctl_lun *lun;
7401 struct ctl_softc *softc;

--- 6980 unchanged lines hidden ---
7477ctl_report_tagret_port_groups(struct ctl_scsiio *ctsio)
7478{
7479 struct scsi_maintenance_in *cdb;
7480 int retval;
7481 int alloc_len, ext, total_len = 0, g, p, pc, pg;
7482 int num_target_port_groups, num_target_ports, single;
7483 struct ctl_lun *lun;
7484 struct ctl_softc *softc;

--- 6980 unchanged lines hidden ---