devices/ccat/netdev.c
author Edouard Tisserant <edouard.tisserant@gmail.com>
Mon, 01 Oct 2018 18:55:06 +0200
branchstable-1.5
changeset 2716 4f7421c058bb
parent 2695 ad58465e75ca
permissions -rw-r--r--
Fixed wrong xeno_lib_ldflags, missing --posix --auto-init-solib
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     1
/**
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     2
    Network Driver for Beckhoff CCAT communication controller
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
     3
    Copyright (C) 2014 - 2015  Beckhoff Automation GmbH
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     4
    Author: Patrick Bruenn <p.bruenn@beckhoff.com>
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     5
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     6
    This program is free software; you can redistribute it and/or modify
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     7
    it under the terms of the GNU General Public License as published by
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     8
    the Free Software Foundation; either version 2 of the License, or
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     9
    (at your option) any later version.
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    10
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    11
    This program is distributed in the hope that it will be useful,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    14
    GNU General Public License for more details.
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    15
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    16
    You should have received a copy of the GNU General Public License along
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    17
    with this program; if not, write to the Free Software Foundation, Inc.,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    18
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    19
*/
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    20
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    21
#include <linux/etherdevice.h>
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    22
#include <linux/kernel.h>
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    23
#include <linux/module.h>
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    24
#include <linux/netdevice.h>
2695
ad58465e75ca Applied CCAT patch 0001-fix-ccat-netdev-for-v4.11.patch from Beckhoff.
Florian Pose
parents: 2654
diff changeset
    25
#include <linux/version.h>
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    26
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    27
#ifdef CONFIG_PCI
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    28
#include <asm/dma.h>
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    29
#else
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    30
#define free_dma(X)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    31
#define request_dma(X, Y) ((int)(-EINVAL))
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    32
#endif
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    33
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    34
#include "module.h"
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    35
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    36
/**
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    37
 * EtherCAT frame to enable forwarding on EtherCAT Terminals
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    38
 */
2567
d70aad2f131f - use short kernel types, add empty lines after variable declaration to conform better with linux coding style
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2565
diff changeset
    39
static const u8 frameForwardEthernetFrames[] = {
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    40
	0x01, 0x01, 0x05, 0x01, 0x00, 0x00,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    41
	0x00, 0x1b, 0x21, 0x36, 0x1b, 0xce,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    42
	0x88, 0xa4, 0x0e, 0x10,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    43
	0x08,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    44
	0x00,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    45
	0x00, 0x00,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    46
	0x00, 0x01,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    47
	0x02, 0x00,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    48
	0x00, 0x00,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    49
	0x00, 0x00,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    50
	0x00, 0x00
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    51
};
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    52
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    53
#define FIFO_LENGTH 64
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    54
#define POLL_TIME ktime_set(0, 50 * NSEC_PER_USEC)
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
    55
#define CCAT_ALIGNMENT ((size_t)(128 * 1024))
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
    56
