All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergei Shtylyov <sshtylyov@ru.mvista.com>
To: bzolnier@gmail.com
Cc: linux-ide@vger.kernel.org
Subject: [PATCH pata-2.6 fix queue] cmd64x: fix recovery time calculation (take 3)
Date: Sat, 3 Mar 2007 23:17:10 +0300	[thread overview]
Message-ID: <200703032317.10173.sshtylyov@ru.mvista.com> (raw)
In-Reply-To: <200702262332.31751.sshtylyov@ru.mvista.com>

[PATCH] cmd64x: fix recovery time calculation

The driver wrongly takes the address setup time into account when calculating
the PIO recovery time -- this leads to slight overclocking of the PIO modes 0
and 1 (so, the prayers failed to help, as usual :-).  Rework the code to be
calculating recovery clock count as a difference between the total cycle count
and the active count (we don't need to calculate the recovery time itself since
it's not specified for the PIO modes 0 to 2, and for modes 3 and 4 this formula
gives enough recovery time anyway in the chip's supported PCI frequency range).

This patch has been inspired by reading the datasheets and looking at what the
libata driver does; it has been compile-tested only (as usual :-) but anyway,
the new code gives the same or longer recovery times than the old one...

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>

---
This patch has been changed in accordance to the pending reordering as DMA
support removal and addition patches are going to be merged.  In addition,
I've put quantize_timing() to its proper place to avoid moving it later...

 drivers/ide/pci/cmd64x.c |   49 +++++++++++++++++++++--------------------------
 1 files changed, 22 insertions(+), 27 deletions(-)

Index: linux-2.6/drivers/ide/pci/cmd64x.c
===================================================================
--- linux-2.6.orig/drivers/ide/pci/cmd64x.c
+++ linux-2.6/drivers/ide/pci/cmd64x.c
@@ -1,6 +1,6 @@
 /* $Id: cmd64x.c,v 1.21 2000/01/30 23:23:16
  *
- * linux/drivers/ide/pci/cmd64x.c		Version 1.41	Feb 3, 2007
+ * linux/drivers/ide/pci/cmd64x.c		Version 1.42	Feb 8, 2007
  *
  * cmd64x.c: Enable interrupts at initialization time on Ultra/PCI machines.
  *           Note, this driver is not used at all on other systems because
@@ -189,6 +189,11 @@ static int cmd64x_get_info (char *buffer
 
 #endif	/* defined(DISPLAY_CMD64X_TIMINGS) && defined(CONFIG_PROC_FS) */
 
+static u8 quantize_timing(int timing, int quant)
+{
+	return (timing + quant - 1) / quant;
+}
+
 /*
  * This routine writes the prepared setup/active/recovery counts
  * for a drive into the cmd646 chipset registers to active them.
@@ -268,47 +273,37 @@ static void program_drive_counts (ide_dr
  */
 static u8 cmd64x_tune_pio (ide_drive_t *drive, u8 mode_wanted)
 {
-	int setup_time, active_time, recovery_time;
-	int clock_time, pio_mode, cycle_time;
-	u8 recovery_count2, cycle_count;
-	int setup_count, active_count, recovery_count;
-	int bus_speed = system_bus_clock();
-	ide_pio_data_t  d;
+	int setup_time, active_time, cycle_time;
+	u8  cycle_count, setup_count, active_count, recovery_count;
+	u8  pio_mode;
+	int clock_time = 1000 / system_bus_clock();
+	ide_pio_data_t pio;
 
-	pio_mode = ide_get_best_pio_mode(drive, mode_wanted, 5, &d);
-	cycle_time = d.cycle_time;
+	pio_mode = ide_get_best_pio_mode(drive, mode_wanted, 5, &pio);
+	cycle_time = pio.cycle_time;
 
-	/*
-	 * I copied all this complicated stuff from cmd640.c and made a few
-	 * minor changes.  For now I am just going to pray that it is correct.
-	 */
 	setup_time  = ide_pio_timings[pio_mode].setup_time;
 	active_time = ide_pio_timings[pio_mode].active_time;
-	recovery_time = cycle_time - (setup_time + active_time);
-	clock_time = 1000 / bus_speed;
-	cycle_count = (cycle_time + clock_time - 1) / clock_time;
-
-	setup_count = (setup_time + clock_time - 1) / clock_time;
-
-	active_count = (active_time + clock_time - 1) / clock_time;
-
-	recovery_count = (recovery_time + clock_time - 1) / clock_time;
-	recovery_count2 = cycle_count - (setup_count + active_count);
-	if (recovery_count2 > recovery_count)
-		recovery_count = recovery_count2;
+
+	setup_count  = quantize_timing( setup_time, clock_time);
+	cycle_count  = quantize_timing( cycle_time, clock_time);
+	active_count = quantize_timing(active_time, clock_time);
+
+	recovery_count = cycle_count - active_count;
+	/* program_drive_counts() takes care of zero recovery cycles */
 	if (recovery_count > 16) {
 		active_count += recovery_count - 16;
 		recovery_count = 16;
 	}
 	if (active_count > 16)
-		active_count = 16; /* maximum allowed by cmd646 */
+		active_count = 16; /* maximum allowed by cmd64x */
 
 	program_drive_counts (drive, setup_count, active_count, recovery_count);
 
 	cmdprintk("%s: PIO mode wanted %d, selected %d (%dns)%s, "
 		"clocks=%d/%d/%d\n",
 		drive->name, mode_wanted, pio_mode, cycle_time,
-		d.overridden ? " (overriding vendor mode)" : "",
+		pio.overridden ? " (overriding vendor mode)" : "",
 		setup_count, active_count, recovery_count);
 
 	return pio_mode;


  parent reply	other threads:[~2007-03-03 20:17 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-03 20:09 [PATCH] (2.6.20-rc7) cmd64x: fix PIO mode setup Sergei Shtylyov
2007-02-03 21:04 ` [PATCH] (2.6.20-rc7) cmd64x: fix PIO mode setup (take 2) Sergei Shtylyov
2007-02-03 22:25   ` Bartlomiej Zolnierkiewicz
2007-02-05 13:29     ` Sergei Shtylyov
2007-02-05 13:57       ` Sergei Shtylyov
     [not found]         ` <58cb370e0702061459r1b001421gb4592d066793ab46@mail.gmail.com>
2007-02-06 23:44           ` Bartlomiej Zolnierkiewicz
2007-02-07 12:50             ` Sergei Shtylyov
     [not found]       ` <58cb370e0702061459k4a147891v3686b267d8e3001a@mail.gmail.com>
2007-02-06 23:33         ` Bartlomiej Zolnierkiewicz
2007-02-06 14:45   ` [PATCH] (2.6.20) cmd64x: fix PIO mode setup (take 3) Sergei Shtylyov
2007-02-06 21:11     ` Mikael Pettersson
2007-02-07  0:28       ` Bartlomiej Zolnierkiewicz
     [not found]     ` <58cb370e0702061500g3047b8ccpca894962491b588a@mail.gmail.com>
2007-02-06 23:48       ` Bartlomiej Zolnierkiewicz
2007-02-09 22:29   ` [PATCH] (pata-2.6 fix queue) cmd64x: fix recovery time calculation Sergei Shtylyov
2007-02-10  0:14     ` Bartlomiej Zolnierkiewicz
2007-02-14 21:42   ` [PATCH] (pata-2.6 fix queue) cmd64x: interrupt status fixes Sergei Shtylyov
2007-02-14 22:35   ` [PATCH] (pata-2.6 fix queue) cmd64x: add/fix enablebits Sergei Shtylyov
2007-02-19 23:09     ` Bartlomiej Zolnierkiewicz
2007-02-20 14:28       ` Sergei Shtylyov
2007-02-23 20:10         ` Bartlomiej Zolnierkiewicz
2007-04-14 19:31     ` [PATCH pata-2.6] cmd64x: add/fix enablebits (take 2) Sergei Shtylyov
2007-04-23 21:54       ` Bartlomiej Zolnierkiewicz
2007-02-15 13:53   ` [PATCH] (pata-2.6 fix queue) cmd64x: interrupt status fixes (resend) Sergei Shtylyov
2007-02-19 23:04     ` Bartlomiej Zolnierkiewicz
2007-04-14 19:17     ` [PATCH pata-2.6] cmd64x: interrupt status fixes (take 2) Sergei Shtylyov
2007-04-23 21:52       ` Bartlomiej Zolnierkiewicz
2007-02-15 19:17   ` [PATCH] (pata-2.6 fix queue) cmd64x: procfs code fixes/cleanups Sergei Shtylyov
2007-02-19 23:10     ` Bartlomiej Zolnierkiewicz
2007-04-14 19:41     ` [PATCH pata-2.6] cmd64x: procfs code fixes/cleanups (take 2) Sergei Shtylyov
2007-04-23 21:58       ` Bartlomiej Zolnierkiewicz
2007-02-16 20:15   ` [PATCH] (pata-2.6 fix queue) cmd64x: Sergei Shtylyov
2007-02-16 20:21   ` [PATCH] (pata-2.6 fix queue) cmd64x: use interrupt status from MRDMODE register Sergei Shtylyov
2007-02-23 20:09     ` Bartlomiej Zolnierkiewicz
2007-04-14 19:53     ` [PATCH pata-2.6] cmd64x: use interrupt status from MRDMODE register (take 2) Sergei Shtylyov
2007-04-23 22:03       ` Bartlomiej Zolnierkiewicz
2007-04-18 19:38     ` [PATCH pata-2.6 fix queue] hpt366: fix kernel oops with HPT302N Sergei Shtylyov
2007-04-20 19:54       ` Bartlomiej Zolnierkiewicz
2007-04-22 18:05     ` [PATCH pata-2.6 fix queue] aec62xx: fix PIO/DMA setup issues Sergei Shtylyov
2007-04-23 22:33       ` Bartlomiej Zolnierkiewicz
2007-05-10 20:01     ` [PATCH pata-2.6 fix queue] cmd64x: init. code cleanup Sergei Shtylyov
2007-05-10 20:04     ` Sergei Shtylyov
2007-05-15 21:16       ` Bartlomiej Zolnierkiewicz
2007-05-11 19:31     ` [PATCH pata-2.6 fix queue] aec62xx: rework init_setup_aec6x80() Sergei Shtylyov
2007-05-15 21:31       ` Bartlomiej Zolnierkiewicz
2007-05-11 21:11     ` [PATCH pata-2.6 fix queue] aec62xx: remove init_dma() method Sergei Shtylyov
2007-05-15 21:40       ` Bartlomiej Zolnierkiewicz
2007-05-11 21:22     ` [PATCH pata-2.6 fix queue] aec62xx: kill speedproc() method wrapper Sergei Shtylyov
2007-05-15 21:43       ` Bartlomiej Zolnierkiewicz
2007-05-16 14:20         ` Sergei Shtylyov
2007-05-23 23:33           ` Bartlomiej Zolnierkiewicz
2007-05-24 13:18             ` Sergei Shtylyov
2007-05-24 16:44     ` [PATCH pata-2.6] aec62xx: remove init_dma() method (take 2) Sergei Shtylyov
2007-05-24 16:46     ` [PATCH pata-2.6] aec62xx: kill speedproc() method wrapper " Sergei Shtylyov
2007-05-28 20:44       ` Bartlomiej Zolnierkiewicz
2007-06-05 15:15         ` Sergei Shtylyov
2007-06-08 12:22           ` Bartlomiej Zolnierkiewicz
2007-06-09 10:05             ` Sergei Shtylyov
2007-11-09 11:07     ` [PATCH] cmd64x: don't clear the other channels interrupt Sergei Shtylyov
2007-11-11 21:52       ` Bartlomiej Zolnierkiewicz
2007-11-13 20:58         ` Bartlomiej Zolnierkiewicz
2007-11-15 19:23           ` Martin Rogge
2007-11-16 13:34           ` Sergei Shtylyov
2007-02-26 20:32   ` [PATCH] (pata-2.6 fix queue) cmd64x: fix recovery time calculation (take 2) Sergei Shtylyov
2007-03-02 20:34     ` Bartlomiej Zolnierkiewicz
2007-03-03 20:17     ` Sergei Shtylyov [this message]
2007-03-15 20:29       ` [PATCH pata-2.6 fix queue] cmd64x: fix recovery time calculation (take 3) Bartlomiej Zolnierkiewicz
2007-02-27 21:49   ` [PATCH] (pata-2.6 fix queue) cmd64x: fix primary channel address setup time Sergei Shtylyov
2007-02-28 13:27     ` Sergei Shtylyov
2007-02-28 20:52   ` [PATCH] (pata-2.6 fix queue) cmd64x: add back MWDMA support Sergei Shtylyov
2007-03-02 22:03     ` Bartlomiej Zolnierkiewicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200703032317.10173.sshtylyov@ru.mvista.com \
    --to=sshtylyov@ru.mvista.com \
    --cc=bzolnier@gmail.com \
    --cc=linux-ide@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.