[PATCH] ieee1394: fix calculation of csr->expire
authorStefan Richter <stefanr@s5r6.in-berlin.de>
Mon, 3 Jul 2006 16:01:59 +0000 (12:01 -0400)
committerBen Collins <bcollins@ubuntu.com>
Mon, 3 Jul 2006 16:01:59 +0000 (12:01 -0400)
This variant of calculate_expire() is more correct and easier to read.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Signed-off-by: Ben Collins <bcollins@ubuntu.com>
drivers/ieee1394/csr.c

index 149573d..ab0c80f 100644 (file)
  *
  */
 
-#include <linux/string.h>
+#include <linux/jiffies.h>
+#include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/param.h>
 #include <linux/spinlock.h>
+#include <linux/string.h>
 
 #include "csr1212.h"
 #include "ieee1394_types.h"
@@ -149,31 +151,18 @@ static void host_reset(struct hpsb_host *host)
 
 /*
  * HI == seconds (bits 0:2)
- * LO == fraction units of 1/8000 of a second, as per 1394 (bits 19:31)
- *
- * Convert to units and then to HZ, for comparison to jiffies.
- *
- * By default this will end up being 800 units, or 100ms (125usec per
- * unit).
+ * LO == fractions of a second in units of 125usec (bits 19:31)
  *
- * NOTE: The spec says 1/8000, but also says we can compute based on 1/8192
- * like CSR specifies. Should make our math less complex.
+ * Convert SPLIT_TIMEOUT to jiffies.
+ * The default and minimum as per 1394a-2000 clause 8.3.2.2.6 is 100ms.
  */
 static inline void calculate_expire(struct csr_control *csr)
 {
-       unsigned long units;
-
-       /* Take the seconds, and convert to units */
-       units = (unsigned long)(csr->split_timeout_hi & 0x07) << 13;
-
-       /* Add in the fractional units */
-       units += (unsigned long)(csr->split_timeout_lo >> 19);
-
-       /* Convert to jiffies */
-       csr->expire = (unsigned long)(units * HZ) >> 13UL;
+       unsigned long usecs =
+               (csr->split_timeout_hi & 0x07) * USEC_PER_SEC +
+               (csr->split_timeout_lo >> 19) * 125L;
 
-       /* Just to keep from rounding low */
-       csr->expire++;
+       csr->expire = usecs_to_jiffies(usecs > 100000L ? usecs : 100000L);
 
        HPSB_VERBOSE("CSR: setting expire to %lu, HZ=%u", csr->expire, HZ);
 }