diff --git a/sys/amd64/conf/GENERIC b/sys/amd64/conf/GENERIC index f3497ef91f63..8f2e5e9fccb4 100644 --- a/sys/amd64/conf/GENERIC +++ b/sys/amd64/conf/GENERIC @@ -195,7 +195,6 @@ device mlx # Mylex DAC960 family device mrsas # LSI/Avago MegaRAID SAS/SATA, 6Gb/s and 12Gb/s #XXX pointer/int warnings #device pst # Promise Supertrak SX6000 -device twe # 3ware ATA RAID # NVM Express (NVMe) support device nvme # base NVMe driver diff --git a/sys/conf/NOTES b/sys/conf/NOTES index a6c3c42fc00e..8725d11a5434 100644 --- a/sys/conf/NOTES +++ b/sys/conf/NOTES @@ -1646,11 +1646,6 @@ device mfip # LSI MegaRAID SAS passthrough, requires CAM options MFI_DEBUG device mrsas # LSI/Avago MegaRAID SAS/SATA, 6Gb/s and 12Gb/s -# -# 3ware ATA RAID -# -device twe # 3ware ATA RAID - # # Serial ATA host controllers: # diff --git a/sys/conf/files b/sys/conf/files index 8c3d80c48b01..c0728504da5a 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -3171,8 +3171,6 @@ dev/syscons/warp/warp_saver.c optional warp_saver dev/tcp_log/tcp_log_dev.c optional tcp_blackbox inet | tcp_blackbox inet6 dev/tdfx/tdfx_pci.c optional tdfx pci dev/ti/if_ti.c optional ti pci -dev/twe/twe.c optional twe -dev/twe/twe_freebsd.c optional twe dev/tws/tws.c optional tws dev/tws/tws_cam.c optional tws dev/tws/tws_hdm.c optional tws diff --git a/sys/dev/twe/twe.c b/sys/dev/twe/twe.c deleted file mode 100644 index 6d05ac7c2b95..000000000000 --- a/sys/dev/twe/twe.c +++ /dev/null @@ -1,1973 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2000 Michael Smith - * Copyright (c) 2003 Paul Saab - * Copyright (c) 2003 Vinod Kashyap - * Copyright (c) 2000 BSDi - * 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. - * - * $FreeBSD$ - */ - -/* - * Driver for the 3ware Escalade family of IDE RAID controllers. - */ - -#include -#include -#include -#include -#define TWE_DEFINE_TABLES -#include - -/* - * Command submission. - */ -static int twe_get_param_1(struct twe_softc *sc, int table_id, int param_id, u_int8_t *result); -static int twe_get_param_2(struct twe_softc *sc, int table_id, int param_id, u_int16_t *result); -static int twe_get_param_4(struct twe_softc *sc, int table_id, int param_id, u_int32_t *result); -static void *twe_get_param(struct twe_softc *sc, int table_id, int parameter_id, size_t size, - void (* func)(struct twe_request *tr)); -#ifdef TWE_SHUTDOWN_NOTIFICATION -static int twe_set_param_1(struct twe_softc *sc, int table_id, int param_id, u_int8_t value); -#endif -#if 0 -static int twe_set_param_2(struct twe_softc *sc, int table_id, int param_id, u_int16_t value); -static int twe_set_param_4(struct twe_softc *sc, int table_id, int param_id, u_int32_t value); -#endif -static int twe_set_param(struct twe_softc *sc, int table_id, int param_id, int param_size, - void *data); -static int twe_init_connection(struct twe_softc *sc, int mode); -static int twe_wait_request(struct twe_request *tr); -static int twe_immediate_request(struct twe_request *tr, int usetmp); -static void twe_completeio(struct twe_request *tr); -static void twe_reset(struct twe_softc *sc); -static int twe_add_unit(struct twe_softc *sc, int unit); -static int twe_del_unit(struct twe_softc *sc, int unit); - -/* - * Command I/O to controller. - */ -static void twe_done(struct twe_softc *sc, int startio); -static void twe_complete(struct twe_softc *sc); -static int twe_wait_status(struct twe_softc *sc, u_int32_t status, int timeout); -static int twe_drain_response_queue(struct twe_softc *sc); -static int twe_check_bits(struct twe_softc *sc, u_int32_t status_reg); -static int twe_soft_reset(struct twe_softc *sc); - -/* - * Interrupt handling. - */ -static void twe_host_intr(struct twe_softc *sc); -static void twe_attention_intr(struct twe_softc *sc); -static void twe_command_intr(struct twe_softc *sc); - -/* - * Asynchronous event handling. - */ -static int twe_fetch_aen(struct twe_softc *sc); -static void twe_handle_aen(struct twe_request *tr); -static void twe_enqueue_aen(struct twe_softc *sc, u_int16_t aen); -static u_int16_t twe_dequeue_aen(struct twe_softc *sc); -static int twe_drain_aen_queue(struct twe_softc *sc); -static int twe_find_aen(struct twe_softc *sc, u_int16_t aen); - -/* - * Command buffer management. - */ -static int twe_get_request(struct twe_softc *sc, struct twe_request **tr); -static void twe_release_request(struct twe_request *tr); - -/* - * Debugging. - */ -static char *twe_format_aen(struct twe_softc *sc, u_int16_t aen); -static int twe_report_request(struct twe_request *tr); -static void twe_panic(struct twe_softc *sc, char *reason); - -/******************************************************************************** - ******************************************************************************** - Public Interfaces - ******************************************************************************** - ********************************************************************************/ - -/******************************************************************************** - * Initialise the controller, set up driver data structures. - */ -int -twe_setup(struct twe_softc *sc) -{ - struct twe_request *tr; - TWE_Command *cmd; - u_int32_t status_reg; - int i; - - debug_called(4); - - gone_in(14, "Please migrate to newer hardware"); - - /* - * Initialise request queues. - */ - twe_initq_free(sc); - twe_initq_bio(sc); - twe_initq_ready(sc); - twe_initq_busy(sc); - twe_initq_complete(sc); - sc->twe_wait_aen = -1; - - /* - * Allocate request structures up front. - */ - for (i = 0; i < TWE_Q_LENGTH; i++) { - if ((tr = twe_allocate_request(sc, i)) == NULL) - return(ENOMEM); - /* - * Set global defaults that won't change. - */ - cmd = TWE_FIND_COMMAND(tr); - cmd->generic.host_id = sc->twe_host_id; /* controller-assigned host ID */ - cmd->generic.request_id = i; /* our index number */ - sc->twe_lookup[i] = tr; - - /* - * Put command onto the freelist. - */ - TWE_IO_LOCK(sc); - twe_release_request(tr); - TWE_IO_UNLOCK(sc); - } - TWE_IO_LOCK(sc); - - /* - * Check status register for errors, clear them. - */ - status_reg = TWE_STATUS(sc); - twe_check_bits(sc, status_reg); - - /* - * Wait for the controller to come ready. - */ - if (twe_wait_status(sc, TWE_STATUS_MICROCONTROLLER_READY, 60)) { - TWE_IO_UNLOCK(sc); - twe_printf(sc, "microcontroller not ready\n"); - return(ENXIO); - } - - /* - * Disable interrupts from the card. - */ - twe_disable_interrupts(sc); - - /* - * Soft reset the controller, look for the AEN acknowledging the reset, - * check for errors, drain the response queue. - */ - for (i = 0; i < TWE_MAX_RESET_TRIES; i++) { - if (i > 0) - twe_printf(sc, "reset %d failed, trying again\n", i); - - if (!twe_soft_reset(sc)) - break; /* reset process complete */ - } - TWE_IO_UNLOCK(sc); - /* did we give up? */ - if (i >= TWE_MAX_RESET_TRIES) { - twe_printf(sc, "can't initialise controller, giving up\n"); - return(ENXIO); - } - - return(0); -} - -static int -twe_add_unit(struct twe_softc *sc, int unit) -{ - struct twe_drive *dr; - int table, error = 0; - u_int16_t dsize; - TWE_Param *drives = NULL, *param = NULL; - TWE_Array_Descriptor *ud; - - TWE_CONFIG_ASSERT_LOCKED(sc); - if (unit < 0 || unit > TWE_MAX_UNITS) - return (EINVAL); - - /* - * The controller is in a safe state, so try to find drives attached to it. - */ - TWE_IO_LOCK(sc); - if ((drives = twe_get_param(sc, TWE_PARAM_UNITSUMMARY, TWE_PARAM_UNITSUMMARY_Status, - TWE_MAX_UNITS, NULL)) == NULL) { - TWE_IO_UNLOCK(sc); - twe_printf(sc, "can't detect attached units\n"); - return (EIO); - } - - dr = &sc->twe_drive[unit]; - /* check that the drive is online */ - if (!(drives->data[unit] & TWE_PARAM_UNITSTATUS_Online)) { - TWE_IO_UNLOCK(sc); - error = ENXIO; - goto out; - } - - table = TWE_PARAM_UNITINFO + unit; - - if (twe_get_param_4(sc, table, TWE_PARAM_UNITINFO_Capacity, &dr->td_size)) { - TWE_IO_UNLOCK(sc); - twe_printf(sc, "error fetching capacity for unit %d\n", unit); - error = EIO; - goto out; - } - if (twe_get_param_1(sc, table, TWE_PARAM_UNITINFO_Status, &dr->td_state)) { - TWE_IO_UNLOCK(sc); - twe_printf(sc, "error fetching state for unit %d\n", unit); - error = EIO; - goto out; - } - if (twe_get_param_2(sc, table, TWE_PARAM_UNITINFO_DescriptorSize, &dsize)) { - TWE_IO_UNLOCK(sc); - twe_printf(sc, "error fetching descriptor size for unit %d\n", unit); - error = EIO; - goto out; - } - if ((param = twe_get_param(sc, table, TWE_PARAM_UNITINFO_Descriptor, dsize - 3, NULL)) == NULL) { - TWE_IO_UNLOCK(sc); - twe_printf(sc, "error fetching descriptor for unit %d\n", unit); - error = EIO; - goto out; - } - ud = (TWE_Array_Descriptor *)param->data; - dr->td_type = ud->configuration; - dr->td_stripe = ud->stripe_size; - - /* build synthetic geometry as per controller internal rules */ - if (dr->td_size > 0x200000) { - dr->td_heads = 255; - dr->td_sectors = 63; - } else { - dr->td_heads = 64; - dr->td_sectors = 32; - } - dr->td_cylinders = dr->td_size / (dr->td_heads * dr->td_sectors); - dr->td_twe_unit = unit; - TWE_IO_UNLOCK(sc); - - error = twe_attach_drive(sc, dr); - -out: - if (param != NULL) - free(param, M_DEVBUF); - if (drives != NULL) - free(drives, M_DEVBUF); - return (error); -} - -static int -twe_del_unit(struct twe_softc *sc, int unit) -{ - int error; - - TWE_CONFIG_ASSERT_LOCKED(sc); - if (unit < 0 || unit >= TWE_MAX_UNITS) - return (ENXIO); - - if (sc->twe_drive[unit].td_disk == NULL) - return (ENXIO); - - error = twe_detach_drive(sc, unit); - return (error); -} - -/******************************************************************************** - * Locate disk devices and attach children to them. - */ -void -twe_init(struct twe_softc *sc) -{ - int i; - - /* - * Scan for drives - */ - TWE_CONFIG_LOCK(sc); - for (i = 0; i < TWE_MAX_UNITS; i++) - twe_add_unit(sc, i); - TWE_CONFIG_UNLOCK(sc); - - /* - * Initialise connection with controller. - */ - TWE_IO_LOCK(sc); - twe_init_connection(sc, TWE_INIT_MESSAGE_CREDITS); - -#ifdef TWE_SHUTDOWN_NOTIFICATION - /* - * Tell the controller we support shutdown notification. - */ - twe_set_param_1(sc, TWE_PARAM_FEATURES, TWE_PARAM_FEATURES_DriverShutdown, 1); -#endif - - /* - * Mark controller up and ready to run. - */ - sc->twe_state &= ~TWE_STATE_SHUTDOWN; - - /* - * Finally enable interrupts. - */ - twe_enable_interrupts(sc); - TWE_IO_UNLOCK(sc); -} - -/******************************************************************************** - * Stop the controller - */ -void -twe_deinit(struct twe_softc *sc) -{ - /* - * Mark the controller as shutting down, and disable any further interrupts. - */ - TWE_IO_ASSERT_LOCKED(sc); - sc->twe_state |= TWE_STATE_SHUTDOWN; - twe_disable_interrupts(sc); - -#ifdef TWE_SHUTDOWN_NOTIFICATION - /* - * Disconnect from the controller - */ - twe_init_connection(sc, TWE_SHUTDOWN_MESSAGE_CREDITS); -#endif -} - -/******************************************************************************* - * Take an interrupt, or be poked by other code to look for interrupt-worthy - * status. - */ -void -twe_intr(struct twe_softc *sc) -{ - u_int32_t status_reg; - - debug_called(4); - - /* - * Collect current interrupt status. - */ - status_reg = TWE_STATUS(sc); - twe_check_bits(sc, status_reg); - - /* - * Dispatch based on interrupt status - */ - if (status_reg & TWE_STATUS_HOST_INTERRUPT) - twe_host_intr(sc); - if (status_reg & TWE_STATUS_ATTENTION_INTERRUPT) - twe_attention_intr(sc); - if (status_reg & TWE_STATUS_COMMAND_INTERRUPT) - twe_command_intr(sc); - if (status_reg & TWE_STATUS_RESPONSE_INTERRUPT) - twe_done(sc, 1); -}; - -/******************************************************************************** - * Pull as much work off the softc's work queue as possible and give it to the - * controller. - */ -void -twe_startio(struct twe_softc *sc) -{ - struct twe_request *tr; - TWE_Command *cmd; - struct bio *bp; - int error; - - debug_called(4); - - TWE_IO_ASSERT_LOCKED(sc); - if (sc->twe_state & (TWE_STATE_CTLR_BUSY | TWE_STATE_FRZN)) - return; - - /* spin until something prevents us from doing any work */ - for (;;) { - /* try to get a command that's already ready to go */ - tr = twe_dequeue_ready(sc); - - /* build a command from an outstanding bio */ - if (tr == NULL) { - - /* get a command to handle the bio with */ - if (twe_get_request(sc, &tr)) - break; - - /* see if there's work to be done */ - if ((bp = twe_dequeue_bio(sc)) == NULL) { - twe_release_request(tr); - break; - } - - /* connect the bio to the command */ - tr->tr_complete = twe_completeio; - tr->tr_private = bp; - tr->tr_data = bp->bio_data; - tr->tr_length = bp->bio_bcount; - cmd = TWE_FIND_COMMAND(tr); - if (bp->bio_cmd == BIO_READ) { - tr->tr_flags |= TWE_CMD_DATAIN; - cmd->io.opcode = TWE_OP_READ; - } else if (bp->bio_cmd == BIO_WRITE) { - tr->tr_flags |= TWE_CMD_DATAOUT; - cmd->io.opcode = TWE_OP_WRITE; - } else { - twe_release_request(tr); - biofinish(bp, NULL, EOPNOTSUPP); - break; - } - - /* build a suitable I/O command (assumes 512-byte rounded transfers) */ - cmd->io.size = 3; - cmd->io.unit = *(int *)(bp->bio_driver1); - cmd->io.block_count = (tr->tr_length + TWE_BLOCK_SIZE - 1) / TWE_BLOCK_SIZE; - cmd->io.lba = bp->bio_pblkno; - } - - /* did we find something to do? */ - if (tr == NULL) - break; - - /* try to map and submit the command to controller */ - error = twe_map_request(tr); - - if (error != 0) { - if (error == EBUSY) - break; - tr->tr_status = TWE_CMD_ERROR; - if (tr->tr_private != NULL) { - bp = (struct bio *)(tr->tr_private); - bp->bio_error = error; - bp->bio_flags |= BIO_ERROR; - tr->tr_private = NULL; - twed_intr(bp); - twe_release_request(tr); - } else if (tr->tr_flags & TWE_CMD_SLEEPER) - wakeup_one(tr); /* wakeup the sleeping owner */ - } - } -} - -/******************************************************************************** - * Write blocks from memory to disk, for system crash dumps. - */ -int -twe_dump_blocks(struct twe_softc *sc, int unit, u_int32_t lba, void *data, int nblks) -{ - struct twe_request *tr; - TWE_Command *cmd; - int error; - - if (twe_get_request(sc, &tr)) - return(ENOMEM); - - tr->tr_data = data; - tr->tr_status = TWE_CMD_SETUP; - tr->tr_length = nblks * TWE_BLOCK_SIZE; - tr->tr_flags = TWE_CMD_DATAOUT; - - cmd = TWE_FIND_COMMAND(tr); - cmd->io.opcode = TWE_OP_WRITE; - cmd->io.size = 3; - cmd->io.unit = unit; - cmd->io.block_count = nblks; - cmd->io.lba = lba; - - error = twe_immediate_request(tr, 0); - if (error == 0) - if (twe_report_request(tr)) - error = EIO; - twe_release_request(tr); - return(error); -} - -/******************************************************************************** - * Handle controller-specific control operations. - */ -int -twe_ioctl(struct twe_softc *sc, u_long ioctlcmd, void *addr) -{ - struct twe_usercommand *tu = (struct twe_usercommand *)addr; - struct twe_paramcommand *tp = (struct twe_paramcommand *)addr; - struct twe_drivecommand *td = (struct twe_drivecommand *)addr; - union twe_statrequest *ts = (union twe_statrequest *)addr; - TWE_Param *param; - TWE_Command *cmd; - void *data; - u_int16_t *aen_code = (u_int16_t *)addr; - struct twe_request *tr; - u_int8_t srid; - int error; - size_t tr_length; - - error = 0; - switch(ioctlcmd) { - /* handle a command from userspace */ - case TWEIO_COMMAND: - /* - * if there's a data buffer, allocate and copy it in. - * Must be in multiplied of 512 bytes. - */ - tr_length = roundup2(tu->tu_size, 512); - if (tr_length > 0) { - data = malloc(tr_length, M_DEVBUF, M_WAITOK); - error = copyin(tu->tu_data, data, tu->tu_size); - if (error) { - free(data, M_DEVBUF); - break; - } - } else - data = NULL; - - /* get a request */ - TWE_IO_LOCK(sc); - while (twe_get_request(sc, &tr)) - mtx_sleep(sc, &sc->twe_io_lock, PPAUSE, "twioctl", hz); - - /* - * Save the command's request ID, copy the user-supplied command in, - * restore the request ID. - */ - cmd = TWE_FIND_COMMAND(tr); - srid = cmd->generic.request_id; - bcopy(&tu->tu_command, cmd, sizeof(TWE_Command)); - cmd->generic.request_id = srid; - - tr->tr_length = tr_length; - tr->tr_data = data; - if (tr->tr_length > 0) { - tr->tr_flags |= TWE_CMD_DATAIN | TWE_CMD_DATAOUT; - } - - /* run the command */ - error = twe_wait_request(tr); - TWE_IO_UNLOCK(sc); - if (error) - goto cmd_done; - - /* copy the command out again */ - bcopy(cmd, &tu->tu_command, sizeof(TWE_Command)); - - /* if there was a data buffer, copy it out */ - if (tr->tr_length > 0) - error = copyout(tr->tr_data, tu->tu_data, tu->tu_size); - - cmd_done: - /* free resources */ - if (tr->tr_data != NULL) - free(tr->tr_data, M_DEVBUF); - TWE_IO_LOCK(sc); - twe_release_request(tr); - TWE_IO_UNLOCK(sc); - - break; - - /* fetch statistics counter */ - case TWEIO_STATS: - switch (ts->ts_item) { -#ifdef TWE_PERFORMANCE_MONITOR - case TWEQ_FREE: - case TWEQ_BIO: - case TWEQ_READY: - case TWEQ_BUSY: - case TWEQ_COMPLETE: - TWE_IO_LOCK(sc); - bcopy(&sc->twe_qstat[ts->ts_item], &ts->ts_qstat, sizeof(struct twe_qstat)); - TWE_IO_UNLOCK(sc); - break; -#endif - default: - error = ENOENT; - break; - } - break; - - /* poll for an AEN */ - case TWEIO_AEN_POLL: - TWE_IO_LOCK(sc); - *aen_code = twe_dequeue_aen(sc); - TWE_IO_UNLOCK(sc); - break; - - /* wait for another AEN to show up */ - case TWEIO_AEN_WAIT: - TWE_IO_LOCK(sc); - while ((*aen_code = twe_dequeue_aen(sc)) == TWE_AEN_QUEUE_EMPTY) { - error = mtx_sleep(&sc->twe_aen_queue, &sc->twe_io_lock, PRIBIO | PCATCH, - "tweaen", 0); - if (error == EINTR) - break; - } - TWE_IO_UNLOCK(sc); - break; - - case TWEIO_GET_PARAM: - TWE_IO_LOCK(sc); - param = twe_get_param(sc, tp->tp_table_id, tp->tp_param_id, tp->tp_size, NULL); - TWE_IO_UNLOCK(sc); - if (param == NULL) { - twe_printf(sc, "TWEIO_GET_PARAM failed for 0x%x/0x%x/%d\n", - tp->tp_table_id, tp->tp_param_id, tp->tp_size); - error = EINVAL; - } else { - if (param->parameter_size_bytes > tp->tp_size) { - twe_printf(sc, "TWEIO_GET_PARAM parameter too large (%d > %d)\n", - param->parameter_size_bytes, tp->tp_size); - error = EFAULT; - } else { - error = copyout(param->data, tp->tp_data, param->parameter_size_bytes); - } - free(param, M_DEVBUF); - } - break; - - case TWEIO_SET_PARAM: - data = malloc(tp->tp_size, M_DEVBUF, M_WAITOK); - error = copyin(tp->tp_data, data, tp->tp_size); - if (error == 0) { - TWE_IO_LOCK(sc); - error = twe_set_param(sc, tp->tp_table_id, tp->tp_param_id, tp->tp_size, data); - TWE_IO_UNLOCK(sc); - } - free(data, M_DEVBUF); - break; - - case TWEIO_RESET: - TWE_IO_LOCK(sc); - twe_reset(sc); - TWE_IO_UNLOCK(sc); - break; - - case TWEIO_ADD_UNIT: - TWE_CONFIG_LOCK(sc); - error = twe_add_unit(sc, td->td_unit); - TWE_CONFIG_UNLOCK(sc); - break; - - case TWEIO_DEL_UNIT: - TWE_CONFIG_LOCK(sc); - error = twe_del_unit(sc, td->td_unit); - TWE_CONFIG_UNLOCK(sc); - break; - - /* XXX implement ATA PASSTHROUGH */ - - /* nothing we understand */ - default: - error = ENOTTY; - } - - return(error); -} - -/******************************************************************************** - * Enable the useful interrupts from the controller. - */ -void -twe_enable_interrupts(struct twe_softc *sc) -{ - sc->twe_state |= TWE_STATE_INTEN; - TWE_CONTROL(sc, - TWE_CONTROL_CLEAR_ATTENTION_INTERRUPT | - TWE_CONTROL_UNMASK_RESPONSE_INTERRUPT | - TWE_CONTROL_ENABLE_INTERRUPTS); -} - -/******************************************************************************** - * Disable interrupts from the controller. - */ -void -twe_disable_interrupts(struct twe_softc *sc) -{ - TWE_CONTROL(sc, TWE_CONTROL_DISABLE_INTERRUPTS); - sc->twe_state &= ~TWE_STATE_INTEN; -} - -/******************************************************************************** - ******************************************************************************** - Command Submission - ******************************************************************************** - ********************************************************************************/ - -/******************************************************************************** - * Read integer parameter table entries. - */ -static int -twe_get_param_1(struct twe_softc *sc, int table_id, int param_id, u_int8_t *result) -{ - TWE_Param *param; - - if ((param = twe_get_param(sc, table_id, param_id, 1, NULL)) == NULL) - return(ENOENT); - *result = *(u_int8_t *)param->data; - free(param, M_DEVBUF); - return(0); -} - -static int -twe_get_param_2(struct twe_softc *sc, int table_id, int param_id, u_int16_t *result) -{ - TWE_Param *param; - - if ((param = twe_get_param(sc, table_id, param_id, 2, NULL)) == NULL) - return(ENOENT); - *result = *(u_int16_t *)param->data; - free(param, M_DEVBUF); - return(0); -} - -static int -twe_get_param_4(struct twe_softc *sc, int table_id, int param_id, u_int32_t *result) -{ - TWE_Param *param; - - if ((param = twe_get_param(sc, table_id, param_id, 4, NULL)) == NULL) - return(ENOENT); - *result = *(u_int32_t *)param->data; - free(param, M_DEVBUF); - return(0); -} - -/******************************************************************************** - * Perform a TWE_OP_GET_PARAM command. If a callback function is provided, it - * will be called with the command when it's completed. If no callback is - * provided, we will wait for the command to complete and then return just the data. - * The caller is responsible for freeing the data when done with it. - */ -static void * -twe_get_param(struct twe_softc *sc, int table_id, int param_id, size_t param_size, - void (* func)(struct twe_request *tr)) -{ - struct twe_request *tr; - TWE_Command *cmd; - TWE_Param *param; - int error; - - debug_called(4); - - TWE_IO_ASSERT_LOCKED(sc); - tr = NULL; - param = NULL; - - /* get a command */ - if (twe_get_request(sc, &tr)) - goto err; - - /* get a buffer */ - if ((param = (TWE_Param *)malloc(TWE_SECTOR_SIZE, M_DEVBUF, M_NOWAIT)) == NULL) - goto err; - tr->tr_data = param; - tr->tr_length = TWE_SECTOR_SIZE; - tr->tr_flags = TWE_CMD_DATAIN | TWE_CMD_DATAOUT; - - /* build the command for the controller */ - cmd = TWE_FIND_COMMAND(tr); - cmd->param.opcode = TWE_OP_GET_PARAM; - cmd->param.size = 2; - cmd->param.unit = 0; - cmd->param.param_count = 1; - - /* fill in the outbound parameter data */ - param->table_id = table_id; - param->parameter_id = param_id; - param->parameter_size_bytes = param_size; - - /* submit the command and either wait or let the callback handle it */ - if (func == NULL) { - /* XXX could use twe_wait_request here if interrupts were enabled? */ - error = twe_immediate_request(tr, 1 /* usetmp */); - if (error == 0) { - if (twe_report_request(tr)) - goto err; - } else { - goto err; - } - twe_release_request(tr); - return(param); - } else { - tr->tr_complete = func; - error = twe_map_request(tr); - if ((error == 0) || (error == EBUSY)) - return(func); - } - - /* something failed */ -err: - debug(1, "failed"); - if (tr != NULL) - twe_release_request(tr); - if (param != NULL) - free(param, M_DEVBUF); - return(NULL); -} - -/******************************************************************************** - * Set integer parameter table entries. - */ -#ifdef TWE_SHUTDOWN_NOTIFICATION -static int -twe_set_param_1(struct twe_softc *sc, int table_id, int param_id, u_int8_t value) -{ - return(twe_set_param(sc, table_id, param_id, sizeof(value), &value)); -} -#endif - -#if 0 -static int -twe_set_param_2(struct twe_softc *sc, int table_id, int param_id, u_int16_t value) -{ - return(twe_set_param(sc, table_id, param_id, sizeof(value), &value)); -} - -static int -twe_set_param_4(struct twe_softc *sc, int table_id, int param_id, u_int32_t value) -{ - return(twe_set_param(sc, table_id, param_id, sizeof(value), &value)); -} -#endif - -/******************************************************************************** - * Perform a TWE_OP_SET_PARAM command, returns nonzero on error. - */ -static int -twe_set_param(struct twe_softc *sc, int table_id, int param_id, int param_size, void *data) -{ - struct twe_request *tr; - TWE_Command *cmd; - TWE_Param *param; - int error; - - debug_called(4); - - TWE_IO_ASSERT_LOCKED(sc); - tr = NULL; - param = NULL; - error = ENOMEM; - - /* get a command */ - if (twe_get_request(sc, &tr)) - goto out; - - /* get a buffer */ - if ((param = (TWE_Param *)malloc(TWE_SECTOR_SIZE, M_DEVBUF, M_NOWAIT)) == NULL) - goto out; - tr->tr_data = param; - tr->tr_length = TWE_SECTOR_SIZE; - tr->tr_flags = TWE_CMD_DATAIN | TWE_CMD_DATAOUT; - - /* build the command for the controller */ - cmd = TWE_FIND_COMMAND(tr); - cmd->param.opcode = TWE_OP_SET_PARAM; - cmd->param.size = 2; - cmd->param.unit = 0; - cmd->param.param_count = 1; - - /* fill in the outbound parameter data */ - param->table_id = table_id; - param->parameter_id = param_id; - param->parameter_size_bytes = param_size; - bcopy(data, param->data, param_size); - - /* XXX could use twe_wait_request here if interrupts were enabled? */ - error = twe_immediate_request(tr, 1 /* usetmp */); - if (error == 0) { - if (twe_report_request(tr)) - error = EIO; - } - -out: - if (tr != NULL) - twe_release_request(tr); - if (param != NULL) - free(param, M_DEVBUF); - return(error); -} - -/******************************************************************************** - * Perform a TWE_OP_INIT_CONNECTION command, returns nonzero on error. - * - * Typically called with interrupts disabled. - */ -static int -twe_init_connection(struct twe_softc *sc, int mode) -{ - struct twe_request *tr; - TWE_Command *cmd; - int error; - - debug_called(4); - - TWE_IO_ASSERT_LOCKED(sc); - - /* get a command */ - if (twe_get_request(sc, &tr)) - return(0); - - /* build the command */ - cmd = TWE_FIND_COMMAND(tr); - cmd->initconnection.opcode = TWE_OP_INIT_CONNECTION; - cmd->initconnection.size = 3; - cmd->initconnection.host_id = 0; - cmd->initconnection.message_credits = mode; - cmd->initconnection.response_queue_pointer = 0; - - /* submit the command */ - error = twe_immediate_request(tr, 0 /* usetmp */); - twe_release_request(tr); - - if (mode == TWE_INIT_MESSAGE_CREDITS) - sc->twe_host_id = cmd->initconnection.host_id; - return(error); -} - -/******************************************************************************** - * Start the command (tr) and sleep waiting for it to complete. - * - * Successfully completed commands are dequeued. - */ -static int -twe_wait_request(struct twe_request *tr) -{ - - debug_called(4); - - TWE_IO_ASSERT_LOCKED(tr->tr_sc); - tr->tr_flags |= TWE_CMD_SLEEPER; - tr->tr_status = TWE_CMD_BUSY; - twe_enqueue_ready(tr); - twe_startio(tr->tr_sc); - while (tr->tr_status == TWE_CMD_BUSY) - mtx_sleep(tr, &tr->tr_sc->twe_io_lock, PRIBIO, "twewait", 0); - - return(tr->tr_status != TWE_CMD_COMPLETE); -} - -/******************************************************************************** - * Start the command (tr) and busy-wait for it to complete. - * This should only be used when interrupts are actually disabled (although it - * will work if they are not). - */ -static int -twe_immediate_request(struct twe_request *tr, int usetmp) -{ - struct twe_softc *sc; - int error; - int count = 0; - - debug_called(4); - - sc = tr->tr_sc; - - if (usetmp && (tr->tr_data != NULL)) { - tr->tr_flags |= TWE_CMD_IMMEDIATE; - if (tr->tr_length > DFLTPHYS) - return (EINVAL); - bcopy(tr->tr_data, sc->twe_immediate, tr->tr_length); - } - tr->tr_status = TWE_CMD_BUSY; - if ((error = twe_map_request(tr)) != 0) - if (error != EBUSY) - return(error); - - /* Wait up to 5 seconds for the command to complete */ - while ((count++ < 5000) && (tr->tr_status == TWE_CMD_BUSY)){ - DELAY(1000); - twe_done(sc, 1); - } - if (usetmp && (tr->tr_data != NULL)) - bcopy(sc->twe_immediate, tr->tr_data, tr->tr_length); - - return(tr->tr_status != TWE_CMD_COMPLETE); -} - -/******************************************************************************** - * Handle completion of an I/O command. - */ -static void -twe_completeio(struct twe_request *tr) -{ - TWE_Command *cmd = TWE_FIND_COMMAND(tr); - struct twe_softc *sc = tr->tr_sc; - struct bio *bp = tr->tr_private; - - debug_called(4); - - if (tr->tr_status == TWE_CMD_COMPLETE) { - if (cmd->generic.status) - if (twe_report_request(tr)) { - bp->bio_error = EIO; - bp->bio_flags |= BIO_ERROR; - } - - } else { - twe_panic(sc, "twe_completeio on incomplete command"); - } - tr->tr_private = NULL; - twed_intr(bp); - twe_release_request(tr); -} - -/******************************************************************************** - * Reset the controller and pull all the active commands back onto the ready - * queue. Used to restart a controller that's exhibiting bad behaviour. - */ -static void -twe_reset(struct twe_softc *sc) -{ - struct twe_request *tr; - int i; - - /* - * Sleep for a short period to allow AENs to be signalled. - */ - mtx_sleep(sc, &sc->twe_io_lock, PRIBIO, "twereset", hz); - - /* - * Disable interrupts from the controller, and mask any accidental entry - * into our interrupt handler. - */ - twe_printf(sc, "controller reset in progress...\n"); - twe_disable_interrupts(sc); - - /* - * Try to soft-reset the controller. - */ - for (i = 0; i < TWE_MAX_RESET_TRIES; i++) { - if (i > 0) - twe_printf(sc, "reset %d failed, trying again\n", i); - - if (!twe_soft_reset(sc)) - break; /* reset process complete */ - } - /* did we give up? */ - if (i >= TWE_MAX_RESET_TRIES) { - twe_printf(sc, "can't reset controller, giving up\n"); - goto out; - } - - /* - * Move all of the commands that were busy back to the ready queue. - */ - i = 0; - while ((tr = twe_dequeue_busy(sc)) != NULL) { - twe_enqueue_ready(tr); - i++; - } - - /* - * Kick the controller to start things going again, then re-enable interrupts. - */ - twe_startio(sc); - twe_printf(sc, "controller reset done, %d commands restarted\n", i); - -out: - twe_enable_interrupts(sc); -} - -/******************************************************************************** - ******************************************************************************** - Command I/O to Controller - ******************************************************************************** - ********************************************************************************/ - -/******************************************************************************** - * Try to deliver (tr) to the controller. - * - * Can be called at any interrupt level, with or without interrupts enabled. - */ -int -twe_start(struct twe_request *tr) -{ - struct twe_softc *sc = tr->tr_sc; -#ifdef TWE_DEBUG - TWE_Command *cmd; -#endif - int i; - u_int32_t status_reg; - - debug_called(4); - - if (!dumping) - TWE_IO_ASSERT_LOCKED(sc); - - /* mark the command as currently being processed */ - tr->tr_status = TWE_CMD_BUSY; -#ifdef TWE_DEBUG - cmd = TWE_FIND_COMMAND(tr); -#endif - - /* - * Spin briefly waiting for the controller to come ready - * - * XXX it might be more efficient to return EBUSY immediately - * and let the command be rescheduled. - */ - for (i = 100000; (i > 0); i--) { - /* check to see if we can post a command */ - status_reg = TWE_STATUS(sc); - twe_check_bits(sc, status_reg); - - if (!(status_reg & TWE_STATUS_COMMAND_QUEUE_FULL)) { - twe_enqueue_busy(tr); - - TWE_COMMAND_QUEUE(sc, TWE_FIND_COMMANDPHYS(tr)); - - /* move command to work queue */ -#ifdef TWE_DEBUG - if (tr->tr_complete != NULL) { - debug(3, "queued request %d with callback %p", cmd->generic.request_id, tr->tr_complete); - } else if (tr->tr_flags & TWE_CMD_SLEEPER) { - debug(3, "queued request %d with wait channel %p", cmd->generic.request_id, tr); - } else { - debug(3, "queued request %d for polling caller", cmd->generic.request_id); - } -#endif - return(0); - } else if (!(status_reg & TWE_STATUS_RESPONSE_QUEUE_EMPTY) && i > 1) - twe_done(sc, 0); - } - - /* - * We couldn't get the controller to take the command; try submitting it again later. - * This should only happen if something is wrong with the controller, or if we have - * overestimated the number of commands it can accept. (Should we actually reject - * the command at this point?) - */ - return(EBUSY); -} - -/******************************************************************************** - * Poll the controller (sc) for completed commands. - * - * Can be called at any interrupt level, with or without interrupts enabled. - */ -static void -twe_done(struct twe_softc *sc, int startio) -{ - TWE_Response_Queue rq; -#ifdef TWE_DEBUG - TWE_Command *cmd; -#endif - struct twe_request *tr; - int found; - u_int32_t status_reg; - - debug_called(5); - - /* loop collecting completed commands */ - found = 0; - for (;;) { - status_reg = TWE_STATUS(sc); - twe_check_bits(sc, status_reg); /* XXX should this fail? */ - - if (!(status_reg & TWE_STATUS_RESPONSE_QUEUE_EMPTY)) { - found = 1; - rq = TWE_RESPONSE_QUEUE(sc); - tr = sc->twe_lookup[rq.u.response_id]; /* find command */ -#ifdef TWE_DEBUG - cmd = TWE_FIND_COMMAND(tr); -#endif - if (tr->tr_status != TWE_CMD_BUSY) - twe_printf(sc, "completion event for nonbusy command\n"); - tr->tr_status = TWE_CMD_COMPLETE; - debug(3, "completed request id %d with status %d", - cmd->generic.request_id, cmd->generic.status); - /* move to completed queue */ - twe_remove_busy(tr); - twe_enqueue_complete(tr); - sc->twe_state &= ~TWE_STATE_CTLR_BUSY; - } else { - break; /* no response ready */ - } - } - - /* if we've completed any commands, try posting some more */ - if (found && startio) - twe_startio(sc); - - /* handle completion and timeouts */ - twe_complete(sc); /* XXX use deferred completion? */ -} - -/******************************************************************************** - * Perform post-completion processing for commands on (sc). - * - * This is split from twe_done as it can be safely deferred and run at a lower - * priority level should facilities for such a thing become available. - */ -static void -twe_complete(struct twe_softc *sc) -{ - struct twe_request *tr; - - debug_called(5); - - /* - * Pull commands off the completed list, dispatch them appropriately - */ - while ((tr = twe_dequeue_complete(sc)) != NULL) { - /* unmap the command's data buffer */ - twe_unmap_request(tr); - - /* dispatch to suit command originator */ - if (tr->tr_complete != NULL) { /* completion callback */ - debug(2, "call completion handler %p", tr->tr_complete); - tr->tr_complete(tr); - - } else if (tr->tr_flags & TWE_CMD_SLEEPER) { /* caller is asleep waiting */ - debug(2, "wake up command owner on %p", tr); - wakeup_one(tr); - - } else { /* caller is polling command */ - debug(2, "command left for owner"); - } - } -} - -/******************************************************************************** - * Wait for (status) to be set in the controller status register for up to - * (timeout) seconds. Returns 0 if found, nonzero if we time out. - * - * Note: this busy-waits, rather than sleeping, since we may be called with - * eg. clock interrupts masked. - */ -static int -twe_wait_status(struct twe_softc *sc, u_int32_t status, int timeout) -{ - time_t expiry; - u_int32_t status_reg; - - debug_called(4); - - expiry = time_second + timeout; - - do { - status_reg = TWE_STATUS(sc); - if (status_reg & status) /* got the required bit(s)? */ - return(0); - DELAY(100000); - } while (time_second <= expiry); - - return(1); -} - -/******************************************************************************** - * Drain the response queue, which may contain responses to commands we know - * nothing about. - */ -static int -twe_drain_response_queue(struct twe_softc *sc) -{ - u_int32_t status_reg; - - debug_called(4); - - for (;;) { /* XXX give up eventually? */ - status_reg = TWE_STATUS(sc); - if (twe_check_bits(sc, status_reg)) - return(1); - if (status_reg & TWE_STATUS_RESPONSE_QUEUE_EMPTY) - return(0); - } -} - -/******************************************************************************** - * Soft-reset the controller - */ -static int -twe_soft_reset(struct twe_softc *sc) -{ - u_int32_t status_reg; - - debug_called(2); - - TWE_IO_ASSERT_LOCKED(sc); - TWE_SOFT_RESET(sc); - - if (twe_wait_status(sc, TWE_STATUS_ATTENTION_INTERRUPT, 30)) { - twe_printf(sc, "no attention interrupt\n"); - return(1); - } - TWE_CONTROL(sc, TWE_CONTROL_CLEAR_ATTENTION_INTERRUPT); - if (twe_drain_aen_queue(sc)) { - twe_printf(sc, "can't drain AEN queue\n"); - return(1); - } - if (twe_find_aen(sc, TWE_AEN_SOFT_RESET)) { - twe_printf(sc, "reset not reported\n"); - return(1); - } - status_reg = TWE_STATUS(sc); - if (TWE_STATUS_ERRORS(status_reg) || twe_check_bits(sc, status_reg)) { - twe_printf(sc, "controller errors detected\n"); - return(1); - } - if (twe_drain_response_queue(sc)) { - twe_printf(sc, "can't drain response queue\n"); - return(1); - } - return(0); -} - -/******************************************************************************** - ******************************************************************************** - Interrupt Handling - ******************************************************************************** - ********************************************************************************/ - -/******************************************************************************** - * Host interrupt. - * - * XXX what does this mean? - */ -static void -twe_host_intr(struct twe_softc *sc) -{ - debug_called(4); - - twe_printf(sc, "host interrupt\n"); - TWE_CONTROL(sc, TWE_CONTROL_CLEAR_HOST_INTERRUPT); -} - -/******************************************************************************** - * Attention interrupt. - * - * Signalled when the controller has one or more AENs for us. - */ -static void -twe_attention_intr(struct twe_softc *sc) -{ - debug_called(4); - - /* instigate a poll for AENs */ - if (twe_fetch_aen(sc)) { - twe_printf(sc, "error polling for signalled AEN\n"); - } else { - TWE_CONTROL(sc, TWE_CONTROL_CLEAR_ATTENTION_INTERRUPT); - } -} - -/******************************************************************************** - * Command interrupt. - * - * Signalled when the controller can handle more commands. - */ -static void -twe_command_intr(struct twe_softc *sc) -{ - debug_called(4); - - /* - * We don't use this, rather we try to submit commands when we receive - * them, and when other commands have completed. Mask it so we don't get - * another one. - */ - TWE_CONTROL(sc, TWE_CONTROL_MASK_COMMAND_INTERRUPT); -} - -/******************************************************************************** - ******************************************************************************** - Asynchronous Event Handling - ******************************************************************************** - ********************************************************************************/ - -/******************************************************************************** - * Request an AEN from the controller. - */ -static int -twe_fetch_aen(struct twe_softc *sc) -{ - - debug_called(4); - - if ((twe_get_param(sc, TWE_PARAM_AEN, TWE_PARAM_AEN_UnitCode, 2, twe_handle_aen)) == NULL) - return(EIO); - return(0); -} - -/******************************************************************************** - * Handle an AEN returned by the controller. - */ -static void -twe_handle_aen(struct twe_request *tr) -{ - struct twe_softc *sc = tr->tr_sc; - TWE_Param *param; - u_int16_t aen; - - debug_called(4); - - /* XXX check for command success somehow? */ - - param = (TWE_Param *)tr->tr_data; - aen = *(u_int16_t *)(param->data); - - free(tr->tr_data, M_DEVBUF); - twe_release_request(tr); - twe_enqueue_aen(sc, aen); - - /* XXX poll for more AENs? */ -} - -/******************************************************************************** - * Pull AENs out of the controller and park them in the queue, in a context where - * interrupts aren't active. Return nonzero if we encounter any errors in the - * process of obtaining all the available AENs. - */ -static int -twe_drain_aen_queue(struct twe_softc *sc) -{ - u_int16_t aen; - - TWE_IO_ASSERT_LOCKED(sc); - for (;;) { - if (twe_get_param_2(sc, TWE_PARAM_AEN, TWE_PARAM_AEN_UnitCode, &aen)) - return(1); - if (aen == TWE_AEN_QUEUE_EMPTY) - return(0); - twe_enqueue_aen(sc, aen); - } -} - -/******************************************************************************** - * Push an AEN that we've received onto the queue. - * - * Note that we have to lock this against reentrance, since it may be called - * from both interrupt and non-interrupt context. - * - * If someone is waiting for the AEN we have, wake them up. - */ -static void -twe_enqueue_aen(struct twe_softc *sc, u_int16_t aen) -{ - char *msg; - int next, nextnext; - - debug_called(4); - - TWE_IO_ASSERT_LOCKED(sc); - if ((msg = twe_format_aen(sc, aen)) != NULL) - twe_printf(sc, "AEN: <%s>\n", msg); - - /* enqueue the AEN */ - next = ((sc->twe_aen_head + 1) % TWE_Q_LENGTH); - nextnext = ((sc->twe_aen_head + 2) % TWE_Q_LENGTH); - - /* check to see if this is the last free slot, and subvert the AEN if it is */ - if (nextnext == sc->twe_aen_tail) - aen = TWE_AEN_QUEUE_FULL; - - /* look to see if there's room for this AEN */ - if (next != sc->twe_aen_tail) { - sc->twe_aen_queue[sc->twe_aen_head] = aen; - sc->twe_aen_head = next; - } - - /* wake up anyone asleep on the queue */ - wakeup(&sc->twe_aen_queue); - - /* anyone looking for this AEN? */ - if (sc->twe_wait_aen == aen) { - sc->twe_wait_aen = -1; - wakeup(&sc->twe_wait_aen); - } -} - -/******************************************************************************** - * Pop an AEN off the queue, or return -1 if there are none left. - * - * We are more or less interrupt-safe, so don't block interrupts. - */ -static u_int16_t -twe_dequeue_aen(struct twe_softc *sc) -{ - u_int16_t result; - - debug_called(4); - - TWE_IO_ASSERT_LOCKED(sc); - if (sc->twe_aen_tail == sc->twe_aen_head) { - result = TWE_AEN_QUEUE_EMPTY; - } else { - result = sc->twe_aen_queue[sc->twe_aen_tail]; - sc->twe_aen_tail = ((sc->twe_aen_tail + 1) % TWE_Q_LENGTH); - } - return(result); -} - -/******************************************************************************** - * Check to see if the requested AEN is in the queue. - * - * XXX we could probably avoid masking interrupts here - */ -static int -twe_find_aen(struct twe_softc *sc, u_int16_t aen) -{ - int i, missing; - - missing = 1; - for (i = sc->twe_aen_tail; (i != sc->twe_aen_head) && missing; i = (i + 1) % TWE_Q_LENGTH) { - if (sc->twe_aen_queue[i] == aen) - missing = 0; - } - return(missing); -} - -#if 0 /* currently unused */ -/******************************************************************************** - * Sleep waiting for at least (timeout) seconds until we see (aen) as - * requested. Returns nonzero on timeout or failure. - * - * XXX: this should not be used in cases where there may be more than one sleeper - * without a mechanism for registering multiple sleepers. - */ -static int -twe_wait_aen(struct twe_softc *sc, int aen, int timeout) -{ - time_t expiry; - int found; - - debug_called(4); - - expiry = time_second + timeout; - found = 0; - - sc->twe_wait_aen = aen; - do { - twe_fetch_aen(sc); - mtx_sleep(&sc->twe_wait_aen, &sc->twe_io_lock, PZERO, "twewaen", hz); - if (sc->twe_wait_aen == -1) - found = 1; - } while ((time_second <= expiry) && !found); - return(!found); -} -#endif - -/******************************************************************************** - ******************************************************************************** - Command Buffer Management - ******************************************************************************** - ********************************************************************************/ - -/******************************************************************************** - * Get a new command buffer. - * - * This will return NULL if all command buffers are in use. - */ -static int -twe_get_request(struct twe_softc *sc, struct twe_request **tr) -{ - TWE_Command *cmd; - debug_called(4); - - if (!dumping) - TWE_IO_ASSERT_LOCKED(sc); - - /* try to reuse an old buffer */ - *tr = twe_dequeue_free(sc); - - /* initialise some fields to their defaults */ - if (*tr != NULL) { - cmd = TWE_FIND_COMMAND(*tr); - (*tr)->tr_data = NULL; - (*tr)->tr_private = NULL; - (*tr)->tr_status = TWE_CMD_SETUP; /* command is in setup phase */ - (*tr)->tr_flags = 0; - (*tr)->tr_complete = NULL; - cmd->generic.status = 0; /* before submission to controller */ - cmd->generic.flags = 0; /* not used */ - } - return(*tr == NULL); -} - -/******************************************************************************** - * Release a command buffer for reuse. - * - */ -static void -twe_release_request(struct twe_request *tr) -{ - debug_called(4); - - if (!dumping) - TWE_IO_ASSERT_LOCKED(tr->tr_sc); - if (tr->tr_private != NULL) - twe_panic(tr->tr_sc, "tr_private != NULL"); - twe_enqueue_free(tr); -} - -/******************************************************************************** - ******************************************************************************** - Debugging - ******************************************************************************** - ********************************************************************************/ - -/******************************************************************************** - * Print some information about the controller - */ -void -twe_describe_controller(struct twe_softc *sc) -{ - TWE_Param *p[6]; - u_int8_t ports; - u_int32_t size; - int i; - - debug_called(2); - - TWE_IO_LOCK(sc); - - /* get the port count */ - twe_get_param_1(sc, TWE_PARAM_CONTROLLER, TWE_PARAM_CONTROLLER_PortCount, &ports); - - /* get version strings */ - p[0] = twe_get_param(sc, TWE_PARAM_VERSION, TWE_PARAM_VERSION_FW, 16, NULL); - p[1] = twe_get_param(sc, TWE_PARAM_VERSION, TWE_PARAM_VERSION_BIOS, 16, NULL); - if (p[0] && p[1]) - twe_printf(sc, "%d ports, Firmware %.16s, BIOS %.16s\n", ports, p[0]->data, p[1]->data); - - if (bootverbose) { - p[2] = twe_get_param(sc, TWE_PARAM_VERSION, TWE_PARAM_VERSION_Mon, 16, NULL); - p[3] = twe_get_param(sc, TWE_PARAM_VERSION, TWE_PARAM_VERSION_PCB, 8, NULL); - p[4] = twe_get_param(sc, TWE_PARAM_VERSION, TWE_PARAM_VERSION_ATA, 8, NULL); - p[5] = twe_get_param(sc, TWE_PARAM_VERSION, TWE_PARAM_VERSION_PCI, 8, NULL); - - if (p[2] && p[3] && p[4] && p[5]) - twe_printf(sc, "Monitor %.16s, PCB %.8s, Achip %.8s, Pchip %.8s\n", p[2]->data, p[3]->data, - p[4]->data, p[5]->data); - if (p[2]) - free(p[2], M_DEVBUF); - if (p[3]) - free(p[3], M_DEVBUF); - if (p[4]) - free(p[4], M_DEVBUF); - if (p[5]) - free(p[5], M_DEVBUF); - } - if (p[0]) - free(p[0], M_DEVBUF); - if (p[1]) - free(p[1], M_DEVBUF); - - /* print attached drives */ - if (bootverbose) { - p[0] = twe_get_param(sc, TWE_PARAM_DRIVESUMMARY, TWE_PARAM_DRIVESUMMARY_Status, 16, NULL); - for (i = 0; i < ports; i++) { - if (p[0]->data[i] != TWE_PARAM_DRIVESTATUS_Present) - continue; - twe_get_param_4(sc, TWE_PARAM_DRIVEINFO + i, TWE_PARAM_DRIVEINFO_Size, &size); - p[1] = twe_get_param(sc, TWE_PARAM_DRIVEINFO + i, TWE_PARAM_DRIVEINFO_Model, 40, NULL); - if (p[1] != NULL) { - twe_printf(sc, "port %d: %.40s %dMB\n", i, p[1]->data, size / 2048); - free(p[1], M_DEVBUF); - } else { - twe_printf(sc, "port %d, drive status unavailable\n", i); - } - } - if (p[0]) - free(p[0], M_DEVBUF); - } - TWE_IO_UNLOCK(sc); -} - -/******************************************************************************** - * Look up a text description of a numeric code and return a pointer to same. - */ -char * -twe_describe_code(struct twe_code_lookup *table, u_int32_t code) -{ - int i; - - for (i = 0; table[i].string != NULL; i++) - if (table[i].code == code) - return(table[i].string); - return(table[i+1].string); -} - -/******************************************************************************** - * Complain if the status bits aren't what we're expecting. - * - * Rate-limit the complaints to at most one of each every five seconds, but - * always return the correct status. - */ -static int -twe_check_bits(struct twe_softc *sc, u_int32_t status_reg) -{ - int result; - static time_t lastwarn[2] = {0, 0}; - - /* - * This can be a little problematic, as twe_panic may call twe_reset if - * TWE_DEBUG is not set, which will call us again as part of the soft reset. - */ - if ((status_reg & TWE_STATUS_PANIC_BITS) != 0) { - twe_printf(sc, "FATAL STATUS BIT(S) %b\n", status_reg & TWE_STATUS_PANIC_BITS, - TWE_STATUS_BITS_DESCRIPTION); - twe_panic(sc, "fatal status bits"); - } - - result = 0; - if ((status_reg & TWE_STATUS_EXPECTED_BITS) != TWE_STATUS_EXPECTED_BITS) { - if (time_second > (lastwarn[0] + 5)) { - twe_printf(sc, "missing expected status bit(s) %b\n", ~status_reg & TWE_STATUS_EXPECTED_BITS, - TWE_STATUS_BITS_DESCRIPTION); - lastwarn[0] = time_second; - } - result = 1; - } - - if ((status_reg & TWE_STATUS_UNEXPECTED_BITS) != 0) { - if (time_second > (lastwarn[1] + 5)) { - twe_printf(sc, "unexpected status bit(s) %b\n", status_reg & TWE_STATUS_UNEXPECTED_BITS, - TWE_STATUS_BITS_DESCRIPTION); - lastwarn[1] = time_second; - } - result = 1; - if (status_reg & TWE_STATUS_PCI_PARITY_ERROR) { - twe_printf(sc, "PCI parity error: Reseat card, move card or buggy device present.\n"); - twe_clear_pci_parity_error(sc); - } - if (status_reg & TWE_STATUS_PCI_ABORT) { - twe_printf(sc, "PCI abort, clearing.\n"); - twe_clear_pci_abort(sc); - } - } - - return(result); -} - -/******************************************************************************** - * Return a string describing (aen). - * - * The low 8 bits of the aen are the code, the high 8 bits give the unit number - * where an AEN is specific to a unit. - * - * Note that we could expand this routine to handle eg. up/downgrading the status - * of a drive if we had some idea of what the drive's initial status was. - */ - -static char * -twe_format_aen(struct twe_softc *sc, u_int16_t aen) -{ - device_t child; - char *code, *msg; - - code = twe_describe_code(twe_table_aen, TWE_AEN_CODE(aen)); - msg = code + 2; - - switch (*code) { - case 'q': - if (!bootverbose) - return(NULL); - /* FALLTHROUGH */ - case 'a': - return(msg); - - case 'c': - if ((child = sc->twe_drive[TWE_AEN_UNIT(aen)].td_disk) != NULL) { - snprintf(sc->twe_aen_buf, sizeof(sc->twe_aen_buf), "twed%d: %s", - device_get_unit(child), msg); - } else { - snprintf(sc->twe_aen_buf, sizeof(sc->twe_aen_buf), - "twe%d: %s for unknown unit %d", device_get_unit(sc->twe_dev), - msg, TWE_AEN_UNIT(aen)); - } - return(sc->twe_aen_buf); - - case 'p': - snprintf(sc->twe_aen_buf, sizeof(sc->twe_aen_buf), - "twe%d: port %d: %s", device_get_unit(sc->twe_dev), - TWE_AEN_UNIT(aen), msg); - return(sc->twe_aen_buf); - - case 'x': - default: - break; - } - snprintf(sc->twe_aen_buf, sizeof(sc->twe_aen_buf), "unknown AEN 0x%x", aen); - return(sc->twe_aen_buf); -} - -/******************************************************************************** - * Print a diagnostic if the status of the command warrants it, and return - * either zero (command was ok) or nonzero (command failed). - */ -static int -twe_report_request(struct twe_request *tr) -{ - struct twe_softc *sc = tr->tr_sc; - TWE_Command *cmd = TWE_FIND_COMMAND(tr); - int result = 0; - - /* - * Check the command status value and handle accordingly. - */ - if (cmd->generic.status == TWE_STATUS_RESET) { - /* - * The status code 0xff requests a controller reset. - */ - twe_printf(sc, "command returned with controller reset request\n"); - twe_reset(sc); - result = 1; - } else if (cmd->generic.status > TWE_STATUS_FATAL) { - /* - * Fatal errors that don't require controller reset. - * - * We know a few special flags values. - */ - switch (cmd->generic.flags) { - case 0x1b: - device_printf(sc->twe_drive[cmd->generic.unit].td_disk, - "drive timeout"); - break; - case 0x51: - device_printf(sc->twe_drive[cmd->generic.unit].td_disk, - "unrecoverable drive error"); - break; - default: - device_printf(sc->twe_drive[cmd->generic.unit].td_disk, - "controller error - %s (flags = 0x%x)\n", - twe_describe_code(twe_table_status, cmd->generic.status), - cmd->generic.flags); - result = 1; - } - } else if (cmd->generic.status > TWE_STATUS_WARNING) { - /* - * Warning level status. - */ - device_printf(sc->twe_drive[cmd->generic.unit].td_disk, - "warning - %s (flags = 0x%x)\n", - twe_describe_code(twe_table_status, cmd->generic.status), - cmd->generic.flags); - } else if (cmd->generic.status > 0x40) { - /* - * Info level status. - */ - device_printf(sc->twe_drive[cmd->generic.unit].td_disk, - "attention - %s (flags = 0x%x)\n", - twe_describe_code(twe_table_status, cmd->generic.status), - cmd->generic.flags); - } - - return(result); -} - -/******************************************************************************** - * Print some controller state to aid in debugging error/panic conditions - */ -void -twe_print_controller(struct twe_softc *sc) -{ - u_int32_t status_reg; - - status_reg = TWE_STATUS(sc); - twe_printf(sc, "status %b\n", status_reg, TWE_STATUS_BITS_DESCRIPTION); - twe_printf(sc, " current max min\n"); - twe_printf(sc, "free %04d %04d %04d\n", - sc->twe_qstat[TWEQ_FREE].q_length, sc->twe_qstat[TWEQ_FREE].q_max, sc->twe_qstat[TWEQ_FREE].q_min); - - twe_printf(sc, "ready %04d %04d %04d\n", - sc->twe_qstat[TWEQ_READY].q_length, sc->twe_qstat[TWEQ_READY].q_max, sc->twe_qstat[TWEQ_READY].q_min); - - twe_printf(sc, "busy %04d %04d %04d\n", - sc->twe_qstat[TWEQ_BUSY].q_length, sc->twe_qstat[TWEQ_BUSY].q_max, sc->twe_qstat[TWEQ_BUSY].q_min); - - twe_printf(sc, "complete %04d %04d %04d\n", - sc->twe_qstat[TWEQ_COMPLETE].q_length, sc->twe_qstat[TWEQ_COMPLETE].q_max, sc->twe_qstat[TWEQ_COMPLETE].q_min); - - twe_printf(sc, "bioq %04d %04d %04d\n", - sc->twe_qstat[TWEQ_BIO].q_length, sc->twe_qstat[TWEQ_BIO].q_max, sc->twe_qstat[TWEQ_BIO].q_min); - - twe_printf(sc, "AEN queue head %d tail %d\n", sc->twe_aen_head, sc->twe_aen_tail); -} - -static void -twe_panic(struct twe_softc *sc, char *reason) -{ - twe_print_controller(sc); -#ifdef TWE_DEBUG - panic(reason); -#else - twe_reset(sc); -#endif -} - -#if 0 -/******************************************************************************** - * Print a request/command in human-readable format. - */ -static void -twe_print_request(struct twe_request *tr) -{ - struct twe_softc *sc = tr->tr_sc; - TWE_Command *cmd = TWE_FIND_COMMAND(tr); - int i; - - twe_printf(sc, "CMD: request_id %d opcode <%s> size %d unit %d host_id %d\n", - cmd->generic.request_id, twe_describe_code(twe_table_opcode, cmd->generic.opcode), cmd->generic.size, - cmd->generic.unit, cmd->generic.host_id); - twe_printf(sc, " status %d flags 0x%x count %d sgl_offset %d\n", - cmd->generic.status, cmd->generic.flags, cmd->generic.count, cmd->generic.sgl_offset); - - switch(cmd->generic.opcode) { /* XXX add more opcodes? */ - case TWE_OP_READ: - case TWE_OP_WRITE: - twe_printf(sc, " lba %d\n", cmd->io.lba); - for (i = 0; (i < TWE_MAX_SGL_LENGTH) && (cmd->io.sgl[i].length != 0); i++) - twe_printf(sc, " %d: 0x%x/%d\n", - i, cmd->io.sgl[i].address, cmd->io.sgl[i].length); - break; - - case TWE_OP_GET_PARAM: - case TWE_OP_SET_PARAM: - for (i = 0; (i < TWE_MAX_SGL_LENGTH) && (cmd->param.sgl[i].length != 0); i++) - twe_printf(sc, " %d: 0x%x/%d\n", - i, cmd->param.sgl[i].address, cmd->param.sgl[i].length); - break; - - case TWE_OP_INIT_CONNECTION: - twe_printf(sc, " response queue pointer 0x%x\n", - cmd->initconnection.response_queue_pointer); - break; - - default: - break; - } - twe_printf(sc, " tr_command %p/0x%x tr_data %p/0x%x,%d\n", - tr, TWE_FIND_COMMANDPHYS(tr), tr->tr_data, tr->tr_dataphys, tr->tr_length); - twe_printf(sc, " tr_status %d tr_flags 0x%x tr_complete %p tr_private %p\n", - tr->tr_status, tr->tr_flags, tr->tr_complete, tr->tr_private); -} - -#endif diff --git a/sys/dev/twe/twe_compat.h b/sys/dev/twe/twe_compat.h deleted file mode 100644 index 51d021657012..000000000000 --- a/sys/dev/twe/twe_compat.h +++ /dev/null @@ -1,127 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2000 Michael Smith - * Copyright (c) 2003 Paul Saab - * Copyright (c) 2003 Vinod Kashyap - * Copyright (c) 2000 BSDi - * 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. - * - * $FreeBSD$ - */ -/* - * Portability and compatibility interfaces. - */ - -#ifdef __FreeBSD__ -/****************************************************************************** - * FreeBSD - */ -#define TWE_SUPPORTED_PLATFORM - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include - -#define TWE_DRIVER_NAME twe -#define TWED_DRIVER_NAME twed -#define TWE_MALLOC_CLASS M_TWE - -/* - * Wrappers for bus-space actions - */ -#define TWE_CONTROL(sc, val) bus_write_4((sc)->twe_io, 0x0, (u_int32_t)val) -#define TWE_STATUS(sc) (u_int32_t)bus_read_4((sc)->twe_io, 0x4) -#define TWE_COMMAND_QUEUE(sc, val) bus_write_4((sc)->twe_io, 0x8, (u_int32_t)val) -#define TWE_RESPONSE_QUEUE(sc) (TWE_Response_Queue)bus_read_4((sc)->twe_io, 0xc) - -/* - * FreeBSD-specific softc elements - */ -#define TWE_PLATFORM_SOFTC \ - bus_dmamap_t twe_cmdmap; /* DMA map for command */ \ - u_int32_t twe_cmdphys; /* address of command in controller space */ \ - device_t twe_dev; /* bus device */ \ - struct cdev *twe_dev_t; /* control device */ \ - struct resource *twe_io; /* register interface window */ \ - bus_dma_tag_t twe_parent_dmat; /* parent DMA tag */ \ - bus_dma_tag_t twe_buffer_dmat; /* data buffer DMA tag */ \ - bus_dma_tag_t twe_cmd_dmat; /* command buffer DMA tag */ \ - bus_dma_tag_t twe_immediate_dmat; /* command buffer DMA tag */ \ - struct resource *twe_irq; /* interrupt */ \ - void *twe_intr; /* interrupt handle */ \ - struct intr_config_hook twe_ich; /* delayed-startup hook */ \ - void *twe_cmd; /* command structures */ \ - void *twe_immediate; /* immediate commands */ \ - bus_dmamap_t twe_immediate_map; \ - struct mtx twe_io_lock; \ - struct sx twe_config_lock; - -/* - * FreeBSD-specific request elements - */ -#define TWE_PLATFORM_REQUEST \ - bus_dmamap_t tr_dmamap; /* DMA map for data */ \ - u_int32_t tr_dataphys; /* data buffer base address in controller space */ - -/* - * Output identifying the controller/disk - */ -#define twe_printf(sc, fmt, args...) device_printf(sc->twe_dev, fmt , ##args) -#define twed_printf(twed, fmt, args...) device_printf(twed->twed_dev, fmt , ##args) - -#define TWE_IO_LOCK(sc) mtx_lock(&(sc)->twe_io_lock) -#define TWE_IO_UNLOCK(sc) mtx_unlock(&(sc)->twe_io_lock) -#define TWE_IO_ASSERT_LOCKED(sc) mtx_assert(&(sc)->twe_io_lock, MA_OWNED) -#define TWE_CONFIG_LOCK(sc) sx_xlock(&(sc)->twe_config_lock) -#define TWE_CONFIG_UNLOCK(sc) sx_xunlock(&(sc)->twe_config_lock) -#define TWE_CONFIG_ASSERT_LOCKED(sc) sx_assert(&(sc)->twe_config_lock, SA_XLOCKED) - -#endif /* FreeBSD */ - -#ifndef TWE_SUPPORTED_PLATFORM -#error platform not supported -#endif diff --git a/sys/dev/twe/twe_freebsd.c b/sys/dev/twe/twe_freebsd.c deleted file mode 100644 index 89a3940a8aad..000000000000 --- a/sys/dev/twe/twe_freebsd.c +++ /dev/null @@ -1,1170 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2000 Michael Smith - * Copyright (c) 2003 Paul Saab - * Copyright (c) 2003 Vinod Kashyap - * Copyright (c) 2000 BSDi - * 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. - */ - -#include -__FBSDID("$FreeBSD$"); - -/* - * FreeBSD-specific code. - */ - -#include -#include -#include -#include -#include - -#include - -#ifdef TWE_DEBUG -static u_int32_t twed_bio_in; -#define TWED_BIO_IN twed_bio_in++ -static u_int32_t twed_bio_out; -#define TWED_BIO_OUT twed_bio_out++ -#else -#define TWED_BIO_IN -#define TWED_BIO_OUT -#endif - -static void twe_setup_data_dmamap(void *arg, bus_dma_segment_t *segs, int nsegments, int error); -static void twe_setup_request_dmamap(void *arg, bus_dma_segment_t *segs, int nsegments, int error); - -/******************************************************************************** - ******************************************************************************** - Control device interface - ******************************************************************************** - ********************************************************************************/ - -static d_open_t twe_open; -static d_close_t twe_close; -static d_ioctl_t twe_ioctl_wrapper; - -static struct cdevsw twe_cdevsw = { - .d_version = D_VERSION, - .d_open = twe_open, - .d_close = twe_close, - .d_ioctl = twe_ioctl_wrapper, - .d_name = "twe", -}; - -/******************************************************************************** - * Accept an open operation on the control device. - */ -static int -twe_open(struct cdev *dev, int flags, int fmt, struct thread *td) -{ - struct twe_softc *sc = (struct twe_softc *)dev->si_drv1; - - TWE_IO_LOCK(sc); - if (sc->twe_state & TWE_STATE_DETACHING) { - TWE_IO_UNLOCK(sc); - return (ENXIO); - } - sc->twe_state |= TWE_STATE_OPEN; - TWE_IO_UNLOCK(sc); - return(0); -} - -/******************************************************************************** - * Accept the last close on the control device. - */ -static int -twe_close(struct cdev *dev, int flags, int fmt, struct thread *td) -{ - struct twe_softc *sc = (struct twe_softc *)dev->si_drv1; - - TWE_IO_LOCK(sc); - sc->twe_state &= ~TWE_STATE_OPEN; - TWE_IO_UNLOCK(sc); - return (0); -} - -/******************************************************************************** - * Handle controller-specific control operations. - */ -static int -twe_ioctl_wrapper(struct cdev *dev, u_long cmd, caddr_t addr, int32_t flag, struct thread *td) -{ - struct twe_softc *sc = (struct twe_softc *)dev->si_drv1; - - return(twe_ioctl(sc, cmd, addr)); -} - -/******************************************************************************** - ******************************************************************************** - PCI device interface - ******************************************************************************** - ********************************************************************************/ - -static int twe_probe(device_t dev); -static int twe_attach(device_t dev); -static void twe_free(struct twe_softc *sc); -static int twe_detach(device_t dev); -static int twe_shutdown(device_t dev); -static int twe_suspend(device_t dev); -static int twe_resume(device_t dev); -static void twe_pci_intr(void *arg); -static void twe_intrhook(void *arg); - -static device_method_t twe_methods[] = { - /* Device interface */ - DEVMETHOD(device_probe, twe_probe), - DEVMETHOD(device_attach, twe_attach), - DEVMETHOD(device_detach, twe_detach), - DEVMETHOD(device_shutdown, twe_shutdown), - DEVMETHOD(device_suspend, twe_suspend), - DEVMETHOD(device_resume, twe_resume), - - DEVMETHOD_END -}; - -static driver_t twe_pci_driver = { - "twe", - twe_methods, - sizeof(struct twe_softc) -}; - -DRIVER_MODULE(twe, pci, twe_pci_driver, 0, 0); - -/******************************************************************************** - * Match a 3ware Escalade ATA RAID controller. - */ -static int -twe_probe(device_t dev) -{ - - debug_called(4); - - if ((pci_get_vendor(dev) == TWE_VENDOR_ID) && - ((pci_get_device(dev) == TWE_DEVICE_ID) || - (pci_get_device(dev) == TWE_DEVICE_ID_ASIC))) { - device_set_desc_copy(dev, TWE_DEVICE_NAME ". Driver version " TWE_DRIVER_VERSION_STRING); - return(BUS_PROBE_DEFAULT); - } - return(ENXIO); -} - -/******************************************************************************** - * Allocate resources, initialise the controller. - */ -static int -twe_attach(device_t dev) -{ - struct twe_softc *sc; - struct sysctl_oid *sysctl_tree; - int rid, error; - - debug_called(4); - - /* - * Initialise the softc structure. - */ - sc = device_get_softc(dev); - sc->twe_dev = dev; - mtx_init(&sc->twe_io_lock, "twe I/O", NULL, MTX_DEF); - sx_init(&sc->twe_config_lock, "twe config"); - - /* - * XXX: This sysctl tree must stay at hw.tweX rather than using - * the device_get_sysctl_tree() created by new-bus because - * existing 3rd party binary tools such as tw_cli and 3dm2 use the - * existence of this sysctl node to discover controllers. - */ - sysctl_tree = SYSCTL_ADD_NODE(device_get_sysctl_ctx(dev), - SYSCTL_STATIC_CHILDREN(_hw), OID_AUTO, - device_get_nameunit(dev), CTLFLAG_RD | CTLFLAG_MPSAFE, 0, ""); - if (sysctl_tree == NULL) { - twe_printf(sc, "cannot add sysctl tree node\n"); - return (ENXIO); - } - SYSCTL_ADD_STRING(device_get_sysctl_ctx(dev), SYSCTL_CHILDREN(sysctl_tree), - OID_AUTO, "driver_version", CTLFLAG_RD, TWE_DRIVER_VERSION_STRING, 0, - "TWE driver version"); - - /* - * Force the busmaster enable bit on, in case the BIOS forgot. - */ - pci_enable_busmaster(dev); - - /* - * Allocate the PCI register window. - */ - rid = TWE_IO_CONFIG_REG; - if ((sc->twe_io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, - RF_ACTIVE)) == NULL) { - twe_printf(sc, "can't allocate register window\n"); - twe_free(sc); - return(ENXIO); - } - - /* - * Allocate the parent bus DMA tag appropriate for PCI. - */ - if (bus_dma_tag_create(bus_get_dma_tag(dev), /* PCI parent */ - 1, 0, /* alignment, boundary */ - BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ - BUS_SPACE_MAXADDR, /* highaddr */ - NULL, NULL, /* filter, filterarg */ - BUS_SPACE_MAXSIZE_32BIT, /* maxsize */ - BUS_SPACE_UNRESTRICTED, /* nsegments */ - BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ - 0, /* flags */ - NULL, /* lockfunc */ - NULL, /* lockarg */ - &sc->twe_parent_dmat)) { - twe_printf(sc, "can't allocate parent DMA tag\n"); - twe_free(sc); - return(ENOMEM); - } - - /* - * Allocate and connect our interrupt. - */ - rid = 0; - if ((sc->twe_irq = bus_alloc_resource_any(sc->twe_dev, SYS_RES_IRQ, - &rid, RF_SHAREABLE | RF_ACTIVE)) == NULL) { - twe_printf(sc, "can't allocate interrupt\n"); - twe_free(sc); - return(ENXIO); - } - if (bus_setup_intr(sc->twe_dev, sc->twe_irq, INTR_TYPE_BIO | INTR_ENTROPY | INTR_MPSAFE, - NULL, twe_pci_intr, sc, &sc->twe_intr)) { - twe_printf(sc, "can't set up interrupt\n"); - twe_free(sc); - return(ENXIO); - } - - /* - * Create DMA tag for mapping command's into controller-addressable space. - */ - if (bus_dma_tag_create(sc->twe_parent_dmat, /* parent */ - 1, 0, /* alignment, boundary */ - BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ - BUS_SPACE_MAXADDR, /* highaddr */ - NULL, NULL, /* filter, filterarg */ - sizeof(TWE_Command) * - TWE_Q_LENGTH, 1, /* maxsize, nsegments */ - BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ - 0, /* flags */ - NULL, /* lockfunc */ - NULL, /* lockarg */ - &sc->twe_cmd_dmat)) { - twe_printf(sc, "can't allocate data buffer DMA tag\n"); - twe_free(sc); - return(ENOMEM); - } - /* - * Allocate memory and make it available for DMA. - */ - if (bus_dmamem_alloc(sc->twe_cmd_dmat, (void **)&sc->twe_cmd, - BUS_DMA_NOWAIT, &sc->twe_cmdmap)) { - twe_printf(sc, "can't allocate command memory\n"); - return(ENOMEM); - } - bus_dmamap_load(sc->twe_cmd_dmat, sc->twe_cmdmap, sc->twe_cmd, - sizeof(TWE_Command) * TWE_Q_LENGTH, - twe_setup_request_dmamap, sc, 0); - bzero(sc->twe_cmd, sizeof(TWE_Command) * TWE_Q_LENGTH); - - /* - * Create DMA tag for mapping objects into controller-addressable space. - */ - if (bus_dma_tag_create(sc->twe_parent_dmat, /* parent */ - 1, 0, /* alignment, boundary */ - BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ - BUS_SPACE_MAXADDR, /* highaddr */ - NULL, NULL, /* filter, filterarg */ - (TWE_MAX_SGL_LENGTH - 1) * PAGE_SIZE,/* maxsize */ - TWE_MAX_SGL_LENGTH, /* nsegments */ - BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ - BUS_DMA_ALLOCNOW, /* flags */ - busdma_lock_mutex, /* lockfunc */ - &sc->twe_io_lock, /* lockarg */ - &sc->twe_buffer_dmat)) { - twe_printf(sc, "can't allocate data buffer DMA tag\n"); - twe_free(sc); - return(ENOMEM); - } - - /* - * Create DMA tag for mapping objects into controller-addressable space. - */ - if (bus_dma_tag_create(sc->twe_parent_dmat, /* parent */ - 1, 0, /* alignment, boundary */ - BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ - BUS_SPACE_MAXADDR, /* highaddr */ - NULL, NULL, /* filter, filterarg */ - DFLTPHYS, 1, /* maxsize, nsegments */ - BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ - 0, /* flags */ - NULL, /* lockfunc */ - NULL, /* lockarg */ - &sc->twe_immediate_dmat)) { - twe_printf(sc, "can't allocate data buffer DMA tag\n"); - twe_free(sc); - return(ENOMEM); - } - /* - * Allocate memory for requests which cannot sleep or support continuation. - */ - if (bus_dmamem_alloc(sc->twe_immediate_dmat, (void **)&sc->twe_immediate, - BUS_DMA_NOWAIT, &sc->twe_immediate_map)) { - twe_printf(sc, "can't allocate memory for immediate requests\n"); - return(ENOMEM); - } - - /* - * Initialise the controller and driver core. - */ - if ((error = twe_setup(sc))) { - twe_free(sc); - return(error); - } - - /* - * Print some information about the controller and configuration. - */ - twe_describe_controller(sc); - - /* - * Create the control device. - */ - sc->twe_dev_t = make_dev(&twe_cdevsw, device_get_unit(sc->twe_dev), UID_ROOT, GID_OPERATOR, - S_IRUSR | S_IWUSR, "twe%d", device_get_unit(sc->twe_dev)); - sc->twe_dev_t->si_drv1 = sc; - /* - * Schedule ourselves to bring the controller up once interrupts are available. - * This isn't strictly necessary, since we disable interrupts while probing the - * controller, but it is more in keeping with common practice for other disk - * devices. - */ - sc->twe_ich.ich_func = twe_intrhook; - sc->twe_ich.ich_arg = sc; - if (config_intrhook_establish(&sc->twe_ich) != 0) { - twe_printf(sc, "can't establish configuration hook\n"); - twe_free(sc); - return(ENXIO); - } - - return(0); -} - -/******************************************************************************** - * Free all of the resources associated with (sc). - * - * Should not be called if the controller is active. - */ -static void -twe_free(struct twe_softc *sc) -{ - struct twe_request *tr; - - debug_called(4); - - /* throw away any command buffers */ - while ((tr = twe_dequeue_free(sc)) != NULL) - twe_free_request(tr); - - if (sc->twe_cmd != NULL) { - bus_dmamap_unload(sc->twe_cmd_dmat, sc->twe_cmdmap); - bus_dmamem_free(sc->twe_cmd_dmat, sc->twe_cmd, sc->twe_cmdmap); - } - - if (sc->twe_immediate != NULL) { - bus_dmamap_unload(sc->twe_immediate_dmat, sc->twe_immediate_map); - bus_dmamem_free(sc->twe_immediate_dmat, sc->twe_immediate, - sc->twe_immediate_map); - } - - if (sc->twe_immediate_dmat) - bus_dma_tag_destroy(sc->twe_immediate_dmat); - - /* destroy the data-transfer DMA tag */ - if (sc->twe_buffer_dmat) - bus_dma_tag_destroy(sc->twe_buffer_dmat); - - /* disconnect the interrupt handler */ - if (sc->twe_intr) - bus_teardown_intr(sc->twe_dev, sc->twe_irq, sc->twe_intr); - if (sc->twe_irq != NULL) - bus_release_resource(sc->twe_dev, SYS_RES_IRQ, 0, sc->twe_irq); - - /* destroy the parent DMA tag */ - if (sc->twe_parent_dmat) - bus_dma_tag_destroy(sc->twe_parent_dmat); - - /* release the register window mapping */ - if (sc->twe_io != NULL) - bus_release_resource(sc->twe_dev, SYS_RES_IOPORT, TWE_IO_CONFIG_REG, sc->twe_io); - - /* destroy control device */ - if (sc->twe_dev_t != (struct cdev *)NULL) - destroy_dev(sc->twe_dev_t); - - sx_destroy(&sc->twe_config_lock); - mtx_destroy(&sc->twe_io_lock); -} - -/******************************************************************************** - * Disconnect from the controller completely, in preparation for unload. - */ -static int -twe_detach(device_t dev) -{ - struct twe_softc *sc = device_get_softc(dev); - - debug_called(4); - - TWE_IO_LOCK(sc); - if (sc->twe_state & TWE_STATE_OPEN) { - TWE_IO_UNLOCK(sc); - return (EBUSY); - } - sc->twe_state |= TWE_STATE_DETACHING; - TWE_IO_UNLOCK(sc); - - /* - * Shut the controller down. - */ - if (twe_shutdown(dev)) { - TWE_IO_LOCK(sc); - sc->twe_state &= ~TWE_STATE_DETACHING; - TWE_IO_UNLOCK(sc); - return (EBUSY); - } - - twe_free(sc); - - return(0); -} - -/******************************************************************************** - * Bring the controller down to a dormant state and detach all child devices. - * - * Note that we can assume that the bioq on the controller is empty, as we won't - * allow shutdown if any device is open. - */ -static int -twe_shutdown(device_t dev) -{ - struct twe_softc *sc = device_get_softc(dev); - int i, error = 0; - - debug_called(4); - - /* - * Delete all our child devices. - */ - TWE_CONFIG_LOCK(sc); - for (i = 0; i < TWE_MAX_UNITS; i++) { - if (sc->twe_drive[i].td_disk != 0) { - if ((error = twe_detach_drive(sc, i)) != 0) { - TWE_CONFIG_UNLOCK(sc); - return (error); - } - } - } - TWE_CONFIG_UNLOCK(sc); - - /* - * Bring the controller down. - */ - TWE_IO_LOCK(sc); - twe_deinit(sc); - TWE_IO_UNLOCK(sc); - - return(0); -} - -/******************************************************************************** - * Bring the controller to a quiescent state, ready for system suspend. - */ -static int -twe_suspend(device_t dev) -{ - struct twe_softc *sc = device_get_softc(dev); - - debug_called(4); - - TWE_IO_LOCK(sc); - sc->twe_state |= TWE_STATE_SUSPEND; - - twe_disable_interrupts(sc); - TWE_IO_UNLOCK(sc); - - return(0); -} - -/******************************************************************************** - * Bring the controller back to a state ready for operation. - */ -static int -twe_resume(device_t dev) -{ - struct twe_softc *sc = device_get_softc(dev); - - debug_called(4); - - TWE_IO_LOCK(sc); - sc->twe_state &= ~TWE_STATE_SUSPEND; - twe_enable_interrupts(sc); - TWE_IO_UNLOCK(sc); - - return(0); -} - -/******************************************************************************* - * Take an interrupt, or be poked by other code to look for interrupt-worthy - * status. - */ -static void -twe_pci_intr(void *arg) -{ - struct twe_softc *sc = arg; - - TWE_IO_LOCK(sc); - twe_intr(sc); - TWE_IO_UNLOCK(sc); -} - -/******************************************************************************** - * Delayed-startup hook - */ -static void -twe_intrhook(void *arg) -{ - struct twe_softc *sc = (struct twe_softc *)arg; - - /* pull ourselves off the intrhook chain */ - config_intrhook_disestablish(&sc->twe_ich); - - /* call core startup routine */ - twe_init(sc); -} - -/******************************************************************************** - * Given a detected drive, attach it to the bio interface. - * - * This is called from twe_add_unit. - */ -int -twe_attach_drive(struct twe_softc *sc, struct twe_drive *dr) -{ - char buf[80]; - int error; - - bus_topo_lock(); - dr->td_disk = device_add_child(sc->twe_dev, NULL, -1); - if (dr->td_disk == NULL) { - bus_topo_unlock(); - twe_printf(sc, "Cannot add unit\n"); - return (EIO); - } - device_set_ivars(dr->td_disk, dr); - - /* - * XXX It would make sense to test the online/initialising bits, but they seem to be - * always set... - */ - sprintf(buf, "Unit %d, %s, %s", - dr->td_twe_unit, - twe_describe_code(twe_table_unittype, dr->td_type), - twe_describe_code(twe_table_unitstate, dr->td_state & TWE_PARAM_UNITSTATUS_MASK)); - device_set_desc_copy(dr->td_disk, buf); - - error = device_probe_and_attach(dr->td_disk); - bus_topo_unlock(); - if (error != 0) { - twe_printf(sc, "Cannot attach unit to controller. error = %d\n", error); - return (EIO); - } - return (0); -} - -/******************************************************************************** - * Detach the specified unit if it exsists - * - * This is called from twe_del_unit. - */ -int -twe_detach_drive(struct twe_softc *sc, int unit) -{ - int error = 0; - - TWE_CONFIG_ASSERT_LOCKED(sc); - bus_topo_lock(); - error = device_delete_child(sc->twe_dev, sc->twe_drive[unit].td_disk); - bus_topo_unlock(); - if (error != 0) { - twe_printf(sc, "failed to delete unit %d\n", unit); - return(error); - } - bzero(&sc->twe_drive[unit], sizeof(sc->twe_drive[unit])); - return(error); -} - -/******************************************************************************** - * Clear a PCI parity error. - */ -void -twe_clear_pci_parity_error(struct twe_softc *sc) -{ - TWE_CONTROL(sc, TWE_CONTROL_CLEAR_PARITY_ERROR); - pci_write_config(sc->twe_dev, PCIR_STATUS, TWE_PCI_CLEAR_PARITY_ERROR, 2); -} - -/******************************************************************************** - * Clear a PCI abort. - */ -void -twe_clear_pci_abort(struct twe_softc *sc) -{ - TWE_CONTROL(sc, TWE_CONTROL_CLEAR_PCI_ABORT); - pci_write_config(sc->twe_dev, PCIR_STATUS, TWE_PCI_CLEAR_PCI_ABORT, 2); -} - -/******************************************************************************** - ******************************************************************************** - Disk device - ******************************************************************************** - ********************************************************************************/ - -/* - * Disk device softc - */ -struct twed_softc -{ - device_t twed_dev; - struct twe_softc *twed_controller; /* parent device softc */ - struct twe_drive *twed_drive; /* drive data in parent softc */ - struct disk *twed_disk; /* generic disk handle */ -}; - -/* - * Disk device bus interface - */ -static int twed_probe(device_t dev); -static int twed_attach(device_t dev); -static int twed_detach(device_t dev); - -static device_method_t twed_methods[] = { - DEVMETHOD(device_probe, twed_probe), - DEVMETHOD(device_attach, twed_attach), - DEVMETHOD(device_detach, twed_detach), - { 0, 0 } -}; - -static driver_t twed_driver = { - "twed", - twed_methods, - sizeof(struct twed_softc) -}; - -DRIVER_MODULE(twed, twe, twed_driver, 0, 0); - -/* - * Disk device control interface. - */ - -/******************************************************************************** - * Handle open from generic layer. - * - * Note that this is typically only called by the diskslice code, and not - * for opens on subdevices (eg. slices, partitions). - */ -static int -twed_open(struct disk *dp) -{ - struct twed_softc *sc = (struct twed_softc *)dp->d_drv1; - - debug_called(4); - - if (sc == NULL) - return (ENXIO); - - /* check that the controller is up and running */ - if (sc->twed_controller->twe_state & TWE_STATE_SHUTDOWN) - return(ENXIO); - - return (0); -} - -/******************************************************************************** - * Handle an I/O request. - */ -static void -twed_strategy(struct bio *bp) -{ - struct twed_softc *sc = bp->bio_disk->d_drv1; - - debug_called(4); - - bp->bio_driver1 = &sc->twed_drive->td_twe_unit; - TWED_BIO_IN; - - /* bogus disk? */ - if (sc == NULL || sc->twed_drive->td_disk == NULL) { - bp->bio_error = EINVAL; - bp->bio_flags |= BIO_ERROR; - printf("twe: bio for invalid disk!\n"); - biodone(bp); - TWED_BIO_OUT; - return; - } - - /* queue the bio on the controller */ - TWE_IO_LOCK(sc->twed_controller); - twe_enqueue_bio(sc->twed_controller, bp); - - /* poke the controller to start I/O */ - twe_startio(sc->twed_controller); - TWE_IO_UNLOCK(sc->twed_controller); - return; -} - -/******************************************************************************** - * System crashdump support - */ -static int -twed_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length) -{ - struct twed_softc *twed_sc; - struct twe_softc *twe_sc; - int error; - struct disk *dp; - - dp = arg; - twed_sc = (struct twed_softc *)dp->d_drv1; - if (twed_sc == NULL) - return(ENXIO); - twe_sc = (struct twe_softc *)twed_sc->twed_controller; - - if (length > 0) { - if ((error = twe_dump_blocks(twe_sc, twed_sc->twed_drive->td_twe_unit, offset / TWE_BLOCK_SIZE, virtual, length / TWE_BLOCK_SIZE)) != 0) - return(error); - } - return(0); -} - -/******************************************************************************** - * Handle completion of an I/O request. - */ -void -twed_intr(struct bio *bp) -{ - debug_called(4); - - /* if no error, transfer completed */ - if (!(bp->bio_flags & BIO_ERROR)) - bp->bio_resid = 0; - - biodone(bp); - TWED_BIO_OUT; -} - -/******************************************************************************** - * Default probe stub. - */ -static int -twed_probe(device_t dev) -{ - return (0); -} - -/******************************************************************************** - * Attach a unit to the controller. - */ -static int -twed_attach(device_t dev) -{ - struct twed_softc *sc; - device_t parent; - - debug_called(4); - - /* initialise our softc */ - sc = device_get_softc(dev); - parent = device_get_parent(dev); - sc->twed_controller = (struct twe_softc *)device_get_softc(parent); - sc->twed_drive = device_get_ivars(dev); - sc->twed_dev = dev; - - /* report the drive */ - twed_printf(sc, "%uMB (%u sectors)\n", - sc->twed_drive->td_size / ((1024 * 1024) / TWE_BLOCK_SIZE), - sc->twed_drive->td_size); - - /* attach a generic disk device to ourselves */ - - sc->twed_drive->td_sys_unit = device_get_unit(dev); - - sc->twed_disk = disk_alloc(); - sc->twed_disk->d_open = twed_open; - sc->twed_disk->d_strategy = twed_strategy; - sc->twed_disk->d_dump = (dumper_t *)twed_dump; - sc->twed_disk->d_name = "twed"; - sc->twed_disk->d_drv1 = sc; - sc->twed_disk->d_maxsize = (TWE_MAX_SGL_LENGTH - 1) * PAGE_SIZE; - sc->twed_disk->d_sectorsize = TWE_BLOCK_SIZE; - sc->twed_disk->d_mediasize = TWE_BLOCK_SIZE * (off_t)sc->twed_drive->td_size; - if (sc->twed_drive->td_type == TWE_UD_CONFIG_RAID0 || - sc->twed_drive->td_type == TWE_UD_CONFIG_RAID5 || - sc->twed_drive->td_type == TWE_UD_CONFIG_RAID10) { - sc->twed_disk->d_stripesize = - TWE_BLOCK_SIZE << sc->twed_drive->td_stripe; - sc->twed_disk->d_stripeoffset = 0; - } - sc->twed_disk->d_fwsectors = sc->twed_drive->td_sectors; - sc->twed_disk->d_fwheads = sc->twed_drive->td_heads; - sc->twed_disk->d_unit = sc->twed_drive->td_sys_unit; - - disk_create(sc->twed_disk, DISK_VERSION); - - /* set the maximum I/O size to the theoretical maximum allowed by the S/G list size */ - - return (0); -} - -/******************************************************************************** - * Disconnect ourselves from the system. - */ -static int -twed_detach(device_t dev) -{ - struct twed_softc *sc = (struct twed_softc *)device_get_softc(dev); - - debug_called(4); - - if (sc->twed_disk->d_flags & DISKFLAG_OPEN) - return(EBUSY); - - disk_destroy(sc->twed_disk); - - return(0); -} - -/******************************************************************************** - ******************************************************************************** - Misc - ******************************************************************************** - ********************************************************************************/ - -/******************************************************************************** - * Allocate a command buffer - */ -static MALLOC_DEFINE(TWE_MALLOC_CLASS, "twe_commands", "twe commands"); - -struct twe_request * -twe_allocate_request(struct twe_softc *sc, int tag) -{ - struct twe_request *tr; - - tr = malloc(sizeof(struct twe_request), TWE_MALLOC_CLASS, M_WAITOK | M_ZERO); - tr->tr_sc = sc; - tr->tr_tag = tag; - if (bus_dmamap_create(sc->twe_buffer_dmat, 0, &tr->tr_dmamap)) { - twe_free_request(tr); - twe_printf(sc, "unable to allocate dmamap for tag %d\n", tag); - return(NULL); - } - return(tr); -} - -/******************************************************************************** - * Permanently discard a command buffer. - */ -void -twe_free_request(struct twe_request *tr) -{ - struct twe_softc *sc = tr->tr_sc; - - debug_called(4); - - bus_dmamap_destroy(sc->twe_buffer_dmat, tr->tr_dmamap); - free(tr, TWE_MALLOC_CLASS); -} - -/******************************************************************************** - * Map/unmap (tr)'s command and data in the controller's addressable space. - * - * These routines ensure that the data which the controller is going to try to - * access is actually visible to the controller, in a machine-independent - * fashion. Due to a hardware limitation, I/O buffers must be 512-byte aligned - * and we take care of that here as well. - */ -static void -twe_fillin_sgl(TWE_SG_Entry *sgl, bus_dma_segment_t *segs, int nsegments, int max_sgl) -{ - int i; - - for (i = 0; i < nsegments; i++) { - sgl[i].address = segs[i].ds_addr; - sgl[i].length = segs[i].ds_len; - } - for (; i < max_sgl; i++) { /* XXX necessary? */ - sgl[i].address = 0; - sgl[i].length = 0; - } -} - -static void -twe_setup_data_dmamap(void *arg, bus_dma_segment_t *segs, int nsegments, int error) -{ - struct twe_request *tr = (struct twe_request *)arg; - struct twe_softc *sc = tr->tr_sc; - TWE_Command *cmd = TWE_FIND_COMMAND(tr); - - debug_called(4); - - if (tr->tr_flags & TWE_CMD_MAPPED) - panic("already mapped command"); - - tr->tr_flags |= TWE_CMD_MAPPED; - - if (tr->tr_flags & TWE_CMD_IN_PROGRESS) - sc->twe_state &= ~TWE_STATE_FRZN; - /* save base of first segment in command (applicable if there only one segment) */ - tr->tr_dataphys = segs[0].ds_addr; - - /* correct command size for s/g list size */ - cmd->generic.size += 2 * nsegments; - - /* - * Due to the fact that parameter and I/O commands have the scatter/gather list in - * different places, we need to determine which sort of command this actually is - * before we can populate it correctly. - */ - switch(cmd->generic.opcode) { - case TWE_OP_GET_PARAM: - case TWE_OP_SET_PARAM: - cmd->generic.sgl_offset = 2; - twe_fillin_sgl(&cmd->param.sgl[0], segs, nsegments, TWE_MAX_SGL_LENGTH); - break; - case TWE_OP_READ: - case TWE_OP_WRITE: - cmd->generic.sgl_offset = 3; - twe_fillin_sgl(&cmd->io.sgl[0], segs, nsegments, TWE_MAX_SGL_LENGTH); - break; - case TWE_OP_ATA_PASSTHROUGH: - cmd->generic.sgl_offset = 5; - twe_fillin_sgl(&cmd->ata.sgl[0], segs, nsegments, TWE_MAX_ATA_SGL_LENGTH); - break; - default: - /* - * Fall back to what the linux driver does. - * Do this because the API may send an opcode - * the driver knows nothing about and this will - * at least stop PCIABRT's from hosing us. - */ - switch (cmd->generic.sgl_offset) { - case 2: - twe_fillin_sgl(&cmd->param.sgl[0], segs, nsegments, TWE_MAX_SGL_LENGTH); - break; - case 3: - twe_fillin_sgl(&cmd->io.sgl[0], segs, nsegments, TWE_MAX_SGL_LENGTH); - break; - case 5: - twe_fillin_sgl(&cmd->ata.sgl[0], segs, nsegments, TWE_MAX_ATA_SGL_LENGTH); - break; - } - } - - if (tr->tr_flags & TWE_CMD_DATAIN) { - if (tr->tr_flags & TWE_CMD_IMMEDIATE) { - bus_dmamap_sync(sc->twe_immediate_dmat, sc->twe_immediate_map, - BUS_DMASYNC_PREREAD); - } else { - bus_dmamap_sync(sc->twe_buffer_dmat, tr->tr_dmamap, - BUS_DMASYNC_PREREAD); - } - } - - if (tr->tr_flags & TWE_CMD_DATAOUT) { - /* - * if we're using an alignment buffer, and we're writing data - * copy the real data out - */ - if (tr->tr_flags & TWE_CMD_ALIGNBUF) - bcopy(tr->tr_realdata, tr->tr_data, tr->tr_length); - - if (tr->tr_flags & TWE_CMD_IMMEDIATE) { - bus_dmamap_sync(sc->twe_immediate_dmat, sc->twe_immediate_map, - BUS_DMASYNC_PREWRITE); - } else { - bus_dmamap_sync(sc->twe_buffer_dmat, tr->tr_dmamap, - BUS_DMASYNC_PREWRITE); - } - } - - if (twe_start(tr) == EBUSY) { - tr->tr_sc->twe_state |= TWE_STATE_CTLR_BUSY; - twe_requeue_ready(tr); - } -} - -static void -twe_setup_request_dmamap(void *arg, bus_dma_segment_t *segs, int nsegments, int error) -{ - struct twe_softc *sc = (struct twe_softc *)arg; - - debug_called(4); - - /* command can't cross a page boundary */ - sc->twe_cmdphys = segs[0].ds_addr; -} - -int -twe_map_request(struct twe_request *tr) -{ - struct twe_softc *sc = tr->tr_sc; - int error = 0; - - debug_called(4); - - if (!dumping) - TWE_IO_ASSERT_LOCKED(sc); - if (sc->twe_state & (TWE_STATE_CTLR_BUSY | TWE_STATE_FRZN)) { - twe_requeue_ready(tr); - return (EBUSY); - } - - bus_dmamap_sync(sc->twe_cmd_dmat, sc->twe_cmdmap, BUS_DMASYNC_PREWRITE); - - /* - * If the command involves data, map that too. - */ - if (tr->tr_data != NULL && ((tr->tr_flags & TWE_CMD_MAPPED) == 0)) { - /* - * Data must be 64-byte aligned; allocate a fixup buffer if it's not. - */ - if (((vm_offset_t)tr->tr_data % TWE_ALIGNMENT) != 0) { - tr->tr_realdata = tr->tr_data; /* save pointer to 'real' data */ - tr->tr_flags |= TWE_CMD_ALIGNBUF; - tr->tr_data = malloc(tr->tr_length, TWE_MALLOC_CLASS, M_NOWAIT); - if (tr->tr_data == NULL) { - twe_printf(sc, "%s: malloc failed\n", __func__); - tr->tr_data = tr->tr_realdata; /* restore original data pointer */ - return(ENOMEM); - } - } - - /* - * Map the data buffer into bus space and build the s/g list. - */ - if (tr->tr_flags & TWE_CMD_IMMEDIATE) { - error = bus_dmamap_load(sc->twe_immediate_dmat, sc->twe_immediate_map, sc->twe_immediate, - tr->tr_length, twe_setup_data_dmamap, tr, BUS_DMA_NOWAIT); - } else { - error = bus_dmamap_load(sc->twe_buffer_dmat, tr->tr_dmamap, tr->tr_data, tr->tr_length, - twe_setup_data_dmamap, tr, 0); - } - if (error == EINPROGRESS) { - tr->tr_flags |= TWE_CMD_IN_PROGRESS; - sc->twe_state |= TWE_STATE_FRZN; - error = 0; - } - } else - if ((error = twe_start(tr)) == EBUSY) { - sc->twe_state |= TWE_STATE_CTLR_BUSY; - twe_requeue_ready(tr); - } - - return(error); -} - -void -twe_unmap_request(struct twe_request *tr) -{ - struct twe_softc *sc = tr->tr_sc; - - debug_called(4); - - if (!dumping) - TWE_IO_ASSERT_LOCKED(sc); - bus_dmamap_sync(sc->twe_cmd_dmat, sc->twe_cmdmap, BUS_DMASYNC_POSTWRITE); - - /* - * If the command involved data, unmap that too. - */ - if (tr->tr_data != NULL) { - if (tr->tr_flags & TWE_CMD_DATAIN) { - if (tr->tr_flags & TWE_CMD_IMMEDIATE) { - bus_dmamap_sync(sc->twe_immediate_dmat, sc->twe_immediate_map, - BUS_DMASYNC_POSTREAD); - } else { - bus_dmamap_sync(sc->twe_buffer_dmat, tr->tr_dmamap, - BUS_DMASYNC_POSTREAD); - } - - /* if we're using an alignment buffer, and we're reading data, copy the real data in */ - if (tr->tr_flags & TWE_CMD_ALIGNBUF) - bcopy(tr->tr_data, tr->tr_realdata, tr->tr_length); - } - if (tr->tr_flags & TWE_CMD_DATAOUT) { - if (tr->tr_flags & TWE_CMD_IMMEDIATE) { - bus_dmamap_sync(sc->twe_immediate_dmat, sc->twe_immediate_map, - BUS_DMASYNC_POSTWRITE); - } else { - bus_dmamap_sync(sc->twe_buffer_dmat, tr->tr_dmamap, - BUS_DMASYNC_POSTWRITE); - } - } - - if (tr->tr_flags & TWE_CMD_IMMEDIATE) { - bus_dmamap_unload(sc->twe_immediate_dmat, sc->twe_immediate_map); - } else { - bus_dmamap_unload(sc->twe_buffer_dmat, tr->tr_dmamap); - } - } - - /* free alignment buffer if it was used */ - if (tr->tr_flags & TWE_CMD_ALIGNBUF) { - free(tr->tr_data, TWE_MALLOC_CLASS); - tr->tr_data = tr->tr_realdata; /* restore 'real' data pointer */ - } -} - -#ifdef TWE_DEBUG -void twe_report(void); -/******************************************************************************** - * Print current controller status, call from DDB. - */ -void -twe_report(void) -{ - struct twe_softc *sc; - int i; - - for (i = 0; (sc = devclass_get_softc(devclass_find("twe"), i)) != NULL; i++) - twe_print_controller(sc); - printf("twed: total bio count in %u out %u\n", twed_bio_in, twed_bio_out); -} -#endif diff --git a/sys/dev/twe/twe_tables.h b/sys/dev/twe/twe_tables.h deleted file mode 100644 index 408dcebe717a..000000000000 --- a/sys/dev/twe/twe_tables.h +++ /dev/null @@ -1,169 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2000 Michael Smith - * Copyright (c) 2003 Paul Saab - * Copyright (c) 2003 Vinod Kashyap - * Copyright (c) 2000 BSDi - * 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. - * - * $FreeBSD$ - */ - -/* - * Lookup table for code-to-text translations. - */ -struct twe_code_lookup { - char *string; - u_int32_t code; -}; - -extern char *twe_describe_code(struct twe_code_lookup *table, u_int32_t code); - -#ifndef TWE_DEFINE_TABLES -extern struct twe_code_lookup twe_table_status[]; -extern struct twe_code_lookup twe_table_unitstate[]; -extern struct twe_code_lookup twe_table_unittype[]; -extern struct twe_code_lookup twe_table_aen[]; -extern struct twe_code_lookup twe_table_opcode[]; -#else /* TWE_DEFINE_TABLES */ - -struct twe_code_lookup twe_table_status[] = { - /* success */ - {"successful completion", 0x00}, - /* info */ - {"command in progress", 0x42}, - {"retrying interface CRC error from UDMA command", 0x6c}, - /* warning */ - {"redundant/inconsequential request ignored", 0x81}, - {"failed to write zeroes to LBA 0", 0x8e}, - {"failed to profile TwinStor zones", 0x8f}, - /* fatal */ - {"aborted due to system command or reconfiguration", 0xc1}, - {"aborted", 0xc4}, - {"access error", 0xc5}, - {"access violation", 0xc6}, - {"device failure", 0xc7}, /* high byte may be port number */ - {"controller error", 0xc8}, - {"timed out", 0xc9}, - {"invalid unit number", 0xcb}, - {"unit not available", 0xcf}, - {"undefined opcode", 0xd2}, - {"request incompatible with unit", 0xdb}, - {"invalid request", 0xdc}, - {"firmware error, reset requested", 0xff}, - {NULL, 0}, - {"unknown status", 0} -}; - -struct twe_code_lookup twe_table_unitstate[] = { - {"Normal", TWE_PARAM_UNITSTATUS_Normal}, - {"Initialising", TWE_PARAM_UNITSTATUS_Initialising}, - {"Degraded", TWE_PARAM_UNITSTATUS_Degraded}, - {"Rebuilding", TWE_PARAM_UNITSTATUS_Rebuilding}, - {"Verifying", TWE_PARAM_UNITSTATUS_Verifying}, - {"Corrupt", TWE_PARAM_UNITSTATUS_Corrupt}, - {"Missing", TWE_PARAM_UNITSTATUS_Missing}, - {NULL, 0}, - {"unknown state", 0} -}; - -struct twe_code_lookup twe_table_unittype[] = { - {"RAID0", TWE_UD_CONFIG_RAID0}, - {"RAID1", TWE_UD_CONFIG_RAID1}, - {"TwinStor", TWE_UD_CONFIG_TwinStor}, - {"RAID5", TWE_UD_CONFIG_RAID5}, - {"RAID10", TWE_UD_CONFIG_RAID10}, - {"CBOD", TWE_UD_CONFIG_CBOD}, - {"SPARE", TWE_UD_CONFIG_SPARE}, - {"SUBUNIT", TWE_UD_CONFIG_SUBUNIT}, - {"JBOD", TWE_UD_CONFIG_JBOD}, - {NULL, 0}, - {"unknown type", 0} -}; - -struct twe_code_lookup twe_table_aen[] = { - {"q queue empty", 0x00}, - {"q soft reset", 0x01}, - {"c degraded unit", 0x02}, - {"a controller error", 0x03}, - {"c rebuild fail", 0x04}, - {"c rebuild done", 0x05}, - {"c incomplete unit", 0x06}, - {"c initialisation done", 0x07}, - {"c unclean shutdown detected", 0x08}, - {"c drive timeout", 0x09}, - {"c drive error", 0x0a}, - {"c rebuild started", 0x0b}, - {"c init started", 0x0c}, - {"c logical unit deleted", 0x0d}, - {"p SMART threshold exceeded", 0x0f}, - {"p ATA UDMA downgrade", 0x21}, - {"p ATA UDMA upgrade", 0x22}, - {"p sector repair occurred", 0x23}, - {"a SBUF integrity check failure", 0x24}, - {"p lost cached write", 0x25}, - {"p drive ECC error detected", 0x26}, - {"p DCB checksum error", 0x27}, - {"p DCB unsupported version", 0x28}, - {"c verify started", 0x29}, - {"c verify failed", 0x2a}, - {"c verify complete", 0x2b}, - {"p overwrote bad sector during rebuild", 0x2c}, - {"p encountered bad sector during rebuild", 0x2d}, - {"a replacement drive too small", 0x2e}, - {"c array not previously initialized", 0x2f}, - {"p drive not supported", 0x30}, - {"a aen queue full", 0xff}, - {NULL, 0}, - {"x unknown AEN", 0} -}; - -struct twe_code_lookup twe_table_opcode[] = { - {"NOP", 0x00}, - {"INIT_CONNECTION", 0x01}, - {"READ", 0x02}, - {"WRITE", 0x03}, - {"READVERIFY", 0x04}, - {"VERIFY", 0x05}, - {"ZEROUNIT", 0x08}, - {"REPLACEUNIT", 0x09}, - {"HOTSWAP", 0x0a}, - {"SETATAFEATURE", 0x0c}, - {"FLUSH", 0x0e}, - {"ABORT", 0x0f}, - {"CHECKSTATUS", 0x10}, - {"GET_PARAM", 0x12}, - {"SET_PARAM", 0x13}, - {"CREATEUNIT", 0x14}, - {"DELETEUNIT", 0x15}, - {"REBUILDUNIT", 0x17}, - {"SECTOR_INFO", 0x1a}, - {"AEN_LISTEN", 0x1c}, - {"CMD_PACKET", 0x1d}, - {NULL, 0}, - {"unknown opcode", 0} -}; - -#endif diff --git a/sys/dev/twe/tweio.h b/sys/dev/twe/tweio.h deleted file mode 100644 index e2fa72932501..000000000000 --- a/sys/dev/twe/tweio.h +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2000 Michael Smith - * Copyright (c) 2003 Paul Saab - * Copyright (c) 2003 Vinod Kashyap - * Copyright (c) 2000 BSDi - * 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. - * - * $FreeBSD$ - */ - -/* - * User-space command - * - * Note that the command's scatter/gather list will be computed by the - * driver, and cannot be filled in by the consumer. - */ -struct twe_usercommand { - TWE_Command tu_command; /* command ready for the controller */ - void *tu_data; /* pointer to data in userspace */ - size_t tu_size; /* userspace data length */ -}; - -#define TWEIO_COMMAND _IOWR('T', 100, struct twe_usercommand) - -/* - * Command queue statistics - */ -#define TWEQ_FREE 0 -#define TWEQ_BIO 1 -#define TWEQ_READY 2 -#define TWEQ_BUSY 3 -#define TWEQ_COMPLETE 4 -#define TWEQ_COUNT 5 /* total number of queues */ - -struct twe_qstat { - u_int32_t q_length; - u_int32_t q_max; - u_int32_t q_min; -}; - -/* - * Statistics request - */ -union twe_statrequest { - u_int32_t ts_item; - struct twe_qstat ts_qstat; -}; - -#define TWEIO_STATS _IOWR('T', 101, union twe_statrequest) - -/* - * AEN listen - */ -#define TWEIO_AEN_POLL _IOR('T', 102, u_int16_t) -#define TWEIO_AEN_WAIT _IOR('T', 103, u_int16_t) - -/* - * Controller parameter access - */ -struct twe_paramcommand { - u_int16_t tp_table_id; - u_int8_t tp_param_id; - void *tp_data; - u_int8_t tp_size; -}; - -#define TWEIO_SET_PARAM _IOW ('T', 104, struct twe_paramcommand) -#define TWEIO_GET_PARAM _IOW ('T', 105, struct twe_paramcommand) - -/* - * Request a controller soft-reset - */ -#define TWEIO_RESET _IO ('T', 106) - -/* - * Request a drive addition or deletion - */ -struct twe_drivecommand { - int td_unit; -}; - -#define TWEIO_ADD_UNIT _IOW ('U', 107, int) -#define TWEIO_DEL_UNIT _IOW ('U', 108, int) diff --git a/sys/dev/twe/twereg.h b/sys/dev/twe/twereg.h deleted file mode 100644 index d07135f5a83e..000000000000 --- a/sys/dev/twe/twereg.h +++ /dev/null @@ -1,496 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2000 Michael Smith - * Copyright (c) 2003 Paul Saab - * Copyright (c) 2003 Vinod Kashyap - * Copyright (c) 2000 BSDi - * 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. - * - * $FreeBSD$ - */ - -/* - * Register names, bit definitions, structure names and members are - * identical with those in the Linux driver where possible and sane - * for simplicity's sake. (The TW_ prefix has become TWE_) - * Some defines that are clearly irrelevant to FreeBSD have been - * removed. - */ - -/* control register bit definitions */ -#define TWE_CONTROL_CLEAR_HOST_INTERRUPT 0x00080000 -#define TWE_CONTROL_CLEAR_ATTENTION_INTERRUPT 0x00040000 -#define TWE_CONTROL_MASK_COMMAND_INTERRUPT 0x00020000 -#define TWE_CONTROL_MASK_RESPONSE_INTERRUPT 0x00010000 -#define TWE_CONTROL_UNMASK_COMMAND_INTERRUPT 0x00008000 -#define TWE_CONTROL_UNMASK_RESPONSE_INTERRUPT 0x00004000 -#define TWE_CONTROL_CLEAR_ERROR_STATUS 0x00000200 -#define TWE_CONTROL_ISSUE_SOFT_RESET 0x00000100 -#define TWE_CONTROL_ENABLE_INTERRUPTS 0x00000080 -#define TWE_CONTROL_DISABLE_INTERRUPTS 0x00000040 -#define TWE_CONTROL_ISSUE_HOST_INTERRUPT 0x00000020 -#define TWE_CONTROL_CLEAR_PARITY_ERROR 0x00800000 -#define TWE_CONTROL_CLEAR_PCI_ABORT 0x00100000 - -#define TWE_SOFT_RESET(sc) TWE_CONTROL(sc, TWE_CONTROL_ISSUE_SOFT_RESET | \ - TWE_CONTROL_CLEAR_HOST_INTERRUPT | \ - TWE_CONTROL_CLEAR_ATTENTION_INTERRUPT | \ - TWE_CONTROL_MASK_COMMAND_INTERRUPT | \ - TWE_CONTROL_MASK_RESPONSE_INTERRUPT | \ - TWE_CONTROL_CLEAR_ERROR_STATUS | \ - TWE_CONTROL_DISABLE_INTERRUPTS) - -/* status register bit definitions */ -#define TWE_STATUS_MAJOR_VERSION_MASK 0xF0000000 -#define TWE_STATUS_MINOR_VERSION_MASK 0x0F000000 -#define TWE_STATUS_PCI_PARITY_ERROR 0x00800000 -#define TWE_STATUS_QUEUE_ERROR 0x00400000 -#define TWE_STATUS_MICROCONTROLLER_ERROR 0x00200000 -#define TWE_STATUS_PCI_ABORT 0x00100000 -#define TWE_STATUS_HOST_INTERRUPT 0x00080000 -#define TWE_STATUS_ATTENTION_INTERRUPT 0x00040000 -#define TWE_STATUS_COMMAND_INTERRUPT 0x00020000 -#define TWE_STATUS_RESPONSE_INTERRUPT 0x00010000 -#define TWE_STATUS_COMMAND_QUEUE_FULL 0x00008000 -#define TWE_STATUS_RESPONSE_QUEUE_EMPTY 0x00004000 -#define TWE_STATUS_MICROCONTROLLER_READY 0x00002000 -#define TWE_STATUS_COMMAND_QUEUE_EMPTY 0x00001000 -#define TWE_STATUS_ALL_INTERRUPTS 0x000F0000 -#define TWE_STATUS_CLEARABLE_BITS 0x00D00000 -#define TWE_STATUS_EXPECTED_BITS 0x00002000 -#define TWE_STATUS_UNEXPECTED_BITS 0x00F80000 - -/* XXX this is a little harsh, but necessary to chase down firmware problems */ -#define TWE_STATUS_PANIC_BITS (TWE_STATUS_MICROCONTROLLER_ERROR) - -/* for use with the %b printf format */ -#define TWE_STATUS_BITS_DESCRIPTION \ - "\20\15CQEMPTY\16UCREADY\17RQEMPTY\20CQFULL\21RINTR\22CINTR\23AINTR\24HINTR\25PCIABRT\26MCERR\27QERR\30PCIPERR\n" - -/* detect inconsistencies in the status register */ -#define TWE_STATUS_ERRORS(x) \ - (((x & TWE_STATUS_PCI_ABORT) || \ - (x & TWE_STATUS_PCI_PARITY_ERROR) || \ - (x & TWE_STATUS_QUEUE_ERROR) || \ - (x & TWE_STATUS_MICROCONTROLLER_ERROR)) && \ - (x & TWE_STATUS_MICROCONTROLLER_READY)) - -/* Response queue bit definitions */ -#define TWE_RESPONSE_ID_MASK 0x00000FF0 - -/* PCI related defines */ -#define TWE_IO_CONFIG_REG 0x10 -#define TWE_DEVICE_NAME "3ware Storage Controller" -#define TWE_VENDOR_ID 0x13C1 -#define TWE_DEVICE_ID 0x1000 -#define TWE_DEVICE_ID_ASIC 0x1001 -#define TWE_PCI_CLEAR_PARITY_ERROR 0xc100 -#define TWE_PCI_CLEAR_PCI_ABORT 0x2000 - -/* command packet opcodes */ -#define TWE_OP_NOP 0x00 -#define TWE_OP_INIT_CONNECTION 0x01 -#define TWE_OP_READ 0x02 -#define TWE_OP_WRITE 0x03 -#define TWE_OP_READVERIFY 0x04 -#define TWE_OP_VERIFY 0x05 -#define TWE_OP_ZEROUNIT 0x08 -#define TWE_OP_REPLACEUNIT 0x09 -#define TWE_OP_HOTSWAP 0x0a -#define TWE_OP_SETATAFEATURE 0x0c -#define TWE_OP_FLUSH 0x0e -#define TWE_OP_ABORT 0x0f -#define TWE_OP_CHECKSTATUS 0x10 -#define TWE_OP_ATA_PASSTHROUGH 0x11 -#define TWE_OP_GET_PARAM 0x12 -#define TWE_OP_SET_PARAM 0x13 -#define TWE_OP_CREATEUNIT 0x14 -#define TWE_OP_DELETEUNIT 0x15 -#define TWE_OP_REBUILDUNIT 0x17 -#define TWE_OP_SECTOR_INFO 0x1a -#define TWE_OP_AEN_LISTEN 0x1c -#define TWE_OP_CMD_PACKET 0x1d -#define TWE_OP_CMD_WITH_DATA 0x1f - -/* command status values */ -#define TWE_STATUS_RESET 0xff /* controller requests reset */ -#define TWE_STATUS_FATAL 0xc0 /* fatal errors not requiring reset */ -#define TWE_STATUS_WARNING 0x80 /* warnings */ -#define TWE_STAUS_INFO 0x40 /* informative status */ - -/* misc defines */ -#define TWE_ALIGNMENT 0x200 -#define TWE_MAX_UNITS 16 -#define TWE_COMMAND_ALIGNMENT_MASK 0x1ff -#define TWE_INIT_MESSAGE_CREDITS 0xff /* older firmware has issues with 256 commands */ -#define TWE_SHUTDOWN_MESSAGE_CREDITS 0x001 -#define TWE_INIT_COMMAND_PACKET_SIZE 0x3 -#define TWE_MAX_SGL_LENGTH 62 -#define TWE_MAX_ATA_SGL_LENGTH 60 -#define TWE_MAX_PASSTHROUGH 4096 -#define TWE_Q_LENGTH TWE_INIT_MESSAGE_CREDITS -#define TWE_Q_START 0 -#define TWE_MAX_RESET_TRIES 3 -#define TWE_BLOCK_SIZE 0x200 /* 512-byte blocks */ -#define TWE_SECTOR_SIZE 0x200 /* generic I/O bufffer */ -#define TWE_IOCTL 0x80 -#define TWE_MAX_AEN_TRIES 100 -#define TWE_UNIT_ONLINE 1 - -/* scatter/gather list entry */ -typedef struct -{ - u_int32_t address; - u_int32_t length; -} __packed TWE_SG_Entry; - -typedef struct { - u_int8_t opcode:5; /* TWE_OP_INITCONNECTION */ - u_int8_t res1:3; - u_int8_t size; - u_int8_t request_id; - u_int8_t res2:4; - u_int8_t host_id:4; - u_int8_t status; - u_int8_t flags; - u_int16_t message_credits; - u_int32_t response_queue_pointer; -} __packed TWE_Command_INITCONNECTION; - -typedef struct -{ - u_int8_t opcode:5; /* TWE_OP_READ/TWE_OP_WRITE */ - u_int8_t res1:3; - u_int8_t size; - u_int8_t request_id; - u_int8_t unit:4; - u_int8_t host_id:4; - u_int8_t status; - u_int8_t flags; - u_int16_t block_count; - u_int32_t lba; - TWE_SG_Entry sgl[TWE_MAX_SGL_LENGTH]; -} __packed TWE_Command_IO; - -typedef struct -{ - u_int8_t opcode:5; /* TWE_OP_HOTSWAP */ - u_int8_t res1:3; - u_int8_t size; - u_int8_t request_id; - u_int8_t unit:4; - u_int8_t host_id:4; - u_int8_t status; - u_int8_t flags; - u_int8_t action; -#define TWE_OP_HOTSWAP_REMOVE 0x00 /* remove assumed-degraded unit */ -#define TWE_OP_HOTSWAP_ADD_CBOD 0x01 /* add CBOD to empty port */ -#define TWE_OP_HOTSWAP_ADD_SPARE 0x02 /* add spare to empty port */ - u_int8_t aport; -} __packed TWE_Command_HOTSWAP; - -typedef struct -{ - u_int8_t opcode:5; /* TWE_OP_SETATAFEATURE */ - u_int8_t res1:3; - u_int8_t size; - u_int8_t request_id; - u_int8_t unit:4; - u_int8_t host_id:4; - u_int8_t status; - u_int8_t flags; - u_int8_t feature; -#define TWE_OP_SETATAFEATURE_WCE 0x02 -#define TWE_OP_SETATAFEATURE_DIS_WCE 0x82 - u_int8_t feature_mode; - u_int16_t all_units; - u_int16_t persistence; -} __packed TWE_Command_SETATAFEATURE; - -typedef struct -{ - u_int8_t opcode:5; /* TWE_OP_CHECKSTATUS */ - u_int8_t res1:3; - u_int8_t size; - u_int8_t request_id; - u_int8_t unit:4; - u_int8_t res2:4; - u_int8_t status; - u_int8_t flags; - u_int16_t target_status; /* set low byte to target request's ID */ -} __packed TWE_Command_CHECKSTATUS; - -typedef struct -{ - u_int8_t opcode:5; /* TWE_OP_GETPARAM, TWE_OP_SETPARAM */ - u_int8_t res1:3; - u_int8_t size; - u_int8_t request_id; - u_int8_t unit:4; - u_int8_t host_id:4; - u_int8_t status; - u_int8_t flags; - u_int16_t param_count; - TWE_SG_Entry sgl[TWE_MAX_SGL_LENGTH]; -} __packed TWE_Command_PARAM; - -typedef struct -{ - u_int8_t opcode:5; /* TWE_OP_REBUILDUNIT */ - u_int8_t res1:3; - u_int8_t size; - u_int8_t request_id; - u_int8_t src_unit:4; - u_int8_t host_id:4; - u_int8_t status; - u_int8_t flags; - u_int8_t action:7; -#define TWE_OP_REBUILDUNIT_NOP 0 -#define TWE_OP_REBUILDUNIT_STOP 2 /* stop all rebuilds */ -#define TWE_OP_REBUILDUNIT_START 4 /* start rebuild with lowest unit */ -#define TWE_OP_REBUILDUNIT_STARTUNIT 5 /* rebuild src_unit (not supported) */ - u_int8_t cs:1; /* request state change on src_unit */ - u_int8_t logical_subunit; /* for RAID10 rebuild of logical subunit */ -} __packed TWE_Command_REBUILDUNIT; - -typedef struct -{ - u_int8_t opcode:5; - u_int8_t sgl_offset:3; - u_int8_t size; - u_int8_t request_id; - u_int8_t unit:4; - u_int8_t host_id:4; - u_int8_t status; - u_int8_t flags; - u_int16_t param; - u_int16_t features; - u_int16_t sector_count; - u_int16_t sector_num; - u_int16_t cylinder_lo; - u_int16_t cylinder_hi; - u_int8_t drive_head; - u_int8_t command; - TWE_SG_Entry sgl[TWE_MAX_ATA_SGL_LENGTH]; -} __packed TWE_Command_ATA; - -typedef struct -{ - u_int8_t opcode:5; - u_int8_t sgl_offset:3; - u_int8_t size; - u_int8_t request_id; - u_int8_t unit:4; - u_int8_t host_id:4; - u_int8_t status; - u_int8_t flags; -#define TWE_FLAGS_SUCCESS 0x00 -#define TWE_FLAGS_INFORMATIONAL 0x01 -#define TWE_FLAGS_WARNING 0x02 -#define TWE_FLAGS_FATAL 0x03 -#define TWE_FLAGS_PERCENTAGE (1<<8) /* bits 0-6 indicate completion percentage */ - u_int16_t count; /* block count, parameter count, message credits */ -} __packed TWE_Command_Generic; - -/* command packet - must be TWE_ALIGNMENT aligned */ -typedef union -{ - TWE_Command_INITCONNECTION initconnection; - TWE_Command_IO io; - TWE_Command_PARAM param; - TWE_Command_CHECKSTATUS checkstatus; - TWE_Command_REBUILDUNIT rebuildunit; - TWE_Command_SETATAFEATURE setatafeature; - TWE_Command_ATA ata; - TWE_Command_Generic generic; - u_int8_t pad[512]; -} TWE_Command; - -/* response queue entry */ -typedef union -{ - struct - { - u_int32_t undefined_1:4; - u_int32_t response_id:8; - u_int32_t undefined_2:20; - } u; - u_int32_t value; -} TWE_Response_Queue; - -/* - * From 3ware's documentation: - * All parameters maintained by the controller are grouped into related tables. - * Tables are are accessed indirectly via get and set parameter commands. - * To access a specific parameter in a table, the table ID and parameter index - * are used to uniquely identify a parameter. Table 0xffff is the directory - * table and provides a list of the table IDs and sizes of all other tables. - * Index zero in each table specifies the entire table, and index one specifies - * the size of the table. An entire table can be read or set by using index zero. - */ - -#define TWE_PARAM_PARAM_ALL 0 -#define TWE_PARAM_PARAM_SIZE 1 - -#define TWE_PARAM_DIRECTORY 0xffff /* size is 4 * number of tables */ -#define TWE_PARAM_DIRECTORY_TABLES 2 /* 16 bits * number of tables */ -#define TWE_PARAM_DIRECTORY_SIZES 3 /* 16 bits * number of tables */ - -#define TWE_PARAM_DRIVESUMMARY 0x0002 -#define TWE_PARAM_DRIVESUMMARY_Num 2 /* number of physical drives [2] */ -#define TWE_PARAM_DRIVESUMMARY_Status 3 /* array giving drive status per aport */ -#define TWE_PARAM_DRIVESTATUS_Missing 0x00 -#define TWE_PARAM_DRIVESTATUS_NotSupp 0xfe -#define TWE_PARAM_DRIVESTATUS_Present 0xff - -#define TWE_PARAM_UNITSUMMARY 0x0003 -#define TWE_PARAM_UNITSUMMARY_Num 2 /* number of logical units [2] */ -#define TWE_PARAM_UNITSUMMARY_Status 3 /* array giving unit status [16] */ -#define TWE_PARAM_UNITSTATUS_Online (1<<0) -#define TWE_PARAM_UNITSTATUS_Complete (1<<1) -#define TWE_PARAM_UNITSTATUS_MASK 0xfc -#define TWE_PARAM_UNITSTATUS_Normal 0xfc -#define TWE_PARAM_UNITSTATUS_Initialising 0xf4 /* cannot be incomplete */ -#define TWE_PARAM_UNITSTATUS_Degraded 0xec -#define TWE_PARAM_UNITSTATUS_Rebuilding 0xdc /* cannot be incomplete */ -#define TWE_PARAM_UNITSTATUS_Verifying 0xcc /* cannot be incomplete */ -#define TWE_PARAM_UNITSTATUS_Corrupt 0xbc /* cannot be complete */ -#define TWE_PARAM_UNITSTATUS_Missing 0x00 /* cannot be complete or online */ - -#define TWE_PARAM_DRIVEINFO 0x0200 /* add drive number 0x00-0x0f XXX docco confused 0x0100 vs 0x0200 */ -#define TWE_PARAM_DRIVEINFO_Size 2 /* size in blocks [4] */ -#define TWE_PARAM_DRIVEINFO_Model 3 /* drive model string [40] */ -#define TWE_PARAM_DRIVEINFO_Serial 4 /* drive serial number [20] */ -#define TWE_PARAM_DRIVEINFO_PhysCylNum 5 /* physical geometry [2] */ -#define TWE_PARAM_DRIVEINFO_PhysHeadNum 6 /* [2] */ -#define TWE_PARAM_DRIVEINFO_PhysSectorNym 7 /* [2] */ -#define TWE_PARAM_DRIVEINFO_LogCylNum 8 /* logical geometry [2] */ -#define TWE_PARAM_DRIVEINFO_LogHeadNum 9 /* [2] */ -#define TWE_PARAM_DRIVEINFO_LogSectorNum 10 /* [2] */ -#define TWE_PARAM_DRIVEINFO_UnitNum 11 /* unit number this drive is associated with or 0xff [1] */ -#define TWE_PARAM_DRIVEINFO_DriveFlags 12 /* N/A [1] */ - -#define TWE_PARAM_APORTTIMEOUT 0x02c0 /* add (aport_number * 3) to parameter index */ -#define TWE_PARAM_APORTTIMEOUT_READ 2 /* read timeouts last 24hrs [2] */ -#define TWE_PARAM_APORTTIMEOUT_WRITE 3 /* write timeouts last 24hrs [2] */ -#define TWE_PARAM_APORTTIMEOUT_DEGRADE 4 /* degrade threshold [2] */ - -#define TWE_PARAM_UNITINFO 0x0300 /* add unit number 0x00-0x0f */ -#define TWE_PARAM_UNITINFO_Number 2 /* unit number [1] */ -#define TWE_PARAM_UNITINFO_Status 3 /* unit status [1] */ -#define TWE_PARAM_UNITINFO_Capacity 4 /* unit capacity in blocks [4] */ -#define TWE_PARAM_UNITINFO_DescriptorSize 5 /* unit descriptor size + 3 bytes [2] */ -#define TWE_PARAM_UNITINFO_Descriptor 6 /* unit descriptor, TWE_UnitDescriptor or TWE_Array_Descriptor */ -#define TWE_PARAM_UNITINFO_Flags 7 /* unit flags [1] */ -#define TWE_PARAM_UNITFLAGS_WCE (1<<0) - -#define TWE_PARAM_AEN 0x0401 -#define TWE_PARAM_AEN_UnitCode 2 /* (unit number << 8) | AEN code [2] */ -#define TWE_AEN_QUEUE_EMPTY 0x00 -#define TWE_AEN_SOFT_RESET 0x01 -#define TWE_AEN_DEGRADED_MIRROR 0x02 /* reports unit */ -#define TWE_AEN_CONTROLLER_ERROR 0x03 -#define TWE_AEN_REBUILD_FAIL 0x04 /* reports unit */ -#define TWE_AEN_REBUILD_DONE 0x05 /* reports unit */ -#define TWE_AEN_INCOMP_UNIT 0x06 /* reports unit */ -#define TWE_AEN_INIT_DONE 0x07 /* reports unit */ -#define TWE_AEN_UNCLEAN_SHUTDOWN 0x08 /* reports unit */ -#define TWE_AEN_APORT_TIMEOUT 0x09 /* reports unit, rate limited to 1 per 2^16 errors */ -#define TWE_AEN_DRIVE_ERROR 0x0a /* reports unit */ -#define TWE_AEN_REBUILD_STARTED 0x0b /* reports unit */ -#define TWE_AEN_QUEUE_FULL 0xff -#define TWE_AEN_TABLE_UNDEFINED 0x15 -#define TWE_AEN_CODE(x) ((x) & 0xff) -#define TWE_AEN_UNIT(x) ((x) >> 8) - -#define TWE_PARAM_VERSION 0x0402 -#define TWE_PARAM_VERSION_Mon 2 /* monitor version [16] */ -#define TWE_PARAM_VERSION_FW 3 /* firmware version [16] */ -#define TWE_PARAM_VERSION_BIOS 4 /* BIOSs version [16] */ -#define TWE_PARAM_VERSION_PCB 5 /* PCB version [8] */ -#define TWE_PARAM_VERSION_ATA 6 /* A-chip version [8] */ -#define TWE_PARAM_VERSION_PCI 7 /* P-chip version [8] */ -#define TWE_PARAM_VERSION_CtrlModel 8 /* N/A */ -#define TWE_PARAM_VERSION_CtrlSerial 9 /* N/A */ -#define TWE_PARAM_VERSION_SBufSize 10 /* N/A */ -#define TWE_PARAM_VERSION_CompCode 11 /* compatibility code [4] */ - -#define TWE_PARAM_CONTROLLER 0x0403 -#define TWE_PARAM_CONTROLLER_DCBSectors 2 /* # sectors reserved for DCB per drive [2] */ -#define TWE_PARAM_CONTROLLER_PortCount 3 /* number of drive ports [1] */ - -#define TWE_PARAM_FEATURES 0x404 -#define TWE_PARAM_FEATURES_DriverShutdown 2 /* set to 1 if driver supports shutdown notification [1] */ - -typedef struct -{ - u_int8_t num_subunits; /* must be zero */ - u_int8_t configuration; -#define TWE_UD_CONFIG_CBOD 0x0c /* JBOD with DCB, used for mirrors */ -#define TWE_UD_CONFIG_SPARE 0x0d /* same as CBOD, but firmware will use as spare */ -#define TWE_UD_CONFIG_SUBUNIT 0x0e /* drive is a subunit in an array */ -#define TWE_UD_CONFIG_JBOD 0x0f /* plain drive */ - u_int8_t phys_drv_num; /* may be 0xff if port can't be determined at runtime */ - u_int8_t log_drv_num; /* must be zero for configuration == 0x0f */ - u_int32_t start_lba; - u_int32_t block_count; /* actual drive size if configuration == 0x0f, otherwise less DCB size */ -} __packed TWE_Unit_Descriptor; - -typedef struct -{ - u_int8_t flag; /* must be 0xff */ - u_int8_t res1; - u_int8_t mirunit_status[4]; /* bitmap of functional subunits in each mirror */ - u_int8_t res2[6]; -} __packed TWE_Mirror_Descriptor; - -typedef struct -{ - u_int8_t num_subunits; /* number of subunits, or number of mirror units in RAID10 */ - u_int8_t configuration; -#define TWE_UD_CONFIG_RAID0 0x00 -#define TWE_UD_CONFIG_RAID1 0x01 -#define TWE_UD_CONFIG_TwinStor 0x02 -#define TWE_UD_CONFIG_RAID5 0x05 -#define TWE_UD_CONFIG_RAID10 0x06 - u_int8_t stripe_size; -#define TWE_UD_STRIPE_4k 0x03 -#define TWE_UD_STRIPE_8k 0x04 -#define TWE_UD_STRIPE_16k 0x05 -#define TWE_UD_STRIPE_32k 0x06 -#define TWE_UD_STRIPE_64k 0x07 - u_int8_t log_drv_status; /* bitmap of functional subunits, or mirror units in RAID10 */ - u_int32_t start_lba; - u_int32_t block_count; /* actual drive size if configuration == 0x0f, otherwise less DCB size */ - TWE_Unit_Descriptor subunit[0]; /* subunit descriptors, in RAID10 mode is [mirunit][subunit] */ -} __packed TWE_Array_Descriptor; - -typedef struct -{ - u_int16_t table_id; - u_int8_t parameter_id; - u_int8_t parameter_size_bytes; - u_int8_t data[0]; -} __packed TWE_Param; diff --git a/sys/dev/twe/twevar.h b/sys/dev/twe/twevar.h deleted file mode 100644 index bb7c28e874e5..000000000000 --- a/sys/dev/twe/twevar.h +++ /dev/null @@ -1,274 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2000 Michael Smith - * Copyright (c) 2000 BSDi - * 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. - * - * $FreeBSD$ - */ - -#define TWE_DRIVER_VERSION_STRING "1.50.01.002" - -#ifdef TWE_DEBUG -#define debug(level, fmt, args...) \ - do { \ - if (level <= TWE_DEBUG) printf("%s: " fmt "\n", __func__ , ##args); \ - } while(0) -#define debug_called(level) \ - do { \ - if (level <= TWE_DEBUG) printf("%s: called\n", __func__); \ - } while(0) -#else -#define debug(level, fmt, args...) -#define debug_called(level) -#endif - -/* - * Structure describing a logical unit as attached to the controller - */ -struct twe_drive -{ - /* unit properties */ - u_int32_t td_size; - int td_cylinders; - int td_heads; - int td_sectors; - int td_sys_unit; /* device unit number */ - int td_twe_unit; /* index into sc->twe_drive[] */ - - /* unit state and type */ - u_int8_t td_state; - u_int8_t td_type; - u_int8_t td_stripe; - - /* handle for attached driver */ - device_t td_disk; -}; - -/* - * Per-command control structure. - * - * Note that due to alignment constraints on the tc_command field, this *must* be 64-byte aligned. - * We achieve this by placing the command at the beginning of the structure, and using malloc() - * to allocate each structure. - */ -struct twe_request -{ - int tr_tag; - /* command payload */ - void *tr_data; /* data buffer */ - void *tr_realdata; /* copy of real data buffer pointer for alignment fixup */ - size_t tr_length; - - TAILQ_ENTRY(twe_request) tr_link; /* list linkage */ - struct twe_softc *tr_sc; /* controller that owns us */ - int tr_status; /* command status */ -#define TWE_CMD_SETUP 0 /* being assembled */ -#define TWE_CMD_BUSY 1 /* submitted to controller */ -#define TWE_CMD_COMPLETE 2 /* completed by controller (maybe with error) */ -#define TWE_CMD_ERROR 3 /* encountered error, even before submission to controller */ - int tr_flags; -#define TWE_CMD_DATAIN (1<<0) -#define TWE_CMD_DATAOUT (1<<1) -#define TWE_CMD_ALIGNBUF (1<<2) /* data in bio is misaligned, have to copy to/from private buffer */ -#define TWE_CMD_SLEEPER (1<<3) /* owner is sleeping on this command */ -#define TWE_CMD_IMMEDIATE (1<<4) /* immediate request */ -#define TWE_CMD_MAPPED (1<<5) -#define TWE_CMD_IN_PROGRESS (1<<6) /* bus_dmamap_load returned EINPROGRESS */ - void (* tr_complete)(struct twe_request *tr); /* completion handler */ - void *tr_private; /* submitter-private data or wait channel */ - - TWE_PLATFORM_REQUEST /* platform-specific request elements */ -}; - -#define TWE_FIND_COMMAND(tr) \ - (TWE_Command *)((u_int8_t *)(tr)->tr_sc->twe_cmd + \ - ((tr)->tr_tag * sizeof(TWE_Command))) -#define TWE_FIND_COMMANDPHYS(tr) ((tr)->tr_sc->twe_cmdphys + \ - ((tr)->tr_tag * sizeof(TWE_Command))) - -/* - * Per-controller state. - */ -struct twe_softc -{ - /* controller queues and arrays */ - TAILQ_HEAD(, twe_request) twe_free; /* command structures available for reuse */ - struct bio_queue_head twe_bioq; /* outstanding I/O operations */ - TAILQ_HEAD(, twe_request) twe_ready; /* requests ready for the controller */ - TAILQ_HEAD(, twe_request) twe_busy; /* requests busy in the controller */ - TAILQ_HEAD(, twe_request) twe_complete; /* active commands (busy or waiting for completion) */ - struct twe_request *twe_lookup[TWE_Q_LENGTH]; /* commands indexed by request ID */ - struct twe_drive twe_drive[TWE_MAX_UNITS]; /* attached drives */ - - /* asynchronous event handling */ - u_int16_t twe_aen_queue[TWE_Q_LENGTH]; /* AENs queued for userland tool(s) */ - int twe_aen_head, twe_aen_tail; /* ringbuffer pointers for AEN queue */ - int twe_wait_aen; /* wait-for-aen notification */ - char twe_aen_buf[80]; /* AEN format buffer */ - - /* controller status */ - int twe_state; -#define TWE_STATE_INTEN (1<<0) /* interrupts have been enabled */ -#define TWE_STATE_SHUTDOWN (1<<1) /* controller is shut down */ -#define TWE_STATE_OPEN (1<<2) /* control device is open */ -#define TWE_STATE_SUSPEND (1<<3) /* controller is suspended */ -#define TWE_STATE_FRZN (1<<4) /* got EINPROGRESS */ -#define TWE_STATE_CTLR_BUSY (1<<5) /* controller cmd queue full */ -#define TWE_STATE_DETACHING (1<<6) /* controller is being shut down */ - int twe_host_id; - struct twe_qstat twe_qstat[TWEQ_COUNT]; /* queue statistics */ - - TWE_PLATFORM_SOFTC /* platform-specific softc elements */ -}; - -/* - * Interface between driver core and platform-dependant code. - */ -extern int twe_setup(struct twe_softc *sc); /* do early driver/controller setup */ -extern void twe_init(struct twe_softc *sc); /* init controller */ -extern void twe_deinit(struct twe_softc *sc); /* stop controller */ -extern void twe_intr(struct twe_softc *sc); /* hardware interrupt signalled */ -extern void twe_startio(struct twe_softc *sc); -extern int twe_start(struct twe_request *tr); -extern int twe_dump_blocks(struct twe_softc *sc, int unit, /* crashdump block write */ - u_int32_t lba, void *data, int nblks); -extern int twe_ioctl(struct twe_softc *sc, u_long cmd, - void *addr); /* handle user request */ -extern void twe_describe_controller(struct twe_softc *sc); /* print controller info */ -extern void twe_print_controller(struct twe_softc *sc); -extern void twe_enable_interrupts(struct twe_softc *sc); /* enable controller interrupts */ -extern void twe_disable_interrupts(struct twe_softc *sc); /* disable controller interrupts */ - -extern int twe_attach_drive(struct twe_softc *sc, - struct twe_drive *dr); /* attach drive when found in twe_init */ -extern int twe_detach_drive(struct twe_softc *sc, - int unit); /* detach drive */ -extern void twe_clear_pci_parity_error(struct twe_softc *sc); -extern void twe_clear_pci_abort(struct twe_softc *sc); -extern void twed_intr(struct bio *bp); /* return bio from core */ -extern struct twe_request *twe_allocate_request(struct twe_softc *sc, int tag); /* allocate request structure */ -extern void twe_free_request(struct twe_request *tr); /* free request structure */ -extern int twe_map_request(struct twe_request *tr); /* make request visible to controller, do s/g */ -extern void twe_unmap_request(struct twe_request *tr); /* cleanup after transfer, unmap */ - -/******************************************************************************** - * Queue primitives - */ -#define TWEQ_ADD(sc, qname) \ - do { \ - struct twe_qstat *qs = &(sc)->twe_qstat[qname]; \ - \ - qs->q_length++; \ - if (qs->q_length > qs->q_max) \ - qs->q_max = qs->q_length; \ - } while(0) - -#define TWEQ_REMOVE(sc, qname) \ - do { \ - struct twe_qstat *qs = &(sc)->twe_qstat[qname]; \ - \ - qs->q_length--; \ - if (qs->q_length < qs->q_min) \ - qs->q_min = qs->q_length; \ - } while(0); - -#define TWEQ_INIT(sc, qname) \ - do { \ - sc->twe_qstat[qname].q_length = 0; \ - sc->twe_qstat[qname].q_max = 0; \ - sc->twe_qstat[qname].q_min = 0xFFFFFFFF; \ - } while(0) - -#define TWEQ_REQUEST_QUEUE(name, index) \ -static __inline void \ -twe_initq_ ## name (struct twe_softc *sc) \ -{ \ - TAILQ_INIT(&sc->twe_ ## name); \ - TWEQ_INIT(sc, index); \ -} \ -static __inline void \ -twe_enqueue_ ## name (struct twe_request *tr) \ -{ \ - TAILQ_INSERT_TAIL(&tr->tr_sc->twe_ ## name, tr, tr_link); \ - TWEQ_ADD(tr->tr_sc, index); \ -} \ -static __inline void \ -twe_requeue_ ## name (struct twe_request *tr) \ -{ \ - TAILQ_INSERT_HEAD(&tr->tr_sc->twe_ ## name, tr, tr_link); \ - TWEQ_ADD(tr->tr_sc, index); \ -} \ -static __inline struct twe_request * \ -twe_dequeue_ ## name (struct twe_softc *sc) \ -{ \ - struct twe_request *tr; \ - \ - if ((tr = TAILQ_FIRST(&sc->twe_ ## name)) != NULL) { \ - TAILQ_REMOVE(&sc->twe_ ## name, tr, tr_link); \ - TWEQ_REMOVE(sc, index); \ - } \ - return(tr); \ -} \ -static __inline void \ -twe_remove_ ## name (struct twe_request *tr) \ -{ \ - TAILQ_REMOVE(&tr->tr_sc->twe_ ## name, tr, tr_link); \ - TWEQ_REMOVE(tr->tr_sc, index); \ -} - -TWEQ_REQUEST_QUEUE(free, TWEQ_FREE) -TWEQ_REQUEST_QUEUE(ready, TWEQ_READY) -TWEQ_REQUEST_QUEUE(busy, TWEQ_BUSY) -TWEQ_REQUEST_QUEUE(complete, TWEQ_COMPLETE) - -/* - * outstanding bio queue - */ -static __inline void -twe_initq_bio(struct twe_softc *sc) -{ - bioq_init(&sc->twe_bioq); - TWEQ_INIT(sc, TWEQ_BIO); -} - -static __inline void -twe_enqueue_bio(struct twe_softc *sc, struct bio *bp) -{ - bioq_insert_tail(&sc->twe_bioq, bp); - TWEQ_ADD(sc, TWEQ_BIO); -} - -static __inline struct bio * -twe_dequeue_bio(struct twe_softc *sc) -{ - struct bio *bp; - - if ((bp = bioq_first(&sc->twe_bioq)) != NULL) { - bioq_remove(&sc->twe_bioq, bp); - TWEQ_REMOVE(sc, TWEQ_BIO); - } - return(bp); -} diff --git a/sys/modules/Makefile b/sys/modules/Makefile index a98f67d9ec22..b9867f25df4e 100644 --- a/sys/modules/Makefile +++ b/sys/modules/Makefile @@ -383,7 +383,6 @@ SUBDIR= \ tmpfs \ ${_toecore} \ ${_tpm} \ - twe \ tws \ uart \ udf \ diff --git a/sys/modules/twe/Makefile b/sys/modules/twe/Makefile deleted file mode 100644 index f5d09e4463e1..000000000000 --- a/sys/modules/twe/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -# $FreeBSD$ - -KMOD= twe -.PATH: ${SRCTOP}/sys/dev/${KMOD} -SRCS= bus_if.h device_if.h pci_if.h twe.c twe_freebsd.c - -#CFLAGS+=-DTWE_DEBUG=0 - -# The 3ware controller offers a choice of options related to handling of -# mirror consistency in shutdown situations. -# -# If TWE_SHUTDOWN_NOTIFICATION is defined, the driver will inform the -# controller on clean shutdown. On reboot after an unclean shutdown, the -# controller will perform a complete mirror rebuild. This is the most -# "safe" configuration, but it imposes a severe performance penalty in the -# event of an unexpected reboot. -# -# In the alternate configuration, the controller assumes that all writes to -# a mirror complete successfully. In the case of an unclean shutdown, -# mirror corruption may occur if the controller is reset or power is lost -# during a disk write. This configuration is more suitable if the system -# has reliable power, but may be unstable for other reasons. -# -CFLAGS+=-DTWE_SHUTDOWN_NOTIFICATION - -# The module can be built to override a compiled-in driver -# -#CFLAGS+=-DTWE_OVERRIDE - -.include