1 /*	$OpenBSD: mpt.h,v 1.3 2004/03/20 03:54:16 krw Exp $	*/
2 /*	$NetBSD: mpt.h,v 1.2 2003/07/08 10:06:31 itojun Exp $	*/
3 
4 /*
5  * Copyright (c) 2000, 2001 by Greg Ansley
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 immediately at the beginning of the file, without modification,
12  *    this list of conditions, and the following disclaimer.
13  * 2. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
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 FOR
20  * 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
26  * SUCH DAMAGE.
27  */
28 /*
29  * Additional Copyright (c) 2002 by Matthew Jacob under same license.
30  */
31 
32 /*
33  * mpt.h:
34  *
35  * Generic definitions for LSI Fusion adapters.
36  *
37  * Adapted from the FreeBSD "mpt" driver by Jason R. Thorpe for
38  * Wasabi Systems, Inc.
39  */
40 
41 #ifndef _DEV_IC_MPT_H_
42 #define	_DEV_IC_MPT_H_
43 
44 #include <dev/ic/mpt_openbsd.h>
45 
46 #define MPT_OK (0)
47 #define MPT_FAIL (0x10000)
48 
49 /* Register Offset to chip registers */
50 #define MPT_OFFSET_DOORBELL     0x00
51 #define MPT_OFFSET_SEQUENCE     0x04
52 #define MPT_OFFSET_DIAGNOSTIC   0x08
53 #define MPT_OFFSET_TEST         0x0C
54 #define MPT_OFFSET_RWDATA       0x10
55 #define MPT_OFFSET_RWADDR       0x14
56 #define MPT_OFFSET_INTR_STATUS  0x30
57 #define MPT_OFFSET_INTR_MASK    0x34
58 #define MPT_OFFSET_REQUEST_Q    0x40
59 #define MPT_OFFSET_REPLY_Q      0x44
60 #define MPT_OFFSET_HOST_INDEX   0x50
61 #define MPT_OFFSET_FUBAR        0x90
62 
63 #define MPT_DIAG_SEQUENCE_1     0x04
64 #define MPT_DIAG_SEQUENCE_2     0x0b
65 #define MPT_DIAG_SEQUENCE_3     0x02
66 #define MPT_DIAG_SEQUENCE_4     0x07
67 #define MPT_DIAG_SEQUENCE_5     0x0d
68 
69 /* Bit Maps for DOORBELL register */
70 enum DB_STATE_BITS {
71 	MPT_DB_STATE_RESET   =    0x00000000,
72 	MPT_DB_STATE_READY   =    0x10000000,
73 	MPT_DB_STATE_RUNNING =    0x20000000,
74 	MPT_DB_STATE_FAULT   =    0x40000000,
75 	MPT_DB_STATE_MASK    =    0xf0000000
76 };
77 
78 #define MPT_STATE(v) ((enum DB_STATE_BITS)((v) & MPT_DB_STATE_MASK))
79 
80 #define MPT_DB_LENGTH_SHIFT (16)
81 #define MPT_DB_DATA_MASK (0xffff)
82 
83 #define MPT_DB_DB_USED            0x08000000
84 #define MPT_DB_IS_IN_USE(v) (((v) & MPT_DB_DB_USED) != 0)
85 
86 /*
87  * "Whom" initializor values
88  */
89 #define	MPT_DB_INIT_NOONE       0x00
90 #define	MPT_DB_INIT_BIOS        0x01
91 #define	MPT_DB_INIT_ROMBIOS     0x02
92 #define	MPT_DB_INIT_PCIPEER     0x03
93 #define	MPT_DB_INIT_HOST        0x04
94 #define	MPT_DB_INIT_MANUFACTURE 0x05
95 
96 #define MPT_WHO(v)	\
97 	((v & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT)
98 
99 /* Function Maps for DOORBELL register */
100 enum DB_FUNCTION_BITS {
101 	MPT_FUNC_IOC_RESET    =    0x40000000,
102 	MPT_FUNC_UNIT_RESET   =    0x41000000,
103 	MPT_FUNC_HANDSHAKE    =    0x42000000,
104 	MPT_FUNC_REPLY_REMOVE =    0x43000000,
105 	MPT_FUNC_MASK         =    0xff000000
106 };
107 
108 /* Function Maps for INTERRUPT request register */
109 enum _MPT_INTR_REQ_BITS {
110 	MPT_INTR_DB_BUSY      =    0x80000000,
111 	MPT_INTR_REPLY_READY  =    0x00000008,
112 	MPT_INTR_DB_READY     =    0x00000001
113 };
114 
115 #define MPT_DB_IS_BUSY(v) (((v) & MPT_INTR_DB_BUSY) != 0)
116 #define MPT_DB_INTR(v)    (((v) & MPT_INTR_DB_READY) != 0)
117 #define MPT_REPLY_INTR(v) (((v) & MPT_INTR_REPLY_READY) != 0)
118 
119 /* Function Maps for INTERRUPT make register */
120 enum _MPT_INTR_MASK_BITS {
121 	MPT_INTR_REPLY_MASK   =    0x00000008,
122 	MPT_INTR_DB_MASK      =    0x00000001
123 };
124 
125 /* Function Maps for DIAGNOSTIC make register */
126 enum _MPT_DIAG_BITS {
127 	MPT_DIAG_ENABLED      =    0x00000080,
128 	MPT_DIAG_FLASHBAD     =    0x00000040,
129 	MPT_DIAG_RESET_HIST   =    0x00000020,
130 	MPT_DIAG_TTLI         =    0x00000008,
131 	MPT_DIAG_RESET_IOC    =    0x00000004,
132 	MPT_DIAG_ARM_DISABLE  =    0x00000002,
133 	MPT_DIAG_DME          =    0x00000001
134 };
135 
136 /* Magic addresses in diagnostic memory space */
137 #define MPT_DIAG_IOP_BASE        (0x00000000)
138 #define MPT_DIAG_IOP_SIZE                      (0x00002000)
139 #define MPT_DIAG_GPIO            (0x00030010)
140 #define MPT_DIAG_IOPQ_REG_BASE0  (0x00050004)
141 #define MPT_DIAG_IOPQ_REG_BASE1  (0x00051004)
142 #define MPT_DIAG_MEM_CFG_BASE    (0x00040000)
143 #define MPT_DIAG_CTX0_BASE       (0x000E0000)
144 #define MPT_DIAG_CTX0_SIZE                     (0x00002000)
145 #define MPT_DIAG_CTX1_BASE       (0x001E0000)
146 #define MPT_DIAG_CTX1_SIZE                     (0x00002000)
147 #define MPT_DIAG_FLASH_BASE      (0x00800000)
148 #define MPT_DIAG_RAM_BASE        (0x01000000)
149 #define MPT_DIAG_RAM_SIZE                      (0x00400000)
150 
151 /* GPIO bit assignments */
152 #define MPT_DIAG_GPIO_SCL	(0x00010000)
153 #define MPT_DIAG_GPIO_SDA_OUT	(0x00008000)
154 #define MPT_DIAG_GPIO_SDA_IN	(0x00004000)
155 
156 #define MPT_REPLY_EMPTY   (0xffffffff)    /* Reply Queue Empty Symbol */
157 #define MPT_CONTEXT_REPLY (0x80000000)
158 #define MPT_CONTEXT_MASK  (~0xE0000000)
159 
160 #ifdef _KERNEL
161 int mpt_soft_reset(mpt_softc_t *);
162 void mpt_hard_reset(mpt_softc_t *);
163 int mpt_recv_handshake_reply(mpt_softc_t *, size_t, void *);
164 
165 void mpt_send_cmd(mpt_softc_t *, request_t *);
166 void mpt_free_reply(mpt_softc_t *, u_int32_t);
167 void mpt_enable_ints(mpt_softc_t *);
168 void mpt_disable_ints(mpt_softc_t *);
169 u_int32_t mpt_pop_reply_queue(mpt_softc_t *);
170 int mpt_init(mpt_softc_t *, u_int32_t);
171 int mpt_reset(mpt_softc_t *);
172 int mpt_send_handshake_cmd(mpt_softc_t *, size_t, void *);
173 request_t * mpt_get_request(mpt_softc_t *);
174 void mpt_free_request(mpt_softc_t *, request_t *);
175 void mpt_init_request(mpt_softc_t *, request_t *);
176 int mpt_intr(void *);
177 void mpt_check_doorbell(mpt_softc_t *);
178 
179 int mpt_read_cfg_page(mpt_softc_t *, int, fCONFIG_PAGE_HEADER *);
180 int mpt_write_cfg_page(mpt_softc_t *, int, fCONFIG_PAGE_HEADER *);
181 
182 /* FW Download Boot */
183 int mpt_downloadboot(mpt_softc_t *);
184 int mpt_do_upload(mpt_softc_t *);
185 int mpt_alloc_fw_mem(mpt_softc_t *, uint32_t , int);
186 void mpt_free_fw_mem(mpt_softc_t *);
187 
188 /* mpt_debug.c functions */
189 void mpt_print_reply(void *);
190 void mpt_print_db(u_int32_t);
191 void mpt_print_config_reply(void *);
192 char *mpt_ioc_diag(u_int32_t);
193 char *mpt_req_state(enum mpt_req_state);
194 void mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *);
195 void mpt_print_config_request(void *);
196 void mpt_print_request(void *);
197 #endif /* _KERNEL */
198 
199 #endif /* _DEV_IC_MPT_H_ */
200