xref: /openbsd/sys/dev/ic/amivar.h (revision 7380a3a4)
1 /*	$OpenBSD: amivar.h,v 1.60 2020/07/22 13:16:04 krw Exp $	*/
2 
3 /*
4  * Copyright (c) 2001 Michael Shalayeff
5  * Copyright (c) 2005 Marco Peereboom
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27  * THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 struct ami_mem {
31 	bus_dmamap_t		am_map;
32 	bus_dma_segment_t	am_seg;
33 	size_t			am_size;
34 	caddr_t			am_kva;
35 };
36 
37 #define AMIMEM_MAP(_am)		((_am)->am_map)
38 #define AMIMEM_DVA(_am)		((_am)->am_map->dm_segs[0].ds_addr)
39 #define AMIMEM_KVA(_am)		((void *)(_am)->am_kva)
40 
41 struct ami_ccbmem {
42 	struct ami_passthrough	cd_pt;
43 	struct ami_sgent	cd_sg[AMI_SGEPERCMD];
44 };
45 
46 struct ami_softc;
47 
48 struct ami_ccb {
49 	struct ami_softc	*ccb_sc;
50 
51 	struct ami_iocmd	ccb_cmd;
52 	struct ami_passthrough	*ccb_pt;
53 	paddr_t			ccb_ptpa;
54 	struct ami_sgent	*ccb_sglist;
55 	paddr_t			ccb_sglistpa;
56 	int			ccb_offset;
57 	bus_dmamap_t		ccb_dmamap;
58 
59 	struct scsi_xfer	*ccb_xs;
60 	void			(*ccb_done)(struct ami_softc *sc,
61 				    struct ami_ccb *ccb);
62 
63 	volatile enum {
64 		AMI_CCB_FREE,
65 		AMI_CCB_READY,
66 		AMI_CCB_QUEUED,
67 		AMI_CCB_PREQUEUED
68 	}			ccb_state;
69 	int			ccb_flags;
70 #define AMI_CCB_F_ERR			(1<<0)
71 	int			ccb_status;
72 	TAILQ_ENTRY(ami_ccb)	ccb_link;
73 };
74 
75 TAILQ_HEAD(ami_ccb_list, ami_ccb);
76 
77 struct ami_rawsoftc {
78 	struct ami_softc	*sc_softc;
79 	u_int8_t		sc_channel;
80 
81 	int			sc_proctarget;	/* ses/safte target id */
82 	char			sc_procdev[16];	/* ses/safte device */
83 };
84 
85 struct ami_softc {
86 	struct device		sc_dev;
87 	void			*sc_ih;
88 	struct scsibus_softc	*sc_scsibus;
89 
90 	int			sc_flags;
91 #define AMI_CHECK_SIGN	0x0001
92 #define AMI_BROKEN 	0x0002
93 #define AMI_QUARTZ	0x0008
94 
95 	/* low-level interface */
96 	int			(*sc_init)(struct ami_softc *sc);
97 	int			(*sc_exec)(struct ami_softc *sc,
98 				    struct ami_iocmd *);
99 	int			(*sc_done)(struct ami_softc *sc,
100 				    struct ami_iocmd *);
101 	int			(*sc_poll)(struct ami_softc *sc,
102 				    struct ami_iocmd *);
103 	int			(*sc_ioctl)(struct device *, u_long, caddr_t);
104 
105 	bus_space_tag_t		sc_iot;
106 	bus_space_handle_t	sc_ioh;
107 	bus_dma_tag_t		sc_dmat;
108 
109 	struct ami_ccb		*sc_ccbs;
110 	struct ami_ccb_list	sc_ccb_freeq;
111 	struct mutex		sc_ccb_freeq_mtx;
112 
113 	struct ami_mem		*sc_mbox_am;
114 	volatile struct ami_iocmd *sc_mbox;
115 	paddr_t			sc_mbox_pa;
116 
117 	struct ami_ccb_list	sc_ccb_preq, sc_ccb_runq;
118 	struct mutex		sc_cmd_mtx;
119 
120 	struct scsi_iopool	sc_iopool;
121 
122 	struct ami_mem		*sc_ccbmem_am;
123 
124 	int			sc_timeout;
125 	struct timeout		sc_run_tmo;
126 	int			sc_dis_poll;
127 
128 	struct rwlock		sc_lock;
129 
130 	char			sc_fwver[16];
131 	char			sc_biosver[16];
132 	int			sc_maxcmds;
133 	int			sc_memory;
134 	int			sc_targets;
135 	int			sc_channels;
136 	int			sc_maxunits;
137 	int			sc_nunits;
138 	struct {
139 		u_int8_t		hd_present;
140 		u_int8_t		hd_is_logdrv;
141 		u_int8_t		hd_prop;
142 		u_int8_t		hd_stat;
143 		u_int32_t		hd_size;
144 		char			dev[16];
145 	}			sc_hdr[AMI_BIG_MAX_LDRIVES];
146 	struct ami_rawsoftc	*sc_rawsoftcs;
147 
148 	struct ksensor		*sc_sensors;
149 	struct ksensordev	sc_sensordev;
150 	struct ami_big_diskarray *sc_bd;
151 
152 	/* bio stuff */
153 	struct bioc_inq		sc_bi;
154 	char			sc_plist[AMI_BIG_MAX_PDRIVES];
155 
156 	struct ami_ccb		*sc_mgmtccb;
157 	int			sc_drainio;
158 	u_int8_t		sc_drvinscnt;
159 };
160 
161 int  ami_attach(struct ami_softc *sc);
162 int  ami_intr(void *);
163 
164 int ami_quartz_init(struct ami_softc *sc);
165 int ami_quartz_exec(struct ami_softc *sc, struct ami_iocmd *);
166 int ami_quartz_done(struct ami_softc *sc, struct ami_iocmd *);
167 int ami_quartz_poll(struct ami_softc *sc, struct ami_iocmd *);
168 
169 int ami_schwartz_init(struct ami_softc *sc);
170 int ami_schwartz_exec(struct ami_softc *sc, struct ami_iocmd *);
171 int ami_schwartz_done(struct ami_softc *sc, struct ami_iocmd *);
172 int ami_schwartz_poll(struct ami_softc *sc, struct ami_iocmd *);
173 
174 #ifdef AMI_DEBUG
175 void ami_print_mbox(struct ami_iocmd *);
176 #endif /* AMI_DEBUG */
177