1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 #define OOSIOP_NTGT 8
31 #define OOSIOP_NCB 32
32 #define OOSIOP_NSG (MIN(btoc(MAXPHYS) + 1, 32))
33 #define OOSIOP_MAX_XFER ctob(OOSIOP_NSG - 1)
34
35 struct oosiop_xfer {
36
37 u_int32_t datain_scr[(OOSIOP_NSG + 1) * 2];
38 u_int32_t dataout_scr[(OOSIOP_NSG + 1) * 2];
39
40 u_int8_t msgin[8];
41 u_int8_t msgout[8];
42 u_int8_t status;
43 u_int8_t pad[7];
44 } __packed;
45
46 #define SCSI_OOSIOP_NOSTATUS 0xff
47
48 #define OOSIOP_XFEROFF(x) offsetof(struct oosiop_xfer, x)
49 #define OOSIOP_DINSCROFF OOSIOP_XFEROFF(datain_scr[0])
50 #define OOSIOP_DOUTSCROFF OOSIOP_XFEROFF(dataout_scr[0])
51 #define OOSIOP_MSGINOFF OOSIOP_XFEROFF(msgin[0])
52 #define OOSIOP_MSGOUTOFF OOSIOP_XFEROFF(msgout[0])
53
54 #define OOSIOP_XFERSCR_SYNC(sc, cb, ops) \
55 bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_DINSCROFF, \
56 OOSIOP_MSGINOFF - OOSIOP_DINSCROFF, (ops))
57 #define OOSIOP_DINSCR_SYNC(sc, cb, ops) \
58 bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_DINSCROFF, \
59 OOSIOP_DOUTSCROFF - OOSIOP_DINSCROFF, (ops))
60 #define OOSIOP_DOUTSCR_SYNC(sc, cb, ops) \
61 bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_DOUTSCROFF,\
62 OOSIOP_MSGINOFF - OOSIOP_DOUTSCROFF, (ops))
63 #define OOSIOP_XFERMSG_SYNC(sc, cb, ops) \
64 bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_MSGINOFF, \
65 sizeof(struct oosiop_xfer) - OOSIOP_MSGINOFF, (ops))
66
67 #define OOSIOP_SCRIPT_SYNC(sc, ops) \
68 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_scrdma, \
69 0, sizeof(oosiop_script), (ops))
70
71 struct oosiop_cb {
72 TAILQ_ENTRY(oosiop_cb) chain;
73
74 struct scsi_xfer *xs;
75 int flags;
76 int id;
77 int lun;
78
79 bus_dmamap_t cmddma;
80 bus_dmamap_t datadma;
81 bus_dmamap_t xferdma;
82
83 int curdp;
84 int savedp;
85 int msgoutlen;
86
87 int xsflags;
88 int datalen;
89 int cmdlen;
90
91 struct oosiop_xfer *xfer;
92 };
93
94
95 #define CBF_SELTOUT 0x01
96 #define CBF_TIMEOUT 0x02
97 #define CBF_AUTOSENSE 0x04
98
99 struct oosiop_target {
100 struct oosiop_cb *nexus;
101 int flags;
102 u_int8_t scf;
103 u_int8_t sxfer;
104 };
105
106
107 #define TGTF_SYNCNEG 0x01
108 #define TGTF_WAITSDTR 0x02
109
110 struct oosiop_softc {
111 struct device sc_dev;
112
113 bus_space_tag_t sc_bst;
114 bus_space_handle_t sc_bsh;
115
116 bus_dma_tag_t sc_dmat;
117 bus_dmamap_t sc_scrdma;
118
119 bus_addr_t sc_scrbase;
120 u_int32_t *sc_scr;
121
122 int sc_chip;
123 #define OOSIOP_700 0
124 #define OOSIOP_700_66 1
125
126 int sc_id;
127 int sc_freq;
128 int sc_ccf;
129 u_int8_t sc_dcntl;
130 u_int8_t sc_minperiod;
131
132 struct oosiop_target sc_tgt[OOSIOP_NTGT];
133
134 struct scsi_link sc_link;
135
136
137 TAILQ_HEAD(oosiop_cb_queue, oosiop_cb) sc_free_cb,
138 sc_cbq;
139
140 struct oosiop_cb *sc_curcb;
141 struct oosiop_cb *sc_lastcb;
142
143 bus_addr_t sc_reselbuf;
144 int sc_resid;
145
146 int sc_active;
147 int sc_nextdsp;
148 };
149
150 #define oosiop_read_1(sc, addr) \
151 bus_space_read_1((sc)->sc_bst, (sc)->sc_bsh, (addr))
152 #define oosiop_write_1(sc, addr, data) \
153 bus_space_write_1((sc)->sc_bst, (sc)->sc_bsh, (addr), (data))
154
155 #define oosiop_read_4(sc, addr) \
156 letoh32(bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (addr)))
157 #define oosiop_write_4(sc, addr, data) \
158 bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (addr), htole32(data))
159
160 void oosiop_attach(struct oosiop_softc *);
161 int oosiop_intr(struct oosiop_softc *);