master/ethernet.c
changeset 1579 326d47aa986c
parent 1500 ed1a733efbc5
child 1581 e51cf2af3ff9
equal deleted inserted replaced
1511:53bf35f7b6ea 1579:326d47aa986c
    32    Ethernet over EtherCAT (EoE).
    32    Ethernet over EtherCAT (EoE).
    33 */
    33 */
    34 
    34 
    35 /*****************************************************************************/
    35 /*****************************************************************************/
    36 
    36 
       
    37 #include <linux/version.h>
    37 #include <linux/netdevice.h>
    38 #include <linux/netdevice.h>
    38 #include <linux/etherdevice.h>
    39 #include <linux/etherdevice.h>
    39 
    40 
    40 #include "globals.h"
    41 #include "globals.h"
    41 #include "master.h"
    42 #include "master.h"
    76 // net_device functions
    77 // net_device functions
    77 int ec_eoedev_open(struct net_device *);
    78 int ec_eoedev_open(struct net_device *);
    78 int ec_eoedev_stop(struct net_device *);
    79 int ec_eoedev_stop(struct net_device *);
    79 int ec_eoedev_tx(struct sk_buff *, struct net_device *);
    80 int ec_eoedev_tx(struct sk_buff *, struct net_device *);
    80 struct net_device_stats *ec_eoedev_stats(struct net_device *);
    81 struct net_device_stats *ec_eoedev_stats(struct net_device *);
       
    82 
       
    83 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
       
    84 static const struct net_device_ops ec_eoe_netdev_ops =
       
    85 {
       
    86     .ndo_open = ec_eoedev_open,
       
    87     .ndo_stop = ec_eoedev_stop,
       
    88     .ndo_start_xmit = ec_eoedev_tx,
       
    89     .ndo_get_stats = ec_eoedev_stats,
       
    90 };
       
    91 #endif
    81 
    92 
    82 /*****************************************************************************/
    93 /*****************************************************************************/
    83 
    94 
    84 /** EoE constructor.
    95 /** EoE constructor.
    85  *
    96  *
   105     INIT_LIST_HEAD(&eoe->tx_queue);
   116     INIT_LIST_HEAD(&eoe->tx_queue);
   106     eoe->tx_frame = NULL;
   117     eoe->tx_frame = NULL;
   107     eoe->tx_queue_active = 0;
   118     eoe->tx_queue_active = 0;
   108     eoe->tx_queue_size = EC_EOE_TX_QUEUE_SIZE;
   119     eoe->tx_queue_size = EC_EOE_TX_QUEUE_SIZE;
   109     eoe->tx_queued_frames = 0;
   120     eoe->tx_queued_frames = 0;
   110     init_MUTEX(&eoe->tx_queue_sem);
   121 
       
   122     sema_init(&eoe->tx_queue_sem, 1);
   111     eoe->tx_frame_number = 0xFF;
   123     eoe->tx_frame_number = 0xFF;
   112     memset(&eoe->stats, 0, sizeof(struct net_device_stats));
   124     memset(&eoe->stats, 0, sizeof(struct net_device_stats));
   113 
   125 
   114     eoe->rx_counter = 0;
   126     eoe->rx_counter = 0;
   115     eoe->tx_counter = 0;
   127     eoe->tx_counter = 0;
   136         ret = -ENODEV;
   148         ret = -ENODEV;
   137         goto out_return;
   149         goto out_return;
   138     }
   150     }
   139 
   151 
   140     // initialize net_device
   152     // initialize net_device
       
   153 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
       
   154     eoe->dev->netdev_ops = &ec_eoe_netdev_ops;
       
   155 #else
   141     eoe->dev->open = ec_eoedev_open;
   156     eoe->dev->open = ec_eoedev_open;
   142     eoe->dev->stop = ec_eoedev_stop;
   157     eoe->dev->stop = ec_eoedev_stop;
   143     eoe->dev->hard_start_xmit = ec_eoedev_tx;
   158     eoe->dev->hard_start_xmit = ec_eoedev_tx;
   144     eoe->dev->get_stats = ec_eoedev_stats;
   159     eoe->dev->get_stats = ec_eoedev_stats;
       
   160 #endif
   145 
   161 
   146     for (i = 0; i < ETH_ALEN; i++)
   162     for (i = 0; i < ETH_ALEN; i++)
   147         eoe->dev->dev_addr[i] = i | (i << 4);
   163         eoe->dev->dev_addr[i] = i | (i << 4);
   148 
   164 
   149     // initialize private data
   165     // initialize private data