equal
deleted
inserted
replaced
46 #include "master.h" |
46 #include "master.h" |
47 #include "slave.h" |
47 #include "slave.h" |
48 #include "mailbox.h" |
48 #include "mailbox.h" |
49 #include "ethernet.h" |
49 #include "ethernet.h" |
50 |
50 |
51 /** |
51 /*****************************************************************************/ |
52 Defines the debug level of EoE processing |
52 |
53 |
53 /** |
54 0 = No debug messages. |
54 * Defines the debug level of EoE processing. |
55 1 = Output actions. |
55 * |
56 2 = Output actions and frame data. |
56 * 0 = No debug messages. |
57 */ |
57 * 1 = Output actions. |
|
58 * 2 = Output actions and frame data. |
|
59 */ |
58 |
60 |
59 #define EOE_DEBUG_LEVEL 0 |
61 #define EOE_DEBUG_LEVEL 0 |
|
62 |
|
63 /** size of the EoE tx queue */ |
|
64 #define EC_EOE_TX_QUEUE_SIZE 100 |
60 |
65 |
61 /*****************************************************************************/ |
66 /*****************************************************************************/ |
62 |
67 |
63 void ec_eoe_flush(ec_eoe_t *); |
68 void ec_eoe_flush(ec_eoe_t *); |
64 |
69 |
76 struct net_device_stats *ec_eoedev_stats(struct net_device *); |
81 struct net_device_stats *ec_eoedev_stats(struct net_device *); |
77 |
82 |
78 /*****************************************************************************/ |
83 /*****************************************************************************/ |
79 |
84 |
80 /** |
85 /** |
81 EoE constructor. |
86 * EoE constructor. |
82 Initializes the EoE handler, creates a net_device and registeres it. |
87 * Initializes the EoE handler, creates a net_device and registers it. |
83 */ |
88 */ |
84 |
89 |
85 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 ) |
86 { |
94 { |
87 ec_eoe_t **priv; |
95 ec_eoe_t **priv; |
88 int result, i; |
96 int result, i; |
89 |
97 char name[20]; |
90 eoe->slave = NULL; |
98 |
|
99 eoe->slave = slave; |
|
100 |
91 ec_datagram_init(&eoe->datagram); |
101 ec_datagram_init(&eoe->datagram); |
92 eoe->state = ec_eoe_state_rx_start; |
102 eoe->state = ec_eoe_state_rx_start; |
93 eoe->opened = 0; |
103 eoe->opened = 0; |
94 eoe->rx_skb = NULL; |
104 eoe->rx_skb = NULL; |
95 eoe->rx_expected_fragment = 0; |
105 eoe->rx_expected_fragment = 0; |
105 eoe->tx_counter = 0; |
115 eoe->tx_counter = 0; |
106 eoe->rx_rate = 0; |
116 eoe->rx_rate = 0; |
107 eoe->tx_rate = 0; |
117 eoe->tx_rate = 0; |
108 eoe->rate_jiffies = 0; |
118 eoe->rate_jiffies = 0; |
109 |
119 |
110 if (!(eoe->dev = |
120 /* device name eoe<MASTER>s<SLAVE>, because system tools don't like |
111 alloc_netdev(sizeof(ec_eoe_t *), "eoe%d", ether_setup))) { |
121 * hyphens etc. in interface names. */ |
|
122 sprintf(name, "eoe%us%u", slave->master->index, slave->ring_position); |
|
123 |
|
124 if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) { |
112 EC_ERR("Unable to allocate net_device for EoE handler!\n"); |
125 EC_ERR("Unable to allocate net_device for EoE handler!\n"); |
113 goto out_return; |
126 goto out_return; |
114 } |
127 } |
115 |
128 |
116 // initialize net_device |
129 // initialize net_device |
140 goto out_free; |
153 goto out_free; |
141 } |
154 } |
142 |
155 |
143 // make the last address octet unique |
156 // make the last address octet unique |
144 eoe->dev->dev_addr[ETH_ALEN - 1] = (uint8_t) eoe->dev->ifindex; |
157 eoe->dev->dev_addr[ETH_ALEN - 1] = (uint8_t) eoe->dev->ifindex; |
145 |
|
146 return 0; |
158 return 0; |
147 |
159 |
148 out_free: |
160 out_free: |
149 free_netdev(eoe->dev); |
161 free_netdev(eoe->dev); |
150 eoe->dev = NULL; |
162 eoe->dev = NULL; |
298 /** |
310 /** |
299 Returns the state of the device. |
311 Returns the state of the device. |
300 \return 1 if the device is "up", 0 if it is "down" |
312 \return 1 if the device is "up", 0 if it is "down" |
301 */ |
313 */ |
302 |
314 |
303 int ec_eoe_active(const ec_eoe_t *eoe /**< EoE handler */) |
315 int ec_eoe_is_open(const ec_eoe_t *eoe /**< EoE handler */) |
304 { |
316 { |
305 return eoe->slave && eoe->opened; |
317 return eoe->opened; |
306 } |
318 } |
307 |
319 |
308 /****************************************************************************** |
320 /****************************************************************************** |
309 * STATE PROCESSING FUNCTIONS |
321 * STATE PROCESSING FUNCTIONS |
310 *****************************************************************************/ |
322 *****************************************************************************/ |
315 slave's mailbox for a new EoE datagram. |
327 slave's mailbox for a new EoE datagram. |
316 */ |
328 */ |
317 |
329 |
318 void ec_eoe_state_rx_start(ec_eoe_t *eoe /**< EoE handler */) |
330 void ec_eoe_state_rx_start(ec_eoe_t *eoe /**< EoE handler */) |
319 { |
331 { |
320 if (!eoe->slave->online || !eoe->slave->master->device->link_state) |
332 if (eoe->slave->online_state == EC_SLAVE_OFFLINE || |
|
333 !eoe->slave->master->main_device.link_state) |
321 return; |
334 return; |
322 |
335 |
323 ec_slave_mbox_prepare_check(eoe->slave, &eoe->datagram); |
336 ec_slave_mbox_prepare_check(eoe->slave, &eoe->datagram); |
324 ec_master_queue_datagram(eoe->slave->master, &eoe->datagram); |
337 ec_master_queue_datagram(eoe->slave->master, &eoe->datagram); |
325 eoe->state = ec_eoe_state_rx_check; |
338 eoe->state = ec_eoe_state_rx_check; |
380 eoe->stats.rx_errors++; |
393 eoe->stats.rx_errors++; |
381 eoe->state = ec_eoe_state_tx_start; |
394 eoe->state = ec_eoe_state_tx_start; |
382 return; |
395 return; |
383 } |
396 } |
384 |
397 |
385 if (mbox_prot != 0x02) { // EoE |
398 if (mbox_prot != 0x02) { // EoE FIXME mailbox handler necessary |
386 eoe->stats.rx_errors++; |
399 eoe->stats.rx_errors++; |
387 eoe->state = ec_eoe_state_tx_start; |
400 eoe->state = ec_eoe_state_tx_start; |
388 return; |
401 return; |
389 } |
402 } |
390 |
403 |
516 { |
529 { |
517 #if EOE_DEBUG_LEVEL > 0 |
530 #if EOE_DEBUG_LEVEL > 0 |
518 unsigned int wakeup = 0; |
531 unsigned int wakeup = 0; |
519 #endif |
532 #endif |
520 |
533 |
521 if (!eoe->slave->online || !eoe->slave->master->device->link_state) |
534 if (eoe->slave->online_state == EC_SLAVE_OFFLINE || |
|
535 !eoe->slave->master->main_device.link_state) |
522 return; |
536 return; |
523 |
537 |
524 spin_lock_bh(&eoe->tx_queue_lock); |
538 spin_lock_bh(&eoe->tx_queue_lock); |
525 |
539 |
526 if (!eoe->tx_queued_frames || list_empty(&eoe->tx_queue)) { |
540 if (!eoe->tx_queued_frames || list_empty(&eoe->tx_queue)) { |
624 ec_eoe_flush(eoe); |
638 ec_eoe_flush(eoe); |
625 eoe->opened = 1; |
639 eoe->opened = 1; |
626 netif_start_queue(dev); |
640 netif_start_queue(dev); |
627 eoe->tx_queue_active = 1; |
641 eoe->tx_queue_active = 1; |
628 EC_INFO("%s opened.\n", dev->name); |
642 EC_INFO("%s opened.\n", dev->name); |
629 if (!eoe->slave) |
643 ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP); |
630 EC_WARN("Device %s is not coupled to any EoE slave!\n", dev->name); |
|
631 else { |
|
632 ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP); |
|
633 } |
|
634 return 0; |
644 return 0; |
635 } |
645 } |
636 |
646 |
637 /*****************************************************************************/ |
647 /*****************************************************************************/ |
638 |
648 |
646 netif_stop_queue(dev); |
656 netif_stop_queue(dev); |
647 eoe->tx_queue_active = 0; |
657 eoe->tx_queue_active = 0; |
648 eoe->opened = 0; |
658 eoe->opened = 0; |
649 ec_eoe_flush(eoe); |
659 ec_eoe_flush(eoe); |
650 EC_INFO("%s stopped.\n", dev->name); |
660 EC_INFO("%s stopped.\n", dev->name); |
651 if (eoe->slave) |
661 ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_PREOP); |
652 ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_PREOP); |
|
653 return 0; |
662 return 0; |
654 } |
663 } |
655 |
664 |
656 /*****************************************************************************/ |
665 /*****************************************************************************/ |
657 |
666 |