satalink.c revision 1.4 1 1.4 thorpej /* $NetBSD: satalink.c,v 1.4 2003/12/19 03:33:52 thorpej Exp $ */
2 1.2 thorpej
3 1.2 thorpej /*-
4 1.2 thorpej * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 1.2 thorpej * All rights reserved.
6 1.2 thorpej *
7 1.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.2 thorpej * by Jason R. Thorpe of Wasabi Systems, Inc.
9 1.2 thorpej *
10 1.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.2 thorpej * modification, are permitted provided that the following conditions
12 1.2 thorpej * are met:
13 1.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.2 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.2 thorpej * must display the following acknowledgement:
20 1.2 thorpej * This product includes software developed by the NetBSD
21 1.2 thorpej * Foundation, Inc. and its contributors.
22 1.2 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2 thorpej * contributors may be used to endorse or promote products derived
24 1.2 thorpej * from this software without specific prior written permission.
25 1.2 thorpej *
26 1.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.1 thorpej */
38 1.1 thorpej
39 1.1 thorpej #include <sys/param.h>
40 1.1 thorpej #include <sys/systm.h>
41 1.1 thorpej #include <sys/malloc.h>
42 1.1 thorpej
43 1.1 thorpej #include <dev/pci/pcivar.h>
44 1.1 thorpej #include <dev/pci/pcidevs.h>
45 1.1 thorpej #include <dev/pci/pciidereg.h>
46 1.1 thorpej #include <dev/pci/pciidevar.h>
47 1.1 thorpej #include <dev/pci/pciide_sii3112_reg.h>
48 1.1 thorpej
49 1.2 thorpej #include <dev/ata/satareg.h>
50 1.1 thorpej
51 1.4 thorpej /*
52 1.4 thorpej * Register map for BA5 register space, indexed by channel.
53 1.4 thorpej */
54 1.4 thorpej static const struct {
55 1.4 thorpej bus_addr_t ba5_IDEDMA_CMD;
56 1.4 thorpej bus_addr_t ba5_IDEDMA_CTL;
57 1.4 thorpej bus_addr_t ba5_IDEDMA_TBL;
58 1.4 thorpej bus_addr_t ba5_IDEDMA_CMD2;
59 1.4 thorpej bus_addr_t ba5_IDEDMA_CTL2;
60 1.4 thorpej bus_addr_t ba5_IDE_TF0;
61 1.4 thorpej bus_addr_t ba5_IDE_TF1;
62 1.4 thorpej bus_addr_t ba5_IDE_TF2;
63 1.4 thorpej bus_addr_t ba5_IDE_TF3;
64 1.4 thorpej bus_addr_t ba5_IDE_TF4;
65 1.4 thorpej bus_addr_t ba5_IDE_TF5;
66 1.4 thorpej bus_addr_t ba5_IDE_TF6;
67 1.4 thorpej bus_addr_t ba5_IDE_TF7;
68 1.4 thorpej bus_addr_t ba5_IDE_TF8;
69 1.4 thorpej bus_addr_t ba5_IDE_RAD;
70 1.4 thorpej bus_addr_t ba5_IDE_TF9;
71 1.4 thorpej bus_addr_t ba5_IDE_TF10;
72 1.4 thorpej bus_addr_t ba5_IDE_TF11;
73 1.4 thorpej bus_addr_t ba5_IDE_TF12;
74 1.4 thorpej bus_addr_t ba5_IDE_TF13;
75 1.4 thorpej bus_addr_t ba5_IDE_TF14;
76 1.4 thorpej bus_addr_t ba5_IDE_TF15;
77 1.4 thorpej bus_addr_t ba5_IDE_TF16;
78 1.4 thorpej bus_addr_t ba5_IDE_TF17;
79 1.4 thorpej bus_addr_t ba5_IDE_TF18;
80 1.4 thorpej bus_addr_t ba5_IDE_TF19;
81 1.4 thorpej bus_addr_t ba5_IDE_RABC;
82 1.4 thorpej bus_addr_t ba5_IDE_CMD_STS;
83 1.4 thorpej bus_addr_t ba5_IDE_CFG_STS;
84 1.4 thorpej bus_addr_t ba5_IDE_DTM;
85 1.4 thorpej bus_addr_t ba5_SControl;
86 1.4 thorpej bus_addr_t ba5_SStatus;
87 1.4 thorpej bus_addr_t ba5_SError;
88 1.4 thorpej } satalink_ba5_regmap[] = {
89 1.4 thorpej {
90 1.4 thorpej .ba5_IDEDMA_CMD = 0x000,
91 1.4 thorpej .ba5_IDEDMA_CTL = 0x002,
92 1.4 thorpej .ba5_IDEDMA_TBL = 0x004,
93 1.4 thorpej .ba5_IDEDMA_CMD2 = 0x010,
94 1.4 thorpej .ba5_IDEDMA_CTL2 = 0x012,
95 1.4 thorpej .ba5_IDE_TF0 = 0x080, /* wd_data */
96 1.4 thorpej .ba5_IDE_TF1 = 0x081, /* wd_error */
97 1.4 thorpej .ba5_IDE_TF2 = 0x082, /* wd_seccnt */
98 1.4 thorpej .ba5_IDE_TF3 = 0x083, /* wd_sector */
99 1.4 thorpej .ba5_IDE_TF4 = 0x084, /* wd_cyl_lo */
100 1.4 thorpej .ba5_IDE_TF5 = 0x085, /* wd_cyl_hi */
101 1.4 thorpej .ba5_IDE_TF6 = 0x086, /* wd_sdh */
102 1.4 thorpej .ba5_IDE_TF7 = 0x087, /* wd_command */
103 1.4 thorpej .ba5_IDE_TF8 = 0x08a, /* wd_altsts */
104 1.4 thorpej .ba5_IDE_RAD = 0x08c,
105 1.4 thorpej .ba5_IDE_TF9 = 0x091, /* Features 2 */
106 1.4 thorpej .ba5_IDE_TF10 = 0x092, /* Sector Count 2 */
107 1.4 thorpej .ba5_IDE_TF11 = 0x093, /* Start Sector 2 */
108 1.4 thorpej .ba5_IDE_TF12 = 0x094, /* Cylinder Low 2 */
109 1.4 thorpej .ba5_IDE_TF13 = 0x095, /* Cylinder High 2 */
110 1.4 thorpej .ba5_IDE_TF14 = 0x096, /* Device/Head 2 */
111 1.4 thorpej .ba5_IDE_TF15 = 0x097, /* Cmd Sts 2 */
112 1.4 thorpej .ba5_IDE_TF16 = 0x098, /* Sector Count 2 ext */
113 1.4 thorpej .ba5_IDE_TF17 = 0x099, /* Start Sector 2 ext */
114 1.4 thorpej .ba5_IDE_TF18 = 0x09a, /* Cyl Low 2 ext */
115 1.4 thorpej .ba5_IDE_TF19 = 0x09b, /* Cyl High 2 ext */
116 1.4 thorpej .ba5_IDE_RABC = 0x09c,
117 1.4 thorpej .ba5_IDE_CMD_STS = 0x0a0,
118 1.4 thorpej .ba5_IDE_CFG_STS = 0x0a1,
119 1.4 thorpej .ba5_IDE_DTM = 0x0b4,
120 1.4 thorpej .ba5_SControl = 0x100,
121 1.4 thorpej .ba5_SStatus = 0x104,
122 1.4 thorpej .ba5_SError = 0x108,
123 1.4 thorpej },
124 1.4 thorpej {
125 1.4 thorpej .ba5_IDEDMA_CMD = 0x008,
126 1.4 thorpej .ba5_IDEDMA_CTL = 0x00a,
127 1.4 thorpej .ba5_IDEDMA_TBL = 0x00c,
128 1.4 thorpej .ba5_IDEDMA_CMD2 = 0x018,
129 1.4 thorpej .ba5_IDEDMA_CTL2 = 0x01a,
130 1.4 thorpej .ba5_IDE_TF0 = 0x0c0, /* wd_data */
131 1.4 thorpej .ba5_IDE_TF1 = 0x0c1, /* wd_error */
132 1.4 thorpej .ba5_IDE_TF2 = 0x0c2, /* wd_seccnt */
133 1.4 thorpej .ba5_IDE_TF3 = 0x0c3, /* wd_sector */
134 1.4 thorpej .ba5_IDE_TF4 = 0x0c4, /* wd_cyl_lo */
135 1.4 thorpej .ba5_IDE_TF5 = 0x0c5, /* wd_cyl_hi */
136 1.4 thorpej .ba5_IDE_TF6 = 0x0c6, /* wd_sdh */
137 1.4 thorpej .ba5_IDE_TF7 = 0x0c7, /* wd_command */
138 1.4 thorpej .ba5_IDE_TF8 = 0x0ca, /* wd_altsts */
139 1.4 thorpej .ba5_IDE_RAD = 0x0cc,
140 1.4 thorpej .ba5_IDE_TF9 = 0x0d1, /* Features 2 */
141 1.4 thorpej .ba5_IDE_TF10 = 0x0d2, /* Sector Count 2 */
142 1.4 thorpej .ba5_IDE_TF11 = 0x0d3, /* Start Sector 2 */
143 1.4 thorpej .ba5_IDE_TF12 = 0x0d4, /* Cylinder Low 2 */
144 1.4 thorpej .ba5_IDE_TF13 = 0x0d5, /* Cylinder High 2 */
145 1.4 thorpej .ba5_IDE_TF14 = 0x0d6, /* Device/Head 2 */
146 1.4 thorpej .ba5_IDE_TF15 = 0x0d7, /* Cmd Sts 2 */
147 1.4 thorpej .ba5_IDE_TF16 = 0x0d8, /* Sector Count 2 ext */
148 1.4 thorpej .ba5_IDE_TF17 = 0x0d9, /* Start Sector 2 ext */
149 1.4 thorpej .ba5_IDE_TF18 = 0x0da, /* Cyl Low 2 ext */
150 1.4 thorpej .ba5_IDE_TF19 = 0x0db, /* Cyl High 2 ext */
151 1.4 thorpej .ba5_IDE_RABC = 0x0dc,
152 1.4 thorpej .ba5_IDE_CMD_STS = 0x0e0,
153 1.4 thorpej .ba5_IDE_CFG_STS = 0x0e1,
154 1.4 thorpej .ba5_IDE_DTM = 0x0f4,
155 1.4 thorpej .ba5_SControl = 0x180,
156 1.4 thorpej .ba5_SStatus = 0x184,
157 1.4 thorpej .ba5_SError = 0x188,
158 1.4 thorpej }
159 1.4 thorpej };
160 1.4 thorpej
161 1.1 thorpej static int satalink_match(struct device *, struct cfdata *, void *);
162 1.1 thorpej static void satalink_attach(struct device *, struct device *, void *);
163 1.1 thorpej
164 1.1 thorpej CFATTACH_DECL(satalink, sizeof(struct pciide_softc),
165 1.1 thorpej satalink_match, satalink_attach, NULL, NULL);
166 1.1 thorpej
167 1.1 thorpej static void sii3112_chip_map(struct pciide_softc*, struct pci_attach_args*);
168 1.2 thorpej static int sii3112_drv_probe(struct channel_softc*);
169 1.1 thorpej static void sii3112_setup_channel(struct channel_softc*);
170 1.1 thorpej
171 1.1 thorpej static const struct pciide_product_desc pciide_satalink_products[] = {
172 1.1 thorpej { PCI_PRODUCT_CMDTECH_3112,
173 1.1 thorpej 0,
174 1.1 thorpej "Silicon Image SATALink 3112",
175 1.1 thorpej sii3112_chip_map,
176 1.1 thorpej },
177 1.1 thorpej { 0,
178 1.1 thorpej 0,
179 1.1 thorpej NULL,
180 1.1 thorpej NULL
181 1.1 thorpej }
182 1.1 thorpej };
183 1.1 thorpej
184 1.1 thorpej static int
185 1.1 thorpej satalink_match(struct device *parent, struct cfdata *match, void *aux)
186 1.1 thorpej {
187 1.1 thorpej struct pci_attach_args *pa = aux;
188 1.1 thorpej
189 1.1 thorpej if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CMDTECH) {
190 1.1 thorpej if (pciide_lookup_product(pa->pa_id, pciide_satalink_products))
191 1.1 thorpej return (2);
192 1.1 thorpej }
193 1.1 thorpej return (0);
194 1.1 thorpej }
195 1.1 thorpej
196 1.1 thorpej static void
197 1.1 thorpej satalink_attach(struct device *parent, struct device *self, void *aux)
198 1.1 thorpej {
199 1.1 thorpej struct pci_attach_args *pa = aux;
200 1.1 thorpej struct pciide_softc *sc = (struct pciide_softc *)self;
201 1.1 thorpej
202 1.1 thorpej pciide_common_attach(sc, pa,
203 1.1 thorpej pciide_lookup_product(pa->pa_id, pciide_satalink_products));
204 1.1 thorpej
205 1.1 thorpej }
206 1.1 thorpej
207 1.2 thorpej static __inline uint32_t
208 1.2 thorpej ba5_read_4(struct pciide_softc *sc, bus_addr_t reg)
209 1.2 thorpej {
210 1.2 thorpej
211 1.2 thorpej if (__predict_true(sc->sc_ba5_en != 0))
212 1.2 thorpej return (bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, reg));
213 1.2 thorpej
214 1.2 thorpej pci_conf_write(sc->sc_pc, sc->sc_tag, SII3112_BA5_IND_ADDR, reg);
215 1.2 thorpej return (pci_conf_read(sc->sc_pc, sc->sc_tag, SII3112_BA5_IND_DATA));
216 1.2 thorpej }
217 1.2 thorpej
218 1.4 thorpej #define BA5_READ_4(sc, chan, reg) \
219 1.4 thorpej ba5_read_4((sc), satalink_ba5_regmap[(chan)].reg)
220 1.4 thorpej
221 1.2 thorpej static __inline void
222 1.2 thorpej ba5_write_4(struct pciide_softc *sc, bus_addr_t reg, uint32_t val)
223 1.2 thorpej {
224 1.2 thorpej
225 1.2 thorpej if (__predict_true(sc->sc_ba5_en != 0))
226 1.2 thorpej bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, reg, val);
227 1.2 thorpej else {
228 1.2 thorpej pci_conf_write(sc->sc_pc, sc->sc_tag, SII3112_BA5_IND_ADDR,
229 1.2 thorpej reg);
230 1.2 thorpej pci_conf_write(sc->sc_pc, sc->sc_tag, SII3112_BA5_IND_DATA,
231 1.2 thorpej val);
232 1.2 thorpej }
233 1.2 thorpej }
234 1.2 thorpej
235 1.4 thorpej #define BA5_WRITE_4(sc, chan, reg, val) \
236 1.4 thorpej ba5_write_4((sc), satalink_ba5_regmap[(chan)].reg, (val))
237 1.4 thorpej
238 1.1 thorpej static void
239 1.1 thorpej sii3112_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
240 1.1 thorpej {
241 1.1 thorpej struct pciide_channel *cp;
242 1.1 thorpej bus_size_t cmdsize, ctlsize;
243 1.2 thorpej pcireg_t interface, scs_cmd, cfgctl;
244 1.1 thorpej int channel;
245 1.1 thorpej
246 1.1 thorpej if (pciide_chipen(sc, pa) == 0)
247 1.1 thorpej return;
248 1.1 thorpej
249 1.2 thorpej scs_cmd = pci_conf_read(pa->pa_pc, pa->pa_tag, SII3112_SCS_CMD);
250 1.2 thorpej pci_conf_write(pa->pa_pc, pa->pa_tag, SII3112_SCS_CMD,
251 1.2 thorpej scs_cmd & SCS_CMD_BA5_EN);
252 1.2 thorpej
253 1.2 thorpej if (scs_cmd & SCS_CMD_BA5_EN) {
254 1.2 thorpej aprint_verbose("%s: SATALink BA5 register space enabled\n",
255 1.2 thorpej sc->sc_wdcdev.sc_dev.dv_xname);
256 1.2 thorpej if (pci_mapreg_map(pa, PCI_MAPREG_START + 0x14,
257 1.2 thorpej PCI_MAPREG_TYPE_MEM|
258 1.2 thorpej PCI_MAPREG_MEM_TYPE_32BIT, 0,
259 1.2 thorpej &sc->sc_ba5_st, &sc->sc_ba5_sh,
260 1.2 thorpej NULL, NULL) != 0)
261 1.2 thorpej aprint_error("%s: unable to map SATALink BA5 "
262 1.2 thorpej "register space\n", sc->sc_wdcdev.sc_dev.dv_xname);
263 1.2 thorpej else
264 1.2 thorpej sc->sc_ba5_en = 1;
265 1.2 thorpej } else {
266 1.2 thorpej aprint_verbose("%s: SATALink BA5 register space disabled\n",
267 1.2 thorpej sc->sc_wdcdev.sc_dev.dv_xname);
268 1.2 thorpej
269 1.2 thorpej /* Enable indirect BA5 addressing. */
270 1.2 thorpej cfgctl = pci_conf_read(pa->pa_pc, pa->pa_tag,
271 1.2 thorpej SII3112_PCI_CFGCTL);
272 1.2 thorpej pci_conf_write(pa->pa_pc, pa->pa_tag, SII3112_PCI_CFGCTL,
273 1.2 thorpej cfgctl | CFGCTL_BA5INDEN);
274 1.2 thorpej }
275 1.2 thorpej
276 1.1 thorpej aprint_normal("%s: bus-master DMA support present",
277 1.1 thorpej sc->sc_wdcdev.sc_dev.dv_xname);
278 1.1 thorpej pciide_mapreg_dma(sc, pa);
279 1.1 thorpej aprint_normal("\n");
280 1.1 thorpej
281 1.1 thorpej /*
282 1.1 thorpej * Rev. <= 0x01 of the 3112 have a bug that can cause data
283 1.1 thorpej * corruption if DMA transfers cross an 8K boundary. This is
284 1.1 thorpej * apparently hard to tickle, but we'll go ahead and play it
285 1.1 thorpej * safe.
286 1.1 thorpej */
287 1.1 thorpej if (PCI_REVISION(pa->pa_class) <= 0x01) {
288 1.1 thorpej sc->sc_dma_maxsegsz = 8192;
289 1.1 thorpej sc->sc_dma_boundary = 8192;
290 1.1 thorpej }
291 1.1 thorpej
292 1.1 thorpej sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32 |
293 1.1 thorpej WDC_CAPABILITY_MODE;
294 1.1 thorpej sc->sc_wdcdev.PIO_cap = 4;
295 1.1 thorpej if (sc->sc_dma_ok) {
296 1.1 thorpej sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA | WDC_CAPABILITY_UDMA;
297 1.1 thorpej sc->sc_wdcdev.cap |= WDC_CAPABILITY_IRQACK;
298 1.1 thorpej sc->sc_wdcdev.irqack = pciide_irqack;
299 1.1 thorpej sc->sc_wdcdev.DMA_cap = 2;
300 1.1 thorpej sc->sc_wdcdev.UDMA_cap = 6;
301 1.1 thorpej }
302 1.1 thorpej sc->sc_wdcdev.set_modes = sii3112_setup_channel;
303 1.1 thorpej
304 1.2 thorpej /* We can use SControl and SStatus to probe for drives. */
305 1.2 thorpej sc->sc_wdcdev.cap |= WDC_CAPABILITY_DRVPROBE;
306 1.2 thorpej sc->sc_wdcdev.drv_probe = sii3112_drv_probe;
307 1.2 thorpej
308 1.1 thorpej sc->sc_wdcdev.channels = sc->wdc_chanarray;
309 1.1 thorpej sc->sc_wdcdev.nchannels = PCIIDE_NUM_CHANNELS;
310 1.1 thorpej
311 1.1 thorpej /*
312 1.2 thorpej * The 3112 either identifies itself as a RAID storage device
313 1.2 thorpej * or a Misc storage device. Fake up the interface bits for
314 1.2 thorpej * what our driver expects.
315 1.1 thorpej */
316 1.1 thorpej if (PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_IDE) {
317 1.1 thorpej interface = PCI_INTERFACE(pa->pa_class);
318 1.1 thorpej } else {
319 1.1 thorpej interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
320 1.1 thorpej PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
321 1.1 thorpej }
322 1.1 thorpej
323 1.1 thorpej for (channel = 0; channel < sc->sc_wdcdev.nchannels; channel++) {
324 1.1 thorpej cp = &sc->pciide_channels[channel];
325 1.1 thorpej if (pciide_chansetup(sc, channel, interface) == 0)
326 1.1 thorpej continue;
327 1.1 thorpej pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
328 1.1 thorpej pciide_pci_intr);
329 1.1 thorpej }
330 1.2 thorpej }
331 1.2 thorpej
332 1.2 thorpej static const char *sata_speed[] = {
333 1.2 thorpej "no negotiated speed",
334 1.2 thorpej "1.5Gb/s",
335 1.2 thorpej "<unknown 2>",
336 1.2 thorpej "<unknown 3>",
337 1.2 thorpej "<unknown 4>",
338 1.2 thorpej "<unknown 5>",
339 1.2 thorpej "<unknown 6>",
340 1.2 thorpej "<unknown 7>",
341 1.2 thorpej "<unknown 8>",
342 1.2 thorpej "<unknown 9>",
343 1.2 thorpej "<unknown 10>",
344 1.2 thorpej "<unknown 11>",
345 1.2 thorpej "<unknown 12>",
346 1.2 thorpej "<unknown 13>",
347 1.2 thorpej "<unknown 14>",
348 1.2 thorpej "<unknown 15>",
349 1.2 thorpej };
350 1.2 thorpej
351 1.2 thorpej static int
352 1.2 thorpej sii3112_drv_probe(struct channel_softc *chp)
353 1.2 thorpej {
354 1.2 thorpej struct pciide_channel *cp = (struct pciide_channel *)chp;
355 1.2 thorpej struct pciide_softc *sc = (struct pciide_softc *)cp->wdc_channel.wdc;
356 1.2 thorpej uint32_t scontrol, sstatus;
357 1.2 thorpej int rv = 0;
358 1.2 thorpej uint8_t scnt, sn, cl, ch;
359 1.2 thorpej
360 1.2 thorpej /*
361 1.2 thorpej * The 3112 is a 2-port part, and only has one drive per channel
362 1.2 thorpej * (each port emulates a master drive).
363 1.2 thorpej */
364 1.2 thorpej
365 1.2 thorpej /*
366 1.2 thorpej * Request communication initialization sequence, any speed.
367 1.2 thorpej * Performing this is the equivalent of an ATA Reset.
368 1.2 thorpej */
369 1.2 thorpej scontrol = SControl_DET_INIT | SControl_SPD_ANY;
370 1.2 thorpej
371 1.2 thorpej /*
372 1.2 thorpej * XXX We don't yet support SATA power management; disable all
373 1.2 thorpej * power management state transitions.
374 1.2 thorpej */
375 1.2 thorpej scontrol |= SControl_IPM_NONE;
376 1.2 thorpej
377 1.4 thorpej BA5_WRITE_4(sc, chp->channel, ba5_SControl, scontrol);
378 1.2 thorpej delay(500);
379 1.2 thorpej scontrol &= ~SControl_DET_INIT;
380 1.4 thorpej BA5_WRITE_4(sc, chp->channel, ba5_SControl, scontrol);
381 1.2 thorpej delay(500);
382 1.2 thorpej
383 1.4 thorpej sstatus = BA5_READ_4(sc, chp->channel, ba5_SStatus);
384 1.2 thorpej switch (sstatus & SStatus_DET_mask) {
385 1.2 thorpej case SStatus_DET_NODEV:
386 1.2 thorpej /* No device; be silent. */
387 1.2 thorpej break;
388 1.2 thorpej
389 1.2 thorpej case SStatus_DET_DEV_NE:
390 1.2 thorpej aprint_error("%s: port %d: device connected, but "
391 1.2 thorpej "communication not established\n",
392 1.2 thorpej sc->sc_wdcdev.sc_dev.dv_xname, chp->channel);
393 1.2 thorpej break;
394 1.2 thorpej
395 1.2 thorpej case SStatus_DET_OFFLINE:
396 1.2 thorpej aprint_error("%s: port %d: PHY offline\n",
397 1.2 thorpej sc->sc_wdcdev.sc_dev.dv_xname, chp->channel);
398 1.2 thorpej break;
399 1.2 thorpej
400 1.2 thorpej case SStatus_DET_DEV:
401 1.2 thorpej /*
402 1.2 thorpej * XXX ATAPI detection doesn't currently work. Don't
403 1.2 thorpej * XXX know why. But, it's not like the standard method
404 1.2 thorpej * XXX can detect an ATAPI device connected via a SATA/PATA
405 1.2 thorpej * XXX bridge, so at least this is no worse. --thorpej
406 1.2 thorpej */
407 1.2 thorpej bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0,
408 1.2 thorpej WDSD_IBM | (0 << 4));
409 1.2 thorpej delay(10); /* 400ns delay */
410 1.2 thorpej /* Save register contents. */
411 1.2 thorpej scnt = bus_space_read_1(chp->cmd_iot,
412 1.2 thorpej chp->cmd_iohs[wd_seccnt], 0);
413 1.2 thorpej sn = bus_space_read_1(chp->cmd_iot,
414 1.2 thorpej chp->cmd_iohs[wd_sector], 0);
415 1.2 thorpej cl = bus_space_read_1(chp->cmd_iot,
416 1.2 thorpej chp->cmd_iohs[wd_cyl_lo], 0);
417 1.2 thorpej ch = bus_space_read_1(chp->cmd_iot,
418 1.2 thorpej chp->cmd_iohs[wd_cyl_hi], 0);
419 1.2 thorpej #if 0
420 1.2 thorpej printf("%s: port %d: scnt=0x%x sn=0x%x cl=0x%x ch=0x%x\n",
421 1.2 thorpej sc->sc_wdcdev.sc_dev.dv_xname, chp->channel,
422 1.2 thorpej scnt, sn, cl, ch);
423 1.2 thorpej #endif
424 1.2 thorpej /*
425 1.2 thorpej * scnt and sn are supposed to be 0x1 for ATAPI, but in some
426 1.2 thorpej * cases we get wrong values here, so ignore it.
427 1.2 thorpej */
428 1.2 thorpej if (cl == 0x14 && ch == 0xeb)
429 1.2 thorpej chp->ch_drive[0].drive_flags |= DRIVE_ATAPI;
430 1.2 thorpej else
431 1.2 thorpej chp->ch_drive[0].drive_flags |= DRIVE_ATA;
432 1.2 thorpej
433 1.2 thorpej aprint_normal("%s: port %d: device present, speed: %s\n",
434 1.2 thorpej sc->sc_wdcdev.sc_dev.dv_xname, chp->channel,
435 1.2 thorpej sata_speed[(sstatus & SStatus_SPD_mask) >>
436 1.2 thorpej SStatus_SPD_shift]);
437 1.2 thorpej rv |= (1 << 0);
438 1.2 thorpej break;
439 1.2 thorpej
440 1.2 thorpej default:
441 1.2 thorpej aprint_error("%s: port %d: unknown SStatus: 0x%08x\n",
442 1.2 thorpej sc->sc_wdcdev.sc_dev.dv_xname, chp->channel, sstatus);
443 1.2 thorpej }
444 1.2 thorpej
445 1.2 thorpej return (rv);
446 1.1 thorpej }
447 1.1 thorpej
448 1.1 thorpej static void
449 1.1 thorpej sii3112_setup_channel(struct channel_softc *chp)
450 1.1 thorpej {
451 1.1 thorpej struct ata_drive_datas *drvp;
452 1.1 thorpej int drive;
453 1.1 thorpej u_int32_t idedma_ctl, dtm;
454 1.1 thorpej struct pciide_channel *cp = (struct pciide_channel*)chp;
455 1.1 thorpej struct pciide_softc *sc = (struct pciide_softc*)cp->wdc_channel.wdc;
456 1.1 thorpej
457 1.1 thorpej /* setup DMA if needed */
458 1.1 thorpej pciide_channel_dma_setup(cp);
459 1.1 thorpej
460 1.1 thorpej idedma_ctl = 0;
461 1.1 thorpej dtm = 0;
462 1.1 thorpej
463 1.1 thorpej for (drive = 0; drive < 2; drive++) {
464 1.1 thorpej drvp = &chp->ch_drive[drive];
465 1.1 thorpej /* If no drive, skip */
466 1.1 thorpej if ((drvp->drive_flags & DRIVE) == 0)
467 1.1 thorpej continue;
468 1.1 thorpej if (drvp->drive_flags & DRIVE_UDMA) {
469 1.1 thorpej /* use Ultra/DMA */
470 1.1 thorpej drvp->drive_flags &= ~DRIVE_DMA;
471 1.1 thorpej idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
472 1.1 thorpej dtm |= DTM_IDEx_DMA;
473 1.1 thorpej } else if (drvp->drive_flags & DRIVE_DMA) {
474 1.1 thorpej idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
475 1.1 thorpej dtm |= DTM_IDEx_DMA;
476 1.1 thorpej } else {
477 1.1 thorpej dtm |= DTM_IDEx_PIO;
478 1.1 thorpej }
479 1.1 thorpej }
480 1.1 thorpej
481 1.1 thorpej /*
482 1.1 thorpej * Nothing to do to setup modes; it is meaningless in S-ATA
483 1.1 thorpej * (but many S-ATA drives still want to get the SET_FEATURE
484 1.1 thorpej * command).
485 1.1 thorpej */
486 1.1 thorpej if (idedma_ctl != 0) {
487 1.1 thorpej /* Add software bits in status register */
488 1.1 thorpej bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
489 1.1 thorpej idedma_ctl);
490 1.1 thorpej }
491 1.1 thorpej pci_conf_write(sc->sc_pc, sc->sc_tag,
492 1.1 thorpej chp->channel == 0 ? SII3112_DTM_IDE0 : SII3112_DTM_IDE1, dtm);
493 1.1 thorpej }
494