1 /*- 2 * Copyright (c) 2002 Adaptec Inc. 3 * All rights reserved. 4 * 5 * Written by: David Jeffery 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 #ifndef _IPS_H 31 #define _IPS_H 32 33 #ifdef _KERNEL 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/kernel.h> 38 #include <sys/module.h> 39 #include <sys/bus.h> 40 #include <sys/conf.h> 41 #include <sys/types.h> 42 #include <sys/queue.h> 43 #include <sys/bio.h> 44 #include <sys/malloc.h> 45 #include <sys/mutex.h> 46 #include <sys/sema.h> 47 #include <sys/time.h> 48 49 #include <machine/bus.h> 50 #include <sys/rman.h> 51 #include <machine/resource.h> 52 53 MALLOC_DECLARE(M_IPSBUF); 54 55 /* 56 * IPS MACROS 57 */ 58 59 #define ips_read_1(sc,offset) bus_read_1(sc->iores, offset) 60 #define ips_read_2(sc,offset) bus_read_2(sc->iores, offset) 61 #define ips_read_4(sc,offset) bus_read_4(sc->iores, offset) 62 63 #define ips_write_1(sc,offset,value) bus_write_1(sc->iores, offset, value) 64 #define ips_write_2(sc,offset,value) bus_write_2(sc->iores, offset, value) 65 #define ips_write_4(sc,offset,value) bus_write_4(sc->iores, offset, value) 66 67 /* this is ugly. It zeros the end elements in an ips_command_t struct starting with the status element */ 68 #define clear_ips_command(command) bzero(&((command)->status), (unsigned long)(&(command)[1])-(unsigned long)&((command)->status)) 69 70 #define ips_read_request(iobuf) ((iobuf)->bio_cmd == BIO_READ) 71 72 #define COMMAND_ERROR(command) (((command)->status.fields.basic_status & IPS_GSC_STATUS_MASK) >= IPS_MIN_ERROR) 73 74 #define ips_set_error(command, error) do { \ 75 (command)->status.fields.basic_status = IPS_DRV_ERROR; \ 76 (command)->status.fields.reserved = ((error) & 0x0f); \ 77 } while (0) 78 79 #ifndef IPS_DEBUG 80 #define DEVICE_PRINTF(x...) 81 #define PRINTF(x...) 82 #else 83 #define DEVICE_PRINTF(level,x...) if(IPS_DEBUG >= level)device_printf(x) 84 #define PRINTF(level,x...) if(IPS_DEBUG >= level)printf(x) 85 #endif 86 87 struct ips_softc; 88 89 typedef struct { 90 u_int32_t status[IPS_MAX_CMD_NUM]; 91 u_int32_t base_phys_addr; 92 int nextstatus; 93 bus_dma_tag_t dmatag; 94 bus_dmamap_t dmamap; 95 } ips_copper_queue_t; 96 97 /* used to keep track of current commands to the card */ 98 typedef struct ips_command{ 99 u_int8_t command_number; 100 u_int8_t id; 101 u_int8_t timeout; 102 struct ips_softc * sc; 103 bus_dma_tag_t data_dmatag; 104 bus_dmamap_t data_dmamap; 105 bus_dmamap_t command_dmamap; 106 void * command_buffer; 107 u_int32_t command_phys_addr;/*WARNING! must be changed if 64bit addressing ever used*/ 108 ips_cmd_status_t status; 109 SLIST_ENTRY(ips_command) next; 110 void * data_buffer; 111 void * arg; 112 void (* callback)(struct ips_command *command); 113 }ips_command_t; 114 115 typedef struct ips_softc{ 116 struct resource * iores; 117 struct resource * irqres; 118 struct intr_config_hook ips_ich; 119 int configured; 120 int state; 121 int iotype; 122 int rid; 123 int irqrid; 124 void * irqcookie; 125 bus_dma_tag_t adapter_dmatag; 126 bus_dma_tag_t command_dmatag; 127 bus_dma_tag_t sg_dmatag; 128 device_t dev; 129 struct cdev *device_file; 130 struct callout timer; 131 u_int16_t adapter_type; 132 ips_adapter_info_t adapter_info; 133 device_t diskdev[IPS_MAX_NUM_DRIVES]; 134 ips_drive_t drives[IPS_MAX_NUM_DRIVES]; 135 u_int8_t drivecount; 136 u_int16_t ffdc_resetcount; 137 struct timeval ffdc_resettime; 138 u_int8_t next_drive; 139 u_int8_t max_cmds; 140 volatile u_int8_t used_commands; 141 ips_command_t *commandarray; 142 ips_command_t *staticcmd; 143 SLIST_HEAD(command_list, ips_command) free_cmd_list; 144 int (* ips_adapter_reinit)(struct ips_softc *sc, 145 int force); 146 void (* ips_adapter_intr)(void *sc); 147 void (* ips_issue_cmd)(ips_command_t *command); 148 void (* ips_poll_cmd)(ips_command_t *command); 149 ips_copper_queue_t * copper_queue; 150 struct mtx queue_mtx; 151 struct bio_queue_head queue; 152 struct sema cmd_sema; 153 154 }ips_softc_t; 155 156 /* function defines from ips_ioctl.c */ 157 extern int ips_ioctl_request(ips_softc_t *sc, u_long ioctl_cmd, caddr_t addr, 158 int32_t flags); 159 /* function defines from ips_disk.c */ 160 extern void ipsd_finish(struct bio *iobuf); 161 162 /* function defines from ips_commands.c */ 163 extern int ips_flush_cache(ips_softc_t *sc); 164 extern void ips_start_io_request(ips_softc_t *sc); 165 extern int ips_get_drive_info(ips_softc_t *sc); 166 extern int ips_get_adapter_info(ips_softc_t *sc); 167 extern int ips_ffdc_reset(ips_softc_t *sc); 168 extern int ips_update_nvram(ips_softc_t *sc); 169 extern int ips_clear_adapter(ips_softc_t *sc); 170 171 /* function defines from ips.c */ 172 extern int ips_get_free_cmd(ips_softc_t *sc, ips_command_t **command, unsigned long flags); 173 extern void ips_insert_free_cmd(ips_softc_t *sc, ips_command_t *command); 174 extern int ips_adapter_init(ips_softc_t *sc); 175 extern int ips_morpheus_reinit(ips_softc_t *sc, int force); 176 extern int ips_adapter_free(ips_softc_t *sc); 177 extern void ips_morpheus_intr(void *sc); 178 extern void ips_issue_morpheus_cmd(ips_command_t *command); 179 extern void ips_morpheus_poll(ips_command_t *command); 180 extern int ips_copperhead_reinit(ips_softc_t *sc, int force); 181 extern void ips_copperhead_intr(void *sc); 182 extern void ips_issue_copperhead_cmd(ips_command_t *command); 183 extern void ips_copperhead_poll(ips_command_t *command); 184 185 #endif 186 #endif 187