devices/ccat/module.h
branchstable-1.5
changeset 2550 7e25950ea941
parent 2549 933a1b36b05f
child 2551 000da5069f1a
equal deleted inserted replaced
2549:933a1b36b05f 2550:7e25950ea941
     1 ../../../ccat/module.h
     1 /**
       
     2     Network Driver for Beckhoff CCAT communication controller
       
     3     Copyright (C) 2014  Beckhoff Automation GmbH
       
     4     Author: Patrick Bruenn <p.bruenn@beckhoff.com>
       
     5 
       
     6     This program is free software; you can redistribute it and/or modify
       
     7     it under the terms of the GNU General Public License as published by
       
     8     the Free Software Foundation; either version 2 of the License, or
       
     9     (at your option) any later version.
       
    10 
       
    11     This program is distributed in the hope that it will be useful,
       
    12     but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    14     GNU General Public License for more details.
       
    15 
       
    16     You should have received a copy of the GNU General Public License along
       
    17     with this program; if not, write to the Free Software Foundation, Inc.,
       
    18     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
       
    19 */
       
    20 
       
    21 #ifndef _CCAT_H_
       
    22 #define _CCAT_H_
       
    23 
       
    24 #include <linux/cdev.h>
       
    25 #include <linux/kernel.h>
       
    26 #include <linux/pci.h>
       
    27 #include "CCatDefinitions.h"
       
    28 #include "../ecdev.h"
       
    29 
       
    30 #define DRV_NAME         "ec_ccat"
       
    31 #define DRV_EXTRAVERSION "-ec"
       
    32 #define DRV_VERSION      "0.7" DRV_EXTRAVERSION
       
    33 #define DRV_DESCRIPTION  "Beckhoff CCAT Ethernet/EtherCAT Network Driver"
       
    34 
       
    35 /**
       
    36  * struct ccat_bar - CCAT PCI Base Address Register(BAR) configuration
       
    37  * @start: start address of this BAR
       
    38  * @end: end address of this BAR
       
    39  * @len: length of this BAR
       
    40  * @flags: flags set on this BAR
       
    41  * @ioaddr: ioremapped address of this bar
       
    42  */
       
    43 struct ccat_bar {
       
    44 	unsigned long start;
       
    45 	unsigned long end;
       
    46 	unsigned long len;
       
    47 	unsigned long flags;
       
    48 	void __iomem *ioaddr;
       
    49 };
       
    50 
       
    51 /**
       
    52  * struct ccat_dma - CCAT DMA channel configuration
       
    53  * @phys: device-viewed address(physical) of the associated DMA memory
       
    54  * @virt: CPU-viewed address(virtual) of the associated DMA memory
       
    55  * @size: number of bytes in the associated DMA memory
       
    56  * @channel: CCAT DMA channel number
       
    57  * @dev: valid struct device pointer
       
    58  */
       
    59 struct ccat_dma {
       
    60 	dma_addr_t phys;
       
    61 	void *virt;
       
    62 	size_t size;
       
    63 	size_t channel;
       
    64 	struct device *dev;
       
    65 };
       
    66 
       
    67 extern void ccat_dma_free(struct ccat_dma *const dma);
       
    68 extern int ccat_dma_init(struct ccat_dma *const dma, size_t channel,
       
    69 			 void __iomem * const ioaddr, struct device *const dev);
       
    70 
       
    71 /**
       
    72  * struct ccat_eth_frame - Ethernet frame with DMA descriptor header in front
       
    73  * @reservedn: is not used and should always be set to 0
       
    74  * @received: used for reception, is set to 1 by the CCAT when data was written
       
    75  * @length: number of bytes in the frame including the DMA header
       
    76  * @sent: is set to 1 by the CCAT when data was transmitted
       
    77  * @timestamp: a 64 bit EtherCAT timestamp
       
    78  * @data: the bytes of the ethernet frame
       
    79  */
       
    80 struct ccat_eth_frame {
       
    81 	uint32_t reserved1;
       
    82 	uint32_t received:1;
       
    83 	uint32_t reserved2:31;
       
    84 	uint16_t length;
       
    85 	uint16_t reserved3;
       
    86 	uint32_t sent:1;
       
    87 	uint32_t reserved4:31;
       
    88 	uint64_t timestamp;
       
    89 	uint8_t data[0x800 - 3 * sizeof(uint64_t)];
       
    90 };
       
    91 
       
    92 /**
       
    93  * struct ccat_eth_register - CCAT register addresses in the PCI BAR
       
    94  * @mii: address of the CCAT management interface register
       
    95  * @tx_fifo: address of the CCAT TX DMA fifo register
       
    96  * @rx_fifo: address of the CCAT RX DMA fifo register
       
    97  * @mac: address of the CCAT media access control register
       
    98  * @rx_mem: address of the CCAT register holding the RX DMA address
       
    99  * @tx_mem: address of the CCAT register holding the TX DMA address
       
   100  * @misc: address of a CCAT register holding miscellaneous information
       
   101  */
       
   102 struct ccat_eth_register {
       
   103 	void __iomem *mii;
       
   104 	void __iomem *tx_fifo;
       
   105 	void __iomem *rx_fifo;
       
   106 	void __iomem *mac;
       
   107 	void __iomem *rx_mem;
       
   108 	void __iomem *tx_mem;
       
   109 	void __iomem *misc;
       
   110 };
       
   111 
       
   112 /**
       
   113  * struct ccat_eth_dma_fifo - CCAT RX or TX DMA fifo
       
   114  * @add: callback used to add a frame to this fifo
       
   115  * @reg: PCI register address of this DMA fifo
       
   116  * @dma: information about the associated DMA memory
       
   117  */
       
   118 struct ccat_eth_dma_fifo {
       
   119 	void (*add) (struct ccat_eth_frame *, struct ccat_eth_dma_fifo *);
       
   120 	void __iomem *reg;
       
   121 	struct ccat_dma dma;
       
   122 };
       
   123 
       
   124 /**
       
   125  * struct ccat_device - CCAT device representation
       
   126  * @pdev: pointer to the pci object allocated by the kernel
       
   127  * @ethdev: CCAT Ethernet/EtherCAT Master (with DMA) function, NULL if function is not available or failed to initialize
       
   128  * @update: CCAT Update function, NULL if function is not available or failed to initialize
       
   129  * @bar [0] and [2] holding information about PCI BARs 0 and 2.
       
   130  *
       
   131  * One instance of a ccat_device should represent a physical CCAT. Since
       
   132  * a CCAT is implemented as FPGA the available functions can vary so
       
   133  * the function object pointers can be NULL.
       
   134  * Extra note: you will recognize that PCI BAR1 is not used and is a
       
   135  * waste of memory, thats true but right now, its very easy to use it
       
   136  * this way. So we might optimize it later.
       
   137  */
       
   138 struct ccat_device {
       
   139 	struct pci_dev *pdev;
       
   140 	struct ccat_eth_priv *ethdev;
       
   141 	struct ccat_update *update;
       
   142 	struct ccat_bar bar[3];	//TODO optimize this
       
   143 };
       
   144 
       
   145 /**
       
   146  * struct ccat_eth_priv - CCAT Ethernet/EtherCAT Master function (netdev)
       
   147  * @ccatdev: pointer to the parent struct ccat_device
       
   148  * @netdev: the net_device structure used by the kernel networking stack
       
   149  * @poll_thread: is used to poll status registers like link state
       
   150  * @rx_thread: thread which does housekeeping of RX DMA descriptors
       
   151  * @tx_thread: thread which does housekeeping of TX DMA descriptors
       
   152  * @next_tx_frame: pointer to the next TX DMA descriptor, which the tx_thread should check for availablity
       
   153  * @info: holds a copy of the CCAT Ethernet/EtherCAT Master function information block (read from PCI config space)
       
   154  * @reg: register addresses in PCI config space of the Ethernet/EtherCAT Master function
       
   155  * @rx_fifo: DMA fifo used for RX DMA descriptors
       
   156  * @tx_fifo: DMA fifo used for TX DMA descriptors
       
   157  * @rx_bytes: number of bytes received -> reported with ndo_get_stats64()
       
   158  * @rx_dropped: number of received frames, which were dropped -> reported with ndo_get_stats64()
       
   159  * @tx_bytes: number of bytes send -> reported with ndo_get_stats64()
       
   160  * @tx_dropped: number of frames requested to send, which were dropped -> reported with ndo_get_stats64()
       
   161  */
       
   162 struct ccat_eth_priv {
       
   163 	const struct ccat_device *ccatdev;
       
   164 	struct net_device *netdev;
       
   165 	struct task_struct *poll_thread;
       
   166 	struct task_struct *rx_thread;
       
   167 	struct task_struct *tx_thread;
       
   168 	const struct ccat_eth_frame *next_tx_frame;	/* next frame the tx_thread should check for availability */
       
   169 	CCatInfoBlock info;
       
   170 	struct ccat_eth_register reg;
       
   171 	struct ccat_eth_dma_fifo rx_fifo;
       
   172 	struct ccat_eth_dma_fifo tx_fifo;
       
   173 	atomic64_t rx_bytes;
       
   174 	atomic64_t rx_dropped;
       
   175 	atomic64_t tx_bytes;
       
   176 	atomic64_t tx_dropped;
       
   177 	ec_device_t *ecdev;
       
   178 	void (*carrier_off) (struct net_device * const netdev);
       
   179 	void (*carrier_on) (struct net_device * const netdev);
       
   180 	void (*kfree_skb_any) (struct sk_buff * skb);
       
   181 	void (*start_queue) (struct net_device * const netdev);
       
   182 	void (*stop_queue) (struct net_device * const netdev);
       
   183 	void (*tx_fifo_full) (struct net_device * const dev,
       
   184 			      const struct ccat_eth_frame * const frame);
       
   185 	void (*unregister) (struct net_device * const netdev);
       
   186 };
       
   187 
       
   188 /**
       
   189  * struct ccat_update - CCAT Update function (update)
       
   190  * @ccatdev: pointer to the parent struct ccat_device
       
   191  * @ioaddr: PCI base address of the CCAT Update function
       
   192  * dev: device number for this update function
       
   193  * cdev: character device used for the CCAT Update function
       
   194  * class: pointer to a device class used when registering the CCAT Update device
       
   195  * @info: holds a copy of the CCAT Update function information block (read from PCI config space)
       
   196  */
       
   197 struct ccat_update {
       
   198 	struct kref refcount;
       
   199 	void __iomem *ioaddr;
       
   200 	dev_t dev;
       
   201 	struct cdev cdev;
       
   202 	struct class *class;
       
   203 	CCatInfoBlock info;
       
   204 };
       
   205 #endif /* #ifndef _CCAT_H_ */