1 /*	$OpenBSD: amivar.h,v 1.6 2003/06/02 19:24:22 mickey Exp $	*/
2 
3 /*
4  * Copyright (c) 2001 Michael Shalayeff
5  * All rights reserved.
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, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  * THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 struct ami_softc;
30 
31 struct ami_ccb {
32 	struct ami_softc	*ccb_sc;
33 	struct ami_iocmd	*ccb_cmd;
34 	paddr_t			ccb_cmdpa;
35 	struct ami_sgent	*ccb_sglist;
36 	paddr_t			ccb_sglistpa;
37 	struct scsi_xfer	*ccb_xs;
38 	struct ami_ccb		*ccb_ccb1;	/* for passthrough */
39 	TAILQ_ENTRY(ami_ccb)	ccb_link;
40 	enum {
41 		AMI_CCB_FREE, AMI_CCB_READY, AMI_CCB_QUEUED, AMI_CCB_PREQUEUED
42 	} ccb_state;
43 	int			ccb_len;
44 	void			*ccb_data;
45 	bus_dmamap_t		ccb_dmamap;
46 };
47 
48 typedef TAILQ_HEAD(ami_queue_head, ami_ccb)	ami_queue_head;
49 
50 struct ami_rawsoftc {
51 	struct scsi_link sc_link;
52 	struct ami_softc *sc_softc;
53 	u_int8_t	sc_channel;
54 };
55 
56 struct ami_softc {
57 	struct device	sc_dev;
58 	void		*sc_ih;
59 	struct scsi_link sc_link;
60 
61 	u_int	sc_flags;
62 
63 	/* low-level interface */
64 	int (*sc_init)(struct ami_softc *sc);
65 	int (*sc_exec)(struct ami_softc *sc, struct ami_iocmd *);
66 	int (*sc_done)(struct ami_softc *sc, struct ami_iocmd *);
67 
68 	bus_space_tag_t	iot;
69 	bus_space_handle_t ioh;
70 	bus_dma_tag_t	dmat;
71 
72 	volatile struct ami_iocmd *sc_mbox;
73 	paddr_t		sc_mbox_pa;
74 	struct ami_ccb	sc_ccbs[AMI_MAXCMDS];
75 	ami_queue_head	sc_free_ccb, sc_ccbq, sc_ccbdone;
76 
77 	void		*sc_cmds;
78 	bus_dmamap_t	sc_cmdmap;
79 	bus_dma_segment_t sc_cmdseg[1];
80 
81 	void		*sc_sgents;
82 	bus_dmamap_t	sc_sgmap;
83 	bus_dma_segment_t sc_sgseg[1];
84 
85 	int		sc_timeout;
86 	struct timeout	sc_requeue_tmo;
87 	struct timeout	sc_poll_tmo;
88 
89 	char	sc_fwver[16];
90 	char	sc_biosver[16];
91 	int	sc_maxcmds;
92 	int	sc_memory;
93 	int	sc_targets;
94 	int	sc_channels;
95 	int	sc_maxunits;
96 	int	sc_nunits;
97 	struct {
98 		u_int8_t	hd_present;
99 		u_int8_t	hd_is_logdrv;
100 		u_int8_t	hd_heads;
101 		u_int8_t	hd_secs;
102 		u_int8_t	hd_prop;
103 		u_int8_t	hd_stat;
104 		u_int32_t	hd_size;
105 	} sc_hdr[AMI_BIG_MAX_LDRIVES];
106 	struct ami_rawsoftc *sc_rawsoftcs;
107 };
108 
109 /* XXX These have to become spinlocks in case of SMP */
110 #define AMI_LOCK_AMI(sc) splbio()
111 #define AMI_UNLOCK_AMI(sc, lock) splx(lock)
112 typedef int ami_lock_t;
113 
114 int  ami_attach(struct ami_softc *sc);
115 int  ami_intr(void *);
116 
117 int ami_quartz_init(struct ami_softc *sc);
118 int ami_quartz_exec(struct ami_softc *sc, struct ami_iocmd *);
119 int ami_quartz_done(struct ami_softc *sc, struct ami_iocmd *);
120 
121 int ami_schwartz_init(struct ami_softc *sc);
122 int ami_schwartz_exec(struct ami_softc *sc, struct ami_iocmd *);
123 int ami_schwartz_done(struct ami_softc *sc, struct ami_iocmd *);
124 
125