| @@ -1,1428 +1,1429 @@ | | | @@ -1,1428 +1,1429 @@ |
1 | /* $NetBSD: siisata.c,v 1.30.4.35 2017/08/12 22:12:04 jdolecek Exp $ */ | | 1 | /* $NetBSD: siisata.c,v 1.30.4.36 2017/08/15 20:12:28 jakllsch Exp $ */ |
2 | | | 2 | |
3 | /* from ahcisata_core.c */ | | 3 | /* from ahcisata_core.c */ |
4 | | | 4 | |
5 | /* | | 5 | /* |
6 | * Copyright (c) 2006 Manuel Bouyer. | | 6 | * Copyright (c) 2006 Manuel Bouyer. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | | 15 | * documentation and/or other materials provided with the distribution. |
16 | * | | 16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 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 | | 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * | | 27 | * |
28 | */ | | 28 | */ |
29 | | | 29 | |
30 | /* from atapi_wdc.c */ | | 30 | /* from atapi_wdc.c */ |
31 | | | 31 | |
32 | /* | | 32 | /* |
33 | * Copyright (c) 1998, 2001 Manuel Bouyer. | | 33 | * Copyright (c) 1998, 2001 Manuel Bouyer. |
34 | * | | 34 | * |
35 | * Redistribution and use in source and binary forms, with or without | | 35 | * Redistribution and use in source and binary forms, with or without |
36 | * modification, are permitted provided that the following conditions | | 36 | * modification, are permitted provided that the following conditions |
37 | * are met: | | 37 | * are met: |
38 | * 1. Redistributions of source code must retain the above copyright | | 38 | * 1. Redistributions of source code must retain the above copyright |
39 | * notice, this list of conditions and the following disclaimer. | | 39 | * notice, this list of conditions and the following disclaimer. |
40 | * 2. Redistributions in binary form must reproduce the above copyright | | 40 | * 2. Redistributions in binary form must reproduce the above copyright |
41 | * notice, this list of conditions and the following disclaimer in the | | 41 | * notice, this list of conditions and the following disclaimer in the |
42 | * documentation and/or other materials provided with the distribution. | | 42 | * documentation and/or other materials provided with the distribution. |
43 | * | | 43 | * |
44 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 44 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
45 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 45 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
46 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 46 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
47 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 47 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
48 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 48 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
49 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 49 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
50 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 50 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
51 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 51 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
52 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 52 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
53 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 53 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
54 | */ | | 54 | */ |
55 | | | 55 | |
56 | /* | | 56 | /* |
57 | * Copyright (c) 2007, 2008, 2009, 2010 Jonathan A. Kollasch. | | 57 | * Copyright (c) 2007, 2008, 2009, 2010 Jonathan A. Kollasch. |
58 | * All rights reserved. | | 58 | * All rights reserved. |
59 | * | | 59 | * |
60 | * Redistribution and use in source and binary forms, with or without | | 60 | * Redistribution and use in source and binary forms, with or without |
61 | * modification, are permitted provided that the following conditions | | 61 | * modification, are permitted provided that the following conditions |
62 | * are met: | | 62 | * are met: |
63 | * 1. Redistributions of source code must retain the above copyright | | 63 | * 1. Redistributions of source code must retain the above copyright |
64 | * notice, this list of conditions and the following disclaimer. | | 64 | * notice, this list of conditions and the following disclaimer. |
65 | * 2. Redistributions in binary form must reproduce the above copyright | | 65 | * 2. Redistributions in binary form must reproduce the above copyright |
66 | * notice, this list of conditions and the following disclaimer in the | | 66 | * notice, this list of conditions and the following disclaimer in the |
67 | * documentation and/or other materials provided with the distribution. | | 67 | * documentation and/or other materials provided with the distribution. |
68 | * | | 68 | * |
69 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 69 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
70 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 70 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
71 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 71 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
72 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 72 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
73 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 73 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
74 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 74 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
75 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 75 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
76 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 76 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
77 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 77 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
78 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 78 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
79 | */ | | 79 | */ |
80 | | | 80 | |
81 | #include <sys/cdefs.h> | | 81 | #include <sys/cdefs.h> |
82 | __KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.35 2017/08/12 22:12:04 jdolecek Exp $"); | | 82 | __KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.36 2017/08/15 20:12:28 jakllsch Exp $"); |
83 | | | 83 | |
84 | #include <sys/types.h> | | 84 | #include <sys/types.h> |
85 | #include <sys/param.h> | | 85 | #include <sys/param.h> |
86 | #include <sys/kernel.h> | | 86 | #include <sys/kernel.h> |
87 | #include <sys/malloc.h> | | 87 | #include <sys/malloc.h> |
88 | #include <sys/systm.h> | | 88 | #include <sys/systm.h> |
89 | #include <sys/syslog.h> | | 89 | #include <sys/syslog.h> |
90 | #include <sys/disklabel.h> | | 90 | #include <sys/disklabel.h> |
91 | #include <sys/buf.h> | | 91 | #include <sys/buf.h> |
92 | #include <sys/proc.h> | | 92 | #include <sys/proc.h> |
93 | | | 93 | |
94 | #include <dev/ata/atareg.h> | | 94 | #include <dev/ata/atareg.h> |
95 | #include <dev/ata/satavar.h> | | 95 | #include <dev/ata/satavar.h> |
96 | #include <dev/ata/satareg.h> | | 96 | #include <dev/ata/satareg.h> |
97 | #include <dev/ata/satafisvar.h> | | 97 | #include <dev/ata/satafisvar.h> |
98 | #include <dev/ata/satafisreg.h> | | 98 | #include <dev/ata/satafisreg.h> |
99 | #include <dev/ata/satapmpreg.h> | | 99 | #include <dev/ata/satapmpreg.h> |
100 | #include <dev/ic/siisatavar.h> | | 100 | #include <dev/ic/siisatavar.h> |
101 | #include <dev/ic/siisatareg.h> | | 101 | #include <dev/ic/siisatareg.h> |
102 | | | 102 | |
103 | #include <dev/scsipi/scsi_all.h> /* for SCSI status */ | | 103 | #include <dev/scsipi/scsi_all.h> /* for SCSI status */ |
104 | | | 104 | |
105 | #include "atapibus.h" | | 105 | #include "atapibus.h" |
106 | | | 106 | |
107 | #ifdef SIISATA_DEBUG | | 107 | #ifdef SIISATA_DEBUG |
108 | int siisata_debug_mask = 0; | | 108 | int siisata_debug_mask = 0; |
109 | #endif | | 109 | #endif |
110 | | | 110 | |
111 | #define ATA_DELAY 10000 /* 10s for a drive I/O */ | | 111 | #define ATA_DELAY 10000 /* 10s for a drive I/O */ |
112 | #define WDC_RESET_WAIT 31000 /* 31s for drive reset */ | | 112 | #define WDC_RESET_WAIT 31000 /* 31s for drive reset */ |
113 | | | 113 | |
114 | #ifndef __BUS_SPACE_HAS_STREAM_METHODS | | 114 | #ifndef __BUS_SPACE_HAS_STREAM_METHODS |
115 | #if _BYTE_ORDER == _LITTLE_ENDIAN | | 115 | #if _BYTE_ORDER == _LITTLE_ENDIAN |
116 | #define bus_space_read_stream_4 bus_space_read_4 | | 116 | #define bus_space_read_stream_4 bus_space_read_4 |
117 | #define bus_space_read_region_stream_4 bus_space_read_region_4 | | 117 | #define bus_space_read_region_stream_4 bus_space_read_region_4 |
118 | #else | | 118 | #else |
119 | static inline uint32_t | | 119 | static inline uint32_t |
120 | bus_space_read_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) | | 120 | bus_space_read_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) |
121 | { | | 121 | { |
122 | return htole32(bus_space_read_4(t, h, o)); | | 122 | return htole32(bus_space_read_4(t, h, o)); |
123 | } | | 123 | } |
124 | | | 124 | |
125 | static inline void | | 125 | static inline void |
126 | bus_space_read_region_stream_4(bus_space_tag_t t, bus_space_handle_t h, | | 126 | bus_space_read_region_stream_4(bus_space_tag_t t, bus_space_handle_t h, |
127 | bus_size_t o, uint32_t *p, bus_size_t c) | | 127 | bus_size_t o, uint32_t *p, bus_size_t c) |
128 | { | | 128 | { |
129 | bus_space_read_region_4(t, h, o, p, c); | | 129 | bus_space_read_region_4(t, h, o, p, c); |
130 | for (bus_size_t i = 0; i < c; i++) { | | 130 | for (bus_size_t i = 0; i < c; i++) { |
131 | p[i] = htole32(p[i]); | | 131 | p[i] = htole32(p[i]); |
132 | } | | 132 | } |
133 | } | | 133 | } |
134 | #endif | | 134 | #endif |
135 | #endif | | 135 | #endif |
136 | | | 136 | |
137 | static void siisata_attach_port(struct siisata_softc *, int); | | 137 | static void siisata_attach_port(struct siisata_softc *, int); |
138 | static void siisata_intr_port(struct siisata_channel *); | | 138 | static void siisata_intr_port(struct siisata_channel *); |
139 | | | 139 | |
140 | void siisata_probe_drive(struct ata_channel *); | | 140 | void siisata_probe_drive(struct ata_channel *); |
141 | void siisata_setup_channel(struct ata_channel *); | | 141 | void siisata_setup_channel(struct ata_channel *); |
142 | | | 142 | |
143 | int siisata_ata_bio(struct ata_drive_datas *, struct ata_xfer *); | | 143 | int siisata_ata_bio(struct ata_drive_datas *, struct ata_xfer *); |
144 | void siisata_reset_drive(struct ata_drive_datas *, int, uint32_t *); | | 144 | void siisata_reset_drive(struct ata_drive_datas *, int, uint32_t *); |
145 | void siisata_reset_channel(struct ata_channel *, int); | | 145 | void siisata_reset_channel(struct ata_channel *, int); |
146 | int siisata_ata_addref(struct ata_drive_datas *); | | 146 | int siisata_ata_addref(struct ata_drive_datas *); |
147 | void siisata_ata_delref(struct ata_drive_datas *); | | 147 | void siisata_ata_delref(struct ata_drive_datas *); |
148 | void siisata_killpending(struct ata_drive_datas *); | | 148 | void siisata_killpending(struct ata_drive_datas *); |
149 | | | 149 | |
150 | void siisata_cmd_start(struct ata_channel *, struct ata_xfer *); | | 150 | void siisata_cmd_start(struct ata_channel *, struct ata_xfer *); |
151 | int siisata_cmd_complete(struct ata_channel *, struct ata_xfer *, int); | | 151 | int siisata_cmd_complete(struct ata_channel *, struct ata_xfer *, int); |
152 | void siisata_cmd_done(struct ata_channel *, struct ata_xfer *, int); | | 152 | void siisata_cmd_done(struct ata_channel *, struct ata_xfer *, int); |
153 | static void siisata_cmd_done_end(struct ata_channel *, struct ata_xfer *); | | 153 | static void siisata_cmd_done_end(struct ata_channel *, struct ata_xfer *); |
154 | void siisata_cmd_kill_xfer(struct ata_channel *, struct ata_xfer *, int); | | 154 | void siisata_cmd_kill_xfer(struct ata_channel *, struct ata_xfer *, int); |
155 | | | 155 | |
156 | void siisata_bio_start(struct ata_channel *, struct ata_xfer *); | | 156 | void siisata_bio_start(struct ata_channel *, struct ata_xfer *); |
157 | int siisata_bio_complete(struct ata_channel *, struct ata_xfer *, int); | | 157 | int siisata_bio_complete(struct ata_channel *, struct ata_xfer *, int); |
158 | void siisata_bio_kill_xfer(struct ata_channel *, struct ata_xfer *, int); | | 158 | void siisata_bio_kill_xfer(struct ata_channel *, struct ata_xfer *, int); |
159 | int siisata_exec_command(struct ata_drive_datas *, struct ata_xfer *); | | 159 | int siisata_exec_command(struct ata_drive_datas *, struct ata_xfer *); |
160 | | | 160 | |
161 | static void siisata_reinit_port(struct ata_channel *, int); | | 161 | static void siisata_reinit_port(struct ata_channel *, int); |
162 | static void siisata_device_reset(struct ata_channel *); | | 162 | static void siisata_device_reset(struct ata_channel *); |
163 | static void siisata_activate_prb(struct siisata_channel *, int); | | 163 | static void siisata_activate_prb(struct siisata_channel *, int); |
164 | static void siisata_deactivate_prb(struct siisata_channel *, int); | | 164 | static void siisata_deactivate_prb(struct siisata_channel *, int); |
165 | static int siisata_dma_setup(struct ata_channel *, int, void *, size_t, int); | | 165 | static int siisata_dma_setup(struct ata_channel *, int, void *, size_t, int); |
166 | void siisata_channel_recover(struct ata_channel *, uint32_t); | | 166 | void siisata_channel_recover(struct ata_channel *, uint32_t); |
167 | | | 167 | |
168 | #if NATAPIBUS > 0 | | 168 | #if NATAPIBUS > 0 |
169 | void siisata_atapibus_attach(struct atabus_softc *); | | 169 | void siisata_atapibus_attach(struct atabus_softc *); |
170 | void siisata_atapi_probe_device(struct atapibus_softc *, int); | | 170 | void siisata_atapi_probe_device(struct atapibus_softc *, int); |
171 | void siisata_atapi_minphys(struct buf *); | | 171 | void siisata_atapi_minphys(struct buf *); |
172 | void siisata_atapi_start(struct ata_channel *,struct ata_xfer *); | | 172 | void siisata_atapi_start(struct ata_channel *,struct ata_xfer *); |
173 | int siisata_atapi_complete(struct ata_channel *, struct ata_xfer *, int); | | 173 | int siisata_atapi_complete(struct ata_channel *, struct ata_xfer *, int); |
174 | void siisata_atapi_kill_xfer(struct ata_channel *, struct ata_xfer *, int); | | 174 | void siisata_atapi_kill_xfer(struct ata_channel *, struct ata_xfer *, int); |
175 | void siisata_atapi_scsipi_request(struct scsipi_channel *, | | 175 | void siisata_atapi_scsipi_request(struct scsipi_channel *, |
176 | scsipi_adapter_req_t, void *); | | 176 | scsipi_adapter_req_t, void *); |
177 | void siisata_atapi_kill_pending(struct scsipi_periph *); | | 177 | void siisata_atapi_kill_pending(struct scsipi_periph *); |
178 | #endif /* NATAPIBUS */ | | 178 | #endif /* NATAPIBUS */ |
179 | | | 179 | |
180 | const struct ata_bustype siisata_ata_bustype = { | | 180 | const struct ata_bustype siisata_ata_bustype = { |
181 | SCSIPI_BUSTYPE_ATA, | | 181 | SCSIPI_BUSTYPE_ATA, |
182 | siisata_ata_bio, | | 182 | siisata_ata_bio, |
183 | siisata_reset_drive, | | 183 | siisata_reset_drive, |
184 | siisata_reset_channel, | | 184 | siisata_reset_channel, |
185 | siisata_exec_command, | | 185 | siisata_exec_command, |
186 | ata_get_params, | | 186 | ata_get_params, |
187 | siisata_ata_addref, | | 187 | siisata_ata_addref, |
188 | siisata_ata_delref, | | 188 | siisata_ata_delref, |
189 | siisata_killpending | | 189 | siisata_killpending |
190 | }; | | 190 | }; |
191 | | | 191 | |
192 | #if NATAPIBUS > 0 | | 192 | #if NATAPIBUS > 0 |
193 | static const struct scsipi_bustype siisata_atapi_bustype = { | | 193 | static const struct scsipi_bustype siisata_atapi_bustype = { |
194 | SCSIPI_BUSTYPE_ATAPI, | | 194 | SCSIPI_BUSTYPE_ATAPI, |
195 | atapi_scsipi_cmd, | | 195 | atapi_scsipi_cmd, |
196 | atapi_interpret_sense, | | 196 | atapi_interpret_sense, |
197 | atapi_print_addr, | | 197 | atapi_print_addr, |
198 | siisata_atapi_kill_pending, | | 198 | siisata_atapi_kill_pending, |
199 | NULL, | | 199 | NULL, |
200 | }; | | 200 | }; |
201 | #endif /* NATAPIBUS */ | | 201 | #endif /* NATAPIBUS */ |
202 | | | 202 | |
203 | | | 203 | |
204 | void | | 204 | void |
205 | siisata_attach(struct siisata_softc *sc) | | 205 | siisata_attach(struct siisata_softc *sc) |
206 | { | | 206 | { |
207 | int i; | | 207 | int i; |
208 | | | 208 | |
209 | SIISATA_DEBUG_PRINT(("%s: %s: GR_GC: 0x%08x\n", | | 209 | SIISATA_DEBUG_PRINT(("%s: %s: GR_GC: 0x%08x\n", |
210 | SIISATANAME(sc), __func__, GRREAD(sc, GR_GC)), DEBUG_FUNCS); | | 210 | SIISATANAME(sc), __func__, GRREAD(sc, GR_GC)), DEBUG_FUNCS); |
211 | | | 211 | |
212 | sc->sc_atac.atac_cap = ATAC_CAP_DMA | ATAC_CAP_UDMA | ATAC_CAP_NCQ; | | 212 | sc->sc_atac.atac_cap = ATAC_CAP_DMA | ATAC_CAP_UDMA | ATAC_CAP_NCQ; |
213 | sc->sc_atac.atac_pio_cap = 4; | | 213 | sc->sc_atac.atac_pio_cap = 4; |
214 | sc->sc_atac.atac_dma_cap = 2; | | 214 | sc->sc_atac.atac_dma_cap = 2; |
215 | sc->sc_atac.atac_udma_cap = 6; | | 215 | sc->sc_atac.atac_udma_cap = 6; |
216 | sc->sc_atac.atac_channels = sc->sc_chanarray; | | 216 | sc->sc_atac.atac_channels = sc->sc_chanarray; |
217 | sc->sc_atac.atac_probe = siisata_probe_drive; | | 217 | sc->sc_atac.atac_probe = siisata_probe_drive; |
218 | sc->sc_atac.atac_bustype_ata = &siisata_ata_bustype; | | 218 | sc->sc_atac.atac_bustype_ata = &siisata_ata_bustype; |
219 | sc->sc_atac.atac_set_modes = siisata_setup_channel; | | 219 | sc->sc_atac.atac_set_modes = siisata_setup_channel; |
220 | #if NATAPIBUS > 0 | | 220 | #if NATAPIBUS > 0 |
221 | sc->sc_atac.atac_atapibus_attach = siisata_atapibus_attach; | | 221 | sc->sc_atac.atac_atapibus_attach = siisata_atapibus_attach; |
222 | #endif | | 222 | #endif |
223 | | | 223 | |
224 | /* come out of reset state */ | | 224 | /* come out of reset state */ |
225 | GRWRITE(sc, GR_GC, 0); | | 225 | GRWRITE(sc, GR_GC, 0); |
226 | | | 226 | |
227 | for (i = 0; i < sc->sc_atac.atac_nchannels; i++) { | | 227 | for (i = 0; i < sc->sc_atac.atac_nchannels; i++) { |
228 | siisata_attach_port(sc, i); | | 228 | siisata_attach_port(sc, i); |
229 | } | | 229 | } |
230 | | | 230 | |
231 | SIISATA_DEBUG_PRINT(("%s: %s: GR_GC: 0x%08x\n", SIISATANAME(sc), | | 231 | SIISATA_DEBUG_PRINT(("%s: %s: GR_GC: 0x%08x\n", SIISATANAME(sc), |
232 | __func__, GRREAD(sc, GR_GC)), DEBUG_FUNCS); | | 232 | __func__, GRREAD(sc, GR_GC)), DEBUG_FUNCS); |
233 | return; | | 233 | return; |
234 | } | | 234 | } |
235 | | | 235 | |
236 | static void | | 236 | static void |
237 | siisata_disable_port_interrupt(struct ata_channel *chp) | | 237 | siisata_disable_port_interrupt(struct ata_channel *chp) |
238 | { | | 238 | { |
239 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; | | 239 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; |
240 | | | 240 | |
241 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PIEC), 0xffffffff); | | 241 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PIEC), 0xffffffff); |
242 | } | | 242 | } |
243 | | | 243 | |
244 | static void | | 244 | static void |
245 | siisata_enable_port_interrupt(struct ata_channel *chp) | | 245 | siisata_enable_port_interrupt(struct ata_channel *chp) |
246 | { | | 246 | { |
247 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; | | 247 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; |
248 | | | 248 | |
249 | /* clear any interrupts */ | | 249 | /* clear any interrupts */ |
250 | (void)PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)); | | 250 | (void)PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)); |
251 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), 0xffffffff); | | 251 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), 0xffffffff); |
252 | /* and enable CmdErrr+CmdCmpl interrupting */ | | 252 | /* and enable CmdErrr+CmdCmpl interrupting */ |
253 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PIES), | | 253 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PIES), |
254 | PR_PIS_CMDERRR | PR_PIS_CMDCMPL); | | 254 | PR_PIS_CMDERRR | PR_PIS_CMDCMPL); |
255 | } | | 255 | } |
256 | | | 256 | |
257 | static void | | 257 | static void |
258 | siisata_init_port(struct siisata_softc *sc, int port) | | 258 | siisata_init_port(struct siisata_softc *sc, int port) |
259 | { | | 259 | { |
260 | struct siisata_channel *schp; | | 260 | struct siisata_channel *schp; |
261 | struct ata_channel *chp; | | 261 | struct ata_channel *chp; |
262 | | | 262 | |
263 | schp = &sc->sc_channels[port]; | | 263 | schp = &sc->sc_channels[port]; |
264 | chp = (struct ata_channel *)schp; | | 264 | chp = (struct ata_channel *)schp; |
265 | | | 265 | |
266 | /* | | 266 | /* |
267 | * Come out of reset. Disable no clearing of PR_PIS_CMDCMPL on read | | 267 | * Come out of reset. Disable no clearing of PR_PIS_CMDCMPL on read |
268 | * of PR_PSS. Disable 32-bit PRB activation, we use 64-bit activation. | | 268 | * of PR_PSS. Disable 32-bit PRB activation, we use 64-bit activation. |
269 | */ | | 269 | */ |
270 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PCC), | | 270 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PCC), |
271 | PR_PC_32BA | PR_PC_INCOR | PR_PC_PORT_RESET); | | 271 | PR_PC_32BA | PR_PC_INCOR | PR_PC_PORT_RESET); |
272 | /* initialize port */ | | 272 | /* initialize port */ |
273 | siisata_reinit_port(chp, -1); | | 273 | siisata_reinit_port(chp, -1); |
274 | /* enable CmdErrr+CmdCmpl interrupting */ | | 274 | /* enable CmdErrr+CmdCmpl interrupting */ |
275 | siisata_enable_port_interrupt(chp); | | 275 | siisata_enable_port_interrupt(chp); |
276 | /* enable port interrupt */ | | 276 | /* enable port interrupt */ |
277 | GRWRITE(sc, GR_GC, GRREAD(sc, GR_GC) | GR_GC_PXIE(chp->ch_channel)); | | 277 | GRWRITE(sc, GR_GC, GRREAD(sc, GR_GC) | GR_GC_PXIE(chp->ch_channel)); |
278 | } | | 278 | } |
279 | | | 279 | |
280 | static void | | 280 | static void |
281 | siisata_attach_port(struct siisata_softc *sc, int port) | | 281 | siisata_attach_port(struct siisata_softc *sc, int port) |
282 | { | | 282 | { |
283 | int j; | | 283 | int j; |
284 | int dmasize; | | 284 | int dmasize; |
285 | int error; | | 285 | int error; |
286 | void *prbp; | | 286 | void *prbp; |
287 | struct siisata_channel *schp; | | 287 | struct siisata_channel *schp; |
288 | struct ata_channel *chp; | | 288 | struct ata_channel *chp; |
289 | | | 289 | |
290 | schp = &sc->sc_channels[port]; | | 290 | schp = &sc->sc_channels[port]; |
291 | chp = (struct ata_channel *)schp; | | 291 | chp = (struct ata_channel *)schp; |
292 | sc->sc_chanarray[port] = chp; | | 292 | sc->sc_chanarray[port] = chp; |
293 | chp->ch_channel = port; | | 293 | chp->ch_channel = port; |
294 | chp->ch_atac = &sc->sc_atac; | | 294 | chp->ch_atac = &sc->sc_atac; |
295 | chp->ch_queue = ata_queue_alloc(SIISATA_MAX_SLOTS); | | 295 | chp->ch_queue = ata_queue_alloc(SIISATA_MAX_SLOTS); |
296 | if (chp->ch_queue == NULL) { | | 296 | if (chp->ch_queue == NULL) { |
297 | aprint_error_dev(sc->sc_atac.atac_dev, | | 297 | aprint_error_dev(sc->sc_atac.atac_dev, |
298 | "port %d: can't allocate memory " | | 298 | "port %d: can't allocate memory " |
299 | "for command queue\n", chp->ch_channel); | | 299 | "for command queue\n", chp->ch_channel); |
300 | return; | | 300 | return; |
301 | } | | 301 | } |
302 | | | 302 | |
303 | dmasize = SIISATA_CMD_SIZE * SIISATA_MAX_SLOTS; | | 303 | dmasize = SIISATA_CMD_SIZE * SIISATA_MAX_SLOTS; |
304 | | | 304 | |
305 | SIISATA_DEBUG_PRINT(("%s: %s: dmasize: %d\n", SIISATANAME(sc), | | 305 | SIISATA_DEBUG_PRINT(("%s: %s: dmasize: %d\n", SIISATANAME(sc), |
306 | __func__, dmasize), DEBUG_FUNCS); | | 306 | __func__, dmasize), DEBUG_FUNCS); |
307 | | | 307 | |
308 | error = bus_dmamem_alloc(sc->sc_dmat, dmasize, PAGE_SIZE, 0, | | 308 | error = bus_dmamem_alloc(sc->sc_dmat, dmasize, PAGE_SIZE, 0, |
309 | &schp->sch_prb_seg, 1, &schp->sch_prb_nseg, BUS_DMA_NOWAIT); | | 309 | &schp->sch_prb_seg, 1, &schp->sch_prb_nseg, BUS_DMA_NOWAIT); |
310 | if (error) { | | 310 | if (error) { |
311 | aprint_error_dev(sc->sc_atac.atac_dev, | | 311 | aprint_error_dev(sc->sc_atac.atac_dev, |
312 | "unable to allocate PRB table memory, " | | 312 | "unable to allocate PRB table memory, " |
313 | "error=%d\n", error); | | 313 | "error=%d\n", error); |
314 | return; | | 314 | return; |
315 | } | | 315 | } |
316 | | | 316 | |
317 | error = bus_dmamem_map(sc->sc_dmat, | | 317 | error = bus_dmamem_map(sc->sc_dmat, |
318 | &schp->sch_prb_seg, schp->sch_prb_nseg, | | 318 | &schp->sch_prb_seg, schp->sch_prb_nseg, |
319 | dmasize, &prbp, BUS_DMA_NOWAIT | BUS_DMA_COHERENT); | | 319 | dmasize, &prbp, BUS_DMA_NOWAIT | BUS_DMA_COHERENT); |
320 | if (error) { | | 320 | if (error) { |
321 | aprint_error_dev(sc->sc_atac.atac_dev, | | 321 | aprint_error_dev(sc->sc_atac.atac_dev, |
322 | "unable to map PRB table memory, " | | 322 | "unable to map PRB table memory, " |
323 | "error=%d\n", error); | | 323 | "error=%d\n", error); |
324 | bus_dmamem_free(sc->sc_dmat, | | 324 | bus_dmamem_free(sc->sc_dmat, |
325 | &schp->sch_prb_seg, schp->sch_prb_nseg); | | 325 | &schp->sch_prb_seg, schp->sch_prb_nseg); |
326 | return; | | 326 | return; |
327 | } | | 327 | } |
328 | | | 328 | |
329 | error = bus_dmamap_create(sc->sc_dmat, dmasize, 1, dmasize, 0, | | 329 | error = bus_dmamap_create(sc->sc_dmat, dmasize, 1, dmasize, 0, |
330 | BUS_DMA_NOWAIT, &schp->sch_prbd); | | 330 | BUS_DMA_NOWAIT, &schp->sch_prbd); |
331 | if (error) { | | 331 | if (error) { |
332 | aprint_error_dev(sc->sc_atac.atac_dev, | | 332 | aprint_error_dev(sc->sc_atac.atac_dev, |
333 | "unable to create PRB table map, " | | 333 | "unable to create PRB table map, " |
334 | "error=%d\n", error); | | 334 | "error=%d\n", error); |
335 | bus_dmamem_unmap(sc->sc_dmat, prbp, dmasize); | | 335 | bus_dmamem_unmap(sc->sc_dmat, prbp, dmasize); |
336 | bus_dmamem_free(sc->sc_dmat, | | 336 | bus_dmamem_free(sc->sc_dmat, |
337 | &schp->sch_prb_seg, schp->sch_prb_nseg); | | 337 | &schp->sch_prb_seg, schp->sch_prb_nseg); |
338 | return; | | 338 | return; |
339 | } | | 339 | } |
340 | | | 340 | |
341 | error = bus_dmamap_load(sc->sc_dmat, schp->sch_prbd, | | 341 | error = bus_dmamap_load(sc->sc_dmat, schp->sch_prbd, |
342 | prbp, dmasize, NULL, BUS_DMA_NOWAIT); | | 342 | prbp, dmasize, NULL, BUS_DMA_NOWAIT); |
343 | if (error) { | | 343 | if (error) { |
344 | aprint_error_dev(sc->sc_atac.atac_dev, | | 344 | aprint_error_dev(sc->sc_atac.atac_dev, |
345 | "unable to load PRB table map, " | | 345 | "unable to load PRB table map, " |
346 | "error=%d\n", error); | | 346 | "error=%d\n", error); |
347 | bus_dmamap_destroy(sc->sc_dmat, schp->sch_prbd); | | 347 | bus_dmamap_destroy(sc->sc_dmat, schp->sch_prbd); |
348 | bus_dmamem_unmap(sc->sc_dmat, prbp, dmasize); | | 348 | bus_dmamem_unmap(sc->sc_dmat, prbp, dmasize); |
349 | bus_dmamem_free(sc->sc_dmat, | | 349 | bus_dmamem_free(sc->sc_dmat, |
350 | &schp->sch_prb_seg, schp->sch_prb_nseg); | | 350 | &schp->sch_prb_seg, schp->sch_prb_nseg); |
351 | return; | | 351 | return; |
352 | } | | 352 | } |
353 | | | 353 | |
354 | for (j = 0; j < SIISATA_MAX_SLOTS; j++) { | | 354 | for (j = 0; j < SIISATA_MAX_SLOTS; j++) { |
355 | schp->sch_prb[j] = (struct siisata_prb *) | | 355 | schp->sch_prb[j] = (struct siisata_prb *) |
356 | ((char *)prbp + SIISATA_CMD_SIZE * j); | | 356 | ((char *)prbp + SIISATA_CMD_SIZE * j); |
357 | schp->sch_bus_prb[j] = | | 357 | schp->sch_bus_prb[j] = |
358 | schp->sch_prbd->dm_segs[0].ds_addr + | | 358 | schp->sch_prbd->dm_segs[0].ds_addr + |
359 | SIISATA_CMD_SIZE * j; | | 359 | SIISATA_CMD_SIZE * j; |
360 | error = bus_dmamap_create(sc->sc_dmat, MAXPHYS, | | 360 | error = bus_dmamap_create(sc->sc_dmat, MAXPHYS, |
361 | SIISATA_NSGE, MAXPHYS, 0, | | 361 | SIISATA_NSGE, MAXPHYS, 0, |
362 | BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, | | 362 | BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, |
363 | &schp->sch_datad[j]); | | 363 | &schp->sch_datad[j]); |
364 | if (error) { | | 364 | if (error) { |
365 | aprint_error_dev(sc->sc_atac.atac_dev, | | 365 | aprint_error_dev(sc->sc_atac.atac_dev, |
366 | "couldn't create xfer DMA map, error=%d\n", | | 366 | "couldn't create xfer DMA map, error=%d\n", |
367 | error); | | 367 | error); |
368 | return; | | 368 | return; |
369 | } | | 369 | } |
370 | } | | 370 | } |
371 | | | 371 | |
372 | if (bus_space_subregion(sc->sc_prt, sc->sc_prh, | | 372 | if (bus_space_subregion(sc->sc_prt, sc->sc_prh, |
373 | PRX(chp->ch_channel, PRO_SSTATUS), 4, &schp->sch_sstatus) != 0) { | | 373 | PRX(chp->ch_channel, PRO_SSTATUS), 4, &schp->sch_sstatus) != 0) { |
374 | aprint_error_dev(sc->sc_atac.atac_dev, | | 374 | aprint_error_dev(sc->sc_atac.atac_dev, |
375 | "couldn't map port %d SStatus regs\n", | | 375 | "couldn't map port %d SStatus regs\n", |
376 | chp->ch_channel); | | 376 | chp->ch_channel); |
377 | return; | | 377 | return; |
378 | } | | 378 | } |
379 | if (bus_space_subregion(sc->sc_prt, sc->sc_prh, | | 379 | if (bus_space_subregion(sc->sc_prt, sc->sc_prh, |
380 | PRX(chp->ch_channel, PRO_SCONTROL), 4, &schp->sch_scontrol) != 0) { | | 380 | PRX(chp->ch_channel, PRO_SCONTROL), 4, &schp->sch_scontrol) != 0) { |
381 | aprint_error_dev(sc->sc_atac.atac_dev, | | 381 | aprint_error_dev(sc->sc_atac.atac_dev, |
382 | "couldn't map port %d SControl regs\n", | | 382 | "couldn't map port %d SControl regs\n", |
383 | chp->ch_channel); | | 383 | chp->ch_channel); |
384 | return; | | 384 | return; |
385 | } | | 385 | } |
386 | if (bus_space_subregion(sc->sc_prt, sc->sc_prh, | | 386 | if (bus_space_subregion(sc->sc_prt, sc->sc_prh, |
387 | PRX(chp->ch_channel, PRO_SERROR), 4, &schp->sch_serror) != 0) { | | 387 | PRX(chp->ch_channel, PRO_SERROR), 4, &schp->sch_serror) != 0) { |
388 | aprint_error_dev(sc->sc_atac.atac_dev, | | 388 | aprint_error_dev(sc->sc_atac.atac_dev, |
389 | "couldn't map port %d SError regs\n", | | 389 | "couldn't map port %d SError regs\n", |
390 | chp->ch_channel); | | 390 | chp->ch_channel); |
391 | return; | | 391 | return; |
392 | } | | 392 | } |
393 | | | 393 | |
394 | siisata_init_port(sc, port); | | 394 | siisata_init_port(sc, port); |
395 | | | 395 | |
396 | ata_channel_attach(chp); | | 396 | ata_channel_attach(chp); |
397 | | | 397 | |
398 | return; | | 398 | return; |
399 | } | | 399 | } |
400 | | | 400 | |
401 | int | | 401 | int |
402 | siisata_detach(struct siisata_softc *sc, int flags) | | 402 | siisata_detach(struct siisata_softc *sc, int flags) |
403 | { | | 403 | { |
404 | struct atac_softc *atac = &sc->sc_atac; | | 404 | struct atac_softc *atac = &sc->sc_atac; |
405 | struct scsipi_adapter *adapt = &atac->atac_atapi_adapter._generic; | | 405 | struct scsipi_adapter *adapt = &atac->atac_atapi_adapter._generic; |
406 | struct siisata_channel *schp; | | 406 | struct siisata_channel *schp; |
407 | struct ata_channel *chp; | | 407 | struct ata_channel *chp; |
408 | int i, j, error; | | 408 | int i, j, error; |
409 | | | 409 | |
410 | for (i = 0; i < sc->sc_atac.atac_nchannels; i++) { | | 410 | for (i = 0; i < sc->sc_atac.atac_nchannels; i++) { |
411 | schp = &sc->sc_channels[i]; | | 411 | schp = &sc->sc_channels[i]; |
412 | chp = sc->sc_chanarray[i]; | | 412 | chp = sc->sc_chanarray[i]; |
413 | | | 413 | |
414 | if (chp->atabus == NULL) | | 414 | if (chp->atabus == NULL) |
415 | continue; | | 415 | continue; |
416 | if ((error = config_detach(chp->atabus, flags)) != 0) | | 416 | if ((error = config_detach(chp->atabus, flags)) != 0) |
417 | return error; | | 417 | return error; |
418 | | | 418 | |
419 | for (j = 0; j < SIISATA_MAX_SLOTS; j++) | | 419 | for (j = 0; j < SIISATA_MAX_SLOTS; j++) |
420 | bus_dmamap_destroy(sc->sc_dmat, schp->sch_datad[j]); | | 420 | bus_dmamap_destroy(sc->sc_dmat, schp->sch_datad[j]); |
421 | | | 421 | |
422 | bus_dmamap_unload(sc->sc_dmat, schp->sch_prbd); | | 422 | bus_dmamap_unload(sc->sc_dmat, schp->sch_prbd); |
423 | bus_dmamap_destroy(sc->sc_dmat, schp->sch_prbd); | | 423 | bus_dmamap_destroy(sc->sc_dmat, schp->sch_prbd); |
424 | bus_dmamem_unmap(sc->sc_dmat, schp->sch_prb[0], | | 424 | bus_dmamem_unmap(sc->sc_dmat, schp->sch_prb[0], |
425 | SIISATA_CMD_SIZE * SIISATA_MAX_SLOTS); | | 425 | SIISATA_CMD_SIZE * SIISATA_MAX_SLOTS); |
426 | bus_dmamem_free(sc->sc_dmat, | | 426 | bus_dmamem_free(sc->sc_dmat, |
427 | &schp->sch_prb_seg, schp->sch_prb_nseg); | | 427 | &schp->sch_prb_seg, schp->sch_prb_nseg); |
428 | | | 428 | |
429 | free(chp->ch_queue, M_DEVBUF); | | 429 | ata_queue_free(chp->ch_queue); |
| | | 430 | chp->ch_queue = NULL; |
430 | chp->atabus = NULL; | | 431 | chp->atabus = NULL; |
431 | | | 432 | |
432 | ata_channel_detach(chp); | | 433 | ata_channel_detach(chp); |
433 | } | | 434 | } |
434 | | | 435 | |
435 | if (adapt->adapt_refcnt != 0) | | 436 | if (adapt->adapt_refcnt != 0) |
436 | return EBUSY; | | 437 | return EBUSY; |
437 | | | 438 | |
438 | /* leave the chip in reset */ | | 439 | /* leave the chip in reset */ |
439 | GRWRITE(sc, GR_GC, GR_GC_GLBLRST); | | 440 | GRWRITE(sc, GR_GC, GR_GC_GLBLRST); |
440 | | | 441 | |
441 | return 0; | | 442 | return 0; |
442 | } | | 443 | } |
443 | | | 444 | |
444 | void | | 445 | void |
445 | siisata_resume(struct siisata_softc *sc) | | 446 | siisata_resume(struct siisata_softc *sc) |
446 | { | | 447 | { |
447 | int i; | | 448 | int i; |
448 | | | 449 | |
449 | /* come out of reset state */ | | 450 | /* come out of reset state */ |
450 | GRWRITE(sc, GR_GC, 0); | | 451 | GRWRITE(sc, GR_GC, 0); |
451 | | | 452 | |
452 | for (i = 0; i < sc->sc_atac.atac_nchannels; i++) { | | 453 | for (i = 0; i < sc->sc_atac.atac_nchannels; i++) { |
453 | siisata_init_port(sc, i); | | 454 | siisata_init_port(sc, i); |
454 | } | | 455 | } |
455 | | | 456 | |
456 | } | | 457 | } |
457 | | | 458 | |
458 | int | | 459 | int |
459 | siisata_intr(void *v) | | 460 | siisata_intr(void *v) |
460 | { | | 461 | { |
461 | struct siisata_softc *sc = v; | | 462 | struct siisata_softc *sc = v; |
462 | uint32_t is; | | 463 | uint32_t is; |
463 | int i, r = 0; | | 464 | int i, r = 0; |
464 | while ((is = GRREAD(sc, GR_GIS))) { | | 465 | while ((is = GRREAD(sc, GR_GIS))) { |
465 | SIISATA_DEBUG_PRINT(("%s: %s: GR_GIS: 0x%08x\n", | | 466 | SIISATA_DEBUG_PRINT(("%s: %s: GR_GIS: 0x%08x\n", |
466 | SIISATANAME(sc), __func__, is), DEBUG_INTR); | | 467 | SIISATANAME(sc), __func__, is), DEBUG_INTR); |
467 | r = 1; | | 468 | r = 1; |
468 | for (i = 0; i < sc->sc_atac.atac_nchannels; i++) | | 469 | for (i = 0; i < sc->sc_atac.atac_nchannels; i++) |
469 | if (is & GR_GIS_PXIS(i)) | | 470 | if (is & GR_GIS_PXIS(i)) |
470 | siisata_intr_port(&sc->sc_channels[i]); | | 471 | siisata_intr_port(&sc->sc_channels[i]); |
471 | } | | 472 | } |
472 | return r; | | 473 | return r; |
473 | } | | 474 | } |
474 | | | 475 | |
475 | static void | | 476 | static void |
476 | siisata_intr_port(struct siisata_channel *schp) | | 477 | siisata_intr_port(struct siisata_channel *schp) |
477 | { | | 478 | { |
478 | struct siisata_softc *sc = | | 479 | struct siisata_softc *sc = |
479 | (struct siisata_softc *)schp->ata_channel.ch_atac; | | 480 | (struct siisata_softc *)schp->ata_channel.ch_atac; |
480 | struct ata_channel *chp = &schp->ata_channel; | | 481 | struct ata_channel *chp = &schp->ata_channel; |
481 | struct ata_xfer *xfer = NULL; | | 482 | struct ata_xfer *xfer = NULL; |
482 | uint32_t pss, pis, tfd = 0; | | 483 | uint32_t pss, pis, tfd = 0; |
483 | bool recover = false; | | 484 | bool recover = false; |
484 | | | 485 | |
485 | /* get slot status, clearing completion interrupt */ | | 486 | /* get slot status, clearing completion interrupt */ |
486 | pss = PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)); | | 487 | pss = PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)); |
487 | | | 488 | |
488 | SIISATA_DEBUG_PRINT(("%s: %s port %d, pss 0x%x ", | | 489 | SIISATA_DEBUG_PRINT(("%s: %s port %d, pss 0x%x ", |
489 | SIISATANAME(sc), __func__, chp->ch_channel, pss), | | 490 | SIISATANAME(sc), __func__, chp->ch_channel, pss), |
490 | DEBUG_INTR); | | 491 | DEBUG_INTR); |
491 | | | 492 | |
492 | if (__predict_true((pss & PR_PSS_ATTENTION) == 0)) { | | 493 | if (__predict_true((pss & PR_PSS_ATTENTION) == 0)) { |
493 | SIISATA_DEBUG_PRINT(("no attention"), DEBUG_INTR); | | 494 | SIISATA_DEBUG_PRINT(("no attention"), DEBUG_INTR); |
494 | goto process; | | 495 | goto process; |
495 | } | | 496 | } |
496 | | | 497 | |
497 | pis = PRREAD(sc, PRX(chp->ch_channel, PRO_PIS)); | | 498 | pis = PRREAD(sc, PRX(chp->ch_channel, PRO_PIS)); |
498 | | | 499 | |
499 | SIISATA_DEBUG_PRINT(("pis 0x%x\n", pss), DEBUG_INTR); | | 500 | SIISATA_DEBUG_PRINT(("pis 0x%x\n", pss), DEBUG_INTR); |
500 | | | 501 | |
501 | if (pis & PR_PIS_CMDERRR) { | | 502 | if (pis & PR_PIS_CMDERRR) { |
502 | uint32_t ec; | | 503 | uint32_t ec; |
503 | | | 504 | |
504 | ec = PRREAD(sc, PRX(chp->ch_channel, PRO_PCE)); | | 505 | ec = PRREAD(sc, PRX(chp->ch_channel, PRO_PCE)); |
505 | SIISATA_DEBUG_PRINT(("ec %d\n", ec), DEBUG_INTR); | | 506 | SIISATA_DEBUG_PRINT(("ec %d\n", ec), DEBUG_INTR); |
506 | | | 507 | |
507 | /* emulate a CRC error by default */ | | 508 | /* emulate a CRC error by default */ |
508 | tfd = ATACH_ERR_ST(WDCE_CRC, WDCS_ERR); | | 509 | tfd = ATACH_ERR_ST(WDCE_CRC, WDCS_ERR); |
509 | | | 510 | |
510 | if (ec <= PR_PCE_DATAFISERROR) { | | 511 | if (ec <= PR_PCE_DATAFISERROR) { |
511 | if (ec == PR_PCE_DEVICEERROR | | 512 | if (ec == PR_PCE_DEVICEERROR |
512 | && (chp->ch_flags & ATACH_NCQ) == 0) { | | 513 | && (chp->ch_flags & ATACH_NCQ) == 0) { |
513 | xfer = ata_queue_get_active_xfer(chp); | | 514 | xfer = ata_queue_get_active_xfer(chp); |
514 | | | 515 | |
515 | /* read in specific information about error */ | | 516 | /* read in specific information about error */ |
516 | uint32_t prbfis = bus_space_read_stream_4( | | 517 | uint32_t prbfis = bus_space_read_stream_4( |
517 | sc->sc_prt, sc->sc_prh, | | 518 | sc->sc_prt, sc->sc_prh, |
518 | PRSX(chp->ch_channel, xfer->c_slot, | | 519 | PRSX(chp->ch_channel, xfer->c_slot, |
519 | PRSO_FIS)); | | 520 | PRSO_FIS)); |
520 | | | 521 | |
521 | /* get status and error */ | | 522 | /* get status and error */ |
522 | int ntfd = satafis_rdh_parse(chp, | | 523 | int ntfd = satafis_rdh_parse(chp, |
523 | (uint8_t *)&prbfis); | | 524 | (uint8_t *)&prbfis); |
524 | | | 525 | |
525 | if (ATACH_ST(ntfd) & WDCS_ERR) | | 526 | if (ATACH_ST(ntfd) & WDCS_ERR) |
526 | tfd = ntfd; | | 527 | tfd = ntfd; |
527 | } | | 528 | } |
528 | | | 529 | |
529 | /* | | 530 | /* |
530 | * We don't expect the recovery to trigger error, | | 531 | * We don't expect the recovery to trigger error, |
531 | * but handle this just in case. | | 532 | * but handle this just in case. |
532 | */ | | 533 | */ |
533 | if (!schp->sch_recovering) | | 534 | if (!schp->sch_recovering) |
534 | recover = true; | | 535 | recover = true; |
535 | else { | | 536 | else { |
536 | aprint_error_dev(sc->sc_atac.atac_dev, | | 537 | aprint_error_dev(sc->sc_atac.atac_dev, |
537 | "error ec %x while recovering\n", ec); | | 538 | "error ec %x while recovering\n", ec); |
538 | | | 539 | |
539 | /* Command will be marked as errored out */ | | 540 | /* Command will be marked as errored out */ |
540 | pss = 0; | | 541 | pss = 0; |
541 | } | | 542 | } |
542 | } else { | | 543 | } else { |
543 | aprint_error_dev(sc->sc_atac.atac_dev, "fatal error %d" | | 544 | aprint_error_dev(sc->sc_atac.atac_dev, "fatal error %d" |
544 | " on channel %d (ctx 0x%x), resetting\n", | | 545 | " on channel %d (ctx 0x%x), resetting\n", |
545 | ec, chp->ch_channel, | | 546 | ec, chp->ch_channel, |
546 | PRREAD(sc, PRX(chp->ch_channel, PRO_PCR))); | | 547 | PRREAD(sc, PRX(chp->ch_channel, PRO_PCR))); |
547 | | | 548 | |
548 | /* okay, we have a "Fatal Error" */ | | 549 | /* okay, we have a "Fatal Error" */ |
549 | siisata_device_reset(chp); | | 550 | siisata_device_reset(chp); |
550 | } | | 551 | } |
551 | } | | 552 | } |
552 | | | 553 | |
553 | /* clear some (ok, all) ints */ | | 554 | /* clear some (ok, all) ints */ |
554 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), 0xffffffff); | | 555 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), 0xffffffff); |
555 | | | 556 | |
556 | if (__predict_false(recover)) | | 557 | if (__predict_false(recover)) |
557 | ata_channel_freeze(chp); | | 558 | ata_channel_freeze(chp); |
558 | | | 559 | |
559 | process: | | 560 | process: |
560 | if (xfer != NULL) { | | 561 | if (xfer != NULL) { |
561 | xfer->c_intr(chp, xfer, tfd); | | 562 | xfer->c_intr(chp, xfer, tfd); |
562 | } else { | | 563 | } else { |
563 | /* | | 564 | /* |
564 | * For NCQ, HBA halts processing when error is notified, | | 565 | * For NCQ, HBA halts processing when error is notified, |
565 | * and any further D2H FISes are ignored until the error | | 566 | * and any further D2H FISes are ignored until the error |
566 | * condition is cleared. Hence if a command is inactive, | | 567 | * condition is cleared. Hence if a command is inactive, |
567 | * it means it actually already finished successfully. | | 568 | * it means it actually already finished successfully. |
568 | * Note: active slots can change as c_intr() callback | | 569 | * Note: active slots can change as c_intr() callback |
569 | * can activate another command(s), so must only process | | 570 | * can activate another command(s), so must only process |
570 | * commands active before we start processing. | | 571 | * commands active before we start processing. |
571 | */ | | 572 | */ |
572 | uint32_t aslots = schp->sch_active_slots; | | 573 | uint32_t aslots = schp->sch_active_slots; |
573 | | | 574 | |
574 | for (int slot=0; slot < SIISATA_MAX_SLOTS; slot++) { | | 575 | for (int slot=0; slot < SIISATA_MAX_SLOTS; slot++) { |
575 | if ((aslots & __BIT(slot)) != 0 && | | 576 | if ((aslots & __BIT(slot)) != 0 && |
576 | (pss & PR_PXSS(slot)) == 0) { | | 577 | (pss & PR_PXSS(slot)) == 0) { |
577 | xfer = ata_queue_hwslot_to_xfer(chp, slot); | | 578 | xfer = ata_queue_hwslot_to_xfer(chp, slot); |
578 | xfer->c_intr(chp, xfer, 0); | | 579 | xfer->c_intr(chp, xfer, 0); |
579 | } | | 580 | } |
580 | } | | 581 | } |
581 | } | | 582 | } |
582 | | | 583 | |
583 | if (__predict_false(recover)) { | | 584 | if (__predict_false(recover)) { |
584 | ata_channel_thaw(chp); | | 585 | ata_channel_thaw(chp); |
585 | siisata_channel_recover(chp, tfd); | | 586 | siisata_channel_recover(chp, tfd); |
586 | } | | 587 | } |
587 | } | | 588 | } |
588 | | | 589 | |
589 | static void | | 590 | static void |
590 | siisata_hold(struct siisata_channel *schp) | | 591 | siisata_hold(struct siisata_channel *schp) |
591 | { | | 592 | { |
592 | schp->sch_hold_slots |= schp->sch_active_slots; | | 593 | schp->sch_hold_slots |= schp->sch_active_slots; |
593 | schp->sch_active_slots = 0; | | 594 | schp->sch_active_slots = 0; |
594 | } | | 595 | } |
595 | | | 596 | |
596 | static void | | 597 | static void |
597 | siisata_unhold(struct siisata_channel *schp) | | 598 | siisata_unhold(struct siisata_channel *schp) |
598 | { | | 599 | { |
599 | schp->sch_active_slots = schp->sch_hold_slots; | | 600 | schp->sch_active_slots = schp->sch_hold_slots; |
600 | schp->sch_hold_slots = 0; | | 601 | schp->sch_hold_slots = 0; |
601 | } | | 602 | } |
602 | | | 603 | |
603 | /* Recover channel after transfer aborted */ | | 604 | /* Recover channel after transfer aborted */ |
604 | void | | 605 | void |
605 | siisata_channel_recover(struct ata_channel *chp, uint32_t tfd) | | 606 | siisata_channel_recover(struct ata_channel *chp, uint32_t tfd) |
606 | { | | 607 | { |
607 | struct siisata_channel *schp = (struct siisata_channel *)chp; | | 608 | struct siisata_channel *schp = (struct siisata_channel *)chp; |
608 | struct siisata_softc *sc = | | 609 | struct siisata_softc *sc = |
609 | (struct siisata_softc *)schp->ata_channel.ch_atac; | | 610 | (struct siisata_softc *)schp->ata_channel.ch_atac; |
610 | struct ata_drive_datas *drvp; | | 611 | struct ata_drive_datas *drvp; |
611 | int drive, error; | | 612 | int drive, error; |
612 | uint8_t eslot, slot, st, err; | | 613 | uint8_t eslot, slot, st, err; |
613 | struct ata_xfer *xfer; | | 614 | struct ata_xfer *xfer; |
614 | | | 615 | |
615 | KASSERT(!schp->sch_recovering); | | 616 | KASSERT(!schp->sch_recovering); |
616 | | | 617 | |
617 | schp->sch_recovering = true; | | 618 | schp->sch_recovering = true; |
618 | | | 619 | |
619 | if (chp->ch_ndrives > PMP_PORT_CTL) { | | 620 | if (chp->ch_ndrives > PMP_PORT_CTL) { |
620 | /* Get PM port number for the device in error */ | | 621 | /* Get PM port number for the device in error */ |
621 | int pcr = PRREAD(sc, PRX(chp->ch_channel, PRO_PCR)); | | 622 | int pcr = PRREAD(sc, PRX(chp->ch_channel, PRO_PCR)); |
622 | drive = PRO_PCR_PMP(pcr); | | 623 | drive = PRO_PCR_PMP(pcr); |
623 | } else | | 624 | } else |
624 | drive = 0; | | 625 | drive = 0; |
625 | | | 626 | |
626 | drvp = &chp->ch_drive[drive]; | | 627 | drvp = &chp->ch_drive[drive]; |
627 | | | 628 | |
628 | /* | | 629 | /* |
629 | * If BSY or DRQ bits are set, must execute COMRESET to return | | 630 | * If BSY or DRQ bits are set, must execute COMRESET to return |
630 | * device to idle state. Otherwise, commands can be reissued | | 631 | * device to idle state. Otherwise, commands can be reissued |
631 | * after reinitalization of port. After that, need to execute | | 632 | * after reinitalization of port. After that, need to execute |
632 | * READ LOG EXT for NCQ to unblock device processing if COMRESET | | 633 | * READ LOG EXT for NCQ to unblock device processing if COMRESET |
633 | * was not done. | | 634 | * was not done. |
634 | */ | | 635 | */ |
635 | if ((ATACH_ST(tfd) & (WDCS_BSY|WDCS_DRQ)) != 0) | | 636 | if ((ATACH_ST(tfd) & (WDCS_BSY|WDCS_DRQ)) != 0) |
636 | goto reset; | | 637 | goto reset; |
637 | | | 638 | |
638 | KASSERT(drive >= 0); | | 639 | KASSERT(drive >= 0); |
639 | siisata_reinit_port(chp, drive); | | 640 | siisata_reinit_port(chp, drive); |
640 | | | 641 | |
641 | siisata_hold(schp); | | 642 | siisata_hold(schp); |
642 | | | 643 | |
643 | /* | | 644 | /* |
644 | * When running NCQ commands, READ LOG EXT is necessary to clear the | | 645 | * When running NCQ commands, READ LOG EXT is necessary to clear the |
645 | * error condition and unblock the device. | | 646 | * error condition and unblock the device. |
646 | */ | | 647 | */ |
647 | error = ata_read_log_ext_ncq(drvp, AT_POLL, &eslot, &st, &err); | | 648 | error = ata_read_log_ext_ncq(drvp, AT_POLL, &eslot, &st, &err); |
648 | | | 649 | |
649 | siisata_unhold(schp); | | 650 | siisata_unhold(schp); |
650 | | | 651 | |
651 | switch (error) { | | 652 | switch (error) { |
652 | case 0: | | 653 | case 0: |
653 | /* Error out the particular NCQ xfer, then requeue the others */ | | 654 | /* Error out the particular NCQ xfer, then requeue the others */ |
654 | if ((schp->sch_active_slots & (1 << eslot)) != 0) { | | 655 | if ((schp->sch_active_slots & (1 << eslot)) != 0) { |
655 | xfer = ata_queue_hwslot_to_xfer(chp, eslot); | | 656 | xfer = ata_queue_hwslot_to_xfer(chp, eslot); |
656 | xfer->c_flags |= C_RECOVERED; | | 657 | xfer->c_flags |= C_RECOVERED; |
657 | xfer->c_intr(chp, xfer, ATACH_ERR_ST(err, st)); | | 658 | xfer->c_intr(chp, xfer, ATACH_ERR_ST(err, st)); |
658 | } | | 659 | } |
659 | break; | | 660 | break; |
660 | | | 661 | |
661 | case EOPNOTSUPP: | | 662 | case EOPNOTSUPP: |
662 | /* | | 663 | /* |
663 | * Non-NCQ command error, just find the slot and end it with | | 664 | * Non-NCQ command error, just find the slot and end it with |
664 | * the error. | | 665 | * the error. |
665 | */ | | 666 | */ |
666 | for (slot = 0; slot < SIISATA_MAX_SLOTS; slot++) { | | 667 | for (slot = 0; slot < SIISATA_MAX_SLOTS; slot++) { |
667 | if ((schp->sch_active_slots & (1 << slot)) != 0) { | | 668 | if ((schp->sch_active_slots & (1 << slot)) != 0) { |
668 | xfer = ata_queue_hwslot_to_xfer(chp, slot); | | 669 | xfer = ata_queue_hwslot_to_xfer(chp, slot); |
669 | if (xfer->c_drive != drive) | | 670 | if (xfer->c_drive != drive) |
670 | continue; | | 671 | continue; |
671 | | | 672 | |
672 | xfer->c_intr(chp, xfer, tfd); | | 673 | xfer->c_intr(chp, xfer, tfd); |
673 | } | | 674 | } |
674 | } | | 675 | } |
675 | break; | | 676 | break; |
676 | | | 677 | |
677 | case EAGAIN: | | 678 | case EAGAIN: |
678 | /* | | 679 | /* |
679 | * Failed to get resources to run the recovery command, must | | 680 | * Failed to get resources to run the recovery command, must |
680 | * reset the drive. This will also kill all still outstanding | | 681 | * reset the drive. This will also kill all still outstanding |
681 | * transfers. | | 682 | * transfers. |
682 | */ | | 683 | */ |
683 | reset: | | 684 | reset: |
684 | siisata_device_reset(chp); | | 685 | siisata_device_reset(chp); |
685 | goto out; | | 686 | goto out; |
686 | /* NOTREACHED */ | | 687 | /* NOTREACHED */ |
687 | | | 688 | |
688 | default: | | 689 | default: |
689 | /* | | 690 | /* |
690 | * The command to get the slot failed. Kill outstanding | | 691 | * The command to get the slot failed. Kill outstanding |
691 | * commands for the same drive only. No need to reset | | 692 | * commands for the same drive only. No need to reset |
692 | * the drive, it's unblocked nevertheless. | | 693 | * the drive, it's unblocked nevertheless. |
693 | */ | | 694 | */ |
694 | break; | | 695 | break; |
695 | } | | 696 | } |
696 | | | 697 | |
697 | /* Requeue the non-errorred commands */ | | 698 | /* Requeue the non-errorred commands */ |
698 | for (slot = 0; slot < SIISATA_MAX_SLOTS; slot++) { | | 699 | for (slot = 0; slot < SIISATA_MAX_SLOTS; slot++) { |
699 | if (((schp->sch_active_slots >> slot) & 1) == 0) | | 700 | if (((schp->sch_active_slots >> slot) & 1) == 0) |
700 | continue; | | 701 | continue; |
701 | | | 702 | |
702 | xfer = ata_queue_hwslot_to_xfer(chp, slot); | | 703 | xfer = ata_queue_hwslot_to_xfer(chp, slot); |
703 | if (xfer->c_drive != drive) | | 704 | if (xfer->c_drive != drive) |
704 | continue; | | 705 | continue; |
705 | | | 706 | |
706 | xfer->c_kill_xfer(chp, xfer, | | 707 | xfer->c_kill_xfer(chp, xfer, |
707 | (error == 0) ? KILL_REQUEUE : KILL_RESET); | | 708 | (error == 0) ? KILL_REQUEUE : KILL_RESET); |
708 | } | | 709 | } |
709 | | | 710 | |
710 | out: | | 711 | out: |
711 | /* Drive unblocked, back to normal operation */ | | 712 | /* Drive unblocked, back to normal operation */ |
712 | schp->sch_recovering = false; | | 713 | schp->sch_recovering = false; |
713 | atastart(chp); | | 714 | atastart(chp); |
714 | } | | 715 | } |
715 | | | 716 | |
716 | void | | 717 | void |
717 | siisata_reset_drive(struct ata_drive_datas *drvp, int flags, uint32_t *sigp) | | 718 | siisata_reset_drive(struct ata_drive_datas *drvp, int flags, uint32_t *sigp) |
718 | { | | 719 | { |
719 | struct ata_channel *chp = drvp->chnl_softc; | | 720 | struct ata_channel *chp = drvp->chnl_softc; |
720 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; | | 721 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; |
721 | struct siisata_channel *schp = (struct siisata_channel *)chp; | | 722 | struct siisata_channel *schp = (struct siisata_channel *)chp; |
722 | struct siisata_prb *prb; | | 723 | struct siisata_prb *prb; |
723 | struct ata_xfer *xfer; | | 724 | struct ata_xfer *xfer; |
724 | uint32_t pss, pis; | | 725 | uint32_t pss, pis; |
725 | int i; | | 726 | int i; |
726 | bool timed_out; | | 727 | bool timed_out; |
727 | | | 728 | |
728 | siisata_reinit_port(chp, drvp->drive); | | 729 | siisata_reinit_port(chp, drvp->drive); |
729 | | | 730 | |
730 | xfer = ata_get_xfer_ext(chp, C_RECOVERY, 0); | | 731 | xfer = ata_get_xfer_ext(chp, C_RECOVERY, 0); |
731 | | | 732 | |
732 | prb = schp->sch_prb[xfer->c_slot]; | | 733 | prb = schp->sch_prb[xfer->c_slot]; |
733 | memset(prb, 0, SIISATA_CMD_SIZE); | | 734 | memset(prb, 0, SIISATA_CMD_SIZE); |
734 | prb->prb_control = | | 735 | prb->prb_control = |
735 | htole16(PRB_CF_SOFT_RESET | PRB_CF_INTERRUPT_MASK); | | 736 | htole16(PRB_CF_SOFT_RESET | PRB_CF_INTERRUPT_MASK); |
736 | KASSERT(drvp->drive <= PMP_PORT_CTL); | | 737 | KASSERT(drvp->drive <= PMP_PORT_CTL); |
737 | prb->prb_fis[rhd_c] = drvp->drive; | | 738 | prb->prb_fis[rhd_c] = drvp->drive; |
738 | | | 739 | |
739 | siisata_disable_port_interrupt(chp); | | 740 | siisata_disable_port_interrupt(chp); |
740 | | | 741 | |
741 | siisata_activate_prb(schp, xfer->c_slot); | | 742 | siisata_activate_prb(schp, xfer->c_slot); |
742 | | | 743 | |
743 | timed_out = true; | | 744 | timed_out = true; |
744 | for(i = 0; i < WDC_RESET_WAIT / 10; i++) { | | 745 | for(i = 0; i < WDC_RESET_WAIT / 10; i++) { |
745 | pss = PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)); | | 746 | pss = PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)); |
746 | if ((pss & PR_PXSS(xfer->c_slot)) == 0) { | | 747 | if ((pss & PR_PXSS(xfer->c_slot)) == 0) { |
747 | timed_out = false; | | 748 | timed_out = false; |
748 | break; | | 749 | break; |
749 | } | | 750 | } |
750 | if (pss & PR_PSS_ATTENTION) | | 751 | if (pss & PR_PSS_ATTENTION) |
751 | break; | | 752 | break; |
752 | ata_delay(10, "siiprb", flags); | | 753 | ata_delay(10, "siiprb", flags); |
753 | } | | 754 | } |
754 | | | 755 | |
755 | siisata_deactivate_prb(schp, xfer->c_slot); | | 756 | siisata_deactivate_prb(schp, xfer->c_slot); |
756 | | | 757 | |
757 | if ((pss & PR_PSS_ATTENTION) != 0) { | | 758 | if ((pss & PR_PSS_ATTENTION) != 0) { |
758 | pis = PRREAD(sc, PRX(chp->ch_channel, PRO_PIS)); | | 759 | pis = PRREAD(sc, PRX(chp->ch_channel, PRO_PIS)); |
759 | const uint32_t ps = PRREAD(sc, PRX(chp->ch_channel, PRO_PS)); | | 760 | const uint32_t ps = PRREAD(sc, PRX(chp->ch_channel, PRO_PS)); |
760 | const u_int slot = PR_PS_ACTIVE_SLOT(ps); | | 761 | const u_int slot = PR_PS_ACTIVE_SLOT(ps); |
761 | | | 762 | |
762 | if (slot != xfer->c_slot) | | 763 | if (slot != xfer->c_slot) |
763 | device_printf(sc->sc_atac.atac_dev, "%s port %d " | | 764 | device_printf(sc->sc_atac.atac_dev, "%s port %d " |
764 | "drive %d slot %d c_slot %d", __func__, | | 765 | "drive %d slot %d c_slot %d", __func__, |
765 | chp->ch_channel, drvp->drive, slot, xfer->c_slot); | | 766 | chp->ch_channel, drvp->drive, slot, xfer->c_slot); |
766 | | | 767 | |
767 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), pis & | | 768 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), pis & |
768 | PR_PIS_CMDERRR); | | 769 | PR_PIS_CMDERRR); |
769 | } | | 770 | } |
770 | | | 771 | |
771 | siisata_enable_port_interrupt(chp); | | 772 | siisata_enable_port_interrupt(chp); |
772 | | | 773 | |
773 | if (timed_out) { | | 774 | if (timed_out) { |
774 | /* timeout */ | | 775 | /* timeout */ |
775 | siisata_device_reset(chp); /* XXX is this right? */ | | 776 | siisata_device_reset(chp); /* XXX is this right? */ |
776 | if (sigp) | | 777 | if (sigp) |
777 | *sigp = 0xffffffff; | | 778 | *sigp = 0xffffffff; |
778 | } else { | | 779 | } else { |
779 | /* read the signature out of the FIS */ | | 780 | /* read the signature out of the FIS */ |
780 | if (sigp) { | | 781 | if (sigp) { |
781 | *sigp = 0; | | 782 | *sigp = 0; |
782 | *sigp |= (PRREAD(sc, PRSX(chp->ch_channel, xfer->c_slot, | | 783 | *sigp |= (PRREAD(sc, PRSX(chp->ch_channel, xfer->c_slot, |
783 | PRSO_FIS+0x4)) & 0x00ffffff) << 8; | | 784 | PRSO_FIS+0x4)) & 0x00ffffff) << 8; |
784 | *sigp |= PRREAD(sc, PRSX(chp->ch_channel, xfer->c_slot, | | 785 | *sigp |= PRREAD(sc, PRSX(chp->ch_channel, xfer->c_slot, |
785 | PRSO_FIS+0xc)) & 0xff; | | 786 | PRSO_FIS+0xc)) & 0xff; |
786 | } | | 787 | } |
787 | } | | 788 | } |
788 | | | 789 | |
789 | ata_free_xfer(chp, xfer); | | 790 | ata_free_xfer(chp, xfer); |
790 | | | 791 | |
791 | return; | | 792 | return; |
792 | } | | 793 | } |
793 | | | 794 | |
794 | void | | 795 | void |
795 | siisata_reset_channel(struct ata_channel *chp, int flags) | | 796 | siisata_reset_channel(struct ata_channel *chp, int flags) |
796 | { | | 797 | { |
797 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; | | 798 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; |
798 | struct siisata_channel *schp = (struct siisata_channel *)chp; | | 799 | struct siisata_channel *schp = (struct siisata_channel *)chp; |
799 | | | 800 | |
800 | SIISATA_DEBUG_PRINT(("%s: %s channel %d\n", SIISATANAME(sc), __func__, | | 801 | SIISATA_DEBUG_PRINT(("%s: %s channel %d\n", SIISATANAME(sc), __func__, |
801 | chp->ch_channel), DEBUG_FUNCS); | | 802 | chp->ch_channel), DEBUG_FUNCS); |
802 | | | 803 | |
803 | if (sata_reset_interface(chp, sc->sc_prt, schp->sch_scontrol, | | 804 | if (sata_reset_interface(chp, sc->sc_prt, schp->sch_scontrol, |
804 | schp->sch_sstatus, flags) != SStatus_DET_DEV) { | | 805 | schp->sch_sstatus, flags) != SStatus_DET_DEV) { |
805 | aprint_error("%s port %d: reset failed\n", | | 806 | aprint_error("%s port %d: reset failed\n", |
806 | SIISATANAME(sc), chp->ch_channel); | | 807 | SIISATANAME(sc), chp->ch_channel); |
807 | /* XXX and then ? */ | | 808 | /* XXX and then ? */ |
808 | } | | 809 | } |
809 | | | 810 | |
810 | siisata_device_reset(chp); | | 811 | siisata_device_reset(chp); |
811 | | | 812 | |
812 | PRWRITE(sc, PRX(chp->ch_channel, PRO_SERROR), | | 813 | PRWRITE(sc, PRX(chp->ch_channel, PRO_SERROR), |
813 | PRREAD(sc, PRX(chp->ch_channel, PRO_SERROR))); | | 814 | PRREAD(sc, PRX(chp->ch_channel, PRO_SERROR))); |
814 | | | 815 | |
815 | return; | | 816 | return; |
816 | } | | 817 | } |
817 | | | 818 | |
818 | int | | 819 | int |
819 | siisata_ata_addref(struct ata_drive_datas *drvp) | | 820 | siisata_ata_addref(struct ata_drive_datas *drvp) |
820 | { | | 821 | { |
821 | return 0; | | 822 | return 0; |
822 | } | | 823 | } |
823 | | | 824 | |
824 | void | | 825 | void |
825 | siisata_ata_delref(struct ata_drive_datas *drvp) | | 826 | siisata_ata_delref(struct ata_drive_datas *drvp) |
826 | { | | 827 | { |
827 | return; | | 828 | return; |
828 | } | | 829 | } |
829 | | | 830 | |
830 | void | | 831 | void |
831 | siisata_killpending(struct ata_drive_datas *drvp) | | 832 | siisata_killpending(struct ata_drive_datas *drvp) |
832 | { | | 833 | { |
833 | return; | | 834 | return; |
834 | } | | 835 | } |
835 | | | 836 | |
836 | void | | 837 | void |
837 | siisata_probe_drive(struct ata_channel *chp) | | 838 | siisata_probe_drive(struct ata_channel *chp) |
838 | { | | 839 | { |
839 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; | | 840 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; |
840 | struct siisata_channel *schp = (struct siisata_channel *)chp; | | 841 | struct siisata_channel *schp = (struct siisata_channel *)chp; |
841 | int i; | | 842 | int i; |
842 | uint32_t sig; | | 843 | uint32_t sig; |
843 | struct siisata_prb *prb; | | 844 | struct siisata_prb *prb; |
844 | bool timed_out; | | 845 | bool timed_out; |
845 | struct ata_xfer *xfer; | | 846 | struct ata_xfer *xfer; |
846 | | | 847 | |
847 | SIISATA_DEBUG_PRINT(("%s: %s: port %d start\n", SIISATANAME(sc), | | 848 | SIISATA_DEBUG_PRINT(("%s: %s: port %d start\n", SIISATANAME(sc), |
848 | __func__, chp->ch_channel), DEBUG_FUNCS); | | 849 | __func__, chp->ch_channel), DEBUG_FUNCS); |
849 | | | 850 | |
850 | xfer = ata_get_xfer_ext(chp, 0, 0); | | 851 | xfer = ata_get_xfer_ext(chp, 0, 0); |
851 | if (xfer == NULL) { | | 852 | if (xfer == NULL) { |
852 | aprint_error_dev(sc->sc_atac.atac_dev, | | 853 | aprint_error_dev(sc->sc_atac.atac_dev, |
853 | "failed to get xfer port %d\n", | | 854 | "failed to get xfer port %d\n", |
854 | chp->ch_channel); | | 855 | chp->ch_channel); |
855 | return; | | 856 | return; |
856 | } | | 857 | } |
857 | | | 858 | |
858 | /* | | 859 | /* |
859 | * disable port interrupt as we're polling for PHY up and | | 860 | * disable port interrupt as we're polling for PHY up and |
860 | * prb completion | | 861 | * prb completion |
861 | */ | | 862 | */ |
862 | siisata_disable_port_interrupt(chp); | | 863 | siisata_disable_port_interrupt(chp); |
863 | | | 864 | |
864 | switch(sata_reset_interface(chp, sc->sc_prt, schp->sch_scontrol, | | 865 | switch(sata_reset_interface(chp, sc->sc_prt, schp->sch_scontrol, |
865 | schp->sch_sstatus, AT_WAIT)) { | | 866 | schp->sch_sstatus, AT_WAIT)) { |
866 | case SStatus_DET_DEV: | | 867 | case SStatus_DET_DEV: |
867 | /* clear any interrupts */ | | 868 | /* clear any interrupts */ |
868 | (void)PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)); | | 869 | (void)PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)); |
869 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), 0xffffffff); | | 870 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), 0xffffffff); |
870 | | | 871 | |
871 | /* wait for ready */ | | 872 | /* wait for ready */ |
872 | timed_out = 1; | | 873 | timed_out = 1; |
873 | for (i = 0; i < ATA_DELAY / 10; i++) { | | 874 | for (i = 0; i < ATA_DELAY / 10; i++) { |
874 | if (PRREAD(sc, PRX(chp->ch_channel, PRO_PS)) & | | 875 | if (PRREAD(sc, PRX(chp->ch_channel, PRO_PS)) & |
875 | PR_PS_PORT_READY) { | | 876 | PR_PS_PORT_READY) { |
876 | timed_out = 0; | | 877 | timed_out = 0; |
877 | break; | | 878 | break; |
878 | } | | 879 | } |
879 | | | 880 | |
880 | ata_delay(10, "siiprbrd", AT_WAIT); | | 881 | ata_delay(10, "siiprbrd", AT_WAIT); |
881 | } | | 882 | } |
882 | if (timed_out) { | | 883 | if (timed_out) { |
883 | aprint_error_dev(sc->sc_atac.atac_dev, | | 884 | aprint_error_dev(sc->sc_atac.atac_dev, |
884 | "timed out waiting for PORT_READY on port %d, " | | 885 | "timed out waiting for PORT_READY on port %d, " |
885 | "reinitializing\n", chp->ch_channel); | | 886 | "reinitializing\n", chp->ch_channel); |
886 | siisata_reinit_port(chp, -1); | | 887 | siisata_reinit_port(chp, -1); |
887 | } | | 888 | } |
888 | | | 889 | |
889 | prb = schp->sch_prb[xfer->c_slot]; | | 890 | prb = schp->sch_prb[xfer->c_slot]; |
890 | memset(prb, 0, SIISATA_CMD_SIZE); | | 891 | memset(prb, 0, SIISATA_CMD_SIZE); |
891 | prb->prb_control = htole16(PRB_CF_SOFT_RESET); | | 892 | prb->prb_control = htole16(PRB_CF_SOFT_RESET); |
892 | prb->prb_fis[rhd_c] = PMP_PORT_CTL; | | 893 | prb->prb_fis[rhd_c] = PMP_PORT_CTL; |
893 | | | 894 | |
894 | siisata_activate_prb(schp, xfer->c_slot); | | 895 | siisata_activate_prb(schp, xfer->c_slot); |
895 | | | 896 | |
896 | timed_out = 1; | | 897 | timed_out = 1; |
897 | for(i = 0; i < WDC_RESET_WAIT / 10; i++) { | | 898 | for(i = 0; i < WDC_RESET_WAIT / 10; i++) { |
898 | if ((PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)) & | | 899 | if ((PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)) & |
899 | PR_PXSS(xfer->c_slot)) == 0) { | | 900 | PR_PXSS(xfer->c_slot)) == 0) { |
900 | /* prb completed */ | | 901 | /* prb completed */ |
901 | timed_out = 0; | | 902 | timed_out = 0; |
902 | break; | | 903 | break; |
903 | } | | 904 | } |
904 | if (PRREAD(sc, PRX(chp->ch_channel, PRO_PIS)) & | | 905 | if (PRREAD(sc, PRX(chp->ch_channel, PRO_PIS)) & |
905 | PR_PIS_CMDERRR) { | | 906 | PR_PIS_CMDERRR) { |
906 | /* we got an error; handle as timeout */ | | 907 | /* we got an error; handle as timeout */ |
907 | break; | | 908 | break; |
908 | } | | 909 | } |
909 | | | 910 | |
910 | ata_delay(10, "siiprb", AT_WAIT); | | 911 | ata_delay(10, "siiprb", AT_WAIT); |
911 | } | | 912 | } |
912 | | | 913 | |
913 | siisata_deactivate_prb(schp, xfer->c_slot); | | 914 | siisata_deactivate_prb(schp, xfer->c_slot); |
914 | | | 915 | |
915 | if (timed_out) { | | 916 | if (timed_out) { |
916 | aprint_error_dev(sc->sc_atac.atac_dev, | | 917 | aprint_error_dev(sc->sc_atac.atac_dev, |
917 | "SOFT_RESET failed on port %d (error %d PSS 0x%x PIS 0x%x), " | | 918 | "SOFT_RESET failed on port %d (error %d PSS 0x%x PIS 0x%x), " |
918 | "resetting\n", chp->ch_channel, | | 919 | "resetting\n", chp->ch_channel, |
919 | PRREAD(sc, PRX(chp->ch_channel, PRO_PCE)), | | 920 | PRREAD(sc, PRX(chp->ch_channel, PRO_PCE)), |
920 | PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)), | | 921 | PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)), |
921 | PRREAD(sc, PRX(chp->ch_channel, PRO_PIS))); | | 922 | PRREAD(sc, PRX(chp->ch_channel, PRO_PIS))); |
922 | siisata_reinit_port(chp, -1); | | 923 | siisata_reinit_port(chp, -1); |
923 | break; | | 924 | break; |
924 | } | | 925 | } |
925 | | | 926 | |
926 | /* read the signature out of the FIS */ | | 927 | /* read the signature out of the FIS */ |
927 | sig = 0; | | 928 | sig = 0; |
928 | sig |= (PRREAD(sc, PRSX(chp->ch_channel, xfer->c_slot, | | 929 | sig |= (PRREAD(sc, PRSX(chp->ch_channel, xfer->c_slot, |
929 | PRSO_FIS+0x4)) & 0x00ffffff) << 8; | | 930 | PRSO_FIS+0x4)) & 0x00ffffff) << 8; |
930 | sig |= PRREAD(sc, PRSX(chp->ch_channel, xfer->c_slot, | | 931 | sig |= PRREAD(sc, PRSX(chp->ch_channel, xfer->c_slot, |
931 | PRSO_FIS+0xc)) & 0xff; | | 932 | PRSO_FIS+0xc)) & 0xff; |
932 | | | 933 | |
933 | SIISATA_DEBUG_PRINT(("%s: %s: sig=0x%08x\n", SIISATANAME(sc), | | 934 | SIISATA_DEBUG_PRINT(("%s: %s: sig=0x%08x\n", SIISATANAME(sc), |
934 | __func__, sig), DEBUG_PROBE); | | 935 | __func__, sig), DEBUG_PROBE); |
935 | | | 936 | |
936 | if (sig == 0x96690101) | | 937 | if (sig == 0x96690101) |
937 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PCS), | | 938 | PRWRITE(sc, PRX(chp->ch_channel, PRO_PCS), |
938 | PR_PC_PMP_ENABLE); | | 939 | PR_PC_PMP_ENABLE); |
939 | sata_interpret_sig(chp, 0, sig); | | 940 | sata_interpret_sig(chp, 0, sig); |
940 | break; | | 941 | break; |
941 | default: | | 942 | default: |
942 | break; | | 943 | break; |
943 | } | | 944 | } |
944 | | | 945 | |
945 | siisata_enable_port_interrupt(chp); | | 946 | siisata_enable_port_interrupt(chp); |
946 | | | 947 | |
947 | ata_free_xfer(chp, xfer); | | 948 | ata_free_xfer(chp, xfer); |
948 | | | 949 | |
949 | SIISATA_DEBUG_PRINT(("%s: %s: port %d done\n", SIISATANAME(sc), | | 950 | SIISATA_DEBUG_PRINT(("%s: %s: port %d done\n", SIISATANAME(sc), |
950 | __func__, chp->ch_channel), DEBUG_PROBE); | | 951 | __func__, chp->ch_channel), DEBUG_PROBE); |
951 | return; | | 952 | return; |
952 | } | | 953 | } |
953 | | | 954 | |
954 | void | | 955 | void |
955 | siisata_setup_channel(struct ata_channel *chp) | | 956 | siisata_setup_channel(struct ata_channel *chp) |
956 | { | | 957 | { |
957 | return; | | 958 | return; |
958 | } | | 959 | } |
959 | | | 960 | |
960 | int | | 961 | int |
961 | siisata_exec_command(struct ata_drive_datas *drvp, struct ata_xfer *xfer) | | 962 | siisata_exec_command(struct ata_drive_datas *drvp, struct ata_xfer *xfer) |
962 | { | | 963 | { |
963 | struct ata_channel *chp = drvp->chnl_softc; | | 964 | struct ata_channel *chp = drvp->chnl_softc; |
964 | struct ata_command *ata_c = &xfer->c_ata_c; | | 965 | struct ata_command *ata_c = &xfer->c_ata_c; |
965 | int ret; | | 966 | int ret; |
966 | int s; | | 967 | int s; |
967 | | | 968 | |
968 | SIISATA_DEBUG_PRINT(("%s: %s begins\n", | | 969 | SIISATA_DEBUG_PRINT(("%s: %s begins\n", |
969 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__), | | 970 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__), |
970 | DEBUG_FUNCS); | | 971 | DEBUG_FUNCS); |
971 | | | 972 | |
972 | if (ata_c->flags & AT_POLL) | | 973 | if (ata_c->flags & AT_POLL) |
973 | xfer->c_flags |= C_POLL; | | 974 | xfer->c_flags |= C_POLL; |
974 | if (ata_c->flags & AT_WAIT) | | 975 | if (ata_c->flags & AT_WAIT) |
975 | xfer->c_flags |= C_WAIT; | | 976 | xfer->c_flags |= C_WAIT; |
976 | xfer->c_drive = drvp->drive; | | 977 | xfer->c_drive = drvp->drive; |
977 | xfer->c_databuf = ata_c->data; | | 978 | xfer->c_databuf = ata_c->data; |
978 | xfer->c_bcount = ata_c->bcount; | | 979 | xfer->c_bcount = ata_c->bcount; |
979 | xfer->c_start = siisata_cmd_start; | | 980 | xfer->c_start = siisata_cmd_start; |
980 | xfer->c_intr = siisata_cmd_complete; | | 981 | xfer->c_intr = siisata_cmd_complete; |
981 | xfer->c_kill_xfer = siisata_cmd_kill_xfer; | | 982 | xfer->c_kill_xfer = siisata_cmd_kill_xfer; |
982 | s = splbio(); | | 983 | s = splbio(); |
983 | ata_exec_xfer(chp, xfer); | | 984 | ata_exec_xfer(chp, xfer); |
984 | #ifdef DIAGNOSTIC | | 985 | #ifdef DIAGNOSTIC |
985 | if ((ata_c->flags & AT_POLL) != 0 && | | 986 | if ((ata_c->flags & AT_POLL) != 0 && |
986 | (ata_c->flags & AT_DONE) == 0) | | 987 | (ata_c->flags & AT_DONE) == 0) |
987 | panic("%s: polled command not done", __func__); | | 988 | panic("%s: polled command not done", __func__); |
988 | #endif | | 989 | #endif |
989 | if (ata_c->flags & AT_DONE) { | | 990 | if (ata_c->flags & AT_DONE) { |
990 | ret = ATACMD_COMPLETE; | | 991 | ret = ATACMD_COMPLETE; |
991 | } else { | | 992 | } else { |
992 | if (ata_c->flags & AT_WAIT) { | | 993 | if (ata_c->flags & AT_WAIT) { |
993 | while ((ata_c->flags & AT_DONE) == 0) { | | 994 | while ((ata_c->flags & AT_DONE) == 0) { |
994 | SIISATA_DEBUG_PRINT(("%s: %s: sleeping\n", | | 995 | SIISATA_DEBUG_PRINT(("%s: %s: sleeping\n", |
995 | SIISATANAME( | | 996 | SIISATANAME( |
996 | (struct siisata_softc *)chp->ch_atac), | | 997 | (struct siisata_softc *)chp->ch_atac), |
997 | __func__), DEBUG_FUNCS); | | 998 | __func__), DEBUG_FUNCS); |
998 | tsleep(ata_c, PRIBIO, "siicmd", 0); | | 999 | tsleep(ata_c, PRIBIO, "siicmd", 0); |
999 | } | | 1000 | } |
1000 | ret = ATACMD_COMPLETE; | | 1001 | ret = ATACMD_COMPLETE; |
1001 | } else { | | 1002 | } else { |
1002 | ret = ATACMD_QUEUED; | | 1003 | ret = ATACMD_QUEUED; |
1003 | } | | 1004 | } |
1004 | } | | 1005 | } |
1005 | splx(s); | | 1006 | splx(s); |
1006 | SIISATA_DEBUG_PRINT( ("%s: %s ends\n", | | 1007 | SIISATA_DEBUG_PRINT( ("%s: %s ends\n", |
1007 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__), | | 1008 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__), |
1008 | DEBUG_FUNCS); | | 1009 | DEBUG_FUNCS); |
1009 | return ret; | | 1010 | return ret; |
1010 | } | | 1011 | } |
1011 | | | 1012 | |
1012 | void | | 1013 | void |
1013 | siisata_cmd_start(struct ata_channel *chp, struct ata_xfer *xfer) | | 1014 | siisata_cmd_start(struct ata_channel *chp, struct ata_xfer *xfer) |
1014 | { | | 1015 | { |
1015 | struct siisata_channel *schp = (struct siisata_channel *)chp; | | 1016 | struct siisata_channel *schp = (struct siisata_channel *)chp; |
1016 | struct ata_command *ata_c = &xfer->c_ata_c; | | 1017 | struct ata_command *ata_c = &xfer->c_ata_c; |
1017 | struct siisata_prb *prb; | | 1018 | struct siisata_prb *prb; |
1018 | int i; | | 1019 | int i; |
1019 | | | 1020 | |
1020 | SIISATA_DEBUG_PRINT(("%s: %s port %d drive %d command 0x%x, slot %d\n", | | 1021 | SIISATA_DEBUG_PRINT(("%s: %s port %d drive %d command 0x%x, slot %d\n", |
1021 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__, | | 1022 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__, |
1022 | chp->ch_channel, xfer->c_drive, ata_c->r_command, xfer->c_slot), | | 1023 | chp->ch_channel, xfer->c_drive, ata_c->r_command, xfer->c_slot), |
1023 | DEBUG_FUNCS|DEBUG_XFERS); | | 1024 | DEBUG_FUNCS|DEBUG_XFERS); |
1024 | | | 1025 | |
1025 | prb = schp->sch_prb[xfer->c_slot]; | | 1026 | prb = schp->sch_prb[xfer->c_slot]; |
1026 | memset(prb, 0, SIISATA_CMD_SIZE); | | 1027 | memset(prb, 0, SIISATA_CMD_SIZE); |
1027 | | | 1028 | |
1028 | satafis_rhd_construct_cmd(ata_c, prb->prb_fis); | | 1029 | satafis_rhd_construct_cmd(ata_c, prb->prb_fis); |
1029 | KASSERT(xfer->c_drive <= PMP_PORT_CTL); | | 1030 | KASSERT(xfer->c_drive <= PMP_PORT_CTL); |
1030 | prb->prb_fis[rhd_c] |= xfer->c_drive; | | 1031 | prb->prb_fis[rhd_c] |= xfer->c_drive; |
1031 | | | 1032 | |
1032 | if (ata_c->r_command == ATA_DATA_SET_MANAGEMENT) { | | 1033 | if (ata_c->r_command == ATA_DATA_SET_MANAGEMENT) { |
1033 | prb->prb_control |= htole16(PRB_CF_PROTOCOL_OVERRIDE); | | 1034 | prb->prb_control |= htole16(PRB_CF_PROTOCOL_OVERRIDE); |
1034 | prb->prb_protocol_override |= htole16(PRB_PO_WRITE); | | 1035 | prb->prb_protocol_override |= htole16(PRB_PO_WRITE); |
1035 | } | | 1036 | } |
1036 | | | 1037 | |
1037 | if (siisata_dma_setup(chp, xfer->c_slot, | | 1038 | if (siisata_dma_setup(chp, xfer->c_slot, |
1038 | (ata_c->flags & (AT_READ | AT_WRITE)) ? ata_c->data : NULL, | | 1039 | (ata_c->flags & (AT_READ | AT_WRITE)) ? ata_c->data : NULL, |
1039 | ata_c->bcount, | | 1040 | ata_c->bcount, |
1040 | (ata_c->flags & AT_READ) ? BUS_DMA_READ : BUS_DMA_WRITE)) { | | 1041 | (ata_c->flags & AT_READ) ? BUS_DMA_READ : BUS_DMA_WRITE)) { |
1041 | ata_c->flags |= AT_DF; | | 1042 | ata_c->flags |= AT_DF; |
1042 | siisata_cmd_complete(chp, xfer, 0); | | 1043 | siisata_cmd_complete(chp, xfer, 0); |
1043 | return; | | 1044 | return; |
1044 | } | | 1045 | } |
1045 | | | 1046 | |
1046 | if (xfer->c_flags & C_POLL) { | | 1047 | if (xfer->c_flags & C_POLL) { |
1047 | /* polled command, disable interrupts */ | | 1048 | /* polled command, disable interrupts */ |
1048 | prb->prb_control |= htole16(PRB_CF_INTERRUPT_MASK); | | 1049 | prb->prb_control |= htole16(PRB_CF_INTERRUPT_MASK); |
1049 | siisata_disable_port_interrupt(chp); | | 1050 | siisata_disable_port_interrupt(chp); |
1050 | } | | 1051 | } |
1051 | | | 1052 | |
1052 | /* go for it */ | | 1053 | /* go for it */ |
1053 | siisata_activate_prb(schp, xfer->c_slot); | | 1054 | siisata_activate_prb(schp, xfer->c_slot); |
1054 | | | 1055 | |
1055 | if ((ata_c->flags & AT_POLL) == 0) { | | 1056 | if ((ata_c->flags & AT_POLL) == 0) { |
1056 | callout_reset(&xfer->c_timo_callout, mstohz(ata_c->timeout), | | 1057 | callout_reset(&xfer->c_timo_callout, mstohz(ata_c->timeout), |
1057 | ata_timeout, xfer); | | 1058 | ata_timeout, xfer); |
1058 | goto out; | | 1059 | goto out; |
1059 | } | | 1060 | } |
1060 | | | 1061 | |
1061 | /* | | 1062 | /* |
1062 | * polled command | | 1063 | * polled command |
1063 | */ | | 1064 | */ |
1064 | for (i = 0; i < ata_c->timeout * 10; i++) { | | 1065 | for (i = 0; i < ata_c->timeout * 10; i++) { |
1065 | if (ata_c->flags & AT_DONE) | | 1066 | if (ata_c->flags & AT_DONE) |
1066 | break; | | 1067 | break; |
1067 | siisata_intr_port(schp); | | 1068 | siisata_intr_port(schp); |
1068 | DELAY(100); | | 1069 | DELAY(100); |
1069 | } | | 1070 | } |
1070 | | | 1071 | |
1071 | if ((ata_c->flags & AT_DONE) == 0) { | | 1072 | if ((ata_c->flags & AT_DONE) == 0) { |
1072 | ata_timeout(xfer); | | 1073 | ata_timeout(xfer); |
1073 | } | | 1074 | } |
1074 | | | 1075 | |
1075 | /* reenable interrupts */ | | 1076 | /* reenable interrupts */ |
1076 | siisata_enable_port_interrupt(chp); | | 1077 | siisata_enable_port_interrupt(chp); |
1077 | out: | | 1078 | out: |
1078 | SIISATA_DEBUG_PRINT(("%s: %s: done\n", | | 1079 | SIISATA_DEBUG_PRINT(("%s: %s: done\n", |
1079 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__), | | 1080 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__), |
1080 | DEBUG_FUNCS); | | 1081 | DEBUG_FUNCS); |
1081 | return; | | 1082 | return; |
1082 | } | | 1083 | } |
1083 | | | 1084 | |
1084 | void | | 1085 | void |
1085 | siisata_cmd_kill_xfer(struct ata_channel *chp, struct ata_xfer *xfer, | | 1086 | siisata_cmd_kill_xfer(struct ata_channel *chp, struct ata_xfer *xfer, |
1086 | int reason) | | 1087 | int reason) |
1087 | { | | 1088 | { |
1088 | struct ata_command *ata_c = &xfer->c_ata_c; | | 1089 | struct ata_command *ata_c = &xfer->c_ata_c; |
1089 | struct siisata_channel *schp = (struct siisata_channel *)chp; | | 1090 | struct siisata_channel *schp = (struct siisata_channel *)chp; |
1090 | bool deactivate = true; | | 1091 | bool deactivate = true; |
1091 | | | 1092 | |
1092 | switch (reason) { | | 1093 | switch (reason) { |
1093 | case KILL_GONE_INACTIVE: | | 1094 | case KILL_GONE_INACTIVE: |
1094 | deactivate = false; | | 1095 | deactivate = false; |
1095 | /* FALLTHROUGH */ | | 1096 | /* FALLTHROUGH */ |
1096 | case KILL_GONE: | | 1097 | case KILL_GONE: |
1097 | ata_c->flags |= AT_GONE; | | 1098 | ata_c->flags |= AT_GONE; |
1098 | break; | | 1099 | break; |
1099 | case KILL_RESET: | | 1100 | case KILL_RESET: |
1100 | ata_c->flags |= AT_RESET; | | 1101 | ata_c->flags |= AT_RESET; |
1101 | break; | | 1102 | break; |
1102 | case KILL_REQUEUE: | | 1103 | case KILL_REQUEUE: |
1103 | panic("%s: not supposed to be requeued\n", __func__); | | 1104 | panic("%s: not supposed to be requeued\n", __func__); |
1104 | break; | | 1105 | break; |
1105 | default: | | 1106 | default: |
1106 | panic("%s: port %d: unknown reason %d", | | 1107 | panic("%s: port %d: unknown reason %d", |
1107 | __func__, chp->ch_channel, reason); | | 1108 | __func__, chp->ch_channel, reason); |
1108 | } | | 1109 | } |
1109 | | | 1110 | |
1110 | if (deactivate) { | | 1111 | if (deactivate) { |
1111 | siisata_deactivate_prb(schp, xfer->c_slot); | | 1112 | siisata_deactivate_prb(schp, xfer->c_slot); |
1112 | ata_deactivate_xfer(chp, xfer); | | 1113 | ata_deactivate_xfer(chp, xfer); |
1113 | } | | 1114 | } |
1114 | | | 1115 | |
1115 | siisata_cmd_done_end(chp, xfer); | | 1116 | siisata_cmd_done_end(chp, xfer); |
1116 | } | | 1117 | } |
1117 | | | 1118 | |
1118 | int | | 1119 | int |
1119 | siisata_cmd_complete(struct ata_channel *chp, struct ata_xfer *xfer, int tfd) | | 1120 | siisata_cmd_complete(struct ata_channel *chp, struct ata_xfer *xfer, int tfd) |
1120 | { | | 1121 | { |
1121 | struct siisata_channel *schp = (struct siisata_channel *)chp; | | 1122 | struct siisata_channel *schp = (struct siisata_channel *)chp; |
1122 | struct ata_command *ata_c = &xfer->c_ata_c; | | 1123 | struct ata_command *ata_c = &xfer->c_ata_c; |
1123 | #ifdef SIISATA_DEBUG | | 1124 | #ifdef SIISATA_DEBUG |
1124 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; | | 1125 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; |
1125 | #endif | | 1126 | #endif |
1126 | | | 1127 | |
1127 | SIISATA_DEBUG_PRINT(("%s: %s: port %d slot %d\n", | | 1128 | SIISATA_DEBUG_PRINT(("%s: %s: port %d slot %d\n", |
1128 | SIISATANAME(sc), __func__, | | 1129 | SIISATANAME(sc), __func__, |
1129 | chp->ch_channel, xfer->c_slot), DEBUG_FUNCS); | | 1130 | chp->ch_channel, xfer->c_slot), DEBUG_FUNCS); |
1130 | SIISATA_DEBUG_PRINT(("%s: %s\n", SIISATANAME(sc), __func__), | | 1131 | SIISATA_DEBUG_PRINT(("%s: %s\n", SIISATANAME(sc), __func__), |
1131 | DEBUG_FUNCS|DEBUG_XFERS); | | 1132 | DEBUG_FUNCS|DEBUG_XFERS); |
1132 | | | 1133 | |
1133 | if (ata_waitdrain_xfer_check(chp, xfer)) | | 1134 | if (ata_waitdrain_xfer_check(chp, xfer)) |
1134 | return 0; | | 1135 | return 0; |
1135 | | | 1136 | |
1136 | siisata_deactivate_prb(schp, xfer->c_slot); | | 1137 | siisata_deactivate_prb(schp, xfer->c_slot); |
1137 | ata_deactivate_xfer(chp, xfer); | | 1138 | ata_deactivate_xfer(chp, xfer); |
1138 | | | 1139 | |
1139 | if (xfer->c_flags & C_TIMEOU) | | 1140 | if (xfer->c_flags & C_TIMEOU) |
1140 | ata_c->flags |= AT_TIMEOU; | | 1141 | ata_c->flags |= AT_TIMEOU; |
1141 | | | 1142 | |
1142 | if (ATACH_ST(tfd) & WDCS_BSY) { | | 1143 | if (ATACH_ST(tfd) & WDCS_BSY) { |
1143 | ata_c->flags |= AT_TIMEOU; | | 1144 | ata_c->flags |= AT_TIMEOU; |
1144 | } else if (ATACH_ST(tfd) & WDCS_ERR) { | | 1145 | } else if (ATACH_ST(tfd) & WDCS_ERR) { |
1145 | ata_c->r_error = ATACH_ERR(tfd); | | 1146 | ata_c->r_error = ATACH_ERR(tfd); |
1146 | ata_c->flags |= AT_ERROR; | | 1147 | ata_c->flags |= AT_ERROR; |
1147 | } | | 1148 | } |
1148 | | | 1149 | |
1149 | siisata_cmd_done(chp, xfer, tfd); | | 1150 | siisata_cmd_done(chp, xfer, tfd); |
1150 | | | 1151 | |
1151 | return 0; | | 1152 | return 0; |
1152 | } | | 1153 | } |
1153 | | | 1154 | |
1154 | void | | 1155 | void |
1155 | siisata_cmd_done(struct ata_channel *chp, struct ata_xfer *xfer, int tfd) | | 1156 | siisata_cmd_done(struct ata_channel *chp, struct ata_xfer *xfer, int tfd) |
1156 | { | | 1157 | { |
1157 | uint32_t fis[howmany(RDH_FISLEN,sizeof(uint32_t))]; | | 1158 | uint32_t fis[howmany(RDH_FISLEN,sizeof(uint32_t))]; |
1158 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; | | 1159 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; |
1159 | struct siisata_channel *schp = (struct siisata_channel *)chp; | | 1160 | struct siisata_channel *schp = (struct siisata_channel *)chp; |
1160 | struct ata_command *ata_c = &xfer->c_ata_c; | | 1161 | struct ata_command *ata_c = &xfer->c_ata_c; |
1161 | uint16_t *idwordbuf; | | 1162 | uint16_t *idwordbuf; |
1162 | int i; | | 1163 | int i; |
1163 | | | 1164 | |
1164 | SIISATA_DEBUG_PRINT(("%s: %s flags 0x%x error 0x%x\n", SIISATANAME(sc), | | 1165 | SIISATA_DEBUG_PRINT(("%s: %s flags 0x%x error 0x%x\n", SIISATANAME(sc), |
1165 | __func__, ata_c->flags, ata_c->r_error), DEBUG_FUNCS|DEBUG_XFERS); | | 1166 | __func__, ata_c->flags, ata_c->r_error), DEBUG_FUNCS|DEBUG_XFERS); |
1166 | | | 1167 | |
1167 | if (ata_c->flags & (AT_READ | AT_WRITE)) { | | 1168 | if (ata_c->flags & (AT_READ | AT_WRITE)) { |
1168 | bus_dmamap_sync(sc->sc_dmat, schp->sch_datad[xfer->c_slot], 0, | | 1169 | bus_dmamap_sync(sc->sc_dmat, schp->sch_datad[xfer->c_slot], 0, |
1169 | schp->sch_datad[xfer->c_slot]->dm_mapsize, | | 1170 | schp->sch_datad[xfer->c_slot]->dm_mapsize, |
1170 | (ata_c->flags & AT_READ) ? BUS_DMASYNC_POSTREAD : | | 1171 | (ata_c->flags & AT_READ) ? BUS_DMASYNC_POSTREAD : |
1171 | BUS_DMASYNC_POSTWRITE); | | 1172 | BUS_DMASYNC_POSTWRITE); |
1172 | bus_dmamap_unload(sc->sc_dmat, schp->sch_datad[xfer->c_slot]); | | 1173 | bus_dmamap_unload(sc->sc_dmat, schp->sch_datad[xfer->c_slot]); |
1173 | } | | 1174 | } |
1174 | | | 1175 | |
1175 | if (ata_c->flags & AT_READREG) { | | 1176 | if (ata_c->flags & AT_READREG) { |
1176 | bus_space_read_region_stream_4(sc->sc_prt, sc->sc_prh, | | 1177 | bus_space_read_region_stream_4(sc->sc_prt, sc->sc_prh, |
1177 | PRSX(chp->ch_channel, xfer->c_slot, PRSO_FIS), | | 1178 | PRSX(chp->ch_channel, xfer->c_slot, PRSO_FIS), |
1178 | fis, __arraycount(fis)); | | 1179 | fis, __arraycount(fis)); |
1179 | satafis_rdh_cmd_readreg(ata_c, (uint8_t *)fis); | | 1180 | satafis_rdh_cmd_readreg(ata_c, (uint8_t *)fis); |
1180 | } | | 1181 | } |
1181 | | | 1182 | |
1182 | /* correct the endianess of IDENTIFY data */ | | 1183 | /* correct the endianess of IDENTIFY data */ |
1183 | if (ata_c->r_command == WDCC_IDENTIFY || | | 1184 | if (ata_c->r_command == WDCC_IDENTIFY || |
1184 | ata_c->r_command == ATAPI_IDENTIFY_DEVICE) { | | 1185 | ata_c->r_command == ATAPI_IDENTIFY_DEVICE) { |
1185 | idwordbuf = xfer->c_databuf; | | 1186 | idwordbuf = xfer->c_databuf; |
1186 | for (i = 0; i < (xfer->c_bcount / sizeof(*idwordbuf)); i++) { | | 1187 | for (i = 0; i < (xfer->c_bcount / sizeof(*idwordbuf)); i++) { |
1187 | idwordbuf[i] = le16toh(idwordbuf[i]); | | 1188 | idwordbuf[i] = le16toh(idwordbuf[i]); |
1188 | } | | 1189 | } |
1189 | } | | 1190 | } |
1190 | | | 1191 | |
1191 | if (PRREAD(sc, PRSX(chp->ch_channel, xfer->c_slot, PRSO_RTC))) | | 1192 | if (PRREAD(sc, PRSX(chp->ch_channel, xfer->c_slot, PRSO_RTC))) |
1192 | ata_c->flags |= AT_XFDONE; | | 1193 | ata_c->flags |= AT_XFDONE; |
1193 | | | 1194 | |
1194 | siisata_cmd_done_end(chp, xfer); | | 1195 | siisata_cmd_done_end(chp, xfer); |
1195 | if ((ATACH_ST(tfd) & WDCS_ERR) == 0) | | 1196 | if ((ATACH_ST(tfd) & WDCS_ERR) == 0) |
1196 | atastart(chp); | | 1197 | atastart(chp); |
1197 | } | | 1198 | } |
1198 | | | 1199 | |
1199 | static void | | 1200 | static void |
1200 | siisata_cmd_done_end(struct ata_channel *chp, struct ata_xfer *xfer) | | 1201 | siisata_cmd_done_end(struct ata_channel *chp, struct ata_xfer *xfer) |
1201 | { | | 1202 | { |
1202 | struct ata_command *ata_c = &xfer->c_ata_c; | | 1203 | struct ata_command *ata_c = &xfer->c_ata_c; |
1203 | | | 1204 | |
1204 | ata_c->flags |= AT_DONE; | | 1205 | ata_c->flags |= AT_DONE; |
1205 | | | 1206 | |
1206 | if (ata_c->flags & AT_WAIT) | | 1207 | if (ata_c->flags & AT_WAIT) |
1207 | wakeup(ata_c); | | 1208 | wakeup(ata_c); |
1208 | return; | | 1209 | return; |
1209 | } | | 1210 | } |
1210 | | | 1211 | |
1211 | int | | 1212 | int |
1212 | siisata_ata_bio(struct ata_drive_datas *drvp, struct ata_xfer *xfer) | | 1213 | siisata_ata_bio(struct ata_drive_datas *drvp, struct ata_xfer *xfer) |
1213 | { | | 1214 | { |
1214 | struct ata_channel *chp = drvp->chnl_softc; | | 1215 | struct ata_channel *chp = drvp->chnl_softc; |
1215 | struct ata_bio *ata_bio = &xfer->c_bio; | | 1216 | struct ata_bio *ata_bio = &xfer->c_bio; |
1216 | | | 1217 | |
1217 | SIISATA_DEBUG_PRINT(("%s: %s.\n", | | 1218 | SIISATA_DEBUG_PRINT(("%s: %s.\n", |
1218 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__), | | 1219 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__), |
1219 | DEBUG_FUNCS); | | 1220 | DEBUG_FUNCS); |
1220 | | | 1221 | |
1221 | if (xfer == NULL) | | 1222 | if (xfer == NULL) |
1222 | return ATACMD_TRY_AGAIN; | | 1223 | return ATACMD_TRY_AGAIN; |
1223 | if (ata_bio->flags & ATA_POLL) | | 1224 | if (ata_bio->flags & ATA_POLL) |
1224 | xfer->c_flags |= C_POLL; | | 1225 | xfer->c_flags |= C_POLL; |
1225 | xfer->c_drive = drvp->drive; | | 1226 | xfer->c_drive = drvp->drive; |
1226 | xfer->c_databuf = ata_bio->databuf; | | 1227 | xfer->c_databuf = ata_bio->databuf; |
1227 | xfer->c_bcount = ata_bio->bcount; | | 1228 | xfer->c_bcount = ata_bio->bcount; |
1228 | xfer->c_start = siisata_bio_start; | | 1229 | xfer->c_start = siisata_bio_start; |
1229 | xfer->c_intr = siisata_bio_complete; | | 1230 | xfer->c_intr = siisata_bio_complete; |
1230 | xfer->c_kill_xfer = siisata_bio_kill_xfer; | | 1231 | xfer->c_kill_xfer = siisata_bio_kill_xfer; |
1231 | ata_exec_xfer(chp, xfer); | | 1232 | ata_exec_xfer(chp, xfer); |
1232 | return (ata_bio->flags & ATA_ITSDONE) ? | | 1233 | return (ata_bio->flags & ATA_ITSDONE) ? |
1233 | ATACMD_COMPLETE : ATACMD_QUEUED; | | 1234 | ATACMD_COMPLETE : ATACMD_QUEUED; |
1234 | } | | 1235 | } |
1235 | | | 1236 | |
1236 | void | | 1237 | void |
1237 | siisata_bio_start(struct ata_channel *chp, struct ata_xfer *xfer) | | 1238 | siisata_bio_start(struct ata_channel *chp, struct ata_xfer *xfer) |
1238 | { | | 1239 | { |
1239 | struct siisata_channel *schp = (struct siisata_channel *)chp; | | 1240 | struct siisata_channel *schp = (struct siisata_channel *)chp; |
1240 | struct siisata_prb *prb; | | 1241 | struct siisata_prb *prb; |
1241 | struct ata_bio *ata_bio = &xfer->c_bio; | | 1242 | struct ata_bio *ata_bio = &xfer->c_bio; |
1242 | int i; | | 1243 | int i; |
1243 | | | 1244 | |
1244 | SIISATA_DEBUG_PRINT(("%s: %s port %d slot %d drive %d\n", | | 1245 | SIISATA_DEBUG_PRINT(("%s: %s port %d slot %d drive %d\n", |
1245 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__, | | 1246 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__, |
1246 | chp->ch_channel, xfer->c_slot, xfer->c_drive), DEBUG_FUNCS); | | 1247 | chp->ch_channel, xfer->c_slot, xfer->c_drive), DEBUG_FUNCS); |
1247 | | | 1248 | |
1248 | prb = schp->sch_prb[xfer->c_slot]; | | 1249 | prb = schp->sch_prb[xfer->c_slot]; |
1249 | memset(prb, 0, SIISATA_CMD_SIZE); | | 1250 | memset(prb, 0, SIISATA_CMD_SIZE); |
1250 | | | 1251 | |
1251 | satafis_rhd_construct_bio(xfer, prb->prb_fis); | | 1252 | satafis_rhd_construct_bio(xfer, prb->prb_fis); |
1252 | KASSERT(xfer->c_drive <= PMP_PORT_CTL); | | 1253 | KASSERT(xfer->c_drive <= PMP_PORT_CTL); |
1253 | prb->prb_fis[rhd_c] |= xfer->c_drive; | | 1254 | prb->prb_fis[rhd_c] |= xfer->c_drive; |
1254 | | | 1255 | |
1255 | if (siisata_dma_setup(chp, xfer->c_slot, ata_bio->databuf, ata_bio->bcount, | | 1256 | if (siisata_dma_setup(chp, xfer->c_slot, ata_bio->databuf, ata_bio->bcount, |
1256 | (ata_bio->flags & ATA_READ) ? BUS_DMA_READ : BUS_DMA_WRITE)) { | | 1257 | (ata_bio->flags & ATA_READ) ? BUS_DMA_READ : BUS_DMA_WRITE)) { |
1257 | ata_bio->error = ERR_DMA; | | 1258 | ata_bio->error = ERR_DMA; |
1258 | ata_bio->r_error = 0; | | 1259 | ata_bio->r_error = 0; |
1259 | siisata_bio_complete(chp, xfer, 0); | | 1260 | siisata_bio_complete(chp, xfer, 0); |
1260 | return; | | 1261 | return; |
1261 | } | | 1262 | } |
1262 | | | 1263 | |
1263 | if (xfer->c_flags & C_POLL) { | | 1264 | if (xfer->c_flags & C_POLL) { |
1264 | /* polled command, disable interrupts */ | | 1265 | /* polled command, disable interrupts */ |
1265 | prb->prb_control |= htole16(PRB_CF_INTERRUPT_MASK); | | 1266 | prb->prb_control |= htole16(PRB_CF_INTERRUPT_MASK); |
1266 | siisata_disable_port_interrupt(chp); | | 1267 | siisata_disable_port_interrupt(chp); |
1267 | } | | 1268 | } |
1268 | | | 1269 | |
1269 | siisata_activate_prb(schp, xfer->c_slot); | | 1270 | siisata_activate_prb(schp, xfer->c_slot); |
1270 | | | 1271 | |
1271 | if ((ata_bio->flags & ATA_POLL) == 0) { | | 1272 | if ((ata_bio->flags & ATA_POLL) == 0) { |
1272 | callout_reset(&xfer->c_timo_callout, mstohz(ATA_DELAY), | | 1273 | callout_reset(&xfer->c_timo_callout, mstohz(ATA_DELAY), |
1273 | ata_timeout, xfer); | | 1274 | ata_timeout, xfer); |
1274 | goto out; | | 1275 | goto out; |
1275 | } | | 1276 | } |
1276 | | | 1277 | |
1277 | /* | | 1278 | /* |
1278 | * polled command | | 1279 | * polled command |
1279 | */ | | 1280 | */ |
1280 | for (i = 0; i < ATA_DELAY * 10; i++) { | | 1281 | for (i = 0; i < ATA_DELAY * 10; i++) { |
1281 | if (ata_bio->flags & ATA_ITSDONE) | | 1282 | if (ata_bio->flags & ATA_ITSDONE) |
1282 | break; | | 1283 | break; |
1283 | siisata_intr_port(schp); | | 1284 | siisata_intr_port(schp); |
1284 | DELAY(100); | | 1285 | DELAY(100); |
1285 | } | | 1286 | } |
1286 | | | 1287 | |
1287 | if ((ata_bio->flags & ATA_ITSDONE) == 0) { | | 1288 | if ((ata_bio->flags & ATA_ITSDONE) == 0) { |
1288 | ata_timeout(xfer); | | 1289 | ata_timeout(xfer); |
1289 | } | | 1290 | } |
1290 | | | 1291 | |
1291 | siisata_enable_port_interrupt(chp); | | 1292 | siisata_enable_port_interrupt(chp); |
1292 | out: | | 1293 | out: |
1293 | SIISATA_DEBUG_PRINT(("%s: %s: done\n", | | 1294 | SIISATA_DEBUG_PRINT(("%s: %s: done\n", |
1294 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__), | | 1295 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__), |
1295 | DEBUG_FUNCS); | | 1296 | DEBUG_FUNCS); |
1296 | return; | | 1297 | return; |
1297 | } | | 1298 | } |
1298 | | | 1299 | |
1299 | void | | 1300 | void |
1300 | siisata_bio_kill_xfer(struct ata_channel *chp, struct ata_xfer *xfer, | | 1301 | siisata_bio_kill_xfer(struct ata_channel *chp, struct ata_xfer *xfer, |
1301 | int reason) | | 1302 | int reason) |
1302 | { | | 1303 | { |
1303 | struct siisata_channel *schp = (struct siisata_channel *)chp; | | 1304 | struct siisata_channel *schp = (struct siisata_channel *)chp; |
1304 | struct ata_bio *ata_bio = &xfer->c_bio; | | 1305 | struct ata_bio *ata_bio = &xfer->c_bio; |
1305 | int drive = xfer->c_drive; | | 1306 | int drive = xfer->c_drive; |
1306 | bool deactivate = true; | | 1307 | bool deactivate = true; |
1307 | | | 1308 | |
1308 | SIISATA_DEBUG_PRINT(("%s: %s: port %d slot %d\n", | | 1309 | SIISATA_DEBUG_PRINT(("%s: %s: port %d slot %d\n", |
1309 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__, | | 1310 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__, |
1310 | chp->ch_channel, xfer->c_slot), DEBUG_FUNCS); | | 1311 | chp->ch_channel, xfer->c_slot), DEBUG_FUNCS); |
1311 | | | 1312 | |
1312 | ata_bio->flags |= ATA_ITSDONE; | | 1313 | ata_bio->flags |= ATA_ITSDONE; |
1313 | switch (reason) { | | 1314 | switch (reason) { |
1314 | case KILL_GONE_INACTIVE: | | 1315 | case KILL_GONE_INACTIVE: |
1315 | deactivate = false; | | 1316 | deactivate = false; |
1316 | /* FALLTHROUGH */ | | 1317 | /* FALLTHROUGH */ |
1317 | case KILL_GONE: | | 1318 | case KILL_GONE: |
1318 | ata_bio->error = ERR_NODEV; | | 1319 | ata_bio->error = ERR_NODEV; |
1319 | break; | | 1320 | break; |
1320 | case KILL_RESET: | | 1321 | case KILL_RESET: |
1321 | ata_bio->error = ERR_RESET; | | 1322 | ata_bio->error = ERR_RESET; |
1322 | break; | | 1323 | break; |
1323 | case KILL_REQUEUE: | | 1324 | case KILL_REQUEUE: |
1324 | ata_bio->error = REQUEUE; | | 1325 | ata_bio->error = REQUEUE; |
1325 | break; | | 1326 | break; |
1326 | default: | | 1327 | default: |
1327 | panic("%s: port %d: unknown reason %d", | | 1328 | panic("%s: port %d: unknown reason %d", |
1328 | __func__, chp->ch_channel, reason); | | 1329 | __func__, chp->ch_channel, reason); |
1329 | } | | 1330 | } |
1330 | ata_bio->r_error = WDCE_ABRT; | | 1331 | ata_bio->r_error = WDCE_ABRT; |
1331 | | | 1332 | |
1332 | if (deactivate) { | | 1333 | if (deactivate) { |
1333 | siisata_deactivate_prb(schp, xfer->c_slot); | | 1334 | siisata_deactivate_prb(schp, xfer->c_slot); |
1334 | ata_deactivate_xfer(chp, xfer); | | 1335 | ata_deactivate_xfer(chp, xfer); |
1335 | } | | 1336 | } |
1336 | | | 1337 | |
1337 | (*chp->ch_drive[drive].drv_done)(chp->ch_drive[drive].drv_softc, xfer); | | 1338 | (*chp->ch_drive[drive].drv_done)(chp->ch_drive[drive].drv_softc, xfer); |
1338 | } | | 1339 | } |
1339 | | | 1340 | |
1340 | int | | 1341 | int |
1341 | siisata_bio_complete(struct ata_channel *chp, struct ata_xfer *xfer, int tfd) | | 1342 | siisata_bio_complete(struct ata_channel *chp, struct ata_xfer *xfer, int tfd) |
1342 | { | | 1343 | { |
1343 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; | | 1344 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; |
1344 | struct siisata_channel *schp = (struct siisata_channel *)chp; | | 1345 | struct siisata_channel *schp = (struct siisata_channel *)chp; |
1345 | struct ata_bio *ata_bio = &xfer->c_bio; | | 1346 | struct ata_bio *ata_bio = &xfer->c_bio; |
1346 | int drive = xfer->c_drive; | | 1347 | int drive = xfer->c_drive; |
1347 | | | 1348 | |
1348 | SIISATA_DEBUG_PRINT(("%s: %s: port %d slot %d drive %d tfd %x\n", | | 1349 | SIISATA_DEBUG_PRINT(("%s: %s: port %d slot %d drive %d tfd %x\n", |
1349 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__, | | 1350 | SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__, |
1350 | chp->ch_channel, xfer->c_slot, xfer->c_drive, tfd), DEBUG_FUNCS); | | 1351 | chp->ch_channel, xfer->c_slot, xfer->c_drive, tfd), DEBUG_FUNCS); |
1351 | | | 1352 | |
1352 | if (ata_waitdrain_xfer_check(chp, xfer)) | | 1353 | if (ata_waitdrain_xfer_check(chp, xfer)) |
1353 | return 0; | | 1354 | return 0; |
1354 | | | 1355 | |
1355 | siisata_deactivate_prb(schp, xfer->c_slot); | | 1356 | siisata_deactivate_prb(schp, xfer->c_slot); |
1356 | ata_deactivate_xfer(chp, xfer); | | 1357 | ata_deactivate_xfer(chp, xfer); |
1357 | | | 1358 | |
1358 | if (xfer->c_flags & C_TIMEOU) { | | 1359 | if (xfer->c_flags & C_TIMEOU) { |
1359 | ata_bio->error = TIMEOUT; | | 1360 | ata_bio->error = TIMEOUT; |
1360 | } | | 1361 | } |
1361 | | | 1362 | |
1362 | bus_dmamap_sync(sc->sc_dmat, schp->sch_datad[xfer->c_slot], 0, | | 1363 | bus_dmamap_sync(sc->sc_dmat, schp->sch_datad[xfer->c_slot], 0, |
1363 | schp->sch_datad[xfer->c_slot]->dm_mapsize, | | 1364 | schp->sch_datad[xfer->c_slot]->dm_mapsize, |
1364 | (ata_bio->flags & ATA_READ) ? BUS_DMASYNC_POSTREAD : | | 1365 | (ata_bio->flags & ATA_READ) ? BUS_DMASYNC_POSTREAD : |
1365 | BUS_DMASYNC_POSTWRITE); | | 1366 | BUS_DMASYNC_POSTWRITE); |
1366 | bus_dmamap_unload(sc->sc_dmat, schp->sch_datad[xfer->c_slot]); | | 1367 | bus_dmamap_unload(sc->sc_dmat, schp->sch_datad[xfer->c_slot]); |
1367 | | | 1368 | |
1368 | ata_bio->flags |= ATA_ITSDONE; | | 1369 | ata_bio->flags |= ATA_ITSDONE; |
1369 | if (ATACH_ST(tfd) & WDCS_DWF) { | | 1370 | if (ATACH_ST(tfd) & WDCS_DWF) { |
1370 | ata_bio->error = ERR_DF; | | 1371 | ata_bio->error = ERR_DF; |
1371 | } else if (ATACH_ST(tfd) & WDCS_ERR) { | | 1372 | } else if (ATACH_ST(tfd) & WDCS_ERR) { |
1372 | ata_bio->error = ERROR; | | 1373 | ata_bio->error = ERROR; |
1373 | ata_bio->r_error = ATACH_ERR(tfd); | | 1374 | ata_bio->r_error = ATACH_ERR(tfd); |
1374 | } else if (ATACH_ST(tfd) & WDCS_CORR) | | 1375 | } else if (ATACH_ST(tfd) & WDCS_CORR) |
1375 | ata_bio->flags |= ATA_CORR; | | 1376 | ata_bio->flags |= ATA_CORR; |
1376 | | | 1377 | |
1377 | SIISATA_DEBUG_PRINT(("%s: %s bcount: %ld", SIISATANAME(sc), __func__, | | 1378 | SIISATA_DEBUG_PRINT(("%s: %s bcount: %ld", SIISATANAME(sc), __func__, |
1378 | ata_bio->bcount), DEBUG_XFERS); | | 1379 | ata_bio->bcount), DEBUG_XFERS); |
1379 | if (ata_bio->error == NOERROR) { | | 1380 | if (ata_bio->error == NOERROR) { |
1380 | if ((xfer->c_flags & C_NCQ) != 0 && ata_bio->flags & ATA_READ) | | 1381 | if ((xfer->c_flags & C_NCQ) != 0 && ata_bio->flags & ATA_READ) |
1381 | ata_bio->bcount -= | | 1382 | ata_bio->bcount -= |
1382 | PRREAD(sc, PRSX(chp->ch_channel, xfer->c_slot, PRSO_RTC)); | | 1383 | PRREAD(sc, PRSX(chp->ch_channel, xfer->c_slot, PRSO_RTC)); |
1383 | else | | 1384 | else |
1384 | ata_bio->bcount = 0; | | 1385 | ata_bio->bcount = 0; |
1385 | } | | 1386 | } |
1386 | SIISATA_DEBUG_PRINT((" now %ld\n", ata_bio->bcount), DEBUG_XFERS); | | 1387 | SIISATA_DEBUG_PRINT((" now %ld\n", ata_bio->bcount), DEBUG_XFERS); |
1387 | (*chp->ch_drive[drive].drv_done)(chp->ch_drive[drive].drv_softc, xfer); | | 1388 | (*chp->ch_drive[drive].drv_done)(chp->ch_drive[drive].drv_softc, xfer); |
1388 | if ((ATACH_ST(tfd) & WDCS_ERR) == 0) | | 1389 | if ((ATACH_ST(tfd) & WDCS_ERR) == 0) |
1389 | atastart(chp); | | 1390 | atastart(chp); |
1390 | return 0; | | 1391 | return 0; |
1391 | } | | 1392 | } |
1392 | | | 1393 | |
1393 | static int | | 1394 | static int |
1394 | siisata_dma_setup(struct ata_channel *chp, int slot, void *data, | | 1395 | siisata_dma_setup(struct ata_channel *chp, int slot, void *data, |
1395 | size_t count, int op) | | 1396 | size_t count, int op) |
1396 | { | | 1397 | { |
1397 | | | 1398 | |
1398 | int error, seg; | | 1399 | int error, seg; |
1399 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; | | 1400 | struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac; |
1400 | struct siisata_channel *schp = (struct siisata_channel *)chp; | | 1401 | struct siisata_channel *schp = (struct siisata_channel *)chp; |
1401 | | | 1402 | |
1402 | struct siisata_prb *prbp; | | 1403 | struct siisata_prb *prbp; |
1403 | | | 1404 | |
1404 | prbp = schp->sch_prb[slot]; | | 1405 | prbp = schp->sch_prb[slot]; |
1405 | | | 1406 | |
1406 | if (data == NULL) { | | 1407 | if (data == NULL) { |
1407 | goto end; | | 1408 | goto end; |
1408 | } | | 1409 | } |
1409 | | | 1410 | |
1410 | error = bus_dmamap_load(sc->sc_dmat, schp->sch_datad[slot], | | 1411 | error = bus_dmamap_load(sc->sc_dmat, schp->sch_datad[slot], |
1411 | data, count, NULL, BUS_DMA_NOWAIT | BUS_DMA_STREAMING | op); | | 1412 | data, count, NULL, BUS_DMA_NOWAIT | BUS_DMA_STREAMING | op); |
1412 | if (error) { | | 1413 | if (error) { |
1413 | aprint_error("%s port %d: " | | 1414 | aprint_error("%s port %d: " |
1414 | "failed to load xfer in slot %d: error %d\n", | | 1415 | "failed to load xfer in slot %d: error %d\n", |
1415 | SIISATANAME(sc), chp->ch_channel, slot, error); | | 1416 | SIISATANAME(sc), chp->ch_channel, slot, error); |
1416 | return error; | | 1417 | return error; |
1417 | } | | 1418 | } |
1418 | | | 1419 | |
1419 | bus_dmamap_sync(sc->sc_dmat, schp->sch_datad[slot], 0, | | 1420 | bus_dmamap_sync(sc->sc_dmat, schp->sch_datad[slot], 0, |
1420 | schp->sch_datad[slot]->dm_mapsize, | | 1421 | schp->sch_datad[slot]->dm_mapsize, |
1421 | (op == BUS_DMA_READ) ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE); | | 1422 | (op == BUS_DMA_READ) ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE); |
1422 | | | 1423 | |
1423 | SIISATA_DEBUG_PRINT(("%s: %d segs, %ld count\n", __func__, | | 1424 | SIISATA_DEBUG_PRINT(("%s: %d segs, %ld count\n", __func__, |
1424 | schp->sch_datad[slot]->dm_nsegs, (long unsigned int) count), | | 1425 | schp->sch_datad[slot]->dm_nsegs, (long unsigned int) count), |
1425 | DEBUG_FUNCS | DEBUG_DEBUG); | | 1426 | DEBUG_FUNCS | DEBUG_DEBUG); |
1426 | | | 1427 | |
1427 | for (seg = 0; seg < schp->sch_datad[slot]->dm_nsegs; seg++) { | | 1428 | for (seg = 0; seg < schp->sch_datad[slot]->dm_nsegs; seg++) { |
1428 | prbp->prb_sge[seg].sge_da = | | 1429 | prbp->prb_sge[seg].sge_da = |