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