// SPDX-License-Identifier: GPL-2.0-or-later /* * sata_svw.c - ServerWorks / Apple K2 SATA * * Maintained by: Benjamin Herrenschmidt <benh@kernel.crashing.org> and * Jeff Garzik <jgarzik@pobox.com> * Please ALWAYS copy linux-ide@vger.kernel.org * on emails. * * Copyright 2003 Benjamin Herrenschmidt <benh@kernel.crashing.org> * * Bits from Jeff Garzik, Copyright RedHat, Inc. * * This driver probably works with non-Apple versions of the * Broadcom chipset... * * libata documentation is available via 'make {ps|pdf}docs', * as Documentation/driver-api/libata.rst * * Hardware documentation available under NDA.
*/
if (qc->ap->flags & K2_FLAG_NO_ATAPI_DMA) return -1; /* ATAPI DMA not supported */ else { switch (cmnd) { case READ_10: case READ_12: case READ_16: case WRITE_10: case WRITE_12: case WRITE_16: return 0;
/** * k2_bmdma_setup_mmio - Set up PCI IDE BMDMA transaction (MMIO) * @qc: Info associated with this ATA transaction. * * LOCKING: * spin_lock_irqsave(host lock)
*/
/* load PRD table addr. */
mb(); /* make sure PRD table writes are visible to controller */
writel(ap->bmdma_prd_dma, mmio + ATA_DMA_TABLE_OFS);
/* specify data direction, triple-check start bit is clear */
dmactl = readb(mmio + ATA_DMA_CMD);
dmactl &= ~(ATA_DMA_WR | ATA_DMA_START); if (!rw)
dmactl |= ATA_DMA_WR;
writeb(dmactl, mmio + ATA_DMA_CMD);
/* issue r/w command if this is not a ATA DMA command*/ if (qc->tf.protocol != ATA_PROT_DMA)
ap->ops->sff_exec_command(ap, &qc->tf);
}
/** * k2_bmdma_start_mmio - Start a PCI IDE BMDMA transaction (MMIO) * @qc: Info associated with this ATA transaction. * * LOCKING: * spin_lock_irqsave(host lock)
*/
/* start host DMA transaction */
dmactl = readb(mmio + ATA_DMA_CMD);
writeb(dmactl | ATA_DMA_START, mmio + ATA_DMA_CMD); /* This works around possible data corruption.
On certain SATA controllers that can be seen when the r/w command is given to the controller before the host DMA is started.
On a Read command, the controller would initiate the command to the drive even before it sees the DMA start. When there are very fast drives connected to the controller, or when the data request hits in the drive cache, there is the possibility that the drive returns a part or all of the requested data to the controller before the DMA start is issued. In this case, the controller would become confused as to what to do with the data. In the worst case when all the data is returned back to the controller, the controller could hang. In other cases it could return partial data returning in data corruption. This problem has been seen in PPC systems and can also appear on an system with very fast disks, where the SATA controller is sitting behind a number of bridges, and hence there is significant latency between the r/w
command and the start command. */ /* issue r/w command if the access is to ATA */ if (qc->tf.protocol == ATA_PROT_DMA)
ap->ops->sff_exec_command(ap, &qc->tf);
}
host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); if (!host) return -ENOMEM;
bar_pos = 5; if (ppi[0]->flags & K2_FLAG_BAR_POS_3)
bar_pos = 3; /* * If this driver happens to only be useful on Apple's K2, then * we should check that here as it has a normal Serverworks ID
*/
rc = pcim_enable_device(pdev); if (rc) return rc;
/* * Check if we have resources mapped at all (second function may * have been disabled by firmware)
*/ if (pci_resource_len(pdev, bar_pos) == 0) { /* In IDE mode we need to pin the device to ensure that pcim_release does not clear the busmaster bit in config space, clearing causes busmaster DMA to fail on
ports 3 & 4 */
pcim_pin_device(pdev); return -ENODEV;
}
/* Request and iomap PCI regions */
rc = pcim_iomap_regions(pdev, 1 << bar_pos, DRV_NAME); if (rc == -EBUSY)
pcim_pin_device(pdev); if (rc) return rc;
host->iomap = pcim_iomap_table(pdev);
mmio_base = host->iomap[bar_pos];
/* different controllers have different number of ports - currently 4 or 8 */ /* All ports are on the same function. Multi-function device is no
* longer available. This should not be seen in any system. */ for (i = 0; i < host->n_ports; i++) { struct ata_port *ap = host->ports[i]; unsignedint offset = i * K2_SATA_PORT_OFFSET;
rc = dma_set_mask_and_coherent(&pdev->dev, ATA_DMA_MASK); if (rc) return rc;
/* Clear a magic bit in SCR1 according to Darwin, those help * some funky seagate drives (though so far, those were already * set by the firmware on the machines I had access to)
*/
writel(readl(mmio_base + K2_SATA_SICR1_OFFSET) & ~0x00040000,
mmio_base + K2_SATA_SICR1_OFFSET);
/* Clear SATA error & interrupts we don't use */
writel(0xffffffff, mmio_base + K2_SATA_SCR_ERROR_OFFSET);
writel(0x0, mmio_base + K2_SATA_SIM_OFFSET);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.