Driver for Beckhoff CX5020 EtherCAT master module.
Subsystems (2)
PATCH v2 1/1 Driver for Beckhoff CX5020 EtherCAT master module.
Changes since v1:
* added endianess annotation to descriptors' structures
* killed checkpath warnings about string literals being split into multiple lines
Quoted 1 line
8----------------------------------------8<
This driver adds support for EtherCAT master module located on CCAT FPGA found on Beckhoff CX series industrail PCs. The driver exposes EtherCAT master as an ethernet interface.
EtherCAT is a filedbus protocol defined on top of ethernet and Beckhoff CX5020 PCs come with built-in EtherCAT master module located on a FPGA, which in turn is connected to a PCI bus.
--- drivers/net/ethernet/Kconfig | 11 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/ec_bh.c | 768 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 780 insertions(+) create mode 100644 drivers/net/ethernet/ec_bh.c
drivers/net/ethernet/Kconfig +11 -0
@@ -35,6 +35,17 @@ source "drivers/net/ethernet/calxeda/Kconfig" source "drivers/net/ethernet/chelsio/Kconfig" source "drivers/net/ethernet/cirrus/Kconfig" source "drivers/net/ethernet/cisco/Kconfig" + +config CX_ECAT + tristate "Beckhoff CX5020 EtherCAT master support" + ---help--- + Driver for EtherCAT master module located on CCAT FPGA + that can be found on Beckhoff CX5020, and possibly other of CX + Beckhoff CX series industrial PCs. + + To compile this driver as a module, choose M here. The module + will be called ec_bh. + source "drivers/net/ethernet/davicom/Kconfig" config DNET
drivers/net/ethernet/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_NET_CALXEDA_XGMAC) += calxeda/ obj-$(CONFIG_NET_VENDOR_CHELSIO) += chelsio/ obj-$(CONFIG_NET_VENDOR_CIRRUS) += cirrus/ obj-$(CONFIG_NET_VENDOR_CISCO) += cisco/ +obj-$(CONFIG_CX_ECAT) += ec_bh.o obj-$(CONFIG_DM9000) += davicom/ obj-$(CONFIG_DNET) += dnet.o obj-$(CONFIG_NET_VENDOR_DEC) += dec/
drivers/net/ethernet/ec_bh.c new file +768 -0
768 lines not on this page · raw message
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Darek Marcinkiewicz <[email protected]>
Date: Mon, 28 Apr 2014 07:36:58 +0200
Quoted 14 lines
drivers/net/ethernet/ec_bh.c new file +14
-0+void *ec_bh_alloc_dma_mem (struct bh_priv *priv, +int channel, +u8 **buf, +dma_addr_t *phys, +dma_addr_t *phys_buf, +size_t *len) { +u32 mask; +int offset = channel *DMA_CHAN_SIZE +DMA_CHAN_OFFSET ; + +iowrite32 (0xffffffff , priv->dma_io + offset); + + mask =ioread32 (priv->dma_io + offset); + mask &=0xfffffffc ; + dev_info(PRIV_TO_DEV(priv),
drivers/net/ethernet/ec_bh.c line 481
Quoted 10 lines
drivers/net/ethernet/ec_bh.c new file +10
-0+"Read mask %x for channel %d\n" , + mask, channel); + *len = ~mask +1 ; + +dev_info (PRIV_TO_DEV (priv), +"Allocating %d bytes for channel %d" , + (int )*len, channel); + *buf =pci_alloc_consistent (priv->dev, + *len *2 , + phys_buf);
This is really confusing, the log message says that it allocates "*len" bytes, but actually you are allocating "*len * 2" bytes as per the arguments you are passing into pci_alloc_consistent.
Either one or the other is wrong, and if "*len * 2" is the correct size then it should be explained why you're doubling this value but providing just plain "*len" to the caller.
All of these *len values seem to be doubled over and over again, in the memset() calls, in the pci_free_consistent() calls during resource release on probe error and driver shutdown.
Why not just assign X * 2 to *len and get rid of this doubling all over the place?
Quoted 36 lines · David Miller
From: Darek Marcinkiewicz <[email protected]>
Date: Mon, 28 Apr 2014 07:36:58 +0200Quoted 14 lines
drivers/net/ethernet/ec_bh.c new file +14
-0+void *ec_bh_alloc_dma_mem (struct bh_priv *priv, +int channel, +u8 **buf, +dma_addr_t *phys, +dma_addr_t *phys_buf, +size_t *len) { +u32 mask; +int offset = channel *DMA_CHAN_SIZE +DMA_CHAN_OFFSET ; + +iowrite32 (0xffffffff , priv->dma_io + offset); + + mask =ioread32 (priv->dma_io + offset); + mask &=0xfffffffc ; + dev_info(PRIV_TO_DEV(priv),drivers/net/ethernet/ec_bh.c line 481
Quoted 10 lines
drivers/net/ethernet/ec_bh.c new file +10
-0+"Read mask %x for channel %d\n" , + mask, channel); + *len = ~mask +1 ; + +dev_info (PRIV_TO_DEV (priv), +"Allocating %d bytes for channel %d" , + (int )*len, channel); + *buf =pci_alloc_consistent (priv->dev, + *len *2 , + phys_buf);This is really confusing, the log message says that it allocates "*len" bytes, but actually you are allocating "*len * 2" bytes as per the arguments you are passing into
pci_alloc_consistent.Either one or the other is wrong, and if "*len * 2" is the correct size then it should be explained why you're doubling this value but providing just plain "*len" to the caller.
Quoted 7 lines
All of these *len values seem to be doubled over and over again, in the
memset()calls, in thepci_free_consistent()calls during resource release on probe error and driver shutdown.Why not just assign X * 2 to *len and get rid of this doubling all over the place?
This device imposes some limitations on location and size of the buffers that it dma data from/to. It has a "mask" parameter saying two things:
1. RX/TX buffers have to be aligned to "mask" bits.
2. Their max size is 2^mask.
In order to have a buffer meeting above criteria driver allocates chunk of size 2 * max buffer size, and half of this chunk gets used later on. So, len here is the size of that aligned buffer, whereas 2 * len is how much memory was actually allocated.
So, yes, this is a little bit confusing. I'll try to clean this up a little bit and send updated patch.
Thank you!
Signature · 1 line
DM