]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/net/benet/be_main.c
Merge branch 'bkl-removal' of git://git.lwn.net/linux-2.6
[karo-tx-linux.git] / drivers / net / benet / be_main.c
index 897a63de5bdb46e08f7155088009617b1b997cd8..9b75aa630062401886b404392ca0ecbc22d524e8 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include "be.h"
+#include <asm/div64.h>
 
 MODULE_VERSION(DRV_VER);
 MODULE_DEVICE_TABLE(pci, be_dev_ids);
@@ -245,19 +246,29 @@ static void be_link_status_update(struct be_adapter *adapter)
 /* Update the EQ delay n BE based on the RX frags consumed / sec */
 static void be_rx_eqd_update(struct be_adapter *adapter)
 {
-       u32 eqd;
        struct be_ctrl_info *ctrl = &adapter->ctrl;
        struct be_eq_obj *rx_eq = &adapter->rx_eq;
        struct be_drvr_stats *stats = &adapter->stats.drvr_stats;
+       ulong now = jiffies;
+       u32 eqd;
+
+       if (!rx_eq->enable_aic)
+               return;
+
+       /* Wrapped around */
+       if (time_before(now, stats->rx_fps_jiffies)) {
+               stats->rx_fps_jiffies = now;
+               return;
+       }
 
        /* Update once a second */
-       if (((jiffies - stats->rx_fps_jiffies) < HZ) || rx_eq->enable_aic == 0)
+       if ((now - stats->rx_fps_jiffies) < HZ)
                return;
 
        stats->be_rx_fps = (stats->be_rx_frags - stats->be_prev_rx_frags) /
-                       ((jiffies - stats->rx_fps_jiffies) / HZ);
+                       ((now - stats->rx_fps_jiffies) / HZ);
 
-       stats->rx_fps_jiffies = jiffies;
+       stats->rx_fps_jiffies = now;
        stats->be_prev_rx_frags = stats->be_rx_frags;
        eqd = stats->be_rx_fps / 110000;
        eqd = eqd << 3;
@@ -273,53 +284,54 @@ static void be_rx_eqd_update(struct be_adapter *adapter)
        rx_eq->cur_eqd = eqd;
 }
 
-static void be_worker(struct work_struct *work)
+static struct net_device_stats *be_get_stats(struct net_device *dev)
 {
-       struct be_adapter *adapter =
-               container_of(work, struct be_adapter, work.work);
-       int status;
+       struct be_adapter *adapter = netdev_priv(dev);
 
-       /* Check link */
-       be_link_status_update(adapter);
+       return &adapter->stats.net_stats;
+}
 
-       /* Get Stats */
-       status = be_cmd_get_stats(&adapter->ctrl, &adapter->stats.cmd);
-       if (!status)
-               netdev_stats_update(adapter);
+static u32 be_calc_rate(u64 bytes, unsigned long ticks)
+{
+       u64 rate = bytes;
 
-       /* Set EQ delay */
-       be_rx_eqd_update(adapter);
+       do_div(rate, ticks / HZ);
+       rate <<= 3;                     /* bytes/sec -> bits/sec */
+       do_div(rate, 1000000ul);        /* MB/Sec */
 
-       schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000));
+       return rate;
 }
 
