blob: ce135b84a54c8640cfe7a48e8513934a9e3a8e4e [file] [log] [blame]
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001/*
2 * New driver for Marvell Yukon 2 chipset.
3 * Based on earlier sk98lin, and skge driver.
4 *
5 * This driver intentionally does not support all the features
6 * of the original driver such as link fail-over and link management because
7 * those should be done at higher levels.
8 *
9 * Copyright (C) 2005 Stephen Hemminger <shemminger@osdl.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Stephen Hemminger793b8832005-09-14 16:06:14 -070018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070019 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070026#include <linux/config.h>
Stephen Hemminger793b8832005-09-14 16:06:14 -070027#include <linux/crc32.h>
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070028#include <linux/kernel.h>
29#include <linux/version.h>
30#include <linux/module.h>
31#include <linux/netdevice.h>
Andrew Mortond0bbccf2005-11-10 15:29:27 -080032#include <linux/dma-mapping.h>
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070033#include <linux/etherdevice.h>
34#include <linux/ethtool.h>
35#include <linux/pci.h>
36#include <linux/ip.h>
37#include <linux/tcp.h>
38#include <linux/in.h>
39#include <linux/delay.h>
Stephen Hemminger91c86df2005-12-09 11:34:57 -080040#include <linux/workqueue.h>
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -070041#include <linux/if_vlan.h>
Stephen Hemmingerd70cd512005-12-09 11:35:09 -080042#include <linux/prefetch.h>
shemminger@osdl.orgef743d32005-11-30 11:45:12 -080043#include <linux/mii.h>
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070044
45#include <asm/irq.h>
46
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -070047#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
48#define SKY2_VLAN_TAG_USED 1
49#endif
50
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070051#include "sky2.h"
52
53#define DRV_NAME "sky2"
Stephen Hemmingerfa8d3542006-01-30 11:38:01 -080054#define DRV_VERSION "0.15"
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070055#define PFX DRV_NAME " "
56
57/*
58 * The Yukon II chipset takes 64 bit command blocks (called list elements)
59 * that are organized into three (receive, transmit, status) different rings
60 * similar to Tigon3. A transmit can require several elements;
61 * a receive requires one (or two if using 64 bit dma).
62 */
63
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070064#define is_ec_a1(hw) \
shemminger@osdl.org21437642005-11-30 11:45:11 -080065 unlikely((hw)->chip_id == CHIP_ID_YUKON_EC && \
66 (hw)->chip_rev == CHIP_REV_YU_EC_A1)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070067
shemminger@osdl.org13210ce2005-11-30 11:45:14 -080068#define RX_LE_SIZE 512
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070069#define RX_LE_BYTES (RX_LE_SIZE*sizeof(struct sky2_rx_le))
shemminger@osdl.orgbea86102005-10-26 12:16:10 -070070#define RX_MAX_PENDING (RX_LE_SIZE/2 - 2)
shemminger@osdl.org13210ce2005-11-30 11:45:14 -080071#define RX_DEF_PENDING RX_MAX_PENDING
Stephen Hemminger82788c72006-01-17 13:43:10 -080072#define RX_SKB_ALIGN 8
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070073
Stephen Hemminger793b8832005-09-14 16:06:14 -070074#define TX_RING_SIZE 512
75#define TX_DEF_PENDING (TX_RING_SIZE - 1)
76#define TX_MIN_PENDING 64
77#define MAX_SKB_TX_LE (4 + 2*MAX_SKB_FRAGS)
78
79#define STATUS_RING_SIZE 2048 /* 2 ports * (TX + 2*RX) */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070080#define STATUS_LE_BYTES (STATUS_RING_SIZE*sizeof(struct sky2_status_le))
81#define ETH_JUMBO_MTU 9000
82#define TX_WATCHDOG (5 * HZ)
83#define NAPI_WEIGHT 64
84#define PHY_RETRIES 1000
85
86static const u32 default_msg =
Stephen Hemminger793b8832005-09-14 16:06:14 -070087 NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK
88 | NETIF_MSG_TIMER | NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR
Stephen Hemminger3be92a72006-01-17 13:43:17 -080089 | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070090
Stephen Hemminger793b8832005-09-14 16:06:14 -070091static int debug = -1; /* defaults above */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070092module_param(debug, int, 0);
93MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
94
Stephen Hemmingerbdb5c582005-12-09 11:34:55 -080095static int copybreak __read_mostly = 256;
96module_param(copybreak, int, 0);
97MODULE_PARM_DESC(copybreak, "Receive copy threshold");
98
Stephen Hemminger4d52b482006-01-30 11:38:00 -080099static int disable_msi = 0;
100module_param(disable_msi, int, 0);
101MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
102
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700103static const struct pci_device_id sky2_id_table[] = {
Stephen Hemminger793b8832005-09-14 16:06:14 -0700104 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9000) },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700105 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) },
106 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b00) },
107 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b01) },
108 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4340) },
109 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4341) },
110 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4342) },
111 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4343) },
112 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4344) },
113 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4345) },
114 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4346) },
115 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4347) },
116 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4350) },
117 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4351) },
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -0800118 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4352) },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700119 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4360) },
120 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4361) },
121 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4362) },
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -0800122 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4363) },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700123 { 0 }
124};
Stephen Hemminger793b8832005-09-14 16:06:14 -0700125
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700126MODULE_DEVICE_TABLE(pci, sky2_id_table);
127
128/* Avoid conditionals by using array */
129static const unsigned txqaddr[] = { Q_XA1, Q_XA2 };
130static const unsigned rxqaddr[] = { Q_R1, Q_R2 };
131
Stephen Hemminger92f965e2005-12-09 11:34:53 -0800132/* This driver supports yukon2 chipset only */
133static const char *yukon2_name[] = {
134 "XL", /* 0xb3 */
135 "EC Ultra", /* 0xb4 */
136 "UNKNOWN", /* 0xb5 */
137 "EC", /* 0xb6 */
138 "FE", /* 0xb7 */
Stephen Hemminger793b8832005-09-14 16:06:14 -0700139};
140
Stephen Hemminger793b8832005-09-14 16:06:14 -0700141/* Access to external PHY */
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800142static int gm_phy_write(struct sky2_hw *hw, unsigned port, u16 reg, u16 val)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700143{
144 int i;
145
146 gma_write16(hw, port, GM_SMI_DATA, val);
147 gma_write16(hw, port, GM_SMI_CTRL,
148 GM_SMI_CT_PHY_AD(PHY_ADDR_MARV) | GM_SMI_CT_REG_AD(reg));
149
150 for (i = 0; i < PHY_RETRIES; i++) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700151 if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY))
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800152 return 0;
Stephen Hemminger793b8832005-09-14 16:06:14 -0700153 udelay(1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700154 }
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800155
Stephen Hemminger793b8832005-09-14 16:06:14 -0700156 printk(KERN_WARNING PFX "%s: phy write timeout\n", hw->dev[port]->name);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800157 return -ETIMEDOUT;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700158}
159
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800160static int __gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg, u16 *val)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700161{
162 int i;
163
Stephen Hemminger793b8832005-09-14 16:06:14 -0700164 gma_write16(hw, port, GM_SMI_CTRL, GM_SMI_CT_PHY_AD(PHY_ADDR_MARV)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700165 | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD);
166
167 for (i = 0; i < PHY_RETRIES; i++) {
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800168 if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL) {
169 *val = gma_read16(hw, port, GM_SMI_DATA);
170 return 0;
171 }
172
Stephen Hemminger793b8832005-09-14 16:06:14 -0700173 udelay(1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700174 }
175
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800176 return -ETIMEDOUT;
177}
178
179static u16 gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg)
180{
181 u16 v;
182
183 if (__gm_phy_read(hw, port, reg, &v) != 0)
184 printk(KERN_WARNING PFX "%s: phy read timeout\n", hw->dev[port]->name);
185 return v;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700186}
187
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700188static int sky2_set_power_state(struct sky2_hw *hw, pci_power_t state)
189{
190 u16 power_control;
191 u32 reg1;
192 int vaux;
193 int ret = 0;
194
195 pr_debug("sky2_set_power_state %d\n", state);
196 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
197
198 pci_read_config_word(hw->pdev, hw->pm_cap + PCI_PM_PMC, &power_control);
Stephen Hemminger08c06d82006-01-30 11:37:54 -0800199 vaux = (sky2_read16(hw, B0_CTST) & Y2_VAUX_AVAIL) &&
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700200 (power_control & PCI_PM_CAP_PME_D3cold);
201
202 pci_read_config_word(hw->pdev, hw->pm_cap + PCI_PM_CTRL, &power_control);
203
204 power_control |= PCI_PM_CTRL_PME_STATUS;
205 power_control &= ~(PCI_PM_CTRL_STATE_MASK);
206
207 switch (state) {
208 case PCI_D0:
209 /* switch power to VCC (WA for VAUX problem) */
210 sky2_write8(hw, B0_POWER_CTRL,
211 PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
212
213 /* disable Core Clock Division, */
214 sky2_write32(hw, B2_Y2_CLK_CTRL, Y2_CLK_DIV_DIS);
215
216 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
217 /* enable bits are inverted */
218 sky2_write8(hw, B2_Y2_CLK_GATE,
219 Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
220 Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
221 Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
222 else
223 sky2_write8(hw, B2_Y2_CLK_GATE, 0);
224
225 /* Turn off phy power saving */
226 pci_read_config_dword(hw->pdev, PCI_DEV_REG1, &reg1);
227 reg1 &= ~(PCI_Y2_PHY1_POWD | PCI_Y2_PHY2_POWD);
228
shemminger@osdl.orgd571b692005-10-26 12:16:09 -0700229 /* looks like this XL is back asswards .. */
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700230 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) {
231 reg1 |= PCI_Y2_PHY1_COMA;
232 if (hw->ports > 1)
233 reg1 |= PCI_Y2_PHY2_COMA;
234 }
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800235
236 if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
237 pci_write_config_dword(hw->pdev, PCI_DEV_REG3, 0);
238 pci_read_config_dword(hw->pdev, PCI_DEV_REG4, &reg1);
239 reg1 &= P_ASPM_CONTROL_MSK;
240 pci_write_config_dword(hw->pdev, PCI_DEV_REG4, reg1);
241 pci_write_config_dword(hw->pdev, PCI_DEV_REG5, 0);
242 }
243
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700244 pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg1);
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800245
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700246 break;
247
248 case PCI_D3hot:
249 case PCI_D3cold:
250 /* Turn on phy power saving */
251 pci_read_config_dword(hw->pdev, PCI_DEV_REG1, &reg1);
252 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
253 reg1 &= ~(PCI_Y2_PHY1_POWD | PCI_Y2_PHY2_POWD);
254 else
255 reg1 |= (PCI_Y2_PHY1_POWD | PCI_Y2_PHY2_POWD);
256 pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg1);
257
258 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
259 sky2_write8(hw, B2_Y2_CLK_GATE, 0);
260 else
261 /* enable bits are inverted */
262 sky2_write8(hw, B2_Y2_CLK_GATE,
263 Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
264 Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
265 Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
266
267 /* switch power to VAUX */
268 if (vaux && state != PCI_D3cold)
269 sky2_write8(hw, B0_POWER_CTRL,
270 (PC_VAUX_ENA | PC_VCC_ENA |
271 PC_VAUX_ON | PC_VCC_OFF));
272 break;
273 default:
274 printk(KERN_ERR PFX "Unknown power state %d\n", state);
275 ret = -1;
276 }
277
278 pci_write_config_byte(hw->pdev, hw->pm_cap + PCI_PM_CTRL, power_control);
279 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
280 return ret;
281}
282
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700283static void sky2_phy_reset(struct sky2_hw *hw, unsigned port)
284{
285 u16 reg;
286
287 /* disable all GMAC IRQ's */
288 sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
289 /* disable PHY IRQs */
290 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700291
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700292 gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */
293 gma_write16(hw, port, GM_MC_ADDR_H2, 0);
294 gma_write16(hw, port, GM_MC_ADDR_H3, 0);
295 gma_write16(hw, port, GM_MC_ADDR_H4, 0);
296
297 reg = gma_read16(hw, port, GM_RX_CTRL);
298 reg |= GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA;
299 gma_write16(hw, port, GM_RX_CTRL, reg);
300}
301
302static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
303{
304 struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700305 u16 ctrl, ct1000, adv, pg, ledctrl, ledover;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700306
Stephen Hemminger793b8832005-09-14 16:06:14 -0700307 if (sky2->autoneg == AUTONEG_ENABLE && hw->chip_id != CHIP_ID_YUKON_XL) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700308 u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
309
310 ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
Stephen Hemminger793b8832005-09-14 16:06:14 -0700311 PHY_M_EC_MAC_S_MSK);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700312 ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ);
313
314 if (hw->chip_id == CHIP_ID_YUKON_EC)
315 ectrl |= PHY_M_EC_DSC_2(2) | PHY_M_EC_DOWN_S_ENA;
316 else
317 ectrl |= PHY_M_EC_M_DSC(2) | PHY_M_EC_S_DSC(3);
318
319 gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl);
320 }
321
322 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
323 if (hw->copper) {
324 if (hw->chip_id == CHIP_ID_YUKON_FE) {
325 /* enable automatic crossover */
326 ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO) >> 1;
327 } else {
328 /* disable energy detect */
329 ctrl &= ~PHY_M_PC_EN_DET_MSK;
330
331 /* enable automatic crossover */
332 ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO);
333
334 if (sky2->autoneg == AUTONEG_ENABLE &&
335 hw->chip_id == CHIP_ID_YUKON_XL) {
336 ctrl &= ~PHY_M_PC_DSC_MSK;
337 ctrl |= PHY_M_PC_DSC(2) | PHY_M_PC_DOWN_S_ENA;
338 }
339 }
340 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
341 } else {
342 /* workaround for deviation #4.88 (CRC errors) */
343 /* disable Automatic Crossover */
344
345 ctrl &= ~PHY_M_PC_MDIX_MSK;
346 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
347
348 if (hw->chip_id == CHIP_ID_YUKON_XL) {
349 /* Fiber: select 1000BASE-X only mode MAC Specific Ctrl Reg. */
350 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2);
351 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
352 ctrl &= ~PHY_M_MAC_MD_MSK;
353 ctrl |= PHY_M_MAC_MODE_SEL(PHY_M_MAC_MD_1000BX);
354 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
355
356 /* select page 1 to access Fiber registers */
357 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 1);
358 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700359 }
360
361 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
362 if (sky2->autoneg == AUTONEG_DISABLE)
363 ctrl &= ~PHY_CT_ANE;
364 else
365 ctrl |= PHY_CT_ANE;
366
367 ctrl |= PHY_CT_RESET;
368 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
369
370 ctrl = 0;
371 ct1000 = 0;
372 adv = PHY_AN_CSMA;
373
374 if (sky2->autoneg == AUTONEG_ENABLE) {
375 if (hw->copper) {
376 if (sky2->advertising & ADVERTISED_1000baseT_Full)
377 ct1000 |= PHY_M_1000C_AFD;
378 if (sky2->advertising & ADVERTISED_1000baseT_Half)
379 ct1000 |= PHY_M_1000C_AHD;
380 if (sky2->advertising & ADVERTISED_100baseT_Full)
381 adv |= PHY_M_AN_100_FD;
382 if (sky2->advertising & ADVERTISED_100baseT_Half)
383 adv |= PHY_M_AN_100_HD;
384 if (sky2->advertising & ADVERTISED_10baseT_Full)
385 adv |= PHY_M_AN_10_FD;
386 if (sky2->advertising & ADVERTISED_10baseT_Half)
387 adv |= PHY_M_AN_10_HD;
Stephen Hemminger793b8832005-09-14 16:06:14 -0700388 } else /* special defines for FIBER (88E1011S only) */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700389 adv |= PHY_M_AN_1000X_AHD | PHY_M_AN_1000X_AFD;
390
391 /* Set Flow-control capabilities */
392 if (sky2->tx_pause && sky2->rx_pause)
Stephen Hemminger793b8832005-09-14 16:06:14 -0700393 adv |= PHY_AN_PAUSE_CAP; /* symmetric */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700394 else if (sky2->rx_pause && !sky2->tx_pause)
Stephen Hemminger793b8832005-09-14 16:06:14 -0700395 adv |= PHY_AN_PAUSE_ASYM | PHY_AN_PAUSE_CAP;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700396 else if (!sky2->rx_pause && sky2->tx_pause)
397 adv |= PHY_AN_PAUSE_ASYM; /* local */
398
399 /* Restart Auto-negotiation */
400 ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG;
401 } else {
402 /* forced speed/duplex settings */
403 ct1000 = PHY_M_1000C_MSE;
404
405 if (sky2->duplex == DUPLEX_FULL)
406 ctrl |= PHY_CT_DUP_MD;
407
408 switch (sky2->speed) {
409 case SPEED_1000:
410 ctrl |= PHY_CT_SP1000;
411 break;
412 case SPEED_100:
413 ctrl |= PHY_CT_SP100;
414 break;
415 }
416
417 ctrl |= PHY_CT_RESET;
418 }
419
420 if (hw->chip_id != CHIP_ID_YUKON_FE)
421 gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000);
422
423 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv);
424 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
425
426 /* Setup Phy LED's */
427 ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS);
428 ledover = 0;
429
430 switch (hw->chip_id) {
431 case CHIP_ID_YUKON_FE:
432 /* on 88E3082 these bits are at 11..9 (shifted left) */
433 ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) << 1;
434
435 ctrl = gm_phy_read(hw, port, PHY_MARV_FE_LED_PAR);
436
437 /* delete ACT LED control bits */
438 ctrl &= ~PHY_M_FELP_LED1_MSK;
439 /* change ACT LED control to blink mode */
440 ctrl |= PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_ACT_BL);
441 gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl);
442 break;
443
444 case CHIP_ID_YUKON_XL:
Stephen Hemminger793b8832005-09-14 16:06:14 -0700445 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700446
447 /* select page 3 to access LED control register */
448 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
449
450 /* set LED Function Control register */
Stephen Hemminger793b8832005-09-14 16:06:14 -0700451 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */
452 PHY_M_LEDC_INIT_CTRL(7) | /* 10 Mbps */
453 PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */
454 PHY_M_LEDC_STA0_CTRL(7))); /* 1000 Mbps */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700455
456 /* set Polarity Control register */
457 gm_phy_write(hw, port, PHY_MARV_PHY_STAT,
Stephen Hemminger793b8832005-09-14 16:06:14 -0700458 (PHY_M_POLC_LS1_P_MIX(4) |
459 PHY_M_POLC_IS0_P_MIX(4) |
460 PHY_M_POLC_LOS_CTRL(2) |
461 PHY_M_POLC_INIT_CTRL(2) |
462 PHY_M_POLC_STA1_CTRL(2) |
463 PHY_M_POLC_STA0_CTRL(2)));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700464
465 /* restore page register */
Stephen Hemminger793b8832005-09-14 16:06:14 -0700466 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700467 break;
468
469 default:
470 /* set Tx LED (LED_TX) to blink mode on Rx OR Tx activity */
471 ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL;
472 /* turn off the Rx LED (LED_RX) */
473 ledover |= PHY_M_LED_MO_RX(MO_LED_OFF);
474 }
475
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800476 if (hw->chip_id == CHIP_ID_YUKON_EC_U && hw->chip_rev >= 2) {
477 /* apply fixes in PHY AFE */
478 gm_phy_write(hw, port, 22, 255);
479 /* increase differential signal amplitude in 10BASE-T */
480 gm_phy_write(hw, port, 24, 0xaa99);
481 gm_phy_write(hw, port, 23, 0x2011);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700482
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800483 /* fix for IEEE A/B Symmetry failure in 1000BASE-T */
484 gm_phy_write(hw, port, 24, 0xa204);
485 gm_phy_write(hw, port, 23, 0x2002);
486
487 /* set page register to 0 */
488 gm_phy_write(hw, port, 22, 0);
489 } else {
490 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl);
491
492 if (sky2->autoneg == AUTONEG_DISABLE || sky2->speed == SPEED_100) {
493 /* turn on 100 Mbps LED (LED_LINK100) */
494 ledover |= PHY_M_LED_MO_100(MO_LED_ON);
495 }
496
497 if (ledover)
498 gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover);
499
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700500 }
shemminger@osdl.orgd571b692005-10-26 12:16:09 -0700501 /* Enable phy interrupt on auto-negotiation complete (or link up) */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700502 if (sky2->autoneg == AUTONEG_ENABLE)
503 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL);
504 else
505 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
506}
507
Stephen Hemminger1b537562005-12-20 15:08:07 -0800508/* Force a renegotiation */
509static void sky2_phy_reinit(struct sky2_port *sky2)
510{
511 down(&sky2->phy_sema);
512 sky2_phy_init(sky2->hw, sky2->port);
513 up(&sky2->phy_sema);
514}
515
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700516static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
517{
518 struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
519 u16 reg;
520 int i;
521 const u8 *addr = hw->dev[port]->dev_addr;
522
shemminger@osdl.org42eeea02005-11-30 11:45:13 -0800523 sky2_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
524 sky2_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR|GPC_ENA_PAUSE);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700525
526 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
527
Stephen Hemminger793b8832005-09-14 16:06:14 -0700528 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0 && port == 1) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700529 /* WA DEV_472 -- looks like crossed wires on port 2 */
530 /* clear GMAC 1 Control reset */
531 sky2_write8(hw, SK_REG(0, GMAC_CTRL), GMC_RST_CLR);
532 do {
533 sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_SET);
534 sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_CLR);
535 } while (gm_phy_read(hw, 1, PHY_MARV_ID0) != PHY_MARV_ID0_VAL ||
536 gm_phy_read(hw, 1, PHY_MARV_ID1) != PHY_MARV_ID1_Y2 ||
537 gm_phy_read(hw, 1, PHY_MARV_INT_MASK) != 0);
538 }
539
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700540 if (sky2->autoneg == AUTONEG_DISABLE) {
541 reg = gma_read16(hw, port, GM_GP_CTRL);
542 reg |= GM_GPCR_AU_ALL_DIS;
543 gma_write16(hw, port, GM_GP_CTRL, reg);
544 gma_read16(hw, port, GM_GP_CTRL);
545
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700546 switch (sky2->speed) {
547 case SPEED_1000:
Stephen Hemminger6f4c56b2006-02-10 15:58:59 -0800548 reg &= ~GM_GPCR_SPEED_100;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700549 reg |= GM_GPCR_SPEED_1000;
Stephen Hemminger6f4c56b2006-02-10 15:58:59 -0800550 break;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700551 case SPEED_100:
Stephen Hemminger6f4c56b2006-02-10 15:58:59 -0800552 reg &= ~GM_GPCR_SPEED_1000;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700553 reg |= GM_GPCR_SPEED_100;
Stephen Hemminger6f4c56b2006-02-10 15:58:59 -0800554 break;
555 case SPEED_10:
556 reg &= ~(GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100);
557 break;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700558 }
559
560 if (sky2->duplex == DUPLEX_FULL)
561 reg |= GM_GPCR_DUP_FULL;
562 } else
563 reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL;
564
565 if (!sky2->tx_pause && !sky2->rx_pause) {
566 sky2_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700567 reg |=
568 GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
569 } else if (sky2->tx_pause && !sky2->rx_pause) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700570 /* disable Rx flow-control */
571 reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
572 }
573
574 gma_write16(hw, port, GM_GP_CTRL, reg);
575
Stephen Hemminger793b8832005-09-14 16:06:14 -0700576 sky2_read16(hw, SK_REG(port, GMAC_IRQ_SRC));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700577
Stephen Hemminger91c86df2005-12-09 11:34:57 -0800578 down(&sky2->phy_sema);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700579 sky2_phy_init(hw, port);
Stephen Hemminger91c86df2005-12-09 11:34:57 -0800580 up(&sky2->phy_sema);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700581
582 /* MIB clear */
583 reg = gma_read16(hw, port, GM_PHY_ADDR);
584 gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR);
585
586 for (i = 0; i < GM_MIB_CNT_SIZE; i++)
Stephen Hemminger793b8832005-09-14 16:06:14 -0700587 gma_read16(hw, port, GM_MIB_CNT_BASE + 8 * i);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700588 gma_write16(hw, port, GM_PHY_ADDR, reg);
589
590 /* transmit control */
591 gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF));
592
593 /* receive control reg: unicast + multicast + no FCS */
594 gma_write16(hw, port, GM_RX_CTRL,
Stephen Hemminger793b8832005-09-14 16:06:14 -0700595 GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700596
597 /* transmit flow control */
598 gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff);
599
600 /* transmit parameter */
601 gma_write16(hw, port, GM_TX_PARAM,
602 TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) |
603 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) |
604 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF) |
605 TX_BACK_OFF_LIM(TX_BOF_LIM_DEF));
606
607 /* serial mode register */
608 reg = DATA_BLIND_VAL(DATA_BLIND_DEF) |
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -0700609 GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700610
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -0700611 if (hw->dev[port]->mtu > ETH_DATA_LEN)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700612 reg |= GM_SMOD_JUMBO_ENA;
613
614 gma_write16(hw, port, GM_SERIAL_MODE, reg);
615
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700616 /* virtual address for data */
617 gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr);
618
Stephen Hemminger793b8832005-09-14 16:06:14 -0700619 /* physical address: used for pause frames */
620 gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr);
621
622 /* ignore counter overflows */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700623 gma_write16(hw, port, GM_TX_IRQ_MSK, 0);
624 gma_write16(hw, port, GM_RX_IRQ_MSK, 0);
625 gma_write16(hw, port, GM_TR_IRQ_MSK, 0);
626
627 /* Configure Rx MAC FIFO */
628 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700629 sky2_write16(hw, SK_REG(port, RX_GMF_CTRL_T),
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -0700630 GMF_RX_CTRL_DEF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700631
shemminger@osdl.orgd571b692005-10-26 12:16:09 -0700632 /* Flush Rx MAC FIFO on any flow control or error */
shemminger@osdl.org42eeea02005-11-30 11:45:13 -0800633 sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700634
Stephen Hemminger793b8832005-09-14 16:06:14 -0700635 /* Set threshold to 0xa (64 bytes)
636 * ASF disabled so no need to do WA dev #4.30
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700637 */
638 sky2_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF);
639
640 /* Configure Tx MAC FIFO */
641 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
642 sky2_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -0800643
644 if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
645 sky2_write8(hw, SK_REG(port, RX_GMF_LP_THR), 768/8);
646 sky2_write8(hw, SK_REG(port, RX_GMF_UP_THR), 1024/8);
647 if (hw->dev[port]->mtu > ETH_DATA_LEN) {
648 /* set Tx GMAC FIFO Almost Empty Threshold */
649 sky2_write32(hw, SK_REG(port, TX_GMF_AE_THR), 0x180);
650 /* Disable Store & Forward mode for TX */
651 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_DIS);
652 }
653 }
654
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700655}
656
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -0800657/* Assign Ram Buffer allocation.
658 * start and end are in units of 4k bytes
659 * ram registers are in units of 64bit words
660 */
661static void sky2_ramset(struct sky2_hw *hw, u16 q, u8 startk, u8 endk)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700662{
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -0800663 u32 start, end;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700664
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -0800665 start = startk * 4096/8;
666 end = (endk * 4096/8) - 1;
Stephen Hemminger793b8832005-09-14 16:06:14 -0700667
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700668 sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR);
669 sky2_write32(hw, RB_ADDR(q, RB_START), start);
670 sky2_write32(hw, RB_ADDR(q, RB_END), end);
671 sky2_write32(hw, RB_ADDR(q, RB_WP), start);
672 sky2_write32(hw, RB_ADDR(q, RB_RP), start);
673
674 if (q == Q_R1 || q == Q_R2) {
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -0800675 u32 space = (endk - startk) * 4096/8;
676 u32 tp = space - space/4;
Stephen Hemminger793b8832005-09-14 16:06:14 -0700677
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -0800678 /* On receive queue's set the thresholds
679 * give receiver priority when > 3/4 full
680 * send pause when down to 2K
681 */
682 sky2_write32(hw, RB_ADDR(q, RB_RX_UTHP), tp);
683 sky2_write32(hw, RB_ADDR(q, RB_RX_LTHP), space/2);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700684
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -0800685 tp = space - 2048/8;
686 sky2_write32(hw, RB_ADDR(q, RB_RX_UTPP), tp);
687 sky2_write32(hw, RB_ADDR(q, RB_RX_LTPP), space/4);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700688 } else {
689 /* Enable store & forward on Tx queue's because
690 * Tx FIFO is only 1K on Yukon
691 */
692 sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD);
693 }
694
695 sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700696 sky2_read8(hw, RB_ADDR(q, RB_CTRL));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700697}
698
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700699/* Setup Bus Memory Interface */
shemminger@osdl.orgaf4ed7e2005-11-30 11:45:21 -0800700static void sky2_qset(struct sky2_hw *hw, u16 q)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700701{
702 sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_RESET);
703 sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_OPER_INIT);
704 sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_FIFO_OP_ON);
shemminger@osdl.orgaf4ed7e2005-11-30 11:45:21 -0800705 sky2_write32(hw, Q_ADDR(q, Q_WM), BMU_WM_DEFAULT);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700706}
707
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700708/* Setup prefetch unit registers. This is the interface between
709 * hardware and driver list elements
710 */
Stephen Hemminger8cc048e2005-12-09 11:35:07 -0800711static void sky2_prefetch_init(struct sky2_hw *hw, u32 qaddr,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700712 u64 addr, u32 last)
713{
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700714 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
715 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_CLR);
716 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_HI), addr >> 32);
717 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_LO), (u32) addr);
718 sky2_write16(hw, Y2_QADDR(qaddr, PREF_UNIT_LAST_IDX), last);
719 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_OP_ON);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700720
721 sky2_read32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700722}
723
Stephen Hemminger793b8832005-09-14 16:06:14 -0700724static inline struct sky2_tx_le *get_tx_le(struct sky2_port *sky2)
725{
726 struct sky2_tx_le *le = sky2->tx_le + sky2->tx_prod;
727
728 sky2->tx_prod = (sky2->tx_prod + 1) % TX_RING_SIZE;
729 return le;
730}
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700731
732/*
shemminger@osdl.orgd571b692005-10-26 12:16:09 -0700733 * This is a workaround code taken from SysKonnect sk98lin driver
Stephen Hemminger793b8832005-09-14 16:06:14 -0700734 * to deal with chip bug on Yukon EC rev 0 in the wraparound case.
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700735 */
Stephen Hemminger28bd1812006-01-17 13:43:19 -0800736static void sky2_put_idx(struct sky2_hw *hw, unsigned q,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700737 u16 idx, u16 *last, u16 size)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700738{
Stephen Hemminger762c2de2006-01-17 13:43:14 -0800739 wmb();
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700740 if (is_ec_a1(hw) && idx < *last) {
741 u16 hwget = sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_GET_IDX));
742
743 if (hwget == 0) {
744 /* Start prefetching again */
Stephen Hemminger793b8832005-09-14 16:06:14 -0700745 sky2_write8(hw, Y2_QADDR(q, PREF_UNIT_FIFO_WM), 0xe0);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700746 goto setnew;
747 }
748
Stephen Hemminger793b8832005-09-14 16:06:14 -0700749 if (hwget == size - 1) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700750 /* set watermark to one list element */
751 sky2_write8(hw, Y2_QADDR(q, PREF_UNIT_FIFO_WM), 8);
752
753 /* set put index to first list element */
754 sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), 0);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700755 } else /* have hardware go to end of list */
756 sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX),
757 size - 1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700758 } else {
Stephen Hemminger793b8832005-09-14 16:06:14 -0700759setnew:
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700760 sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), idx);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700761 }
shemminger@osdl.orgbea86102005-10-26 12:16:10 -0700762 *last = idx;
Stephen Hemminger762c2de2006-01-17 13:43:14 -0800763 mmiowb();
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700764}
765
Stephen Hemminger793b8832005-09-14 16:06:14 -0700766
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700767static inline struct sky2_rx_le *sky2_next_rx(struct sky2_port *sky2)
768{
769 struct sky2_rx_le *le = sky2->rx_le + sky2->rx_put;
770 sky2->rx_put = (sky2->rx_put + 1) % RX_LE_SIZE;
771 return le;
772}
773
shemminger@osdl.orga018e332005-11-30 11:45:16 -0800774/* Return high part of DMA address (could be 32 or 64 bit) */
775static inline u32 high32(dma_addr_t a)
776{
Stephen Hemmingera0361192006-01-17 13:43:16 -0800777 return sizeof(a) > sizeof(u32) ? (a >> 16) >> 16 : 0;
shemminger@osdl.orga018e332005-11-30 11:45:16 -0800778}
779
Stephen Hemminger793b8832005-09-14 16:06:14 -0700780/* Build description to hardware about buffer */
Stephen Hemminger28bd1812006-01-17 13:43:19 -0800781static void sky2_rx_add(struct sky2_port *sky2, dma_addr_t map)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700782{
783 struct sky2_rx_le *le;
Stephen Hemminger734d1862005-12-09 11:35:00 -0800784 u32 hi = high32(map);
785 u16 len = sky2->rx_bufsize;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700786
Stephen Hemminger793b8832005-09-14 16:06:14 -0700787 if (sky2->rx_addr64 != hi) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700788 le = sky2_next_rx(sky2);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700789 le->addr = cpu_to_le32(hi);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700790 le->ctrl = 0;
791 le->opcode = OP_ADDR64 | HW_OWNER;
Stephen Hemminger734d1862005-12-09 11:35:00 -0800792 sky2->rx_addr64 = high32(map + len);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700793 }
Stephen Hemminger793b8832005-09-14 16:06:14 -0700794
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700795 le = sky2_next_rx(sky2);
Stephen Hemminger734d1862005-12-09 11:35:00 -0800796 le->addr = cpu_to_le32((u32) map);
797 le->length = cpu_to_le16(len);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700798 le->ctrl = 0;
799 le->opcode = OP_PACKET | HW_OWNER;
800}
801
Stephen Hemminger793b8832005-09-14 16:06:14 -0700802
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700803/* Tell chip where to start receive checksum.
804 * Actually has two checksums, but set both same to avoid possible byte
805 * order problems.
806 */
Stephen Hemminger793b8832005-09-14 16:06:14 -0700807static void rx_set_checksum(struct sky2_port *sky2)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700808{
809 struct sky2_rx_le *le;
810
Stephen Hemminger793b8832005-09-14 16:06:14 -0700811 le = sky2_next_rx(sky2);
812 le->addr = (ETH_HLEN << 16) | ETH_HLEN;
813 le->ctrl = 0;
814 le->opcode = OP_TCPSTART | HW_OWNER;
815
Stephen Hemminger793b8832005-09-14 16:06:14 -0700816 sky2_write32(sky2->hw,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700817 Q_ADDR(rxqaddr[sky2->port], Q_CSR),
818 sky2->rx_csum ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM);
819
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700820}
821
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -0700822/*
823 * The RX Stop command will not work for Yukon-2 if the BMU does not
824 * reach the end of packet and since we can't make sure that we have
825 * incoming data, we must reset the BMU while it is not doing a DMA
826 * transfer. Since it is possible that the RX path is still active,
827 * the RX RAM buffer will be stopped first, so any possible incoming
828 * data will not trigger a DMA. After the RAM buffer is stopped, the
829 * BMU is polled until any DMA in progress is ended and only then it
830 * will be reset.
831 */
832static void sky2_rx_stop(struct sky2_port *sky2)
833{
834 struct sky2_hw *hw = sky2->hw;
835 unsigned rxq = rxqaddr[sky2->port];
836 int i;
837
838 /* disable the RAM Buffer receive queue */
839 sky2_write8(hw, RB_ADDR(rxq, RB_CTRL), RB_DIS_OP_MD);
840
841 for (i = 0; i < 0xffff; i++)
842 if (sky2_read8(hw, RB_ADDR(rxq, Q_RSL))
843 == sky2_read8(hw, RB_ADDR(rxq, Q_RL)))
844 goto stopped;
845
846 printk(KERN_WARNING PFX "%s: receiver stop failed\n",
847 sky2->netdev->name);
848stopped:
849 sky2_write32(hw, Q_ADDR(rxq, Q_CSR), BMU_RST_SET | BMU_FIFO_RST);
850
851 /* reset the Rx prefetch unit */
852 sky2_write32(hw, Y2_QADDR(rxq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
853}
Stephen Hemminger793b8832005-09-14 16:06:14 -0700854
shemminger@osdl.orgd571b692005-10-26 12:16:09 -0700855/* Clean out receive buffer area, assumes receiver hardware stopped */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700856static void sky2_rx_clean(struct sky2_port *sky2)
857{
858 unsigned i;
859
860 memset(sky2->rx_le, 0, RX_LE_BYTES);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700861 for (i = 0; i < sky2->rx_pending; i++) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700862 struct ring_info *re = sky2->rx_ring + i;
863
864 if (re->skb) {
Stephen Hemminger793b8832005-09-14 16:06:14 -0700865 pci_unmap_single(sky2->hw->pdev,
Stephen Hemminger734d1862005-12-09 11:35:00 -0800866 re->mapaddr, sky2->rx_bufsize,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700867 PCI_DMA_FROMDEVICE);
868 kfree_skb(re->skb);
869 re->skb = NULL;
870 }
871 }
872}
873
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800874/* Basic MII support */
875static int sky2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
876{
877 struct mii_ioctl_data *data = if_mii(ifr);
878 struct sky2_port *sky2 = netdev_priv(dev);
879 struct sky2_hw *hw = sky2->hw;
880 int err = -EOPNOTSUPP;
881
882 if (!netif_running(dev))
883 return -ENODEV; /* Phy still in reset */
884
885 switch(cmd) {
886 case SIOCGMIIPHY:
887 data->phy_id = PHY_ADDR_MARV;
888
889 /* fallthru */
890 case SIOCGMIIREG: {
891 u16 val = 0;
Stephen Hemminger91c86df2005-12-09 11:34:57 -0800892
893 down(&sky2->phy_sema);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800894 err = __gm_phy_read(hw, sky2->port, data->reg_num & 0x1f, &val);
Stephen Hemminger91c86df2005-12-09 11:34:57 -0800895 up(&sky2->phy_sema);
896
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800897 data->val_out = val;
898 break;
899 }
900
901 case SIOCSMIIREG:
902 if (!capable(CAP_NET_ADMIN))
903 return -EPERM;
904
Stephen Hemminger91c86df2005-12-09 11:34:57 -0800905 down(&sky2->phy_sema);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800906 err = gm_phy_write(hw, sky2->port, data->reg_num & 0x1f,
907 data->val_in);
Stephen Hemminger91c86df2005-12-09 11:34:57 -0800908 up(&sky2->phy_sema);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800909 break;
910 }
911 return err;
912}
913
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -0700914#ifdef SKY2_VLAN_TAG_USED
915static void sky2_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
916{
917 struct sky2_port *sky2 = netdev_priv(dev);
918 struct sky2_hw *hw = sky2->hw;
919 u16 port = sky2->port;
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -0700920
Stephen Hemminger302d1252006-01-17 13:43:20 -0800921 spin_lock_bh(&sky2->tx_lock);
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -0700922
923 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), RX_VLAN_STRIP_ON);
924 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_VLAN_TAG_ON);
925 sky2->vlgrp = grp;
926
Stephen Hemminger302d1252006-01-17 13:43:20 -0800927 spin_unlock_bh(&sky2->tx_lock);
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -0700928}
929
930static void sky2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
931{
932 struct sky2_port *sky2 = netdev_priv(dev);
933 struct sky2_hw *hw = sky2->hw;
934 u16 port = sky2->port;
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -0700935
Stephen Hemminger302d1252006-01-17 13:43:20 -0800936 spin_lock_bh(&sky2->tx_lock);
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -0700937
938 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), RX_VLAN_STRIP_OFF);
939 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_VLAN_TAG_OFF);
940 if (sky2->vlgrp)
941 sky2->vlgrp->vlan_devices[vid] = NULL;
942
Stephen Hemminger302d1252006-01-17 13:43:20 -0800943 spin_unlock_bh(&sky2->tx_lock);
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -0700944}
945#endif
946
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700947/*
Stephen Hemminger82788c72006-01-17 13:43:10 -0800948 * It appears the hardware has a bug in the FIFO logic that
949 * cause it to hang if the FIFO gets overrun and the receive buffer
950 * is not aligned. ALso alloc_skb() won't align properly if slab
951 * debugging is enabled.
952 */
953static inline struct sk_buff *sky2_alloc_skb(unsigned int size, gfp_t gfp_mask)
954{
955 struct sk_buff *skb;
956
957 skb = alloc_skb(size + RX_SKB_ALIGN, gfp_mask);
958 if (likely(skb)) {
959 unsigned long p = (unsigned long) skb->data;
960 skb_reserve(skb,
961 ((p + RX_SKB_ALIGN - 1) & ~(RX_SKB_ALIGN - 1)) - p);
962 }
963
964 return skb;
965}
966
967/*
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700968 * Allocate and setup receiver buffer pool.
969 * In case of 64 bit dma, there are 2X as many list elements
970 * available as ring entries
971 * and need to reserve one list element so we don't wrap around.
972 */
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -0700973static int sky2_rx_start(struct sky2_port *sky2)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700974{
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -0700975 struct sky2_hw *hw = sky2->hw;
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -0700976 unsigned rxq = rxqaddr[sky2->port];
977 int i;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700978
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -0700979 sky2->rx_put = sky2->rx_next = 0;
shemminger@osdl.orgaf4ed7e2005-11-30 11:45:21 -0800980 sky2_qset(hw, rxq);
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800981
982 if (hw->chip_id == CHIP_ID_YUKON_EC_U && hw->chip_rev >= 2) {
983 /* MAC Rx RAM Read is controlled by hardware */
984 sky2_write32(hw, Q_ADDR(rxq, Q_F), F_M_RX_RAM_DIS);
985 }
986
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -0700987 sky2_prefetch_init(hw, rxq, sky2->rx_le_map, RX_LE_SIZE - 1);
988
989 rx_set_checksum(sky2);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700990 for (i = 0; i < sky2->rx_pending; i++) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700991 struct ring_info *re = sky2->rx_ring + i;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700992
Stephen Hemminger82788c72006-01-17 13:43:10 -0800993 re->skb = sky2_alloc_skb(sky2->rx_bufsize, GFP_KERNEL);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700994 if (!re->skb)
995 goto nomem;
996
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -0700997 re->mapaddr = pci_map_single(hw->pdev, re->skb->data,
Stephen Hemminger734d1862005-12-09 11:35:00 -0800998 sky2->rx_bufsize, PCI_DMA_FROMDEVICE);
999 sky2_rx_add(sky2, re->mapaddr);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001000 }
1001
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001002 /* Tell chip about available buffers */
1003 sky2_write16(hw, Y2_QADDR(rxq, PREF_UNIT_PUT_IDX), sky2->rx_put);
1004 sky2->rx_last_put = sky2_read16(hw, Y2_QADDR(rxq, PREF_UNIT_PUT_IDX));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001005 return 0;
1006nomem:
1007 sky2_rx_clean(sky2);
1008 return -ENOMEM;
1009}
1010
1011/* Bring up network interface. */
1012static int sky2_up(struct net_device *dev)
1013{
1014 struct sky2_port *sky2 = netdev_priv(dev);
1015 struct sky2_hw *hw = sky2->hw;
1016 unsigned port = sky2->port;
1017 u32 ramsize, rxspace;
1018 int err = -ENOMEM;
1019
1020 if (netif_msg_ifup(sky2))
1021 printk(KERN_INFO PFX "%s: enabling interface\n", dev->name);
1022
1023 /* must be power of 2 */
1024 sky2->tx_le = pci_alloc_consistent(hw->pdev,
Stephen Hemminger793b8832005-09-14 16:06:14 -07001025 TX_RING_SIZE *
1026 sizeof(struct sky2_tx_le),
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001027 &sky2->tx_le_map);
1028 if (!sky2->tx_le)
1029 goto err_out;
1030
Stephen Hemminger6cdbbdf2005-12-09 11:35:01 -08001031 sky2->tx_ring = kcalloc(TX_RING_SIZE, sizeof(struct tx_ring_info),
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001032 GFP_KERNEL);
1033 if (!sky2->tx_ring)
1034 goto err_out;
1035 sky2->tx_prod = sky2->tx_cons = 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001036
1037 sky2->rx_le = pci_alloc_consistent(hw->pdev, RX_LE_BYTES,
1038 &sky2->rx_le_map);
1039 if (!sky2->rx_le)
1040 goto err_out;
1041 memset(sky2->rx_le, 0, RX_LE_BYTES);
1042
Stephen Hemminger6cdbbdf2005-12-09 11:35:01 -08001043 sky2->rx_ring = kcalloc(sky2->rx_pending, sizeof(struct ring_info),
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001044 GFP_KERNEL);
1045 if (!sky2->rx_ring)
1046 goto err_out;
1047
1048 sky2_mac_init(hw, port);
1049
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -08001050 /* Determine available ram buffer space (in 4K blocks).
1051 * Note: not sure about the FE setting below yet
1052 */
1053 if (hw->chip_id == CHIP_ID_YUKON_FE)
1054 ramsize = 4;
1055 else
1056 ramsize = sky2_read8(hw, B2_E_0);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001057
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -08001058 /* Give transmitter one third (rounded up) */
1059 rxspace = ramsize - (ramsize + 2) / 3;
1060
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001061 sky2_ramset(hw, rxqaddr[port], 0, rxspace);
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -08001062 sky2_ramset(hw, txqaddr[port], rxspace, ramsize);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001063
Stephen Hemminger793b8832005-09-14 16:06:14 -07001064 /* Make sure SyncQ is disabled */
1065 sky2_write8(hw, RB_ADDR(port == 0 ? Q_XS1 : Q_XS2, RB_CTRL),
1066 RB_RST_SET);
1067
shemminger@osdl.orgaf4ed7e2005-11-30 11:45:21 -08001068 sky2_qset(hw, txqaddr[port]);
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -08001069
Stephen Hemminger977bdf02006-02-22 11:44:58 -08001070 /* Set almost empty threshold */
1071 if (hw->chip_id == CHIP_ID_YUKON_EC_U && hw->chip_rev == 1)
1072 sky2_write16(hw, Q_ADDR(txqaddr[port], Q_AL), 0x1a0);
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -08001073
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001074 sky2_prefetch_init(hw, txqaddr[port], sky2->tx_le_map,
1075 TX_RING_SIZE - 1);
1076
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001077 err = sky2_rx_start(sky2);
1078 if (err)
1079 goto err_out;
1080
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001081 /* Enable interrupts from phy/mac for port */
1082 hw->intr_mask |= (port == 0) ? Y2_IS_PORT_1 : Y2_IS_PORT_2;
1083 sky2_write32(hw, B0_IMSK, hw->intr_mask);
1084 return 0;
1085
1086err_out:
Stephen Hemminger1b537562005-12-20 15:08:07 -08001087 if (sky2->rx_le) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001088 pci_free_consistent(hw->pdev, RX_LE_BYTES,
1089 sky2->rx_le, sky2->rx_le_map);
Stephen Hemminger1b537562005-12-20 15:08:07 -08001090 sky2->rx_le = NULL;
1091 }
1092 if (sky2->tx_le) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001093 pci_free_consistent(hw->pdev,
1094 TX_RING_SIZE * sizeof(struct sky2_tx_le),
1095 sky2->tx_le, sky2->tx_le_map);
Stephen Hemminger1b537562005-12-20 15:08:07 -08001096 sky2->tx_le = NULL;
1097 }
1098 kfree(sky2->tx_ring);
1099 kfree(sky2->rx_ring);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001100
Stephen Hemminger1b537562005-12-20 15:08:07 -08001101 sky2->tx_ring = NULL;
1102 sky2->rx_ring = NULL;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001103 return err;
1104}
1105
Stephen Hemminger793b8832005-09-14 16:06:14 -07001106/* Modular subtraction in ring */
1107static inline int tx_dist(unsigned tail, unsigned head)
1108{
Stephen Hemminger129372d2005-12-09 11:34:59 -08001109 return (head - tail) % TX_RING_SIZE;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001110}
1111
1112/* Number of list elements available for next tx */
1113static inline int tx_avail(const struct sky2_port *sky2)
1114{
1115 return sky2->tx_pending - tx_dist(sky2->tx_cons, sky2->tx_prod);
1116}
1117
1118/* Estimate of number of transmit list elements required */
Stephen Hemminger28bd1812006-01-17 13:43:19 -08001119static unsigned tx_le_req(const struct sk_buff *skb)
Stephen Hemminger793b8832005-09-14 16:06:14 -07001120{
1121 unsigned count;
1122
1123 count = sizeof(dma_addr_t) / sizeof(u32);
1124 count += skb_shinfo(skb)->nr_frags * count;
1125
1126 if (skb_shinfo(skb)->tso_size)
1127 ++count;
1128
Stephen Hemminger0e3ff6a2005-12-09 11:35:02 -08001129 if (skb->ip_summed == CHECKSUM_HW)
Stephen Hemminger793b8832005-09-14 16:06:14 -07001130 ++count;
1131
1132 return count;
1133}
1134
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001135/*
Stephen Hemminger793b8832005-09-14 16:06:14 -07001136 * Put one packet in ring for transmit.
1137 * A single packet can generate multiple list elements, and
1138 * the number of ring elements will probably be less than the number
1139 * of list elements used.
Stephen Hemmingerf2e46562005-12-09 11:34:58 -08001140 *
1141 * No BH disabling for tx_lock here (like tg3)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001142 */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001143static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
1144{
1145 struct sky2_port *sky2 = netdev_priv(dev);
1146 struct sky2_hw *hw = sky2->hw;
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001147 struct sky2_tx_le *le = NULL;
Stephen Hemminger6cdbbdf2005-12-09 11:35:01 -08001148 struct tx_ring_info *re;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001149 unsigned i, len;
1150 dma_addr_t mapping;
1151 u32 addr64;
1152 u16 mss;
1153 u8 ctrl;
1154
Stephen Hemminger302d1252006-01-17 13:43:20 -08001155 /* No BH disabling for tx_lock here. We are running in BH disabled
1156 * context and TX reclaim runs via poll inside of a software
1157 * interrupt, and no related locks in IRQ processing.
1158 */
Stephen Hemmingerf2e46562005-12-09 11:34:58 -08001159 if (!spin_trylock(&sky2->tx_lock))
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001160 return NETDEV_TX_LOCKED;
1161
Stephen Hemminger793b8832005-09-14 16:06:14 -07001162 if (unlikely(tx_avail(sky2) < tx_le_req(skb))) {
Stephen Hemminger8c463ef2005-12-09 11:35:08 -08001163 /* There is a known but harmless race with lockless tx
1164 * and netif_stop_queue.
1165 */
1166 if (!netif_queue_stopped(dev)) {
1167 netif_stop_queue(dev);
Stephen Hemminger3be92a72006-01-17 13:43:17 -08001168 if (net_ratelimit())
1169 printk(KERN_WARNING PFX "%s: ring full when queue awake!\n",
1170 dev->name);
Stephen Hemminger8c463ef2005-12-09 11:35:08 -08001171 }
Stephen Hemmingerf2e46562005-12-09 11:34:58 -08001172 spin_unlock(&sky2->tx_lock);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001173
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001174 return NETDEV_TX_BUSY;
1175 }
1176
Stephen Hemminger793b8832005-09-14 16:06:14 -07001177 if (unlikely(netif_msg_tx_queued(sky2)))
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001178 printk(KERN_DEBUG "%s: tx queued, slot %u, len %d\n",
1179 dev->name, sky2->tx_prod, skb->len);
1180
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001181 len = skb_headlen(skb);
1182 mapping = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE);
shemminger@osdl.orga018e332005-11-30 11:45:16 -08001183 addr64 = high32(mapping);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001184
1185 re = sky2->tx_ring + sky2->tx_prod;
1186
shemminger@osdl.orga018e332005-11-30 11:45:16 -08001187 /* Send high bits if changed or crosses boundary */
1188 if (addr64 != sky2->tx_addr64 || high32(mapping + len) != sky2->tx_addr64) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07001189 le = get_tx_le(sky2);
1190 le->tx.addr = cpu_to_le32(addr64);
1191 le->ctrl = 0;
1192 le->opcode = OP_ADDR64 | HW_OWNER;
shemminger@osdl.orga018e332005-11-30 11:45:16 -08001193 sky2->tx_addr64 = high32(mapping + len);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001194 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001195
1196 /* Check for TCP Segmentation Offload */
1197 mss = skb_shinfo(skb)->tso_size;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001198 if (mss != 0) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001199 /* just drop the packet if non-linear expansion fails */
1200 if (skb_header_cloned(skb) &&
1201 pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07001202 dev_kfree_skb_any(skb);
1203 goto out_unlock;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001204 }
1205
1206 mss += ((skb->h.th->doff - 5) * 4); /* TCP options */
1207 mss += (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr);
1208 mss += ETH_HLEN;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001209 }
1210
Stephen Hemminger793b8832005-09-14 16:06:14 -07001211 if (mss != sky2->tx_last_mss) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001212 le = get_tx_le(sky2);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001213 le->tx.tso.size = cpu_to_le16(mss);
1214 le->tx.tso.rsvd = 0;
1215 le->opcode = OP_LRGLEN | HW_OWNER;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001216 le->ctrl = 0;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001217 sky2->tx_last_mss = mss;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001218 }
1219
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001220 ctrl = 0;
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001221#ifdef SKY2_VLAN_TAG_USED
1222 /* Add VLAN tag, can piggyback on LRGLEN or ADDR64 */
1223 if (sky2->vlgrp && vlan_tx_tag_present(skb)) {
1224 if (!le) {
1225 le = get_tx_le(sky2);
1226 le->tx.addr = 0;
1227 le->opcode = OP_VLAN|HW_OWNER;
1228 le->ctrl = 0;
1229 } else
1230 le->opcode |= OP_VLAN;
1231 le->length = cpu_to_be16(vlan_tx_tag_get(skb));
1232 ctrl |= INS_VLAN;
1233 }
1234#endif
1235
1236 /* Handle TCP checksum offload */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001237 if (skb->ip_summed == CHECKSUM_HW) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07001238 u16 hdr = skb->h.raw - skb->data;
1239 u16 offset = hdr + skb->csum;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001240
1241 ctrl = CALSUM | WR_SUM | INIT_SUM | LOCK_SUM;
1242 if (skb->nh.iph->protocol == IPPROTO_UDP)
1243 ctrl |= UDPTCP;
1244
1245 le = get_tx_le(sky2);
1246 le->tx.csum.start = cpu_to_le16(hdr);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001247 le->tx.csum.offset = cpu_to_le16(offset);
1248 le->length = 0; /* initial checksum value */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001249 le->ctrl = 1; /* one packet */
Stephen Hemminger793b8832005-09-14 16:06:14 -07001250 le->opcode = OP_TCPLISW | HW_OWNER;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001251 }
1252
1253 le = get_tx_le(sky2);
1254 le->tx.addr = cpu_to_le32((u32) mapping);
1255 le->length = cpu_to_le16(len);
1256 le->ctrl = ctrl;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001257 le->opcode = mss ? (OP_LARGESEND | HW_OWNER) : (OP_PACKET | HW_OWNER);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001258
Stephen Hemminger793b8832005-09-14 16:06:14 -07001259 /* Record the transmit mapping info */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001260 re->skb = skb;
Stephen Hemminger6cdbbdf2005-12-09 11:35:01 -08001261 pci_unmap_addr_set(re, mapaddr, mapping);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001262
1263 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1264 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
Stephen Hemminger6cdbbdf2005-12-09 11:35:01 -08001265 struct tx_ring_info *fre;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001266
1267 mapping = pci_map_page(hw->pdev, frag->page, frag->page_offset,
1268 frag->size, PCI_DMA_TODEVICE);
Stephen Hemmingera0361192006-01-17 13:43:16 -08001269 addr64 = high32(mapping);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001270 if (addr64 != sky2->tx_addr64) {
1271 le = get_tx_le(sky2);
1272 le->tx.addr = cpu_to_le32(addr64);
1273 le->ctrl = 0;
1274 le->opcode = OP_ADDR64 | HW_OWNER;
1275 sky2->tx_addr64 = addr64;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001276 }
1277
1278 le = get_tx_le(sky2);
1279 le->tx.addr = cpu_to_le32((u32) mapping);
1280 le->length = cpu_to_le16(frag->size);
1281 le->ctrl = ctrl;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001282 le->opcode = OP_BUFFER | HW_OWNER;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001283
Stephen Hemminger793b8832005-09-14 16:06:14 -07001284 fre = sky2->tx_ring
1285 + ((re - sky2->tx_ring) + i + 1) % TX_RING_SIZE;
Stephen Hemminger6cdbbdf2005-12-09 11:35:01 -08001286 pci_unmap_addr_set(fre, mapaddr, mapping);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001287 }
Stephen Hemminger6cdbbdf2005-12-09 11:35:01 -08001288
Stephen Hemminger793b8832005-09-14 16:06:14 -07001289 re->idx = sky2->tx_prod;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001290 le->ctrl |= EOP;
1291
shemminger@osdl.org724bca32005-09-27 15:03:01 -07001292 sky2_put_idx(hw, txqaddr[sky2->port], sky2->tx_prod,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001293 &sky2->tx_last_put, TX_RING_SIZE);
1294
Stephen Hemminger0e3ff6a2005-12-09 11:35:02 -08001295 if (tx_avail(sky2) <= MAX_SKB_TX_LE)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001296 netif_stop_queue(dev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001297
1298out_unlock:
Stephen Hemmingerf2e46562005-12-09 11:34:58 -08001299 spin_unlock(&sky2->tx_lock);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001300
1301 dev->trans_start = jiffies;
1302 return NETDEV_TX_OK;
1303}
1304
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001305/*
Stephen Hemminger793b8832005-09-14 16:06:14 -07001306 * Free ring elements from starting at tx_cons until "done"
1307 *
1308 * NB: the hardware will tell us about partial completion of multi-part
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07001309 * buffers; these are deferred until completion.
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001310 */
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001311static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001312{
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001313 struct net_device *dev = sky2->netdev;
Stephen Hemmingeraf2a58a2005-12-09 11:35:04 -08001314 struct pci_dev *pdev = sky2->hw->pdev;
1315 u16 nxt, put;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001316 unsigned i;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001317
Stephen Hemminger0e3ff6a2005-12-09 11:35:02 -08001318 BUG_ON(done >= TX_RING_SIZE);
shemminger@osdl.org22247952005-11-30 11:45:19 -08001319
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001320 if (unlikely(netif_msg_tx_done(sky2)))
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07001321 printk(KERN_DEBUG "%s: tx done, up to %u\n",
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001322 dev->name, done);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001323
Stephen Hemmingeraf2a58a2005-12-09 11:35:04 -08001324 for (put = sky2->tx_cons; put != done; put = nxt) {
1325 struct tx_ring_info *re = sky2->tx_ring + put;
1326 struct sk_buff *skb = re->skb;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001327
Stephen Hemmingeraf2a58a2005-12-09 11:35:04 -08001328 nxt = re->idx;
1329 BUG_ON(nxt >= TX_RING_SIZE);
Stephen Hemmingerd70cd512005-12-09 11:35:09 -08001330 prefetch(sky2->tx_ring + nxt);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001331
Stephen Hemminger793b8832005-09-14 16:06:14 -07001332 /* Check for partial status */
Stephen Hemmingeraf2a58a2005-12-09 11:35:04 -08001333 if (tx_dist(put, done) < tx_dist(put, nxt))
1334 break;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001335
Stephen Hemminger793b8832005-09-14 16:06:14 -07001336 skb = re->skb;
Stephen Hemmingeraf2a58a2005-12-09 11:35:04 -08001337 pci_unmap_single(pdev, pci_unmap_addr(re, mapaddr),
Stephen Hemminger734d1862005-12-09 11:35:00 -08001338 skb_headlen(skb), PCI_DMA_TODEVICE);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001339
Stephen Hemminger793b8832005-09-14 16:06:14 -07001340 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
Stephen Hemminger6cdbbdf2005-12-09 11:35:01 -08001341 struct tx_ring_info *fre;
Stephen Hemmingeraf2a58a2005-12-09 11:35:04 -08001342 fre = sky2->tx_ring + (put + i + 1) % TX_RING_SIZE;
1343 pci_unmap_page(pdev, pci_unmap_addr(fre, mapaddr),
1344 skb_shinfo(skb)->frags[i].size,
Stephen Hemminger734d1862005-12-09 11:35:00 -08001345 PCI_DMA_TODEVICE);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001346 }
1347
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001348 dev_kfree_skb_any(skb);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001349 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07001350
Stephen Hemmingeraf2a58a2005-12-09 11:35:04 -08001351 sky2->tx_cons = put;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001352 if (netif_queue_stopped(dev) && tx_avail(sky2) > MAX_SKB_TX_LE)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001353 netif_wake_queue(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001354}
1355
1356/* Cleanup all untransmitted buffers, assume transmitter not running */
Stephen Hemminger13b97b72005-12-09 11:35:03 -08001357static void sky2_tx_clean(struct sky2_port *sky2)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001358{
Stephen Hemminger302d1252006-01-17 13:43:20 -08001359 spin_lock_bh(&sky2->tx_lock);
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001360 sky2_tx_complete(sky2, sky2->tx_prod);
Stephen Hemminger302d1252006-01-17 13:43:20 -08001361 spin_unlock_bh(&sky2->tx_lock);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001362}
1363
1364/* Network shutdown */
1365static int sky2_down(struct net_device *dev)
1366{
1367 struct sky2_port *sky2 = netdev_priv(dev);
1368 struct sky2_hw *hw = sky2->hw;
1369 unsigned port = sky2->port;
1370 u16 ctrl;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001371
Stephen Hemminger1b537562005-12-20 15:08:07 -08001372 /* Never really got started! */
1373 if (!sky2->tx_le)
1374 return 0;
1375
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001376 if (netif_msg_ifdown(sky2))
1377 printk(KERN_INFO PFX "%s: disabling interface\n", dev->name);
1378
shemminger@osdl.org018d1c62005-11-30 11:45:18 -08001379 /* Stop more packets from being queued */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001380 netif_stop_queue(dev);
1381
shemminger@osdl.org018d1c62005-11-30 11:45:18 -08001382 /* Disable port IRQ */
1383 local_irq_disable();
1384 hw->intr_mask &= ~((sky2->port == 0) ? Y2_IS_IRQ_PHY1 : Y2_IS_IRQ_PHY2);
1385 sky2_write32(hw, B0_IMSK, hw->intr_mask);
1386 local_irq_enable();
1387
Stephen Hemminger91c86df2005-12-09 11:34:57 -08001388 flush_scheduled_work();
shemminger@osdl.org018d1c62005-11-30 11:45:18 -08001389
Stephen Hemminger793b8832005-09-14 16:06:14 -07001390 sky2_phy_reset(hw, port);
1391
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001392 /* Stop transmitter */
1393 sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_STOP);
1394 sky2_read32(hw, Q_ADDR(txqaddr[port], Q_CSR));
1395
1396 sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL),
Stephen Hemminger793b8832005-09-14 16:06:14 -07001397 RB_RST_SET | RB_DIS_OP_MD);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001398
1399 ctrl = gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001400 ctrl &= ~(GM_GPCR_TX_ENA | GM_GPCR_RX_ENA);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001401 gma_write16(hw, port, GM_GP_CTRL, ctrl);
1402
1403 sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
1404
1405 /* Workaround shared GMAC reset */
Stephen Hemminger793b8832005-09-14 16:06:14 -07001406 if (!(hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0
1407 && port == 0 && hw->dev[1] && netif_running(hw->dev[1])))
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001408 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
1409
1410 /* Disable Force Sync bit and Enable Alloc bit */
1411 sky2_write8(hw, SK_REG(port, TXA_CTRL),
1412 TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
1413
1414 /* Stop Interval Timer and Limit Counter of Tx Arbiter */
1415 sky2_write32(hw, SK_REG(port, TXA_ITI_INI), 0L);
1416 sky2_write32(hw, SK_REG(port, TXA_LIM_INI), 0L);
1417
1418 /* Reset the PCI FIFO of the async Tx queue */
Stephen Hemminger793b8832005-09-14 16:06:14 -07001419 sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR),
1420 BMU_RST_SET | BMU_FIFO_RST);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001421
1422 /* Reset the Tx prefetch units */
1423 sky2_write32(hw, Y2_QADDR(txqaddr[port], PREF_UNIT_CTRL),
1424 PREF_UNIT_RST_SET);
1425
1426 sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET);
1427
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001428 sky2_rx_stop(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001429
1430 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
1431 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
1432
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07001433 /* turn off LED's */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001434 sky2_write16(hw, B0_Y2LED, LED_STAT_OFF);
1435
shemminger@osdl.org018d1c62005-11-30 11:45:18 -08001436 synchronize_irq(hw->pdev->irq);
1437
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001438 sky2_tx_clean(sky2);
1439 sky2_rx_clean(sky2);
1440
1441 pci_free_consistent(hw->pdev, RX_LE_BYTES,
1442 sky2->rx_le, sky2->rx_le_map);
1443 kfree(sky2->rx_ring);
1444
1445 pci_free_consistent(hw->pdev,
1446 TX_RING_SIZE * sizeof(struct sky2_tx_le),
1447 sky2->tx_le, sky2->tx_le_map);
1448 kfree(sky2->tx_ring);
1449
Stephen Hemminger1b537562005-12-20 15:08:07 -08001450 sky2->tx_le = NULL;
1451 sky2->rx_le = NULL;
1452
1453 sky2->rx_ring = NULL;
1454 sky2->tx_ring = NULL;
1455
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001456 return 0;
1457}
1458
1459static u16 sky2_phy_speed(const struct sky2_hw *hw, u16 aux)
1460{
Stephen Hemminger793b8832005-09-14 16:06:14 -07001461 if (!hw->copper)
1462 return SPEED_1000;
1463
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001464 if (hw->chip_id == CHIP_ID_YUKON_FE)
1465 return (aux & PHY_M_PS_SPEED_100) ? SPEED_100 : SPEED_10;
1466
1467 switch (aux & PHY_M_PS_SPEED_MSK) {
1468 case PHY_M_PS_SPEED_1000:
1469 return SPEED_1000;
1470 case PHY_M_PS_SPEED_100:
1471 return SPEED_100;
1472 default:
1473 return SPEED_10;
1474 }
1475}
1476
1477static void sky2_link_up(struct sky2_port *sky2)
1478{
1479 struct sky2_hw *hw = sky2->hw;
1480 unsigned port = sky2->port;
1481 u16 reg;
1482
1483 /* Enable Transmit FIFO Underrun */
Stephen Hemminger793b8832005-09-14 16:06:14 -07001484 sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001485
1486 reg = gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemminger6f4c56b2006-02-10 15:58:59 -08001487 if (sky2->autoneg == AUTONEG_DISABLE) {
1488 reg |= GM_GPCR_AU_ALL_DIS;
1489
1490 /* Is write/read necessary? Copied from sky2_mac_init */
1491 gma_write16(hw, port, GM_GP_CTRL, reg);
1492 gma_read16(hw, port, GM_GP_CTRL);
1493
1494 switch (sky2->speed) {
1495 case SPEED_1000:
1496 reg &= ~GM_GPCR_SPEED_100;
1497 reg |= GM_GPCR_SPEED_1000;
1498 break;
1499 case SPEED_100:
1500 reg &= ~GM_GPCR_SPEED_1000;
1501 reg |= GM_GPCR_SPEED_100;
1502 break;
1503 case SPEED_10:
1504 reg &= ~(GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100);
1505 break;
1506 }
1507 } else
1508 reg &= ~GM_GPCR_AU_ALL_DIS;
1509
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001510 if (sky2->duplex == DUPLEX_FULL || sky2->autoneg == AUTONEG_ENABLE)
1511 reg |= GM_GPCR_DUP_FULL;
1512
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001513 /* enable Rx/Tx */
1514 reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA;
1515 gma_write16(hw, port, GM_GP_CTRL, reg);
1516 gma_read16(hw, port, GM_GP_CTRL);
1517
1518 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
1519
1520 netif_carrier_on(sky2->netdev);
1521 netif_wake_queue(sky2->netdev);
1522
1523 /* Turn on link LED */
Stephen Hemminger793b8832005-09-14 16:06:14 -07001524 sky2_write8(hw, SK_REG(port, LNK_LED_REG),
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001525 LINKLED_ON | LINKLED_BLINK_OFF | LINKLED_LINKSYNC_OFF);
1526
Stephen Hemminger793b8832005-09-14 16:06:14 -07001527 if (hw->chip_id == CHIP_ID_YUKON_XL) {
1528 u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
1529
1530 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
1531 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */
1532 PHY_M_LEDC_INIT_CTRL(sky2->speed ==
1533 SPEED_10 ? 7 : 0) |
1534 PHY_M_LEDC_STA1_CTRL(sky2->speed ==
1535 SPEED_100 ? 7 : 0) |
1536 PHY_M_LEDC_STA0_CTRL(sky2->speed ==
1537 SPEED_1000 ? 7 : 0));
1538 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
1539 }
1540
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001541 if (netif_msg_link(sky2))
1542 printk(KERN_INFO PFX
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07001543 "%s: Link is up at %d Mbps, %s duplex, flow control %s\n",
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001544 sky2->netdev->name, sky2->speed,
1545 sky2->duplex == DUPLEX_FULL ? "full" : "half",
1546 (sky2->tx_pause && sky2->rx_pause) ? "both" :
Stephen Hemminger793b8832005-09-14 16:06:14 -07001547 sky2->tx_pause ? "tx" : sky2->rx_pause ? "rx" : "none");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001548}
1549
1550static void sky2_link_down(struct sky2_port *sky2)
1551{
1552 struct sky2_hw *hw = sky2->hw;
1553 unsigned port = sky2->port;
1554 u16 reg;
1555
1556 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);
1557
1558 reg = gma_read16(hw, port, GM_GP_CTRL);
1559 reg &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
1560 gma_write16(hw, port, GM_GP_CTRL, reg);
1561 gma_read16(hw, port, GM_GP_CTRL); /* PCI post */
1562
1563 if (sky2->rx_pause && !sky2->tx_pause) {
1564 /* restore Asymmetric Pause bit */
1565 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV,
Stephen Hemminger793b8832005-09-14 16:06:14 -07001566 gm_phy_read(hw, port, PHY_MARV_AUNE_ADV)
1567 | PHY_M_AN_ASP);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001568 }
1569
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001570 netif_carrier_off(sky2->netdev);
1571 netif_stop_queue(sky2->netdev);
1572
1573 /* Turn on link LED */
1574 sky2_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
1575
1576 if (netif_msg_link(sky2))
1577 printk(KERN_INFO PFX "%s: Link is down.\n", sky2->netdev->name);
1578 sky2_phy_init(hw, port);
1579}
1580
Stephen Hemminger793b8832005-09-14 16:06:14 -07001581static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux)
1582{
1583 struct sky2_hw *hw = sky2->hw;
1584 unsigned port = sky2->port;
1585 u16 lpa;
1586
1587 lpa = gm_phy_read(hw, port, PHY_MARV_AUNE_LP);
1588
1589 if (lpa & PHY_M_AN_RF) {
1590 printk(KERN_ERR PFX "%s: remote fault", sky2->netdev->name);
1591 return -1;
1592 }
1593
1594 if (hw->chip_id != CHIP_ID_YUKON_FE &&
1595 gm_phy_read(hw, port, PHY_MARV_1000T_STAT) & PHY_B_1000S_MSF) {
1596 printk(KERN_ERR PFX "%s: master/slave fault",
1597 sky2->netdev->name);
1598 return -1;
1599 }
1600
1601 if (!(aux & PHY_M_PS_SPDUP_RES)) {
1602 printk(KERN_ERR PFX "%s: speed/duplex mismatch",
1603 sky2->netdev->name);
1604 return -1;
1605 }
1606
1607 sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
1608
1609 sky2->speed = sky2_phy_speed(hw, aux);
1610
1611 /* Pause bits are offset (9..8) */
1612 if (hw->chip_id == CHIP_ID_YUKON_XL)
1613 aux >>= 6;
1614
1615 sky2->rx_pause = (aux & PHY_M_PS_RX_P_EN) != 0;
1616 sky2->tx_pause = (aux & PHY_M_PS_TX_P_EN) != 0;
1617
1618 if ((sky2->tx_pause || sky2->rx_pause)
1619 && !(sky2->speed < SPEED_1000 && sky2->duplex == DUPLEX_HALF))
1620 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
1621 else
1622 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
1623
1624 return 0;
1625}
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001626
1627/*
Stephen Hemminger91c86df2005-12-09 11:34:57 -08001628 * Interrupt from PHY are handled outside of interrupt context
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001629 * because accessing phy registers requires spin wait which might
1630 * cause excess interrupt latency.
1631 */
Stephen Hemminger91c86df2005-12-09 11:34:57 -08001632static void sky2_phy_task(void *arg)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001633{
Stephen Hemminger91c86df2005-12-09 11:34:57 -08001634 struct sky2_port *sky2 = arg;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001635 struct sky2_hw *hw = sky2->hw;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001636 u16 istatus, phystat;
1637
Stephen Hemminger91c86df2005-12-09 11:34:57 -08001638 down(&sky2->phy_sema);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001639 istatus = gm_phy_read(hw, sky2->port, PHY_MARV_INT_STAT);
1640 phystat = gm_phy_read(hw, sky2->port, PHY_MARV_PHY_STAT);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001641
1642 if (netif_msg_intr(sky2))
1643 printk(KERN_INFO PFX "%s: phy interrupt status 0x%x 0x%x\n",
1644 sky2->netdev->name, istatus, phystat);
1645
1646 if (istatus & PHY_M_IS_AN_COMPL) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07001647 if (sky2_autoneg_done(sky2, phystat) == 0)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001648 sky2_link_up(sky2);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001649 goto out;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001650 }
1651
Stephen Hemminger793b8832005-09-14 16:06:14 -07001652 if (istatus & PHY_M_IS_LSP_CHANGE)
1653 sky2->speed = sky2_phy_speed(hw, phystat);
1654
1655 if (istatus & PHY_M_IS_DUP_CHANGE)
1656 sky2->duplex =
1657 (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
1658
1659 if (istatus & PHY_M_IS_LST_CHANGE) {
1660 if (phystat & PHY_M_PS_LINK_UP)
1661 sky2_link_up(sky2);
1662 else
1663 sky2_link_down(sky2);
1664 }
1665out:
Stephen Hemminger91c86df2005-12-09 11:34:57 -08001666 up(&sky2->phy_sema);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001667
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001668 local_irq_disable();
Stephen Hemminger793b8832005-09-14 16:06:14 -07001669 hw->intr_mask |= (sky2->port == 0) ? Y2_IS_IRQ_PHY1 : Y2_IS_IRQ_PHY2;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001670 sky2_write32(hw, B0_IMSK, hw->intr_mask);
1671 local_irq_enable();
1672}
1673
Stephen Hemminger302d1252006-01-17 13:43:20 -08001674
1675/* Transmit timeout is only called if we are running, carries is up
1676 * and tx queue is full (stopped).
1677 */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001678static void sky2_tx_timeout(struct net_device *dev)
1679{
1680 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger8cc048e2005-12-09 11:35:07 -08001681 struct sky2_hw *hw = sky2->hw;
1682 unsigned txq = txqaddr[sky2->port];
Stephen Hemminger302d1252006-01-17 13:43:20 -08001683 u16 ridx;
1684
1685 /* Maybe we just missed an status interrupt */
1686 spin_lock(&sky2->tx_lock);
1687 ridx = sky2_read16(hw,
1688 sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX);
1689 sky2_tx_complete(sky2, ridx);
1690 spin_unlock(&sky2->tx_lock);
1691
1692 if (!netif_queue_stopped(dev)) {
1693 if (net_ratelimit())
1694 pr_info(PFX "transmit interrupt missed? recovered\n");
1695 return;
1696 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001697
1698 if (netif_msg_timer(sky2))
1699 printk(KERN_ERR PFX "%s: tx timeout\n", dev->name);
1700
Stephen Hemminger8cc048e2005-12-09 11:35:07 -08001701 sky2_write32(hw, Q_ADDR(txq, Q_CSR), BMU_STOP);
Stephen Hemminger8cc048e2005-12-09 11:35:07 -08001702 sky2_write32(hw, Y2_QADDR(txq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001703
1704 sky2_tx_clean(sky2);
Stephen Hemminger8cc048e2005-12-09 11:35:07 -08001705
1706 sky2_qset(hw, txq);
1707 sky2_prefetch_init(hw, txq, sky2->tx_le_map, TX_RING_SIZE - 1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001708}
1709
Stephen Hemminger734d1862005-12-09 11:35:00 -08001710
1711#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
1712/* Want receive buffer size to be multiple of 64 bits, and incl room for vlan */
1713static inline unsigned sky2_buf_size(int mtu)
1714{
1715 return roundup(mtu + ETH_HLEN + 4, 8);
1716}
1717
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001718static int sky2_change_mtu(struct net_device *dev, int new_mtu)
1719{
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001720 struct sky2_port *sky2 = netdev_priv(dev);
1721 struct sky2_hw *hw = sky2->hw;
1722 int err;
1723 u16 ctl, mode;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001724
1725 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
1726 return -EINVAL;
1727
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -08001728 if (hw->chip_id == CHIP_ID_YUKON_EC_U && new_mtu > ETH_DATA_LEN)
1729 return -EINVAL;
1730
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001731 if (!netif_running(dev)) {
1732 dev->mtu = new_mtu;
1733 return 0;
1734 }
1735
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001736 sky2_write32(hw, B0_IMSK, 0);
1737
shemminger@osdl.org018d1c62005-11-30 11:45:18 -08001738 dev->trans_start = jiffies; /* prevent tx timeout */
1739 netif_stop_queue(dev);
1740 netif_poll_disable(hw->dev[0]);
1741
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001742 ctl = gma_read16(hw, sky2->port, GM_GP_CTRL);
1743 gma_write16(hw, sky2->port, GM_GP_CTRL, ctl & ~GM_GPCR_RX_ENA);
1744 sky2_rx_stop(sky2);
1745 sky2_rx_clean(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001746
1747 dev->mtu = new_mtu;
Stephen Hemminger734d1862005-12-09 11:35:00 -08001748 sky2->rx_bufsize = sky2_buf_size(new_mtu);
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001749 mode = DATA_BLIND_VAL(DATA_BLIND_DEF) |
1750 GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001751
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001752 if (dev->mtu > ETH_DATA_LEN)
1753 mode |= GM_SMOD_JUMBO_ENA;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001754
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001755 gma_write16(hw, sky2->port, GM_SERIAL_MODE, mode);
1756
1757 sky2_write8(hw, RB_ADDR(rxqaddr[sky2->port], RB_CTRL), RB_ENA_OP_MD);
1758
1759 err = sky2_rx_start(sky2);
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001760 sky2_write32(hw, B0_IMSK, hw->intr_mask);
shemminger@osdl.org018d1c62005-11-30 11:45:18 -08001761
Stephen Hemminger1b537562005-12-20 15:08:07 -08001762 if (err)
1763 dev_close(dev);
1764 else {
1765 gma_write16(hw, sky2->port, GM_GP_CTRL, ctl);
1766
1767 netif_poll_enable(hw->dev[0]);
1768 netif_wake_queue(dev);
1769 }
1770
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001771 return err;
1772}
1773
1774/*
1775 * Receive one packet.
1776 * For small packets or errors, just reuse existing skb.
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07001777 * For larger packets, get new buffer.
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001778 */
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001779static struct sk_buff *sky2_receive(struct sky2_port *sky2,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001780 u16 length, u32 status)
1781{
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001782 struct ring_info *re = sky2->rx_ring + sky2->rx_next;
Stephen Hemminger79e57d32005-09-19 15:42:33 -07001783 struct sk_buff *skb = NULL;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001784
1785 if (unlikely(netif_msg_rx_status(sky2)))
1786 printk(KERN_DEBUG PFX "%s: rx slot %u status 0x%x len %d\n",
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001787 sky2->netdev->name, sky2->rx_next, status, length);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001788
Stephen Hemminger793b8832005-09-14 16:06:14 -07001789 sky2->rx_next = (sky2->rx_next + 1) % sky2->rx_pending;
Stephen Hemmingerd70cd512005-12-09 11:35:09 -08001790 prefetch(sky2->rx_ring + sky2->rx_next);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001791
shemminger@osdl.org42eeea02005-11-30 11:45:13 -08001792 if (status & GMR_FS_ANY_ERR)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001793 goto error;
1794
shemminger@osdl.org42eeea02005-11-30 11:45:13 -08001795 if (!(status & GMR_FS_RX_OK))
1796 goto resubmit;
1797
Stephen Hemminger6e15b712005-12-20 15:08:09 -08001798 if ((status >> 16) != length || length > sky2->rx_bufsize)
1799 goto oversize;
1800
Stephen Hemmingerbdb5c582005-12-09 11:34:55 -08001801 if (length < copybreak) {
Stephen Hemminger79e57d32005-09-19 15:42:33 -07001802 skb = alloc_skb(length + 2, GFP_ATOMIC);
1803 if (!skb)
Stephen Hemminger793b8832005-09-14 16:06:14 -07001804 goto resubmit;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001805
Stephen Hemminger79e57d32005-09-19 15:42:33 -07001806 skb_reserve(skb, 2);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001807 pci_dma_sync_single_for_cpu(sky2->hw->pdev, re->mapaddr,
1808 length, PCI_DMA_FROMDEVICE);
Stephen Hemminger79e57d32005-09-19 15:42:33 -07001809 memcpy(skb->data, re->skb->data, length);
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001810 skb->ip_summed = re->skb->ip_summed;
1811 skb->csum = re->skb->csum;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001812 pci_dma_sync_single_for_device(sky2->hw->pdev, re->mapaddr,
1813 length, PCI_DMA_FROMDEVICE);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001814 } else {
Stephen Hemminger79e57d32005-09-19 15:42:33 -07001815 struct sk_buff *nskb;
1816
Stephen Hemminger82788c72006-01-17 13:43:10 -08001817 nskb = sky2_alloc_skb(sky2->rx_bufsize, GFP_ATOMIC);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001818 if (!nskb)
1819 goto resubmit;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001820
Stephen Hemminger793b8832005-09-14 16:06:14 -07001821 skb = re->skb;
Stephen Hemminger79e57d32005-09-19 15:42:33 -07001822 re->skb = nskb;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001823 pci_unmap_single(sky2->hw->pdev, re->mapaddr,
Stephen Hemminger734d1862005-12-09 11:35:00 -08001824 sky2->rx_bufsize, PCI_DMA_FROMDEVICE);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001825 prefetch(skb->data);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001826
Stephen Hemminger793b8832005-09-14 16:06:14 -07001827 re->mapaddr = pci_map_single(sky2->hw->pdev, nskb->data,
Stephen Hemminger734d1862005-12-09 11:35:00 -08001828 sky2->rx_bufsize, PCI_DMA_FROMDEVICE);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001829 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001830
Stephen Hemminger79e57d32005-09-19 15:42:33 -07001831 skb_put(skb, length);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001832resubmit:
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001833 re->skb->ip_summed = CHECKSUM_NONE;
Stephen Hemminger734d1862005-12-09 11:35:00 -08001834 sky2_rx_add(sky2, re->mapaddr);
Stephen Hemminger79e57d32005-09-19 15:42:33 -07001835
shemminger@osdl.orgbea86102005-10-26 12:16:10 -07001836 /* Tell receiver about new buffers. */
1837 sky2_put_idx(sky2->hw, rxqaddr[sky2->port], sky2->rx_put,
1838 &sky2->rx_last_put, RX_LE_SIZE);
1839
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001840 return skb;
1841
Stephen Hemminger6e15b712005-12-20 15:08:09 -08001842oversize:
1843 ++sky2->net_stats.rx_over_errors;
1844 goto resubmit;
1845
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001846error:
Stephen Hemminger6e15b712005-12-20 15:08:09 -08001847 ++sky2->net_stats.rx_errors;
1848
Stephen Hemminger3be92a72006-01-17 13:43:17 -08001849 if (netif_msg_rx_err(sky2) && net_ratelimit())
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001850 printk(KERN_INFO PFX "%s: rx error, status 0x%x length %d\n",
1851 sky2->netdev->name, status, length);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001852
1853 if (status & (GMR_FS_LONG_ERR | GMR_FS_UN_SIZE))
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001854 sky2->net_stats.rx_length_errors++;
1855 if (status & GMR_FS_FRAGMENT)
1856 sky2->net_stats.rx_frame_errors++;
1857 if (status & GMR_FS_CRC_ERR)
1858 sky2->net_stats.rx_crc_errors++;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001859 if (status & GMR_FS_RX_FF_OV)
1860 sky2->net_stats.rx_fifo_errors++;
Stephen Hemminger79e57d32005-09-19 15:42:33 -07001861
Stephen Hemminger793b8832005-09-14 16:06:14 -07001862 goto resubmit;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001863}
1864
shemminger@osdl.org22247952005-11-30 11:45:19 -08001865/*
1866 * Check for transmit complete
Stephen Hemminger793b8832005-09-14 16:06:14 -07001867 */
Stephen Hemminger13b97b72005-12-09 11:35:03 -08001868#define TX_NO_STATUS 0xffff
shemminger@osdl.org22247952005-11-30 11:45:19 -08001869
Stephen Hemminger28bd1812006-01-17 13:43:19 -08001870static void sky2_tx_check(struct sky2_hw *hw, int port, u16 last)
Stephen Hemminger13b97b72005-12-09 11:35:03 -08001871{
1872 if (last != TX_NO_STATUS) {
1873 struct net_device *dev = hw->dev[port];
1874 if (dev && netif_running(dev)) {
1875 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger302d1252006-01-17 13:43:20 -08001876
1877 spin_lock(&sky2->tx_lock);
Stephen Hemminger13b97b72005-12-09 11:35:03 -08001878 sky2_tx_complete(sky2, last);
Stephen Hemminger302d1252006-01-17 13:43:20 -08001879 spin_unlock(&sky2->tx_lock);
Stephen Hemminger13b97b72005-12-09 11:35:03 -08001880 }
shemminger@osdl.org22247952005-11-30 11:45:19 -08001881 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001882}
1883
1884/*
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001885 * Both ports share the same status interrupt, therefore there is only
1886 * one poll routine.
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001887 */
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001888static int sky2_poll(struct net_device *dev0, int *budget)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001889{
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001890 struct sky2_hw *hw = ((struct sky2_port *) netdev_priv(dev0))->hw;
1891 unsigned int to_do = min(dev0->quota, *budget);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001892 unsigned int work_done = 0;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001893 u16 hwidx;
Stephen Hemminger13b97b72005-12-09 11:35:03 -08001894 u16 tx_done[2] = { TX_NO_STATUS, TX_NO_STATUS };
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001895
Stephen Hemmingerf9a66c72006-01-30 11:37:58 -08001896 sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ);
1897
Stephen Hemminger793b8832005-09-14 16:06:14 -07001898 hwidx = sky2_read16(hw, STAT_PUT_IDX);
Stephen Hemminger79e57d32005-09-19 15:42:33 -07001899 BUG_ON(hwidx >= STATUS_RING_SIZE);
Stephen Hemmingeraf2a58a2005-12-09 11:35:04 -08001900 rmb();
shemminger@osdl.orgbea86102005-10-26 12:16:10 -07001901
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08001902 while (hwidx != hw->st_idx) {
1903 struct sky2_status_le *le = hw->st_le + hw->st_idx;
1904 struct net_device *dev;
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001905 struct sky2_port *sky2;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001906 struct sk_buff *skb;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001907 u32 status;
1908 u16 length;
1909
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08001910 le = hw->st_le + hw->st_idx;
shemminger@osdl.orgbea86102005-10-26 12:16:10 -07001911 hw->st_idx = (hw->st_idx + 1) % STATUS_RING_SIZE;
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08001912 prefetch(hw->st_le + hw->st_idx);
shemminger@osdl.orgbea86102005-10-26 12:16:10 -07001913
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08001914 BUG_ON(le->link >= 2);
1915 dev = hw->dev[le->link];
1916 if (dev == NULL || !netif_running(dev))
1917 continue;
1918
1919 sky2 = netdev_priv(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001920 status = le32_to_cpu(le->status);
1921 length = le16_to_cpu(le->length);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001922
Stephen Hemmingerdc4d5ea2006-01-17 13:43:15 -08001923 switch (le->opcode & ~HW_OWNER) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001924 case OP_RXSTAT:
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001925 skb = sky2_receive(sky2, length, status);
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001926 if (!skb)
1927 break;
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08001928
1929 skb->dev = dev;
1930 skb->protocol = eth_type_trans(skb, dev);
1931 dev->last_rx = jiffies;
1932
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001933#ifdef SKY2_VLAN_TAG_USED
1934 if (sky2->vlgrp && (status & GMR_FS_VLAN)) {
1935 vlan_hwaccel_receive_skb(skb,
1936 sky2->vlgrp,
1937 be16_to_cpu(sky2->rx_tag));
1938 } else
1939#endif
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001940 netif_receive_skb(skb);
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08001941
1942 if (++work_done >= to_do)
1943 goto exit_loop;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001944 break;
1945
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001946#ifdef SKY2_VLAN_TAG_USED
1947 case OP_RXVLAN:
1948 sky2->rx_tag = length;
1949 break;
1950
1951 case OP_RXCHKSVLAN:
1952 sky2->rx_tag = length;
1953 /* fall through */
1954#endif
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001955 case OP_RXCHKS:
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001956 skb = sky2->rx_ring[sky2->rx_next].skb;
1957 skb->ip_summed = CHECKSUM_HW;
1958 skb->csum = le16_to_cpu(status);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001959 break;
1960
1961 case OP_TXINDEXLE:
Stephen Hemminger13b97b72005-12-09 11:35:03 -08001962 /* TX index reports status for both ports */
1963 tx_done[0] = status & 0xffff;
1964 tx_done[1] = ((status >> 24) & 0xff)
1965 | (u16)(length & 0xf) << 8;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001966 break;
1967
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001968 default:
1969 if (net_ratelimit())
Stephen Hemminger793b8832005-09-14 16:06:14 -07001970 printk(KERN_WARNING PFX
Stephen Hemmingerdc4d5ea2006-01-17 13:43:15 -08001971 "unknown status opcode 0x%x\n", le->opcode);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001972 break;
1973 }
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08001974 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001975
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08001976exit_loop:
Stephen Hemminger13b97b72005-12-09 11:35:03 -08001977 sky2_tx_check(hw, 0, tx_done[0]);
1978 sky2_tx_check(hw, 1, tx_done[1]);
1979
Stephen Hemmingerf9a66c72006-01-30 11:37:58 -08001980 if (likely(work_done < to_do)) {
Stephen Hemminger13b97b72005-12-09 11:35:03 -08001981 /* need to restart TX timer */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001982 if (is_ec_a1(hw)) {
1983 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP);
1984 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
1985 }
1986
shemminger@osdl.orgbea86102005-10-26 12:16:10 -07001987 netif_rx_complete(dev0);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001988 hw->intr_mask |= Y2_IS_STAT_BMU;
1989 sky2_write32(hw, B0_IMSK, hw->intr_mask);
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08001990 return 0;
1991 } else {
1992 *budget -= work_done;
1993 dev0->quota -= work_done;
1994 return 1;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001995 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001996}
1997
1998static void sky2_hw_error(struct sky2_hw *hw, unsigned port, u32 status)
1999{
2000 struct net_device *dev = hw->dev[port];
2001
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002002 if (net_ratelimit())
2003 printk(KERN_INFO PFX "%s: hw error interrupt status 0x%x\n",
2004 dev->name, status);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002005
2006 if (status & Y2_IS_PAR_RD1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002007 if (net_ratelimit())
2008 printk(KERN_ERR PFX "%s: ram data read parity error\n",
2009 dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002010 /* Clear IRQ */
2011 sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_RD_PERR);
2012 }
2013
2014 if (status & Y2_IS_PAR_WR1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002015 if (net_ratelimit())
2016 printk(KERN_ERR PFX "%s: ram data write parity error\n",
2017 dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002018
2019 sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_WR_PERR);
2020 }
2021
2022 if (status & Y2_IS_PAR_MAC1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002023 if (net_ratelimit())
2024 printk(KERN_ERR PFX "%s: MAC parity error\n", dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002025 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_PE);
2026 }
2027
2028 if (status & Y2_IS_PAR_RX1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002029 if (net_ratelimit())
2030 printk(KERN_ERR PFX "%s: RX parity error\n", dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002031 sky2_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), BMU_CLR_IRQ_PAR);
2032 }
2033
2034 if (status & Y2_IS_TCP_TXA1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002035 if (net_ratelimit())
2036 printk(KERN_ERR PFX "%s: TCP segmentation error\n",
2037 dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002038 sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_CLR_IRQ_TCP);
2039 }
2040}
2041
2042static void sky2_hw_intr(struct sky2_hw *hw)
2043{
2044 u32 status = sky2_read32(hw, B0_HWE_ISRC);
2045
Stephen Hemminger793b8832005-09-14 16:06:14 -07002046 if (status & Y2_IS_TIST_OV)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002047 sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002048
2049 if (status & (Y2_IS_MST_ERR | Y2_IS_IRQ_STAT)) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07002050 u16 pci_err;
2051
2052 pci_read_config_word(hw->pdev, PCI_STATUS, &pci_err);
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002053 if (net_ratelimit())
2054 printk(KERN_ERR PFX "%s: pci hw error (0x%x)\n",
2055 pci_name(hw->pdev), pci_err);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002056
2057 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002058 pci_write_config_word(hw->pdev, PCI_STATUS,
2059 pci_err | PCI_STATUS_ERROR_BITS);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002060 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
2061 }
2062
2063 if (status & Y2_IS_PCI_EXP) {
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07002064 /* PCI-Express uncorrectable Error occurred */
Stephen Hemminger793b8832005-09-14 16:06:14 -07002065 u32 pex_err;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002066
Stephen Hemminger793b8832005-09-14 16:06:14 -07002067 pci_read_config_dword(hw->pdev, PEX_UNC_ERR_STAT, &pex_err);
2068
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002069 if (net_ratelimit())
2070 printk(KERN_ERR PFX "%s: pci express error (0x%x)\n",
2071 pci_name(hw->pdev), pex_err);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002072
2073 /* clear the interrupt */
2074 sky2_write32(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002075 pci_write_config_dword(hw->pdev, PEX_UNC_ERR_STAT,
2076 0xffffffffUL);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002077 sky2_write32(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
2078
2079 if (pex_err & PEX_FATAL_ERRORS) {
2080 u32 hwmsk = sky2_read32(hw, B0_HWE_IMSK);
2081 hwmsk &= ~Y2_IS_PCI_EXP;
2082 sky2_write32(hw, B0_HWE_IMSK, hwmsk);
2083 }
2084 }
2085
2086 if (status & Y2_HWE_L1_MASK)
2087 sky2_hw_error(hw, 0, status);
2088 status >>= 8;
2089 if (status & Y2_HWE_L1_MASK)
2090 sky2_hw_error(hw, 1, status);
2091}
2092
2093static void sky2_mac_intr(struct sky2_hw *hw, unsigned port)
2094{
2095 struct net_device *dev = hw->dev[port];
2096 struct sky2_port *sky2 = netdev_priv(dev);
2097 u8 status = sky2_read8(hw, SK_REG(port, GMAC_IRQ_SRC));
2098
2099 if (netif_msg_intr(sky2))
2100 printk(KERN_INFO PFX "%s: mac interrupt status 0x%x\n",
2101 dev->name, status);
2102
2103 if (status & GM_IS_RX_FF_OR) {
2104 ++sky2->net_stats.rx_fifo_errors;
2105 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO);
2106 }
2107
2108 if (status & GM_IS_TX_FF_UR) {
2109 ++sky2->net_stats.tx_fifo_errors;
2110 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU);
2111 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002112}
2113
2114static void sky2_phy_intr(struct sky2_hw *hw, unsigned port)
2115{
2116 struct net_device *dev = hw->dev[port];
2117 struct sky2_port *sky2 = netdev_priv(dev);
2118
2119 hw->intr_mask &= ~(port == 0 ? Y2_IS_IRQ_PHY1 : Y2_IS_IRQ_PHY2);
2120 sky2_write32(hw, B0_IMSK, hw->intr_mask);
Stephen Hemminger91c86df2005-12-09 11:34:57 -08002121 schedule_work(&sky2->phy_task);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002122}
2123
2124static irqreturn_t sky2_intr(int irq, void *dev_id, struct pt_regs *regs)
2125{
2126 struct sky2_hw *hw = dev_id;
shemminger@osdl.orgbea86102005-10-26 12:16:10 -07002127 struct net_device *dev0 = hw->dev[0];
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002128 u32 status;
2129
2130 status = sky2_read32(hw, B0_Y2_SP_ISRC2);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002131 if (status == 0 || status == ~0)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002132 return IRQ_NONE;
2133
2134 if (status & Y2_IS_HW_ERR)
2135 sky2_hw_intr(hw);
2136
Stephen Hemminger793b8832005-09-14 16:06:14 -07002137 /* Do NAPI for Rx and Tx status */
shemminger@osdl.orgbea86102005-10-26 12:16:10 -07002138 if (status & Y2_IS_STAT_BMU) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002139 hw->intr_mask &= ~Y2_IS_STAT_BMU;
2140 sky2_write32(hw, B0_IMSK, hw->intr_mask);
shemminger@osdl.orgbea86102005-10-26 12:16:10 -07002141
shemminger@osdl.org0a122572005-11-30 11:45:17 -08002142 if (likely(__netif_rx_schedule_prep(dev0))) {
2143 prefetch(&hw->st_le[hw->st_idx]);
shemminger@osdl.orgbea86102005-10-26 12:16:10 -07002144 __netif_rx_schedule(dev0);
shemminger@osdl.org0a122572005-11-30 11:45:17 -08002145 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002146 }
2147
Stephen Hemminger793b8832005-09-14 16:06:14 -07002148 if (status & Y2_IS_IRQ_PHY1)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002149 sky2_phy_intr(hw, 0);
2150
2151 if (status & Y2_IS_IRQ_PHY2)
2152 sky2_phy_intr(hw, 1);
2153
2154 if (status & Y2_IS_IRQ_MAC1)
2155 sky2_mac_intr(hw, 0);
2156
2157 if (status & Y2_IS_IRQ_MAC2)
2158 sky2_mac_intr(hw, 1);
2159
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002160 sky2_write32(hw, B0_Y2_SP_ICR, 2);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002161
2162 sky2_read32(hw, B0_IMSK);
2163
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002164 return IRQ_HANDLED;
2165}
2166
2167#ifdef CONFIG_NET_POLL_CONTROLLER
2168static void sky2_netpoll(struct net_device *dev)
2169{
2170 struct sky2_port *sky2 = netdev_priv(dev);
2171
Stephen Hemminger793b8832005-09-14 16:06:14 -07002172 sky2_intr(sky2->hw->pdev->irq, sky2->hw, NULL);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002173}
2174#endif
2175
2176/* Chip internal frequency for clock calculations */
Stephen Hemmingerfb173582005-12-09 11:34:56 -08002177static inline u32 sky2_mhz(const struct sky2_hw *hw)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002178{
Stephen Hemminger793b8832005-09-14 16:06:14 -07002179 switch (hw->chip_id) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002180 case CHIP_ID_YUKON_EC:
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -08002181 case CHIP_ID_YUKON_EC_U:
Stephen Hemmingerfb173582005-12-09 11:34:56 -08002182 return 125; /* 125 Mhz */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002183 case CHIP_ID_YUKON_FE:
Stephen Hemmingerfb173582005-12-09 11:34:56 -08002184 return 100; /* 100 Mhz */
Stephen Hemminger793b8832005-09-14 16:06:14 -07002185 default: /* YUKON_XL */
Stephen Hemmingerfb173582005-12-09 11:34:56 -08002186 return 156; /* 156 Mhz */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002187 }
2188}
2189
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002190static inline u32 sky2_us2clk(const struct sky2_hw *hw, u32 us)
2191{
Stephen Hemmingerfb173582005-12-09 11:34:56 -08002192 return sky2_mhz(hw) * us;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002193}
2194
Stephen Hemmingerfb173582005-12-09 11:34:56 -08002195static inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk)
2196{
2197 return clk / sky2_mhz(hw);
2198}
2199
2200
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002201static int sky2_reset(struct sky2_hw *hw)
2202{
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002203 u16 status;
2204 u8 t8, pmd_type;
Stephen Hemminger2d42d212006-01-30 11:37:55 -08002205 int i, err;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002206
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002207 sky2_write8(hw, B0_CTST, CS_RST_CLR);
Stephen Hemminger08c06d82006-01-30 11:37:54 -08002208
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002209 hw->chip_id = sky2_read8(hw, B2_CHIP_ID);
2210 if (hw->chip_id < CHIP_ID_YUKON_XL || hw->chip_id > CHIP_ID_YUKON_FE) {
2211 printk(KERN_ERR PFX "%s: unsupported chip type 0x%x\n",
2212 pci_name(hw->pdev), hw->chip_id);
2213 return -EOPNOTSUPP;
2214 }
2215
2216 /* disable ASF */
2217 if (hw->chip_id <= CHIP_ID_YUKON_EC) {
2218 sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET);
2219 sky2_write16(hw, B0_CTST, Y2_ASF_DISABLE);
2220 }
2221
2222 /* do a SW reset */
2223 sky2_write8(hw, B0_CTST, CS_RST_SET);
2224 sky2_write8(hw, B0_CTST, CS_RST_CLR);
2225
2226 /* clear PCI errors, if any */
Stephen Hemminger2d42d212006-01-30 11:37:55 -08002227 err = pci_read_config_word(hw->pdev, PCI_STATUS, &status);
2228 if (err)
2229 goto pci_err;
2230
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002231 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
Stephen Hemminger2d42d212006-01-30 11:37:55 -08002232 err = pci_write_config_word(hw->pdev, PCI_STATUS,
2233 status | PCI_STATUS_ERROR_BITS);
2234 if (err)
2235 goto pci_err;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002236
2237 sky2_write8(hw, B0_CTST, CS_MRST_CLR);
2238
2239 /* clear any PEX errors */
Stephen Hemminger2d42d212006-01-30 11:37:55 -08002240 if (pci_find_capability(hw->pdev, PCI_CAP_ID_EXP)) {
2241 err = pci_write_config_dword(hw->pdev, PEX_UNC_ERR_STAT,
2242 0xffffffffUL);
2243 if (err)
2244 goto pci_err;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002245 }
2246
2247 pmd_type = sky2_read8(hw, B2_PMD_TYP);
2248 hw->copper = !(pmd_type == 'L' || pmd_type == 'S');
2249
2250 hw->ports = 1;
2251 t8 = sky2_read8(hw, B2_Y2_HW_RES);
2252 if ((t8 & CFG_DUAL_MAC_MSK) == CFG_DUAL_MAC_MSK) {
2253 if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC))
2254 ++hw->ports;
2255 }
2256 hw->chip_rev = (sky2_read8(hw, B2_MAC_CFG) & CFG_CHIP_R_MSK) >> 4;
2257
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07002258 sky2_set_power_state(hw, PCI_D0);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002259
2260 for (i = 0; i < hw->ports; i++) {
2261 sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
2262 sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
2263 }
2264
2265 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
2266
Stephen Hemminger793b8832005-09-14 16:06:14 -07002267 /* Clear I2C IRQ noise */
2268 sky2_write32(hw, B2_I2C_IRQ, 1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002269
2270 /* turn off hardware timer (unused) */
2271 sky2_write8(hw, B2_TI_CTRL, TIM_STOP);
2272 sky2_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002273
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002274 sky2_write8(hw, B0_Y2LED, LED_STAT_ON);
2275
Stephen Hemminger69634ee2005-12-09 11:35:06 -08002276 /* Turn off descriptor polling */
2277 sky2_write32(hw, B28_DPT_CTRL, DPT_STOP);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002278
2279 /* Turn off receive timestamp */
2280 sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_STOP);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002281 sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002282
2283 /* enable the Tx Arbiters */
2284 for (i = 0; i < hw->ports; i++)
2285 sky2_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB);
2286
2287 /* Initialize ram interface */
2288 for (i = 0; i < hw->ports; i++) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07002289 sky2_write8(hw, RAM_BUFFER(i, B3_RI_CTRL), RI_RST_CLR);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002290
2291 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R1), SK_RI_TO_53);
2292 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA1), SK_RI_TO_53);
2293 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS1), SK_RI_TO_53);
2294 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R1), SK_RI_TO_53);
2295 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA1), SK_RI_TO_53);
2296 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS1), SK_RI_TO_53);
2297 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R2), SK_RI_TO_53);
2298 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA2), SK_RI_TO_53);
2299 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS2), SK_RI_TO_53);
2300 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R2), SK_RI_TO_53);
2301 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA2), SK_RI_TO_53);
2302 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS2), SK_RI_TO_53);
2303 }
2304
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002305 sky2_write32(hw, B0_HWE_IMSK, Y2_HWE_ALL_MASK);
2306
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002307 for (i = 0; i < hw->ports; i++)
2308 sky2_phy_reset(hw, i);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002309
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002310 memset(hw->st_le, 0, STATUS_LE_BYTES);
2311 hw->st_idx = 0;
2312
2313 sky2_write32(hw, STAT_CTRL, SC_STAT_RST_SET);
2314 sky2_write32(hw, STAT_CTRL, SC_STAT_RST_CLR);
2315
2316 sky2_write32(hw, STAT_LIST_ADDR_LO, hw->st_dma);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002317 sky2_write32(hw, STAT_LIST_ADDR_HI, (u64) hw->st_dma >> 32);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002318
2319 /* Set the list last index */
Stephen Hemminger793b8832005-09-14 16:06:14 -07002320 sky2_write16(hw, STAT_LAST_IDX, STATUS_RING_SIZE - 1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002321
Stephen Hemminger793b8832005-09-14 16:06:14 -07002322 /* These status setup values are copied from SysKonnect's driver */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002323 if (is_ec_a1(hw)) {
2324 /* WA for dev. #4.3 */
Stephen Hemminger793b8832005-09-14 16:06:14 -07002325 sky2_write16(hw, STAT_TX_IDX_TH, 0xfff); /* Tx Threshold */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002326
2327 /* set Status-FIFO watermark */
2328 sky2_write8(hw, STAT_FIFO_WM, 0x21); /* WA for dev. #4.18 */
2329
2330 /* set Status-FIFO ISR watermark */
Stephen Hemminger793b8832005-09-14 16:06:14 -07002331 sky2_write8(hw, STAT_FIFO_ISR_WM, 0x07); /* WA for dev. #4.18 */
Stephen Hemminger69634ee2005-12-09 11:35:06 -08002332 sky2_write32(hw, STAT_TX_TIMER_INI, sky2_us2clk(hw, 10000));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002333 } else {
Stephen Hemminger69634ee2005-12-09 11:35:06 -08002334 sky2_write16(hw, STAT_TX_IDX_TH, 10);
2335 sky2_write8(hw, STAT_FIFO_WM, 16);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002336
2337 /* set Status-FIFO ISR watermark */
2338 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0)
Stephen Hemminger69634ee2005-12-09 11:35:06 -08002339 sky2_write8(hw, STAT_FIFO_ISR_WM, 4);
2340 else
2341 sky2_write8(hw, STAT_FIFO_ISR_WM, 16);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002342
Stephen Hemminger69634ee2005-12-09 11:35:06 -08002343 sky2_write32(hw, STAT_TX_TIMER_INI, sky2_us2clk(hw, 1000));
2344 sky2_write32(hw, STAT_LEV_TIMER_INI, sky2_us2clk(hw, 100));
2345 sky2_write32(hw, STAT_ISR_TIMER_INI, sky2_us2clk(hw, 20));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002346 }
2347
Stephen Hemminger793b8832005-09-14 16:06:14 -07002348 /* enable status unit */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002349 sky2_write32(hw, STAT_CTRL, SC_STAT_OP_ON);
2350
2351 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
2352 sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START);
2353 sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START);
2354
2355 return 0;
Stephen Hemminger2d42d212006-01-30 11:37:55 -08002356
2357pci_err:
2358 /* This is to catch a BIOS bug workaround where
2359 * mmconfig table doesn't have other buses.
2360 */
2361 printk(KERN_ERR PFX "%s: can't access PCI config space\n",
2362 pci_name(hw->pdev));
2363 return err;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002364}
2365
Stephen Hemminger28bd1812006-01-17 13:43:19 -08002366static u32 sky2_supported_modes(const struct sky2_hw *hw)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002367{
2368 u32 modes;
2369 if (hw->copper) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07002370 modes = SUPPORTED_10baseT_Half
2371 | SUPPORTED_10baseT_Full
2372 | SUPPORTED_100baseT_Half
2373 | SUPPORTED_100baseT_Full
2374 | SUPPORTED_Autoneg | SUPPORTED_TP;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002375
2376 if (hw->chip_id != CHIP_ID_YUKON_FE)
2377 modes |= SUPPORTED_1000baseT_Half
Stephen Hemminger793b8832005-09-14 16:06:14 -07002378 | SUPPORTED_1000baseT_Full;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002379 } else
2380 modes = SUPPORTED_1000baseT_Full | SUPPORTED_FIBRE
Stephen Hemminger793b8832005-09-14 16:06:14 -07002381 | SUPPORTED_Autoneg;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002382 return modes;
2383}
2384
Stephen Hemminger793b8832005-09-14 16:06:14 -07002385static int sky2_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002386{
2387 struct sky2_port *sky2 = netdev_priv(dev);
2388 struct sky2_hw *hw = sky2->hw;
2389
2390 ecmd->transceiver = XCVR_INTERNAL;
2391 ecmd->supported = sky2_supported_modes(hw);
2392 ecmd->phy_address = PHY_ADDR_MARV;
2393 if (hw->copper) {
2394 ecmd->supported = SUPPORTED_10baseT_Half
Stephen Hemminger793b8832005-09-14 16:06:14 -07002395 | SUPPORTED_10baseT_Full
2396 | SUPPORTED_100baseT_Half
2397 | SUPPORTED_100baseT_Full
2398 | SUPPORTED_1000baseT_Half
2399 | SUPPORTED_1000baseT_Full
2400 | SUPPORTED_Autoneg | SUPPORTED_TP;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002401 ecmd->port = PORT_TP;
2402 } else
2403 ecmd->port = PORT_FIBRE;
2404
2405 ecmd->advertising = sky2->advertising;
2406 ecmd->autoneg = sky2->autoneg;
2407 ecmd->speed = sky2->speed;
2408 ecmd->duplex = sky2->duplex;
2409 return 0;
2410}
2411
2412static int sky2_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2413{
2414 struct sky2_port *sky2 = netdev_priv(dev);
2415 const struct sky2_hw *hw = sky2->hw;
2416 u32 supported = sky2_supported_modes(hw);
2417
2418 if (ecmd->autoneg == AUTONEG_ENABLE) {
2419 ecmd->advertising = supported;
2420 sky2->duplex = -1;
2421 sky2->speed = -1;
2422 } else {
2423 u32 setting;
2424
Stephen Hemminger793b8832005-09-14 16:06:14 -07002425 switch (ecmd->speed) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002426 case SPEED_1000:
2427 if (ecmd->duplex == DUPLEX_FULL)
2428 setting = SUPPORTED_1000baseT_Full;
2429 else if (ecmd->duplex == DUPLEX_HALF)
2430 setting = SUPPORTED_1000baseT_Half;
2431 else
2432 return -EINVAL;
2433 break;
2434 case SPEED_100:
2435 if (ecmd->duplex == DUPLEX_FULL)
2436 setting = SUPPORTED_100baseT_Full;
2437 else if (ecmd->duplex == DUPLEX_HALF)
2438 setting = SUPPORTED_100baseT_Half;
2439 else
2440 return -EINVAL;
2441 break;
2442
2443 case SPEED_10:
2444 if (ecmd->duplex == DUPLEX_FULL)
2445 setting = SUPPORTED_10baseT_Full;
2446 else if (ecmd->duplex == DUPLEX_HALF)
2447 setting = SUPPORTED_10baseT_Half;
2448 else
2449 return -EINVAL;
2450 break;
2451 default:
2452 return -EINVAL;
2453 }
2454
2455 if ((setting & supported) == 0)
2456 return -EINVAL;
2457
2458 sky2->speed = ecmd->speed;
2459 sky2->duplex = ecmd->duplex;
2460 }
2461
2462 sky2->autoneg = ecmd->autoneg;
2463 sky2->advertising = ecmd->advertising;
2464
Stephen Hemminger1b537562005-12-20 15:08:07 -08002465 if (netif_running(dev))
2466 sky2_phy_reinit(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002467
2468 return 0;
2469}
2470
2471static void sky2_get_drvinfo(struct net_device *dev,
2472 struct ethtool_drvinfo *info)
2473{
2474 struct sky2_port *sky2 = netdev_priv(dev);
2475
2476 strcpy(info->driver, DRV_NAME);
2477 strcpy(info->version, DRV_VERSION);
2478 strcpy(info->fw_version, "N/A");
2479 strcpy(info->bus_info, pci_name(sky2->hw->pdev));
2480}
2481
2482static const struct sky2_stat {
Stephen Hemminger793b8832005-09-14 16:06:14 -07002483 char name[ETH_GSTRING_LEN];
2484 u16 offset;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002485} sky2_stats[] = {
2486 { "tx_bytes", GM_TXO_OK_HI },
2487 { "rx_bytes", GM_RXO_OK_HI },
2488 { "tx_broadcast", GM_TXF_BC_OK },
2489 { "rx_broadcast", GM_RXF_BC_OK },
2490 { "tx_multicast", GM_TXF_MC_OK },
2491 { "rx_multicast", GM_RXF_MC_OK },
2492 { "tx_unicast", GM_TXF_UC_OK },
2493 { "rx_unicast", GM_RXF_UC_OK },
2494 { "tx_mac_pause", GM_TXF_MPAUSE },
2495 { "rx_mac_pause", GM_RXF_MPAUSE },
2496 { "collisions", GM_TXF_SNG_COL },
2497 { "late_collision",GM_TXF_LAT_COL },
2498 { "aborted", GM_TXF_ABO_COL },
2499 { "multi_collisions", GM_TXF_MUL_COL },
2500 { "fifo_underrun", GM_TXE_FIFO_UR },
2501 { "fifo_overflow", GM_RXE_FIFO_OV },
2502 { "rx_toolong", GM_RXF_LNG_ERR },
2503 { "rx_jabber", GM_RXF_JAB_PKT },
2504 { "rx_runt", GM_RXE_FRAG },
2505 { "rx_too_long", GM_RXF_LNG_ERR },
2506 { "rx_fcs_error", GM_RXF_FCS_ERR },
2507};
2508
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002509static u32 sky2_get_rx_csum(struct net_device *dev)
2510{
2511 struct sky2_port *sky2 = netdev_priv(dev);
2512
2513 return sky2->rx_csum;
2514}
2515
2516static int sky2_set_rx_csum(struct net_device *dev, u32 data)
2517{
2518 struct sky2_port *sky2 = netdev_priv(dev);
2519
2520 sky2->rx_csum = data;
Stephen Hemminger793b8832005-09-14 16:06:14 -07002521
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002522 sky2_write32(sky2->hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR),
2523 data ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM);
2524
2525 return 0;
2526}
2527
2528static u32 sky2_get_msglevel(struct net_device *netdev)
2529{
2530 struct sky2_port *sky2 = netdev_priv(netdev);
2531 return sky2->msg_enable;
2532}
2533
Stephen Hemminger9a7ae0a2005-09-27 15:28:42 -07002534static int sky2_nway_reset(struct net_device *dev)
2535{
2536 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger9a7ae0a2005-09-27 15:28:42 -07002537
2538 if (sky2->autoneg != AUTONEG_ENABLE)
2539 return -EINVAL;
2540
Stephen Hemminger1b537562005-12-20 15:08:07 -08002541 sky2_phy_reinit(sky2);
Stephen Hemminger9a7ae0a2005-09-27 15:28:42 -07002542
2543 return 0;
2544}
2545
Stephen Hemminger793b8832005-09-14 16:06:14 -07002546static void sky2_phy_stats(struct sky2_port *sky2, u64 * data, unsigned count)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002547{
2548 struct sky2_hw *hw = sky2->hw;
2549 unsigned port = sky2->port;
2550 int i;
2551
2552 data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32
Stephen Hemminger793b8832005-09-14 16:06:14 -07002553 | (u64) gma_read32(hw, port, GM_TXO_OK_LO);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002554 data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32
Stephen Hemminger793b8832005-09-14 16:06:14 -07002555 | (u64) gma_read32(hw, port, GM_RXO_OK_LO);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002556
Stephen Hemminger793b8832005-09-14 16:06:14 -07002557 for (i = 2; i < count; i++)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002558 data[i] = (u64) gma_read32(hw, port, sky2_stats[i].offset);
2559}
2560
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002561static void sky2_set_msglevel(struct net_device *netdev, u32 value)
2562{
2563 struct sky2_port *sky2 = netdev_priv(netdev);
2564 sky2->msg_enable = value;
2565}
2566
2567static int sky2_get_stats_count(struct net_device *dev)
2568{
2569 return ARRAY_SIZE(sky2_stats);
2570}
2571
2572static void sky2_get_ethtool_stats(struct net_device *dev,
Stephen Hemminger793b8832005-09-14 16:06:14 -07002573 struct ethtool_stats *stats, u64 * data)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002574{
2575 struct sky2_port *sky2 = netdev_priv(dev);
2576
Stephen Hemminger793b8832005-09-14 16:06:14 -07002577 sky2_phy_stats(sky2, data, ARRAY_SIZE(sky2_stats));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002578}
2579
Stephen Hemminger793b8832005-09-14 16:06:14 -07002580static void sky2_get_strings(struct net_device *dev, u32 stringset, u8 * data)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002581{
2582 int i;
2583
2584 switch (stringset) {
2585 case ETH_SS_STATS:
2586 for (i = 0; i < ARRAY_SIZE(sky2_stats); i++)
2587 memcpy(data + i * ETH_GSTRING_LEN,
2588 sky2_stats[i].name, ETH_GSTRING_LEN);
2589 break;
2590 }
2591}
2592
2593/* Use hardware MIB variables for critical path statistics and
2594 * transmit feedback not reported at interrupt.
2595 * Other errors are accounted for in interrupt handler.
2596 */
2597static struct net_device_stats *sky2_get_stats(struct net_device *dev)
2598{
2599 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002600 u64 data[13];
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002601
Stephen Hemminger793b8832005-09-14 16:06:14 -07002602 sky2_phy_stats(sky2, data, ARRAY_SIZE(data));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002603
2604 sky2->net_stats.tx_bytes = data[0];
2605 sky2->net_stats.rx_bytes = data[1];
2606 sky2->net_stats.tx_packets = data[2] + data[4] + data[6];
2607 sky2->net_stats.rx_packets = data[3] + data[5] + data[7];
2608 sky2->net_stats.multicast = data[5] + data[7];
2609 sky2->net_stats.collisions = data[10];
2610 sky2->net_stats.tx_aborted_errors = data[12];
2611
2612 return &sky2->net_stats;
2613}
2614
2615static int sky2_set_mac_address(struct net_device *dev, void *p)
2616{
2617 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingera8ab1ec2006-01-30 11:37:57 -08002618 struct sky2_hw *hw = sky2->hw;
2619 unsigned port = sky2->port;
2620 const struct sockaddr *addr = p;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002621
2622 if (!is_valid_ether_addr(addr->sa_data))
2623 return -EADDRNOTAVAIL;
2624
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002625 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
Stephen Hemmingera8ab1ec2006-01-30 11:37:57 -08002626 memcpy_toio(hw->regs + B2_MAC_1 + port * 8,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002627 dev->dev_addr, ETH_ALEN);
Stephen Hemmingera8ab1ec2006-01-30 11:37:57 -08002628 memcpy_toio(hw->regs + B2_MAC_2 + port * 8,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002629 dev->dev_addr, ETH_ALEN);
Stephen Hemminger1b537562005-12-20 15:08:07 -08002630
Stephen Hemmingera8ab1ec2006-01-30 11:37:57 -08002631 /* virtual address for data */
2632 gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr);
2633
2634 /* physical address: used for pause frames */
2635 gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr);
Stephen Hemminger1b537562005-12-20 15:08:07 -08002636
2637 return 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002638}
2639
2640static void sky2_set_multicast(struct net_device *dev)
2641{
2642 struct sky2_port *sky2 = netdev_priv(dev);
2643 struct sky2_hw *hw = sky2->hw;
2644 unsigned port = sky2->port;
2645 struct dev_mc_list *list = dev->mc_list;
2646 u16 reg;
2647 u8 filter[8];
2648
2649 memset(filter, 0, sizeof(filter));
2650
2651 reg = gma_read16(hw, port, GM_RX_CTRL);
2652 reg |= GM_RXCR_UCF_ENA;
2653
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07002654 if (dev->flags & IFF_PROMISC) /* promiscuous */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002655 reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002656 else if ((dev->flags & IFF_ALLMULTI) || dev->mc_count > 16) /* all multicast */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002657 memset(filter, 0xff, sizeof(filter));
Stephen Hemminger793b8832005-09-14 16:06:14 -07002658 else if (dev->mc_count == 0) /* no multicast */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002659 reg &= ~GM_RXCR_MCF_ENA;
2660 else {
2661 int i;
2662 reg |= GM_RXCR_MCF_ENA;
2663
2664 for (i = 0; list && i < dev->mc_count; i++, list = list->next) {
2665 u32 bit = ether_crc(ETH_ALEN, list->dmi_addr) & 0x3f;
Stephen Hemminger793b8832005-09-14 16:06:14 -07002666 filter[bit / 8] |= 1 << (bit % 8);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002667 }
2668 }
2669
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002670 gma_write16(hw, port, GM_MC_ADDR_H1,
Stephen Hemminger793b8832005-09-14 16:06:14 -07002671 (u16) filter[0] | ((u16) filter[1] << 8));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002672 gma_write16(hw, port, GM_MC_ADDR_H2,
Stephen Hemminger793b8832005-09-14 16:06:14 -07002673 (u16) filter[2] | ((u16) filter[3] << 8));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002674 gma_write16(hw, port, GM_MC_ADDR_H3,
Stephen Hemminger793b8832005-09-14 16:06:14 -07002675 (u16) filter[4] | ((u16) filter[5] << 8));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002676 gma_write16(hw, port, GM_MC_ADDR_H4,
Stephen Hemminger793b8832005-09-14 16:06:14 -07002677 (u16) filter[6] | ((u16) filter[7] << 8));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002678
2679 gma_write16(hw, port, GM_RX_CTRL, reg);
2680}
2681
2682/* Can have one global because blinking is controlled by
2683 * ethtool and that is always under RTNL mutex
2684 */
Stephen Hemminger91c86df2005-12-09 11:34:57 -08002685static void sky2_led(struct sky2_hw *hw, unsigned port, int on)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002686{
Stephen Hemminger793b8832005-09-14 16:06:14 -07002687 u16 pg;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002688
Stephen Hemminger793b8832005-09-14 16:06:14 -07002689 switch (hw->chip_id) {
2690 case CHIP_ID_YUKON_XL:
2691 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
2692 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
2693 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
2694 on ? (PHY_M_LEDC_LOS_CTRL(1) |
2695 PHY_M_LEDC_INIT_CTRL(7) |
2696 PHY_M_LEDC_STA1_CTRL(7) |
2697 PHY_M_LEDC_STA0_CTRL(7))
2698 : 0);
2699
2700 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
2701 break;
2702
2703 default:
2704 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
2705 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
2706 on ? PHY_M_LED_MO_DUP(MO_LED_ON) |
2707 PHY_M_LED_MO_10(MO_LED_ON) |
2708 PHY_M_LED_MO_100(MO_LED_ON) |
2709 PHY_M_LED_MO_1000(MO_LED_ON) |
2710 PHY_M_LED_MO_RX(MO_LED_ON)
2711 : PHY_M_LED_MO_DUP(MO_LED_OFF) |
2712 PHY_M_LED_MO_10(MO_LED_OFF) |
2713 PHY_M_LED_MO_100(MO_LED_OFF) |
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002714 PHY_M_LED_MO_1000(MO_LED_OFF) |
2715 PHY_M_LED_MO_RX(MO_LED_OFF));
2716
Stephen Hemminger793b8832005-09-14 16:06:14 -07002717 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002718}
2719
2720/* blink LED's for finding board */
2721static int sky2_phys_id(struct net_device *dev, u32 data)
2722{
2723 struct sky2_port *sky2 = netdev_priv(dev);
2724 struct sky2_hw *hw = sky2->hw;
2725 unsigned port = sky2->port;
Stephen Hemminger793b8832005-09-14 16:06:14 -07002726 u16 ledctrl, ledover = 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002727 long ms;
Stephen Hemminger91c86df2005-12-09 11:34:57 -08002728 int interrupted;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002729 int onoff = 1;
2730
Stephen Hemminger793b8832005-09-14 16:06:14 -07002731 if (!data || data > (u32) (MAX_SCHEDULE_TIMEOUT / HZ))
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002732 ms = jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT);
2733 else
2734 ms = data * 1000;
2735
2736 /* save initial values */
Stephen Hemminger91c86df2005-12-09 11:34:57 -08002737 down(&sky2->phy_sema);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002738 if (hw->chip_id == CHIP_ID_YUKON_XL) {
2739 u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
2740 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
2741 ledctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
2742 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
2743 } else {
2744 ledctrl = gm_phy_read(hw, port, PHY_MARV_LED_CTRL);
2745 ledover = gm_phy_read(hw, port, PHY_MARV_LED_OVER);
2746 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002747
Stephen Hemminger91c86df2005-12-09 11:34:57 -08002748 interrupted = 0;
2749 while (!interrupted && ms > 0) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002750 sky2_led(hw, port, onoff);
2751 onoff = !onoff;
2752
Stephen Hemminger91c86df2005-12-09 11:34:57 -08002753 up(&sky2->phy_sema);
2754 interrupted = msleep_interruptible(250);
2755 down(&sky2->phy_sema);
2756
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002757 ms -= 250;
2758 }
2759
2760 /* resume regularly scheduled programming */
Stephen Hemminger793b8832005-09-14 16:06:14 -07002761 if (hw->chip_id == CHIP_ID_YUKON_XL) {
2762 u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
2763 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
2764 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ledctrl);
2765 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
2766 } else {
2767 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl);
2768 gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover);
2769 }
Stephen Hemminger91c86df2005-12-09 11:34:57 -08002770 up(&sky2->phy_sema);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002771
2772 return 0;
2773}
2774
2775static void sky2_get_pauseparam(struct net_device *dev,
2776 struct ethtool_pauseparam *ecmd)
2777{
2778 struct sky2_port *sky2 = netdev_priv(dev);
2779
2780 ecmd->tx_pause = sky2->tx_pause;
2781 ecmd->rx_pause = sky2->rx_pause;
2782 ecmd->autoneg = sky2->autoneg;
2783}
2784
2785static int sky2_set_pauseparam(struct net_device *dev,
2786 struct ethtool_pauseparam *ecmd)
2787{
2788 struct sky2_port *sky2 = netdev_priv(dev);
2789 int err = 0;
2790
2791 sky2->autoneg = ecmd->autoneg;
2792 sky2->tx_pause = ecmd->tx_pause != 0;
2793 sky2->rx_pause = ecmd->rx_pause != 0;
2794
Stephen Hemminger1b537562005-12-20 15:08:07 -08002795 sky2_phy_reinit(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002796
2797 return err;
2798}
2799
2800#ifdef CONFIG_PM
2801static void sky2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
2802{
2803 struct sky2_port *sky2 = netdev_priv(dev);
2804
2805 wol->supported = WAKE_MAGIC;
2806 wol->wolopts = sky2->wol ? WAKE_MAGIC : 0;
2807}
2808
2809static int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
2810{
2811 struct sky2_port *sky2 = netdev_priv(dev);
2812 struct sky2_hw *hw = sky2->hw;
2813
2814 if (wol->wolopts != WAKE_MAGIC && wol->wolopts != 0)
2815 return -EOPNOTSUPP;
2816
2817 sky2->wol = wol->wolopts == WAKE_MAGIC;
2818
2819 if (sky2->wol) {
2820 memcpy_toio(hw->regs + WOL_MAC_ADDR, dev->dev_addr, ETH_ALEN);
2821
2822 sky2_write16(hw, WOL_CTRL_STAT,
2823 WOL_CTL_ENA_PME_ON_MAGIC_PKT |
2824 WOL_CTL_ENA_MAGIC_PKT_UNIT);
2825 } else
2826 sky2_write16(hw, WOL_CTRL_STAT, WOL_CTL_DEFAULT);
2827
2828 return 0;
2829}
2830#endif
2831
Stephen Hemmingerfb173582005-12-09 11:34:56 -08002832static int sky2_get_coalesce(struct net_device *dev,
2833 struct ethtool_coalesce *ecmd)
2834{
2835 struct sky2_port *sky2 = netdev_priv(dev);
2836 struct sky2_hw *hw = sky2->hw;
2837
2838 if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_STOP)
2839 ecmd->tx_coalesce_usecs = 0;
2840 else {
2841 u32 clks = sky2_read32(hw, STAT_TX_TIMER_INI);
2842 ecmd->tx_coalesce_usecs = sky2_clk2us(hw, clks);
2843 }
2844 ecmd->tx_max_coalesced_frames = sky2_read16(hw, STAT_TX_IDX_TH);
2845
2846 if (sky2_read8(hw, STAT_LEV_TIMER_CTRL) == TIM_STOP)
2847 ecmd->rx_coalesce_usecs = 0;
2848 else {
2849 u32 clks = sky2_read32(hw, STAT_LEV_TIMER_INI);
2850 ecmd->rx_coalesce_usecs = sky2_clk2us(hw, clks);
2851 }
2852 ecmd->rx_max_coalesced_frames = sky2_read8(hw, STAT_FIFO_WM);
2853
2854 if (sky2_read8(hw, STAT_ISR_TIMER_CTRL) == TIM_STOP)
2855 ecmd->rx_coalesce_usecs_irq = 0;
2856 else {
2857 u32 clks = sky2_read32(hw, STAT_ISR_TIMER_INI);
2858 ecmd->rx_coalesce_usecs_irq = sky2_clk2us(hw, clks);
2859 }
2860
2861 ecmd->rx_max_coalesced_frames_irq = sky2_read8(hw, STAT_FIFO_ISR_WM);
2862
2863 return 0;
2864}
2865
2866/* Note: this affect both ports */
2867static int sky2_set_coalesce(struct net_device *dev,
2868 struct ethtool_coalesce *ecmd)
2869{
2870 struct sky2_port *sky2 = netdev_priv(dev);
2871 struct sky2_hw *hw = sky2->hw;
2872 const u32 tmin = sky2_clk2us(hw, 1);
2873 const u32 tmax = 5000;
2874
2875 if (ecmd->tx_coalesce_usecs != 0 &&
2876 (ecmd->tx_coalesce_usecs < tmin || ecmd->tx_coalesce_usecs > tmax))
2877 return -EINVAL;
2878
2879 if (ecmd->rx_coalesce_usecs != 0 &&
2880 (ecmd->rx_coalesce_usecs < tmin || ecmd->rx_coalesce_usecs > tmax))
2881 return -EINVAL;
2882
2883 if (ecmd->rx_coalesce_usecs_irq != 0 &&
2884 (ecmd->rx_coalesce_usecs_irq < tmin || ecmd->rx_coalesce_usecs_irq > tmax))
2885 return -EINVAL;
2886
2887 if (ecmd->tx_max_coalesced_frames > 0xffff)
2888 return -EINVAL;
2889 if (ecmd->rx_max_coalesced_frames > 0xff)
2890 return -EINVAL;
2891 if (ecmd->rx_max_coalesced_frames_irq > 0xff)
2892 return -EINVAL;
2893
2894 if (ecmd->tx_coalesce_usecs == 0)
2895 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP);
2896 else {
2897 sky2_write32(hw, STAT_TX_TIMER_INI,
2898 sky2_us2clk(hw, ecmd->tx_coalesce_usecs));
2899 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
2900 }
2901 sky2_write16(hw, STAT_TX_IDX_TH, ecmd->tx_max_coalesced_frames);
2902
2903 if (ecmd->rx_coalesce_usecs == 0)
2904 sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_STOP);
2905 else {
2906 sky2_write32(hw, STAT_LEV_TIMER_INI,
2907 sky2_us2clk(hw, ecmd->rx_coalesce_usecs));
2908 sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START);
2909 }
2910 sky2_write8(hw, STAT_FIFO_WM, ecmd->rx_max_coalesced_frames);
2911
2912 if (ecmd->rx_coalesce_usecs_irq == 0)
2913 sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_STOP);
2914 else {
Stephen Hemmingerd28d4872006-01-30 11:37:56 -08002915 sky2_write32(hw, STAT_ISR_TIMER_INI,
Stephen Hemmingerfb173582005-12-09 11:34:56 -08002916 sky2_us2clk(hw, ecmd->rx_coalesce_usecs_irq));
2917 sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START);
2918 }
2919 sky2_write8(hw, STAT_FIFO_ISR_WM, ecmd->rx_max_coalesced_frames_irq);
2920 return 0;
2921}
2922
Stephen Hemminger793b8832005-09-14 16:06:14 -07002923static void sky2_get_ringparam(struct net_device *dev,
2924 struct ethtool_ringparam *ering)
2925{
2926 struct sky2_port *sky2 = netdev_priv(dev);
2927
2928 ering->rx_max_pending = RX_MAX_PENDING;
2929 ering->rx_mini_max_pending = 0;
2930 ering->rx_jumbo_max_pending = 0;
2931 ering->tx_max_pending = TX_RING_SIZE - 1;
2932
2933 ering->rx_pending = sky2->rx_pending;
2934 ering->rx_mini_pending = 0;
2935 ering->rx_jumbo_pending = 0;
2936 ering->tx_pending = sky2->tx_pending;
2937}
2938
2939static int sky2_set_ringparam(struct net_device *dev,
2940 struct ethtool_ringparam *ering)
2941{
2942 struct sky2_port *sky2 = netdev_priv(dev);
2943 int err = 0;
2944
2945 if (ering->rx_pending > RX_MAX_PENDING ||
2946 ering->rx_pending < 8 ||
2947 ering->tx_pending < MAX_SKB_TX_LE ||
2948 ering->tx_pending > TX_RING_SIZE - 1)
2949 return -EINVAL;
2950
2951 if (netif_running(dev))
2952 sky2_down(dev);
2953
2954 sky2->rx_pending = ering->rx_pending;
2955 sky2->tx_pending = ering->tx_pending;
2956
Stephen Hemminger1b537562005-12-20 15:08:07 -08002957 if (netif_running(dev)) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07002958 err = sky2_up(dev);
Stephen Hemminger1b537562005-12-20 15:08:07 -08002959 if (err)
2960 dev_close(dev);
Stephen Hemminger6ed995b2005-12-20 15:08:08 -08002961 else
2962 sky2_set_multicast(dev);
Stephen Hemminger1b537562005-12-20 15:08:07 -08002963 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07002964
2965 return err;
2966}
2967
Stephen Hemminger793b8832005-09-14 16:06:14 -07002968static int sky2_get_regs_len(struct net_device *dev)
2969{
Stephen Hemminger6e4cbb32005-09-19 15:47:57 -07002970 return 0x4000;
Stephen Hemminger793b8832005-09-14 16:06:14 -07002971}
2972
2973/*
2974 * Returns copy of control register region
Stephen Hemminger6e4cbb32005-09-19 15:47:57 -07002975 * Note: access to the RAM address register set will cause timeouts.
Stephen Hemminger793b8832005-09-14 16:06:14 -07002976 */
2977static void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs,
2978 void *p)
2979{
2980 const struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002981 const void __iomem *io = sky2->hw->regs;
Stephen Hemminger793b8832005-09-14 16:06:14 -07002982
Stephen Hemminger6e4cbb32005-09-19 15:47:57 -07002983 BUG_ON(regs->len < B3_RI_WTO_R1);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002984 regs->version = 1;
Stephen Hemminger6e4cbb32005-09-19 15:47:57 -07002985 memset(p, 0, regs->len);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002986
Stephen Hemminger6e4cbb32005-09-19 15:47:57 -07002987 memcpy_fromio(p, io, B3_RAM_ADDR);
2988
2989 memcpy_fromio(p + B3_RI_WTO_R1,
2990 io + B3_RI_WTO_R1,
2991 regs->len - B3_RI_WTO_R1);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002992}
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002993
2994static struct ethtool_ops sky2_ethtool_ops = {
Stephen Hemminger793b8832005-09-14 16:06:14 -07002995 .get_settings = sky2_get_settings,
2996 .set_settings = sky2_set_settings,
2997 .get_drvinfo = sky2_get_drvinfo,
2998 .get_msglevel = sky2_get_msglevel,
2999 .set_msglevel = sky2_set_msglevel,
Stephen Hemminger9a7ae0a2005-09-27 15:28:42 -07003000 .nway_reset = sky2_nway_reset,
Stephen Hemminger793b8832005-09-14 16:06:14 -07003001 .get_regs_len = sky2_get_regs_len,
3002 .get_regs = sky2_get_regs,
3003 .get_link = ethtool_op_get_link,
3004 .get_sg = ethtool_op_get_sg,
3005 .set_sg = ethtool_op_set_sg,
3006 .get_tx_csum = ethtool_op_get_tx_csum,
3007 .set_tx_csum = ethtool_op_set_tx_csum,
3008 .get_tso = ethtool_op_get_tso,
3009 .set_tso = ethtool_op_set_tso,
3010 .get_rx_csum = sky2_get_rx_csum,
3011 .set_rx_csum = sky2_set_rx_csum,
3012 .get_strings = sky2_get_strings,
Stephen Hemmingerfb173582005-12-09 11:34:56 -08003013 .get_coalesce = sky2_get_coalesce,
3014 .set_coalesce = sky2_set_coalesce,
Stephen Hemminger793b8832005-09-14 16:06:14 -07003015 .get_ringparam = sky2_get_ringparam,
3016 .set_ringparam = sky2_set_ringparam,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003017 .get_pauseparam = sky2_get_pauseparam,
3018 .set_pauseparam = sky2_set_pauseparam,
3019#ifdef CONFIG_PM
Stephen Hemminger793b8832005-09-14 16:06:14 -07003020 .get_wol = sky2_get_wol,
3021 .set_wol = sky2_set_wol,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003022#endif
Stephen Hemminger793b8832005-09-14 16:06:14 -07003023 .phys_id = sky2_phys_id,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003024 .get_stats_count = sky2_get_stats_count,
3025 .get_ethtool_stats = sky2_get_ethtool_stats,
Stephen Hemminger2995bfb2005-09-28 10:01:03 -07003026 .get_perm_addr = ethtool_op_get_perm_addr,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003027};
3028
3029/* Initialize network device */
3030static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
3031 unsigned port, int highmem)
3032{
3033 struct sky2_port *sky2;
3034 struct net_device *dev = alloc_etherdev(sizeof(*sky2));
3035
3036 if (!dev) {
3037 printk(KERN_ERR "sky2 etherdev alloc failed");
3038 return NULL;
3039 }
3040
3041 SET_MODULE_OWNER(dev);
3042 SET_NETDEV_DEV(dev, &hw->pdev->dev);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08003043 dev->irq = hw->pdev->irq;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003044 dev->open = sky2_up;
3045 dev->stop = sky2_down;
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08003046 dev->do_ioctl = sky2_ioctl;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003047 dev->hard_start_xmit = sky2_xmit_frame;
3048 dev->get_stats = sky2_get_stats;
3049 dev->set_multicast_list = sky2_set_multicast;
3050 dev->set_mac_address = sky2_set_mac_address;
3051 dev->change_mtu = sky2_change_mtu;
3052 SET_ETHTOOL_OPS(dev, &sky2_ethtool_ops);
3053 dev->tx_timeout = sky2_tx_timeout;
3054 dev->watchdog_timeo = TX_WATCHDOG;
3055 if (port == 0)
3056 dev->poll = sky2_poll;
3057 dev->weight = NAPI_WEIGHT;
3058#ifdef CONFIG_NET_POLL_CONTROLLER
3059 dev->poll_controller = sky2_netpoll;
3060#endif
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003061
3062 sky2 = netdev_priv(dev);
3063 sky2->netdev = dev;
3064 sky2->hw = hw;
3065 sky2->msg_enable = netif_msg_init(debug, default_msg);
3066
3067 spin_lock_init(&sky2->tx_lock);
3068 /* Auto speed and flow control */
3069 sky2->autoneg = AUTONEG_ENABLE;
Stephen Hemminger585b56012005-12-09 11:35:10 -08003070 sky2->tx_pause = 1;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003071 sky2->rx_pause = 1;
3072 sky2->duplex = -1;
3073 sky2->speed = -1;
3074 sky2->advertising = sky2_supported_modes(hw);
Stephen Hemminger75d070c2005-12-09 11:35:11 -08003075
3076 /* Receive checksum disabled for Yukon XL
3077 * because of observed problems with incorrect
3078 * values when multiple packets are received in one interrupt
3079 */
3080 sky2->rx_csum = (hw->chip_id != CHIP_ID_YUKON_XL);
3081
Stephen Hemminger91c86df2005-12-09 11:34:57 -08003082 INIT_WORK(&sky2->phy_task, sky2_phy_task, sky2);
3083 init_MUTEX(&sky2->phy_sema);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003084 sky2->tx_pending = TX_DEF_PENDING;
3085 sky2->rx_pending = is_ec_a1(hw) ? 8 : RX_DEF_PENDING;
Stephen Hemminger734d1862005-12-09 11:35:00 -08003086 sky2->rx_bufsize = sky2_buf_size(ETH_DATA_LEN);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003087
3088 hw->dev[port] = dev;
3089
3090 sky2->port = port;
3091
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -08003092 dev->features |= NETIF_F_LLTX;
3093 if (hw->chip_id != CHIP_ID_YUKON_EC_U)
3094 dev->features |= NETIF_F_TSO;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003095 if (highmem)
3096 dev->features |= NETIF_F_HIGHDMA;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003097 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003098
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07003099#ifdef SKY2_VLAN_TAG_USED
3100 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
3101 dev->vlan_rx_register = sky2_vlan_rx_register;
3102 dev->vlan_rx_kill_vid = sky2_vlan_rx_kill_vid;
3103#endif
3104
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003105 /* read the mac address */
Stephen Hemminger793b8832005-09-14 16:06:14 -07003106 memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8, ETH_ALEN);
Stephen Hemminger2995bfb2005-09-28 10:01:03 -07003107 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003108
3109 /* device is off until link detection */
3110 netif_carrier_off(dev);
3111 netif_stop_queue(dev);
3112
3113 return dev;
3114}
3115
Stephen Hemminger28bd1812006-01-17 13:43:19 -08003116static void __devinit sky2_show_addr(struct net_device *dev)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003117{
3118 const struct sky2_port *sky2 = netdev_priv(dev);
3119
3120 if (netif_msg_probe(sky2))
3121 printk(KERN_INFO PFX "%s: addr %02x:%02x:%02x:%02x:%02x:%02x\n",
3122 dev->name,
3123 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
3124 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
3125}
3126
Stephen Hemminger4d52b482006-01-30 11:38:00 -08003127/* Handle software interrupt used during MSI test */
3128static irqreturn_t __devinit sky2_test_intr(int irq, void *dev_id,
3129 struct pt_regs *regs)
3130{
3131 struct sky2_hw *hw = dev_id;
3132 u32 status = sky2_read32(hw, B0_Y2_SP_ISRC2);
3133
3134 if (status == 0)
3135 return IRQ_NONE;
3136
3137 if (status & Y2_IS_IRQ_SW) {
3138 sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ);
3139 hw->msi = 1;
3140 }
3141 sky2_write32(hw, B0_Y2_SP_ICR, 2);
3142
3143 sky2_read32(hw, B0_IMSK);
3144 return IRQ_HANDLED;
3145}
3146
3147/* Test interrupt path by forcing a a software IRQ */
3148static int __devinit sky2_test_msi(struct sky2_hw *hw)
3149{
3150 struct pci_dev *pdev = hw->pdev;
3151 int i, err;
3152
3153 sky2_write32(hw, B0_IMSK, Y2_IS_IRQ_SW);
3154
3155 err = request_irq(pdev->irq, sky2_test_intr, SA_SHIRQ, DRV_NAME, hw);
3156 if (err) {
3157 printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
3158 pci_name(pdev), pdev->irq);
3159 return err;
3160 }
3161
3162 sky2_write8(hw, B0_CTST, CS_ST_SW_IRQ);
3163 wmb();
3164
3165 for (i = 0; i < 10; i++) {
3166 barrier();
3167 if (hw->msi)
3168 goto found;
3169 mdelay(1);
3170 }
3171
3172 err = -EOPNOTSUPP;
3173 sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ);
3174 found:
3175 sky2_write32(hw, B0_IMSK, 0);
3176
3177 free_irq(pdev->irq, hw);
3178
3179 return err;
3180}
3181
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003182static int __devinit sky2_probe(struct pci_dev *pdev,
3183 const struct pci_device_id *ent)
3184{
Stephen Hemminger793b8832005-09-14 16:06:14 -07003185 struct net_device *dev, *dev1 = NULL;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003186 struct sky2_hw *hw;
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07003187 int err, pm_cap, using_dac = 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003188
Stephen Hemminger793b8832005-09-14 16:06:14 -07003189 err = pci_enable_device(pdev);
3190 if (err) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003191 printk(KERN_ERR PFX "%s cannot enable PCI device\n",
3192 pci_name(pdev));
3193 goto err_out;
3194 }
3195
Stephen Hemminger793b8832005-09-14 16:06:14 -07003196 err = pci_request_regions(pdev, DRV_NAME);
3197 if (err) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003198 printk(KERN_ERR PFX "%s cannot obtain PCI resources\n",
3199 pci_name(pdev));
Stephen Hemminger793b8832005-09-14 16:06:14 -07003200 goto err_out;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003201 }
3202
3203 pci_set_master(pdev);
3204
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07003205 /* Find power-management capability. */
3206 pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
3207 if (pm_cap == 0) {
3208 printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
3209 "aborting.\n");
3210 err = -EIO;
3211 goto err_out_free_regions;
3212 }
3213
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08003214 if (sizeof(dma_addr_t) > sizeof(u32) &&
3215 !(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
3216 using_dac = 1;
3217 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
3218 if (err < 0) {
3219 printk(KERN_ERR PFX "%s unable to obtain 64 bit DMA "
3220 "for consistent allocations\n", pci_name(pdev));
3221 goto err_out_free_regions;
3222 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003223
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08003224 } else {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003225 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
3226 if (err) {
3227 printk(KERN_ERR PFX "%s no usable DMA configuration\n",
3228 pci_name(pdev));
3229 goto err_out_free_regions;
3230 }
3231 }
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08003232
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003233#ifdef __BIG_ENDIAN
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07003234 /* byte swap descriptors in hardware */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003235 {
3236 u32 reg;
3237
3238 pci_read_config_dword(pdev, PCI_DEV_REG2, &reg);
3239 reg |= PCI_REV_DESC;
3240 pci_write_config_dword(pdev, PCI_DEV_REG2, reg);
3241 }
3242#endif
3243
3244 err = -ENOMEM;
Stephen Hemminger6aad85d2006-01-17 13:43:18 -08003245 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003246 if (!hw) {
3247 printk(KERN_ERR PFX "%s: cannot allocate hardware struct\n",
3248 pci_name(pdev));
3249 goto err_out_free_regions;
3250 }
3251
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003252 hw->pdev = pdev;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003253
3254 hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
3255 if (!hw->regs) {
3256 printk(KERN_ERR PFX "%s: cannot map device registers\n",
3257 pci_name(pdev));
3258 goto err_out_free_hw;
3259 }
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07003260 hw->pm_cap = pm_cap;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003261
Stephen Hemminger08c06d82006-01-30 11:37:54 -08003262 /* ring for status responses */
3263 hw->st_le = pci_alloc_consistent(hw->pdev, STATUS_LE_BYTES,
3264 &hw->st_dma);
3265 if (!hw->st_le)
3266 goto err_out_iounmap;
3267
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003268 err = sky2_reset(hw);
3269 if (err)
Stephen Hemminger793b8832005-09-14 16:06:14 -07003270 goto err_out_iounmap;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003271
shemminger@osdl.org5f4f9dc2005-11-30 11:45:23 -08003272 printk(KERN_INFO PFX "v%s addr 0x%lx irq %d Yukon-%s (0x%x) rev %d\n",
3273 DRV_VERSION, pci_resource_start(pdev, 0), pdev->irq,
Stephen Hemminger92f965e2005-12-09 11:34:53 -08003274 yukon2_name[hw->chip_id - CHIP_ID_YUKON_XL],
Stephen Hemminger793b8832005-09-14 16:06:14 -07003275 hw->chip_id, hw->chip_rev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003276
Stephen Hemminger793b8832005-09-14 16:06:14 -07003277 dev = sky2_init_netdev(hw, 0, using_dac);
3278 if (!dev)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003279 goto err_out_free_pci;
3280
Stephen Hemminger793b8832005-09-14 16:06:14 -07003281 err = register_netdev(dev);
3282 if (err) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003283 printk(KERN_ERR PFX "%s: cannot register net device\n",
3284 pci_name(pdev));
3285 goto err_out_free_netdev;
3286 }
3287
3288 sky2_show_addr(dev);
3289
3290 if (hw->ports > 1 && (dev1 = sky2_init_netdev(hw, 1, using_dac))) {
3291 if (register_netdev(dev1) == 0)
3292 sky2_show_addr(dev1);
3293 else {
3294 /* Failure to register second port need not be fatal */
Stephen Hemminger793b8832005-09-14 16:06:14 -07003295 printk(KERN_WARNING PFX
3296 "register of second port failed\n");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003297 hw->dev[1] = NULL;
3298 free_netdev(dev1);
3299 }
3300 }
3301
Stephen Hemminger4d52b482006-01-30 11:38:00 -08003302 if (!disable_msi && pci_enable_msi(pdev) == 0) {
3303 err = sky2_test_msi(hw);
3304 if (err == -EOPNOTSUPP) {
3305 /* MSI test failed, go back to INTx mode */
3306 printk(KERN_WARNING PFX "%s: No interrupt was generated using MSI, "
3307 "switching to INTx mode. Please report this failure to "
3308 "the PCI maintainer and include system chipset information.\n",
3309 pci_name(pdev));
3310 pci_disable_msi(pdev);
3311 }
3312 else if (err)
3313 goto err_out_unregister;
3314 }
3315
Stephen Hemmingerdb992c92006-01-30 11:37:59 -08003316 err = request_irq(pdev->irq, sky2_intr, SA_SHIRQ | SA_SAMPLE_RANDOM,
3317 DRV_NAME, hw);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003318 if (err) {
3319 printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
3320 pci_name(pdev), pdev->irq);
3321 goto err_out_unregister;
3322 }
3323
3324 hw->intr_mask = Y2_IS_BASE;
3325 sky2_write32(hw, B0_IMSK, hw->intr_mask);
3326
3327 pci_set_drvdata(pdev, hw);
3328
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003329 return 0;
3330
Stephen Hemminger793b8832005-09-14 16:06:14 -07003331err_out_unregister:
Stephen Hemminger4d52b482006-01-30 11:38:00 -08003332 if (hw->msi)
3333 pci_disable_msi(pdev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003334 if (dev1) {
3335 unregister_netdev(dev1);
3336 free_netdev(dev1);
3337 }
3338 unregister_netdev(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003339err_out_free_netdev:
3340 free_netdev(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003341err_out_free_pci:
Stephen Hemminger793b8832005-09-14 16:06:14 -07003342 sky2_write8(hw, B0_CTST, CS_RST_SET);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003343 pci_free_consistent(hw->pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma);
3344err_out_iounmap:
3345 iounmap(hw->regs);
3346err_out_free_hw:
3347 kfree(hw);
3348err_out_free_regions:
3349 pci_release_regions(pdev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003350 pci_disable_device(pdev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003351err_out:
3352 return err;
3353}
3354
3355static void __devexit sky2_remove(struct pci_dev *pdev)
3356{
Stephen Hemminger793b8832005-09-14 16:06:14 -07003357 struct sky2_hw *hw = pci_get_drvdata(pdev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003358 struct net_device *dev0, *dev1;
3359
Stephen Hemminger793b8832005-09-14 16:06:14 -07003360 if (!hw)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003361 return;
3362
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003363 dev0 = hw->dev[0];
Stephen Hemminger793b8832005-09-14 16:06:14 -07003364 dev1 = hw->dev[1];
3365 if (dev1)
3366 unregister_netdev(dev1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003367 unregister_netdev(dev0);
3368
Stephen Hemminger793b8832005-09-14 16:06:14 -07003369 sky2_write32(hw, B0_IMSK, 0);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07003370 sky2_set_power_state(hw, PCI_D3hot);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003371 sky2_write16(hw, B0_Y2LED, LED_STAT_OFF);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003372 sky2_write8(hw, B0_CTST, CS_RST_SET);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07003373 sky2_read8(hw, B0_CTST);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003374
3375 free_irq(pdev->irq, hw);
Stephen Hemminger4d52b482006-01-30 11:38:00 -08003376 if (hw->msi)
3377 pci_disable_msi(pdev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003378 pci_free_consistent(pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003379 pci_release_regions(pdev);
3380 pci_disable_device(pdev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003381
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003382 if (dev1)
3383 free_netdev(dev1);
3384 free_netdev(dev0);
3385 iounmap(hw->regs);
3386 kfree(hw);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07003387
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003388 pci_set_drvdata(pdev, NULL);
3389}
3390
3391#ifdef CONFIG_PM
3392static int sky2_suspend(struct pci_dev *pdev, pm_message_t state)
3393{
Stephen Hemminger793b8832005-09-14 16:06:14 -07003394 struct sky2_hw *hw = pci_get_drvdata(pdev);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07003395 int i;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003396
3397 for (i = 0; i < 2; i++) {
3398 struct net_device *dev = hw->dev[i];
3399
3400 if (dev) {
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07003401 if (!netif_running(dev))
3402 continue;
3403
3404 sky2_down(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003405 netif_device_detach(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003406 }
3407 }
3408
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07003409 return sky2_set_power_state(hw, pci_choose_state(pdev, state));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003410}
3411
3412static int sky2_resume(struct pci_dev *pdev)
3413{
Stephen Hemminger793b8832005-09-14 16:06:14 -07003414 struct sky2_hw *hw = pci_get_drvdata(pdev);
Stephen Hemminger08c06d82006-01-30 11:37:54 -08003415 int i, err;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003416
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003417 pci_restore_state(pdev);
3418 pci_enable_wake(pdev, PCI_D0, 0);
Stephen Hemminger08c06d82006-01-30 11:37:54 -08003419 err = sky2_set_power_state(hw, PCI_D0);
3420 if (err)
3421 goto out;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003422
Stephen Hemminger08c06d82006-01-30 11:37:54 -08003423 err = sky2_reset(hw);
3424 if (err)
3425 goto out;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003426
3427 for (i = 0; i < 2; i++) {
3428 struct net_device *dev = hw->dev[i];
Stephen Hemminger08c06d82006-01-30 11:37:54 -08003429 if (dev && netif_running(dev)) {
3430 netif_device_attach(dev);
3431 err = sky2_up(dev);
3432 if (err) {
3433 printk(KERN_ERR PFX "%s: could not up: %d\n",
3434 dev->name, err);
3435 dev_close(dev);
3436 break;
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07003437 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003438 }
3439 }
Stephen Hemminger08c06d82006-01-30 11:37:54 -08003440out:
3441 return err;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003442}
3443#endif
3444
3445static struct pci_driver sky2_driver = {
Stephen Hemminger793b8832005-09-14 16:06:14 -07003446 .name = DRV_NAME,
3447 .id_table = sky2_id_table,
3448 .probe = sky2_probe,
3449 .remove = __devexit_p(sky2_remove),
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003450#ifdef CONFIG_PM
Stephen Hemminger793b8832005-09-14 16:06:14 -07003451 .suspend = sky2_suspend,
3452 .resume = sky2_resume,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003453#endif
3454};
3455
3456static int __init sky2_init_module(void)
3457{
shemminger@osdl.org50241c42005-11-30 11:45:22 -08003458 return pci_register_driver(&sky2_driver);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003459}
3460
3461static void __exit sky2_cleanup_module(void)
3462{
3463 pci_unregister_driver(&sky2_driver);
3464}
3465
3466module_init(sky2_init_module);
3467module_exit(sky2_cleanup_module);
3468
3469MODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver");
3470MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>");
3471MODULE_LICENSE("GPL");
shemminger@osdl.org5f4f9dc2005-11-30 11:45:23 -08003472MODULE_VERSION(DRV_VERSION);