2003-05-11 06:36:49 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2003-08-24 17:55:58 +00:00
|
|
|
* Written by: David Jeffery
|
2003-05-11 06:36:49 +00:00
|
|
|
* Copyright (c) 2002 Adaptec Inc.
|
|
|
|
* 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 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 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.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
2003-05-11 06:36:49 +00:00
|
|
|
|
2005-11-29 09:39:41 +00:00
|
|
|
#include <dev/ips/ipsreg.h>
|
2003-05-11 06:36:49 +00:00
|
|
|
#include <dev/ips/ips.h>
|
|
|
|
#include <dev/ips/ips_ioctl.h>
|
2003-08-24 17:55:58 +00:00
|
|
|
|
2003-05-11 06:36:49 +00:00
|
|
|
static void ips_ioctl_finish(ips_command_t *command)
|
|
|
|
{
|
|
|
|
ips_ioctl_t *ioctl_cmd = command->arg;
|
|
|
|
if(ioctl_cmd->readwrite & IPS_IOCTL_READ){
|
|
|
|
bus_dmamap_sync(ioctl_cmd->dmatag, ioctl_cmd->dmamap,
|
|
|
|
BUS_DMASYNC_POSTREAD);
|
|
|
|
} else if(ioctl_cmd->readwrite & IPS_IOCTL_WRITE){
|
|
|
|
bus_dmamap_sync(ioctl_cmd->dmatag, ioctl_cmd->dmamap,
|
|
|
|
BUS_DMASYNC_POSTWRITE);
|
|
|
|
}
|
|
|
|
bus_dmamap_sync(command->sc->command_dmatag, command->command_dmamap,
|
|
|
|
BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(ioctl_cmd->dmatag, ioctl_cmd->dmamap);
|
|
|
|
ioctl_cmd->status.value = command->status.value;
|
|
|
|
ips_insert_free_cmd(command->sc, command);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ips_ioctl_callback(void *cmdptr, bus_dma_segment_t *segments,int segnum, int error)
|
|
|
|
{
|
|
|
|
ips_command_t *command = cmdptr;
|
|
|
|
ips_ioctl_t *ioctl_cmd = command->arg;
|
|
|
|
ips_generic_cmd *command_buffer = command->command_buffer;
|
|
|
|
if(error){
|
2005-09-25 17:12:41 +00:00
|
|
|
ips_set_error(command, error);
|
2003-05-11 06:36:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
command_buffer->id = command->id;
|
|
|
|
command_buffer->buffaddr = segments[0].ds_addr;
|
|
|
|
if(ioctl_cmd->readwrite & IPS_IOCTL_WRITE){
|
|
|
|
bus_dmamap_sync(ioctl_cmd->dmatag, ioctl_cmd->dmamap,
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
} else if(ioctl_cmd->readwrite & IPS_IOCTL_READ){
|
|
|
|
bus_dmamap_sync(ioctl_cmd->dmatag, ioctl_cmd->dmamap,
|
|
|
|
BUS_DMASYNC_PREREAD);
|
|
|
|
}
|
|
|
|
bus_dmamap_sync(command->sc->command_dmatag, command->command_dmamap,
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
command->sc->ips_issue_cmd(command);
|
|
|
|
}
|
|
|
|
static int ips_ioctl_start(ips_command_t *command)
|
|
|
|
{
|
|
|
|
ips_ioctl_t *ioctl_cmd = command->arg;
|
|
|
|
memcpy(command->command_buffer, ioctl_cmd->command_buffer,
|
|
|
|
sizeof(ips_generic_cmd));
|
|
|
|
command->callback = ips_ioctl_finish;
|
|
|
|
bus_dmamap_load(ioctl_cmd->dmatag, ioctl_cmd->dmamap,
|
|
|
|
ioctl_cmd->data_buffer,ioctl_cmd->datasize,
|
|
|
|
ips_ioctl_callback, command, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ips_ioctl_cmd(ips_softc_t *sc, ips_ioctl_t *ioctl_cmd, ips_user_request *user_request)
|
|
|
|
{
|
2005-01-28 05:02:13 +00:00
|
|
|
ips_command_t *command;
|
2003-05-11 06:36:49 +00:00
|
|
|
int error = EINVAL;
|
2003-05-31 20:40:12 +00:00
|
|
|
|
|
|
|
if (bus_dma_tag_create( /* parent */ sc->adapter_dmatag,
|
|
|
|
/* alignment */ 1,
|
|
|
|
/* boundary */ 0,
|
|
|
|
/* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
|
|
|
|
/* highaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* filter */ NULL,
|
|
|
|
/* filterarg */ NULL,
|
|
|
|
/* maxsize */ ioctl_cmd->datasize,
|
|
|
|
/* numsegs */ 1,
|
|
|
|
/* maxsegsize*/ ioctl_cmd->datasize,
|
|
|
|
/* flags */ 0,
|
2005-01-28 05:02:13 +00:00
|
|
|
/* lockfunc */ NULL,
|
|
|
|
/* lockarg */ NULL,
|
2003-05-31 20:40:12 +00:00
|
|
|
&ioctl_cmd->dmatag) != 0) {
|
2003-05-11 06:36:49 +00:00
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
if(bus_dmamem_alloc(ioctl_cmd->dmatag, &ioctl_cmd->data_buffer,
|
|
|
|
0, &ioctl_cmd->dmamap)){
|
|
|
|
error = ENOMEM;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if(copyin(user_request->data_buffer,ioctl_cmd->data_buffer,
|
|
|
|
ioctl_cmd->datasize))
|
|
|
|
goto exit;
|
|
|
|
ioctl_cmd->status.value = 0xffffffff;
|
2005-01-28 05:02:13 +00:00
|
|
|
mtx_lock(&sc->queue_mtx);
|
|
|
|
if((error = ips_get_free_cmd(sc, &command, 0)) > 0){
|
2003-05-11 06:36:49 +00:00
|
|
|
error = ENOMEM;
|
2005-01-28 05:02:13 +00:00
|
|
|
mtx_unlock(&sc->queue_mtx);
|
2003-05-11 06:36:49 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
2005-01-28 05:02:13 +00:00
|
|
|
command->arg = ioctl_cmd;
|
|
|
|
ips_ioctl_start(command);
|
2003-05-11 06:36:49 +00:00
|
|
|
while( ioctl_cmd->status.value == 0xffffffff)
|
2005-01-28 05:02:13 +00:00
|
|
|
msleep(ioctl_cmd, &sc->queue_mtx, 0, "ips", hz/10);
|
2005-09-25 17:12:41 +00:00
|
|
|
if(COMMAND_ERROR(ioctl_cmd))
|
2003-05-11 06:36:49 +00:00
|
|
|
error = EIO;
|
|
|
|
else
|
|
|
|
error = 0;
|
2005-01-28 05:02:13 +00:00
|
|
|
mtx_unlock(&sc->queue_mtx);
|
2003-05-11 06:36:49 +00:00
|
|
|
if(copyout(ioctl_cmd->data_buffer, user_request->data_buffer,
|
|
|
|
ioctl_cmd->datasize))
|
|
|
|
error = EINVAL;
|
2005-09-25 17:12:41 +00:00
|
|
|
mtx_lock(&sc->queue_mtx);
|
|
|
|
ips_insert_free_cmd(sc, command);
|
|
|
|
mtx_unlock(&sc->queue_mtx);
|
|
|
|
|
2003-05-11 06:36:49 +00:00
|
|
|
exit: bus_dmamem_free(ioctl_cmd->dmatag, ioctl_cmd->data_buffer,
|
|
|
|
ioctl_cmd->dmamap);
|
|
|
|
bus_dma_tag_destroy(ioctl_cmd->dmatag);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ips_ioctl_request(ips_softc_t *sc, u_long ioctl_request, caddr_t addr, int32_t flags){
|
|
|
|
int error = EINVAL;
|
|
|
|
ips_ioctl_t *ioctl_cmd;
|
|
|
|
ips_user_request *user_request;
|
|
|
|
switch(ioctl_request){
|
|
|
|
case IPS_USER_CMD:
|
|
|
|
user_request = (ips_user_request *)addr;
|
2004-05-30 04:01:29 +00:00
|
|
|
ioctl_cmd = malloc(sizeof(ips_ioctl_t), M_IPSBUF, M_WAITOK);
|
2003-05-11 06:36:49 +00:00
|
|
|
ioctl_cmd->command_buffer = malloc(sizeof(ips_generic_cmd),
|
2004-05-30 04:01:29 +00:00
|
|
|
M_IPSBUF, M_WAITOK);
|
2003-05-11 06:36:49 +00:00
|
|
|
if(copyin(user_request->command_buffer,
|
|
|
|
ioctl_cmd->command_buffer, sizeof(ips_generic_cmd))){
|
2004-05-30 04:01:29 +00:00
|
|
|
free(ioctl_cmd->command_buffer, M_IPSBUF);
|
|
|
|
free(ioctl_cmd, M_IPSBUF);
|
2003-05-11 06:36:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
ioctl_cmd->readwrite = IPS_IOCTL_READ | IPS_IOCTL_WRITE;
|
|
|
|
ioctl_cmd->datasize = IPS_IOCTL_BUFFER_SIZE;
|
|
|
|
error = ips_ioctl_cmd(sc, ioctl_cmd, user_request);
|
2004-05-30 04:01:29 +00:00
|
|
|
free(ioctl_cmd->command_buffer, M_IPSBUF);
|
|
|
|
free(ioctl_cmd, M_IPSBUF);
|
2003-05-11 06:36:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|