cacvar.h revision 1.17 1 /* $NetBSD: cacvar.h,v 1.17 2008/03/14 03:30:19 mhitch Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #ifndef _IC_CACVAR_H_
40 #define _IC_CACVAR_H_
41
42 #include <sys/mutex.h>
43 #include <sys/condvar.h>
44
45 #include <dev/sysmon/sysmonvar.h>
46 #include <sys/envsys.h>
47
48 #define CAC_MAX_CCBS 256
49 #define CAC_MAX_XFER (0xffff * 512)
50 #define CAC_SG_SIZE 32
51
52 #define cac_inb(sc, port) \
53 bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh, port)
54 #define cac_inw(sc, port) \
55 bus_space_read_2((sc)->sc_iot, (sc)->sc_ioh, port)
56 #define cac_inl(sc, port) \
57 bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, port)
58 #define cac_outb(sc, port, val) \
59 bus_space_write_1((sc)->sc_iot, (sc)->sc_ioh, port, val)
60 #define cac_outw(sc, port, val) \
61 bus_space_write_2((sc)->sc_iot, (sc)->sc_ioh, port, val)
62 #define cac_outl(sc, port, val) \
63 bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, port, val)
64
65 /*
66 * Stupid macros to deal with alignment/endianness issues.
67 */
68
69 #define CAC_GET1(x) \
70 (((u_char *)&(x))[0])
71 #define CAC_GET2(x) \
72 (((u_char *)&(x))[0] | (((u_char *)&(x))[1] << 8))
73 #define CAC_GET4(x) \
74 ((((u_char *)&(x))[0] | (((u_char *)&(x))[1] << 8)) | \
75 (((u_char *)&(x))[2] << 16 | (((u_char *)&(x))[3] << 24)))
76
77 struct cac_softc;
78 struct cac_ccb;
79
80 struct cac_context {
81 void (*cc_handler)(struct device *, void *, int);
82 struct device *cc_dv;
83 void *cc_context;
84 };
85
86 struct cac_ccb {
87 /* Data the controller will touch - 276 bytes */
88 struct cac_hdr ccb_hdr;
89 struct cac_req ccb_req;
90 struct cac_sgb ccb_seg[CAC_SG_SIZE];
91
92 /* Data the controller won't touch */
93 int ccb_flags;
94 int ccb_datasize;
95 paddr_t ccb_paddr;
96 bus_dmamap_t ccb_dmamap_xfer;
97 SIMPLEQ_ENTRY(cac_ccb) ccb_chain;
98 struct cac_context ccb_context;
99 };
100
101 #define CAC_CCB_DATA_IN 0x0001 /* Map describes inbound xfer */
102 #define CAC_CCB_DATA_OUT 0x0002 /* Map describes outbound xfer */
103 #define CAC_CCB_ACTIVE 0x0004 /* Command submitted to controller */
104
105 struct cac_linkage {
106 struct cac_ccb *(*cl_completed)(struct cac_softc *);
107 int (*cl_fifo_full)(struct cac_softc *);
108 void (*cl_intr_enable)(struct cac_softc *, int);
109 int (*cl_intr_pending)(struct cac_softc *);
110 void (*cl_submit)(struct cac_softc *, struct cac_ccb *);
111 };
112
113 struct cac_softc {
114 struct device sc_dv;
115 kmutex_t sc_mutex;
116 bus_space_tag_t sc_iot;
117 bus_space_handle_t sc_ioh;
118 bus_dma_tag_t sc_dmat;
119 bus_dmamap_t sc_dmamap;
120 int sc_nunits;
121 void *sc_ih;
122 void * sc_ccbs;
123 paddr_t sc_ccbs_paddr;
124 SIMPLEQ_HEAD(, cac_ccb) sc_ccb_free;
125 SIMPLEQ_HEAD(, cac_ccb) sc_ccb_queue;
126 kcondvar_t sc_ccb_cv;
127 struct cac_linkage sc_cl;
128
129 /* scsi ioctl from sd device */
130 int (*sc_ioctl)(struct device *, u_long, void *);
131
132 struct sysmon_envsys *sc_sme;
133 envsys_data_t *sc_sensor;
134 };
135
136 /* XXX These have to become spinlocks in case of fine SMP */
137 #define CAC_LOCK(sc) splbio()
138 #define CAC_UNLOCK(sc, lock) splx(lock)
139 typedef int cac_lock_t;
140
141 struct cac_attach_args {
142 int caca_unit;
143 };
144
145 int cac_cmd(struct cac_softc *, int, void *, int, int, int, int,
146 struct cac_context *);
147 int cac_init(struct cac_softc *, const char *, int);
148 int cac_intr(void *);
149
150 extern const struct cac_linkage cac_l0;
151
152 #endif /* !_IC_CACVAR_H_ */
153