1 /* $OpenBSD: twereg.h,v 1.10 2023/04/11 00:45:08 jsg Exp $ */ 2 3 /* 4 * Copyright (c) 2000 Michael Shalayeff 5 * All rights reserved. 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 ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 26 * THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 /* 29 * most of the meaning for registers were taken from 30 * freebsd driver, which in turn got 'em from linux. 31 * it seems those got 'em from windows driver, in turn. 32 */ 33 34 35 /* general parameters */ 36 #define TWE_MAX_UNITS 16 37 #define TWE_MAXOFFSETS 62 38 #define TWE_MAXCMDS 255 39 #define TWE_SECTOR_SIZE 512 40 #define TWE_ALIGN 512 41 #define TWE_MAXFER (TWE_MAXOFFSETS * PAGE_SIZE) 42 43 /* registers */ 44 #define TWE_CONTROL 0x00 45 #define TWE_CTRL_CHOSTI 0x00080000 /* clear host int */ 46 #define TWE_CTRL_CATTNI 0x00040000 /* clear attention int */ 47 #define TWE_CTRL_MCMDI 0x00020000 /* mask cmd int */ 48 #define TWE_CTRL_MRDYI 0x00010000 /* mask ready int */ 49 #define TWE_CTRL_ECMDI 0x00008000 /* enable cmd int */ 50 #define TWE_CTRL_ERDYI 0x00004000 /* enable ready int */ 51 #define TWE_CTRL_CERR 0x00000200 /* clear error status */ 52 #define TWE_CTRL_SRST 0x00000100 /* soft reset */ 53 #define TWE_CTRL_EINT 0x00000080 /* enable ints */ 54 #define TWE_CTRL_MINT 0x00000040 /* mask ints */ 55 #define TWE_CTRL_HOSTI 0x00000020 /* generate host int */ 56 #define TWE_STATUS 0x04 57 #define TWE_STAT_MAJV 0xf0000000 58 #define TWE_MAJV(st) (((st) >> 28) & 0xf) 59 #define TWE_STAT_MINV 0x0f000000 60 #define TWE_MINV(st) (((st) >> 24) & 0xf) 61 #define TWE_STAT_PCIPAR 0x00800000 62 #define TWE_STAT_QUEUEE 0x00400000 63 #define TWE_STAT_CPUERR 0x00200000 64 #define TWE_STAT_PCIABR 0x00100000 65 #define TWE_STAT_HOSTI 0x00080000 66 #define TWE_STAT_ATTNI 0x00040000 67 #define TWE_STAT_CMDI 0x00020000 68 #define TWE_STAT_RDYI 0x00010000 69 #define TWE_STAT_CQF 0x00008000 /* cmd queue full */ 70 #define TWE_STAT_RQE 0x00004000 /* ready queue empty */ 71 #define TWE_STAT_CPURDY 0x00002000 /* cpu ready */ 72 #define TWE_STAT_CQR 0x00001000 /* cmd queue ready */ 73 #define TWE_STAT_FLAGS 0x00fff000 /* mask out other stuff */ 74 #define TWE_STAT_BITS "\020\015cqr\016cpurdy\017rqe\20cqf" \ 75 "\021rdyi\022cmdi\023attni\024hosti\025pciabr\026cpuerr\027queuee\030pcipar" 76 77 #define TWE_COMMANDQUEUE 0x08 78 /* 79 * the segs offset is encoded into upper 3 bits of the opcode. 80 * i bet other bits mean something too 81 * upper 8 bits is the command size in 32bit words. 82 */ 83 #define TWE_CMD_NOP 0x0200 84 #define TWE_CMD_INIT 0x0301 85 #define TWE_CMD_READ 0x0362 86 #define TWE_CMD_WRITE 0x0363 87 #define TWE_CMD_RDVRFY 0x0364 88 #define TWE_CMD_VERIFY 0x0365 89 #define TWE_CMD_ZRFUNIT 0x0208 90 #define TWE_CMD_RPLUNIT 0x0209 91 #define TWE_CMD_HOTSWAP 0x020a 92 #define TWE_CMD_SETATA 0x020c 93 #define TWE_CMD_FLUSH 0x020e 94 #define TWE_CMD_ABORT 0x020f 95 #define TWE_CMD_QSTAT 0x0210 96 #define TWE_CMD_GPARAM 0x0252 97 #define TWE_CMD_SPARAM 0x0253 98 #define TWE_CMD_NEWUNIT 0x0214 99 #define TWE_CMD_DELUNIT 0x0215 100 #define TWE_CMD_RBLUNIT 0x0217 /* rebuild */ 101 #define TWE_CMD_SECINF 0x021a 102 #define TWE_CMD_AEN 0x021c 103 #define TWE_CMD_CMDPK 0x021d 104 #define TWE_READYQUEUE 0x0c 105 #define TWE_READYID(u) (((u) >> 4) & 0xff) 106 107 /* 108 * From 3ware's documentation: 109 * 110 * All parameters maintained by the controller are grouped into related 111 * tables. Tables are accessed indirectly via get and set parameter 112 * commands. To access a specific parameter in a table, the table ID and 113 * parameter index are used to uniquely identify a parameter. Table 114 * 0xffff is the directory table and provides a list of the table IDs and 115 * sizes of all other tables. Index zero in each table specifies the 116 * entire table, and index one specifies the size of the table. An entire 117 * table can be read or set by using index zero. 118 */ 119 120 /* get/set param table ids */ 121 #define TWE_PARAM_ALL 0x000 /* everything */ 122 #define TWE_PARAM_DSUM 0x002 /* drive summary */ 123 #define TWE_PARAM_UC 0x003 /* unit config */ 124 #define TWE_PARAM_DC 0x200 /* + 15 -- drive config (doc says 0x100) */ 125 #define TWE_PARAM_UI 0x300 /* + 16 -- unit information */ 126 #define TWE_PARAM_AEN 0x401 127 #define TWE_PARAM_VER 0x402 /* version info */ 128 #define TWE_PARAM_CTRL 0x403 /* controller info */ 129 #define TWE_PARAM_FTRS 0x404 /* features */ 130 #define TWE_PARAM_DIR 0xffff /* param table directory */ 131 132 #define TWE_AEN_QEMPTY 0x0000 133 #define TWE_AEN_SRST 0x0001 /* soft reset */ 134 #define TWE_AEN_DMIRROR 0x0002 /* degraded mirror */ 135 #define TWE_AEN_CERROR 0x0003 /* controller error */ 136 #define TWE_AEN_RBFAIL 0x0004 /* rebuild failed */ 137 #define TWE_AEN_RBDONE 0x0005 /* rebuild done */ 138 #define TWE_AEN_ILLUN 0x0006 /* incompatible unit */ 139 #define TWE_AEN_INDONE 0x0007 /* init done */ 140 #define TWE_AEN_DSHUT 0x0008 /* unclean shutdown */ 141 #define TWE_AEN_APORT 0x0009 /* aport timeout */ 142 #define TWE_AEN_DRVERR 0x000a /* drive error */ 143 #define TWE_AEN_RBSTART 0x000b /* rebuild start */ 144 #define TWE_AEN_ISTART 0x000c /* init started */ 145 #define TWE_AEN_TUN 0x0015 /* table undefined */ 146 /* TWE_AEN_ 0x0000 * dunno what this is (yet) */ 147 #define TWE_AEN_QFULL 0x00ff 148 149 /* struct definitions */ 150 struct twe_param { 151 u_int16_t table_id; 152 u_int8_t param_id; 153 u_int8_t param_size; 154 u_int8_t data[1]; 155 } __packed; 156 157 struct twe_segs { 158 u_int32_t twes_addr; 159 u_int32_t twes_len; 160 } __packed; 161 162 struct twe_cmd { 163 u_int16_t cmd_op; 164 u_int8_t cmd_index; 165 u_int8_t cmd_unit_host; 166 #define TWE_UNITHOST(u, h) (((u) & 0xf) | ((h) << 4)) 167 u_int8_t cmd_status; 168 u_int8_t cmd_flags; 169 #define TWE_FLAGS_CACHEDISABLE 0x01 170 union { 171 struct { 172 u_int16_t count; 173 u_int32_t lba; 174 struct twe_segs segs[TWE_MAXOFFSETS]; 175 u_int32_t pad; 176 } __packed _cmd_io; 177 #define cmd_io _._cmd_io 178 struct { 179 u_int16_t count; 180 struct twe_segs segs[TWE_MAXOFFSETS]; 181 } __packed _cmd_param; 182 #define cmd_param _._cmd_param 183 struct { 184 u_int16_t msgcr; 185 u_int32_t rdy_q_ptr; 186 } __packed _cmd_init; 187 #define cmd_init _._cmd_init 188 struct { 189 u_int8_t action; 190 #define TWE_HSWAP_REMOVE 0 191 #define TWE_HSWAP_ADDCBOD 1 192 #define TWE_HSWAP_ADDSPARE 2 193 u_int8_t port; 194 } __packed _cmd_aport; 195 #define cmd_hswap _._cmd_hswap 196 struct { 197 u_int8_t feature; 198 #define TWE_ATA_WCE 0x02 199 #define TWE_ATA_NWCE 0x82 200 u_int8_t mode; 201 u_int16_t units; 202 u_int16_t persist; 203 } __packed _cmd_ata; 204 #define cmd_ata _._cmd_ata 205 u_int16_t cmd_status; 206 struct { 207 u_int8_t action; 208 #define TWE_REBUILD_NOP 0 209 #define TWE_REBUILD_STOP 2 210 #define TWE_REBUILD_START 4 211 #define TWE_REBUILD_STARTU 5 212 #define TWE_REBUILD_CS 0x80 213 u_int8_t subunit; /* raid10 lu rebuild */ 214 } __packed _cmd_rebuild; 215 #define cmd_rebuild _._cmd_rebuild 216 } _; 217 } __packed; /* 512 bytes */ 218