p@2550: /**
p@2550: Network Driver for Beckhoff CCAT communication controller
p@2550: Copyright (C) 2014 Beckhoff Automation GmbH
p@2550: Author: Patrick Bruenn
p@2550:
p@2550: This program is free software; you can redistribute it and/or modify
p@2550: it under the terms of the GNU General Public License as published by
p@2550: the Free Software Foundation; either version 2 of the License, or
p@2550: (at your option) any later version.
p@2550:
p@2550: This program is distributed in the hope that it will be useful,
p@2550: but WITHOUT ANY WARRANTY; without even the implied warranty of
p@2550: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
p@2550: GNU General Public License for more details.
p@2550:
p@2550: You should have received a copy of the GNU General Public License along
p@2550: with this program; if not, write to the Free Software Foundation, Inc.,
p@2550: 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
p@2550: */
p@2550:
p@2550: #ifndef _CCAT_H_
p@2550: #define _CCAT_H_
p@2550:
p@2550: #include
p@2636: #include
p@2567: #include
p@2550: #include
p@2550: #include
p@2550: #include "../ecdev.h"
p@2550:
p@2550: #define DRV_EXTRAVERSION "-ec"
p@2654: #define DRV_VERSION "0.15" DRV_EXTRAVERSION
p@2550: #define DRV_DESCRIPTION "Beckhoff CCAT Ethernet/EtherCAT Network Driver"
p@2550:
p@2551: #undef pr_fmt
p@2551: #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
p@2551:
p@2638: extern const struct ccat_driver eth_eim_driver;
p@2638: extern const struct ccat_driver eth_dma_driver;
fp@2684: #ifdef CONFIG_GPIO
p@2638: extern const struct ccat_driver gpio_driver;
fp@2684: #endif
p@2638: extern const struct ccat_driver sram_driver;
p@2638: extern const struct ccat_driver update_driver;
p@2636:
fp@2684:
p@2550: /**
p@2569: * CCAT function type identifiers (u16)
p@2569: */
p@2569: enum ccat_info_t {
p@2569: CCATINFO_NOTUSED = 0,
p@2636: CCATINFO_ETHERCAT_NODMA = 0x3,
p@2636: CCATINFO_GPIO = 0xd,
p@2569: CCATINFO_EPCS_PROM = 0xf,
p@2569: CCATINFO_ETHERCAT_MASTER_DMA = 0x14,
p@2636: CCATINFO_SRAM = 0x16,
p@2636: };
p@2636:
p@2636: struct ccat_cdev {
p@2636: atomic_t in_use;
p@2636: void __iomem *ioaddr;
p@2636: size_t iosize;
p@2636: dev_t dev;
p@2636: struct cdev cdev;
p@2636: struct ccat_class *class;
p@2569: };
p@2569:
p@2569: /**
p@2636: * struct cdev_buffer
p@2636: * @ccdev: referenced character device
p@2636: * @data: buffer used for write operations
p@2636: * @size: number of bytes written to the data buffer
p@2550: */
p@2636: struct cdev_buffer {
p@2636: struct ccat_cdev *ccdev;
p@2636: size_t size;
p@2636: char data[];
p@2550: };
p@2550:
p@2636: extern int ccat_cdev_open(struct inode *const i, struct file *const f);
p@2636: extern int ccat_cdev_release(struct inode *const i, struct file *const f);
p@2550:
p@2550: /**
p@2550: * struct ccat_device - CCAT device representation
p@2550: * @pdev: pointer to the pci object allocated by the kernel
p@2636: * @bar_0: holding information about PCI BAR 0
p@2636: * @bar_2: holding information about PCI BAR 2 (optional)
p@2636: * @functions: list of available (driver loaded) FPGA functions
p@2550: *
p@2550: * One instance of a ccat_device should represent a physical CCAT. Since
p@2636: * a CCAT is implemented as FPGA the available functions can vary.
p@2550: */
p@2550: struct ccat_device {
p@2636: void *pdev;
p@2636: void __iomem *bar_0;
p@2636: void __iomem *bar_2;
p@2636: struct list_head functions;
p@2550: };
p@2550:
p@2573: struct ccat_info_block {
p@2569: u16 type;
p@2569: u16 rev;
p@2569: union {
p@2569: u32 config;
p@2636: u8 num_gpios;
p@2636: struct {
p@2636: u16 tx_size;
p@2636: u16 rx_size;
p@2636: };
p@2569: struct {
p@2569: u8 tx_dma_chan;
p@2569: u8 rx_dma_chan;
p@2569: };
p@2636: struct {
p@2636: u8 sram_width;
p@2636: u8 sram_size;
p@2636: u16 reserved;
p@2636: };
p@2569: };
p@2569: u32 addr;
p@2569: u32 size;
p@2569: };
p@2569:
p@2636: struct ccat_function {
p@2636: const struct ccat_driver *drv;
p@2636: struct ccat_device *ccat;
p@2569: struct ccat_info_block info;
p@2636: struct list_head list;
p@2636: void *private_data;
p@2550: };
p@2550:
p@2636: struct ccat_class {
p@2636: dev_t dev;
p@2636: struct class *class;
p@2636: atomic_t instances;
p@2636: const unsigned count;
p@2636: struct ccat_cdev *devices;
p@2636: const char *name;
p@2636: struct file_operations fops;
p@2573: };
p@2573:
p@2636: extern void ccat_cdev_remove(struct ccat_function *func);
p@2636: extern int ccat_cdev_probe(struct ccat_function *func,
p@2636: struct ccat_class *cdev_class, size_t iosize);
p@2636:
p@2636: /**
p@2636: * struct ccat_driver - CCAT FPGA function
p@2636: * @probe: add device instance
p@2636: * @remove: remove device instance
p@2636: * @type: type of the FPGA function supported by this driver
p@2636: * @cdev_class: if not NULL that driver supports ccat_class_init()/_exit()
p@2636: */
p@2636: struct ccat_driver {
p@2636: int (*probe) (struct ccat_function * func);
p@2636: void (*remove) (struct ccat_function * drv);
p@2636: enum ccat_info_t type;
p@2636: struct ccat_class *cdev_class;
p@2569: };
p@2569:
p@2550: #endif /* #ifndef _CCAT_H_ */