Home | History | Annotate | Line # | Download | only in pci
satalink.c revision 1.2
      1  1.2  thorpej /*	$NetBSD: satalink.c,v 1.2 2003/12/15 00:36:23 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.2  thorpej  */
     38  1.1  thorpej 
     39  1.1  thorpej /*
     40  1.1  thorpej  * Copyright (c) 1999, 2000, 2001 Manuel Bouyer.
     41  1.1  thorpej  *
     42  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     43  1.1  thorpej  * modification, are permitted provided that the following conditions
     44  1.1  thorpej  * are met:
     45  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     46  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     47  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     48  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     49  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     50  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     51  1.1  thorpej  *    must display the following acknowledgement:
     52  1.1  thorpej  *	This product includes software developed by Manuel Bouyer.
     53  1.1  thorpej  * 4. The name of the author may not be used to endorse or promote products
     54  1.1  thorpej  *    derived from this software without specific prior written permission.
     55  1.1  thorpej  *
     56  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     57  1.1  thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     58  1.1  thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     59  1.1  thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     60  1.1  thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     61  1.1  thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     62  1.1  thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     63  1.1  thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     64  1.1  thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     65  1.1  thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     66  1.1  thorpej  */
     67  1.1  thorpej 
     68  1.1  thorpej #include <sys/param.h>
     69  1.1  thorpej #include <sys/systm.h>
     70  1.1  thorpej #include <sys/malloc.h>
     71  1.1  thorpej 
     72  1.1  thorpej #include <dev/pci/pcivar.h>
     73  1.1  thorpej #include <dev/pci/pcidevs.h>
     74  1.1  thorpej #include <dev/pci/pciidereg.h>
     75  1.1  thorpej #include <dev/pci/pciidevar.h>
     76  1.1  thorpej #include <dev/pci/pciide_sii3112_reg.h>
     77  1.1  thorpej 
     78  1.2  thorpej #include <dev/ata/satareg.h>
     79  1.1  thorpej 
     80  1.1  thorpej static int  satalink_match(struct device *, struct cfdata *, void *);
     81  1.1  thorpej static void satalink_attach(struct device *, struct device *, void *);
     82  1.1  thorpej 
     83  1.1  thorpej CFATTACH_DECL(satalink, sizeof(struct pciide_softc),
     84  1.1  thorpej     satalink_match, satalink_attach, NULL, NULL);
     85  1.1  thorpej 
     86  1.1  thorpej static void sii3112_chip_map(struct pciide_softc*, struct pci_attach_args*);
     87  1.2  thorpej static int  sii3112_drv_probe(struct channel_softc*);
     88  1.1  thorpej static void sii3112_setup_channel(struct channel_softc*);
     89  1.1  thorpej 
     90  1.1  thorpej static const struct pciide_product_desc pciide_satalink_products[] =  {
     91  1.1  thorpej 	{ PCI_PRODUCT_CMDTECH_3112,
     92  1.1  thorpej 	  0,
     93  1.1  thorpej 	  "Silicon Image SATALink 3112",
     94  1.1  thorpej 	  sii3112_chip_map,
     95  1.1  thorpej 	},
     96  1.1  thorpej 	{ 0,
     97  1.1  thorpej 	  0,
     98  1.1  thorpej 	  NULL,
     99  1.1  thorpej 	  NULL
    100  1.1  thorpej 	}
    101  1.1  thorpej };
    102  1.1  thorpej 
    103  1.1  thorpej static int
    104  1.1  thorpej satalink_match(struct device *parent, struct cfdata *match, void *aux)
    105  1.1  thorpej {
    106  1.1  thorpej 	struct pci_attach_args *pa = aux;
    107  1.1  thorpej 
    108  1.1  thorpej 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CMDTECH) {
    109  1.1  thorpej 		if (pciide_lookup_product(pa->pa_id, pciide_satalink_products))
    110  1.1  thorpej 			return (2);
    111  1.1  thorpej 	}
    112  1.1  thorpej 	return (0);
    113  1.1  thorpej }
    114  1.1  thorpej 
    115  1.1  thorpej static void
    116  1.1  thorpej satalink_attach(struct device *parent, struct device *self, void *aux)
    117  1.1  thorpej {
    118  1.1  thorpej 	struct pci_attach_args *pa = aux;
    119  1.1  thorpej 	struct pciide_softc *sc = (struct pciide_softc *)self;
    120  1.1  thorpej 
    121  1.1  thorpej 	pciide_common_attach(sc, pa,
    122  1.1  thorpej 	    pciide_lookup_product(pa->pa_id, pciide_satalink_products));
    123  1.1  thorpej 
    124  1.1  thorpej }
    125  1.1  thorpej 
    126  1.2  thorpej static __inline uint32_t
    127  1.2  thorpej ba5_read_4(struct pciide_softc *sc, bus_addr_t reg)
    128  1.2  thorpej {
    129  1.2  thorpej 
    130  1.2  thorpej 	if (__predict_true(sc->sc_ba5_en != 0))
    131  1.2  thorpej 		return (bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, reg));
    132  1.2  thorpej 
    133  1.2  thorpej 	pci_conf_write(sc->sc_pc, sc->sc_tag, SII3112_BA5_IND_ADDR, reg);
    134  1.2  thorpej 	return (pci_conf_read(sc->sc_pc, sc->sc_tag, SII3112_BA5_IND_DATA));
    135  1.2  thorpej }
    136  1.2  thorpej 
    137  1.2  thorpej static __inline void
    138  1.2  thorpej ba5_write_4(struct pciide_softc *sc, bus_addr_t reg, uint32_t val)
    139  1.2  thorpej {
    140  1.2  thorpej 
    141  1.2  thorpej 	if (__predict_true(sc->sc_ba5_en != 0))
    142  1.2  thorpej 		bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, reg, val);
    143  1.2  thorpej 	else {
    144  1.2  thorpej 		pci_conf_write(sc->sc_pc, sc->sc_tag, SII3112_BA5_IND_ADDR,
    145  1.2  thorpej 			       reg);
    146  1.2  thorpej 		pci_conf_write(sc->sc_pc, sc->sc_tag, SII3112_BA5_IND_DATA,
    147  1.2  thorpej 			       val);
    148  1.2  thorpej 	}
    149  1.2  thorpej }
    150  1.2  thorpej 
    151  1.1  thorpej static void
    152  1.1  thorpej sii3112_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    153  1.1  thorpej {
    154  1.1  thorpej 	struct pciide_channel *cp;
    155  1.1  thorpej 	bus_size_t cmdsize, ctlsize;
    156  1.2  thorpej 	pcireg_t interface, scs_cmd, cfgctl;
    157  1.1  thorpej 	int channel;
    158  1.1  thorpej 
    159  1.1  thorpej 	if (pciide_chipen(sc, pa) == 0)
    160  1.1  thorpej 		return;
    161  1.1  thorpej 
    162  1.2  thorpej 	scs_cmd = pci_conf_read(pa->pa_pc, pa->pa_tag, SII3112_SCS_CMD);
    163  1.2  thorpej 	pci_conf_write(pa->pa_pc, pa->pa_tag, SII3112_SCS_CMD,
    164  1.2  thorpej 		       scs_cmd & SCS_CMD_BA5_EN);
    165  1.2  thorpej 
    166  1.2  thorpej 	if (scs_cmd & SCS_CMD_BA5_EN) {
    167  1.2  thorpej 		aprint_verbose("%s: SATALink BA5 register space enabled\n",
    168  1.2  thorpej 		    sc->sc_wdcdev.sc_dev.dv_xname);
    169  1.2  thorpej 		if (pci_mapreg_map(pa, PCI_MAPREG_START + 0x14,
    170  1.2  thorpej 				   PCI_MAPREG_TYPE_MEM|
    171  1.2  thorpej 				   PCI_MAPREG_MEM_TYPE_32BIT, 0,
    172  1.2  thorpej 				   &sc->sc_ba5_st, &sc->sc_ba5_sh,
    173  1.2  thorpej 				   NULL, NULL) != 0)
    174  1.2  thorpej 			aprint_error("%s: unable to map SATALink BA5 "
    175  1.2  thorpej 			    "register space\n", sc->sc_wdcdev.sc_dev.dv_xname);
    176  1.2  thorpej 		else
    177  1.2  thorpej 			sc->sc_ba5_en = 1;
    178  1.2  thorpej 	} else {
    179  1.2  thorpej 		aprint_verbose("%s: SATALink BA5 register space disabled\n",
    180  1.2  thorpej 		    sc->sc_wdcdev.sc_dev.dv_xname);
    181  1.2  thorpej 
    182  1.2  thorpej 		/* Enable indirect BA5 addressing. */
    183  1.2  thorpej 		cfgctl = pci_conf_read(pa->pa_pc, pa->pa_tag,
    184  1.2  thorpej 				       SII3112_PCI_CFGCTL);
    185  1.2  thorpej 		pci_conf_write(pa->pa_pc, pa->pa_tag, SII3112_PCI_CFGCTL,
    186  1.2  thorpej 			       cfgctl | CFGCTL_BA5INDEN);
    187  1.2  thorpej 	}
    188  1.2  thorpej 
    189  1.1  thorpej 	aprint_normal("%s: bus-master DMA support present",
    190  1.1  thorpej 	    sc->sc_wdcdev.sc_dev.dv_xname);
    191  1.1  thorpej 	pciide_mapreg_dma(sc, pa);
    192  1.1  thorpej 	aprint_normal("\n");
    193  1.1  thorpej 
    194  1.1  thorpej 	/*
    195  1.1  thorpej 	 * Rev. <= 0x01 of the 3112 have a bug that can cause data
    196  1.1  thorpej 	 * corruption if DMA transfers cross an 8K boundary.  This is
    197  1.1  thorpej 	 * apparently hard to tickle, but we'll go ahead and play it
    198  1.1  thorpej 	 * safe.
    199  1.1  thorpej 	 */
    200  1.1  thorpej 	if (PCI_REVISION(pa->pa_class) <= 0x01) {
    201  1.1  thorpej 		sc->sc_dma_maxsegsz = 8192;
    202  1.1  thorpej 		sc->sc_dma_boundary = 8192;
    203  1.1  thorpej 	}
    204  1.1  thorpej 
    205  1.1  thorpej 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32 |
    206  1.1  thorpej 	    WDC_CAPABILITY_MODE;
    207  1.1  thorpej 	sc->sc_wdcdev.PIO_cap = 4;
    208  1.1  thorpej 	if (sc->sc_dma_ok) {
    209  1.1  thorpej 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA | WDC_CAPABILITY_UDMA;
    210  1.1  thorpej 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_IRQACK;
    211  1.1  thorpej 		sc->sc_wdcdev.irqack = pciide_irqack;
    212  1.1  thorpej 		sc->sc_wdcdev.DMA_cap = 2;
    213  1.1  thorpej 		sc->sc_wdcdev.UDMA_cap = 6;
    214  1.1  thorpej 	}
    215  1.1  thorpej 	sc->sc_wdcdev.set_modes = sii3112_setup_channel;
    216  1.1  thorpej 
    217  1.2  thorpej 	/* We can use SControl and SStatus to probe for drives. */
    218  1.2  thorpej 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DRVPROBE;
    219  1.2  thorpej 	sc->sc_wdcdev.drv_probe = sii3112_drv_probe;
    220  1.2  thorpej 
    221  1.1  thorpej 	sc->sc_wdcdev.channels = sc->wdc_chanarray;
    222  1.1  thorpej 	sc->sc_wdcdev.nchannels = PCIIDE_NUM_CHANNELS;
    223  1.1  thorpej 
    224  1.1  thorpej 	/*
    225  1.2  thorpej 	 * The 3112 either identifies itself as a RAID storage device
    226  1.2  thorpej 	 * or a Misc storage device.  Fake up the interface bits for
    227  1.2  thorpej 	 * what our driver expects.
    228  1.1  thorpej 	 */
    229  1.1  thorpej 	if (PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_IDE) {
    230  1.1  thorpej 		interface = PCI_INTERFACE(pa->pa_class);
    231  1.1  thorpej 	} else {
    232  1.1  thorpej 		interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    233  1.1  thorpej 		    PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    234  1.1  thorpej 	}
    235  1.1  thorpej 
    236  1.1  thorpej 	for (channel = 0; channel < sc->sc_wdcdev.nchannels; channel++) {
    237  1.1  thorpej 		cp = &sc->pciide_channels[channel];
    238  1.1  thorpej 		if (pciide_chansetup(sc, channel, interface) == 0)
    239  1.1  thorpej 			continue;
    240  1.1  thorpej 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    241  1.1  thorpej 		    pciide_pci_intr);
    242  1.1  thorpej 	}
    243  1.2  thorpej }
    244  1.2  thorpej 
    245  1.2  thorpej static const char *sata_speed[] = {
    246  1.2  thorpej 	"no negotiated speed",
    247  1.2  thorpej 	"1.5Gb/s",
    248  1.2  thorpej 	"<unknown 2>",
    249  1.2  thorpej 	"<unknown 3>",
    250  1.2  thorpej 	"<unknown 4>",
    251  1.2  thorpej 	"<unknown 5>",
    252  1.2  thorpej 	"<unknown 6>",
    253  1.2  thorpej 	"<unknown 7>",
    254  1.2  thorpej 	"<unknown 8>",
    255  1.2  thorpej 	"<unknown 9>",
    256  1.2  thorpej 	"<unknown 10>",
    257  1.2  thorpej 	"<unknown 11>",
    258  1.2  thorpej 	"<unknown 12>",
    259  1.2  thorpej 	"<unknown 13>",
    260  1.2  thorpej 	"<unknown 14>",
    261  1.2  thorpej 	"<unknown 15>",
    262  1.2  thorpej };
    263  1.2  thorpej 
    264  1.2  thorpej static int
    265  1.2  thorpej sii3112_drv_probe(struct channel_softc *chp)
    266  1.2  thorpej {
    267  1.2  thorpej 	struct pciide_channel *cp = (struct pciide_channel *)chp;
    268  1.2  thorpej 	struct pciide_softc *sc = (struct pciide_softc *)cp->wdc_channel.wdc;
    269  1.2  thorpej 	uint32_t scontrol, sstatus;
    270  1.2  thorpej 	int rv = 0;
    271  1.2  thorpej 	uint8_t scnt, sn, cl, ch;
    272  1.2  thorpej 
    273  1.2  thorpej 	/*
    274  1.2  thorpej 	 * The 3112 is a 2-port part, and only has one drive per channel
    275  1.2  thorpej 	 * (each port emulates a master drive).
    276  1.2  thorpej 	 */
    277  1.2  thorpej 
    278  1.2  thorpej 	/*
    279  1.2  thorpej 	 * Request communication initialization sequence, any speed.
    280  1.2  thorpej 	 * Performing this is the equivalent of an ATA Reset.
    281  1.2  thorpej 	 */
    282  1.2  thorpej 	scontrol = SControl_DET_INIT | SControl_SPD_ANY;
    283  1.2  thorpej 
    284  1.2  thorpej 	/*
    285  1.2  thorpej 	 * XXX We don't yet support SATA power management; disable all
    286  1.2  thorpej 	 * power management state transitions.
    287  1.2  thorpej 	 */
    288  1.2  thorpej 	scontrol |= SControl_IPM_NONE;
    289  1.2  thorpej 
    290  1.2  thorpej 	ba5_write_4(sc, chp->channel == 0 ? 0x100 : 0x180, scontrol);
    291  1.2  thorpej 	delay(500);
    292  1.2  thorpej 	scontrol &= ~SControl_DET_INIT;
    293  1.2  thorpej 	ba5_write_4(sc, chp->channel == 0 ? 0x100 : 0x180, scontrol);
    294  1.2  thorpej 	delay(500);
    295  1.2  thorpej 
    296  1.2  thorpej 	sstatus = ba5_read_4(sc, chp->channel == 0 ? 0x104 : 0x184);
    297  1.2  thorpej 	switch (sstatus & SStatus_DET_mask) {
    298  1.2  thorpej 	case SStatus_DET_NODEV:
    299  1.2  thorpej 		/* No device; be silent. */
    300  1.2  thorpej 		break;
    301  1.2  thorpej 
    302  1.2  thorpej 	case SStatus_DET_DEV_NE:
    303  1.2  thorpej 		aprint_error("%s: port %d: device connected, but "
    304  1.2  thorpej 		    "communication not established\n",
    305  1.2  thorpej 		    sc->sc_wdcdev.sc_dev.dv_xname, chp->channel);
    306  1.2  thorpej 		break;
    307  1.2  thorpej 
    308  1.2  thorpej 	case SStatus_DET_OFFLINE:
    309  1.2  thorpej 		aprint_error("%s: port %d: PHY offline\n",
    310  1.2  thorpej 		    sc->sc_wdcdev.sc_dev.dv_xname, chp->channel);
    311  1.2  thorpej 		break;
    312  1.2  thorpej 
    313  1.2  thorpej 	case SStatus_DET_DEV:
    314  1.2  thorpej 		/*
    315  1.2  thorpej 		 * XXX ATAPI detection doesn't currently work.  Don't
    316  1.2  thorpej 		 * XXX know why.  But, it's not like the standard method
    317  1.2  thorpej 		 * XXX can detect an ATAPI device connected via a SATA/PATA
    318  1.2  thorpej 		 * XXX bridge, so at least this is no worse.  --thorpej
    319  1.2  thorpej 		 */
    320  1.2  thorpej 		bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0,
    321  1.2  thorpej 		    WDSD_IBM | (0 << 4));
    322  1.2  thorpej 		delay(10);	/* 400ns delay */
    323  1.2  thorpej 		/* Save register contents. */
    324  1.2  thorpej 		scnt = bus_space_read_1(chp->cmd_iot,
    325  1.2  thorpej 				        chp->cmd_iohs[wd_seccnt], 0);
    326  1.2  thorpej 		sn = bus_space_read_1(chp->cmd_iot,
    327  1.2  thorpej 				      chp->cmd_iohs[wd_sector], 0);
    328  1.2  thorpej 		cl = bus_space_read_1(chp->cmd_iot,
    329  1.2  thorpej 				      chp->cmd_iohs[wd_cyl_lo], 0);
    330  1.2  thorpej 		ch = bus_space_read_1(chp->cmd_iot,
    331  1.2  thorpej 				      chp->cmd_iohs[wd_cyl_hi], 0);
    332  1.2  thorpej #if 0
    333  1.2  thorpej 		printf("%s: port %d: scnt=0x%x sn=0x%x cl=0x%x ch=0x%x\n",
    334  1.2  thorpej 		    sc->sc_wdcdev.sc_dev.dv_xname, chp->channel,
    335  1.2  thorpej 		    scnt, sn, cl, ch);
    336  1.2  thorpej #endif
    337  1.2  thorpej 		/*
    338  1.2  thorpej 		 * scnt and sn are supposed to be 0x1 for ATAPI, but in some
    339  1.2  thorpej 		 * cases we get wrong values here, so ignore it.
    340  1.2  thorpej 		 */
    341  1.2  thorpej 		if (cl == 0x14 && ch == 0xeb)
    342  1.2  thorpej 			chp->ch_drive[0].drive_flags |= DRIVE_ATAPI;
    343  1.2  thorpej 		else
    344  1.2  thorpej 			chp->ch_drive[0].drive_flags |= DRIVE_ATA;
    345  1.2  thorpej 
    346  1.2  thorpej 		aprint_normal("%s: port %d: device present, speed: %s\n",
    347  1.2  thorpej 		    sc->sc_wdcdev.sc_dev.dv_xname, chp->channel,
    348  1.2  thorpej 		    sata_speed[(sstatus & SStatus_SPD_mask) >>
    349  1.2  thorpej 			       SStatus_SPD_shift]);
    350  1.2  thorpej 		rv |= (1 << 0);
    351  1.2  thorpej 		break;
    352  1.2  thorpej 
    353  1.2  thorpej 	default:
    354  1.2  thorpej 		aprint_error("%s: port %d: unknown SStatus: 0x%08x\n",
    355  1.2  thorpej 		    sc->sc_wdcdev.sc_dev.dv_xname, chp->channel, sstatus);
    356  1.2  thorpej 	}
    357  1.2  thorpej 
    358  1.2  thorpej 	return (rv);
    359  1.1  thorpej }
    360  1.1  thorpej 
    361  1.1  thorpej static void
    362  1.1  thorpej sii3112_setup_channel(struct channel_softc *chp)
    363  1.1  thorpej {
    364  1.1  thorpej 	struct ata_drive_datas *drvp;
    365  1.1  thorpej 	int drive;
    366  1.1  thorpej 	u_int32_t idedma_ctl, dtm;
    367  1.1  thorpej 	struct pciide_channel *cp = (struct pciide_channel*)chp;
    368  1.1  thorpej 	struct pciide_softc *sc = (struct pciide_softc*)cp->wdc_channel.wdc;
    369  1.1  thorpej 
    370  1.1  thorpej 	/* setup DMA if needed */
    371  1.1  thorpej 	pciide_channel_dma_setup(cp);
    372  1.1  thorpej 
    373  1.1  thorpej 	idedma_ctl = 0;
    374  1.1  thorpej 	dtm = 0;
    375  1.1  thorpej 
    376  1.1  thorpej 	for (drive = 0; drive < 2; drive++) {
    377  1.1  thorpej 		drvp = &chp->ch_drive[drive];
    378  1.1  thorpej 		/* If no drive, skip */
    379  1.1  thorpej 		if ((drvp->drive_flags & DRIVE) == 0)
    380  1.1  thorpej 			continue;
    381  1.1  thorpej 		if (drvp->drive_flags & DRIVE_UDMA) {
    382  1.1  thorpej 			/* use Ultra/DMA */
    383  1.1  thorpej 			drvp->drive_flags &= ~DRIVE_DMA;
    384  1.1  thorpej 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    385  1.1  thorpej 			dtm |= DTM_IDEx_DMA;
    386  1.1  thorpej 		} else if (drvp->drive_flags & DRIVE_DMA) {
    387  1.1  thorpej 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    388  1.1  thorpej 			dtm |= DTM_IDEx_DMA;
    389  1.1  thorpej 		} else {
    390  1.1  thorpej 			dtm |= DTM_IDEx_PIO;
    391  1.1  thorpej 		}
    392  1.1  thorpej 	}
    393  1.1  thorpej 
    394  1.1  thorpej 	/*
    395  1.1  thorpej 	 * Nothing to do to setup modes; it is meaningless in S-ATA
    396  1.1  thorpej 	 * (but many S-ATA drives still want to get the SET_FEATURE
    397  1.1  thorpej 	 * command).
    398  1.1  thorpej 	 */
    399  1.1  thorpej 	if (idedma_ctl != 0) {
    400  1.1  thorpej 		/* Add software bits in status register */
    401  1.1  thorpej 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    402  1.1  thorpej 		    idedma_ctl);
    403  1.1  thorpej 	}
    404  1.1  thorpej 	pci_conf_write(sc->sc_pc, sc->sc_tag,
    405  1.1  thorpej 	    chp->channel == 0 ? SII3112_DTM_IDE0 : SII3112_DTM_IDE1, dtm);
    406  1.1  thorpej }
    407