ata-all.c (88477) | ata-all.c (90215) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 1998,1999,2000,2001 S�ren Schmidt | 2 * Copyright (c) 1998,1999,2000,2001,2002 S�ren Schmidt <sos@FreeBSD.org> |
3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer, 10 * without modification, immediately at the beginning of the file. --- 9 unchanged lines hidden (view full) --- 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 * | 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer, 10 * without modification, immediately at the beginning of the file. --- 9 unchanged lines hidden (view full) --- 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 * $FreeBSD: head/sys/dev/ata/ata-all.c 88477 2001-12-25 14:43:08Z sos $ | 28 * $FreeBSD: head/sys/dev/ata/ata-all.c 90215 2002-02-04 19:23:40Z sos $ |
29 */ 30 31#include "pci.h" 32#include "opt_ata.h" 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/ata.h> 36#include <sys/kernel.h> --- 9 unchanged lines hidden (view full) --- 46#include <machine/resource.h> 47#include <machine/bus.h> 48#include <sys/rman.h> 49#ifdef __alpha__ 50#include <machine/md_var.h> 51#endif 52#include <dev/ata/ata-all.h> 53#include <dev/ata/ata-disk.h> | 29 */ 30 31#include "pci.h" 32#include "opt_ata.h" 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/ata.h> 36#include <sys/kernel.h> --- 9 unchanged lines hidden (view full) --- 46#include <machine/resource.h> 47#include <machine/bus.h> 48#include <sys/rman.h> 49#ifdef __alpha__ 50#include <machine/md_var.h> 51#endif 52#include <dev/ata/ata-all.h> 53#include <dev/ata/ata-disk.h> |
54#include <dev/ata/ata-raid.h> |
|
54#include <dev/ata/atapi-all.h> 55 56/* device structures */ | 55#include <dev/ata/atapi-all.h> 56 57/* device structures */ |
57static d_ioctl_t ataioctl; | 58static d_ioctl_t ataioctl; |
58static struct cdevsw ata_cdevsw = { 59 /* open */ nullopen, 60 /* close */ nullclose, 61 /* read */ noread, 62 /* write */ nowrite, 63 /* ioctl */ ataioctl, 64 /* poll */ nopoll, 65 /* mmap */ nommap, 66 /* strategy */ nostrategy, 67 /* name */ "ata", 68 /* maj */ 159, 69 /* dump */ nodump, 70 /* psize */ nopsize, 71 /* flags */ 0, 72}; 73 74/* prototypes */ 75static void ata_boot_attach(void); 76static void ata_intr(void *); | 59static struct cdevsw ata_cdevsw = { 60 /* open */ nullopen, 61 /* close */ nullclose, 62 /* read */ noread, 63 /* write */ nowrite, 64 /* ioctl */ ataioctl, 65 /* poll */ nopoll, 66 /* mmap */ nommap, 67 /* strategy */ nostrategy, 68 /* name */ "ata", 69 /* maj */ 159, 70 /* dump */ nodump, 71 /* psize */ nopsize, 72 /* flags */ 0, 73}; 74 75/* prototypes */ 76static void ata_boot_attach(void); 77static void ata_intr(void *); |
77static int ata_getparam(struct ata_softc *, int, u_int8_t); 78static int ata_service(struct ata_softc *); | 78static int ata_getparam(struct ata_device *, u_int8_t); 79static int ata_service(struct ata_channel *); |
79static void bswap(int8_t *, int); 80static void btrim(int8_t *, int); 81static void bpack(int8_t *, int8_t *, int); | 80static void bswap(int8_t *, int); 81static void btrim(int8_t *, int); 82static void bpack(int8_t *, int8_t *, int); |
82static void ata_change_mode(struct ata_softc *, int, int); | 83static void ata_change_mode(struct ata_device *, int); |
83 84/* sysctl vars */ 85SYSCTL_NODE(_hw, OID_AUTO, ata, CTLFLAG_RD, 0, "ATA driver parameters"); 86 87/* global vars */ 88devclass_t ata_devclass; 89 90/* local vars */ 91static struct intr_config_hook *ata_delayed_attach = NULL; 92static MALLOC_DEFINE(M_ATA, "ATA generic", "ATA driver generic layer"); 93 | 84 85/* sysctl vars */ 86SYSCTL_NODE(_hw, OID_AUTO, ata, CTLFLAG_RD, 0, "ATA driver parameters"); 87 88/* global vars */ 89devclass_t ata_devclass; 90 91/* local vars */ 92static struct intr_config_hook *ata_delayed_attach = NULL; 93static MALLOC_DEFINE(M_ATA, "ATA generic", "ATA driver generic layer"); 94 |
94/* misc defines */ 95#define MASTER 0 96#define SLAVE 1 97 | |
98int 99ata_probe(device_t dev) 100{ | 95int 96ata_probe(device_t dev) 97{ |
101 struct ata_softc *scp; | 98 struct ata_channel *ch; |
102 int rid; 103 | 99 int rid; 100 |
104 if (!dev) | 101 if (!dev || !(ch = device_get_softc(dev))) |
105 return ENXIO; | 102 return ENXIO; |
106 scp = device_get_softc(dev); 107 if (!scp) 108 return ENXIO; 109 if (scp->r_io || scp->r_altio || scp->r_irq) | 103 104 if (ch->r_io || ch->r_altio || ch->r_irq) |
110 return EEXIST; 111 112 /* initialize the softc basics */ | 105 return EEXIST; 106 107 /* initialize the softc basics */ |
113 scp->active = ATA_IDLE; 114 scp->dev = dev; | 108 ch->active = ATA_IDLE; 109 ch->dev = dev; |
115 116 rid = ATA_IOADDR_RID; | 110 111 rid = ATA_IOADDR_RID; |
117 scp->r_io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 118 ATA_IOSIZE, RF_ACTIVE); 119 if (!scp->r_io) | 112 ch->r_io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 113 ATA_IOSIZE, RF_ACTIVE); 114 if (!ch->r_io) |
120 goto failure; 121 122 rid = ATA_ALTADDR_RID; | 115 goto failure; 116 117 rid = ATA_ALTADDR_RID; |
123 scp->r_altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 124 ATA_ALTIOSIZE, RF_ACTIVE); 125 if (!scp->r_altio) | 118 ch->r_altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 119 ATA_ALTIOSIZE, RF_ACTIVE); 120 if (!ch->r_altio) |
126 goto failure; 127 128 rid = ATA_BMADDR_RID; | 121 goto failure; 122 123 rid = ATA_BMADDR_RID; |
129 scp->r_bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 130 ATA_BMIOSIZE, RF_ACTIVE); | 124 ch->r_bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 125 ATA_BMIOSIZE, RF_ACTIVE); |
131 if (bootverbose) | 126 if (bootverbose) |
132 ata_printf(scp, -1, "iobase=0x%04x altiobase=0x%04x bmaddr=0x%04x\n", 133 (int)rman_get_start(scp->r_io), 134 (int)rman_get_start(scp->r_altio), 135 (scp->r_bmio) ? (int)rman_get_start(scp->r_bmio) : 0); | 127 ata_printf(ch, -1, "iobase=0x%04x altiobase=0x%04x bmaddr=0x%04x\n", 128 (int)rman_get_start(ch->r_io), 129 (int)rman_get_start(ch->r_altio), 130 (ch->r_bmio) ? (int)rman_get_start(ch->r_bmio) : 0); |
136 | 131 |
137 ata_reset(scp); | 132 ata_reset(ch); |
138 | 133 |
139 TAILQ_INIT(&scp->ata_queue); 140 TAILQ_INIT(&scp->atapi_queue); | 134 ch->device[MASTER].channel = ch; 135 ch->device[MASTER].unit = ATA_MASTER; 136 ch->device[MASTER].mode = ATA_PIO; 137 ch->device[SLAVE].channel = ch; 138 ch->device[SLAVE].unit = ATA_SLAVE; 139 ch->device[SLAVE].mode = ATA_PIO; 140 TAILQ_INIT(&ch->ata_queue); 141 TAILQ_INIT(&ch->atapi_queue); |
141 return 0; 142 143failure: | 142 return 0; 143 144failure: |
144 if (scp->r_io) 145 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, scp->r_io); 146 if (scp->r_altio) 147 bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,scp->r_altio); 148 if (scp->r_bmio) 149 bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, scp->r_bmio); | 145 if (ch->r_io) 146 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, ch->r_io); 147 if (ch->r_altio) 148 bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, ch->r_altio); 149 if (ch->r_bmio) 150 bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, ch->r_bmio); |
150 if (bootverbose) | 151 if (bootverbose) |
151 ata_printf(scp, -1, "probe allocation failed\n"); | 152 ata_printf(ch, -1, "probe allocation failed\n"); |
152 return ENXIO; 153} 154 155int 156ata_attach(device_t dev) 157{ | 153 return ENXIO; 154} 155 156int 157ata_attach(device_t dev) 158{ |
158 struct ata_softc *scp; | 159 struct ata_channel *ch; |
159 int error, rid; 160 | 160 int error, rid; 161 |
161 if (!dev) | 162 if (!dev || !(ch = device_get_softc(dev))) |
162 return ENXIO; | 163 return ENXIO; |
163 scp = device_get_softc(dev); 164 if (!scp) 165 return ENXIO; | |
166 167 rid = ATA_IRQ_RID; | 164 165 rid = ATA_IRQ_RID; |
168 scp->r_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 169 RF_SHAREABLE | RF_ACTIVE); 170 if (!scp->r_irq) { 171 ata_printf(scp, -1, "unable to allocate interrupt\n"); | 166 ch->r_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 167 RF_SHAREABLE | RF_ACTIVE); 168 if (!ch->r_irq) { 169 ata_printf(ch, -1, "unable to allocate interrupt\n"); |
172 return ENXIO; 173 } | 170 return ENXIO; 171 } |
174 if ((error = bus_setup_intr(dev, scp->r_irq, INTR_TYPE_BIO|INTR_ENTROPY, 175 ata_intr, scp, &scp->ih))) | 172 if ((error = bus_setup_intr(dev, ch->r_irq, INTR_TYPE_BIO | INTR_ENTROPY, 173 ata_intr, ch, &ch->ih))) |
176 return error; 177 178 /* 179 * do not attach devices if we are in early boot, this is done later 180 * when interrupts are enabled by a hook into the boot process. | 174 return error; 175 176 /* 177 * do not attach devices if we are in early boot, this is done later 178 * when interrupts are enabled by a hook into the boot process. |
181 * otherwise attach what the probe has found in scp->devices. | 179 * otherwise attach what the probe has found in ch->devices. |
182 */ 183 if (!ata_delayed_attach) { | 180 */ 181 if (!ata_delayed_attach) { |
184 if (scp->devices & ATA_ATA_SLAVE) 185 if (ata_getparam(scp, ATA_SLAVE, ATA_C_ATA_IDENTIFY)) 186 scp->devices &= ~ATA_ATA_SLAVE; 187 if (scp->devices & ATA_ATAPI_SLAVE) 188 if (ata_getparam(scp, ATA_SLAVE, ATA_C_ATAPI_IDENTIFY)) 189 scp->devices &= ~ATA_ATAPI_SLAVE; 190 if (scp->devices & ATA_ATA_MASTER) 191 if (ata_getparam(scp, ATA_MASTER, ATA_C_ATA_IDENTIFY)) 192 scp->devices &= ~ATA_ATA_MASTER; 193 if (scp->devices & ATA_ATAPI_MASTER) 194 if (ata_getparam(scp, ATA_MASTER,ATA_C_ATAPI_IDENTIFY)) 195 scp->devices &= ~ATA_ATAPI_MASTER; | 182 if (ch->devices & ATA_ATA_SLAVE) 183 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATA_IDENTIFY)) 184 ch->devices &= ~ATA_ATA_SLAVE; 185 if (ch->devices & ATA_ATAPI_SLAVE) 186 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATAPI_IDENTIFY)) 187 ch->devices &= ~ATA_ATAPI_SLAVE; 188 if (ch->devices & ATA_ATA_MASTER) 189 if (ata_getparam(&ch->device[MASTER], ATA_C_ATA_IDENTIFY)) 190 ch->devices &= ~ATA_ATA_MASTER; 191 if (ch->devices & ATA_ATAPI_MASTER) 192 if (ata_getparam(&ch->device[MASTER] ,ATA_C_ATAPI_IDENTIFY)) 193 ch->devices &= ~ATA_ATAPI_MASTER; |
196#ifdef DEV_ATADISK | 194#ifdef DEV_ATADISK |
197 if (scp->devices & ATA_ATA_MASTER) 198 ad_attach(scp, ATA_MASTER); 199 if (scp->devices & ATA_ATA_SLAVE) 200 ad_attach(scp, ATA_SLAVE); | 195 if (ch->devices & ATA_ATA_MASTER) 196 ad_attach(&ch->device[MASTER]); 197 if (ch->devices & ATA_ATA_SLAVE) 198 ad_attach(&ch->device[SLAVE]); |
201#endif 202#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) | 199#endif 200#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) |
203 if (scp->devices & ATA_ATAPI_MASTER) 204 atapi_attach(scp, ATA_MASTER); 205 if (scp->devices & ATA_ATAPI_SLAVE) 206 atapi_attach(scp, ATA_SLAVE); | 201 if (ch->devices & ATA_ATAPI_MASTER) 202 atapi_attach(&ch->device[MASTER]); 203 if (ch->devices & ATA_ATAPI_SLAVE) 204 atapi_attach(&ch->device[SLAVE]); |
207#endif | 205#endif |
206 /* we should probe & attach RAID's here as well SOS XXX */ |
|
208 } 209 return 0; 210} 211 212int 213ata_detach(device_t dev) 214{ | 207 } 208 return 0; 209} 210 211int 212ata_detach(device_t dev) 213{ |
215 struct ata_softc *scp; | 214 struct ata_channel *ch; |
216 int s; 217 | 215 int s; 216 |
218 if (!dev) | 217 if (!dev || !(ch = device_get_softc(dev))) |
219 return ENXIO; | 218 return ENXIO; |
220 scp = device_get_softc(dev); 221 if (!scp) 222 return ENXIO; | |
223 | 219 |
224 /* make sure channel is not busy SOS XXX */ | 220 /* make sure channel is not busy */ |
225 s = splbio(); | 221 s = splbio(); |
226 while (!atomic_cmpset_int(&scp->active, ATA_IDLE, ATA_CONTROL)) 227 tsleep((caddr_t)&s, PRIBIO, "atachm", hz/4); | 222 while (!atomic_cmpset_int(&ch->active, ATA_IDLE, ATA_CONTROL)) 223 tsleep((caddr_t)&s, PRIBIO, "atarel", hz/4); |
228 splx(s); 229 230 /* disable interrupts on devices */ | 224 splx(s); 225 226 /* disable interrupts on devices */ |
231 ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER); 232 ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_4BIT); 233 ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE); 234 ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_4BIT); | 227 ATA_OUTB(ch->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER); 228 ATA_OUTB(ch->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_4BIT); 229 ATA_OUTB(ch->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE); 230 ATA_OUTB(ch->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_4BIT); |
235 236#ifdef DEV_ATADISK | 231 232#ifdef DEV_ATADISK |
237 if (scp->devices & ATA_ATA_MASTER && scp->dev_softc[MASTER]) 238 ad_detach(scp->dev_softc[MASTER], 1); 239 if (scp->devices & ATA_ATA_SLAVE && scp->dev_softc[SLAVE]) 240 ad_detach(scp->dev_softc[SLAVE], 1); | 233 if (ch->devices & ATA_ATA_MASTER && ch->device[MASTER].driver) 234 ad_detach(&ch->device[MASTER], 1); 235 if (ch->devices & ATA_ATA_SLAVE && ch->device[SLAVE].driver) 236 ad_detach(&ch->device[SLAVE], 1); |
241#endif 242#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) | 237#endif 238#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) |
243 if (scp->devices & ATA_ATAPI_MASTER && scp->dev_softc[MASTER]) 244 atapi_detach(scp->dev_softc[MASTER]); 245 if (scp->devices & ATA_ATAPI_SLAVE && scp->dev_softc[SLAVE]) 246 atapi_detach(scp->dev_softc[SLAVE]); | 239 if (ch->devices & ATA_ATAPI_MASTER && ch->device[MASTER].driver) 240 atapi_detach(&ch->device[MASTER]); 241 if (ch->devices & ATA_ATAPI_SLAVE && ch->device[SLAVE].driver) 242 atapi_detach(&ch->device[SLAVE]); |
247#endif 248 | 243#endif 244 |
249 if (scp->dev_param[MASTER]) { 250 free(scp->dev_param[MASTER], M_ATA); 251 scp->dev_param[MASTER] = NULL; | 245 if (ch->device[MASTER].param) { 246 free(ch->device[MASTER].param, M_ATA); 247 ch->device[MASTER].param = NULL; |
252 } | 248 } |
253 if (scp->dev_param[SLAVE]) { 254 free(scp->dev_param[SLAVE], M_ATA); 255 scp->dev_param[SLAVE] = NULL; | 249 if (ch->device[SLAVE].param) { 250 free(ch->device[SLAVE].param, M_ATA); 251 ch->device[SLAVE].param = NULL; |
256 } | 252 } |
257 scp->dev_softc[MASTER] = NULL; 258 scp->dev_softc[SLAVE] = NULL; 259 scp->mode[MASTER] = ATA_PIO; 260 scp->mode[SLAVE] = ATA_PIO; 261 scp->devices = 0; | 253 ch->device[MASTER].driver = NULL; 254 ch->device[SLAVE].driver = NULL; 255 ch->device[MASTER].mode = ATA_PIO; 256 ch->device[SLAVE].mode = ATA_PIO; 257 ch->devices = 0; |
262 | 258 |
263 bus_teardown_intr(dev, scp->r_irq, scp->ih); 264 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, scp->r_irq); 265 if (scp->r_bmio) 266 bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, scp->r_bmio); 267 bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, scp->r_altio); 268 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, scp->r_io); 269 scp->r_io = NULL; 270 scp->r_altio = NULL; 271 scp->r_bmio = NULL; 272 scp->r_irq = NULL; 273 scp->active = ATA_IDLE; | 259 bus_teardown_intr(dev, ch->r_irq, ch->ih); 260 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq); 261 if (ch->r_bmio) 262 bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, ch->r_bmio); 263 bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, ch->r_altio); 264 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, ch->r_io); 265 ch->r_io = NULL; 266 ch->r_altio = NULL; 267 ch->r_bmio = NULL; 268 ch->r_irq = NULL; 269 ch->active = ATA_IDLE; |
274 return 0; 275} 276 277int 278ata_resume(device_t dev) 279{ | 270 return 0; 271} 272 273int 274ata_resume(device_t dev) 275{ |
280 struct ata_softc *scp = device_get_softc(dev); 281 282 ata_reinit(scp); 283 return 0; | 276 return ata_reinit(device_get_softc(dev)); |
284} 285 286static int 287ataioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct thread *td) 288{ 289 struct ata_cmd *iocmd = (struct ata_cmd *)addr; | 277} 278 279static int 280ataioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct thread *td) 281{ 282 struct ata_cmd *iocmd = (struct ata_cmd *)addr; |
283 struct ata_device *atadev; 284 struct ata_channel *ch; |
|
290 device_t device; 291 int error; 292 293 if (cmd != IOCATA) 294 return ENOTTY; 295 | 285 device_t device; 286 int error; 287 288 if (cmd != IOCATA) 289 return ENOTTY; 290 |
296 if (iocmd->channel >= devclass_get_maxunit(ata_devclass)) | 291 if (iocmd->device < -1 || iocmd->device > SLAVE || iocmd->channel < 0 || 292 iocmd->channel >= devclass_get_maxunit(ata_devclass)) |
297 return ENXIO; 298 299 if (!(device = devclass_get_device(ata_devclass, iocmd->channel))) 300 return ENODEV; 301 302 switch (iocmd->cmd) { 303 case ATAATTACH: { 304 /* should enable channel HW on controller that can SOS XXX */ --- 5 unchanged lines hidden (view full) --- 310 311 case ATADETACH: { 312 error = ata_detach(device); 313 /* should disable channel HW on controller that can SOS XXX */ 314 return error; 315 } 316 317 case ATAREINIT: { | 293 return ENXIO; 294 295 if (!(device = devclass_get_device(ata_devclass, iocmd->channel))) 296 return ENODEV; 297 298 switch (iocmd->cmd) { 299 case ATAATTACH: { 300 /* should enable channel HW on controller that can SOS XXX */ --- 5 unchanged lines hidden (view full) --- 306 307 case ATADETACH: { 308 error = ata_detach(device); 309 /* should disable channel HW on controller that can SOS XXX */ 310 return error; 311 } 312 313 case ATAREINIT: { |
318 struct ata_softc *scp; | |
319 int s; 320 | 314 int s; 315 |
321 scp = device_get_softc(device); 322 if (!scp) | 316 if (!(ch = device_get_softc(device))) |
323 return ENODEV; 324 | 317 return ENODEV; 318 |
325 /* make sure channel is not busy SOS XXX */ | 319 /* make sure channel is not busy */ |
326 s = splbio(); | 320 s = splbio(); |
327 while (!atomic_cmpset_int(&scp->active, ATA_IDLE, ATA_ACTIVE)) 328 tsleep((caddr_t)&s, PRIBIO, "atachm", hz/4); 329 error = ata_reinit(scp); | 321 while (!atomic_cmpset_int(&ch->active, ATA_IDLE, ATA_ACTIVE)) 322 tsleep((caddr_t)&s, PRIBIO, "atarin", hz/4); 323 error = ata_reinit(ch); |
330 splx(s); 331 return error; 332 } 333 | 324 splx(s); 325 return error; 326 } 327 |
334 case ATAGMODE: { 335 struct ata_softc *scp; 336 337 scp = device_get_softc(device); 338 if (!scp) | 328 case ATAGMODE: 329 if (!(ch = device_get_softc(device))) |
339 return ENODEV; | 330 return ENODEV; |
340 if (scp->dev_param[MASTER]) 341 iocmd->u.mode.mode[MASTER] = scp->mode[MASTER]; | 331 332 if ((iocmd->device == MASTER || iocmd->device == -1) && 333 ch->device[MASTER].driver) 334 iocmd->u.mode.mode[MASTER] = ch->device[MASTER].mode; |
342 else 343 iocmd->u.mode.mode[MASTER] = -1; | 335 else 336 iocmd->u.mode.mode[MASTER] = -1; |
344 if (scp->dev_param[SLAVE]) 345 iocmd->u.mode.mode[SLAVE] = scp->mode[SLAVE]; | 337 338 if ((iocmd->device == SLAVE || iocmd->device == -1) && 339 ch->device[SLAVE].param) 340 iocmd->u.mode.mode[SLAVE] = ch->device[SLAVE].mode; |
346 else 347 iocmd->u.mode.mode[SLAVE] = -1; 348 return 0; | 341 else 342 iocmd->u.mode.mode[SLAVE] = -1; 343 return 0; |
349 } | |
350 | 344 |
351 case ATASMODE: { 352 struct ata_softc *scp; 353 354 scp = device_get_softc(device); 355 if (!scp) | 345 case ATASMODE: 346 if (!(ch = device_get_softc(device))) |
356 return ENODEV; | 347 return ENODEV; |
357 if (scp->dev_param[MASTER] && iocmd->u.mode.mode[MASTER] >= 0) { 358 ata_change_mode(scp, ATA_MASTER, iocmd->u.mode.mode[MASTER]); 359 iocmd->u.mode.mode[MASTER] = scp->mode[MASTER]; | 348 349 if ((iocmd->device == MASTER || iocmd->device == -1) && 350 iocmd->u.mode.mode[MASTER] >= 0 && ch->device[MASTER].param) { 351 ata_change_mode(&ch->device[MASTER],iocmd->u.mode.mode[MASTER]); 352 iocmd->u.mode.mode[MASTER] = ch->device[MASTER].mode; |
360 } 361 else 362 iocmd->u.mode.mode[MASTER] = -1; 363 | 353 } 354 else 355 iocmd->u.mode.mode[MASTER] = -1; 356 |
364 if (scp->dev_param[SLAVE] && iocmd->u.mode.mode[SLAVE] >= 0) { 365 ata_change_mode(scp, ATA_SLAVE, iocmd->u.mode.mode[SLAVE]); 366 iocmd->u.mode.mode[SLAVE] = scp->mode[SLAVE]; | 357 if ((iocmd->device == SLAVE || iocmd->device == -1) && 358 iocmd->u.mode.mode[SLAVE] >= 0 && ch->device[SLAVE].param) { 359 ata_change_mode(&ch->device[SLAVE], iocmd->u.mode.mode[SLAVE]); 360 iocmd->u.mode.mode[SLAVE] = ch->device[SLAVE].mode; |
367 } 368 else 369 iocmd->u.mode.mode[SLAVE] = -1; | 361 } 362 else 363 iocmd->u.mode.mode[SLAVE] = -1; |
364 |
|
370 return 0; | 365 return 0; |
371 } | |
372 | 366 |
373 case ATAGPARM: { 374 struct ata_softc *scp; 375 376 scp = device_get_softc(device); 377 if (!scp) | 367 case ATAGPARM: 368 if (!(ch = device_get_softc(device))) |
378 return ENODEV; 379 380 iocmd->u.param.type[MASTER] = | 369 return ENODEV; 370 371 iocmd->u.param.type[MASTER] = |
381 scp->devices & (ATA_ATA_MASTER | ATA_ATAPI_MASTER); | 372 ch->devices & (ATA_ATA_MASTER | ATA_ATAPI_MASTER); |
382 iocmd->u.param.type[SLAVE] = | 373 iocmd->u.param.type[SLAVE] = |
383 scp->devices & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE); | 374 ch->devices & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE); |
384 | 375 |
385 if (scp->dev_name[MASTER]) 386 strcpy(iocmd->u.param.name[MASTER], scp->dev_name[MASTER]); 387 if (scp->dev_name[SLAVE]) 388 strcpy(iocmd->u.param.name[SLAVE], scp->dev_name[SLAVE]); | 376 if (ch->device[MASTER].name) 377 strcpy(iocmd->u.param.name[MASTER], ch->device[MASTER].name); 378 if (ch->device[SLAVE].name) 379 strcpy(iocmd->u.param.name[SLAVE], ch->device[SLAVE].name); |
389 | 380 |
390 if (scp->dev_param[MASTER]) 391 bcopy(scp->dev_param[MASTER], &iocmd->u.param.params[MASTER], | 381 if (ch->device[MASTER].param) 382 bcopy(ch->device[MASTER].param, &iocmd->u.param.params[MASTER], |
392 sizeof(struct ata_params)); | 383 sizeof(struct ata_params)); |
393 if (scp->dev_param[SLAVE]) 394 bcopy(scp->dev_param[SLAVE], &iocmd->u.param.params[SLAVE], | 384 if (ch->device[SLAVE].param) 385 bcopy(ch->device[SLAVE].param, &iocmd->u.param.params[SLAVE], |
395 sizeof(struct ata_params)); | 386 sizeof(struct ata_params)); |
387 |
|
396 return 0; | 388 return 0; |
397 } | |
398 399#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) 400 case ATAPICMD: { | 389 390#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) 391 case ATAPICMD: { |
401 struct ata_softc *scp; 402 struct atapi_softc *atp; | |
403 caddr_t buf; 404 | 392 caddr_t buf; 393 |
405 scp = device_get_softc(device); 406 if (!scp) | 394 ch = device_get_softc(device); 395 if (!ch) |
407 return ENODEV; 408 | 396 return ENODEV; 397 |
409 if (!scp->dev_softc[iocmd->device] || 410 !(scp->devices & 411 (iocmd->device == 0 ? ATA_ATAPI_MASTER : ATA_ATAPI_SLAVE))) | 398 399 if (!(atadev = &ch->device[iocmd->device]) || 400 !(ch->devices & (iocmd->device == MASTER ? 401 ATA_ATAPI_MASTER : ATA_ATAPI_SLAVE))) |
412 return ENODEV; 413 | 402 return ENODEV; 403 |
414 if (!(buf = malloc(iocmd->u.atapi.count, M_ATA, M_NOWAIT))) | 404 if (!(buf = malloc(iocmd->u.atapi.count, M_ATA, M_NOWAIT))) |
415 return ENOMEM; 416 | 405 return ENOMEM; 406 |
417 atp = scp->dev_softc[iocmd->device]; | |
418 if (iocmd->u.atapi.flags & ATAPI_CMD_WRITE) { 419 error = copyin(iocmd->u.atapi.data, buf, iocmd->u.atapi.count); 420 if (error) 421 return error; 422 } | 407 if (iocmd->u.atapi.flags & ATAPI_CMD_WRITE) { 408 error = copyin(iocmd->u.atapi.data, buf, iocmd->u.atapi.count); 409 if (error) 410 return error; 411 } |
423 error = atapi_queue_cmd(atp, iocmd->u.atapi.ccb, | 412 error = atapi_queue_cmd(atadev, iocmd->u.atapi.ccb, |
424 buf, iocmd->u.atapi.count, 425 (iocmd->u.atapi.flags == ATAPI_CMD_READ ? | 413 buf, iocmd->u.atapi.count, 414 (iocmd->u.atapi.flags == ATAPI_CMD_READ ? |
426 ATPR_F_READ : 0) | ATPR_F_QUIET, | 415 ATPR_F_READ : 0) | ATPR_F_QUIET, |
427 iocmd->u.atapi.timeout, NULL, NULL); 428 if (error) { 429 iocmd->u.atapi.error = error; | 416 iocmd->u.atapi.timeout, NULL, NULL); 417 if (error) { 418 iocmd->u.atapi.error = error; |
430 bcopy(&atp->sense, iocmd->u.atapi.sense_data, | 419 bcopy(&atadev->result, iocmd->u.atapi.sense_data, |
431 sizeof(struct atapi_reqsense)); 432 error = 0; 433 } 434 else if (iocmd->u.atapi.flags & ATAPI_CMD_READ) 435 error = copyout(buf, iocmd->u.atapi.data, iocmd->u.atapi.count); 436 437 free(buf, M_ATA); 438 return error; 439 } 440#endif 441 } 442 return ENOTTY; 443} 444 445static int | 420 sizeof(struct atapi_reqsense)); 421 error = 0; 422 } 423 else if (iocmd->u.atapi.flags & ATAPI_CMD_READ) 424 error = copyout(buf, iocmd->u.atapi.data, iocmd->u.atapi.count); 425 426 free(buf, M_ATA); 427 return error; 428 } 429#endif 430 } 431 return ENOTTY; 432} 433 434static int |
446ata_getparam(struct ata_softc *scp, int device, u_int8_t command) | 435ata_getparam(struct ata_device *atadev, u_int8_t command) |
447{ 448 struct ata_params *ata_parm; 449 int retry = 0; 450 451 /* select drive */ | 436{ 437 struct ata_params *ata_parm; 438 int retry = 0; 439 440 /* select drive */ |
452 ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | device); | 441 ATA_OUTB(atadev->channel->r_io, ATA_DRIVE, ATA_D_IBM | atadev->unit); |
453 DELAY(1); 454 455 /* enable interrupt */ | 442 DELAY(1); 443 444 /* enable interrupt */ |
456 ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_4BIT); | 445 ATA_OUTB(atadev->channel->r_altio, ATA_ALTSTAT, ATA_A_4BIT); |
457 DELAY(1); 458 459 /* apparently some devices needs this repeated */ 460 do { | 446 DELAY(1); 447 448 /* apparently some devices needs this repeated */ 449 do { |
461 if (ata_command(scp, device, command, 0, 0, 0, ATA_WAIT_INTR)) { 462 ata_printf(scp, device, "%s identify failed\n", | 450 if (ata_command(atadev, command, 0, 0, 0, ATA_WAIT_INTR)) { 451 ata_prtdev(atadev, "%s identify failed\n", |
463 command == ATA_C_ATAPI_IDENTIFY ? "ATAPI" : "ATA"); 464 return -1; 465 } 466 if (retry++ > 4) { | 452 command == ATA_C_ATAPI_IDENTIFY ? "ATAPI" : "ATA"); 453 return -1; 454 } 455 if (retry++ > 4) { |
467 ata_printf(scp, device, "%s identify retries exceeded\n", | 456 ata_prtdev(atadev, "%s identify retries exceeded\n", |
468 command == ATA_C_ATAPI_IDENTIFY ? "ATAPI" : "ATA"); 469 return -1; 470 } | 457 command == ATA_C_ATAPI_IDENTIFY ? "ATAPI" : "ATA"); 458 return -1; 459 } |
471 } while (ata_wait(scp, device, 472 ((command == ATA_C_ATAPI_IDENTIFY) ? 473 ATA_S_DRQ : (ATA_S_READY | ATA_S_DSC | ATA_S_DRQ)))); | 460 } while (ata_wait(atadev, ((command == ATA_C_ATAPI_IDENTIFY) ? 461 ATA_S_DRQ : (ATA_S_READY|ATA_S_DSC|ATA_S_DRQ)))); |
474 475 ata_parm = malloc(sizeof(struct ata_params), M_ATA, M_NOWAIT); 476 if (!ata_parm) { 477 int i; 478 479 for (i = 0; i < sizeof(struct ata_params)/sizeof(int16_t); i++) | 462 463 ata_parm = malloc(sizeof(struct ata_params), M_ATA, M_NOWAIT); 464 if (!ata_parm) { 465 int i; 466 467 for (i = 0; i < sizeof(struct ata_params)/sizeof(int16_t); i++) |
480 ATA_INW(scp->r_io, ATA_DATA); 481 ata_printf(scp, device, "malloc for identify data failed\n"); 482 return -1; | 468 ATA_INW(atadev->channel->r_io, ATA_DATA); 469 ata_prtdev(atadev, "malloc for identify data failed\n"); 470 return -1; |
483 } 484 | 471 } 472 |
485 ATA_INSW(scp->r_io, ATA_DATA, (int16_t *)ata_parm, | 473 ATA_INSW(atadev->channel->r_io, ATA_DATA, (int16_t *)ata_parm, |
486 sizeof(struct ata_params)/sizeof(int16_t)); 487 488 if (command == ATA_C_ATA_IDENTIFY || 489 !((ata_parm->model[0] == 'N' && ata_parm->model[1] == 'E') || | 474 sizeof(struct ata_params)/sizeof(int16_t)); 475 476 if (command == ATA_C_ATA_IDENTIFY || 477 !((ata_parm->model[0] == 'N' && ata_parm->model[1] == 'E') || |
490 (ata_parm->model[0] == 'F' && ata_parm->model[1] == 'X'))) 491 bswap(ata_parm->model, sizeof(ata_parm->model)); | 478 (ata_parm->model[0] == 'F' && ata_parm->model[1] == 'X') || 479 (ata_parm->model[0] == 'P' && ata_parm->model[1] == 'i'))) 480 bswap(ata_parm->model, sizeof(ata_parm->model)); |
492 btrim(ata_parm->model, sizeof(ata_parm->model)); 493 bpack(ata_parm->model, ata_parm->model, sizeof(ata_parm->model)); 494 bswap(ata_parm->revision, sizeof(ata_parm->revision)); 495 btrim(ata_parm->revision, sizeof(ata_parm->revision)); 496 bpack(ata_parm->revision, ata_parm->revision, sizeof(ata_parm->revision)); | 481 btrim(ata_parm->model, sizeof(ata_parm->model)); 482 bpack(ata_parm->model, ata_parm->model, sizeof(ata_parm->model)); 483 bswap(ata_parm->revision, sizeof(ata_parm->revision)); 484 btrim(ata_parm->revision, sizeof(ata_parm->revision)); 485 bpack(ata_parm->revision, ata_parm->revision, sizeof(ata_parm->revision)); |
497 scp->dev_param[ATA_DEV(device)] = ata_parm; | 486 atadev->param = ata_parm; |
498 return 0; 499} 500 501static void 502ata_boot_attach(void) 503{ | 487 return 0; 488} 489 490static void 491ata_boot_attach(void) 492{ |
504 struct ata_softc *scp; | 493 struct ata_channel *ch; |
505 int ctlr; 506 | 494 int ctlr; 495 |
496 if (ata_delayed_attach) { 497 config_intrhook_disestablish(ata_delayed_attach); 498 free(ata_delayed_attach, M_TEMP); 499 ata_delayed_attach = NULL; 500 } 501 |
|
507 /* 508 * run through all ata devices and look for real ATA & ATAPI devices 509 * using the hints we found in the early probe, this avoids some of 510 * the delays probing of non-exsistent devices can cause. 511 */ 512 for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) { | 502 /* 503 * run through all ata devices and look for real ATA & ATAPI devices 504 * using the hints we found in the early probe, this avoids some of 505 * the delays probing of non-exsistent devices can cause. 506 */ 507 for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) { |
513 if (!(scp = devclass_get_softc(ata_devclass, ctlr))) | 508 if (!(ch = devclass_get_softc(ata_devclass, ctlr))) |
514 continue; | 509 continue; |
515 if (scp->devices & ATA_ATA_SLAVE) 516 if (ata_getparam(scp, ATA_SLAVE, ATA_C_ATA_IDENTIFY)) 517 scp->devices &= ~ATA_ATA_SLAVE; 518 if (scp->devices & ATA_ATAPI_SLAVE) 519 if (ata_getparam(scp, ATA_SLAVE, ATA_C_ATAPI_IDENTIFY)) 520 scp->devices &= ~ATA_ATAPI_SLAVE; 521 if (scp->devices & ATA_ATA_MASTER) 522 if (ata_getparam(scp, ATA_MASTER, ATA_C_ATA_IDENTIFY)) 523 scp->devices &= ~ATA_ATA_MASTER; 524 if (scp->devices & ATA_ATAPI_MASTER) 525 if (ata_getparam(scp, ATA_MASTER, ATA_C_ATAPI_IDENTIFY)) 526 scp->devices &= ~ATA_ATAPI_MASTER; | 510 if (ch->devices & ATA_ATA_SLAVE) 511 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATA_IDENTIFY)) 512 ch->devices &= ~ATA_ATA_SLAVE; 513 if (ch->devices & ATA_ATAPI_SLAVE) 514 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATAPI_IDENTIFY)) 515 ch->devices &= ~ATA_ATAPI_SLAVE; 516 if (ch->devices & ATA_ATA_MASTER) 517 if (ata_getparam(&ch->device[MASTER], ATA_C_ATA_IDENTIFY)) 518 ch->devices &= ~ATA_ATA_MASTER; 519 if (ch->devices & ATA_ATAPI_MASTER) 520 if (ata_getparam(&ch->device[MASTER], ATA_C_ATAPI_IDENTIFY)) 521 ch->devices &= ~ATA_ATAPI_MASTER; |
527 } 528 529#ifdef DEV_ATADISK 530 /* now we know whats there, do the real attach, first the ATA disks */ 531 for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) { | 522 } 523 524#ifdef DEV_ATADISK 525 /* now we know whats there, do the real attach, first the ATA disks */ 526 for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) { |
532 if (!(scp = devclass_get_softc(ata_devclass, ctlr))) | 527 if (!(ch = devclass_get_softc(ata_devclass, ctlr))) |
533 continue; | 528 continue; |
534 if (scp->devices & ATA_ATA_MASTER) 535 ad_attach(scp, ATA_MASTER); 536 if (scp->devices & ATA_ATA_SLAVE) 537 ad_attach(scp, ATA_SLAVE); | 529 if (ch->devices & ATA_ATA_MASTER) 530 ad_attach(&ch->device[MASTER]); 531 if (ch->devices & ATA_ATA_SLAVE) 532 ad_attach(&ch->device[SLAVE]); |
538 } | 533 } |
534 ar_attach(); |
|
539#endif 540#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) 541 /* then the atapi devices */ 542 for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) { | 535#endif 536#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) 537 /* then the atapi devices */ 538 for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) { |
543 if (!(scp = devclass_get_softc(ata_devclass, ctlr))) | 539 if (!(ch = devclass_get_softc(ata_devclass, ctlr))) |
544 continue; | 540 continue; |
545 if (scp->devices & ATA_ATAPI_MASTER) 546 atapi_attach(scp, ATA_MASTER); 547 if (scp->devices & ATA_ATAPI_SLAVE) 548 atapi_attach(scp, ATA_SLAVE); | 541 if (ch->devices & ATA_ATAPI_MASTER) 542 atapi_attach(&ch->device[MASTER]); 543 if (ch->devices & ATA_ATAPI_SLAVE) 544 atapi_attach(&ch->device[SLAVE]); |
549 } 550#endif | 545 } 546#endif |
551 if (ata_delayed_attach) { 552 config_intrhook_disestablish(ata_delayed_attach); 553 free(ata_delayed_attach, M_TEMP); 554 ata_delayed_attach = NULL; 555 } | |
556} 557 558static void 559ata_intr(void *data) 560{ | 547} 548 549static void 550ata_intr(void *data) 551{ |
561 struct ata_softc *scp = (struct ata_softc *)data; | 552 struct ata_channel *ch = (struct ata_channel *)data; |
562 /* 563 * on PCI systems we might share an interrupt line with another | 553 /* 554 * on PCI systems we might share an interrupt line with another |
564 * device or our twin ATA channel, so call scp->intr_func to figure | 555 * device or our twin ATA channel, so call ch->intr_func to figure |
565 * out if it is really an interrupt we should process here 566 */ | 556 * out if it is really an interrupt we should process here 557 */ |
567 if (scp->intr_func && scp->intr_func(scp)) | 558 if (ch->intr_func && ch->intr_func(ch)) |
568 return; 569 570 /* if drive is busy it didn't interrupt */ | 559 return; 560 561 /* if drive is busy it didn't interrupt */ |
571 if (ATA_INB(scp->r_altio, ATA_ALTSTAT) & ATA_S_BUSY) { | 562 if (ATA_INB(ch->r_altio, ATA_ALTSTAT) & ATA_S_BUSY) { |
572 DELAY(100); | 563 DELAY(100); |
573 if (!(ATA_INB(scp->r_altio, ATA_ALTSTAT) & ATA_S_DRQ)) | 564 if (!(ATA_INB(ch->r_altio, ATA_ALTSTAT) & ATA_S_DRQ)) |
574 return; 575 } 576 577 /* clear interrupt and get status */ | 565 return; 566 } 567 568 /* clear interrupt and get status */ |
578 scp->status = ATA_INB(scp->r_io, ATA_STATUS); | 569 ch->status = ATA_INB(ch->r_io, ATA_STATUS); |
579 | 570 |
580 if (scp->status & ATA_S_ERROR) 581 scp->error = ATA_INB(scp->r_io, ATA_ERROR); | 571 if (ch->status & ATA_S_ERROR) 572 ch->error = ATA_INB(ch->r_io, ATA_ERROR); |
582 583 /* find & call the responsible driver to process this interrupt */ | 573 574 /* find & call the responsible driver to process this interrupt */ |
584 switch (scp->active) { | 575 switch (ch->active) { |
585#ifdef DEV_ATADISK 586 case ATA_ACTIVE_ATA: | 576#ifdef DEV_ATADISK 577 case ATA_ACTIVE_ATA: |
587 if (!scp->running || ad_interrupt(scp->running) == ATA_OP_CONTINUES) | 578 if (!ch->running || ad_interrupt(ch->running) == ATA_OP_CONTINUES) |
588 return; 589 break; 590#endif 591#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) 592 case ATA_ACTIVE_ATAPI: | 579 return; 580 break; 581#endif 582#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) 583 case ATA_ACTIVE_ATAPI: |
593 if (!scp->running || atapi_interrupt(scp->running) == ATA_OP_CONTINUES) | 584 if (!ch->running || atapi_interrupt(ch->running) == ATA_OP_CONTINUES) |
594 return; 595 break; 596#endif 597 case ATA_WAIT_INTR: 598 case ATA_WAIT_INTR | ATA_CONTROL: | 585 return; 586 break; 587#endif 588 case ATA_WAIT_INTR: 589 case ATA_WAIT_INTR | ATA_CONTROL: |
599 wakeup((caddr_t)scp); | 590 wakeup((caddr_t)ch); |
600 break; 601 602 case ATA_WAIT_READY: 603 case ATA_WAIT_READY | ATA_CONTROL: 604 break; 605 606 case ATA_IDLE: | 591 break; 592 593 case ATA_WAIT_READY: 594 case ATA_WAIT_READY | ATA_CONTROL: 595 break; 596 597 case ATA_IDLE: |
607 if (scp->flags & ATA_QUEUED) { 608 scp->active = ATA_ACTIVE; /* XXX */ 609 if (ata_service(scp) == ATA_OP_CONTINUES) | 598 if (ch->flags & ATA_QUEUED) { 599 ch->active = ATA_ACTIVE; /* XXX */ 600 if (ata_service(ch) == ATA_OP_CONTINUES) |
610 return; 611 } 612 /* FALLTHROUGH */ 613 614 default: 615#ifdef ATA_DEBUG 616 { 617 static int intr_count = 0; 618 619 if (intr_count++ < 10) | 601 return; 602 } 603 /* FALLTHROUGH */ 604 605 default: 606#ifdef ATA_DEBUG 607 { 608 static int intr_count = 0; 609 610 if (intr_count++ < 10) |
620 ata_printf(scp, -1, 621 "unwanted interrupt #%d active=0x%x status=0x%02x\n", 622 intr_count, scp->active, scp->status); | 611 ata_printf(ch, -1, "unwanted interrupt #%d active=%02x s=%02x\n", 612 intr_count, ch->active, ch->status); |
623 } 624#endif 625 } | 613 } 614#endif 615 } |
626 scp->active &= ATA_CONTROL; 627 if (scp->active & ATA_CONTROL) | 616 ch->active &= ATA_CONTROL; 617 if (ch->active & ATA_CONTROL) |
628 return; | 618 return; |
629 scp->running = NULL; 630 ata_start(scp); | 619 ch->running = NULL; 620 ata_start(ch); |
631 return; 632} 633 634void | 621 return; 622} 623 624void |
635ata_start(struct ata_softc *scp) | 625ata_start(struct ata_channel *ch) |
636{ 637#ifdef DEV_ATADISK 638 struct ad_request *ad_request; 639#endif 640#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) 641 struct atapi_request *atapi_request; 642#endif 643 | 626{ 627#ifdef DEV_ATADISK 628 struct ad_request *ad_request; 629#endif 630#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) 631 struct atapi_request *atapi_request; 632#endif 633 |
644 if (!atomic_cmpset_int(&scp->active, ATA_IDLE, ATA_ACTIVE)) | 634 if (!atomic_cmpset_int(&ch->active, ATA_IDLE, ATA_ACTIVE)) |
645 return; 646 647#ifdef DEV_ATADISK 648 /* find & call the responsible driver if anything on the ATA queue */ | 635 return; 636 637#ifdef DEV_ATADISK 638 /* find & call the responsible driver if anything on the ATA queue */ |
649 if (TAILQ_EMPTY(&scp->ata_queue)) { 650 if (scp->devices & (ATA_ATA_MASTER) && scp->dev_softc[MASTER]) 651 ad_start((struct ad_softc *)scp->dev_softc[MASTER]); 652 if (scp->devices & (ATA_ATA_SLAVE) && scp->dev_softc[SLAVE]) 653 ad_start((struct ad_softc *)scp->dev_softc[SLAVE]); | 639 if (TAILQ_EMPTY(&ch->ata_queue)) { 640 if (ch->devices & (ATA_ATA_MASTER) && ch->device[MASTER].driver) 641 ad_start(&ch->device[MASTER]); 642 if (ch->devices & (ATA_ATA_SLAVE) && ch->device[SLAVE].driver) 643 ad_start(&ch->device[SLAVE]); |
654 } | 644 } |
655 if ((ad_request = TAILQ_FIRST(&scp->ata_queue))) { 656 TAILQ_REMOVE(&scp->ata_queue, ad_request, chain); 657 scp->active = ATA_ACTIVE_ATA; 658 scp->running = ad_request; | 645 if ((ad_request = TAILQ_FIRST(&ch->ata_queue))) { 646 TAILQ_REMOVE(&ch->ata_queue, ad_request, chain); 647 ch->active = ATA_ACTIVE_ATA; 648 ch->running = ad_request; |
659 if (ad_transfer(ad_request) == ATA_OP_CONTINUES) 660 return; 661 } 662 663#endif 664#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) 665 /* find & call the responsible driver if anything on the ATAPI queue */ | 649 if (ad_transfer(ad_request) == ATA_OP_CONTINUES) 650 return; 651 } 652 653#endif 654#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) 655 /* find & call the responsible driver if anything on the ATAPI queue */ |
666 if (TAILQ_EMPTY(&scp->atapi_queue)) { 667 if (scp->devices & (ATA_ATAPI_MASTER) && scp->dev_softc[MASTER]) 668 atapi_start((struct atapi_softc *)scp->dev_softc[MASTER]); 669 if (scp->devices & (ATA_ATAPI_SLAVE) && scp->dev_softc[SLAVE]) 670 atapi_start((struct atapi_softc *)scp->dev_softc[SLAVE]); | 656 if (TAILQ_EMPTY(&ch->atapi_queue)) { 657 if (ch->devices & (ATA_ATAPI_MASTER) && ch->device[MASTER].driver) 658 atapi_start(&ch->device[MASTER]); 659 if (ch->devices & (ATA_ATAPI_SLAVE) && ch->device[SLAVE].driver) 660 atapi_start(&ch->device[SLAVE]); |
671 } | 661 } |
672 if ((atapi_request = TAILQ_FIRST(&scp->atapi_queue))) { 673 TAILQ_REMOVE(&scp->atapi_queue, atapi_request, chain); 674 scp->active = ATA_ACTIVE_ATAPI; 675 scp->running = atapi_request; | 662 if ((atapi_request = TAILQ_FIRST(&ch->atapi_queue))) { 663 TAILQ_REMOVE(&ch->atapi_queue, atapi_request, chain); 664 ch->active = ATA_ACTIVE_ATAPI; 665 ch->running = atapi_request; |
676 if (atapi_transfer(atapi_request) == ATA_OP_CONTINUES) 677 return; 678 } 679#endif | 666 if (atapi_transfer(atapi_request) == ATA_OP_CONTINUES) 667 return; 668 } 669#endif |
680 scp->active = ATA_IDLE; | 670 ch->active = ATA_IDLE; |
681} 682 683void | 671} 672 673void |
684ata_reset(struct ata_softc *scp) | 674ata_reset(struct ata_channel *ch) |
685{ 686 u_int8_t lsb, msb, ostat0, ostat1; 687 u_int8_t stat0 = 0, stat1 = 0; 688 int mask = 0, timeout; 689 690 /* do we have any signs of ATA/ATAPI HW being present ? */ | 675{ 676 u_int8_t lsb, msb, ostat0, ostat1; 677 u_int8_t stat0 = 0, stat1 = 0; 678 int mask = 0, timeout; 679 680 /* do we have any signs of ATA/ATAPI HW being present ? */ |
691 ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER); | 681 ATA_OUTB(ch->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER); |
692 DELAY(10); | 682 DELAY(10); |
693 ostat0 = ATA_INB(scp->r_io, ATA_STATUS); | 683 ostat0 = ATA_INB(ch->r_io, ATA_STATUS); |
694 if ((ostat0 & 0xf8) != 0xf8 && ostat0 != 0xa5) { 695 stat0 = ATA_S_BUSY; 696 mask |= 0x01; 697 } | 684 if ((ostat0 & 0xf8) != 0xf8 && ostat0 != 0xa5) { 685 stat0 = ATA_S_BUSY; 686 mask |= 0x01; 687 } |
698 ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE); | 688 ATA_OUTB(ch->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE); |
699 DELAY(10); | 689 DELAY(10); |
700 ostat1 = ATA_INB(scp->r_io, ATA_STATUS); | 690 ostat1 = ATA_INB(ch->r_io, ATA_STATUS); |
701 if ((ostat1 & 0xf8) != 0xf8 && ostat1 != 0xa5) { 702 stat1 = ATA_S_BUSY; 703 mask |= 0x02; 704 } 705 | 691 if ((ostat1 & 0xf8) != 0xf8 && ostat1 != 0xa5) { 692 stat1 = ATA_S_BUSY; 693 mask |= 0x02; 694 } 695 |
706 scp->devices = 0; | 696 ch->devices = 0; |
707 if (!mask) 708 return; 709 710 /* in some setups we dont want to test for a slave */ | 697 if (!mask) 698 return; 699 700 /* in some setups we dont want to test for a slave */ |
711 if (scp->flags & ATA_NO_SLAVE) { | 701 if (ch->flags & ATA_NO_SLAVE) { |
712 stat1 = 0x0; 713 mask &= ~0x02; 714 } 715 716 if (bootverbose) | 702 stat1 = 0x0; 703 mask &= ~0x02; 704 } 705 706 if (bootverbose) |
717 ata_printf(scp, -1, "mask=%02x ostat0=%02x ostat2=%02x\n", | 707 ata_printf(ch, -1, "mask=%02x ostat0=%02x ostat2=%02x\n", |
718 mask, ostat0, ostat1); 719 720 /* reset channel */ | 708 mask, ostat0, ostat1); 709 710 /* reset channel */ |
721 ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER); | 711 ATA_OUTB(ch->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER); |
722 DELAY(10); | 712 DELAY(10); |
723 ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_RESET); | 713 ATA_OUTB(ch->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_RESET); |
724 DELAY(10000); | 714 DELAY(10000); |
725 ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS); | 715 ATA_OUTB(ch->r_altio, ATA_ALTSTAT, ATA_A_IDS); |
726 DELAY(100000); | 716 DELAY(100000); |
727 ATA_INB(scp->r_io, ATA_ERROR); | 717 ATA_INB(ch->r_io, ATA_ERROR); |
728 729 /* wait for BUSY to go inactive */ 730 for (timeout = 0; timeout < 310000; timeout++) { 731 if (stat0 & ATA_S_BUSY) { | 718 719 /* wait for BUSY to go inactive */ 720 for (timeout = 0; timeout < 310000; timeout++) { 721 if (stat0 & ATA_S_BUSY) { |
732 ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER); 733 DELAY(10); 734 stat0 = ATA_INB(scp->r_io, ATA_STATUS); 735 if (!(stat0 & ATA_S_BUSY)) { 736 /* check for ATAPI signature while its still there */ 737 lsb = ATA_INB(scp->r_io, ATA_CYL_LSB); 738 msb = ATA_INB(scp->r_io, ATA_CYL_MSB); | 722 ATA_OUTB(ch->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER); 723 DELAY(10); 724 stat0 = ATA_INB(ch->r_io, ATA_STATUS); 725 if (!(stat0 & ATA_S_BUSY)) { 726 /* check for ATAPI signature while its still there */ 727 lsb = ATA_INB(ch->r_io, ATA_CYL_LSB); 728 msb = ATA_INB(ch->r_io, ATA_CYL_MSB); |
739 if (bootverbose) | 729 if (bootverbose) |
740 ata_printf(scp, ATA_MASTER, 741 "ATAPI probe %02x %02x\n", lsb, msb); | 730 ata_printf(ch, ATA_MASTER, "ATAPI %02x %02x\n", lsb, msb); |
742 if (lsb == ATAPI_MAGIC_LSB && msb == ATAPI_MAGIC_MSB) | 731 if (lsb == ATAPI_MAGIC_LSB && msb == ATAPI_MAGIC_MSB) |
743 scp->devices |= ATA_ATAPI_MASTER; 744 } 745 } 746 if (stat1 & ATA_S_BUSY) { 747 ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE); 748 DELAY(10); 749 stat1 = ATA_INB(scp->r_io, ATA_STATUS); 750 if (!(stat1 & ATA_S_BUSY)) { 751 /* check for ATAPI signature while its still there */ 752 lsb = ATA_INB(scp->r_io, ATA_CYL_LSB); 753 msb = ATA_INB(scp->r_io, ATA_CYL_MSB); | 732 ch->devices |= ATA_ATAPI_MASTER; 733 } 734 } 735 if (stat1 & ATA_S_BUSY) { 736 ATA_OUTB(ch->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE); 737 DELAY(10); 738 stat1 = ATA_INB(ch->r_io, ATA_STATUS); 739 if (!(stat1 & ATA_S_BUSY)) { 740 /* check for ATAPI signature while its still there */ 741 lsb = ATA_INB(ch->r_io, ATA_CYL_LSB); 742 msb = ATA_INB(ch->r_io, ATA_CYL_MSB); |
754 if (bootverbose) | 743 if (bootverbose) |
755 ata_printf(scp, ATA_SLAVE, 756 "ATAPI probe %02x %02x\n", lsb, msb); | 744 ata_printf(ch, ATA_SLAVE, "ATAPI %02x %02x\n", lsb, msb); |
757 if (lsb == ATAPI_MAGIC_LSB && msb == ATAPI_MAGIC_MSB) | 745 if (lsb == ATAPI_MAGIC_LSB && msb == ATAPI_MAGIC_MSB) |
758 scp->devices |= ATA_ATAPI_SLAVE; 759 } 760 } | 746 ch->devices |= ATA_ATAPI_SLAVE; 747 } 748 } |
761 if (mask == 0x01) /* wait for master only */ 762 if (!(stat0 & ATA_S_BUSY)) 763 break; 764 if (mask == 0x02) /* wait for slave only */ 765 if (!(stat1 & ATA_S_BUSY)) 766 break; 767 if (mask == 0x03) /* wait for both master & slave */ 768 if (!(stat0 & ATA_S_BUSY) && !(stat1 & ATA_S_BUSY)) 769 break; 770 DELAY(100); 771 } 772 DELAY(10); | 749 if (mask == 0x01) /* wait for master only */ 750 if (!(stat0 & ATA_S_BUSY)) 751 break; 752 if (mask == 0x02) /* wait for slave only */ 753 if (!(stat1 & ATA_S_BUSY)) 754 break; 755 if (mask == 0x03) /* wait for both master & slave */ 756 if (!(stat0 & ATA_S_BUSY) && !(stat1 & ATA_S_BUSY)) 757 break; 758 DELAY(100); 759 } 760 DELAY(10); |
773 ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_4BIT); | 761 ATA_OUTB(ch->r_altio, ATA_ALTSTAT, ATA_A_4BIT); |
774 775 if (stat0 & ATA_S_BUSY) 776 mask &= ~0x01; 777 if (stat1 & ATA_S_BUSY) 778 mask &= ~0x02; 779 if (bootverbose) | 762 763 if (stat0 & ATA_S_BUSY) 764 mask &= ~0x01; 765 if (stat1 & ATA_S_BUSY) 766 mask &= ~0x02; 767 if (bootverbose) |
780 ata_printf(scp, -1, "mask=%02x stat0=%02x stat1=%02x\n", | 768 ata_printf(ch, -1, "mask=%02x stat0=%02x stat1=%02x\n", |
781 mask, stat0, stat1); 782 if (!mask) 783 return; 784 | 769 mask, stat0, stat1); 770 if (!mask) 771 return; 772 |
785 if (mask & 0x01 && ostat0 != 0x00 && !(scp->devices & ATA_ATAPI_MASTER)) { 786 ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER); 787 DELAY(10); 788 ATA_OUTB(scp->r_io, ATA_ERROR, 0x58); 789 ATA_OUTB(scp->r_io, ATA_CYL_LSB, 0xa5); 790 lsb = ATA_INB(scp->r_io, ATA_ERROR); 791 msb = ATA_INB(scp->r_io, ATA_CYL_LSB); | 773 if (mask & 0x01 && ostat0 != 0x00 && !(ch->devices & ATA_ATAPI_MASTER)) { 774 ATA_OUTB(ch->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER); 775 DELAY(10); 776 ATA_OUTB(ch->r_io, ATA_ERROR, 0x58); 777 ATA_OUTB(ch->r_io, ATA_CYL_LSB, 0xa5); 778 lsb = ATA_INB(ch->r_io, ATA_ERROR); 779 msb = ATA_INB(ch->r_io, ATA_CYL_LSB); |
792 if (bootverbose) | 780 if (bootverbose) |
793 ata_printf(scp, ATA_MASTER, "ATA probe %02x %02x\n", lsb, msb); 794 if (lsb != 0x58 && msb == 0xa5) 795 scp->devices |= ATA_ATA_MASTER; | 781 ata_printf(ch, ATA_MASTER, "ATA %02x %02x\n", lsb, msb); 782 if (lsb != 0x58 && msb == 0xa5) 783 ch->devices |= ATA_ATA_MASTER; |
796 } | 784 } |
797 if (mask & 0x02 && ostat1 != 0x00 && !(scp->devices & ATA_ATAPI_SLAVE)) { 798 ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE); 799 DELAY(10); 800 ATA_OUTB(scp->r_io, ATA_ERROR, 0x58); 801 ATA_OUTB(scp->r_io, ATA_CYL_LSB, 0xa5); 802 lsb = ATA_INB(scp->r_io, ATA_ERROR); 803 msb = ATA_INB(scp->r_io, ATA_CYL_LSB); | 785 if (mask & 0x02 && ostat1 != 0x00 && !(ch->devices & ATA_ATAPI_SLAVE)) { 786 ATA_OUTB(ch->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE); 787 DELAY(10); 788 ATA_OUTB(ch->r_io, ATA_ERROR, 0x58); 789 ATA_OUTB(ch->r_io, ATA_CYL_LSB, 0xa5); 790 lsb = ATA_INB(ch->r_io, ATA_ERROR); 791 msb = ATA_INB(ch->r_io, ATA_CYL_LSB); |
804 if (bootverbose) | 792 if (bootverbose) |
805 ata_printf(scp, ATA_SLAVE, "ATA probe %02x %02x\n", lsb, msb); 806 if (lsb != 0x58 && msb == 0xa5) 807 scp->devices |= ATA_ATA_SLAVE; | 793 ata_printf(ch, ATA_SLAVE, "ATA %02x %02x\n", lsb, msb); 794 if (lsb != 0x58 && msb == 0xa5) 795 ch->devices |= ATA_ATA_SLAVE; |
808 } 809 if (bootverbose) | 796 } 797 if (bootverbose) |
810 ata_printf(scp, -1, "devices=%02x\n", scp->devices); | 798 ata_printf(ch, -1, "devices=%02x\n", ch->devices); |
811} 812 813int | 799} 800 801int |
814ata_reinit(struct ata_softc *scp) | 802ata_reinit(struct ata_channel *ch) |
815{ 816 int devices, misdev, newdev; 817 | 803{ 804 int devices, misdev, newdev; 805 |
818 if (!scp->r_io || !scp->r_altio || !scp->r_irq) | 806 if (!ch->r_io || !ch->r_altio || !ch->r_irq) |
819 return ENXIO; | 807 return ENXIO; |
820 scp->active = ATA_CONTROL; 821 scp->running = NULL; 822 devices = scp->devices; 823 ata_printf(scp, -1, "resetting devices .. "); 824 ata_reset(scp); | 808 ch->active = ATA_CONTROL; 809 ch->running = NULL; 810 devices = ch->devices; 811 ata_printf(ch, -1, "resetting devices .. "); 812 ata_reset(ch); |
825 | 813 |
826 if ((misdev = devices & ~scp->devices)) { | 814 if ((misdev = devices & ~ch->devices)) { |
827 if (misdev) 828 printf("\n"); 829#ifdef DEV_ATADISK | 815 if (misdev) 816 printf("\n"); 817#ifdef DEV_ATADISK |
830 if (misdev & ATA_ATA_MASTER && scp->dev_softc[MASTER]) 831 ad_detach(scp->dev_softc[MASTER], 0); 832 if (misdev & ATA_ATA_SLAVE && scp->dev_softc[SLAVE]) 833 ad_detach(scp->dev_softc[SLAVE], 0); | 818 if (misdev & ATA_ATA_MASTER && ch->device[MASTER].driver) 819 ad_detach(&ch->device[MASTER], 0); 820 if (misdev & ATA_ATA_SLAVE && ch->device[SLAVE].driver) 821 ad_detach(&ch->device[SLAVE], 0); |
834#endif 835#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) | 822#endif 823#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) |
836 if (misdev & ATA_ATAPI_MASTER && scp->dev_softc[MASTER]) 837 atapi_detach(scp->dev_softc[MASTER]); 838 if (misdev & ATA_ATAPI_SLAVE && scp->dev_softc[SLAVE]) 839 atapi_detach(scp->dev_softc[SLAVE]); | 824 if (misdev & ATA_ATAPI_MASTER && ch->device[MASTER].driver) 825 atapi_detach(&ch->device[MASTER]); 826 if (misdev & ATA_ATAPI_SLAVE && ch->device[SLAVE].driver) 827 atapi_detach(&ch->device[SLAVE]); |
840#endif 841 if (misdev & ATA_ATA_MASTER || misdev & ATA_ATAPI_MASTER) { | 828#endif 829 if (misdev & ATA_ATA_MASTER || misdev & ATA_ATAPI_MASTER) { |
842 free(scp->dev_param[MASTER], M_ATA); 843 scp->dev_param[MASTER] = NULL; | 830 free(ch->device[MASTER].param, M_ATA); 831 ch->device[MASTER].param = NULL; |
844 } 845 if (misdev & ATA_ATA_SLAVE || misdev & ATA_ATAPI_SLAVE) { | 832 } 833 if (misdev & ATA_ATA_SLAVE || misdev & ATA_ATAPI_SLAVE) { |
846 free(scp->dev_param[SLAVE], M_ATA); 847 scp->dev_param[SLAVE] = NULL; | 834 free(ch->device[SLAVE].param, M_ATA); 835 ch->device[SLAVE].param = NULL; |
848 } 849 } | 836 } 837 } |
850 if ((newdev = ~devices & scp->devices)) { | 838 if ((newdev = ~devices & ch->devices)) { |
851 if (newdev & ATA_ATA_MASTER) | 839 if (newdev & ATA_ATA_MASTER) |
852 if (ata_getparam(scp, ATA_MASTER, ATA_C_ATA_IDENTIFY)) | 840 if (ata_getparam(&ch->device[MASTER], ATA_C_ATA_IDENTIFY)) |
853 newdev &= ~ATA_ATA_MASTER; 854 if (newdev & ATA_ATA_SLAVE) | 841 newdev &= ~ATA_ATA_MASTER; 842 if (newdev & ATA_ATA_SLAVE) |
855 if (ata_getparam(scp, ATA_SLAVE, ATA_C_ATA_IDENTIFY)) | 843 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATA_IDENTIFY)) |
856 newdev &= ~ATA_ATA_SLAVE; 857 if (newdev & ATA_ATAPI_MASTER) | 844 newdev &= ~ATA_ATA_SLAVE; 845 if (newdev & ATA_ATAPI_MASTER) |
858 if (ata_getparam(scp, ATA_MASTER, ATA_C_ATAPI_IDENTIFY)) | 846 if (ata_getparam(&ch->device[MASTER], ATA_C_ATAPI_IDENTIFY)) |
859 newdev &= ~ATA_ATAPI_MASTER; 860 if (newdev & ATA_ATAPI_SLAVE) | 847 newdev &= ~ATA_ATAPI_MASTER; 848 if (newdev & ATA_ATAPI_SLAVE) |
861 if (ata_getparam(scp, ATA_SLAVE, ATA_C_ATAPI_IDENTIFY)) | 849 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATAPI_IDENTIFY)) |
862 newdev &= ~ATA_ATAPI_SLAVE; 863 } 864 if (!misdev && newdev) 865 printf("\n"); 866#ifdef DEV_ATADISK | 850 newdev &= ~ATA_ATAPI_SLAVE; 851 } 852 if (!misdev && newdev) 853 printf("\n"); 854#ifdef DEV_ATADISK |
867 if (newdev & ATA_ATA_MASTER && !scp->dev_softc[MASTER]) 868 ad_attach(scp, ATA_MASTER); 869 else if (scp->devices & ATA_ATA_MASTER && scp->dev_softc[MASTER]) 870 ad_reinit((struct ad_softc *)scp->dev_softc[MASTER]); 871 if (newdev & ATA_ATA_SLAVE && !scp->dev_softc[SLAVE]) 872 ad_attach(scp, ATA_SLAVE); 873 else if (scp->devices & (ATA_ATA_SLAVE) && scp->dev_softc[SLAVE]) 874 ad_reinit((struct ad_softc *)scp->dev_softc[SLAVE]); | 855 if (newdev & ATA_ATA_MASTER && !ch->device[MASTER].driver) 856 ad_attach(&ch->device[MASTER]); 857 else if (ch->devices & ATA_ATA_MASTER && ch->device[MASTER].driver) 858 ad_reinit((struct ad_softc *)ch->device[MASTER].driver); 859 if (newdev & ATA_ATA_SLAVE && !ch->device[SLAVE].driver) 860 ad_attach(&ch->device[SLAVE]); 861 else if (ch->devices & (ATA_ATA_SLAVE) && ch->device[SLAVE].driver) 862 ad_reinit((struct ad_softc *)ch->device[SLAVE].driver); |
875#endif 876#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) | 863#endif 864#if defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || defined(DEV_ATAPIST) |
877 if (newdev & ATA_ATAPI_MASTER && !scp->dev_softc[MASTER]) 878 atapi_attach(scp, ATA_MASTER); 879 else if (scp->devices & (ATA_ATAPI_MASTER) && scp->dev_softc[MASTER]) 880 atapi_reinit((struct atapi_softc *)scp->dev_softc[MASTER]); 881 if (newdev & ATA_ATAPI_SLAVE && !scp->dev_softc[SLAVE]) 882 atapi_attach(scp, ATA_SLAVE); 883 else if (scp->devices & (ATA_ATAPI_SLAVE) && scp->dev_softc[SLAVE]) 884 atapi_reinit((struct atapi_softc *)scp->dev_softc[SLAVE]); | 865 if (newdev & ATA_ATAPI_MASTER && !ch->device[MASTER].driver) 866 atapi_attach(&ch->device[MASTER]); 867 else if (ch->devices & (ATA_ATAPI_MASTER) && ch->device[MASTER].driver) 868 atapi_reinit(ch->device[MASTER].driver); 869 if (newdev & ATA_ATAPI_SLAVE && !ch->device[SLAVE].driver) 870 atapi_attach(&ch->device[SLAVE]); 871 else if (ch->devices & (ATA_ATAPI_SLAVE) && ch->device[SLAVE].driver) 872 atapi_reinit(ch->device[SLAVE].driver); |
885#endif 886 printf("done\n"); | 873#endif 874 printf("done\n"); |
887 scp->active = ATA_IDLE; 888 ata_start(scp); | 875 ch->active = ATA_IDLE; 876 ata_start(ch); |
889 return 0; 890} 891 892static int | 877 return 0; 878} 879 880static int |
893ata_service(struct ata_softc *scp) | 881ata_service(struct ata_channel *ch) |
894{ 895 /* do we have a SERVICE request from the drive ? */ | 882{ 883 /* do we have a SERVICE request from the drive ? */ |
896 if ((scp->status & (ATA_S_SERVICE|ATA_S_ERROR|ATA_S_DRQ)) == ATA_S_SERVICE){ 897 ATA_OUTB(scp->r_bmio, ATA_BMSTAT_PORT, 898 ata_dmastatus(scp) | ATA_BMSTAT_INTERRUPT); | 884 if ((ch->status & (ATA_S_SERVICE|ATA_S_ERROR|ATA_S_DRQ)) == ATA_S_SERVICE) { 885 ATA_OUTB(ch->r_bmio, ATA_BMSTAT_PORT, 886 ata_dmastatus(ch) | ATA_BMSTAT_INTERRUPT); |
899#ifdef DEV_ATADISK | 887#ifdef DEV_ATADISK |
900 if ((ATA_INB(scp->r_io, ATA_DRIVE) & ATA_SLAVE) == ATA_MASTER) { 901 if ((scp->devices & ATA_ATA_MASTER) && scp->dev_softc[MASTER]) 902 return ad_service((struct ad_softc *)scp->dev_softc[MASTER], 0); | 888 if ((ATA_INB(ch->r_io, ATA_DRIVE) & ATA_SLAVE) == ATA_MASTER) { 889 if ((ch->devices & ATA_ATA_MASTER) && ch->device[MASTER].driver) 890 return ad_service((struct ad_softc *) 891 ch->device[MASTER].driver, 0); |
903 } 904 else { | 892 } 893 else { |
905 if ((scp->devices & ATA_ATA_SLAVE) && scp->dev_softc[SLAVE]) 906 return ad_service((struct ad_softc *)scp->dev_softc[SLAVE], 0); | 894 if ((ch->devices & ATA_ATA_SLAVE) && ch->device[SLAVE].driver) 895 return ad_service((struct ad_softc *) 896 ch->device[SLAVE].driver, 0); |
907 } 908#endif 909 } 910 return ATA_OP_FINISHED; 911} 912 913int | 897 } 898#endif 899 } 900 return ATA_OP_FINISHED; 901} 902 903int |
914ata_wait(struct ata_softc *scp, int device, u_int8_t mask) | 904ata_wait(struct ata_device *atadev, u_int8_t mask) |
915{ 916 int timeout = 0; 917 918 DELAY(1); | 905{ 906 int timeout = 0; 907 908 DELAY(1); |
919 while (timeout < 5000000) { /* timeout 5 secs */ 920 scp->status = ATA_INB(scp->r_io, ATA_STATUS); | 909 while (timeout < 5000000) { /* timeout 5 secs */ 910 atadev->channel->status = ATA_INB(atadev->channel->r_io, ATA_STATUS); |
921 922 /* if drive fails status, reselect the drive just to be sure */ | 911 912 /* if drive fails status, reselect the drive just to be sure */ |
923 if (scp->status == 0xff) { 924 ata_printf(scp, device, "no status, reselecting device\n"); 925 ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | device); | 913 if (atadev->channel->status == 0xff) { 914 ata_prtdev(atadev, "no status, reselecting device\n"); 915 ATA_OUTB(atadev->channel->r_io, ATA_DRIVE, ATA_D_IBM|atadev->unit); |
926 DELAY(10); | 916 DELAY(10); |
927 scp->status = ATA_INB(scp->r_io, ATA_STATUS); 928 if (scp->status == 0xff) | 917 atadev->channel->status = ATA_INB(atadev->channel->r_io,ATA_STATUS); 918 if (atadev->channel->status == 0xff) |
929 return -1; 930 } 931 932 /* are we done ? */ | 919 return -1; 920 } 921 922 /* are we done ? */ |
933 if (!(scp->status & ATA_S_BUSY)) | 923 if (!(atadev->channel->status & ATA_S_BUSY)) |
934 break; 935 936 if (timeout > 1000) { 937 timeout += 1000; 938 DELAY(1000); 939 } 940 else { 941 timeout += 10; 942 DELAY(10); 943 } 944 } | 924 break; 925 926 if (timeout > 1000) { 927 timeout += 1000; 928 DELAY(1000); 929 } 930 else { 931 timeout += 10; 932 DELAY(10); 933 } 934 } |
945 if (scp->status & ATA_S_ERROR) 946 scp->error = ATA_INB(scp->r_io, ATA_ERROR); | 935 if (atadev->channel->status & ATA_S_ERROR) 936 atadev->channel->error = ATA_INB(atadev->channel->r_io, ATA_ERROR); |
947 if (timeout >= 5000000) 948 return -1; 949 if (!mask) | 937 if (timeout >= 5000000) 938 return -1; 939 if (!mask) |
950 return (scp->status & ATA_S_ERROR); | 940 return (atadev->channel->status & ATA_S_ERROR); |
951 952 /* Wait 50 msec for bits wanted. */ 953 timeout = 5000; 954 while (timeout--) { | 941 942 /* Wait 50 msec for bits wanted. */ 943 timeout = 5000; 944 while (timeout--) { |
955 scp->status = ATA_INB(scp->r_io, ATA_STATUS); 956 if ((scp->status & mask) == mask) { 957 if (scp->status & ATA_S_ERROR) 958 scp->error = ATA_INB(scp->r_io, ATA_ERROR); 959 return (scp->status & ATA_S_ERROR); | 945 atadev->channel->status = ATA_INB(atadev->channel->r_io, ATA_STATUS); 946 if ((atadev->channel->status & mask) == mask) { 947 if (atadev->channel->status & ATA_S_ERROR) 948 atadev->channel->error=ATA_INB(atadev->channel->r_io,ATA_ERROR); 949 return (atadev->channel->status & ATA_S_ERROR); |
960 } 961 DELAY (10); 962 } 963 return -1; 964} 965 966int | 950 } 951 DELAY (10); 952 } 953 return -1; 954} 955 956int |
967ata_command(struct ata_softc *scp, int device, u_int8_t command, | 957ata_command(struct ata_device *atadev, u_int8_t command, |
968 u_int64_t lba, u_int16_t count, u_int8_t feature, int flags) 969{ 970 int error = 0; 971#ifdef ATA_DEBUG | 958 u_int64_t lba, u_int16_t count, u_int8_t feature, int flags) 959{ 960 int error = 0; 961#ifdef ATA_DEBUG |
972 ata_printf(scp, device, "ata_command: addr=%04lx, cmd=%02x, " | 962 ata_prtdev(atadev, "ata_command: addr=%04lx, cmd=%02x, " |
973 "lba=%lld, count=%d, feature=%d, flags=%02x\n", | 963 "lba=%lld, count=%d, feature=%d, flags=%02x\n", |
974 rman_get_start(scp->r_io), command, lba, count, feature, flags); | 964 rman_get_start(atadev->channel->r_io), 965 command, lba, count, feature, flags); |
975#endif 976 977 /* select device */ | 966#endif 967 968 /* select device */ |
978 ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | device); | 969 ATA_OUTB(atadev->channel->r_io, ATA_DRIVE, ATA_D_IBM | atadev->unit); |
979 980 /* disable interrupt from device */ | 970 971 /* disable interrupt from device */ |
981 if (scp->flags & ATA_QUEUED) 982 ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_4BIT); | 972 if (atadev->channel->flags & ATA_QUEUED) 973 ATA_OUTB(atadev->channel->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_4BIT); |
983 984 /* ready to issue command ? */ | 974 975 /* ready to issue command ? */ |
985 if (ata_wait(scp, device, 0) < 0) { 986 ata_printf(scp, device, 987 "timeout waiting to give command=%02x s=%02x e=%02x\n", 988 command, scp->status, scp->error); | 976 if (ata_wait(atadev, 0) < 0) { 977 ata_prtdev(atadev, "timeout sending command=%02x s=%02x e=%02x\n", 978 command, atadev->channel->status, atadev->channel->error); |
989 return -1; 990 } 991 992 /* only use 48bit addressing if needed because of the overhead */ | 979 return -1; 980 } 981 982 /* only use 48bit addressing if needed because of the overhead */ |
993 if ((lba > 268435455 || count > 256) && scp->dev_param[ATA_DEV(device)] && 994 scp->dev_param[ATA_DEV(device)]->support.address48) { 995 ATA_OUTB(scp->r_io, ATA_FEATURE, (feature>>8) & 0xff); 996 ATA_OUTB(scp->r_io, ATA_FEATURE, feature); 997 ATA_OUTB(scp->r_io, ATA_COUNT, (count>>8) & 0xff); 998 ATA_OUTB(scp->r_io, ATA_COUNT, count & 0xff); 999 ATA_OUTB(scp->r_io, ATA_SECTOR, (lba>>24) & 0xff); 1000 ATA_OUTB(scp->r_io, ATA_SECTOR, lba & 0xff); 1001 ATA_OUTB(scp->r_io, ATA_CYL_LSB, (lba<<32) & 0xff); 1002 ATA_OUTB(scp->r_io, ATA_CYL_LSB, (lba>>8) & 0xff); 1003 ATA_OUTB(scp->r_io, ATA_CYL_MSB, (lba>>40) & 0xff); 1004 ATA_OUTB(scp->r_io, ATA_CYL_MSB, (lba>>16) & 0xff); 1005 ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_LBA | device); | 983 if ((lba > 268435455 || count > 256) && atadev->param && 984 atadev->param->support.address48) { 985 ATA_OUTB(atadev->channel->r_io, ATA_FEATURE, (feature>>8) & 0xff); 986 ATA_OUTB(atadev->channel->r_io, ATA_FEATURE, feature); 987 ATA_OUTB(atadev->channel->r_io, ATA_COUNT, (count>>8) & 0xff); 988 ATA_OUTB(atadev->channel->r_io, ATA_COUNT, count & 0xff); 989 ATA_OUTB(atadev->channel->r_io, ATA_SECTOR, (lba>>24) & 0xff); 990 ATA_OUTB(atadev->channel->r_io, ATA_SECTOR, lba & 0xff); 991 ATA_OUTB(atadev->channel->r_io, ATA_CYL_LSB, (lba<<32) & 0xff); 992 ATA_OUTB(atadev->channel->r_io, ATA_CYL_LSB, (lba>>8) & 0xff); 993 ATA_OUTB(atadev->channel->r_io, ATA_CYL_MSB, (lba>>40) & 0xff); 994 ATA_OUTB(atadev->channel->r_io, ATA_CYL_MSB, (lba>>16) & 0xff); 995 ATA_OUTB(atadev->channel->r_io, ATA_DRIVE, ATA_D_LBA | atadev->unit); |
1006 1007 /* translate command into 48bit version */ 1008 switch (command) { 1009 case ATA_C_READ: 1010 command = ATA_C_READ48; break; 1011 case ATA_C_READ_MUL: 1012 command = ATA_C_READ_MUL48; break; 1013 case ATA_C_READ_DMA: --- 6 unchanged lines hidden (view full) --- 1020 command = ATA_C_WRITE_MUL48; break; 1021 case ATA_C_WRITE_DMA: 1022 command = ATA_C_WRITE_DMA48; break; 1023 case ATA_C_WRITE_DMA_QUEUED: 1024 command = ATA_C_WRITE_DMA_QUEUED48; break; 1025 case ATA_C_FLUSHCACHE: 1026 command = ATA_C_FLUSHCACHE48; break; 1027 default: | 996 997 /* translate command into 48bit version */ 998 switch (command) { 999 case ATA_C_READ: 1000 command = ATA_C_READ48; break; 1001 case ATA_C_READ_MUL: 1002 command = ATA_C_READ_MUL48; break; 1003 case ATA_C_READ_DMA: --- 6 unchanged lines hidden (view full) --- 1010 command = ATA_C_WRITE_MUL48; break; 1011 case ATA_C_WRITE_DMA: 1012 command = ATA_C_WRITE_DMA48; break; 1013 case ATA_C_WRITE_DMA_QUEUED: 1014 command = ATA_C_WRITE_DMA_QUEUED48; break; 1015 case ATA_C_FLUSHCACHE: 1016 command = ATA_C_FLUSHCACHE48; break; 1017 default: |
1028 ata_printf(scp, device, "can't translate cmd to 48bit version\n"); | 1018 ata_prtdev(atadev, "can't translate cmd to 48bit version\n"); |
1029 return -1; 1030 } 1031 } 1032 else { | 1019 return -1; 1020 } 1021 } 1022 else { |
1033 ATA_OUTB(scp->r_io, ATA_FEATURE, feature); 1034 ATA_OUTB(scp->r_io, ATA_COUNT, count); 1035 ATA_OUTB(scp->r_io, ATA_SECTOR, lba & 0xff); 1036 ATA_OUTB(scp->r_io, ATA_CYL_LSB, (lba>>8) & 0xff); 1037 ATA_OUTB(scp->r_io, ATA_CYL_MSB, (lba>>16) & 0xff); 1038 if (flags & ATA_USE_CHS) 1039 ATA_OUTB(scp->r_io, ATA_DRIVE, 1040 ATA_D_IBM | device | ((lba>>24) & 0xf)); | 1023 ATA_OUTB(atadev->channel->r_io, ATA_FEATURE, feature); 1024 ATA_OUTB(atadev->channel->r_io, ATA_COUNT, count); 1025 ATA_OUTB(atadev->channel->r_io, ATA_SECTOR, lba & 0xff); 1026 ATA_OUTB(atadev->channel->r_io, ATA_CYL_LSB, (lba>>8) & 0xff); 1027 ATA_OUTB(atadev->channel->r_io, ATA_CYL_MSB, (lba>>16) & 0xff); 1028 if (atadev->flags & ATA_D_USE_CHS) 1029 ATA_OUTB(atadev->channel->r_io, ATA_DRIVE, 1030 ATA_D_IBM | atadev->unit | ((lba>>24) & 0xf)); |
1041 else | 1031 else |
1042 ATA_OUTB(scp->r_io, ATA_DRIVE, 1043 ATA_D_IBM | ATA_D_LBA | device | ((lba>>24) & 0xf)); | 1032 ATA_OUTB(atadev->channel->r_io, ATA_DRIVE, 1033 ATA_D_IBM | ATA_D_LBA | atadev->unit | ((lba>>24) &0xf)); |
1044 } 1045 1046 switch (flags & ATA_WAIT_MASK) { 1047 case ATA_IMMEDIATE: | 1034 } 1035 1036 switch (flags & ATA_WAIT_MASK) { 1037 case ATA_IMMEDIATE: |
1048 ATA_OUTB(scp->r_io, ATA_CMD, command); | 1038 ATA_OUTB(atadev->channel->r_io, ATA_CMD, command); |
1049 1050 /* enable interrupt */ | 1039 1040 /* enable interrupt */ |
1051 if (scp->flags & ATA_QUEUED) 1052 ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_4BIT); | 1041 if (atadev->channel->flags & ATA_QUEUED) 1042 ATA_OUTB(atadev->channel->r_altio, ATA_ALTSTAT, ATA_A_4BIT); |
1053 break; 1054 1055 case ATA_WAIT_INTR: | 1043 break; 1044 1045 case ATA_WAIT_INTR: |
1056 scp->active |= ATA_WAIT_INTR; 1057 ATA_OUTB(scp->r_io, ATA_CMD, command); | 1046 atadev->channel->active |= ATA_WAIT_INTR; 1047 ATA_OUTB(atadev->channel->r_io, ATA_CMD, command); |
1058 1059 /* enable interrupt */ | 1048 1049 /* enable interrupt */ |
1060 if (scp->flags & ATA_QUEUED) 1061 ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_4BIT); | 1050 if (atadev->channel->flags & ATA_QUEUED) 1051 ATA_OUTB(atadev->channel->r_altio, ATA_ALTSTAT, ATA_A_4BIT); |
1062 | 1052 |
1063 if (tsleep((caddr_t)scp, PRIBIO, "atacmd", 10 * hz) != 0) { 1064 ata_printf(scp, device, "ata_command: timeout waiting for intr\n"); 1065 scp->active &= ~ATA_WAIT_INTR; | 1053 if (tsleep((caddr_t)atadev->channel, PRIBIO, "atacmd", 10 * hz) != 0) { 1054 ata_prtdev(atadev, "timeout waiting for interrupt\n"); 1055 atadev->channel->active &= ~ATA_WAIT_INTR; |
1066 error = -1; 1067 } 1068 break; 1069 1070 case ATA_WAIT_READY: | 1056 error = -1; 1057 } 1058 break; 1059 1060 case ATA_WAIT_READY: |
1071 scp->active |= ATA_WAIT_READY; 1072 ATA_OUTB(scp->r_io, ATA_CMD, command); 1073 if (ata_wait(scp, device, ATA_S_READY) < 0) { 1074 ata_printf(scp, device, 1075 "timeout waiting for command=%02x s=%02x e=%02x\n", 1076 command, scp->status, scp->error); | 1061 atadev->channel->active |= ATA_WAIT_READY; 1062 ATA_OUTB(atadev->channel->r_io, ATA_CMD, command); 1063 if (ata_wait(atadev, ATA_S_READY) < 0) { 1064 ata_prtdev(atadev, "timeout waiting for cmd=%02x s=%02x e=%02x\n", 1065 command, atadev->channel->status,atadev->channel->error); |
1077 error = -1; 1078 } | 1066 error = -1; 1067 } |
1079 scp->active &= ~ATA_WAIT_READY; | 1068 atadev->channel->active &= ~ATA_WAIT_READY; |
1080 break; 1081 } 1082 return error; 1083} 1084 1085void | 1069 break; 1070 } 1071 return error; 1072} 1073 1074void |
1086ata_set_name(struct ata_softc *scp, int device, char *name, int lun) | 1075ata_drawerleds(struct ata_device *atadev, u_int8_t color) |
1087{ | 1076{ |
1088 scp->dev_name[ATA_DEV(device)] = malloc(strlen(name) + 4, M_ATA, M_NOWAIT); 1089 if (scp->dev_name[ATA_DEV(device)]) 1090 sprintf(scp->dev_name[ATA_DEV(device)], "%s%d", name, lun); | 1077 u_int8_t count, drive; 1078 int s = splbio(); 1079 int state; 1080 1081 if ((state = atadev->channel->active) != ATA_CONTROL) { 1082 while (!atomic_cmpset_int(&atadev->channel->active, 1083 ATA_IDLE, ATA_CONTROL)) 1084 tsleep((caddr_t)&s, PRIBIO, "ataled", hz/4); 1085 } 1086 1087 /* magic sequence to set the LED color on the Promise SuperSwap */ 1088 ATA_INB(atadev->channel->r_io, ATA_DRIVE); 1089 DELAY(1); 1090 ATA_OUTB(atadev->channel->r_io, ATA_DRIVE, ATA_D_IBM | atadev->unit); 1091 DELAY(1); 1092 ATA_OUTB(atadev->channel->r_io, ATA_DRIVE, ATA_D_IBM | atadev->unit); 1093 DELAY(1); 1094 ATA_OUTB(atadev->channel->r_io, ATA_DRIVE, ATA_D_IBM | atadev->unit); 1095 DELAY(1); 1096 count = ATA_INB(atadev->channel->r_io, ATA_COUNT); 1097 DELAY(1); 1098 drive = ATA_INB(atadev->channel->r_io, ATA_DRIVE); 1099 DELAY(1); 1100 ATA_OUTB(atadev->channel->r_io, ATA_COUNT, color); 1101 DELAY(1); 1102 ATA_OUTB(atadev->channel->r_io, ATA_DRIVE, ATA_D_IBM | atadev->unit); 1103 DELAY(1); 1104 1105 atadev->channel->active = state; 1106 splx(s); |
1091} 1092 | 1107} 1108 |
1109static void 1110ata_change_mode(struct ata_device *atadev, int mode) 1111{ 1112 int umode, wmode, pmode; 1113 int s = splbio(); 1114 1115 while (!atomic_cmpset_int(&atadev->channel->active, ATA_IDLE, ATA_ACTIVE)) 1116 tsleep((caddr_t)&s, PRIBIO, "atachm", hz/4); 1117 1118 umode = ata_umode(atadev->param); 1119 wmode = ata_wmode(atadev->param); 1120 pmode = ata_pmode(atadev->param); 1121 1122 switch (mode & ATA_DMA_MASK) { 1123 case ATA_UDMA: 1124 if ((mode & ATA_MODE_MASK) < umode) 1125 umode = mode & ATA_MODE_MASK; 1126 break; 1127 case ATA_WDMA: 1128 if ((mode & ATA_MODE_MASK) < wmode) 1129 wmode = mode & ATA_MODE_MASK; 1130 umode = -1; 1131 break; 1132 default: 1133 if (((mode & ATA_MODE_MASK) - ATA_PIO0) < pmode) 1134 pmode = (mode & ATA_MODE_MASK) - ATA_PIO0; 1135 umode = -1; 1136 wmode = -1; 1137 } 1138 ata_dmainit(atadev->channel, atadev->unit, pmode, wmode, umode); 1139 1140 atadev->channel->active = ATA_IDLE; 1141 ata_start(atadev->channel); 1142 splx(s); 1143} 1144 1145int 1146ata_printf(struct ata_channel *ch, int device, const char * fmt, ...) 1147{ 1148 va_list ap; 1149 int ret; 1150 1151 if (device == -1) 1152 ret = printf("ata%d: ", device_get_unit(ch->dev)); 1153 else { 1154 if (ch->device[ATA_DEV(device)].name) 1155 ret = printf("%s: ", ch->device[ATA_DEV(device)].name); 1156 else 1157 ret = printf("ata%d-%s: ", device_get_unit(ch->dev), 1158 (device == ATA_MASTER) ? "master" : "slave"); 1159 } 1160 va_start(ap, fmt); 1161 ret += vprintf(fmt, ap); 1162 va_end(ap); 1163 return ret; 1164} 1165 1166int 1167ata_prtdev(struct ata_device *atadev, const char * fmt, ...) 1168{ 1169 va_list ap; 1170 int ret; 1171 1172 if (atadev->name) 1173 ret = printf("%s: ", atadev->name); 1174 else 1175 ret = printf("ata%d-%s: ", device_get_unit(atadev->channel->dev), 1176 (atadev->unit == ATA_MASTER) ? "master" : "slave"); 1177 va_start(ap, fmt); 1178 ret += vprintf(fmt, ap); 1179 va_end(ap); 1180 return ret; 1181} 1182 |
|
1093void | 1183void |
1094ata_free_name(struct ata_softc *scp, int device) | 1184ata_set_name(struct ata_device *atadev, char *name, int lun) |
1095{ | 1185{ |
1096 if (scp->dev_name[ATA_DEV(device)]) 1097 free(scp->dev_name[ATA_DEV(device)], M_ATA); 1098 scp->dev_name[ATA_DEV(device)] = NULL; | 1186 atadev->name = malloc(strlen(name) + 4, M_ATA, M_NOWAIT); 1187 if (atadev->name) 1188 sprintf(atadev->name, "%s%d", name, lun); |
1099} | 1189} |
1190 1191void 1192ata_free_name(struct ata_device *atadev) 1193{ 1194 if (atadev->name) 1195 free(atadev->name, M_ATA); 1196 atadev->name = NULL; 1197} |
|
1100 1101int 1102ata_get_lun(u_int32_t *map) 1103{ 1104 int lun = ffs(~*map) - 1; 1105 1106 *map |= (1 << lun); 1107 return lun; --- 6 unchanged lines hidden (view full) --- 1114} 1115 1116void 1117ata_free_lun(u_int32_t *map, int lun) 1118{ 1119 *map &= ~(1 << lun); 1120} 1121 | 1198 1199int 1200ata_get_lun(u_int32_t *map) 1201{ 1202 int lun = ffs(~*map) - 1; 1203 1204 *map |= (1 << lun); 1205 return lun; --- 6 unchanged lines hidden (view full) --- 1212} 1213 1214void 1215ata_free_lun(u_int32_t *map, int lun) 1216{ 1217 *map &= ~(1 << lun); 1218} 1219 |
1122int 1123ata_printf(struct ata_softc *scp, int device, const char * fmt, ...) 1124{ 1125 va_list ap; 1126 int ret; 1127 1128 if (device == -1) 1129 ret = printf("ata%d: ", device_get_unit(scp->dev)); 1130 else { 1131 if (scp->dev_name[ATA_DEV(device)]) 1132 ret = printf("%s: ", scp->dev_name[ATA_DEV(device)]); 1133 else 1134 ret = printf("ata%d-%s: ", device_get_unit(scp->dev), 1135 (device == ATA_MASTER) ? "master" : "slave"); 1136 } 1137 va_start(ap, fmt); 1138 ret += vprintf(fmt, ap); 1139 va_end(ap); 1140 return ret; 1141} 1142 | |
1143char * 1144ata_mode2str(int mode) 1145{ 1146 switch (mode) { 1147 case ATA_PIO: return "BIOSPIO"; 1148 case ATA_PIO0: return "PIO0"; 1149 case ATA_PIO1: return "PIO1"; 1150 case ATA_PIO2: return "PIO2"; 1151 case ATA_PIO3: return "PIO3"; 1152 case ATA_PIO4: return "PIO4"; | 1220char * 1221ata_mode2str(int mode) 1222{ 1223 switch (mode) { 1224 case ATA_PIO: return "BIOSPIO"; 1225 case ATA_PIO0: return "PIO0"; 1226 case ATA_PIO1: return "PIO1"; 1227 case ATA_PIO2: return "PIO2"; 1228 case ATA_PIO3: return "PIO3"; 1229 case ATA_PIO4: return "PIO4"; |
1230 case ATA_DMA: return "BIOSDMA"; |
|
1153 case ATA_WDMA2: return "WDMA2"; 1154 case ATA_UDMA2: return "UDMA33"; 1155 case ATA_UDMA4: return "UDMA66"; 1156 case ATA_UDMA5: return "UDMA100"; 1157 case ATA_UDMA6: return "UDMA133"; | 1231 case ATA_WDMA2: return "WDMA2"; 1232 case ATA_UDMA2: return "UDMA33"; 1233 case ATA_UDMA4: return "UDMA66"; 1234 case ATA_UDMA5: return "UDMA100"; 1235 case ATA_UDMA6: return "UDMA133"; |
1158 case ATA_DMA: return "BIOSDMA"; | |
1159 default: return "???"; 1160 } 1161} 1162 1163int 1164ata_pmode(struct ata_params *ap) 1165{ 1166 if (ap->atavalid & ATA_FLAG_64_70) { --- 85 unchanged lines hidden (view full) --- 1252 } 1253 dst[j++] = src[i]; 1254 } 1255 if (j < len) 1256 dst[j] = 0x00; 1257} 1258 1259static void | 1236 default: return "???"; 1237 } 1238} 1239 1240int 1241ata_pmode(struct ata_params *ap) 1242{ 1243 if (ap->atavalid & ATA_FLAG_64_70) { --- 85 unchanged lines hidden (view full) --- 1329 } 1330 dst[j++] = src[i]; 1331 } 1332 if (j < len) 1333 dst[j] = 0x00; 1334} 1335 1336static void |
1260ata_change_mode(struct ata_softc *scp, int device, int mode) 1261{ 1262 int umode, wmode, pmode; 1263 int s = splbio(); 1264 1265 while (!atomic_cmpset_int(&scp->active, ATA_IDLE, ATA_ACTIVE)) 1266 tsleep((caddr_t)&s, PRIBIO, "atachm", hz/4); 1267 1268 umode = ata_umode(ATA_PARAM(scp, device)); 1269 wmode = ata_wmode(ATA_PARAM(scp, device)); 1270 pmode = ata_pmode(ATA_PARAM(scp, device)); 1271 1272 switch (mode & ATA_DMA_MASK) { 1273 case ATA_UDMA: 1274 if ((mode & ATA_MODE_MASK) < umode) 1275 umode = mode & ATA_MODE_MASK; 1276 break; 1277 case ATA_WDMA: 1278 if ((mode & ATA_MODE_MASK) < wmode) 1279 wmode = mode & ATA_MODE_MASK; 1280 umode = -1; 1281 break; 1282 default: 1283 if (((mode & ATA_MODE_MASK) - ATA_PIO0) < pmode) 1284 pmode = (mode & ATA_MODE_MASK) - ATA_PIO0; 1285 umode = -1; 1286 wmode = -1; 1287 } 1288 ata_dmainit(scp, device, pmode, wmode, umode); 1289 1290 scp->active = ATA_IDLE; 1291 ata_start(scp); 1292 splx(s); 1293} 1294 1295static void | |
1296ata_init(void) 1297{ 1298 /* register controlling device */ 1299 make_dev(&ata_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600, "ata"); 1300 1301 /* register boot attach to be run when interrupts are enabled */ 1302 if (!(ata_delayed_attach = (struct intr_config_hook *) 1303 malloc(sizeof(struct intr_config_hook), --- 12 unchanged lines hidden --- | 1337ata_init(void) 1338{ 1339 /* register controlling device */ 1340 make_dev(&ata_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600, "ata"); 1341 1342 /* register boot attach to be run when interrupts are enabled */ 1343 if (!(ata_delayed_attach = (struct intr_config_hook *) 1344 malloc(sizeof(struct intr_config_hook), --- 12 unchanged lines hidden --- |