master/ethernet.c
changeset 661 bc1de1362efb
parent 629 84a64efca00d
child 683 43700671b37a
equal deleted inserted replaced
660:582a90a34303 661:bc1de1362efb
    81 struct net_device_stats *ec_eoedev_stats(struct net_device *);
    81 struct net_device_stats *ec_eoedev_stats(struct net_device *);
    82 
    82 
    83 /*****************************************************************************/
    83 /*****************************************************************************/
    84 
    84 
    85 /**
    85 /**
    86    EoE constructor.
    86  * EoE constructor.
    87    Initializes the EoE handler, creates a net_device and registeres it.
    87  * Initializes the EoE handler, creates a net_device and registers it.
    88 */
    88  */
    89 
    89 
    90 int ec_eoe_init(ec_eoe_t *eoe /**< EoE handler */)
    90 int ec_eoe_init(
       
    91         ec_eoe_t *eoe, /**< EoE handler */
       
    92         ec_slave_t *slave /**< EtherCAT slave */
       
    93         )
    91 {
    94 {
    92     ec_eoe_t **priv;
    95     ec_eoe_t **priv;
    93     int result, i;
    96     int result, i;
    94 
    97     char name[20];
    95     eoe->slave = NULL;
    98 
       
    99     eoe->slave = slave;
       
   100 
    96     ec_datagram_init(&eoe->datagram);
   101     ec_datagram_init(&eoe->datagram);
    97     eoe->state = ec_eoe_state_rx_start;
   102     eoe->state = ec_eoe_state_rx_start;
    98     eoe->opened = 0;
   103     eoe->opened = 0;
    99     eoe->rx_skb = NULL;
   104     eoe->rx_skb = NULL;
   100     eoe->rx_expected_fragment = 0;
   105     eoe->rx_expected_fragment = 0;
   110     eoe->tx_counter = 0;
   115     eoe->tx_counter = 0;
   111     eoe->rx_rate = 0;
   116     eoe->rx_rate = 0;
   112     eoe->tx_rate = 0;
   117     eoe->tx_rate = 0;
   113     eoe->rate_jiffies = 0;
   118     eoe->rate_jiffies = 0;
   114 
   119 
   115     if (!(eoe->dev =
   120     sprintf(name, "eoe%u-%u", slave->master->index, slave->ring_position);
   116           alloc_netdev(sizeof(ec_eoe_t *), "eoe%d", ether_setup))) {
   121 
       
   122     if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) {
   117         EC_ERR("Unable to allocate net_device for EoE handler!\n");
   123         EC_ERR("Unable to allocate net_device for EoE handler!\n");
   118         goto out_return;
   124         goto out_return;
   119     }
   125     }
   120 
   126 
   121     // initialize net_device
   127     // initialize net_device
   145         goto out_free;
   151         goto out_free;
   146     }
   152     }
   147 
   153 
   148     // make the last address octet unique
   154     // make the last address octet unique
   149     eoe->dev->dev_addr[ETH_ALEN - 1] = (uint8_t) eoe->dev->ifindex;
   155     eoe->dev->dev_addr[ETH_ALEN - 1] = (uint8_t) eoe->dev->ifindex;
   150 
       
   151     return 0;
   156     return 0;
   152 
   157 
   153  out_free:
   158  out_free:
   154     free_netdev(eoe->dev);
   159     free_netdev(eoe->dev);
   155     eoe->dev = NULL;
   160     eoe->dev = NULL;
   303 /**
   308 /**
   304    Returns the state of the device.
   309    Returns the state of the device.
   305    \return 1 if the device is "up", 0 if it is "down"
   310    \return 1 if the device is "up", 0 if it is "down"
   306 */
   311 */
   307 
   312 
   308 int ec_eoe_active(const ec_eoe_t *eoe /**< EoE handler */)
   313 int ec_eoe_is_open(const ec_eoe_t *eoe /**< EoE handler */)
   309 {
   314 {
   310     return eoe->slave && eoe->opened;
   315     return eoe->opened;
   311 }
   316 }
   312 
   317 
   313 /******************************************************************************
   318 /******************************************************************************
   314  *  STATE PROCESSING FUNCTIONS
   319  *  STATE PROCESSING FUNCTIONS
   315  *****************************************************************************/
   320  *****************************************************************************/