ctl.c (130f4520cba830cc6da47c9f871fed78710a4709) ctl.c (2a2443d8332be10a2d2b4421eb9c180d875bd95c)
1/*-
2 * Copyright (c) 2003-2009 Silicon Graphics International Corp.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

8731int
8732ctl_request_sense(struct ctl_scsiio *ctsio)
8733{
8734 struct scsi_request_sense *cdb;
8735 struct scsi_sense_data *sense_ptr;
8736 struct ctl_lun *lun;
8737 uint32_t initidx;
8738 int have_error;
1/*-
2 * Copyright (c) 2003-2009 Silicon Graphics International Corp.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

8731int
8732ctl_request_sense(struct ctl_scsiio *ctsio)
8733{
8734 struct scsi_request_sense *cdb;
8735 struct scsi_sense_data *sense_ptr;
8736 struct ctl_lun *lun;
8737 uint32_t initidx;
8738 int have_error;
8739 ctl_sense_format sense_format;
8739 scsi_sense_data_type sense_format;
8740
8741 cdb = (struct scsi_request_sense *)ctsio->cdb;
8742
8743 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
8744
8745 CTL_DEBUG_PRINT(("ctl_request_sense\n"));
8746
8747 /*
8748 * Determine which sense format the user wants.
8749 */
8750 if (cdb->byte2 & SRS_DESC)
8740
8741 cdb = (struct scsi_request_sense *)ctsio->cdb;
8742
8743 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
8744
8745 CTL_DEBUG_PRINT(("ctl_request_sense\n"));
8746
8747 /*
8748 * Determine which sense format the user wants.
8749 */
8750 if (cdb->byte2 & SRS_DESC)
8751 sense_format = CTL_SENSE_DESCRIPTOR;
8751 sense_format = SSD_TYPE_DESC;
8752 else
8752 else
8753 sense_format = CTL_SENSE_FIXED;
8753 sense_format = SSD_TYPE_FIXED;
8754
8755 ctsio->kern_data_ptr = malloc(sizeof(*sense_ptr), M_CTL, M_WAITOK);
8756 if (ctsio->kern_data_ptr == NULL) {
8757 ctsio->io_hdr.status = CTL_SCSI_ERROR;
8758 ctsio->scsi_status = SCSI_STATUS_BUSY;
8759 ctl_done((union ctl_io *)ctsio);
8760 return (CTL_RETVAL_COMPLETE);
8761 }

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

