/*
* Copyright (c) 2010 Antti Kantee. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* A SCSI target which is useful for debugging our scsipi driver stack.
* Currently it pretends to be a single CD.
*
* Freely add the necessary features for your tests. Just remember to
* run the atf test suite to make sure you didn't cause regressions to
* other tests.
*/
/*
* This is pretty much a CD target for now
*/
static void
scsitest_request(struct scsipi_channel *chan,
scsipi_adapter_req_t req, void *arg)
{
struct scsipi_xfer *xs = arg;
struct scsipi_generic *cmd = xs->cmd;
#ifdef USE_TOSI_ISO
int error;
#endif
if (req != ADAPTER_REQ_RUN_XFER)
return;
//show_scsipi_xs(xs);
switch (cmd->opcode) {
case SCSI_TEST_UNIT_READY:
if (isofd == -1)
sense_notready(xs);
break;
case INQUIRY: {
struct scsipi_inquiry_data *inqbuf = (void *)xs->data;
break;
}
case SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL:
/* hardcoded for now */
break;
default:
printf("unhandled opcode 0x%x\n", cmd->opcode);
break;
}
scsipi_done(xs);
}
int
scsitest_match(device_t parent, cfdata_t match, void *aux)
{
#ifdef USE_TOSI_ISO
uint64_t fsize;
int error, ft;
if (rumpuser_getfileinfo(MYCDISO, &fsize, &ft, &error))
return 0;
if (ft != RUMPUSER_FT_REG)
return 0;
mycdsize = fsize / CDBLOCKSIZE;
if ((isofd = rumpuser_open(MYCDISO, RUMPUSER_OPEN_RDWR, &error)) == -1)
return 0;
#else
/*
* We pretend to have a medium present initially, so != -1.
*/
isofd = -2;
#endif