-static struct net_device_stats *be_get_stats(struct net_device *dev)
+static void be_tx_rate_update(struct be_adapter *adapter)
 {
-       struct be_adapter *adapter = netdev_priv(dev);
+       struct be_drvr_stats *stats = drvr_stats(adapter);
+       ulong now = jiffies;
 
-       return &adapter->stats.net_stats;
+       /* Wrapped around? */
+       if (time_before(now, stats->be_tx_jiffies)) {
+               stats->be_tx_jiffies = now;
+               return;
+       }
+
+       /* Update tx rate once in two seconds */
+       if ((now - stats->be_tx_jiffies) > 2 * HZ) {
+               stats->be_tx_rate = be_calc_rate(stats->be_tx_bytes
+                                                 - stats->be_tx_bytes_prev,
+                                                now - stats->be_tx_jiffies);
+               stats->be_tx_jiffies = now;
+               stats->be_tx_bytes_prev = stats->be_tx_bytes;
+       }
 }
 
 static void be_tx_stats_update(struct be_adapter *adapter,
                        u32 wrb_cnt, u32 copied, bool stopped)
 {
-       struct be_drvr_stats *stats = &adapter->stats.drvr_stats;
+       struct be_drvr_stats *stats = drvr_stats(adapter);
        stats->be_tx_reqs++;
        stats->be_tx_wrbs += wrb_cnt;
        stats->be_tx_bytes += copied;
        if (stopped)
                stats->be_tx_stops++;
-
-       /* Update tx rate once in two seconds */
-       if ((jiffies - stats->be_tx_jiffies) > 2 * HZ) {
-               u32 r;
-               r = (stats->be_tx_bytes - stats->be_tx_bytes_prev) /
-                       ((u32) (jiffies - stats->be_tx_jiffies) / HZ);
-               r = (r / 1000000);                      /* M bytes/s */
-               stats->be_tx_rate = (r * 8);    /* M bits/s */
-               stats->be_tx_jiffies = jiffies;
-               stats->be_tx_bytes_prev = stats->be_tx_bytes;
-       }
 }
 
 /* Determine number of WRB entries needed to xmit data in an skb */
@@ -493,7 +505,7 @@ static int be_change_mtu(struct net_device *netdev, int new_mtu)
  * program them in BE.  If more than BE_NUM_VLANS_SUPPORTED are configured,
  * set the BE in promiscuous VLAN mode.
  */
-static void be_vids_config(struct net_device *netdev)
+static void be_vid_config(struct net_device *netdev)
 {
        struct be_adapter *adapter = netdev_priv(netdev);
        u16 vtag[BE_NUM_VLANS_SUPPORTED];
@@ -536,7 +548,7 @@ static void be_vlan_add_vid(struct net_device *netdev, u16 vid)
        adapter->num_vlans++;
        adapter->vlan_tag[vid] = 1;
 
-       be_vids_config(netdev);
+       be_vid_config(netdev);
 }
 
 static void be_vlan_rem_vid(struct net_device *netdev, u16 vid)
@@ -547,7 +559,7 @@ static void be_vlan_rem_vid(struct net_device *netdev, u16 vid)
        adapter->vlan_tag[vid] = 0;
 
        vlan_group_set_device(adapter->vlan_grp, vid, NULL);
-       be_vids_config(netdev);
+       be_vid_config(netdev);
 }
 
 static void be_set_multicast_filter(struct net_device *netdev)
@@ -593,28 +605,38 @@ static void be_set_multicast_list(struct net_device *netdev)
        }
 }
 
-static void be_rx_rate_update(struct be_adapter *adapter, u32 pktsize,
-                       u16 numfrags)
+static void be_rx_rate_update(struct be_adapter *adapter)
 {
-       struct be_drvr_stats *stats = &adapter->stats.drvr_stats;
-       u32 rate;
+       struct be_drvr_stats *stats = drvr_stats(adapter);
+       ulong now = jiffies;
 
-       stats->be_rx_compl++;
-       stats->be_rx_frags += numfrags;
-       stats->be_rx_bytes += pktsize;
+       /* Wrapped around */
+       if (time_before(now, stats->be_rx_jiffies)) {
+               stats->be_rx_jiffies = now;
+               return;
+       }
 
        /* Update the rate once in two seconds */
-       if ((jiffies - stats->be_rx_jiffies) < 2 * HZ)
+       if ((now - stats->be_rx_jiffies) < 2 * HZ)
                return;
 
-       rate = (stats->be_rx_bytes - stats->be_rx_bytes_prev) /
-               ((u32) (jiffies - stats->be_rx_jiffies) / HZ);
-       rate = (rate / 1000000);        /* MB/Sec */
-       stats->be_rx_rate = (rate * 8);         /* Mega Bits/Sec */
-       stats->be_rx_jiffies = jiffies;
+       stats->be_rx_rate = be_calc_rate(stats->be_rx_bytes
+                                         - stats->be_rx_bytes_prev,
+                                        now - stats->be_rx_jiffies);
+       stats->be_rx_jiffies = now;
        stats->be_rx_bytes_prev = stats->be_rx_bytes;
 }
 
