Lines Matching +full:sense +full:-
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
117 /* We start out life with a UA to indicate power-on/reset. */ in tcmd_init()
121 istate->pending_ua = UA_POWER_ON; in tcmd_init()
140 atio->ccb_h.flags); in tcmd_handle()
143 a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; in tcmd_handle()
145 /* Do a full lookup if one-behind cache failed */ in tcmd_handle()
146 if (last_cmd == NULL || last_cmd->cmd != a_descr->cdb[0]) { in tcmd_handle()
149 for (h = cdb_handlers; h->cmd != ILLEGAL_CDB; h++) { in tcmd_handle()
150 if (a_descr->cdb[0] == h->cmd) in tcmd_handle()
158 if (last_cmd->done != NULL) in tcmd_handle()
159 last_cmd->done(atio, ctio, event); in tcmd_handle()
165 if (last_cmd->cmd == ILLEGAL_CDB) { in tcmd_handle()
167 warnx("no done func for %#x???", a_descr->cdb[0]); in tcmd_handle()
171 warnx("cdb %#x not handled", a_descr->cdb[0]); in tcmd_handle()
177 istate = tcmd_get_istate(ctio->init_id); in tcmd_handle()
184 if (istate->pending_ca == 0 && istate->pending_ua != 0 && in tcmd_handle()
185 a_descr->cdb[0] != INQUIRY) { in tcmd_handle()
186 tcmd_sense(ctio->init_id, ctio, SSD_KEY_UNIT_ATTENTION, in tcmd_handle()
187 0x29, istate->pending_ua == UA_POWER_ON ? 1 : 2); in tcmd_handle()
188 istate->pending_ca = CA_UNIT_ATTN; in tcmd_handle()
190 cdb_debug(a_descr->cdb, "UA active for %u: ", in tcmd_handle()
191 atio->init_id); in tcmd_handle()
198 istate->orig_ua = istate->pending_ua; in tcmd_handle()
199 istate->orig_ca = istate->pending_ca; in tcmd_handle()
208 istate->pending_ca = CA_NONE; in tcmd_handle()
209 if (istate->orig_ca == CA_UNIT_ATTN) in tcmd_handle()
210 istate->pending_ua = UA_NONE; in tcmd_handle()
213 if (last_cmd->cmd != ILLEGAL_CDB) { in tcmd_handle()
214 ret = last_cmd->start(atio, ctio); in tcmd_handle()
216 if (last_cmd->start != tcmd_rdwr) { in tcmd_handle()
217 a_descr->init_req += ctio->dxfer_len; in tcmd_handle()
229 warnx("illegal init_id %d, max %d", init_id, MAX_INITIATORS - 1); in tcmd_get_istate()
241 struct scsi_sense_data_fixed *sense; in tcmd_sense() local
247 istate->pending_ca |= CA_CMD_SENSE; /* XXX set instead of or? */ in tcmd_sense()
248 sense = (struct scsi_sense_data_fixed *)&istate->sense_data; in tcmd_sense()
249 bzero(sense, sizeof(*sense)); in tcmd_sense()
250 sense->error_code = SSD_CURRENT_ERROR; in tcmd_sense()
251 sense->flags = flags; in tcmd_sense()
252 sense->add_sense_code = asc; in tcmd_sense()
253 sense->add_sense_code_qual = ascq; in tcmd_sense()
254 sense->extra_len = in tcmd_sense()
255 offsetof(struct scsi_sense_data_fixed, sense_key_spec[2]) - in tcmd_sense()
260 bcopy(sense, &ctio->sense_data, sizeof(*sense)); in tcmd_sense()
261 ctio->sense_len = sizeof(*sense); /* XXX */ in tcmd_sense()
262 ctio->ccb_h.flags &= ~CAM_DIR_MASK; in tcmd_sense()
263 ctio->ccb_h.flags |= CAM_DIR_NONE | CAM_SEND_SENSE | in tcmd_sense()
265 ctio->dxfer_len = 0; in tcmd_sense()
266 ctio->scsi_status = SCSI_STATUS_CHECK_COND; in tcmd_sense()
278 end = MAX_INITIATORS - 1; in tcmd_ua()
287 istate->pending_ua = new_ua; in tcmd_ua()
297 struct scsi_sense_data_fixed *sense; in tcmd_inquiry() local
299 a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; in tcmd_inquiry()
300 inq = (struct scsi_inquiry *)a_descr->cdb; in tcmd_inquiry()
303 cdb_debug(a_descr->cdb, "INQUIRY from %u: ", atio->init_id); in tcmd_inquiry()
308 istate = tcmd_get_istate(ctio->init_id); in tcmd_inquiry()
309 sense = (struct scsi_sense_data_fixed *)&istate->sense_data; in tcmd_inquiry()
310 if ((inq->byte2 & SI_EVPD) != 0) { in tcmd_inquiry()
312 sense->sense_key_spec[0] = SSD_SCS_VALID | SSD_FIELDPTR_CMD | in tcmd_inquiry()
314 sense->sense_key_spec[1] = 0; in tcmd_inquiry()
315 sense->sense_key_spec[2] = in tcmd_inquiry()
317 } else if (inq->page_code != 0) { in tcmd_inquiry()
319 sense->sense_key_spec[0] = SSD_SCS_VALID | SSD_FIELDPTR_CMD; in tcmd_inquiry()
320 sense->sense_key_spec[1] = 0; in tcmd_inquiry()
321 sense->sense_key_spec[2] = in tcmd_inquiry()
324 bcopy(&inq_data, ctio->data_ptr, sizeof(inq_data)); in tcmd_inquiry()
325 ctio->dxfer_len = inq_data.additional_length + 4; in tcmd_inquiry()
326 ctio->dxfer_len = min(ctio->dxfer_len, in tcmd_inquiry()
327 scsi_2btoul(inq->length)); in tcmd_inquiry()
328 ctio->ccb_h.flags |= CAM_DIR_IN | CAM_SEND_STATUS; in tcmd_inquiry()
329 ctio->scsi_status = SCSI_STATUS_OK; in tcmd_inquiry()
342 inq->device = T_DIRECT | (SID_QUAL_LU_CONNECTED << 5); in init_inquiry()
344 inq->version = SCSI_REV_SPC; /* was 2 */ in init_inquiry()
346 inq->version = SCSI_REV_3; /* was 2 */ in init_inquiry()
360 scsi_ulto2b(req_flags, &inq->spc2_flags); in init_inquiry()
362 inq->response_format = 2; /* SCSI2 Inquiry Format */ in init_inquiry()
363 inq->additional_length = SHORT_INQUIRY_LENGTH - in init_inquiry()
365 bcopy("FreeBSD ", inq->vendor, SID_VENDOR_SIZE); in init_inquiry()
366 bcopy("Emulated Disk ", inq->product, SID_PRODUCT_SIZE); in init_inquiry()
367 bcopy("0.1 ", inq->revision, SID_REVISION_SIZE); in init_inquiry()
375 struct scsi_sense_data_fixed *sense; in tcmd_req_sense() local
380 a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; in tcmd_req_sense()
381 rsense = (struct scsi_request_sense *)a_descr->cdb; in tcmd_req_sense()
383 istate = tcmd_get_istate(ctio->init_id); in tcmd_req_sense()
384 sense = (struct scsi_sense_data_fixed *)&istate->sense_data; in tcmd_req_sense()
387 cdb_debug(a_descr->cdb, "REQ SENSE from %u: ", atio->init_id); in tcmd_req_sense()
388 warnx("Sending sense: %#x %#x %#x", sense->flags, in tcmd_req_sense()
389 sense->add_sense_code, sense->add_sense_code_qual); in tcmd_req_sense()
392 if (istate->orig_ca == 0) { in tcmd_req_sense()
393 tcmd_sense(ctio->init_id, NULL, SSD_KEY_NO_SENSE, 0, 0); in tcmd_req_sense()
394 warnx("REQUEST SENSE from %u but no pending CA!", in tcmd_req_sense()
395 ctio->init_id); in tcmd_req_sense()
398 bcopy(sense, ctio->data_ptr, sizeof(struct scsi_sense_data)); in tcmd_req_sense()
400 sense->extra_len + 1; in tcmd_req_sense()
401 ctio->dxfer_len = min(dlen, SCSI_CDB6_LEN(rsense->length)); in tcmd_req_sense()
402 ctio->ccb_h.flags |= CAM_DIR_IN | CAM_SEND_STATUS; in tcmd_req_sense()
403 ctio->scsi_status = SCSI_STATUS_OK; in tcmd_req_sense()
414 a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; in tcmd_rd_cap()
415 srp = (struct scsi_read_capacity_data *)ctio->data_ptr; in tcmd_rd_cap()
420 vsize = (uint32_t)(volume_size - 1); in tcmd_rd_cap()
423 cdb_debug(a_descr->cdb, "READ CAP from %u (%u, %u): ", in tcmd_rd_cap()
424 atio->init_id, vsize, sector_size); in tcmd_rd_cap()
428 scsi_ulto4b(vsize, srp->addr); in tcmd_rd_cap()
429 scsi_ulto4b(sector_size, srp->length); in tcmd_rd_cap()
431 ctio->dxfer_len = sizeof(*srp); in tcmd_rd_cap()
432 ctio->ccb_h.flags |= CAM_DIR_IN | CAM_SEND_STATUS; in tcmd_rd_cap()
433 ctio->scsi_status = SCSI_STATUS_OK; in tcmd_rd_cap()
445 a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; in tcmd_rd_cap16()
446 scsi_cmd = (struct scsi_read_capacity_16 *)a_descr->cdb; in tcmd_rd_cap16()
447 srp = (struct scsi_read_capacity_data_long *)ctio->data_ptr; in tcmd_rd_cap16()
449 if (scsi_cmd->service_action != SRC16_SERVICE_ACTION) { in tcmd_rd_cap16()
455 cdb_debug(a_descr->cdb, "READ CAP16 from %u (%u, %u): ", in tcmd_rd_cap16()
456 atio->init_id, volume_size - 1, sector_size); in tcmd_rd_cap16()
460 scsi_u64to8b(volume_size - 1, srp->addr); in tcmd_rd_cap16()
461 scsi_ulto4b(sector_size, srp->length); in tcmd_rd_cap16()
463 ctio->dxfer_len = sizeof(*srp); in tcmd_rd_cap16()
464 ctio->ccb_h.flags |= CAM_DIR_IN | CAM_SEND_STATUS; in tcmd_rd_cap16()
465 ctio->scsi_status = SCSI_STATUS_OK; in tcmd_rd_cap16()
477 a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; in tcmd_rdwr()
478 c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; in tcmd_rdwr()
481 if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_BOTH) { in tcmd_rdwr()
490 ctio->ccb_h.flags |= a_descr->flags; in tcmd_rdwr()
493 if ((a_descr->flags & CAM_DIR_IN) != 0) { in tcmd_rdwr()
497 a_descr, c_descr->offset, a_descr->targ_req); in tcmd_rdwr()
502 a_descr, c_descr->offset, a_descr->init_req); in tcmd_rdwr()
516 a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; in tcmd_rdwr_decode()
517 cdb = a_descr->cdb; in tcmd_rdwr_decode()
519 cdb_debug(cdb, "R/W from %u: ", atio->init_id); in tcmd_rdwr_decode()
526 blkno = scsi_3btoul(rw_6->addr); in tcmd_rdwr_decode()
527 count = rw_6->length; in tcmd_rdwr_decode()
534 blkno = scsi_4btoul(rw_10->addr); in tcmd_rdwr_decode()
535 count = scsi_2btoul(rw_10->length); in tcmd_rdwr_decode()
543 blkno = scsi_8btou64(rw_16->addr); in tcmd_rdwr_decode()
544 count = scsi_4btoul(rw_16->length); in tcmd_rdwr_decode()
554 tcmd_sense(ctio->init_id, ctio, in tcmd_rdwr_decode()
560 a_descr->base_off = ((off_t)blkno) * sector_size; in tcmd_rdwr_decode()
561 a_descr->total_len = count * sector_size; in tcmd_rdwr_decode()
562 if (a_descr->total_len == 0) { in tcmd_rdwr_decode()
568 a_descr->flags |= CAM_DIR_OUT; in tcmd_rdwr_decode()
572 a_descr->flags |= CAM_DIR_IN; in tcmd_rdwr_decode()
587 a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; in start_io()
588 c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; in start_io()
591 c_descr->offset = a_descr->base_off + a_descr->targ_req; in start_io()
592 ctio->dxfer_len = a_descr->total_len - a_descr->targ_req; in start_io()
594 c_descr->offset = a_descr->base_off + a_descr->init_req; in start_io()
595 ctio->dxfer_len = a_descr->total_len - a_descr->init_req; in start_io()
597 ctio->dxfer_len = min(ctio->dxfer_len, buf_size); in start_io()
598 assert(ctio->dxfer_len >= 0); in start_io()
600 c_descr->aiocb.aio_offset = c_descr->offset; in start_io()
601 c_descr->aiocb.aio_nbytes = ctio->dxfer_len; in start_io()
610 (ctio->dxfer_len / sector_size), in start_io()
611 c_descr->offset / sector_size); in start_io()
612 if (lseek(c_descr->aiocb.aio_fildes, in start_io()
613 c_descr->aiocb.aio_offset, SEEK_SET) < 0) { in start_io()
617 if (read(c_descr->aiocb.aio_fildes, in start_io()
618 (void *)c_descr->aiocb.aio_buf, in start_io()
619 ctio->dxfer_len) != ctio->dxfer_len) { in start_io()
626 (ctio->dxfer_len / sector_size), in start_io()
627 c_descr->offset / sector_size); in start_io()
628 if (aio_read(&c_descr->aiocb) < 0) { in start_io()
632 a_descr->targ_req += ctio->dxfer_len; in start_io()
634 if (a_descr->targ_req == a_descr->total_len) { in start_io()
635 ctio->ccb_h.flags |= CAM_SEND_STATUS; in start_io()
636 ctio->scsi_status = SCSI_STATUS_OK; in start_io()
642 if (a_descr->targ_ack == a_descr->total_len) in start_io()
644 a_descr->init_req += ctio->dxfer_len; in start_io()
645 if (a_descr->init_req == a_descr->total_len && in start_io()
646 ctio->dxfer_len > 0) { in start_io()
667 a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; in tcmd_rdwr_done()
668 c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; in tcmd_rdwr_done()
672 if (!notaio && aio_return(&c_descr->aiocb) < 0) { in tcmd_rdwr_done()
675 tcmd_sense(ctio->init_id, ctio, in tcmd_rdwr_done()
680 a_descr->targ_ack += ctio->dxfer_len; in tcmd_rdwr_done()
681 if ((a_descr->flags & CAM_DIR_IN) != 0) { in tcmd_rdwr_done()
688 a_descr->init_req += ctio->dxfer_len; in tcmd_rdwr_done()
692 if (a_descr->init_req == a_descr->total_len) in tcmd_rdwr_done()
700 switch (ctio->ccb_h.status & CAM_STATUS_MASK) { in tcmd_rdwr_done()
705 if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_OUT) { in tcmd_rdwr_done()
706 if (aio_write(&c_descr->aiocb) < 0) { in tcmd_rdwr_done()
710 if (aio_read(&c_descr->aiocb) < 0) { in tcmd_rdwr_done()
716 errx(1, "CTIO failed, status %#x", ctio->ccb_h.status); in tcmd_rdwr_done()
718 a_descr->init_ack += ctio->dxfer_len; in tcmd_rdwr_done()
719 if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_OUT && in tcmd_rdwr_done()
720 ctio->dxfer_len > 0) { in tcmd_rdwr_done()
721 a_descr->targ_req += ctio->dxfer_len; in tcmd_rdwr_done()
726 (ctio->dxfer_len / sector_size), in tcmd_rdwr_done()
727 c_descr->offset / sector_size); in tcmd_rdwr_done()
728 if (lseek(c_descr->aiocb.aio_fildes, in tcmd_rdwr_done()
729 c_descr->aiocb.aio_offset, SEEK_SET) < 0) { in tcmd_rdwr_done()
733 if (write(c_descr->aiocb.aio_fildes, in tcmd_rdwr_done()
734 (void *) c_descr->aiocb.aio_buf, in tcmd_rdwr_done()
735 ctio->dxfer_len) != ctio->dxfer_len) { in tcmd_rdwr_done()
743 (ctio->dxfer_len / sector_size), in tcmd_rdwr_done()
744 c_descr->offset / sector_size); in tcmd_rdwr_done()
745 if (aio_write(&c_descr->aiocb) < 0) { in tcmd_rdwr_done()
769 a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; in tcmd_null_ok()
770 cdb_debug(a_descr->cdb, "Sending null ok to %u : ", atio->init_id); in tcmd_null_ok()
773 ctio->dxfer_len = 0; in tcmd_null_ok()
774 ctio->ccb_h.flags &= ~CAM_DIR_MASK; in tcmd_null_ok()
775 ctio->ccb_h.flags |= CAM_DIR_NONE | CAM_SEND_STATUS; in tcmd_null_ok()
776 ctio->scsi_status = SCSI_STATUS_OK; in tcmd_null_ok()
780 /* Simple illegal request message used by MODE SENSE, etc. */
787 a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; in tcmd_illegal_req()
788 cdb_debug(a_descr->cdb, "Sending ill req to %u: ", atio->init_id); in tcmd_illegal_req()
791 tcmd_sense(atio->init_id, ctio, SSD_KEY_ILLEGAL_REQUEST, in tcmd_illegal_req()
807 scsi_cdb_string(cdb, msg_buf + len, sizeof(msg_buf) - len); in cdb_debug()