devices/r8169-2.6.24-ethercat.c
author Florian Pose <fp@igh-essen.com>
Mon, 05 May 2014 13:55:00 +0200
branchstable-1.5
changeset 2542 8dd49f6f6d32
parent 2251 5023ce75fe91
child 2582 87e502828b3f
permissions -rw-r--r--
Fixed hex display of slave position; thanks to Henry Bausley.
1353
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 * r8169.c: RealTek 8169/8168/8101 ethernet driver.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 * Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 * Copyright (c) a lot of people too. Please respect their work.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 * See MAINTAINERS file for support contact information.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 * vim: noexpandtab
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
#include <linux/module.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
#include <linux/moduleparam.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
#include <linux/pci.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
#include <linux/netdevice.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
#include <linux/etherdevice.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
#include <linux/delay.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
#include <linux/ethtool.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
#include <linux/mii.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
#include <linux/if_vlan.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
#include <linux/crc32.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
#include <linux/in.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
#include <linux/ip.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
#include <linux/tcp.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
#include <linux/init.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
#include <linux/dma-mapping.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
#include <asm/system.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <asm/io.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <asm/irq.h>
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include "../globals.h"
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include "ecdev.h"
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#ifdef CONFIG_R8169_NAPI
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#define NAPI_SUFFIX	"-NAPI"
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#else
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#define NAPI_SUFFIX	""
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#define RTL8169_VERSION "2.2LK" NAPI_SUFFIX
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#define MODULENAME "ec_r8169"
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#define PFX MODULENAME ": "
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
#ifdef RTL8169_DEBUG
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
#define assert(expr) \
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
	if (!(expr)) {					\
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
		printk( "Assertion failed! %s,%s,%s,line=%d\n",	\
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
		#expr,__FILE__,__FUNCTION__,__LINE__);		\
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
#define dprintk(fmt, args...) \
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
	do { printk(KERN_DEBUG PFX fmt, ## args); } while (0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
#else
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
#define assert(expr) do {} while (0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
#define dprintk(fmt, args...)	do {} while (0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
#endif /* RTL8169_DEBUG */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
#define R8169_MSG_DEFAULT \
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
	(NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
#define TX_BUFFS_AVAIL(tp) \
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
	(tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
#ifdef CONFIG_R8169_NAPI
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
#define rtl8169_rx_skb			netif_receive_skb
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
#define rtl8169_rx_hwaccel_skb		vlan_hwaccel_receive_skb
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
#define rtl8169_rx_quota(count, quota)	min(count, quota)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
#else
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
#define rtl8169_rx_skb			netif_rx
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
#define rtl8169_rx_hwaccel_skb		vlan_hwaccel_rx
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
#define rtl8169_rx_quota(count, quota)	count
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
static const int max_interrupt_work = 20;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
   The RTL chips use a 64 element hash table based on the Ethernet CRC. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
static const int multicast_filter_limit = 32;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
/* MAC address length */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
#define MAC_ADDR_LEN	6
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
#define RX_FIFO_THRESH	7	/* 7 means NO threshold, Rx buffer level before first PCI xfer. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
#define RX_DMA_BURST	6	/* Maximum PCI burst, '6' is 1024 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
#define TX_DMA_BURST	6	/* Maximum PCI burst, '6' is 1024 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
#define EarlyTxThld	0x3F	/* 0x3F means NO early transmit */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
#define RxPacketMaxSize	0x3FE8	/* 16K - 1 - ETH_HLEN - VLAN - CRC... */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
#define SafeMtu		0x1c20	/* ... actually life sucks beyond ~7k */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
#define InterFrameGap	0x03	/* 3 means InterFrameGap = the shortest one */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
#define R8169_REGS_SIZE		256
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
#define R8169_NAPI_WEIGHT	64
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
#define NUM_TX_DESC	64	/* Number of Tx descriptor registers */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
#define NUM_RX_DESC	256	/* Number of Rx descriptor registers */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
#define RX_BUF_SIZE	1536	/* Rx Buffer size */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
#define R8169_TX_RING_BYTES	(NUM_TX_DESC * sizeof(struct TxDesc))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
#define R8169_RX_RING_BYTES	(NUM_RX_DESC * sizeof(struct RxDesc))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
#define RTL8169_TX_TIMEOUT	(6*HZ)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
#define RTL8169_PHY_TIMEOUT	(10*HZ)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
/* write/read MMIO register */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
#define RTL_W8(reg, val8)	writeb ((val8), ioaddr + (reg))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
#define RTL_W16(reg, val16)	writew ((val16), ioaddr + (reg))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
#define RTL_W32(reg, val32)	writel ((val32), ioaddr + (reg))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
#define RTL_R8(reg)		readb (ioaddr + (reg))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
#define RTL_R16(reg)		readw (ioaddr + (reg))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
#define RTL_R32(reg)		((unsigned long) readl (ioaddr + (reg)))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
enum mac_version {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
	RTL_GIGA_MAC_VER_01 = 0x01, // 8169
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
	RTL_GIGA_MAC_VER_02 = 0x02, // 8169S
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
	RTL_GIGA_MAC_VER_03 = 0x03, // 8110S
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
	RTL_GIGA_MAC_VER_04 = 0x04, // 8169SB
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
	RTL_GIGA_MAC_VER_05 = 0x05, // 8110SCd
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
	RTL_GIGA_MAC_VER_06 = 0x06, // 8110SCe
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
	RTL_GIGA_MAC_VER_11 = 0x0b, // 8168Bb
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
	RTL_GIGA_MAC_VER_12 = 0x0c, // 8168Be
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
	RTL_GIGA_MAC_VER_13 = 0x0d, // 8101Eb
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
	RTL_GIGA_MAC_VER_14 = 0x0e, // 8101 ?
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
	RTL_GIGA_MAC_VER_15 = 0x0f, // 8101 ?
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
	RTL_GIGA_MAC_VER_16 = 0x11, // 8101Ec
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
	RTL_GIGA_MAC_VER_17 = 0x10, // 8168Bf
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
	RTL_GIGA_MAC_VER_18 = 0x12, // 8168CP
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
	RTL_GIGA_MAC_VER_19 = 0x13, // 8168C
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
	RTL_GIGA_MAC_VER_20 = 0x14  // 8168C
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
#define _R(NAME,MAC,MASK) \
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
	{ .name = NAME, .mac_version = MAC, .RxConfigMask = MASK }
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
static const struct {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
	const char *name;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
	u8 mac_version;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
	u32 RxConfigMask;	/* Clears the bits supported by this chip */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
} rtl_chip_info[] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
	_R("RTL8169",		RTL_GIGA_MAC_VER_01, 0xff7e1880), // 8169
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
	_R("RTL8169s",		RTL_GIGA_MAC_VER_02, 0xff7e1880), // 8169S
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
	_R("RTL8110s",		RTL_GIGA_MAC_VER_03, 0xff7e1880), // 8110S
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
	_R("RTL8169sb/8110sb",	RTL_GIGA_MAC_VER_04, 0xff7e1880), // 8169SB
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
	_R("RTL8169sc/8110sc",	RTL_GIGA_MAC_VER_05, 0xff7e1880), // 8110SCd
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
	_R("RTL8169sc/8110sc",	RTL_GIGA_MAC_VER_06, 0xff7e1880), // 8110SCe
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
	_R("RTL8168b/8111b",	RTL_GIGA_MAC_VER_11, 0xff7e1880), // PCI-E
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
	_R("RTL8168b/8111b",	RTL_GIGA_MAC_VER_12, 0xff7e1880), // PCI-E
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
	_R("RTL8101e",		RTL_GIGA_MAC_VER_13, 0xff7e1880), // PCI-E 8139
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
	_R("RTL8100e",		RTL_GIGA_MAC_VER_14, 0xff7e1880), // PCI-E 8139
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
	_R("RTL8100e",		RTL_GIGA_MAC_VER_15, 0xff7e1880), // PCI-E 8139
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
	_R("RTL8168b/8111b",	RTL_GIGA_MAC_VER_17, 0xff7e1880), // PCI-E
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
	_R("RTL8101e",		RTL_GIGA_MAC_VER_16, 0xff7e1880), // PCI-E
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
	_R("RTL8168cp/8111cp",	RTL_GIGA_MAC_VER_18, 0xff7e1880), // PCI-E
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
	_R("RTL8168c/8111c",	RTL_GIGA_MAC_VER_19, 0xff7e1880), // PCI-E
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
	_R("RTL8168c/8111c",	RTL_GIGA_MAC_VER_20, 0xff7e1880)  // PCI-E
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
#undef _R
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
enum cfg_version {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
	RTL_CFG_0 = 0x00,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
	RTL_CFG_1,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
	RTL_CFG_2
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
static void rtl_hw_start_8169(struct net_device *);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
static void rtl_hw_start_8168(struct net_device *);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
static void rtl_hw_start_8101(struct net_device *);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
static struct pci_device_id rtl8169_pci_tbl[] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
	{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK,	0x8129), 0, 0, RTL_CFG_0 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
	{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK,	0x8136), 0, 0, RTL_CFG_2 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
	{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK,	0x8167), 0, 0, RTL_CFG_0 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
	{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK,	0x8168), 0, 0, RTL_CFG_1 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
	{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK,	0x8169), 0, 0, RTL_CFG_0 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
	{ PCI_DEVICE(PCI_VENDOR_ID_DLINK,	0x4300), 0, 0, RTL_CFG_0 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
	{ PCI_DEVICE(PCI_VENDOR_ID_AT,		0xc107), 0, 0, RTL_CFG_0 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
	{ PCI_DEVICE(0x16ec,			0x0116), 0, 0, RTL_CFG_0 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
	{ PCI_VENDOR_ID_LINKSYS,		0x1032,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
		PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
	{ 0x0001,				0x8168,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
		PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
	{0,},
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
/* prevent driver from being loaded automatically */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
//MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
static int rx_copybreak = 200;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
static int use_dac;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
static struct {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
	u32 msg_enable;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
} debug = { -1 };
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
enum rtl_registers {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
	MAC0		= 0,	/* Ethernet hardware address. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
	MAC4		= 4,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
	MAR0		= 8,	/* Multicast filter. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
	CounterAddrLow		= 0x10,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
	CounterAddrHigh		= 0x14,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
	TxDescStartAddrLow	= 0x20,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
	TxDescStartAddrHigh	= 0x24,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
	TxHDescStartAddrLow	= 0x28,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
	TxHDescStartAddrHigh	= 0x2c,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
	FLASH		= 0x30,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
	ERSR		= 0x36,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
	ChipCmd		= 0x37,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
	TxPoll		= 0x38,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
	IntrMask	= 0x3c,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
	IntrStatus	= 0x3e,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
	TxConfig	= 0x40,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
	RxConfig	= 0x44,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
	RxMissed	= 0x4c,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
	Cfg9346		= 0x50,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
	Config0		= 0x51,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
	Config1		= 0x52,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
	Config2		= 0x53,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
	Config3		= 0x54,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
	Config4		= 0x55,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
	Config5		= 0x56,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
	MultiIntr	= 0x5c,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
	PHYAR		= 0x60,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
	TBICSR		= 0x64,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
	TBI_ANAR	= 0x68,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
	TBI_LPAR	= 0x6a,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
	PHYstatus	= 0x6c,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
	RxMaxSize	= 0xda,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
	CPlusCmd	= 0xe0,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
	IntrMitigate	= 0xe2,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
	RxDescAddrLow	= 0xe4,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
	RxDescAddrHigh	= 0xe8,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
	EarlyTxThres	= 0xec,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
	FuncEvent	= 0xf0,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
	FuncEventMask	= 0xf4,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
	FuncPresetState	= 0xf8,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
	FuncForceEvent	= 0xfc,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
enum rtl_register_content {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
	/* InterruptStatusBits */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
	SYSErr		= 0x8000,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
	PCSTimeout	= 0x4000,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
	SWInt		= 0x0100,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
	TxDescUnavail	= 0x0080,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
	RxFIFOOver	= 0x0040,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
	LinkChg		= 0x0020,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
	RxOverflow	= 0x0010,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
	TxErr		= 0x0008,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
	TxOK		= 0x0004,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
	RxErr		= 0x0002,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
	RxOK		= 0x0001,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
	/* RxStatusDesc */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
	RxFOVF	= (1 << 23),
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
	RxRWT	= (1 << 22),
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
	RxRES	= (1 << 21),
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
	RxRUNT	= (1 << 20),
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
	RxCRC	= (1 << 19),
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
	/* ChipCmdBits */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
	CmdReset	= 0x10,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
	CmdRxEnb	= 0x08,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
	CmdTxEnb	= 0x04,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
	RxBufEmpty	= 0x01,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
	/* TXPoll register p.5 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
	HPQ		= 0x80,		/* Poll cmd on the high prio queue */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
	NPQ		= 0x40,		/* Poll cmd on the low prio queue */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
	FSWInt		= 0x01,		/* Forced software interrupt */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
	/* Cfg9346Bits */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
	Cfg9346_Lock	= 0x00,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
	Cfg9346_Unlock	= 0xc0,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
	/* rx_mode_bits */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
	AcceptErr	= 0x20,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
	AcceptRunt	= 0x10,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
	AcceptBroadcast	= 0x08,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
	AcceptMulticast	= 0x04,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
	AcceptMyPhys	= 0x02,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
	AcceptAllPhys	= 0x01,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
	/* RxConfigBits */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
	RxCfgFIFOShift	= 13,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
	RxCfgDMAShift	=  8,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
	/* TxConfigBits */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
	TxInterFrameGapShift = 24,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
	TxDMAShift = 8,	/* DMA burst value (0-7) is shift this many bits */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
	/* Config1 register p.24 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
	MSIEnable	= (1 << 5),	/* Enable Message Signaled Interrupt */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
	PMEnable	= (1 << 0),	/* Power Management Enable */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
	/* Config2 register p. 25 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
	PCI_Clock_66MHz = 0x01,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
	PCI_Clock_33MHz = 0x00,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   297
	/* Config3 register p.25 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
	MagicPacket	= (1 << 5),	/* Wake up when receives a Magic Packet */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
	LinkUp		= (1 << 4),	/* Wake up when the cable connection is re-established */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
	/* Config5 register p.27 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
	BWF		= (1 << 6),	/* Accept Broadcast wakeup frame */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
	MWF		= (1 << 5),	/* Accept Multicast wakeup frame */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
	UWF		= (1 << 4),	/* Accept Unicast wakeup frame */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
	LanWake		= (1 << 1),	/* LanWake enable/disable */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
	PMEStatus	= (1 << 0),	/* PME status can be reset by PCI RST# */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
	/* TBICSR p.28 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
	TBIReset	= 0x80000000,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
	TBILoopback	= 0x40000000,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
	TBINwEnable	= 0x20000000,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
	TBINwRestart	= 0x10000000,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
	TBILinkOk	= 0x02000000,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
	TBINwComplete	= 0x01000000,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
	/* CPlusCmd p.31 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
	PktCntrDisable	= (1 << 7),	// 8168
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
	RxVlan		= (1 << 6),
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
	RxChkSum	= (1 << 5),
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
	PCIDAC		= (1 << 4),
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   321
	PCIMulRW	= (1 << 3),
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   322
	INTT_0		= 0x0000,	// 8168
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
	INTT_1		= 0x0001,	// 8168
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
	INTT_2		= 0x0002,	// 8168
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
	INTT_3		= 0x0003,	// 8168
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   327
	/* rtl8169_PHYstatus */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   328
	TBI_Enable	= 0x80,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   329
	TxFlowCtrl	= 0x40,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   330
	RxFlowCtrl	= 0x20,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   331
	_1000bpsF	= 0x10,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   332
	_100bps		= 0x08,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   333
	_10bps		= 0x04,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
	LinkStatus	= 0x02,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
	FullDup		= 0x01,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   336
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
	/* _TBICSRBit */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
	TBILinkOK	= 0x02000000,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
	/* DumpCounterCommand */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
	CounterDump	= 0x8,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   342
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   343
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   344
enum desc_status_bit {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   345
	DescOwn		= (1 << 31), /* Descriptor is owned by NIC */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
	RingEnd		= (1 << 30), /* End of descriptor ring */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
	FirstFrag	= (1 << 29), /* First segment of a packet */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
	LastFrag	= (1 << 28), /* Final segment of a packet */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
	/* Tx private */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   351
	LargeSend	= (1 << 27), /* TCP Large Send Offload (TSO) */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   352
	MSSShift	= 16,        /* MSS value position */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   353
	MSSMask		= 0xfff,     /* MSS value + LargeSend bit: 12 bits */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
	IPCS		= (1 << 18), /* Calculate IP checksum */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
	UDPCS		= (1 << 17), /* Calculate UDP/IP checksum */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
	TCPCS		= (1 << 16), /* Calculate TCP/IP checksum */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   357
	TxVlanTag	= (1 << 17), /* Add VLAN tag */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   359
	/* Rx private */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   360
	PID1		= (1 << 18), /* Protocol ID bit 1/2 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   361
	PID0		= (1 << 17), /* Protocol ID bit 2/2 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   362
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   363
#define RxProtoUDP	(PID1)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   364
#define RxProtoTCP	(PID0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   365
#define RxProtoIP	(PID1 | PID0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
#define RxProtoMask	RxProtoIP
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   367
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   368
	IPFail		= (1 << 16), /* IP checksum failed */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   369
	UDPFail		= (1 << 15), /* UDP/IP checksum failed */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   370
	TCPFail		= (1 << 14), /* TCP/IP checksum failed */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   371
	RxVlanTag	= (1 << 16), /* VLAN tag available */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   372
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   373
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   374
#define RsvdMask	0x3fffc000
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   376
struct TxDesc {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   377
	__le32 opts1;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   378
	__le32 opts2;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   379
	__le64 addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   380
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   381
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   382
struct RxDesc {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   383
	__le32 opts1;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   384
	__le32 opts2;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   385
	__le64 addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   386
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   387
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   388
struct ring_info {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   389
	struct sk_buff	*skb;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   390
	u32		len;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   391
	u8		__pad[sizeof(void *) - sizeof(u32)];
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   392
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   393
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   394
enum features {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   395
	RTL_FEATURE_WOL	= (1 << 0),
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   396
	RTL_FEATURE_MSI	= (1 << 1),
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   397
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   398
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   399
struct rtl8169_private {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   400
	void __iomem *mmio_addr;	/* memory map physical address */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   401
	struct pci_dev *pci_dev;	/* Index of PCI device */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   402
	struct net_device *dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   403
#ifdef CONFIG_R8169_NAPI
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   404
	struct napi_struct napi;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   405
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   406
	spinlock_t lock;		/* spin lock flag */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   407
	u32 msg_enable;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   408
	int chipset;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   409
	int mac_version;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   410
	u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   411
	u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   412
	u32 dirty_rx;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   413
	u32 dirty_tx;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   414
	struct TxDesc *TxDescArray;	/* 256-aligned Tx descriptor ring */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   415
	struct RxDesc *RxDescArray;	/* 256-aligned Rx descriptor ring */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   416
	dma_addr_t TxPhyAddr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   417
	dma_addr_t RxPhyAddr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   418
	struct sk_buff *Rx_skbuff[NUM_RX_DESC];	/* Rx data buffers */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   419
	struct ring_info tx_skb[NUM_TX_DESC];	/* Tx data buffers */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   420
	unsigned align;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   421
	unsigned rx_buf_sz;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   422
	struct timer_list timer;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   423
	u16 cp_cmd;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   424
	u16 intr_event;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   425
	u16 napi_event;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   426
	u16 intr_mask;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   427
	int phy_auto_nego_reg;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   428
	int phy_1000_ctrl_reg;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   429
#ifdef CONFIG_R8169_VLAN
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   430
	struct vlan_group *vlgrp;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   431
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   432
	int (*set_speed)(struct net_device *, u8 autoneg, u16 speed, u8 duplex);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   433
	void (*get_settings)(struct net_device *, struct ethtool_cmd *);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   434
	void (*phy_reset_enable)(void __iomem *);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   435
	void (*hw_start)(struct net_device *);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   436
	unsigned int (*phy_reset_pending)(void __iomem *);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   437
	unsigned int (*link_ok)(void __iomem *);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   438
	struct delayed_work task;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   439
	unsigned features;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   440
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   441
	ec_device_t *ecdev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   442
	unsigned long ec_watchdog_jiffies;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   443
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   444
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   445
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   446
MODULE_DESCRIPTION("EtherCAT-capable RealTek RTL-8169 Gigabit Ethernet driver");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   447
module_param(rx_copybreak, int, 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   448
MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   449
module_param(use_dac, int, 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   450
MODULE_PARM_DESC(use_dac, "Enable PCI DAC. Unsafe on 32 bit PCI slot.");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   451
module_param_named(debug, debug.msg_enable, int, 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   452
MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   453
MODULE_LICENSE("GPL");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   454
MODULE_VERSION(EC_MASTER_VERSION);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   455
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   456
static int rtl8169_open(struct net_device *dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   457
static int rtl8169_start_xmit(struct sk_buff *skb, struct net_device *dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   458
static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   459
static int rtl8169_init_ring(struct net_device *dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   460
static void rtl_hw_start(struct net_device *dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   461
static int rtl8169_close(struct net_device *dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   462
static void rtl_set_rx_mode(struct net_device *dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   463
static void rtl8169_tx_timeout(struct net_device *dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   464
static struct net_device_stats *rtl8169_get_stats(struct net_device *dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   465
static int rtl8169_rx_interrupt(struct net_device *, struct rtl8169_private *,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   466
				void __iomem *, u32 budget);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   467
static int rtl8169_change_mtu(struct net_device *dev, int new_mtu);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   468
static void rtl8169_down(struct net_device *dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   469
static void rtl8169_rx_clear(struct rtl8169_private *tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   470
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   471
#ifdef CONFIG_R8169_NAPI
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   472
static int rtl8169_poll(struct napi_struct *napi, int budget);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   473
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   474
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   475
static const unsigned int rtl8169_rx_config =
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   476
	(RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   477
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   478
static void mdio_write(void __iomem *ioaddr, int reg_addr, int value)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   479
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   480
	int i;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   481
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   482
	RTL_W32(PHYAR, 0x80000000 | (reg_addr & 0x1f) << 16 | (value & 0xffff));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   483
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   484
	for (i = 20; i > 0; i--) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   485
		/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   486
		 * Check if the RTL8169 has completed writing to the specified
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   487
		 * MII register.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   488
		 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   489
		if (!(RTL_R32(PHYAR) & 0x80000000))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   490
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   491
		udelay(25);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   492
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   493
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   494
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   495
static int mdio_read(void __iomem *ioaddr, int reg_addr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   496
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   497
	int i, value = -1;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   498
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   499
	RTL_W32(PHYAR, 0x0 | (reg_addr & 0x1f) << 16);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   500
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   501
	for (i = 20; i > 0; i--) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   502
		/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   503
		 * Check if the RTL8169 has completed retrieving data from
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   504
		 * the specified MII register.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   505
		 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   506
		if (RTL_R32(PHYAR) & 0x80000000) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   507
			value = RTL_R32(PHYAR) & 0xffff;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   508
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   509
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   510
		udelay(25);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   511
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   512
	return value;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   513
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   514
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   515
static void rtl8169_irq_mask_and_ack(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   516
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   517
	RTL_W16(IntrMask, 0x0000);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   518
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   519
	RTL_W16(IntrStatus, 0xffff);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   520
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   521
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   522
static void rtl8169_asic_down(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   523
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   524
	RTL_W8(ChipCmd, 0x00);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   525
	rtl8169_irq_mask_and_ack(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   526
	RTL_R16(CPlusCmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   527
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   528
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   529
static unsigned int rtl8169_tbi_reset_pending(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   530
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   531
	return RTL_R32(TBICSR) & TBIReset;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   532
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   533
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   534
static unsigned int rtl8169_xmii_reset_pending(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   535
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   536
	return mdio_read(ioaddr, MII_BMCR) & BMCR_RESET;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   537
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   538
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   539
static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   540
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   541
	return RTL_R32(TBICSR) & TBILinkOk;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   542
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   543
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   544
static unsigned int rtl8169_xmii_link_ok(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   545
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   546
	return RTL_R8(PHYstatus) & LinkStatus;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   547
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   548
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   549
static void rtl8169_tbi_reset_enable(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   550
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   551
	RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   552
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   553
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   554
static void rtl8169_xmii_reset_enable(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   555
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   556
	unsigned int val;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   557
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   558
	val = mdio_read(ioaddr, MII_BMCR) | BMCR_RESET;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   559
	mdio_write(ioaddr, MII_BMCR, val & 0xffff);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   560
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   561
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   562
static void rtl8169_check_link_status(struct net_device *dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   563
				      struct rtl8169_private *tp,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   564
				      void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   565
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   566
	unsigned long flags;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   567
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   568
    if (tp->ecdev) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   569
		ecdev_set_link(tp->ecdev, tp->link_ok(ioaddr) ? 1 : 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   570
	} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   571
		spin_lock_irqsave(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   572
		if (tp->link_ok(ioaddr)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   573
			netif_carrier_on(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   574
			if (netif_msg_ifup(tp))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   575
				printk(KERN_INFO PFX "%s: link up\n", dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   576
		} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   577
			if (netif_msg_ifdown(tp))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   578
				printk(KERN_INFO PFX "%s: link down\n", dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   579
			netif_carrier_off(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   580
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   581
		spin_unlock_irqrestore(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   582
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   583
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   584
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   585
static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   586
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   587
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   588
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   589
	u8 options;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   590
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   591
	wol->wolopts = 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   592
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   593
#define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   594
	wol->supported = WAKE_ANY;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   595
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   596
	spin_lock_irq(&tp->lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   597
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   598
	options = RTL_R8(Config1);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   599
	if (!(options & PMEnable))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   600
		goto out_unlock;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   601
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   602
	options = RTL_R8(Config3);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   603
	if (options & LinkUp)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   604
		wol->wolopts |= WAKE_PHY;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   605
	if (options & MagicPacket)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   606
		wol->wolopts |= WAKE_MAGIC;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   607
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   608
	options = RTL_R8(Config5);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   609
	if (options & UWF)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   610
		wol->wolopts |= WAKE_UCAST;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   611
	if (options & BWF)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   612
		wol->wolopts |= WAKE_BCAST;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   613
	if (options & MWF)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   614
		wol->wolopts |= WAKE_MCAST;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   615
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   616
out_unlock:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   617
	spin_unlock_irq(&tp->lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   618
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   619
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   620
static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   621
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   622
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   623
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   624
	unsigned int i;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   625
	static struct {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   626
		u32 opt;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   627
		u16 reg;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   628
		u8  mask;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   629
	} cfg[] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   630
		{ WAKE_ANY,   Config1, PMEnable },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   631
		{ WAKE_PHY,   Config3, LinkUp },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   632
		{ WAKE_MAGIC, Config3, MagicPacket },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   633
		{ WAKE_UCAST, Config5, UWF },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   634
		{ WAKE_BCAST, Config5, BWF },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   635
		{ WAKE_MCAST, Config5, MWF },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   636
		{ WAKE_ANY,   Config5, LanWake }
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   637
	};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   638
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   639
	spin_lock_irq(&tp->lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   640
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   641
	RTL_W8(Cfg9346, Cfg9346_Unlock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   642
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   643
	for (i = 0; i < ARRAY_SIZE(cfg); i++) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   644
		u8 options = RTL_R8(cfg[i].reg) & ~cfg[i].mask;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   645
		if (wol->wolopts & cfg[i].opt)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   646
			options |= cfg[i].mask;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   647
		RTL_W8(cfg[i].reg, options);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   648
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   649
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   650
	RTL_W8(Cfg9346, Cfg9346_Lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   651
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   652
	if (wol->wolopts)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   653
		tp->features |= RTL_FEATURE_WOL;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   654
	else
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   655
		tp->features &= ~RTL_FEATURE_WOL;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   656
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   657
	spin_unlock_irq(&tp->lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   658
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   659
	return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   660
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   661
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   662
static void rtl8169_get_drvinfo(struct net_device *dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   663
				struct ethtool_drvinfo *info)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   664
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   665
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   666
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   667
	strcpy(info->driver, MODULENAME);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   668
	strcpy(info->version, RTL8169_VERSION);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   669
	strcpy(info->bus_info, pci_name(tp->pci_dev));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   670
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   671
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   672
static int rtl8169_get_regs_len(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   673
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   674
	return R8169_REGS_SIZE;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   675
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   676
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   677
static int rtl8169_set_speed_tbi(struct net_device *dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   678
				 u8 autoneg, u16 speed, u8 duplex)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   679
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   680
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   681
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   682
	int ret = 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   683
	u32 reg;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   684
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   685
	reg = RTL_R32(TBICSR);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   686
	if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) &&
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   687
	    (duplex == DUPLEX_FULL)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   688
		RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   689
	} else if (autoneg == AUTONEG_ENABLE)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   690
		RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   691
	else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   692
		if (netif_msg_link(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   693
			printk(KERN_WARNING "%s: "
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   694
			       "incorrect speed setting refused in TBI mode\n",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   695
			       dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   696
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   697
		ret = -EOPNOTSUPP;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   698
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   699
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   700
	return ret;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   701
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   702
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   703
static int rtl8169_set_speed_xmii(struct net_device *dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   704
				  u8 autoneg, u16 speed, u8 duplex)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   705
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   706
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   707
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   708
	int auto_nego, giga_ctrl;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   709
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   710
	auto_nego = mdio_read(ioaddr, MII_ADVERTISE);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   711
	auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   712
		       ADVERTISE_100HALF | ADVERTISE_100FULL);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   713
	giga_ctrl = mdio_read(ioaddr, MII_CTRL1000);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   714
	giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   715
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   716
	if (autoneg == AUTONEG_ENABLE) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   717
		auto_nego |= (ADVERTISE_10HALF | ADVERTISE_10FULL |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   718
			      ADVERTISE_100HALF | ADVERTISE_100FULL);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   719
		giga_ctrl |= ADVERTISE_1000FULL | ADVERTISE_1000HALF;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   720
	} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   721
		if (speed == SPEED_10)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   722
			auto_nego |= ADVERTISE_10HALF | ADVERTISE_10FULL;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   723
		else if (speed == SPEED_100)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   724
			auto_nego |= ADVERTISE_100HALF | ADVERTISE_100FULL;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   725
		else if (speed == SPEED_1000)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   726
			giga_ctrl |= ADVERTISE_1000FULL | ADVERTISE_1000HALF;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   727
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   728
		if (duplex == DUPLEX_HALF)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   729
			auto_nego &= ~(ADVERTISE_10FULL | ADVERTISE_100FULL);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   730
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   731
		if (duplex == DUPLEX_FULL)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   732
			auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_100HALF);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   733
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   734
		/* This tweak comes straight from Realtek's driver. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   735
		if ((speed == SPEED_100) && (duplex == DUPLEX_HALF) &&
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   736
		    ((tp->mac_version == RTL_GIGA_MAC_VER_13) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   737
		     (tp->mac_version == RTL_GIGA_MAC_VER_16))) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   738
			auto_nego = ADVERTISE_100HALF | ADVERTISE_CSMA;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   739
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   740
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   741
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   742
	/* The 8100e/8101e do Fast Ethernet only. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   743
	if ((tp->mac_version == RTL_GIGA_MAC_VER_13) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   744
	    (tp->mac_version == RTL_GIGA_MAC_VER_14) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   745
	    (tp->mac_version == RTL_GIGA_MAC_VER_15) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   746
	    (tp->mac_version == RTL_GIGA_MAC_VER_16)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   747
		if ((giga_ctrl & (ADVERTISE_1000FULL | ADVERTISE_1000HALF)) &&
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   748
		    netif_msg_link(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   749
			printk(KERN_INFO "%s: PHY does not support 1000Mbps.\n",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   750
			       dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   751
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   752
		giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   753
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   754
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   755
	auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   756
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   757
	if ((tp->mac_version == RTL_GIGA_MAC_VER_12) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   758
	    (tp->mac_version == RTL_GIGA_MAC_VER_17)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   759
		/* Vendor specific (0x1f) and reserved (0x0e) MII registers. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   760
		mdio_write(ioaddr, 0x1f, 0x0000);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   761
		mdio_write(ioaddr, 0x0e, 0x0000);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   762
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   763
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   764
	tp->phy_auto_nego_reg = auto_nego;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   765
	tp->phy_1000_ctrl_reg = giga_ctrl;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   766
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   767
	mdio_write(ioaddr, MII_ADVERTISE, auto_nego);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   768
	mdio_write(ioaddr, MII_CTRL1000, giga_ctrl);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   769
	mdio_write(ioaddr, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   770
	return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   771
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   772
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   773
static int rtl8169_set_speed(struct net_device *dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   774
			     u8 autoneg, u16 speed, u8 duplex)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   775
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   776
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   777
	int ret;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   778
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   779
	ret = tp->set_speed(dev, autoneg, speed, duplex);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   780
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   781
	if (netif_running(dev) && (tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   782
		mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   783
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   784
	return ret;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   785
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   786
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   787
static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   788
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   789
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   790
	unsigned long flags;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   791
	int ret;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   792
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   793
	spin_lock_irqsave(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   794
	ret = rtl8169_set_speed(dev, cmd->autoneg, cmd->speed, cmd->duplex);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   795
	spin_unlock_irqrestore(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   796
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   797
	return ret;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   798
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   799
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   800
static u32 rtl8169_get_rx_csum(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   801
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   802
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   803
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   804
	return tp->cp_cmd & RxChkSum;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   805
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   806
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   807
static int rtl8169_set_rx_csum(struct net_device *dev, u32 data)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   808
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   809
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   810
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   811
	unsigned long flags;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   812
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   813
	spin_lock_irqsave(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   814
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   815
	if (data)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   816
		tp->cp_cmd |= RxChkSum;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   817
	else
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   818
		tp->cp_cmd &= ~RxChkSum;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   819
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   820
	RTL_W16(CPlusCmd, tp->cp_cmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   821
	RTL_R16(CPlusCmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   822
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   823
	spin_unlock_irqrestore(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   824
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   825
	return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   826
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   827
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   828
#ifdef CONFIG_R8169_VLAN
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   829
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   830
static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   831
				      struct sk_buff *skb)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   832
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   833
	return (tp->vlgrp && vlan_tx_tag_present(skb)) ?
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   834
		TxVlanTag | swab16(vlan_tx_tag_get(skb)) : 0x00;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   835
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   836
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   837
static void rtl8169_vlan_rx_register(struct net_device *dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   838
				     struct vlan_group *grp)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   839
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   840
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   841
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   842
	unsigned long flags;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   843
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   844
	spin_lock_irqsave(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   845
	tp->vlgrp = grp;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   846
	if (tp->vlgrp)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   847
		tp->cp_cmd |= RxVlan;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   848
	else
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   849
		tp->cp_cmd &= ~RxVlan;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   850
	RTL_W16(CPlusCmd, tp->cp_cmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   851
	RTL_R16(CPlusCmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   852
	spin_unlock_irqrestore(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   853
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   854
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   855
static int rtl8169_rx_vlan_skb(struct rtl8169_private *tp, struct RxDesc *desc,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   856
			       struct sk_buff *skb)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   857
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   858
	u32 opts2 = le32_to_cpu(desc->opts2);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   859
	int ret;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   860
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   861
	if (tp->vlgrp && (opts2 & RxVlanTag)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   862
		rtl8169_rx_hwaccel_skb(skb, tp->vlgrp, swab16(opts2 & 0xffff));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   863
		ret = 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   864
	} else
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   865
		ret = -1;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   866
	desc->opts2 = 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   867
	return ret;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   868
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   869
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   870
#else /* !CONFIG_R8169_VLAN */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   871
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   872
static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   873
				      struct sk_buff *skb)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   874
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   875
	return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   876
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   877
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   878
static int rtl8169_rx_vlan_skb(struct rtl8169_private *tp, struct RxDesc *desc,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   879
			       struct sk_buff *skb)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   880
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   881
	return -1;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   882
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   883
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   884
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   885
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   886
static void rtl8169_gset_tbi(struct net_device *dev, struct ethtool_cmd *cmd)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   887
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   888
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   889
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   890
	u32 status;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   891
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   892
	cmd->supported =
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   893
		SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   894
	cmd->port = PORT_FIBRE;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   895
	cmd->transceiver = XCVR_INTERNAL;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   896
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   897
	status = RTL_R32(TBICSR);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   898
	cmd->advertising = (status & TBINwEnable) ?  ADVERTISED_Autoneg : 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   899
	cmd->autoneg = !!(status & TBINwEnable);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   900
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   901
	cmd->speed = SPEED_1000;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   902
	cmd->duplex = DUPLEX_FULL; /* Always set */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   903
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   904
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   905
static void rtl8169_gset_xmii(struct net_device *dev, struct ethtool_cmd *cmd)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   906
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   907
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   908
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   909
	u8 status;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   910
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   911
	cmd->supported = SUPPORTED_10baseT_Half |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   912
			 SUPPORTED_10baseT_Full |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   913
			 SUPPORTED_100baseT_Half |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   914
			 SUPPORTED_100baseT_Full |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   915
			 SUPPORTED_1000baseT_Full |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   916
			 SUPPORTED_Autoneg |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   917
			 SUPPORTED_TP;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   918
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   919
	cmd->autoneg = 1;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   920
	cmd->advertising = ADVERTISED_TP | ADVERTISED_Autoneg;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   921
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   922
	if (tp->phy_auto_nego_reg & ADVERTISE_10HALF)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   923
		cmd->advertising |= ADVERTISED_10baseT_Half;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   924
	if (tp->phy_auto_nego_reg & ADVERTISE_10FULL)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   925
		cmd->advertising |= ADVERTISED_10baseT_Full;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   926
	if (tp->phy_auto_nego_reg & ADVERTISE_100HALF)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   927
		cmd->advertising |= ADVERTISED_100baseT_Half;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   928
	if (tp->phy_auto_nego_reg & ADVERTISE_100FULL)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   929
		cmd->advertising |= ADVERTISED_100baseT_Full;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   930
	if (tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   931
		cmd->advertising |= ADVERTISED_1000baseT_Full;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   932
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   933
	status = RTL_R8(PHYstatus);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   934
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   935
	if (status & _1000bpsF)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   936
		cmd->speed = SPEED_1000;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   937
	else if (status & _100bps)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   938
		cmd->speed = SPEED_100;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   939
	else if (status & _10bps)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   940
		cmd->speed = SPEED_10;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   941
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   942
	if (status & TxFlowCtrl)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   943
		cmd->advertising |= ADVERTISED_Asym_Pause;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   944
	if (status & RxFlowCtrl)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   945
		cmd->advertising |= ADVERTISED_Pause;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   946
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   947
	cmd->duplex = ((status & _1000bpsF) || (status & FullDup)) ?
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   948
		      DUPLEX_FULL : DUPLEX_HALF;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   949
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   950
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   951
static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   952
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   953
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   954
	unsigned long flags;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   955
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   956
	spin_lock_irqsave(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   957
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   958
	tp->get_settings(dev, cmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   959
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   960
	spin_unlock_irqrestore(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   961
	return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   962
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   963
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   964
static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   965
			     void *p)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   966
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   967
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   968
	unsigned long flags;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   969
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   970
	if (regs->len > R8169_REGS_SIZE)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   971
		regs->len = R8169_REGS_SIZE;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   972
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   973
	spin_lock_irqsave(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   974
	memcpy_fromio(p, tp->mmio_addr, regs->len);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   975
	spin_unlock_irqrestore(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   976
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   977
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   978
static u32 rtl8169_get_msglevel(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   979
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   980
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   981
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   982
	return tp->msg_enable;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   983
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   984
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   985
static void rtl8169_set_msglevel(struct net_device *dev, u32 value)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   986
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   987
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   988
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   989
	tp->msg_enable = value;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   990
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   991
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   992
static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   993
	"tx_packets",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   994
	"rx_packets",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   995
	"tx_errors",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   996
	"rx_errors",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   997
	"rx_missed",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   998
	"align_errors",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   999
	"tx_single_collisions",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1000
	"tx_multi_collisions",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1001
	"unicast",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1002
	"broadcast",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1003
	"multicast",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1004
	"tx_aborted",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1005
	"tx_underrun",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1006
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1007
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1008
struct rtl8169_counters {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1009
	__le64	tx_packets;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1010
	__le64	rx_packets;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1011
	__le64	tx_errors;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1012
	__le32	rx_errors;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1013
	__le16	rx_missed;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1014
	__le16	align_errors;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1015
	__le32	tx_one_collision;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1016
	__le32	tx_multi_collision;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1017
	__le64	rx_unicast;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1018
	__le64	rx_broadcast;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1019
	__le32	rx_multicast;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1020
	__le16	tx_aborted;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1021
	__le16	tx_underun;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1022
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1023
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1024
static int rtl8169_get_sset_count(struct net_device *dev, int sset)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1025
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1026
	switch (sset) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1027
	case ETH_SS_STATS:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1028
		return ARRAY_SIZE(rtl8169_gstrings);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1029
	default:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1030
		return -EOPNOTSUPP;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1031
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1032
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1033
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1034
static void rtl8169_get_ethtool_stats(struct net_device *dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1035
				      struct ethtool_stats *stats, u64 *data)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1036
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1037
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1038
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1039
	struct rtl8169_counters *counters;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1040
	dma_addr_t paddr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1041
	u32 cmd;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1042
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1043
	ASSERT_RTNL();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1044
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1045
	counters = pci_alloc_consistent(tp->pci_dev, sizeof(*counters), &paddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1046
	if (!counters)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1047
		return;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1048
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1049
	RTL_W32(CounterAddrHigh, (u64)paddr >> 32);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1050
	cmd = (u64)paddr & DMA_32BIT_MASK;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1051
	RTL_W32(CounterAddrLow, cmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1052
	RTL_W32(CounterAddrLow, cmd | CounterDump);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1053
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1054
	while (RTL_R32(CounterAddrLow) & CounterDump) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1055
		if (msleep_interruptible(1))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1056
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1057
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1058
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1059
	RTL_W32(CounterAddrLow, 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1060
	RTL_W32(CounterAddrHigh, 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1061
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1062
	data[0] = le64_to_cpu(counters->tx_packets);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1063
	data[1] = le64_to_cpu(counters->rx_packets);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1064
	data[2] = le64_to_cpu(counters->tx_errors);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1065
	data[3] = le32_to_cpu(counters->rx_errors);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1066
	data[4] = le16_to_cpu(counters->rx_missed);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1067
	data[5] = le16_to_cpu(counters->align_errors);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1068
	data[6] = le32_to_cpu(counters->tx_one_collision);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1069
	data[7] = le32_to_cpu(counters->tx_multi_collision);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1070
	data[8] = le64_to_cpu(counters->rx_unicast);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1071
	data[9] = le64_to_cpu(counters->rx_broadcast);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1072
	data[10] = le32_to_cpu(counters->rx_multicast);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1073
	data[11] = le16_to_cpu(counters->tx_aborted);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1074
	data[12] = le16_to_cpu(counters->tx_underun);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1075
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1076
	pci_free_consistent(tp->pci_dev, sizeof(*counters), counters, paddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1077
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1078
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1079
static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1080
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1081
	switch(stringset) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1082
	case ETH_SS_STATS:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1083
		memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1084
		break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1085
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1086
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1087
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1088
static const struct ethtool_ops rtl8169_ethtool_ops = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1089
	.get_drvinfo		= rtl8169_get_drvinfo,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1090
	.get_regs_len		= rtl8169_get_regs_len,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1091
	.get_link		= ethtool_op_get_link,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1092
	.get_settings		= rtl8169_get_settings,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1093
	.set_settings		= rtl8169_set_settings,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1094
	.get_msglevel		= rtl8169_get_msglevel,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1095
	.set_msglevel		= rtl8169_set_msglevel,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1096
	.get_rx_csum		= rtl8169_get_rx_csum,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1097
	.set_rx_csum		= rtl8169_set_rx_csum,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1098
	.set_tx_csum		= ethtool_op_set_tx_csum,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1099
	.set_sg			= ethtool_op_set_sg,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1100
	.set_tso		= ethtool_op_set_tso,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1101
	.get_regs		= rtl8169_get_regs,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1102
	.get_wol		= rtl8169_get_wol,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1103
	.set_wol		= rtl8169_set_wol,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1104
	.get_strings		= rtl8169_get_strings,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1105
	.get_sset_count		= rtl8169_get_sset_count,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1106
	.get_ethtool_stats	= rtl8169_get_ethtool_stats,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1107
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1108
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1109
static void rtl8169_write_gmii_reg_bit(void __iomem *ioaddr, int reg,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1110
				       int bitnum, int bitval)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1111
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1112
	int val;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1113
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1114
	val = mdio_read(ioaddr, reg);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1115
	val = (bitval == 1) ?
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1116
		val | (bitval << bitnum) :  val & ~(0x0001 << bitnum);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1117
	mdio_write(ioaddr, reg, val & 0xffff);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1118
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1119
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1120
static void rtl8169_get_mac_version(struct rtl8169_private *tp,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1121
				    void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1122
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1123
	/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1124
	 * The driver currently handles the 8168Bf and the 8168Be identically
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1125
	 * but they can be identified more specifically through the test below
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1126
	 * if needed:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1127
	 *
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1128
	 * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1129
	 *
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1130
	 * Same thing for the 8101Eb and the 8101Ec:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1131
	 *
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1132
	 * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1133
	 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1134
	const struct {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1135
		u32 mask;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1136
		u32 val;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1137
		int mac_version;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1138
	} mac_info[] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1139
		/* 8168B family. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1140
		{ 0x7c800000, 0x3c800000,	RTL_GIGA_MAC_VER_18 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1141
		{ 0x7cf00000, 0x3c000000,	RTL_GIGA_MAC_VER_19 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1142
		{ 0x7cf00000, 0x3c200000,	RTL_GIGA_MAC_VER_20 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1143
		{ 0x7c800000, 0x3c000000,	RTL_GIGA_MAC_VER_20 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1144
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1145
		/* 8168B family. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1146
		{ 0x7cf00000, 0x38000000,	RTL_GIGA_MAC_VER_12 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1147
		{ 0x7cf00000, 0x38500000,	RTL_GIGA_MAC_VER_17 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1148
		{ 0x7c800000, 0x38000000,	RTL_GIGA_MAC_VER_17 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1149
		{ 0x7c800000, 0x30000000,	RTL_GIGA_MAC_VER_11 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1150
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1151
		/* 8101 family. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1152
		{ 0x7cf00000, 0x34000000,	RTL_GIGA_MAC_VER_13 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1153
		{ 0x7cf00000, 0x34200000,	RTL_GIGA_MAC_VER_16 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1154
		{ 0x7c800000, 0x34000000,	RTL_GIGA_MAC_VER_16 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1155
		/* FIXME: where did these entries come from ? -- FR */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1156
		{ 0xfc800000, 0x38800000,	RTL_GIGA_MAC_VER_15 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1157
		{ 0xfc800000, 0x30800000,	RTL_GIGA_MAC_VER_14 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1158
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1159
		/* 8110 family. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1160
		{ 0xfc800000, 0x98000000,	RTL_GIGA_MAC_VER_06 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1161
		{ 0xfc800000, 0x18000000,	RTL_GIGA_MAC_VER_05 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1162
		{ 0xfc800000, 0x10000000,	RTL_GIGA_MAC_VER_04 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1163
		{ 0xfc800000, 0x04000000,	RTL_GIGA_MAC_VER_03 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1164
		{ 0xfc800000, 0x00800000,	RTL_GIGA_MAC_VER_02 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1165
		{ 0xfc800000, 0x00000000,	RTL_GIGA_MAC_VER_01 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1166
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1167
		{ 0x00000000, 0x00000000,	RTL_GIGA_MAC_VER_01 }	/* Catch-all */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1168
	}, *p = mac_info;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1169
	u32 reg;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1170
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1171
	reg = RTL_R32(TxConfig);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1172
	while ((reg & p->mask) != p->val)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1173
		p++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1174
	tp->mac_version = p->mac_version;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1175
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1176
	if (p->mask == 0x00000000) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1177
		struct pci_dev *pdev = tp->pci_dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1178
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1179
		dev_info(&pdev->dev, "unknown MAC (%08x)\n", reg);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1180
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1181
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1182
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1183
static void rtl8169_print_mac_version(struct rtl8169_private *tp)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1184
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1185
	dprintk("mac_version = 0x%02x\n", tp->mac_version);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1186
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1187
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1188
struct phy_reg {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1189
	u16 reg;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1190
	u16 val;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1191
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1192
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1193
static void rtl_phy_write(void __iomem *ioaddr, struct phy_reg *regs, int len)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1194
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1195
	while (len-- > 0) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1196
		mdio_write(ioaddr, regs->reg, regs->val);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1197
		regs++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1198
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1199
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1200
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1201
static void rtl8169s_hw_phy_config(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1202
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1203
	struct {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1204
		u16 regs[5]; /* Beware of bit-sign propagation */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1205
	} phy_magic[5] = { {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1206
		{ 0x0000,	//w 4 15 12 0
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1207
		  0x00a1,	//w 3 15 0 00a1
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1208
		  0x0008,	//w 2 15 0 0008
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1209
		  0x1020,	//w 1 15 0 1020
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1210
		  0x1000 } },{	//w 0 15 0 1000
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1211
		{ 0x7000,	//w 4 15 12 7
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1212
		  0xff41,	//w 3 15 0 ff41
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1213
		  0xde60,	//w 2 15 0 de60
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1214
		  0x0140,	//w 1 15 0 0140
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1215
		  0x0077 } },{	//w 0 15 0 0077
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1216
		{ 0xa000,	//w 4 15 12 a
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1217
		  0xdf01,	//w 3 15 0 df01
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1218
		  0xdf20,	//w 2 15 0 df20
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1219
		  0xff95,	//w 1 15 0 ff95
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1220
		  0xfa00 } },{	//w 0 15 0 fa00
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1221
		{ 0xb000,	//w 4 15 12 b
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1222
		  0xff41,	//w 3 15 0 ff41
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1223
		  0xde20,	//w 2 15 0 de20
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1224
		  0x0140,	//w 1 15 0 0140
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1225
		  0x00bb } },{	//w 0 15 0 00bb
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1226
		{ 0xf000,	//w 4 15 12 f
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1227
		  0xdf01,	//w 3 15 0 df01
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1228
		  0xdf20,	//w 2 15 0 df20
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1229
		  0xff95,	//w 1 15 0 ff95
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1230
		  0xbf00 }	//w 0 15 0 bf00
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1231
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1232
	}, *p = phy_magic;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1233
	unsigned int i;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1234
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1235
	mdio_write(ioaddr, 0x1f, 0x0001);		//w 31 2 0 1
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1236
	mdio_write(ioaddr, 0x15, 0x1000);		//w 21 15 0 1000
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1237
	mdio_write(ioaddr, 0x18, 0x65c7);		//w 24 15 0 65c7
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1238
	rtl8169_write_gmii_reg_bit(ioaddr, 4, 11, 0);	//w 4 11 11 0
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1239
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1240
	for (i = 0; i < ARRAY_SIZE(phy_magic); i++, p++) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1241
		int val, pos = 4;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1242
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1243
		val = (mdio_read(ioaddr, pos) & 0x0fff) | (p->regs[0] & 0xffff);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1244
		mdio_write(ioaddr, pos, val);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1245
		while (--pos >= 0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1246
			mdio_write(ioaddr, pos, p->regs[4 - pos] & 0xffff);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1247
		rtl8169_write_gmii_reg_bit(ioaddr, 4, 11, 1); //w 4 11 11 1
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1248
		rtl8169_write_gmii_reg_bit(ioaddr, 4, 11, 0); //w 4 11 11 0
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1249
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1250
	mdio_write(ioaddr, 0x1f, 0x0000); //w 31 2 0 0
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1251
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1252
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1253
static void rtl8169sb_hw_phy_config(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1254
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1255
	struct phy_reg phy_reg_init[] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1256
		{ 0x1f, 0x0002 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1257
		{ 0x01, 0x90d0 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1258
		{ 0x1f, 0x0000 }
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1259
	};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1260
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1261
	rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1262
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1263
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1264
static void rtl8168cp_hw_phy_config(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1265
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1266
	struct phy_reg phy_reg_init[] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1267
		{ 0x1f, 0x0000 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1268
		{ 0x1d, 0x0f00 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1269
		{ 0x1f, 0x0002 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1270
		{ 0x0c, 0x1ec8 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1271
		{ 0x1f, 0x0000 }
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1272
	};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1273
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1274
	rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1275
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1276
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1277
static void rtl8168c_hw_phy_config(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1278
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1279
	struct phy_reg phy_reg_init[] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1280
		{ 0x1f, 0x0001 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1281
		{ 0x12, 0x2300 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1282
		{ 0x1f, 0x0002 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1283
		{ 0x00, 0x88d4 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1284
		{ 0x01, 0x82b1 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1285
		{ 0x03, 0x7002 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1286
		{ 0x08, 0x9e30 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1287
		{ 0x09, 0x01f0 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1288
		{ 0x0a, 0x5500 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1289
		{ 0x0c, 0x00c8 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1290
		{ 0x1f, 0x0003 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1291
		{ 0x12, 0xc096 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1292
		{ 0x16, 0x000a },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1293
		{ 0x1f, 0x0000 }
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1294
	};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1295
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1296
	rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1297
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1298
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1299
static void rtl8168cx_hw_phy_config(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1300
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1301
	struct phy_reg phy_reg_init[] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1302
		{ 0x1f, 0x0000 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1303
		{ 0x12, 0x2300 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1304
		{ 0x1f, 0x0003 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1305
		{ 0x16, 0x0f0a },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1306
		{ 0x1f, 0x0000 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1307
		{ 0x1f, 0x0002 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1308
		{ 0x0c, 0x7eb8 },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1309
		{ 0x1f, 0x0000 }
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1310
	};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1311
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1312
	rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1313
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1314
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1315
static void rtl_hw_phy_config(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1316
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1317
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1318
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1319
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1320
	rtl8169_print_mac_version(tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1321
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1322
	switch (tp->mac_version) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1323
	case RTL_GIGA_MAC_VER_01:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1324
		break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1325
	case RTL_GIGA_MAC_VER_02:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1326
	case RTL_GIGA_MAC_VER_03:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1327
		rtl8169s_hw_phy_config(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1328
		break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1329
	case RTL_GIGA_MAC_VER_04:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1330
		rtl8169sb_hw_phy_config(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1331
		break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1332
	case RTL_GIGA_MAC_VER_18:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1333
		rtl8168cp_hw_phy_config(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1334
		break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1335
	case RTL_GIGA_MAC_VER_19:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1336
		rtl8168c_hw_phy_config(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1337
		break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1338
	case RTL_GIGA_MAC_VER_20:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1339
		rtl8168cx_hw_phy_config(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1340
		break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1341
	default:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1342
		break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1343
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1344
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1345
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1346
static void rtl8169_phy_timer(unsigned long __opaque)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1347
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1348
	struct net_device *dev = (struct net_device *)__opaque;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1349
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1350
	struct timer_list *timer = &tp->timer;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1351
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1352
	unsigned long timeout = RTL8169_PHY_TIMEOUT;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1353
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1354
	assert(tp->mac_version > RTL_GIGA_MAC_VER_01);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1355
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1356
	if (!(tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1357
		return;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1358
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1359
	if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1360
		spin_lock_irq(&tp->lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1361
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1362
	if (tp->phy_reset_pending(ioaddr)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1363
		/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1364
		 * A busy loop could burn quite a few cycles on nowadays CPU.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1365
		 * Let's delay the execution of the timer for a few ticks.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1366
		 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1367
		timeout = HZ/10;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1368
		goto out_mod_timer;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1369
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1370
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1371
	if (tp->link_ok(ioaddr))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1372
		goto out_unlock;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1373
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1374
	if (netif_msg_link(tp))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1375
		printk(KERN_WARNING "%s: PHY reset until link up\n", dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1376
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1377
	tp->phy_reset_enable(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1378
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1379
out_mod_timer:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1380
	if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1381
		mod_timer(timer, jiffies + timeout);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1382
out_unlock:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1383
	if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1384
		spin_unlock_irq(&tp->lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1385
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1386
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1387
static inline void rtl8169_delete_timer(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1388
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1389
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1390
	struct timer_list *timer = &tp->timer;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1391
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1392
	if (tp->ecdev || tp->mac_version <= RTL_GIGA_MAC_VER_01)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1393
		return;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1394
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1395
	del_timer_sync(timer);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1396
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1397
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1398
static inline void rtl8169_request_timer(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1399
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1400
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1401
	struct timer_list *timer = &tp->timer;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1402
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1403
	if (tp->ecdev || tp->mac_version <= RTL_GIGA_MAC_VER_01)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1404
		return;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1405
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1406
	mod_timer(timer, jiffies + RTL8169_PHY_TIMEOUT);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1407
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1408
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1409
static void ec_poll(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1410
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1411
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1412
	struct pci_dev *pdev = tp->pci_dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1413
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1414
	rtl8169_interrupt(pdev->irq, dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1415
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1416
    if (jiffies - tp->ec_watchdog_jiffies >= 2 * HZ) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1417
		rtl8169_phy_timer((unsigned long) dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1418
		tp->ec_watchdog_jiffies = jiffies;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1419
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1420
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1421
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1422
#ifdef CONFIG_NET_POLL_CONTROLLER
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1423
/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1424
 * Polling 'interrupt' - used by things like netconsole to send skbs
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1425
 * without having to re-enable interrupts. It's not called while
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1426
 * the interrupt routine is executing.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1427
 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1428
static void rtl8169_netpoll(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1429
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1430
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1431
	struct pci_dev *pdev = tp->pci_dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1432
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1433
	disable_irq(pdev->irq);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1434
	rtl8169_interrupt(pdev->irq, dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1435
	enable_irq(pdev->irq);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1436
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1437
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1438
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1439
static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1440
				  void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1441
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1442
	iounmap(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1443
	pci_release_regions(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1444
	pci_disable_device(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1445
	free_netdev(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1446
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1447
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1448
static void rtl8169_phy_reset(struct net_device *dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1449
			      struct rtl8169_private *tp)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1450
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1451
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1452
	unsigned int i;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1453
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1454
	tp->phy_reset_enable(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1455
	for (i = 0; i < 100; i++) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1456
		if (!tp->phy_reset_pending(ioaddr))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1457
			return;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1458
		msleep(1);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1459
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1460
	if (netif_msg_link(tp))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1461
		printk(KERN_ERR "%s: PHY reset failed.\n", dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1462
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1463
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1464
static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1465
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1466
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1467
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1468
	rtl_hw_phy_config(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1469
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1470
	dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1471
	RTL_W8(0x82, 0x01);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1472
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1473
	pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1474
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1475
	if (tp->mac_version <= RTL_GIGA_MAC_VER_06)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1476
		pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1477
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1478
	if (tp->mac_version == RTL_GIGA_MAC_VER_02) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1479
		dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1480
		RTL_W8(0x82, 0x01);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1481
		dprintk("Set PHY Reg 0x0bh = 0x00h\n");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1482
		mdio_write(ioaddr, 0x0b, 0x0000); //w 0x0b 15 0 0
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1483
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1484
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1485
	rtl8169_phy_reset(dev, tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1486
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1487
	/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1488
	 * rtl8169_set_speed_xmii takes good care of the Fast Ethernet
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1489
	 * only 8101. Don't panic.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1490
	 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1491
	rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1492
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1493
	if ((RTL_R8(PHYstatus) & TBI_Enable) && netif_msg_link(tp))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1494
		printk(KERN_INFO PFX "%s: TBI auto-negotiating\n", dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1495
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1496
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1497
static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1498
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1499
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1500
	u32 high;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1501
	u32 low;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1502
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1503
	low  = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1504
	high = addr[4] | (addr[5] << 8);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1505
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1506
	spin_lock_irq(&tp->lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1507
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1508
	RTL_W8(Cfg9346, Cfg9346_Unlock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1509
	RTL_W32(MAC0, low);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1510
	RTL_W32(MAC4, high);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1511
	RTL_W8(Cfg9346, Cfg9346_Lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1512
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1513
	spin_unlock_irq(&tp->lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1514
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1515
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1516
static int rtl_set_mac_address(struct net_device *dev, void *p)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1517
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1518
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1519
	struct sockaddr *addr = p;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1520
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1521
	if (!is_valid_ether_addr(addr->sa_data))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1522
		return -EADDRNOTAVAIL;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1523
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1524
	memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1525
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1526
	rtl_rar_set(tp, dev->dev_addr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1527
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1528
	return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1529
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1530
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1531
static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1532
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1533
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1534
	struct mii_ioctl_data *data = if_mii(ifr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1535
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1536
	if (!netif_running(dev))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1537
		return -ENODEV;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1538
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1539
	switch (cmd) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1540
	case SIOCGMIIPHY:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1541
		data->phy_id = 32; /* Internal PHY */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1542
		return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1543
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1544
	case SIOCGMIIREG:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1545
		data->val_out = mdio_read(tp->mmio_addr, data->reg_num & 0x1f);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1546
		return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1547
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1548
	case SIOCSMIIREG:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1549
		if (!capable(CAP_NET_ADMIN))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1550
			return -EPERM;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1551
		mdio_write(tp->mmio_addr, data->reg_num & 0x1f, data->val_in);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1552
		return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1553
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1554
	return -EOPNOTSUPP;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1555
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1556
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1557
static const struct rtl_cfg_info {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1558
	void (*hw_start)(struct net_device *);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1559
	unsigned int region;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1560
	unsigned int align;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1561
	u16 intr_event;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1562
	u16 napi_event;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1563
	unsigned msi;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1564
} rtl_cfg_infos [] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1565
	[RTL_CFG_0] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1566
		.hw_start	= rtl_hw_start_8169,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1567
		.region		= 1,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1568
		.align		= 0,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1569
		.intr_event	= SYSErr | LinkChg | RxOverflow |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1570
				  RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1571
		.napi_event	= RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1572
		.msi		= 0
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1573
	},
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1574
	[RTL_CFG_1] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1575
		.hw_start	= rtl_hw_start_8168,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1576
		.region		= 2,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1577
		.align		= 8,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1578
		.intr_event	= SYSErr | LinkChg | RxOverflow |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1579
				  TxErr | TxOK | RxOK | RxErr,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1580
		.napi_event	= TxErr | TxOK | RxOK | RxOverflow,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1581
		.msi		= RTL_FEATURE_MSI
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1582
	},
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1583
	[RTL_CFG_2] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1584
		.hw_start	= rtl_hw_start_8101,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1585
		.region		= 2,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1586
		.align		= 8,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1587
		.intr_event	= SYSErr | LinkChg | RxOverflow | PCSTimeout |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1588
				  RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1589
		.napi_event	= RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1590
		.msi		= RTL_FEATURE_MSI
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1591
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1592
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1593
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1594
/* Cfg9346_Unlock assumed. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1595
static unsigned rtl_try_msi(struct pci_dev *pdev, void __iomem *ioaddr,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1596
			    const struct rtl_cfg_info *cfg)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1597
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1598
	unsigned msi = 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1599
	u8 cfg2;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1600
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1601
	cfg2 = RTL_R8(Config2) & ~MSIEnable;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1602
	if (cfg->msi) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1603
		if (pci_enable_msi(pdev)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1604
			dev_info(&pdev->dev, "no MSI. Back to INTx.\n");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1605
		} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1606
			cfg2 |= MSIEnable;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1607
			msi = RTL_FEATURE_MSI;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1608
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1609
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1610
	RTL_W8(Config2, cfg2);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1611
	return msi;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1612
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1613
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1614
static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1615
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1616
	if (tp->features & RTL_FEATURE_MSI) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1617
		pci_disable_msi(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1618
		tp->features &= ~RTL_FEATURE_MSI;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1619
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1620
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1621
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1622
static int __devinit
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1623
rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1624
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1625
	const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1626
	const unsigned int region = cfg->region;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1627
	struct rtl8169_private *tp;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1628
	struct net_device *dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1629
	void __iomem *ioaddr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1630
	unsigned int i;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1631
	int rc;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1632
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1633
	if (netif_msg_drv(&debug)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1634
		printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1635
		       MODULENAME, RTL8169_VERSION);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1636
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1637
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1638
	dev = alloc_etherdev(sizeof (*tp));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1639
	if (!dev) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1640
		if (netif_msg_drv(&debug))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1641
			dev_err(&pdev->dev, "unable to alloc new ethernet\n");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1642
		rc = -ENOMEM;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1643
		goto out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1644
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1645
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1646
	SET_NETDEV_DEV(dev, &pdev->dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1647
	tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1648
	tp->dev = dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1649
	tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1650
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1651
	/* enable device (incl. PCI PM wakeup and hotplug setup) */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1652
	rc = pci_enable_device(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1653
	if (rc < 0) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1654
		if (netif_msg_probe(tp))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1655
			dev_err(&pdev->dev, "enable failure\n");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1656
		goto err_out_free_dev_1;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1657
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1658
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1659
	rc = pci_set_mwi(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1660
	if (rc < 0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1661
		goto err_out_disable_2;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1662
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1663
	/* make sure PCI base addr 1 is MMIO */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1664
	if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1665
		if (netif_msg_probe(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1666
			dev_err(&pdev->dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1667
				"region #%d not an MMIO resource, aborting\n",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1668
				region);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1669
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1670
		rc = -ENODEV;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1671
		goto err_out_mwi_3;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1672
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1673
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1674
	/* check for weird/broken PCI region reporting */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1675
	if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1676
		if (netif_msg_probe(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1677
			dev_err(&pdev->dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1678
				"Invalid PCI region size(s), aborting\n");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1679
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1680
		rc = -ENODEV;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1681
		goto err_out_mwi_3;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1682
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1683
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1684
	rc = pci_request_regions(pdev, MODULENAME);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1685
	if (rc < 0) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1686
		if (netif_msg_probe(tp))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1687
			dev_err(&pdev->dev, "could not request regions.\n");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1688
		goto err_out_mwi_3;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1689
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1690
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1691
	tp->cp_cmd = PCIMulRW | RxChkSum;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1692
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1693
	if ((sizeof(dma_addr_t) > 4) &&
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1694
	    !pci_set_dma_mask(pdev, DMA_64BIT_MASK) && use_dac) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1695
		tp->cp_cmd |= PCIDAC;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1696
		dev->features |= NETIF_F_HIGHDMA;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1697
	} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1698
		rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1699
		if (rc < 0) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1700
			if (netif_msg_probe(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1701
				dev_err(&pdev->dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1702
					"DMA configuration failed.\n");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1703
			}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1704
			goto err_out_free_res_4;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1705
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1706
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1707
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1708
	pci_set_master(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1709
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1710
	/* ioremap MMIO region */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1711
	ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1712
	if (!ioaddr) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1713
		if (netif_msg_probe(tp))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1714
			dev_err(&pdev->dev, "cannot remap MMIO, aborting\n");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1715
		rc = -EIO;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1716
		goto err_out_free_res_4;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1717
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1718
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1719
	/* Unneeded ? Don't mess with Mrs. Murphy. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1720
	rtl8169_irq_mask_and_ack(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1721
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1722
	/* Soft reset the chip. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1723
	RTL_W8(ChipCmd, CmdReset);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1724
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1725
	/* Check that the chip has finished the reset. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1726
	for (i = 0; i < 100; i++) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1727
		if ((RTL_R8(ChipCmd) & CmdReset) == 0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1728
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1729
		msleep_interruptible(1);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1730
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1731
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1732
	/* Identify chip attached to board */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1733
	rtl8169_get_mac_version(tp, ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1734
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1735
	rtl8169_print_mac_version(tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1736
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1737
	for (i = ARRAY_SIZE(rtl_chip_info) - 1; i >= 0; i--) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1738
		if (tp->mac_version == rtl_chip_info[i].mac_version)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1739
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1740
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1741
	if (i < 0) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1742
		/* Unknown chip: assume array element #0, original RTL-8169 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1743
		if (netif_msg_probe(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1744
			dev_printk(KERN_DEBUG, &pdev->dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1745
				"unknown chip version, assuming %s\n",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1746
				rtl_chip_info[0].name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1747
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1748
		i++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1749
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1750
	tp->chipset = i;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1751
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1752
	RTL_W8(Cfg9346, Cfg9346_Unlock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1753
	RTL_W8(Config1, RTL_R8(Config1) | PMEnable);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1754
	RTL_W8(Config5, RTL_R8(Config5) & PMEStatus);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1755
	tp->features |= rtl_try_msi(pdev, ioaddr, cfg);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1756
	RTL_W8(Cfg9346, Cfg9346_Lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1757
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1758
	if ((tp->mac_version <= RTL_GIGA_MAC_VER_06) &&
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1759
	    (RTL_R8(PHYstatus) & TBI_Enable)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1760
		tp->set_speed = rtl8169_set_speed_tbi;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1761
		tp->get_settings = rtl8169_gset_tbi;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1762
		tp->phy_reset_enable = rtl8169_tbi_reset_enable;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1763
		tp->phy_reset_pending = rtl8169_tbi_reset_pending;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1764
		tp->link_ok = rtl8169_tbi_link_ok;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1765
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1766
		tp->phy_1000_ctrl_reg = ADVERTISE_1000FULL; /* Implied by TBI */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1767
	} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1768
		tp->set_speed = rtl8169_set_speed_xmii;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1769
		tp->get_settings = rtl8169_gset_xmii;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1770
		tp->phy_reset_enable = rtl8169_xmii_reset_enable;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1771
		tp->phy_reset_pending = rtl8169_xmii_reset_pending;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1772
		tp->link_ok = rtl8169_xmii_link_ok;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1773
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1774
		dev->do_ioctl = rtl8169_ioctl;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1775
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1776
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1777
	/* Get MAC address.  FIXME: read EEPROM */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1778
	for (i = 0; i < MAC_ADDR_LEN; i++)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1779
		dev->dev_addr[i] = RTL_R8(MAC0 + i);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1780
	memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1781
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1782
	dev->open = rtl8169_open;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1783
	dev->hard_start_xmit = rtl8169_start_xmit;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1784
	dev->get_stats = rtl8169_get_stats;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1785
	SET_ETHTOOL_OPS(dev, &rtl8169_ethtool_ops);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1786
	dev->stop = rtl8169_close;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1787
	dev->tx_timeout = rtl8169_tx_timeout;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1788
	dev->set_multicast_list = rtl_set_rx_mode;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1789
	dev->watchdog_timeo = RTL8169_TX_TIMEOUT;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1790
	dev->irq = pdev->irq;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1791
	dev->base_addr = (unsigned long) ioaddr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1792
	dev->change_mtu = rtl8169_change_mtu;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1793
	dev->set_mac_address = rtl_set_mac_address;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1794
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1795
#ifdef CONFIG_R8169_NAPI
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1796
	netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1797
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1798
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1799
#ifdef CONFIG_R8169_VLAN
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1800
	dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1801
	dev->vlan_rx_register = rtl8169_vlan_rx_register;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1802
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1803
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1804
#ifdef CONFIG_NET_POLL_CONTROLLER
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1805
	dev->poll_controller = rtl8169_netpoll;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1806
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1807
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1808
	tp->intr_mask = 0xffff;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1809
	tp->pci_dev = pdev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1810
	tp->mmio_addr = ioaddr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1811
	tp->align = cfg->align;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1812
	tp->hw_start = cfg->hw_start;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1813
	tp->intr_event = cfg->intr_event;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1814
	tp->napi_event = cfg->napi_event;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1815
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1816
	init_timer(&tp->timer);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1817
	tp->timer.data = (unsigned long) dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1818
	tp->timer.function = rtl8169_phy_timer;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1819
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1820
	spin_lock_init(&tp->lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1821
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1822
	// offer device to EtherCAT master module
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1823
	tp->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1824
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1825
	if (!tp->ecdev) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1826
		rc = register_netdev(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1827
		if (rc < 0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1828
			goto err_out_msi_5;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1829
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1830
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1831
	pci_set_drvdata(pdev, dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1832
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1833
	if (netif_msg_probe(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1834
		u32 xid = RTL_R32(TxConfig) & 0x7cf0f8ff;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1835
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1836
		printk(KERN_INFO "%s: %s at 0x%lx, "
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1837
		       "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, "
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1838
		       "XID %08x IRQ %d\n",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1839
		       dev->name,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1840
		       rtl_chip_info[tp->chipset].name,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1841
		       dev->base_addr,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1842
		       dev->dev_addr[0], dev->dev_addr[1],
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1843
		       dev->dev_addr[2], dev->dev_addr[3],
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1844
		       dev->dev_addr[4], dev->dev_addr[5], xid, dev->irq);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1845
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1846
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1847
	rtl8169_init_phy(dev, tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1848
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1849
	if (tp->ecdev && ecdev_open(tp->ecdev)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1850
		ecdev_withdraw(tp->ecdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1851
		goto err_out_msi_5;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1852
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1853
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1854
out:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1855
	return rc;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1856
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1857
err_out_msi_5:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1858
	rtl_disable_msi(pdev, tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1859
	iounmap(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1860
err_out_free_res_4:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1861
	pci_release_regions(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1862
err_out_mwi_3:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1863
	pci_clear_mwi(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1864
err_out_disable_2:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1865
	pci_disable_device(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1866
err_out_free_dev_1:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1867
	free_netdev(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1868
	goto out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1869
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1870
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1871
static void __devexit rtl8169_remove_one(struct pci_dev *pdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1872
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1873
	struct net_device *dev = pci_get_drvdata(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1874
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1875
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1876
	flush_scheduled_work();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1877
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1878
	if (tp->ecdev) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1879
		ecdev_close(tp->ecdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1880
		ecdev_withdraw(tp->ecdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1881
	} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1882
		unregister_netdev(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1883
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1884
	rtl_disable_msi(pdev, tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1885
	rtl8169_release_board(pdev, dev, tp->mmio_addr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1886
	pci_set_drvdata(pdev, NULL);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1887
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1888
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1889
static void rtl8169_set_rxbufsize(struct rtl8169_private *tp,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1890
				  struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1891
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1892
	unsigned int mtu = dev->mtu;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1893
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1894
	tp->rx_buf_sz = (mtu > RX_BUF_SIZE) ? mtu + ETH_HLEN + 8 : RX_BUF_SIZE;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1895
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1896
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1897
static int rtl8169_open(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1898
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1899
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1900
	struct pci_dev *pdev = tp->pci_dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1901
	int retval = -ENOMEM;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1902
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1903
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1904
	rtl8169_set_rxbufsize(tp, dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1905
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1906
	/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1907
	 * Rx and Tx desscriptors needs 256 bytes alignment.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1908
	 * pci_alloc_consistent provides more.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1909
	 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1910
	tp->TxDescArray = pci_alloc_consistent(pdev, R8169_TX_RING_BYTES,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1911
					       &tp->TxPhyAddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1912
	if (!tp->TxDescArray)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1913
		goto out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1914
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1915
	tp->RxDescArray = pci_alloc_consistent(pdev, R8169_RX_RING_BYTES,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1916
					       &tp->RxPhyAddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1917
	if (!tp->RxDescArray)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1918
		goto err_free_tx_0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1919
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1920
	retval = rtl8169_init_ring(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1921
	if (retval < 0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1922
		goto err_free_rx_1;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1923
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1924
	INIT_DELAYED_WORK(&tp->task, NULL);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1925
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1926
	smp_mb();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1927
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1928
	if (!tp->ecdev) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1929
		retval = request_irq(dev->irq, rtl8169_interrupt,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1930
				(tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1931
				dev->name, dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1932
		if (retval < 0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1933
			goto err_release_ring_2;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1934
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1935
#ifdef CONFIG_R8169_NAPI
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1936
		napi_enable(&tp->napi);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1937
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1938
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1939
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1940
	rtl_hw_start(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1941
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1942
	rtl8169_request_timer(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1943
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1944
	rtl8169_check_link_status(dev, tp, tp->mmio_addr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1945
out:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1946
	return retval;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1947
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1948
err_release_ring_2:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1949
	rtl8169_rx_clear(tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1950
err_free_rx_1:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1951
	pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1952
			    tp->RxPhyAddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1953
err_free_tx_0:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1954
	pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1955
			    tp->TxPhyAddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1956
	goto out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1957
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1958
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1959
static void rtl8169_hw_reset(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1960
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1961
	/* Disable interrupts */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1962
	rtl8169_irq_mask_and_ack(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1963
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1964
	/* Reset the chipset */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1965
	RTL_W8(ChipCmd, CmdReset);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1966
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1967
	/* PCI commit */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1968
	RTL_R8(ChipCmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1969
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1970
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1971
static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1972
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1973
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1974
	u32 cfg = rtl8169_rx_config;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1975
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1976
	cfg |= (RTL_R32(RxConfig) & rtl_chip_info[tp->chipset].RxConfigMask);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1977
	RTL_W32(RxConfig, cfg);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1978
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1979
	/* Set DMA burst size and Interframe Gap Time */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1980
	RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1981
		(InterFrameGap << TxInterFrameGapShift));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1982
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1983
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1984
static void rtl_hw_start(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1985
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1986
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1987
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1988
	unsigned int i;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1989
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1990
	/* Soft reset the chip. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1991
	RTL_W8(ChipCmd, CmdReset);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1992
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1993
	/* Check that the chip has finished the reset. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1994
	for (i = 0; i < 100; i++) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1995
		if ((RTL_R8(ChipCmd) & CmdReset) == 0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1996
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1997
		msleep_interruptible(1);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1998
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1999
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2000
	tp->hw_start(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2001
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2002
	if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2003
		netif_start_queue(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2004
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2005
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2006
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2007
static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2008
					 void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2009
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2010
	/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2011
	 * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2012
	 * register to be written before TxDescAddrLow to work.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2013
	 * Switching from MMIO to I/O access fixes the issue as well.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2014
	 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2015
	RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2016
	RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_32BIT_MASK);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2017
	RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2018
	RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_32BIT_MASK);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2019
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2020
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2021
static u16 rtl_rw_cpluscmd(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2022
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2023
	u16 cmd;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2024
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2025
	cmd = RTL_R16(CPlusCmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2026
	RTL_W16(CPlusCmd, cmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2027
	return cmd;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2028
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2029
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2030
static void rtl_set_rx_max_size(void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2031
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2032
	/* Low hurts. Let's disable the filtering. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2033
	RTL_W16(RxMaxSize, 16383);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2034
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2035
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2036
static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2037
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2038
	struct {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2039
		u32 mac_version;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2040
		u32 clk;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2041
		u32 val;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2042
	} cfg2_info [] = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2043
		{ RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2044
		{ RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff },
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2045
		{ RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2046
		{ RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff }
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2047
	}, *p = cfg2_info;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2048
	unsigned int i;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2049
	u32 clk;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2050
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2051
	clk = RTL_R8(Config2) & PCI_Clock_66MHz;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2052
	for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2053
		if ((p->mac_version == mac_version) && (p->clk == clk)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2054
			RTL_W32(0x7c, p->val);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2055
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2056
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2057
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2058
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2059
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2060
static void rtl_hw_start_8169(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2061
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2062
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2063
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2064
	struct pci_dev *pdev = tp->pci_dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2065
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2066
	if (tp->mac_version == RTL_GIGA_MAC_VER_05) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2067
		RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2068
		pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2069
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2070
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2071
	RTL_W8(Cfg9346, Cfg9346_Unlock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2072
	if ((tp->mac_version == RTL_GIGA_MAC_VER_01) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2073
	    (tp->mac_version == RTL_GIGA_MAC_VER_02) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2074
	    (tp->mac_version == RTL_GIGA_MAC_VER_03) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2075
	    (tp->mac_version == RTL_GIGA_MAC_VER_04))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2076
		RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2077
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2078
	RTL_W8(EarlyTxThres, EarlyTxThld);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2079
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2080
	rtl_set_rx_max_size(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2081
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2082
	if ((tp->mac_version == RTL_GIGA_MAC_VER_01) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2083
	    (tp->mac_version == RTL_GIGA_MAC_VER_02) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2084
	    (tp->mac_version == RTL_GIGA_MAC_VER_03) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2085
	    (tp->mac_version == RTL_GIGA_MAC_VER_04))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2086
		rtl_set_rx_tx_config_registers(tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2087
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2088
	tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2089
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2090
	if ((tp->mac_version == RTL_GIGA_MAC_VER_02) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2091
	    (tp->mac_version == RTL_GIGA_MAC_VER_03)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2092
		dprintk("Set MAC Reg C+CR Offset 0xE0. "
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2093
			"Bit-3 and bit-14 MUST be 1\n");
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2094
		tp->cp_cmd |= (1 << 14);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2095
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2096
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2097
	RTL_W16(CPlusCmd, tp->cp_cmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2098
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2099
	rtl8169_set_magic_reg(ioaddr, tp->mac_version);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2100
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2101
	/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2102
	 * Undocumented corner. Supposedly:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2103
	 * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2104
	 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2105
	RTL_W16(IntrMitigate, 0x0000);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2106
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2107
	rtl_set_rx_tx_desc_registers(tp, ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2108
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2109
	if ((tp->mac_version != RTL_GIGA_MAC_VER_01) &&
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2110
	    (tp->mac_version != RTL_GIGA_MAC_VER_02) &&
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2111
	    (tp->mac_version != RTL_GIGA_MAC_VER_03) &&
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2112
	    (tp->mac_version != RTL_GIGA_MAC_VER_04)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2113
		RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2114
		rtl_set_rx_tx_config_registers(tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2115
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2116
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2117
	RTL_W8(Cfg9346, Cfg9346_Lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2118
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2119
	/* Initially a 10 us delay. Turned it into a PCI commit. - FR */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2120
	RTL_R8(IntrMask);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2121
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2122
	RTL_W32(RxMissed, 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2123
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2124
	rtl_set_rx_mode(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2125
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2126
	/* no early-rx interrupts */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2127
	RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2128
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2129
	/* Enable all known interrupts by setting the interrupt mask. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2130
	if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2131
		RTL_W16(IntrMask, tp->intr_event);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2132
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2133
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2134
static void rtl_hw_start_8168(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2135
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2136
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2137
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2138
	struct pci_dev *pdev = tp->pci_dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2139
	u8 ctl;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2140
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2141
	RTL_W8(Cfg9346, Cfg9346_Unlock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2142
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2143
	RTL_W8(EarlyTxThres, EarlyTxThld);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2144
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2145
	rtl_set_rx_max_size(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2146
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2147
	rtl_set_rx_tx_config_registers(tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2148
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2149
	tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2150
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2151
	RTL_W16(CPlusCmd, tp->cp_cmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2152
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2153
	/* Tx performance tweak. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2154
	pci_read_config_byte(pdev, 0x69, &ctl);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2155
	ctl = (ctl & ~0x70) | 0x50;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2156
	pci_write_config_byte(pdev, 0x69, ctl);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2157
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2158
	RTL_W16(IntrMitigate, 0x5151);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2159
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2160
	/* Work around for RxFIFO overflow. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2161
	if (tp->mac_version == RTL_GIGA_MAC_VER_11) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2162
		tp->intr_event |= RxFIFOOver | PCSTimeout;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2163
		tp->intr_event &= ~RxOverflow;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2164
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2165
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2166
	rtl_set_rx_tx_desc_registers(tp, ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2167
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2168
	RTL_W8(Cfg9346, Cfg9346_Lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2169
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2170
	RTL_R8(IntrMask);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2171
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2172
	RTL_W32(RxMissed, 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2173
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2174
	rtl_set_rx_mode(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2175
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2176
	RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2177
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2178
	RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2179
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2180
	if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2181
		RTL_W16(IntrMask, tp->intr_event);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2182
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2183
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2184
static void rtl_hw_start_8101(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2185
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2186
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2187
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2188
	struct pci_dev *pdev = tp->pci_dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2189
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2190
	if ((tp->mac_version == RTL_GIGA_MAC_VER_13) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2191
	    (tp->mac_version == RTL_GIGA_MAC_VER_16)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2192
		pci_write_config_word(pdev, 0x68, 0x00);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2193
		pci_write_config_word(pdev, 0x69, 0x08);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2194
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2195
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2196
	RTL_W8(Cfg9346, Cfg9346_Unlock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2197
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2198
	RTL_W8(EarlyTxThres, EarlyTxThld);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2199
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2200
	rtl_set_rx_max_size(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2201
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2202
	tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2203
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2204
	RTL_W16(CPlusCmd, tp->cp_cmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2205
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2206
	RTL_W16(IntrMitigate, 0x0000);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2207
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2208
	rtl_set_rx_tx_desc_registers(tp, ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2209
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2210
	RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2211
	rtl_set_rx_tx_config_registers(tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2212
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2213
	RTL_W8(Cfg9346, Cfg9346_Lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2214
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2215
	RTL_R8(IntrMask);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2216
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2217
	RTL_W32(RxMissed, 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2218
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2219
	rtl_set_rx_mode(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2220
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2221
	RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2222
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2223
	RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2224
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2225
	if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2226
		RTL_W16(IntrMask, tp->intr_event);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2227
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2228
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2229
static int rtl8169_change_mtu(struct net_device *dev, int new_mtu)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2230
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2231
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2232
	int ret = 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2233
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2234
	if (new_mtu < ETH_ZLEN || new_mtu > SafeMtu)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2235
		return -EINVAL;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2236
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2237
	dev->mtu = new_mtu;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2238
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2239
	if (!netif_running(dev))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2240
		goto out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2241
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2242
	rtl8169_down(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2243
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2244
	rtl8169_set_rxbufsize(tp, dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2245
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2246
	ret = rtl8169_init_ring(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2247
	if (ret < 0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2248
		goto out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2249
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2250
#ifdef CONFIG_R8169_NAPI
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2251
	napi_enable(&tp->napi);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2252
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2253
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2254
	rtl_hw_start(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2255
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2256
	rtl8169_request_timer(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2257
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2258
out:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2259
	return ret;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2260
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2261
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2262
static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2263
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2264
	desc->addr = cpu_to_le64(0x0badbadbadbadbadull);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2265
	desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2266
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2267
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2268
static void rtl8169_free_rx_skb(struct rtl8169_private *tp,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2269
				struct sk_buff **sk_buff, struct RxDesc *desc)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2270
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2271
	struct pci_dev *pdev = tp->pci_dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2272
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2273
	pci_unmap_single(pdev, le64_to_cpu(desc->addr), tp->rx_buf_sz,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2274
			 PCI_DMA_FROMDEVICE);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2275
	dev_kfree_skb(*sk_buff);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2276
	*sk_buff = NULL;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2277
	rtl8169_make_unusable_by_asic(desc);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2278
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2279
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2280
static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2281
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2282
	u32 eor = le32_to_cpu(desc->opts1) & RingEnd;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2283
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2284
	desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2285
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2286
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2287
static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2288
				       u32 rx_buf_sz)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2289
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2290
	desc->addr = cpu_to_le64(mapping);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2291
	wmb();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2292
	rtl8169_mark_to_asic(desc, rx_buf_sz);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2293
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2294
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2295
static struct sk_buff *rtl8169_alloc_rx_skb(struct pci_dev *pdev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2296
					    struct net_device *dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2297
					    struct RxDesc *desc, int rx_buf_sz,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2298
					    unsigned int align)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2299
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2300
	struct sk_buff *skb;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2301
	dma_addr_t mapping;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2302
	unsigned int pad;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2303
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2304
	pad = align ? align : NET_IP_ALIGN;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2305
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2306
	skb = netdev_alloc_skb(dev, rx_buf_sz + pad);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2307
	if (!skb)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2308
		goto err_out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2309
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2310
	skb_reserve(skb, align ? ((pad - 1) & (unsigned long)skb->data) : pad);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2311
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2312
	mapping = pci_map_single(pdev, skb->data, rx_buf_sz,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2313
				 PCI_DMA_FROMDEVICE);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2314
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2315
	rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2316
out:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2317
	return skb;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2318
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2319
err_out:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2320
	rtl8169_make_unusable_by_asic(desc);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2321
	goto out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2322
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2323
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2324
static void rtl8169_rx_clear(struct rtl8169_private *tp)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2325
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2326
	unsigned int i;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2327
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2328
	for (i = 0; i < NUM_RX_DESC; i++) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2329
		if (tp->Rx_skbuff[i]) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2330
			rtl8169_free_rx_skb(tp, tp->Rx_skbuff + i,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2331
					    tp->RxDescArray + i);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2332
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2333
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2334
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2335
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2336
static u32 rtl8169_rx_fill(struct rtl8169_private *tp, struct net_device *dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2337
			   u32 start, u32 end)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2338
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2339
	u32 cur;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2340
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2341
	for (cur = start; end - cur != 0; cur++) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2342
		struct sk_buff *skb;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2343
		unsigned int i = cur % NUM_RX_DESC;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2344
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2345
		WARN_ON((s32)(end - cur) < 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2346
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2347
		if (tp->Rx_skbuff[i])
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2348
			continue;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2349
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2350
		skb = rtl8169_alloc_rx_skb(tp->pci_dev, dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2351
					   tp->RxDescArray + i,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2352
					   tp->rx_buf_sz, tp->align);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2353
		if (!skb)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2354
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2355
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2356
		tp->Rx_skbuff[i] = skb;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2357
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2358
	return cur - start;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2359
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2360
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2361
static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2362
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2363
	desc->opts1 |= cpu_to_le32(RingEnd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2364
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2365
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2366
static void rtl8169_init_ring_indexes(struct rtl8169_private *tp)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2367
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2368
	tp->dirty_tx = tp->dirty_rx = tp->cur_tx = tp->cur_rx = 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2369
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2370
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2371
static int rtl8169_init_ring(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2372
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2373
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2374
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2375
	rtl8169_init_ring_indexes(tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2376
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2377
	memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2378
	memset(tp->Rx_skbuff, 0x0, NUM_RX_DESC * sizeof(struct sk_buff *));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2379
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2380
	if (rtl8169_rx_fill(tp, dev, 0, NUM_RX_DESC) != NUM_RX_DESC)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2381
		goto err_out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2382
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2383
	rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2384
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2385
	return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2386
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2387
err_out:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2388
	rtl8169_rx_clear(tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2389
	return -ENOMEM;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2390
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2391
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2392
static void rtl8169_unmap_tx_skb(struct pci_dev *pdev, struct ring_info *tx_skb,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2393
				 struct TxDesc *desc)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2394
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2395
	unsigned int len = tx_skb->len;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2396
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2397
	pci_unmap_single(pdev, le64_to_cpu(desc->addr), len, PCI_DMA_TODEVICE);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2398
	desc->opts1 = 0x00;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2399
	desc->opts2 = 0x00;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2400
	desc->addr = 0x00;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2401
	tx_skb->len = 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2402
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2403
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2404
static void rtl8169_tx_clear(struct rtl8169_private *tp)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2405
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2406
	unsigned int i;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2407
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2408
	for (i = tp->dirty_tx; i < tp->dirty_tx + NUM_TX_DESC; i++) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2409
		unsigned int entry = i % NUM_TX_DESC;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2410
		struct ring_info *tx_skb = tp->tx_skb + entry;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2411
		unsigned int len = tx_skb->len;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2412
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2413
		if (len) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2414
			struct sk_buff *skb = tx_skb->skb;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2415
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2416
			rtl8169_unmap_tx_skb(tp->pci_dev, tx_skb,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2417
					     tp->TxDescArray + entry);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2418
			if (skb) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2419
				if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2420
					dev_kfree_skb(skb);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2421
				tx_skb->skb = NULL;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2422
			}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2423
			tp->dev->stats.tx_dropped++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2424
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2425
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2426
	tp->cur_tx = tp->dirty_tx = 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2427
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2428
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2429
static void rtl8169_schedule_work(struct net_device *dev, work_func_t task)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2430
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2431
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2432
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2433
	PREPARE_DELAYED_WORK(&tp->task, task);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2434
	schedule_delayed_work(&tp->task, 4);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2435
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2436
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2437
static void rtl8169_wait_for_quiescence(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2438
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2439
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2440
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2441
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2442
	synchronize_irq(dev->irq);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2443
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2444
	/* Wait for any pending NAPI task to complete */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2445
#ifdef CONFIG_R8169_NAPI
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2446
	napi_disable(&tp->napi);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2447
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2448
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2449
	rtl8169_irq_mask_and_ack(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2450
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2451
#ifdef CONFIG_R8169_NAPI
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2452
	tp->intr_mask = 0xffff;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2453
	RTL_W16(IntrMask, tp->intr_event);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2454
	napi_enable(&tp->napi);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2455
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2456
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2457
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2458
static void rtl8169_reinit_task(struct work_struct *work)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2459
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2460
	struct rtl8169_private *tp =
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2461
		container_of(work, struct rtl8169_private, task.work);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2462
	struct net_device *dev = tp->dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2463
	int ret;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2464
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2465
	rtnl_lock();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2466
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2467
	if (!netif_running(dev))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2468
		goto out_unlock;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2469
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2470
	rtl8169_wait_for_quiescence(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2471
	rtl8169_close(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2472
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2473
	ret = rtl8169_open(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2474
	if (unlikely(ret < 0)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2475
		if (net_ratelimit() && netif_msg_drv(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2476
			printk(KERN_ERR PFX "%s: reinit failure (status = %d)."
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2477
			       " Rescheduling.\n", dev->name, ret);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2478
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2479
		rtl8169_schedule_work(dev, rtl8169_reinit_task);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2480
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2481
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2482
out_unlock:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2483
	rtnl_unlock();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2484
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2485
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2486
static void rtl8169_reset_task(struct work_struct *work)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2487
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2488
	struct rtl8169_private *tp =
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2489
		container_of(work, struct rtl8169_private, task.work);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2490
	struct net_device *dev = tp->dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2491
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2492
	rtnl_lock();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2493
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2494
	if (!netif_running(dev))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2495
		goto out_unlock;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2496
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2497
	rtl8169_wait_for_quiescence(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2498
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2499
	rtl8169_rx_interrupt(dev, tp, tp->mmio_addr, ~(u32)0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2500
	rtl8169_tx_clear(tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2501
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2502
	if (tp->dirty_rx == tp->cur_rx) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2503
		rtl8169_init_ring_indexes(tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2504
		rtl_hw_start(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2505
		netif_wake_queue(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2506
		rtl8169_check_link_status(dev, tp, tp->mmio_addr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2507
	} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2508
		if (net_ratelimit() && netif_msg_intr(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2509
			printk(KERN_EMERG PFX "%s: Rx buffers shortage\n",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2510
			       dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2511
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2512
		rtl8169_schedule_work(dev, rtl8169_reset_task);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2513
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2514
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2515
out_unlock:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2516
	rtnl_unlock();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2517
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2518
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2519
static void rtl8169_tx_timeout(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2520
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2521
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2522
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2523
	if (tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2524
		return;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2525
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2526
	rtl8169_hw_reset(tp->mmio_addr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2527
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2528
	/* Let's wait a bit while any (async) irq lands on */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2529
	rtl8169_schedule_work(dev, rtl8169_reset_task);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2530
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2531
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2532
static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2533
			      u32 opts1)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2534
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2535
	struct skb_shared_info *info = skb_shinfo(skb);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2536
	unsigned int cur_frag, entry;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2537
	struct TxDesc * uninitialized_var(txd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2538
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2539
	entry = tp->cur_tx;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2540
	for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2541
		skb_frag_t *frag = info->frags + cur_frag;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2542
		dma_addr_t mapping;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2543
		u32 status, len;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2544
		void *addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2545
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2546
		entry = (entry + 1) % NUM_TX_DESC;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2547
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2548
		txd = tp->TxDescArray + entry;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2549
		len = frag->size;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2550
		addr = ((void *) page_address(frag->page)) + frag->page_offset;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2551
		mapping = pci_map_single(tp->pci_dev, addr, len, PCI_DMA_TODEVICE);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2552
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2553
		/* anti gcc 2.95.3 bugware (sic) */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2554
		status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2555
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2556
		txd->opts1 = cpu_to_le32(status);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2557
		txd->addr = cpu_to_le64(mapping);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2558
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2559
		tp->tx_skb[entry].len = len;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2560
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2561
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2562
	if (cur_frag) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2563
		tp->tx_skb[entry].skb = skb;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2564
		txd->opts1 |= cpu_to_le32(LastFrag);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2565
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2566
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2567
	return cur_frag;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2568
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2569
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2570
static inline u32 rtl8169_tso_csum(struct sk_buff *skb, struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2571
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2572
	if (dev->features & NETIF_F_TSO) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2573
		u32 mss = skb_shinfo(skb)->gso_size;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2574
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2575
		if (mss)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2576
			return LargeSend | ((mss & MSSMask) << MSSShift);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2577
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2578
	if (skb->ip_summed == CHECKSUM_PARTIAL) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2579
		const struct iphdr *ip = ip_hdr(skb);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2580
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2581
		if (ip->protocol == IPPROTO_TCP)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2582
			return IPCS | TCPCS;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2583
		else if (ip->protocol == IPPROTO_UDP)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2584
			return IPCS | UDPCS;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2585
		WARN_ON(1);	/* we need a WARN() */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2586
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2587
	return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2588
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2589
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2590
static int rtl8169_start_xmit(struct sk_buff *skb, struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2591
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2592
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2593
	unsigned int frags, entry = tp->cur_tx % NUM_TX_DESC;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2594
	struct TxDesc *txd = tp->TxDescArray + entry;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2595
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2596
	dma_addr_t mapping;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2597
	u32 status, len;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2598
	u32 opts1;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2599
	int ret = NETDEV_TX_OK;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2600
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2601
	if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2602
		if (netif_msg_drv(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2603
			printk(KERN_ERR
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2604
			       "%s: BUG! Tx Ring full when queue awake!\n",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2605
			       dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2606
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2607
		goto err_stop;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2608
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2609
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2610
	if (unlikely(le32_to_cpu(txd->opts1) & DescOwn))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2611
		goto err_stop;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2612
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2613
	opts1 = DescOwn | rtl8169_tso_csum(skb, dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2614
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2615
	frags = rtl8169_xmit_frags(tp, skb, opts1);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2616
	if (frags) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2617
		len = skb_headlen(skb);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2618
		opts1 |= FirstFrag;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2619
	} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2620
		len = skb->len;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2621
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2622
		if (unlikely(len < ETH_ZLEN)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2623
			if (skb_padto(skb, ETH_ZLEN))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2624
				goto err_update_stats;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2625
			len = ETH_ZLEN;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2626
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2627
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2628
		opts1 |= FirstFrag | LastFrag;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2629
		tp->tx_skb[entry].skb = skb;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2630
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2631
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2632
	mapping = pci_map_single(tp->pci_dev, skb->data, len, PCI_DMA_TODEVICE);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2633
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2634
	tp->tx_skb[entry].len = len;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2635
	txd->addr = cpu_to_le64(mapping);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2636
	txd->opts2 = cpu_to_le32(rtl8169_tx_vlan_tag(tp, skb));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2637
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2638
	wmb();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2639
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2640
	/* anti gcc 2.95.3 bugware (sic) */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2641
	status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2642
	txd->opts1 = cpu_to_le32(status);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2643
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2644
	dev->trans_start = jiffies;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2645
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2646
	tp->cur_tx += frags + 1;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2647
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2648
	smp_wmb();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2649
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2650
	RTL_W8(TxPoll, NPQ);	/* set polling bit */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2651
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2652
	if (!tp->ecdev) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2653
		if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2654
			netif_stop_queue(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2655
			smp_rmb();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2656
			if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2657
				netif_wake_queue(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2658
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2659
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2660
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2661
out:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2662
	return ret;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2663
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2664
err_stop:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2665
	if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2666
		netif_stop_queue(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2667
	ret = NETDEV_TX_BUSY;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2668
err_update_stats:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2669
	dev->stats.tx_dropped++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2670
	goto out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2671
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2672
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2673
static void rtl8169_pcierr_interrupt(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2674
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2675
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2676
	struct pci_dev *pdev = tp->pci_dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2677
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2678
	u16 pci_status, pci_cmd;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2679
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2680
	pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2681
	pci_read_config_word(pdev, PCI_STATUS, &pci_status);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2682
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2683
	if (netif_msg_intr(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2684
		printk(KERN_ERR
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2685
		       "%s: PCI error (cmd = 0x%04x, status = 0x%04x).\n",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2686
		       dev->name, pci_cmd, pci_status);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2687
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2688
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2689
	/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2690
	 * The recovery sequence below admits a very elaborated explanation:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2691
	 * - it seems to work;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2692
	 * - I did not see what else could be done;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2693
	 * - it makes iop3xx happy.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2694
	 *
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2695
	 * Feel free to adjust to your needs.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2696
	 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2697
	if (pdev->broken_parity_status)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2698
		pci_cmd &= ~PCI_COMMAND_PARITY;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2699
	else
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2700
		pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2701
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2702
	pci_write_config_word(pdev, PCI_COMMAND, pci_cmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2703
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2704
	pci_write_config_word(pdev, PCI_STATUS,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2705
		pci_status & (PCI_STATUS_DETECTED_PARITY |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2706
		PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2707
		PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2708
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2709
	/* The infamous DAC f*ckup only happens at boot time */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2710
	if ((tp->cp_cmd & PCIDAC) && !tp->dirty_rx && !tp->cur_rx) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2711
		if (netif_msg_intr(tp))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2712
			printk(KERN_INFO "%s: disabling PCI DAC.\n", dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2713
		tp->cp_cmd &= ~PCIDAC;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2714
		RTL_W16(CPlusCmd, tp->cp_cmd);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2715
		dev->features &= ~NETIF_F_HIGHDMA;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2716
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2717
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2718
	rtl8169_hw_reset(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2719
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2720
	rtl8169_schedule_work(dev, rtl8169_reinit_task);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2721
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2722
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2723
static void rtl8169_tx_interrupt(struct net_device *dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2724
				 struct rtl8169_private *tp,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2725
				 void __iomem *ioaddr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2726
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2727
	unsigned int dirty_tx, tx_left;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2728
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2729
	dirty_tx = tp->dirty_tx;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2730
	smp_rmb();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2731
	tx_left = tp->cur_tx - dirty_tx;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2732
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2733
	while (tx_left > 0) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2734
		unsigned int entry = dirty_tx % NUM_TX_DESC;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2735
		struct ring_info *tx_skb = tp->tx_skb + entry;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2736
		u32 len = tx_skb->len;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2737
		u32 status;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2738
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2739
		rmb();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2740
		status = le32_to_cpu(tp->TxDescArray[entry].opts1);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2741
		if (status & DescOwn)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2742
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2743
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2744
		dev->stats.tx_bytes += len;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2745
		dev->stats.tx_packets++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2746
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2747
		rtl8169_unmap_tx_skb(tp->pci_dev, tx_skb, tp->TxDescArray + entry);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2748
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2749
		if (status & LastFrag) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2750
			if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2751
				dev_kfree_skb_irq(tx_skb->skb);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2752
			tx_skb->skb = NULL;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2753
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2754
		dirty_tx++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2755
		tx_left--;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2756
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2757
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2758
	if (tp->dirty_tx != dirty_tx) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2759
		tp->dirty_tx = dirty_tx;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2760
		smp_wmb();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2761
		if (!tp->ecdev && netif_queue_stopped(dev) &&
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2762
		    (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2763
			netif_wake_queue(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2764
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2765
		/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2766
		 * 8168 hack: TxPoll requests are lost when the Tx packets are
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2767
		 * too close. Let's kick an extra TxPoll request when a burst
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2768
		 * of start_xmit activity is detected (if it is not detected,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2769
		 * it is slow enough). -- FR
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2770
		 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2771
		smp_rmb();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2772
		if (tp->cur_tx != dirty_tx)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2773
			RTL_W8(TxPoll, NPQ);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2774
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2775
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2776
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2777
static inline int rtl8169_fragmented_frame(u32 status)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2778
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2779
	return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2780
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2781
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2782
static inline void rtl8169_rx_csum(struct sk_buff *skb, struct RxDesc *desc)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2783
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2784
	u32 opts1 = le32_to_cpu(desc->opts1);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2785
	u32 status = opts1 & RxProtoMask;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2786
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2787
	if (((status == RxProtoTCP) && !(opts1 & TCPFail)) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2788
	    ((status == RxProtoUDP) && !(opts1 & UDPFail)) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2789
	    ((status == RxProtoIP) && !(opts1 & IPFail)))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2790
		skb->ip_summed = CHECKSUM_UNNECESSARY;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2791
	else
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2792
		skb->ip_summed = CHECKSUM_NONE;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2793
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2794
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2795
static inline bool rtl8169_try_rx_copy(struct sk_buff **sk_buff,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2796
				       struct rtl8169_private *tp, int pkt_size,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2797
				       dma_addr_t addr)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2798
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2799
	struct sk_buff *skb;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2800
	bool done = false;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2801
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2802
	if (pkt_size >= rx_copybreak)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2803
		goto out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2804
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2805
	skb = netdev_alloc_skb(tp->dev, pkt_size + NET_IP_ALIGN);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2806
	if (!skb)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2807
		goto out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2808
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2809
	pci_dma_sync_single_for_cpu(tp->pci_dev, addr, pkt_size,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2810
				    PCI_DMA_FROMDEVICE);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2811
	skb_reserve(skb, NET_IP_ALIGN);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2812
	skb_copy_from_linear_data(*sk_buff, skb->data, pkt_size);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2813
	*sk_buff = skb;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2814
	done = true;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2815
out:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2816
	return done;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2817
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2818
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2819
static int rtl8169_rx_interrupt(struct net_device *dev,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2820
				struct rtl8169_private *tp,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2821
				void __iomem *ioaddr, u32 budget)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2822
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2823
	unsigned int cur_rx, rx_left;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2824
	unsigned int delta, count;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2825
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2826
	cur_rx = tp->cur_rx;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2827
	rx_left = NUM_RX_DESC + tp->dirty_rx - cur_rx;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2828
	rx_left = rtl8169_rx_quota(rx_left, budget);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2829
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2830
	for (; rx_left > 0; rx_left--, cur_rx++) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2831
		unsigned int entry = cur_rx % NUM_RX_DESC;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2832
		struct RxDesc *desc = tp->RxDescArray + entry;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2833
		u32 status;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2834
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2835
		rmb();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2836
		status = le32_to_cpu(desc->opts1);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2837
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2838
		if (status & DescOwn)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2839
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2840
		if (unlikely(status & RxRES)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2841
			if (netif_msg_rx_err(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2842
				printk(KERN_INFO
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2843
				       "%s: Rx ERROR. status = %08x\n",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2844
				       dev->name, status);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2845
			}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2846
			dev->stats.rx_errors++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2847
			if (status & (RxRWT | RxRUNT))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2848
				dev->stats.rx_length_errors++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2849
			if (status & RxCRC)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2850
				dev->stats.rx_crc_errors++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2851
			if (status & RxFOVF) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2852
				if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2853
					rtl8169_schedule_work(dev, rtl8169_reset_task);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2854
				dev->stats.rx_fifo_errors++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2855
			}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2856
			rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2857
		} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2858
			struct sk_buff *skb = tp->Rx_skbuff[entry];
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2859
			dma_addr_t addr = le64_to_cpu(desc->addr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2860
			int pkt_size = (status & 0x00001FFF) - 4;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2861
			struct pci_dev *pdev = tp->pci_dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2862
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2863
			/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2864
			 * The driver does not support incoming fragmented
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2865
			 * frames. They are seen as a symptom of over-mtu
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2866
			 * sized frames.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2867
			 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2868
			if (unlikely(rtl8169_fragmented_frame(status))) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2869
				dev->stats.rx_dropped++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2870
				dev->stats.rx_length_errors++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2871
				rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2872
				continue;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2873
			}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2874
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2875
			rtl8169_rx_csum(skb, desc);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2876
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2877
			if (tp->ecdev) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2878
				pci_dma_sync_single_for_cpu(pdev, addr, pkt_size,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2879
						PCI_DMA_FROMDEVICE);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2880
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2881
				ecdev_receive(tp->ecdev, skb->data, pkt_size);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2882
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2883
				pci_dma_sync_single_for_device(pdev, addr,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2884
						pkt_size, PCI_DMA_FROMDEVICE);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2885
				rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2886
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2887
				// No need to detect link status as
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2888
				// long as frames are received: Reset watchdog.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2889
				tp->ec_watchdog_jiffies = jiffies;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2890
			} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2891
				if (rtl8169_try_rx_copy(&skb, tp, pkt_size, addr)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2892
					pci_dma_sync_single_for_device(pdev, addr,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2893
							pkt_size, PCI_DMA_FROMDEVICE);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2894
					rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2895
				} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2896
					pci_unmap_single(pdev, addr, pkt_size,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2897
							PCI_DMA_FROMDEVICE);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2898
					tp->Rx_skbuff[entry] = NULL;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2899
				}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2900
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2901
				skb_put(skb, pkt_size);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2902
				skb->protocol = eth_type_trans(skb, dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2903
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2904
				if (rtl8169_rx_vlan_skb(tp, desc, skb) < 0)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2905
					rtl8169_rx_skb(skb);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2906
			}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2907
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2908
			dev->last_rx = jiffies;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2909
			dev->stats.rx_bytes += pkt_size;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2910
			dev->stats.rx_packets++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2911
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2912
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2913
		/* Work around for AMD plateform. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2914
		if ((desc->opts2 & cpu_to_le32(0xfffe000)) &&
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2915
		    (tp->mac_version == RTL_GIGA_MAC_VER_05)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2916
			desc->opts2 = 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2917
			cur_rx++;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2918
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2919
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2920
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2921
	count = cur_rx - tp->cur_rx;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2922
	tp->cur_rx = cur_rx;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2923
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2924
	if (tp->ecdev) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2925
		/* descriptors are cleaned up immediately. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2926
		tp->dirty_rx = tp->cur_rx;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2927
	} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2928
		delta = rtl8169_rx_fill(tp, dev, tp->dirty_rx, tp->cur_rx);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2929
		if (!delta && count && netif_msg_intr(tp))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2930
			printk(KERN_INFO "%s: no Rx buffer allocated\n", dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2931
		tp->dirty_rx += delta;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2932
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2933
		/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2934
		 * FIXME: until there is periodic timer to try and refill the ring,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2935
		 * a temporary shortage may definitely kill the Rx process.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2936
		 * - disable the asic to try and avoid an overflow and kick it again
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2937
		 *   after refill ?
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2938
		 * - how do others driver handle this condition (Uh oh...).
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2939
		 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2940
		if ((tp->dirty_rx + NUM_RX_DESC == tp->cur_rx) && netif_msg_intr(tp))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2941
			printk(KERN_EMERG "%s: Rx buffers exhausted\n", dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2942
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2943
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2944
	return count;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2945
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2946
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2947
static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2948
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2949
	struct net_device *dev = dev_instance;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2950
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2951
	int boguscnt = max_interrupt_work;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2952
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2953
	int status;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2954
	int handled = 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2955
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2956
	do {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2957
		status = RTL_R16(IntrStatus);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2958
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2959
		/* hotplug/major error/no more work/shared irq */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2960
		if ((status == 0xFFFF) || !status)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2961
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2962
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2963
		handled = 1;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2964
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2965
		if (unlikely(!tp->ecdev && !netif_running(dev))) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2966
			rtl8169_asic_down(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2967
			goto out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2968
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2969
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2970
		status &= tp->intr_mask;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2971
		RTL_W16(IntrStatus,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2972
			(status & RxFIFOOver) ? (status | RxOverflow) : status);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2973
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2974
		if (!(status & tp->intr_event))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2975
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2976
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2977
		/* Work around for rx fifo overflow */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2978
		if (!tp->ecdev && unlikely(status & RxFIFOOver) &&
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2979
				(tp->mac_version == RTL_GIGA_MAC_VER_11)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2980
			netif_stop_queue(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2981
			rtl8169_tx_timeout(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2982
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2983
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2984
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2985
		if (unlikely(!tp->ecdev && (status & SYSErr))) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2986
			rtl8169_pcierr_interrupt(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2987
			break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2988
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2989
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2990
		if (status & LinkChg)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2991
			rtl8169_check_link_status(dev, tp, ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2992
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2993
#ifdef CONFIG_R8169_NAPI
1376
6b51a2201d41 Fixed r8169 frame reception if NAPI is enabled.
Florian Pose <fp@igh-essen.com>
parents: 1353
diff changeset
  2994
		if (tp->ecdev) {
6b51a2201d41 Fixed r8169 frame reception if NAPI is enabled.
Florian Pose <fp@igh-essen.com>
parents: 1353
diff changeset
  2995
			/* Rx interrupt */
6b51a2201d41 Fixed r8169 frame reception if NAPI is enabled.
Florian Pose <fp@igh-essen.com>
parents: 1353
diff changeset
  2996
			if (status & (RxOK | RxOverflow | RxFIFOOver))
6b51a2201d41 Fixed r8169 frame reception if NAPI is enabled.
Florian Pose <fp@igh-essen.com>
parents: 1353
diff changeset
  2997
				rtl8169_rx_interrupt(dev, tp, ioaddr, ~(u32)0);
6b51a2201d41 Fixed r8169 frame reception if NAPI is enabled.
Florian Pose <fp@igh-essen.com>
parents: 1353
diff changeset
  2998
6b51a2201d41 Fixed r8169 frame reception if NAPI is enabled.
Florian Pose <fp@igh-essen.com>
parents: 1353
diff changeset
  2999
			/* Tx interrupt */
6b51a2201d41 Fixed r8169 frame reception if NAPI is enabled.
Florian Pose <fp@igh-essen.com>
parents: 1353
diff changeset
  3000
			if (status & (TxOK | TxErr))
6b51a2201d41 Fixed r8169 frame reception if NAPI is enabled.
Florian Pose <fp@igh-essen.com>
parents: 1353
diff changeset
  3001
				rtl8169_tx_interrupt(dev, tp, ioaddr);
6b51a2201d41 Fixed r8169 frame reception if NAPI is enabled.
Florian Pose <fp@igh-essen.com>
parents: 1353
diff changeset
  3002
			
6b51a2201d41 Fixed r8169 frame reception if NAPI is enabled.
Florian Pose <fp@igh-essen.com>
parents: 1353
diff changeset
  3003
		} else if (status & tp->napi_event) {
1353
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3004
			RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3005
			tp->intr_mask = ~tp->napi_event;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3006
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3007
			if (likely(netif_rx_schedule_prep(dev, &tp->napi)))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3008
				__netif_rx_schedule(dev, &tp->napi);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3009
			else if (netif_msg_intr(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3010
				printk(KERN_INFO "%s: interrupt %04x in poll\n",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3011
						dev->name, status);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3012
			}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3013
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3014
		break;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3015
#else
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3016
		/* Rx interrupt */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3017
		if (status & (RxOK | RxOverflow | RxFIFOOver))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3018
			rtl8169_rx_interrupt(dev, tp, ioaddr, ~(u32)0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3019
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3020
		/* Tx interrupt */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3021
		if (status & (TxOK | TxErr))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3022
			rtl8169_tx_interrupt(dev, tp, ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3023
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3024
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3025
		boguscnt--;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3026
	} while (boguscnt > 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3027
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3028
	if (!tp->ecdev) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3029
		if (boguscnt <= 0) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3030
			if (netif_msg_intr(tp) && net_ratelimit() ) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3031
				printk(KERN_WARNING
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3032
						"%s: Too much work at interrupt!\n", dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3033
			}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3034
			/* Clear all interrupt sources. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3035
			RTL_W16(IntrStatus, 0xffff);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3036
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3037
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3038
out:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3039
	return IRQ_RETVAL(handled);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3040
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3041
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3042
#ifdef CONFIG_R8169_NAPI
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3043
static int rtl8169_poll(struct napi_struct *napi, int budget)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3044
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3045
	struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3046
	struct net_device *dev = tp->dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3047
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3048
	int work_done;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3049
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3050
	work_done = rtl8169_rx_interrupt(dev, tp, ioaddr, (u32) budget);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3051
	rtl8169_tx_interrupt(dev, tp, ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3052
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3053
	if (work_done < budget) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3054
		netif_rx_complete(dev, napi);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3055
		tp->intr_mask = 0xffff;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3056
		/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3057
		 * 20040426: the barrier is not strictly required but the
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3058
		 * behavior of the irq handler could be less predictable
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3059
		 * without it. Btw, the lack of flush for the posted pci
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3060
		 * write is safe - FR
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3061
		 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3062
		smp_wmb();
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3063
		RTL_W16(IntrMask, tp->intr_event);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3064
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3065
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3066
	return work_done;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3067
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3068
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3069
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3070
static void rtl8169_down(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3071
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3072
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3073
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3074
	unsigned int intrmask;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3075
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3076
	rtl8169_delete_timer(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3077
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3078
	if (!tp->ecdev) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3079
		netif_stop_queue(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3080
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3081
#ifdef CONFIG_R8169_NAPI
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3082
		napi_disable(&tp->napi);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3083
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3084
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3085
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3086
core_down:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3087
	if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3088
		spin_lock_irq(&tp->lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3089
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3090
	rtl8169_asic_down(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3091
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3092
	/* Update the error counts. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3093
	dev->stats.rx_missed_errors += RTL_R32(RxMissed);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3094
	RTL_W32(RxMissed, 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3095
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3096
	if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3097
		spin_unlock_irq(&tp->lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3098
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3099
	if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3100
		synchronize_irq(dev->irq);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3101
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3102
	/* Give a racing hard_start_xmit a few cycles to complete. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3103
	synchronize_sched();  /* FIXME: should this be synchronize_irq()? */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3104
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3105
	/*
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3106
	 * And now for the 50k$ question: are IRQ disabled or not ?
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3107
	 *
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3108
	 * Two paths lead here:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3109
	 * 1) dev->close
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3110
	 *    -> netif_running() is available to sync the current code and the
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3111
	 *       IRQ handler. See rtl8169_interrupt for details.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3112
	 * 2) dev->change_mtu
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3113
	 *    -> rtl8169_poll can not be issued again and re-enable the
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3114
	 *       interruptions. Let's simply issue the IRQ down sequence again.
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3115
	 *
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3116
	 * No loop if hotpluged or major error (0xffff).
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3117
	 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3118
	intrmask = RTL_R16(IntrMask);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3119
	if (intrmask && (intrmask != 0xffff))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3120
		goto core_down;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3121
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3122
	rtl8169_tx_clear(tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3123
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3124
	rtl8169_rx_clear(tp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3125
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3126
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3127
static int rtl8169_close(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3128
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3129
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3130
	struct pci_dev *pdev = tp->pci_dev;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3131
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3132
	rtl8169_down(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3133
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3134
	if (!tp->ecdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3135
		free_irq(dev->irq, dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3136
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3137
	pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3138
			    tp->RxPhyAddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3139
	pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3140
			    tp->TxPhyAddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3141
	tp->TxDescArray = NULL;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3142
	tp->RxDescArray = NULL;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3143
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3144
	return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3145
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3146
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3147
static void rtl_set_rx_mode(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3148
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3149
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3150
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3151
	unsigned long flags;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3152
	u32 mc_filter[2];	/* Multicast hash filter */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3153
	int rx_mode;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3154
	u32 tmp = 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3155
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3156
	if (dev->flags & IFF_PROMISC) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3157
		/* Unconditionally log net taps. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3158
		if (netif_msg_link(tp)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3159
			printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n",
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3160
			       dev->name);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3161
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3162
		rx_mode =
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3163
		    AcceptBroadcast | AcceptMulticast | AcceptMyPhys |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3164
		    AcceptAllPhys;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3165
		mc_filter[1] = mc_filter[0] = 0xffffffff;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3166
	} else if ((dev->mc_count > multicast_filter_limit)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3167
		   || (dev->flags & IFF_ALLMULTI)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3168
		/* Too many to filter perfectly -- accept all multicasts. */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3169
		rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3170
		mc_filter[1] = mc_filter[0] = 0xffffffff;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3171
	} else {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3172
		struct dev_mc_list *mclist;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3173
		unsigned int i;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3174
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3175
		rx_mode = AcceptBroadcast | AcceptMyPhys;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3176
		mc_filter[1] = mc_filter[0] = 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3177
		for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3178
		     i++, mclist = mclist->next) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3179
			int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3180
			mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3181
			rx_mode |= AcceptMulticast;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3182
		}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3183
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3184
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3185
	spin_lock_irqsave(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3186
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3187
	tmp = rtl8169_rx_config | rx_mode |
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3188
	      (RTL_R32(RxConfig) & rtl_chip_info[tp->chipset].RxConfigMask);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3189
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3190
	if ((tp->mac_version == RTL_GIGA_MAC_VER_11) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3191
	    (tp->mac_version == RTL_GIGA_MAC_VER_12) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3192
	    (tp->mac_version == RTL_GIGA_MAC_VER_13) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3193
	    (tp->mac_version == RTL_GIGA_MAC_VER_14) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3194
	    (tp->mac_version == RTL_GIGA_MAC_VER_15) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3195
	    (tp->mac_version == RTL_GIGA_MAC_VER_16) ||
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3196
	    (tp->mac_version == RTL_GIGA_MAC_VER_17)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3197
		mc_filter[0] = 0xffffffff;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3198
		mc_filter[1] = 0xffffffff;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3199
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3200
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3201
	RTL_W32(MAR0 + 0, mc_filter[0]);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3202
	RTL_W32(MAR0 + 4, mc_filter[1]);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3203
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3204
	RTL_W32(RxConfig, tmp);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3205
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3206
	spin_unlock_irqrestore(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3207
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3208
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3209
/**
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3210
 *  rtl8169_get_stats - Get rtl8169 read/write statistics
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3211
 *  @dev: The Ethernet Device to get statistics for
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3212
 *
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3213
 *  Get TX/RX statistics for rtl8169
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3214
 */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3215
static struct net_device_stats *rtl8169_get_stats(struct net_device *dev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3216
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3217
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3218
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3219
	unsigned long flags;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3220
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3221
	if (netif_running(dev)) {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3222
		spin_lock_irqsave(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3223
		dev->stats.rx_missed_errors += RTL_R32(RxMissed);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3224
		RTL_W32(RxMissed, 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3225
		spin_unlock_irqrestore(&tp->lock, flags);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3226
	}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3227
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3228
	return &dev->stats;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3229
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3230
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3231
#ifdef CONFIG_PM
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3232
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3233
static int rtl8169_suspend(struct pci_dev *pdev, pm_message_t state)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3234
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3235
	struct net_device *dev = pci_get_drvdata(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3236
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3237
	void __iomem *ioaddr = tp->mmio_addr;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3238
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3239
	if (tp->ecdev)
2251
5023ce75fe91 Fixed suspend/resume for r8169 drivers.
Florian Pose <fp@igh-essen.com>
parents: 1376
diff changeset
  3240
		return -EBUSY;
1353
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3241
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3242
	if (!netif_running(dev))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3243
		goto out_pci_suspend;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3244
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3245
	netif_device_detach(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3246
	netif_stop_queue(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3247
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3248
	spin_lock_irq(&tp->lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3249
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3250
	rtl8169_asic_down(ioaddr);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3251
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3252
	dev->stats.rx_missed_errors += RTL_R32(RxMissed);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3253
	RTL_W32(RxMissed, 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3254
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3255
	spin_unlock_irq(&tp->lock);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3256
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3257
out_pci_suspend:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3258
	pci_save_state(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3259
	pci_enable_wake(pdev, pci_choose_state(pdev, state),
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3260
		(tp->features & RTL_FEATURE_WOL) ? 1 : 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3261
	pci_set_power_state(pdev, pci_choose_state(pdev, state));
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3262
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3263
	return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3264
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3265
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3266
static int rtl8169_resume(struct pci_dev *pdev)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3267
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3268
	struct net_device *dev = pci_get_drvdata(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3269
	struct rtl8169_private *tp = netdev_priv(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3270
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3271
	if (tp->ecdev)
2251
5023ce75fe91 Fixed suspend/resume for r8169 drivers.
Florian Pose <fp@igh-essen.com>
parents: 1376
diff changeset
  3272
		return -EBUSY;
1353
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3273
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3274
	pci_set_power_state(pdev, PCI_D0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3275
	pci_restore_state(pdev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3276
	pci_enable_wake(pdev, PCI_D0, 0);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3277
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3278
	if (!netif_running(dev))
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3279
		goto out;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3280
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3281
	netif_device_attach(dev);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3282
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3283
	rtl8169_schedule_work(dev, rtl8169_reset_task);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3284
out:
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3285
	return 0;
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3286
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3287
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3288
#endif /* CONFIG_PM */
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3289
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3290
static struct pci_driver rtl8169_pci_driver = {
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3291
	.name		= MODULENAME,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3292
	.id_table	= rtl8169_pci_tbl,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3293
	.probe		= rtl8169_init_one,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3294
	.remove		= __devexit_p(rtl8169_remove_one),
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3295
#ifdef CONFIG_PM
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3296
	.suspend	= rtl8169_suspend,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3297
	.resume		= rtl8169_resume,
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3298
#endif
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3299
};
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3300
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3301
static int __init rtl8169_init_module(void)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3302
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3303
	return pci_register_driver(&rtl8169_pci_driver);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3304
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3305
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3306
static void __exit rtl8169_cleanup_module(void)
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3307
{
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3308
	pci_unregister_driver(&rtl8169_pci_driver);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3309
}
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3310
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3311
module_init(rtl8169_init_module);
22b1de4c74e4 First version of r8169 driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3312
module_exit(rtl8169_cleanup_module);