+static void be_rx_stats_update(struct be_adapter *adapter,
+               u32 pktsize, u16 numfrags)
+{
+       struct be_drvr_stats *stats = drvr_stats(adapter);
+
+       stats->be_rx_compl++;
+       stats->be_rx_frags += numfrags;
+       stats->be_rx_bytes += pktsize;
+}
+
 static struct be_rx_page_info *
 get_rx_page_info(struct be_adapter *adapter, u16 frag_idx)
 {
@@ -720,7 +742,7 @@ static void skb_fill_rx_data(struct be_adapter *adapter,
                memset(page_info, 0, sizeof(*page_info));
        }
 
-       be_rx_rate_update(adapter, pktsize, num_rcvd);
+       be_rx_stats_update(adapter, pktsize, num_rcvd);
        return;
 }
 
@@ -819,7 +841,7 @@ static void be_rx_compl_process_lro(struct be_adapter *adapter,
                        vid, NULL, 0);
        }
 
-       be_rx_rate_update(adapter, pkt_size, num_rcvd);
+       be_rx_stats_update(adapter, pkt_size, num_rcvd);
        return;
 }
 
@@ -861,7 +883,6 @@ static void be_post_rx_frags(struct be_adapter *adapter)
        u64 page_dmaaddr = 0, frag_dmaaddr;
        u32 posted, page_offset = 0;
 
-
        page_info = &page_info_tbl[rxq->head];
        for (posted = 0; posted < MAX_RX_POST && !page_info->page; posted++) {
                if (!pagep) {
@@ -900,8 +921,11 @@ static void be_post_rx_frags(struct be_adapter *adapter)
                page_info->last_page_user = true;
 
        if (posted) {
-               be_rxq_notify(&adapter->ctrl, rxq->id, posted);
                atomic_add(posted, &rxq->used);
+               be_rxq_notify(&adapter->ctrl, rxq->id, posted);
+       } else if (atomic_read(&rxq->used) == 0) {
+               /* Let be_worker replenish when memory is available */
+               adapter->rx_post_starved = true;
        }
 
        return;
@@ -1305,6 +1329,34 @@ int be_poll_tx(struct napi_struct *napi, int budget)
        return 1;
 }
 
+static void be_worker(struct work_struct *work)
+{
+       struct be_adapter *adapter =
+               container_of(work, struct be_adapter, work.work);
+       int status;
+
+       /* Check link */
+       be_link_status_update(adapter);
+
+       /* Get Stats */
+       status = be_cmd_get_stats(&adapter->ctrl, &adapter->stats.cmd);
+       if (!status)
+               netdev_stats_update(adapter);
+
+       /* Set EQ delay */
+       be_rx_eqd_update(adapter);
+
+       be_tx_rate_update(adapter);
+       be_rx_rate_update(adapter);
+
+       if (adapter->rx_post_starved) {
+               adapter->rx_post_starved = false;
+               be_post_rx_frags(adapter);
+       }
+
+       schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000));
+}
+
 static void be_msix_enable(struct be_adapter *adapter)
 {
        int i, status;
@@ -1422,6 +1474,8 @@ static int be_open(struct net_device *netdev)
        if (status != 0)
                goto do_none;
 
+       be_vid_config(netdev);
+
        status = be_cmd_set_flow_control(ctrl, true, true);
        if (status != 0)
                goto if_destroy;
@@ -1856,8 +1910,6 @@ static int be_resume(struct pci_dev *pdev)
        pci_set_power_state(pdev, 0);
        pci_restore_state(pdev);
 
-       be_vids_config(netdev);
-
        if (netif_running(netdev)) {
                rtnl_lock();
                be_open(netdev);