1/* $OpenBSD: mfivar.h,v 1.55 2020/07/22 13:16:04 krw 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
18struct mfi_softc;
19#define DEVNAME(_s)	((_s)->sc_dev.dv_xname)
20
21/* #define MFI_DEBUG */
22#ifdef MFI_DEBUG
23extern 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
39struct 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
51struct 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
57struct 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
94SLIST_HEAD(mfi_ccb_list, mfi_ccb);
95
96enum mfi_iop {
97	MFI_IOP_XSCALE,
98	MFI_IOP_PPC,
99	MFI_IOP_GEN2,
100	MFI_IOP_SKINNY
101};
102
103struct 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_int		(*mio_sgd_load)(struct mfi_softc *, struct mfi_ccb *);
109	u_int32_t	mio_idb;
110	u_int32_t	mio_flags;
111#define MFI_IOP_F_SYSPD		(1 << 0)
112};
113
114struct mfi_pd_link {
115	u_int16_t		pd_id;
116	struct mfi_pd_details	pd_info;
117};
118
119struct mfi_pd_softc {
120	struct scsibus_softc	*pd_scsibus;
121	struct mfi_pd_link	*pd_links[MFI_MAX_PD];
122};
123
124struct mfi_softc {
125	struct device		sc_dev;
126	void			*sc_ih;
127	struct scsi_iopool	sc_iopool;
128
129	const struct mfi_iop_ops *sc_iop;
130
131	int			sc_64bit_dma;
132
133	bus_space_tag_t		sc_iot;
134	bus_space_handle_t	sc_ioh;
135	bus_dma_tag_t		sc_dmat;
136
137	/* save some useful information for logical drives that is missing
138	 * in sc_ld_list
139	 */
140	struct {
141		uint32_t	ld_present;
142		char		ld_dev[16];	/* device name sd? */
143	}			sc_ld[MFI_MAX_LD];
144
145	/* scsi ioctl from sd device */
146	int			(*sc_ioctl)(struct device *, u_long, caddr_t);
147
148	/* firmware determined max, totals and other information*/
149	uint32_t		sc_max_cmds;
150	uint32_t		sc_max_sgl;
151	uint32_t		sc_sgl_size;
152	uint32_t		sc_ld_cnt;
153
154	uint16_t		sc_sgl_flags;
155	uint16_t		sc_reserved;
156
157	/* bio */
158	struct mfi_conf		*sc_cfg;
159	struct mfi_ctrl_info	sc_info;
160	struct mfi_ld_list	sc_ld_list;
161	struct mfi_ld_details	*sc_ld_details; /* array to all logical disks */
162	int			sc_no_pd; /* used physical disks */
163	int			sc_ld_sz; /* sizeof sc_ld_details */
164
165	/* all commands */
166	struct mfi_ccb		*sc_ccb;
167
168	/* producer/consumer pointers and reply queue */
169	struct mfi_mem		*sc_pcq;
170
171	/* frame memory */
172	struct mfi_mem		*sc_frames;
173	uint32_t		sc_frames_size;
174
175	/* sense memory */
176	struct mfi_mem		*sc_sense;
177
178	struct mfi_ccb_list	sc_ccb_freeq;
179	struct mutex		sc_ccb_mtx;
180
181	struct scsibus_softc	*sc_scsibus;
182	struct mfi_pd_softc	*sc_pd;
183
184	/* mgmt lock */
185	struct rwlock		sc_lock;
186
187	/* sensors */
188	struct ksensordev	sc_sensordev;
189	struct ksensor		*sc_bbu;
190	struct ksensor		*sc_bbu_status;
191	struct ksensor		*sc_sensors;
192};
193
194int	mfi_attach(struct mfi_softc *sc, enum mfi_iop);
195int	mfi_intr(void *);
196