moved stats into eoe struct; persistent rx-skb; tx queue.
authorFlorian Pose <fp@igh-essen.com>
Wed, 03 May 2006 07:47:04 +0000
changeset 212 82980deb8b00
parent 211 c684b6b7adaf
child 213 8d723b9833a9
moved stats into eoe struct; persistent rx-skb; tx queue.
master/ethernet.c
master/ethernet.h
master/globals.h
--- a/master/ethernet.c	Wed May 03 07:19:19 2006 +0000
+++ b/master/ethernet.c	Wed May 03 07:47:04 2006 +0000
@@ -45,7 +45,6 @@
 
 typedef struct
 {
-    struct net_device_stats stats; /**< device statistics */
     ec_eoe_t *eoe; /**< pointer to parent eoe object */
 }
 ec_eoedev_priv_t;
@@ -73,6 +72,10 @@
     eoe->slave = slave;
     eoe->rx_state = EC_EOE_IDLE;
     eoe->opened = 0;
+    eoe->skb = NULL;
+    INIT_LIST_HEAD(&eoe->tx_queue);
+    eoe->queued_frames = 0;
+    eoe->tx_queue_lock = SPIN_LOCK_UNLOCKED;
 
     if (!(eoe->dev =
           alloc_netdev(sizeof(ec_eoedev_priv_t), "eoe%d", ec_eoedev_init))) {
@@ -257,11 +260,10 @@
 
 int ec_eoedev_open(struct net_device *dev /**< EoE net_device */)
 {
-    ec_eoedev_priv_t *priv = netdev_priv(dev);
-    priv->eoe->opened = 1;
+    ec_eoe_t *eoe = ((ec_eoedev_priv_t *) netdev_priv(dev))->eoe;
+    eoe->opened = 1;
     netif_start_queue(dev);
-    EC_INFO("%s (slave %i) opened.\n", dev->name,
-            priv->eoe->slave->ring_position);
+    EC_INFO("%s (slave %i) opened.\n", dev->name, eoe->slave->ring_position);
     return 0;
 }
 
@@ -273,11 +275,10 @@
 
 int ec_eoedev_stop(struct net_device *dev /**< EoE net_device */)
 {
-    ec_eoedev_priv_t *priv = netdev_priv(dev);
+    ec_eoe_t *eoe = ((ec_eoedev_priv_t *) netdev_priv(dev))->eoe;
     netif_stop_queue(dev);
-    priv->eoe->opened = 0;
-    EC_INFO("%s (slave %i) stopped.\n", dev->name,
-            priv->eoe->slave->ring_position);
+    eoe->opened = 0;
+    EC_INFO("%s (slave %i) stopped.\n", dev->name, eoe->slave->ring_position);
     return 0;
 }
 
@@ -289,12 +290,23 @@
 
 int ec_eoedev_tx(struct sk_buff *skb, /**< transmit socket buffer */
                  struct net_device *dev /**< EoE net_device */
-                 )
-{
-    ec_eoedev_priv_t *priv = netdev_priv(dev);
-    priv->stats.tx_packets++;
+                )
+{
+    ec_eoe_t *eoe = ((ec_eoedev_priv_t *) netdev_priv(dev))->eoe;
+
+    spin_lock_bh(&eoe->tx_queue_lock);
+
+#if 0
+    eoe->stats.tx_packets++;
     dev_kfree_skb(skb);
     EC_INFO("EoE device sent %i octets.\n", skb->len);
+#endif
+
+    if (eoe->queued_frames == EC_EOE_TX_QUEUE_SIZE)
+        netif_stop_queue(dev);
+
+    spin_unlock_bh(&eoe->tx_queue_lock);
+
     return 0;
 }
 
@@ -305,35 +317,35 @@
 */
 
 void ec_eoedev_rx(struct net_device *dev, /**< EoE net_device */
-                 const uint8_t *data, /**< pointer to the data */
-                 size_t size /**< size of the received data */
+                  const uint8_t *data, /**< pointer to the data */
+                  size_t size /**< size of the received data */
                  )
 {
-    ec_eoedev_priv_t *priv = netdev_priv(dev);
-    struct sk_buff *skb;
+    ec_eoe_t *eoe = ((ec_eoedev_priv_t *) netdev_priv(dev))->eoe;
 
     // allocate socket buffer
-    if (!(skb = dev_alloc_skb(size + 2))) {
+    if (!(eoe->skb = dev_alloc_skb(size + 2))) {
         if (printk_ratelimit())
             EC_WARN("EoE RX: low on mem. frame dropped.\n");
-        priv->stats.rx_dropped++;
+        eoe->stats.rx_dropped++;
         return;
     }
 
     // copy received data to socket buffer
-    memcpy(skb_put(skb, size), data, size);
+    memcpy(skb_put(eoe->skb, size), data, size);
 
     // set socket buffer fields
-    skb->dev = dev;
-    skb->protocol = eth_type_trans(skb, dev);
-    skb->ip_summed = CHECKSUM_UNNECESSARY;
+    eoe->skb->dev = dev;
+    eoe->skb->protocol = eth_type_trans(eoe->skb, dev);
+    eoe->skb->ip_summed = CHECKSUM_UNNECESSARY;
 
     // update statistics
-    priv->stats.rx_packets++;
-    priv->stats.rx_bytes += size;
+    eoe->stats.rx_packets++;
+    eoe->stats.rx_bytes += size;
 
     // pass socket buffer to network stack
-    netif_rx(skb);
+    netif_rx(eoe->skb);
+    eoe->skb = NULL;
 }
 
 /*****************************************************************************/
@@ -345,8 +357,8 @@
 struct net_device_stats *ec_eoedev_stats(struct net_device *dev
                                          /**< EoE net_device */)
 {
-    ec_eoedev_priv_t *priv = netdev_priv(dev);
-    return &priv->stats;
-}
-
-/*****************************************************************************/
+    ec_eoe_t *eoe = ((ec_eoedev_priv_t *) netdev_priv(dev))->eoe;
+    return &eoe->stats;
+}
+
+/*****************************************************************************/
--- a/master/ethernet.h	Wed May 03 07:19:19 2006 +0000
+++ b/master/ethernet.h	Wed May 03 07:47:04 2006 +0000
@@ -65,6 +65,11 @@
     ec_eoe_state_t rx_state; /**< state of the state machine */
     struct net_device *dev; /**< net_device for virtual ethernet device */
     uint8_t opened; /**< net_device is opened */
+    struct sk_buff *skb; /**< current rx socket buffer */
+    struct net_device_stats stats; /**< device statistics */
+    struct list_head tx_queue; /**< queue for frames to send */
+    unsigned int queued_frames; /**< number of frames in the queue */
+    spinlock_t tx_queue_lock; /**< spinlock for the send queue */
 }
 ec_eoe_t;
 
--- a/master/globals.h	Wed May 03 07:19:19 2006 +0000
+++ b/master/globals.h	Wed May 03 07:47:04 2006 +0000
@@ -49,6 +49,9 @@
 /** maximum number of FMMUs per slave */
 #define EC_MAX_FMMUS 16
 
+/** size of the EoE tx queue */
+#define EC_EOE_TX_QUEUE_SIZE 10
+
 /******************************************************************************
  *  EtherCAT protocol
  *****************************************************************************/