/*-
* Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Wasabi Systems, Inc.
*
* 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION 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.
*/
#include "iscsi_globals.h"
/*******************************************************************************
* Open and Close device interfaces. We don't really need them, because we don't
* have to keep track of device opens and closes from userland. But apps can't
* call ioctl without a handle to the device, and the kernel doesn't hand out
* handles without an open routine in the driver. So here they are in all their
* glory...
*******************************************************************************/
int
iscsiopen(dev_t dev, int flag, int mode, struct lwp *l)
{
struct iscsifd *d;
struct iscsi_softc *sc;
struct file *fp;
int error, fd, unit;
unit = minor(dev);
DEB(99, ("ISCSI Open unit=%d\n",unit));
sc = device_lookup_private(&iscsi_cd, unit);
if (sc == NULL)
return ENXIO;
if ((error = fd_allocfile(&fp, &fd)) != 0)
return error;
d = kmem_alloc(sizeof(*d), KM_SLEEP);
d->fd_dev = sc->dev;
d->fd_unit = unit;
/*
* iscsi_attach:
* One-time inits go here. Not much for now, probably even less later.
*/
static void
iscsi_attach(device_t parent, device_t self, void *aux)
{
struct iscsi_softc *sc;
/* loop through the quirktab looking for a match on target name */
static const quirktab_t *
getquirks(const char *iqn)
{
const quirktab_t *qp;
size_t iqnlen, quirklen;
if (iqn == NULL)
iqn = "unknown";
iqnlen = strlen(iqn);
for (qp = quirktab ; qp->iqn ; qp++) {
quirklen = strlen(qp->iqn);
if (quirklen > iqnlen)
continue;
if (memcmp(qp->iqn, iqn, quirklen) == 0)
break;
}
return qp;
}
/*
* map_session
* This (indirectly) maps the existing LUNs for a target to SCSI devices
* by going through config_found to tell any child drivers that there's
* a new adapter.
* Note that each session is equivalent to a SCSI adapter.
*
* Parameter: the session pointer
*
* Returns: 1 on success, 0 on failure
*
* ToDo: Figuring out how to handle more than one LUN. It appears that
* the NetBSD SCSI LUN discovery doesn't use "report LUNs", and instead
* goes through the LUNs sequentially, stopping somewhere on the way if it
* gets an error. We may have to do some LUN mapping in here if this is
* really how things work.
*/
/*
* unmap_session
* This (indirectly) unmaps the existing all LUNs for a target by
* telling the config system that the adapter has detached.
*
* Parameter: the session pointer
*
* Returns: 1 on success, 0 on failure
*/
int
unmap_session(session_t *sess)
{
device_t dev;
int rv = 1;
if ((dev = sess->s_child_dev) != NULL) {
if (config_detach(dev, 0))
rv = 0;
if (rv)
sess->s_child_dev = NULL;
}
return rv;
}
/*
* grow_resources
* Try to grow openings up to current window size
*/
static int
grow_resources(session_t *sess)
{
struct scsipi_adapter *adapt = &sess->s_sc_adapter;
int win;
int rc = -1;
if ((flags & XS_CTL_POLL) != 0) {
xs->error = XS_DRIVER_STUFFUP;
DEBOUT(("Run Xfer request with polling\n"));
scsipi_done(xs);
break;
}
/*
* NOTE: It appears that XS_CTL_DATA_UIO is not actually used anywhere.
* Since it really would complicate matters to handle offsets
* into scatter-gather lists, and a number of other drivers don't
* handle uio-based data as well, XS_CTL_DATA_UIO isn't
* implemented in this driver (at least for now).
*/
if (flags & XS_CTL_DATA_UIO) {
xs->error = XS_DRIVER_STUFFUP;
DEBOUT(("Run Xfer with data in UIO\n"));
scsipi_done(xs);
break;
}
/*
* iscsi_done:
*
* A CCB has completed execution. Pass the status back to the
* upper layer.
*/
void
iscsi_done(ccb_t *ccb)
{
struct scsipi_xfer *xs = ccb->ccb_xs;
DEB(9, ("iscsi_done\n"));