Skip to content

Commit

Permalink
ide: add ide_set{_max}_pio() (take 4)
Browse files Browse the repository at this point in the history
* Add IDE_HFLAG_ABUSE_{PREFETCH,FAST_DEVSEL,DMA_MODES} flags
  and set them in ht6560, cmd640, cmd64x and sc1200 host drivers.

* Add set_pio_mode_abuse() for checking if host driver has a non-standard
  ->tuneproc() implementation and use it in do_special().

* Add ide_set_pio() for setting PIO mode (it uses hwif->pio_mask to find
  the maximum PIO mode supported by the host), also add ide_set_max_pio()
  wrapper for ide_set_pio() to use for auto-tuning.  Convert users of
  ->tuneproc to use ide_set{_max}_pio() where possible.  This leaves only
  do_special(), set_using_pio(), ide_hwif_restore() and ide_set_pio() as
  a direct users of ->tuneproc.

* Remove no longer needed ide_get_best_pio_mode() calls and printk-s
  reporting PIO mode selected from ->tuneproc implementations.

* Rename ->tuneproc hook to ->set_pio_mode and make 'pio' argument const.

* Remove stale comment from ide_config_drive_speed().

v2:
* Fix "ata_" prefix (Noticed by Jeff).

v3:
* Minor cleanups/fixups per Sergei's suggestions.

v4:
* Fix compile problem in drivers/ide/pci/cmd640.c
  (Noticed by Andrew Morton).

* Improve some ->set_pio_mode comments.

Reviewed-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Cc: Jeff Garzik <jeff@garzik.org>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
  • Loading branch information
Bartlomiej Zolnierkiewicz committed Oct 11, 2007
1 parent 842c19a commit 26bcb87
Show file tree
Hide file tree
Showing 45 changed files with 318 additions and 326 deletions.
8 changes: 3 additions & 5 deletions drivers/ide/cris/ide-cris.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,12 +680,10 @@ static void cris_dma_off(ide_drive_t *drive)
{
}

static void tune_cris_ide(ide_drive_t *drive, u8 pio)
static void cris_set_pio_mode(ide_drive_t *drive, const u8 pio)
{
int setup, strobe, hold;

pio = ide_get_best_pio_mode(drive, pio, 4);

switch(pio)
{
case 0:
Expand Down Expand Up @@ -727,7 +725,7 @@ static int speed_cris_ide(ide_drive_t *drive, const u8 speed)
int cyc = 0, dvs = 0, strobe = 0, hold = 0;

if (speed >= XFER_PIO_0 && speed <= XFER_PIO_4) {
tune_cris_ide(drive, speed - XFER_PIO_0);
cris_set_pio_mode(drive, speed - XFER_PIO_0);
return ide_config_drive_speed(drive, speed);
}

Expand Down Expand Up @@ -797,7 +795,7 @@ init_e100_ide (void)
ide_register_hw(&hw, 1, &hwif);
hwif->mmio = 1;
hwif->chipset = ide_etrax100;
hwif->tuneproc = &tune_cris_ide;
hwif->set_pio_mode = &cris_set_pio_mode;
hwif->speedproc = &speed_cris_ide;
hwif->ata_input_data = &cris_ide_input_data;
hwif->ata_output_data = &cris_ide_output_data;
Expand Down
39 changes: 35 additions & 4 deletions drivers/ide/ide-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
return do_rw_taskfile(drive, args);

case idedisk_pm_restore_pio: /* Resume step 1 (restore PIO) */
if (drive->hwif->tuneproc != NULL)
drive->hwif->tuneproc(drive, 255);
ide_set_max_pio(drive);
/*
* skip idedisk_pm_idle for ATAPI devices
*/
Expand Down Expand Up @@ -788,6 +787,30 @@ static ide_startstop_t ide_disk_special(ide_drive_t *drive)
return ide_started;
}

/*
* handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
*/
static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
{
switch (req_pio) {
case 202:
case 201:
case 200:
case 102:
case 101:
case 100:
return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
case 9:
case 8:
return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
case 7:
case 6:
return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
default:
return 0;
}
}

/**
* do_special - issue some special commands
* @drive: drive the command is for
Expand All @@ -805,9 +828,17 @@ static ide_startstop_t do_special (ide_drive_t *drive)
printk("%s: do_special: 0x%02x\n", drive->name, s->all);
#endif
if (s->b.set_tune) {
ide_hwif_t *hwif = drive->hwif;
u8 req_pio = drive->tune_req;

s->b.set_tune = 0;
if (HWIF(drive)->tuneproc != NULL)
HWIF(drive)->tuneproc(drive, drive->tune_req);

if (set_pio_mode_abuse(drive->hwif, req_pio)) {
if (hwif->set_pio_mode)
hwif->set_pio_mode(drive, req_pio);
} else
ide_set_pio(drive, req_pio);

return ide_stopped;
} else {
if (drive->media == ide_disk)
Expand Down
6 changes: 0 additions & 6 deletions drivers/ide/ide-iops.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,12 +780,6 @@ int ide_driveid_update (ide_drive_t *drive)

/*
* Similar to ide_wait_stat(), except it never calls ide_error internally.
* This is a kludge to handle the new ide_config_drive_speed() function,
* and should not otherwise be used anywhere. Eventually, the tuneproc's
* should be updated to return ide_startstop_t, in which case we can get
* rid of this abomination again. :) -ml
*
* It is gone..........
*
* const char *msg == consider adding for verbose errors.
*/
Expand Down
29 changes: 29 additions & 0 deletions drivers/ide/ide-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,35 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode)

