devices/ccat/module.h
branchstable-1.5
changeset 2579 273d15e0f301
parent 2578 d707b650fa52
child 2636 0613017547fe
equal deleted inserted replaced
2564:976381a3bd9e 2579:273d15e0f301
    20 
    20 
    21 #ifndef _CCAT_H_
    21 #ifndef _CCAT_H_
    22 #define _CCAT_H_
    22 #define _CCAT_H_
    23 
    23 
    24 #include <linux/cdev.h>
    24 #include <linux/cdev.h>
       
    25 #include <linux/hrtimer.h>
    25 #include <linux/kernel.h>
    26 #include <linux/kernel.h>
    26 #include <linux/pci.h>
    27 #include <linux/pci.h>
    27 #include "CCatDefinitions.h"
       
    28 #include "../ecdev.h"
    28 #include "../ecdev.h"
    29 
    29 
    30 #define DRV_NAME         "ec_ccat"
       
    31 #define DRV_EXTRAVERSION "-ec"
    30 #define DRV_EXTRAVERSION "-ec"
    32 #define DRV_VERSION      "0.8" DRV_EXTRAVERSION
    31 #define DRV_VERSION      "0.10" DRV_EXTRAVERSION
    33 #define DRV_DESCRIPTION  "Beckhoff CCAT Ethernet/EtherCAT Network Driver"
    32 #define DRV_DESCRIPTION  "Beckhoff CCAT Ethernet/EtherCAT Network Driver"
    34 
    33 
    35 #undef pr_fmt
    34 #undef pr_fmt
    36 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
    35 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
       
    36 
       
    37 /**
       
    38  * CCAT function type identifiers (u16)
       
    39  */
       
    40 enum ccat_info_t {
       
    41 	CCATINFO_NOTUSED = 0,
       
    42 	CCATINFO_EPCS_PROM = 0xf,
       
    43 	CCATINFO_ETHERCAT_MASTER_DMA = 0x14,
       
    44 	CCATINFO_COPY_BLOCK = 0x17,
       
    45 	CCATINFO_MAX
       
    46 };
    37 
    47 
    38 /**
    48 /**
    39  * struct ccat_bar - CCAT PCI Base Address Register(BAR) configuration
    49  * struct ccat_bar - CCAT PCI Base Address Register(BAR) configuration
    40  * @start: start address of this BAR
    50  * @start: start address of this BAR
    41  * @end: end address of this BAR
    51  * @end: end address of this BAR
    79  * @sent: is set to 1 by the CCAT when data was transmitted
    89  * @sent: is set to 1 by the CCAT when data was transmitted
    80  * @timestamp: a 64 bit EtherCAT timestamp
    90  * @timestamp: a 64 bit EtherCAT timestamp
    81  * @data: the bytes of the ethernet frame
    91  * @data: the bytes of the ethernet frame
    82  */
    92  */
    83 struct ccat_eth_frame {
    93 struct ccat_eth_frame {
    84 	uint32_t reserved1;
    94 	__le32 reserved1;
    85 	uint32_t received:1;
    95 	__le32 rx_flags;
    86 	uint32_t reserved2:31;
    96 #define CCAT_FRAME_RECEIVED 0x1
    87 	uint16_t length;
    97 	__le16 length;
    88 	uint16_t reserved3;
    98 	__le16 reserved3;
    89 	uint32_t sent:1;
    99 	__le32 tx_flags;
    90 	uint32_t reserved4:31;
   100 #define CCAT_FRAME_SENT 0x1
    91 	uint64_t timestamp;
   101 	__le64 timestamp;
    92 	uint8_t data[0x800 - 3 * sizeof(uint64_t)];
   102 	u8 data[0x800 - 3 * sizeof(u64)];
       
   103 #define CCAT_ETH_FRAME_HEAD_LEN offsetof(struct ccat_eth_frame, data)
    93 };
   104 };
    94 
   105 
    95 /**
   106 /**
    96  * struct ccat_eth_register - CCAT register addresses in the PCI BAR
   107  * struct ccat_eth_register - CCAT register addresses in the PCI BAR
    97  * @mii: address of the CCAT management interface register
   108  * @mii: address of the CCAT management interface register
   117  * @add: callback used to add a frame to this fifo
   128  * @add: callback used to add a frame to this fifo
   118  * @reg: PCI register address of this DMA fifo
   129  * @reg: PCI register address of this DMA fifo
   119  * @dma: information about the associated DMA memory
   130  * @dma: information about the associated DMA memory
   120  */
   131  */
   121 struct ccat_eth_dma_fifo {
   132 struct ccat_eth_dma_fifo {
   122 	void (*add) (struct ccat_eth_frame *, struct ccat_eth_dma_fifo *);
   133 	void (*add) (struct ccat_eth_dma_fifo *, struct ccat_eth_frame *);
   123 	void __iomem *reg;
   134 	void __iomem *reg;
       
   135 	const struct ccat_eth_frame *end;
       
   136 	struct ccat_eth_frame *next;
   124 	struct ccat_dma dma;
   137 	struct ccat_dma dma;
   125 };
   138 };
   126 
   139 
   127 /**
   140 /**
   128  * struct ccat_device - CCAT device representation
   141  * struct ccat_device - CCAT device representation
   143 	struct ccat_eth_priv *ethdev;
   156 	struct ccat_eth_priv *ethdev;
   144 	struct ccat_update *update;
   157 	struct ccat_update *update;
   145 	struct ccat_bar bar[3];	//TODO optimize this
   158 	struct ccat_bar bar[3];	//TODO optimize this
   146 };
   159 };
   147 
   160 
       
   161 struct ccat_info_block {
       
   162 	u16 type;
       
   163 	u16 rev;
       
   164 	union {
       
   165 		u32 config;
       
   166 		struct {
       
   167 			u8 tx_dma_chan;
       
   168 			u8 rx_dma_chan;
       
   169 		};
       
   170 	};
       
   171 	u32 addr;
       
   172 	u32 size;
       
   173 };
       
   174 
   148 /**
   175 /**
   149  * struct ccat_eth_priv - CCAT Ethernet/EtherCAT Master function (netdev)
   176  * struct ccat_eth_priv - CCAT Ethernet/EtherCAT Master function (netdev)
   150  * @ccatdev: pointer to the parent struct ccat_device
   177  * @ccatdev: pointer to the parent struct ccat_device
   151  * @netdev: the net_device structure used by the kernel networking stack
   178  * @netdev: the net_device structure used by the kernel networking stack
   152  * @poll_thread: is used to poll status registers like link state
       
   153  * @rx_thread: thread which does housekeeping of RX DMA descriptors
       
   154  * @tx_thread: thread which does housekeeping of TX DMA descriptors
       
   155  * @next_tx_frame: pointer to the next TX DMA descriptor, which the tx_thread should check for availablity
       
   156  * @info: holds a copy of the CCAT Ethernet/EtherCAT Master function information block (read from PCI config space)
   179  * @info: holds a copy of the CCAT Ethernet/EtherCAT Master function information block (read from PCI config space)
   157  * @reg: register addresses in PCI config space of the Ethernet/EtherCAT Master function
   180  * @reg: register addresses in PCI config space of the Ethernet/EtherCAT Master function
   158  * @rx_fifo: DMA fifo used for RX DMA descriptors
   181  * @rx_fifo: DMA fifo used for RX DMA descriptors
   159  * @tx_fifo: DMA fifo used for TX DMA descriptors
   182  * @tx_fifo: DMA fifo used for TX DMA descriptors
       
   183  * @poll_timer: interval timer used to poll CCAT for events like link changed, rx done, tx done
   160  * @rx_bytes: number of bytes received -> reported with ndo_get_stats64()
   184  * @rx_bytes: number of bytes received -> reported with ndo_get_stats64()
   161  * @rx_dropped: number of received frames, which were dropped -> reported with ndo_get_stats64()
   185  * @rx_dropped: number of received frames, which were dropped -> reported with ndo_get_stats64()
   162  * @tx_bytes: number of bytes send -> reported with ndo_get_stats64()
   186  * @tx_bytes: number of bytes send -> reported with ndo_get_stats64()
   163  * @tx_dropped: number of frames requested to send, which were dropped -> reported with ndo_get_stats64()
   187  * @tx_dropped: number of frames requested to send, which were dropped -> reported with ndo_get_stats64()
   164  */
   188  */
   165 struct ccat_eth_priv {
   189 struct ccat_eth_priv {
   166 	const struct ccat_device *ccatdev;
   190 	const struct ccat_device *ccatdev;
   167 	struct net_device *netdev;
   191 	struct net_device *netdev;
   168 	struct task_struct *poll_thread;
   192 	struct ccat_info_block info;
   169 	struct task_struct *rx_thread;
       
   170 	struct task_struct *tx_thread;
       
   171 	const struct ccat_eth_frame *next_tx_frame;	/* next frame the tx_thread should check for availability */
       
   172 	CCatInfoBlock info;
       
   173 	struct ccat_eth_register reg;
   193 	struct ccat_eth_register reg;
   174 	struct ccat_eth_dma_fifo rx_fifo;
   194 	struct ccat_eth_dma_fifo rx_fifo;
   175 	struct ccat_eth_dma_fifo tx_fifo;
   195 	struct ccat_eth_dma_fifo tx_fifo;
       
   196 	struct hrtimer poll_timer;
   176 	atomic64_t rx_bytes;
   197 	atomic64_t rx_bytes;
   177 	atomic64_t rx_dropped;
   198 	atomic64_t rx_dropped;
   178 	atomic64_t tx_bytes;
   199 	atomic64_t tx_bytes;
   179 	atomic64_t tx_dropped;
   200 	atomic64_t tx_dropped;
   180 	ec_device_t *ecdev;
   201 	ec_device_t *ecdev;
   181 	void (*carrier_off) (struct net_device * const netdev);
   202 	void (*carrier_off) (struct net_device * netdev);
   182 	void (*carrier_on) (struct net_device * const netdev);
   203 	bool (*carrier_ok) (const struct net_device * netdev);
       
   204 	void (*carrier_on) (struct net_device * netdev);
   183 	void (*kfree_skb_any) (struct sk_buff * skb);
   205 	void (*kfree_skb_any) (struct sk_buff * skb);
   184 	void (*start_queue) (struct net_device * const netdev);
   206 	void (*start_queue) (struct net_device * netdev);
   185 	void (*stop_queue) (struct net_device * const netdev);
   207 	void (*stop_queue) (struct net_device * netdev);
   186 	void (*tx_fifo_full) (struct net_device * const dev,
   208 	void (*unregister) (struct net_device * netdev);
   187 			      const struct ccat_eth_frame * const frame);
   209 };
   188 	void (*unregister) (struct net_device * const netdev);
   210 
       
   211 /**
       
   212  * same as: typedef struct _CCatInfoBlockOffs from CCatDefinitions.h
       
   213  * TODO add some checking facility outside of the linux tree
       
   214  */
       
   215 struct ccat_mac_infoblock {
       
   216 	u32 reserved;
       
   217 	u32 mii;
       
   218 	u32 tx_fifo;
       
   219 	u32 mac;
       
   220 	u32 rx_mem;
       
   221 	u32 tx_mem;
       
   222 	u32 misc;
       
   223 };
       
   224 
       
   225 struct ccat_mac_register {
       
   226 	/** MAC error register     @+0x0 */
       
   227 	u8 frame_len_err;
       
   228 	u8 rx_err;
       
   229 	u8 crc_err;
       
   230 	u8 link_lost_err;
       
   231 	u32 reserved1;
       
   232 	/** Buffer overflow errors @+0x8 */
       
   233 	u8 rx_mem_full;
       
   234 	u8 reserved2[7];
       
   235 	/** MAC frame counter      @+0x10 */
       
   236 	u32 tx_frames;
       
   237 	u32 rx_frames;
       
   238 	u64 reserved3;
       
   239 	/** MAC fifo level         @+0x20 */
       
   240 	u8 tx_fifo_level:7;
       
   241 	u8 reserved4:1;
       
   242 	u8 reserved5[7];
       
   243 	/** TX memory full error   @+0x28 */
       
   244 	u8 tx_mem_full;
       
   245 	u8 reserved6[7];
       
   246 	u64 reserved8[9];
       
   247 	/** Connection             @+0x78 */
       
   248 	u8 mii_connected;
   189 };
   249 };
   190 
   250 
   191 /**
   251 /**
   192  * struct ccat_update - CCAT Update function (update)
   252  * struct ccat_update - CCAT Update function (update)
   193  * @ccatdev: pointer to the parent struct ccat_device
   253  * @ccatdev: pointer to the parent struct ccat_device
   201 	struct kref refcount;
   261 	struct kref refcount;
   202 	void __iomem *ioaddr;
   262 	void __iomem *ioaddr;
   203 	dev_t dev;
   263 	dev_t dev;
   204 	struct cdev cdev;
   264 	struct cdev cdev;
   205 	struct class *class;
   265 	struct class *class;
   206 	CCatInfoBlock info;
   266 	struct ccat_info_block info;
   207 };
   267 };
   208 #endif /* #ifndef _CCAT_H_ */
   268 #endif /* #ifndef _CCAT_H_ */