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