xref: /openbsd/sys/dev/ic/twevar.h (revision 5af055cd)
1 /*	$OpenBSD: twevar.h,v 1.10 2011/04/03 15:49:16 dlg Exp $	*/
2 
3 /*
4  * Copyright (c) 2000 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 twe_softc;
30 
31 struct twe_ccb {
32 	struct twe_softc	*ccb_sc;
33 	struct twe_cmd		*ccb_cmd;
34 	struct scsi_xfer	*ccb_xs;
35 	paddr_t			ccb_cmdpa;
36 	TAILQ_ENTRY(twe_ccb)	ccb_link;
37 	enum {
38 		TWE_CCB_FREE, TWE_CCB_READY, TWE_CCB_QUEUED, TWE_CCB_PREQUEUED,
39 		TWE_CCB_DONE
40 	} ccb_state;
41 	int			ccb_length;
42 	void			*ccb_data;
43 	void			*ccb_realdata;
44 	bus_dmamap_t		ccb_dmamap;
45 	bus_dma_segment_t	ccb_2bseg[TWE_MAXOFFSETS];
46 	int			ccb_2nseg;
47 };
48 
49 typedef TAILQ_HEAD(twe_queue_head, twe_ccb)	twe_queue_head;
50 
51 struct twe_softc {
52 	struct device	sc_dev;
53 	void		*sc_ih;
54 	struct scsi_link sc_link;
55 	struct proc	*sc_thread;
56 	int		sc_thread_on;
57 
58 	bus_space_tag_t	iot;
59 	bus_space_handle_t ioh;
60 	bus_dma_tag_t	dmat;
61 
62 	void *sc_cmds;
63 	bus_dmamap_t	sc_cmdmap;
64 	bus_dma_segment_t sc_cmdseg[1];
65 	struct twe_ccb	sc_ccbs[TWE_MAXCMDS];
66 	twe_queue_head	sc_free_ccb;
67 	twe_queue_head	sc_ccbq;
68 	twe_queue_head	sc_ccb2q;
69 	twe_queue_head	sc_done_ccb;
70 	struct mutex	sc_ccb_mtx;
71 	struct scsi_iopool sc_iopool;
72 
73 	struct timeout	sc_enqueue_tmo;
74 
75 	struct scsi_iohandler sc_aen;
76 
77 	struct {
78 		int	hd_present;
79 		int	hd_devtype;
80 		int	hd_lock;
81 		int	hd_size;
82 	} sc_hdr[TWE_MAX_UNITS];
83 };
84 
85 /* XXX These have to become spinlocks in case of SMP */
86 #define TWE_LOCK(sc) splbio()
87 #define TWE_UNLOCK(sc, lock) splx(lock)
88 typedef int twe_lock_t;
89 
90 void	tweminphys(struct buf *bp, struct scsi_link *sl);
91 int	twe_attach(struct twe_softc *);
92 int	twe_intr(void *);
93