1/*- |
2 * Copyright (c) 1998 - 2004 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. --- 11 unchanged lines hidden (view full) --- 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/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/dev/ata/ata-lowlevel.c 124403 2004-01-11 22:08:34Z sos $"); |
31 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> 37#include <sys/conf.h> 38#include <sys/bus.h> |
39#include <sys/sema.h> |
40#include <sys/taskqueue.h> 41#include <machine/bus.h> 42#include <sys/rman.h> 43#include <dev/ata/ata-all.h> 44 45/* prototypes */ 46static int ata_transaction(struct ata_request *); 47static void ata_interrupt(void *); --- 16 unchanged lines hidden (view full) --- 64 ch->hw.transaction = ata_transaction; 65 ch->hw.interrupt = ata_interrupt; 66} 67 68/* must be called with ATA channel locked */ 69static int 70ata_transaction(struct ata_request *request) 71{ |
72 /* safety check, device might have been detached FIXME SOS */ 73 if (!request->device->param) { 74 request->result = ENXIO; 75 return ATA_OP_FINISHED; 76 } 77 |
78 /* record the request as running */ 79 request->device->channel->running = request; 80 |
81 ATA_DEBUG_RQ(request, "transaction"); 82 |
83 /* disable ATAPI DMA writes if HW doesn't support it */ 84 if ((request->device->channel->flags & ATA_ATAPI_DMA_RO) && 85 ((request->flags & (ATA_R_ATAPI | ATA_R_DMA | ATA_R_WRITE)) == 86 (ATA_R_ATAPI | ATA_R_DMA | ATA_R_WRITE))) 87 request->flags &= ~ATA_R_DMA; 88 89 switch (request->flags & (ATA_R_ATAPI | ATA_R_DMA)) { 90 91 /* ATA PIO data transfer and control commands */ 92 default: 93 { |
94 /* record command direction here as our request might be gone later */ |
95 int write = (request->flags & ATA_R_WRITE); 96 97 /* issue command */ 98 if (ata_command(request->device, request->u.ata.command, 99 request->u.ata.lba, request->u.ata.count, 100 request->u.ata.feature)) { 101 ata_prtdev(request->device, "error issueing PIO command\n"); 102 request->result = EIO; --- 6 unchanged lines hidden (view full) --- 109 (ATA_S_READY | ATA_S_DSC | ATA_S_DRQ)) < 0) { 110 ata_prtdev(request->device,"timeout waiting for write DRQ"); 111 request->result = EIO; 112 break; 113 } 114 ata_pio_write(request, request->transfersize); 115 } 116 } |
117 |
118 /* return and wait for interrupt */ 119 return ATA_OP_CONTINUES; 120 121 /* ATA DMA data transfer commands */ 122 case ATA_R_DMA: 123 /* check sanity, setup SG list and DMA engine */ 124 if (request->device->channel->dma->load(request->device, 125 request->data, --- 14 unchanged lines hidden (view full) --- 140 } 141 142 /* start DMA engine */ 143 if (request->device->channel->dma->start(request->device->channel)) { 144 ata_prtdev(request->device, "error starting DMA\n"); 145 request->result = EIO; 146 break; 147 } |
148 |
149 /* return and wait for interrupt */ 150 return ATA_OP_CONTINUES; 151 152 /* ATAPI PIO commands */ 153 case ATA_R_ATAPI: 154 /* is this just a POLL DSC command ? */ 155 if (request->u.atapi.ccb[0] == ATAPI_POLL_DSC) { 156 ATA_IDX_OUTB(request->device->channel, ATA_DRIVE, --- 142 unchanged lines hidden (view full) --- 299 } 300 else { 301 if (bootverbose) 302 ata_printf(ch, -1, "spurious interrupt - channel busy\n"); 303 } 304 return; 305 } 306 |
307 ATA_DEBUG_RQ(request, "interrupt"); 308 |
309 /* ignore interrupt if device is busy */ |
310 if (!(request->flags & ATA_R_TIMEOUT) && 311 ATA_IDX_INB(ch, ATA_ALTSTAT) & ATA_S_BUSY) { |
312 DELAY(100); 313 if (!(ATA_IDX_INB(ch, ATA_ALTSTAT) & ATA_S_DRQ)) 314 return; 315 } 316 |
317 ATA_DEBUG_RQ(request, "interrupt accepted"); 318 |
319 /* clear interrupt and get status */ 320 request->status = ATA_IDX_INB(ch, ATA_STATUS); 321 |
322 request->flags |= ATA_R_INTR_SEEN; 323 |
324 switch (request->flags & (ATA_R_ATAPI | ATA_R_DMA | ATA_R_CONTROL)) { 325 326 /* ATA PIO data transfer and control commands */ 327 default: 328 329 /* on control commands read back registers to the request struct */ 330 if (request->flags & ATA_R_CONTROL) { 331 request->u.ata.count = ATA_IDX_INB(ch, ATA_COUNT); --- 172 unchanged lines hidden (view full) --- 504 505 /* release SG list etc */ 506 ch->dma->unload(ch); 507 508 /* done with HW */ 509 break; 510 } 511 |
512 /* if we timed out, we hold on to the channel, ata_reinit() will unlock */ 513 if (request->flags & ATA_R_TIMEOUT) { 514 ata_finish(request); 515 return; 516 } 517 518 /* schedule completition for this request */ |
519 ata_finish(request); 520 521 /* unlock the ATA channel for new work */ 522 ch->running = NULL; 523 ATA_UNLOCK_CH(ch); 524 ch->locking(ch, ATA_LF_UNLOCK); 525} 526 --- 21 unchanged lines hidden (view full) --- 548 /* in some setups we dont want to test for a slave */ 549 if (!(ch->flags & ATA_NO_SLAVE)) { 550 if ((ostat1 & 0xf8) != 0xf8 && ostat1 != 0xa5) { 551 stat1 = ATA_S_BUSY; 552 mask |= 0x02; 553 } 554 } 555 |
556 /* if nothing showed up there is no need to get any further */ |
557 /* SOS is that too strong?, we just might loose devices here XXX */ 558 ch->devices = 0; 559 if (!mask) 560 return; 561 562 if (bootverbose) 563 ata_printf(ch, -1, "reset tp1 mask=%02x ostat0=%02x ostat1=%02x\n", 564 mask, ostat0, ostat1); 565 |
566 /* reset host end of channel (if supported) */ 567 if (ch->reset) 568 ch->reset(ch); 569 570 /* reset (both) devices on this channel */ |
571 ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | ATA_MASTER); 572 DELAY(10); 573 ATA_IDX_OUTB(ch, ATA_ALTSTAT, ATA_A_IDS | ATA_A_RESET); 574 DELAY(10000); 575 ATA_IDX_OUTB(ch, ATA_ALTSTAT, ATA_A_IDS); 576 DELAY(100000); 577 ATA_IDX_INB(ch, ATA_ERROR); 578 --- 61 unchanged lines hidden (view full) --- 640 if (stat0 == 0xff && timeout > 20) 641 mask &= ~0x01; 642 if (stat1 == 0xff && timeout > 20) 643 mask &= ~0x02; 644 } 645 DELAY(100000); 646 } 647 |
648 /* enable interrupt */ 649 DELAY(10); 650 ATA_IDX_OUTB(ch, ATA_ALTSTAT, ATA_A_4BIT); 651 |
652 if (stat0 & ATA_S_BUSY) 653 mask &= ~0x01; 654 if (stat1 & ATA_S_BUSY) 655 mask &= ~0x02; 656 657 if (bootverbose) 658 ata_printf(ch, -1, 659 "reset tp2 mask=%02x stat0=%02x stat1=%02x devices=0x%b\n", 660 mask, stat0, stat1, ch->devices, 661 "\20\4ATAPI_SLAVE\3ATAPI_MASTER\2ATA_SLAVE\1ATA_MASTER"); |
662} 663 664static int 665ata_wait(struct ata_device *atadev, u_int8_t mask) 666{ 667 u_int8_t status; 668 int timeout = 0; 669 --- 58 unchanged lines hidden (view full) --- 728 ATA_IDX_OUTB(atadev->channel, ATA_DRIVE, ATA_D_IBM | atadev->unit); 729 730 /* ready to issue command ? */ 731 if (ata_wait(atadev, 0) < 0) { 732 ata_prtdev(atadev, "timeout sending command=%02x\n", command); 733 return -1; 734 } 735 |
736 /* only use 48bit addressing if needed (avoid bugs and overhead) */ 737 if ((lba > 268435455 || count > 256) && atadev->param && 738 atadev->param->support.command2 & ATA_SUPPORT_ADDRESS48) { 739 740 /* translate command into 48bit version */ 741 switch (command) { 742 case ATA_READ: 743 command = ATA_READ48; break; --- 103 unchanged lines hidden --- |