Commit 65f71b8b authored by Stephen Hemminger's avatar Stephen Hemminger Committed by David S. Miller

benet: use do_div() for 64 bit divide

The benet driver is doing a 64 bit divide, which is not supported in
Linux kernel on 32 bit architectures. The correct way to do this is to
use do_div().  Compile tested on i386 only.
Signed-off-by: default avatarStephen Hemminger <shemminger@vyatta.com>
Acked-by: default avatarRandy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7d0b591c
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
*/ */
#include "be.h" #include "be.h"
#include <asm/div64.h>
MODULE_VERSION(DRV_VER); MODULE_VERSION(DRV_VER);
MODULE_DEVICE_TABLE(pci, be_dev_ids); MODULE_DEVICE_TABLE(pci, be_dev_ids);
...@@ -290,6 +291,17 @@ static struct net_device_stats *be_get_stats(struct net_device *dev) ...@@ -290,6 +291,17 @@ static struct net_device_stats *be_get_stats(struct net_device *dev)
return &adapter->stats.net_stats; return &adapter->stats.net_stats;
} }
static u32 be_calc_rate(u64 bytes, unsigned long ticks)
{
u64 rate = bytes;
do_div(rate, ticks / HZ);
rate <<= 3; /* bytes/sec -> bits/sec */
do_div(rate, 1000000ul); /* MB/Sec */
return rate;
}
static void be_tx_rate_update(struct be_adapter *adapter) static void be_tx_rate_update(struct be_adapter *adapter)
{ {
struct be_drvr_stats *stats = drvr_stats(adapter); struct be_drvr_stats *stats = drvr_stats(adapter);
...@@ -303,11 +315,9 @@ static void be_tx_rate_update(struct be_adapter *adapter) ...@@ -303,11 +315,9 @@ static void be_tx_rate_update(struct be_adapter *adapter)
/* Update tx rate once in two seconds */ /* Update tx rate once in two seconds */
if ((now - stats->be_tx_jiffies) > 2 * HZ) { if ((now - stats->be_tx_jiffies) > 2 * HZ) {
u32 r; stats->be_tx_rate = be_calc_rate(stats->be_tx_bytes
r = (stats->be_tx_bytes - stats->be_tx_bytes_prev) / - stats->be_tx_bytes_prev,
((now - stats->be_tx_jiffies) / HZ); now - stats->be_tx_jiffies);
r = r / 1000000; /* M bytes/s */
stats->be_tx_rate = r * 8; /* M bits/s */
stats->be_tx_jiffies = now; stats->be_tx_jiffies = now;
stats->be_tx_bytes_prev = stats->be_tx_bytes; stats->be_tx_bytes_prev = stats->be_tx_bytes;
} }
...@@ -599,7 +609,6 @@ static void be_rx_rate_update(struct be_adapter *adapter) ...@@ -599,7 +609,6 @@ static void be_rx_rate_update(struct be_adapter *adapter)
{ {
struct be_drvr_stats *stats = drvr_stats(adapter); struct be_drvr_stats *stats = drvr_stats(adapter);
ulong now = jiffies; ulong now = jiffies;
u32 rate;
/* Wrapped around */ /* Wrapped around */
if (time_before(now, stats->be_rx_jiffies)) { if (time_before(now, stats->be_rx_jiffies)) {
...@@ -611,10 +620,9 @@ static void be_rx_rate_update(struct be_adapter *adapter) ...@@ -611,10 +620,9 @@ static void be_rx_rate_update(struct be_adapter *adapter)
if ((now - stats->be_rx_jiffies) < 2 * HZ) if ((now - stats->be_rx_jiffies) < 2 * HZ)
return; return;
rate = (stats->be_rx_bytes - stats->be_rx_bytes_prev) / stats->be_rx_rate = be_calc_rate(stats->be_rx_bytes
((now - stats->be_rx_jiffies) / HZ); - stats->be_rx_bytes_prev,
rate = rate / 1000000; /* MB/Sec */ now - stats->be_rx_jiffies);
stats->be_rx_rate = rate * 8; /* Mega Bits/Sec */
stats->be_rx_jiffies = now; stats->be_rx_jiffies = now;
stats->be_rx_bytes_prev = stats->be_rx_bytes; stats->be_rx_bytes_prev = stats->be_rx_bytes;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment