79 int ec_eoedev_tx(struct sk_buff *, struct net_device *); |
79 int ec_eoedev_tx(struct sk_buff *, struct net_device *); |
80 struct net_device_stats *ec_eoedev_stats(struct net_device *); |
80 struct net_device_stats *ec_eoedev_stats(struct net_device *); |
81 |
81 |
82 /*****************************************************************************/ |
82 /*****************************************************************************/ |
83 |
83 |
84 /** |
84 /** EoE constructor. |
85 * EoE constructor. |
85 * |
86 * Initializes the EoE handler, creates a net_device and registers it. |
86 * Initializes the EoE handler, creates a net_device and registers it. |
87 */ |
87 */ |
88 |
|
89 int ec_eoe_init( |
88 int ec_eoe_init( |
90 ec_eoe_t *eoe, /**< EoE handler */ |
89 ec_eoe_t *eoe, /**< EoE handler */ |
91 ec_slave_t *slave /**< EtherCAT slave */ |
90 ec_slave_t *slave /**< EtherCAT slave */ |
92 ) |
91 ) |
93 { |
92 { |
175 return ret; |
174 return ret; |
176 } |
175 } |
177 |
176 |
178 /*****************************************************************************/ |
177 /*****************************************************************************/ |
179 |
178 |
180 /** |
179 /** EoE destructor. |
181 EoE destructor. |
180 * |
182 Unregisteres the net_device and frees allocated memory. |
181 * Unregisteres the net_device and frees allocated memory. |
183 */ |
182 */ |
184 |
|
185 void ec_eoe_clear(ec_eoe_t *eoe /**< EoE handler */) |
183 void ec_eoe_clear(ec_eoe_t *eoe /**< EoE handler */) |
186 { |
184 { |
187 unregister_netdev(eoe->dev); // possibly calls close callback |
185 unregister_netdev(eoe->dev); // possibly calls close callback |
188 free_netdev(eoe->dev); |
186 free_netdev(eoe->dev); |
189 |
187 |
200 ec_datagram_clear(&eoe->datagram); |
198 ec_datagram_clear(&eoe->datagram); |
201 } |
199 } |
202 |
200 |
203 /*****************************************************************************/ |
201 /*****************************************************************************/ |
204 |
202 |
205 /** |
203 /** Empties the transmit queue. |
206 Empties the transmit queue. |
204 */ |
207 */ |
|
208 |
|
209 void ec_eoe_flush(ec_eoe_t *eoe /**< EoE handler */) |
205 void ec_eoe_flush(ec_eoe_t *eoe /**< EoE handler */) |
210 { |
206 { |
211 ec_eoe_frame_t *frame, *next; |
207 ec_eoe_frame_t *frame, *next; |
212 |
208 |
213 spin_lock_bh(&eoe->tx_queue_lock); |
209 spin_lock_bh(&eoe->tx_queue_lock); |
222 spin_unlock_bh(&eoe->tx_queue_lock); |
218 spin_unlock_bh(&eoe->tx_queue_lock); |
223 } |
219 } |
224 |
220 |
225 /*****************************************************************************/ |
221 /*****************************************************************************/ |
226 |
222 |
227 /** |
223 /** Sends a frame or the next fragment. |
228 Sends a frame or the next fragment. |
224 */ |
229 */ |
|
230 |
|
231 int ec_eoe_send(ec_eoe_t *eoe /**< EoE handler */) |
225 int ec_eoe_send(ec_eoe_t *eoe /**< EoE handler */) |
232 { |
226 { |
233 size_t remaining_size, current_size, complete_offset; |
227 size_t remaining_size, current_size, complete_offset; |
234 unsigned int last_fragment; |
228 unsigned int last_fragment; |
235 uint8_t *data; |
229 uint8_t *data; |
323 ec_datagram_output_stats(&eoe->datagram); |
315 ec_datagram_output_stats(&eoe->datagram); |
324 } |
316 } |
325 |
317 |
326 /*****************************************************************************/ |
318 /*****************************************************************************/ |
327 |
319 |
328 /** |
320 /** Queues the datagram, if necessary. |
329 * Queues the datagram, if necessary. |
321 */ |
330 */ |
|
331 |
|
332 void ec_eoe_queue(ec_eoe_t *eoe /**< EoE handler */) |
322 void ec_eoe_queue(ec_eoe_t *eoe /**< EoE handler */) |
333 { |
323 { |
334 if (eoe->queue_datagram) { |
324 if (eoe->queue_datagram) { |
335 ec_master_queue_datagram(eoe->slave->master, &eoe->datagram); |
325 ec_master_queue_datagram(eoe->slave->master, &eoe->datagram); |
336 eoe->queue_datagram = 0; |
326 eoe->queue_datagram = 0; |
337 } |
327 } |
338 } |
328 } |
339 |
329 |
340 /*****************************************************************************/ |
330 /*****************************************************************************/ |
341 |
331 |
342 /** |
332 /** Returns the state of the device. |
343 Returns the state of the device. |
333 * |
344 \return 1 if the device is "up", 0 if it is "down" |
334 * \return 1 if the device is "up", 0 if it is "down" |
345 */ |
335 */ |
346 |
|
347 int ec_eoe_is_open(const ec_eoe_t *eoe /**< EoE handler */) |
336 int ec_eoe_is_open(const ec_eoe_t *eoe /**< EoE handler */) |
348 { |
337 { |
349 return eoe->opened; |
338 return eoe->opened; |
350 } |
339 } |
351 |
340 |
352 /****************************************************************************** |
341 /****************************************************************************** |
353 * STATE PROCESSING FUNCTIONS |
342 * STATE PROCESSING FUNCTIONS |
354 *****************************************************************************/ |
343 *****************************************************************************/ |
355 |
344 |
356 /** |
345 /** State: RX_START. |
357 State: RX_START. |
346 * |
358 Starts a new receiving sequence by queueing a datagram that checks the |
347 * Starts a new receiving sequence by queueing a datagram that checks the |
359 slave's mailbox for a new EoE datagram. |
348 * slave's mailbox for a new EoE datagram. |
360 */ |
349 */ |
361 |
|
362 void ec_eoe_state_rx_start(ec_eoe_t *eoe /**< EoE handler */) |
350 void ec_eoe_state_rx_start(ec_eoe_t *eoe /**< EoE handler */) |
363 { |
351 { |
364 if (eoe->slave->error_flag || !eoe->slave->master->main_device.link_state) |
352 if (eoe->slave->error_flag || !eoe->slave->master->main_device.link_state) |
365 return; |
353 return; |
366 |
354 |
369 eoe->state = ec_eoe_state_rx_check; |
357 eoe->state = ec_eoe_state_rx_check; |
370 } |
358 } |
371 |
359 |
372 /*****************************************************************************/ |
360 /*****************************************************************************/ |
373 |
361 |
374 /** |
362 /** State: RX_CHECK. |
375 State: RX_CHECK. |
363 * |
376 Processes the checking datagram sent in RX_START and issues a receive |
364 * Processes the checking datagram sent in RX_START and issues a receive |
377 datagram, if new data is available. |
365 * datagram, if new data is available. |
378 */ |
366 */ |
379 |
|
380 void ec_eoe_state_rx_check(ec_eoe_t *eoe /**< EoE handler */) |
367 void ec_eoe_state_rx_check(ec_eoe_t *eoe /**< EoE handler */) |
381 { |
368 { |
382 if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) { |
369 if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) { |
383 eoe->stats.rx_errors++; |
370 eoe->stats.rx_errors++; |
384 #if EOE_DEBUG_LEVEL >= 1 |
371 #if EOE_DEBUG_LEVEL >= 1 |
399 eoe->state = ec_eoe_state_rx_fetch; |
386 eoe->state = ec_eoe_state_rx_fetch; |
400 } |
387 } |
401 |
388 |
402 /*****************************************************************************/ |
389 /*****************************************************************************/ |
403 |
390 |
404 /** |
391 /** State: RX_FETCH. |
405 State: RX_FETCH. |
392 * |
406 Checks if the requested data of RX_CHECK was received and processes the |
393 * Checks if the requested data of RX_CHECK was received and processes the EoE |
407 EoE datagram. |
394 * datagram. |
408 */ |
395 */ |
409 |
|
410 void ec_eoe_state_rx_fetch(ec_eoe_t *eoe /**< EoE handler */) |
396 void ec_eoe_state_rx_fetch(ec_eoe_t *eoe /**< EoE handler */) |
411 { |
397 { |
412 size_t rec_size, data_size; |
398 size_t rec_size, data_size; |
413 uint8_t *data, frame_type, last_fragment, time_appended, mbox_prot; |
399 uint8_t *data, frame_type, last_fragment, time_appended, mbox_prot; |
414 uint8_t frame_number, fragment_offset, fragment_number; |
400 uint8_t frame_number, fragment_offset, fragment_number; |
567 } |
553 } |
568 } |
554 } |
569 |
555 |
570 /*****************************************************************************/ |
556 /*****************************************************************************/ |
571 |
557 |
572 /** |
558 /** State: TX START. |
573 State: TX START. |
559 * |
574 Starts a new transmit sequence. If no data is available, a new receive |
560 * Starts a new transmit sequence. If no data is available, a new receive |
575 sequence is started instead. |
561 * sequence is started instead. |
576 */ |
562 */ |
577 |
|
578 void ec_eoe_state_tx_start(ec_eoe_t *eoe /**< EoE handler */) |
563 void ec_eoe_state_tx_start(ec_eoe_t *eoe /**< EoE handler */) |
579 { |
564 { |
580 #if EOE_DEBUG_LEVEL >= 2 |
565 #if EOE_DEBUG_LEVEL >= 2 |
581 unsigned int wakeup = 0; |
566 unsigned int wakeup = 0; |
582 #endif |
567 #endif |
635 eoe->state = ec_eoe_state_tx_sent; |
620 eoe->state = ec_eoe_state_tx_sent; |
636 } |
621 } |
637 |
622 |
638 /*****************************************************************************/ |
623 /*****************************************************************************/ |
639 |
624 |
640 /** |
625 /** State: TX SENT. |
641 State: TX SENT. |
626 * |
642 Checks is the previous transmit datagram succeded and sends the next |
627 * Checks is the previous transmit datagram succeded and sends the next |
643 fragment, if necessary. |
628 * fragment, if necessary. |
644 */ |
629 */ |
645 |
|
646 void ec_eoe_state_tx_sent(ec_eoe_t *eoe /**< EoE handler */) |
630 void ec_eoe_state_tx_sent(ec_eoe_t *eoe /**< EoE handler */) |
647 { |
631 { |
648 if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) { |
632 if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) { |
649 if (eoe->tries) { |
633 if (eoe->tries) { |
650 eoe->tries--; // try again |
634 eoe->tries--; // try again |
707 |
691 |
708 /****************************************************************************** |
692 /****************************************************************************** |
709 * NET_DEVICE functions |
693 * NET_DEVICE functions |
710 *****************************************************************************/ |
694 *****************************************************************************/ |
711 |
695 |
712 /** |
696 /** Opens the virtual network device. |
713 Opens the virtual network device. |
697 */ |
714 */ |
|
715 |
|
716 int ec_eoedev_open(struct net_device *dev /**< EoE net_device */) |
698 int ec_eoedev_open(struct net_device *dev /**< EoE net_device */) |
717 { |
699 { |
718 ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev)); |
700 ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev)); |
719 ec_eoe_flush(eoe); |
701 ec_eoe_flush(eoe); |
720 eoe->opened = 1; |
702 eoe->opened = 1; |
725 return 0; |
707 return 0; |
726 } |
708 } |
727 |
709 |
728 /*****************************************************************************/ |
710 /*****************************************************************************/ |
729 |
711 |
730 /** |
712 /** Stops the virtual network device. |
731 Stops the virtual network device. |
713 */ |
732 */ |
|
733 |
|
734 int ec_eoedev_stop(struct net_device *dev /**< EoE net_device */) |
714 int ec_eoedev_stop(struct net_device *dev /**< EoE net_device */) |
735 { |
715 { |
736 ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev)); |
716 ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev)); |
737 netif_stop_queue(dev); |
717 netif_stop_queue(dev); |
738 eoe->tx_queue_active = 0; |
718 eoe->tx_queue_active = 0; |
743 return 0; |
723 return 0; |
744 } |
724 } |
745 |
725 |
746 /*****************************************************************************/ |
726 /*****************************************************************************/ |
747 |
727 |
748 /** |
728 /** Transmits data via the virtual network device. |
749 Transmits data via the virtual network device. |
729 */ |
750 */ |
|
751 |
|
752 int ec_eoedev_tx(struct sk_buff *skb, /**< transmit socket buffer */ |
730 int ec_eoedev_tx(struct sk_buff *skb, /**< transmit socket buffer */ |
753 struct net_device *dev /**< EoE net_device */ |
731 struct net_device *dev /**< EoE net_device */ |
754 ) |
732 ) |
755 { |
733 { |
756 ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev)); |
734 ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev)); |
793 return 0; |
771 return 0; |
794 } |
772 } |
795 |
773 |
796 /*****************************************************************************/ |
774 /*****************************************************************************/ |
797 |
775 |
798 /** |
776 /** Gets statistics about the virtual network device. |
799 Gets statistics about the virtual network device. |
777 */ |
800 */ |
778 struct net_device_stats *ec_eoedev_stats( |
801 |
779 struct net_device *dev /**< EoE net_device */ |
802 struct net_device_stats *ec_eoedev_stats(struct net_device *dev |
780 ) |
803 /**< EoE net_device */) |
|
804 { |
781 { |
805 ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev)); |
782 ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev)); |
806 return &eoe->stats; |
783 return &eoe->stats; |
807 } |
784 } |
808 |
785 |