fp@39: /****************************************************************************** fp@0: * fp@39: * $Id$ fp@0: * fp@1326: * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH fp@197: * fp@197: * This file is part of the IgH EtherCAT Master. fp@197: * fp@1326: * The IgH EtherCAT Master is free software; you can redistribute it and/or fp@1326: * modify it under the terms of the GNU General Public License version 2, as fp@1326: * published by the Free Software Foundation. fp@197: * fp@1326: * The IgH EtherCAT Master is distributed in the hope that it will be useful, fp@1326: * but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1326: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General fp@1326: * Public License for more details. fp@197: * fp@1326: * You should have received a copy of the GNU General Public License along fp@1326: * with the IgH EtherCAT Master; if not, write to the Free Software fp@197: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@197: * fp@1363: * --- fp@1363: * fp@1363: * The license mentioned above concerns the source code only. Using the fp@1363: * EtherCAT technology and brand is only permitted in compliance with the fp@1363: * industrial property and similar rights of Beckhoff Automation GmbH. fp@246: * fp@39: *****************************************************************************/ fp@0: fp@199: /** fp@199: \file fp@199: EtherCAT device structure. fp@199: */ fp@199: fp@199: /*****************************************************************************/ fp@199: fp@883: #ifndef __EC_DEVICE_H__ fp@883: #define __EC_DEVICE_H__ fp@0: fp@25: #include fp@25: fp@104: #include "../devices/ecdev.h" fp@54: #include "globals.h" fp@392: fp@758: /** fp@758: * Size of the transmit ring. fp@758: * This memory ring is used to transmit frames. It is necessary to use fp@758: * different memory regions, because otherwise the network device DMA could fp@758: * send the same data twice, if it is called twice. fp@758: */ fp@693: #define EC_TX_RING_SIZE 2 fp@693: fp@679: #ifdef EC_DEBUG_IF fp@231: #include "debug.h" fp@392: #endif fp@0: fp@692: #ifdef EC_DEBUG_RING fp@692: #define EC_DEBUG_RING_SIZE 10 fp@692: fp@692: typedef enum { fp@692: TX, RX fp@692: } ec_debug_frame_dir_t; fp@692: fp@692: typedef struct { fp@692: ec_debug_frame_dir_t dir; fp@692: struct timeval t; fp@692: unsigned int addr; fp@692: uint8_t data[EC_MAX_DATA_SIZE]; fp@692: unsigned int data_size; fp@692: } ec_debug_frame_t; fp@692: fp@692: #endif fp@692: fp@39: /*****************************************************************************/ fp@0: fp@0: /** fp@195: EtherCAT device. fp@195: An EtherCAT device is a network interface card, that is owned by an fp@195: EtherCAT master to send and receive EtherCAT frames with. fp@0: */ fp@0: fp@54: struct ec_device fp@0: { fp@195: ec_master_t *master; /**< EtherCAT master */ fp@195: struct net_device *dev; /**< pointer to the assigned net_device */ fp@579: ec_pollfunc_t poll; /**< pointer to the device's poll function */ fp@579: struct module *module; /**< pointer to the device's owning module */ fp@195: uint8_t open; /**< true, if the net_device has been opened */ fp@579: uint8_t link_state; /**< device link state */ fp@693: struct sk_buff *tx_skb[EC_TX_RING_SIZE]; /**< transmit skb ring */ fp@758: unsigned int tx_ring_index; /**< last ring entry used to transmit */ fp@1040: #ifdef EC_HAVE_CYCLES fp@533: cycles_t cycles_poll; /**< cycles of last poll */ fp@1040: #endif fp@692: #ifdef EC_DEBUG_RING fp@692: struct timeval timeval_poll; fp@692: #endif fp@533: unsigned long jiffies_poll; /**< jiffies of last poll */ fp@1854: fp@1854: // Frame statistics fp@1854: unsigned int tx_count; /**< Number of frames sent. */ fp@1854: unsigned int rx_count; /**< Number of frames received. */ fp@1857: unsigned int tx_bytes; /**< Number of frames sent. */ fp@1857: unsigned int tx_errors; /**< Number of transmit errors. */ fp@1857: unsigned int tx_frame_rates[EC_RATE_COUNT]; /**< Transmit rates in fp@1857: frames/s for different fp@1857: statistics cycle periods. */ fp@1857: unsigned int tx_byte_rates[EC_RATE_COUNT]; /**< Transmit rates in byte/s fp@1857: for different statistics fp@1857: cycle periods. */ fp@1854: unsigned int last_tx_count; /**< Number of frames sent of last statistics fp@1854: cycle. */ fp@1857: unsigned int last_tx_bytes; /**< Number of bytes sent of last statistics fp@1857: cycle. */ fp@1854: int last_loss; /**< Tx/Rx difference of last statistics cycle. */ fp@1854: int loss_rates[EC_RATE_COUNT]; /**< Frame loss rates for different fp@1854: statistics cycle periods. */ fp@1854: unsigned long stats_jiffies; /**< Jiffies of last statistic cycle. */ fp@1854: fp@679: #ifdef EC_DEBUG_IF fp@231: ec_debug_t dbg; /**< debug device */ fp@392: #endif fp@692: #ifdef EC_DEBUG_RING fp@692: ec_debug_frame_t debug_frames[EC_DEBUG_RING_SIZE]; fp@692: unsigned int debug_frame_index; fp@692: unsigned int debug_frame_count; fp@692: #endif fp@54: }; fp@0: fp@39: /*****************************************************************************/ fp@0: fp@579: int ec_device_init(ec_device_t *, ec_master_t *); fp@54: void ec_device_clear(ec_device_t *); fp@78: fp@579: void ec_device_attach(ec_device_t *, struct net_device *, ec_pollfunc_t, fp@579: struct module *); fp@579: void ec_device_detach(ec_device_t *); fp@579: fp@54: int ec_device_open(ec_device_t *); fp@54: int ec_device_close(ec_device_t *); fp@78: fp@533: void ec_device_poll(ec_device_t *); fp@98: uint8_t *ec_device_tx_data(ec_device_t *); fp@78: void ec_device_send(ec_device_t *, size_t); fp@1856: void ec_device_clear_stats(ec_device_t *); fp@78: fp@692: #ifdef EC_DEBUG_RING fp@692: void ec_device_debug_ring_append(ec_device_t *, ec_debug_frame_dir_t, fp@692: const void *, size_t); fp@692: void ec_device_debug_ring_print(const ec_device_t *); fp@692: #endif fp@692: fp@39: /*****************************************************************************/ fp@0: fp@0: #endif