xref: /openbsd-src/sys/dev/ic/mpivar.h (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: mpivar.h,v 1.39 2014/09/03 00:46:04 dlg Exp $ */
2 
3 /*
4  * Copyright (c) 2005 David Gwynne <dlg@openbsd.org>
5  * Copyright (c) 2005 Marco Peereboom <marco@openbsd.org>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include <sys/task.h>
21 
22 /* #define MPI_DEBUG */
23 #ifdef MPI_DEBUG
24 extern uint32_t			mpi_debug;
25 #define DPRINTF(x...)		do { if (mpi_debug) printf(x); } while(0)
26 #define DNPRINTF(n,x...)	do { if (mpi_debug & (n)) printf(x); } while(0)
27 #define	MPI_D_CMD		0x0001
28 #define	MPI_D_INTR		0x0002
29 #define	MPI_D_MISC		0x0004
30 #define	MPI_D_DMA		0x0008
31 #define	MPI_D_IOCTL		0x0010
32 #define	MPI_D_RW		0x0020
33 #define	MPI_D_MEM		0x0040
34 #define	MPI_D_CCB		0x0080
35 #define	MPI_D_PPR		0x0100
36 #define	MPI_D_RAID		0x0200
37 #define	MPI_D_EVT		0x0400
38 #else
39 #define DPRINTF(x...)
40 #define DNPRINTF(n,x...)
41 #endif
42 
43 #define MPI_REQUEST_SIZE	512
44 #define MPI_REPLY_SIZE		80
45 #define MPI_REPLYQ_DEPTH	128
46 #define MPI_REPLY_COUNT		(PAGE_SIZE / MPI_REPLY_SIZE)
47 
48 /*
49  * this is the max number of sge's we can stuff in a request frame:
50  * sizeof(scsi_io) + sizeof(sense) + sizeof(sge) * 32 = MPI_REQUEST_SIZE
51  */
52 #define MPI_MAX_SGL		36
53 
54 struct mpi_dmamem {
55 	bus_dmamap_t		mdm_map;
56 	bus_dma_segment_t	mdm_seg;
57 	size_t			mdm_size;
58 	caddr_t			mdm_kva;
59 };
60 #define MPI_DMA_MAP(_mdm)	((_mdm)->mdm_map)
61 #define MPI_DMA_DVA(_mdm)	((u_int64_t)(_mdm)->mdm_map->dm_segs[0].ds_addr)
62 #define MPI_DMA_KVA(_mdm)	((void *)(_mdm)->mdm_kva)
63 
64 struct mpi_ccb_bundle {
65 	struct mpi_msg_scsi_io	mcb_io; /* sgl must follow */
66 	struct mpi_sge		mcb_sgl[MPI_MAX_SGL];
67 	struct scsi_sense_data	mcb_sense;
68 } __packed;
69 
70 struct mpi_softc;
71 
72 struct mpi_rcb {
73 	SIMPLEQ_ENTRY(mpi_rcb)	rcb_link;
74 	void			*rcb_reply;
75 	bus_addr_t		rcb_offset;
76 	u_int32_t		rcb_reply_dva;
77 };
78 SIMPLEQ_HEAD(mpi_rcb_list, mpi_rcb);
79 
80 struct mpi_ccb {
81 	struct mpi_softc	*ccb_sc;
82 	int			ccb_id;
83 
84 	void 			*ccb_cookie;
85 	bus_dmamap_t		ccb_dmamap;
86 
87 	bus_addr_t		ccb_offset;
88 	void			*ccb_cmd;
89 	u_int64_t		ccb_cmd_dva;
90 
91 	volatile enum {
92 		MPI_CCB_FREE,
93 		MPI_CCB_READY,
94 		MPI_CCB_QUEUED
95 	}			ccb_state;
96 	void			(*ccb_done)(struct mpi_ccb *);
97 	struct mpi_rcb		*ccb_rcb;
98 
99 	SLIST_ENTRY(mpi_ccb)	ccb_link;
100 };
101 
102 SLIST_HEAD(mpi_ccb_list, mpi_ccb);
103 
104 struct mpi_softc {
105 	struct device		sc_dev;
106 	struct scsi_link	sc_link;
107 
108 	int			sc_flags;
109 #define MPI_F_SPI			(1<<0)
110 #define MPI_F_RAID			(1<<1)
111 
112 	struct scsibus_softc	*sc_scsibus;
113 
114 	bus_space_tag_t		sc_iot;
115 	bus_space_handle_t	sc_ioh;
116 	bus_size_t		sc_ios;
117 	bus_dma_tag_t		sc_dmat;
118 
119 	u_int8_t		sc_fw_maj;
120 	u_int8_t		sc_fw_min;
121 	u_int8_t		sc_fw_unit;
122 	u_int8_t		sc_fw_dev;
123 
124 	u_int8_t		sc_porttype;
125 	int			sc_maxcmds;
126 	int			sc_maxchdepth;
127 	int			sc_first_sgl_len;
128 	int			sc_chain_len;
129 	int			sc_max_sgl_len;
130 
131 	int			sc_buswidth;
132 	int			sc_target;
133 	int			sc_ioc_number;
134 
135 	struct mpi_dmamem	*sc_requests;
136 	struct mpi_ccb		*sc_ccbs;
137 	struct mpi_ccb_list	sc_ccb_free;
138 	struct mutex		sc_ccb_mtx;
139 	struct scsi_iopool	sc_iopool;
140 
141 	struct mpi_dmamem	*sc_replies;
142 	struct mpi_rcb		*sc_rcbs;
143 	int			sc_repq;
144 
145 	struct mpi_ccb		*sc_evt_ccb;
146 	struct mpi_rcb_list	sc_evt_ack_queue;
147 	struct mutex		sc_evt_ack_mtx;
148 	struct scsi_iohandler	sc_evt_ack_handler;
149 
150 	struct mpi_rcb_list	sc_evt_scan_queue;
151 	struct mutex		sc_evt_scan_mtx;
152 	struct scsi_iohandler	sc_evt_scan_handler;
153 
154 	struct task		sc_evt_rescan;
155 
156 	size_t			sc_fw_len;
157 	struct mpi_dmamem	*sc_fw;
158 
159 	/* scsi ioctl from sd device */
160 	int			(*sc_ioctl)(struct device *, u_long, caddr_t);
161 
162 	struct rwlock		sc_lock;
163 	struct mpi_cfg_hdr	sc_cfg_hdr;
164 	struct mpi_cfg_ioc_pg2	*sc_vol_page;
165 	struct mpi_cfg_raid_vol	*sc_vol_list;
166 	struct mpi_cfg_raid_vol_pg0 *sc_rpg0;
167 
168 	struct ksensor		*sc_sensors;
169 	struct ksensordev	sc_sensordev;
170 };
171 
172 int	mpi_attach(struct mpi_softc *);
173 void	mpi_detach(struct mpi_softc *);
174 
175 int	mpi_intr(void *);
176