EXPORT_SYMBOL_GPL(ide_get_best_pio_mode);

/* req_pio == "255" for auto-tune */
void ide_set_pio(ide_drive_t *drive, u8 req_pio)
{
ide_hwif_t *hwif = drive->hwif;
u8 host_pio, pio;

if (hwif->set_pio_mode == NULL)
return;

BUG_ON(hwif->pio_mask == 0x00);

host_pio = fls(hwif->pio_mask) - 1;

pio = ide_get_best_pio_mode(drive, req_pio, host_pio);

/*
* TODO:
* - report device max PIO mode
* - check req_pio != 255 against device max PIO mode
*/
printk(KERN_DEBUG "%s: host max PIO%d wanted PIO%d%s selected PIO%d\n",
drive->name, host_pio, req_pio,
req_pio == 255 ? "(auto-tune)" : "", pio);

hwif->set_pio_mode(drive, pio);
}

EXPORT_SYMBOL_GPL(ide_set_pio);

/**
* ide_toggle_bounce - handle bounce buffering
* @drive: drive to update
Expand Down
6 changes: 2 additions & 4 deletions drivers/ide/ide-probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,10 +827,8 @@ static void probe_hwif(ide_hwif_t *hwif, void (*fixup)(ide_hwif_t *hwif))
ide_drive_t *drive = &hwif->drives[unit];

if (drive->present) {
if (hwif->tuneproc != NULL &&
drive->autotune == IDE_TUNE_AUTO)
/* auto-tune PIO mode */
hwif->tuneproc(drive, 255);
if (drive->autotune == IDE_TUNE_AUTO)
ide_set_max_pio(drive);

if (drive->autotune != IDE_TUNE_DEFAULT &&
drive->autotune != IDE_TUNE_AUTO)
Expand Down
5 changes: 3 additions & 2 deletions drivers/ide/ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
hwif->cds = tmp_hwif->cds;
#endif

hwif->tuneproc = tmp_hwif->tuneproc;
hwif->set_pio_mode = tmp_hwif->set_pio_mode;
hwif->speedproc = tmp_hwif->speedproc;
hwif->mdma_filter = tmp_hwif->mdma_filter;
hwif->udma_filter = tmp_hwif->udma_filter;
Expand Down Expand Up @@ -867,8 +867,9 @@ int set_pio_mode(ide_drive_t *drive, int arg)
if (arg < 0 || arg > 255)
return -EINVAL;

if (!HWIF(drive)->tuneproc)
if (drive->hwif->set_pio_mode == NULL)
return -ENOSYS;

if (drive->special.b.set_tune)
return -EBUSY;
ide_init_drive_cmd(&rq);
Expand Down
10 changes: 3 additions & 7 deletions drivers/ide/legacy/ali14xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ static RegInitializer initData[] __initdata = {
{0x35, 0x03}, {0x00, 0x00}
};

#define ALI_MAX_PIO 4

