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