2 * Copyright (c) 2002 Adaptec Inc.
5 * Written by: David Jeffery
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
41 #include <sys/types.h>
42 #include <sys/queue.h>
44 #include <sys/malloc.h>
45 #include <sys/mutex.h>
49 #include <machine/bus.h>
51 #include <machine/resource.h>
53 MALLOC_DECLARE(M_IPSBUF);
59 #define ips_read_1(sc,offset) bus_space_read_1(sc->bustag, sc->bushandle, offset)
60 #define ips_read_2(sc,offset) bus_space_read_2(sc->bustag, sc->bushandle, offset)
61 #define ips_read_4(sc,offset) bus_space_read_4(sc->bustag, sc->bushandle, offset)
63 #define ips_write_1(sc,offset,value) bus_space_write_1(sc->bustag, sc->bushandle, offset, value)
64 #define ips_write_2(sc,offset,value) bus_space_write_2(sc->bustag, sc->bushandle, offset, value)
65 #define ips_write_4(sc,offset,value) bus_space_write_4(sc->bustag, sc->bushandle, offset, value)
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))
70 #define ips_read_request(iobuf) ((iobuf)->bio_cmd == BIO_READ)
72 #define COMMAND_ERROR(command) (((command)->status.fields.basic_status & IPS_GSC_STATUS_MASK) >= IPS_MIN_ERROR)
74 #define ips_set_error(command, error) do { \
75 (command)->status.fields.basic_status = IPS_DRV_ERROR; \
76 (command)->status.fields.reserved = ((error) & 0x0f); \
80 #define DEVICE_PRINTF(x...)
83 #define DEVICE_PRINTF(level,x...) if(IPS_DEBUG >= level)device_printf(x)
84 #define PRINTF(level,x...) if(IPS_DEBUG >= level)printf(x)
90 u_int32_t status[IPS_MAX_CMD_NUM];
91 u_int32_t base_phys_addr;
97 /* used to keep track of current commands to the card */
98 typedef struct ips_command{
99 u_int8_t command_number;
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;
112 void (* callback)(struct ips_command *command);
115 typedef struct ips_softc{
116 struct resource * iores;
117 struct resource * irqres;
118 struct intr_config_hook ips_ich;
125 bus_space_tag_t bustag;
126 bus_space_handle_t bushandle;
127 bus_dma_tag_t adapter_dmatag;
128 bus_dma_tag_t command_dmatag;
129 bus_dma_tag_t sg_dmatag;
131 struct cdev *device_file;
132 struct callout_handle timer;
133 u_int16_t adapter_type;
134 ips_adapter_info_t adapter_info;
135 device_t diskdev[IPS_MAX_NUM_DRIVES];
136 ips_drive_t drives[IPS_MAX_NUM_DRIVES];
138 u_int16_t ffdc_resetcount;
139 struct timeval ffdc_resettime;
142 volatile u_int8_t used_commands;
143 ips_command_t *commandarray;
144 ips_command_t *staticcmd;
145 SLIST_HEAD(command_list, ips_command) free_cmd_list;
146 int (* ips_adapter_reinit)(struct ips_softc *sc,
148 void (* ips_adapter_intr)(void *sc);
149 void (* ips_issue_cmd)(ips_command_t *command);
150 void (* ips_poll_cmd)(ips_command_t *command);
151 ips_copper_queue_t * copper_queue;
152 struct mtx queue_mtx;
153 struct bio_queue_head queue;
154 struct sema cmd_sema;
158 /* function defines from ips_ioctl.c */
159 extern int ips_ioctl_request(ips_softc_t *sc, u_long ioctl_cmd, caddr_t addr,
161 /* function defines from ips_disk.c */
162 extern void ipsd_finish(struct bio *iobuf);
164 /* function defines from ips_commands.c */
165 extern int ips_flush_cache(ips_softc_t *sc);
166 extern void ips_start_io_request(ips_softc_t *sc);
167 extern int ips_get_drive_info(ips_softc_t *sc);
168 extern int ips_get_adapter_info(ips_softc_t *sc);
169 extern int ips_ffdc_reset(ips_softc_t *sc);
170 extern int ips_update_nvram(ips_softc_t *sc);
171 extern int ips_clear_adapter(ips_softc_t *sc);
173 /* function defines from ips.c */
174 extern int ips_get_free_cmd(ips_softc_t *sc, ips_command_t **command, unsigned long flags);
175 extern void ips_insert_free_cmd(ips_softc_t *sc, ips_command_t *command);
176 extern int ips_adapter_init(ips_softc_t *sc);
177 extern int ips_morpheus_reinit(ips_softc_t *sc, int force);
178 extern int ips_adapter_free(ips_softc_t *sc);
179 extern void ips_morpheus_intr(void *sc);
180 extern void ips_issue_morpheus_cmd(ips_command_t *command);
181 extern void ips_morpheus_poll(ips_command_t *command);
182 extern int ips_copperhead_reinit(ips_softc_t *sc, int force);
183 extern void ips_copperhead_intr(void *sc);
184 extern void ips_issue_copperhead_cmd(ips_command_t *command);
185 extern void ips_copperhead_poll(ips_command_t *command);