1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 1998 - 2008 Søren Schmidt <sos@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer, 12 * without modification, immediately at the beginning of the file. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 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 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 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 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 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <sys/param.h> 30 #include <sys/module.h> 31 #include <sys/systm.h> 32 #include <sys/kernel.h> 33 #include <sys/ata.h> 34 #include <sys/bus.h> 35 #include <sys/endian.h> 36 #include <sys/malloc.h> 37 #include <sys/lock.h> 38 #include <sys/mutex.h> 39 #include <sys/sema.h> 40 #include <sys/taskqueue.h> 41 #include <vm/uma.h> 42 #include <machine/stdarg.h> 43 #include <machine/resource.h> 44 #include <machine/bus.h> 45 #include <sys/rman.h> 46 #include <dev/pci/pcivar.h> 47 #include <dev/pci/pcireg.h> 48 #include <dev/ata/ata-all.h> 49 #include <dev/ata/ata-pci.h> 50 #include <ata_if.h> 51 52 /* local prototypes */ 53 static int ata_marvell_chipinit(device_t dev); 54 static int ata_marvell_ch_attach(device_t dev); 55 static int ata_marvell_setmode(device_t dev, int target, int mode); 56 static int ata_marvell_dummy_chipinit(device_t dev); 57 58 /* misc defines */ 59 #define MV_61XX 61 60 #define MV_91XX 91 61 62 /* 63 * Marvell chipset support functions 64 */ 65 #define ATA_MV_HOST_BASE(ch) \ 66 ((ch->unit & 3) * 0x0100) + (ch->unit > 3 ? 0x30000 : 0x20000) 67 #define ATA_MV_EDMA_BASE(ch) \ 68 ((ch->unit & 3) * 0x2000) + (ch->unit > 3 ? 0x30000 : 0x20000) 69 70 struct ata_marvell_response { 71 u_int16_t tag; 72 u_int8_t edma_status; 73 u_int8_t dev_status; 74 u_int32_t timestamp; 75 }; 76 77 struct ata_marvell_dma_prdentry { 78 u_int32_t addrlo; 79 u_int32_t count; 80 u_int32_t addrhi; 81 u_int32_t reserved; 82 }; 83 84 static int 85 ata_marvell_probe(device_t dev) 86 { 87 struct ata_pci_controller *ctlr = device_get_softc(dev); 88 static const struct ata_chip_id ids[] = 89 {{ ATA_M88SE6101, 0, 0, MV_61XX, ATA_UDMA6, "88SE6101" }, 90 { ATA_M88SE6102, 0, 0, MV_61XX, ATA_UDMA6, "88SE6102" }, 91 { ATA_M88SE6111, 0, 1, MV_61XX, ATA_UDMA6, "88SE6111" }, 92 { ATA_M88SE6121, 0, 2, MV_61XX, ATA_UDMA6, "88SE6121" }, 93 { ATA_M88SE6141, 0, 4, MV_61XX, ATA_UDMA6, "88SE6141" }, 94 { ATA_M88SE6145, 0, 4, MV_61XX, ATA_UDMA6, "88SE6145" }, 95 { 0x91a41b4b, 0, 0, MV_91XX, ATA_UDMA6, "88SE912x" }, 96 { 0, 0, 0, 0, 0, 0}}; 97 98 if (pci_get_vendor(dev) != ATA_MARVELL_ID && 99 pci_get_vendor(dev) != ATA_MARVELL2_ID) 100 return ENXIO; 101 102 if (!(ctlr->chip = ata_match_chip(dev, ids))) 103 return ENXIO; 104 105 ata_set_desc(dev); 106 107 switch (ctlr->chip->cfg2) { 108 case MV_61XX: 109 ctlr->chipinit = ata_marvell_chipinit; 110 break; 111 case MV_91XX: 112 ctlr->chipinit = ata_marvell_dummy_chipinit; 113 break; 114 } 115 return (BUS_PROBE_LOW_PRIORITY); 116 } 117 118 static int 119 ata_marvell_chipinit(device_t dev) 120 { 121 struct ata_pci_controller *ctlr = device_get_softc(dev); 122 device_t child; 123 124 if (ata_setup_interrupt(dev, ata_generic_intr)) 125 return ENXIO; 126 /* Create AHCI subdevice if AHCI part present. */ 127 if (ctlr->chip->cfg1) { 128 child = device_add_child(dev, NULL, DEVICE_UNIT_ANY); 129 if (child != NULL) { 130 device_set_ivars(child, (void *)(intptr_t)-1); 131 bus_generic_attach(dev); 132 } 133 } 134 ctlr->ch_attach = ata_marvell_ch_attach; 135 ctlr->ch_detach = ata_pci_ch_detach; 136 ctlr->reset = ata_generic_reset; 137 ctlr->setmode = ata_marvell_setmode; 138 ctlr->channels = 1; 139 return (0); 140 } 141 142 static int 143 ata_marvell_ch_attach(device_t dev) 144 { 145 struct ata_channel *ch = device_get_softc(dev); 146 int error; 147 148 error = ata_pci_ch_attach(dev); 149 /* dont use 32 bit PIO transfers */ 150 ch->flags |= ATA_USE_16BIT; 151 ch->flags |= ATA_CHECKS_CABLE; 152 return (error); 153 } 154 155 static int 156 ata_marvell_setmode(device_t dev, int target, int mode) 157 { 158 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev)); 159 struct ata_channel *ch = device_get_softc(dev); 160 161 mode = min(mode, ctlr->chip->max_dma); 162 /* Check for 80pin cable present. */ 163 if (ata_dma_check_80pin && mode > ATA_UDMA2 && 164 ATA_IDX_INB(ch, ATA_BMDEVSPEC_0) & 0x01) { 165 ata_print_cable(dev, "controller"); 166 mode = ATA_UDMA2; 167 } 168 /* Nothing to do to setup mode, the controller snoop SET_FEATURE cmd. */ 169 return (mode); 170 } 171 172 static int 173 ata_marvell_dummy_chipinit(device_t dev) 174 { 175 struct ata_pci_controller *ctlr = device_get_softc(dev); 176 177 ctlr->channels = 0; 178 return (0); 179 } 180 181 ATA_DECLARE_DRIVER(ata_marvell); 182