/* $NetBSD: ld_twe.c,v 1.41 2025/04/13 02:34:03 rin Exp $ */
/*-
* Copyright (c) 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran; and by Jason R. Thorpe of 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.
*/
/* Map the data transfer. */
if ((rv = twe_ccb_map(twe, ccb)) != 0) {
twe_ccb_free(twe, ccb);
return (rv);
}
if (bp == NULL) {
/*
* Polled commands must not sit on the software queue. Wait
* up to 2 seconds for the command to complete.
*/
s = splbio();
rv = twe_ccb_poll(twe, ccb, 2000);
twe_ccb_unmap(twe, ccb);
twe_ccb_free(twe, ccb);
splx(s);
} else {
ccb->ccb_tx.tx_handler = ld_twe_handler;
ccb->ccb_tx.tx_context = bp;
ccb->ccb_tx.tx_dv = sc->sc_ld.sc_dv;
twe_ccb_enqueue(twe, ccb);
rv = 0;
}
return (rv);
}
static int
ld_twe_start(struct ld_softc *ld, struct buf *bp)
{
if (poll) {
/*
* Polled commands must not sit on the software queue. Wait
* up to 2 seconds for the command to complete.
*/
s = splbio();
rv = twe_ccb_poll(twe, ccb, 2000);
twe_ccb_unmap(twe, ccb);
twe_ccb_free(twe, ccb);
splx(s);
} else {
ccb->ccb_tx.tx_handler = twe_ccb_wait_handler;
ccb->ccb_tx.tx_context = NULL;
ccb->ccb_tx.tx_dv = ld->sc_dv;
twe_ccb_enqueue(twe, ccb);
rv = 0;
s = splbio();
while ((ccb->ccb_flags & TWE_CCB_COMPLETE) == 0)
if ((rv = tsleep(ccb, PRIBIO, "tweflush",
60 * hz)) != 0)
break;
twe_ccb_free(twe, ccb);
splx(s);
}
return (rv);
}
static int
ld_twe_ioctl(struct ld_softc *ld, u_long cmd, void *addr, int32_t flag, bool poll)
{
int error;
switch (cmd) {
case DIOCCACHESYNC:
error = ld_twe_flush(ld, poll);
break;
#ifdef _MODULE
/*
* XXX Don't allow ioconf.c to redefine the "struct cfdriver ld_cd"
* XXX it will be defined in the common-code module
*/
#undef CFDRIVER_DECL
#define CFDRIVER_DECL(name, class, attr)
#include "ioconf.c"
#endif
static int
ld_twe_modcmd(modcmd_t cmd, void *opaque)
{
#ifdef _MODULE
/*
* We ignore the cfdriver_vec[] that ioconf provides, since
* the cfdrivers are attached already.
*/
static struct cfdriver * const no_cfdriver_vec[] = { NULL };
#endif
int error = 0;