xref: /openbsd/sys/dev/ic/mfivar.h (revision 0704c0ab)
1 /* $OpenBSD: mfivar.h,v 1.53 2013/05/03 02:46:28 dlg Exp $ */
2 /*
3  * Copyright (c) 2006 Marco Peereboom <marco@peereboom.us>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 struct mfi_softc;
19 #define DEVNAME(_s)	((_s)->sc_dev.dv_xname)
20 
21 /* #define MFI_DEBUG */
22 #ifdef MFI_DEBUG
23 extern uint32_t			mfi_debug;
24 #define DPRINTF(x...)		do { if (mfi_debug) printf(x); } while(0)
25 #define DNPRINTF(n,x...)	do { if (mfi_debug & n) printf(x); } while(0)
26 #define	MFI_D_CMD		0x0001
27 #define	MFI_D_INTR		0x0002
28 #define	MFI_D_MISC		0x0004
29 #define	MFI_D_DMA		0x0008
30 #define	MFI_D_IOCTL		0x0010
31 #define	MFI_D_RW		0x0020
32 #define	MFI_D_MEM		0x0040
33 #define	MFI_D_CCB		0x0080
34 #else
35 #define DPRINTF(x...)
36 #define DNPRINTF(n,x...)
37 #endif
38 
39 struct mfi_mem {
40 	bus_dmamap_t		am_map;
41 	bus_dma_segment_t	am_seg;
42 	size_t			am_size;
43 	caddr_t			am_kva;
44 };
45 
46 #define MFIMEM_MAP(_am)		((_am)->am_map)
47 #define MFIMEM_LEN(_am)		((_am)->am_map->dm_mapsize)
48 #define MFIMEM_DVA(_am)		((_am)->am_map->dm_segs[0].ds_addr)
49 #define MFIMEM_KVA(_am)		((void *)(_am)->am_kva)
50 
51 struct mfi_prod_cons {
52 	uint32_t		mpc_producer;
53 	uint32_t		mpc_consumer;
54 	uint32_t		mpc_reply_q[1]; /* compensate for 1 extra reply per spec */
55 };
56 
57 struct mfi_ccb {
58 	union mfi_frame		*ccb_frame;
59 	paddr_t			ccb_pframe;
60 	bus_addr_t		ccb_pframe_offset;
61 	uint32_t		ccb_frame_size;
62 	uint32_t		ccb_extra_frames;
63 
64 	struct mfi_sense	*ccb_sense;
65 	paddr_t			ccb_psense;
66 
67 	bus_dmamap_t		ccb_dmamap;
68 
69 	union mfi_sgl		*ccb_sgl;
70 
71 	/* data for sgl */
72 	void			*ccb_data;
73 	uint32_t		ccb_len;
74 
75 	uint32_t		ccb_direction;
76 #define MFI_DATA_NONE	0
77 #define MFI_DATA_IN	1
78 #define MFI_DATA_OUT	2
79 
80 	void			*ccb_cookie;
81 	void			(*ccb_done)(struct mfi_softc *,
82 				    struct mfi_ccb *);
83 
84 	volatile enum {
85 		MFI_CCB_FREE,
86 		MFI_CCB_READY,
87 		MFI_CCB_DONE
88 	}			ccb_state;
89 	uint32_t		ccb_flags;
90 #define MFI_CCB_F_ERR			(1<<0)
91 	SLIST_ENTRY(mfi_ccb)	ccb_link;
92 };
93 
94 SLIST_HEAD(mfi_ccb_list, mfi_ccb);
95 
96 enum mfi_iop {
97 	MFI_IOP_XSCALE,
98 	MFI_IOP_PPC,
99 	MFI_IOP_GEN2,
100 	MFI_IOP_SKINNY
101 };
102 
103 struct mfi_iop_ops {
104 	u_int32_t	(*mio_fw_state)(struct mfi_softc *);
105 	void		(*mio_intr_ena)(struct mfi_softc *);
106 	int		(*mio_intr)(struct mfi_softc *);
107 	void		(*mio_post)(struct mfi_softc *, struct mfi_ccb *);
108 	u_int32_t	mio_idb;
109 	u_int32_t	mio_flags;
110 #define MFI_IOP_F_SYSPD		(1 << 0)
111 };
112 
113 struct mfi_pd_link {
114 	u_int16_t		pd_id;
115 	struct mfi_pd_details	pd_info;
116 };
117 
118 struct mfi_pd_softc {
119 	struct scsi_link	pd_link;
120 	struct scsibus_softc	*pd_scsibus;
121 	struct mfi_pd_link	*pd_links[MFI_MAX_PD];
122 };
123 
124 struct mfi_softc {
125 	struct device		sc_dev;
126 	void			*sc_ih;
127 	struct scsi_link	sc_link;
128 	struct scsi_iopool	sc_iopool;
129 
130 	const struct mfi_iop_ops *sc_iop;
131 
132 	int			sc_64bit_dma;
133 
134 	bus_space_tag_t		sc_iot;
135 	bus_space_handle_t	sc_ioh;
136 	bus_dma_tag_t		sc_dmat;
137 
138 	/* save some useful information for logical drives that is missing
139 	 * in sc_ld_list
140 	 */
141 	struct {
142 		uint32_t	ld_present;
143 		char		ld_dev[16];	/* device name sd? */
144 	}			sc_ld[MFI_MAX_LD];
145 
146 	/* scsi ioctl from sd device */
147 	int			(*sc_ioctl)(struct device *, u_long, caddr_t);
148 
149 	/* firmware determined max, totals and other information*/
150 	uint32_t		sc_max_cmds;
151 	uint32_t		sc_max_sgl;
152 	uint32_t		sc_sgl_size;
153 	uint32_t		sc_ld_cnt;
154 
155 	uint16_t		sc_sgl_flags;
156 	uint16_t		sc_reserved;
157 
158 	/* bio */
159 	struct mfi_conf		*sc_cfg;
160 	struct mfi_ctrl_info	sc_info;
161 	struct mfi_ld_list	sc_ld_list;
162 	struct mfi_ld_details	*sc_ld_details; /* array to all logical disks */
163 	int			sc_no_pd; /* used physical disks */
164 	int			sc_ld_sz; /* sizeof sc_ld_details */
165 
166 	/* all commands */
167 	struct mfi_ccb		*sc_ccb;
168 
169 	/* producer/consumer pointers and reply queue */
170 	struct mfi_mem		*sc_pcq;
171 
172 	/* frame memory */
173 	struct mfi_mem		*sc_frames;
174 	uint32_t		sc_frames_size;
175 
176 	/* sense memory */
177 	struct mfi_mem		*sc_sense;
178 
179 	struct mfi_ccb_list	sc_ccb_freeq;
180 	struct mutex		sc_ccb_mtx;
181 
182 	struct scsibus_softc	*sc_scsibus;
183 	struct mfi_pd_softc	*sc_pd;
184 
185 	/* mgmt lock */
186 	struct rwlock		sc_lock;
187 
188 	/* sensors */
189 	struct ksensordev	sc_sensordev;
190 	struct ksensor		*sc_bbu;
191 	struct ksensor		*sc_bbu_status;
192 	struct ksensor		*sc_sensors;
193 };
194 
195 int	mfi_attach(struct mfi_softc *sc, enum mfi_iop);
196 int	mfi_intr(void *);
197