12aedd662SScott Long /*- 22aedd662SScott Long * Copyright (c) 2002 Adaptec Inc. 32aedd662SScott Long * All rights reserved. 42aedd662SScott Long * 52aedd662SScott Long * Written by: David Jeffery 62aedd662SScott Long * 72aedd662SScott Long * Redistribution and use in source and binary forms, with or without 82aedd662SScott Long * modification, are permitted provided that the following conditions 92aedd662SScott Long * are met: 102aedd662SScott Long * 1. Redistributions of source code must retain the above copyright 112aedd662SScott Long * notice, this list of conditions and the following disclaimer. 122aedd662SScott Long * 2. Redistributions in binary form must reproduce the above copyright 132aedd662SScott Long * notice, this list of conditions and the following disclaimer in the 142aedd662SScott Long * documentation and/or other materials provided with the distribution. 152aedd662SScott Long * 162aedd662SScott Long * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 172aedd662SScott Long * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 182aedd662SScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 192aedd662SScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 202aedd662SScott Long * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 212aedd662SScott Long * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 222aedd662SScott Long * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 232aedd662SScott Long * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 242aedd662SScott Long * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 252aedd662SScott Long * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 262aedd662SScott Long * SUCH DAMAGE. 272aedd662SScott Long * 282aedd662SScott Long * $FreeBSD$ 292aedd662SScott Long */ 30f94dfeb4SScott Long #ifndef _IPS_H 31f94dfeb4SScott Long #define _IPS_H 322aedd662SScott Long 33f94dfeb4SScott Long #ifdef _KERNEL 342aedd662SScott Long 352aedd662SScott Long #include <sys/param.h> 362aedd662SScott Long #include <sys/systm.h> 372aedd662SScott Long #include <sys/kernel.h> 38fe12f24bSPoul-Henning Kamp #include <sys/module.h> 392aedd662SScott Long #include <sys/bus.h> 402aedd662SScott Long #include <sys/conf.h> 412aedd662SScott Long #include <sys/types.h> 422aedd662SScott Long #include <sys/queue.h> 432aedd662SScott Long #include <sys/bio.h> 442aedd662SScott Long #include <sys/malloc.h> 452aedd662SScott Long #include <sys/mutex.h> 46b234a120SScott Long #include <sys/sema.h> 477633e7f1SMartin Blapp #include <sys/time.h> 482aedd662SScott Long 492aedd662SScott Long #include <machine/bus.h> 502aedd662SScott Long #include <sys/rman.h> 512aedd662SScott Long #include <machine/resource.h> 522aedd662SScott Long 53dd83a01eSScott Long MALLOC_DECLARE(M_IPSBUF); 54dd83a01eSScott Long 552aedd662SScott Long /* 562aedd662SScott Long * IPS MACROS 572aedd662SScott Long */ 582aedd662SScott Long 592aedd662SScott Long #define ips_read_1(sc,offset) bus_space_read_1(sc->bustag, sc->bushandle, offset) 602aedd662SScott Long #define ips_read_2(sc,offset) bus_space_read_2(sc->bustag, sc->bushandle, offset) 612aedd662SScott Long #define ips_read_4(sc,offset) bus_space_read_4(sc->bustag, sc->bushandle, offset) 622aedd662SScott Long 632aedd662SScott Long #define ips_write_1(sc,offset,value) bus_space_write_1(sc->bustag, sc->bushandle, offset, value) 642aedd662SScott Long #define ips_write_2(sc,offset,value) bus_space_write_2(sc->bustag, sc->bushandle, offset, value) 652aedd662SScott Long #define ips_write_4(sc,offset,value) bus_space_write_4(sc->bustag, sc->bushandle, offset, value) 662aedd662SScott Long 672aedd662SScott Long /* this is ugly. It zeros the end elements in an ips_command_t struct starting with the status element */ 682aedd662SScott Long #define clear_ips_command(command) bzero(&((command)->status), (unsigned long)(&(command)[1])-(unsigned long)&((command)->status)) 692aedd662SScott Long 702aedd662SScott Long #define ips_read_request(iobuf) ((iobuf)->bio_cmd == BIO_READ) 712aedd662SScott Long 722eea7051SScott Long #define COMMAND_ERROR(command) (((command)->status.fields.basic_status & IPS_GSC_STATUS_MASK) >= IPS_MIN_ERROR) 732eea7051SScott Long 742eea7051SScott Long #define ips_set_error(command, error) do { \ 752eea7051SScott Long (command)->status.fields.basic_status = IPS_DRV_ERROR; \ 762eea7051SScott Long (command)->status.fields.reserved = ((error) & 0x0f); \ 772eea7051SScott Long } while (0); 782aedd662SScott Long 792aedd662SScott Long #ifndef IPS_DEBUG 802aedd662SScott Long #define DEVICE_PRINTF(x...) 812aedd662SScott Long #define PRINTF(x...) 822aedd662SScott Long #else 832aedd662SScott Long #define DEVICE_PRINTF(level,x...) if(IPS_DEBUG >= level)device_printf(x) 842aedd662SScott Long #define PRINTF(level,x...) if(IPS_DEBUG >= level)printf(x) 852aedd662SScott Long #endif 862eea7051SScott Long 872aedd662SScott Long struct ips_softc; 882aedd662SScott Long 892aedd662SScott Long typedef struct { 902aedd662SScott Long u_int32_t status[IPS_MAX_CMD_NUM]; 912aedd662SScott Long u_int32_t base_phys_addr; 922aedd662SScott Long int nextstatus; 932aedd662SScott Long bus_dma_tag_t dmatag; 942aedd662SScott Long bus_dmamap_t dmamap; 952aedd662SScott Long } ips_copper_queue_t; 962aedd662SScott Long 972aedd662SScott Long /* used to keep track of current commands to the card */ 982aedd662SScott Long typedef struct ips_command{ 992aedd662SScott Long u_int8_t command_number; 1002aedd662SScott Long u_int8_t id; 1012aedd662SScott Long u_int8_t timeout; 1022aedd662SScott Long struct ips_softc * sc; 10303a908f2SScott Long bus_dma_tag_t data_dmatag; 10403a908f2SScott Long bus_dmamap_t data_dmamap; 1052aedd662SScott Long bus_dmamap_t command_dmamap; 1062aedd662SScott Long void * command_buffer; 1072aedd662SScott Long u_int32_t command_phys_addr;/*WARNING! must be changed if 64bit addressing ever used*/ 1082aedd662SScott Long ips_cmd_status_t status; 1092aedd662SScott Long SLIST_ENTRY(ips_command) next; 1102aedd662SScott Long void * data_buffer; 1112aedd662SScott Long void * arg; 1122aedd662SScott Long void (* callback)(struct ips_command *command); 1132aedd662SScott Long }ips_command_t; 1142aedd662SScott Long 1152aedd662SScott Long typedef struct ips_softc{ 1162aedd662SScott Long struct resource * iores; 1172aedd662SScott Long struct resource * irqres; 118faf13262SPaul Saab struct intr_config_hook ips_ich; 119dea4622dSScott Long int configured; 1202aedd662SScott Long int state; 1212aedd662SScott Long int iotype; 1222aedd662SScott Long int rid; 1232aedd662SScott Long int irqrid; 1242aedd662SScott Long void * irqcookie; 1252aedd662SScott Long bus_space_tag_t bustag; 1262aedd662SScott Long bus_space_handle_t bushandle; 1272aedd662SScott Long bus_dma_tag_t adapter_dmatag; 1282aedd662SScott Long bus_dma_tag_t command_dmatag; 1292aedd662SScott Long bus_dma_tag_t sg_dmatag; 1302aedd662SScott Long device_t dev; 13189c9c53dSPoul-Henning Kamp struct cdev *device_file; 1322aedd662SScott Long struct callout_handle timer; 1337633e7f1SMartin Blapp u_int16_t adapter_type; 1342aedd662SScott Long ips_adapter_info_t adapter_info; 1352aedd662SScott Long device_t diskdev[IPS_MAX_NUM_DRIVES]; 1362aedd662SScott Long ips_drive_t drives[IPS_MAX_NUM_DRIVES]; 1372aedd662SScott Long u_int8_t drivecount; 1387633e7f1SMartin Blapp u_int16_t ffdc_resetcount; 1397633e7f1SMartin Blapp struct timeval ffdc_resettime; 1402aedd662SScott Long u_int8_t next_drive; 1412aedd662SScott Long u_int8_t max_cmds; 1422aedd662SScott Long volatile u_int8_t used_commands; 14303a908f2SScott Long ips_command_t *commandarray; 14403a908f2SScott Long ips_command_t *staticcmd; 1452aedd662SScott Long SLIST_HEAD(command_list, ips_command) free_cmd_list; 1462aedd662SScott Long int (* ips_adapter_reinit)(struct ips_softc *sc, 1472aedd662SScott Long int force); 1482aedd662SScott Long void (* ips_adapter_intr)(void *sc); 1492aedd662SScott Long void (* ips_issue_cmd)(ips_command_t *command); 1507765040eSScott Long void (* ips_poll_cmd)(ips_command_t *command); 1512aedd662SScott Long ips_copper_queue_t * copper_queue; 152b234a120SScott Long struct mtx queue_mtx; 153b234a120SScott Long struct bio_queue_head queue; 15403a908f2SScott Long struct sema cmd_sema; 155b234a120SScott Long 1562aedd662SScott Long }ips_softc_t; 1572aedd662SScott Long 1582aedd662SScott Long /* function defines from ips_ioctl.c */ 1592aedd662SScott Long extern int ips_ioctl_request(ips_softc_t *sc, u_long ioctl_cmd, caddr_t addr, 1602aedd662SScott Long int32_t flags); 1612aedd662SScott Long /* function defines from ips_disk.c */ 1622aedd662SScott Long extern void ipsd_finish(struct bio *iobuf); 1632aedd662SScott Long 1642aedd662SScott Long /* function defines from ips_commands.c */ 1652aedd662SScott Long extern int ips_flush_cache(ips_softc_t *sc); 166b234a120SScott Long extern void ips_start_io_request(ips_softc_t *sc); 1672aedd662SScott Long extern int ips_get_drive_info(ips_softc_t *sc); 1682aedd662SScott Long extern int ips_get_adapter_info(ips_softc_t *sc); 1697633e7f1SMartin Blapp extern int ips_ffdc_reset(ips_softc_t *sc); 1702aedd662SScott Long extern int ips_update_nvram(ips_softc_t *sc); 1712aedd662SScott Long extern int ips_clear_adapter(ips_softc_t *sc); 1722aedd662SScott Long 1732aedd662SScott Long /* function defines from ips.c */ 17403a908f2SScott Long extern int ips_get_free_cmd(ips_softc_t *sc, ips_command_t **command, unsigned long flags); 1752aedd662SScott Long extern void ips_insert_free_cmd(ips_softc_t *sc, ips_command_t *command); 1762aedd662SScott Long extern int ips_adapter_init(ips_softc_t *sc); 1772aedd662SScott Long extern int ips_morpheus_reinit(ips_softc_t *sc, int force); 1782aedd662SScott Long extern int ips_adapter_free(ips_softc_t *sc); 1792aedd662SScott Long extern void ips_morpheus_intr(void *sc); 1802aedd662SScott Long extern void ips_issue_morpheus_cmd(ips_command_t *command); 1817765040eSScott Long extern void ips_morpheus_poll(ips_command_t *command); 1822aedd662SScott Long extern int ips_copperhead_reinit(ips_softc_t *sc, int force); 1832aedd662SScott Long extern void ips_copperhead_intr(void *sc); 1842aedd662SScott Long extern void ips_issue_copperhead_cmd(ips_command_t *command); 1857765040eSScott Long extern void ips_copperhead_poll(ips_command_t *command); 1862aedd662SScott Long 187f94dfeb4SScott Long #endif 188f94dfeb4SScott Long #endif 189