/* $NetBSD: ld_aac.c,v 1.32 2025/04/13 02:34:03 rin Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* 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.
*/
/*
* Allocate a command control block and map the data transfer.
*/
ac = aac_ccb_alloc(aac, (dowrite ? AAC_CCB_DATA_OUT : AAC_CCB_DATA_IN));
if (ac == NULL)
return EBUSY;
ac->ac_data = data;
ac->ac_datalen = datasize;
for (i = 0; i < xfer->dm_nsegs; i++, sge++) {
sge->SgAddress = htole32(xfer->dm_segs[i].ds_addr);
sge->SgByteCount = htole32(xfer->dm_segs[i].ds_len);
AAC_DPRINTF(AAC_D_IO,
("#%d va %p pa %" PRIxPADDR " len %zx\n",
i, data, xfer->dm_segs[i].ds_addr,
xfer->dm_segs[i].ds_len));
}
for (i = 0; i < xfer->dm_nsegs; i++, sge++) {
/*
* XXX - This is probably an alignment issue on non-x86
* platforms since this is a packed array of 64/32-bit
* tuples, so every other SgAddress is 32-bit, but not
* 64-bit aligned.
*/
sge->SgAddress = htole64(xfer->dm_segs[i].ds_addr);
sge->SgByteCount = htole32(xfer->dm_segs[i].ds_len);
AAC_DPRINTF(AAC_D_IO,
("#%d va %p pa %" PRIxPADDR " len %zx\n",
i, data, xfer->dm_segs[i].ds_addr,
xfer->dm_segs[i].ds_len));
}
size += xfer->dm_nsegs * sizeof(struct aac_sg_entry64);
size = sizeof(fib->Header) + size;
fib->Header.Size = htole16(size);
}
if (bp == NULL) {
/*
* Polled commands must not sit on the software queue. Wait
* up to 30 seconds for the command to complete.
*/
s = splbio();
rv = aac_ccb_poll(aac, ac, 30000);
aac_ccb_unmap(aac, ac);
aac_ccb_free(aac, ac);
splx(s);
if (rv == 0) {
if (dowrite) {
bwr = (struct aac_blockwrite_response *)
&ac->ac_fib->data[0];
status = le32toh(bwr->Status);
} else {
brr = (struct aac_blockread_response *)
&ac->ac_fib->data[0];
status = le32toh(brr->Status);
}
#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_aac_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;