devices/ccat/netdev.c
author Patrick Bruenn <p.bruenn@beckhoff.com>
Mon, 26 Oct 2015 08:28:10 +0100
branchstable-1.5
changeset 2637 1d9be5716dee
parent 2636 0613017547fe
child 2638 5995331a55fe
permissions -rw-r--r--
fix ccat startup stall. In case the dma memory was allocated above 4 GB limit, CCAT is unable to access it.
-> limit the dma_mask to 32-bit to omit this situation
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>
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    25
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    26
#ifdef CONFIG_PCI
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    27
#include <asm/dma.h>
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    28
#else
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    29
#define free_dma(X)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    30
#define request_dma(X, Y) ((int)(-EINVAL))
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    31
#endif
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    32
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
    33
#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
    34
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
 * 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
    37
 */
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
    38
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
    39
	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
    40
	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
    41
	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
    42
	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
    43
	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
    44
	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
    45
	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
    46
	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
    47
	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
    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
};
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
#define FIFO_LENGTH 64
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    53
#define POLL_TIME ktime_set(0, 50 * NSEC_PER_USEC)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    54
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    55
struct ccat_dma_frame_hdr {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    56
	__le32 reserved1;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    57
	__le32 rx_flags;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    58
#define CCAT_FRAME_RECEIVED 0x1
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    59
	__le16 length;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    60
	__le16 reserved3;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    61
	__le32 tx_flags;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    62
#define CCAT_FRAME_SENT 0x1
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    63
	__le64 timestamp;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    64
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    65
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    66
struct ccat_eim_frame_hdr {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    67
	__le16 length;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    68
	__le16 reserved3;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    69
	__le32 tx_flags;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    70
	__le64 timestamp;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    71
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    72
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    73
struct ccat_eth_frame {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    74
	u8 placeholder[0x800];
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
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    77
struct ccat_dma_frame {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    78
	struct ccat_dma_frame_hdr hdr;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    79
	u8 data[sizeof(struct ccat_eth_frame) -
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    80
		sizeof(struct ccat_dma_frame_hdr)];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    81
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    82
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    83
struct ccat_eim_frame {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    84
	struct ccat_eim_frame_hdr hdr;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    85
	u8 data[sizeof(struct ccat_eth_frame) -
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    86
		sizeof(struct ccat_eim_frame_hdr)];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    87
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    88
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    89
#define MAX_PAYLOAD_SIZE \
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    90
	(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
    91
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    92
/**
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    93
 * 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
    94
 * @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
    95
 * @tx_fifo: address of the CCAT TX DMA fifo register
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    96
 * @rx_fifo: address of the CCAT RX DMA fifo register
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
    97
 * @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
    98
 * @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
    99
 * @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
   100
 * @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
   101
 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   102
struct ccat_eth_register {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   103
	void __iomem *mii;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   104
	void __iomem *tx_fifo;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   105
	void __iomem *rx_fifo;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   106
	void __iomem *mac;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   107
	void __iomem *rx_mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   108
	void __iomem *tx_mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   109
	void __iomem *misc;
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
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   112
/**
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   113
 * struct ccat_dma - CCAT DMA channel configuration
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
 * @start: CPU-viewed address(virtual) of the associated DMA memory
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   116
 * @size: number of bytes in the associated DMA memory
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   117
 * @channel: CCAT DMA channel number
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   118
 * @dev: valid struct device pointer
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   119
 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   120
struct ccat_dma {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   121
	struct ccat_dma_frame *next;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   122
	void *start;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   123
	size_t size;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   124
	dma_addr_t phys;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   125
	size_t channel;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   126
	struct device *dev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   127
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   128
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   129
struct ccat_eim {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   130
	struct ccat_eim_frame __iomem *next;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   131
	void __iomem *start;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   132
	size_t size;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   133
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   134
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   135
struct ccat_mem {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   136
	struct ccat_eth_frame *next;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   137
	void *start;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   138
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   139
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
 * struct ccat_eth_fifo - CCAT RX or TX DMA fifo
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   142
 * @add: callback used to add a frame to this fifo
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   143
 * @reg: PCI register address of this DMA fifo
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   144
 * @dma: information about the associated DMA memory
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
struct ccat_eth_fifo {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   147
	void (*add) (struct ccat_eth_fifo *);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   148
	void (*copy_to_skb) (struct ccat_eth_fifo *, struct sk_buff *, size_t);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   149
	void (*queue_skb) (struct ccat_eth_fifo * const, struct sk_buff *);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   150
	void __iomem *reg;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   151
	const struct ccat_eth_frame *end;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   152
	union {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   153
		struct ccat_mem mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   154
		struct ccat_dma dma;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   155
		struct ccat_eim eim;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   156
	};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   157
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   158
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   159
/**
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   160
 * 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
   161
 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   162
struct ccat_mac_infoblock {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   163
	u32 reserved;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   164
	u32 mii;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   165
	u32 tx_fifo;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   166
	u32 mac;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   167
	u32 rx_mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   168
	u32 tx_mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   169
	u32 misc;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   170
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   171
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   172
/**
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   173
 * 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
   174
 * @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
   175
 * @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
   176
 * @info: holds a copy of the CCAT Ethernet/EtherCAT Master function information block (read from PCI config space)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   177
 * @reg: register addresses in PCI config space of the Ethernet/EtherCAT Master function
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   178
 * @rx_fifo: DMA fifo used for RX DMA descriptors
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   179
 * @tx_fifo: DMA fifo used for TX DMA descriptors
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   180
 * @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
   181
 * @rx_bytes: number of bytes received -> reported with ndo_get_stats64()
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   182
 * @rx_dropped: number of received frames, which were dropped -> reported with ndo_get_stats64()
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   183
 * @tx_bytes: number of bytes send -> reported with ndo_get_stats64()
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   184
 * @tx_dropped: number of frames requested to send, which were dropped -> reported with ndo_get_stats64()
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   185
 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   186
struct ccat_eth_priv {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   187
	void (*free) (struct ccat_eth_priv *);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   188
	 bool(*tx_ready) (const struct ccat_eth_priv *);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   189
	 size_t(*rx_ready) (struct ccat_eth_fifo *);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   190
	struct ccat_function *func;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   191
	struct net_device *netdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   192
	struct ccat_eth_register reg;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   193
	struct ccat_eth_fifo rx_fifo;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   194
	struct ccat_eth_fifo tx_fifo;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   195
	struct hrtimer poll_timer;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   196
	atomic64_t rx_bytes;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   197
	atomic64_t rx_dropped;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   198
	atomic64_t tx_bytes;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   199
	atomic64_t tx_dropped;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   200
	ec_device_t *ecdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   201
	void (*carrier_off) (struct net_device * netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   202
	 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
   203
	void (*carrier_on) (struct net_device * netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   204
	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
   205
	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
   206
	void (*start_queue) (struct net_device * netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   207
	void (*stop_queue) (struct net_device * netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   208
	void (*unregister) (struct net_device * netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   209
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   210
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   211
struct ccat_mac_register {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   212
	/** MAC error register     @+0x0 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   213
	u8 frame_len_err;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   214
	u8 rx_err;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   215
	u8 crc_err;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   216
	u8 link_lost_err;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   217
	u32 reserved1;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   218
	/** Buffer overflow errors @+0x8 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   219
	u8 rx_mem_full;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   220
	u8 reserved2[7];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   221
	/** MAC frame counter      @+0x10 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   222
	u32 tx_frames;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   223
	u32 rx_frames;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   224
	u64 reserved3;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   225
	/** MAC fifo level         @+0x20 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   226
	u8 tx_fifo_level:7;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   227
	u8 reserved4:1;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   228
	u8 reserved5[7];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   229
	/** TX memory full error   @+0x28 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   230
	u8 tx_mem_full;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   231
	u8 reserved6[7];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   232
	u64 reserved8[9];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   233
	/** Connection             @+0x78 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   234
	u8 mii_connected;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   235
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   236
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   237
static void ccat_dma_free(struct ccat_dma *const dma)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   238
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   239
	const struct ccat_dma tmp = *dma;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   240
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   241
	free_dma(dma->channel);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   242
	memset(dma, 0, sizeof(*dma));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   243
	dma_free_coherent(tmp.dev, tmp.size, tmp.start, tmp.phys);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   244
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   245
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   246
/**
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   247
 * 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
   248
 * @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
   249
 * @channel number of the DMA channel
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   250
 * @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
   251
 * @dev which should be configured for DMA
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   252
 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   253
static int ccat_dma_init(struct ccat_dma *const dma, size_t channel,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   254
			 void __iomem * const ioaddr, struct device *const dev)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   255
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   256
	void *frame;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   257
	u64 addr;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   258
	u32 translateAddr;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   259
	u32 memTranslate;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   260
	u32 memSize;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   261
	u32 data = 0xffffffff;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   262
	u32 offset = (sizeof(u64) * channel) + 0x1000;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   263
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   264
	dma->channel = channel;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   265
	dma->dev = dev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   266
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   267
	/* calculate size and alignments */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   268
	iowrite32(data, ioaddr + offset);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   269
	wmb();
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   270
	data = ioread32(ioaddr + offset);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   271
	memTranslate = data & 0xfffffffc;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   272
	memSize = (~memTranslate) + 1;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   273
	dma->size = 2 * memSize - PAGE_SIZE;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   274
	dma->start =
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   275
	    dma_zalloc_coherent(dev, dma->size, &dma->phys, GFP_KERNEL);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   276
	if (!dma->start || !dma->phys) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   277
		pr_info("init DMA%llu memory failed.\n", (u64) channel);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   278
		return -ENOMEM;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   279
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   280
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   281
	if (request_dma(channel, KBUILD_MODNAME)) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   282
		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
   283
		ccat_dma_free(dma);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   284
		return -EINVAL;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   285
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   286
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   287
	translateAddr = (dma->phys + memSize - PAGE_SIZE) & memTranslate;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   288
	addr = translateAddr;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   289
	memcpy_toio(ioaddr + offset, &addr, sizeof(addr));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   290
	frame = dma->start + translateAddr - dma->phys;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   291
	pr_debug
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   292
	    ("DMA%llu mem initialized\n start:         0x%p\n phys:         0x%llx\n translated:   0x%llx\n pci addr:     0x%08x%x\n memTranslate: 0x%x\n size:         %llu bytes.\n",
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   293
	     (u64) channel, dma->start, (u64) (dma->phys), addr,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   294
	     ioread32(ioaddr + offset + 4), ioread32(ioaddr + offset),
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   295
	     memTranslate, (u64) dma->size);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   296
	return 0;
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   297
}
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
   298
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   299
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
   300
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   301
	/* 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
   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
2570
144e11d93e99 - don't use compat.h in the mainline driver
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2569
diff changeset
   304
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
   305
{
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
   306
	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
   307
	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
   308
}
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
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
   310
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
   311
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   312
	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
   313
	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
   314
}
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
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
   317
{
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
	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
   319
	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
   320
}
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
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
   323
{
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
	/* 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
   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
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   327
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
   328
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   329
	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
   330
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   331
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   332
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
   333
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   334
	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
   335
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   336
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
   337
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
   338
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   339
	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
   340
	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
   341
	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
   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
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   344
static inline bool fifo_eim_tx_ready(const struct ccat_eth_priv *const priv)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   345
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   346
	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
   347
	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
   348
	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
   349
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   350
	return !(ioread8(addr) & TX_FIFO_LEVEL_MASK);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   351
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   352
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   353
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
   354
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   355
	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
   356
	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
   357
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   358
	return (len < OVERHEAD) ? 0 : len - OVERHEAD;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   359
}
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 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
   362
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   363
	if (++fifo->mem.next > fifo->end)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   364
		fifo->mem.next = fifo->mem.start;
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 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
   368
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   369
	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
   370
	iowrite16(0, frame);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   371
	wmb();
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
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   374
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
   375
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   376
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   377
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   378
#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
   379
#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
   380
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
   381
					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
   382
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   383
	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
   384
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   385
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   386
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
   387
			       struct sk_buff *skb)
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
	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
   390
	const u32 addr_and_length =
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   391
	    (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
   392
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   393
	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
   394
	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
   395
	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
   396
	iowrite32(addr_and_length, fifo->reg);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   397
}
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
static void ccat_eth_priv_free_eim(struct ccat_eth_priv *priv)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   400
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   401
	/* reset hw fifo's */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   402
	iowrite32(0, priv->tx_fifo.reg + 0x8);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   403
	wmb();
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   404
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   405
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   406
static void ccat_eth_fifo_reset(struct ccat_eth_fifo *const fifo)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   407
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   408
	/* reset hw fifo */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   409
	if (fifo->reg) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   410
		iowrite32(0, fifo->reg + 0x8);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   411
		wmb();
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   412
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   413
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   414
	if (fifo->add) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   415
		fifo->mem.next = fifo->mem.start;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   416
		do {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   417
			fifo->add(fifo);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   418
			ccat_eth_fifo_inc(fifo);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   419
		} while (fifo->mem.next != fifo->mem.start);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   420
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   421
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   422
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   423
static inline bool fifo_dma_tx_ready(const struct ccat_eth_priv *const priv)
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
	const struct ccat_dma_frame *frame = priv->tx_fifo.dma.next;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   426
	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
   427
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   428
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   429
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
   430
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   431
	static const size_t OVERHEAD =
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   432
	    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
   433
	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
   434
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   435
	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
   436
		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
   437
		return (len < OVERHEAD) ? 0 : len - OVERHEAD;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   438
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   439
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   440
}
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
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
   443
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   444
	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
   445
	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
   446
	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
   447
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   448
	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
   449
	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
   450
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   451
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   452
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
   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
	/* 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
   455
	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
   456
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   457
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   458
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
   459
					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
   460
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   461
	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
   462
}
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
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
   465
			       struct sk_buff *skb)
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
	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
   468
	u32 addr_and_length;
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
	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
   471
	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
   472
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   473
	memcpy(frame->data, skb->data, skb->len);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   474
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   475
	/* 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
   476
	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
   477
	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
   478
	addr_and_length +=
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   479
	    ((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
   480
	iowrite32(addr_and_length, fifo->reg);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   481
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   482
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
   483
static void ccat_eth_priv_free_dma(struct ccat_eth_priv *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
   484
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   485
	/* reset hw fifo's */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   486
	iowrite32(0, priv->rx_fifo.reg + 0x8);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   487
	iowrite32(0, priv->tx_fifo.reg + 0x8);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   488
	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
   489
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   490
	/* release dma */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   491
	ccat_dma_free(&priv->rx_fifo.dma);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   492
	ccat_dma_free(&priv->tx_fifo.dma);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   493
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   494
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   495
/**
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   496
 * Initalizes both (Rx/Tx) DMA fifo's and related management structures
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   497
 */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   498
static int ccat_eth_priv_init_dma(struct ccat_eth_priv *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
   499
{
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   500
	struct ccat_function *const func = priv->func;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   501
	struct pci_dev *pdev = func->ccat->pdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   502
	int status = 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   503
	priv->rx_ready = fifo_dma_rx_ready;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   504
	priv->tx_ready = fifo_dma_tx_ready;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   505
	priv->free = ccat_eth_priv_free_dma;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   506
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   507
	status =
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   508
	    ccat_dma_init(&priv->rx_fifo.dma, func->info.rx_dma_chan,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   509
			  func->ccat->bar_2, &pdev->dev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   510
	if (status) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   511
		pr_info("init RX DMA memory failed.\n");
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   512
		return status;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   513
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   514
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   515
	status =
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   516
	    ccat_dma_init(&priv->tx_fifo.dma, func->info.tx_dma_chan,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   517
			  func->ccat->bar_2, &pdev->dev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   518
	if (status) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   519
		pr_info("init TX DMA memory failed.\n");
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
   520
		ccat_dma_free(&priv->rx_fifo.dma);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   521
		return status;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   522
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   523
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   524
	priv->rx_fifo.add = ccat_eth_rx_fifo_dma_add;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   525
	priv->rx_fifo.copy_to_skb = fifo_dma_copy_to_linear_skb;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   526
	priv->rx_fifo.queue_skb = NULL;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   527
	priv->rx_fifo.end =
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   528
	    ((struct ccat_eth_frame *)priv->rx_fifo.dma.start) + FIFO_LENGTH -
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   529
	    1;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   530
	priv->rx_fifo.reg = priv->reg.rx_fifo;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   531
	ccat_eth_fifo_reset(&priv->rx_fifo);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   532
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   533
	priv->tx_fifo.add = ccat_eth_tx_fifo_dma_add_free;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   534
	priv->tx_fifo.copy_to_skb = NULL;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   535
	priv->tx_fifo.queue_skb = fifo_dma_queue_skb;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   536
	priv->tx_fifo.end =
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   537
	    ((struct ccat_eth_frame *)priv->tx_fifo.dma.start) + FIFO_LENGTH -
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   538
	    1;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   539
	priv->tx_fifo.reg = priv->reg.tx_fifo;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   540
	ccat_eth_fifo_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
   541
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   542
	/* disable MAC filter */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   543
	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
   544
	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
   545
	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
   546
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   547
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   548
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
   549
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   550
	priv->rx_ready = fifo_eim_rx_ready;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   551
	priv->tx_ready = fifo_eim_tx_ready;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   552
	priv->free = ccat_eth_priv_free_eim;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   553
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   554
	priv->rx_fifo.eim.start = priv->reg.rx_mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   555
	priv->rx_fifo.eim.size = priv->func->info.rx_size;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   556
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   557
	priv->rx_fifo.add = fifo_eim_rx_add;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   558
	priv->rx_fifo.copy_to_skb = fifo_eim_copy_to_linear_skb;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   559
	priv->rx_fifo.queue_skb = NULL;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   560
	priv->rx_fifo.end = priv->rx_fifo.dma.start;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   561
	priv->rx_fifo.reg = NULL;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   562
	ccat_eth_fifo_reset(&priv->rx_fifo);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   563
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   564
	priv->tx_fifo.eim.start = priv->reg.tx_mem;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   565
	priv->tx_fifo.eim.size = priv->func->info.tx_size;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   566
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   567
	priv->tx_fifo.add = fifo_eim_tx_add;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   568
	priv->tx_fifo.copy_to_skb = NULL;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   569
	priv->tx_fifo.queue_skb = fifo_eim_queue_skb;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   570
	priv->tx_fifo.end =
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   571
	    priv->tx_fifo.dma.start + priv->tx_fifo.dma.size -
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   572
	    sizeof(struct ccat_eth_frame);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   573
	priv->tx_fifo.reg = priv->reg.tx_fifo;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   574
	ccat_eth_fifo_reset(&priv->tx_fifo);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   575
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   576
	/* disable MAC filter */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   577
	iowrite8(0, priv->reg.mii + 0x8 + 6);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   578
	wmb();
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   579
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   580
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   581
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   582
/**
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   583
 * 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
   584
 * CCAT function.
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   585
 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   586
static void ccat_eth_priv_init_reg(struct ccat_eth_register *const reg,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   587
				   const struct ccat_function *const func)
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
   588
{
2569
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2568
diff changeset
   589
	struct ccat_mac_infoblock offsets;
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   590
	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
   591
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   592
	/* struct ccat_eth_fifo contains a union of ccat_dma, ccat_eim and ccat_mem
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   593
	 * the members next, start and size have to overlay the exact same memory,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   594
	 * to support 'polymorphic' usage of them */
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, next) !=
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   596
		     offsetof(struct ccat_mem, next));
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, start) !=
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   598
		     offsetof(struct ccat_mem, start));
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, next) !=
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   600
		     offsetof(struct ccat_eim, next));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   601
	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
   602
		     offsetof(struct ccat_eim, start));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   603
	BUILD_BUG_ON(offsetof(struct ccat_dma, size) !=
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   604
		     offsetof(struct ccat_eim, size));
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
   605
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
   606
	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
   607
	reg->mii = func_base + offsets.mii;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   608
	reg->tx_fifo = func_base + offsets.tx_fifo;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   609
	reg->rx_fifo = func_base + offsets.tx_fifo + 0x10;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   610
	reg->mac = func_base + offsets.mac;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   611
	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
   612
	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
   613
	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
   614
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   615
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   616
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
   617
				       struct net_device *dev)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   618
{
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   619
	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
   620
	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
   621
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   622
	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
   623
		pr_warn("Non linear skb not supported -> drop frame.\n");
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   624
		atomic64_inc(&priv->tx_dropped);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   625
		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
   626
		return NETDEV_TX_OK;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   627
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   628
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   629
	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
   630
		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
   631
			(u64) skb->len, (u64) MAX_PAYLOAD_SIZE);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   632
		atomic64_inc(&priv->tx_dropped);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   633
		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
   634
		return NETDEV_TX_OK;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   635
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   636
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   637
	if (!priv->tx_ready(priv)) {
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   638
		netdev_err(dev, "BUG! Tx Ring full when queue awake!\n");
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   639
		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
   640
		return NETDEV_TX_BUSY;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   641
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   642
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   643
	/* prepare frame in DMA memory */
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   644
	fifo->queue_skb(fifo, skb);
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   645
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   646
	/* update stats */
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   647
	atomic64_add(skb->len, &priv->tx_bytes);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   648
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   649
	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
   650
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   651
	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
   652
	/* stop queue if tx ring is full */
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   653
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   654
	if (!priv->tx_ready(priv)) {
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   655
		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
   656
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   657
	return NETDEV_TX_OK;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   658
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   659
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
 * 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
   662
 * @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
   663
 * @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
   664
 * @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
   665
 */
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   666
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
   667
			      size_t len)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   668
{
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   669
	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
   670
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   671
	skb->dev = dev;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   672
	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
   673
	skb_put(skb, len);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   674
	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
   675
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   676
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   677
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
   678
{
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   679
	struct sk_buff *const skb = dev_alloc_skb(len + NET_IP_ALIGN);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   680
	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
   681
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   682
	if (!skb) {
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   683
		pr_info("%s() out of memory :-(\n", __FUNCTION__);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   684
		atomic64_inc(&priv->rx_dropped);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   685
		return;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   686
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   687
	skb->dev = dev;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   688
	skb_reserve(skb, NET_IP_ALIGN);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   689
	priv->rx_fifo.copy_to_skb(&priv->rx_fifo, skb, len);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   690
	skb_put(skb, len);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   691
	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
   692
	skb->ip_summed = CHECKSUM_UNNECESSARY;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   693
	atomic64_add(len, &priv->rx_bytes);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   694
	netif_rx(skb);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   695
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   696
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   697
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
   698
{
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   699
	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
   700
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   701
	priv->stop_queue(dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   702
	priv->carrier_off(dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   703
	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
   704
}
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
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
   707
{
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   708
	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
   709
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   710
	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
   711
	/* 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
   712
	   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
   713
	   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
   714
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   715
	ccat_eth_fifo_reset(&priv->rx_fifo);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   716
	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
   717
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   718
	/* 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
   719
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   720
	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
   721
			  sizeof(frameForwardEthernetFrames));
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   722
	priv->carrier_on(dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   723
	priv->start_queue(dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   724
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   725
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
   726
/**
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
 * 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
   728
 * @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
   729
 */
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
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
   731
						   *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
   732
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   733
	return (1 << 24) == (ioread32(priv->reg.mii + 0x8 + 4) & (1 << 24));
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   734
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   735
2572
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
 * 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
   738
 */
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   739
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
   740
{
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   741
	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
   742
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   743
	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
   744
		if (link)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   745
			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
   746
		else
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   747
			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
   748
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   749
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   750
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   751
/**
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   752
 * Poll for available rx dma descriptors in ethernet operating mode
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   753
 */
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   754
static void poll_rx(struct ccat_eth_priv *const priv)
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   755
{
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   756
	struct ccat_eth_fifo *const fifo = &priv->rx_fifo;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   757
	size_t rx_per_poll = FIFO_LENGTH / 2;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   758
	size_t len = priv->rx_ready(fifo);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   759
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   760
	while (len && --rx_per_poll) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   761
		priv->receive(priv, len);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   762
		fifo->add(fifo);
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   763
		ccat_eth_fifo_inc(fifo);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   764
		len = priv->rx_ready(fifo);
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   765
	}
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   766
}
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   767
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   768
static void ec_poll_rx(struct net_device *dev)
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   769
{
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   770
	struct ccat_eth_priv *const priv = netdev_priv(dev);
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   771
	poll_rx(priv);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   772
}
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
/**
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   775
 * 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
   776
 */
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   777
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
   778
{
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   779
	if (priv->tx_ready(priv)) {
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   780
		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
   781
	}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   782
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   783
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
 * 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
   786
 * 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
   787
 */
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   788
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
   789
{
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   790
	struct ccat_eth_priv *const priv =
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   791
	    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
   792
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   793
	poll_link(priv);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   794
	if (!priv->ecdev) {
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   795
		poll_rx(priv);
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   796
		poll_tx(priv);
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   797
	}
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   798
	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
   799
	return HRTIMER_RESTART;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   800
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   801
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
   802
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
   803
						      *storage)
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
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   805
	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
   806
	struct ccat_mac_register mac;
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    */
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
   810
	storage->rx_bytes = atomic64_read(&priv->rx_bytes);	/* total bytes 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
   811
	storage->tx_bytes = atomic64_read(&priv->tx_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     */
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
   814
	storage->rx_dropped = atomic64_read(&priv->rx_dropped);	/* no space in linux buffers    */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   815
	storage->tx_dropped = atomic64_read(&priv->tx_dropped);	/* no space available in linux  */
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;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   837
	return storage;
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
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   839
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   840
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
   841
{
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   842
	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
   843
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   844
	hrtimer_init(&priv->poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   845
	priv->poll_timer.function = poll_timer_callback;
2576
f6a5b3bb0594 Refactoring:
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2574
diff changeset
   846
	hrtimer_start(&priv->poll_timer, POLL_TIME, HRTIMER_MODE_REL);
2572
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   847
	return 0;
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   848
}
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   849
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   850
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
   851
{
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   852
	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
   853
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   854
	priv->stop_queue(dev);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   855
	hrtimer_cancel(&priv->poll_timer);
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   856
	return 0;
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
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   859
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
   860
	.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
   861
	.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
   862
	.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
   863
	.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
   864
};
0bc1ec2711b1 reorder functions in netdev.c to avoid forward declarations
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2570
diff changeset
   865
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   866
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
   867
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   868
	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
   869
	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
   870
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   871
	if (netdev) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   872
		priv = netdev_priv(netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   873
		memset(priv, 0, sizeof(*priv));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   874
		priv->netdev = netdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   875
		priv->func = func;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   876
		ccat_eth_priv_init_reg(&priv->reg, func);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   877
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   878
	return priv;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   879
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   880
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   881
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
   882
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   883
	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
   884
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   885
	/* 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
   886
	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
   887
		      priv->netdev->addr_len);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   888
	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
   889
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
	/* use as EtherCAT device? */
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   891
	priv->carrier_off = ecdev_carrier_off;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   892
	priv->carrier_ok = ecdev_carrier_ok;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   893
	priv->carrier_on = ecdev_carrier_on;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   894
	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
   895
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   896
	/* 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
   897
	 * 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
   898
	 * 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
   899
	 * So we check if there is a rx dma fifo registered to determine dma/io mode */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   900
	if (priv->rx_fifo.reg) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   901
		priv->receive = ecdev_receive_dma;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   902
	} else {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   903
		priv->receive = ecdev_receive_eim;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   904
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   905
	priv->start_queue = ecdev_nop;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   906
	priv->stop_queue = ecdev_nop;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   907
	priv->unregister = unregister_ecdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   908
	priv->ecdev = ecdev_offer(priv->netdev, ec_poll_rx, 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
   909
	if (priv->ecdev) {
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   910
		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
   911
		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
   912
			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
   913
			ecdev_withdraw(priv->ecdev);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   914
			priv->free(priv);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   915
			free_netdev(priv->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   916
			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
   917
		}
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   918
		priv->func->private_data = priv;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   919
		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
   920
	}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   921
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   922
	/* 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
   923
	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
   924
	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
   925
	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
   926
	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
   927
	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
   928
	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
   929
	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
   930
	priv->unregister = unregister_netdev;
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   931
	priv->carrier_off(priv->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   932
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   933
	status = register_netdev(priv->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   934
	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
   935
		pr_info("unable to register network device.\n");
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   936
		priv->free(priv);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   937
		free_netdev(priv->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   938
		return status;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   939
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   940
	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
   941
	priv->func->private_data = priv;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   942
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   943
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   944
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   945
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
   946
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   947
	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
   948
	int status;
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
	if (!priv)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   951
		return -ENOMEM;
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
	status = ccat_eth_priv_init_dma(priv);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   954
	if (status) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   955
		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
   956
		free_netdev(priv->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   957
		return status;
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
	return ccat_eth_init_netdev(priv);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   960
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   961
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   962
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
   963
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   964
	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
   965
	eth->unregister(eth->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   966
	eth->free(eth);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   967
	free_netdev(eth->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   968
}
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_driver eth_dma_driver = {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   971
	.type = CCATINFO_ETHERCAT_MASTER_DMA,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   972
	.probe = ccat_eth_dma_probe,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   973
	.remove = ccat_eth_dma_remove,
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
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   976
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
   977
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   978
	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
   979
	int status;
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
	if (!priv)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   982
		return -ENOMEM;
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
	status = ccat_eth_priv_init_eim(priv);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   985
	if (status) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   986
		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
   987
		free_netdev(priv->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   988
		return status;
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
	return ccat_eth_init_netdev(priv);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   991
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   992
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   993
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
   994
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   995
	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
   996
	eth->unregister(eth->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   997
	eth->free(eth);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   998
	free_netdev(eth->netdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
   999
}
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_driver eth_eim_driver = {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1002
	.type = CCATINFO_ETHERCAT_NODMA,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1003
	.probe = ccat_eth_eim_probe,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1004
	.remove = ccat_eth_eim_remove,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2578
diff changeset
  1005
};