Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * New driver for Marvell Yukon 2 chipset. |
| 3 | * Based on earlier sk98lin, and skge driver. |
| 4 | * |
| 5 | * This driver intentionally does not support all the features |
| 6 | * of the original driver such as link fail-over and link management because |
| 7 | * those should be done at higher levels. |
| 8 | * |
| 9 | * Copyright (C) 2005 Stephen Hemminger <shemminger@osdl.org> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
Stephen Hemminger | 798b6b1 | 2006-10-22 20:16:57 -0700 | [diff] [blame] | 13 | * the Free Software Foundation; either version 2 of the License. |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | */ |
| 24 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 25 | #include <linux/crc32.h> |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 26 | #include <linux/kernel.h> |
| 27 | #include <linux/version.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/netdevice.h> |
Andrew Morton | d0bbccf | 2005-11-10 15:29:27 -0800 | [diff] [blame] | 30 | #include <linux/dma-mapping.h> |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 31 | #include <linux/etherdevice.h> |
| 32 | #include <linux/ethtool.h> |
| 33 | #include <linux/pci.h> |
| 34 | #include <linux/ip.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 35 | #include <net/ip.h> |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 36 | #include <linux/tcp.h> |
| 37 | #include <linux/in.h> |
| 38 | #include <linux/delay.h> |
Stephen Hemminger | 91c86df | 2005-12-09 11:34:57 -0800 | [diff] [blame] | 39 | #include <linux/workqueue.h> |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 40 | #include <linux/if_vlan.h> |
Stephen Hemminger | d70cd51 | 2005-12-09 11:35:09 -0800 | [diff] [blame] | 41 | #include <linux/prefetch.h> |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 42 | #include <linux/debugfs.h> |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 43 | #include <linux/mii.h> |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 44 | |
| 45 | #include <asm/irq.h> |
| 46 | |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 47 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) |
| 48 | #define SKY2_VLAN_TAG_USED 1 |
| 49 | #endif |
| 50 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 51 | #include "sky2.h" |
| 52 | |
| 53 | #define DRV_NAME "sky2" |
Stephen Hemminger | faf60e7 | 2007-09-19 15:36:47 -0700 | [diff] [blame] | 54 | #define DRV_VERSION "1.18" |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 55 | #define PFX DRV_NAME " " |
| 56 | |
| 57 | /* |
| 58 | * The Yukon II chipset takes 64 bit command blocks (called list elements) |
| 59 | * that are organized into three (receive, transmit, status) different rings |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 60 | * similar to Tigon3. |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 61 | */ |
| 62 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 63 | #define RX_LE_SIZE 1024 |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 64 | #define RX_LE_BYTES (RX_LE_SIZE*sizeof(struct sky2_rx_le)) |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 65 | #define RX_MAX_PENDING (RX_LE_SIZE/6 - 2) |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 66 | #define RX_DEF_PENDING RX_MAX_PENDING |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 67 | #define RX_SKB_ALIGN 8 |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 68 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 69 | #define TX_RING_SIZE 512 |
| 70 | #define TX_DEF_PENDING (TX_RING_SIZE - 1) |
| 71 | #define TX_MIN_PENDING 64 |
Stephen Hemminger | b19666d | 2006-03-07 11:06:36 -0800 | [diff] [blame] | 72 | #define MAX_SKB_TX_LE (4 + (sizeof(dma_addr_t)/sizeof(u32))*MAX_SKB_FRAGS) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 73 | |
| 74 | #define STATUS_RING_SIZE 2048 /* 2 ports * (TX + 2*RX) */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 75 | #define STATUS_LE_BYTES (STATUS_RING_SIZE*sizeof(struct sky2_status_le)) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 76 | #define TX_WATCHDOG (5 * HZ) |
| 77 | #define NAPI_WEIGHT 64 |
| 78 | #define PHY_RETRIES 1000 |
| 79 | |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 80 | #define SKY2_EEPROM_MAGIC 0x9955aabb |
| 81 | |
| 82 | |
Stephen Hemminger | cb5d954 | 2006-05-08 15:11:29 -0700 | [diff] [blame] | 83 | #define RING_NEXT(x,s) (((x)+1) & ((s)-1)) |
| 84 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 85 | static const u32 default_msg = |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 86 | NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK |
| 87 | | NETIF_MSG_TIMER | NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 88 | | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 89 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 90 | static int debug = -1; /* defaults above */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 91 | module_param(debug, int, 0); |
| 92 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 93 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 94 | static int copybreak __read_mostly = 128; |
Stephen Hemminger | bdb5c58 | 2005-12-09 11:34:55 -0800 | [diff] [blame] | 95 | module_param(copybreak, int, 0); |
| 96 | MODULE_PARM_DESC(copybreak, "Receive copy threshold"); |
| 97 | |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 98 | static int disable_msi = 0; |
| 99 | module_param(disable_msi, int, 0); |
| 100 | MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)"); |
| 101 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 102 | static const struct pci_device_id sky2_id_table[] = { |
Stephen Hemminger | e5b74c7 | 2006-12-04 15:53:36 -0800 | [diff] [blame] | 103 | { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9000) }, /* SK-9Sxx */ |
| 104 | { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) }, /* SK-9Exx */ |
Stephen Hemminger | 2d2a387 | 2006-05-17 14:37:04 -0700 | [diff] [blame] | 105 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b00) }, /* DGE-560T */ |
Stephen Hemminger | 2f4a66a | 2006-09-01 14:52:04 -0700 | [diff] [blame] | 106 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4001) }, /* DGE-550SX */ |
Stephen Hemminger | 508f89e | 2006-12-01 14:29:34 -0800 | [diff] [blame] | 107 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B02) }, /* DGE-560SX */ |
Stephen Hemminger | f1a0b6f | 2007-02-06 10:45:44 -0800 | [diff] [blame] | 108 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B03) }, /* DGE-550T */ |
Stephen Hemminger | e5b74c7 | 2006-12-04 15:53:36 -0800 | [diff] [blame] | 109 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4340) }, /* 88E8021 */ |
| 110 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4341) }, /* 88E8022 */ |
| 111 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4342) }, /* 88E8061 */ |
| 112 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4343) }, /* 88E8062 */ |
| 113 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4344) }, /* 88E8021 */ |
| 114 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4345) }, /* 88E8022 */ |
| 115 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4346) }, /* 88E8061 */ |
| 116 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4347) }, /* 88E8062 */ |
| 117 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4350) }, /* 88E8035 */ |
| 118 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4351) }, /* 88E8036 */ |
| 119 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4352) }, /* 88E8038 */ |
| 120 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4353) }, /* 88E8039 */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 121 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4354) }, /* 88E8040 */ |
Stephen Hemminger | e5b74c7 | 2006-12-04 15:53:36 -0800 | [diff] [blame] | 122 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4356) }, /* 88EC033 */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 123 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x435A) }, /* 88E8048 */ |
Stephen Hemminger | e5b74c7 | 2006-12-04 15:53:36 -0800 | [diff] [blame] | 124 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4360) }, /* 88E8052 */ |
| 125 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4361) }, /* 88E8050 */ |
| 126 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4362) }, /* 88E8053 */ |
| 127 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4363) }, /* 88E8055 */ |
| 128 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4364) }, /* 88E8056 */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 129 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4365) }, /* 88E8070 */ |
Stephen Hemminger | e5b74c7 | 2006-12-04 15:53:36 -0800 | [diff] [blame] | 130 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4366) }, /* 88EC036 */ |
| 131 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4367) }, /* 88EC032 */ |
| 132 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4368) }, /* 88EC034 */ |
Stephen Hemminger | f1a0b6f | 2007-02-06 10:45:44 -0800 | [diff] [blame] | 133 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4369) }, /* 88EC042 */ |
| 134 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436A) }, /* 88E8058 */ |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 135 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436B) }, /* 88E8071 */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 136 | { 0 } |
| 137 | }; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 138 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 139 | MODULE_DEVICE_TABLE(pci, sky2_id_table); |
| 140 | |
| 141 | /* Avoid conditionals by using array */ |
| 142 | static const unsigned txqaddr[] = { Q_XA1, Q_XA2 }; |
| 143 | static const unsigned rxqaddr[] = { Q_R1, Q_R2 }; |
Stephen Hemminger | f4ea431 | 2006-05-09 14:46:54 -0700 | [diff] [blame] | 144 | static const u32 portirq_msk[] = { Y2_IS_PORT_1, Y2_IS_PORT_2 }; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 145 | |
Stephen Hemminger | 92f965e | 2005-12-09 11:34:53 -0800 | [diff] [blame] | 146 | /* This driver supports yukon2 chipset only */ |
| 147 | static const char *yukon2_name[] = { |
| 148 | "XL", /* 0xb3 */ |
| 149 | "EC Ultra", /* 0xb4 */ |
Stephen Hemminger | 9374549 | 2007-02-06 10:45:43 -0800 | [diff] [blame] | 150 | "Extreme", /* 0xb5 */ |
Stephen Hemminger | 92f965e | 2005-12-09 11:34:53 -0800 | [diff] [blame] | 151 | "EC", /* 0xb6 */ |
| 152 | "FE", /* 0xb7 */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 153 | "FE+", /* 0xb8 */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Stephen Hemminger | d1b139c | 2007-09-05 16:56:19 +0100 | [diff] [blame] | 156 | static void sky2_set_multicast(struct net_device *dev); |
| 157 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 158 | /* Access to external PHY */ |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 159 | static int gm_phy_write(struct sky2_hw *hw, unsigned port, u16 reg, u16 val) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 160 | { |
| 161 | int i; |
| 162 | |
| 163 | gma_write16(hw, port, GM_SMI_DATA, val); |
| 164 | gma_write16(hw, port, GM_SMI_CTRL, |
| 165 | GM_SMI_CT_PHY_AD(PHY_ADDR_MARV) | GM_SMI_CT_REG_AD(reg)); |
| 166 | |
| 167 | for (i = 0; i < PHY_RETRIES; i++) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 168 | if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY)) |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 169 | return 0; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 170 | udelay(1); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 171 | } |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 172 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 173 | printk(KERN_WARNING PFX "%s: phy write timeout\n", hw->dev[port]->name); |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 174 | return -ETIMEDOUT; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 175 | } |
| 176 | |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 177 | static int __gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg, u16 *val) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 178 | { |
| 179 | int i; |
| 180 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 181 | gma_write16(hw, port, GM_SMI_CTRL, GM_SMI_CT_PHY_AD(PHY_ADDR_MARV) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 182 | | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD); |
| 183 | |
| 184 | for (i = 0; i < PHY_RETRIES; i++) { |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 185 | if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL) { |
| 186 | *val = gma_read16(hw, port, GM_SMI_DATA); |
| 187 | return 0; |
| 188 | } |
| 189 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 190 | udelay(1); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 191 | } |
| 192 | |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 193 | return -ETIMEDOUT; |
| 194 | } |
| 195 | |
| 196 | static u16 gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg) |
| 197 | { |
| 198 | u16 v; |
| 199 | |
| 200 | if (__gm_phy_read(hw, port, reg, &v) != 0) |
| 201 | printk(KERN_WARNING PFX "%s: phy read timeout\n", hw->dev[port]->name); |
| 202 | return v; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 205 | |
| 206 | static void sky2_power_on(struct sky2_hw *hw) |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 207 | { |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 208 | /* switch power to VCC (WA for VAUX problem) */ |
| 209 | sky2_write8(hw, B0_POWER_CTRL, |
| 210 | PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 211 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 212 | /* disable Core Clock Division, */ |
| 213 | sky2_write32(hw, B2_Y2_CLK_CTRL, Y2_CLK_DIV_DIS); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 214 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 215 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) |
| 216 | /* enable bits are inverted */ |
| 217 | sky2_write8(hw, B2_Y2_CLK_GATE, |
| 218 | Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS | |
| 219 | Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS | |
| 220 | Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS); |
| 221 | else |
| 222 | sky2_write8(hw, B2_Y2_CLK_GATE, 0); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 223 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 224 | if (hw->flags & SKY2_HW_ADV_POWER_CTL) { |
Stephen Hemminger | fc99fe0 | 2007-06-04 17:23:22 -0700 | [diff] [blame] | 225 | u32 reg; |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 226 | |
Stephen Hemminger | b234577 | 2007-08-21 14:34:02 -0700 | [diff] [blame] | 227 | sky2_pci_write32(hw, PCI_DEV_REG3, 0); |
| 228 | |
Stephen Hemminger | fc99fe0 | 2007-06-04 17:23:22 -0700 | [diff] [blame] | 229 | reg = sky2_pci_read32(hw, PCI_DEV_REG4); |
| 230 | /* set all bits to 0 except bits 15..12 and 8 */ |
| 231 | reg &= P_ASPM_CONTROL_MSK; |
| 232 | sky2_pci_write32(hw, PCI_DEV_REG4, reg); |
| 233 | |
| 234 | reg = sky2_pci_read32(hw, PCI_DEV_REG5); |
| 235 | /* set all bits to 0 except bits 28 & 27 */ |
| 236 | reg &= P_CTL_TIM_VMAIN_AV_MSK; |
| 237 | sky2_pci_write32(hw, PCI_DEV_REG5, reg); |
| 238 | |
| 239 | sky2_pci_write32(hw, PCI_CFG_REG_1, 0); |
Stephen Hemminger | 8f70920 | 2007-06-04 17:23:25 -0700 | [diff] [blame] | 240 | |
| 241 | /* Enable workaround for dev 4.107 on Yukon-Ultra & Extreme */ |
| 242 | reg = sky2_read32(hw, B2_GP_IO); |
| 243 | reg |= GLB_GPIO_STAT_RACE_DIS; |
| 244 | sky2_write32(hw, B2_GP_IO, reg); |
Stephen Hemminger | b234577 | 2007-08-21 14:34:02 -0700 | [diff] [blame] | 245 | |
| 246 | sky2_read32(hw, B2_GP_IO); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 247 | } |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 248 | } |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 249 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 250 | static void sky2_power_aux(struct sky2_hw *hw) |
| 251 | { |
| 252 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) |
| 253 | sky2_write8(hw, B2_Y2_CLK_GATE, 0); |
| 254 | else |
| 255 | /* enable bits are inverted */ |
| 256 | sky2_write8(hw, B2_Y2_CLK_GATE, |
| 257 | Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS | |
| 258 | Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS | |
| 259 | Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS); |
| 260 | |
| 261 | /* switch power to VAUX */ |
| 262 | if (sky2_read16(hw, B0_CTST) & Y2_VAUX_AVAIL) |
| 263 | sky2_write8(hw, B0_POWER_CTRL, |
| 264 | (PC_VAUX_ENA | PC_VCC_ENA | |
| 265 | PC_VAUX_ON | PC_VCC_OFF)); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 266 | } |
| 267 | |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 268 | static void sky2_gmac_reset(struct sky2_hw *hw, unsigned port) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 269 | { |
| 270 | u16 reg; |
| 271 | |
| 272 | /* disable all GMAC IRQ's */ |
| 273 | sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0); |
| 274 | /* disable PHY IRQs */ |
| 275 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 276 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 277 | gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */ |
| 278 | gma_write16(hw, port, GM_MC_ADDR_H2, 0); |
| 279 | gma_write16(hw, port, GM_MC_ADDR_H3, 0); |
| 280 | gma_write16(hw, port, GM_MC_ADDR_H4, 0); |
| 281 | |
| 282 | reg = gma_read16(hw, port, GM_RX_CTRL); |
| 283 | reg |= GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA; |
| 284 | gma_write16(hw, port, GM_RX_CTRL, reg); |
| 285 | } |
| 286 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 287 | /* flow control to advertise bits */ |
| 288 | static const u16 copper_fc_adv[] = { |
| 289 | [FC_NONE] = 0, |
| 290 | [FC_TX] = PHY_M_AN_ASP, |
| 291 | [FC_RX] = PHY_M_AN_PC, |
| 292 | [FC_BOTH] = PHY_M_AN_PC | PHY_M_AN_ASP, |
| 293 | }; |
| 294 | |
| 295 | /* flow control to advertise bits when using 1000BaseX */ |
| 296 | static const u16 fiber_fc_adv[] = { |
| 297 | [FC_BOTH] = PHY_M_P_BOTH_MD_X, |
| 298 | [FC_TX] = PHY_M_P_ASYM_MD_X, |
| 299 | [FC_RX] = PHY_M_P_SYM_MD_X, |
| 300 | [FC_NONE] = PHY_M_P_NO_PAUSE_X, |
| 301 | }; |
| 302 | |
| 303 | /* flow control to GMA disable bits */ |
| 304 | static const u16 gm_fc_disable[] = { |
| 305 | [FC_NONE] = GM_GPCR_FC_RX_DIS | GM_GPCR_FC_TX_DIS, |
| 306 | [FC_TX] = GM_GPCR_FC_RX_DIS, |
| 307 | [FC_RX] = GM_GPCR_FC_TX_DIS, |
| 308 | [FC_BOTH] = 0, |
| 309 | }; |
| 310 | |
| 311 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 312 | static void sky2_phy_init(struct sky2_hw *hw, unsigned port) |
| 313 | { |
| 314 | struct sky2_port *sky2 = netdev_priv(hw->dev[port]); |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 315 | u16 ctrl, ct1000, adv, pg, ledctrl, ledover, reg; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 316 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 317 | if (sky2->autoneg == AUTONEG_ENABLE && |
| 318 | !(hw->flags & SKY2_HW_NEWER_PHY)) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 319 | u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL); |
| 320 | |
| 321 | ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 322 | PHY_M_EC_MAC_S_MSK); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 323 | ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ); |
| 324 | |
Stephen Hemminger | 53419c6 | 2007-05-14 12:38:11 -0700 | [diff] [blame] | 325 | /* on PHY 88E1040 Rev.D0 (and newer) downshift control changed */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 326 | if (hw->chip_id == CHIP_ID_YUKON_EC) |
Stephen Hemminger | 53419c6 | 2007-05-14 12:38:11 -0700 | [diff] [blame] | 327 | /* set downshift counter to 3x and enable downshift */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 328 | ectrl |= PHY_M_EC_DSC_2(2) | PHY_M_EC_DOWN_S_ENA; |
| 329 | else |
Stephen Hemminger | 53419c6 | 2007-05-14 12:38:11 -0700 | [diff] [blame] | 330 | /* set master & slave downshift counter to 1x */ |
| 331 | ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 332 | |
| 333 | gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl); |
| 334 | } |
| 335 | |
| 336 | ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 337 | if (sky2_is_copper(hw)) { |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 338 | if (!(hw->flags & SKY2_HW_GIGABIT)) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 339 | /* enable automatic crossover */ |
| 340 | ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO) >> 1; |
Stephen Hemminger | 6d3105d | 2007-09-24 19:34:51 -0700 | [diff] [blame] | 341 | |
| 342 | if (hw->chip_id == CHIP_ID_YUKON_FE_P && |
| 343 | hw->chip_rev == CHIP_REV_YU_FE2_A0) { |
| 344 | u16 spec; |
| 345 | |
| 346 | /* Enable Class A driver for FE+ A0 */ |
| 347 | spec = gm_phy_read(hw, port, PHY_MARV_FE_SPEC_2); |
| 348 | spec |= PHY_M_FESC_SEL_CL_A; |
| 349 | gm_phy_write(hw, port, PHY_MARV_FE_SPEC_2, spec); |
| 350 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 351 | } else { |
| 352 | /* disable energy detect */ |
| 353 | ctrl &= ~PHY_M_PC_EN_DET_MSK; |
| 354 | |
| 355 | /* enable automatic crossover */ |
| 356 | ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO); |
| 357 | |
Stephen Hemminger | 53419c6 | 2007-05-14 12:38:11 -0700 | [diff] [blame] | 358 | /* downshift on PHY 88E1112 and 88E1149 is changed */ |
Stephen Hemminger | 9374549 | 2007-02-06 10:45:43 -0800 | [diff] [blame] | 359 | if (sky2->autoneg == AUTONEG_ENABLE |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 360 | && (hw->flags & SKY2_HW_NEWER_PHY)) { |
Stephen Hemminger | 53419c6 | 2007-05-14 12:38:11 -0700 | [diff] [blame] | 361 | /* set downshift counter to 3x and enable downshift */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 362 | ctrl &= ~PHY_M_PC_DSC_MSK; |
| 363 | ctrl |= PHY_M_PC_DSC(2) | PHY_M_PC_DOWN_S_ENA; |
| 364 | } |
| 365 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 366 | } else { |
| 367 | /* workaround for deviation #4.88 (CRC errors) */ |
| 368 | /* disable Automatic Crossover */ |
| 369 | |
| 370 | ctrl &= ~PHY_M_PC_MDIX_MSK; |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); |
| 374 | |
| 375 | /* special setup for PHY 88E1112 Fiber */ |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 376 | if (hw->chip_id == CHIP_ID_YUKON_XL && (hw->flags & SKY2_HW_FIBRE_PHY)) { |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 377 | pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); |
| 378 | |
| 379 | /* Fiber: select 1000BASE-X only mode MAC Specific Ctrl Reg. */ |
| 380 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2); |
| 381 | ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); |
| 382 | ctrl &= ~PHY_M_MAC_MD_MSK; |
| 383 | ctrl |= PHY_M_MAC_MODE_SEL(PHY_M_MAC_MD_1000BX); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 384 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); |
| 385 | |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 386 | if (hw->pmd_type == 'P') { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 387 | /* select page 1 to access Fiber registers */ |
| 388 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 1); |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 389 | |
| 390 | /* for SFP-module set SIGDET polarity to low */ |
| 391 | ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); |
| 392 | ctrl |= PHY_M_FIB_SIGD_POL; |
Stephen Hemminger | 34dd962 | 2007-05-24 15:22:45 -0700 | [diff] [blame] | 393 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 394 | } |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 395 | |
| 396 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Stephen Hemminger | 7800fdd | 2006-10-17 10:24:10 -0700 | [diff] [blame] | 399 | ctrl = PHY_CT_RESET; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 400 | ct1000 = 0; |
| 401 | adv = PHY_AN_CSMA; |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 402 | reg = 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 403 | |
| 404 | if (sky2->autoneg == AUTONEG_ENABLE) { |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 405 | if (sky2_is_copper(hw)) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 406 | if (sky2->advertising & ADVERTISED_1000baseT_Full) |
| 407 | ct1000 |= PHY_M_1000C_AFD; |
| 408 | if (sky2->advertising & ADVERTISED_1000baseT_Half) |
| 409 | ct1000 |= PHY_M_1000C_AHD; |
| 410 | if (sky2->advertising & ADVERTISED_100baseT_Full) |
| 411 | adv |= PHY_M_AN_100_FD; |
| 412 | if (sky2->advertising & ADVERTISED_100baseT_Half) |
| 413 | adv |= PHY_M_AN_100_HD; |
| 414 | if (sky2->advertising & ADVERTISED_10baseT_Full) |
| 415 | adv |= PHY_M_AN_10_FD; |
| 416 | if (sky2->advertising & ADVERTISED_10baseT_Half) |
| 417 | adv |= PHY_M_AN_10_HD; |
Stephen Hemminger | 709c6e7 | 2006-10-17 10:24:04 -0700 | [diff] [blame] | 418 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 419 | adv |= copper_fc_adv[sky2->flow_mode]; |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 420 | } else { /* special defines for FIBER (88E1040S only) */ |
| 421 | if (sky2->advertising & ADVERTISED_1000baseT_Full) |
| 422 | adv |= PHY_M_AN_1000X_AFD; |
| 423 | if (sky2->advertising & ADVERTISED_1000baseT_Half) |
| 424 | adv |= PHY_M_AN_1000X_AHD; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 425 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 426 | adv |= fiber_fc_adv[sky2->flow_mode]; |
Stephen Hemminger | 709c6e7 | 2006-10-17 10:24:04 -0700 | [diff] [blame] | 427 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 428 | |
| 429 | /* Restart Auto-negotiation */ |
| 430 | ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG; |
| 431 | } else { |
| 432 | /* forced speed/duplex settings */ |
| 433 | ct1000 = PHY_M_1000C_MSE; |
| 434 | |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 435 | /* Disable auto update for duplex flow control and speed */ |
| 436 | reg |= GM_GPCR_AU_ALL_DIS; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 437 | |
| 438 | switch (sky2->speed) { |
| 439 | case SPEED_1000: |
| 440 | ctrl |= PHY_CT_SP1000; |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 441 | reg |= GM_GPCR_SPEED_1000; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 442 | break; |
| 443 | case SPEED_100: |
| 444 | ctrl |= PHY_CT_SP100; |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 445 | reg |= GM_GPCR_SPEED_100; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 446 | break; |
| 447 | } |
| 448 | |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 449 | if (sky2->duplex == DUPLEX_FULL) { |
| 450 | reg |= GM_GPCR_DUP_FULL; |
| 451 | ctrl |= PHY_CT_DUP_MD; |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 452 | } else if (sky2->speed < SPEED_1000) |
| 453 | sky2->flow_mode = FC_NONE; |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 454 | |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 455 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 456 | reg |= gm_fc_disable[sky2->flow_mode]; |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 457 | |
| 458 | /* Forward pause packets to GMAC? */ |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 459 | if (sky2->flow_mode & FC_RX) |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 460 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON); |
| 461 | else |
| 462 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 465 | gma_write16(hw, port, GM_GP_CTRL, reg); |
| 466 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 467 | if (hw->flags & SKY2_HW_GIGABIT) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 468 | gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000); |
| 469 | |
| 470 | gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv); |
| 471 | gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); |
| 472 | |
| 473 | /* Setup Phy LED's */ |
| 474 | ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS); |
| 475 | ledover = 0; |
| 476 | |
| 477 | switch (hw->chip_id) { |
| 478 | case CHIP_ID_YUKON_FE: |
| 479 | /* on 88E3082 these bits are at 11..9 (shifted left) */ |
| 480 | ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) << 1; |
| 481 | |
| 482 | ctrl = gm_phy_read(hw, port, PHY_MARV_FE_LED_PAR); |
| 483 | |
| 484 | /* delete ACT LED control bits */ |
| 485 | ctrl &= ~PHY_M_FELP_LED1_MSK; |
| 486 | /* change ACT LED control to blink mode */ |
| 487 | ctrl |= PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_ACT_BL); |
| 488 | gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl); |
| 489 | break; |
| 490 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 491 | case CHIP_ID_YUKON_FE_P: |
| 492 | /* Enable Link Partner Next Page */ |
| 493 | ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); |
| 494 | ctrl |= PHY_M_PC_ENA_LIP_NP; |
| 495 | |
| 496 | /* disable Energy Detect and enable scrambler */ |
| 497 | ctrl &= ~(PHY_M_PC_ENA_ENE_DT | PHY_M_PC_DIS_SCRAMB); |
| 498 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); |
| 499 | |
| 500 | /* set LED2 -> ACT, LED1 -> LINK, LED0 -> SPEED */ |
| 501 | ctrl = PHY_M_FELP_LED2_CTRL(LED_PAR_CTRL_ACT_BL) | |
| 502 | PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_LINK) | |
| 503 | PHY_M_FELP_LED0_CTRL(LED_PAR_CTRL_SPEED); |
| 504 | |
| 505 | gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl); |
| 506 | break; |
| 507 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 508 | case CHIP_ID_YUKON_XL: |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 509 | pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 510 | |
| 511 | /* select page 3 to access LED control register */ |
| 512 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); |
| 513 | |
| 514 | /* set LED Function Control register */ |
Stephen Hemminger | ed6d32c | 2006-05-08 15:11:33 -0700 | [diff] [blame] | 515 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, |
| 516 | (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */ |
| 517 | PHY_M_LEDC_INIT_CTRL(7) | /* 10 Mbps */ |
| 518 | PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */ |
| 519 | PHY_M_LEDC_STA0_CTRL(7))); /* 1000 Mbps */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 520 | |
| 521 | /* set Polarity Control register */ |
| 522 | gm_phy_write(hw, port, PHY_MARV_PHY_STAT, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 523 | (PHY_M_POLC_LS1_P_MIX(4) | |
| 524 | PHY_M_POLC_IS0_P_MIX(4) | |
| 525 | PHY_M_POLC_LOS_CTRL(2) | |
| 526 | PHY_M_POLC_INIT_CTRL(2) | |
| 527 | PHY_M_POLC_STA1_CTRL(2) | |
| 528 | PHY_M_POLC_STA0_CTRL(2))); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 529 | |
| 530 | /* restore page register */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 531 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 532 | break; |
Stephen Hemminger | 9374549 | 2007-02-06 10:45:43 -0800 | [diff] [blame] | 533 | |
Stephen Hemminger | ed6d32c | 2006-05-08 15:11:33 -0700 | [diff] [blame] | 534 | case CHIP_ID_YUKON_EC_U: |
Stephen Hemminger | 9374549 | 2007-02-06 10:45:43 -0800 | [diff] [blame] | 535 | case CHIP_ID_YUKON_EX: |
Stephen Hemminger | ed6d32c | 2006-05-08 15:11:33 -0700 | [diff] [blame] | 536 | pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); |
| 537 | |
| 538 | /* select page 3 to access LED control register */ |
| 539 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); |
| 540 | |
| 541 | /* set LED Function Control register */ |
| 542 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, |
| 543 | (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */ |
| 544 | PHY_M_LEDC_INIT_CTRL(8) | /* 10 Mbps */ |
| 545 | PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */ |
| 546 | PHY_M_LEDC_STA0_CTRL(7)));/* 1000 Mbps */ |
| 547 | |
| 548 | /* set Blink Rate in LED Timer Control Register */ |
| 549 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, |
| 550 | ledctrl | PHY_M_LED_BLINK_RT(BLINK_84MS)); |
| 551 | /* restore page register */ |
| 552 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); |
| 553 | break; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 554 | |
| 555 | default: |
| 556 | /* set Tx LED (LED_TX) to blink mode on Rx OR Tx activity */ |
| 557 | ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL; |
| 558 | /* turn off the Rx LED (LED_RX) */ |
Stephen Hemminger | 0efdf26 | 2006-12-05 12:03:41 -0800 | [diff] [blame] | 559 | ledover &= ~PHY_M_LED_MO_RX; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Stephen Hemminger | 9467a8f | 2007-04-07 16:02:28 -0700 | [diff] [blame] | 562 | if (hw->chip_id == CHIP_ID_YUKON_EC_U && |
| 563 | hw->chip_rev == CHIP_REV_YU_EC_U_A1) { |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 564 | /* apply fixes in PHY AFE */ |
Stephen Hemminger | ed6d32c | 2006-05-08 15:11:33 -0700 | [diff] [blame] | 565 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 255); |
| 566 | |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 567 | /* increase differential signal amplitude in 10BASE-T */ |
Stephen Hemminger | ed6d32c | 2006-05-08 15:11:33 -0700 | [diff] [blame] | 568 | gm_phy_write(hw, port, 0x18, 0xaa99); |
| 569 | gm_phy_write(hw, port, 0x17, 0x2011); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 570 | |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 571 | /* fix for IEEE A/B Symmetry failure in 1000BASE-T */ |
Stephen Hemminger | ed6d32c | 2006-05-08 15:11:33 -0700 | [diff] [blame] | 572 | gm_phy_write(hw, port, 0x18, 0xa204); |
| 573 | gm_phy_write(hw, port, 0x17, 0x2002); |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 574 | |
| 575 | /* set page register to 0 */ |
Stephen Hemminger | 9467a8f | 2007-04-07 16:02:28 -0700 | [diff] [blame] | 576 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0); |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 577 | } else if (hw->chip_id == CHIP_ID_YUKON_FE_P && |
| 578 | hw->chip_rev == CHIP_REV_YU_FE2_A0) { |
| 579 | /* apply workaround for integrated resistors calibration */ |
| 580 | gm_phy_write(hw, port, PHY_MARV_PAGE_ADDR, 17); |
| 581 | gm_phy_write(hw, port, PHY_MARV_PAGE_DATA, 0x3f60); |
Stephen Hemminger | 9374549 | 2007-02-06 10:45:43 -0800 | [diff] [blame] | 582 | } else if (hw->chip_id != CHIP_ID_YUKON_EX) { |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 583 | /* no effect on Yukon-XL */ |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 584 | gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl); |
| 585 | |
| 586 | if (sky2->autoneg == AUTONEG_DISABLE || sky2->speed == SPEED_100) { |
| 587 | /* turn on 100 Mbps LED (LED_LINK100) */ |
Stephen Hemminger | 0efdf26 | 2006-12-05 12:03:41 -0800 | [diff] [blame] | 588 | ledover |= PHY_M_LED_MO_100; |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | if (ledover) |
| 592 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover); |
| 593 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 594 | } |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 595 | |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 596 | /* Enable phy interrupt on auto-negotiation complete (or link up) */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 597 | if (sky2->autoneg == AUTONEG_ENABLE) |
| 598 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL); |
| 599 | else |
| 600 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); |
| 601 | } |
| 602 | |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 603 | static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff) |
| 604 | { |
| 605 | u32 reg1; |
| 606 | static const u32 phy_power[] |
| 607 | = { PCI_Y2_PHY1_POWD, PCI_Y2_PHY2_POWD }; |
| 608 | |
| 609 | /* looks like this XL is back asswards .. */ |
| 610 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) |
| 611 | onoff = !onoff; |
| 612 | |
Stephen Hemminger | aed2cec | 2006-12-20 13:06:35 -0800 | [diff] [blame] | 613 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 614 | reg1 = sky2_pci_read32(hw, PCI_DEV_REG1); |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 615 | if (onoff) |
| 616 | /* Turn off phy power saving */ |
| 617 | reg1 &= ~phy_power[port]; |
| 618 | else |
| 619 | reg1 |= phy_power[port]; |
| 620 | |
| 621 | sky2_pci_write32(hw, PCI_DEV_REG1, reg1); |
shemminger@osdl.org | 98232f8 | 2006-08-28 10:00:52 -0700 | [diff] [blame] | 622 | sky2_pci_read32(hw, PCI_DEV_REG1); |
Stephen Hemminger | aed2cec | 2006-12-20 13:06:35 -0800 | [diff] [blame] | 623 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 624 | udelay(100); |
| 625 | } |
| 626 | |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 627 | /* Force a renegotiation */ |
| 628 | static void sky2_phy_reinit(struct sky2_port *sky2) |
| 629 | { |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 630 | spin_lock_bh(&sky2->phy_lock); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 631 | sky2_phy_init(sky2->hw, sky2->port); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 632 | spin_unlock_bh(&sky2->phy_lock); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 633 | } |
| 634 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 635 | /* Put device in state to listen for Wake On Lan */ |
| 636 | static void sky2_wol_init(struct sky2_port *sky2) |
| 637 | { |
| 638 | struct sky2_hw *hw = sky2->hw; |
| 639 | unsigned port = sky2->port; |
| 640 | enum flow_control save_mode; |
| 641 | u16 ctrl; |
| 642 | u32 reg1; |
| 643 | |
| 644 | /* Bring hardware out of reset */ |
| 645 | sky2_write16(hw, B0_CTST, CS_RST_CLR); |
| 646 | sky2_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR); |
| 647 | |
| 648 | sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR); |
| 649 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR); |
| 650 | |
| 651 | /* Force to 10/100 |
| 652 | * sky2_reset will re-enable on resume |
| 653 | */ |
| 654 | save_mode = sky2->flow_mode; |
| 655 | ctrl = sky2->advertising; |
| 656 | |
| 657 | sky2->advertising &= ~(ADVERTISED_1000baseT_Half|ADVERTISED_1000baseT_Full); |
| 658 | sky2->flow_mode = FC_NONE; |
| 659 | sky2_phy_power(hw, port, 1); |
| 660 | sky2_phy_reinit(sky2); |
| 661 | |
| 662 | sky2->flow_mode = save_mode; |
| 663 | sky2->advertising = ctrl; |
| 664 | |
| 665 | /* Set GMAC to no flow control and auto update for speed/duplex */ |
| 666 | gma_write16(hw, port, GM_GP_CTRL, |
| 667 | GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA| |
| 668 | GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS); |
| 669 | |
| 670 | /* Set WOL address */ |
| 671 | memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR), |
| 672 | sky2->netdev->dev_addr, ETH_ALEN); |
| 673 | |
| 674 | /* Turn on appropriate WOL control bits */ |
| 675 | sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT); |
| 676 | ctrl = 0; |
| 677 | if (sky2->wol & WAKE_PHY) |
| 678 | ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT; |
| 679 | else |
| 680 | ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT; |
| 681 | |
| 682 | if (sky2->wol & WAKE_MAGIC) |
| 683 | ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT; |
| 684 | else |
| 685 | ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT;; |
| 686 | |
| 687 | ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT; |
| 688 | sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl); |
| 689 | |
| 690 | /* Turn on legacy PCI-Express PME mode */ |
| 691 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
| 692 | reg1 = sky2_pci_read32(hw, PCI_DEV_REG1); |
| 693 | reg1 |= PCI_Y2_PME_LEGACY; |
| 694 | sky2_pci_write32(hw, PCI_DEV_REG1, reg1); |
| 695 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
| 696 | |
| 697 | /* block receiver */ |
| 698 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); |
| 699 | |
| 700 | } |
| 701 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 702 | static void sky2_set_tx_stfwd(struct sky2_hw *hw, unsigned port) |
| 703 | { |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 704 | struct net_device *dev = hw->dev[port]; |
| 705 | |
| 706 | if (dev->mtu <= ETH_DATA_LEN) |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 707 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 708 | TX_JUMBO_DIS | TX_STFW_ENA); |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 709 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 710 | else if (hw->chip_id != CHIP_ID_YUKON_EC_U) |
| 711 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), |
| 712 | TX_STFW_ENA | TX_JUMBO_ENA); |
| 713 | else { |
| 714 | /* set Tx GMAC FIFO Almost Empty Threshold */ |
| 715 | sky2_write32(hw, SK_REG(port, TX_GMF_AE_THR), |
| 716 | (ECU_JUMBO_WM << 16) | ECU_AE_THR); |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 717 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 718 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), |
| 719 | TX_JUMBO_ENA | TX_STFW_DIS); |
| 720 | |
| 721 | /* Can't do offload because of lack of store/forward */ |
| 722 | dev->features &= ~(NETIF_F_TSO | NETIF_F_SG | NETIF_F_ALL_CSUM); |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 726 | static void sky2_mac_init(struct sky2_hw *hw, unsigned port) |
| 727 | { |
| 728 | struct sky2_port *sky2 = netdev_priv(hw->dev[port]); |
| 729 | u16 reg; |
Al Viro | 25cccec | 2007-07-20 16:07:33 +0100 | [diff] [blame] | 730 | u32 rx_reg; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 731 | int i; |
| 732 | const u8 *addr = hw->dev[port]->dev_addr; |
| 733 | |
Stephen Hemminger | f350339 | 2007-08-21 11:10:22 -0700 | [diff] [blame] | 734 | sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET); |
| 735 | sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 736 | |
| 737 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR); |
| 738 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 739 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0 && port == 1) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 740 | /* WA DEV_472 -- looks like crossed wires on port 2 */ |
| 741 | /* clear GMAC 1 Control reset */ |
| 742 | sky2_write8(hw, SK_REG(0, GMAC_CTRL), GMC_RST_CLR); |
| 743 | do { |
| 744 | sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_SET); |
| 745 | sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_CLR); |
| 746 | } while (gm_phy_read(hw, 1, PHY_MARV_ID0) != PHY_MARV_ID0_VAL || |
| 747 | gm_phy_read(hw, 1, PHY_MARV_ID1) != PHY_MARV_ID1_Y2 || |
| 748 | gm_phy_read(hw, 1, PHY_MARV_INT_MASK) != 0); |
| 749 | } |
| 750 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 751 | sky2_read16(hw, SK_REG(port, GMAC_IRQ_SRC)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 752 | |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 753 | /* Enable Transmit FIFO Underrun */ |
| 754 | sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK); |
| 755 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 756 | spin_lock_bh(&sky2->phy_lock); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 757 | sky2_phy_init(hw, port); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 758 | spin_unlock_bh(&sky2->phy_lock); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 759 | |
| 760 | /* MIB clear */ |
| 761 | reg = gma_read16(hw, port, GM_PHY_ADDR); |
| 762 | gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR); |
| 763 | |
Stephen Hemminger | 43f2f10 | 2006-04-05 17:47:15 -0700 | [diff] [blame] | 764 | for (i = GM_MIB_CNT_BASE; i <= GM_MIB_CNT_END; i += 4) |
| 765 | gma_read16(hw, port, i); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 766 | gma_write16(hw, port, GM_PHY_ADDR, reg); |
| 767 | |
| 768 | /* transmit control */ |
| 769 | gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF)); |
| 770 | |
| 771 | /* receive control reg: unicast + multicast + no FCS */ |
| 772 | gma_write16(hw, port, GM_RX_CTRL, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 773 | GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 774 | |
| 775 | /* transmit flow control */ |
| 776 | gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff); |
| 777 | |
| 778 | /* transmit parameter */ |
| 779 | gma_write16(hw, port, GM_TX_PARAM, |
| 780 | TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) | |
| 781 | TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) | |
| 782 | TX_IPG_JAM_DATA(TX_IPG_JAM_DEF) | |
| 783 | TX_BACK_OFF_LIM(TX_BOF_LIM_DEF)); |
| 784 | |
| 785 | /* serial mode register */ |
| 786 | reg = DATA_BLIND_VAL(DATA_BLIND_DEF) | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 787 | GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 788 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 789 | if (hw->dev[port]->mtu > ETH_DATA_LEN) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 790 | reg |= GM_SMOD_JUMBO_ENA; |
| 791 | |
| 792 | gma_write16(hw, port, GM_SERIAL_MODE, reg); |
| 793 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 794 | /* virtual address for data */ |
| 795 | gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr); |
| 796 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 797 | /* physical address: used for pause frames */ |
| 798 | gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr); |
| 799 | |
| 800 | /* ignore counter overflows */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 801 | gma_write16(hw, port, GM_TX_IRQ_MSK, 0); |
| 802 | gma_write16(hw, port, GM_RX_IRQ_MSK, 0); |
| 803 | gma_write16(hw, port, GM_TR_IRQ_MSK, 0); |
| 804 | |
| 805 | /* Configure Rx MAC FIFO */ |
| 806 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR); |
Al Viro | 25cccec | 2007-07-20 16:07:33 +0100 | [diff] [blame] | 807 | rx_reg = GMF_OPER_ON | GMF_RX_F_FL_ON; |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 808 | if (hw->chip_id == CHIP_ID_YUKON_EX || |
| 809 | hw->chip_id == CHIP_ID_YUKON_FE_P) |
Al Viro | 25cccec | 2007-07-20 16:07:33 +0100 | [diff] [blame] | 810 | rx_reg |= GMF_RX_OVER_ON; |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 811 | |
Al Viro | 25cccec | 2007-07-20 16:07:33 +0100 | [diff] [blame] | 812 | sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), rx_reg); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 813 | |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 814 | /* Flush Rx MAC FIFO on any flow control or error */ |
shemminger@osdl.org | 42eeea0 | 2005-11-30 11:45:13 -0800 | [diff] [blame] | 815 | sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 816 | |
Stephen Hemminger | 8df9a87 | 2006-12-01 14:29:35 -0800 | [diff] [blame] | 817 | /* Set threshold to 0xa (64 bytes) + 1 to workaround pause bug */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 818 | reg = RX_GMF_FL_THR_DEF + 1; |
| 819 | /* Another magic mystery workaround from sk98lin */ |
| 820 | if (hw->chip_id == CHIP_ID_YUKON_FE_P && |
| 821 | hw->chip_rev == CHIP_REV_YU_FE2_A0) |
| 822 | reg = 0x178; |
| 823 | sky2_write16(hw, SK_REG(port, RX_GMF_FL_THR), reg); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 824 | |
| 825 | /* Configure Tx MAC FIFO */ |
| 826 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR); |
| 827 | sky2_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON); |
shemminger@osdl.org | 5a5b1ea | 2005-11-30 11:45:15 -0800 | [diff] [blame] | 828 | |
Stephen Hemminger | e0c2811 | 2007-09-20 13:03:49 -0700 | [diff] [blame^] | 829 | /* On chips without ram buffer, pause is controled by MAC level */ |
| 830 | if (sky2_read8(hw, B2_E_0) == 0) { |
Stephen Hemminger | 8df9a87 | 2006-12-01 14:29:35 -0800 | [diff] [blame] | 831 | sky2_write8(hw, SK_REG(port, RX_GMF_LP_THR), 768/8); |
shemminger@osdl.org | 5a5b1ea | 2005-11-30 11:45:15 -0800 | [diff] [blame] | 832 | sky2_write8(hw, SK_REG(port, RX_GMF_UP_THR), 1024/8); |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 833 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 834 | sky2_set_tx_stfwd(hw, port); |
shemminger@osdl.org | 5a5b1ea | 2005-11-30 11:45:15 -0800 | [diff] [blame] | 835 | } |
| 836 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Stephen Hemminger | 6771290 | 2006-12-04 15:53:45 -0800 | [diff] [blame] | 839 | /* Assign Ram Buffer allocation to queue */ |
| 840 | static void sky2_ramset(struct sky2_hw *hw, u16 q, u32 start, u32 space) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 841 | { |
Stephen Hemminger | 6771290 | 2006-12-04 15:53:45 -0800 | [diff] [blame] | 842 | u32 end; |
| 843 | |
| 844 | /* convert from K bytes to qwords used for hw register */ |
| 845 | start *= 1024/8; |
| 846 | space *= 1024/8; |
| 847 | end = start + space - 1; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 848 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 849 | sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR); |
| 850 | sky2_write32(hw, RB_ADDR(q, RB_START), start); |
| 851 | sky2_write32(hw, RB_ADDR(q, RB_END), end); |
| 852 | sky2_write32(hw, RB_ADDR(q, RB_WP), start); |
| 853 | sky2_write32(hw, RB_ADDR(q, RB_RP), start); |
| 854 | |
| 855 | if (q == Q_R1 || q == Q_R2) { |
Stephen Hemminger | 1c28f6b | 2006-01-17 13:43:13 -0800 | [diff] [blame] | 856 | u32 tp = space - space/4; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 857 | |
Stephen Hemminger | 1c28f6b | 2006-01-17 13:43:13 -0800 | [diff] [blame] | 858 | /* On receive queue's set the thresholds |
| 859 | * give receiver priority when > 3/4 full |
| 860 | * send pause when down to 2K |
| 861 | */ |
| 862 | sky2_write32(hw, RB_ADDR(q, RB_RX_UTHP), tp); |
| 863 | sky2_write32(hw, RB_ADDR(q, RB_RX_LTHP), space/2); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 864 | |
Stephen Hemminger | 1c28f6b | 2006-01-17 13:43:13 -0800 | [diff] [blame] | 865 | tp = space - 2048/8; |
| 866 | sky2_write32(hw, RB_ADDR(q, RB_RX_UTPP), tp); |
| 867 | sky2_write32(hw, RB_ADDR(q, RB_RX_LTPP), space/4); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 868 | } else { |
| 869 | /* Enable store & forward on Tx queue's because |
| 870 | * Tx FIFO is only 1K on Yukon |
| 871 | */ |
| 872 | sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD); |
| 873 | } |
| 874 | |
| 875 | sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 876 | sky2_read8(hw, RB_ADDR(q, RB_CTRL)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 879 | /* Setup Bus Memory Interface */ |
shemminger@osdl.org | af4ed7e | 2005-11-30 11:45:21 -0800 | [diff] [blame] | 880 | static void sky2_qset(struct sky2_hw *hw, u16 q) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 881 | { |
| 882 | sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_RESET); |
| 883 | sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_OPER_INIT); |
| 884 | sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_FIFO_OP_ON); |
shemminger@osdl.org | af4ed7e | 2005-11-30 11:45:21 -0800 | [diff] [blame] | 885 | sky2_write32(hw, Q_ADDR(q, Q_WM), BMU_WM_DEFAULT); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 888 | /* Setup prefetch unit registers. This is the interface between |
| 889 | * hardware and driver list elements |
| 890 | */ |
Stephen Hemminger | 8cc048e | 2005-12-09 11:35:07 -0800 | [diff] [blame] | 891 | static void sky2_prefetch_init(struct sky2_hw *hw, u32 qaddr, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 892 | u64 addr, u32 last) |
| 893 | { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 894 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_SET); |
| 895 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_CLR); |
| 896 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_HI), addr >> 32); |
| 897 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_LO), (u32) addr); |
| 898 | sky2_write16(hw, Y2_QADDR(qaddr, PREF_UNIT_LAST_IDX), last); |
| 899 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_OP_ON); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 900 | |
| 901 | sky2_read32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 904 | static inline struct sky2_tx_le *get_tx_le(struct sky2_port *sky2) |
| 905 | { |
| 906 | struct sky2_tx_le *le = sky2->tx_le + sky2->tx_prod; |
| 907 | |
Stephen Hemminger | cb5d954 | 2006-05-08 15:11:29 -0700 | [diff] [blame] | 908 | sky2->tx_prod = RING_NEXT(sky2->tx_prod, TX_RING_SIZE); |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 909 | le->ctrl = 0; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 910 | return le; |
| 911 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 912 | |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 913 | static inline struct tx_ring_info *tx_le_re(struct sky2_port *sky2, |
| 914 | struct sky2_tx_le *le) |
| 915 | { |
| 916 | return sky2->tx_ring + (le - sky2->tx_le); |
| 917 | } |
| 918 | |
Stephen Hemminger | 290d4de | 2006-03-20 15:48:15 -0800 | [diff] [blame] | 919 | /* Update chip's next pointer */ |
| 920 | static inline void sky2_put_idx(struct sky2_hw *hw, unsigned q, u16 idx) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 921 | { |
Stephen Hemminger | 50432cb | 2007-05-14 12:38:15 -0700 | [diff] [blame] | 922 | /* Make sure write' to descriptors are complete before we tell hardware */ |
Stephen Hemminger | 762c2de | 2006-01-17 13:43:14 -0800 | [diff] [blame] | 923 | wmb(); |
Stephen Hemminger | 50432cb | 2007-05-14 12:38:15 -0700 | [diff] [blame] | 924 | sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), idx); |
| 925 | |
| 926 | /* Synchronize I/O on since next processor may write to tail */ |
| 927 | mmiowb(); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 930 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 931 | static inline struct sky2_rx_le *sky2_next_rx(struct sky2_port *sky2) |
| 932 | { |
| 933 | struct sky2_rx_le *le = sky2->rx_le + sky2->rx_put; |
Stephen Hemminger | cb5d954 | 2006-05-08 15:11:29 -0700 | [diff] [blame] | 934 | sky2->rx_put = RING_NEXT(sky2->rx_put, RX_LE_SIZE); |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 935 | le->ctrl = 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 936 | return le; |
| 937 | } |
| 938 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 939 | /* Build description to hardware for one receive segment */ |
| 940 | static void sky2_rx_add(struct sky2_port *sky2, u8 op, |
| 941 | dma_addr_t map, unsigned len) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 942 | { |
| 943 | struct sky2_rx_le *le; |
Stephen Hemminger | 36eb0c7 | 2007-07-09 15:33:42 -0700 | [diff] [blame] | 944 | u32 hi = upper_32_bits(map); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 945 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 946 | if (sky2->rx_addr64 != hi) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 947 | le = sky2_next_rx(sky2); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 948 | le->addr = cpu_to_le32(hi); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 949 | le->opcode = OP_ADDR64 | HW_OWNER; |
Stephen Hemminger | 36eb0c7 | 2007-07-09 15:33:42 -0700 | [diff] [blame] | 950 | sky2->rx_addr64 = upper_32_bits(map + len); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 951 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 952 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 953 | le = sky2_next_rx(sky2); |
Stephen Hemminger | 734d186 | 2005-12-09 11:35:00 -0800 | [diff] [blame] | 954 | le->addr = cpu_to_le32((u32) map); |
| 955 | le->length = cpu_to_le16(len); |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 956 | le->opcode = op | HW_OWNER; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 957 | } |
| 958 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 959 | /* Build description to hardware for one possibly fragmented skb */ |
| 960 | static void sky2_rx_submit(struct sky2_port *sky2, |
| 961 | const struct rx_ring_info *re) |
| 962 | { |
| 963 | int i; |
| 964 | |
| 965 | sky2_rx_add(sky2, OP_PACKET, re->data_addr, sky2->rx_data_size); |
| 966 | |
| 967 | for (i = 0; i < skb_shinfo(re->skb)->nr_frags; i++) |
| 968 | sky2_rx_add(sky2, OP_BUFFER, re->frag_addr[i], PAGE_SIZE); |
| 969 | } |
| 970 | |
| 971 | |
| 972 | static void sky2_rx_map_skb(struct pci_dev *pdev, struct rx_ring_info *re, |
| 973 | unsigned size) |
| 974 | { |
| 975 | struct sk_buff *skb = re->skb; |
| 976 | int i; |
| 977 | |
| 978 | re->data_addr = pci_map_single(pdev, skb->data, size, PCI_DMA_FROMDEVICE); |
| 979 | pci_unmap_len_set(re, data_size, size); |
| 980 | |
| 981 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) |
| 982 | re->frag_addr[i] = pci_map_page(pdev, |
| 983 | skb_shinfo(skb)->frags[i].page, |
| 984 | skb_shinfo(skb)->frags[i].page_offset, |
| 985 | skb_shinfo(skb)->frags[i].size, |
| 986 | PCI_DMA_FROMDEVICE); |
| 987 | } |
| 988 | |
| 989 | static void sky2_rx_unmap_skb(struct pci_dev *pdev, struct rx_ring_info *re) |
| 990 | { |
| 991 | struct sk_buff *skb = re->skb; |
| 992 | int i; |
| 993 | |
| 994 | pci_unmap_single(pdev, re->data_addr, pci_unmap_len(re, data_size), |
| 995 | PCI_DMA_FROMDEVICE); |
| 996 | |
| 997 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) |
| 998 | pci_unmap_page(pdev, re->frag_addr[i], |
| 999 | skb_shinfo(skb)->frags[i].size, |
| 1000 | PCI_DMA_FROMDEVICE); |
| 1001 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1002 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1003 | /* Tell chip where to start receive checksum. |
| 1004 | * Actually has two checksums, but set both same to avoid possible byte |
| 1005 | * order problems. |
| 1006 | */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1007 | static void rx_set_checksum(struct sky2_port *sky2) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1008 | { |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1009 | struct sky2_rx_le *le = sky2_next_rx(sky2); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1010 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1011 | le->addr = cpu_to_le32((ETH_HLEN << 16) | ETH_HLEN); |
| 1012 | le->ctrl = 0; |
| 1013 | le->opcode = OP_TCPSTART | HW_OWNER; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1014 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1015 | sky2_write32(sky2->hw, |
| 1016 | Q_ADDR(rxqaddr[sky2->port], Q_CSR), |
| 1017 | sky2->rx_csum ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1020 | /* |
| 1021 | * The RX Stop command will not work for Yukon-2 if the BMU does not |
| 1022 | * reach the end of packet and since we can't make sure that we have |
| 1023 | * incoming data, we must reset the BMU while it is not doing a DMA |
| 1024 | * transfer. Since it is possible that the RX path is still active, |
| 1025 | * the RX RAM buffer will be stopped first, so any possible incoming |
| 1026 | * data will not trigger a DMA. After the RAM buffer is stopped, the |
| 1027 | * BMU is polled until any DMA in progress is ended and only then it |
| 1028 | * will be reset. |
| 1029 | */ |
| 1030 | static void sky2_rx_stop(struct sky2_port *sky2) |
| 1031 | { |
| 1032 | struct sky2_hw *hw = sky2->hw; |
| 1033 | unsigned rxq = rxqaddr[sky2->port]; |
| 1034 | int i; |
| 1035 | |
| 1036 | /* disable the RAM Buffer receive queue */ |
| 1037 | sky2_write8(hw, RB_ADDR(rxq, RB_CTRL), RB_DIS_OP_MD); |
| 1038 | |
| 1039 | for (i = 0; i < 0xffff; i++) |
| 1040 | if (sky2_read8(hw, RB_ADDR(rxq, Q_RSL)) |
| 1041 | == sky2_read8(hw, RB_ADDR(rxq, Q_RL))) |
| 1042 | goto stopped; |
| 1043 | |
| 1044 | printk(KERN_WARNING PFX "%s: receiver stop failed\n", |
| 1045 | sky2->netdev->name); |
| 1046 | stopped: |
| 1047 | sky2_write32(hw, Q_ADDR(rxq, Q_CSR), BMU_RST_SET | BMU_FIFO_RST); |
| 1048 | |
| 1049 | /* reset the Rx prefetch unit */ |
| 1050 | sky2_write32(hw, Y2_QADDR(rxq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET); |
Stephen Hemminger | 50432cb | 2007-05-14 12:38:15 -0700 | [diff] [blame] | 1051 | mmiowb(); |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1052 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1053 | |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 1054 | /* Clean out receive buffer area, assumes receiver hardware stopped */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1055 | static void sky2_rx_clean(struct sky2_port *sky2) |
| 1056 | { |
| 1057 | unsigned i; |
| 1058 | |
| 1059 | memset(sky2->rx_le, 0, RX_LE_BYTES); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1060 | for (i = 0; i < sky2->rx_pending; i++) { |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1061 | struct rx_ring_info *re = sky2->rx_ring + i; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1062 | |
| 1063 | if (re->skb) { |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1064 | sky2_rx_unmap_skb(sky2->hw->pdev, re); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1065 | kfree_skb(re->skb); |
| 1066 | re->skb = NULL; |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 1071 | /* Basic MII support */ |
| 1072 | static int sky2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 1073 | { |
| 1074 | struct mii_ioctl_data *data = if_mii(ifr); |
| 1075 | struct sky2_port *sky2 = netdev_priv(dev); |
| 1076 | struct sky2_hw *hw = sky2->hw; |
| 1077 | int err = -EOPNOTSUPP; |
| 1078 | |
| 1079 | if (!netif_running(dev)) |
| 1080 | return -ENODEV; /* Phy still in reset */ |
| 1081 | |
Stephen Hemminger | d89e134 | 2006-03-20 15:48:20 -0800 | [diff] [blame] | 1082 | switch (cmd) { |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 1083 | case SIOCGMIIPHY: |
| 1084 | data->phy_id = PHY_ADDR_MARV; |
| 1085 | |
| 1086 | /* fallthru */ |
| 1087 | case SIOCGMIIREG: { |
| 1088 | u16 val = 0; |
Stephen Hemminger | 91c86df | 2005-12-09 11:34:57 -0800 | [diff] [blame] | 1089 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1090 | spin_lock_bh(&sky2->phy_lock); |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 1091 | err = __gm_phy_read(hw, sky2->port, data->reg_num & 0x1f, &val); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1092 | spin_unlock_bh(&sky2->phy_lock); |
Stephen Hemminger | 91c86df | 2005-12-09 11:34:57 -0800 | [diff] [blame] | 1093 | |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 1094 | data->val_out = val; |
| 1095 | break; |
| 1096 | } |
| 1097 | |
| 1098 | case SIOCSMIIREG: |
| 1099 | if (!capable(CAP_NET_ADMIN)) |
| 1100 | return -EPERM; |
| 1101 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1102 | spin_lock_bh(&sky2->phy_lock); |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 1103 | err = gm_phy_write(hw, sky2->port, data->reg_num & 0x1f, |
| 1104 | data->val_in); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1105 | spin_unlock_bh(&sky2->phy_lock); |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 1106 | break; |
| 1107 | } |
| 1108 | return err; |
| 1109 | } |
| 1110 | |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1111 | #ifdef SKY2_VLAN_TAG_USED |
| 1112 | static void sky2_vlan_rx_register(struct net_device *dev, struct vlan_group *grp) |
| 1113 | { |
| 1114 | struct sky2_port *sky2 = netdev_priv(dev); |
| 1115 | struct sky2_hw *hw = sky2->hw; |
| 1116 | u16 port = sky2->port; |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1117 | |
Stephen Hemminger | 2bb8c26 | 2006-09-26 11:57:42 -0700 | [diff] [blame] | 1118 | netif_tx_lock_bh(dev); |
Stephen Hemminger | 3d4e66f | 2007-06-01 09:43:58 -0700 | [diff] [blame] | 1119 | netif_poll_disable(sky2->hw->dev[0]); |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1120 | |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1121 | sky2->vlgrp = grp; |
Stephen Hemminger | 3d4e66f | 2007-06-01 09:43:58 -0700 | [diff] [blame] | 1122 | if (grp) { |
| 1123 | sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), |
| 1124 | RX_VLAN_STRIP_ON); |
| 1125 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), |
| 1126 | TX_VLAN_TAG_ON); |
| 1127 | } else { |
| 1128 | sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), |
| 1129 | RX_VLAN_STRIP_OFF); |
| 1130 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), |
| 1131 | TX_VLAN_TAG_OFF); |
| 1132 | } |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1133 | |
Stephen Hemminger | 3d4e66f | 2007-06-01 09:43:58 -0700 | [diff] [blame] | 1134 | netif_poll_enable(sky2->hw->dev[0]); |
Stephen Hemminger | 2bb8c26 | 2006-09-26 11:57:42 -0700 | [diff] [blame] | 1135 | netif_tx_unlock_bh(dev); |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1136 | } |
| 1137 | #endif |
| 1138 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1139 | /* |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1140 | * Allocate an skb for receiving. If the MTU is large enough |
| 1141 | * make the skb non-linear with a fragment list of pages. |
| 1142 | * |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 1143 | * It appears the hardware has a bug in the FIFO logic that |
| 1144 | * cause it to hang if the FIFO gets overrun and the receive buffer |
shemminger@osdl.org | 497d7c8 | 2006-08-28 10:00:46 -0700 | [diff] [blame] | 1145 | * is not 64 byte aligned. The buffer returned from netdev_alloc_skb is |
| 1146 | * aligned except if slab debugging is enabled. |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 1147 | */ |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1148 | static struct sk_buff *sky2_rx_alloc(struct sky2_port *sky2) |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 1149 | { |
| 1150 | struct sk_buff *skb; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1151 | unsigned long p; |
| 1152 | int i; |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 1153 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1154 | skb = netdev_alloc_skb(sky2->netdev, sky2->rx_data_size + RX_SKB_ALIGN); |
| 1155 | if (!skb) |
| 1156 | goto nomem; |
| 1157 | |
| 1158 | p = (unsigned long) skb->data; |
| 1159 | skb_reserve(skb, ALIGN(p, RX_SKB_ALIGN) - p); |
| 1160 | |
| 1161 | for (i = 0; i < sky2->rx_nfrags; i++) { |
| 1162 | struct page *page = alloc_page(GFP_ATOMIC); |
| 1163 | |
| 1164 | if (!page) |
| 1165 | goto free_partial; |
| 1166 | skb_fill_page_desc(skb, i, page, 0, PAGE_SIZE); |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | return skb; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1170 | free_partial: |
| 1171 | kfree_skb(skb); |
| 1172 | nomem: |
| 1173 | return NULL; |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 1174 | } |
| 1175 | |
Stephen Hemminger | 55c9dd3 | 2007-07-09 15:33:37 -0700 | [diff] [blame] | 1176 | static inline void sky2_rx_update(struct sky2_port *sky2, unsigned rxq) |
| 1177 | { |
| 1178 | sky2_put_idx(sky2->hw, rxq, sky2->rx_put); |
| 1179 | } |
| 1180 | |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 1181 | /* |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1182 | * Allocate and setup receiver buffer pool. |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1183 | * Normal case this ends up creating one list element for skb |
| 1184 | * in the receive ring. Worst case if using large MTU and each |
| 1185 | * allocation falls on a different 64 bit region, that results |
| 1186 | * in 6 list elements per ring entry. |
| 1187 | * One element is used for checksum enable/disable, and one |
| 1188 | * extra to avoid wrap. |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1189 | */ |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1190 | static int sky2_rx_start(struct sky2_port *sky2) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1191 | { |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1192 | struct sky2_hw *hw = sky2->hw; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1193 | struct rx_ring_info *re; |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1194 | unsigned rxq = rxqaddr[sky2->port]; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1195 | unsigned i, size, space, thresh; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1196 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1197 | sky2->rx_put = sky2->rx_next = 0; |
shemminger@osdl.org | af4ed7e | 2005-11-30 11:45:21 -0800 | [diff] [blame] | 1198 | sky2_qset(hw, rxq); |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 1199 | |
Stephen Hemminger | c3905bc | 2006-12-04 17:08:19 -0800 | [diff] [blame] | 1200 | /* On PCI express lowering the watermark gives better performance */ |
| 1201 | if (pci_find_capability(hw->pdev, PCI_CAP_ID_EXP)) |
| 1202 | sky2_write32(hw, Q_ADDR(rxq, Q_WM), BMU_WM_PEX); |
| 1203 | |
| 1204 | /* These chips have no ram buffer? |
| 1205 | * MAC Rx RAM Read is controlled by hardware */ |
Stephen Hemminger | 8df9a87 | 2006-12-01 14:29:35 -0800 | [diff] [blame] | 1206 | if (hw->chip_id == CHIP_ID_YUKON_EC_U && |
Stephen Hemminger | c3905bc | 2006-12-04 17:08:19 -0800 | [diff] [blame] | 1207 | (hw->chip_rev == CHIP_REV_YU_EC_U_A1 |
| 1208 | || hw->chip_rev == CHIP_REV_YU_EC_U_B0)) |
Stephen Hemminger | f449c7c | 2007-06-04 17:23:23 -0700 | [diff] [blame] | 1209 | sky2_write32(hw, Q_ADDR(rxq, Q_TEST), F_M_RX_RAM_DIS); |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 1210 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1211 | sky2_prefetch_init(hw, rxq, sky2->rx_le_map, RX_LE_SIZE - 1); |
| 1212 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1213 | if (!(hw->flags & SKY2_HW_NEW_LE)) |
| 1214 | rx_set_checksum(sky2); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1215 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1216 | /* Space needed for frame data + headers rounded up */ |
Stephen Hemminger | f957da2 | 2007-07-09 15:33:41 -0700 | [diff] [blame] | 1217 | size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8); |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1218 | |
| 1219 | /* Stopping point for hardware truncation */ |
| 1220 | thresh = (size - 8) / sizeof(u32); |
| 1221 | |
| 1222 | /* Account for overhead of skb - to avoid order > 0 allocation */ |
| 1223 | space = SKB_DATA_ALIGN(size) + NET_SKB_PAD |
| 1224 | + sizeof(struct skb_shared_info); |
| 1225 | |
| 1226 | sky2->rx_nfrags = space >> PAGE_SHIFT; |
| 1227 | BUG_ON(sky2->rx_nfrags > ARRAY_SIZE(re->frag_addr)); |
| 1228 | |
| 1229 | if (sky2->rx_nfrags != 0) { |
| 1230 | /* Compute residue after pages */ |
| 1231 | space = sky2->rx_nfrags << PAGE_SHIFT; |
| 1232 | |
| 1233 | if (space < size) |
| 1234 | size -= space; |
| 1235 | else |
| 1236 | size = 0; |
| 1237 | |
| 1238 | /* Optimize to handle small packets and headers */ |
| 1239 | if (size < copybreak) |
| 1240 | size = copybreak; |
| 1241 | if (size < ETH_HLEN) |
| 1242 | size = ETH_HLEN; |
| 1243 | } |
| 1244 | sky2->rx_data_size = size; |
| 1245 | |
| 1246 | /* Fill Rx ring */ |
| 1247 | for (i = 0; i < sky2->rx_pending; i++) { |
| 1248 | re = sky2->rx_ring + i; |
| 1249 | |
| 1250 | re->skb = sky2_rx_alloc(sky2); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1251 | if (!re->skb) |
| 1252 | goto nomem; |
| 1253 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1254 | sky2_rx_map_skb(hw->pdev, re, sky2->rx_data_size); |
| 1255 | sky2_rx_submit(sky2, re); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
Stephen Hemminger | a1433ac | 2006-05-22 12:03:42 -0700 | [diff] [blame] | 1258 | /* |
| 1259 | * The receiver hangs if it receives frames larger than the |
| 1260 | * packet buffer. As a workaround, truncate oversize frames, but |
| 1261 | * the register is limited to 9 bits, so if you do frames > 2052 |
| 1262 | * you better get the MTU right! |
| 1263 | */ |
Stephen Hemminger | a1433ac | 2006-05-22 12:03:42 -0700 | [diff] [blame] | 1264 | if (thresh > 0x1ff) |
| 1265 | sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_OFF); |
| 1266 | else { |
| 1267 | sky2_write16(hw, SK_REG(sky2->port, RX_GMF_TR_THR), thresh); |
| 1268 | sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_ON); |
| 1269 | } |
| 1270 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1271 | /* Tell chip about available buffers */ |
Stephen Hemminger | 55c9dd3 | 2007-07-09 15:33:37 -0700 | [diff] [blame] | 1272 | sky2_rx_update(sky2, rxq); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1273 | return 0; |
| 1274 | nomem: |
| 1275 | sky2_rx_clean(sky2); |
| 1276 | return -ENOMEM; |
| 1277 | } |
| 1278 | |
| 1279 | /* Bring up network interface. */ |
| 1280 | static int sky2_up(struct net_device *dev) |
| 1281 | { |
| 1282 | struct sky2_port *sky2 = netdev_priv(dev); |
| 1283 | struct sky2_hw *hw = sky2->hw; |
| 1284 | unsigned port = sky2->port; |
Stephen Hemminger | e0c2811 | 2007-09-20 13:03:49 -0700 | [diff] [blame^] | 1285 | u32 imask, ramsize; |
Stephen Hemminger | ee7abb0 | 2006-05-18 11:16:21 -0700 | [diff] [blame] | 1286 | int cap, err = -ENOMEM; |
Stephen Hemminger | 843a46f | 2006-05-11 15:07:28 -0700 | [diff] [blame] | 1287 | struct net_device *otherdev = hw->dev[sky2->port^1]; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1288 | |
Stephen Hemminger | ee7abb0 | 2006-05-18 11:16:21 -0700 | [diff] [blame] | 1289 | /* |
| 1290 | * On dual port PCI-X card, there is an problem where status |
| 1291 | * can be received out of order due to split transactions |
Stephen Hemminger | 843a46f | 2006-05-11 15:07:28 -0700 | [diff] [blame] | 1292 | */ |
Stephen Hemminger | ee7abb0 | 2006-05-18 11:16:21 -0700 | [diff] [blame] | 1293 | if (otherdev && netif_running(otherdev) && |
| 1294 | (cap = pci_find_capability(hw->pdev, PCI_CAP_ID_PCIX))) { |
| 1295 | struct sky2_port *osky2 = netdev_priv(otherdev); |
| 1296 | u16 cmd; |
Stephen Hemminger | 843a46f | 2006-05-11 15:07:28 -0700 | [diff] [blame] | 1297 | |
Stephen Hemminger | ee7abb0 | 2006-05-18 11:16:21 -0700 | [diff] [blame] | 1298 | cmd = sky2_pci_read16(hw, cap + PCI_X_CMD); |
| 1299 | cmd &= ~PCI_X_CMD_MAX_SPLIT; |
| 1300 | sky2_pci_write16(hw, cap + PCI_X_CMD, cmd); |
| 1301 | |
| 1302 | sky2->rx_csum = 0; |
| 1303 | osky2->rx_csum = 0; |
| 1304 | } |
| 1305 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1306 | if (netif_msg_ifup(sky2)) |
| 1307 | printk(KERN_INFO PFX "%s: enabling interface\n", dev->name); |
| 1308 | |
Stephen Hemminger | 55d7b4e | 2007-07-09 15:33:34 -0700 | [diff] [blame] | 1309 | netif_carrier_off(dev); |
| 1310 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1311 | /* must be power of 2 */ |
| 1312 | sky2->tx_le = pci_alloc_consistent(hw->pdev, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1313 | TX_RING_SIZE * |
| 1314 | sizeof(struct sky2_tx_le), |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1315 | &sky2->tx_le_map); |
| 1316 | if (!sky2->tx_le) |
| 1317 | goto err_out; |
| 1318 | |
Stephen Hemminger | 6cdbbdf | 2005-12-09 11:35:01 -0800 | [diff] [blame] | 1319 | sky2->tx_ring = kcalloc(TX_RING_SIZE, sizeof(struct tx_ring_info), |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1320 | GFP_KERNEL); |
| 1321 | if (!sky2->tx_ring) |
| 1322 | goto err_out; |
| 1323 | sky2->tx_prod = sky2->tx_cons = 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1324 | |
| 1325 | sky2->rx_le = pci_alloc_consistent(hw->pdev, RX_LE_BYTES, |
| 1326 | &sky2->rx_le_map); |
| 1327 | if (!sky2->rx_le) |
| 1328 | goto err_out; |
| 1329 | memset(sky2->rx_le, 0, RX_LE_BYTES); |
| 1330 | |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1331 | sky2->rx_ring = kcalloc(sky2->rx_pending, sizeof(struct rx_ring_info), |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1332 | GFP_KERNEL); |
| 1333 | if (!sky2->rx_ring) |
| 1334 | goto err_out; |
| 1335 | |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 1336 | sky2_phy_power(hw, port, 1); |
| 1337 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1338 | sky2_mac_init(hw, port); |
| 1339 | |
Stephen Hemminger | e0c2811 | 2007-09-20 13:03:49 -0700 | [diff] [blame^] | 1340 | /* Register is number of 4K blocks on internal RAM buffer. */ |
| 1341 | ramsize = sky2_read8(hw, B2_E_0) * 4; |
| 1342 | if (ramsize > 0) { |
Stephen Hemminger | 6771290 | 2006-12-04 15:53:45 -0800 | [diff] [blame] | 1343 | u32 rxspace; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1344 | |
Stephen Hemminger | e0c2811 | 2007-09-20 13:03:49 -0700 | [diff] [blame^] | 1345 | pr_debug(PFX "%s: ram buffer %dK\n", dev->name, ramsize); |
Stephen Hemminger | 6771290 | 2006-12-04 15:53:45 -0800 | [diff] [blame] | 1346 | if (ramsize < 16) |
| 1347 | rxspace = ramsize / 2; |
| 1348 | else |
| 1349 | rxspace = 8 + (2*(ramsize - 16))/3; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1350 | |
Stephen Hemminger | 6771290 | 2006-12-04 15:53:45 -0800 | [diff] [blame] | 1351 | sky2_ramset(hw, rxqaddr[port], 0, rxspace); |
| 1352 | sky2_ramset(hw, txqaddr[port], rxspace, ramsize - rxspace); |
| 1353 | |
| 1354 | /* Make sure SyncQ is disabled */ |
| 1355 | sky2_write8(hw, RB_ADDR(port == 0 ? Q_XS1 : Q_XS2, RB_CTRL), |
| 1356 | RB_RST_SET); |
| 1357 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1358 | |
shemminger@osdl.org | af4ed7e | 2005-11-30 11:45:21 -0800 | [diff] [blame] | 1359 | sky2_qset(hw, txqaddr[port]); |
shemminger@osdl.org | 5a5b1ea | 2005-11-30 11:45:15 -0800 | [diff] [blame] | 1360 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1361 | /* This is copied from sk98lin 10.0.5.3; no one tells me about erratta's */ |
| 1362 | if (hw->chip_id == CHIP_ID_YUKON_EX && hw->chip_rev == CHIP_REV_YU_EX_B0) |
| 1363 | sky2_write32(hw, Q_ADDR(txqaddr[port], Q_TEST), F_TX_CHK_AUTO_OFF); |
| 1364 | |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 1365 | /* Set almost empty threshold */ |
Stephen Hemminger | c2716fb | 2006-09-26 11:57:39 -0700 | [diff] [blame] | 1366 | if (hw->chip_id == CHIP_ID_YUKON_EC_U |
| 1367 | && hw->chip_rev == CHIP_REV_YU_EC_U_A0) |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 1368 | sky2_write16(hw, Q_ADDR(txqaddr[port], Q_AL), ECU_TXFF_LEV); |
shemminger@osdl.org | 5a5b1ea | 2005-11-30 11:45:15 -0800 | [diff] [blame] | 1369 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1370 | sky2_prefetch_init(hw, txqaddr[port], sky2->tx_le_map, |
| 1371 | TX_RING_SIZE - 1); |
| 1372 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1373 | err = sky2_rx_start(sky2); |
| 1374 | if (err) |
| 1375 | goto err_out; |
| 1376 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1377 | /* Enable interrupts from phy/mac for port */ |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1378 | imask = sky2_read32(hw, B0_IMSK); |
Stephen Hemminger | f4ea431 | 2006-05-09 14:46:54 -0700 | [diff] [blame] | 1379 | imask |= portirq_msk[port]; |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1380 | sky2_write32(hw, B0_IMSK, imask); |
| 1381 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1382 | return 0; |
| 1383 | |
| 1384 | err_out: |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 1385 | if (sky2->rx_le) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1386 | pci_free_consistent(hw->pdev, RX_LE_BYTES, |
| 1387 | sky2->rx_le, sky2->rx_le_map); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 1388 | sky2->rx_le = NULL; |
| 1389 | } |
| 1390 | if (sky2->tx_le) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1391 | pci_free_consistent(hw->pdev, |
| 1392 | TX_RING_SIZE * sizeof(struct sky2_tx_le), |
| 1393 | sky2->tx_le, sky2->tx_le_map); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 1394 | sky2->tx_le = NULL; |
| 1395 | } |
| 1396 | kfree(sky2->tx_ring); |
| 1397 | kfree(sky2->rx_ring); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1398 | |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 1399 | sky2->tx_ring = NULL; |
| 1400 | sky2->rx_ring = NULL; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1401 | return err; |
| 1402 | } |
| 1403 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1404 | /* Modular subtraction in ring */ |
| 1405 | static inline int tx_dist(unsigned tail, unsigned head) |
| 1406 | { |
Stephen Hemminger | cb5d954 | 2006-05-08 15:11:29 -0700 | [diff] [blame] | 1407 | return (head - tail) & (TX_RING_SIZE - 1); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | /* Number of list elements available for next tx */ |
| 1411 | static inline int tx_avail(const struct sky2_port *sky2) |
| 1412 | { |
| 1413 | return sky2->tx_pending - tx_dist(sky2->tx_cons, sky2->tx_prod); |
| 1414 | } |
| 1415 | |
| 1416 | /* Estimate of number of transmit list elements required */ |
Stephen Hemminger | 28bd181 | 2006-01-17 13:43:19 -0800 | [diff] [blame] | 1417 | static unsigned tx_le_req(const struct sk_buff *skb) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1418 | { |
| 1419 | unsigned count; |
| 1420 | |
| 1421 | count = sizeof(dma_addr_t) / sizeof(u32); |
| 1422 | count += skb_shinfo(skb)->nr_frags * count; |
| 1423 | |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 1424 | if (skb_is_gso(skb)) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1425 | ++count; |
| 1426 | |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 1427 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1428 | ++count; |
| 1429 | |
| 1430 | return count; |
| 1431 | } |
| 1432 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1433 | /* |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1434 | * Put one packet in ring for transmit. |
| 1435 | * A single packet can generate multiple list elements, and |
| 1436 | * the number of ring elements will probably be less than the number |
| 1437 | * of list elements used. |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1438 | */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1439 | static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev) |
| 1440 | { |
| 1441 | struct sky2_port *sky2 = netdev_priv(dev); |
| 1442 | struct sky2_hw *hw = sky2->hw; |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1443 | struct sky2_tx_le *le = NULL; |
Stephen Hemminger | 6cdbbdf | 2005-12-09 11:35:01 -0800 | [diff] [blame] | 1444 | struct tx_ring_info *re; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1445 | unsigned i, len; |
| 1446 | dma_addr_t mapping; |
| 1447 | u32 addr64; |
| 1448 | u16 mss; |
| 1449 | u8 ctrl; |
| 1450 | |
Stephen Hemminger | 2bb8c26 | 2006-09-26 11:57:42 -0700 | [diff] [blame] | 1451 | if (unlikely(tx_avail(sky2) < tx_le_req(skb))) |
| 1452 | return NETDEV_TX_BUSY; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1453 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1454 | if (unlikely(netif_msg_tx_queued(sky2))) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1455 | printk(KERN_DEBUG "%s: tx queued, slot %u, len %d\n", |
| 1456 | dev->name, sky2->tx_prod, skb->len); |
| 1457 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1458 | len = skb_headlen(skb); |
| 1459 | mapping = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE); |
Stephen Hemminger | 36eb0c7 | 2007-07-09 15:33:42 -0700 | [diff] [blame] | 1460 | addr64 = upper_32_bits(mapping); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1461 | |
shemminger@osdl.org | a018e33 | 2005-11-30 11:45:16 -0800 | [diff] [blame] | 1462 | /* Send high bits if changed or crosses boundary */ |
Stephen Hemminger | 36eb0c7 | 2007-07-09 15:33:42 -0700 | [diff] [blame] | 1463 | if (addr64 != sky2->tx_addr64 || |
| 1464 | upper_32_bits(mapping + len) != sky2->tx_addr64) { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1465 | le = get_tx_le(sky2); |
Stephen Hemminger | f65b138 | 2006-09-06 12:45:02 -0700 | [diff] [blame] | 1466 | le->addr = cpu_to_le32(addr64); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1467 | le->opcode = OP_ADDR64 | HW_OWNER; |
Stephen Hemminger | 36eb0c7 | 2007-07-09 15:33:42 -0700 | [diff] [blame] | 1468 | sky2->tx_addr64 = upper_32_bits(mapping + len); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1469 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1470 | |
| 1471 | /* Check for TCP Segmentation Offload */ |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 1472 | mss = skb_shinfo(skb)->gso_size; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1473 | if (mss != 0) { |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1474 | |
| 1475 | if (!(hw->flags & SKY2_HW_NEW_LE)) |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1476 | mss += ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1477 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1478 | if (mss != sky2->tx_last_mss) { |
| 1479 | le = get_tx_le(sky2); |
| 1480 | le->addr = cpu_to_le32(mss); |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1481 | |
| 1482 | if (hw->flags & SKY2_HW_NEW_LE) |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1483 | le->opcode = OP_MSS | HW_OWNER; |
| 1484 | else |
| 1485 | le->opcode = OP_LRGLEN | HW_OWNER; |
shemminger@osdl.org | e07560c | 2006-08-28 10:00:49 -0700 | [diff] [blame] | 1486 | sky2->tx_last_mss = mss; |
| 1487 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1490 | ctrl = 0; |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1491 | #ifdef SKY2_VLAN_TAG_USED |
| 1492 | /* Add VLAN tag, can piggyback on LRGLEN or ADDR64 */ |
| 1493 | if (sky2->vlgrp && vlan_tx_tag_present(skb)) { |
| 1494 | if (!le) { |
| 1495 | le = get_tx_le(sky2); |
Stephen Hemminger | f65b138 | 2006-09-06 12:45:02 -0700 | [diff] [blame] | 1496 | le->addr = 0; |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1497 | le->opcode = OP_VLAN|HW_OWNER; |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1498 | } else |
| 1499 | le->opcode |= OP_VLAN; |
| 1500 | le->length = cpu_to_be16(vlan_tx_tag_get(skb)); |
| 1501 | ctrl |= INS_VLAN; |
| 1502 | } |
| 1503 | #endif |
| 1504 | |
| 1505 | /* Handle TCP checksum offload */ |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 1506 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1507 | /* On Yukon EX (some versions) encoding change. */ |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1508 | if (hw->flags & SKY2_HW_AUTO_TX_SUM) |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1509 | ctrl |= CALSUM; /* auto checksum */ |
| 1510 | else { |
| 1511 | const unsigned offset = skb_transport_offset(skb); |
| 1512 | u32 tcpsum; |
Stephen Hemminger | f65b138 | 2006-09-06 12:45:02 -0700 | [diff] [blame] | 1513 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1514 | tcpsum = offset << 16; /* sum start */ |
| 1515 | tcpsum |= offset + skb->csum_offset; /* sum write */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1516 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1517 | ctrl |= CALSUM | WR_SUM | INIT_SUM | LOCK_SUM; |
| 1518 | if (ip_hdr(skb)->protocol == IPPROTO_UDP) |
| 1519 | ctrl |= UDPTCP; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1520 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1521 | if (tcpsum != sky2->tx_tcpsum) { |
| 1522 | sky2->tx_tcpsum = tcpsum; |
shemminger@osdl.org | 1d17933 | 2006-08-28 10:00:50 -0700 | [diff] [blame] | 1523 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1524 | le = get_tx_le(sky2); |
| 1525 | le->addr = cpu_to_le32(tcpsum); |
| 1526 | le->length = 0; /* initial checksum value */ |
| 1527 | le->ctrl = 1; /* one packet */ |
| 1528 | le->opcode = OP_TCPLISW | HW_OWNER; |
| 1529 | } |
shemminger@osdl.org | 1d17933 | 2006-08-28 10:00:50 -0700 | [diff] [blame] | 1530 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | le = get_tx_le(sky2); |
Stephen Hemminger | f65b138 | 2006-09-06 12:45:02 -0700 | [diff] [blame] | 1534 | le->addr = cpu_to_le32((u32) mapping); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1535 | le->length = cpu_to_le16(len); |
| 1536 | le->ctrl = ctrl; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1537 | le->opcode = mss ? (OP_LARGESEND | HW_OWNER) : (OP_PACKET | HW_OWNER); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1538 | |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1539 | re = tx_le_re(sky2, le); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1540 | re->skb = skb; |
Stephen Hemminger | 6cdbbdf | 2005-12-09 11:35:01 -0800 | [diff] [blame] | 1541 | pci_unmap_addr_set(re, mapaddr, mapping); |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1542 | pci_unmap_len_set(re, maplen, len); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1543 | |
| 1544 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1545 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1546 | |
| 1547 | mapping = pci_map_page(hw->pdev, frag->page, frag->page_offset, |
| 1548 | frag->size, PCI_DMA_TODEVICE); |
Stephen Hemminger | 36eb0c7 | 2007-07-09 15:33:42 -0700 | [diff] [blame] | 1549 | addr64 = upper_32_bits(mapping); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1550 | if (addr64 != sky2->tx_addr64) { |
| 1551 | le = get_tx_le(sky2); |
Stephen Hemminger | f65b138 | 2006-09-06 12:45:02 -0700 | [diff] [blame] | 1552 | le->addr = cpu_to_le32(addr64); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1553 | le->ctrl = 0; |
| 1554 | le->opcode = OP_ADDR64 | HW_OWNER; |
| 1555 | sky2->tx_addr64 = addr64; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | le = get_tx_le(sky2); |
Stephen Hemminger | f65b138 | 2006-09-06 12:45:02 -0700 | [diff] [blame] | 1559 | le->addr = cpu_to_le32((u32) mapping); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1560 | le->length = cpu_to_le16(frag->size); |
| 1561 | le->ctrl = ctrl; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1562 | le->opcode = OP_BUFFER | HW_OWNER; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1563 | |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1564 | re = tx_le_re(sky2, le); |
| 1565 | re->skb = skb; |
| 1566 | pci_unmap_addr_set(re, mapaddr, mapping); |
| 1567 | pci_unmap_len_set(re, maplen, frag->size); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1568 | } |
Stephen Hemminger | 6cdbbdf | 2005-12-09 11:35:01 -0800 | [diff] [blame] | 1569 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1570 | le->ctrl |= EOP; |
| 1571 | |
shemminger@osdl.org | 97bda70 | 2006-08-28 10:00:47 -0700 | [diff] [blame] | 1572 | if (tx_avail(sky2) <= MAX_SKB_TX_LE) |
| 1573 | netif_stop_queue(dev); |
Stephen Hemminger | b19666d | 2006-03-07 11:06:36 -0800 | [diff] [blame] | 1574 | |
Stephen Hemminger | 290d4de | 2006-03-20 15:48:15 -0800 | [diff] [blame] | 1575 | sky2_put_idx(hw, txqaddr[sky2->port], sky2->tx_prod); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1576 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1577 | dev->trans_start = jiffies; |
| 1578 | return NETDEV_TX_OK; |
| 1579 | } |
| 1580 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1581 | /* |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1582 | * Free ring elements from starting at tx_cons until "done" |
| 1583 | * |
| 1584 | * NB: the hardware will tell us about partial completion of multi-part |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1585 | * buffers so make sure not to free skb to early. |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1586 | */ |
shemminger@osdl.org | d11c13e | 2005-09-27 15:02:56 -0700 | [diff] [blame] | 1587 | static void sky2_tx_complete(struct sky2_port *sky2, u16 done) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1588 | { |
shemminger@osdl.org | d11c13e | 2005-09-27 15:02:56 -0700 | [diff] [blame] | 1589 | struct net_device *dev = sky2->netdev; |
Stephen Hemminger | af2a58a | 2005-12-09 11:35:04 -0800 | [diff] [blame] | 1590 | struct pci_dev *pdev = sky2->hw->pdev; |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1591 | unsigned idx; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1592 | |
Stephen Hemminger | 0e3ff6a | 2005-12-09 11:35:02 -0800 | [diff] [blame] | 1593 | BUG_ON(done >= TX_RING_SIZE); |
shemminger@osdl.org | 2224795 | 2005-11-30 11:45:19 -0800 | [diff] [blame] | 1594 | |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1595 | for (idx = sky2->tx_cons; idx != done; |
| 1596 | idx = RING_NEXT(idx, TX_RING_SIZE)) { |
| 1597 | struct sky2_tx_le *le = sky2->tx_le + idx; |
| 1598 | struct tx_ring_info *re = sky2->tx_ring + idx; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1599 | |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1600 | switch(le->opcode & ~HW_OWNER) { |
| 1601 | case OP_LARGESEND: |
| 1602 | case OP_PACKET: |
| 1603 | pci_unmap_single(pdev, |
| 1604 | pci_unmap_addr(re, mapaddr), |
| 1605 | pci_unmap_len(re, maplen), |
| 1606 | PCI_DMA_TODEVICE); |
Stephen Hemminger | af2a58a | 2005-12-09 11:35:04 -0800 | [diff] [blame] | 1607 | break; |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1608 | case OP_BUFFER: |
| 1609 | pci_unmap_page(pdev, pci_unmap_addr(re, mapaddr), |
| 1610 | pci_unmap_len(re, maplen), |
Stephen Hemminger | 734d186 | 2005-12-09 11:35:00 -0800 | [diff] [blame] | 1611 | PCI_DMA_TODEVICE); |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1612 | break; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1615 | if (le->ctrl & EOP) { |
| 1616 | if (unlikely(netif_msg_tx_done(sky2))) |
| 1617 | printk(KERN_DEBUG "%s: tx done %u\n", |
| 1618 | dev->name, idx); |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 1619 | |
shemminger@linux-foundation.org | 2bf56fe | 2007-01-26 11:38:39 -0800 | [diff] [blame] | 1620 | sky2->net_stats.tx_packets++; |
| 1621 | sky2->net_stats.tx_bytes += re->skb->len; |
| 1622 | |
Stephen Hemminger | 794b2bd | 2006-12-01 14:29:36 -0800 | [diff] [blame] | 1623 | dev_kfree_skb_any(re->skb); |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 1624 | sky2->tx_next = RING_NEXT(idx, TX_RING_SIZE); |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1625 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1626 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1627 | |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1628 | sky2->tx_cons = idx; |
Stephen Hemminger | 50432cb | 2007-05-14 12:38:15 -0700 | [diff] [blame] | 1629 | smp_mb(); |
| 1630 | |
Stephen Hemminger | 22e1170 | 2006-07-12 15:23:48 -0700 | [diff] [blame] | 1631 | if (tx_avail(sky2) > MAX_SKB_TX_LE + 4) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1632 | netif_wake_queue(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | /* Cleanup all untransmitted buffers, assume transmitter not running */ |
Stephen Hemminger | 2bb8c26 | 2006-09-26 11:57:42 -0700 | [diff] [blame] | 1636 | static void sky2_tx_clean(struct net_device *dev) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1637 | { |
Stephen Hemminger | 2bb8c26 | 2006-09-26 11:57:42 -0700 | [diff] [blame] | 1638 | struct sky2_port *sky2 = netdev_priv(dev); |
| 1639 | |
| 1640 | netif_tx_lock_bh(dev); |
shemminger@osdl.org | d11c13e | 2005-09-27 15:02:56 -0700 | [diff] [blame] | 1641 | sky2_tx_complete(sky2, sky2->tx_prod); |
Stephen Hemminger | 2bb8c26 | 2006-09-26 11:57:42 -0700 | [diff] [blame] | 1642 | netif_tx_unlock_bh(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | /* Network shutdown */ |
| 1646 | static int sky2_down(struct net_device *dev) |
| 1647 | { |
| 1648 | struct sky2_port *sky2 = netdev_priv(dev); |
| 1649 | struct sky2_hw *hw = sky2->hw; |
| 1650 | unsigned port = sky2->port; |
| 1651 | u16 ctrl; |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1652 | u32 imask; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1653 | |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 1654 | /* Never really got started! */ |
| 1655 | if (!sky2->tx_le) |
| 1656 | return 0; |
| 1657 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1658 | if (netif_msg_ifdown(sky2)) |
| 1659 | printk(KERN_INFO PFX "%s: disabling interface\n", dev->name); |
| 1660 | |
shemminger@osdl.org | 018d1c6 | 2005-11-30 11:45:18 -0800 | [diff] [blame] | 1661 | /* Stop more packets from being queued */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1662 | netif_stop_queue(dev); |
| 1663 | |
Stephen Hemminger | ebc646f | 2006-10-17 10:23:56 -0700 | [diff] [blame] | 1664 | /* Disable port IRQ */ |
| 1665 | imask = sky2_read32(hw, B0_IMSK); |
| 1666 | imask &= ~portirq_msk[port]; |
| 1667 | sky2_write32(hw, B0_IMSK, imask); |
| 1668 | |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 1669 | sky2_gmac_reset(hw, port); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1670 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1671 | /* Stop transmitter */ |
| 1672 | sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_STOP); |
| 1673 | sky2_read32(hw, Q_ADDR(txqaddr[port], Q_CSR)); |
| 1674 | |
| 1675 | sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1676 | RB_RST_SET | RB_DIS_OP_MD); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1677 | |
| 1678 | ctrl = gma_read16(hw, port, GM_GP_CTRL); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1679 | ctrl &= ~(GM_GPCR_TX_ENA | GM_GPCR_RX_ENA); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1680 | gma_write16(hw, port, GM_GP_CTRL, ctrl); |
| 1681 | |
| 1682 | sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET); |
| 1683 | |
| 1684 | /* Workaround shared GMAC reset */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1685 | if (!(hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0 |
| 1686 | && port == 0 && hw->dev[1] && netif_running(hw->dev[1]))) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1687 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET); |
| 1688 | |
| 1689 | /* Disable Force Sync bit and Enable Alloc bit */ |
| 1690 | sky2_write8(hw, SK_REG(port, TXA_CTRL), |
| 1691 | TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC); |
| 1692 | |
| 1693 | /* Stop Interval Timer and Limit Counter of Tx Arbiter */ |
| 1694 | sky2_write32(hw, SK_REG(port, TXA_ITI_INI), 0L); |
| 1695 | sky2_write32(hw, SK_REG(port, TXA_LIM_INI), 0L); |
| 1696 | |
| 1697 | /* Reset the PCI FIFO of the async Tx queue */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1698 | sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), |
| 1699 | BMU_RST_SET | BMU_FIFO_RST); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1700 | |
| 1701 | /* Reset the Tx prefetch units */ |
| 1702 | sky2_write32(hw, Y2_QADDR(txqaddr[port], PREF_UNIT_CTRL), |
| 1703 | PREF_UNIT_RST_SET); |
| 1704 | |
| 1705 | sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET); |
| 1706 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1707 | sky2_rx_stop(sky2); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1708 | |
| 1709 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); |
| 1710 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET); |
| 1711 | |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 1712 | sky2_phy_power(hw, port, 0); |
| 1713 | |
Stephen Hemminger | 55d7b4e | 2007-07-09 15:33:34 -0700 | [diff] [blame] | 1714 | netif_carrier_off(dev); |
| 1715 | |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 1716 | /* turn off LED's */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1717 | sky2_write16(hw, B0_Y2LED, LED_STAT_OFF); |
| 1718 | |
shemminger@osdl.org | 018d1c6 | 2005-11-30 11:45:18 -0800 | [diff] [blame] | 1719 | synchronize_irq(hw->pdev->irq); |
| 1720 | |
Stephen Hemminger | 2bb8c26 | 2006-09-26 11:57:42 -0700 | [diff] [blame] | 1721 | sky2_tx_clean(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1722 | sky2_rx_clean(sky2); |
| 1723 | |
| 1724 | pci_free_consistent(hw->pdev, RX_LE_BYTES, |
| 1725 | sky2->rx_le, sky2->rx_le_map); |
| 1726 | kfree(sky2->rx_ring); |
| 1727 | |
| 1728 | pci_free_consistent(hw->pdev, |
| 1729 | TX_RING_SIZE * sizeof(struct sky2_tx_le), |
| 1730 | sky2->tx_le, sky2->tx_le_map); |
| 1731 | kfree(sky2->tx_ring); |
| 1732 | |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 1733 | sky2->tx_le = NULL; |
| 1734 | sky2->rx_le = NULL; |
| 1735 | |
| 1736 | sky2->rx_ring = NULL; |
| 1737 | sky2->tx_ring = NULL; |
| 1738 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1739 | return 0; |
| 1740 | } |
| 1741 | |
| 1742 | static u16 sky2_phy_speed(const struct sky2_hw *hw, u16 aux) |
| 1743 | { |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1744 | if (hw->flags & SKY2_HW_FIBRE_PHY) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1745 | return SPEED_1000; |
| 1746 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 1747 | if (!(hw->flags & SKY2_HW_GIGABIT)) { |
| 1748 | if (aux & PHY_M_PS_SPEED_100) |
| 1749 | return SPEED_100; |
| 1750 | else |
| 1751 | return SPEED_10; |
| 1752 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1753 | |
| 1754 | switch (aux & PHY_M_PS_SPEED_MSK) { |
| 1755 | case PHY_M_PS_SPEED_1000: |
| 1756 | return SPEED_1000; |
| 1757 | case PHY_M_PS_SPEED_100: |
| 1758 | return SPEED_100; |
| 1759 | default: |
| 1760 | return SPEED_10; |
| 1761 | } |
| 1762 | } |
| 1763 | |
| 1764 | static void sky2_link_up(struct sky2_port *sky2) |
| 1765 | { |
| 1766 | struct sky2_hw *hw = sky2->hw; |
| 1767 | unsigned port = sky2->port; |
| 1768 | u16 reg; |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 1769 | static const char *fc_name[] = { |
| 1770 | [FC_NONE] = "none", |
| 1771 | [FC_TX] = "tx", |
| 1772 | [FC_RX] = "rx", |
| 1773 | [FC_BOTH] = "both", |
| 1774 | }; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1775 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1776 | /* enable Rx/Tx */ |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 1777 | reg = gma_read16(hw, port, GM_GP_CTRL); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1778 | reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA; |
| 1779 | gma_write16(hw, port, GM_GP_CTRL, reg); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1780 | |
| 1781 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); |
| 1782 | |
| 1783 | netif_carrier_on(sky2->netdev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1784 | |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 1785 | mod_timer(&hw->watchdog_timer, jiffies + 1); |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 1786 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1787 | /* Turn on link LED */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1788 | sky2_write8(hw, SK_REG(port, LNK_LED_REG), |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1789 | LINKLED_ON | LINKLED_BLINK_OFF | LINKLED_LINKSYNC_OFF); |
| 1790 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1791 | if (hw->flags & SKY2_HW_NEWER_PHY) { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1792 | u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); |
Stephen Hemminger | ed6d32c | 2006-05-08 15:11:33 -0700 | [diff] [blame] | 1793 | u16 led = PHY_M_LEDC_LOS_CTRL(1); /* link active */ |
| 1794 | |
| 1795 | switch(sky2->speed) { |
| 1796 | case SPEED_10: |
| 1797 | led |= PHY_M_LEDC_INIT_CTRL(7); |
| 1798 | break; |
| 1799 | |
| 1800 | case SPEED_100: |
| 1801 | led |= PHY_M_LEDC_STA1_CTRL(7); |
| 1802 | break; |
| 1803 | |
| 1804 | case SPEED_1000: |
| 1805 | led |= PHY_M_LEDC_STA0_CTRL(7); |
| 1806 | break; |
| 1807 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1808 | |
| 1809 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); |
Stephen Hemminger | ed6d32c | 2006-05-08 15:11:33 -0700 | [diff] [blame] | 1810 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, led); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1811 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); |
| 1812 | } |
| 1813 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1814 | if (netif_msg_link(sky2)) |
| 1815 | printk(KERN_INFO PFX |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 1816 | "%s: Link is up at %d Mbps, %s duplex, flow control %s\n", |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1817 | sky2->netdev->name, sky2->speed, |
| 1818 | sky2->duplex == DUPLEX_FULL ? "full" : "half", |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 1819 | fc_name[sky2->flow_status]); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | static void sky2_link_down(struct sky2_port *sky2) |
| 1823 | { |
| 1824 | struct sky2_hw *hw = sky2->hw; |
| 1825 | unsigned port = sky2->port; |
| 1826 | u16 reg; |
| 1827 | |
| 1828 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0); |
| 1829 | |
| 1830 | reg = gma_read16(hw, port, GM_GP_CTRL); |
| 1831 | reg &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA); |
| 1832 | gma_write16(hw, port, GM_GP_CTRL, reg); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1833 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1834 | netif_carrier_off(sky2->netdev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1835 | |
| 1836 | /* Turn on link LED */ |
| 1837 | sky2_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF); |
| 1838 | |
| 1839 | if (netif_msg_link(sky2)) |
| 1840 | printk(KERN_INFO PFX "%s: Link is down.\n", sky2->netdev->name); |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 1841 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1842 | sky2_phy_init(hw, port); |
| 1843 | } |
| 1844 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 1845 | static enum flow_control sky2_flow(int rx, int tx) |
| 1846 | { |
| 1847 | if (rx) |
| 1848 | return tx ? FC_BOTH : FC_RX; |
| 1849 | else |
| 1850 | return tx ? FC_TX : FC_NONE; |
| 1851 | } |
| 1852 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1853 | static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux) |
| 1854 | { |
| 1855 | struct sky2_hw *hw = sky2->hw; |
| 1856 | unsigned port = sky2->port; |
Stephen Hemminger | da4c1ff | 2007-02-15 16:40:32 -0800 | [diff] [blame] | 1857 | u16 advert, lpa; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1858 | |
Stephen Hemminger | da4c1ff | 2007-02-15 16:40:32 -0800 | [diff] [blame] | 1859 | advert = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1860 | lpa = gm_phy_read(hw, port, PHY_MARV_AUNE_LP); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1861 | if (lpa & PHY_M_AN_RF) { |
| 1862 | printk(KERN_ERR PFX "%s: remote fault", sky2->netdev->name); |
| 1863 | return -1; |
| 1864 | } |
| 1865 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1866 | if (!(aux & PHY_M_PS_SPDUP_RES)) { |
| 1867 | printk(KERN_ERR PFX "%s: speed/duplex mismatch", |
| 1868 | sky2->netdev->name); |
| 1869 | return -1; |
| 1870 | } |
| 1871 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1872 | sky2->speed = sky2_phy_speed(hw, aux); |
Stephen Hemminger | 7c74ac1 | 2006-10-17 10:24:08 -0700 | [diff] [blame] | 1873 | sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1874 | |
Stephen Hemminger | da4c1ff | 2007-02-15 16:40:32 -0800 | [diff] [blame] | 1875 | /* Since the pause result bits seem to in different positions on |
| 1876 | * different chips. look at registers. |
| 1877 | */ |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1878 | if (hw->flags & SKY2_HW_FIBRE_PHY) { |
Stephen Hemminger | da4c1ff | 2007-02-15 16:40:32 -0800 | [diff] [blame] | 1879 | /* Shift for bits in fiber PHY */ |
| 1880 | advert &= ~(ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM); |
| 1881 | lpa &= ~(LPA_PAUSE_CAP|LPA_PAUSE_ASYM); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1882 | |
Stephen Hemminger | da4c1ff | 2007-02-15 16:40:32 -0800 | [diff] [blame] | 1883 | if (advert & ADVERTISE_1000XPAUSE) |
| 1884 | advert |= ADVERTISE_PAUSE_CAP; |
| 1885 | if (advert & ADVERTISE_1000XPSE_ASYM) |
| 1886 | advert |= ADVERTISE_PAUSE_ASYM; |
| 1887 | if (lpa & LPA_1000XPAUSE) |
| 1888 | lpa |= LPA_PAUSE_CAP; |
| 1889 | if (lpa & LPA_1000XPAUSE_ASYM) |
| 1890 | lpa |= LPA_PAUSE_ASYM; |
| 1891 | } |
| 1892 | |
| 1893 | sky2->flow_status = FC_NONE; |
| 1894 | if (advert & ADVERTISE_PAUSE_CAP) { |
| 1895 | if (lpa & LPA_PAUSE_CAP) |
| 1896 | sky2->flow_status = FC_BOTH; |
| 1897 | else if (advert & ADVERTISE_PAUSE_ASYM) |
| 1898 | sky2->flow_status = FC_RX; |
| 1899 | } else if (advert & ADVERTISE_PAUSE_ASYM) { |
| 1900 | if ((lpa & LPA_PAUSE_CAP) && (lpa & LPA_PAUSE_ASYM)) |
| 1901 | sky2->flow_status = FC_TX; |
| 1902 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1903 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 1904 | if (sky2->duplex == DUPLEX_HALF && sky2->speed < SPEED_1000 |
Stephen Hemminger | 9374549 | 2007-02-06 10:45:43 -0800 | [diff] [blame] | 1905 | && !(hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX)) |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 1906 | sky2->flow_status = FC_NONE; |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 1907 | |
Stephen Hemminger | da4c1ff | 2007-02-15 16:40:32 -0800 | [diff] [blame] | 1908 | if (sky2->flow_status & FC_TX) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1909 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON); |
| 1910 | else |
| 1911 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); |
| 1912 | |
| 1913 | return 0; |
| 1914 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1915 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1916 | /* Interrupt from PHY */ |
| 1917 | static void sky2_phy_intr(struct sky2_hw *hw, unsigned port) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1918 | { |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1919 | struct net_device *dev = hw->dev[port]; |
| 1920 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1921 | u16 istatus, phystat; |
| 1922 | |
Stephen Hemminger | ebc646f | 2006-10-17 10:23:56 -0700 | [diff] [blame] | 1923 | if (!netif_running(dev)) |
| 1924 | return; |
| 1925 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1926 | spin_lock(&sky2->phy_lock); |
| 1927 | istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT); |
| 1928 | phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT); |
| 1929 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1930 | if (netif_msg_intr(sky2)) |
| 1931 | printk(KERN_INFO PFX "%s: phy interrupt status 0x%x 0x%x\n", |
| 1932 | sky2->netdev->name, istatus, phystat); |
| 1933 | |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 1934 | if (sky2->autoneg == AUTONEG_ENABLE && (istatus & PHY_M_IS_AN_COMPL)) { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1935 | if (sky2_autoneg_done(sky2, phystat) == 0) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1936 | sky2_link_up(sky2); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1937 | goto out; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1940 | if (istatus & PHY_M_IS_LSP_CHANGE) |
| 1941 | sky2->speed = sky2_phy_speed(hw, phystat); |
| 1942 | |
| 1943 | if (istatus & PHY_M_IS_DUP_CHANGE) |
| 1944 | sky2->duplex = |
| 1945 | (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF; |
| 1946 | |
| 1947 | if (istatus & PHY_M_IS_LST_CHANGE) { |
| 1948 | if (phystat & PHY_M_PS_LINK_UP) |
| 1949 | sky2_link_up(sky2); |
| 1950 | else |
| 1951 | sky2_link_down(sky2); |
| 1952 | } |
| 1953 | out: |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1954 | spin_unlock(&sky2->phy_lock); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
Stephen Hemminger | 62335ab | 2007-02-06 10:45:42 -0800 | [diff] [blame] | 1957 | /* Transmit timeout is only called if we are running, carrier is up |
Stephen Hemminger | 302d125 | 2006-01-17 13:43:20 -0800 | [diff] [blame] | 1958 | * and tx queue is full (stopped). |
| 1959 | */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1960 | static void sky2_tx_timeout(struct net_device *dev) |
| 1961 | { |
| 1962 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 8cc048e | 2005-12-09 11:35:07 -0800 | [diff] [blame] | 1963 | struct sky2_hw *hw = sky2->hw; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1964 | |
| 1965 | if (netif_msg_timer(sky2)) |
| 1966 | printk(KERN_ERR PFX "%s: tx timeout\n", dev->name); |
| 1967 | |
Stephen Hemminger | 8f24664 | 2006-03-20 15:48:21 -0800 | [diff] [blame] | 1968 | printk(KERN_DEBUG PFX "%s: transmit ring %u .. %u report=%u done=%u\n", |
Stephen Hemminger | 62335ab | 2007-02-06 10:45:42 -0800 | [diff] [blame] | 1969 | dev->name, sky2->tx_cons, sky2->tx_prod, |
| 1970 | sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX), |
| 1971 | sky2_read16(hw, Q_ADDR(txqaddr[sky2->port], Q_DONE))); |
Stephen Hemminger | 8cc048e | 2005-12-09 11:35:07 -0800 | [diff] [blame] | 1972 | |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 1973 | /* can't restart safely under softirq */ |
| 1974 | schedule_work(&hw->restart_work); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | static int sky2_change_mtu(struct net_device *dev, int new_mtu) |
| 1978 | { |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1979 | struct sky2_port *sky2 = netdev_priv(dev); |
| 1980 | struct sky2_hw *hw = sky2->hw; |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 1981 | unsigned port = sky2->port; |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1982 | int err; |
| 1983 | u16 ctl, mode; |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1984 | u32 imask; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1985 | |
| 1986 | if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU) |
| 1987 | return -EINVAL; |
| 1988 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 1989 | if (new_mtu > ETH_DATA_LEN && |
| 1990 | (hw->chip_id == CHIP_ID_YUKON_FE || |
| 1991 | hw->chip_id == CHIP_ID_YUKON_FE_P)) |
Stephen Hemminger | d2adf4f | 2007-04-11 14:48:02 -0700 | [diff] [blame] | 1992 | return -EINVAL; |
| 1993 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1994 | if (!netif_running(dev)) { |
| 1995 | dev->mtu = new_mtu; |
| 1996 | return 0; |
| 1997 | } |
| 1998 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1999 | imask = sky2_read32(hw, B0_IMSK); |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2000 | sky2_write32(hw, B0_IMSK, 0); |
| 2001 | |
shemminger@osdl.org | 018d1c6 | 2005-11-30 11:45:18 -0800 | [diff] [blame] | 2002 | dev->trans_start = jiffies; /* prevent tx timeout */ |
| 2003 | netif_stop_queue(dev); |
| 2004 | netif_poll_disable(hw->dev[0]); |
| 2005 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2006 | synchronize_irq(hw->pdev->irq); |
| 2007 | |
Stephen Hemminger | e0c2811 | 2007-09-20 13:03:49 -0700 | [diff] [blame^] | 2008 | if (sky2_read8(hw, B2_E_0) == 0) |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 2009 | sky2_set_tx_stfwd(hw, port); |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 2010 | |
| 2011 | ctl = gma_read16(hw, port, GM_GP_CTRL); |
| 2012 | gma_write16(hw, port, GM_GP_CTRL, ctl & ~GM_GPCR_RX_ENA); |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2013 | sky2_rx_stop(sky2); |
| 2014 | sky2_rx_clean(sky2); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2015 | |
| 2016 | dev->mtu = new_mtu; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2017 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2018 | mode = DATA_BLIND_VAL(DATA_BLIND_DEF) | |
| 2019 | GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2020 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2021 | if (dev->mtu > ETH_DATA_LEN) |
| 2022 | mode |= GM_SMOD_JUMBO_ENA; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2023 | |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 2024 | gma_write16(hw, port, GM_SERIAL_MODE, mode); |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2025 | |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 2026 | sky2_write8(hw, RB_ADDR(rxqaddr[port], RB_CTRL), RB_ENA_OP_MD); |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2027 | |
| 2028 | err = sky2_rx_start(sky2); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2029 | sky2_write32(hw, B0_IMSK, imask); |
shemminger@osdl.org | 018d1c6 | 2005-11-30 11:45:18 -0800 | [diff] [blame] | 2030 | |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 2031 | if (err) |
| 2032 | dev_close(dev); |
| 2033 | else { |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 2034 | gma_write16(hw, port, GM_GP_CTRL, ctl); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 2035 | |
| 2036 | netif_poll_enable(hw->dev[0]); |
| 2037 | netif_wake_queue(dev); |
| 2038 | } |
| 2039 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2040 | return err; |
| 2041 | } |
| 2042 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2043 | /* For small just reuse existing skb for next receive */ |
| 2044 | static struct sk_buff *receive_copy(struct sky2_port *sky2, |
| 2045 | const struct rx_ring_info *re, |
| 2046 | unsigned length) |
| 2047 | { |
| 2048 | struct sk_buff *skb; |
| 2049 | |
| 2050 | skb = netdev_alloc_skb(sky2->netdev, length + 2); |
| 2051 | if (likely(skb)) { |
| 2052 | skb_reserve(skb, 2); |
| 2053 | pci_dma_sync_single_for_cpu(sky2->hw->pdev, re->data_addr, |
| 2054 | length, PCI_DMA_FROMDEVICE); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 2055 | skb_copy_from_linear_data(re->skb, skb->data, length); |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2056 | skb->ip_summed = re->skb->ip_summed; |
| 2057 | skb->csum = re->skb->csum; |
| 2058 | pci_dma_sync_single_for_device(sky2->hw->pdev, re->data_addr, |
| 2059 | length, PCI_DMA_FROMDEVICE); |
| 2060 | re->skb->ip_summed = CHECKSUM_NONE; |
Stephen Hemminger | 489b10c | 2006-10-03 16:39:12 -0700 | [diff] [blame] | 2061 | skb_put(skb, length); |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2062 | } |
| 2063 | return skb; |
| 2064 | } |
| 2065 | |
| 2066 | /* Adjust length of skb with fragments to match received data */ |
| 2067 | static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space, |
| 2068 | unsigned int length) |
| 2069 | { |
| 2070 | int i, num_frags; |
| 2071 | unsigned int size; |
| 2072 | |
| 2073 | /* put header into skb */ |
| 2074 | size = min(length, hdr_space); |
| 2075 | skb->tail += size; |
| 2076 | skb->len += size; |
| 2077 | length -= size; |
| 2078 | |
| 2079 | num_frags = skb_shinfo(skb)->nr_frags; |
| 2080 | for (i = 0; i < num_frags; i++) { |
| 2081 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 2082 | |
| 2083 | if (length == 0) { |
| 2084 | /* don't need this page */ |
| 2085 | __free_page(frag->page); |
| 2086 | --skb_shinfo(skb)->nr_frags; |
| 2087 | } else { |
| 2088 | size = min(length, (unsigned) PAGE_SIZE); |
| 2089 | |
| 2090 | frag->size = size; |
| 2091 | skb->data_len += size; |
| 2092 | skb->truesize += size; |
| 2093 | skb->len += size; |
| 2094 | length -= size; |
| 2095 | } |
| 2096 | } |
| 2097 | } |
| 2098 | |
| 2099 | /* Normal packet - take skb from ring element and put in a new one */ |
| 2100 | static struct sk_buff *receive_new(struct sky2_port *sky2, |
| 2101 | struct rx_ring_info *re, |
| 2102 | unsigned int length) |
| 2103 | { |
| 2104 | struct sk_buff *skb, *nskb; |
| 2105 | unsigned hdr_space = sky2->rx_data_size; |
| 2106 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2107 | /* Don't be tricky about reusing pages (yet) */ |
| 2108 | nskb = sky2_rx_alloc(sky2); |
| 2109 | if (unlikely(!nskb)) |
| 2110 | return NULL; |
| 2111 | |
| 2112 | skb = re->skb; |
| 2113 | sky2_rx_unmap_skb(sky2->hw->pdev, re); |
| 2114 | |
| 2115 | prefetch(skb->data); |
| 2116 | re->skb = nskb; |
| 2117 | sky2_rx_map_skb(sky2->hw->pdev, re, hdr_space); |
| 2118 | |
| 2119 | if (skb_shinfo(skb)->nr_frags) |
| 2120 | skb_put_frags(skb, hdr_space, length); |
| 2121 | else |
Stephen Hemminger | 489b10c | 2006-10-03 16:39:12 -0700 | [diff] [blame] | 2122 | skb_put(skb, length); |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2123 | return skb; |
| 2124 | } |
| 2125 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2126 | /* |
| 2127 | * Receive one packet. |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 2128 | * For larger packets, get new buffer. |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2129 | */ |
shemminger@osdl.org | 497d7c8 | 2006-08-28 10:00:46 -0700 | [diff] [blame] | 2130 | static struct sk_buff *sky2_receive(struct net_device *dev, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2131 | u16 length, u32 status) |
| 2132 | { |
shemminger@osdl.org | 497d7c8 | 2006-08-28 10:00:46 -0700 | [diff] [blame] | 2133 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 2134 | struct rx_ring_info *re = sky2->rx_ring + sky2->rx_next; |
Stephen Hemminger | 79e57d3 | 2005-09-19 15:42:33 -0700 | [diff] [blame] | 2135 | struct sk_buff *skb = NULL; |
Stephen Hemminger | d653223 | 2007-09-19 15:36:42 -0700 | [diff] [blame] | 2136 | u16 count = (status & GMR_FS_LEN) >> 16; |
| 2137 | |
| 2138 | #ifdef SKY2_VLAN_TAG_USED |
| 2139 | /* Account for vlan tag */ |
| 2140 | if (sky2->vlgrp && (status & GMR_FS_VLAN)) |
| 2141 | count -= VLAN_HLEN; |
| 2142 | #endif |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2143 | |
| 2144 | if (unlikely(netif_msg_rx_status(sky2))) |
| 2145 | printk(KERN_DEBUG PFX "%s: rx slot %u status 0x%x len %d\n", |
shemminger@osdl.org | 497d7c8 | 2006-08-28 10:00:46 -0700 | [diff] [blame] | 2146 | dev->name, sky2->rx_next, status, length); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2147 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2148 | sky2->rx_next = (sky2->rx_next + 1) % sky2->rx_pending; |
Stephen Hemminger | d70cd51 | 2005-12-09 11:35:09 -0800 | [diff] [blame] | 2149 | prefetch(sky2->rx_ring + sky2->rx_next); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2150 | |
shemminger@osdl.org | 42eeea0 | 2005-11-30 11:45:13 -0800 | [diff] [blame] | 2151 | if (status & GMR_FS_ANY_ERR) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2152 | goto error; |
| 2153 | |
shemminger@osdl.org | 42eeea0 | 2005-11-30 11:45:13 -0800 | [diff] [blame] | 2154 | if (!(status & GMR_FS_RX_OK)) |
| 2155 | goto resubmit; |
| 2156 | |
Stephen Hemminger | d653223 | 2007-09-19 15:36:42 -0700 | [diff] [blame] | 2157 | /* if length reported by DMA does not match PHY, packet was truncated */ |
| 2158 | if (length != count) |
Stephen Hemminger | 7174953 | 2007-07-09 15:33:40 -0700 | [diff] [blame] | 2159 | goto len_mismatch; |
| 2160 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2161 | if (length < copybreak) |
| 2162 | skb = receive_copy(sky2, re, length); |
| 2163 | else |
| 2164 | skb = receive_new(sky2, re, length); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2165 | resubmit: |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2166 | sky2_rx_submit(sky2, re); |
Stephen Hemminger | 79e57d3 | 2005-09-19 15:42:33 -0700 | [diff] [blame] | 2167 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2168 | return skb; |
| 2169 | |
Stephen Hemminger | 7174953 | 2007-07-09 15:33:40 -0700 | [diff] [blame] | 2170 | len_mismatch: |
| 2171 | /* Truncation of overlength packets |
| 2172 | causes PHY length to not match MAC length */ |
| 2173 | ++sky2->net_stats.rx_length_errors; |
Stephen Hemminger | d653223 | 2007-09-19 15:36:42 -0700 | [diff] [blame] | 2174 | if (netif_msg_rx_err(sky2) && net_ratelimit()) |
| 2175 | pr_info(PFX "%s: rx length mismatch: length %d status %#x\n", |
| 2176 | dev->name, length, status); |
| 2177 | goto resubmit; |
Stephen Hemminger | 7174953 | 2007-07-09 15:33:40 -0700 | [diff] [blame] | 2178 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2179 | error: |
Stephen Hemminger | 6e15b71 | 2005-12-20 15:08:09 -0800 | [diff] [blame] | 2180 | ++sky2->net_stats.rx_errors; |
Stephen Hemminger | b6d7773 | 2006-10-17 10:24:16 -0700 | [diff] [blame] | 2181 | if (status & GMR_FS_RX_FF_OV) { |
Stephen Hemminger | a79abdc | 2007-02-15 16:40:34 -0800 | [diff] [blame] | 2182 | sky2->net_stats.rx_over_errors++; |
Stephen Hemminger | b6d7773 | 2006-10-17 10:24:16 -0700 | [diff] [blame] | 2183 | goto resubmit; |
| 2184 | } |
Stephen Hemminger | 6e15b71 | 2005-12-20 15:08:09 -0800 | [diff] [blame] | 2185 | |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2186 | if (netif_msg_rx_err(sky2) && net_ratelimit()) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2187 | printk(KERN_INFO PFX "%s: rx error, status 0x%x length %d\n", |
shemminger@osdl.org | 497d7c8 | 2006-08-28 10:00:46 -0700 | [diff] [blame] | 2188 | dev->name, status, length); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2189 | |
| 2190 | if (status & (GMR_FS_LONG_ERR | GMR_FS_UN_SIZE)) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2191 | sky2->net_stats.rx_length_errors++; |
| 2192 | if (status & GMR_FS_FRAGMENT) |
| 2193 | sky2->net_stats.rx_frame_errors++; |
| 2194 | if (status & GMR_FS_CRC_ERR) |
| 2195 | sky2->net_stats.rx_crc_errors++; |
Stephen Hemminger | 79e57d3 | 2005-09-19 15:42:33 -0700 | [diff] [blame] | 2196 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2197 | goto resubmit; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2198 | } |
| 2199 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2200 | /* Transmit complete */ |
| 2201 | static inline void sky2_tx_done(struct net_device *dev, u16 last) |
Stephen Hemminger | 13b97b7 | 2005-12-09 11:35:03 -0800 | [diff] [blame] | 2202 | { |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2203 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 302d125 | 2006-01-17 13:43:20 -0800 | [diff] [blame] | 2204 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2205 | if (netif_running(dev)) { |
Stephen Hemminger | 2bb8c26 | 2006-09-26 11:57:42 -0700 | [diff] [blame] | 2206 | netif_tx_lock(dev); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2207 | sky2_tx_complete(sky2, last); |
Stephen Hemminger | 2bb8c26 | 2006-09-26 11:57:42 -0700 | [diff] [blame] | 2208 | netif_tx_unlock(dev); |
shemminger@osdl.org | 2224795 | 2005-11-30 11:45:19 -0800 | [diff] [blame] | 2209 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2212 | /* Process status response ring */ |
| 2213 | static int sky2_status_intr(struct sky2_hw *hw, int to_do) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2214 | { |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2215 | int work_done = 0; |
Stephen Hemminger | 55c9dd3 | 2007-07-09 15:33:37 -0700 | [diff] [blame] | 2216 | unsigned rx[2] = { 0, 0 }; |
Stephen Hemminger | e71ebd7 | 2006-05-08 15:11:31 -0700 | [diff] [blame] | 2217 | u16 hwidx = sky2_read16(hw, STAT_PUT_IDX); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2218 | |
Stephen Hemminger | af2a58a | 2005-12-09 11:35:04 -0800 | [diff] [blame] | 2219 | rmb(); |
shemminger@osdl.org | bea8610 | 2005-10-26 12:16:10 -0700 | [diff] [blame] | 2220 | |
Stephen Hemminger | e71ebd7 | 2006-05-08 15:11:31 -0700 | [diff] [blame] | 2221 | while (hw->st_idx != hwidx) { |
Stephen Hemminger | 55c9dd3 | 2007-07-09 15:33:37 -0700 | [diff] [blame] | 2222 | struct sky2_port *sky2; |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2223 | struct sky2_status_le *le = hw->st_le + hw->st_idx; |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 2224 | unsigned port = le->css & CSS_LINK_BIT; |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2225 | struct net_device *dev; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2226 | struct sk_buff *skb; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2227 | u32 status; |
| 2228 | u16 length; |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2229 | |
Stephen Hemminger | cb5d954 | 2006-05-08 15:11:29 -0700 | [diff] [blame] | 2230 | hw->st_idx = RING_NEXT(hw->st_idx, STATUS_RING_SIZE); |
shemminger@osdl.org | bea8610 | 2005-10-26 12:16:10 -0700 | [diff] [blame] | 2231 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 2232 | dev = hw->dev[port]; |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2233 | sky2 = netdev_priv(dev); |
Stephen Hemminger | f65b138 | 2006-09-06 12:45:02 -0700 | [diff] [blame] | 2234 | length = le16_to_cpu(le->length); |
| 2235 | status = le32_to_cpu(le->status); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2236 | |
Stephen Hemminger | e71ebd7 | 2006-05-08 15:11:31 -0700 | [diff] [blame] | 2237 | switch (le->opcode & ~HW_OWNER) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2238 | case OP_RXSTAT: |
Stephen Hemminger | 55c9dd3 | 2007-07-09 15:33:37 -0700 | [diff] [blame] | 2239 | ++rx[port]; |
shemminger@osdl.org | 497d7c8 | 2006-08-28 10:00:46 -0700 | [diff] [blame] | 2240 | skb = sky2_receive(dev, length, status); |
Stephen Hemminger | 3225b91 | 2007-05-14 12:38:12 -0700 | [diff] [blame] | 2241 | if (unlikely(!skb)) { |
| 2242 | sky2->net_stats.rx_dropped++; |
Stephen Hemminger | 55c9dd3 | 2007-07-09 15:33:37 -0700 | [diff] [blame] | 2243 | break; |
Stephen Hemminger | 3225b91 | 2007-05-14 12:38:12 -0700 | [diff] [blame] | 2244 | } |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2245 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 2246 | /* This chip reports checksum status differently */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 2247 | if (hw->flags & SKY2_HW_NEW_LE) { |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 2248 | if (sky2->rx_csum && |
| 2249 | (le->css & (CSS_ISIPV4 | CSS_ISIPV6)) && |
| 2250 | (le->css & CSS_TCPUDPCSOK)) |
| 2251 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2252 | else |
| 2253 | skb->ip_summed = CHECKSUM_NONE; |
| 2254 | } |
| 2255 | |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2256 | skb->protocol = eth_type_trans(skb, dev); |
shemminger@linux-foundation.org | 2bf56fe | 2007-01-26 11:38:39 -0800 | [diff] [blame] | 2257 | sky2->net_stats.rx_packets++; |
| 2258 | sky2->net_stats.rx_bytes += skb->len; |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2259 | dev->last_rx = jiffies; |
| 2260 | |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 2261 | #ifdef SKY2_VLAN_TAG_USED |
| 2262 | if (sky2->vlgrp && (status & GMR_FS_VLAN)) { |
| 2263 | vlan_hwaccel_receive_skb(skb, |
| 2264 | sky2->vlgrp, |
| 2265 | be16_to_cpu(sky2->rx_tag)); |
| 2266 | } else |
| 2267 | #endif |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2268 | netif_receive_skb(skb); |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2269 | |
Stephen Hemminger | 22e1170 | 2006-07-12 15:23:48 -0700 | [diff] [blame] | 2270 | /* Stop after net poll weight */ |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2271 | if (++work_done >= to_do) |
| 2272 | goto exit_loop; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2273 | break; |
| 2274 | |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 2275 | #ifdef SKY2_VLAN_TAG_USED |
| 2276 | case OP_RXVLAN: |
| 2277 | sky2->rx_tag = length; |
| 2278 | break; |
| 2279 | |
| 2280 | case OP_RXCHKSVLAN: |
| 2281 | sky2->rx_tag = length; |
| 2282 | /* fall through */ |
| 2283 | #endif |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2284 | case OP_RXCHKS: |
Stephen Hemminger | 8741830 | 2007-03-08 12:42:30 -0800 | [diff] [blame] | 2285 | if (!sky2->rx_csum) |
| 2286 | break; |
| 2287 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 2288 | /* If this happens then driver assuming wrong format */ |
| 2289 | if (unlikely(hw->flags & SKY2_HW_NEW_LE)) { |
| 2290 | if (net_ratelimit()) |
| 2291 | printk(KERN_NOTICE "%s: unexpected" |
| 2292 | " checksum status\n", |
| 2293 | dev->name); |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 2294 | break; |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 2295 | } |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 2296 | |
Stephen Hemminger | 8741830 | 2007-03-08 12:42:30 -0800 | [diff] [blame] | 2297 | /* Both checksum counters are programmed to start at |
| 2298 | * the same offset, so unless there is a problem they |
| 2299 | * should match. This failure is an early indication that |
| 2300 | * hardware receive checksumming won't work. |
| 2301 | */ |
| 2302 | if (likely(status >> 16 == (status & 0xffff))) { |
| 2303 | skb = sky2->rx_ring[sky2->rx_next].skb; |
| 2304 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 2305 | skb->csum = status & 0xffff; |
| 2306 | } else { |
| 2307 | printk(KERN_NOTICE PFX "%s: hardware receive " |
| 2308 | "checksum problem (status = %#x)\n", |
| 2309 | dev->name, status); |
| 2310 | sky2->rx_csum = 0; |
| 2311 | sky2_write32(sky2->hw, |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 2312 | Q_ADDR(rxqaddr[port], Q_CSR), |
Stephen Hemminger | 8741830 | 2007-03-08 12:42:30 -0800 | [diff] [blame] | 2313 | BMU_DIS_RX_CHKSUM); |
| 2314 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2315 | break; |
| 2316 | |
| 2317 | case OP_TXINDEXLE: |
Stephen Hemminger | 13b97b7 | 2005-12-09 11:35:03 -0800 | [diff] [blame] | 2318 | /* TX index reports status for both ports */ |
Stephen Hemminger | f55925d | 2006-05-08 15:11:28 -0700 | [diff] [blame] | 2319 | BUILD_BUG_ON(TX_RING_SIZE > 0x1000); |
| 2320 | sky2_tx_done(hw->dev[0], status & 0xfff); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2321 | if (hw->dev[1]) |
| 2322 | sky2_tx_done(hw->dev[1], |
| 2323 | ((status >> 24) & 0xff) |
| 2324 | | (u16)(length & 0xf) << 8); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2325 | break; |
| 2326 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2327 | default: |
| 2328 | if (net_ratelimit()) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2329 | printk(KERN_WARNING PFX |
Stephen Hemminger | e71ebd7 | 2006-05-08 15:11:31 -0700 | [diff] [blame] | 2330 | "unknown status opcode 0x%x\n", le->opcode); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2331 | } |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2332 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2333 | |
Stephen Hemminger | fe2a24d | 2006-08-01 11:55:23 -0700 | [diff] [blame] | 2334 | /* Fully processed status ring so clear irq */ |
| 2335 | sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ); |
| 2336 | |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2337 | exit_loop: |
Stephen Hemminger | 55c9dd3 | 2007-07-09 15:33:37 -0700 | [diff] [blame] | 2338 | if (rx[0]) |
| 2339 | sky2_rx_update(netdev_priv(hw->dev[0]), Q_R1); |
Stephen Hemminger | 22e1170 | 2006-07-12 15:23:48 -0700 | [diff] [blame] | 2340 | |
Stephen Hemminger | 55c9dd3 | 2007-07-09 15:33:37 -0700 | [diff] [blame] | 2341 | if (rx[1]) |
| 2342 | sky2_rx_update(netdev_priv(hw->dev[1]), Q_R2); |
Stephen Hemminger | 22e1170 | 2006-07-12 15:23:48 -0700 | [diff] [blame] | 2343 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2344 | return work_done; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | static void sky2_hw_error(struct sky2_hw *hw, unsigned port, u32 status) |
| 2348 | { |
| 2349 | struct net_device *dev = hw->dev[port]; |
| 2350 | |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2351 | if (net_ratelimit()) |
| 2352 | printk(KERN_INFO PFX "%s: hw error interrupt status 0x%x\n", |
| 2353 | dev->name, status); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2354 | |
| 2355 | if (status & Y2_IS_PAR_RD1) { |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2356 | if (net_ratelimit()) |
| 2357 | printk(KERN_ERR PFX "%s: ram data read parity error\n", |
| 2358 | dev->name); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2359 | /* Clear IRQ */ |
| 2360 | sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_RD_PERR); |
| 2361 | } |
| 2362 | |
| 2363 | if (status & Y2_IS_PAR_WR1) { |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2364 | if (net_ratelimit()) |
| 2365 | printk(KERN_ERR PFX "%s: ram data write parity error\n", |
| 2366 | dev->name); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2367 | |
| 2368 | sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_WR_PERR); |
| 2369 | } |
| 2370 | |
| 2371 | if (status & Y2_IS_PAR_MAC1) { |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2372 | if (net_ratelimit()) |
| 2373 | printk(KERN_ERR PFX "%s: MAC parity error\n", dev->name); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2374 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_PE); |
| 2375 | } |
| 2376 | |
| 2377 | if (status & Y2_IS_PAR_RX1) { |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2378 | if (net_ratelimit()) |
| 2379 | printk(KERN_ERR PFX "%s: RX parity error\n", dev->name); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2380 | sky2_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), BMU_CLR_IRQ_PAR); |
| 2381 | } |
| 2382 | |
| 2383 | if (status & Y2_IS_TCP_TXA1) { |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2384 | if (net_ratelimit()) |
| 2385 | printk(KERN_ERR PFX "%s: TCP segmentation error\n", |
| 2386 | dev->name); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2387 | sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_CLR_IRQ_TCP); |
| 2388 | } |
| 2389 | } |
| 2390 | |
| 2391 | static void sky2_hw_intr(struct sky2_hw *hw) |
| 2392 | { |
| 2393 | u32 status = sky2_read32(hw, B0_HWE_ISRC); |
| 2394 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2395 | if (status & Y2_IS_TIST_OV) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2396 | sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2397 | |
| 2398 | if (status & (Y2_IS_MST_ERR | Y2_IS_IRQ_STAT)) { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2399 | u16 pci_err; |
| 2400 | |
Stephen Hemminger | 56a645c | 2006-02-22 11:45:02 -0800 | [diff] [blame] | 2401 | pci_err = sky2_pci_read16(hw, PCI_STATUS); |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2402 | if (net_ratelimit()) |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 2403 | dev_err(&hw->pdev->dev, "PCI hardware error (0x%x)\n", |
| 2404 | pci_err); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2405 | |
| 2406 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
Stephen Hemminger | 56a645c | 2006-02-22 11:45:02 -0800 | [diff] [blame] | 2407 | sky2_pci_write16(hw, PCI_STATUS, |
Stephen Hemminger | 91aeb3e | 2006-09-26 11:57:38 -0700 | [diff] [blame] | 2408 | pci_err | PCI_STATUS_ERROR_BITS); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2409 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
| 2410 | } |
| 2411 | |
| 2412 | if (status & Y2_IS_PCI_EXP) { |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 2413 | /* PCI-Express uncorrectable Error occurred */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2414 | u32 pex_err; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2415 | |
Stephen Hemminger | 7bd656d | 2006-10-09 14:40:38 -0700 | [diff] [blame] | 2416 | pex_err = sky2_pci_read32(hw, PEX_UNC_ERR_STAT); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2417 | |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2418 | if (net_ratelimit()) |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 2419 | dev_err(&hw->pdev->dev, "PCI Express error (0x%x)\n", |
| 2420 | pex_err); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2421 | |
| 2422 | /* clear the interrupt */ |
| 2423 | sky2_write32(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
Stephen Hemminger | 7bd656d | 2006-10-09 14:40:38 -0700 | [diff] [blame] | 2424 | sky2_pci_write32(hw, PEX_UNC_ERR_STAT, |
| 2425 | 0xffffffffUL); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2426 | sky2_write32(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
| 2427 | |
Stephen Hemminger | 7bd656d | 2006-10-09 14:40:38 -0700 | [diff] [blame] | 2428 | if (pex_err & PEX_FATAL_ERRORS) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2429 | u32 hwmsk = sky2_read32(hw, B0_HWE_IMSK); |
| 2430 | hwmsk &= ~Y2_IS_PCI_EXP; |
| 2431 | sky2_write32(hw, B0_HWE_IMSK, hwmsk); |
| 2432 | } |
| 2433 | } |
| 2434 | |
| 2435 | if (status & Y2_HWE_L1_MASK) |
| 2436 | sky2_hw_error(hw, 0, status); |
| 2437 | status >>= 8; |
| 2438 | if (status & Y2_HWE_L1_MASK) |
| 2439 | sky2_hw_error(hw, 1, status); |
| 2440 | } |
| 2441 | |
| 2442 | static void sky2_mac_intr(struct sky2_hw *hw, unsigned port) |
| 2443 | { |
| 2444 | struct net_device *dev = hw->dev[port]; |
| 2445 | struct sky2_port *sky2 = netdev_priv(dev); |
| 2446 | u8 status = sky2_read8(hw, SK_REG(port, GMAC_IRQ_SRC)); |
| 2447 | |
| 2448 | if (netif_msg_intr(sky2)) |
| 2449 | printk(KERN_INFO PFX "%s: mac interrupt status 0x%x\n", |
| 2450 | dev->name, status); |
| 2451 | |
Stephen Hemminger | a3caead | 2007-05-14 12:38:13 -0700 | [diff] [blame] | 2452 | if (status & GM_IS_RX_CO_OV) |
| 2453 | gma_read16(hw, port, GM_RX_IRQ_SRC); |
| 2454 | |
| 2455 | if (status & GM_IS_TX_CO_OV) |
| 2456 | gma_read16(hw, port, GM_TX_IRQ_SRC); |
| 2457 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2458 | if (status & GM_IS_RX_FF_OR) { |
| 2459 | ++sky2->net_stats.rx_fifo_errors; |
| 2460 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO); |
| 2461 | } |
| 2462 | |
| 2463 | if (status & GM_IS_TX_FF_UR) { |
| 2464 | ++sky2->net_stats.tx_fifo_errors; |
| 2465 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU); |
| 2466 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2469 | /* This should never happen it is a bug. */ |
| 2470 | static void sky2_le_error(struct sky2_hw *hw, unsigned port, |
| 2471 | u16 q, unsigned ring_size) |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2472 | { |
| 2473 | struct net_device *dev = hw->dev[port]; |
| 2474 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2475 | unsigned idx; |
| 2476 | const u64 *le = (q == Q_R1 || q == Q_R2) |
| 2477 | ? (u64 *) sky2->rx_le : (u64 *) sky2->tx_le; |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2478 | |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2479 | idx = sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_GET_IDX)); |
| 2480 | printk(KERN_ERR PFX "%s: descriptor error q=%#x get=%u [%llx] put=%u\n", |
| 2481 | dev->name, (unsigned) q, idx, (unsigned long long) le[idx], |
| 2482 | (unsigned) sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX))); |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2483 | |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2484 | sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_IRQ_CHK); |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2485 | } |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2486 | |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2487 | static int sky2_rx_hung(struct net_device *dev) |
| 2488 | { |
| 2489 | struct sky2_port *sky2 = netdev_priv(dev); |
| 2490 | struct sky2_hw *hw = sky2->hw; |
| 2491 | unsigned port = sky2->port; |
| 2492 | unsigned rxq = rxqaddr[port]; |
| 2493 | u32 mac_rp = sky2_read32(hw, SK_REG(port, RX_GMF_RP)); |
| 2494 | u8 mac_lev = sky2_read8(hw, SK_REG(port, RX_GMF_RLEV)); |
| 2495 | u8 fifo_rp = sky2_read8(hw, Q_ADDR(rxq, Q_RP)); |
| 2496 | u8 fifo_lev = sky2_read8(hw, Q_ADDR(rxq, Q_RL)); |
| 2497 | |
| 2498 | /* If idle and MAC or PCI is stuck */ |
| 2499 | if (sky2->check.last == dev->last_rx && |
| 2500 | ((mac_rp == sky2->check.mac_rp && |
| 2501 | mac_lev != 0 && mac_lev >= sky2->check.mac_lev) || |
| 2502 | /* Check if the PCI RX hang */ |
| 2503 | (fifo_rp == sky2->check.fifo_rp && |
| 2504 | fifo_lev != 0 && fifo_lev >= sky2->check.fifo_lev))) { |
| 2505 | printk(KERN_DEBUG PFX "%s: hung mac %d:%d fifo %d (%d:%d)\n", |
| 2506 | dev->name, mac_lev, mac_rp, fifo_lev, fifo_rp, |
| 2507 | sky2_read8(hw, Q_ADDR(rxq, Q_WP))); |
| 2508 | return 1; |
| 2509 | } else { |
| 2510 | sky2->check.last = dev->last_rx; |
| 2511 | sky2->check.mac_rp = mac_rp; |
| 2512 | sky2->check.mac_lev = mac_lev; |
| 2513 | sky2->check.fifo_rp = fifo_rp; |
| 2514 | sky2->check.fifo_lev = fifo_lev; |
| 2515 | return 0; |
| 2516 | } |
| 2517 | } |
| 2518 | |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 2519 | static void sky2_watchdog(unsigned long arg) |
Stephen Hemminger | d27ed38 | 2006-04-25 10:58:51 -0700 | [diff] [blame] | 2520 | { |
Stephen Hemminger | 01bd756 | 2006-05-08 15:11:30 -0700 | [diff] [blame] | 2521 | struct sky2_hw *hw = (struct sky2_hw *) arg; |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2522 | struct net_device *dev; |
Stephen Hemminger | d27ed38 | 2006-04-25 10:58:51 -0700 | [diff] [blame] | 2523 | |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2524 | /* Check for lost IRQ once a second */ |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 2525 | if (sky2_read32(hw, B0_ISRC)) { |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2526 | dev = hw->dev[0]; |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 2527 | if (__netif_rx_schedule_prep(dev)) |
| 2528 | __netif_rx_schedule(dev); |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2529 | } else { |
| 2530 | int i, active = 0; |
| 2531 | |
| 2532 | for (i = 0; i < hw->ports; i++) { |
| 2533 | dev = hw->dev[i]; |
| 2534 | if (!netif_running(dev)) |
| 2535 | continue; |
| 2536 | ++active; |
| 2537 | |
| 2538 | /* For chips with Rx FIFO, check if stuck */ |
Stephen Hemminger | e0c2811 | 2007-09-20 13:03:49 -0700 | [diff] [blame^] | 2539 | if ((hw->flags & SKY2_HW_FIFO_HANG_CHECK) && |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2540 | sky2_rx_hung(dev)) { |
| 2541 | pr_info(PFX "%s: receiver hang detected\n", |
| 2542 | dev->name); |
| 2543 | schedule_work(&hw->restart_work); |
| 2544 | return; |
| 2545 | } |
| 2546 | } |
| 2547 | |
| 2548 | if (active == 0) |
| 2549 | return; |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 2550 | } |
| 2551 | |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2552 | mod_timer(&hw->watchdog_timer, round_jiffies(jiffies + HZ)); |
Stephen Hemminger | d27ed38 | 2006-04-25 10:58:51 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2555 | /* Hardware/software error handling */ |
| 2556 | static void sky2_err_intr(struct sky2_hw *hw, u32 status) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2557 | { |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2558 | if (net_ratelimit()) |
| 2559 | dev_warn(&hw->pdev->dev, "error interrupt status=%#x\n", status); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2560 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2561 | if (status & Y2_IS_HW_ERR) |
| 2562 | sky2_hw_intr(hw); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2563 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2564 | if (status & Y2_IS_IRQ_MAC1) |
| 2565 | sky2_mac_intr(hw, 0); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2566 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2567 | if (status & Y2_IS_IRQ_MAC2) |
| 2568 | sky2_mac_intr(hw, 1); |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2569 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2570 | if (status & Y2_IS_CHK_RX1) |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2571 | sky2_le_error(hw, 0, Q_R1, RX_LE_SIZE); |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2572 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2573 | if (status & Y2_IS_CHK_RX2) |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2574 | sky2_le_error(hw, 1, Q_R2, RX_LE_SIZE); |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2575 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2576 | if (status & Y2_IS_CHK_TXA1) |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2577 | sky2_le_error(hw, 0, Q_XA1, TX_RING_SIZE); |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2578 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2579 | if (status & Y2_IS_CHK_TXA2) |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2580 | sky2_le_error(hw, 1, Q_XA2, TX_RING_SIZE); |
| 2581 | } |
| 2582 | |
| 2583 | static int sky2_poll(struct net_device *dev0, int *budget) |
| 2584 | { |
| 2585 | struct sky2_hw *hw = ((struct sky2_port *) netdev_priv(dev0))->hw; |
Stephen Hemminger | 5c11ce7 | 2007-07-09 15:33:36 -0700 | [diff] [blame] | 2586 | int work_done; |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2587 | u32 status = sky2_read32(hw, B0_Y2_SP_EISR); |
| 2588 | |
| 2589 | if (unlikely(status & Y2_IS_ERROR)) |
| 2590 | sky2_err_intr(hw, status); |
| 2591 | |
| 2592 | if (status & Y2_IS_IRQ_PHY1) |
| 2593 | sky2_phy_intr(hw, 0); |
| 2594 | |
| 2595 | if (status & Y2_IS_IRQ_PHY2) |
| 2596 | sky2_phy_intr(hw, 1); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2597 | |
Stephen Hemminger | 5c11ce7 | 2007-07-09 15:33:36 -0700 | [diff] [blame] | 2598 | work_done = sky2_status_intr(hw, min(dev0->quota, *budget)); |
| 2599 | *budget -= work_done; |
| 2600 | dev0->quota -= work_done; |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2601 | |
Stephen Hemminger | 5c11ce7 | 2007-07-09 15:33:36 -0700 | [diff] [blame] | 2602 | /* More work? */ |
| 2603 | if (hw->st_idx != sky2_read16(hw, STAT_PUT_IDX)) |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2604 | return 1; |
Stephen Hemminger | 5c11ce7 | 2007-07-09 15:33:36 -0700 | [diff] [blame] | 2605 | |
| 2606 | /* Bug/Errata workaround? |
| 2607 | * Need to kick the TX irq moderation timer. |
| 2608 | */ |
| 2609 | if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_START) { |
| 2610 | sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP); |
| 2611 | sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START); |
Stephen Hemminger | fe2a24d | 2006-08-01 11:55:23 -0700 | [diff] [blame] | 2612 | } |
Stephen Hemminger | 5c11ce7 | 2007-07-09 15:33:36 -0700 | [diff] [blame] | 2613 | netif_rx_complete(dev0); |
| 2614 | |
| 2615 | sky2_read32(hw, B0_Y2_SP_LISR); |
| 2616 | return 0; |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2617 | } |
| 2618 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 2619 | static irqreturn_t sky2_intr(int irq, void *dev_id) |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2620 | { |
| 2621 | struct sky2_hw *hw = dev_id; |
| 2622 | struct net_device *dev0 = hw->dev[0]; |
| 2623 | u32 status; |
| 2624 | |
| 2625 | /* Reading this mask interrupts as side effect */ |
| 2626 | status = sky2_read32(hw, B0_Y2_SP_ISRC2); |
| 2627 | if (status == 0 || status == ~0) |
| 2628 | return IRQ_NONE; |
| 2629 | |
| 2630 | prefetch(&hw->st_le[hw->st_idx]); |
| 2631 | if (likely(__netif_rx_schedule_prep(dev0))) |
| 2632 | __netif_rx_schedule(dev0); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2633 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2634 | return IRQ_HANDLED; |
| 2635 | } |
| 2636 | |
| 2637 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2638 | static void sky2_netpoll(struct net_device *dev) |
| 2639 | { |
| 2640 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 88d1136 | 2006-06-16 12:10:46 -0700 | [diff] [blame] | 2641 | struct net_device *dev0 = sky2->hw->dev[0]; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2642 | |
Stephen Hemminger | 88d1136 | 2006-06-16 12:10:46 -0700 | [diff] [blame] | 2643 | if (netif_running(dev) && __netif_rx_schedule_prep(dev0)) |
| 2644 | __netif_rx_schedule(dev0); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2645 | } |
| 2646 | #endif |
| 2647 | |
| 2648 | /* Chip internal frequency for clock calculations */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 2649 | static u32 sky2_mhz(const struct sky2_hw *hw) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2650 | { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2651 | switch (hw->chip_id) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2652 | case CHIP_ID_YUKON_EC: |
shemminger@osdl.org | 5a5b1ea | 2005-11-30 11:45:15 -0800 | [diff] [blame] | 2653 | case CHIP_ID_YUKON_EC_U: |
Stephen Hemminger | 9374549 | 2007-02-06 10:45:43 -0800 | [diff] [blame] | 2654 | case CHIP_ID_YUKON_EX: |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 2655 | return 125; |
| 2656 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2657 | case CHIP_ID_YUKON_FE: |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 2658 | return 100; |
| 2659 | |
| 2660 | case CHIP_ID_YUKON_FE_P: |
| 2661 | return 50; |
| 2662 | |
| 2663 | case CHIP_ID_YUKON_XL: |
| 2664 | return 156; |
| 2665 | |
| 2666 | default: |
| 2667 | BUG(); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2668 | } |
| 2669 | } |
| 2670 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2671 | static inline u32 sky2_us2clk(const struct sky2_hw *hw, u32 us) |
| 2672 | { |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 2673 | return sky2_mhz(hw) * us; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 2676 | static inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk) |
| 2677 | { |
| 2678 | return clk / sky2_mhz(hw); |
| 2679 | } |
| 2680 | |
| 2681 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 2682 | static int __devinit sky2_init(struct sky2_hw *hw) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2683 | { |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 2684 | u8 t8; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2685 | |
Stephen Hemminger | 451af33 | 2007-06-04 17:23:24 -0700 | [diff] [blame] | 2686 | /* Enable all clocks */ |
| 2687 | sky2_pci_write32(hw, PCI_DEV_REG3, 0); |
| 2688 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2689 | sky2_write8(hw, B0_CTST, CS_RST_CLR); |
Stephen Hemminger | 08c06d8 | 2006-01-30 11:37:54 -0800 | [diff] [blame] | 2690 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2691 | hw->chip_id = sky2_read8(hw, B2_CHIP_ID); |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 2692 | hw->chip_rev = (sky2_read8(hw, B2_MAC_CFG) & CFG_CHIP_R_MSK) >> 4; |
| 2693 | |
| 2694 | switch(hw->chip_id) { |
| 2695 | case CHIP_ID_YUKON_XL: |
| 2696 | hw->flags = SKY2_HW_GIGABIT |
Stephen Hemminger | e0c2811 | 2007-09-20 13:03:49 -0700 | [diff] [blame^] | 2697 | | SKY2_HW_NEWER_PHY; |
| 2698 | if (hw->chip_rev < 3) |
| 2699 | hw->flags |= SKY2_HW_FIFO_HANG_CHECK; |
| 2700 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 2701 | break; |
| 2702 | |
| 2703 | case CHIP_ID_YUKON_EC_U: |
| 2704 | hw->flags = SKY2_HW_GIGABIT |
| 2705 | | SKY2_HW_NEWER_PHY |
| 2706 | | SKY2_HW_ADV_POWER_CTL; |
| 2707 | break; |
| 2708 | |
| 2709 | case CHIP_ID_YUKON_EX: |
| 2710 | hw->flags = SKY2_HW_GIGABIT |
| 2711 | | SKY2_HW_NEWER_PHY |
| 2712 | | SKY2_HW_NEW_LE |
| 2713 | | SKY2_HW_ADV_POWER_CTL; |
| 2714 | |
| 2715 | /* New transmit checksum */ |
| 2716 | if (hw->chip_rev != CHIP_REV_YU_EX_B0) |
| 2717 | hw->flags |= SKY2_HW_AUTO_TX_SUM; |
| 2718 | break; |
| 2719 | |
| 2720 | case CHIP_ID_YUKON_EC: |
| 2721 | /* This rev is really old, and requires untested workarounds */ |
| 2722 | if (hw->chip_rev == CHIP_REV_YU_EC_A1) { |
| 2723 | dev_err(&hw->pdev->dev, "unsupported revision Yukon-EC rev A1\n"); |
| 2724 | return -EOPNOTSUPP; |
| 2725 | } |
Stephen Hemminger | e0c2811 | 2007-09-20 13:03:49 -0700 | [diff] [blame^] | 2726 | hw->flags = SKY2_HW_GIGABIT | SKY2_HW_FIFO_HANG_CHECK; |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 2727 | break; |
| 2728 | |
| 2729 | case CHIP_ID_YUKON_FE: |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 2730 | break; |
| 2731 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 2732 | case CHIP_ID_YUKON_FE_P: |
| 2733 | hw->flags = SKY2_HW_NEWER_PHY |
| 2734 | | SKY2_HW_NEW_LE |
| 2735 | | SKY2_HW_AUTO_TX_SUM |
| 2736 | | SKY2_HW_ADV_POWER_CTL; |
| 2737 | break; |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 2738 | default: |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 2739 | dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n", |
| 2740 | hw->chip_id); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2741 | return -EOPNOTSUPP; |
| 2742 | } |
| 2743 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 2744 | hw->pmd_type = sky2_read8(hw, B2_PMD_TYP); |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 2745 | if (hw->pmd_type == 'L' || hw->pmd_type == 'S' || hw->pmd_type == 'P') |
| 2746 | hw->flags |= SKY2_HW_FIBRE_PHY; |
| 2747 | |
| 2748 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 2749 | hw->ports = 1; |
| 2750 | t8 = sky2_read8(hw, B2_Y2_HW_RES); |
| 2751 | if ((t8 & CFG_DUAL_MAC_MSK) == CFG_DUAL_MAC_MSK) { |
| 2752 | if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC)) |
| 2753 | ++hw->ports; |
| 2754 | } |
| 2755 | |
| 2756 | return 0; |
| 2757 | } |
| 2758 | |
| 2759 | static void sky2_reset(struct sky2_hw *hw) |
| 2760 | { |
| 2761 | u16 status; |
| 2762 | int i; |
| 2763 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2764 | /* disable ASF */ |
Stephen Hemminger | 4f44d8b | 2007-04-11 14:48:00 -0700 | [diff] [blame] | 2765 | if (hw->chip_id == CHIP_ID_YUKON_EX) { |
| 2766 | status = sky2_read16(hw, HCU_CCSR); |
| 2767 | status &= ~(HCU_CCSR_AHB_RST | HCU_CCSR_CPU_RST_MODE | |
| 2768 | HCU_CCSR_UC_STATE_MSK); |
| 2769 | sky2_write16(hw, HCU_CCSR, status); |
| 2770 | } else |
| 2771 | sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET); |
| 2772 | sky2_write16(hw, B0_CTST, Y2_ASF_DISABLE); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2773 | |
| 2774 | /* do a SW reset */ |
| 2775 | sky2_write8(hw, B0_CTST, CS_RST_SET); |
| 2776 | sky2_write8(hw, B0_CTST, CS_RST_CLR); |
| 2777 | |
| 2778 | /* clear PCI errors, if any */ |
Stephen Hemminger | 56a645c | 2006-02-22 11:45:02 -0800 | [diff] [blame] | 2779 | status = sky2_pci_read16(hw, PCI_STATUS); |
Stephen Hemminger | 2d42d21 | 2006-01-30 11:37:55 -0800 | [diff] [blame] | 2780 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2781 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
Stephen Hemminger | 56a645c | 2006-02-22 11:45:02 -0800 | [diff] [blame] | 2782 | sky2_pci_write16(hw, PCI_STATUS, status | PCI_STATUS_ERROR_BITS); |
| 2783 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2784 | |
| 2785 | sky2_write8(hw, B0_CTST, CS_MRST_CLR); |
| 2786 | |
| 2787 | /* clear any PEX errors */ |
Stephen Hemminger | 7bd656d | 2006-10-09 14:40:38 -0700 | [diff] [blame] | 2788 | if (pci_find_capability(hw->pdev, PCI_CAP_ID_EXP)) |
| 2789 | sky2_pci_write32(hw, PEX_UNC_ERR_STAT, 0xffffffffUL); |
| 2790 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2791 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 2792 | sky2_power_on(hw); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2793 | |
| 2794 | for (i = 0; i < hw->ports; i++) { |
| 2795 | sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET); |
| 2796 | sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR); |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 2797 | |
| 2798 | if (hw->chip_id == CHIP_ID_YUKON_EX) |
| 2799 | sky2_write16(hw, SK_REG(i, GMAC_CTRL), |
| 2800 | GMC_BYP_MACSECRX_ON | GMC_BYP_MACSECTX_ON |
| 2801 | | GMC_BYP_RETR_ON); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
| 2805 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2806 | /* Clear I2C IRQ noise */ |
| 2807 | sky2_write32(hw, B2_I2C_IRQ, 1); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2808 | |
| 2809 | /* turn off hardware timer (unused) */ |
| 2810 | sky2_write8(hw, B2_TI_CTRL, TIM_STOP); |
| 2811 | sky2_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2812 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2813 | sky2_write8(hw, B0_Y2LED, LED_STAT_ON); |
| 2814 | |
Stephen Hemminger | 69634ee | 2005-12-09 11:35:06 -0800 | [diff] [blame] | 2815 | /* Turn off descriptor polling */ |
| 2816 | sky2_write32(hw, B28_DPT_CTRL, DPT_STOP); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2817 | |
| 2818 | /* Turn off receive timestamp */ |
| 2819 | sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_STOP); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2820 | sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2821 | |
| 2822 | /* enable the Tx Arbiters */ |
| 2823 | for (i = 0; i < hw->ports; i++) |
| 2824 | sky2_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB); |
| 2825 | |
| 2826 | /* Initialize ram interface */ |
| 2827 | for (i = 0; i < hw->ports; i++) { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2828 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_CTRL), RI_RST_CLR); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2829 | |
| 2830 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R1), SK_RI_TO_53); |
| 2831 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA1), SK_RI_TO_53); |
| 2832 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS1), SK_RI_TO_53); |
| 2833 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R1), SK_RI_TO_53); |
| 2834 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA1), SK_RI_TO_53); |
| 2835 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS1), SK_RI_TO_53); |
| 2836 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R2), SK_RI_TO_53); |
| 2837 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA2), SK_RI_TO_53); |
| 2838 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS2), SK_RI_TO_53); |
| 2839 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R2), SK_RI_TO_53); |
| 2840 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA2), SK_RI_TO_53); |
| 2841 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS2), SK_RI_TO_53); |
| 2842 | } |
| 2843 | |
Stephen Hemminger | 7bd656d | 2006-10-09 14:40:38 -0700 | [diff] [blame] | 2844 | sky2_write32(hw, B0_HWE_IMSK, Y2_HWE_ALL_MASK); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2845 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2846 | for (i = 0; i < hw->ports; i++) |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 2847 | sky2_gmac_reset(hw, i); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2848 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2849 | memset(hw->st_le, 0, STATUS_LE_BYTES); |
| 2850 | hw->st_idx = 0; |
| 2851 | |
| 2852 | sky2_write32(hw, STAT_CTRL, SC_STAT_RST_SET); |
| 2853 | sky2_write32(hw, STAT_CTRL, SC_STAT_RST_CLR); |
| 2854 | |
| 2855 | sky2_write32(hw, STAT_LIST_ADDR_LO, hw->st_dma); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2856 | sky2_write32(hw, STAT_LIST_ADDR_HI, (u64) hw->st_dma >> 32); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2857 | |
| 2858 | /* Set the list last index */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2859 | sky2_write16(hw, STAT_LAST_IDX, STATUS_RING_SIZE - 1); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2860 | |
Stephen Hemminger | 290d4de | 2006-03-20 15:48:15 -0800 | [diff] [blame] | 2861 | sky2_write16(hw, STAT_TX_IDX_TH, 10); |
| 2862 | sky2_write8(hw, STAT_FIFO_WM, 16); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2863 | |
Stephen Hemminger | 290d4de | 2006-03-20 15:48:15 -0800 | [diff] [blame] | 2864 | /* set Status-FIFO ISR watermark */ |
| 2865 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0) |
| 2866 | sky2_write8(hw, STAT_FIFO_ISR_WM, 4); |
| 2867 | else |
| 2868 | sky2_write8(hw, STAT_FIFO_ISR_WM, 16); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2869 | |
Stephen Hemminger | 290d4de | 2006-03-20 15:48:15 -0800 | [diff] [blame] | 2870 | sky2_write32(hw, STAT_TX_TIMER_INI, sky2_us2clk(hw, 1000)); |
Stephen Hemminger | 77b3d6a | 2006-03-20 15:48:18 -0800 | [diff] [blame] | 2871 | sky2_write32(hw, STAT_ISR_TIMER_INI, sky2_us2clk(hw, 20)); |
| 2872 | sky2_write32(hw, STAT_LEV_TIMER_INI, sky2_us2clk(hw, 100)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2873 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2874 | /* enable status unit */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2875 | sky2_write32(hw, STAT_CTRL, SC_STAT_OP_ON); |
| 2876 | |
| 2877 | sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START); |
| 2878 | sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START); |
| 2879 | sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START); |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 2880 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2881 | |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 2882 | static void sky2_restart(struct work_struct *work) |
| 2883 | { |
| 2884 | struct sky2_hw *hw = container_of(work, struct sky2_hw, restart_work); |
| 2885 | struct net_device *dev; |
| 2886 | int i, err; |
| 2887 | |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 2888 | rtnl_lock(); |
| 2889 | sky2_write32(hw, B0_IMSK, 0); |
| 2890 | sky2_read32(hw, B0_IMSK); |
| 2891 | |
| 2892 | netif_poll_disable(hw->dev[0]); |
| 2893 | |
| 2894 | for (i = 0; i < hw->ports; i++) { |
| 2895 | dev = hw->dev[i]; |
| 2896 | if (netif_running(dev)) |
| 2897 | sky2_down(dev); |
| 2898 | } |
| 2899 | |
| 2900 | sky2_reset(hw); |
| 2901 | sky2_write32(hw, B0_IMSK, Y2_IS_BASE); |
| 2902 | netif_poll_enable(hw->dev[0]); |
| 2903 | |
| 2904 | for (i = 0; i < hw->ports; i++) { |
| 2905 | dev = hw->dev[i]; |
| 2906 | if (netif_running(dev)) { |
| 2907 | err = sky2_up(dev); |
| 2908 | if (err) { |
| 2909 | printk(KERN_INFO PFX "%s: could not restart %d\n", |
| 2910 | dev->name, err); |
| 2911 | dev_close(dev); |
| 2912 | } |
| 2913 | } |
| 2914 | } |
| 2915 | |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 2916 | rtnl_unlock(); |
| 2917 | } |
| 2918 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 2919 | static inline u8 sky2_wol_supported(const struct sky2_hw *hw) |
| 2920 | { |
| 2921 | return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0; |
| 2922 | } |
| 2923 | |
| 2924 | static void sky2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 2925 | { |
| 2926 | const struct sky2_port *sky2 = netdev_priv(dev); |
| 2927 | |
| 2928 | wol->supported = sky2_wol_supported(sky2->hw); |
| 2929 | wol->wolopts = sky2->wol; |
| 2930 | } |
| 2931 | |
| 2932 | static int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 2933 | { |
| 2934 | struct sky2_port *sky2 = netdev_priv(dev); |
| 2935 | struct sky2_hw *hw = sky2->hw; |
| 2936 | |
| 2937 | if (wol->wolopts & ~sky2_wol_supported(sky2->hw)) |
| 2938 | return -EOPNOTSUPP; |
| 2939 | |
| 2940 | sky2->wol = wol->wolopts; |
| 2941 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 2942 | if (hw->chip_id == CHIP_ID_YUKON_EC_U || |
| 2943 | hw->chip_id == CHIP_ID_YUKON_EX || |
| 2944 | hw->chip_id == CHIP_ID_YUKON_FE_P) |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 2945 | sky2_write32(hw, B0_CTST, sky2->wol |
| 2946 | ? Y2_HW_WOL_ON : Y2_HW_WOL_OFF); |
| 2947 | |
| 2948 | if (!netif_running(dev)) |
| 2949 | sky2_wol_init(sky2); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2950 | return 0; |
| 2951 | } |
| 2952 | |
Stephen Hemminger | 28bd181 | 2006-01-17 13:43:19 -0800 | [diff] [blame] | 2953 | static u32 sky2_supported_modes(const struct sky2_hw *hw) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2954 | { |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 2955 | if (sky2_is_copper(hw)) { |
| 2956 | u32 modes = SUPPORTED_10baseT_Half |
| 2957 | | SUPPORTED_10baseT_Full |
| 2958 | | SUPPORTED_100baseT_Half |
| 2959 | | SUPPORTED_100baseT_Full |
| 2960 | | SUPPORTED_Autoneg | SUPPORTED_TP; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2961 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 2962 | if (hw->flags & SKY2_HW_GIGABIT) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2963 | modes |= SUPPORTED_1000baseT_Half |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 2964 | | SUPPORTED_1000baseT_Full; |
| 2965 | return modes; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2966 | } else |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 2967 | return SUPPORTED_1000baseT_Half |
| 2968 | | SUPPORTED_1000baseT_Full |
| 2969 | | SUPPORTED_Autoneg |
| 2970 | | SUPPORTED_FIBRE; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2971 | } |
| 2972 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2973 | static int sky2_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2974 | { |
| 2975 | struct sky2_port *sky2 = netdev_priv(dev); |
| 2976 | struct sky2_hw *hw = sky2->hw; |
| 2977 | |
| 2978 | ecmd->transceiver = XCVR_INTERNAL; |
| 2979 | ecmd->supported = sky2_supported_modes(hw); |
| 2980 | ecmd->phy_address = PHY_ADDR_MARV; |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 2981 | if (sky2_is_copper(hw)) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2982 | ecmd->port = PORT_TP; |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 2983 | ecmd->speed = sky2->speed; |
| 2984 | } else { |
| 2985 | ecmd->speed = SPEED_1000; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2986 | ecmd->port = PORT_FIBRE; |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 2987 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2988 | |
| 2989 | ecmd->advertising = sky2->advertising; |
| 2990 | ecmd->autoneg = sky2->autoneg; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2991 | ecmd->duplex = sky2->duplex; |
| 2992 | return 0; |
| 2993 | } |
| 2994 | |
| 2995 | static int sky2_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 2996 | { |
| 2997 | struct sky2_port *sky2 = netdev_priv(dev); |
| 2998 | const struct sky2_hw *hw = sky2->hw; |
| 2999 | u32 supported = sky2_supported_modes(hw); |
| 3000 | |
| 3001 | if (ecmd->autoneg == AUTONEG_ENABLE) { |
| 3002 | ecmd->advertising = supported; |
| 3003 | sky2->duplex = -1; |
| 3004 | sky2->speed = -1; |
| 3005 | } else { |
| 3006 | u32 setting; |
| 3007 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3008 | switch (ecmd->speed) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3009 | case SPEED_1000: |
| 3010 | if (ecmd->duplex == DUPLEX_FULL) |
| 3011 | setting = SUPPORTED_1000baseT_Full; |
| 3012 | else if (ecmd->duplex == DUPLEX_HALF) |
| 3013 | setting = SUPPORTED_1000baseT_Half; |
| 3014 | else |
| 3015 | return -EINVAL; |
| 3016 | break; |
| 3017 | case SPEED_100: |
| 3018 | if (ecmd->duplex == DUPLEX_FULL) |
| 3019 | setting = SUPPORTED_100baseT_Full; |
| 3020 | else if (ecmd->duplex == DUPLEX_HALF) |
| 3021 | setting = SUPPORTED_100baseT_Half; |
| 3022 | else |
| 3023 | return -EINVAL; |
| 3024 | break; |
| 3025 | |
| 3026 | case SPEED_10: |
| 3027 | if (ecmd->duplex == DUPLEX_FULL) |
| 3028 | setting = SUPPORTED_10baseT_Full; |
| 3029 | else if (ecmd->duplex == DUPLEX_HALF) |
| 3030 | setting = SUPPORTED_10baseT_Half; |
| 3031 | else |
| 3032 | return -EINVAL; |
| 3033 | break; |
| 3034 | default: |
| 3035 | return -EINVAL; |
| 3036 | } |
| 3037 | |
| 3038 | if ((setting & supported) == 0) |
| 3039 | return -EINVAL; |
| 3040 | |
| 3041 | sky2->speed = ecmd->speed; |
| 3042 | sky2->duplex = ecmd->duplex; |
| 3043 | } |
| 3044 | |
| 3045 | sky2->autoneg = ecmd->autoneg; |
| 3046 | sky2->advertising = ecmd->advertising; |
| 3047 | |
Stephen Hemminger | d1b139c | 2007-09-05 16:56:19 +0100 | [diff] [blame] | 3048 | if (netif_running(dev)) { |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 3049 | sky2_phy_reinit(sky2); |
Stephen Hemminger | d1b139c | 2007-09-05 16:56:19 +0100 | [diff] [blame] | 3050 | sky2_set_multicast(dev); |
| 3051 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3052 | |
| 3053 | return 0; |
| 3054 | } |
| 3055 | |
| 3056 | static void sky2_get_drvinfo(struct net_device *dev, |
| 3057 | struct ethtool_drvinfo *info) |
| 3058 | { |
| 3059 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3060 | |
| 3061 | strcpy(info->driver, DRV_NAME); |
| 3062 | strcpy(info->version, DRV_VERSION); |
| 3063 | strcpy(info->fw_version, "N/A"); |
| 3064 | strcpy(info->bus_info, pci_name(sky2->hw->pdev)); |
| 3065 | } |
| 3066 | |
| 3067 | static const struct sky2_stat { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3068 | char name[ETH_GSTRING_LEN]; |
| 3069 | u16 offset; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3070 | } sky2_stats[] = { |
| 3071 | { "tx_bytes", GM_TXO_OK_HI }, |
| 3072 | { "rx_bytes", GM_RXO_OK_HI }, |
| 3073 | { "tx_broadcast", GM_TXF_BC_OK }, |
| 3074 | { "rx_broadcast", GM_RXF_BC_OK }, |
| 3075 | { "tx_multicast", GM_TXF_MC_OK }, |
| 3076 | { "rx_multicast", GM_RXF_MC_OK }, |
| 3077 | { "tx_unicast", GM_TXF_UC_OK }, |
| 3078 | { "rx_unicast", GM_RXF_UC_OK }, |
| 3079 | { "tx_mac_pause", GM_TXF_MPAUSE }, |
| 3080 | { "rx_mac_pause", GM_RXF_MPAUSE }, |
Stephen Hemminger | eadfa7dd | 2006-03-22 10:38:45 -0800 | [diff] [blame] | 3081 | { "collisions", GM_TXF_COL }, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3082 | { "late_collision",GM_TXF_LAT_COL }, |
| 3083 | { "aborted", GM_TXF_ABO_COL }, |
Stephen Hemminger | eadfa7dd | 2006-03-22 10:38:45 -0800 | [diff] [blame] | 3084 | { "single_collisions", GM_TXF_SNG_COL }, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3085 | { "multi_collisions", GM_TXF_MUL_COL }, |
Stephen Hemminger | eadfa7dd | 2006-03-22 10:38:45 -0800 | [diff] [blame] | 3086 | |
Stephen Hemminger | d260454 | 2006-03-23 08:51:36 -0800 | [diff] [blame] | 3087 | { "rx_short", GM_RXF_SHT }, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3088 | { "rx_runt", GM_RXE_FRAG }, |
Stephen Hemminger | eadfa7dd | 2006-03-22 10:38:45 -0800 | [diff] [blame] | 3089 | { "rx_64_byte_packets", GM_RXF_64B }, |
| 3090 | { "rx_65_to_127_byte_packets", GM_RXF_127B }, |
| 3091 | { "rx_128_to_255_byte_packets", GM_RXF_255B }, |
| 3092 | { "rx_256_to_511_byte_packets", GM_RXF_511B }, |
| 3093 | { "rx_512_to_1023_byte_packets", GM_RXF_1023B }, |
| 3094 | { "rx_1024_to_1518_byte_packets", GM_RXF_1518B }, |
| 3095 | { "rx_1518_to_max_byte_packets", GM_RXF_MAX_SZ }, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3096 | { "rx_too_long", GM_RXF_LNG_ERR }, |
Stephen Hemminger | eadfa7dd | 2006-03-22 10:38:45 -0800 | [diff] [blame] | 3097 | { "rx_fifo_overflow", GM_RXE_FIFO_OV }, |
| 3098 | { "rx_jabber", GM_RXF_JAB_PKT }, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3099 | { "rx_fcs_error", GM_RXF_FCS_ERR }, |
Stephen Hemminger | eadfa7dd | 2006-03-22 10:38:45 -0800 | [diff] [blame] | 3100 | |
| 3101 | { "tx_64_byte_packets", GM_TXF_64B }, |
| 3102 | { "tx_65_to_127_byte_packets", GM_TXF_127B }, |
| 3103 | { "tx_128_to_255_byte_packets", GM_TXF_255B }, |
| 3104 | { "tx_256_to_511_byte_packets", GM_TXF_511B }, |
| 3105 | { "tx_512_to_1023_byte_packets", GM_TXF_1023B }, |
| 3106 | { "tx_1024_to_1518_byte_packets", GM_TXF_1518B }, |
| 3107 | { "tx_1519_to_max_byte_packets", GM_TXF_MAX_SZ }, |
| 3108 | { "tx_fifo_underrun", GM_TXE_FIFO_UR }, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3109 | }; |
| 3110 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3111 | static u32 sky2_get_rx_csum(struct net_device *dev) |
| 3112 | { |
| 3113 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3114 | |
| 3115 | return sky2->rx_csum; |
| 3116 | } |
| 3117 | |
| 3118 | static int sky2_set_rx_csum(struct net_device *dev, u32 data) |
| 3119 | { |
| 3120 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3121 | |
| 3122 | sky2->rx_csum = data; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3123 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3124 | sky2_write32(sky2->hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR), |
| 3125 | data ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM); |
| 3126 | |
| 3127 | return 0; |
| 3128 | } |
| 3129 | |
| 3130 | static u32 sky2_get_msglevel(struct net_device *netdev) |
| 3131 | { |
| 3132 | struct sky2_port *sky2 = netdev_priv(netdev); |
| 3133 | return sky2->msg_enable; |
| 3134 | } |
| 3135 | |
Stephen Hemminger | 9a7ae0a | 2005-09-27 15:28:42 -0700 | [diff] [blame] | 3136 | static int sky2_nway_reset(struct net_device *dev) |
| 3137 | { |
| 3138 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 9a7ae0a | 2005-09-27 15:28:42 -0700 | [diff] [blame] | 3139 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 3140 | if (!netif_running(dev) || sky2->autoneg != AUTONEG_ENABLE) |
Stephen Hemminger | 9a7ae0a | 2005-09-27 15:28:42 -0700 | [diff] [blame] | 3141 | return -EINVAL; |
| 3142 | |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 3143 | sky2_phy_reinit(sky2); |
Stephen Hemminger | d1b139c | 2007-09-05 16:56:19 +0100 | [diff] [blame] | 3144 | sky2_set_multicast(dev); |
Stephen Hemminger | 9a7ae0a | 2005-09-27 15:28:42 -0700 | [diff] [blame] | 3145 | |
| 3146 | return 0; |
| 3147 | } |
| 3148 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3149 | static void sky2_phy_stats(struct sky2_port *sky2, u64 * data, unsigned count) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3150 | { |
| 3151 | struct sky2_hw *hw = sky2->hw; |
| 3152 | unsigned port = sky2->port; |
| 3153 | int i; |
| 3154 | |
| 3155 | data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32 |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3156 | | (u64) gma_read32(hw, port, GM_TXO_OK_LO); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3157 | data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32 |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3158 | | (u64) gma_read32(hw, port, GM_RXO_OK_LO); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3159 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3160 | for (i = 2; i < count; i++) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3161 | data[i] = (u64) gma_read32(hw, port, sky2_stats[i].offset); |
| 3162 | } |
| 3163 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3164 | static void sky2_set_msglevel(struct net_device *netdev, u32 value) |
| 3165 | { |
| 3166 | struct sky2_port *sky2 = netdev_priv(netdev); |
| 3167 | sky2->msg_enable = value; |
| 3168 | } |
| 3169 | |
| 3170 | static int sky2_get_stats_count(struct net_device *dev) |
| 3171 | { |
| 3172 | return ARRAY_SIZE(sky2_stats); |
| 3173 | } |
| 3174 | |
| 3175 | static void sky2_get_ethtool_stats(struct net_device *dev, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3176 | struct ethtool_stats *stats, u64 * data) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3177 | { |
| 3178 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3179 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3180 | sky2_phy_stats(sky2, data, ARRAY_SIZE(sky2_stats)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3181 | } |
| 3182 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3183 | static void sky2_get_strings(struct net_device *dev, u32 stringset, u8 * data) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3184 | { |
| 3185 | int i; |
| 3186 | |
| 3187 | switch (stringset) { |
| 3188 | case ETH_SS_STATS: |
| 3189 | for (i = 0; i < ARRAY_SIZE(sky2_stats); i++) |
| 3190 | memcpy(data + i * ETH_GSTRING_LEN, |
| 3191 | sky2_stats[i].name, ETH_GSTRING_LEN); |
| 3192 | break; |
| 3193 | } |
| 3194 | } |
| 3195 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3196 | static struct net_device_stats *sky2_get_stats(struct net_device *dev) |
| 3197 | { |
| 3198 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3199 | return &sky2->net_stats; |
| 3200 | } |
| 3201 | |
| 3202 | static int sky2_set_mac_address(struct net_device *dev, void *p) |
| 3203 | { |
| 3204 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | a8ab1ec | 2006-01-30 11:37:57 -0800 | [diff] [blame] | 3205 | struct sky2_hw *hw = sky2->hw; |
| 3206 | unsigned port = sky2->port; |
| 3207 | const struct sockaddr *addr = p; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3208 | |
| 3209 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3210 | return -EADDRNOTAVAIL; |
| 3211 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3212 | memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); |
Stephen Hemminger | a8ab1ec | 2006-01-30 11:37:57 -0800 | [diff] [blame] | 3213 | memcpy_toio(hw->regs + B2_MAC_1 + port * 8, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3214 | dev->dev_addr, ETH_ALEN); |
Stephen Hemminger | a8ab1ec | 2006-01-30 11:37:57 -0800 | [diff] [blame] | 3215 | memcpy_toio(hw->regs + B2_MAC_2 + port * 8, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3216 | dev->dev_addr, ETH_ALEN); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 3217 | |
Stephen Hemminger | a8ab1ec | 2006-01-30 11:37:57 -0800 | [diff] [blame] | 3218 | /* virtual address for data */ |
| 3219 | gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr); |
| 3220 | |
| 3221 | /* physical address: used for pause frames */ |
| 3222 | gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 3223 | |
| 3224 | return 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3225 | } |
| 3226 | |
Stephen Hemminger | a052b52 | 2006-10-17 10:24:23 -0700 | [diff] [blame] | 3227 | static void inline sky2_add_filter(u8 filter[8], const u8 *addr) |
| 3228 | { |
| 3229 | u32 bit; |
| 3230 | |
| 3231 | bit = ether_crc(ETH_ALEN, addr) & 63; |
| 3232 | filter[bit >> 3] |= 1 << (bit & 7); |
| 3233 | } |
| 3234 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3235 | static void sky2_set_multicast(struct net_device *dev) |
| 3236 | { |
| 3237 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3238 | struct sky2_hw *hw = sky2->hw; |
| 3239 | unsigned port = sky2->port; |
| 3240 | struct dev_mc_list *list = dev->mc_list; |
| 3241 | u16 reg; |
| 3242 | u8 filter[8]; |
Stephen Hemminger | a052b52 | 2006-10-17 10:24:23 -0700 | [diff] [blame] | 3243 | int rx_pause; |
| 3244 | static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 }; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3245 | |
Stephen Hemminger | a052b52 | 2006-10-17 10:24:23 -0700 | [diff] [blame] | 3246 | rx_pause = (sky2->flow_status == FC_RX || sky2->flow_status == FC_BOTH); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3247 | memset(filter, 0, sizeof(filter)); |
| 3248 | |
| 3249 | reg = gma_read16(hw, port, GM_RX_CTRL); |
| 3250 | reg |= GM_RXCR_UCF_ENA; |
| 3251 | |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 3252 | if (dev->flags & IFF_PROMISC) /* promiscuous */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3253 | reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); |
Stephen Hemminger | a052b52 | 2006-10-17 10:24:23 -0700 | [diff] [blame] | 3254 | else if (dev->flags & IFF_ALLMULTI) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3255 | memset(filter, 0xff, sizeof(filter)); |
Stephen Hemminger | a052b52 | 2006-10-17 10:24:23 -0700 | [diff] [blame] | 3256 | else if (dev->mc_count == 0 && !rx_pause) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3257 | reg &= ~GM_RXCR_MCF_ENA; |
| 3258 | else { |
| 3259 | int i; |
| 3260 | reg |= GM_RXCR_MCF_ENA; |
| 3261 | |
Stephen Hemminger | a052b52 | 2006-10-17 10:24:23 -0700 | [diff] [blame] | 3262 | if (rx_pause) |
| 3263 | sky2_add_filter(filter, pause_mc_addr); |
| 3264 | |
| 3265 | for (i = 0; list && i < dev->mc_count; i++, list = list->next) |
| 3266 | sky2_add_filter(filter, list->dmi_addr); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3267 | } |
| 3268 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3269 | gma_write16(hw, port, GM_MC_ADDR_H1, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3270 | (u16) filter[0] | ((u16) filter[1] << 8)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3271 | gma_write16(hw, port, GM_MC_ADDR_H2, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3272 | (u16) filter[2] | ((u16) filter[3] << 8)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3273 | gma_write16(hw, port, GM_MC_ADDR_H3, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3274 | (u16) filter[4] | ((u16) filter[5] << 8)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3275 | gma_write16(hw, port, GM_MC_ADDR_H4, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3276 | (u16) filter[6] | ((u16) filter[7] << 8)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3277 | |
| 3278 | gma_write16(hw, port, GM_RX_CTRL, reg); |
| 3279 | } |
| 3280 | |
| 3281 | /* Can have one global because blinking is controlled by |
| 3282 | * ethtool and that is always under RTNL mutex |
| 3283 | */ |
Stephen Hemminger | 91c86df | 2005-12-09 11:34:57 -0800 | [diff] [blame] | 3284 | static void sky2_led(struct sky2_hw *hw, unsigned port, int on) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3285 | { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3286 | u16 pg; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3287 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3288 | switch (hw->chip_id) { |
| 3289 | case CHIP_ID_YUKON_XL: |
| 3290 | pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); |
| 3291 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); |
| 3292 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, |
| 3293 | on ? (PHY_M_LEDC_LOS_CTRL(1) | |
| 3294 | PHY_M_LEDC_INIT_CTRL(7) | |
| 3295 | PHY_M_LEDC_STA1_CTRL(7) | |
| 3296 | PHY_M_LEDC_STA0_CTRL(7)) |
| 3297 | : 0); |
| 3298 | |
| 3299 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); |
| 3300 | break; |
| 3301 | |
| 3302 | default: |
| 3303 | gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0); |
Stephen Hemminger | 0efdf26 | 2006-12-05 12:03:41 -0800 | [diff] [blame] | 3304 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, |
| 3305 | on ? PHY_M_LED_ALL : 0); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3306 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | /* blink LED's for finding board */ |
| 3310 | static int sky2_phys_id(struct net_device *dev, u32 data) |
| 3311 | { |
| 3312 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3313 | struct sky2_hw *hw = sky2->hw; |
| 3314 | unsigned port = sky2->port; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3315 | u16 ledctrl, ledover = 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3316 | long ms; |
Stephen Hemminger | 91c86df | 2005-12-09 11:34:57 -0800 | [diff] [blame] | 3317 | int interrupted; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3318 | int onoff = 1; |
| 3319 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3320 | if (!data || data > (u32) (MAX_SCHEDULE_TIMEOUT / HZ)) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3321 | ms = jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT); |
| 3322 | else |
| 3323 | ms = data * 1000; |
| 3324 | |
| 3325 | /* save initial values */ |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 3326 | spin_lock_bh(&sky2->phy_lock); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3327 | if (hw->chip_id == CHIP_ID_YUKON_XL) { |
| 3328 | u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); |
| 3329 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); |
| 3330 | ledctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); |
| 3331 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); |
| 3332 | } else { |
| 3333 | ledctrl = gm_phy_read(hw, port, PHY_MARV_LED_CTRL); |
| 3334 | ledover = gm_phy_read(hw, port, PHY_MARV_LED_OVER); |
| 3335 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3336 | |
Stephen Hemminger | 91c86df | 2005-12-09 11:34:57 -0800 | [diff] [blame] | 3337 | interrupted = 0; |
| 3338 | while (!interrupted && ms > 0) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3339 | sky2_led(hw, port, onoff); |
| 3340 | onoff = !onoff; |
| 3341 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 3342 | spin_unlock_bh(&sky2->phy_lock); |
Stephen Hemminger | 91c86df | 2005-12-09 11:34:57 -0800 | [diff] [blame] | 3343 | interrupted = msleep_interruptible(250); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 3344 | spin_lock_bh(&sky2->phy_lock); |
Stephen Hemminger | 91c86df | 2005-12-09 11:34:57 -0800 | [diff] [blame] | 3345 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3346 | ms -= 250; |
| 3347 | } |
| 3348 | |
| 3349 | /* resume regularly scheduled programming */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3350 | if (hw->chip_id == CHIP_ID_YUKON_XL) { |
| 3351 | u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); |
| 3352 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); |
| 3353 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ledctrl); |
| 3354 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); |
| 3355 | } else { |
| 3356 | gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl); |
| 3357 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover); |
| 3358 | } |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 3359 | spin_unlock_bh(&sky2->phy_lock); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3360 | |
| 3361 | return 0; |
| 3362 | } |
| 3363 | |
| 3364 | static void sky2_get_pauseparam(struct net_device *dev, |
| 3365 | struct ethtool_pauseparam *ecmd) |
| 3366 | { |
| 3367 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3368 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 3369 | switch (sky2->flow_mode) { |
| 3370 | case FC_NONE: |
| 3371 | ecmd->tx_pause = ecmd->rx_pause = 0; |
| 3372 | break; |
| 3373 | case FC_TX: |
| 3374 | ecmd->tx_pause = 1, ecmd->rx_pause = 0; |
| 3375 | break; |
| 3376 | case FC_RX: |
| 3377 | ecmd->tx_pause = 0, ecmd->rx_pause = 1; |
| 3378 | break; |
| 3379 | case FC_BOTH: |
| 3380 | ecmd->tx_pause = ecmd->rx_pause = 1; |
| 3381 | } |
| 3382 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3383 | ecmd->autoneg = sky2->autoneg; |
| 3384 | } |
| 3385 | |
| 3386 | static int sky2_set_pauseparam(struct net_device *dev, |
| 3387 | struct ethtool_pauseparam *ecmd) |
| 3388 | { |
| 3389 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3390 | |
| 3391 | sky2->autoneg = ecmd->autoneg; |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 3392 | sky2->flow_mode = sky2_flow(ecmd->rx_pause, ecmd->tx_pause); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3393 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 3394 | if (netif_running(dev)) |
| 3395 | sky2_phy_reinit(sky2); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3396 | |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 3397 | return 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3398 | } |
| 3399 | |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3400 | static int sky2_get_coalesce(struct net_device *dev, |
| 3401 | struct ethtool_coalesce *ecmd) |
| 3402 | { |
| 3403 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3404 | struct sky2_hw *hw = sky2->hw; |
| 3405 | |
| 3406 | if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_STOP) |
| 3407 | ecmd->tx_coalesce_usecs = 0; |
| 3408 | else { |
| 3409 | u32 clks = sky2_read32(hw, STAT_TX_TIMER_INI); |
| 3410 | ecmd->tx_coalesce_usecs = sky2_clk2us(hw, clks); |
| 3411 | } |
| 3412 | ecmd->tx_max_coalesced_frames = sky2_read16(hw, STAT_TX_IDX_TH); |
| 3413 | |
| 3414 | if (sky2_read8(hw, STAT_LEV_TIMER_CTRL) == TIM_STOP) |
| 3415 | ecmd->rx_coalesce_usecs = 0; |
| 3416 | else { |
| 3417 | u32 clks = sky2_read32(hw, STAT_LEV_TIMER_INI); |
| 3418 | ecmd->rx_coalesce_usecs = sky2_clk2us(hw, clks); |
| 3419 | } |
| 3420 | ecmd->rx_max_coalesced_frames = sky2_read8(hw, STAT_FIFO_WM); |
| 3421 | |
| 3422 | if (sky2_read8(hw, STAT_ISR_TIMER_CTRL) == TIM_STOP) |
| 3423 | ecmd->rx_coalesce_usecs_irq = 0; |
| 3424 | else { |
| 3425 | u32 clks = sky2_read32(hw, STAT_ISR_TIMER_INI); |
| 3426 | ecmd->rx_coalesce_usecs_irq = sky2_clk2us(hw, clks); |
| 3427 | } |
| 3428 | |
| 3429 | ecmd->rx_max_coalesced_frames_irq = sky2_read8(hw, STAT_FIFO_ISR_WM); |
| 3430 | |
| 3431 | return 0; |
| 3432 | } |
| 3433 | |
| 3434 | /* Note: this affect both ports */ |
| 3435 | static int sky2_set_coalesce(struct net_device *dev, |
| 3436 | struct ethtool_coalesce *ecmd) |
| 3437 | { |
| 3438 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3439 | struct sky2_hw *hw = sky2->hw; |
Stephen Hemminger | 77b3d6a | 2006-03-20 15:48:18 -0800 | [diff] [blame] | 3440 | const u32 tmax = sky2_clk2us(hw, 0x0ffffff); |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3441 | |
Stephen Hemminger | 77b3d6a | 2006-03-20 15:48:18 -0800 | [diff] [blame] | 3442 | if (ecmd->tx_coalesce_usecs > tmax || |
| 3443 | ecmd->rx_coalesce_usecs > tmax || |
| 3444 | ecmd->rx_coalesce_usecs_irq > tmax) |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3445 | return -EINVAL; |
| 3446 | |
Stephen Hemminger | ff81fbb | 2006-02-22 11:44:59 -0800 | [diff] [blame] | 3447 | if (ecmd->tx_max_coalesced_frames >= TX_RING_SIZE-1) |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3448 | return -EINVAL; |
Stephen Hemminger | ff81fbb | 2006-02-22 11:44:59 -0800 | [diff] [blame] | 3449 | if (ecmd->rx_max_coalesced_frames > RX_MAX_PENDING) |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3450 | return -EINVAL; |
Stephen Hemminger | ff81fbb | 2006-02-22 11:44:59 -0800 | [diff] [blame] | 3451 | if (ecmd->rx_max_coalesced_frames_irq >RX_MAX_PENDING) |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3452 | return -EINVAL; |
| 3453 | |
| 3454 | if (ecmd->tx_coalesce_usecs == 0) |
| 3455 | sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP); |
| 3456 | else { |
| 3457 | sky2_write32(hw, STAT_TX_TIMER_INI, |
| 3458 | sky2_us2clk(hw, ecmd->tx_coalesce_usecs)); |
| 3459 | sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START); |
| 3460 | } |
| 3461 | sky2_write16(hw, STAT_TX_IDX_TH, ecmd->tx_max_coalesced_frames); |
| 3462 | |
| 3463 | if (ecmd->rx_coalesce_usecs == 0) |
| 3464 | sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_STOP); |
| 3465 | else { |
| 3466 | sky2_write32(hw, STAT_LEV_TIMER_INI, |
| 3467 | sky2_us2clk(hw, ecmd->rx_coalesce_usecs)); |
| 3468 | sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START); |
| 3469 | } |
| 3470 | sky2_write8(hw, STAT_FIFO_WM, ecmd->rx_max_coalesced_frames); |
| 3471 | |
| 3472 | if (ecmd->rx_coalesce_usecs_irq == 0) |
| 3473 | sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_STOP); |
| 3474 | else { |
Stephen Hemminger | d28d487 | 2006-01-30 11:37:56 -0800 | [diff] [blame] | 3475 | sky2_write32(hw, STAT_ISR_TIMER_INI, |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3476 | sky2_us2clk(hw, ecmd->rx_coalesce_usecs_irq)); |
| 3477 | sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START); |
| 3478 | } |
| 3479 | sky2_write8(hw, STAT_FIFO_ISR_WM, ecmd->rx_max_coalesced_frames_irq); |
| 3480 | return 0; |
| 3481 | } |
| 3482 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3483 | static void sky2_get_ringparam(struct net_device *dev, |
| 3484 | struct ethtool_ringparam *ering) |
| 3485 | { |
| 3486 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3487 | |
| 3488 | ering->rx_max_pending = RX_MAX_PENDING; |
| 3489 | ering->rx_mini_max_pending = 0; |
| 3490 | ering->rx_jumbo_max_pending = 0; |
| 3491 | ering->tx_max_pending = TX_RING_SIZE - 1; |
| 3492 | |
| 3493 | ering->rx_pending = sky2->rx_pending; |
| 3494 | ering->rx_mini_pending = 0; |
| 3495 | ering->rx_jumbo_pending = 0; |
| 3496 | ering->tx_pending = sky2->tx_pending; |
| 3497 | } |
| 3498 | |
| 3499 | static int sky2_set_ringparam(struct net_device *dev, |
| 3500 | struct ethtool_ringparam *ering) |
| 3501 | { |
| 3502 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3503 | int err = 0; |
| 3504 | |
| 3505 | if (ering->rx_pending > RX_MAX_PENDING || |
| 3506 | ering->rx_pending < 8 || |
| 3507 | ering->tx_pending < MAX_SKB_TX_LE || |
| 3508 | ering->tx_pending > TX_RING_SIZE - 1) |
| 3509 | return -EINVAL; |
| 3510 | |
| 3511 | if (netif_running(dev)) |
| 3512 | sky2_down(dev); |
| 3513 | |
| 3514 | sky2->rx_pending = ering->rx_pending; |
| 3515 | sky2->tx_pending = ering->tx_pending; |
| 3516 | |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 3517 | if (netif_running(dev)) { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3518 | err = sky2_up(dev); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 3519 | if (err) |
| 3520 | dev_close(dev); |
Stephen Hemminger | 6ed995b | 2005-12-20 15:08:08 -0800 | [diff] [blame] | 3521 | else |
| 3522 | sky2_set_multicast(dev); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 3523 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3524 | |
| 3525 | return err; |
| 3526 | } |
| 3527 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3528 | static int sky2_get_regs_len(struct net_device *dev) |
| 3529 | { |
Stephen Hemminger | 6e4cbb3 | 2005-09-19 15:47:57 -0700 | [diff] [blame] | 3530 | return 0x4000; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | /* |
| 3534 | * Returns copy of control register region |
Stephen Hemminger | 3ead5db | 2007-06-04 17:23:21 -0700 | [diff] [blame] | 3535 | * Note: ethtool_get_regs always provides full size (16k) buffer |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3536 | */ |
| 3537 | static void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 3538 | void *p) |
| 3539 | { |
| 3540 | const struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3541 | const void __iomem *io = sky2->hw->regs; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3542 | |
| 3543 | regs->version = 1; |
Stephen Hemminger | 6e4cbb3 | 2005-09-19 15:47:57 -0700 | [diff] [blame] | 3544 | memset(p, 0, regs->len); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3545 | |
Stephen Hemminger | 6e4cbb3 | 2005-09-19 15:47:57 -0700 | [diff] [blame] | 3546 | memcpy_fromio(p, io, B3_RAM_ADDR); |
| 3547 | |
Stephen Hemminger | 3ead5db | 2007-06-04 17:23:21 -0700 | [diff] [blame] | 3548 | /* skip diagnostic ram region */ |
| 3549 | memcpy_fromio(p + B3_RI_WTO_R1, io + B3_RI_WTO_R1, 0x2000 - B3_RI_WTO_R1); |
| 3550 | |
| 3551 | /* copy GMAC registers */ |
| 3552 | memcpy_fromio(p + BASE_GMAC_1, io + BASE_GMAC_1, 0x1000); |
| 3553 | if (sky2->hw->ports > 1) |
| 3554 | memcpy_fromio(p + BASE_GMAC_2, io + BASE_GMAC_2, 0x1000); |
| 3555 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3556 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3557 | |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 3558 | /* In order to do Jumbo packets on these chips, need to turn off the |
| 3559 | * transmit store/forward. Therefore checksum offload won't work. |
| 3560 | */ |
| 3561 | static int no_tx_offload(struct net_device *dev) |
| 3562 | { |
| 3563 | const struct sky2_port *sky2 = netdev_priv(dev); |
| 3564 | const struct sky2_hw *hw = sky2->hw; |
| 3565 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 3566 | return dev->mtu > ETH_DATA_LEN && hw->chip_id == CHIP_ID_YUKON_EC_U; |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | static int sky2_set_tx_csum(struct net_device *dev, u32 data) |
| 3570 | { |
| 3571 | if (data && no_tx_offload(dev)) |
| 3572 | return -EINVAL; |
| 3573 | |
| 3574 | return ethtool_op_set_tx_csum(dev, data); |
| 3575 | } |
| 3576 | |
| 3577 | |
| 3578 | static int sky2_set_tso(struct net_device *dev, u32 data) |
| 3579 | { |
| 3580 | if (data && no_tx_offload(dev)) |
| 3581 | return -EINVAL; |
| 3582 | |
| 3583 | return ethtool_op_set_tso(dev, data); |
| 3584 | } |
| 3585 | |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 3586 | static int sky2_get_eeprom_len(struct net_device *dev) |
| 3587 | { |
| 3588 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3589 | u16 reg2; |
| 3590 | |
| 3591 | reg2 = sky2_pci_read32(sky2->hw, PCI_DEV_REG2); |
| 3592 | return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8); |
| 3593 | } |
| 3594 | |
| 3595 | static u32 sky2_vpd_read(struct sky2_hw *hw, int cap, u16 offset) |
| 3596 | { |
| 3597 | sky2_pci_write16(hw, cap + PCI_VPD_ADDR, offset); |
| 3598 | |
| 3599 | while (!(sky2_pci_read16(hw, cap + PCI_VPD_ADDR) & PCI_VPD_ADDR_F)) |
| 3600 | cpu_relax(); |
| 3601 | return sky2_pci_read32(hw, cap + PCI_VPD_DATA); |
| 3602 | } |
| 3603 | |
| 3604 | static void sky2_vpd_write(struct sky2_hw *hw, int cap, u16 offset, u32 val) |
| 3605 | { |
| 3606 | sky2_pci_write32(hw, cap + PCI_VPD_DATA, val); |
| 3607 | sky2_pci_write16(hw, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F); |
| 3608 | do { |
| 3609 | cpu_relax(); |
| 3610 | } while (sky2_pci_read16(hw, cap + PCI_VPD_ADDR) & PCI_VPD_ADDR_F); |
| 3611 | } |
| 3612 | |
| 3613 | static int sky2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, |
| 3614 | u8 *data) |
| 3615 | { |
| 3616 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3617 | int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD); |
| 3618 | int length = eeprom->len; |
| 3619 | u16 offset = eeprom->offset; |
| 3620 | |
| 3621 | if (!cap) |
| 3622 | return -EINVAL; |
| 3623 | |
| 3624 | eeprom->magic = SKY2_EEPROM_MAGIC; |
| 3625 | |
| 3626 | while (length > 0) { |
| 3627 | u32 val = sky2_vpd_read(sky2->hw, cap, offset); |
| 3628 | int n = min_t(int, length, sizeof(val)); |
| 3629 | |
| 3630 | memcpy(data, &val, n); |
| 3631 | length -= n; |
| 3632 | data += n; |
| 3633 | offset += n; |
| 3634 | } |
| 3635 | return 0; |
| 3636 | } |
| 3637 | |
| 3638 | static int sky2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, |
| 3639 | u8 *data) |
| 3640 | { |
| 3641 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3642 | int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD); |
| 3643 | int length = eeprom->len; |
| 3644 | u16 offset = eeprom->offset; |
| 3645 | |
| 3646 | if (!cap) |
| 3647 | return -EINVAL; |
| 3648 | |
| 3649 | if (eeprom->magic != SKY2_EEPROM_MAGIC) |
| 3650 | return -EINVAL; |
| 3651 | |
| 3652 | while (length > 0) { |
| 3653 | u32 val; |
| 3654 | int n = min_t(int, length, sizeof(val)); |
| 3655 | |
| 3656 | if (n < sizeof(val)) |
| 3657 | val = sky2_vpd_read(sky2->hw, cap, offset); |
| 3658 | memcpy(&val, data, n); |
| 3659 | |
| 3660 | sky2_vpd_write(sky2->hw, cap, offset, val); |
| 3661 | |
| 3662 | length -= n; |
| 3663 | data += n; |
| 3664 | offset += n; |
| 3665 | } |
| 3666 | return 0; |
| 3667 | } |
| 3668 | |
| 3669 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 3670 | static const struct ethtool_ops sky2_ethtool_ops = { |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 3671 | .get_settings = sky2_get_settings, |
| 3672 | .set_settings = sky2_set_settings, |
| 3673 | .get_drvinfo = sky2_get_drvinfo, |
| 3674 | .get_wol = sky2_get_wol, |
| 3675 | .set_wol = sky2_set_wol, |
| 3676 | .get_msglevel = sky2_get_msglevel, |
| 3677 | .set_msglevel = sky2_set_msglevel, |
| 3678 | .nway_reset = sky2_nway_reset, |
| 3679 | .get_regs_len = sky2_get_regs_len, |
| 3680 | .get_regs = sky2_get_regs, |
| 3681 | .get_link = ethtool_op_get_link, |
| 3682 | .get_eeprom_len = sky2_get_eeprom_len, |
| 3683 | .get_eeprom = sky2_get_eeprom, |
| 3684 | .set_eeprom = sky2_set_eeprom, |
| 3685 | .get_sg = ethtool_op_get_sg, |
| 3686 | .set_sg = ethtool_op_set_sg, |
| 3687 | .get_tx_csum = ethtool_op_get_tx_csum, |
| 3688 | .set_tx_csum = sky2_set_tx_csum, |
| 3689 | .get_tso = ethtool_op_get_tso, |
| 3690 | .set_tso = sky2_set_tso, |
| 3691 | .get_rx_csum = sky2_get_rx_csum, |
| 3692 | .set_rx_csum = sky2_set_rx_csum, |
| 3693 | .get_strings = sky2_get_strings, |
| 3694 | .get_coalesce = sky2_get_coalesce, |
| 3695 | .set_coalesce = sky2_set_coalesce, |
| 3696 | .get_ringparam = sky2_get_ringparam, |
| 3697 | .set_ringparam = sky2_set_ringparam, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3698 | .get_pauseparam = sky2_get_pauseparam, |
| 3699 | .set_pauseparam = sky2_set_pauseparam, |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 3700 | .phys_id = sky2_phys_id, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3701 | .get_stats_count = sky2_get_stats_count, |
| 3702 | .get_ethtool_stats = sky2_get_ethtool_stats, |
| 3703 | }; |
| 3704 | |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 3705 | #ifdef CONFIG_SKY2_DEBUG |
| 3706 | |
| 3707 | static struct dentry *sky2_debug; |
| 3708 | |
| 3709 | static int sky2_debug_show(struct seq_file *seq, void *v) |
| 3710 | { |
| 3711 | struct net_device *dev = seq->private; |
| 3712 | const struct sky2_port *sky2 = netdev_priv(dev); |
| 3713 | const struct sky2_hw *hw = sky2->hw; |
| 3714 | unsigned port = sky2->port; |
| 3715 | unsigned idx, last; |
| 3716 | int sop; |
| 3717 | |
| 3718 | if (!netif_running(dev)) |
| 3719 | return -ENETDOWN; |
| 3720 | |
| 3721 | seq_printf(seq, "IRQ src=%x mask=%x control=%x\n", |
| 3722 | sky2_read32(hw, B0_ISRC), |
| 3723 | sky2_read32(hw, B0_IMSK), |
| 3724 | sky2_read32(hw, B0_Y2_SP_ICR)); |
| 3725 | |
| 3726 | netif_poll_disable(hw->dev[0]); |
| 3727 | last = sky2_read16(hw, STAT_PUT_IDX); |
| 3728 | |
| 3729 | if (hw->st_idx == last) |
| 3730 | seq_puts(seq, "Status ring (empty)\n"); |
| 3731 | else { |
| 3732 | seq_puts(seq, "Status ring\n"); |
| 3733 | for (idx = hw->st_idx; idx != last && idx < STATUS_RING_SIZE; |
| 3734 | idx = RING_NEXT(idx, STATUS_RING_SIZE)) { |
| 3735 | const struct sky2_status_le *le = hw->st_le + idx; |
| 3736 | seq_printf(seq, "[%d] %#x %d %#x\n", |
| 3737 | idx, le->opcode, le->length, le->status); |
| 3738 | } |
| 3739 | seq_puts(seq, "\n"); |
| 3740 | } |
| 3741 | |
| 3742 | seq_printf(seq, "Tx ring pending=%u...%u report=%d done=%d\n", |
| 3743 | sky2->tx_cons, sky2->tx_prod, |
| 3744 | sky2_read16(hw, port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX), |
| 3745 | sky2_read16(hw, Q_ADDR(txqaddr[port], Q_DONE))); |
| 3746 | |
| 3747 | /* Dump contents of tx ring */ |
| 3748 | sop = 1; |
| 3749 | for (idx = sky2->tx_next; idx != sky2->tx_prod && idx < TX_RING_SIZE; |
| 3750 | idx = RING_NEXT(idx, TX_RING_SIZE)) { |
| 3751 | const struct sky2_tx_le *le = sky2->tx_le + idx; |
| 3752 | u32 a = le32_to_cpu(le->addr); |
| 3753 | |
| 3754 | if (sop) |
| 3755 | seq_printf(seq, "%u:", idx); |
| 3756 | sop = 0; |
| 3757 | |
| 3758 | switch(le->opcode & ~HW_OWNER) { |
| 3759 | case OP_ADDR64: |
| 3760 | seq_printf(seq, " %#x:", a); |
| 3761 | break; |
| 3762 | case OP_LRGLEN: |
| 3763 | seq_printf(seq, " mtu=%d", a); |
| 3764 | break; |
| 3765 | case OP_VLAN: |
| 3766 | seq_printf(seq, " vlan=%d", be16_to_cpu(le->length)); |
| 3767 | break; |
| 3768 | case OP_TCPLISW: |
| 3769 | seq_printf(seq, " csum=%#x", a); |
| 3770 | break; |
| 3771 | case OP_LARGESEND: |
| 3772 | seq_printf(seq, " tso=%#x(%d)", a, le16_to_cpu(le->length)); |
| 3773 | break; |
| 3774 | case OP_PACKET: |
| 3775 | seq_printf(seq, " %#x(%d)", a, le16_to_cpu(le->length)); |
| 3776 | break; |
| 3777 | case OP_BUFFER: |
| 3778 | seq_printf(seq, " frag=%#x(%d)", a, le16_to_cpu(le->length)); |
| 3779 | break; |
| 3780 | default: |
| 3781 | seq_printf(seq, " op=%#x,%#x(%d)", le->opcode, |
| 3782 | a, le16_to_cpu(le->length)); |
| 3783 | } |
| 3784 | |
| 3785 | if (le->ctrl & EOP) { |
| 3786 | seq_putc(seq, '\n'); |
| 3787 | sop = 1; |
| 3788 | } |
| 3789 | } |
| 3790 | |
| 3791 | seq_printf(seq, "\nRx ring hw get=%d put=%d last=%d\n", |
| 3792 | sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_GET_IDX)), |
| 3793 | last = sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_PUT_IDX)), |
| 3794 | sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_LAST_IDX))); |
| 3795 | |
| 3796 | netif_poll_enable(hw->dev[0]); |
| 3797 | return 0; |
| 3798 | } |
| 3799 | |
| 3800 | static int sky2_debug_open(struct inode *inode, struct file *file) |
| 3801 | { |
| 3802 | return single_open(file, sky2_debug_show, inode->i_private); |
| 3803 | } |
| 3804 | |
| 3805 | static const struct file_operations sky2_debug_fops = { |
| 3806 | .owner = THIS_MODULE, |
| 3807 | .open = sky2_debug_open, |
| 3808 | .read = seq_read, |
| 3809 | .llseek = seq_lseek, |
| 3810 | .release = single_release, |
| 3811 | }; |
| 3812 | |
| 3813 | /* |
| 3814 | * Use network device events to create/remove/rename |
| 3815 | * debugfs file entries |
| 3816 | */ |
| 3817 | static int sky2_device_event(struct notifier_block *unused, |
| 3818 | unsigned long event, void *ptr) |
| 3819 | { |
| 3820 | struct net_device *dev = ptr; |
| 3821 | |
| 3822 | if (dev->open == sky2_up) { |
| 3823 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3824 | |
| 3825 | switch(event) { |
| 3826 | case NETDEV_CHANGENAME: |
| 3827 | if (!netif_running(dev)) |
| 3828 | break; |
| 3829 | /* fallthrough */ |
| 3830 | case NETDEV_DOWN: |
| 3831 | case NETDEV_GOING_DOWN: |
| 3832 | if (sky2->debugfs) { |
| 3833 | printk(KERN_DEBUG PFX "%s: remove debugfs\n", |
| 3834 | dev->name); |
| 3835 | debugfs_remove(sky2->debugfs); |
| 3836 | sky2->debugfs = NULL; |
| 3837 | } |
| 3838 | |
| 3839 | if (event != NETDEV_CHANGENAME) |
| 3840 | break; |
| 3841 | /* fallthrough for changename */ |
| 3842 | case NETDEV_UP: |
| 3843 | if (sky2_debug) { |
| 3844 | struct dentry *d; |
| 3845 | d = debugfs_create_file(dev->name, S_IRUGO, |
| 3846 | sky2_debug, dev, |
| 3847 | &sky2_debug_fops); |
| 3848 | if (d == NULL || IS_ERR(d)) |
| 3849 | printk(KERN_INFO PFX |
| 3850 | "%s: debugfs create failed\n", |
| 3851 | dev->name); |
| 3852 | else |
| 3853 | sky2->debugfs = d; |
| 3854 | } |
| 3855 | break; |
| 3856 | } |
| 3857 | } |
| 3858 | |
| 3859 | return NOTIFY_DONE; |
| 3860 | } |
| 3861 | |
| 3862 | static struct notifier_block sky2_notifier = { |
| 3863 | .notifier_call = sky2_device_event, |
| 3864 | }; |
| 3865 | |
| 3866 | |
| 3867 | static __init void sky2_debug_init(void) |
| 3868 | { |
| 3869 | struct dentry *ent; |
| 3870 | |
| 3871 | ent = debugfs_create_dir("sky2", NULL); |
| 3872 | if (!ent || IS_ERR(ent)) |
| 3873 | return; |
| 3874 | |
| 3875 | sky2_debug = ent; |
| 3876 | register_netdevice_notifier(&sky2_notifier); |
| 3877 | } |
| 3878 | |
| 3879 | static __exit void sky2_debug_cleanup(void) |
| 3880 | { |
| 3881 | if (sky2_debug) { |
| 3882 | unregister_netdevice_notifier(&sky2_notifier); |
| 3883 | debugfs_remove(sky2_debug); |
| 3884 | sky2_debug = NULL; |
| 3885 | } |
| 3886 | } |
| 3887 | |
| 3888 | #else |
| 3889 | #define sky2_debug_init() |
| 3890 | #define sky2_debug_cleanup() |
| 3891 | #endif |
| 3892 | |
| 3893 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3894 | /* Initialize network device */ |
| 3895 | static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw, |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 3896 | unsigned port, |
| 3897 | int highmem, int wol) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3898 | { |
| 3899 | struct sky2_port *sky2; |
| 3900 | struct net_device *dev = alloc_etherdev(sizeof(*sky2)); |
| 3901 | |
| 3902 | if (!dev) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 3903 | dev_err(&hw->pdev->dev, "etherdev alloc failed"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3904 | return NULL; |
| 3905 | } |
| 3906 | |
| 3907 | SET_MODULE_OWNER(dev); |
| 3908 | SET_NETDEV_DEV(dev, &hw->pdev->dev); |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 3909 | dev->irq = hw->pdev->irq; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3910 | dev->open = sky2_up; |
| 3911 | dev->stop = sky2_down; |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 3912 | dev->do_ioctl = sky2_ioctl; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3913 | dev->hard_start_xmit = sky2_xmit_frame; |
| 3914 | dev->get_stats = sky2_get_stats; |
| 3915 | dev->set_multicast_list = sky2_set_multicast; |
| 3916 | dev->set_mac_address = sky2_set_mac_address; |
| 3917 | dev->change_mtu = sky2_change_mtu; |
| 3918 | SET_ETHTOOL_OPS(dev, &sky2_ethtool_ops); |
| 3919 | dev->tx_timeout = sky2_tx_timeout; |
| 3920 | dev->watchdog_timeo = TX_WATCHDOG; |
| 3921 | if (port == 0) |
| 3922 | dev->poll = sky2_poll; |
| 3923 | dev->weight = NAPI_WEIGHT; |
| 3924 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Stephen Hemminger | 0ca4323 | 2006-10-18 13:39:28 -0700 | [diff] [blame] | 3925 | /* Network console (only works on port 0) |
| 3926 | * because netpoll makes assumptions about NAPI |
| 3927 | */ |
| 3928 | if (port == 0) |
| 3929 | dev->poll_controller = sky2_netpoll; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3930 | #endif |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3931 | |
| 3932 | sky2 = netdev_priv(dev); |
| 3933 | sky2->netdev = dev; |
| 3934 | sky2->hw = hw; |
| 3935 | sky2->msg_enable = netif_msg_init(debug, default_msg); |
| 3936 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 3937 | /* This chip has hardware problems that generates |
| 3938 | * bogus PHY receive status so by default shut up the message. |
| 3939 | */ |
| 3940 | if (hw->chip_id == CHIP_ID_YUKON_FE_P && |
| 3941 | hw->chip_rev == CHIP_REV_YU_FE2_A0) |
| 3942 | sky2->msg_enable &= ~NETIF_MSG_RX_ERR; |
| 3943 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3944 | /* Auto speed and flow control */ |
| 3945 | sky2->autoneg = AUTONEG_ENABLE; |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 3946 | sky2->flow_mode = FC_BOTH; |
| 3947 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3948 | sky2->duplex = -1; |
| 3949 | sky2->speed = -1; |
| 3950 | sky2->advertising = sky2_supported_modes(hw); |
Stephen Hemminger | ee7abb0 | 2006-05-18 11:16:21 -0700 | [diff] [blame] | 3951 | sky2->rx_csum = 1; |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 3952 | sky2->wol = wol; |
Stephen Hemminger | 75d070c | 2005-12-09 11:35:11 -0800 | [diff] [blame] | 3953 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 3954 | spin_lock_init(&sky2->phy_lock); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3955 | sky2->tx_pending = TX_DEF_PENDING; |
Stephen Hemminger | 290d4de | 2006-03-20 15:48:15 -0800 | [diff] [blame] | 3956 | sky2->rx_pending = RX_DEF_PENDING; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3957 | |
| 3958 | hw->dev[port] = dev; |
| 3959 | |
| 3960 | sky2->port = port; |
| 3961 | |
Stephen Hemminger | 4a50a87 | 2007-02-06 10:45:41 -0800 | [diff] [blame] | 3962 | dev->features |= NETIF_F_TSO | NETIF_F_IP_CSUM | NETIF_F_SG; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3963 | if (highmem) |
| 3964 | dev->features |= NETIF_F_HIGHDMA; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3965 | |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 3966 | #ifdef SKY2_VLAN_TAG_USED |
| 3967 | dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 3968 | dev->vlan_rx_register = sky2_vlan_rx_register; |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 3969 | #endif |
| 3970 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3971 | /* read the mac address */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3972 | memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8, ETH_ALEN); |
Stephen Hemminger | 2995bfb | 2005-09-28 10:01:03 -0700 | [diff] [blame] | 3973 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3974 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3975 | return dev; |
| 3976 | } |
| 3977 | |
Stephen Hemminger | 28bd181 | 2006-01-17 13:43:19 -0800 | [diff] [blame] | 3978 | static void __devinit sky2_show_addr(struct net_device *dev) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3979 | { |
| 3980 | const struct sky2_port *sky2 = netdev_priv(dev); |
| 3981 | |
| 3982 | if (netif_msg_probe(sky2)) |
| 3983 | printk(KERN_INFO PFX "%s: addr %02x:%02x:%02x:%02x:%02x:%02x\n", |
| 3984 | dev->name, |
| 3985 | dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], |
| 3986 | dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); |
| 3987 | } |
| 3988 | |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 3989 | /* Handle software interrupt used during MSI test */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3990 | static irqreturn_t __devinit sky2_test_intr(int irq, void *dev_id) |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 3991 | { |
| 3992 | struct sky2_hw *hw = dev_id; |
| 3993 | u32 status = sky2_read32(hw, B0_Y2_SP_ISRC2); |
| 3994 | |
| 3995 | if (status == 0) |
| 3996 | return IRQ_NONE; |
| 3997 | |
| 3998 | if (status & Y2_IS_IRQ_SW) { |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 3999 | hw->flags |= SKY2_HW_USE_MSI; |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4000 | wake_up(&hw->msi_wait); |
| 4001 | sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ); |
| 4002 | } |
| 4003 | sky2_write32(hw, B0_Y2_SP_ICR, 2); |
| 4004 | |
| 4005 | return IRQ_HANDLED; |
| 4006 | } |
| 4007 | |
| 4008 | /* Test interrupt path by forcing a a software IRQ */ |
| 4009 | static int __devinit sky2_test_msi(struct sky2_hw *hw) |
| 4010 | { |
| 4011 | struct pci_dev *pdev = hw->pdev; |
| 4012 | int err; |
| 4013 | |
shemminger@osdl.org | bb507fe | 2006-08-28 10:00:48 -0700 | [diff] [blame] | 4014 | init_waitqueue_head (&hw->msi_wait); |
| 4015 | |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4016 | sky2_write32(hw, B0_IMSK, Y2_IS_IRQ_SW); |
| 4017 | |
Stephen Hemminger | b0a20de | 2006-12-01 14:29:37 -0800 | [diff] [blame] | 4018 | err = request_irq(pdev->irq, sky2_test_intr, 0, DRV_NAME, hw); |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4019 | if (err) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4020 | dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq); |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4021 | return err; |
| 4022 | } |
| 4023 | |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4024 | sky2_write8(hw, B0_CTST, CS_ST_SW_IRQ); |
shemminger@osdl.org | bb507fe | 2006-08-28 10:00:48 -0700 | [diff] [blame] | 4025 | sky2_read8(hw, B0_CTST); |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4026 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 4027 | wait_event_timeout(hw->msi_wait, (hw->flags & SKY2_HW_USE_MSI), HZ/10); |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4028 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 4029 | if (!(hw->flags & SKY2_HW_USE_MSI)) { |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4030 | /* MSI test failed, go back to INTx mode */ |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4031 | dev_info(&pdev->dev, "No interrupt generated using MSI, " |
| 4032 | "switching to INTx mode.\n"); |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4033 | |
| 4034 | err = -EOPNOTSUPP; |
| 4035 | sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ); |
| 4036 | } |
| 4037 | |
| 4038 | sky2_write32(hw, B0_IMSK, 0); |
Stephen Hemminger | 2bffc23 | 2006-10-17 10:17:18 -0700 | [diff] [blame] | 4039 | sky2_read32(hw, B0_IMSK); |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4040 | |
| 4041 | free_irq(pdev->irq, hw); |
| 4042 | |
| 4043 | return err; |
| 4044 | } |
| 4045 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4046 | static int __devinit pci_wake_enabled(struct pci_dev *dev) |
| 4047 | { |
| 4048 | int pm = pci_find_capability(dev, PCI_CAP_ID_PM); |
| 4049 | u16 value; |
| 4050 | |
| 4051 | if (!pm) |
| 4052 | return 0; |
| 4053 | if (pci_read_config_word(dev, pm + PCI_PM_CTRL, &value)) |
| 4054 | return 0; |
| 4055 | return value & PCI_PM_CTRL_PME_ENABLE; |
| 4056 | } |
| 4057 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4058 | static int __devinit sky2_probe(struct pci_dev *pdev, |
| 4059 | const struct pci_device_id *ent) |
| 4060 | { |
shemminger@linux-foundation.org | 7f60c64 | 2007-01-26 11:38:36 -0800 | [diff] [blame] | 4061 | struct net_device *dev; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4062 | struct sky2_hw *hw; |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4063 | int err, using_dac = 0, wol_default; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4064 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4065 | err = pci_enable_device(pdev); |
| 4066 | if (err) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4067 | dev_err(&pdev->dev, "cannot enable PCI device\n"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4068 | goto err_out; |
| 4069 | } |
| 4070 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4071 | err = pci_request_regions(pdev, DRV_NAME); |
| 4072 | if (err) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4073 | dev_err(&pdev->dev, "cannot obtain PCI resources\n"); |
Stephen Hemminger | 44a1d2e | 2007-04-30 14:23:49 -0700 | [diff] [blame] | 4074 | goto err_out_disable; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | pci_set_master(pdev); |
| 4078 | |
Stephen Hemminger | d1f3d4d | 2006-01-17 13:43:11 -0800 | [diff] [blame] | 4079 | if (sizeof(dma_addr_t) > sizeof(u32) && |
| 4080 | !(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) { |
| 4081 | using_dac = 1; |
| 4082 | err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); |
| 4083 | if (err < 0) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4084 | dev_err(&pdev->dev, "unable to obtain 64 bit DMA " |
| 4085 | "for consistent allocations\n"); |
Stephen Hemminger | d1f3d4d | 2006-01-17 13:43:11 -0800 | [diff] [blame] | 4086 | goto err_out_free_regions; |
| 4087 | } |
Stephen Hemminger | d1f3d4d | 2006-01-17 13:43:11 -0800 | [diff] [blame] | 4088 | } else { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4089 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 4090 | if (err) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4091 | dev_err(&pdev->dev, "no usable DMA configuration\n"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4092 | goto err_out_free_regions; |
| 4093 | } |
| 4094 | } |
Stephen Hemminger | d1f3d4d | 2006-01-17 13:43:11 -0800 | [diff] [blame] | 4095 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4096 | wol_default = pci_wake_enabled(pdev) ? WAKE_MAGIC : 0; |
| 4097 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4098 | err = -ENOMEM; |
Stephen Hemminger | 6aad85d | 2006-01-17 13:43:18 -0800 | [diff] [blame] | 4099 | hw = kzalloc(sizeof(*hw), GFP_KERNEL); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4100 | if (!hw) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4101 | dev_err(&pdev->dev, "cannot allocate hardware struct\n"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4102 | goto err_out_free_regions; |
| 4103 | } |
| 4104 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4105 | hw->pdev = pdev; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4106 | |
| 4107 | hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000); |
| 4108 | if (!hw->regs) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4109 | dev_err(&pdev->dev, "cannot map device registers\n"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4110 | goto err_out_free_hw; |
| 4111 | } |
| 4112 | |
Stephen Hemminger | 56a645c | 2006-02-22 11:45:02 -0800 | [diff] [blame] | 4113 | #ifdef __BIG_ENDIAN |
Stephen Hemminger | f65b138 | 2006-09-06 12:45:02 -0700 | [diff] [blame] | 4114 | /* The sk98lin vendor driver uses hardware byte swapping but |
| 4115 | * this driver uses software swapping. |
| 4116 | */ |
Stephen Hemminger | 56a645c | 2006-02-22 11:45:02 -0800 | [diff] [blame] | 4117 | { |
| 4118 | u32 reg; |
Stephen Hemminger | 56a645c | 2006-02-22 11:45:02 -0800 | [diff] [blame] | 4119 | reg = sky2_pci_read32(hw, PCI_DEV_REG2); |
Stephen Hemminger | f65b138 | 2006-09-06 12:45:02 -0700 | [diff] [blame] | 4120 | reg &= ~PCI_REV_DESC; |
Stephen Hemminger | 56a645c | 2006-02-22 11:45:02 -0800 | [diff] [blame] | 4121 | sky2_pci_write32(hw, PCI_DEV_REG2, reg); |
| 4122 | } |
| 4123 | #endif |
| 4124 | |
Stephen Hemminger | 08c06d8 | 2006-01-30 11:37:54 -0800 | [diff] [blame] | 4125 | /* ring for status responses */ |
| 4126 | hw->st_le = pci_alloc_consistent(hw->pdev, STATUS_LE_BYTES, |
| 4127 | &hw->st_dma); |
| 4128 | if (!hw->st_le) |
| 4129 | goto err_out_iounmap; |
| 4130 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4131 | err = sky2_init(hw); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4132 | if (err) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4133 | goto err_out_iounmap; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4134 | |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4135 | dev_info(&pdev->dev, "v%s addr 0x%llx irq %d Yukon-%s (0x%x) rev %d\n", |
Greg Kroah-Hartman | 7c7459d | 2006-06-12 15:13:08 -0700 | [diff] [blame] | 4136 | DRV_VERSION, (unsigned long long)pci_resource_start(pdev, 0), |
| 4137 | pdev->irq, yukon2_name[hw->chip_id - CHIP_ID_YUKON_XL], |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4138 | hw->chip_id, hw->chip_rev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4139 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4140 | sky2_reset(hw); |
| 4141 | |
| 4142 | dev = sky2_init_netdev(hw, 0, using_dac, wol_default); |
shemminger@linux-foundation.org | 7f60c64 | 2007-01-26 11:38:36 -0800 | [diff] [blame] | 4143 | if (!dev) { |
| 4144 | err = -ENOMEM; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4145 | goto err_out_free_pci; |
shemminger@linux-foundation.org | 7f60c64 | 2007-01-26 11:38:36 -0800 | [diff] [blame] | 4146 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4147 | |
Stephen Hemminger | 9fa1b1f | 2006-09-26 11:57:40 -0700 | [diff] [blame] | 4148 | if (!disable_msi && pci_enable_msi(pdev) == 0) { |
| 4149 | err = sky2_test_msi(hw); |
| 4150 | if (err == -EOPNOTSUPP) |
| 4151 | pci_disable_msi(pdev); |
| 4152 | else if (err) |
| 4153 | goto err_out_free_netdev; |
| 4154 | } |
| 4155 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4156 | err = register_netdev(dev); |
| 4157 | if (err) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4158 | dev_err(&pdev->dev, "cannot register net device\n"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4159 | goto err_out_free_netdev; |
| 4160 | } |
| 4161 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 4162 | err = request_irq(pdev->irq, sky2_intr, |
| 4163 | (hw->flags & SKY2_HW_USE_MSI) ? 0 : IRQF_SHARED, |
Stephen Hemminger | b0a20de | 2006-12-01 14:29:37 -0800 | [diff] [blame] | 4164 | dev->name, hw); |
Stephen Hemminger | 9fa1b1f | 2006-09-26 11:57:40 -0700 | [diff] [blame] | 4165 | if (err) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4166 | dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq); |
Stephen Hemminger | 9fa1b1f | 2006-09-26 11:57:40 -0700 | [diff] [blame] | 4167 | goto err_out_unregister; |
| 4168 | } |
| 4169 | sky2_write32(hw, B0_IMSK, Y2_IS_BASE); |
| 4170 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4171 | sky2_show_addr(dev); |
| 4172 | |
shemminger@linux-foundation.org | 7f60c64 | 2007-01-26 11:38:36 -0800 | [diff] [blame] | 4173 | if (hw->ports > 1) { |
| 4174 | struct net_device *dev1; |
| 4175 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4176 | dev1 = sky2_init_netdev(hw, 1, using_dac, wol_default); |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4177 | if (!dev1) |
| 4178 | dev_warn(&pdev->dev, "allocation for second device failed\n"); |
| 4179 | else if ((err = register_netdev(dev1))) { |
| 4180 | dev_warn(&pdev->dev, |
| 4181 | "register of second port failed (%d)\n", err); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4182 | hw->dev[1] = NULL; |
| 4183 | free_netdev(dev1); |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4184 | } else |
| 4185 | sky2_show_addr(dev1); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4186 | } |
| 4187 | |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 4188 | setup_timer(&hw->watchdog_timer, sky2_watchdog, (unsigned long) hw); |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 4189 | INIT_WORK(&hw->restart_work, sky2_restart); |
| 4190 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4191 | pci_set_drvdata(pdev, hw); |
| 4192 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4193 | return 0; |
| 4194 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4195 | err_out_unregister: |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 4196 | if (hw->flags & SKY2_HW_USE_MSI) |
Stephen Hemminger | b0a20de | 2006-12-01 14:29:37 -0800 | [diff] [blame] | 4197 | pci_disable_msi(pdev); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4198 | unregister_netdev(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4199 | err_out_free_netdev: |
| 4200 | free_netdev(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4201 | err_out_free_pci: |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4202 | sky2_write8(hw, B0_CTST, CS_RST_SET); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4203 | pci_free_consistent(hw->pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma); |
| 4204 | err_out_iounmap: |
| 4205 | iounmap(hw->regs); |
| 4206 | err_out_free_hw: |
| 4207 | kfree(hw); |
| 4208 | err_out_free_regions: |
| 4209 | pci_release_regions(pdev); |
Stephen Hemminger | 44a1d2e | 2007-04-30 14:23:49 -0700 | [diff] [blame] | 4210 | err_out_disable: |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4211 | pci_disable_device(pdev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4212 | err_out: |
Stephen Hemminger | 549a68c | 2007-05-11 11:21:44 -0700 | [diff] [blame] | 4213 | pci_set_drvdata(pdev, NULL); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4214 | return err; |
| 4215 | } |
| 4216 | |
| 4217 | static void __devexit sky2_remove(struct pci_dev *pdev) |
| 4218 | { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4219 | struct sky2_hw *hw = pci_get_drvdata(pdev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4220 | struct net_device *dev0, *dev1; |
| 4221 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4222 | if (!hw) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4223 | return; |
| 4224 | |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 4225 | del_timer_sync(&hw->watchdog_timer); |
Stephen Hemminger | d27ed38 | 2006-04-25 10:58:51 -0700 | [diff] [blame] | 4226 | |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 4227 | flush_scheduled_work(); |
| 4228 | |
Stephen Hemminger | d27ed38 | 2006-04-25 10:58:51 -0700 | [diff] [blame] | 4229 | sky2_write32(hw, B0_IMSK, 0); |
Stephen Hemminger | 72cb852 | 2006-05-08 15:11:32 -0700 | [diff] [blame] | 4230 | synchronize_irq(hw->pdev->irq); |
| 4231 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4232 | dev0 = hw->dev[0]; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4233 | dev1 = hw->dev[1]; |
| 4234 | if (dev1) |
| 4235 | unregister_netdev(dev1); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4236 | unregister_netdev(dev0); |
| 4237 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 4238 | sky2_power_aux(hw); |
| 4239 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4240 | sky2_write16(hw, B0_Y2LED, LED_STAT_OFF); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4241 | sky2_write8(hw, B0_CTST, CS_RST_SET); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 4242 | sky2_read8(hw, B0_CTST); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4243 | |
| 4244 | free_irq(pdev->irq, hw); |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 4245 | if (hw->flags & SKY2_HW_USE_MSI) |
Stephen Hemminger | b0a20de | 2006-12-01 14:29:37 -0800 | [diff] [blame] | 4246 | pci_disable_msi(pdev); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4247 | pci_free_consistent(pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4248 | pci_release_regions(pdev); |
| 4249 | pci_disable_device(pdev); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4250 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4251 | if (dev1) |
| 4252 | free_netdev(dev1); |
| 4253 | free_netdev(dev0); |
| 4254 | iounmap(hw->regs); |
| 4255 | kfree(hw); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 4256 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4257 | pci_set_drvdata(pdev, NULL); |
| 4258 | } |
| 4259 | |
| 4260 | #ifdef CONFIG_PM |
| 4261 | static int sky2_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4262 | { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4263 | struct sky2_hw *hw = pci_get_drvdata(pdev); |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4264 | int i, wol = 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4265 | |
Stephen Hemminger | 549a68c | 2007-05-11 11:21:44 -0700 | [diff] [blame] | 4266 | if (!hw) |
| 4267 | return 0; |
| 4268 | |
Stephen Hemminger | 6a5706b | 2006-07-12 15:23:46 -0700 | [diff] [blame] | 4269 | netif_poll_disable(hw->dev[0]); |
Stephen Hemminger | eb35cf6 | 2006-06-13 17:17:31 +0900 | [diff] [blame] | 4270 | |
Stephen Hemminger | f05267e | 2006-06-13 17:17:28 +0900 | [diff] [blame] | 4271 | for (i = 0; i < hw->ports; i++) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4272 | struct net_device *dev = hw->dev[i]; |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4273 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4274 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4275 | if (netif_running(dev)) |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 4276 | sky2_down(dev); |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4277 | |
| 4278 | if (sky2->wol) |
| 4279 | sky2_wol_init(sky2); |
| 4280 | |
| 4281 | wol |= sky2->wol; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4282 | } |
| 4283 | |
Stephen Hemminger | 8ab8fca | 2006-06-13 17:17:30 +0900 | [diff] [blame] | 4284 | sky2_write32(hw, B0_IMSK, 0); |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 4285 | sky2_power_aux(hw); |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4286 | |
Linus Torvalds | d374c1c | 2006-06-12 12:53:27 -0700 | [diff] [blame] | 4287 | pci_save_state(pdev); |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4288 | pci_enable_wake(pdev, pci_choose_state(pdev, state), wol); |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 4289 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 4290 | |
Stephen Hemminger | 2ccc99b | 2006-06-13 17:17:27 +0900 | [diff] [blame] | 4291 | return 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4292 | } |
| 4293 | |
| 4294 | static int sky2_resume(struct pci_dev *pdev) |
| 4295 | { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4296 | struct sky2_hw *hw = pci_get_drvdata(pdev); |
Stephen Hemminger | 08c06d8 | 2006-01-30 11:37:54 -0800 | [diff] [blame] | 4297 | int i, err; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4298 | |
Stephen Hemminger | 549a68c | 2007-05-11 11:21:44 -0700 | [diff] [blame] | 4299 | if (!hw) |
| 4300 | return 0; |
| 4301 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 4302 | err = pci_set_power_state(pdev, PCI_D0); |
| 4303 | if (err) |
| 4304 | goto out; |
| 4305 | |
| 4306 | err = pci_restore_state(pdev); |
| 4307 | if (err) |
| 4308 | goto out; |
| 4309 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4310 | pci_enable_wake(pdev, PCI_D0, 0); |
Stephen Hemminger | 1ad5b4a | 2007-04-07 16:02:27 -0700 | [diff] [blame] | 4311 | |
| 4312 | /* Re-enable all clocks */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 4313 | if (hw->chip_id == CHIP_ID_YUKON_EX || |
| 4314 | hw->chip_id == CHIP_ID_YUKON_EC_U || |
| 4315 | hw->chip_id == CHIP_ID_YUKON_FE_P) |
Stephen Hemminger | 1ad5b4a | 2007-04-07 16:02:27 -0700 | [diff] [blame] | 4316 | sky2_pci_write32(hw, PCI_DEV_REG3, 0); |
| 4317 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4318 | sky2_reset(hw); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4319 | |
Stephen Hemminger | 8ab8fca | 2006-06-13 17:17:30 +0900 | [diff] [blame] | 4320 | sky2_write32(hw, B0_IMSK, Y2_IS_BASE); |
| 4321 | |
Stephen Hemminger | f05267e | 2006-06-13 17:17:28 +0900 | [diff] [blame] | 4322 | for (i = 0; i < hw->ports; i++) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4323 | struct net_device *dev = hw->dev[i]; |
Stephen Hemminger | 6a5706b | 2006-07-12 15:23:46 -0700 | [diff] [blame] | 4324 | if (netif_running(dev)) { |
Stephen Hemminger | 08c06d8 | 2006-01-30 11:37:54 -0800 | [diff] [blame] | 4325 | err = sky2_up(dev); |
| 4326 | if (err) { |
| 4327 | printk(KERN_ERR PFX "%s: could not up: %d\n", |
| 4328 | dev->name, err); |
| 4329 | dev_close(dev); |
Stephen Hemminger | eb35cf6 | 2006-06-13 17:17:31 +0900 | [diff] [blame] | 4330 | goto out; |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 4331 | } |
Stephen Hemminger | d1b139c | 2007-09-05 16:56:19 +0100 | [diff] [blame] | 4332 | |
| 4333 | sky2_set_multicast(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4334 | } |
| 4335 | } |
Stephen Hemminger | eb35cf6 | 2006-06-13 17:17:31 +0900 | [diff] [blame] | 4336 | |
Stephen Hemminger | 6a5706b | 2006-07-12 15:23:46 -0700 | [diff] [blame] | 4337 | netif_poll_enable(hw->dev[0]); |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 4338 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 4339 | return 0; |
Stephen Hemminger | 08c06d8 | 2006-01-30 11:37:54 -0800 | [diff] [blame] | 4340 | out: |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4341 | dev_err(&pdev->dev, "resume failed (%d)\n", err); |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 4342 | pci_disable_device(pdev); |
Stephen Hemminger | 08c06d8 | 2006-01-30 11:37:54 -0800 | [diff] [blame] | 4343 | return err; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4344 | } |
| 4345 | #endif |
| 4346 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4347 | static void sky2_shutdown(struct pci_dev *pdev) |
| 4348 | { |
| 4349 | struct sky2_hw *hw = pci_get_drvdata(pdev); |
| 4350 | int i, wol = 0; |
| 4351 | |
Stephen Hemminger | 549a68c | 2007-05-11 11:21:44 -0700 | [diff] [blame] | 4352 | if (!hw) |
| 4353 | return; |
| 4354 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4355 | netif_poll_disable(hw->dev[0]); |
| 4356 | |
| 4357 | for (i = 0; i < hw->ports; i++) { |
| 4358 | struct net_device *dev = hw->dev[i]; |
| 4359 | struct sky2_port *sky2 = netdev_priv(dev); |
| 4360 | |
| 4361 | if (sky2->wol) { |
| 4362 | wol = 1; |
| 4363 | sky2_wol_init(sky2); |
| 4364 | } |
| 4365 | } |
| 4366 | |
| 4367 | if (wol) |
| 4368 | sky2_power_aux(hw); |
| 4369 | |
| 4370 | pci_enable_wake(pdev, PCI_D3hot, wol); |
| 4371 | pci_enable_wake(pdev, PCI_D3cold, wol); |
| 4372 | |
| 4373 | pci_disable_device(pdev); |
| 4374 | pci_set_power_state(pdev, PCI_D3hot); |
| 4375 | |
| 4376 | } |
| 4377 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4378 | static struct pci_driver sky2_driver = { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4379 | .name = DRV_NAME, |
| 4380 | .id_table = sky2_id_table, |
| 4381 | .probe = sky2_probe, |
| 4382 | .remove = __devexit_p(sky2_remove), |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4383 | #ifdef CONFIG_PM |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4384 | .suspend = sky2_suspend, |
| 4385 | .resume = sky2_resume, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4386 | #endif |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4387 | .shutdown = sky2_shutdown, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4388 | }; |
| 4389 | |
| 4390 | static int __init sky2_init_module(void) |
| 4391 | { |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4392 | sky2_debug_init(); |
shemminger@osdl.org | 50241c4 | 2005-11-30 11:45:22 -0800 | [diff] [blame] | 4393 | return pci_register_driver(&sky2_driver); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4394 | } |
| 4395 | |
| 4396 | static void __exit sky2_cleanup_module(void) |
| 4397 | { |
| 4398 | pci_unregister_driver(&sky2_driver); |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4399 | sky2_debug_cleanup(); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4400 | } |
| 4401 | |
| 4402 | module_init(sky2_init_module); |
| 4403 | module_exit(sky2_cleanup_module); |
| 4404 | |
| 4405 | MODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver"); |
Stephen Hemminger | 65ebe63 | 2007-01-23 11:38:57 -0800 | [diff] [blame] | 4406 | MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4407 | MODULE_LICENSE("GPL"); |
shemminger@osdl.org | 5f4f9dc | 2005-11-30 11:45:23 -0800 | [diff] [blame] | 4408 | MODULE_VERSION(DRV_VERSION); |