/* timing parameter registers for each drive */
static struct { u8 reg1, reg2, reg3, reg4; } regTab[4] = {
{0x03, 0x26, 0x04, 0x27}, /* drive 0 */
Expand Down Expand Up @@ -109,16 +107,14 @@ static void outReg (u8 data, u8 reg)
* This function computes timing parameters
* and sets controller registers accordingly.
*/
static void ali14xx_tune_drive (ide_drive_t *drive, u8 pio)
static void ali14xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
{
int driveNum;
int time1, time2;
u8 param1, param2, param3, param4;
unsigned long flags;
int bus_speed = system_bus_clock();

pio = ide_get_best_pio_mode(drive, pio, ALI_MAX_PIO);

/* calculate timing, according to PIO mode */
time1 = ide_pio_cycle_time(drive, pio);
time2 = ide_pio_timings[pio].active_time;
Expand Down Expand Up @@ -212,12 +208,12 @@ static int __init ali14xx_probe(void)

hwif->chipset = ide_ali14xx;
hwif->pio_mask = ATA_PIO4;
hwif->tuneproc = &ali14xx_tune_drive;
hwif->set_pio_mode = &ali14xx_set_pio_mode;
hwif->mate = mate;

mate->chipset = ide_ali14xx;
mate->pio_mask = ATA_PIO4;
mate->tuneproc = &ali14xx_tune_drive;
mate->set_pio_mode = &ali14xx_set_pio_mode;
mate->mate = hwif;
mate->channel = 1;

Expand Down
6 changes: 2 additions & 4 deletions drivers/ide/legacy/dtc2278.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ static void sub22 (char b, char c)
}
}

static void tune_dtc2278 (ide_drive_t *drive, u8 pio)
static void dtc2278_set_pio_mode(ide_drive_t *drive, const u8 pio)
{
unsigned long flags;

pio = ide_get_best_pio_mode(drive, pio, 4);

if (pio >= 3) {
spin_lock_irqsave(&ide_lock, flags);
/*
Expand Down Expand Up @@ -124,7 +122,7 @@ static int __init dtc2278_probe(void)
hwif->serialized = 1;
hwif->chipset = ide_dtc2278;
hwif->pio_mask = ATA_PIO4;
hwif->tuneproc = &tune_dtc2278;
hwif->set_pio_mode = &dtc2278_set_pio_mode;
hwif->drives[0].no_unmask = 1;
hwif->drives[1].no_unmask = 1;
hwif->mate = mate;
Expand Down
11 changes: 6 additions & 5 deletions drivers/ide/legacy/ht6560b.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static int __init try_to_init_ht6560b(void)
return 1;
}

static u8 ht_pio2timings(ide_drive_t *drive, u8 pio)
static u8 ht_pio2timings(ide_drive_t *drive, const u8 pio)
{
int active_time, recovery_time;
int active_cycles, recovery_cycles;
Expand All @@ -208,7 +208,6 @@ static u8 ht_pio2timings(ide_drive_t *drive, u8 pio)
if (pio) {
unsigned int cycle_time;

pio = ide_get_best_pio_mode(drive, pio, 5);
cycle_time = ide_pio_cycle_time(drive, pio);

/*
Expand Down Expand Up @@ -277,7 +276,7 @@ static void ht_set_prefetch(ide_drive_t *drive, u8 state)
#endif
}

static void tune_ht6560b (ide_drive_t *drive, u8 pio)
static void ht6560b_set_pio_mode(ide_drive_t *drive, const u8 pio)
{
unsigned long flags;
u8 timing;
Expand Down Expand Up @@ -333,15 +332,17 @@ int __init ht6560b_init(void)

hwif->chipset = ide_ht6560b;
hwif->selectproc = &ht6560b_selectproc;
hwif->host_flags = IDE_HFLAG_ABUSE_PREFETCH;
hwif->pio_mask = ATA_PIO5;
hwif->tuneproc = &tune_ht6560b;
hwif->set_pio_mode = &ht6560b_set_pio_mode;
hwif->serialized = 1; /* is this needed? */
hwif->mate = mate;

mate->chipset = ide_ht6560b;
mate->selectproc = &ht6560b_selectproc;
mate->host_flags = IDE_HFLAG_ABUSE_PREFETCH;
mate->pio_mask = ATA_PIO5;
mate->tuneproc = &tune_ht6560b;
mate->set_pio_mode = &ht6560b_set_pio_mode;
mate->serialized = 1; /* is this needed? */
mate->mate = hwif;
mate->channel = 1;
Expand Down
Loading

0 comments on commit 26bcb87

Please sign in to comment.