2 * New driver for Marvell Yukon 2 chipset.
3 * Based on earlier sk98lin, and skge driver.
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.
9 * Copyright (C) 2005 Stephen Hemminger <shemminger@osdl.org>
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
13 * the Free Software Foundation; either version 2 of the License.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
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.
25 #include <linux/crc32.h>
26 #include <linux/kernel.h>
27 #include <linux/version.h>
28 #include <linux/module.h>
29 #include <linux/netdevice.h>
30 #include <linux/dma-mapping.h>
31 #include <linux/etherdevice.h>
32 #include <linux/ethtool.h>
33 #include <linux/pci.h>
36 #include <linux/tcp.h>
38 #include <linux/delay.h>
39 #include <linux/workqueue.h>
40 #include <linux/if_vlan.h>
41 #include <linux/prefetch.h>
42 #include <linux/debugfs.h>
43 #include <linux/mii.h>
47 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
48 #define SKY2_VLAN_TAG_USED 1
53 #define DRV_NAME "sky2"
54 #define DRV_VERSION "1.16"
55 #define PFX DRV_NAME " "
58 * The Yukon II chipset takes 64 bit command blocks (called list elements)
59 * that are organized into three (receive, transmit, status) different rings
63 #define RX_LE_SIZE 1024
64 #define RX_LE_BYTES (RX_LE_SIZE*sizeof(struct sky2_rx_le))
65 #define RX_MAX_PENDING (RX_LE_SIZE/6 - 2)
66 #define RX_DEF_PENDING RX_MAX_PENDING
67 #define RX_SKB_ALIGN 8
69 #define TX_RING_SIZE 512
70 #define TX_DEF_PENDING (TX_RING_SIZE - 1)
71 #define TX_MIN_PENDING 64
72 #define MAX_SKB_TX_LE (4 + (sizeof(dma_addr_t)/sizeof(u32))*MAX_SKB_FRAGS)
74 #define STATUS_RING_SIZE 2048 /* 2 ports * (TX + 2*RX) */
75 #define STATUS_LE_BYTES (STATUS_RING_SIZE*sizeof(struct sky2_status_le))
76 #define TX_WATCHDOG (5 * HZ)
77 #define NAPI_WEIGHT 64
78 #define PHY_RETRIES 1000
80 #define SKY2_EEPROM_MAGIC 0x9955aabb
83 #define RING_NEXT(x,s) (((x)+1) & ((s)-1))
85 static const u32 default_msg
=
86 NETIF_MSG_DRV
| NETIF_MSG_PROBE
| NETIF_MSG_LINK
87 | NETIF_MSG_TIMER
| NETIF_MSG_TX_ERR
| NETIF_MSG_RX_ERR
88 | NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
;
90 static int debug
= -1; /* defaults above */
91 module_param(debug
, int, 0);
92 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
94 static int copybreak __read_mostly
= 128;
95 module_param(copybreak
, int, 0);
96 MODULE_PARM_DESC(copybreak
, "Receive copy threshold");
98 static int disable_msi
= 0;
99 module_param(disable_msi
, int, 0);
100 MODULE_PARM_DESC(disable_msi
, "Disable Message Signaled Interrupt (MSI)");
102 static const struct pci_device_id sky2_id_table
[] = {
103 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT
, 0x9000) }, /* SK-9Sxx */
104 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT
, 0x9E00) }, /* SK-9Exx */
105 { PCI_DEVICE(PCI_VENDOR_ID_DLINK
, 0x4b00) }, /* DGE-560T */
106 { PCI_DEVICE(PCI_VENDOR_ID_DLINK
, 0x4001) }, /* DGE-550SX */
107 { PCI_DEVICE(PCI_VENDOR_ID_DLINK
, 0x4B02) }, /* DGE-560SX */
108 { PCI_DEVICE(PCI_VENDOR_ID_DLINK
, 0x4B03) }, /* DGE-550T */
109 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4340) }, /* 88E8021 */
110 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4341) }, /* 88E8022 */
111 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4342) }, /* 88E8061 */
112 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4343) }, /* 88E8062 */
113 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4344) }, /* 88E8021 */
114 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4345) }, /* 88E8022 */
115 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4346) }, /* 88E8061 */
116 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4347) }, /* 88E8062 */
117 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4350) }, /* 88E8035 */
118 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4351) }, /* 88E8036 */
119 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4352) }, /* 88E8038 */
120 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4353) }, /* 88E8039 */
121 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4356) }, /* 88EC033 */
122 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4360) }, /* 88E8052 */
123 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4361) }, /* 88E8050 */
124 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4362) }, /* 88E8053 */
125 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4363) }, /* 88E8055 */
126 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4364) }, /* 88E8056 */
127 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4366) }, /* 88EC036 */
128 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4367) }, /* 88EC032 */
129 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4368) }, /* 88EC034 */
130 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x4369) }, /* 88EC042 */
131 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x436A) }, /* 88E8058 */
132 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL
, 0x436B) }, /* 88E8071 */
136 MODULE_DEVICE_TABLE(pci
, sky2_id_table
);
138 /* Avoid conditionals by using array */
139 static const unsigned txqaddr
[] = { Q_XA1
, Q_XA2
};
140 static const unsigned rxqaddr
[] = { Q_R1
, Q_R2
};
141 static const u32 portirq_msk
[] = { Y2_IS_PORT_1
, Y2_IS_PORT_2
};
143 /* This driver supports yukon2 chipset only */
144 static const char *yukon2_name
[] = {
146 "EC Ultra", /* 0xb4 */
147 "Extreme", /* 0xb5 */
152 /* Access to external PHY */
153 static int gm_phy_write(struct sky2_hw
*hw
, unsigned port
, u16 reg
, u16 val
)
157 gma_write16(hw
, port
, GM_SMI_DATA
, val
);
158 gma_write16(hw
, port
, GM_SMI_CTRL
,
159 GM_SMI_CT_PHY_AD(PHY_ADDR_MARV
) | GM_SMI_CT_REG_AD(reg
));
161 for (i
= 0; i
< PHY_RETRIES
; i
++) {
162 if (!(gma_read16(hw
, port
, GM_SMI_CTRL
) & GM_SMI_CT_BUSY
))
167 printk(KERN_WARNING PFX
"%s: phy write timeout\n", hw
->dev
[port
]->name
);
171 static int __gm_phy_read(struct sky2_hw
*hw
, unsigned port
, u16 reg
, u16
*val
)
175 gma_write16(hw
, port
, GM_SMI_CTRL
, GM_SMI_CT_PHY_AD(PHY_ADDR_MARV
)
176 | GM_SMI_CT_REG_AD(reg
) | GM_SMI_CT_OP_RD
);
178 for (i
= 0; i
< PHY_RETRIES
; i
++) {
179 if (gma_read16(hw
, port
, GM_SMI_CTRL
) & GM_SMI_CT_RD_VAL
) {
180 *val
= gma_read16(hw
, port
, GM_SMI_DATA
);
190 static u16
gm_phy_read(struct sky2_hw
*hw
, unsigned port
, u16 reg
)
194 if (__gm_phy_read(hw
, port
, reg
, &v
) != 0)
195 printk(KERN_WARNING PFX
"%s: phy read timeout\n", hw
->dev
[port
]->name
);
200 static void sky2_power_on(struct sky2_hw
*hw
)
202 /* switch power to VCC (WA for VAUX problem) */
203 sky2_write8(hw
, B0_POWER_CTRL
,
204 PC_VAUX_ENA
| PC_VCC_ENA
| PC_VAUX_OFF
| PC_VCC_ON
);
206 /* disable Core Clock Division, */
207 sky2_write32(hw
, B2_Y2_CLK_CTRL
, Y2_CLK_DIV_DIS
);
209 if (hw
->chip_id
== CHIP_ID_YUKON_XL
&& hw
->chip_rev
> 1)
210 /* enable bits are inverted */
211 sky2_write8(hw
, B2_Y2_CLK_GATE
,
212 Y2_PCI_CLK_LNK1_DIS
| Y2_COR_CLK_LNK1_DIS
|
213 Y2_CLK_GAT_LNK1_DIS
| Y2_PCI_CLK_LNK2_DIS
|
214 Y2_COR_CLK_LNK2_DIS
| Y2_CLK_GAT_LNK2_DIS
);
216 sky2_write8(hw
, B2_Y2_CLK_GATE
, 0);
218 if (hw
->chip_id
== CHIP_ID_YUKON_EC_U
||
219 hw
->chip_id
== CHIP_ID_YUKON_EX
) {
222 sky2_pci_write32(hw
, PCI_DEV_REG3
, 0);
224 reg
= sky2_pci_read32(hw
, PCI_DEV_REG4
);
225 /* set all bits to 0 except bits 15..12 and 8 */
226 reg
&= P_ASPM_CONTROL_MSK
;
227 sky2_pci_write32(hw
, PCI_DEV_REG4
, reg
);
229 reg
= sky2_pci_read32(hw
, PCI_DEV_REG5
);
230 /* set all bits to 0 except bits 28 & 27 */
231 reg
&= P_CTL_TIM_VMAIN_AV_MSK
;
232 sky2_pci_write32(hw
, PCI_DEV_REG5
, reg
);
234 sky2_pci_write32(hw
, PCI_CFG_REG_1
, 0);
236 /* Enable workaround for dev 4.107 on Yukon-Ultra & Extreme */
237 reg
= sky2_read32(hw
, B2_GP_IO
);
238 reg
|= GLB_GPIO_STAT_RACE_DIS
;
239 sky2_write32(hw
, B2_GP_IO
, reg
);
241 sky2_read32(hw
, B2_GP_IO
);
245 static void sky2_power_aux(struct sky2_hw
*hw
)
247 if (hw
->chip_id
== CHIP_ID_YUKON_XL
&& hw
->chip_rev
> 1)
248 sky2_write8(hw
, B2_Y2_CLK_GATE
, 0);
250 /* enable bits are inverted */
251 sky2_write8(hw
, B2_Y2_CLK_GATE
,
252 Y2_PCI_CLK_LNK1_DIS
| Y2_COR_CLK_LNK1_DIS
|
253 Y2_CLK_GAT_LNK1_DIS
| Y2_PCI_CLK_LNK2_DIS
|
254 Y2_COR_CLK_LNK2_DIS
| Y2_CLK_GAT_LNK2_DIS
);
256 /* switch power to VAUX */
257 if (sky2_read16(hw
, B0_CTST
) & Y2_VAUX_AVAIL
)
258 sky2_write8(hw
, B0_POWER_CTRL
,
259 (PC_VAUX_ENA
| PC_VCC_ENA
|
260 PC_VAUX_ON
| PC_VCC_OFF
));
263 static void sky2_gmac_reset(struct sky2_hw
*hw
, unsigned port
)
267 /* disable all GMAC IRQ's */
268 sky2_write8(hw
, SK_REG(port
, GMAC_IRQ_MSK
), 0);
269 /* disable PHY IRQs */
270 gm_phy_write(hw
, port
, PHY_MARV_INT_MASK
, 0);
272 gma_write16(hw
, port
, GM_MC_ADDR_H1
, 0); /* clear MC hash */
273 gma_write16(hw
, port
, GM_MC_ADDR_H2
, 0);
274 gma_write16(hw
, port
, GM_MC_ADDR_H3
, 0);
275 gma_write16(hw
, port
, GM_MC_ADDR_H4
, 0);
277 reg
= gma_read16(hw
, port
, GM_RX_CTRL
);
278 reg
|= GM_RXCR_UCF_ENA
| GM_RXCR_MCF_ENA
;
279 gma_write16(hw
, port
, GM_RX_CTRL
, reg
);
282 /* flow control to advertise bits */
283 static const u16 copper_fc_adv
[] = {
285 [FC_TX
] = PHY_M_AN_ASP
,
286 [FC_RX
] = PHY_M_AN_PC
,
287 [FC_BOTH
] = PHY_M_AN_PC
| PHY_M_AN_ASP
,
290 /* flow control to advertise bits when using 1000BaseX */
291 static const u16 fiber_fc_adv
[] = {
292 [FC_BOTH
] = PHY_M_P_BOTH_MD_X
,
293 [FC_TX
] = PHY_M_P_ASYM_MD_X
,
294 [FC_RX
] = PHY_M_P_SYM_MD_X
,
295 [FC_NONE
] = PHY_M_P_NO_PAUSE_X
,
298 /* flow control to GMA disable bits */
299 static const u16 gm_fc_disable
[] = {
300 [FC_NONE
] = GM_GPCR_FC_RX_DIS
| GM_GPCR_FC_TX_DIS
,
301 [FC_TX
] = GM_GPCR_FC_RX_DIS
,
302 [FC_RX
] = GM_GPCR_FC_TX_DIS
,
307 static void sky2_phy_init(struct sky2_hw
*hw
, unsigned port
)
309 struct sky2_port
*sky2
= netdev_priv(hw
->dev
[port
]);
310 u16 ctrl
, ct1000
, adv
, pg
, ledctrl
, ledover
, reg
;
312 if (sky2
->autoneg
== AUTONEG_ENABLE
313 && !(hw
->chip_id
== CHIP_ID_YUKON_XL
314 || hw
->chip_id
== CHIP_ID_YUKON_EC_U
315 || hw
->chip_id
== CHIP_ID_YUKON_EX
)) {
316 u16 ectrl
= gm_phy_read(hw
, port
, PHY_MARV_EXT_CTRL
);
318 ectrl
&= ~(PHY_M_EC_M_DSC_MSK
| PHY_M_EC_S_DSC_MSK
|
320 ectrl
|= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ
);
322 /* on PHY 88E1040 Rev.D0 (and newer) downshift control changed */
323 if (hw
->chip_id
== CHIP_ID_YUKON_EC
)
324 /* set downshift counter to 3x and enable downshift */
325 ectrl
|= PHY_M_EC_DSC_2(2) | PHY_M_EC_DOWN_S_ENA
;
327 /* set master & slave downshift counter to 1x */
328 ectrl
|= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
330 gm_phy_write(hw
, port
, PHY_MARV_EXT_CTRL
, ectrl
);
333 ctrl
= gm_phy_read(hw
, port
, PHY_MARV_PHY_CTRL
);
334 if (sky2_is_copper(hw
)) {
335 if (hw
->chip_id
== CHIP_ID_YUKON_FE
) {
336 /* enable automatic crossover */
337 ctrl
|= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO
) >> 1;
339 /* disable energy detect */
340 ctrl
&= ~PHY_M_PC_EN_DET_MSK
;
342 /* enable automatic crossover */
343 ctrl
|= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO
);
345 /* downshift on PHY 88E1112 and 88E1149 is changed */
346 if (sky2
->autoneg
== AUTONEG_ENABLE
347 && (hw
->chip_id
== CHIP_ID_YUKON_XL
348 || hw
->chip_id
== CHIP_ID_YUKON_EC_U
349 || hw
->chip_id
== CHIP_ID_YUKON_EX
)) {
350 /* set downshift counter to 3x and enable downshift */
351 ctrl
&= ~PHY_M_PC_DSC_MSK
;
352 ctrl
|= PHY_M_PC_DSC(2) | PHY_M_PC_DOWN_S_ENA
;
356 /* workaround for deviation #4.88 (CRC errors) */
357 /* disable Automatic Crossover */
359 ctrl
&= ~PHY_M_PC_MDIX_MSK
;
362 gm_phy_write(hw
, port
, PHY_MARV_PHY_CTRL
, ctrl
);
364 /* special setup for PHY 88E1112 Fiber */
365 if (hw
->chip_id
== CHIP_ID_YUKON_XL
&& !sky2_is_copper(hw
)) {
366 pg
= gm_phy_read(hw
, port
, PHY_MARV_EXT_ADR
);
368 /* Fiber: select 1000BASE-X only mode MAC Specific Ctrl Reg. */
369 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, 2);
370 ctrl
= gm_phy_read(hw
, port
, PHY_MARV_PHY_CTRL
);
371 ctrl
&= ~PHY_M_MAC_MD_MSK
;
372 ctrl
|= PHY_M_MAC_MODE_SEL(PHY_M_MAC_MD_1000BX
);
373 gm_phy_write(hw
, port
, PHY_MARV_PHY_CTRL
, ctrl
);
375 if (hw
->pmd_type
== 'P') {
376 /* select page 1 to access Fiber registers */
377 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, 1);
379 /* for SFP-module set SIGDET polarity to low */
380 ctrl
= gm_phy_read(hw
, port
, PHY_MARV_PHY_CTRL
);
381 ctrl
|= PHY_M_FIB_SIGD_POL
;
382 gm_phy_write(hw
, port
, PHY_MARV_PHY_CTRL
, ctrl
);
385 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, pg
);
393 if (sky2
->autoneg
== AUTONEG_ENABLE
) {
394 if (sky2_is_copper(hw
)) {
395 if (sky2
->advertising
& ADVERTISED_1000baseT_Full
)
396 ct1000
|= PHY_M_1000C_AFD
;
397 if (sky2
->advertising
& ADVERTISED_1000baseT_Half
)
398 ct1000
|= PHY_M_1000C_AHD
;
399 if (sky2
->advertising
& ADVERTISED_100baseT_Full
)
400 adv
|= PHY_M_AN_100_FD
;
401 if (sky2
->advertising
& ADVERTISED_100baseT_Half
)
402 adv
|= PHY_M_AN_100_HD
;
403 if (sky2
->advertising
& ADVERTISED_10baseT_Full
)
404 adv
|= PHY_M_AN_10_FD
;
405 if (sky2
->advertising
& ADVERTISED_10baseT_Half
)
406 adv
|= PHY_M_AN_10_HD
;
408 adv
|= copper_fc_adv
[sky2
->flow_mode
];
409 } else { /* special defines for FIBER (88E1040S only) */
410 if (sky2
->advertising
& ADVERTISED_1000baseT_Full
)
411 adv
|= PHY_M_AN_1000X_AFD
;
412 if (sky2
->advertising
& ADVERTISED_1000baseT_Half
)
413 adv
|= PHY_M_AN_1000X_AHD
;
415 adv
|= fiber_fc_adv
[sky2
->flow_mode
];
418 /* Restart Auto-negotiation */
419 ctrl
|= PHY_CT_ANE
| PHY_CT_RE_CFG
;
421 /* forced speed/duplex settings */
422 ct1000
= PHY_M_1000C_MSE
;
424 /* Disable auto update for duplex flow control and speed */
425 reg
|= GM_GPCR_AU_ALL_DIS
;
427 switch (sky2
->speed
) {
429 ctrl
|= PHY_CT_SP1000
;
430 reg
|= GM_GPCR_SPEED_1000
;
433 ctrl
|= PHY_CT_SP100
;
434 reg
|= GM_GPCR_SPEED_100
;
438 if (sky2
->duplex
== DUPLEX_FULL
) {
439 reg
|= GM_GPCR_DUP_FULL
;
440 ctrl
|= PHY_CT_DUP_MD
;
441 } else if (sky2
->speed
< SPEED_1000
)
442 sky2
->flow_mode
= FC_NONE
;
445 reg
|= gm_fc_disable
[sky2
->flow_mode
];
447 /* Forward pause packets to GMAC? */
448 if (sky2
->flow_mode
& FC_RX
)
449 sky2_write8(hw
, SK_REG(port
, GMAC_CTRL
), GMC_PAUSE_ON
);
451 sky2_write8(hw
, SK_REG(port
, GMAC_CTRL
), GMC_PAUSE_OFF
);
454 gma_write16(hw
, port
, GM_GP_CTRL
, reg
);
456 if (hw
->chip_id
!= CHIP_ID_YUKON_FE
)
457 gm_phy_write(hw
, port
, PHY_MARV_1000T_CTRL
, ct1000
);
459 gm_phy_write(hw
, port
, PHY_MARV_AUNE_ADV
, adv
);
460 gm_phy_write(hw
, port
, PHY_MARV_CTRL
, ctrl
);
462 /* Setup Phy LED's */
463 ledctrl
= PHY_M_LED_PULS_DUR(PULS_170MS
);
466 switch (hw
->chip_id
) {
467 case CHIP_ID_YUKON_FE
:
468 /* on 88E3082 these bits are at 11..9 (shifted left) */
469 ledctrl
|= PHY_M_LED_BLINK_RT(BLINK_84MS
) << 1;
471 ctrl
= gm_phy_read(hw
, port
, PHY_MARV_FE_LED_PAR
);
473 /* delete ACT LED control bits */
474 ctrl
&= ~PHY_M_FELP_LED1_MSK
;
475 /* change ACT LED control to blink mode */
476 ctrl
|= PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_ACT_BL
);
477 gm_phy_write(hw
, port
, PHY_MARV_FE_LED_PAR
, ctrl
);
480 case CHIP_ID_YUKON_XL
:
481 pg
= gm_phy_read(hw
, port
, PHY_MARV_EXT_ADR
);
483 /* select page 3 to access LED control register */
484 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, 3);
486 /* set LED Function Control register */
487 gm_phy_write(hw
, port
, PHY_MARV_PHY_CTRL
,
488 (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */
489 PHY_M_LEDC_INIT_CTRL(7) | /* 10 Mbps */
490 PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */
491 PHY_M_LEDC_STA0_CTRL(7))); /* 1000 Mbps */
493 /* set Polarity Control register */
494 gm_phy_write(hw
, port
, PHY_MARV_PHY_STAT
,
495 (PHY_M_POLC_LS1_P_MIX(4) |
496 PHY_M_POLC_IS0_P_MIX(4) |
497 PHY_M_POLC_LOS_CTRL(2) |
498 PHY_M_POLC_INIT_CTRL(2) |
499 PHY_M_POLC_STA1_CTRL(2) |
500 PHY_M_POLC_STA0_CTRL(2)));
502 /* restore page register */
503 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, pg
);
506 case CHIP_ID_YUKON_EC_U
:
507 case CHIP_ID_YUKON_EX
:
508 pg
= gm_phy_read(hw
, port
, PHY_MARV_EXT_ADR
);
510 /* select page 3 to access LED control register */
511 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, 3);
513 /* set LED Function Control register */
514 gm_phy_write(hw
, port
, PHY_MARV_PHY_CTRL
,
515 (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */
516 PHY_M_LEDC_INIT_CTRL(8) | /* 10 Mbps */
517 PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */
518 PHY_M_LEDC_STA0_CTRL(7)));/* 1000 Mbps */
520 /* set Blink Rate in LED Timer Control Register */
521 gm_phy_write(hw
, port
, PHY_MARV_INT_MASK
,
522 ledctrl
| PHY_M_LED_BLINK_RT(BLINK_84MS
));
523 /* restore page register */
524 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, pg
);
528 /* set Tx LED (LED_TX) to blink mode on Rx OR Tx activity */
529 ledctrl
|= PHY_M_LED_BLINK_RT(BLINK_84MS
) | PHY_M_LEDC_TX_CTRL
;
530 /* turn off the Rx LED (LED_RX) */
531 ledover
&= ~PHY_M_LED_MO_RX
;
534 if (hw
->chip_id
== CHIP_ID_YUKON_EC_U
&&
535 hw
->chip_rev
== CHIP_REV_YU_EC_U_A1
) {
536 /* apply fixes in PHY AFE */
537 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, 255);
539 /* increase differential signal amplitude in 10BASE-T */
540 gm_phy_write(hw
, port
, 0x18, 0xaa99);
541 gm_phy_write(hw
, port
, 0x17, 0x2011);
543 /* fix for IEEE A/B Symmetry failure in 1000BASE-T */
544 gm_phy_write(hw
, port
, 0x18, 0xa204);
545 gm_phy_write(hw
, port
, 0x17, 0x2002);
547 /* set page register to 0 */
548 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, 0);
549 } else if (hw
->chip_id
!= CHIP_ID_YUKON_EX
) {
550 gm_phy_write(hw
, port
, PHY_MARV_LED_CTRL
, ledctrl
);
552 if (sky2
->autoneg
== AUTONEG_DISABLE
|| sky2
->speed
== SPEED_100
) {
553 /* turn on 100 Mbps LED (LED_LINK100) */
554 ledover
|= PHY_M_LED_MO_100
;
558 gm_phy_write(hw
, port
, PHY_MARV_LED_OVER
, ledover
);
562 /* Enable phy interrupt on auto-negotiation complete (or link up) */
563 if (sky2
->autoneg
== AUTONEG_ENABLE
)
564 gm_phy_write(hw
, port
, PHY_MARV_INT_MASK
, PHY_M_IS_AN_COMPL
);
566 gm_phy_write(hw
, port
, PHY_MARV_INT_MASK
, PHY_M_DEF_MSK
);
569 static void sky2_phy_power(struct sky2_hw
*hw
, unsigned port
, int onoff
)
572 static const u32 phy_power
[]
573 = { PCI_Y2_PHY1_POWD
, PCI_Y2_PHY2_POWD
};
575 /* looks like this XL is back asswards .. */
576 if (hw
->chip_id
== CHIP_ID_YUKON_XL
&& hw
->chip_rev
> 1)
579 sky2_write8(hw
, B2_TST_CTRL1
, TST_CFG_WRITE_ON
);
580 reg1
= sky2_pci_read32(hw
, PCI_DEV_REG1
);
582 /* Turn off phy power saving */
583 reg1
&= ~phy_power
[port
];
585 reg1
|= phy_power
[port
];
587 sky2_pci_write32(hw
, PCI_DEV_REG1
, reg1
);
588 sky2_pci_read32(hw
, PCI_DEV_REG1
);
589 sky2_write8(hw
, B2_TST_CTRL1
, TST_CFG_WRITE_OFF
);
593 /* Force a renegotiation */
594 static void sky2_phy_reinit(struct sky2_port
*sky2
)
596 spin_lock_bh(&sky2
->phy_lock
);
597 sky2_phy_init(sky2
->hw
, sky2
->port
);
598 spin_unlock_bh(&sky2
->phy_lock
);
601 /* Put device in state to listen for Wake On Lan */
602 static void sky2_wol_init(struct sky2_port
*sky2
)
604 struct sky2_hw
*hw
= sky2
->hw
;
605 unsigned port
= sky2
->port
;
606 enum flow_control save_mode
;
610 /* Bring hardware out of reset */
611 sky2_write16(hw
, B0_CTST
, CS_RST_CLR
);
612 sky2_write16(hw
, SK_REG(port
, GMAC_LINK_CTRL
), GMLC_RST_CLR
);
614 sky2_write8(hw
, SK_REG(port
, GPHY_CTRL
), GPC_RST_CLR
);
615 sky2_write8(hw
, SK_REG(port
, GMAC_CTRL
), GMC_RST_CLR
);
618 * sky2_reset will re-enable on resume
620 save_mode
= sky2
->flow_mode
;
621 ctrl
= sky2
->advertising
;
623 sky2
->advertising
&= ~(ADVERTISED_1000baseT_Half
|ADVERTISED_1000baseT_Full
);
624 sky2
->flow_mode
= FC_NONE
;
625 sky2_phy_power(hw
, port
, 1);
626 sky2_phy_reinit(sky2
);
628 sky2
->flow_mode
= save_mode
;
629 sky2
->advertising
= ctrl
;
631 /* Set GMAC to no flow control and auto update for speed/duplex */
632 gma_write16(hw
, port
, GM_GP_CTRL
,
633 GM_GPCR_FC_TX_DIS
|GM_GPCR_TX_ENA
|GM_GPCR_RX_ENA
|
634 GM_GPCR_DUP_FULL
|GM_GPCR_FC_RX_DIS
|GM_GPCR_AU_FCT_DIS
);
636 /* Set WOL address */
637 memcpy_toio(hw
->regs
+ WOL_REGS(port
, WOL_MAC_ADDR
),
638 sky2
->netdev
->dev_addr
, ETH_ALEN
);
640 /* Turn on appropriate WOL control bits */
641 sky2_write16(hw
, WOL_REGS(port
, WOL_CTRL_STAT
), WOL_CTL_CLEAR_RESULT
);
643 if (sky2
->wol
& WAKE_PHY
)
644 ctrl
|= WOL_CTL_ENA_PME_ON_LINK_CHG
|WOL_CTL_ENA_LINK_CHG_UNIT
;
646 ctrl
|= WOL_CTL_DIS_PME_ON_LINK_CHG
|WOL_CTL_DIS_LINK_CHG_UNIT
;
648 if (sky2
->wol
& WAKE_MAGIC
)
649 ctrl
|= WOL_CTL_ENA_PME_ON_MAGIC_PKT
|WOL_CTL_ENA_MAGIC_PKT_UNIT
;
651 ctrl
|= WOL_CTL_DIS_PME_ON_MAGIC_PKT
|WOL_CTL_DIS_MAGIC_PKT_UNIT
;;
653 ctrl
|= WOL_CTL_DIS_PME_ON_PATTERN
|WOL_CTL_DIS_PATTERN_UNIT
;
654 sky2_write16(hw
, WOL_REGS(port
, WOL_CTRL_STAT
), ctrl
);
656 /* Turn on legacy PCI-Express PME mode */
657 sky2_write8(hw
, B2_TST_CTRL1
, TST_CFG_WRITE_ON
);
658 reg1
= sky2_pci_read32(hw
, PCI_DEV_REG1
);
659 reg1
|= PCI_Y2_PME_LEGACY
;
660 sky2_pci_write32(hw
, PCI_DEV_REG1
, reg1
);
661 sky2_write8(hw
, B2_TST_CTRL1
, TST_CFG_WRITE_OFF
);
664 sky2_write8(hw
, SK_REG(port
, RX_GMF_CTRL_T
), GMF_RST_SET
);
668 static void sky2_set_tx_stfwd(struct sky2_hw
*hw
, unsigned port
)
670 if (hw
->chip_id
== CHIP_ID_YUKON_EX
&& hw
->chip_rev
!= CHIP_REV_YU_EX_A0
) {
671 sky2_write32(hw
, SK_REG(port
, TX_GMF_CTRL_T
),
673 (hw
->dev
[port
]->mtu
> ETH_DATA_LEN
) ? TX_JUMBO_ENA
: TX_JUMBO_DIS
);
675 if (hw
->dev
[port
]->mtu
> ETH_DATA_LEN
) {
676 /* set Tx GMAC FIFO Almost Empty Threshold */
677 sky2_write32(hw
, SK_REG(port
, TX_GMF_AE_THR
),
678 (ECU_JUMBO_WM
<< 16) | ECU_AE_THR
);
680 sky2_write32(hw
, SK_REG(port
, TX_GMF_CTRL_T
),
681 TX_JUMBO_ENA
| TX_STFW_DIS
);
683 /* Can't do offload because of lack of store/forward */
684 hw
->dev
[port
]->features
&= ~(NETIF_F_TSO
| NETIF_F_SG
687 sky2_write32(hw
, SK_REG(port
, TX_GMF_CTRL_T
),
688 TX_JUMBO_DIS
| TX_STFW_ENA
);
692 static void sky2_mac_init(struct sky2_hw
*hw
, unsigned port
)
694 struct sky2_port
*sky2
= netdev_priv(hw
->dev
[port
]);
698 const u8
*addr
= hw
->dev
[port
]->dev_addr
;
700 sky2_write8(hw
, SK_REG(port
, GPHY_CTRL
), GPC_RST_SET
);
701 sky2_write8(hw
, SK_REG(port
, GPHY_CTRL
), GPC_RST_CLR
);
703 sky2_write8(hw
, SK_REG(port
, GMAC_CTRL
), GMC_RST_CLR
);
705 if (hw
->chip_id
== CHIP_ID_YUKON_XL
&& hw
->chip_rev
== 0 && port
== 1) {
706 /* WA DEV_472 -- looks like crossed wires on port 2 */
707 /* clear GMAC 1 Control reset */
708 sky2_write8(hw
, SK_REG(0, GMAC_CTRL
), GMC_RST_CLR
);
710 sky2_write8(hw
, SK_REG(1, GMAC_CTRL
), GMC_RST_SET
);
711 sky2_write8(hw
, SK_REG(1, GMAC_CTRL
), GMC_RST_CLR
);
712 } while (gm_phy_read(hw
, 1, PHY_MARV_ID0
) != PHY_MARV_ID0_VAL
||
713 gm_phy_read(hw
, 1, PHY_MARV_ID1
) != PHY_MARV_ID1_Y2
||
714 gm_phy_read(hw
, 1, PHY_MARV_INT_MASK
) != 0);
717 sky2_read16(hw
, SK_REG(port
, GMAC_IRQ_SRC
));
719 /* Enable Transmit FIFO Underrun */
720 sky2_write8(hw
, SK_REG(port
, GMAC_IRQ_MSK
), GMAC_DEF_MSK
);
722 spin_lock_bh(&sky2
->phy_lock
);
723 sky2_phy_init(hw
, port
);
724 spin_unlock_bh(&sky2
->phy_lock
);
727 reg
= gma_read16(hw
, port
, GM_PHY_ADDR
);
728 gma_write16(hw
, port
, GM_PHY_ADDR
, reg
| GM_PAR_MIB_CLR
);
730 for (i
= GM_MIB_CNT_BASE
; i
<= GM_MIB_CNT_END
; i
+= 4)
731 gma_read16(hw
, port
, i
);
732 gma_write16(hw
, port
, GM_PHY_ADDR
, reg
);
734 /* transmit control */
735 gma_write16(hw
, port
, GM_TX_CTRL
, TX_COL_THR(TX_COL_DEF
));
737 /* receive control reg: unicast + multicast + no FCS */
738 gma_write16(hw
, port
, GM_RX_CTRL
,
739 GM_RXCR_UCF_ENA
| GM_RXCR_CRC_DIS
| GM_RXCR_MCF_ENA
);
741 /* transmit flow control */
742 gma_write16(hw
, port
, GM_TX_FLOW_CTRL
, 0xffff);
744 /* transmit parameter */
745 gma_write16(hw
, port
, GM_TX_PARAM
,
746 TX_JAM_LEN_VAL(TX_JAM_LEN_DEF
) |
747 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF
) |
748 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF
) |
749 TX_BACK_OFF_LIM(TX_BOF_LIM_DEF
));
751 /* serial mode register */
752 reg
= DATA_BLIND_VAL(DATA_BLIND_DEF
) |
753 GM_SMOD_VLAN_ENA
| IPG_DATA_VAL(IPG_DATA_DEF
);
755 if (hw
->dev
[port
]->mtu
> ETH_DATA_LEN
)
756 reg
|= GM_SMOD_JUMBO_ENA
;
758 gma_write16(hw
, port
, GM_SERIAL_MODE
, reg
);
760 /* virtual address for data */
761 gma_set_addr(hw
, port
, GM_SRC_ADDR_2L
, addr
);
763 /* physical address: used for pause frames */
764 gma_set_addr(hw
, port
, GM_SRC_ADDR_1L
, addr
);
766 /* ignore counter overflows */
767 gma_write16(hw
, port
, GM_TX_IRQ_MSK
, 0);
768 gma_write16(hw
, port
, GM_RX_IRQ_MSK
, 0);
769 gma_write16(hw
, port
, GM_TR_IRQ_MSK
, 0);
771 /* Configure Rx MAC FIFO */
772 sky2_write8(hw
, SK_REG(port
, RX_GMF_CTRL_T
), GMF_RST_CLR
);
773 rx_reg
= GMF_OPER_ON
| GMF_RX_F_FL_ON
;
774 if (hw
->chip_id
== CHIP_ID_YUKON_EX
)
775 rx_reg
|= GMF_RX_OVER_ON
;
777 sky2_write32(hw
, SK_REG(port
, RX_GMF_CTRL_T
), rx_reg
);
779 /* Flush Rx MAC FIFO on any flow control or error */
780 sky2_write16(hw
, SK_REG(port
, RX_GMF_FL_MSK
), GMR_FS_ANY_ERR
);
782 /* Set threshold to 0xa (64 bytes) + 1 to workaround pause bug */
783 sky2_write16(hw
, SK_REG(port
, RX_GMF_FL_THR
), RX_GMF_FL_THR_DEF
+1);
785 /* Configure Tx MAC FIFO */
786 sky2_write8(hw
, SK_REG(port
, TX_GMF_CTRL_T
), GMF_RST_CLR
);
787 sky2_write16(hw
, SK_REG(port
, TX_GMF_CTRL_T
), GMF_OPER_ON
);
789 if (hw
->chip_id
== CHIP_ID_YUKON_EC_U
|| hw
->chip_id
== CHIP_ID_YUKON_EX
) {
790 sky2_write8(hw
, SK_REG(port
, RX_GMF_LP_THR
), 768/8);
791 sky2_write8(hw
, SK_REG(port
, RX_GMF_UP_THR
), 1024/8);
793 sky2_set_tx_stfwd(hw
, port
);
798 /* Assign Ram Buffer allocation to queue */
799 static void sky2_ramset(struct sky2_hw
*hw
, u16 q
, u32 start
, u32 space
)
803 /* convert from K bytes to qwords used for hw register */
806 end
= start
+ space
- 1;
808 sky2_write8(hw
, RB_ADDR(q
, RB_CTRL
), RB_RST_CLR
);
809 sky2_write32(hw
, RB_ADDR(q
, RB_START
), start
);
810 sky2_write32(hw
, RB_ADDR(q
, RB_END
), end
);
811 sky2_write32(hw
, RB_ADDR(q
, RB_WP
), start
);
812 sky2_write32(hw
, RB_ADDR(q
, RB_RP
), start
);
814 if (q
== Q_R1
|| q
== Q_R2
) {
815 u32 tp
= space
- space
/4;
817 /* On receive queue's set the thresholds
818 * give receiver priority when > 3/4 full
819 * send pause when down to 2K
821 sky2_write32(hw
, RB_ADDR(q
, RB_RX_UTHP
), tp
);
822 sky2_write32(hw
, RB_ADDR(q
, RB_RX_LTHP
), space
/2);
825 sky2_write32(hw
, RB_ADDR(q
, RB_RX_UTPP
), tp
);
826 sky2_write32(hw
, RB_ADDR(q
, RB_RX_LTPP
), space
/4);
828 /* Enable store & forward on Tx queue's because
829 * Tx FIFO is only 1K on Yukon
831 sky2_write8(hw
, RB_ADDR(q
, RB_CTRL
), RB_ENA_STFWD
);
834 sky2_write8(hw
, RB_ADDR(q
, RB_CTRL
), RB_ENA_OP_MD
);
835 sky2_read8(hw
, RB_ADDR(q
, RB_CTRL
));
838 /* Setup Bus Memory Interface */
839 static void sky2_qset(struct sky2_hw
*hw
, u16 q
)
841 sky2_write32(hw
, Q_ADDR(q
, Q_CSR
), BMU_CLR_RESET
);
842 sky2_write32(hw
, Q_ADDR(q
, Q_CSR
), BMU_OPER_INIT
);
843 sky2_write32(hw
, Q_ADDR(q
, Q_CSR
), BMU_FIFO_OP_ON
);
844 sky2_write32(hw
, Q_ADDR(q
, Q_WM
), BMU_WM_DEFAULT
);
847 /* Setup prefetch unit registers. This is the interface between
848 * hardware and driver list elements
850 static void sky2_prefetch_init(struct sky2_hw
*hw
, u32 qaddr
,
853 sky2_write32(hw
, Y2_QADDR(qaddr
, PREF_UNIT_CTRL
), PREF_UNIT_RST_SET
);
854 sky2_write32(hw
, Y2_QADDR(qaddr
, PREF_UNIT_CTRL
), PREF_UNIT_RST_CLR
);
855 sky2_write32(hw
, Y2_QADDR(qaddr
, PREF_UNIT_ADDR_HI
), addr
>> 32);
856 sky2_write32(hw
, Y2_QADDR(qaddr
, PREF_UNIT_ADDR_LO
), (u32
) addr
);
857 sky2_write16(hw
, Y2_QADDR(qaddr
, PREF_UNIT_LAST_IDX
), last
);
858 sky2_write32(hw
, Y2_QADDR(qaddr
, PREF_UNIT_CTRL
), PREF_UNIT_OP_ON
);
860 sky2_read32(hw
, Y2_QADDR(qaddr
, PREF_UNIT_CTRL
));
863 static inline struct sky2_tx_le
*get_tx_le(struct sky2_port
*sky2
)
865 struct sky2_tx_le
*le
= sky2
->tx_le
+ sky2
->tx_prod
;
867 sky2
->tx_prod
= RING_NEXT(sky2
->tx_prod
, TX_RING_SIZE
);
872 static inline struct tx_ring_info
*tx_le_re(struct sky2_port
*sky2
,
873 struct sky2_tx_le
*le
)
875 return sky2
->tx_ring
+ (le
- sky2
->tx_le
);
878 /* Update chip's next pointer */
879 static inline void sky2_put_idx(struct sky2_hw
*hw
, unsigned q
, u16 idx
)
881 /* Make sure write' to descriptors are complete before we tell hardware */
883 sky2_write16(hw
, Y2_QADDR(q
, PREF_UNIT_PUT_IDX
), idx
);
885 /* Synchronize I/O on since next processor may write to tail */
890 static inline struct sky2_rx_le
*sky2_next_rx(struct sky2_port
*sky2
)
892 struct sky2_rx_le
*le
= sky2
->rx_le
+ sky2
->rx_put
;
893 sky2
->rx_put
= RING_NEXT(sky2
->rx_put
, RX_LE_SIZE
);
898 /* Build description to hardware for one receive segment */
899 static void sky2_rx_add(struct sky2_port
*sky2
, u8 op
,
900 dma_addr_t map
, unsigned len
)
902 struct sky2_rx_le
*le
;
903 u32 hi
= upper_32_bits(map
);
905 if (sky2
->rx_addr64
!= hi
) {
906 le
= sky2_next_rx(sky2
);
907 le
->addr
= cpu_to_le32(hi
);
908 le
->opcode
= OP_ADDR64
| HW_OWNER
;
909 sky2
->rx_addr64
= upper_32_bits(map
+ len
);
912 le
= sky2_next_rx(sky2
);
913 le
->addr
= cpu_to_le32((u32
) map
);
914 le
->length
= cpu_to_le16(len
);
915 le
->opcode
= op
| HW_OWNER
;
918 /* Build description to hardware for one possibly fragmented skb */
919 static void sky2_rx_submit(struct sky2_port
*sky2
,
920 const struct rx_ring_info
*re
)
924 sky2_rx_add(sky2
, OP_PACKET
, re
->data_addr
, sky2
->rx_data_size
);
926 for (i
= 0; i
< skb_shinfo(re
->skb
)->nr_frags
; i
++)
927 sky2_rx_add(sky2
, OP_BUFFER
, re
->frag_addr
[i
], PAGE_SIZE
);
931 static void sky2_rx_map_skb(struct pci_dev
*pdev
, struct rx_ring_info
*re
,
934 struct sk_buff
*skb
= re
->skb
;
937 re
->data_addr
= pci_map_single(pdev
, skb
->data
, size
, PCI_DMA_FROMDEVICE
);
938 pci_unmap_len_set(re
, data_size
, size
);
940 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++)
941 re
->frag_addr
[i
] = pci_map_page(pdev
,
942 skb_shinfo(skb
)->frags
[i
].page
,
943 skb_shinfo(skb
)->frags
[i
].page_offset
,
944 skb_shinfo(skb
)->frags
[i
].size
,
948 static void sky2_rx_unmap_skb(struct pci_dev
*pdev
, struct rx_ring_info
*re
)
950 struct sk_buff
*skb
= re
->skb
;
953 pci_unmap_single(pdev
, re
->data_addr
, pci_unmap_len(re
, data_size
),
956 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++)
957 pci_unmap_page(pdev
, re
->frag_addr
[i
],
958 skb_shinfo(skb
)->frags
[i
].size
,
962 /* Tell chip where to start receive checksum.
963 * Actually has two checksums, but set both same to avoid possible byte
966 static void rx_set_checksum(struct sky2_port
*sky2
)
968 struct sky2_rx_le
*le
;
970 if (sky2
->hw
->chip_id
!= CHIP_ID_YUKON_EX
) {
971 le
= sky2_next_rx(sky2
);
972 le
->addr
= cpu_to_le32((ETH_HLEN
<< 16) | ETH_HLEN
);
974 le
->opcode
= OP_TCPSTART
| HW_OWNER
;
976 sky2_write32(sky2
->hw
,
977 Q_ADDR(rxqaddr
[sky2
->port
], Q_CSR
),
978 sky2
->rx_csum
? BMU_ENA_RX_CHKSUM
: BMU_DIS_RX_CHKSUM
);
984 * The RX Stop command will not work for Yukon-2 if the BMU does not
985 * reach the end of packet and since we can't make sure that we have
986 * incoming data, we must reset the BMU while it is not doing a DMA
987 * transfer. Since it is possible that the RX path is still active,
988 * the RX RAM buffer will be stopped first, so any possible incoming
989 * data will not trigger a DMA. After the RAM buffer is stopped, the
990 * BMU is polled until any DMA in progress is ended and only then it
993 static void sky2_rx_stop(struct sky2_port
*sky2
)
995 struct sky2_hw
*hw
= sky2
->hw
;
996 unsigned rxq
= rxqaddr
[sky2
->port
];
999 /* disable the RAM Buffer receive queue */
1000 sky2_write8(hw
, RB_ADDR(rxq
, RB_CTRL
), RB_DIS_OP_MD
);
1002 for (i
= 0; i
< 0xffff; i
++)
1003 if (sky2_read8(hw
, RB_ADDR(rxq
, Q_RSL
))
1004 == sky2_read8(hw
, RB_ADDR(rxq
, Q_RL
)))
1007 printk(KERN_WARNING PFX
"%s: receiver stop failed\n",
1008 sky2
->netdev
->name
);
1010 sky2_write32(hw
, Q_ADDR(rxq
, Q_CSR
), BMU_RST_SET
| BMU_FIFO_RST
);
1012 /* reset the Rx prefetch unit */
1013 sky2_write32(hw
, Y2_QADDR(rxq
, PREF_UNIT_CTRL
), PREF_UNIT_RST_SET
);
1017 /* Clean out receive buffer area, assumes receiver hardware stopped */
1018 static void sky2_rx_clean(struct sky2_port
*sky2
)
1022 memset(sky2
->rx_le
, 0, RX_LE_BYTES
);
1023 for (i
= 0; i
< sky2
->rx_pending
; i
++) {
1024 struct rx_ring_info
*re
= sky2
->rx_ring
+ i
;
1027 sky2_rx_unmap_skb(sky2
->hw
->pdev
, re
);
1034 /* Basic MII support */
1035 static int sky2_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1037 struct mii_ioctl_data
*data
= if_mii(ifr
);
1038 struct sky2_port
*sky2
= netdev_priv(dev
);
1039 struct sky2_hw
*hw
= sky2
->hw
;
1040 int err
= -EOPNOTSUPP
;
1042 if (!netif_running(dev
))
1043 return -ENODEV
; /* Phy still in reset */
1047 data
->phy_id
= PHY_ADDR_MARV
;
1053 spin_lock_bh(&sky2
->phy_lock
);
1054 err
= __gm_phy_read(hw
, sky2
->port
, data
->reg_num
& 0x1f, &val
);
1055 spin_unlock_bh(&sky2
->phy_lock
);
1057 data
->val_out
= val
;
1062 if (!capable(CAP_NET_ADMIN
))
1065 spin_lock_bh(&sky2
->phy_lock
);
1066 err
= gm_phy_write(hw
, sky2
->port
, data
->reg_num
& 0x1f,
1068 spin_unlock_bh(&sky2
->phy_lock
);
1074 #ifdef SKY2_VLAN_TAG_USED
1075 static void sky2_vlan_rx_register(struct net_device
*dev
, struct vlan_group
*grp
)
1077 struct sky2_port
*sky2
= netdev_priv(dev
);
1078 struct sky2_hw
*hw
= sky2
->hw
;
1079 u16 port
= sky2
->port
;
1081 netif_tx_lock_bh(dev
);
1082 netif_poll_disable(sky2
->hw
->dev
[0]);
1086 sky2_write32(hw
, SK_REG(port
, RX_GMF_CTRL_T
),
1088 sky2_write32(hw
, SK_REG(port
, TX_GMF_CTRL_T
),
1091 sky2_write32(hw
, SK_REG(port
, RX_GMF_CTRL_T
),
1093 sky2_write32(hw
, SK_REG(port
, TX_GMF_CTRL_T
),
1097 netif_poll_enable(sky2
->hw
->dev
[0]);
1098 netif_tx_unlock_bh(dev
);
1103 * Allocate an skb for receiving. If the MTU is large enough
1104 * make the skb non-linear with a fragment list of pages.
1106 * It appears the hardware has a bug in the FIFO logic that
1107 * cause it to hang if the FIFO gets overrun and the receive buffer
1108 * is not 64 byte aligned. The buffer returned from netdev_alloc_skb is
1109 * aligned except if slab debugging is enabled.
1111 static struct sk_buff
*sky2_rx_alloc(struct sky2_port
*sky2
)
1113 struct sk_buff
*skb
;
1117 skb
= netdev_alloc_skb(sky2
->netdev
, sky2
->rx_data_size
+ RX_SKB_ALIGN
);
1121 p
= (unsigned long) skb
->data
;
1122 skb_reserve(skb
, ALIGN(p
, RX_SKB_ALIGN
) - p
);
1124 for (i
= 0; i
< sky2
->rx_nfrags
; i
++) {
1125 struct page
*page
= alloc_page(GFP_ATOMIC
);
1129 skb_fill_page_desc(skb
, i
, page
, 0, PAGE_SIZE
);
1139 static inline void sky2_rx_update(struct sky2_port
*sky2
, unsigned rxq
)
1141 sky2_put_idx(sky2
->hw
, rxq
, sky2
->rx_put
);
1145 * Allocate and setup receiver buffer pool.
1146 * Normal case this ends up creating one list element for skb
1147 * in the receive ring. Worst case if using large MTU and each
1148 * allocation falls on a different 64 bit region, that results
1149 * in 6 list elements per ring entry.
1150 * One element is used for checksum enable/disable, and one
1151 * extra to avoid wrap.
1153 static int sky2_rx_start(struct sky2_port
*sky2
)
1155 struct sky2_hw
*hw
= sky2
->hw
;
1156 struct rx_ring_info
*re
;
1157 unsigned rxq
= rxqaddr
[sky2
->port
];
1158 unsigned i
, size
, space
, thresh
;
1160 sky2
->rx_put
= sky2
->rx_next
= 0;
1163 /* On PCI express lowering the watermark gives better performance */
1164 if (pci_find_capability(hw
->pdev
, PCI_CAP_ID_EXP
))
1165 sky2_write32(hw
, Q_ADDR(rxq
, Q_WM
), BMU_WM_PEX
);
1167 /* These chips have no ram buffer?
1168 * MAC Rx RAM Read is controlled by hardware */
1169 if (hw
->chip_id
== CHIP_ID_YUKON_EC_U
&&
1170 (hw
->chip_rev
== CHIP_REV_YU_EC_U_A1
1171 || hw
->chip_rev
== CHIP_REV_YU_EC_U_B0
))
1172 sky2_write32(hw
, Q_ADDR(rxq
, Q_TEST
), F_M_RX_RAM_DIS
);
1174 sky2_prefetch_init(hw
, rxq
, sky2
->rx_le_map
, RX_LE_SIZE
- 1);
1176 rx_set_checksum(sky2
);
1178 /* Space needed for frame data + headers rounded up */
1179 size
= roundup(sky2
->netdev
->mtu
+ ETH_HLEN
+ VLAN_HLEN
, 8);
1181 /* Stopping point for hardware truncation */
1182 thresh
= (size
- 8) / sizeof(u32
);
1184 /* Account for overhead of skb - to avoid order > 0 allocation */
1185 space
= SKB_DATA_ALIGN(size
) + NET_SKB_PAD
1186 + sizeof(struct skb_shared_info
);
1188 sky2
->rx_nfrags
= space
>> PAGE_SHIFT
;
1189 BUG_ON(sky2
->rx_nfrags
> ARRAY_SIZE(re
->frag_addr
));
1191 if (sky2
->rx_nfrags
!= 0) {
1192 /* Compute residue after pages */
1193 space
= sky2
->rx_nfrags
<< PAGE_SHIFT
;
1200 /* Optimize to handle small packets and headers */
1201 if (size
< copybreak
)
1203 if (size
< ETH_HLEN
)
1206 sky2
->rx_data_size
= size
;
1209 for (i
= 0; i
< sky2
->rx_pending
; i
++) {
1210 re
= sky2
->rx_ring
+ i
;
1212 re
->skb
= sky2_rx_alloc(sky2
);
1216 sky2_rx_map_skb(hw
->pdev
, re
, sky2
->rx_data_size
);
1217 sky2_rx_submit(sky2
, re
);
1221 * The receiver hangs if it receives frames larger than the
1222 * packet buffer. As a workaround, truncate oversize frames, but
1223 * the register is limited to 9 bits, so if you do frames > 2052
1224 * you better get the MTU right!
1227 sky2_write32(hw
, SK_REG(sky2
->port
, RX_GMF_CTRL_T
), RX_TRUNC_OFF
);
1229 sky2_write16(hw
, SK_REG(sky2
->port
, RX_GMF_TR_THR
), thresh
);
1230 sky2_write32(hw
, SK_REG(sky2
->port
, RX_GMF_CTRL_T
), RX_TRUNC_ON
);
1233 /* Tell chip about available buffers */
1234 sky2_rx_update(sky2
, rxq
);
1237 sky2_rx_clean(sky2
);
1241 /* Bring up network interface. */
1242 static int sky2_up(struct net_device
*dev
)
1244 struct sky2_port
*sky2
= netdev_priv(dev
);
1245 struct sky2_hw
*hw
= sky2
->hw
;
1246 unsigned port
= sky2
->port
;
1248 int cap
, err
= -ENOMEM
;
1249 struct net_device
*otherdev
= hw
->dev
[sky2
->port
^1];
1252 * On dual port PCI-X card, there is an problem where status
1253 * can be received out of order due to split transactions
1255 if (otherdev
&& netif_running(otherdev
) &&
1256 (cap
= pci_find_capability(hw
->pdev
, PCI_CAP_ID_PCIX
))) {
1257 struct sky2_port
*osky2
= netdev_priv(otherdev
);
1260 cmd
= sky2_pci_read16(hw
, cap
+ PCI_X_CMD
);
1261 cmd
&= ~PCI_X_CMD_MAX_SPLIT
;
1262 sky2_pci_write16(hw
, cap
+ PCI_X_CMD
, cmd
);
1268 if (netif_msg_ifup(sky2
))
1269 printk(KERN_INFO PFX
"%s: enabling interface\n", dev
->name
);
1271 netif_carrier_off(dev
);
1273 /* must be power of 2 */
1274 sky2
->tx_le
= pci_alloc_consistent(hw
->pdev
,
1276 sizeof(struct sky2_tx_le
),
1281 sky2
->tx_ring
= kcalloc(TX_RING_SIZE
, sizeof(struct tx_ring_info
),
1285 sky2
->tx_prod
= sky2
->tx_cons
= 0;
1287 sky2
->rx_le
= pci_alloc_consistent(hw
->pdev
, RX_LE_BYTES
,
1291 memset(sky2
->rx_le
, 0, RX_LE_BYTES
);
1293 sky2
->rx_ring
= kcalloc(sky2
->rx_pending
, sizeof(struct rx_ring_info
),
1298 sky2_phy_power(hw
, port
, 1);
1300 sky2_mac_init(hw
, port
);
1302 /* Register is number of 4K blocks on internal RAM buffer. */
1303 ramsize
= sky2_read8(hw
, B2_E_0
) * 4;
1304 printk(KERN_INFO PFX
"%s: ram buffer %dK\n", dev
->name
, ramsize
);
1310 rxspace
= ramsize
/ 2;
1312 rxspace
= 8 + (2*(ramsize
- 16))/3;
1314 sky2_ramset(hw
, rxqaddr
[port
], 0, rxspace
);
1315 sky2_ramset(hw
, txqaddr
[port
], rxspace
, ramsize
- rxspace
);
1317 /* Make sure SyncQ is disabled */
1318 sky2_write8(hw
, RB_ADDR(port
== 0 ? Q_XS1
: Q_XS2
, RB_CTRL
),
1322 sky2_qset(hw
, txqaddr
[port
]);
1324 /* This is copied from sk98lin 10.0.5.3; no one tells me about erratta's */
1325 if (hw
->chip_id
== CHIP_ID_YUKON_EX
&& hw
->chip_rev
== CHIP_REV_YU_EX_B0
)
1326 sky2_write32(hw
, Q_ADDR(txqaddr
[port
], Q_TEST
), F_TX_CHK_AUTO_OFF
);
1328 /* Set almost empty threshold */
1329 if (hw
->chip_id
== CHIP_ID_YUKON_EC_U
1330 && hw
->chip_rev
== CHIP_REV_YU_EC_U_A0
)
1331 sky2_write16(hw
, Q_ADDR(txqaddr
[port
], Q_AL
), ECU_TXFF_LEV
);
1333 sky2_prefetch_init(hw
, txqaddr
[port
], sky2
->tx_le_map
,
1336 err
= sky2_rx_start(sky2
);
1340 /* Enable interrupts from phy/mac for port */
1341 imask
= sky2_read32(hw
, B0_IMSK
);
1342 imask
|= portirq_msk
[port
];
1343 sky2_write32(hw
, B0_IMSK
, imask
);
1349 pci_free_consistent(hw
->pdev
, RX_LE_BYTES
,
1350 sky2
->rx_le
, sky2
->rx_le_map
);
1354 pci_free_consistent(hw
->pdev
,
1355 TX_RING_SIZE
* sizeof(struct sky2_tx_le
),
1356 sky2
->tx_le
, sky2
->tx_le_map
);
1359 kfree(sky2
->tx_ring
);
1360 kfree(sky2
->rx_ring
);
1362 sky2
->tx_ring
= NULL
;
1363 sky2
->rx_ring
= NULL
;
1367 /* Modular subtraction in ring */
1368 static inline int tx_dist(unsigned tail
, unsigned head
)
1370 return (head
- tail
) & (TX_RING_SIZE
- 1);
1373 /* Number of list elements available for next tx */
1374 static inline int tx_avail(const struct sky2_port
*sky2
)
1376 return sky2
->tx_pending
- tx_dist(sky2
->tx_cons
, sky2
->tx_prod
);
1379 /* Estimate of number of transmit list elements required */
1380 static unsigned tx_le_req(const struct sk_buff
*skb
)
1384 count
= sizeof(dma_addr_t
) / sizeof(u32
);
1385 count
+= skb_shinfo(skb
)->nr_frags
* count
;
1387 if (skb_is_gso(skb
))
1390 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
1397 * Put one packet in ring for transmit.
1398 * A single packet can generate multiple list elements, and
1399 * the number of ring elements will probably be less than the number
1400 * of list elements used.
1402 static int sky2_xmit_frame(struct sk_buff
*skb
, struct net_device
*dev
)
1404 struct sky2_port
*sky2
= netdev_priv(dev
);
1405 struct sky2_hw
*hw
= sky2
->hw
;
1406 struct sky2_tx_le
*le
= NULL
;
1407 struct tx_ring_info
*re
;
1414 if (unlikely(tx_avail(sky2
) < tx_le_req(skb
)))
1415 return NETDEV_TX_BUSY
;
1417 if (unlikely(netif_msg_tx_queued(sky2
)))
1418 printk(KERN_DEBUG
"%s: tx queued, slot %u, len %d\n",
1419 dev
->name
, sky2
->tx_prod
, skb
->len
);
1421 len
= skb_headlen(skb
);
1422 mapping
= pci_map_single(hw
->pdev
, skb
->data
, len
, PCI_DMA_TODEVICE
);
1423 addr64
= upper_32_bits(mapping
);
1425 /* Send high bits if changed or crosses boundary */
1426 if (addr64
!= sky2
->tx_addr64
||
1427 upper_32_bits(mapping
+ len
) != sky2
->tx_addr64
) {
1428 le
= get_tx_le(sky2
);
1429 le
->addr
= cpu_to_le32(addr64
);
1430 le
->opcode
= OP_ADDR64
| HW_OWNER
;
1431 sky2
->tx_addr64
= upper_32_bits(mapping
+ len
);
1434 /* Check for TCP Segmentation Offload */
1435 mss
= skb_shinfo(skb
)->gso_size
;
1437 if (hw
->chip_id
!= CHIP_ID_YUKON_EX
)
1438 mss
+= ETH_HLEN
+ ip_hdrlen(skb
) + tcp_hdrlen(skb
);
1440 if (mss
!= sky2
->tx_last_mss
) {
1441 le
= get_tx_le(sky2
);
1442 le
->addr
= cpu_to_le32(mss
);
1443 if (hw
->chip_id
== CHIP_ID_YUKON_EX
)
1444 le
->opcode
= OP_MSS
| HW_OWNER
;
1446 le
->opcode
= OP_LRGLEN
| HW_OWNER
;
1447 sky2
->tx_last_mss
= mss
;
1452 #ifdef SKY2_VLAN_TAG_USED
1453 /* Add VLAN tag, can piggyback on LRGLEN or ADDR64 */
1454 if (sky2
->vlgrp
&& vlan_tx_tag_present(skb
)) {
1456 le
= get_tx_le(sky2
);
1458 le
->opcode
= OP_VLAN
|HW_OWNER
;
1460 le
->opcode
|= OP_VLAN
;
1461 le
->length
= cpu_to_be16(vlan_tx_tag_get(skb
));
1466 /* Handle TCP checksum offload */
1467 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1468 /* On Yukon EX (some versions) encoding change. */
1469 if (hw
->chip_id
== CHIP_ID_YUKON_EX
1470 && hw
->chip_rev
!= CHIP_REV_YU_EX_B0
)
1471 ctrl
|= CALSUM
; /* auto checksum */
1473 const unsigned offset
= skb_transport_offset(skb
);
1476 tcpsum
= offset
<< 16; /* sum start */
1477 tcpsum
|= offset
+ skb
->csum_offset
; /* sum write */
1479 ctrl
|= CALSUM
| WR_SUM
| INIT_SUM
| LOCK_SUM
;
1480 if (ip_hdr(skb
)->protocol
== IPPROTO_UDP
)
1483 if (tcpsum
!= sky2
->tx_tcpsum
) {
1484 sky2
->tx_tcpsum
= tcpsum
;
1486 le
= get_tx_le(sky2
);
1487 le
->addr
= cpu_to_le32(tcpsum
);
1488 le
->length
= 0; /* initial checksum value */
1489 le
->ctrl
= 1; /* one packet */
1490 le
->opcode
= OP_TCPLISW
| HW_OWNER
;
1495 le
= get_tx_le(sky2
);
1496 le
->addr
= cpu_to_le32((u32
) mapping
);
1497 le
->length
= cpu_to_le16(len
);
1499 le
->opcode
= mss
? (OP_LARGESEND
| HW_OWNER
) : (OP_PACKET
| HW_OWNER
);
1501 re
= tx_le_re(sky2
, le
);
1503 pci_unmap_addr_set(re
, mapaddr
, mapping
);
1504 pci_unmap_len_set(re
, maplen
, len
);
1506 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
1507 const skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
1509 mapping
= pci_map_page(hw
->pdev
, frag
->page
, frag
->page_offset
,
1510 frag
->size
, PCI_DMA_TODEVICE
);
1511 addr64
= upper_32_bits(mapping
);
1512 if (addr64
!= sky2
->tx_addr64
) {
1513 le
= get_tx_le(sky2
);
1514 le
->addr
= cpu_to_le32(addr64
);
1516 le
->opcode
= OP_ADDR64
| HW_OWNER
;
1517 sky2
->tx_addr64
= addr64
;
1520 le
= get_tx_le(sky2
);
1521 le
->addr
= cpu_to_le32((u32
) mapping
);
1522 le
->length
= cpu_to_le16(frag
->size
);
1524 le
->opcode
= OP_BUFFER
| HW_OWNER
;
1526 re
= tx_le_re(sky2
, le
);
1528 pci_unmap_addr_set(re
, mapaddr
, mapping
);
1529 pci_unmap_len_set(re
, maplen
, frag
->size
);
1534 if (tx_avail(sky2
) <= MAX_SKB_TX_LE
)
1535 netif_stop_queue(dev
);
1537 sky2_put_idx(hw
, txqaddr
[sky2
->port
], sky2
->tx_prod
);
1539 dev
->trans_start
= jiffies
;
1540 return NETDEV_TX_OK
;
1544 * Free ring elements from starting at tx_cons until "done"
1546 * NB: the hardware will tell us about partial completion of multi-part
1547 * buffers so make sure not to free skb to early.
1549 static void sky2_tx_complete(struct sky2_port
*sky2
, u16 done
)
1551 struct net_device
*dev
= sky2
->netdev
;
1552 struct pci_dev
*pdev
= sky2
->hw
->pdev
;
1555 BUG_ON(done
>= TX_RING_SIZE
);
1557 for (idx
= sky2
->tx_cons
; idx
!= done
;
1558 idx
= RING_NEXT(idx
, TX_RING_SIZE
)) {
1559 struct sky2_tx_le
*le
= sky2
->tx_le
+ idx
;
1560 struct tx_ring_info
*re
= sky2
->tx_ring
+ idx
;
1562 switch(le
->opcode
& ~HW_OWNER
) {
1565 pci_unmap_single(pdev
,
1566 pci_unmap_addr(re
, mapaddr
),
1567 pci_unmap_len(re
, maplen
),
1571 pci_unmap_page(pdev
, pci_unmap_addr(re
, mapaddr
),
1572 pci_unmap_len(re
, maplen
),
1577 if (le
->ctrl
& EOP
) {
1578 if (unlikely(netif_msg_tx_done(sky2
)))
1579 printk(KERN_DEBUG
"%s: tx done %u\n",
1582 sky2
->net_stats
.tx_packets
++;
1583 sky2
->net_stats
.tx_bytes
+= re
->skb
->len
;
1585 dev_kfree_skb_any(re
->skb
);
1586 sky2
->tx_next
= RING_NEXT(idx
, TX_RING_SIZE
);
1590 sky2
->tx_cons
= idx
;
1593 if (tx_avail(sky2
) > MAX_SKB_TX_LE
+ 4)
1594 netif_wake_queue(dev
);
1597 /* Cleanup all untransmitted buffers, assume transmitter not running */
1598 static void sky2_tx_clean(struct net_device
*dev
)
1600 struct sky2_port
*sky2
= netdev_priv(dev
);
1602 netif_tx_lock_bh(dev
);
1603 sky2_tx_complete(sky2
, sky2
->tx_prod
);
1604 netif_tx_unlock_bh(dev
);
1607 /* Network shutdown */
1608 static int sky2_down(struct net_device
*dev
)
1610 struct sky2_port
*sky2
= netdev_priv(dev
);
1611 struct sky2_hw
*hw
= sky2
->hw
;
1612 unsigned port
= sky2
->port
;
1616 /* Never really got started! */
1620 if (netif_msg_ifdown(sky2
))
1621 printk(KERN_INFO PFX
"%s: disabling interface\n", dev
->name
);
1623 if (netif_carrier_ok(dev
) && --hw
->active
== 0)
1624 del_timer(&hw
->watchdog_timer
);
1626 /* Stop more packets from being queued */
1627 netif_stop_queue(dev
);
1629 /* Disable port IRQ */
1630 imask
= sky2_read32(hw
, B0_IMSK
);
1631 imask
&= ~portirq_msk
[port
];
1632 sky2_write32(hw
, B0_IMSK
, imask
);
1634 sky2_gmac_reset(hw
, port
);
1636 /* Stop transmitter */
1637 sky2_write32(hw
, Q_ADDR(txqaddr
[port
], Q_CSR
), BMU_STOP
);
1638 sky2_read32(hw
, Q_ADDR(txqaddr
[port
], Q_CSR
));
1640 sky2_write32(hw
, RB_ADDR(txqaddr
[port
], RB_CTRL
),
1641 RB_RST_SET
| RB_DIS_OP_MD
);
1643 ctrl
= gma_read16(hw
, port
, GM_GP_CTRL
);
1644 ctrl
&= ~(GM_GPCR_TX_ENA
| GM_GPCR_RX_ENA
);
1645 gma_write16(hw
, port
, GM_GP_CTRL
, ctrl
);
1647 sky2_write8(hw
, SK_REG(port
, GPHY_CTRL
), GPC_RST_SET
);
1649 /* Workaround shared GMAC reset */
1650 if (!(hw
->chip_id
== CHIP_ID_YUKON_XL
&& hw
->chip_rev
== 0
1651 && port
== 0 && hw
->dev
[1] && netif_running(hw
->dev
[1])))
1652 sky2_write8(hw
, SK_REG(port
, GMAC_CTRL
), GMC_RST_SET
);
1654 /* Disable Force Sync bit and Enable Alloc bit */
1655 sky2_write8(hw
, SK_REG(port
, TXA_CTRL
),
1656 TXA_DIS_FSYNC
| TXA_DIS_ALLOC
| TXA_STOP_RC
);
1658 /* Stop Interval Timer and Limit Counter of Tx Arbiter */
1659 sky2_write32(hw
, SK_REG(port
, TXA_ITI_INI
), 0L);
1660 sky2_write32(hw
, SK_REG(port
, TXA_LIM_INI
), 0L);
1662 /* Reset the PCI FIFO of the async Tx queue */
1663 sky2_write32(hw
, Q_ADDR(txqaddr
[port
], Q_CSR
),
1664 BMU_RST_SET
| BMU_FIFO_RST
);
1666 /* Reset the Tx prefetch units */
1667 sky2_write32(hw
, Y2_QADDR(txqaddr
[port
], PREF_UNIT_CTRL
),
1670 sky2_write32(hw
, RB_ADDR(txqaddr
[port
], RB_CTRL
), RB_RST_SET
);
1674 sky2_write8(hw
, SK_REG(port
, RX_GMF_CTRL_T
), GMF_RST_SET
);
1675 sky2_write8(hw
, SK_REG(port
, TX_GMF_CTRL_T
), GMF_RST_SET
);
1677 sky2_phy_power(hw
, port
, 0);
1679 netif_carrier_off(dev
);
1681 /* turn off LED's */
1682 sky2_write16(hw
, B0_Y2LED
, LED_STAT_OFF
);
1684 synchronize_irq(hw
->pdev
->irq
);
1687 sky2_rx_clean(sky2
);
1689 pci_free_consistent(hw
->pdev
, RX_LE_BYTES
,
1690 sky2
->rx_le
, sky2
->rx_le_map
);
1691 kfree(sky2
->rx_ring
);
1693 pci_free_consistent(hw
->pdev
,
1694 TX_RING_SIZE
* sizeof(struct sky2_tx_le
),
1695 sky2
->tx_le
, sky2
->tx_le_map
);
1696 kfree(sky2
->tx_ring
);
1701 sky2
->rx_ring
= NULL
;
1702 sky2
->tx_ring
= NULL
;
1707 static u16
sky2_phy_speed(const struct sky2_hw
*hw
, u16 aux
)
1709 if (!sky2_is_copper(hw
))
1712 if (hw
->chip_id
== CHIP_ID_YUKON_FE
)
1713 return (aux
& PHY_M_PS_SPEED_100
) ? SPEED_100
: SPEED_10
;
1715 switch (aux
& PHY_M_PS_SPEED_MSK
) {
1716 case PHY_M_PS_SPEED_1000
:
1718 case PHY_M_PS_SPEED_100
:
1725 static void sky2_link_up(struct sky2_port
*sky2
)
1727 struct sky2_hw
*hw
= sky2
->hw
;
1728 unsigned port
= sky2
->port
;
1730 static const char *fc_name
[] = {
1738 reg
= gma_read16(hw
, port
, GM_GP_CTRL
);
1739 reg
|= GM_GPCR_RX_ENA
| GM_GPCR_TX_ENA
;
1740 gma_write16(hw
, port
, GM_GP_CTRL
, reg
);
1742 gm_phy_write(hw
, port
, PHY_MARV_INT_MASK
, PHY_M_DEF_MSK
);
1744 netif_carrier_on(sky2
->netdev
);
1746 if (hw
->active
++ == 0)
1747 mod_timer(&hw
->watchdog_timer
, jiffies
+ 1);
1750 /* Turn on link LED */
1751 sky2_write8(hw
, SK_REG(port
, LNK_LED_REG
),
1752 LINKLED_ON
| LINKLED_BLINK_OFF
| LINKLED_LINKSYNC_OFF
);
1754 if (hw
->chip_id
== CHIP_ID_YUKON_XL
1755 || hw
->chip_id
== CHIP_ID_YUKON_EC_U
1756 || hw
->chip_id
== CHIP_ID_YUKON_EX
) {
1757 u16 pg
= gm_phy_read(hw
, port
, PHY_MARV_EXT_ADR
);
1758 u16 led
= PHY_M_LEDC_LOS_CTRL(1); /* link active */
1760 switch(sky2
->speed
) {
1762 led
|= PHY_M_LEDC_INIT_CTRL(7);
1766 led
|= PHY_M_LEDC_STA1_CTRL(7);
1770 led
|= PHY_M_LEDC_STA0_CTRL(7);
1774 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, 3);
1775 gm_phy_write(hw
, port
, PHY_MARV_PHY_CTRL
, led
);
1776 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, pg
);
1779 if (netif_msg_link(sky2
))
1780 printk(KERN_INFO PFX
1781 "%s: Link is up at %d Mbps, %s duplex, flow control %s\n",
1782 sky2
->netdev
->name
, sky2
->speed
,
1783 sky2
->duplex
== DUPLEX_FULL
? "full" : "half",
1784 fc_name
[sky2
->flow_status
]);
1787 static void sky2_link_down(struct sky2_port
*sky2
)
1789 struct sky2_hw
*hw
= sky2
->hw
;
1790 unsigned port
= sky2
->port
;
1793 gm_phy_write(hw
, port
, PHY_MARV_INT_MASK
, 0);
1795 reg
= gma_read16(hw
, port
, GM_GP_CTRL
);
1796 reg
&= ~(GM_GPCR_RX_ENA
| GM_GPCR_TX_ENA
);
1797 gma_write16(hw
, port
, GM_GP_CTRL
, reg
);
1799 netif_carrier_off(sky2
->netdev
);
1801 /* Stop watchdog if both ports are not active */
1802 if (--hw
->active
== 0)
1803 del_timer(&hw
->watchdog_timer
);
1806 /* Turn on link LED */
1807 sky2_write8(hw
, SK_REG(port
, LNK_LED_REG
), LINKLED_OFF
);
1809 if (netif_msg_link(sky2
))
1810 printk(KERN_INFO PFX
"%s: Link is down.\n", sky2
->netdev
->name
);
1812 sky2_phy_init(hw
, port
);
1815 static enum flow_control
sky2_flow(int rx
, int tx
)
1818 return tx
? FC_BOTH
: FC_RX
;
1820 return tx
? FC_TX
: FC_NONE
;
1823 static int sky2_autoneg_done(struct sky2_port
*sky2
, u16 aux
)
1825 struct sky2_hw
*hw
= sky2
->hw
;
1826 unsigned port
= sky2
->port
;
1829 advert
= gm_phy_read(hw
, port
, PHY_MARV_AUNE_ADV
);
1830 lpa
= gm_phy_read(hw
, port
, PHY_MARV_AUNE_LP
);
1831 if (lpa
& PHY_M_AN_RF
) {
1832 printk(KERN_ERR PFX
"%s: remote fault", sky2
->netdev
->name
);
1836 if (!(aux
& PHY_M_PS_SPDUP_RES
)) {
1837 printk(KERN_ERR PFX
"%s: speed/duplex mismatch",
1838 sky2
->netdev
->name
);
1842 sky2
->speed
= sky2_phy_speed(hw
, aux
);
1843 sky2
->duplex
= (aux
& PHY_M_PS_FULL_DUP
) ? DUPLEX_FULL
: DUPLEX_HALF
;
1845 /* Since the pause result bits seem to in different positions on
1846 * different chips. look at registers.
1848 if (!sky2_is_copper(hw
)) {
1849 /* Shift for bits in fiber PHY */
1850 advert
&= ~(ADVERTISE_PAUSE_CAP
|ADVERTISE_PAUSE_ASYM
);
1851 lpa
&= ~(LPA_PAUSE_CAP
|LPA_PAUSE_ASYM
);
1853 if (advert
& ADVERTISE_1000XPAUSE
)
1854 advert
|= ADVERTISE_PAUSE_CAP
;
1855 if (advert
& ADVERTISE_1000XPSE_ASYM
)
1856 advert
|= ADVERTISE_PAUSE_ASYM
;
1857 if (lpa
& LPA_1000XPAUSE
)
1858 lpa
|= LPA_PAUSE_CAP
;
1859 if (lpa
& LPA_1000XPAUSE_ASYM
)
1860 lpa
|= LPA_PAUSE_ASYM
;
1863 sky2
->flow_status
= FC_NONE
;
1864 if (advert
& ADVERTISE_PAUSE_CAP
) {
1865 if (lpa
& LPA_PAUSE_CAP
)
1866 sky2
->flow_status
= FC_BOTH
;
1867 else if (advert
& ADVERTISE_PAUSE_ASYM
)
1868 sky2
->flow_status
= FC_RX
;
1869 } else if (advert
& ADVERTISE_PAUSE_ASYM
) {
1870 if ((lpa
& LPA_PAUSE_CAP
) && (lpa
& LPA_PAUSE_ASYM
))
1871 sky2
->flow_status
= FC_TX
;
1874 if (sky2
->duplex
== DUPLEX_HALF
&& sky2
->speed
< SPEED_1000
1875 && !(hw
->chip_id
== CHIP_ID_YUKON_EC_U
|| hw
->chip_id
== CHIP_ID_YUKON_EX
))
1876 sky2
->flow_status
= FC_NONE
;
1878 if (sky2
->flow_status
& FC_TX
)
1879 sky2_write8(hw
, SK_REG(port
, GMAC_CTRL
), GMC_PAUSE_ON
);
1881 sky2_write8(hw
, SK_REG(port
, GMAC_CTRL
), GMC_PAUSE_OFF
);
1886 /* Interrupt from PHY */
1887 static void sky2_phy_intr(struct sky2_hw
*hw
, unsigned port
)
1889 struct net_device
*dev
= hw
->dev
[port
];
1890 struct sky2_port
*sky2
= netdev_priv(dev
);
1891 u16 istatus
, phystat
;
1893 if (!netif_running(dev
))
1896 spin_lock(&sky2
->phy_lock
);
1897 istatus
= gm_phy_read(hw
, port
, PHY_MARV_INT_STAT
);
1898 phystat
= gm_phy_read(hw
, port
, PHY_MARV_PHY_STAT
);
1900 if (netif_msg_intr(sky2
))
1901 printk(KERN_INFO PFX
"%s: phy interrupt status 0x%x 0x%x\n",
1902 sky2
->netdev
->name
, istatus
, phystat
);
1904 if (sky2
->autoneg
== AUTONEG_ENABLE
&& (istatus
& PHY_M_IS_AN_COMPL
)) {
1905 if (sky2_autoneg_done(sky2
, phystat
) == 0)
1910 if (istatus
& PHY_M_IS_LSP_CHANGE
)
1911 sky2
->speed
= sky2_phy_speed(hw
, phystat
);
1913 if (istatus
& PHY_M_IS_DUP_CHANGE
)
1915 (phystat
& PHY_M_PS_FULL_DUP
) ? DUPLEX_FULL
: DUPLEX_HALF
;
1917 if (istatus
& PHY_M_IS_LST_CHANGE
) {
1918 if (phystat
& PHY_M_PS_LINK_UP
)
1921 sky2_link_down(sky2
);
1924 spin_unlock(&sky2
->phy_lock
);
1927 /* Transmit timeout is only called if we are running, carrier is up
1928 * and tx queue is full (stopped).
1930 static void sky2_tx_timeout(struct net_device
*dev
)
1932 struct sky2_port
*sky2
= netdev_priv(dev
);
1933 struct sky2_hw
*hw
= sky2
->hw
;
1935 if (netif_msg_timer(sky2
))
1936 printk(KERN_ERR PFX
"%s: tx timeout\n", dev
->name
);
1938 printk(KERN_DEBUG PFX
"%s: transmit ring %u .. %u report=%u done=%u\n",
1939 dev
->name
, sky2
->tx_cons
, sky2
->tx_prod
,
1940 sky2_read16(hw
, sky2
->port
== 0 ? STAT_TXA1_RIDX
: STAT_TXA2_RIDX
),
1941 sky2_read16(hw
, Q_ADDR(txqaddr
[sky2
->port
], Q_DONE
)));
1943 /* can't restart safely under softirq */
1944 schedule_work(&hw
->restart_work
);
1947 static int sky2_change_mtu(struct net_device
*dev
, int new_mtu
)
1949 struct sky2_port
*sky2
= netdev_priv(dev
);
1950 struct sky2_hw
*hw
= sky2
->hw
;
1951 unsigned port
= sky2
->port
;
1956 if (new_mtu
< ETH_ZLEN
|| new_mtu
> ETH_JUMBO_MTU
)
1959 if (new_mtu
> ETH_DATA_LEN
&& hw
->chip_id
== CHIP_ID_YUKON_FE
)
1962 if (!netif_running(dev
)) {
1967 imask
= sky2_read32(hw
, B0_IMSK
);
1968 sky2_write32(hw
, B0_IMSK
, 0);
1970 dev
->trans_start
= jiffies
; /* prevent tx timeout */
1971 netif_stop_queue(dev
);
1972 netif_poll_disable(hw
->dev
[0]);
1974 synchronize_irq(hw
->pdev
->irq
);
1976 if (hw
->chip_id
== CHIP_ID_YUKON_EC_U
|| hw
->chip_id
== CHIP_ID_YUKON_EX
)
1977 sky2_set_tx_stfwd(hw
, port
);
1979 ctl
= gma_read16(hw
, port
, GM_GP_CTRL
);
1980 gma_write16(hw
, port
, GM_GP_CTRL
, ctl
& ~GM_GPCR_RX_ENA
);
1982 sky2_rx_clean(sky2
);
1986 mode
= DATA_BLIND_VAL(DATA_BLIND_DEF
) |
1987 GM_SMOD_VLAN_ENA
| IPG_DATA_VAL(IPG_DATA_DEF
);
1989 if (dev
->mtu
> ETH_DATA_LEN
)
1990 mode
|= GM_SMOD_JUMBO_ENA
;
1992 gma_write16(hw
, port
, GM_SERIAL_MODE
, mode
);
1994 sky2_write8(hw
, RB_ADDR(rxqaddr
[port
], RB_CTRL
), RB_ENA_OP_MD
);
1996 err
= sky2_rx_start(sky2
);
1997 sky2_write32(hw
, B0_IMSK
, imask
);
2002 gma_write16(hw
, port
, GM_GP_CTRL
, ctl
);
2004 netif_poll_enable(hw
->dev
[0]);
2005 netif_wake_queue(dev
);
2011 /* For small just reuse existing skb for next receive */
2012 static struct sk_buff
*receive_copy(struct sky2_port
*sky2
,
2013 const struct rx_ring_info
*re
,
2016 struct sk_buff
*skb
;
2018 skb
= netdev_alloc_skb(sky2
->netdev
, length
+ 2);
2020 skb_reserve(skb
, 2);
2021 pci_dma_sync_single_for_cpu(sky2
->hw
->pdev
, re
->data_addr
,
2022 length
, PCI_DMA_FROMDEVICE
);
2023 skb_copy_from_linear_data(re
->skb
, skb
->data
, length
);
2024 skb
->ip_summed
= re
->skb
->ip_summed
;
2025 skb
->csum
= re
->skb
->csum
;
2026 pci_dma_sync_single_for_device(sky2
->hw
->pdev
, re
->data_addr
,
2027 length
, PCI_DMA_FROMDEVICE
);
2028 re
->skb
->ip_summed
= CHECKSUM_NONE
;
2029 skb_put(skb
, length
);
2034 /* Adjust length of skb with fragments to match received data */
2035 static void skb_put_frags(struct sk_buff
*skb
, unsigned int hdr_space
,
2036 unsigned int length
)
2041 /* put header into skb */
2042 size
= min(length
, hdr_space
);
2047 num_frags
= skb_shinfo(skb
)->nr_frags
;
2048 for (i
= 0; i
< num_frags
; i
++) {
2049 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
2052 /* don't need this page */
2053 __free_page(frag
->page
);
2054 --skb_shinfo(skb
)->nr_frags
;
2056 size
= min(length
, (unsigned) PAGE_SIZE
);
2059 skb
->data_len
+= size
;
2060 skb
->truesize
+= size
;
2067 /* Normal packet - take skb from ring element and put in a new one */
2068 static struct sk_buff
*receive_new(struct sky2_port
*sky2
,
2069 struct rx_ring_info
*re
,
2070 unsigned int length
)
2072 struct sk_buff
*skb
, *nskb
;
2073 unsigned hdr_space
= sky2
->rx_data_size
;
2075 /* Don't be tricky about reusing pages (yet) */
2076 nskb
= sky2_rx_alloc(sky2
);
2077 if (unlikely(!nskb
))
2081 sky2_rx_unmap_skb(sky2
->hw
->pdev
, re
);
2083 prefetch(skb
->data
);
2085 sky2_rx_map_skb(sky2
->hw
->pdev
, re
, hdr_space
);
2087 if (skb_shinfo(skb
)->nr_frags
)
2088 skb_put_frags(skb
, hdr_space
, length
);
2090 skb_put(skb
, length
);
2095 * Receive one packet.
2096 * For larger packets, get new buffer.
2098 static struct sk_buff
*sky2_receive(struct net_device
*dev
,
2099 u16 length
, u32 status
)
2101 struct sky2_port
*sky2
= netdev_priv(dev
);
2102 struct rx_ring_info
*re
= sky2
->rx_ring
+ sky2
->rx_next
;
2103 struct sk_buff
*skb
= NULL
;
2105 if (unlikely(netif_msg_rx_status(sky2
)))
2106 printk(KERN_DEBUG PFX
"%s: rx slot %u status 0x%x len %d\n",
2107 dev
->name
, sky2
->rx_next
, status
, length
);
2109 sky2
->rx_next
= (sky2
->rx_next
+ 1) % sky2
->rx_pending
;
2110 prefetch(sky2
->rx_ring
+ sky2
->rx_next
);
2112 if (status
& GMR_FS_ANY_ERR
)
2115 if (!(status
& GMR_FS_RX_OK
))
2118 if (status
>> 16 != length
)
2121 if (length
< copybreak
)
2122 skb
= receive_copy(sky2
, re
, length
);
2124 skb
= receive_new(sky2
, re
, length
);
2126 sky2_rx_submit(sky2
, re
);
2131 /* Truncation of overlength packets
2132 causes PHY length to not match MAC length */
2133 ++sky2
->net_stats
.rx_length_errors
;
2136 ++sky2
->net_stats
.rx_errors
;
2137 if (status
& GMR_FS_RX_FF_OV
) {
2138 sky2
->net_stats
.rx_over_errors
++;
2142 if (netif_msg_rx_err(sky2
) && net_ratelimit())
2143 printk(KERN_INFO PFX
"%s: rx error, status 0x%x length %d\n",
2144 dev
->name
, status
, length
);
2146 if (status
& (GMR_FS_LONG_ERR
| GMR_FS_UN_SIZE
))
2147 sky2
->net_stats
.rx_length_errors
++;
2148 if (status
& GMR_FS_FRAGMENT
)
2149 sky2
->net_stats
.rx_frame_errors
++;
2150 if (status
& GMR_FS_CRC_ERR
)
2151 sky2
->net_stats
.rx_crc_errors
++;
2156 /* Transmit complete */
2157 static inline void sky2_tx_done(struct net_device
*dev
, u16 last
)
2159 struct sky2_port
*sky2
= netdev_priv(dev
);
2161 if (netif_running(dev
)) {
2163 sky2_tx_complete(sky2
, last
);
2164 netif_tx_unlock(dev
);
2168 /* Process status response ring */
2169 static int sky2_status_intr(struct sky2_hw
*hw
, int to_do
)
2172 unsigned rx
[2] = { 0, 0 };
2173 u16 hwidx
= sky2_read16(hw
, STAT_PUT_IDX
);
2177 while (hw
->st_idx
!= hwidx
) {
2178 struct sky2_port
*sky2
;
2179 struct sky2_status_le
*le
= hw
->st_le
+ hw
->st_idx
;
2180 unsigned port
= le
->css
& CSS_LINK_BIT
;
2181 struct net_device
*dev
;
2182 struct sk_buff
*skb
;
2186 hw
->st_idx
= RING_NEXT(hw
->st_idx
, STATUS_RING_SIZE
);
2188 dev
= hw
->dev
[port
];
2189 sky2
= netdev_priv(dev
);
2190 length
= le16_to_cpu(le
->length
);
2191 status
= le32_to_cpu(le
->status
);
2193 switch (le
->opcode
& ~HW_OWNER
) {
2196 skb
= sky2_receive(dev
, length
, status
);
2197 if (unlikely(!skb
)) {
2198 sky2
->net_stats
.rx_dropped
++;
2202 /* This chip reports checksum status differently */
2203 if (hw
->chip_id
== CHIP_ID_YUKON_EX
) {
2204 if (sky2
->rx_csum
&&
2205 (le
->css
& (CSS_ISIPV4
| CSS_ISIPV6
)) &&
2206 (le
->css
& CSS_TCPUDPCSOK
))
2207 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2209 skb
->ip_summed
= CHECKSUM_NONE
;
2212 skb
->protocol
= eth_type_trans(skb
, dev
);
2213 sky2
->net_stats
.rx_packets
++;
2214 sky2
->net_stats
.rx_bytes
+= skb
->len
;
2215 dev
->last_rx
= jiffies
;
2217 #ifdef SKY2_VLAN_TAG_USED
2218 if (sky2
->vlgrp
&& (status
& GMR_FS_VLAN
)) {
2219 vlan_hwaccel_receive_skb(skb
,
2221 be16_to_cpu(sky2
->rx_tag
));
2224 netif_receive_skb(skb
);
2226 /* Stop after net poll weight */
2227 if (++work_done
>= to_do
)
2231 #ifdef SKY2_VLAN_TAG_USED
2233 sky2
->rx_tag
= length
;
2237 sky2
->rx_tag
= length
;
2244 if (hw
->chip_id
== CHIP_ID_YUKON_EX
)
2247 /* Both checksum counters are programmed to start at
2248 * the same offset, so unless there is a problem they
2249 * should match. This failure is an early indication that
2250 * hardware receive checksumming won't work.
2252 if (likely(status
>> 16 == (status
& 0xffff))) {
2253 skb
= sky2
->rx_ring
[sky2
->rx_next
].skb
;
2254 skb
->ip_summed
= CHECKSUM_COMPLETE
;
2255 skb
->csum
= status
& 0xffff;
2257 printk(KERN_NOTICE PFX
"%s: hardware receive "
2258 "checksum problem (status = %#x)\n",
2261 sky2_write32(sky2
->hw
,
2262 Q_ADDR(rxqaddr
[port
], Q_CSR
),
2268 /* TX index reports status for both ports */
2269 BUILD_BUG_ON(TX_RING_SIZE
> 0x1000);
2270 sky2_tx_done(hw
->dev
[0], status
& 0xfff);
2272 sky2_tx_done(hw
->dev
[1],
2273 ((status
>> 24) & 0xff)
2274 | (u16
)(length
& 0xf) << 8);
2278 if (net_ratelimit())
2279 printk(KERN_WARNING PFX
2280 "unknown status opcode 0x%x\n", le
->opcode
);
2284 /* Fully processed status ring so clear irq */
2285 sky2_write32(hw
, STAT_CTRL
, SC_STAT_CLR_IRQ
);
2289 sky2_rx_update(netdev_priv(hw
->dev
[0]), Q_R1
);
2292 sky2_rx_update(netdev_priv(hw
->dev
[1]), Q_R2
);
2297 static void sky2_hw_error(struct sky2_hw
*hw
, unsigned port
, u32 status
)
2299 struct net_device
*dev
= hw
->dev
[port
];
2301 if (net_ratelimit())
2302 printk(KERN_INFO PFX
"%s: hw error interrupt status 0x%x\n",
2305 if (status
& Y2_IS_PAR_RD1
) {
2306 if (net_ratelimit())
2307 printk(KERN_ERR PFX
"%s: ram data read parity error\n",
2310 sky2_write16(hw
, RAM_BUFFER(port
, B3_RI_CTRL
), RI_CLR_RD_PERR
);
2313 if (status
& Y2_IS_PAR_WR1
) {
2314 if (net_ratelimit())
2315 printk(KERN_ERR PFX
"%s: ram data write parity error\n",
2318 sky2_write16(hw
, RAM_BUFFER(port
, B3_RI_CTRL
), RI_CLR_WR_PERR
);
2321 if (status
& Y2_IS_PAR_MAC1
) {
2322 if (net_ratelimit())
2323 printk(KERN_ERR PFX
"%s: MAC parity error\n", dev
->name
);
2324 sky2_write8(hw
, SK_REG(port
, TX_GMF_CTRL_T
), GMF_CLI_TX_PE
);
2327 if (status
& Y2_IS_PAR_RX1
) {
2328 if (net_ratelimit())
2329 printk(KERN_ERR PFX
"%s: RX parity error\n", dev
->name
);
2330 sky2_write32(hw
, Q_ADDR(rxqaddr
[port
], Q_CSR
), BMU_CLR_IRQ_PAR
);
2333 if (status
& Y2_IS_TCP_TXA1
) {
2334 if (net_ratelimit())
2335 printk(KERN_ERR PFX
"%s: TCP segmentation error\n",
2337 sky2_write32(hw
, Q_ADDR(txqaddr
[port
], Q_CSR
), BMU_CLR_IRQ_TCP
);
2341 static void sky2_hw_intr(struct sky2_hw
*hw
)
2343 u32 status
= sky2_read32(hw
, B0_HWE_ISRC
);
2345 if (status
& Y2_IS_TIST_OV
)
2346 sky2_write8(hw
, GMAC_TI_ST_CTRL
, GMT_ST_CLR_IRQ
);
2348 if (status
& (Y2_IS_MST_ERR
| Y2_IS_IRQ_STAT
)) {
2351 pci_err
= sky2_pci_read16(hw
, PCI_STATUS
);
2352 if (net_ratelimit())
2353 dev_err(&hw
->pdev
->dev
, "PCI hardware error (0x%x)\n",
2356 sky2_write8(hw
, B2_TST_CTRL1
, TST_CFG_WRITE_ON
);
2357 sky2_pci_write16(hw
, PCI_STATUS
,
2358 pci_err
| PCI_STATUS_ERROR_BITS
);
2359 sky2_write8(hw
, B2_TST_CTRL1
, TST_CFG_WRITE_OFF
);
2362 if (status
& Y2_IS_PCI_EXP
) {
2363 /* PCI-Express uncorrectable Error occurred */
2366 pex_err
= sky2_pci_read32(hw
, PEX_UNC_ERR_STAT
);
2368 if (net_ratelimit())
2369 dev_err(&hw
->pdev
->dev
, "PCI Express error (0x%x)\n",
2372 /* clear the interrupt */
2373 sky2_write32(hw
, B2_TST_CTRL1
, TST_CFG_WRITE_ON
);
2374 sky2_pci_write32(hw
, PEX_UNC_ERR_STAT
,
2376 sky2_write32(hw
, B2_TST_CTRL1
, TST_CFG_WRITE_OFF
);
2378 if (pex_err
& PEX_FATAL_ERRORS
) {
2379 u32 hwmsk
= sky2_read32(hw
, B0_HWE_IMSK
);
2380 hwmsk
&= ~Y2_IS_PCI_EXP
;
2381 sky2_write32(hw
, B0_HWE_IMSK
, hwmsk
);
2385 if (status
& Y2_HWE_L1_MASK
)
2386 sky2_hw_error(hw
, 0, status
);
2388 if (status
& Y2_HWE_L1_MASK
)
2389 sky2_hw_error(hw
, 1, status
);
2392 static void sky2_mac_intr(struct sky2_hw
*hw
, unsigned port
)
2394 struct net_device
*dev
= hw
->dev
[port
];
2395 struct sky2_port
*sky2
= netdev_priv(dev
);
2396 u8 status
= sky2_read8(hw
, SK_REG(port
, GMAC_IRQ_SRC
));
2398 if (netif_msg_intr(sky2
))
2399 printk(KERN_INFO PFX
"%s: mac interrupt status 0x%x\n",
2402 if (status
& GM_IS_RX_CO_OV
)
2403 gma_read16(hw
, port
, GM_RX_IRQ_SRC
);
2405 if (status
& GM_IS_TX_CO_OV
)
2406 gma_read16(hw
, port
, GM_TX_IRQ_SRC
);
2408 if (status
& GM_IS_RX_FF_OR
) {
2409 ++sky2
->net_stats
.rx_fifo_errors
;
2410 sky2_write8(hw
, SK_REG(port
, RX_GMF_CTRL_T
), GMF_CLI_RX_FO
);
2413 if (status
& GM_IS_TX_FF_UR
) {
2414 ++sky2
->net_stats
.tx_fifo_errors
;
2415 sky2_write8(hw
, SK_REG(port
, TX_GMF_CTRL_T
), GMF_CLI_TX_FU
);
2419 /* This should never happen it is a bug. */
2420 static void sky2_le_error(struct sky2_hw
*hw
, unsigned port
,
2421 u16 q
, unsigned ring_size
)
2423 struct net_device
*dev
= hw
->dev
[port
];
2424 struct sky2_port
*sky2
= netdev_priv(dev
);
2426 const u64
*le
= (q
== Q_R1
|| q
== Q_R2
)
2427 ? (u64
*) sky2
->rx_le
: (u64
*) sky2
->tx_le
;
2429 idx
= sky2_read16(hw
, Y2_QADDR(q
, PREF_UNIT_GET_IDX
));
2430 printk(KERN_ERR PFX
"%s: descriptor error q=%#x get=%u [%llx] put=%u\n",
2431 dev
->name
, (unsigned) q
, idx
, (unsigned long long) le
[idx
],
2432 (unsigned) sky2_read16(hw
, Y2_QADDR(q
, PREF_UNIT_PUT_IDX
)));
2434 sky2_write32(hw
, Q_ADDR(q
, Q_CSR
), BMU_CLR_IRQ_CHK
);
2437 /* Check for lost IRQ once a second */
2438 static void sky2_watchdog(unsigned long arg
)
2440 struct sky2_hw
*hw
= (struct sky2_hw
*) arg
;
2442 if (sky2_read32(hw
, B0_ISRC
)) {
2443 struct net_device
*dev
= hw
->dev
[0];
2445 if (__netif_rx_schedule_prep(dev
))
2446 __netif_rx_schedule(dev
);
2450 mod_timer(&hw
->watchdog_timer
, round_jiffies(jiffies
+ HZ
));
2453 /* Hardware/software error handling */
2454 static void sky2_err_intr(struct sky2_hw
*hw
, u32 status
)
2456 if (net_ratelimit())
2457 dev_warn(&hw
->pdev
->dev
, "error interrupt status=%#x\n", status
);
2459 if (status
& Y2_IS_HW_ERR
)
2462 if (status
& Y2_IS_IRQ_MAC1
)
2463 sky2_mac_intr(hw
, 0);
2465 if (status
& Y2_IS_IRQ_MAC2
)
2466 sky2_mac_intr(hw
, 1);
2468 if (status
& Y2_IS_CHK_RX1
)
2469 sky2_le_error(hw
, 0, Q_R1
, RX_LE_SIZE
);
2471 if (status
& Y2_IS_CHK_RX2
)
2472 sky2_le_error(hw
, 1, Q_R2
, RX_LE_SIZE
);
2474 if (status
& Y2_IS_CHK_TXA1
)
2475 sky2_le_error(hw
, 0, Q_XA1
, TX_RING_SIZE
);
2477 if (status
& Y2_IS_CHK_TXA2
)
2478 sky2_le_error(hw
, 1, Q_XA2
, TX_RING_SIZE
);
2481 static int sky2_poll(struct net_device
*dev0
, int *budget
)
2483 struct sky2_hw
*hw
= ((struct sky2_port
*) netdev_priv(dev0
))->hw
;
2485 u32 status
= sky2_read32(hw
, B0_Y2_SP_EISR
);
2487 if (unlikely(status
& Y2_IS_ERROR
))
2488 sky2_err_intr(hw
, status
);
2490 if (status
& Y2_IS_IRQ_PHY1
)
2491 sky2_phy_intr(hw
, 0);
2493 if (status
& Y2_IS_IRQ_PHY2
)
2494 sky2_phy_intr(hw
, 1);
2496 work_done
= sky2_status_intr(hw
, min(dev0
->quota
, *budget
));
2497 *budget
-= work_done
;
2498 dev0
->quota
-= work_done
;
2501 if (hw
->st_idx
!= sky2_read16(hw
, STAT_PUT_IDX
))
2504 /* Bug/Errata workaround?
2505 * Need to kick the TX irq moderation timer.
2507 if (sky2_read8(hw
, STAT_TX_TIMER_CTRL
) == TIM_START
) {
2508 sky2_write8(hw
, STAT_TX_TIMER_CTRL
, TIM_STOP
);
2509 sky2_write8(hw
, STAT_TX_TIMER_CTRL
, TIM_START
);
2511 netif_rx_complete(dev0
);
2513 sky2_read32(hw
, B0_Y2_SP_LISR
);
2517 static irqreturn_t
sky2_intr(int irq
, void *dev_id
)
2519 struct sky2_hw
*hw
= dev_id
;
2520 struct net_device
*dev0
= hw
->dev
[0];
2523 /* Reading this mask interrupts as side effect */
2524 status
= sky2_read32(hw
, B0_Y2_SP_ISRC2
);
2525 if (status
== 0 || status
== ~0)
2528 prefetch(&hw
->st_le
[hw
->st_idx
]);
2529 if (likely(__netif_rx_schedule_prep(dev0
)))
2530 __netif_rx_schedule(dev0
);
2535 #ifdef CONFIG_NET_POLL_CONTROLLER
2536 static void sky2_netpoll(struct net_device
*dev
)
2538 struct sky2_port
*sky2
= netdev_priv(dev
);
2539 struct net_device
*dev0
= sky2
->hw
->dev
[0];
2541 if (netif_running(dev
) && __netif_rx_schedule_prep(dev0
))
2542 __netif_rx_schedule(dev0
);
2546 /* Chip internal frequency for clock calculations */
2547 static inline u32
sky2_mhz(const struct sky2_hw
*hw
)
2549 switch (hw
->chip_id
) {
2550 case CHIP_ID_YUKON_EC
:
2551 case CHIP_ID_YUKON_EC_U
:
2552 case CHIP_ID_YUKON_EX
:
2553 return 125; /* 125 Mhz */
2554 case CHIP_ID_YUKON_FE
:
2555 return 100; /* 100 Mhz */
2556 default: /* YUKON_XL */
2557 return 156; /* 156 Mhz */
2561 static inline u32
sky2_us2clk(const struct sky2_hw
*hw
, u32 us
)
2563 return sky2_mhz(hw
) * us
;
2566 static inline u32
sky2_clk2us(const struct sky2_hw
*hw
, u32 clk
)
2568 return clk
/ sky2_mhz(hw
);
2572 static int __devinit
sky2_init(struct sky2_hw
*hw
)
2576 /* Enable all clocks */
2577 sky2_pci_write32(hw
, PCI_DEV_REG3
, 0);
2579 sky2_write8(hw
, B0_CTST
, CS_RST_CLR
);
2581 hw
->chip_id
= sky2_read8(hw
, B2_CHIP_ID
);
2582 if (hw
->chip_id
< CHIP_ID_YUKON_XL
|| hw
->chip_id
> CHIP_ID_YUKON_FE
) {
2583 dev_err(&hw
->pdev
->dev
, "unsupported chip type 0x%x\n",
2588 hw
->chip_rev
= (sky2_read8(hw
, B2_MAC_CFG
) & CFG_CHIP_R_MSK
) >> 4;
2590 /* This rev is really old, and requires untested workarounds */
2591 if (hw
->chip_id
== CHIP_ID_YUKON_EC
&& hw
->chip_rev
== CHIP_REV_YU_EC_A1
) {
2592 dev_err(&hw
->pdev
->dev
, "unsupported revision Yukon-%s (0x%x) rev %d\n",
2593 yukon2_name
[hw
->chip_id
- CHIP_ID_YUKON_XL
],
2594 hw
->chip_id
, hw
->chip_rev
);
2598 hw
->pmd_type
= sky2_read8(hw
, B2_PMD_TYP
);
2600 t8
= sky2_read8(hw
, B2_Y2_HW_RES
);
2601 if ((t8
& CFG_DUAL_MAC_MSK
) == CFG_DUAL_MAC_MSK
) {
2602 if (!(sky2_read8(hw
, B2_Y2_CLK_GATE
) & Y2_STATUS_LNK2_INAC
))
2609 static void sky2_reset(struct sky2_hw
*hw
)
2615 if (hw
->chip_id
== CHIP_ID_YUKON_EX
) {
2616 status
= sky2_read16(hw
, HCU_CCSR
);
2617 status
&= ~(HCU_CCSR_AHB_RST
| HCU_CCSR_CPU_RST_MODE
|
2618 HCU_CCSR_UC_STATE_MSK
);
2619 sky2_write16(hw
, HCU_CCSR
, status
);
2621 sky2_write8(hw
, B28_Y2_ASF_STAT_CMD
, Y2_ASF_RESET
);
2622 sky2_write16(hw
, B0_CTST
, Y2_ASF_DISABLE
);
2625 sky2_write8(hw
, B0_CTST
, CS_RST_SET
);
2626 sky2_write8(hw
, B0_CTST
, CS_RST_CLR
);
2628 /* clear PCI errors, if any */
2629 status
= sky2_pci_read16(hw
, PCI_STATUS
);
2631 sky2_write8(hw
, B2_TST_CTRL1
, TST_CFG_WRITE_ON
);
2632 sky2_pci_write16(hw
, PCI_STATUS
, status
| PCI_STATUS_ERROR_BITS
);
2635 sky2_write8(hw
, B0_CTST
, CS_MRST_CLR
);
2637 /* clear any PEX errors */
2638 if (pci_find_capability(hw
->pdev
, PCI_CAP_ID_EXP
))
2639 sky2_pci_write32(hw
, PEX_UNC_ERR_STAT
, 0xffffffffUL
);
2644 for (i
= 0; i
< hw
->ports
; i
++) {
2645 sky2_write8(hw
, SK_REG(i
, GMAC_LINK_CTRL
), GMLC_RST_SET
);
2646 sky2_write8(hw
, SK_REG(i
, GMAC_LINK_CTRL
), GMLC_RST_CLR
);
2648 if (hw
->chip_id
== CHIP_ID_YUKON_EX
)
2649 sky2_write16(hw
, SK_REG(i
, GMAC_CTRL
),
2650 GMC_BYP_MACSECRX_ON
| GMC_BYP_MACSECTX_ON
2654 sky2_write8(hw
, B2_TST_CTRL1
, TST_CFG_WRITE_OFF
);
2656 /* Clear I2C IRQ noise */
2657 sky2_write32(hw
, B2_I2C_IRQ
, 1);
2659 /* turn off hardware timer (unused) */
2660 sky2_write8(hw
, B2_TI_CTRL
, TIM_STOP
);
2661 sky2_write8(hw
, B2_TI_CTRL
, TIM_CLR_IRQ
);
2663 sky2_write8(hw
, B0_Y2LED
, LED_STAT_ON
);
2665 /* Turn off descriptor polling */
2666 sky2_write32(hw
, B28_DPT_CTRL
, DPT_STOP
);
2668 /* Turn off receive timestamp */
2669 sky2_write8(hw
, GMAC_TI_ST_CTRL
, GMT_ST_STOP
);
2670 sky2_write8(hw
, GMAC_TI_ST_CTRL
, GMT_ST_CLR_IRQ
);
2672 /* enable the Tx Arbiters */
2673 for (i
= 0; i
< hw
->ports
; i
++)
2674 sky2_write8(hw
, SK_REG(i
, TXA_CTRL
), TXA_ENA_ARB
);
2676 /* Initialize ram interface */
2677 for (i
= 0; i
< hw
->ports
; i
++) {
2678 sky2_write8(hw
, RAM_BUFFER(i
, B3_RI_CTRL
), RI_RST_CLR
);
2680 sky2_write8(hw
, RAM_BUFFER(i
, B3_RI_WTO_R1
), SK_RI_TO_53
);
2681 sky2_write8(hw
, RAM_BUFFER(i
, B3_RI_WTO_XA1
), SK_RI_TO_53
);
2682 sky2_write8(hw
, RAM_BUFFER(i
, B3_RI_WTO_XS1
), SK_RI_TO_53
);
2683 sky2_write8(hw
, RAM_BUFFER(i
, B3_RI_RTO_R1
), SK_RI_TO_53
);
2684 sky2_write8(hw
, RAM_BUFFER(i
, B3_RI_RTO_XA1
), SK_RI_TO_53
);
2685 sky2_write8(hw
, RAM_BUFFER(i
, B3_RI_RTO_XS1
), SK_RI_TO_53
);
2686 sky2_write8(hw
, RAM_BUFFER(i
, B3_RI_WTO_R2
), SK_RI_TO_53
);
2687 sky2_write8(hw
, RAM_BUFFER(i
, B3_RI_WTO_XA2
), SK_RI_TO_53
);
2688 sky2_write8(hw
, RAM_BUFFER(i
, B3_RI_WTO_XS2
), SK_RI_TO_53
);
2689 sky2_write8(hw
, RAM_BUFFER(i
, B3_RI_RTO_R2
), SK_RI_TO_53
);
2690 sky2_write8(hw
, RAM_BUFFER(i
, B3_RI_RTO_XA2
), SK_RI_TO_53
);
2691 sky2_write8(hw
, RAM_BUFFER(i
, B3_RI_RTO_XS2
), SK_RI_TO_53
);
2694 sky2_write32(hw
, B0_HWE_IMSK
, Y2_HWE_ALL_MASK
);
2696 for (i
= 0; i
< hw
->ports
; i
++)
2697 sky2_gmac_reset(hw
, i
);
2699 memset(hw
->st_le
, 0, STATUS_LE_BYTES
);
2702 sky2_write32(hw
, STAT_CTRL
, SC_STAT_RST_SET
);
2703 sky2_write32(hw
, STAT_CTRL
, SC_STAT_RST_CLR
);
2705 sky2_write32(hw
, STAT_LIST_ADDR_LO
, hw
->st_dma
);
2706 sky2_write32(hw
, STAT_LIST_ADDR_HI
, (u64
) hw
->st_dma
>> 32);
2708 /* Set the list last index */
2709 sky2_write16(hw
, STAT_LAST_IDX
, STATUS_RING_SIZE
- 1);
2711 sky2_write16(hw
, STAT_TX_IDX_TH
, 10);
2712 sky2_write8(hw
, STAT_FIFO_WM
, 16);
2714 /* set Status-FIFO ISR watermark */
2715 if (hw
->chip_id
== CHIP_ID_YUKON_XL
&& hw
->chip_rev
== 0)
2716 sky2_write8(hw
, STAT_FIFO_ISR_WM
, 4);
2718 sky2_write8(hw
, STAT_FIFO_ISR_WM
, 16);
2720 sky2_write32(hw
, STAT_TX_TIMER_INI
, sky2_us2clk(hw
, 1000));
2721 sky2_write32(hw
, STAT_ISR_TIMER_INI
, sky2_us2clk(hw
, 20));
2722 sky2_write32(hw
, STAT_LEV_TIMER_INI
, sky2_us2clk(hw
, 100));
2724 /* enable status unit */
2725 sky2_write32(hw
, STAT_CTRL
, SC_STAT_OP_ON
);
2727 sky2_write8(hw
, STAT_TX_TIMER_CTRL
, TIM_START
);
2728 sky2_write8(hw
, STAT_LEV_TIMER_CTRL
, TIM_START
);
2729 sky2_write8(hw
, STAT_ISR_TIMER_CTRL
, TIM_START
);
2732 static void sky2_restart(struct work_struct
*work
)
2734 struct sky2_hw
*hw
= container_of(work
, struct sky2_hw
, restart_work
);
2735 struct net_device
*dev
;
2739 sky2_write32(hw
, B0_IMSK
, 0);
2740 sky2_read32(hw
, B0_IMSK
);
2742 netif_poll_disable(hw
->dev
[0]);
2744 for (i
= 0; i
< hw
->ports
; i
++) {
2746 if (netif_running(dev
))
2751 sky2_write32(hw
, B0_IMSK
, Y2_IS_BASE
);
2752 netif_poll_enable(hw
->dev
[0]);
2754 for (i
= 0; i
< hw
->ports
; i
++) {
2756 if (netif_running(dev
)) {
2759 printk(KERN_INFO PFX
"%s: could not restart %d\n",
2769 static inline u8
sky2_wol_supported(const struct sky2_hw
*hw
)
2771 return sky2_is_copper(hw
) ? (WAKE_PHY
| WAKE_MAGIC
) : 0;
2774 static void sky2_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
2776 const struct sky2_port
*sky2
= netdev_priv(dev
);
2778 wol
->supported
= sky2_wol_supported(sky2
->hw
);
2779 wol
->wolopts
= sky2
->wol
;
2782 static int sky2_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
2784 struct sky2_port
*sky2
= netdev_priv(dev
);
2785 struct sky2_hw
*hw
= sky2
->hw
;
2787 if (wol
->wolopts
& ~sky2_wol_supported(sky2
->hw
))
2790 sky2
->wol
= wol
->wolopts
;
2792 if (hw
->chip_id
== CHIP_ID_YUKON_EC_U
|| hw
->chip_id
== CHIP_ID_YUKON_EX
)
2793 sky2_write32(hw
, B0_CTST
, sky2
->wol
2794 ? Y2_HW_WOL_ON
: Y2_HW_WOL_OFF
);
2796 if (!netif_running(dev
))
2797 sky2_wol_init(sky2
);
2801 static u32
sky2_supported_modes(const struct sky2_hw
*hw
)
2803 if (sky2_is_copper(hw
)) {
2804 u32 modes
= SUPPORTED_10baseT_Half
2805 | SUPPORTED_10baseT_Full
2806 | SUPPORTED_100baseT_Half
2807 | SUPPORTED_100baseT_Full
2808 | SUPPORTED_Autoneg
| SUPPORTED_TP
;
2810 if (hw
->chip_id
!= CHIP_ID_YUKON_FE
)
2811 modes
|= SUPPORTED_1000baseT_Half
2812 | SUPPORTED_1000baseT_Full
;
2815 return SUPPORTED_1000baseT_Half
2816 | SUPPORTED_1000baseT_Full
2821 static int sky2_get_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
2823 struct sky2_port
*sky2
= netdev_priv(dev
);
2824 struct sky2_hw
*hw
= sky2
->hw
;
2826 ecmd
->transceiver
= XCVR_INTERNAL
;
2827 ecmd
->supported
= sky2_supported_modes(hw
);
2828 ecmd
->phy_address
= PHY_ADDR_MARV
;
2829 if (sky2_is_copper(hw
)) {
2830 ecmd
->supported
= SUPPORTED_10baseT_Half
2831 | SUPPORTED_10baseT_Full
2832 | SUPPORTED_100baseT_Half
2833 | SUPPORTED_100baseT_Full
2834 | SUPPORTED_1000baseT_Half
2835 | SUPPORTED_1000baseT_Full
2836 | SUPPORTED_Autoneg
| SUPPORTED_TP
;
2837 ecmd
->port
= PORT_TP
;
2838 ecmd
->speed
= sky2
->speed
;
2840 ecmd
->speed
= SPEED_1000
;
2841 ecmd
->port
= PORT_FIBRE
;
2844 ecmd
->advertising
= sky2
->advertising
;
2845 ecmd
->autoneg
= sky2
->autoneg
;
2846 ecmd
->duplex
= sky2
->duplex
;
2850 static int sky2_set_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
2852 struct sky2_port
*sky2
= netdev_priv(dev
);
2853 const struct sky2_hw
*hw
= sky2
->hw
;
2854 u32 supported
= sky2_supported_modes(hw
);
2856 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
2857 ecmd
->advertising
= supported
;
2863 switch (ecmd
->speed
) {
2865 if (ecmd
->duplex
== DUPLEX_FULL
)
2866 setting
= SUPPORTED_1000baseT_Full
;
2867 else if (ecmd
->duplex
== DUPLEX_HALF
)
2868 setting
= SUPPORTED_1000baseT_Half
;
2873 if (ecmd
->duplex
== DUPLEX_FULL
)
2874 setting
= SUPPORTED_100baseT_Full
;
2875 else if (ecmd
->duplex
== DUPLEX_HALF
)
2876 setting
= SUPPORTED_100baseT_Half
;
2882 if (ecmd
->duplex
== DUPLEX_FULL
)
2883 setting
= SUPPORTED_10baseT_Full
;
2884 else if (ecmd
->duplex
== DUPLEX_HALF
)
2885 setting
= SUPPORTED_10baseT_Half
;
2893 if ((setting
& supported
) == 0)
2896 sky2
->speed
= ecmd
->speed
;
2897 sky2
->duplex
= ecmd
->duplex
;
2900 sky2
->autoneg
= ecmd
->autoneg
;
2901 sky2
->advertising
= ecmd
->advertising
;
2903 if (netif_running(dev
))
2904 sky2_phy_reinit(sky2
);
2909 static void sky2_get_drvinfo(struct net_device
*dev
,
2910 struct ethtool_drvinfo
*info
)
2912 struct sky2_port
*sky2
= netdev_priv(dev
);
2914 strcpy(info
->driver
, DRV_NAME
);
2915 strcpy(info
->version
, DRV_VERSION
);
2916 strcpy(info
->fw_version
, "N/A");
2917 strcpy(info
->bus_info
, pci_name(sky2
->hw
->pdev
));
2920 static const struct sky2_stat
{
2921 char name
[ETH_GSTRING_LEN
];
2924 { "tx_bytes", GM_TXO_OK_HI
},
2925 { "rx_bytes", GM_RXO_OK_HI
},
2926 { "tx_broadcast", GM_TXF_BC_OK
},
2927 { "rx_broadcast", GM_RXF_BC_OK
},
2928 { "tx_multicast", GM_TXF_MC_OK
},
2929 { "rx_multicast", GM_RXF_MC_OK
},
2930 { "tx_unicast", GM_TXF_UC_OK
},
2931 { "rx_unicast", GM_RXF_UC_OK
},
2932 { "tx_mac_pause", GM_TXF_MPAUSE
},
2933 { "rx_mac_pause", GM_RXF_MPAUSE
},
2934 { "collisions", GM_TXF_COL
},
2935 { "late_collision",GM_TXF_LAT_COL
},
2936 { "aborted", GM_TXF_ABO_COL
},
2937 { "single_collisions", GM_TXF_SNG_COL
},
2938 { "multi_collisions", GM_TXF_MUL_COL
},
2940 { "rx_short", GM_RXF_SHT
},
2941 { "rx_runt", GM_RXE_FRAG
},
2942 { "rx_64_byte_packets", GM_RXF_64B
},
2943 { "rx_65_to_127_byte_packets", GM_RXF_127B
},
2944 { "rx_128_to_255_byte_packets", GM_RXF_255B
},
2945 { "rx_256_to_511_byte_packets", GM_RXF_511B
},
2946 { "rx_512_to_1023_byte_packets", GM_RXF_1023B
},
2947 { "rx_1024_to_1518_byte_packets", GM_RXF_1518B
},
2948 { "rx_1518_to_max_byte_packets", GM_RXF_MAX_SZ
},
2949 { "rx_too_long", GM_RXF_LNG_ERR
},
2950 { "rx_fifo_overflow", GM_RXE_FIFO_OV
},
2951 { "rx_jabber", GM_RXF_JAB_PKT
},
2952 { "rx_fcs_error", GM_RXF_FCS_ERR
},
2954 { "tx_64_byte_packets", GM_TXF_64B
},
2955 { "tx_65_to_127_byte_packets", GM_TXF_127B
},
2956 { "tx_128_to_255_byte_packets", GM_TXF_255B
},
2957 { "tx_256_to_511_byte_packets", GM_TXF_511B
},
2958 { "tx_512_to_1023_byte_packets", GM_TXF_1023B
},
2959 { "tx_1024_to_1518_byte_packets", GM_TXF_1518B
},
2960 { "tx_1519_to_max_byte_packets", GM_TXF_MAX_SZ
},
2961 { "tx_fifo_underrun", GM_TXE_FIFO_UR
},
2964 static u32
sky2_get_rx_csum(struct net_device
*dev
)
2966 struct sky2_port
*sky2
= netdev_priv(dev
);
2968 return sky2
->rx_csum
;
2971 static int sky2_set_rx_csum(struct net_device
*dev
, u32 data
)
2973 struct sky2_port
*sky2
= netdev_priv(dev
);
2975 sky2
->rx_csum
= data
;
2977 sky2_write32(sky2
->hw
, Q_ADDR(rxqaddr
[sky2
->port
], Q_CSR
),
2978 data
? BMU_ENA_RX_CHKSUM
: BMU_DIS_RX_CHKSUM
);
2983 static u32
sky2_get_msglevel(struct net_device
*netdev
)
2985 struct sky2_port
*sky2
= netdev_priv(netdev
);
2986 return sky2
->msg_enable
;
2989 static int sky2_nway_reset(struct net_device
*dev
)
2991 struct sky2_port
*sky2
= netdev_priv(dev
);
2993 if (!netif_running(dev
) || sky2
->autoneg
!= AUTONEG_ENABLE
)
2996 sky2_phy_reinit(sky2
);
3001 static void sky2_phy_stats(struct sky2_port
*sky2
, u64
* data
, unsigned count
)
3003 struct sky2_hw
*hw
= sky2
->hw
;
3004 unsigned port
= sky2
->port
;
3007 data
[0] = (u64
) gma_read32(hw
, port
, GM_TXO_OK_HI
) << 32
3008 | (u64
) gma_read32(hw
, port
, GM_TXO_OK_LO
);
3009 data
[1] = (u64
) gma_read32(hw
, port
, GM_RXO_OK_HI
) << 32
3010 | (u64
) gma_read32(hw
, port
, GM_RXO_OK_LO
);
3012 for (i
= 2; i
< count
; i
++)
3013 data
[i
] = (u64
) gma_read32(hw
, port
, sky2_stats
[i
].offset
);
3016 static void sky2_set_msglevel(struct net_device
*netdev
, u32 value
)
3018 struct sky2_port
*sky2
= netdev_priv(netdev
);
3019 sky2
->msg_enable
= value
;
3022 static int sky2_get_stats_count(struct net_device
*dev
)
3024 return ARRAY_SIZE(sky2_stats
);
3027 static void sky2_get_ethtool_stats(struct net_device
*dev
,
3028 struct ethtool_stats
*stats
, u64
* data
)
3030 struct sky2_port
*sky2
= netdev_priv(dev
);
3032 sky2_phy_stats(sky2
, data
, ARRAY_SIZE(sky2_stats
));
3035 static void sky2_get_strings(struct net_device
*dev
, u32 stringset
, u8
* data
)
3039 switch (stringset
) {
3041 for (i
= 0; i
< ARRAY_SIZE(sky2_stats
); i
++)
3042 memcpy(data
+ i
* ETH_GSTRING_LEN
,
3043 sky2_stats
[i
].name
, ETH_GSTRING_LEN
);
3048 static struct net_device_stats
*sky2_get_stats(struct net_device
*dev
)
3050 struct sky2_port
*sky2
= netdev_priv(dev
);
3051 return &sky2
->net_stats
;
3054 static int sky2_set_mac_address(struct net_device
*dev
, void *p
)
3056 struct sky2_port
*sky2
= netdev_priv(dev
);
3057 struct sky2_hw
*hw
= sky2
->hw
;
3058 unsigned port
= sky2
->port
;
3059 const struct sockaddr
*addr
= p
;
3061 if (!is_valid_ether_addr(addr
->sa_data
))
3062 return -EADDRNOTAVAIL
;
3064 memcpy(dev
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
3065 memcpy_toio(hw
->regs
+ B2_MAC_1
+ port
* 8,
3066 dev
->dev_addr
, ETH_ALEN
);
3067 memcpy_toio(hw
->regs
+ B2_MAC_2
+ port
* 8,
3068 dev
->dev_addr
, ETH_ALEN
);
3070 /* virtual address for data */
3071 gma_set_addr(hw
, port
, GM_SRC_ADDR_2L
, dev
->dev_addr
);
3073 /* physical address: used for pause frames */
3074 gma_set_addr(hw
, port
, GM_SRC_ADDR_1L
, dev
->dev_addr
);
3079 static void inline sky2_add_filter(u8 filter
[8], const u8
*addr
)
3083 bit
= ether_crc(ETH_ALEN
, addr
) & 63;
3084 filter
[bit
>> 3] |= 1 << (bit
& 7);
3087 static void sky2_set_multicast(struct net_device
*dev
)
3089 struct sky2_port
*sky2
= netdev_priv(dev
);
3090 struct sky2_hw
*hw
= sky2
->hw
;
3091 unsigned port
= sky2
->port
;
3092 struct dev_mc_list
*list
= dev
->mc_list
;
3096 static const u8 pause_mc_addr
[ETH_ALEN
] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 };
3098 rx_pause
= (sky2
->flow_status
== FC_RX
|| sky2
->flow_status
== FC_BOTH
);
3099 memset(filter
, 0, sizeof(filter
));
3101 reg
= gma_read16(hw
, port
, GM_RX_CTRL
);
3102 reg
|= GM_RXCR_UCF_ENA
;
3104 if (dev
->flags
& IFF_PROMISC
) /* promiscuous */
3105 reg
&= ~(GM_RXCR_UCF_ENA
| GM_RXCR_MCF_ENA
);
3106 else if (dev
->flags
& IFF_ALLMULTI
)
3107 memset(filter
, 0xff, sizeof(filter
));
3108 else if (dev
->mc_count
== 0 && !rx_pause
)
3109 reg
&= ~GM_RXCR_MCF_ENA
;
3112 reg
|= GM_RXCR_MCF_ENA
;
3115 sky2_add_filter(filter
, pause_mc_addr
);
3117 for (i
= 0; list
&& i
< dev
->mc_count
; i
++, list
= list
->next
)
3118 sky2_add_filter(filter
, list
->dmi_addr
);
3121 gma_write16(hw
, port
, GM_MC_ADDR_H1
,
3122 (u16
) filter
[0] | ((u16
) filter
[1] << 8));
3123 gma_write16(hw
, port
, GM_MC_ADDR_H2
,
3124 (u16
) filter
[2] | ((u16
) filter
[3] << 8));
3125 gma_write16(hw
, port
, GM_MC_ADDR_H3
,
3126 (u16
) filter
[4] | ((u16
) filter
[5] << 8));
3127 gma_write16(hw
, port
, GM_MC_ADDR_H4
,
3128 (u16
) filter
[6] | ((u16
) filter
[7] << 8));
3130 gma_write16(hw
, port
, GM_RX_CTRL
, reg
);
3133 /* Can have one global because blinking is controlled by
3134 * ethtool and that is always under RTNL mutex
3136 static void sky2_led(struct sky2_hw
*hw
, unsigned port
, int on
)
3140 switch (hw
->chip_id
) {
3141 case CHIP_ID_YUKON_XL
:
3142 pg
= gm_phy_read(hw
, port
, PHY_MARV_EXT_ADR
);
3143 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, 3);
3144 gm_phy_write(hw
, port
, PHY_MARV_PHY_CTRL
,
3145 on
? (PHY_M_LEDC_LOS_CTRL(1) |
3146 PHY_M_LEDC_INIT_CTRL(7) |
3147 PHY_M_LEDC_STA1_CTRL(7) |
3148 PHY_M_LEDC_STA0_CTRL(7))
3151 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, pg
);
3155 gm_phy_write(hw
, port
, PHY_MARV_LED_CTRL
, 0);
3156 gm_phy_write(hw
, port
, PHY_MARV_LED_OVER
,
3157 on
? PHY_M_LED_ALL
: 0);
3161 /* blink LED's for finding board */
3162 static int sky2_phys_id(struct net_device
*dev
, u32 data
)
3164 struct sky2_port
*sky2
= netdev_priv(dev
);
3165 struct sky2_hw
*hw
= sky2
->hw
;
3166 unsigned port
= sky2
->port
;
3167 u16 ledctrl
, ledover
= 0;
3172 if (!data
|| data
> (u32
) (MAX_SCHEDULE_TIMEOUT
/ HZ
))
3173 ms
= jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT
);
3177 /* save initial values */
3178 spin_lock_bh(&sky2
->phy_lock
);
3179 if (hw
->chip_id
== CHIP_ID_YUKON_XL
) {
3180 u16 pg
= gm_phy_read(hw
, port
, PHY_MARV_EXT_ADR
);
3181 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, 3);
3182 ledctrl
= gm_phy_read(hw
, port
, PHY_MARV_PHY_CTRL
);
3183 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, pg
);
3185 ledctrl
= gm_phy_read(hw
, port
, PHY_MARV_LED_CTRL
);
3186 ledover
= gm_phy_read(hw
, port
, PHY_MARV_LED_OVER
);
3190 while (!interrupted
&& ms
> 0) {
3191 sky2_led(hw
, port
, onoff
);
3194 spin_unlock_bh(&sky2
->phy_lock
);
3195 interrupted
= msleep_interruptible(250);
3196 spin_lock_bh(&sky2
->phy_lock
);
3201 /* resume regularly scheduled programming */
3202 if (hw
->chip_id
== CHIP_ID_YUKON_XL
) {
3203 u16 pg
= gm_phy_read(hw
, port
, PHY_MARV_EXT_ADR
);
3204 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, 3);
3205 gm_phy_write(hw
, port
, PHY_MARV_PHY_CTRL
, ledctrl
);
3206 gm_phy_write(hw
, port
, PHY_MARV_EXT_ADR
, pg
);
3208 gm_phy_write(hw
, port
, PHY_MARV_LED_CTRL
, ledctrl
);
3209 gm_phy_write(hw
, port
, PHY_MARV_LED_OVER
, ledover
);
3211 spin_unlock_bh(&sky2
->phy_lock
);
3216 static void sky2_get_pauseparam(struct net_device
*dev
,
3217 struct ethtool_pauseparam
*ecmd
)
3219 struct sky2_port
*sky2
= netdev_priv(dev
);
3221 switch (sky2
->flow_mode
) {
3223 ecmd
->tx_pause
= ecmd
->rx_pause
= 0;
3226 ecmd
->tx_pause
= 1, ecmd
->rx_pause
= 0;
3229 ecmd
->tx_pause
= 0, ecmd
->rx_pause
= 1;
3232 ecmd
->tx_pause
= ecmd
->rx_pause
= 1;
3235 ecmd
->autoneg
= sky2
->autoneg
;
3238 static int sky2_set_pauseparam(struct net_device
*dev
,
3239 struct ethtool_pauseparam
*ecmd
)
3241 struct sky2_port
*sky2
= netdev_priv(dev
);
3243 sky2
->autoneg
= ecmd
->autoneg
;
3244 sky2
->flow_mode
= sky2_flow(ecmd
->rx_pause
, ecmd
->tx_pause
);
3246 if (netif_running(dev
))
3247 sky2_phy_reinit(sky2
);
3252 static int sky2_get_coalesce(struct net_device
*dev
,
3253 struct ethtool_coalesce
*ecmd
)
3255 struct sky2_port
*sky2
= netdev_priv(dev
);
3256 struct sky2_hw
*hw
= sky2
->hw
;
3258 if (sky2_read8(hw
, STAT_TX_TIMER_CTRL
) == TIM_STOP
)
3259 ecmd
->tx_coalesce_usecs
= 0;
3261 u32 clks
= sky2_read32(hw
, STAT_TX_TIMER_INI
);
3262 ecmd
->tx_coalesce_usecs
= sky2_clk2us(hw
, clks
);
3264 ecmd
->tx_max_coalesced_frames
= sky2_read16(hw
, STAT_TX_IDX_TH
);
3266 if (sky2_read8(hw
, STAT_LEV_TIMER_CTRL
) == TIM_STOP
)
3267 ecmd
->rx_coalesce_usecs
= 0;
3269 u32 clks
= sky2_read32(hw
, STAT_LEV_TIMER_INI
);
3270 ecmd
->rx_coalesce_usecs
= sky2_clk2us(hw
, clks
);
3272 ecmd
->rx_max_coalesced_frames
= sky2_read8(hw
, STAT_FIFO_WM
);
3274 if (sky2_read8(hw
, STAT_ISR_TIMER_CTRL
) == TIM_STOP
)
3275 ecmd
->rx_coalesce_usecs_irq
= 0;
3277 u32 clks
= sky2_read32(hw
, STAT_ISR_TIMER_INI
);
3278 ecmd
->rx_coalesce_usecs_irq
= sky2_clk2us(hw
, clks
);
3281 ecmd
->rx_max_coalesced_frames_irq
= sky2_read8(hw
, STAT_FIFO_ISR_WM
);
3286 /* Note: this affect both ports */
3287 static int sky2_set_coalesce(struct net_device
*dev
,
3288 struct ethtool_coalesce
*ecmd
)
3290 struct sky2_port
*sky2
= netdev_priv(dev
);
3291 struct sky2_hw
*hw
= sky2
->hw
;
3292 const u32 tmax
= sky2_clk2us(hw
, 0x0ffffff);
3294 if (ecmd
->tx_coalesce_usecs
> tmax
||
3295 ecmd
->rx_coalesce_usecs
> tmax
||
3296 ecmd
->rx_coalesce_usecs_irq
> tmax
)
3299 if (ecmd
->tx_max_coalesced_frames
>= TX_RING_SIZE
-1)
3301 if (ecmd
->rx_max_coalesced_frames
> RX_MAX_PENDING
)
3303 if (ecmd
->rx_max_coalesced_frames_irq
>RX_MAX_PENDING
)
3306 if (ecmd
->tx_coalesce_usecs
== 0)
3307 sky2_write8(hw
, STAT_TX_TIMER_CTRL
, TIM_STOP
);
3309 sky2_write32(hw
, STAT_TX_TIMER_INI
,
3310 sky2_us2clk(hw
, ecmd
->tx_coalesce_usecs
));
3311 sky2_write8(hw
, STAT_TX_TIMER_CTRL
, TIM_START
);
3313 sky2_write16(hw
, STAT_TX_IDX_TH
, ecmd
->tx_max_coalesced_frames
);
3315 if (ecmd
->rx_coalesce_usecs
== 0)
3316 sky2_write8(hw
, STAT_LEV_TIMER_CTRL
, TIM_STOP
);
3318 sky2_write32(hw
, STAT_LEV_TIMER_INI
,
3319 sky2_us2clk(hw
, ecmd
->rx_coalesce_usecs
));
3320 sky2_write8(hw
, STAT_LEV_TIMER_CTRL
, TIM_START
);
3322 sky2_write8(hw
, STAT_FIFO_WM
, ecmd
->rx_max_coalesced_frames
);
3324 if (ecmd
->rx_coalesce_usecs_irq
== 0)
3325 sky2_write8(hw
, STAT_ISR_TIMER_CTRL
, TIM_STOP
);
3327 sky2_write32(hw
, STAT_ISR_TIMER_INI
,
3328 sky2_us2clk(hw
, ecmd
->rx_coalesce_usecs_irq
));
3329 sky2_write8(hw
, STAT_ISR_TIMER_CTRL
, TIM_START
);
3331 sky2_write8(hw
, STAT_FIFO_ISR_WM
, ecmd
->rx_max_coalesced_frames_irq
);
3335 static void sky2_get_ringparam(struct net_device
*dev
,
3336 struct ethtool_ringparam
*ering
)
3338 struct sky2_port
*sky2
= netdev_priv(dev
);
3340 ering
->rx_max_pending
= RX_MAX_PENDING
;
3341 ering
->rx_mini_max_pending
= 0;
3342 ering
->rx_jumbo_max_pending
= 0;
3343 ering
->tx_max_pending
= TX_RING_SIZE
- 1;
3345 ering
->rx_pending
= sky2
->rx_pending
;
3346 ering
->rx_mini_pending
= 0;
3347 ering
->rx_jumbo_pending
= 0;
3348 ering
->tx_pending
= sky2
->tx_pending
;
3351 static int sky2_set_ringparam(struct net_device
*dev
,
3352 struct ethtool_ringparam
*ering
)
3354 struct sky2_port
*sky2
= netdev_priv(dev
);
3357 if (ering
->rx_pending
> RX_MAX_PENDING
||
3358 ering
->rx_pending
< 8 ||
3359 ering
->tx_pending
< MAX_SKB_TX_LE
||
3360 ering
->tx_pending
> TX_RING_SIZE
- 1)
3363 if (netif_running(dev
))
3366 sky2
->rx_pending
= ering
->rx_pending
;
3367 sky2
->tx_pending
= ering
->tx_pending
;
3369 if (netif_running(dev
)) {
3374 sky2_set_multicast(dev
);
3380 static int sky2_get_regs_len(struct net_device
*dev
)
3386 * Returns copy of control register region
3387 * Note: ethtool_get_regs always provides full size (16k) buffer
3389 static void sky2_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
,
3392 const struct sky2_port
*sky2
= netdev_priv(dev
);
3393 const void __iomem
*io
= sky2
->hw
->regs
;
3396 memset(p
, 0, regs
->len
);
3398 memcpy_fromio(p
, io
, B3_RAM_ADDR
);
3400 /* skip diagnostic ram region */
3401 memcpy_fromio(p
+ B3_RI_WTO_R1
, io
+ B3_RI_WTO_R1
, 0x2000 - B3_RI_WTO_R1
);
3403 /* copy GMAC registers */
3404 memcpy_fromio(p
+ BASE_GMAC_1
, io
+ BASE_GMAC_1
, 0x1000);
3405 if (sky2
->hw
->ports
> 1)
3406 memcpy_fromio(p
+ BASE_GMAC_2
, io
+ BASE_GMAC_2
, 0x1000);
3410 /* In order to do Jumbo packets on these chips, need to turn off the
3411 * transmit store/forward. Therefore checksum offload won't work.
3413 static int no_tx_offload(struct net_device
*dev
)
3415 const struct sky2_port
*sky2
= netdev_priv(dev
);
3416 const struct sky2_hw
*hw
= sky2
->hw
;
3418 return dev
->mtu
> ETH_DATA_LEN
&& hw
->chip_id
== CHIP_ID_YUKON_EC_U
;
3421 static int sky2_set_tx_csum(struct net_device
*dev
, u32 data
)
3423 if (data
&& no_tx_offload(dev
))
3426 return ethtool_op_set_tx_csum(dev
, data
);
3430 static int sky2_set_tso(struct net_device
*dev
, u32 data
)
3432 if (data
&& no_tx_offload(dev
))
3435 return ethtool_op_set_tso(dev
, data
);
3438 static int sky2_get_eeprom_len(struct net_device
*dev
)
3440 struct sky2_port
*sky2
= netdev_priv(dev
);
3443 reg2
= sky2_pci_read32(sky2
->hw
, PCI_DEV_REG2
);
3444 return 1 << ( ((reg2
& PCI_VPD_ROM_SZ
) >> 14) + 8);
3447 static u32
sky2_vpd_read(struct sky2_hw
*hw
, int cap
, u16 offset
)
3449 sky2_pci_write16(hw
, cap
+ PCI_VPD_ADDR
, offset
);
3451 while (!(sky2_pci_read16(hw
, cap
+ PCI_VPD_ADDR
) & PCI_VPD_ADDR_F
))
3453 return sky2_pci_read32(hw
, cap
+ PCI_VPD_DATA
);
3456 static void sky2_vpd_write(struct sky2_hw
*hw
, int cap
, u16 offset
, u32 val
)
3458 sky2_pci_write32(hw
, cap
+ PCI_VPD_DATA
, val
);
3459 sky2_pci_write16(hw
, cap
+ PCI_VPD_ADDR
, offset
| PCI_VPD_ADDR_F
);
3462 } while (sky2_pci_read16(hw
, cap
+ PCI_VPD_ADDR
) & PCI_VPD_ADDR_F
);
3465 static int sky2_get_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
,
3468 struct sky2_port
*sky2
= netdev_priv(dev
);
3469 int cap
= pci_find_capability(sky2
->hw
->pdev
, PCI_CAP_ID_VPD
);
3470 int length
= eeprom
->len
;
3471 u16 offset
= eeprom
->offset
;
3476 eeprom
->magic
= SKY2_EEPROM_MAGIC
;
3478 while (length
> 0) {
3479 u32 val
= sky2_vpd_read(sky2
->hw
, cap
, offset
);
3480 int n
= min_t(int, length
, sizeof(val
));
3482 memcpy(data
, &val
, n
);
3490 static int sky2_set_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
,
3493 struct sky2_port
*sky2
= netdev_priv(dev
);
3494 int cap
= pci_find_capability(sky2
->hw
->pdev
, PCI_CAP_ID_VPD
);
3495 int length
= eeprom
->len
;
3496 u16 offset
= eeprom
->offset
;
3501 if (eeprom
->magic
!= SKY2_EEPROM_MAGIC
)
3504 while (length
> 0) {
3506 int n
= min_t(int, length
, sizeof(val
));
3508 if (n
< sizeof(val
))
3509 val
= sky2_vpd_read(sky2
->hw
, cap
, offset
);
3510 memcpy(&val
, data
, n
);
3512 sky2_vpd_write(sky2
->hw
, cap
, offset
, val
);
3522 static const struct ethtool_ops sky2_ethtool_ops
= {
3523 .get_settings
= sky2_get_settings
,
3524 .set_settings
= sky2_set_settings
,
3525 .get_drvinfo
= sky2_get_drvinfo
,
3526 .get_wol
= sky2_get_wol
,
3527 .set_wol
= sky2_set_wol
,
3528 .get_msglevel
= sky2_get_msglevel
,
3529 .set_msglevel
= sky2_set_msglevel
,
3530 .nway_reset
= sky2_nway_reset
,
3531 .get_regs_len
= sky2_get_regs_len
,
3532 .get_regs
= sky2_get_regs
,
3533 .get_link
= ethtool_op_get_link
,
3534 .get_eeprom_len
= sky2_get_eeprom_len
,
3535 .get_eeprom
= sky2_get_eeprom
,
3536 .set_eeprom
= sky2_set_eeprom
,
3537 .get_sg
= ethtool_op_get_sg
,
3538 .set_sg
= ethtool_op_set_sg
,
3539 .get_tx_csum
= ethtool_op_get_tx_csum
,
3540 .set_tx_csum
= sky2_set_tx_csum
,
3541 .get_tso
= ethtool_op_get_tso
,
3542 .set_tso
= sky2_set_tso
,
3543 .get_rx_csum
= sky2_get_rx_csum
,
3544 .set_rx_csum
= sky2_set_rx_csum
,
3545 .get_strings
= sky2_get_strings
,
3546 .get_coalesce
= sky2_get_coalesce
,
3547 .set_coalesce
= sky2_set_coalesce
,
3548 .get_ringparam
= sky2_get_ringparam
,
3549 .set_ringparam
= sky2_set_ringparam
,
3550 .get_pauseparam
= sky2_get_pauseparam
,
3551 .set_pauseparam
= sky2_set_pauseparam
,
3552 .phys_id
= sky2_phys_id
,
3553 .get_stats_count
= sky2_get_stats_count
,
3554 .get_ethtool_stats
= sky2_get_ethtool_stats
,
3557 #ifdef CONFIG_SKY2_DEBUG
3559 static struct dentry
*sky2_debug
;
3561 static int sky2_debug_show(struct seq_file
*seq
, void *v
)
3563 struct net_device
*dev
= seq
->private;
3564 const struct sky2_port
*sky2
= netdev_priv(dev
);
3565 const struct sky2_hw
*hw
= sky2
->hw
;
3566 unsigned port
= sky2
->port
;
3570 if (!netif_running(dev
))
3573 seq_printf(seq
, "IRQ src=%x mask=%x control=%x\n",
3574 sky2_read32(hw
, B0_ISRC
),
3575 sky2_read32(hw
, B0_IMSK
),
3576 sky2_read32(hw
, B0_Y2_SP_ICR
));
3578 netif_poll_disable(hw
->dev
[0]);
3579 last
= sky2_read16(hw
, STAT_PUT_IDX
);
3581 if (hw
->st_idx
== last
)
3582 seq_puts(seq
, "Status ring (empty)\n");
3584 seq_puts(seq
, "Status ring\n");
3585 for (idx
= hw
->st_idx
; idx
!= last
&& idx
< STATUS_RING_SIZE
;
3586 idx
= RING_NEXT(idx
, STATUS_RING_SIZE
)) {
3587 const struct sky2_status_le
*le
= hw
->st_le
+ idx
;
3588 seq_printf(seq
, "[%d] %#x %d %#x\n",
3589 idx
, le
->opcode
, le
->length
, le
->status
);
3591 seq_puts(seq
, "\n");
3594 seq_printf(seq
, "Tx ring pending=%u...%u report=%d done=%d\n",
3595 sky2
->tx_cons
, sky2
->tx_prod
,
3596 sky2_read16(hw
, port
== 0 ? STAT_TXA1_RIDX
: STAT_TXA2_RIDX
),
3597 sky2_read16(hw
, Q_ADDR(txqaddr
[port
], Q_DONE
)));
3599 /* Dump contents of tx ring */
3601 for (idx
= sky2
->tx_next
; idx
!= sky2
->tx_prod
&& idx
< TX_RING_SIZE
;
3602 idx
= RING_NEXT(idx
, TX_RING_SIZE
)) {
3603 const struct sky2_tx_le
*le
= sky2
->tx_le
+ idx
;
3604 u32 a
= le32_to_cpu(le
->addr
);
3607 seq_printf(seq
, "%u:", idx
);
3610 switch(le
->opcode
& ~HW_OWNER
) {
3612 seq_printf(seq
, " %#x:", a
);
3615 seq_printf(seq
, " mtu=%d", a
);
3618 seq_printf(seq
, " vlan=%d", be16_to_cpu(le
->length
));
3621 seq_printf(seq
, " csum=%#x", a
);
3624 seq_printf(seq
, " tso=%#x(%d)", a
, le16_to_cpu(le
->length
));
3627 seq_printf(seq
, " %#x(%d)", a
, le16_to_cpu(le
->length
));
3630 seq_printf(seq
, " frag=%#x(%d)", a
, le16_to_cpu(le
->length
));
3633 seq_printf(seq
, " op=%#x,%#x(%d)", le
->opcode
,
3634 a
, le16_to_cpu(le
->length
));
3637 if (le
->ctrl
& EOP
) {
3638 seq_putc(seq
, '\n');
3643 seq_printf(seq
, "\nRx ring hw get=%d put=%d last=%d\n",
3644 sky2_read16(hw
, Y2_QADDR(rxqaddr
[port
], PREF_UNIT_GET_IDX
)),
3645 last
= sky2_read16(hw
, Y2_QADDR(rxqaddr
[port
], PREF_UNIT_PUT_IDX
)),
3646 sky2_read16(hw
, Y2_QADDR(rxqaddr
[port
], PREF_UNIT_LAST_IDX
)));
3648 netif_poll_enable(hw
->dev
[0]);
3652 static int sky2_debug_open(struct inode
*inode
, struct file
*file
)
3654 return single_open(file
, sky2_debug_show
, inode
->i_private
);
3657 static const struct file_operations sky2_debug_fops
= {
3658 .owner
= THIS_MODULE
,
3659 .open
= sky2_debug_open
,
3661 .llseek
= seq_lseek
,
3662 .release
= single_release
,
3666 * Use network device events to create/remove/rename
3667 * debugfs file entries
3669 static int sky2_device_event(struct notifier_block
*unused
,
3670 unsigned long event
, void *ptr
)
3672 struct net_device
*dev
= ptr
;
3674 if (dev
->open
== sky2_up
) {
3675 struct sky2_port
*sky2
= netdev_priv(dev
);
3678 case NETDEV_CHANGENAME
:
3679 if (!netif_running(dev
))
3683 case NETDEV_GOING_DOWN
:
3684 if (sky2
->debugfs
) {
3685 printk(KERN_DEBUG PFX
"%s: remove debugfs\n",
3687 debugfs_remove(sky2
->debugfs
);
3688 sky2
->debugfs
= NULL
;
3691 if (event
!= NETDEV_CHANGENAME
)
3693 /* fallthrough for changename */
3697 d
= debugfs_create_file(dev
->name
, S_IRUGO
,
3700 if (d
== NULL
|| IS_ERR(d
))
3701 printk(KERN_INFO PFX
3702 "%s: debugfs create failed\n",
3714 static struct notifier_block sky2_notifier
= {
3715 .notifier_call
= sky2_device_event
,
3719 static __init
void sky2_debug_init(void)
3723 ent
= debugfs_create_dir("sky2", NULL
);
3724 if (!ent
|| IS_ERR(ent
))
3728 register_netdevice_notifier(&sky2_notifier
);
3731 static __exit
void sky2_debug_cleanup(void)
3734 unregister_netdevice_notifier(&sky2_notifier
);
3735 debugfs_remove(sky2_debug
);
3741 #define sky2_debug_init()
3742 #define sky2_debug_cleanup()
3746 /* Initialize network device */
3747 static __devinit
struct net_device
*sky2_init_netdev(struct sky2_hw
*hw
,
3749 int highmem
, int wol
)
3751 struct sky2_port
*sky2
;
3752 struct net_device
*dev
= alloc_etherdev(sizeof(*sky2
));
3755 dev_err(&hw
->pdev
->dev
, "etherdev alloc failed");
3759 SET_MODULE_OWNER(dev
);
3760 SET_NETDEV_DEV(dev
, &hw
->pdev
->dev
);
3761 dev
->irq
= hw
->pdev
->irq
;
3762 dev
->open
= sky2_up
;
3763 dev
->stop
= sky2_down
;
3764 dev
->do_ioctl
= sky2_ioctl
;
3765 dev
->hard_start_xmit
= sky2_xmit_frame
;
3766 dev
->get_stats
= sky2_get_stats
;
3767 dev
->set_multicast_list
= sky2_set_multicast
;
3768 dev
->set_mac_address
= sky2_set_mac_address
;
3769 dev
->change_mtu
= sky2_change_mtu
;
3770 SET_ETHTOOL_OPS(dev
, &sky2_ethtool_ops
);
3771 dev
->tx_timeout
= sky2_tx_timeout
;
3772 dev
->watchdog_timeo
= TX_WATCHDOG
;
3774 dev
->poll
= sky2_poll
;
3775 dev
->weight
= NAPI_WEIGHT
;
3776 #ifdef CONFIG_NET_POLL_CONTROLLER
3777 /* Network console (only works on port 0)
3778 * because netpoll makes assumptions about NAPI
3781 dev
->poll_controller
= sky2_netpoll
;
3784 sky2
= netdev_priv(dev
);
3787 sky2
->msg_enable
= netif_msg_init(debug
, default_msg
);
3789 /* Auto speed and flow control */
3790 sky2
->autoneg
= AUTONEG_ENABLE
;
3791 sky2
->flow_mode
= FC_BOTH
;
3795 sky2
->advertising
= sky2_supported_modes(hw
);
3799 spin_lock_init(&sky2
->phy_lock
);
3800 sky2
->tx_pending
= TX_DEF_PENDING
;
3801 sky2
->rx_pending
= RX_DEF_PENDING
;
3803 hw
->dev
[port
] = dev
;
3807 dev
->features
|= NETIF_F_TSO
| NETIF_F_IP_CSUM
| NETIF_F_SG
;
3809 dev
->features
|= NETIF_F_HIGHDMA
;
3811 #ifdef SKY2_VLAN_TAG_USED
3812 dev
->features
|= NETIF_F_HW_VLAN_TX
| NETIF_F_HW_VLAN_RX
;
3813 dev
->vlan_rx_register
= sky2_vlan_rx_register
;
3816 /* read the mac address */
3817 memcpy_fromio(dev
->dev_addr
, hw
->regs
+ B2_MAC_1
+ port
* 8, ETH_ALEN
);
3818 memcpy(dev
->perm_addr
, dev
->dev_addr
, dev
->addr_len
);
3823 static void __devinit
sky2_show_addr(struct net_device
*dev
)
3825 const struct sky2_port
*sky2
= netdev_priv(dev
);
3827 if (netif_msg_probe(sky2
))
3828 printk(KERN_INFO PFX
"%s: addr %02x:%02x:%02x:%02x:%02x:%02x\n",
3830 dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
3831 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]);
3834 /* Handle software interrupt used during MSI test */
3835 static irqreturn_t __devinit
sky2_test_intr(int irq
, void *dev_id
)
3837 struct sky2_hw
*hw
= dev_id
;
3838 u32 status
= sky2_read32(hw
, B0_Y2_SP_ISRC2
);
3843 if (status
& Y2_IS_IRQ_SW
) {
3845 wake_up(&hw
->msi_wait
);
3846 sky2_write8(hw
, B0_CTST
, CS_CL_SW_IRQ
);
3848 sky2_write32(hw
, B0_Y2_SP_ICR
, 2);
3853 /* Test interrupt path by forcing a a software IRQ */
3854 static int __devinit
sky2_test_msi(struct sky2_hw
*hw
)
3856 struct pci_dev
*pdev
= hw
->pdev
;
3859 init_waitqueue_head (&hw
->msi_wait
);
3861 sky2_write32(hw
, B0_IMSK
, Y2_IS_IRQ_SW
);
3863 err
= request_irq(pdev
->irq
, sky2_test_intr
, 0, DRV_NAME
, hw
);
3865 dev_err(&pdev
->dev
, "cannot assign irq %d\n", pdev
->irq
);
3869 sky2_write8(hw
, B0_CTST
, CS_ST_SW_IRQ
);
3870 sky2_read8(hw
, B0_CTST
);
3872 wait_event_timeout(hw
->msi_wait
, hw
->msi
, HZ
/10);
3875 /* MSI test failed, go back to INTx mode */
3876 dev_info(&pdev
->dev
, "No interrupt generated using MSI, "
3877 "switching to INTx mode.\n");
3880 sky2_write8(hw
, B0_CTST
, CS_CL_SW_IRQ
);
3883 sky2_write32(hw
, B0_IMSK
, 0);
3884 sky2_read32(hw
, B0_IMSK
);
3886 free_irq(pdev
->irq
, hw
);
3891 static int __devinit
pci_wake_enabled(struct pci_dev
*dev
)
3893 int pm
= pci_find_capability(dev
, PCI_CAP_ID_PM
);
3898 if (pci_read_config_word(dev
, pm
+ PCI_PM_CTRL
, &value
))
3900 return value
& PCI_PM_CTRL_PME_ENABLE
;
3903 static int __devinit
sky2_probe(struct pci_dev
*pdev
,
3904 const struct pci_device_id
*ent
)
3906 struct net_device
*dev
;
3908 int err
, using_dac
= 0, wol_default
;
3910 err
= pci_enable_device(pdev
);
3912 dev_err(&pdev
->dev
, "cannot enable PCI device\n");
3916 err
= pci_request_regions(pdev
, DRV_NAME
);
3918 dev_err(&pdev
->dev
, "cannot obtain PCI resources\n");
3919 goto err_out_disable
;
3922 pci_set_master(pdev
);
3924 if (sizeof(dma_addr_t
) > sizeof(u32
) &&
3925 !(err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
))) {
3927 err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
);
3929 dev_err(&pdev
->dev
, "unable to obtain 64 bit DMA "
3930 "for consistent allocations\n");
3931 goto err_out_free_regions
;
3934 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
3936 dev_err(&pdev
->dev
, "no usable DMA configuration\n");
3937 goto err_out_free_regions
;
3941 wol_default
= pci_wake_enabled(pdev
) ? WAKE_MAGIC
: 0;
3944 hw
= kzalloc(sizeof(*hw
), GFP_KERNEL
);
3946 dev_err(&pdev
->dev
, "cannot allocate hardware struct\n");
3947 goto err_out_free_regions
;
3952 hw
->regs
= ioremap_nocache(pci_resource_start(pdev
, 0), 0x4000);
3954 dev_err(&pdev
->dev
, "cannot map device registers\n");
3955 goto err_out_free_hw
;
3959 /* The sk98lin vendor driver uses hardware byte swapping but
3960 * this driver uses software swapping.
3964 reg
= sky2_pci_read32(hw
, PCI_DEV_REG2
);
3965 reg
&= ~PCI_REV_DESC
;
3966 sky2_pci_write32(hw
, PCI_DEV_REG2
, reg
);
3970 /* ring for status responses */
3971 hw
->st_le
= pci_alloc_consistent(hw
->pdev
, STATUS_LE_BYTES
,
3974 goto err_out_iounmap
;
3976 err
= sky2_init(hw
);
3978 goto err_out_iounmap
;
3980 dev_info(&pdev
->dev
, "v%s addr 0x%llx irq %d Yukon-%s (0x%x) rev %d\n",
3981 DRV_VERSION
, (unsigned long long)pci_resource_start(pdev
, 0),
3982 pdev
->irq
, yukon2_name
[hw
->chip_id
- CHIP_ID_YUKON_XL
],
3983 hw
->chip_id
, hw
->chip_rev
);
3987 dev
= sky2_init_netdev(hw
, 0, using_dac
, wol_default
);
3990 goto err_out_free_pci
;
3993 if (!disable_msi
&& pci_enable_msi(pdev
) == 0) {
3994 err
= sky2_test_msi(hw
);
3995 if (err
== -EOPNOTSUPP
)
3996 pci_disable_msi(pdev
);
3998 goto err_out_free_netdev
;
4001 err
= register_netdev(dev
);
4003 dev_err(&pdev
->dev
, "cannot register net device\n");
4004 goto err_out_free_netdev
;
4007 err
= request_irq(pdev
->irq
, sky2_intr
, hw
->msi
? 0 : IRQF_SHARED
,
4010 dev_err(&pdev
->dev
, "cannot assign irq %d\n", pdev
->irq
);
4011 goto err_out_unregister
;
4013 sky2_write32(hw
, B0_IMSK
, Y2_IS_BASE
);
4015 sky2_show_addr(dev
);
4017 if (hw
->ports
> 1) {
4018 struct net_device
*dev1
;
4020 dev1
= sky2_init_netdev(hw
, 1, using_dac
, wol_default
);
4022 dev_warn(&pdev
->dev
, "allocation for second device failed\n");
4023 else if ((err
= register_netdev(dev1
))) {
4024 dev_warn(&pdev
->dev
,
4025 "register of second port failed (%d)\n", err
);
4029 sky2_show_addr(dev1
);
4032 setup_timer(&hw
->watchdog_timer
, sky2_watchdog
, (unsigned long) hw
);
4033 INIT_WORK(&hw
->restart_work
, sky2_restart
);
4035 pci_set_drvdata(pdev
, hw
);
4041 pci_disable_msi(pdev
);
4042 unregister_netdev(dev
);
4043 err_out_free_netdev
:
4046 sky2_write8(hw
, B0_CTST
, CS_RST_SET
);
4047 pci_free_consistent(hw
->pdev
, STATUS_LE_BYTES
, hw
->st_le
, hw
->st_dma
);
4052 err_out_free_regions
:
4053 pci_release_regions(pdev
);
4055 pci_disable_device(pdev
);
4057 pci_set_drvdata(pdev
, NULL
);
4061 static void __devexit
sky2_remove(struct pci_dev
*pdev
)
4063 struct sky2_hw
*hw
= pci_get_drvdata(pdev
);
4064 struct net_device
*dev0
, *dev1
;
4069 del_timer_sync(&hw
->watchdog_timer
);
4071 flush_scheduled_work();
4073 sky2_write32(hw
, B0_IMSK
, 0);
4074 synchronize_irq(hw
->pdev
->irq
);
4079 unregister_netdev(dev1
);
4080 unregister_netdev(dev0
);
4084 sky2_write16(hw
, B0_Y2LED
, LED_STAT_OFF
);
4085 sky2_write8(hw
, B0_CTST
, CS_RST_SET
);
4086 sky2_read8(hw
, B0_CTST
);
4088 free_irq(pdev
->irq
, hw
);
4090 pci_disable_msi(pdev
);
4091 pci_free_consistent(pdev
, STATUS_LE_BYTES
, hw
->st_le
, hw
->st_dma
);
4092 pci_release_regions(pdev
);
4093 pci_disable_device(pdev
);
4101 pci_set_drvdata(pdev
, NULL
);
4105 static int sky2_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4107 struct sky2_hw
*hw
= pci_get_drvdata(pdev
);
4113 netif_poll_disable(hw
->dev
[0]);
4115 for (i
= 0; i
< hw
->ports
; i
++) {
4116 struct net_device
*dev
= hw
->dev
[i
];
4117 struct sky2_port
*sky2
= netdev_priv(dev
);
4119 if (netif_running(dev
))
4123 sky2_wol_init(sky2
);
4128 sky2_write32(hw
, B0_IMSK
, 0);
4131 pci_save_state(pdev
);
4132 pci_enable_wake(pdev
, pci_choose_state(pdev
, state
), wol
);
4133 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
4138 static int sky2_resume(struct pci_dev
*pdev
)
4140 struct sky2_hw
*hw
= pci_get_drvdata(pdev
);
4146 err
= pci_set_power_state(pdev
, PCI_D0
);
4150 err
= pci_restore_state(pdev
);
4154 pci_enable_wake(pdev
, PCI_D0
, 0);
4156 /* Re-enable all clocks */
4157 if (hw
->chip_id
== CHIP_ID_YUKON_EX
|| hw
->chip_id
== CHIP_ID_YUKON_EC_U
)
4158 sky2_pci_write32(hw
, PCI_DEV_REG3
, 0);
4162 sky2_write32(hw
, B0_IMSK
, Y2_IS_BASE
);
4164 for (i
= 0; i
< hw
->ports
; i
++) {
4165 struct net_device
*dev
= hw
->dev
[i
];
4166 if (netif_running(dev
)) {
4169 printk(KERN_ERR PFX
"%s: could not up: %d\n",
4177 netif_poll_enable(hw
->dev
[0]);
4181 dev_err(&pdev
->dev
, "resume failed (%d)\n", err
);
4182 pci_disable_device(pdev
);
4187 static void sky2_shutdown(struct pci_dev
*pdev
)
4189 struct sky2_hw
*hw
= pci_get_drvdata(pdev
);
4195 netif_poll_disable(hw
->dev
[0]);
4197 for (i
= 0; i
< hw
->ports
; i
++) {
4198 struct net_device
*dev
= hw
->dev
[i
];
4199 struct sky2_port
*sky2
= netdev_priv(dev
);
4203 sky2_wol_init(sky2
);
4210 pci_enable_wake(pdev
, PCI_D3hot
, wol
);
4211 pci_enable_wake(pdev
, PCI_D3cold
, wol
);
4213 pci_disable_device(pdev
);
4214 pci_set_power_state(pdev
, PCI_D3hot
);
4218 static struct pci_driver sky2_driver
= {
4220 .id_table
= sky2_id_table
,
4221 .probe
= sky2_probe
,
4222 .remove
= __devexit_p(sky2_remove
),
4224 .suspend
= sky2_suspend
,
4225 .resume
= sky2_resume
,
4227 .shutdown
= sky2_shutdown
,
4230 static int __init
sky2_init_module(void)
4233 return pci_register_driver(&sky2_driver
);
4236 static void __exit
sky2_cleanup_module(void)
4238 pci_unregister_driver(&sky2_driver
);
4239 sky2_debug_cleanup();
4242 module_init(sky2_init_module
);
4243 module_exit(sky2_cleanup_module
);
4245 MODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver");
4246 MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
4247 MODULE_LICENSE("GPL");
4248 MODULE_VERSION(DRV_VERSION
);