8784 have_error = 0;
8785 initidx = ctl_get_initindex(&ctsio->io_hdr.nexus);
8786 /*
8787 * Check for pending sense, and then for pending unit attentions.
8788 * Pending sense gets returned first, then pending unit attentions.
8789 */
8790 mtx_lock(&lun->ctl_softc->ctl_lock);
8791 if (ctl_is_set(lun->have_ca, initidx)) {
8754
8755 ctsio->kern_data_ptr = malloc(sizeof(*sense_ptr), M_CTL, M_WAITOK);
8756 if (ctsio->kern_data_ptr == NULL) {
8757 ctsio->io_hdr.status = CTL_SCSI_ERROR;
8758 ctsio->scsi_status = SCSI_STATUS_BUSY;
8759 ctl_done((union ctl_io *)ctsio);
8760 return (CTL_RETVAL_COMPLETE);
8761 }

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

8784 have_error = 0;
8785 initidx = ctl_get_initindex(&ctsio->io_hdr.nexus);
8786 /*
8787 * Check for pending sense, and then for pending unit attentions.
8788 * Pending sense gets returned first, then pending unit attentions.
8789 */
8790 mtx_lock(&lun->ctl_softc->ctl_lock);
8791 if (ctl_is_set(lun->have_ca, initidx)) {
8792 ctl_sense_format stored_format;
8792 scsi_sense_data_type stored_format;
8793
8794 /*
8795 * Check to see which sense format was used for the stored
8796 * sense data.
8797 */
8793
8794 /*
8795 * Check to see which sense format was used for the stored
8796 * sense data.
8797 */
8798 stored_format = ctl_get_sense_format(
8798 stored_format = scsi_sense_type(
8799 &lun->pending_sense[initidx].sense);
8800
8801 /*
8802 * If the user requested a different sense format than the
8803 * one we stored, then we need to convert it to the other
8804 * format. If we're going from descriptor to fixed format
8805 * sense data, we may lose things in translation, depending
8806 * on what options were used.
8799 &lun->pending_sense[initidx].sense);
8800
8801 /*
8802 * If the user requested a different sense format than the
8803 * one we stored, then we need to convert it to the other
8804 * format. If we're going from descriptor to fixed format
8805 * sense data, we may lose things in translation, depending
8806 * on what options were used.
8807 *
8808 * If the stored format is SSD_TYPE_NONE (i.e. invalid),
8809 * for some reason we'll just copy it out as-is.
8807 */
8810 */
8808 if ((stored_format == CTL_SENSE_FIXED)
8809 && (sense_format == CTL_SENSE_DESCRIPTOR))
8811 if ((stored_format == SSD_TYPE_FIXED)
8812 && (sense_format == SSD_TYPE_DESC))
8810 ctl_sense_to_desc((struct scsi_sense_data_fixed *)
8811 &lun->pending_sense[initidx].sense,
8812 (struct scsi_sense_data_desc *)sense_ptr);
8813 ctl_sense_to_desc((struct scsi_sense_data_fixed *)
8814 &lun->pending_sense[initidx].sense,
8815 (struct scsi_sense_data_desc *)sense_ptr);
8813 else if ((stored_format == CTL_SENSE_DESCRIPTOR)
8814 && (sense_format == CTL_SENSE_FIXED))
8816 else if ((stored_format == SSD_TYPE_DESC)
8817 && (sense_format == SSD_TYPE_FIXED))
8815 ctl_sense_to_fixed((struct scsi_sense_data_desc *)
8816 &lun->pending_sense[initidx].sense,
8817 (struct scsi_sense_data_fixed *)sense_ptr);
8818 else
8819 memcpy(sense_ptr, &lun->pending_sense[initidx].sense,
8820 ctl_min(sizeof(*sense_ptr),
8821 sizeof(lun->pending_sense[initidx].sense)));
8822

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

10454 *
10455 * XXX KDM need to fix this
10456 */
10457 if ((entry->flags & CTL_CMD_FLAG_NO_SENSE) == 0) {
10458 ctl_ua_type ua_type;
10459
10460 ua_type = lun->pending_sense[initidx].ua_pending;
10461 if (ua_type != CTL_UA_NONE) {
8818 ctl_sense_to_fixed((struct scsi_sense_data_desc *)
8819 &lun->pending_sense[initidx].sense,
8820 (struct scsi_sense_data_fixed *)sense_ptr);
8821 else
8822 memcpy(sense_ptr, &lun->pending_sense[initidx].sense,
8823 ctl_min(sizeof(*sense_ptr),
8824 sizeof(lun->pending_sense[initidx].sense)));
8825

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

10457 *
10458 * XXX KDM need to fix this
10459 */
10460 if ((entry->flags & CTL_CMD_FLAG_NO_SENSE) == 0) {
10461 ctl_ua_type ua_type;
10462
10463 ua_type = lun->pending_sense[initidx].ua_pending;
10464 if (ua_type != CTL_UA_NONE) {
10462 ctl_sense_format sense_format;
10465 scsi_sense_data_type sense_format;
10463
10464 if (lun != NULL)
10465 sense_format = (lun->flags &
10466
10467 if (lun != NULL)
10468 sense_format = (lun->flags &
10466 CTL_LUN_SENSE_DESC) ? CTL_SENSE_DESCRIPTOR :
10467 CTL_SENSE_FIXED;
10469 CTL_LUN_SENSE_DESC) ? SSD_TYPE_DESC :
10470 SSD_TYPE_FIXED;
10468 else
10471 else
10469 sense_format = CTL_SENSE_FIXED;
10472 sense_format = SSD_TYPE_FIXED;
10470
10471 ua_type = ctl_build_ua(ua_type, &ctsio->sense_data,
10472 sense_format);
10473 if (ua_type != CTL_UA_NONE) {
10474 ctsio->scsi_status = SCSI_STATUS_CHECK_COND;
10475 ctsio->io_hdr.status = CTL_SCSI_ERROR |
10476 CTL_AUTOSENSE;
10477 ctsio->sense_len = SSD_FULL_SIZE;

--- 2605 unchanged lines hidden ---
10473
10474 ua_type = ctl_build_ua(ua_type, &ctsio->sense_data,
10475 sense_format);
10476 if (ua_type != CTL_UA_NONE) {
10477 ctsio->scsi_status = SCSI_STATUS_CHECK_COND;
10478 ctsio->io_hdr.status = CTL_SCSI_ERROR |
10479 CTL_AUTOSENSE;
10480 ctsio->sense_len = SSD_FULL_SIZE;

--- 2605 unchanged lines hidden ---