/* * Driver for the Octeon bootbus compact flash. * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 2005 - 2012 Cavium Inc. * Copyright (C) 2008 Wind River Systems
*/
/* * The Octeon bootbus compact flash interface is connected in at least * 3 different configurations on various evaluation boards: * * -- 8 bits no irq, no DMA * -- 16 bits no irq, no DMA * -- 16 bits True IDE mode with DMA, but no irq. * * In the last case the DMA engine can generate an interrupt when the * transfer is complete. For the first two cases only PIO is supported. *
*/
staticint enable_dma;
module_param(enable_dma, int, 0444);
MODULE_PARM_DESC(enable_dma, "Enable use of DMA on interfaces that support it (0=no dma [default], 1=use dma)");
/* * Convert nanosecond based time to setting used in the * boot bus timing register, based on timing multiple
*/ staticunsignedint ns_to_tim_reg(unsignedint tim_mult, unsignedint nsecs)
{ /* * Compute # of eclock periods to get desired duration in * nanoseconds.
*/ return DIV_ROUND_UP(nsecs * (octeon_get_io_clock_rate() / 1000000),
1000 * tim_mult);
}
switch (multiplier) { case 8:
tim_mult = 3; break; case 4:
tim_mult = 0; break; case 2:
tim_mult = 2; break; default:
tim_mult = 1; break;
}
reg_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
reg_cfg.s.dmack = 0; /* Don't assert DMACK on access */
reg_cfg.s.tim_mult = tim_mult; /* Timing mutiplier */
reg_cfg.s.rd_dly = 0; /* Sample on falling edge of BOOT_OE */
reg_cfg.s.sam = 0; /* Don't combine write and output enable */
reg_cfg.s.we_ext = 0; /* No write enable extension */
reg_cfg.s.oe_ext = 0; /* No read enable extension */
reg_cfg.s.en = 1; /* Enable this region */
reg_cfg.s.orbit = 0; /* Don't combine with previous region */
reg_cfg.s.ale = 0; /* Don't do address multiplexing */
cvmx_write_csr(CVMX_MIO_BOOT_REG_CFGX(cs), reg_cfg.u64);
}
/* * Called after libata determines the needed PIO mode. This * function programs the Octeon bootbus regions to support the * timing requirements of the PIO mode. * * @ap: ATA port information * @dev: ATA device
*/ staticvoid octeon_cf_set_piomode(struct ata_port *ap, struct ata_device *dev)
{ struct octeon_cf_port *cf_port = ap->private_data; union cvmx_mio_boot_reg_timx reg_tim; int T; struct ata_timing timing;
unsignedint div; int use_iordy; int trh; int pause; /* These names are timing parameters from the ATA spec */ int t2;
/* * A divisor value of four will overflow the timing fields at * clock rates greater than 800MHz
*/ if (octeon_get_io_clock_rate() <= 800000000)
div = 4; else
div = 8;
T = (int)((1000000000000LL * div) / octeon_get_io_clock_rate());
pause = (int)timing.cycle - (int)timing.active -
(int)timing.setup - trh; if (pause < 0)
pause = 0; if (pause)
pause--;
octeon_cf_set_boot_reg_cfg(cf_port->cs0, div); if (cf_port->is_true_ide) /* True IDE mode, program both chip selects. */
octeon_cf_set_boot_reg_cfg(cf_port->cs1, div);
use_iordy = ata_pio_need_iordy(dev);
reg_tim.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_TIMX(cf_port->cs0)); /* Disable page mode */
reg_tim.s.pagem = 0; /* Enable dynamic timing */
reg_tim.s.waitm = use_iordy; /* Pages are disabled */
reg_tim.s.pages = 0; /* We don't use multiplexed address mode */
reg_tim.s.ale = 0; /* Not used */
reg_tim.s.page = 0; /* Time after IORDY to continue to assert the data */
reg_tim.s.wait = 0; /* Time to wait to complete the cycle. */
reg_tim.s.pause = pause; /* How long to hold after a write to de-assert CE. */
reg_tim.s.wr_hld = trh; /* How long to wait after a read to de-assert CE. */
reg_tim.s.rd_hld = trh; /* How long write enable is asserted */
reg_tim.s.we = t2; /* How long read enable is asserted */
reg_tim.s.oe = t2; /* Time after CE that read/write starts */
reg_tim.s.ce = ns_to_tim_reg(div, 5); /* Time before CE that address is valid */
reg_tim.s.adr = 0;
/* Program the bootbus region timing for the data port chip select. */
cvmx_write_csr(CVMX_MIO_BOOT_REG_TIMX(cf_port->cs0), reg_tim.u64); if (cf_port->is_true_ide) /* True IDE mode, program both chip selects. */
cvmx_write_csr(CVMX_MIO_BOOT_REG_TIMX(cf_port->cs1),
reg_tim.u64);
}
/* * This is tI, C.F. spec. says 0, but Sony CF card requires * more, we use 20 nS.
*/
dma_tim.s.dmack_s = ns_to_tim_reg(tim_mult, 20);
dma_tim.s.dmack_h = ns_to_tim_reg(tim_mult, dma_ackh);
/* * Read the taskfile for 16bit non-True IDE only.
*/ staticvoid octeon_cf_tf_read16(struct ata_port *ap, struct ata_taskfile *tf)
{
u16 blob; /* The base of the registers is at ioaddr.data_addr. */ void __iomem *base = ap->ioaddr.data_addr;
/* determine by signature whether we have ATA or ATAPI devices */
classes[0] = ata_sff_dev_classify(&link->device[0], 1, &err); return 0;
}
/* * Load the taskfile for 16bit non-True IDE only. The device_addr is * not loaded, we do this as part of octeon_cf_exec_command16.
*/ staticvoid octeon_cf_tf_load16(struct ata_port *ap, conststruct ata_taskfile *tf)
{ unsignedint is_addr = tf->flags & ATA_TFLAG_ISADDR; /* The base of the registers is at ioaddr.data_addr. */ void __iomem *base = ap->ioaddr.data_addr;
if (tf->ctl != ap->last_ctl) {
iowrite8(tf->ctl, ap->ioaddr.ctl_addr);
ap->last_ctl = tf->ctl;
ata_wait_idle(ap);
} if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
__raw_writew(tf->hob_feature << 8, base + 0xc);
__raw_writew(tf->hob_nsect | tf->hob_lbal << 8, base + 2);
__raw_writew(tf->hob_lbam | tf->hob_lbah << 8, base + 4);
} if (is_addr) {
__raw_writew(tf->feature << 8, base + 0xc);
__raw_writew(tf->nsect | tf->lbal << 8, base + 2);
__raw_writew(tf->lbam | tf->lbah << 8, base + 4);
}
ata_wait_idle(ap);
}
staticvoid octeon_cf_dev_select(struct ata_port *ap, unsignedint device)
{ /* There is only one device, do nothing. */ return;
}
/* * Issue ATA command to host controller. The device_addr is also sent * as it must be written in a combined write with the command.
*/ staticvoid octeon_cf_exec_command16(struct ata_port *ap, conststruct ata_taskfile *tf)
{ /* The base of the registers is at ioaddr.data_addr. */ void __iomem *base = ap->ioaddr.data_addr;
u16 blob = 0;
if (tf->flags & ATA_TFLAG_DEVICE)
blob = tf->device;
blob |= (tf->command << 8);
__raw_writew(blob, base + 6);
/* * Start a DMA transfer that was already setup * * @qc: Information about the DMA
*/ staticvoid octeon_cf_dma_start(struct ata_queued_cmd *qc)
{ struct octeon_cf_port *cf_port = qc->ap->private_data; union cvmx_mio_boot_dma_cfgx mio_boot_dma_cfg; union cvmx_mio_boot_dma_intx mio_boot_dma_int; struct scatterlist *sg;
/* Get the scatter list entry we need to DMA into */
sg = qc->cursg;
BUG_ON(!sg);
/* Enable the interrupt. */
cvmx_write_csr(cf_port->dma_base + DMA_INT_EN, mio_boot_dma_int.u64);
/* Set the direction of the DMA */
mio_boot_dma_cfg.u64 = 0; #ifdef __LITTLE_ENDIAN
mio_boot_dma_cfg.s.endian = 1; #endif
mio_boot_dma_cfg.s.en = 1;
mio_boot_dma_cfg.s.rw = ((qc->tf.flags & ATA_TFLAG_WRITE) != 0);
/* * Don't stop the DMA if the device deasserts DMARQ. Many * compact flashes deassert DMARQ for a short time between * sectors. Instead of stopping and restarting the DMA, we'll * let the hardware do it. If the DMA is really stopped early * due to an error condition, a later timeout will force us to * stop.
*/
mio_boot_dma_cfg.s.clr = 0;
/* Size is specified in 16bit words and minus one notation */
mio_boot_dma_cfg.s.size = sg_dma_len(sg) / 2 - 1;
/* We need to swap the high and low bytes of every 16 bits */
mio_boot_dma_cfg.s.swap8 = 1;
dma_cfg.u64 = cvmx_read_csr(cf_port->dma_base + DMA_CFG); if (dma_cfg.s.size != 0xfffff) { /* Error, the transfer was not complete. */
qc->err_mask |= AC_ERR_HOST_BUS;
ap->hsm_task_state = HSM_ST_ERR;
}
/* Stop and clear the dma engine. */
dma_cfg.u64 = 0;
dma_cfg.s.size = -1;
cvmx_write_csr(cf_port->dma_base + DMA_CFG, dma_cfg.u64);
/* Clear the DMA complete status */
dma_int.s.done = 1;
cvmx_write_csr(cf_port->dma_base + DMA_INT, dma_int.u64);
status = ap->ops->sff_check_status(ap);
ata_sff_hsm_move(ap, qc, status, 0);
if (unlikely(qc->err_mask) && (qc->tf.protocol == ATA_PROT_DMA))
ata_ehi_push_desc(ehi, "DMA stat 0x%x", status);
return 1;
}
/* * Check if any queued commands have more DMAs, if so start the next * transfer, else do end of transfer handling.
*/ static irqreturn_t octeon_cf_interrupt(int irq, void *dev_instance)
{ struct ata_host *host = dev_instance; struct octeon_cf_port *cf_port; int i; unsignedint handled = 0; unsignedlong flags;
spin_lock_irqsave(&host->lock, flags);
for (i = 0; i < host->n_ports; i++) {
u8 status; struct ata_port *ap; struct ata_queued_cmd *qc; union cvmx_mio_boot_dma_intx dma_int; union cvmx_mio_boot_dma_cfgx dma_cfg;
if (!qc || (qc->tf.flags & ATA_TFLAG_POLLING)) continue;
if (dma_int.s.done && !dma_cfg.s.en) { if (!sg_is_last(qc->cursg)) {
qc->cursg = sg_next(qc->cursg);
handled = 1;
trace_ata_bmdma_start(ap, &qc->tf, qc->tag);
octeon_cf_dma_start(qc); continue;
} else {
cf_port->dma_finished = 1;
}
} if (!cf_port->dma_finished) continue;
status = ioread8(ap->ioaddr.altstatus_addr); if (status & (ATA_BUSY | ATA_DRQ)) { /* * We are busy, try to handle it later. This * is the DMA finished interrupt, and it could * take a little while for the card to be * ready for more commands.
*/ /* Clear DMA irq. */
dma_int.u64 = 0;
dma_int.s.done = 1;
cvmx_write_csr(cf_port->dma_base + DMA_INT,
dma_int.u64);
hrtimer_start_range_ns(&cf_port->delayed_finish,
ns_to_ktime(OCTEON_CF_BUSY_POLL_INTERVAL),
OCTEON_CF_BUSY_POLL_INTERVAL / 5,
HRTIMER_MODE_REL);
handled = 1;
} else {
handled |= octeon_cf_dma_finished(ap, qc);
}
}
spin_unlock_irqrestore(&host->lock, flags); return IRQ_RETVAL(handled);
}
/* * If the port is not waiting for completion, it must have * handled it previously. The hsm_task_state is * protected by host->lock.
*/ if (ap->hsm_task_state != HSM_ST_LAST || !cf_port->dma_finished) goto out;
staticvoid octeon_cf_dev_config(struct ata_device *dev)
{ /* * A maximum of 2^20 - 1 16 bit transfers are possible with * the bootbus DMA. So we need to throttle max_sectors to * (2^12 - 1 == 4095) to assure that this can never happen.
*/
dev->max_sectors = min(dev->max_sectors, 4095U);
}
/* * We don't do ATAPI DMA so return 0.
*/ staticint octeon_cf_check_atapi_dma(struct ata_queued_cmd *qc)
{ return 0;
}
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.