twavar.h revision 1.3.2.2 1 1.3.2.2 kardel /* $NetBSD: twavar.h,v 1.3.2.2 2006/06/01 22:36:49 kardel Exp $ */
2 1.3.2.2 kardel /* $wasabi: twavar.h,v 1.12 2006/05/01 15:16:59 simonb Exp $ */
3 1.3.2.2 kardel /*
4 1.3.2.2 kardel * Copyright (c) 2005-2006 Wasabi Systems, Inc.
5 1.3.2.2 kardel * All rights reserved.
6 1.3.2.2 kardel *
7 1.3.2.2 kardel * Your Wasabi Systems License Agreement specifies the terms and
8 1.3.2.2 kardel * conditions for use and redistribution.
9 1.3.2.2 kardel */
10 1.3.2.2 kardel
11 1.3.2.2 kardel /*-
12 1.3.2.2 kardel * Copyright (c) 2003-04 3ware, Inc.
13 1.3.2.2 kardel * Copyright (c) 2000 Michael Smith
14 1.3.2.2 kardel * Copyright (c) 2000 BSDi
15 1.3.2.2 kardel * All rights reserved.
16 1.3.2.2 kardel *
17 1.3.2.2 kardel * Redistribution and use in source and binary forms, with or without
18 1.3.2.2 kardel * modification, are permitted provided that the following conditions
19 1.3.2.2 kardel * are met:
20 1.3.2.2 kardel * 1. Redistributions of source code must retain the above copyright
21 1.3.2.2 kardel * notice, this list of conditions and the following disclaimer.
22 1.3.2.2 kardel * 2. Redistributions in binary form must reproduce the above copyright
23 1.3.2.2 kardel * notice, this list of conditions and the following disclaimer in the
24 1.3.2.2 kardel * documentation and/or other materials provided with the distribution.
25 1.3.2.2 kardel *
26 1.3.2.2 kardel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
27 1.3.2.2 kardel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.3.2.2 kardel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.3.2.2 kardel * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
30 1.3.2.2 kardel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.3.2.2 kardel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.3.2.2 kardel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.3.2.2 kardel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.3.2.2 kardel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.3.2.2 kardel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.3.2.2 kardel * SUCH DAMAGE.
37 1.3.2.2 kardel *
38 1.3.2.2 kardel * $FreeBSD: src/sys/dev/twa/twa.h,v 1.4 2004/06/16 09:47:00 phk Exp $
39 1.3.2.2 kardel */
40 1.3.2.2 kardel
41 1.3.2.2 kardel /*
42 1.3.2.2 kardel * 3ware driver for 9000 series storage controllers.
43 1.3.2.2 kardel *
44 1.3.2.2 kardel * Author: Vinod Kashyap
45 1.3.2.2 kardel */
46 1.3.2.2 kardel #ifndef _PCI_TWAVAR_H_
47 1.3.2.2 kardel #define _PCI_TWAVAR_H_
48 1.3.2.2 kardel
49 1.3.2.2 kardel #include "locators.h"
50 1.3.2.2 kardel
51 1.3.2.2 kardel struct twa_callbacks {
52 1.3.2.2 kardel void (*tcb_openings)(struct device *, int);
53 1.3.2.2 kardel };
54 1.3.2.2 kardel
55 1.3.2.2 kardel struct twa_drive {
56 1.3.2.2 kardel uint32_t td_id;
57 1.3.2.2 kardel uint64_t td_size;
58 1.3.2.2 kardel struct device *td_dev;
59 1.3.2.2 kardel const struct twa_callbacks *td_callbacks;
60 1.3.2.2 kardel };
61 1.3.2.2 kardel
62 1.3.2.2 kardel /* Per-controller structure. */
63 1.3.2.2 kardel struct twa_softc {
64 1.3.2.2 kardel struct device twa_dv;
65 1.3.2.2 kardel bus_space_tag_t twa_bus_iot; /* bus space tag */
66 1.3.2.2 kardel bus_space_handle_t twa_bus_ioh; /* bus space handle */
67 1.3.2.2 kardel bus_dma_tag_t twa_dma_tag; /* data buffer DMA tag */
68 1.3.2.2 kardel bus_dmamap_t twa_cmd_map; /* DMA map for the array of cmd pkts */
69 1.3.2.2 kardel void *twa_ih; /* interrupt handle cookie */
70 1.3.2.2 kardel caddr_t twa_cmds;
71 1.3.2.2 kardel bus_addr_t twa_cmd_pkt_phys;/* phys addr of first of array of cmd pkts */
72 1.3.2.2 kardel
73 1.3.2.2 kardel pci_chipset_tag_t pc;
74 1.3.2.2 kardel pcitag_t tag;
75 1.3.2.2 kardel /* Request queues and arrays. */
76 1.3.2.2 kardel TAILQ_HEAD(, twa_request) twa_free; /* free request packets */
77 1.3.2.2 kardel TAILQ_HEAD(, twa_request) twa_busy; /* requests busy in the controller */
78 1.3.2.2 kardel TAILQ_HEAD(, twa_request) twa_pending; /* internal requests pending */
79 1.3.2.2 kardel
80 1.3.2.2 kardel struct twa_request *twa_lookup[TWA_Q_LENGTH];/* requests indexed by request_id */
81 1.3.2.2 kardel
82 1.3.2.2 kardel struct twa_request *twa_req_buf;
83 1.3.2.2 kardel struct twa_command_packet *twa_cmd_pkt_buf;
84 1.3.2.2 kardel
85 1.3.2.2 kardel struct twa_drive sc_units[TWA_MAX_UNITS];
86 1.3.2.2 kardel /* AEN handler fields. */
87 1.3.2.2 kardel struct tw_cl_event_packet *twa_aen_queue[TWA_Q_LENGTH];/* circular queue of AENs from firmware */
88 1.3.2.2 kardel uint16_t working_srl; /* driver & firmware negotiated srl */
89 1.3.2.2 kardel uint16_t working_branch; /* branch # of the firmware that the driver is compatible with */
90 1.3.2.2 kardel uint16_t working_build; /* build # of the firmware that the driver is compatible with */
91 1.3.2.2 kardel u_int32_t twa_operating_mode; /* base mode/current mode */
92 1.3.2.2 kardel u_int32_t twa_aen_head; /* AEN queue head */
93 1.3.2.2 kardel u_int32_t twa_aen_tail; /* AEN queue tail */
94 1.3.2.2 kardel u_int32_t twa_current_sequence_id;/* index of the last event + 1 */
95 1.3.2.2 kardel u_int32_t twa_aen_queue_overflow; /* indicates if unretrieved events were overwritten */
96 1.3.2.2 kardel u_int32_t twa_aen_queue_wrapped; /* indicates if AEN queue ever wrapped */
97 1.3.2.2 kardel /* Controller state. */
98 1.3.2.2 kardel u_int32_t twa_state;
99 1.3.2.2 kardel u_int32_t twa_sc_flags;
100 1.3.2.2 kardel #ifdef TWA_DEBUG
101 1.3.2.2 kardel struct twa_q_statistics twa_qstats[TWAQ_COUNT]; /* queue statistics */
102 1.3.2.2 kardel #endif /* TWA_DEBUG */
103 1.3.2.2 kardel
104 1.3.2.2 kardel struct _twa_ioctl_lock{
105 1.3.2.2 kardel u_int32_t lock; /* lock state */
106 1.3.2.2 kardel u_int32_t timeout; /* time at which the lock
107 1.3.2.2 kardel * will become available,
108 1.3.2.2 kardel * even if not released
109 1.3.2.2 kardel */
110 1.3.2.2 kardel } twa_ioctl_lock; /* lock for use by user
111 1.3.2.2 kardel * applications,
112 1.3.2.2 kardel * for synchronization between
113 1.3.2.2 kardel * ioctl calls
114 1.3.2.2 kardel */
115 1.3.2.2 kardel int sc_openings;
116 1.3.2.2 kardel int sc_nunits;
117 1.3.2.2 kardel
118 1.3.2.2 kardel struct twa_request *sc_twa_request;
119 1.3.2.2 kardel };
120 1.3.2.2 kardel
121 1.3.2.2 kardel
122 1.3.2.2 kardel
123 1.3.2.2 kardel /* Possible values of tr->tr_status. */
124 1.3.2.2 kardel #define TWA_CMD_SETUP 0x0 /* being assembled */
125 1.3.2.2 kardel #define TWA_CMD_BUSY 0x1 /* submitted to controller */
126 1.3.2.2 kardel #define TWA_CMD_PENDING 0x2 /* in pending queue */
127 1.3.2.2 kardel #define TWA_CMD_COMPLETE 0x3 /* completed by controller */
128 1.3.2.2 kardel
129 1.3.2.2 kardel /* Possible values of tr->tr_flags. */
130 1.3.2.2 kardel #define TWA_CMD_DATA_IN (1 << 0)
131 1.3.2.2 kardel #define TWA_CMD_DATA_OUT (1 << 1)
132 1.3.2.2 kardel #define TWA_CMD_DATA_COPY_NEEDED (1 << 2)
133 1.3.2.2 kardel #define TWA_CMD_SLEEP_ON_REQUEST (1 << 3)
134 1.3.2.2 kardel #define TWA_CMD_IN_PROGRESS (1 << 4)
135 1.3.2.2 kardel #define TWA_CMD_AEN (1 << 5)
136 1.3.2.2 kardel #define TWA_CMD_AEN_BUSY (1 << 6)
137 1.3.2.2 kardel
138 1.3.2.2 kardel /* Possible values of tr->tr_cmd_pkt_type. */
139 1.3.2.2 kardel #define TWA_CMD_PKT_TYPE_7K (1<<0)
140 1.3.2.2 kardel #define TWA_CMD_PKT_TYPE_9K (1<<1)
141 1.3.2.2 kardel #define TWA_CMD_PKT_TYPE_INTERNAL (1<<2)
142 1.3.2.2 kardel #define TWA_CMD_PKT_TYPE_IOCTL (1<<3)
143 1.3.2.2 kardel #define TWA_CMD_PKT_TYPE_EXTERNAL (1<<4)
144 1.3.2.2 kardel
145 1.3.2.2 kardel /* Possible values of sc->twa_state. */
146 1.3.2.2 kardel #define TWA_STATE_INTR_ENABLED (1<<0) /* interrupts have been enabled */
147 1.3.2.2 kardel #define TWA_STATE_SHUTDOWN (1<<1) /* controller is shut down */
148 1.3.2.2 kardel #define TWA_STATE_OPEN (1<<2) /* control device is open */
149 1.3.2.2 kardel #define TWA_STATE_SIMQ_FROZEN (1<<3) /* simq frozen */
150 1.3.2.2 kardel #define TWA_STATE_REQUEST_WAIT (1<<4)
151 1.3.2.2 kardel
152 1.3.2.2 kardel /* Possible values of sc->twa_ioctl_lock.lock. */
153 1.3.2.2 kardel #define TWA_LOCK_FREE 0x0 /* lock is free */
154 1.3.2.2 kardel #define TWA_LOCK_HELD 0x1 /* lock is held */
155 1.3.2.2 kardel
156 1.3.2.2 kardel /* Driver's request packet. */
157 1.3.2.2 kardel struct twa_request {
158 1.3.2.2 kardel struct twa_command_packet *tr_command;
159 1.3.2.2 kardel /* ptr to cmd pkt submitted to controller */
160 1.3.2.2 kardel u_int32_t tr_request_id;
161 1.3.2.2 kardel /* request id for tracking with firmware */
162 1.3.2.2 kardel void *tr_data;
163 1.3.2.2 kardel /* ptr to data being passed to firmware */
164 1.3.2.2 kardel size_t tr_length;
165 1.3.2.2 kardel /* length of buffer being passed to firmware */
166 1.3.2.2 kardel void *tr_real_data;
167 1.3.2.2 kardel /* ptr to, and length of data passed */
168 1.3.2.2 kardel size_t tr_real_length;
169 1.3.2.2 kardel /* to us from above, in case a buffer copy
170 1.3.2.2 kardel * was done due to non-compliance to
171 1.3.2.2 kardel * alignment requirements
172 1.3.2.2 kardel */
173 1.3.2.2 kardel TAILQ_ENTRY(twa_request) tr_link;
174 1.3.2.2 kardel /* to link this request in a list */
175 1.3.2.2 kardel struct twa_softc *tr_sc;
176 1.3.2.2 kardel /* controller that owns us */
177 1.3.2.2 kardel u_int32_t tr_status;
178 1.3.2.2 kardel /* command status */
179 1.3.2.2 kardel u_int32_t tr_flags;
180 1.3.2.2 kardel /* request flags */
181 1.3.2.2 kardel u_int32_t tr_error;
182 1.3.2.2 kardel /* error encountered before request submission */
183 1.3.2.2 kardel u_int32_t tr_cmd_pkt_type;
184 1.3.2.2 kardel /* request specific data to use during callback */
185 1.3.2.2 kardel void (*tr_callback)(struct twa_request *tr);
186 1.3.2.2 kardel /* callback handler */
187 1.3.2.2 kardel bus_addr_t tr_cmd_phys;
188 1.3.2.2 kardel /* physical address of command in controller space */
189 1.3.2.2 kardel bus_dmamap_t tr_dma_map;
190 1.3.2.2 kardel /* DMA map for data */
191 1.3.2.2 kardel struct buf *bp;
192 1.3.2.2 kardel
193 1.3.2.2 kardel struct ld_twa_softc *tr_ld_sc;
194 1.3.2.2 kardel };
195 1.3.2.2 kardel
196 1.3.2.2 kardel static __inline size_t twa_get_maxsegs(void) {
197 1.3.2.2 kardel size_t max_segs = ((MAXPHYS + PAGE_SIZE - 1) / PAGE_SIZE) + 1;
198 1.3.2.2 kardel #ifdef TWA_SG_SIZE
199 1.3.2.2 kardel if (TWA_MAX_SG_ELEMENTS < max_segs)
200 1.3.2.2 kardel max_segs = TWA_MAX_SG_ELEMENTS;
201 1.3.2.2 kardel #endif
202 1.3.2.2 kardel return max_segs;
203 1.3.2.2 kardel }
204 1.3.2.2 kardel
205 1.3.2.2 kardel static __inline size_t twa_get_maxxfer(size_t maxsegs) {
206 1.3.2.2 kardel return (maxsegs - 1) * PAGE_SIZE;
207 1.3.2.2 kardel }
208 1.3.2.2 kardel
209 1.3.2.2 kardel struct twa_attach_args {
210 1.3.2.2 kardel int twaa_unit;
211 1.3.2.2 kardel };
212 1.3.2.2 kardel
213 1.3.2.2 kardel #define twaacf_unit cf_loc[TWACF_UNIT]
214 1.3.2.2 kardel
215 1.3.2.2 kardel struct twa_request *twa_get_request(struct twa_softc *, int);
216 1.3.2.2 kardel struct twa_request *twa_get_request_wait(struct twa_softc *, int);
217 1.3.2.2 kardel int twa_map_request(struct twa_request *);
218 1.3.2.2 kardel void twa_register_callbacks(struct twa_softc *sc, int unit,
219 1.3.2.2 kardel const struct twa_callbacks *);
220 1.3.2.2 kardel void twa_request_wait_handler(struct twa_request *);
221 1.3.2.2 kardel void twa_release_request(struct twa_request *);
222 1.3.2.2 kardel
223 1.3.2.2 kardel /* Error/AEN message structure. */
224 1.3.2.2 kardel struct twa_message {
225 1.3.2.2 kardel u_int32_t code;
226 1.3.2.2 kardel const char *message;
227 1.3.2.2 kardel };
228 1.3.2.2 kardel
229 1.3.2.2 kardel #endif /* !_PCI_TWAVAR_H_ */
230