void wdc_obio_adjust_timing(struct channel_softc *chp) { struct ata_drive_datas *drvp; u_int conf; int drive; int piomode = -1, dmamode = -1; int min_cycle, min_active; int cycle_tick, act_tick, inact_tick, half_tick; for (drive = 0; drive < 2; drive++) { drvp = &chp->ch_drive[drive]; if ((drvp->drive_flags & DRIVE) == 0) continue; if (piomode == -1 || piomode > drvp->PIO_mode) piomode = drvp->PIO_mode; if (drvp->drive_flags & DRIVE_DMA) if (dmamode == -1 || dmamode > drvp->DMA_mode) dmamode = drvp->DMA_mode; } if (piomode == -1) return; /* No drive */ for (drive = 0; drive < 2; drive++) { drvp = &chp->ch_drive[drive]; if (drvp->drive_flags & DRIVE) { drvp->PIO_mode = piomode; if (drvp->drive_flags & DRIVE_DMA) drvp->DMA_mode = dmamode; } } min_cycle = pio_timing[piomode].cycle; min_active = pio_timing[piomode].active; cycle_tick = TIME_TO_TICK(min_cycle); act_tick = TIME_TO_TICK(min_active); if (act_tick < PIO_ACT_MIN) act_tick = PIO_ACT_MIN; inact_tick = cycle_tick - act_tick - PIO_REC_OFFSET; if (inact_tick < PIO_REC_MIN) inact_tick = PIO_REC_MIN; /* mask: 0x000007ff */ conf = (inact_tick << 5) | act_tick; if (dmamode != -1) { /* there are active DMA mode */ min_cycle = dma_timing[dmamode].cycle; min_active = dma_timing[dmamode].active; cycle_tick = TIME_TO_TICK(min_cycle); act_tick = TIME_TO_TICK(min_active); inact_tick = cycle_tick - act_tick - DMA_REC_OFFSET; if (inact_tick < DMA_REC_MIN) inact_tick = DMA_REC_MIN; half_tick = 0; /* XXX */ /* mask: 0xfffff800 */ conf |= (half_tick << 21) | (inact_tick << 16) | (act_tick << 11); } bus_space_write_4(chp->cmd_iot, chp->cmd_ioh, CONFIG_REG, conf); #if 0 printf("conf = 0x%x, cyc = %d (%d ns), act = %d (%d ns), inact = %d\n", conf, cycle_tick, min_cycle, act_tick, min_active, inact_tick); #endif }
void init_rtt(struct rtt_t *rtt) { memset(rtt, 0, sizeof(struct rtt_t)); rtt->rto = TIME_TO_TICK(1); // according to RFC 6298 }
void adjust_timing(struct ata_channel *chp) { struct wdc_obio_softc *sc = (struct wdc_obio_softc *)chp->ch_atac; int drive; int min_cycle = 0, min_active = 0; int cycle_tick = 0, act_tick = 0, inact_tick = 0, half_tick; for (drive = 0; drive < 2; drive++) { u_int conf = 0; struct ata_drive_datas *drvp; drvp = &chp->ch_drive[drive]; /* set up pio mode timings */ if (drvp->drive_type != ATA_DRIVET_NONE) { int piomode = drvp->PIO_mode; min_cycle = pio_timing[piomode].cycle; min_active = pio_timing[piomode].active; cycle_tick = TIME_TO_TICK(min_cycle); act_tick = TIME_TO_TICK(min_active); if (act_tick < PIO_ACT_MIN) act_tick = PIO_ACT_MIN; inact_tick = cycle_tick - act_tick - PIO_REC_OFFSET; if (inact_tick < PIO_REC_MIN) inact_tick = PIO_REC_MIN; /* mask: 0x000007ff */ conf |= (inact_tick << 5) | act_tick; } /* Set up DMA mode timings */ if (drvp->drive_flags & ATA_DRIVE_DMA) { int dmamode = drvp->DMA_mode; min_cycle = dma_timing[dmamode].cycle; min_active = dma_timing[dmamode].active; cycle_tick = TIME_TO_TICK(min_cycle); act_tick = TIME_TO_TICK(min_active); inact_tick = cycle_tick - act_tick - DMA_REC_OFFSET; if (inact_tick < DMA_REC_MIN) inact_tick = DMA_REC_MIN; half_tick = 0; /* XXX */ /* mask: 0xfffff800 */ conf |= (half_tick << 21) | (inact_tick << 16) | (act_tick << 11); } #ifdef DEBUG if (conf) { printf("conf[%d] = 0x%x, cyc = %d (%d ns), act = %d (%d ns), inact = %d\n", drive, conf, cycle_tick, min_cycle, act_tick, min_active, inact_tick); } #endif sc->sc_dmaconf[drive] = conf; } sc->sc_wdcdev.select = 0; if (sc->sc_dmaconf[0]) { wdc_obio_select(chp,0); if (sc->sc_dmaconf[1] && (sc->sc_dmaconf[0] != sc->sc_dmaconf[1])) { sc->sc_wdcdev.select = wdc_obio_select; } } else if (sc->sc_dmaconf[1]) { wdc_obio_select(chp,1); } }