#define CCAT_ALIGN_CHANNEL(x, c) ((typeof(x))(ALIGN((size_t)((x) + ((c) * CCAT_ALIGNMENT)), CCAT_ALIGNMENT)))
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    57
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    58
struct ccat_dma_frame_hdr {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    59
	__le32 reserved1;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    60
	__le32 rx_flags;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    61
#define CCAT_FRAME_RECEIVED 0x1
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    62
	__le16 length;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    63
	__le16 reserved3;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    64
	__le32 tx_flags;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    65
#define CCAT_FRAME_SENT 0x1
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    66
	__le64 timestamp;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    67
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    68
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    69
struct ccat_eim_frame_hdr {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    70
	__le16 length;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    71
	__le16 reserved3;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    72
	__le32 tx_flags;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    73
	__le64 timestamp;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    74
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    75
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    76
struct ccat_eth_frame {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    77
	u8 placeholder[0x800];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    78
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    79
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    80
struct ccat_dma_frame {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    81
	struct ccat_dma_frame_hdr hdr;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    82
	u8 data[sizeof(struct ccat_eth_frame) -
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    83
		sizeof(struct ccat_dma_frame_hdr)];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    84
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    85
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    86
struct ccat_eim_frame {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    87
	struct ccat_eim_frame_hdr hdr;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    88
	u8 data[sizeof(struct ccat_eth_frame) -
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    89
		sizeof(struct ccat_eim_frame_hdr)];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    90
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    91
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    92
#define MAX_PAYLOAD_SIZE \
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    93
	(sizeof(struct ccat_eth_frame) - max(sizeof(struct ccat_dma_frame_hdr), sizeof(struct ccat_eim_frame_hdr)))
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    94
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    95
/**
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    96
 * struct ccat_eth_register - CCAT register addresses in the PCI BAR
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    97
 * @mii: address of the CCAT management interface register
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    98
 * @mac: address of the CCAT media access control register
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    99
 * @rx_mem: address of the CCAT register holding the RX DMA address
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   100
 * @tx_mem: address of the CCAT register holding the TX DMA address
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   101
 * @misc: address of a CCAT register holding miscellaneous information
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   102
 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   103
struct ccat_eth_register {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   104
	void __iomem *mii;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   105
	void __iomem *mac;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   106
	void __iomem *rx_mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   107
	void __iomem *tx_mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   108
	void __iomem *misc;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   109
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   110
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   111
/**
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   112
 * struct ccat_dma_mem - CCAT DMA channel configuration
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   113
 * @size: number of bytes in the associated DMA memory
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   114
 * @phys: device-viewed address(physical) of the associated DMA memory
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   115
 * @channel: CCAT DMA channel number
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   116
 * @dev: valid struct device pointer
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   117
 * @base: CPU-viewed address(virtual) of the associated DMA memory
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   118
 */
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   119
struct ccat_dma_mem {
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   120
	size_t size;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   121
	dma_addr_t phys;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   122
	size_t channel;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   123
	struct device *dev;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   124
	void *base;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   125
};
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   126
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   127
/**
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   128
 * struct ccat_dma/eim/mem
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   129
 * @next: pointer to the next frame in fifo ring buffer
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   130
 * @start: aligned CPU-viewed address(virtual) of the associated memory
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   131
 */
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   132
struct ccat_dma {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   133
	struct ccat_dma_frame *next;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   134
	void *start;
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   135
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   136
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   137
struct ccat_eim {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   138
	struct ccat_eim_frame __iomem *next;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   139
	void __iomem *start;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   140
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   141
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   142
struct ccat_mem {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   143
	struct ccat_eth_frame *next;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   144
	void *start;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   145
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   146
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   147
/**
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   148
 * struct ccat_eth_fifo - CCAT RX or TX fifo
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   149
 * @ops: function pointer table for dma/eim and rx/tx specific fifo functions
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   150
 * @reg: PCI register address of this fifo
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   151
 * @rx_bytes: number of bytes processed -> reported with ndo_get_stats64()
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   152
 * @rx_dropped: number of dropped frames -> reported with ndo_get_stats64()
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   153
 * @mem/dma/eim: information about the associated memory
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   154
 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   155
struct ccat_eth_fifo {
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   156
	const struct ccat_eth_fifo_operations *ops;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   157
	const struct ccat_eth_frame *end;
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   158
	void __iomem *reg;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   159
	atomic64_t bytes;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   160
	atomic64_t dropped;
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   161
	union {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   162
		struct ccat_mem mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   163
		struct ccat_dma dma;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   164
		struct ccat_eim eim;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   165
	};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   166
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   167
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   168
/**
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   169
 * struct ccat_eth_fifo_operations
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   170
 * @ready: callback used to test the next frames ready bit
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   171
 * @add: callback used to add a frame to this fifo
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   172
 * @copy_to_skb: callback used to copy from rx fifos to skbs
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   173
 * @skb: callback used to queue skbs into tx fifos
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   174
 */
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   175
struct ccat_eth_fifo_operations {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   176
	size_t(*ready) (struct ccat_eth_fifo *);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   177
	void (*add) (struct ccat_eth_fifo *);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   178
	union {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   179
		void (*copy_to_skb) (struct ccat_eth_fifo *, struct sk_buff *,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   180
				     size_t);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   181
		void (*skb) (struct ccat_eth_fifo *, struct sk_buff *);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   182
	} queue;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   183
};
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   184
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   185
/**
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   186
 * same as: typedef struct _CCatInfoBlockOffs from CCatDefinitions.h
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   187
 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   188
struct ccat_mac_infoblock {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   189
	u32 reserved;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   190
	u32 mii;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   191
	u32 tx_fifo;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   192
	u32 mac;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   193
	u32 rx_mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   194
	u32 tx_mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   195
	u32 misc;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   196
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   197
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   198
/**
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   199
 * struct ccat_eth_priv - CCAT Ethernet/EtherCAT Master function (netdev)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   200
 * @func: pointer to the parent struct ccat_function
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   201
 * @netdev: the net_device structure used by the kernel networking stack
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   202
 * @reg: register addresses in PCI config space of the Ethernet/EtherCAT Master function
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   203
 * @rx_fifo: fifo used for RX descriptors
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   204
 * @tx_fifo: fifo used for TX descriptors
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   205
 * @poll_timer: interval timer used to poll CCAT for events like link changed, rx done, tx done
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   206
 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   207
struct ccat_eth_priv {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   208
	struct ccat_function *func;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   209
	struct net_device *netdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   210
	struct ccat_eth_register reg;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   211
	struct ccat_eth_fifo rx_fifo;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   212
	struct ccat_eth_fifo tx_fifo;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   213
	struct hrtimer poll_timer;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   214
	struct ccat_dma_mem dma_mem;
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   215
	ec_device_t *ecdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   216
	void (*carrier_off) (struct net_device * netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   217
	 bool(*carrier_ok) (const struct net_device * netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   218
	void (*carrier_on) (struct net_device * netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   219
	void (*kfree_skb_any) (struct sk_buff * skb);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   220
	void (*receive) (struct ccat_eth_priv *, size_t);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   221
	void (*start_queue) (struct net_device * netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   222
	void (*stop_queue) (struct net_device * netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   223
	void (*unregister) (struct net_device * netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   224
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   225
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   226
struct ccat_mac_register {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   227
	/** MAC error register     @+0x0 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   228
	u8 frame_len_err;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   229
	u8 rx_err;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   230
	u8 crc_err;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   231
	u8 link_lost_err;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   232
	u32 reserved1;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   233
	/** Buffer overflow errors @+0x8 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   234
	u8 rx_mem_full;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   235
	u8 reserved2[7];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   236
	/** MAC frame counter      @+0x10 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   237
	u32 tx_frames;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   238
	u32 rx_frames;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   239
	u64 reserved3;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   240
	/** MAC fifo level         @+0x20 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   241
	u8 tx_fifo_level:7;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   242
	u8 reserved4:1;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   243
	u8 reserved5[7];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   244
	/** TX memory full error   @+0x28 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   245
	u8 tx_mem_full;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   246
	u8 reserved6[7];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   247
	u64 reserved8[9];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   248
	/** Connection             @+0x78 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   249
	u8 mii_connected;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   250
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   251
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   252
static void fifo_set_end(struct ccat_eth_fifo *const fifo, size_t size)
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   253
{
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   254
	fifo->end = fifo->mem.start + size - sizeof(struct ccat_eth_frame);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   255
}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   256
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   257
static void ccat_dma_free(struct ccat_eth_priv *const priv)
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   258
{
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   259
	if (priv->dma_mem.base) {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   260
		const struct ccat_dma_mem tmp = priv->dma_mem;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   261
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   262
		memset(&priv->dma_mem, 0, sizeof(priv->dma_mem));
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   263
		dma_free_coherent(tmp.dev, tmp.size, tmp.base, tmp.phys);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   264
		free_dma(priv->func->info.tx_dma_chan);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   265
		free_dma(priv->func->info.rx_dma_chan);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   266
	}
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   267
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   268
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   269
/**
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   270
 * ccat_dma_init() - Initialize CCAT and host memory for DMA transfer
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   271
 * @dma object for management data which will be initialized
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   272
 * @channel number of the DMA channel
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   273
 * @ioaddr of the pci bar2 configspace used to calculate the address of the pci dma configuration
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   274
 * @dev which should be configured for DMA
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   275
 */
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   276
static int ccat_dma_init(struct ccat_dma_mem *const dma, size_t channel,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   277
			 void __iomem * const bar2,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   278
			 struct ccat_eth_fifo *const fifo)
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   279
{
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   280
	void __iomem *const ioaddr = bar2 + 0x1000 + (sizeof(u64) * channel);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   281
	const dma_addr_t phys = CCAT_ALIGN_CHANNEL(dma->phys, channel);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   282
	const u32 phys_hi = (sizeof(phys) > sizeof(u32)) ? phys >> 32 : 0;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   283
	fifo->dma.start = CCAT_ALIGN_CHANNEL(dma->base, channel);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   284
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   285
	fifo_set_end(fifo, CCAT_ALIGNMENT);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   286
	if (request_dma(channel, KBUILD_MODNAME)) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   287
		pr_info("request dma channel %llu failed\n", (u64) channel);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   288
		return -EINVAL;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   289
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   290
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   291
	/** bit 0 enables 64 bit mode on ccat */
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   292
	iowrite32((u32) phys | ((phys_hi) > 0), ioaddr);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   293
	iowrite32(phys_hi, ioaddr + 4);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   294
2654
b3f6b3e5ef29 devices/ccat: revert "limit rx processing to one frame per poll"
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2638
diff changeset
   295
	pr_info
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   296
	    ("DMA%llu mem initialized\n base:         0x%p\n start:        0x%p\n phys:         0x%09llx\n pci addr:     0x%01x%08x\n size:         %llu |%llx bytes.\n",
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   297
	     (u64) channel, dma->base, fifo->dma.start, (u64) dma->phys,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   298
	     ioread32(ioaddr + 4), ioread32(ioaddr),
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   299
	     (u64) dma->size, (u64) dma->size);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   300
	return 0;
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   301
}
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   302
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   303
static void ecdev_kfree_skb_any(struct sk_buff *skb)
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   304
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   305
	/* never release a skb in EtherCAT mode */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   306
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   307
2570
144e11d93e99 - don't use compat.h in the mainline driver
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2569
diff changeset
   308
static bool ecdev_carrier_ok(const struct net_device *const netdev)
2567
d70aad2f131f - use short kernel types, add empty lines after variable declaration to conform better with linux coding style
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2565
diff changeset
   309
{
d70aad2f131f - use short kernel types, add empty lines after variable declaration to conform better with linux coding style
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2565
diff changeset
   310
	struct ccat_eth_priv *const priv = netdev_priv(netdev);
d70aad2f131f - use short kernel types, add empty lines after variable declaration to conform better with linux coding style
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2565
diff changeset
   311
	return ecdev_get_link(priv->ecdev);
d70aad2f131f - use short kernel types, add empty lines after variable declaration to conform better with linux coding style
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2565
diff changeset
   312
}
d70aad2f131f - use short kernel types, add empty lines after variable declaration to conform better with linux coding style
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2565
diff changeset
   313
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   314
static void ecdev_carrier_on(struct net_device *const netdev)
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   315
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   316
	struct ccat_eth_priv *const priv = netdev_priv(netdev);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   317
	ecdev_set_link(priv->ecdev, 1);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   318
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   319
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   320
static void ecdev_carrier_off(struct net_device *const netdev)
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   321
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   322
	struct ccat_eth_priv *const priv = netdev_priv(netdev);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   323
	ecdev_set_link(priv->ecdev, 0);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   324
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   325
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   326
static void ecdev_nop(struct net_device *const netdev)
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   327
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   328
	/* dummy called if nothing has to be done in EtherCAT operation mode */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   329
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   330
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   331
static void ecdev_receive_dma(struct ccat_eth_priv *const priv, size_t len)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   332
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   333
	ecdev_receive(priv->ecdev, priv->rx_fifo.dma.next->data, len);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   334
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   335
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   336
static void ecdev_receive_eim(struct ccat_eth_priv *const priv, size_t len)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   337
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   338
	ecdev_receive(priv->ecdev, priv->rx_fifo.eim.next->data, len);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   339
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   340
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   341
static void unregister_ecdev(struct net_device *const netdev)
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   342
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   343
	struct ccat_eth_priv *const priv = netdev_priv(netdev);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   344
	ecdev_close(priv->ecdev);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   345
	ecdev_withdraw(priv->ecdev);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   346
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   347
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   348
static inline size_t fifo_eim_tx_ready(struct ccat_eth_fifo *const fifo)
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   349
{
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   350
	struct ccat_eth_priv *const priv =
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   351
	    container_of(fifo, struct ccat_eth_priv, tx_fifo);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   352
	static const size_t TX_FIFO_LEVEL_OFFSET = 0x20;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   353
	static const u8 TX_FIFO_LEVEL_MASK = 0x3F;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   354
	void __iomem *addr = priv->reg.mac + TX_FIFO_LEVEL_OFFSET;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   355
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   356
	return !(ioread8(addr) & TX_FIFO_LEVEL_MASK);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   357
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   358
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   359
static inline size_t fifo_eim_rx_ready(struct ccat_eth_fifo *const fifo)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   360
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   361
	static const size_t OVERHEAD = sizeof(struct ccat_eim_frame_hdr);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   362
	const size_t len = ioread16(&fifo->eim.next->hdr.length);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   363
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   364
	return (len < OVERHEAD) ? 0 : len - OVERHEAD;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   365
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   366
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   367
static void ccat_eth_fifo_inc(struct ccat_eth_fifo *fifo)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   368
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   369
	if (++fifo->mem.next > fifo->end)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   370
		fifo->mem.next = fifo->mem.start;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   371
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   372
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   373
static void fifo_eim_rx_add(struct ccat_eth_fifo *const fifo)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   374
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   375
	struct ccat_eim_frame __iomem *frame = fifo->eim.next;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   376
	iowrite16(0, frame);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   377
	wmb();
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   378
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   379
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   380
static void fifo_eim_tx_add(struct ccat_eth_fifo *const fifo)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   381
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   382
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   383
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   384
#define memcpy_from_ccat(DEST, SRC, LEN) memcpy(DEST,(__force void*)(SRC), LEN)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   385
#define memcpy_to_ccat(DEST, SRC, LEN) memcpy((__force void*)(DEST),SRC, LEN)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   386
static void fifo_eim_copy_to_linear_skb(struct ccat_eth_fifo *const fifo,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   387
					struct sk_buff *skb, const size_t len)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   388
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   389
	memcpy_from_ccat(skb->data, fifo->eim.next->data, len);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   390
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   391
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   392
static void fifo_eim_queue_skb(struct ccat_eth_fifo *const fifo,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   393
			       struct sk_buff *skb)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   394
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   395
	struct ccat_eim_frame __iomem *frame = fifo->eim.next;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   396
	const u32 addr_and_length =
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   397
	    (void __iomem *)frame - (void __iomem *)fifo->eim.start;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   398
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   399
	const __le16 length = cpu_to_le16(skb->len);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   400
	memcpy_to_ccat(&frame->hdr.length, &length, sizeof(length));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   401
	memcpy_to_ccat(frame->data, skb->data, skb->len);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   402
	iowrite32(addr_and_length, fifo->reg);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   403
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   404
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   405
static void ccat_eth_fifo_hw_reset(struct ccat_eth_fifo *const fifo)
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   406
{
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   407
	if (fifo->reg) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   408
		iowrite32(0, fifo->reg + 0x8);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   409
		wmb();
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   410
	}
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   411
}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   412
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   413
static void ccat_eth_fifo_reset(struct ccat_eth_fifo *const fifo)
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   414
{
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   415
	ccat_eth_fifo_hw_reset(fifo);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   416
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   417
	if (fifo->ops->add) {
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   418
		fifo->mem.next = fifo->mem.start;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   419
		do {
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   420
			fifo->ops->add(fifo);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   421
			ccat_eth_fifo_inc(fifo);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   422
		} while (fifo->mem.next != fifo->mem.start);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   423
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   424
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   425
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   426
static inline size_t fifo_dma_tx_ready(struct ccat_eth_fifo *const fifo)
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   427
{
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   428
	const struct ccat_dma_frame *frame = fifo->dma.next;
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   429
	return le32_to_cpu(frame->hdr.tx_flags) & CCAT_FRAME_SENT;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   430
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   431
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   432
static inline size_t fifo_dma_rx_ready(struct ccat_eth_fifo *const fifo)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   433
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   434
	static const size_t OVERHEAD =
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   435
	    offsetof(struct ccat_dma_frame_hdr, rx_flags);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   436
	const struct ccat_dma_frame *const frame = fifo->dma.next;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   437
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   438
	if (le32_to_cpu(frame->hdr.rx_flags) & CCAT_FRAME_RECEIVED) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   439
		const size_t len = le16_to_cpu(frame->hdr.length);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   440
		return (len < OVERHEAD) ? 0 : len - OVERHEAD;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   441
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   442
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   443
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   444
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   445
static void ccat_eth_rx_fifo_dma_add(struct ccat_eth_fifo *const fifo)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   446
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   447
	struct ccat_dma_frame *const frame = fifo->dma.next;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   448
	const size_t offset = (void *)frame - fifo->dma.start;
2567
d70aad2f131f - use short kernel types, add empty lines after variable declaration to conform better with linux coding style
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2565
diff changeset
   449
	const u32 addr_and_length = (1 << 31) | offset;
d70aad2f131f - use short kernel types, add empty lines after variable declaration to conform better with linux coding style
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2565
diff changeset
   450
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   451
	frame->hdr.rx_flags = cpu_to_le32(0);
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   452
	iowrite32(addr_and_length, fifo->reg);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   453
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   454
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   455
static void ccat_eth_tx_fifo_dma_add_free(struct ccat_eth_fifo *const fifo)
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   456
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   457
	/* mark frame as ready to use for tx */
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   458
	fifo->dma.next->hdr.tx_flags = cpu_to_le32(CCAT_FRAME_SENT);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   459
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   460
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   461
static void fifo_dma_copy_to_linear_skb(struct ccat_eth_fifo *const fifo,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   462
					struct sk_buff *skb, const size_t len)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   463
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   464
	skb_copy_to_linear_data(skb, fifo->dma.next->data, len);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   465
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   466
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   467
static void fifo_dma_queue_skb(struct ccat_eth_fifo *const fifo,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   468
			       struct sk_buff *skb)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   469
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   470
	struct ccat_dma_frame *frame = fifo->dma.next;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   471
	u32 addr_and_length;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   472
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   473
	frame->hdr.tx_flags = cpu_to_le32(0);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   474
	frame->hdr.length = cpu_to_le16(skb->len);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   475
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   476
	memcpy(frame->data, skb->data, skb->len);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   477
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   478
	/* Queue frame into CCAT TX-FIFO, CCAT ignores the first 8 bytes of the tx descriptor */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   479
	addr_and_length = offsetof(struct ccat_dma_frame_hdr, length);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   480
	addr_and_length += ((void *)frame - fifo->dma.start);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   481
	addr_and_length +=
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   482
	    ((skb->len + sizeof(struct ccat_dma_frame_hdr)) / 8) << 24;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   483
	iowrite32(addr_and_length, fifo->reg);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   484
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   485
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   486
static const struct ccat_eth_fifo_operations dma_rx_fifo_ops = {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   487
	.add = ccat_eth_rx_fifo_dma_add,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   488
	.ready = fifo_dma_rx_ready,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   489
	.queue.copy_to_skb = fifo_dma_copy_to_linear_skb,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   490
};
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   491
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   492
static const struct ccat_eth_fifo_operations dma_tx_fifo_ops = {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   493
	.add = ccat_eth_tx_fifo_dma_add_free,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   494
	.ready = fifo_dma_tx_ready,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   495
	.queue.skb = fifo_dma_queue_skb,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   496
};
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   497
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   498
static const struct ccat_eth_fifo_operations eim_rx_fifo_ops = {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   499
	.add = fifo_eim_rx_add,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   500
	.queue.copy_to_skb = fifo_eim_copy_to_linear_skb,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   501
	.ready = fifo_eim_rx_ready,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   502
};
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   503
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   504
static const struct ccat_eth_fifo_operations eim_tx_fifo_ops = {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   505
	.add = fifo_eim_tx_add,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   506
	.queue.skb = fifo_eim_queue_skb,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   507
	.ready = fifo_eim_tx_ready,
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   508
};
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   509
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   510
static void ccat_eth_priv_free(struct ccat_eth_priv *priv)
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   511
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   512
	/* reset hw fifo's */
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   513
	ccat_eth_fifo_hw_reset(&priv->rx_fifo);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   514
	ccat_eth_fifo_hw_reset(&priv->tx_fifo);
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   515
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   516
	/* release dma */
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   517
	ccat_dma_free(priv);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   518
}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   519
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   520
static int ccat_hw_disable_mac_filter(struct ccat_eth_priv *priv)
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   521
{
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   522
	iowrite8(0, priv->reg.mii + 0x8 + 6);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   523
	wmb();
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   524
	return 0;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   525
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   526
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   527
/**
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   528
 * Initalizes both (Rx/Tx) DMA fifo's and related management structures
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   529
 */
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   530
static int ccat_eth_priv_init_dma(struct ccat_eth_priv *priv)
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   531
{
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   532
	struct ccat_dma_mem *const dma = &priv->dma_mem;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   533
	struct pci_dev *const pdev = priv->func->ccat->pdev;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   534
	void __iomem *const bar_2 = priv->func->ccat->bar_2;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   535
	const u8 rx_chan = priv->func->info.rx_dma_chan;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   536
	const u8 tx_chan = priv->func->info.tx_dma_chan;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   537
	int status = 0;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   538
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   539
	dma->dev = &pdev->dev;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   540
	dma->size = CCAT_ALIGNMENT * 3;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   541
	dma->base =
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   542
	    dma_zalloc_coherent(dma->dev, dma->size, &dma->phys, GFP_KERNEL);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   543
	if (!dma->base || !dma->phys) {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   544
		pr_err("init DMA memory failed.\n");
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   545
		return -ENOMEM;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   546
	}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   547
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   548
	priv->rx_fifo.ops = &dma_rx_fifo_ops;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   549
	status = ccat_dma_init(dma, rx_chan, bar_2, &priv->rx_fifo);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   550
	if (status) {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   551
		pr_info("init RX DMA memory failed.\n");
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   552
		ccat_dma_free(priv);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   553
		return status;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   554
	}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   555
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   556
	priv->tx_fifo.ops = &dma_tx_fifo_ops;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   557
	status = ccat_dma_init(dma, tx_chan, bar_2, &priv->tx_fifo);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   558
	if (status) {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   559
		pr_info("init TX DMA memory failed.\n");
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   560
		ccat_dma_free(priv);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   561
		return status;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   562
	}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   563
	return ccat_hw_disable_mac_filter(priv);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   564
}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   565
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   566
static int ccat_eth_priv_init_eim(struct ccat_eth_priv *priv)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   567
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   568
	priv->rx_fifo.eim.start = priv->reg.rx_mem;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   569
	priv->rx_fifo.ops = &eim_rx_fifo_ops;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   570
	fifo_set_end(&priv->rx_fifo, sizeof(struct ccat_eth_frame));
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   571
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   572
	priv->tx_fifo.eim.start = priv->reg.tx_mem;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   573
	priv->tx_fifo.ops = &eim_tx_fifo_ops;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   574
	fifo_set_end(&priv->tx_fifo, priv->func->info.tx_size);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   575
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   576
	return ccat_hw_disable_mac_filter(priv);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   577
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   578
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   579
/**
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   580
 * Initializes a struct ccat_eth_register with data from a corresponding
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   581
 * CCAT function.
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   582
 */
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   583
static void ccat_eth_priv_init_reg(struct ccat_eth_priv *const priv)
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   584
{
2569
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2568
diff changeset
   585
	struct ccat_mac_infoblock offsets;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   586
	struct ccat_eth_register *const reg = &priv->reg;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   587
	const struct ccat_function *const func = priv->func;
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   588
	void __iomem *const func_base = func->ccat->bar_0 + func->info.addr;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   589
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   590
	/* struct ccat_eth_fifo contains a union of ccat_dma, ccat_eim and ccat_mem
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   591
	 * the members next and start have to overlay the exact same memory,
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   592
	 * to support 'polymorphic' usage of them */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   593
	BUILD_BUG_ON(offsetof(struct ccat_dma, next) !=
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   594
		     offsetof(struct ccat_mem, next));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   595
	BUILD_BUG_ON(offsetof(struct ccat_dma, start) !=
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   596
		     offsetof(struct ccat_mem, start));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   597
	BUILD_BUG_ON(offsetof(struct ccat_dma, next) !=
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   598
		     offsetof(struct ccat_eim, next));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   599
	BUILD_BUG_ON(offsetof(struct ccat_dma, start) !=
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   600
		     offsetof(struct ccat_eim, start));
2567
d70aad2f131f - use short kernel types, add empty lines after variable declaration to conform better with linux coding style
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2565
diff changeset
   601
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   602
	memcpy_fromio(&offsets, func_base, sizeof(offsets));
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   603
	reg->mii = func_base + offsets.mii;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   604
	priv->tx_fifo.reg = func_base + offsets.tx_fifo;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   605
	priv->rx_fifo.reg = func_base + offsets.tx_fifo + 0x10;
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   606
	reg->mac = func_base + offsets.mac;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   607
	reg->rx_mem = func_base + offsets.rx_mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   608
	reg->tx_mem = func_base + offsets.tx_mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   609
	reg->misc = func_base + offsets.misc;
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   610
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   611
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   612
static netdev_tx_t ccat_eth_start_xmit(struct sk_buff *skb,
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   613
				       struct net_device *dev)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   614
{
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   615
	struct ccat_eth_priv *const priv = netdev_priv(dev);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   616
	struct ccat_eth_fifo *const fifo = &priv->tx_fifo;
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   617
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   618
	if (skb_is_nonlinear(skb)) {
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   619
		pr_warn("Non linear skb not supported -> drop frame.\n");
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   620
		atomic64_inc(&fifo->dropped);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   621
		priv->kfree_skb_any(skb);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   622
		return NETDEV_TX_OK;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   623
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   624
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   625
	if (skb->len > MAX_PAYLOAD_SIZE) {
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   626
		pr_warn("skb.len %llu exceeds dma buffer %llu -> drop frame.\n",
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   627
			(u64) skb->len, (u64) MAX_PAYLOAD_SIZE);
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   628
		atomic64_inc(&fifo->dropped);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   629
		priv->kfree_skb_any(skb);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   630
		return NETDEV_TX_OK;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   631
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   632
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   633
	if (!fifo->ops->ready(fifo)) {
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   634
		netdev_err(dev, "BUG! Tx Ring full when queue awake!\n");
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   635
		priv->stop_queue(priv->netdev);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   636
		return NETDEV_TX_BUSY;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   637
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   638
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   639
	/* prepare frame in DMA memory */
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   640
	fifo->ops->queue.skb(fifo, skb);
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   641
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   642
	/* update stats */
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   643
	atomic64_add(skb->len, &fifo->bytes);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   644
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   645
	priv->kfree_skb_any(skb);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   646
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   647
	ccat_eth_fifo_inc(fifo);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   648
	/* stop queue if tx ring is full */
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   649
	if (!fifo->ops->ready(fifo)) {
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   650
		priv->stop_queue(priv->netdev);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   651
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   652
	return NETDEV_TX_OK;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   653
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   654
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   655
/**
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   656
 * Function to transmit a raw buffer to the network (f.e. frameForwardEthernetFrames)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   657
 * @dev a valid net_device
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   658
 * @data pointer to your raw buffer
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   659
 * @len number of bytes in the raw buffer to transmit
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   660
 */
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   661
static void ccat_eth_xmit_raw(struct net_device *dev, const char *const data,
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   662
			      size_t len)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   663
{
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   664
	struct sk_buff *skb = dev_alloc_skb(len);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   665
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   666
	skb->dev = dev;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   667
	skb_copy_to_linear_data(skb, data, len);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   668
	skb_put(skb, len);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   669
	ccat_eth_start_xmit(skb, dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   670
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   671
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   672
static void ccat_eth_receive(struct ccat_eth_priv *const priv, const size_t len)
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   673
{
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   674
	struct sk_buff *const skb = dev_alloc_skb(len + NET_IP_ALIGN);
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   675
	struct ccat_eth_fifo *const fifo = &priv->rx_fifo;
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   676
	struct net_device *const dev = priv->netdev;
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   677
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   678
	if (!skb) {
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   679
		pr_info("%s() out of memory :-(\n", __FUNCTION__);
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   680
		atomic64_inc(&fifo->dropped);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   681
		return;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   682
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   683
	skb->dev = dev;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   684
	skb_reserve(skb, NET_IP_ALIGN);
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   685
	fifo->ops->queue.copy_to_skb(fifo, skb, len);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   686
	skb_put(skb, len);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   687
	skb->protocol = eth_type_trans(skb, dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   688
	skb->ip_summed = CHECKSUM_UNNECESSARY;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   689
	atomic64_add(len, &fifo->bytes);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   690
	netif_rx(skb);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   691
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   692
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   693
static void ccat_eth_link_down(struct net_device *const dev)
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   694
{
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   695
	struct ccat_eth_priv *const priv = netdev_priv(dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   696
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   697
	priv->stop_queue(dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   698
	priv->carrier_off(dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   699
	netdev_info(dev, "NIC Link is Down\n");
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   700
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   701
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   702
static void ccat_eth_link_up(struct net_device *const dev)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   703
{
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   704
	struct ccat_eth_priv *const priv = netdev_priv(dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   705
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   706
	netdev_info(dev, "NIC Link is Up\n");
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   707
	/* TODO netdev_info(dev, "NIC Link is Up %u Mbps %s Duplex\n",
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   708
	   speed == SPEED_100 ? 100 : 10,
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   709
	   cmd.duplex == DUPLEX_FULL ? "Full" : "Half"); */
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   710
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   711
	ccat_eth_fifo_reset(&priv->rx_fifo);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   712
	ccat_eth_fifo_reset(&priv->tx_fifo);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   713
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   714
	/* TODO reset CCAT MAC register */
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   715
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   716
	ccat_eth_xmit_raw(dev, frameForwardEthernetFrames,
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   717
			  sizeof(frameForwardEthernetFrames));
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   718
	priv->carrier_on(dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   719
	priv->start_queue(dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   720
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   721
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   722
/**
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   723
 * Read link state from CCAT hardware
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   724
 * @return 1 if link is up, 0 if not
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   725
 */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   726
inline static size_t ccat_eth_priv_read_link_state(const struct ccat_eth_priv
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   727
						   *const priv)
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   728
{
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   729
	return ! !(ioread32(priv->reg.mii + 0x8 + 4) & (1 << 24));
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   730
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   731
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   732
/**
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   733
 * Poll for link state changes
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   734
 */
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   735
static void poll_link(struct ccat_eth_priv *const priv)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   736
{
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   737
	const size_t link = ccat_eth_priv_read_link_state(priv);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   738
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   739
	if (link != priv->carrier_ok(priv->netdev)) {
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   740
		if (link)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   741
			ccat_eth_link_up(priv->netdev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   742
		else
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   743
			ccat_eth_link_down(priv->netdev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   744
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   745
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   746
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   747
/**
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   748
 * Poll for available rx dma descriptors in ethernet operating mode
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   749
 */
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   750
static void poll_rx(struct ccat_eth_priv *const priv)
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   751
{
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   752
	struct ccat_eth_fifo *const fifo = &priv->rx_fifo;
2654
b3f6b3e5ef29 devices/ccat: revert "limit rx processing to one frame per poll"
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2638
diff changeset
   753
	size_t rx_per_poll = FIFO_LENGTH / 2;
b3f6b3e5ef29 devices/ccat: revert "limit rx processing to one frame per poll"
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2638
diff changeset
   754
	size_t len = fifo->ops->ready(fifo);
b3f6b3e5ef29 devices/ccat: revert "limit rx processing to one frame per poll"
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2638
diff changeset
   755
b3f6b3e5ef29 devices/ccat: revert "limit rx processing to one frame per poll"
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2638
diff changeset
   756
	while (len && --rx_per_poll) {
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   757
		priv->receive(priv, len);
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   758
		fifo->ops->add(fifo);
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   759
		ccat_eth_fifo_inc(fifo);
2654
b3f6b3e5ef29 devices/ccat: revert "limit rx processing to one frame per poll"
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2638
diff changeset
   760
		len = fifo->ops->ready(fifo);
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   761
	}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   762
}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   763
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   764
static void ec_poll(struct net_device *dev)
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   765
{
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   766
	struct ccat_eth_priv *const priv = netdev_priv(dev);
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   767
	poll_link(priv);
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   768
	poll_rx(priv);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   769
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   770
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   771
/**
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   772
 * Poll for available tx dma descriptors in ethernet operating mode
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   773
 */
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   774
static void poll_tx(struct ccat_eth_priv *const priv)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   775
{
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   776
	if (priv->tx_fifo.ops->ready(&priv->tx_fifo)) {
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   777
		netif_wake_queue(priv->netdev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   778
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   779
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   780
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   781
/**
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   782
 * Since CCAT doesn't support interrupts until now, we have to poll
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   783
 * some status bits to recognize things like link change etc.
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   784
 */
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   785
static enum hrtimer_restart poll_timer_callback(struct hrtimer *timer)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   786
{
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   787
	struct ccat_eth_priv *const priv =
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   788
	    container_of(timer, struct ccat_eth_priv, poll_timer);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   789
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   790
	poll_link(priv);
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   791
	poll_rx(priv);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   792
	poll_tx(priv);
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   793
	hrtimer_forward_now(timer, POLL_TIME);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   794
	return HRTIMER_RESTART;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   795
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   796
2695
ad58465e75ca Applied CCAT patch 0001-fix-ccat-netdev-for-v4.11.patch from Beckhoff.
Florian Pose
parents: 2654
diff changeset
   797
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0))
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   798
static struct rtnl_link_stats64 *ccat_eth_get_stats64(struct net_device *dev, struct rtnl_link_stats64
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   799
						      *storage)
2695
ad58465e75ca Applied CCAT patch 0001-fix-ccat-netdev-for-v4.11.patch from Beckhoff.
Florian Pose
parents: 2654
diff changeset
   800
#else
ad58465e75ca Applied CCAT patch 0001-fix-ccat-netdev-for-v4.11.patch from Beckhoff.
Florian Pose
parents: 2654
diff changeset
   801
static void ccat_eth_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *storage)
ad58465e75ca Applied CCAT patch 0001-fix-ccat-netdev-for-v4.11.patch from Beckhoff.
Florian Pose
parents: 2654
diff changeset
   802
#endif
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   803
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   804
	struct ccat_eth_priv *const priv = netdev_priv(dev);
2569
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2568
diff changeset
   805
	struct ccat_mac_register mac;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   806
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   807
	memcpy_fromio(&mac, priv->reg.mac, sizeof(mac));
2569
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2568
diff changeset
   808
	storage->rx_packets = mac.rx_frames;	/* total packets received       */
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2568
diff changeset
   809
	storage->tx_packets = mac.tx_frames;	/* total packets transmitted    */
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   810
	storage->rx_bytes = atomic64_read(&priv->rx_fifo.bytes);	/* total bytes received         */
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   811
	storage->tx_bytes = atomic64_read(&priv->tx_fifo.bytes);	/* total bytes transmitted      */
2569
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2568
diff changeset
   812
	storage->rx_errors = mac.frame_len_err + mac.rx_mem_full + mac.crc_err + mac.rx_err;	/* bad packets received         */
2573
ad9a35065387 remove print.* from release tree
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2572
diff changeset
   813
	storage->tx_errors = mac.tx_mem_full;	/* packet transmit problems     */
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   814
	storage->rx_dropped = atomic64_read(&priv->rx_fifo.dropped);	/* no space in linux buffers    */
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   815
	storage->tx_dropped = atomic64_read(&priv->tx_fifo.dropped);	/* no space available in linux  */
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   816
	//TODO __u64    multicast;              /* multicast packets received   */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   817
	//TODO __u64    collisions;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   818
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   819
	/* detailed rx_errors: */
2569
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2568
diff changeset
   820
	storage->rx_length_errors = mac.frame_len_err;
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2568
diff changeset
   821
	storage->rx_over_errors = mac.rx_mem_full;	/* receiver ring buff overflow  */
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2568
diff changeset
   822
	storage->rx_crc_errors = mac.crc_err;	/* recved pkt with crc error    */
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2568
diff changeset
   823
	storage->rx_frame_errors = mac.rx_err;	/* recv'd frame alignment error */
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2568
diff changeset
   824
	storage->rx_fifo_errors = mac.rx_mem_full;	/* recv'r fifo overrun          */
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   825
	//TODO __u64    rx_missed_errors;       /* receiver missed packet       */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   826
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   827
	/* detailed tx_errors */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   828
	//TODO __u64    tx_aborted_errors;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   829
	//TODO __u64    tx_carrier_errors;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   830
	//TODO __u64    tx_fifo_errors;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   831
	//TODO __u64    tx_heartbeat_errors;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   832
	//TODO __u64    tx_window_errors;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   833
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   834
	/* for cslip etc */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   835
	//TODO __u64    rx_compressed;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   836
	//TODO __u64    tx_compressed;
2695
ad58465e75ca Applied CCAT patch 0001-fix-ccat-netdev-for-v4.11.patch from Beckhoff.
Florian Pose
parents: 2654
diff changeset
   837
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0))
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   838
	return storage;
2695
ad58465e75ca Applied CCAT patch 0001-fix-ccat-netdev-for-v4.11.patch from Beckhoff.
Florian Pose
parents: 2654
diff changeset
   839
#endif
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   840
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   841
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   842
static int ccat_eth_open(struct net_device *dev)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   843
{
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   844
	struct ccat_eth_priv *const priv = netdev_priv(dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   845
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   846
	if (!priv->ecdev) {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   847
		hrtimer_init(&priv->poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   848
		priv->poll_timer.function = poll_timer_callback;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   849
		hrtimer_start(&priv->poll_timer, POLL_TIME, HRTIMER_MODE_REL);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   850
	}
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   851
	return 0;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   852
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   853
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   854
static int ccat_eth_stop(struct net_device *dev)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   855
{
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   856
	struct ccat_eth_priv *const priv = netdev_priv(dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   857
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   858
	priv->stop_queue(dev);
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   859
	if (!priv->ecdev) {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   860
		hrtimer_cancel(&priv->poll_timer);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   861
	}
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   862
	return 0;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   863
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   864
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   865
static const struct net_device_ops ccat_eth_netdev_ops = {
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   866
	.ndo_get_stats64 = ccat_eth_get_stats64,
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   867
	.ndo_open = ccat_eth_open,
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   868
	.ndo_start_xmit = ccat_eth_start_xmit,
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   869
	.ndo_stop = ccat_eth_stop,
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   870
};
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   871
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   872
static struct ccat_eth_priv *ccat_eth_alloc_netdev(struct ccat_function *func)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   873
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   874
	struct ccat_eth_priv *priv = NULL;
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   875
	struct net_device *const netdev = alloc_etherdev(sizeof(*priv));
2567
d70aad2f131f - use short kernel types, add empty lines after variable declaration to conform better with linux coding style
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2565
diff changeset
   876
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   877
	if (netdev) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   878
		priv = netdev_priv(netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   879
		memset(priv, 0, sizeof(*priv));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   880
		priv->netdev = netdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   881
		priv->func = func;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   882
		ccat_eth_priv_init_reg(priv);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   883
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   884
	return priv;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   885
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   886
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   887
static int ccat_eth_init_netdev(struct ccat_eth_priv *priv)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   888
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   889
	int status;
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   890
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   891
	/* init netdev with MAC and stack callbacks */
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   892
	memcpy_fromio(priv->netdev->dev_addr, priv->reg.mii + 8,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   893
		      priv->netdev->addr_len);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   894
	priv->netdev->netdev_ops = &ccat_eth_netdev_ops;
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   895
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   896
	/* use as EtherCAT device? */
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   897
	priv->carrier_off = ecdev_carrier_off;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   898
	priv->carrier_ok = ecdev_carrier_ok;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   899
	priv->carrier_on = ecdev_carrier_on;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   900
	priv->kfree_skb_any = ecdev_kfree_skb_any;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   901
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   902
	/* It would be more intuitive to check for:
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   903
	 * if (priv->func->drv->type == CCATINFO_ETHERCAT_MASTER_DMA) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   904
	 * unfortunately priv->func->drv is not initialized until probe() returns.
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   905
	 * So we check if there is a rx dma fifo registered to determine dma/io mode */
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   906
	if (&dma_rx_fifo_ops == priv->rx_fifo.ops) {
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   907
		priv->receive = ecdev_receive_dma;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   908
	} else {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   909
		priv->receive = ecdev_receive_eim;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   910
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   911
	priv->start_queue = ecdev_nop;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   912
	priv->stop_queue = ecdev_nop;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   913
	priv->unregister = unregister_ecdev;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   914
	priv->ecdev = ecdev_offer(priv->netdev, ec_poll, THIS_MODULE);
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   915
	if (priv->ecdev) {
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   916
		priv->carrier_off(priv->netdev);
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   917
		if (ecdev_open(priv->ecdev)) {
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   918
			pr_info("unable to register network device.\n");
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   919
			ecdev_withdraw(priv->ecdev);
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   920
			ccat_eth_priv_free(priv);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   921
			free_netdev(priv->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   922
			return -1;	// TODO return better error code
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   923
		}
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   924
		priv->func->private_data = priv;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   925
		return 0;
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   926
	}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   927
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   928
	/* EtherCAT disabled -> prepare normal ethernet mode */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   929
	priv->carrier_off = netif_carrier_off;
2567
d70aad2f131f - use short kernel types, add empty lines after variable declaration to conform better with linux coding style
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2565
diff changeset
   930
	priv->carrier_ok = netif_carrier_ok;
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   931
	priv->carrier_on = netif_carrier_on;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   932
	priv->kfree_skb_any = dev_kfree_skb_any;
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   933
	priv->receive = ccat_eth_receive;
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   934
	priv->start_queue = netif_start_queue;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   935
	priv->stop_queue = netif_stop_queue;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   936
	priv->unregister = unregister_netdev;
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   937
	priv->carrier_off(priv->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   938
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   939
	status = register_netdev(priv->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   940
	if (status) {
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   941
		pr_info("unable to register network device.\n");
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   942
		ccat_eth_priv_free(priv);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   943
		free_netdev(priv->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   944
		return status;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   945
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   946
	pr_info("registered %s as network device.\n", priv->netdev->name);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   947
	priv->func->private_data = priv;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   948
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   949
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   950
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   951
static int ccat_eth_dma_probe(struct ccat_function *func)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   952
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   953
	struct ccat_eth_priv *priv = ccat_eth_alloc_netdev(func);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   954
	int status;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   955
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   956
	if (!priv)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   957
		return -ENOMEM;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   958
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   959
	status = ccat_eth_priv_init_dma(priv);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   960
	if (status) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   961
		pr_warn("%s(): DMA initialization failed.\n", __FUNCTION__);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   962
		free_netdev(priv->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   963
		return status;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   964
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   965
	return ccat_eth_init_netdev(priv);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   966
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   967
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   968
static void ccat_eth_dma_remove(struct ccat_function *func)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   969
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   970
	struct ccat_eth_priv *const eth = func->private_data;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   971
	eth->unregister(eth->netdev);
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   972
	ccat_eth_priv_free(eth);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   973
	free_netdev(eth->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   974
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   975
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   976
const struct ccat_driver eth_dma_driver = {
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   977
	.type = CCATINFO_ETHERCAT_MASTER_DMA,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   978
	.probe = ccat_eth_dma_probe,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   979
	.remove = ccat_eth_dma_remove,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   980
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   981
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   982
static int ccat_eth_eim_probe(struct ccat_function *func)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   983
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   984
	struct ccat_eth_priv *priv = ccat_eth_alloc_netdev(func);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   985
	int status;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   986
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   987
	if (!priv)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   988
		return -ENOMEM;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   989
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   990
	status = ccat_eth_priv_init_eim(priv);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   991
	if (status) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   992
		pr_warn("%s(): memory initialization failed.\n", __FUNCTION__);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   993
		free_netdev(priv->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   994
		return status;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   995
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   996
	return ccat_eth_init_netdev(priv);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   997
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   998
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   999
static void ccat_eth_eim_remove(struct ccat_function *func)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1000
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1001
	struct ccat_eth_priv *const eth = func->private_data;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1002
	eth->unregister(eth->netdev);
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
  1003
	ccat_eth_priv_free(eth);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1004
	free_netdev(eth->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1005
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1006
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
  1007
const struct ccat_driver eth_eim_driver = {
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1008
	.type = CCATINFO_ETHERCAT_NODMA,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1009
	.probe = ccat_eth_eim_probe,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1010
	.remove = ccat_eth_eim_remove,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1011
};