blob: dfff8e56a51ef7d9db0acf618fd04921950315d9 [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
Stephen Hemminger798b6b12006-10-22 20:16:57 -070013 * the Free Software Foundation; either version 2 of the License.
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070014 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Stephen Hemminger793b8832005-09-14 16:06:14 -070017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070018 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
Stephen Hemminger793b8832005-09-14 16:06:14 -070025#include <linux/crc32.h>
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070026#include <linux/kernel.h>
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070027#include <linux/module.h>
28#include <linux/netdevice.h>
Andrew Mortond0bbccf2005-11-10 15:29:27 -080029#include <linux/dma-mapping.h>
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070030#include <linux/etherdevice.h>
31#include <linux/ethtool.h>
32#include <linux/pci.h>
33#include <linux/ip.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030034#include <net/ip.h>
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070035#include <linux/tcp.h>
36#include <linux/in.h>
37#include <linux/delay.h>
Stephen Hemminger91c86df2005-12-09 11:34:57 -080038#include <linux/workqueue.h>
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -070039#include <linux/if_vlan.h>
Stephen Hemmingerd70cd512005-12-09 11:35:09 -080040#include <linux/prefetch.h>
Stephen Hemminger3cf26752007-07-09 15:33:35 -070041#include <linux/debugfs.h>
shemminger@osdl.orgef743d32005-11-30 11:45:12 -080042#include <linux/mii.h>
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070043
44#include <asm/irq.h>
45
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -070046#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
47#define SKY2_VLAN_TAG_USED 1
48#endif
49
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070050#include "sky2.h"
51
52#define DRV_NAME "sky2"
stephen hemmingercfc08612010-02-12 06:58:07 +000053#define DRV_VERSION "1.27"
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070054#define PFX DRV_NAME " "
55
56/*
57 * The Yukon II chipset takes 64 bit command blocks (called list elements)
58 * that are organized into three (receive, transmit, status) different rings
Stephen Hemminger14d02632006-09-26 11:57:43 -070059 * similar to Tigon3.
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070060 */
61
Stephen Hemminger14d02632006-09-26 11:57:43 -070062#define RX_LE_SIZE 1024
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070063#define RX_LE_BYTES (RX_LE_SIZE*sizeof(struct sky2_rx_le))
Stephen Hemminger14d02632006-09-26 11:57:43 -070064#define RX_MAX_PENDING (RX_LE_SIZE/6 - 2)
shemminger@osdl.org13210ce2005-11-30 11:45:14 -080065#define RX_DEF_PENDING RX_MAX_PENDING
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070066
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +000067/* This is the worst case number of transmit list elements for a single skb:
Stephen Hemminger07e31632009-09-14 06:12:55 +000068 VLAN:GSO + CKSUM + Data + skb_frags * DMA */
69#define MAX_SKB_TX_LE (2 + (sizeof(dma_addr_t)/sizeof(u32))*(MAX_SKB_FRAGS+1))
Stephen Hemmingere9c1be82009-06-17 07:30:37 +000070#define TX_MIN_PENDING (MAX_SKB_TX_LE+1)
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +000071#define TX_MAX_PENDING 4096
72#define TX_DEF_PENDING 127
Stephen Hemminger793b8832005-09-14 16:06:14 -070073
74#define STATUS_RING_SIZE 2048 /* 2 ports * (TX + 2*RX) */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070075#define STATUS_LE_BYTES (STATUS_RING_SIZE*sizeof(struct sky2_status_le))
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070076#define TX_WATCHDOG (5 * HZ)
77#define NAPI_WEIGHT 64
78#define PHY_RETRIES 1000
79
Stephen Hemmingerf4331a62007-07-09 15:33:39 -070080#define SKY2_EEPROM_MAGIC 0x9955aabb
81
82
Stephen Hemmingercb5d9542006-05-08 15:11:29 -070083#define RING_NEXT(x,s) (((x)+1) & ((s)-1))
84
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070085static const u32 default_msg =
Stephen Hemminger793b8832005-09-14 16:06:14 -070086 NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK
87 | NETIF_MSG_TIMER | NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR
Stephen Hemminger3be92a72006-01-17 13:43:17 -080088 | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070089
Stephen Hemminger793b8832005-09-14 16:06:14 -070090static int debug = -1; /* defaults above */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -070091module_param(debug, int, 0);
92MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
93
Stephen Hemminger14d02632006-09-26 11:57:43 -070094static int copybreak __read_mostly = 128;
Stephen Hemmingerbdb5c582005-12-09 11:34:55 -080095module_param(copybreak, int, 0);
96MODULE_PARM_DESC(copybreak, "Receive copy threshold");
97
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -080098static int disable_msi = 0;
99module_param(disable_msi, int, 0);
100MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
101
Stephen Hemmingere6cac9b2008-06-17 09:04:26 -0700102static DEFINE_PCI_DEVICE_TABLE(sky2_id_table) = {
Stephen Hemmingere5b74c72006-12-04 15:53:36 -0800103 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9000) }, /* SK-9Sxx */
104 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) }, /* SK-9Exx */
Stephen Hemmingere30a4ac2009-10-29 06:37:05 +0000105 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E01) }, /* SK-9E21M */
Stephen Hemminger2d2a3872006-05-17 14:37:04 -0700106 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b00) }, /* DGE-560T */
Stephen Hemminger2f4a66a2006-09-01 14:52:04 -0700107 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4001) }, /* DGE-550SX */
Stephen Hemminger508f89e2006-12-01 14:29:34 -0800108 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B02) }, /* DGE-560SX */
Stephen Hemmingerf1a0b6f2007-02-06 10:45:44 -0800109 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B03) }, /* DGE-550T */
Stephen Hemmingere5b74c72006-12-04 15:53:36 -0800110 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4340) }, /* 88E8021 */
111 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4341) }, /* 88E8022 */
112 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4342) }, /* 88E8061 */
113 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4343) }, /* 88E8062 */
114 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4344) }, /* 88E8021 */
115 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4345) }, /* 88E8022 */
116 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4346) }, /* 88E8061 */
117 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4347) }, /* 88E8062 */
118 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4350) }, /* 88E8035 */
119 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4351) }, /* 88E8036 */
120 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4352) }, /* 88E8038 */
121 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4353) }, /* 88E8039 */
Stephen Hemminger05745c42007-09-19 15:36:45 -0700122 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4354) }, /* 88E8040 */
Stephen Hemmingera3b4fce2008-06-14 10:32:15 -0700123 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4355) }, /* 88E8040T */
Stephen Hemmingere5b74c72006-12-04 15:53:36 -0800124 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4356) }, /* 88EC033 */
Stephen Hemminger5a37a682007-11-08 08:20:17 -0800125 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4357) }, /* 88E8042 */
Stephen Hemminger05745c42007-09-19 15:36:45 -0700126 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x435A) }, /* 88E8048 */
Stephen Hemmingere5b74c72006-12-04 15:53:36 -0800127 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4360) }, /* 88E8052 */
128 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4361) }, /* 88E8050 */
129 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4362) }, /* 88E8053 */
130 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4363) }, /* 88E8055 */
131 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4364) }, /* 88E8056 */
Stephen Hemminger05745c42007-09-19 15:36:45 -0700132 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4365) }, /* 88E8070 */
Stephen Hemmingere5b74c72006-12-04 15:53:36 -0800133 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4366) }, /* 88EC036 */
134 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4367) }, /* 88EC032 */
135 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4368) }, /* 88EC034 */
Stephen Hemmingerf1a0b6f2007-02-06 10:45:44 -0800136 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4369) }, /* 88EC042 */
137 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436A) }, /* 88E8058 */
Stephen Hemminger69161612007-06-04 17:23:26 -0700138 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436B) }, /* 88E8071 */
Stephen Hemminger5a37a682007-11-08 08:20:17 -0800139 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436C) }, /* 88E8072 */
Stephen Hemmingered4d4162008-01-10 16:14:14 -0800140 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436D) }, /* 88E8055 */
141 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4370) }, /* 88E8075 */
Stephen Hemminger0ce8b982008-06-17 09:04:27 -0700142 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4380) }, /* 88E8057 */
Stephen Hemminger0f5aac72009-10-29 06:37:09 +0000143 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4381) }, /* 88E8059 */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700144 { 0 }
145};
Stephen Hemminger793b8832005-09-14 16:06:14 -0700146
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700147MODULE_DEVICE_TABLE(pci, sky2_id_table);
148
149/* Avoid conditionals by using array */
150static const unsigned txqaddr[] = { Q_XA1, Q_XA2 };
151static const unsigned rxqaddr[] = { Q_R1, Q_R2 };
Stephen Hemmingerf4ea4312006-05-09 14:46:54 -0700152static const u32 portirq_msk[] = { Y2_IS_PORT_1, Y2_IS_PORT_2 };
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700153
Stephen Hemmingerd1b139c2007-09-05 16:56:19 +0100154static void sky2_set_multicast(struct net_device *dev);
155
Stephen Hemmingeraf043aa2007-11-05 15:52:10 -0800156/* Access to PHY via serial interconnect */
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800157static int gm_phy_write(struct sky2_hw *hw, unsigned port, u16 reg, u16 val)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700158{
159 int i;
160
161 gma_write16(hw, port, GM_SMI_DATA, val);
162 gma_write16(hw, port, GM_SMI_CTRL,
163 GM_SMI_CT_PHY_AD(PHY_ADDR_MARV) | GM_SMI_CT_REG_AD(reg));
164
165 for (i = 0; i < PHY_RETRIES; i++) {
Stephen Hemmingeraf043aa2007-11-05 15:52:10 -0800166 u16 ctrl = gma_read16(hw, port, GM_SMI_CTRL);
167 if (ctrl == 0xffff)
168 goto io_error;
169
170 if (!(ctrl & GM_SMI_CT_BUSY))
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800171 return 0;
Stephen Hemmingeraf043aa2007-11-05 15:52:10 -0800172
173 udelay(10);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700174 }
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800175
Stephen Hemmingeraf043aa2007-11-05 15:52:10 -0800176 dev_warn(&hw->pdev->dev,"%s: phy write timeout\n", hw->dev[port]->name);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800177 return -ETIMEDOUT;
Stephen Hemmingeraf043aa2007-11-05 15:52:10 -0800178
179io_error:
180 dev_err(&hw->pdev->dev, "%s: phy I/O error\n", hw->dev[port]->name);
181 return -EIO;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700182}
183
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800184static int __gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg, u16 *val)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700185{
186 int i;
187
Stephen Hemminger793b8832005-09-14 16:06:14 -0700188 gma_write16(hw, port, GM_SMI_CTRL, GM_SMI_CT_PHY_AD(PHY_ADDR_MARV)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700189 | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD);
190
191 for (i = 0; i < PHY_RETRIES; i++) {
Stephen Hemmingeraf043aa2007-11-05 15:52:10 -0800192 u16 ctrl = gma_read16(hw, port, GM_SMI_CTRL);
193 if (ctrl == 0xffff)
194 goto io_error;
195
196 if (ctrl & GM_SMI_CT_RD_VAL) {
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800197 *val = gma_read16(hw, port, GM_SMI_DATA);
198 return 0;
199 }
200
Stephen Hemmingeraf043aa2007-11-05 15:52:10 -0800201 udelay(10);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700202 }
203
Stephen Hemmingeraf043aa2007-11-05 15:52:10 -0800204 dev_warn(&hw->pdev->dev, "%s: phy read timeout\n", hw->dev[port]->name);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800205 return -ETIMEDOUT;
Stephen Hemmingeraf043aa2007-11-05 15:52:10 -0800206io_error:
207 dev_err(&hw->pdev->dev, "%s: phy I/O error\n", hw->dev[port]->name);
208 return -EIO;
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800209}
210
Stephen Hemmingeraf043aa2007-11-05 15:52:10 -0800211static inline u16 gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg)
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800212{
213 u16 v;
Stephen Hemmingeraf043aa2007-11-05 15:52:10 -0800214 __gm_phy_read(hw, port, reg, &v);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -0800215 return v;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700216}
217
Stephen Hemmingerae306cc2006-12-20 13:06:36 -0800218
219static void sky2_power_on(struct sky2_hw *hw)
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700220{
Stephen Hemmingerae306cc2006-12-20 13:06:36 -0800221 /* switch power to VCC (WA for VAUX problem) */
222 sky2_write8(hw, B0_POWER_CTRL,
223 PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700224
Stephen Hemmingerae306cc2006-12-20 13:06:36 -0800225 /* disable Core Clock Division, */
226 sky2_write32(hw, B2_Y2_CLK_CTRL, Y2_CLK_DIV_DIS);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700227
Stephen Hemmingerae306cc2006-12-20 13:06:36 -0800228 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
229 /* enable bits are inverted */
230 sky2_write8(hw, B2_Y2_CLK_GATE,
231 Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
232 Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
233 Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
234 else
235 sky2_write8(hw, B2_Y2_CLK_GATE, 0);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700236
Stephen Hemmingerea76e632007-09-19 15:36:44 -0700237 if (hw->flags & SKY2_HW_ADV_POWER_CTL) {
Stephen Hemmingerfc99fe02007-06-04 17:23:22 -0700238 u32 reg;
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700239
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -0800240 sky2_pci_write32(hw, PCI_DEV_REG3, 0);
Stephen Hemmingerb2345772007-08-21 14:34:02 -0700241
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -0800242 reg = sky2_pci_read32(hw, PCI_DEV_REG4);
Stephen Hemmingerfc99fe02007-06-04 17:23:22 -0700243 /* set all bits to 0 except bits 15..12 and 8 */
244 reg &= P_ASPM_CONTROL_MSK;
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -0800245 sky2_pci_write32(hw, PCI_DEV_REG4, reg);
Stephen Hemmingerfc99fe02007-06-04 17:23:22 -0700246
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -0800247 reg = sky2_pci_read32(hw, PCI_DEV_REG5);
Stephen Hemmingerfc99fe02007-06-04 17:23:22 -0700248 /* set all bits to 0 except bits 28 & 27 */
249 reg &= P_CTL_TIM_VMAIN_AV_MSK;
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -0800250 sky2_pci_write32(hw, PCI_DEV_REG5, reg);
Stephen Hemmingerfc99fe02007-06-04 17:23:22 -0700251
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -0800252 sky2_pci_write32(hw, PCI_CFG_REG_1, 0);
Stephen Hemminger8f709202007-06-04 17:23:25 -0700253
stephen hemminger5f8ae5c2010-02-12 06:57:59 +0000254 sky2_write16(hw, B0_CTST, Y2_HW_WOL_ON);
255
Stephen Hemminger8f709202007-06-04 17:23:25 -0700256 /* Enable workaround for dev 4.107 on Yukon-Ultra & Extreme */
257 reg = sky2_read32(hw, B2_GP_IO);
258 reg |= GLB_GPIO_STAT_RACE_DIS;
259 sky2_write32(hw, B2_GP_IO, reg);
Stephen Hemmingerb2345772007-08-21 14:34:02 -0700260
261 sky2_read32(hw, B2_GP_IO);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700262 }
Stephen Hemminger10547ae2009-08-31 07:31:41 +0000263
264 /* Turn on "driver loaded" LED */
265 sky2_write16(hw, B0_CTST, Y2_LED_STAT_ON);
Stephen Hemmingerae306cc2006-12-20 13:06:36 -0800266}
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700267
Stephen Hemmingerae306cc2006-12-20 13:06:36 -0800268static void sky2_power_aux(struct sky2_hw *hw)
269{
270 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
271 sky2_write8(hw, B2_Y2_CLK_GATE, 0);
272 else
273 /* enable bits are inverted */
274 sky2_write8(hw, B2_Y2_CLK_GATE,
275 Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
276 Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
277 Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
278
Stephen Hemmingerc23ddf82009-09-03 06:16:25 +0000279 /* switch power to VAUX if supported and PME from D3cold */
280 if ( (sky2_read32(hw, B0_CTST) & Y2_VAUX_AVAIL) &&
281 pci_pme_capable(hw->pdev, PCI_D3cold))
Stephen Hemmingerae306cc2006-12-20 13:06:36 -0800282 sky2_write8(hw, B0_POWER_CTRL,
283 (PC_VAUX_ENA | PC_VCC_ENA |
284 PC_VAUX_ON | PC_VCC_OFF));
Stephen Hemminger10547ae2009-08-31 07:31:41 +0000285
286 /* turn off "driver loaded LED" */
287 sky2_write16(hw, B0_CTST, Y2_LED_STAT_OFF);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700288}
289
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -0700290static void sky2_gmac_reset(struct sky2_hw *hw, unsigned port)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700291{
292 u16 reg;
293
294 /* disable all GMAC IRQ's */
295 sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700296
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700297 gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */
298 gma_write16(hw, port, GM_MC_ADDR_H2, 0);
299 gma_write16(hw, port, GM_MC_ADDR_H3, 0);
300 gma_write16(hw, port, GM_MC_ADDR_H4, 0);
301
302 reg = gma_read16(hw, port, GM_RX_CTRL);
303 reg |= GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA;
304 gma_write16(hw, port, GM_RX_CTRL, reg);
305}
306
Stephen Hemminger16ad91e2006-10-17 10:24:13 -0700307/* flow control to advertise bits */
308static const u16 copper_fc_adv[] = {
309 [FC_NONE] = 0,
310 [FC_TX] = PHY_M_AN_ASP,
311 [FC_RX] = PHY_M_AN_PC,
312 [FC_BOTH] = PHY_M_AN_PC | PHY_M_AN_ASP,
313};
314
315/* flow control to advertise bits when using 1000BaseX */
316static const u16 fiber_fc_adv[] = {
Stephen Hemmingerdf3fe1f2007-10-11 19:48:04 -0700317 [FC_NONE] = PHY_M_P_NO_PAUSE_X,
Stephen Hemminger16ad91e2006-10-17 10:24:13 -0700318 [FC_TX] = PHY_M_P_ASYM_MD_X,
319 [FC_RX] = PHY_M_P_SYM_MD_X,
Stephen Hemmingerdf3fe1f2007-10-11 19:48:04 -0700320 [FC_BOTH] = PHY_M_P_BOTH_MD_X,
Stephen Hemminger16ad91e2006-10-17 10:24:13 -0700321};
322
323/* flow control to GMA disable bits */
324static const u16 gm_fc_disable[] = {
325 [FC_NONE] = GM_GPCR_FC_RX_DIS | GM_GPCR_FC_TX_DIS,
326 [FC_TX] = GM_GPCR_FC_RX_DIS,
327 [FC_RX] = GM_GPCR_FC_TX_DIS,
328 [FC_BOTH] = 0,
329};
330
331
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700332static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
333{
334 struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700335 u16 ctrl, ct1000, adv, pg, ledctrl, ledover, reg;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700336
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700337 if ( (sky2->flags & SKY2_FLAG_AUTO_SPEED) &&
Stephen Hemmingerea76e632007-09-19 15:36:44 -0700338 !(hw->flags & SKY2_HW_NEWER_PHY)) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700339 u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
340
341 ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
Stephen Hemminger793b8832005-09-14 16:06:14 -0700342 PHY_M_EC_MAC_S_MSK);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700343 ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ);
344
Stephen Hemminger53419c62007-05-14 12:38:11 -0700345 /* on PHY 88E1040 Rev.D0 (and newer) downshift control changed */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700346 if (hw->chip_id == CHIP_ID_YUKON_EC)
Stephen Hemminger53419c62007-05-14 12:38:11 -0700347 /* set downshift counter to 3x and enable downshift */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700348 ectrl |= PHY_M_EC_DSC_2(2) | PHY_M_EC_DOWN_S_ENA;
349 else
Stephen Hemminger53419c62007-05-14 12:38:11 -0700350 /* set master & slave downshift counter to 1x */
351 ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700352
353 gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl);
354 }
355
356 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700357 if (sky2_is_copper(hw)) {
Stephen Hemminger05745c42007-09-19 15:36:45 -0700358 if (!(hw->flags & SKY2_HW_GIGABIT)) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700359 /* enable automatic crossover */
360 ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO) >> 1;
Stephen Hemminger6d3105d2007-09-24 19:34:51 -0700361
362 if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
363 hw->chip_rev == CHIP_REV_YU_FE2_A0) {
364 u16 spec;
365
366 /* Enable Class A driver for FE+ A0 */
367 spec = gm_phy_read(hw, port, PHY_MARV_FE_SPEC_2);
368 spec |= PHY_M_FESC_SEL_CL_A;
369 gm_phy_write(hw, port, PHY_MARV_FE_SPEC_2, spec);
370 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700371 } else {
372 /* disable energy detect */
373 ctrl &= ~PHY_M_PC_EN_DET_MSK;
374
375 /* enable automatic crossover */
376 ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO);
377
Stephen Hemminger53419c62007-05-14 12:38:11 -0700378 /* downshift on PHY 88E1112 and 88E1149 is changed */
Joe Perches8e95a202009-12-03 07:58:21 +0000379 if ( (sky2->flags & SKY2_FLAG_AUTO_SPEED) &&
380 (hw->flags & SKY2_HW_NEWER_PHY)) {
Stephen Hemminger53419c62007-05-14 12:38:11 -0700381 /* set downshift counter to 3x and enable downshift */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700382 ctrl &= ~PHY_M_PC_DSC_MSK;
383 ctrl |= PHY_M_PC_DSC(2) | PHY_M_PC_DOWN_S_ENA;
384 }
385 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700386 } else {
387 /* workaround for deviation #4.88 (CRC errors) */
388 /* disable Automatic Crossover */
389
390 ctrl &= ~PHY_M_PC_MDIX_MSK;
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700391 }
392
393 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
394
395 /* special setup for PHY 88E1112 Fiber */
Stephen Hemmingerea76e632007-09-19 15:36:44 -0700396 if (hw->chip_id == CHIP_ID_YUKON_XL && (hw->flags & SKY2_HW_FIBRE_PHY)) {
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700397 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
398
399 /* Fiber: select 1000BASE-X only mode MAC Specific Ctrl Reg. */
400 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2);
401 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
402 ctrl &= ~PHY_M_MAC_MD_MSK;
403 ctrl |= PHY_M_MAC_MODE_SEL(PHY_M_MAC_MD_1000BX);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700404 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
405
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700406 if (hw->pmd_type == 'P') {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700407 /* select page 1 to access Fiber registers */
408 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 1);
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700409
410 /* for SFP-module set SIGDET polarity to low */
411 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
412 ctrl |= PHY_M_FIB_SIGD_POL;
Stephen Hemminger34dd9622007-05-24 15:22:45 -0700413 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700414 }
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700415
416 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700417 }
418
Stephen Hemminger7800fdd2006-10-17 10:24:10 -0700419 ctrl = PHY_CT_RESET;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700420 ct1000 = 0;
421 adv = PHY_AN_CSMA;
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700422 reg = 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700423
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700424 if (sky2->flags & SKY2_FLAG_AUTO_SPEED) {
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700425 if (sky2_is_copper(hw)) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700426 if (sky2->advertising & ADVERTISED_1000baseT_Full)
427 ct1000 |= PHY_M_1000C_AFD;
428 if (sky2->advertising & ADVERTISED_1000baseT_Half)
429 ct1000 |= PHY_M_1000C_AHD;
430 if (sky2->advertising & ADVERTISED_100baseT_Full)
431 adv |= PHY_M_AN_100_FD;
432 if (sky2->advertising & ADVERTISED_100baseT_Half)
433 adv |= PHY_M_AN_100_HD;
434 if (sky2->advertising & ADVERTISED_10baseT_Full)
435 adv |= PHY_M_AN_10_FD;
436 if (sky2->advertising & ADVERTISED_10baseT_Half)
437 adv |= PHY_M_AN_10_HD;
Stephen Hemminger709c6e72006-10-17 10:24:04 -0700438
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700439 } else { /* special defines for FIBER (88E1040S only) */
440 if (sky2->advertising & ADVERTISED_1000baseT_Full)
441 adv |= PHY_M_AN_1000X_AFD;
442 if (sky2->advertising & ADVERTISED_1000baseT_Half)
443 adv |= PHY_M_AN_1000X_AHD;
Stephen Hemminger709c6e72006-10-17 10:24:04 -0700444 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700445
446 /* Restart Auto-negotiation */
447 ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG;
448 } else {
449 /* forced speed/duplex settings */
450 ct1000 = PHY_M_1000C_MSE;
451
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700452 /* Disable auto update for duplex flow control and duplex */
453 reg |= GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_SPD_DIS;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700454
455 switch (sky2->speed) {
456 case SPEED_1000:
457 ctrl |= PHY_CT_SP1000;
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700458 reg |= GM_GPCR_SPEED_1000;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700459 break;
460 case SPEED_100:
461 ctrl |= PHY_CT_SP100;
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700462 reg |= GM_GPCR_SPEED_100;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700463 break;
464 }
465
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700466 if (sky2->duplex == DUPLEX_FULL) {
467 reg |= GM_GPCR_DUP_FULL;
468 ctrl |= PHY_CT_DUP_MD;
Stephen Hemminger16ad91e2006-10-17 10:24:13 -0700469 } else if (sky2->speed < SPEED_1000)
470 sky2->flow_mode = FC_NONE;
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700471 }
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700472
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700473 if (sky2->flags & SKY2_FLAG_AUTO_PAUSE) {
474 if (sky2_is_copper(hw))
475 adv |= copper_fc_adv[sky2->flow_mode];
476 else
477 adv |= fiber_fc_adv[sky2->flow_mode];
478 } else {
479 reg |= GM_GPCR_AU_FCT_DIS;
Stephen Hemminger16ad91e2006-10-17 10:24:13 -0700480 reg |= gm_fc_disable[sky2->flow_mode];
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700481
482 /* Forward pause packets to GMAC? */
Stephen Hemminger16ad91e2006-10-17 10:24:13 -0700483 if (sky2->flow_mode & FC_RX)
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700484 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
485 else
486 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700487 }
488
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700489 gma_write16(hw, port, GM_GP_CTRL, reg);
490
Stephen Hemminger05745c42007-09-19 15:36:45 -0700491 if (hw->flags & SKY2_HW_GIGABIT)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700492 gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000);
493
494 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv);
495 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
496
497 /* Setup Phy LED's */
498 ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS);
499 ledover = 0;
500
501 switch (hw->chip_id) {
502 case CHIP_ID_YUKON_FE:
503 /* on 88E3082 these bits are at 11..9 (shifted left) */
504 ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) << 1;
505
506 ctrl = gm_phy_read(hw, port, PHY_MARV_FE_LED_PAR);
507
508 /* delete ACT LED control bits */
509 ctrl &= ~PHY_M_FELP_LED1_MSK;
510 /* change ACT LED control to blink mode */
511 ctrl |= PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_ACT_BL);
512 gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl);
513 break;
514
Stephen Hemminger05745c42007-09-19 15:36:45 -0700515 case CHIP_ID_YUKON_FE_P:
516 /* Enable Link Partner Next Page */
517 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
518 ctrl |= PHY_M_PC_ENA_LIP_NP;
519
520 /* disable Energy Detect and enable scrambler */
521 ctrl &= ~(PHY_M_PC_ENA_ENE_DT | PHY_M_PC_DIS_SCRAMB);
522 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
523
524 /* set LED2 -> ACT, LED1 -> LINK, LED0 -> SPEED */
525 ctrl = PHY_M_FELP_LED2_CTRL(LED_PAR_CTRL_ACT_BL) |
526 PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_LINK) |
527 PHY_M_FELP_LED0_CTRL(LED_PAR_CTRL_SPEED);
528
529 gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl);
530 break;
531
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700532 case CHIP_ID_YUKON_XL:
Stephen Hemminger793b8832005-09-14 16:06:14 -0700533 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700534
535 /* select page 3 to access LED control register */
536 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
537
538 /* set LED Function Control register */
Stephen Hemmingered6d32c2006-05-08 15:11:33 -0700539 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
540 (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */
541 PHY_M_LEDC_INIT_CTRL(7) | /* 10 Mbps */
542 PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */
543 PHY_M_LEDC_STA0_CTRL(7))); /* 1000 Mbps */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700544
545 /* set Polarity Control register */
546 gm_phy_write(hw, port, PHY_MARV_PHY_STAT,
Stephen Hemminger793b8832005-09-14 16:06:14 -0700547 (PHY_M_POLC_LS1_P_MIX(4) |
548 PHY_M_POLC_IS0_P_MIX(4) |
549 PHY_M_POLC_LOS_CTRL(2) |
550 PHY_M_POLC_INIT_CTRL(2) |
551 PHY_M_POLC_STA1_CTRL(2) |
552 PHY_M_POLC_STA0_CTRL(2)));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700553
554 /* restore page register */
Stephen Hemminger793b8832005-09-14 16:06:14 -0700555 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700556 break;
Stephen Hemminger93745492007-02-06 10:45:43 -0800557
Stephen Hemmingered6d32c2006-05-08 15:11:33 -0700558 case CHIP_ID_YUKON_EC_U:
Stephen Hemminger93745492007-02-06 10:45:43 -0800559 case CHIP_ID_YUKON_EX:
Stephen Hemmingered4d4162008-01-10 16:14:14 -0800560 case CHIP_ID_YUKON_SUPR:
Stephen Hemmingered6d32c2006-05-08 15:11:33 -0700561 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
562
563 /* select page 3 to access LED control register */
564 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
565
566 /* set LED Function Control register */
567 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
568 (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */
569 PHY_M_LEDC_INIT_CTRL(8) | /* 10 Mbps */
570 PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */
571 PHY_M_LEDC_STA0_CTRL(7)));/* 1000 Mbps */
572
573 /* set Blink Rate in LED Timer Control Register */
574 gm_phy_write(hw, port, PHY_MARV_INT_MASK,
575 ledctrl | PHY_M_LED_BLINK_RT(BLINK_84MS));
576 /* restore page register */
577 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
578 break;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700579
580 default:
581 /* set Tx LED (LED_TX) to blink mode on Rx OR Tx activity */
582 ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL;
Stephen Hemmingera84d0a32008-02-22 16:00:33 -0800583
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700584 /* turn off the Rx LED (LED_RX) */
Stephen Hemmingera84d0a32008-02-22 16:00:33 -0800585 ledover |= PHY_M_LED_MO_RX(MO_LED_OFF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700586 }
587
Stephen Hemminger0ce8b982008-06-17 09:04:27 -0700588 if (hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_UL_2) {
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800589 /* apply fixes in PHY AFE */
Stephen Hemmingered6d32c2006-05-08 15:11:33 -0700590 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 255);
591
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800592 /* increase differential signal amplitude in 10BASE-T */
Stephen Hemmingered6d32c2006-05-08 15:11:33 -0700593 gm_phy_write(hw, port, 0x18, 0xaa99);
594 gm_phy_write(hw, port, 0x17, 0x2011);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700595
Stephen Hemminger0ce8b982008-06-17 09:04:27 -0700596 if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
597 /* fix for IEEE A/B Symmetry failure in 1000BASE-T */
598 gm_phy_write(hw, port, 0x18, 0xa204);
599 gm_phy_write(hw, port, 0x17, 0x2002);
600 }
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800601
602 /* set page register to 0 */
Stephen Hemminger9467a8f2007-04-07 16:02:28 -0700603 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
Stephen Hemminger05745c42007-09-19 15:36:45 -0700604 } else if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
605 hw->chip_rev == CHIP_REV_YU_FE2_A0) {
606 /* apply workaround for integrated resistors calibration */
607 gm_phy_write(hw, port, PHY_MARV_PAGE_ADDR, 17);
608 gm_phy_write(hw, port, PHY_MARV_PAGE_DATA, 0x3f60);
Stephen Hemminger0f5aac72009-10-29 06:37:09 +0000609 } else if (hw->chip_id == CHIP_ID_YUKON_OPT && hw->chip_rev == 0) {
610 /* apply fixes in PHY AFE */
611 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0x00ff);
612
613 /* apply RDAC termination workaround */
614 gm_phy_write(hw, port, 24, 0x2800);
615 gm_phy_write(hw, port, 23, 0x2001);
616
617 /* set page register back to 0 */
618 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
Stephen Hemmingere1a74b32008-06-17 09:04:24 -0700619 } else if (hw->chip_id != CHIP_ID_YUKON_EX &&
620 hw->chip_id < CHIP_ID_YUKON_SUPR) {
Stephen Hemminger05745c42007-09-19 15:36:45 -0700621 /* no effect on Yukon-XL */
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800622 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl);
623
Joe Perches8e95a202009-12-03 07:58:21 +0000624 if (!(sky2->flags & SKY2_FLAG_AUTO_SPEED) ||
625 sky2->speed == SPEED_100) {
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800626 /* turn on 100 Mbps LED (LED_LINK100) */
Stephen Hemmingera84d0a32008-02-22 16:00:33 -0800627 ledover |= PHY_M_LED_MO_100(MO_LED_ON);
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800628 }
629
630 if (ledover)
631 gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover);
632
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700633 }
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700634
shemminger@osdl.orgd571b692005-10-26 12:16:09 -0700635 /* Enable phy interrupt on auto-negotiation complete (or link up) */
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700636 if (sky2->flags & SKY2_FLAG_AUTO_SPEED)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700637 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL);
638 else
639 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
640}
641
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700642static const u32 phy_power[] = { PCI_Y2_PHY1_POWD, PCI_Y2_PHY2_POWD };
643static const u32 coma_mode[] = { PCI_Y2_PHY1_COMA, PCI_Y2_PHY2_COMA };
644
645static void sky2_phy_power_up(struct sky2_hw *hw, unsigned port)
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -0700646{
647 u32 reg1;
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -0700648
stephen hemmingera40ccc62010-01-24 18:46:06 +0000649 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -0800650 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700651 reg1 &= ~phy_power[port];
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -0700652
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700653 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
Stephen Hemmingerff35164e2007-10-11 19:47:44 -0700654 reg1 |= coma_mode[port];
655
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -0800656 sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
stephen hemmingera40ccc62010-01-24 18:46:06 +0000657 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemminger82637e82008-01-23 19:16:04 -0800658 sky2_pci_read32(hw, PCI_DEV_REG1);
Stephen Hemmingerf71eb1a2008-08-04 13:33:37 -0700659
660 if (hw->chip_id == CHIP_ID_YUKON_FE)
661 gm_phy_write(hw, port, PHY_MARV_CTRL, PHY_CT_ANE);
662 else if (hw->flags & SKY2_HW_ADV_POWER_CTL)
663 sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700664}
Stephen Hemminger167f53d2007-09-25 19:01:02 -0700665
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700666static void sky2_phy_power_down(struct sky2_hw *hw, unsigned port)
667{
668 u32 reg1;
Stephen Hemmingerdb99b982008-05-14 17:04:16 -0700669 u16 ctrl;
670
671 /* release GPHY Control reset */
672 sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
673
674 /* release GMAC reset */
675 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
676
677 if (hw->flags & SKY2_HW_NEWER_PHY) {
678 /* select page 2 to access MAC control register */
679 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2);
680
681 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
682 /* allow GMII Power Down */
683 ctrl &= ~PHY_M_MAC_GMIF_PUP;
684 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
685
686 /* set page register back to 0 */
687 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
688 }
689
690 /* setup General Purpose Control Register */
691 gma_write16(hw, port, GM_GP_CTRL,
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700692 GM_GPCR_FL_PASS | GM_GPCR_SPEED_100 |
693 GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_FCT_DIS |
694 GM_GPCR_AU_SPD_DIS);
Stephen Hemmingerdb99b982008-05-14 17:04:16 -0700695
696 if (hw->chip_id != CHIP_ID_YUKON_EC) {
697 if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
Rafael J. Wysockie484d5f2008-08-10 19:30:28 +0200698 /* select page 2 to access MAC control register */
699 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2);
Stephen Hemmingerdb99b982008-05-14 17:04:16 -0700700
Rafael J. Wysockie484d5f2008-08-10 19:30:28 +0200701 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
Stephen Hemmingerdb99b982008-05-14 17:04:16 -0700702 /* enable Power Down */
703 ctrl |= PHY_M_PC_POW_D_ENA;
704 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
Rafael J. Wysockie484d5f2008-08-10 19:30:28 +0200705
706 /* set page register back to 0 */
707 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
Stephen Hemmingerdb99b982008-05-14 17:04:16 -0700708 }
709
710 /* set IEEE compatible Power Down Mode (dev. #4.99) */
711 gm_phy_write(hw, port, PHY_MARV_CTRL, PHY_CT_PDOWN);
712 }
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700713
stephen hemmingera40ccc62010-01-24 18:46:06 +0000714 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700715 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
Stephen Hemmingerdb99b982008-05-14 17:04:16 -0700716 reg1 |= phy_power[port]; /* set PHY to PowerDown/COMA Mode */
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700717 sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
stephen hemmingera40ccc62010-01-24 18:46:06 +0000718 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -0700719}
720
Stephen Hemminger1b537562005-12-20 15:08:07 -0800721/* Force a renegotiation */
722static void sky2_phy_reinit(struct sky2_port *sky2)
723{
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -0800724 spin_lock_bh(&sky2->phy_lock);
Stephen Hemminger1b537562005-12-20 15:08:07 -0800725 sky2_phy_init(sky2->hw, sky2->port);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -0800726 spin_unlock_bh(&sky2->phy_lock);
Stephen Hemminger1b537562005-12-20 15:08:07 -0800727}
728
Stephen Hemmingere3173832007-02-06 10:45:39 -0800729/* Put device in state to listen for Wake On Lan */
730static void sky2_wol_init(struct sky2_port *sky2)
731{
732 struct sky2_hw *hw = sky2->hw;
733 unsigned port = sky2->port;
734 enum flow_control save_mode;
735 u16 ctrl;
Stephen Hemmingere3173832007-02-06 10:45:39 -0800736
737 /* Bring hardware out of reset */
738 sky2_write16(hw, B0_CTST, CS_RST_CLR);
739 sky2_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR);
740
741 sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
742 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
743
744 /* Force to 10/100
745 * sky2_reset will re-enable on resume
746 */
747 save_mode = sky2->flow_mode;
748 ctrl = sky2->advertising;
749
750 sky2->advertising &= ~(ADVERTISED_1000baseT_Half|ADVERTISED_1000baseT_Full);
751 sky2->flow_mode = FC_NONE;
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700752
753 spin_lock_bh(&sky2->phy_lock);
754 sky2_phy_power_up(hw, port);
755 sky2_phy_init(hw, port);
756 spin_unlock_bh(&sky2->phy_lock);
Stephen Hemmingere3173832007-02-06 10:45:39 -0800757
758 sky2->flow_mode = save_mode;
759 sky2->advertising = ctrl;
760
761 /* Set GMAC to no flow control and auto update for speed/duplex */
762 gma_write16(hw, port, GM_GP_CTRL,
763 GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA|
764 GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS);
765
766 /* Set WOL address */
767 memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR),
768 sky2->netdev->dev_addr, ETH_ALEN);
769
770 /* Turn on appropriate WOL control bits */
771 sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT);
772 ctrl = 0;
773 if (sky2->wol & WAKE_PHY)
774 ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT;
775 else
776 ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT;
777
778 if (sky2->wol & WAKE_MAGIC)
779 ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT;
780 else
Joe Perchesa419aef2009-08-18 11:18:35 -0700781 ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT;
Stephen Hemmingere3173832007-02-06 10:45:39 -0800782
783 ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT;
784 sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
785
stephen hemminger5f8ae5c2010-02-12 06:57:59 +0000786 /* Disable PiG firmware */
787 sky2_write16(hw, B0_CTST, Y2_HW_WOL_OFF);
788
Stephen Hemmingere3173832007-02-06 10:45:39 -0800789 /* block receiver */
790 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
Stephen Hemmingere3173832007-02-06 10:45:39 -0800791}
792
Stephen Hemminger69161612007-06-04 17:23:26 -0700793static void sky2_set_tx_stfwd(struct sky2_hw *hw, unsigned port)
794{
Stephen Hemminger05745c42007-09-19 15:36:45 -0700795 struct net_device *dev = hw->dev[port];
796
Stephen Hemmingered4d4162008-01-10 16:14:14 -0800797 if ( (hw->chip_id == CHIP_ID_YUKON_EX &&
798 hw->chip_rev != CHIP_REV_YU_EX_A0) ||
Stephen Hemminger877c8572009-10-29 06:37:08 +0000799 hw->chip_id >= CHIP_ID_YUKON_FE_P) {
Stephen Hemmingered4d4162008-01-10 16:14:14 -0800800 /* Yukon-Extreme B0 and further Extreme devices */
stephen hemminger44dde562010-02-12 06:58:01 +0000801 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_ENA);
802 } else if (dev->mtu > ETH_DATA_LEN) {
803 /* set Tx GMAC FIFO Almost Empty Threshold */
804 sky2_write32(hw, SK_REG(port, TX_GMF_AE_THR),
805 (ECU_JUMBO_WM << 16) | ECU_AE_THR);
Stephen Hemminger69161612007-06-04 17:23:26 -0700806
stephen hemminger44dde562010-02-12 06:58:01 +0000807 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_DIS);
808 } else
809 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_ENA);
Stephen Hemminger69161612007-06-04 17:23:26 -0700810}
811
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700812static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
813{
814 struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
815 u16 reg;
Al Viro25cccec2007-07-20 16:07:33 +0100816 u32 rx_reg;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700817 int i;
818 const u8 *addr = hw->dev[port]->dev_addr;
819
Stephen Hemmingerf3503392007-08-21 11:10:22 -0700820 sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
821 sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700822
823 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
824
Stephen Hemminger793b8832005-09-14 16:06:14 -0700825 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0 && port == 1) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700826 /* WA DEV_472 -- looks like crossed wires on port 2 */
827 /* clear GMAC 1 Control reset */
828 sky2_write8(hw, SK_REG(0, GMAC_CTRL), GMC_RST_CLR);
829 do {
830 sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_SET);
831 sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_CLR);
832 } while (gm_phy_read(hw, 1, PHY_MARV_ID0) != PHY_MARV_ID0_VAL ||
833 gm_phy_read(hw, 1, PHY_MARV_ID1) != PHY_MARV_ID1_Y2 ||
834 gm_phy_read(hw, 1, PHY_MARV_INT_MASK) != 0);
835 }
836
Stephen Hemminger793b8832005-09-14 16:06:14 -0700837 sky2_read16(hw, SK_REG(port, GMAC_IRQ_SRC));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700838
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700839 /* Enable Transmit FIFO Underrun */
840 sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK);
841
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -0800842 spin_lock_bh(&sky2->phy_lock);
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700843 sky2_phy_power_up(hw, port);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700844 sky2_phy_init(hw, port);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -0800845 spin_unlock_bh(&sky2->phy_lock);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700846
847 /* MIB clear */
848 reg = gma_read16(hw, port, GM_PHY_ADDR);
849 gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR);
850
Stephen Hemminger43f2f102006-04-05 17:47:15 -0700851 for (i = GM_MIB_CNT_BASE; i <= GM_MIB_CNT_END; i += 4)
852 gma_read16(hw, port, i);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700853 gma_write16(hw, port, GM_PHY_ADDR, reg);
854
855 /* transmit control */
856 gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF));
857
858 /* receive control reg: unicast + multicast + no FCS */
859 gma_write16(hw, port, GM_RX_CTRL,
Stephen Hemminger793b8832005-09-14 16:06:14 -0700860 GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700861
862 /* transmit flow control */
863 gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff);
864
865 /* transmit parameter */
866 gma_write16(hw, port, GM_TX_PARAM,
867 TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) |
868 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) |
869 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF) |
870 TX_BACK_OFF_LIM(TX_BOF_LIM_DEF));
871
872 /* serial mode register */
873 reg = DATA_BLIND_VAL(DATA_BLIND_DEF) |
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -0700874 GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700875
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -0700876 if (hw->dev[port]->mtu > ETH_DATA_LEN)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700877 reg |= GM_SMOD_JUMBO_ENA;
878
879 gma_write16(hw, port, GM_SERIAL_MODE, reg);
880
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700881 /* virtual address for data */
882 gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr);
883
Stephen Hemminger793b8832005-09-14 16:06:14 -0700884 /* physical address: used for pause frames */
885 gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr);
886
887 /* ignore counter overflows */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700888 gma_write16(hw, port, GM_TX_IRQ_MSK, 0);
889 gma_write16(hw, port, GM_RX_IRQ_MSK, 0);
890 gma_write16(hw, port, GM_TR_IRQ_MSK, 0);
891
892 /* Configure Rx MAC FIFO */
893 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
Al Viro25cccec2007-07-20 16:07:33 +0100894 rx_reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
Stephen Hemminger05745c42007-09-19 15:36:45 -0700895 if (hw->chip_id == CHIP_ID_YUKON_EX ||
896 hw->chip_id == CHIP_ID_YUKON_FE_P)
Al Viro25cccec2007-07-20 16:07:33 +0100897 rx_reg |= GMF_RX_OVER_ON;
Stephen Hemminger69161612007-06-04 17:23:26 -0700898
Al Viro25cccec2007-07-20 16:07:33 +0100899 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), rx_reg);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700900
Stephen Hemminger798fdd02007-12-07 15:22:15 -0800901 if (hw->chip_id == CHIP_ID_YUKON_XL) {
902 /* Hardware errata - clear flush mask */
903 sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), 0);
904 } else {
905 /* Flush Rx MAC FIFO on any flow control or error */
906 sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR);
907 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700908
Stephen Hemminger8df9a872006-12-01 14:29:35 -0800909 /* Set threshold to 0xa (64 bytes) + 1 to workaround pause bug */
Stephen Hemminger05745c42007-09-19 15:36:45 -0700910 reg = RX_GMF_FL_THR_DEF + 1;
911 /* Another magic mystery workaround from sk98lin */
912 if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
913 hw->chip_rev == CHIP_REV_YU_FE2_A0)
914 reg = 0x178;
915 sky2_write16(hw, SK_REG(port, RX_GMF_FL_THR), reg);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700916
917 /* Configure Tx MAC FIFO */
918 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
919 sky2_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -0800920
Stephen Hemmingere0c28112007-09-20 13:03:49 -0700921 /* On chips without ram buffer, pause is controled by MAC level */
Stephen Hemminger39dbd952008-02-04 19:45:13 -0800922 if (!(hw->flags & SKY2_HW_RAM_BUFFER)) {
Stephen Hemmingerd6b54d22009-10-29 06:37:07 +0000923 /* Pause threshold is scaled by 8 in bytes */
Joe Perches8e95a202009-12-03 07:58:21 +0000924 if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
925 hw->chip_rev == CHIP_REV_YU_FE2_A0)
Stephen Hemmingerd6b54d22009-10-29 06:37:07 +0000926 reg = 1568 / 8;
927 else
928 reg = 1024 / 8;
929 sky2_write16(hw, SK_REG(port, RX_GMF_UP_THR), reg);
930 sky2_write16(hw, SK_REG(port, RX_GMF_LP_THR), 768 / 8);
Stephen Hemmingerb628ed982007-04-11 14:48:01 -0700931
Stephen Hemminger69161612007-06-04 17:23:26 -0700932 sky2_set_tx_stfwd(hw, port);
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -0800933 }
934
Stephen Hemmingere970d1f2007-11-27 11:02:07 -0800935 if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
936 hw->chip_rev == CHIP_REV_YU_FE2_A0) {
937 /* disable dynamic watermark */
938 reg = sky2_read16(hw, SK_REG(port, TX_GMF_EA));
939 reg &= ~TX_DYN_WM_ENA;
940 sky2_write16(hw, SK_REG(port, TX_GMF_EA), reg);
941 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700942}
943
Stephen Hemminger67712902006-12-04 15:53:45 -0800944/* Assign Ram Buffer allocation to queue */
945static void sky2_ramset(struct sky2_hw *hw, u16 q, u32 start, u32 space)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700946{
Stephen Hemminger67712902006-12-04 15:53:45 -0800947 u32 end;
948
949 /* convert from K bytes to qwords used for hw register */
950 start *= 1024/8;
951 space *= 1024/8;
952 end = start + space - 1;
Stephen Hemminger793b8832005-09-14 16:06:14 -0700953
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700954 sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR);
955 sky2_write32(hw, RB_ADDR(q, RB_START), start);
956 sky2_write32(hw, RB_ADDR(q, RB_END), end);
957 sky2_write32(hw, RB_ADDR(q, RB_WP), start);
958 sky2_write32(hw, RB_ADDR(q, RB_RP), start);
959
960 if (q == Q_R1 || q == Q_R2) {
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -0800961 u32 tp = space - space/4;
Stephen Hemminger793b8832005-09-14 16:06:14 -0700962
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -0800963 /* On receive queue's set the thresholds
964 * give receiver priority when > 3/4 full
965 * send pause when down to 2K
966 */
967 sky2_write32(hw, RB_ADDR(q, RB_RX_UTHP), tp);
968 sky2_write32(hw, RB_ADDR(q, RB_RX_LTHP), space/2);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700969
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -0800970 tp = space - 2048/8;
971 sky2_write32(hw, RB_ADDR(q, RB_RX_UTPP), tp);
972 sky2_write32(hw, RB_ADDR(q, RB_RX_LTPP), space/4);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700973 } else {
974 /* Enable store & forward on Tx queue's because
975 * Tx FIFO is only 1K on Yukon
976 */
977 sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD);
978 }
979
980 sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700981 sky2_read8(hw, RB_ADDR(q, RB_CTRL));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700982}
983
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700984/* Setup Bus Memory Interface */
shemminger@osdl.orgaf4ed7e2005-11-30 11:45:21 -0800985static void sky2_qset(struct sky2_hw *hw, u16 q)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700986{
987 sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_RESET);
988 sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_OPER_INIT);
989 sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_FIFO_OP_ON);
shemminger@osdl.orgaf4ed7e2005-11-30 11:45:21 -0800990 sky2_write32(hw, Q_ADDR(q, Q_WM), BMU_WM_DEFAULT);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700991}
992
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700993/* Setup prefetch unit registers. This is the interface between
994 * hardware and driver list elements
995 */
Stephen Hemminger8cc048e2005-12-09 11:35:07 -0800996static void sky2_prefetch_init(struct sky2_hw *hw, u32 qaddr,
Stephen Hemmingerd6e74b62009-08-18 15:17:05 +0000997 dma_addr_t addr, u32 last)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700998{
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700999 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
1000 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_CLR);
Stephen Hemmingerd6e74b62009-08-18 15:17:05 +00001001 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_HI), upper_32_bits(addr));
1002 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_LO), lower_32_bits(addr));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001003 sky2_write16(hw, Y2_QADDR(qaddr, PREF_UNIT_LAST_IDX), last);
1004 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_OP_ON);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001005
1006 sky2_read32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001007}
1008
Mike McCormack9b289c32009-08-14 05:15:12 +00001009static inline struct sky2_tx_le *get_tx_le(struct sky2_port *sky2, u16 *slot)
Stephen Hemminger793b8832005-09-14 16:06:14 -07001010{
Mike McCormack9b289c32009-08-14 05:15:12 +00001011 struct sky2_tx_le *le = sky2->tx_le + *slot;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001012
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001013 *slot = RING_NEXT(*slot, sky2->tx_ring_size);
Stephen Hemminger291ea612006-09-26 11:57:41 -07001014 le->ctrl = 0;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001015 return le;
1016}
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001017
Stephen Hemminger88f5f0c2007-09-27 12:38:12 -07001018static void tx_init(struct sky2_port *sky2)
1019{
1020 struct sky2_tx_le *le;
1021
1022 sky2->tx_prod = sky2->tx_cons = 0;
1023 sky2->tx_tcpsum = 0;
1024 sky2->tx_last_mss = 0;
1025
Mike McCormack9b289c32009-08-14 05:15:12 +00001026 le = get_tx_le(sky2, &sky2->tx_prod);
Stephen Hemminger88f5f0c2007-09-27 12:38:12 -07001027 le->addr = 0;
1028 le->opcode = OP_ADDR64 | HW_OWNER;
Stephen Hemminger5dce95e2009-08-18 15:17:06 +00001029 sky2->tx_last_upper = 0;
Stephen Hemminger88f5f0c2007-09-27 12:38:12 -07001030}
1031
Stephen Hemminger290d4de2006-03-20 15:48:15 -08001032/* Update chip's next pointer */
1033static inline void sky2_put_idx(struct sky2_hw *hw, unsigned q, u16 idx)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001034{
Stephen Hemminger50432cb2007-05-14 12:38:15 -07001035 /* Make sure write' to descriptors are complete before we tell hardware */
Stephen Hemminger762c2de2006-01-17 13:43:14 -08001036 wmb();
Stephen Hemminger50432cb2007-05-14 12:38:15 -07001037 sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), idx);
1038
1039 /* Synchronize I/O on since next processor may write to tail */
1040 mmiowb();
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001041}
1042
Stephen Hemminger793b8832005-09-14 16:06:14 -07001043
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001044static inline struct sky2_rx_le *sky2_next_rx(struct sky2_port *sky2)
1045{
1046 struct sky2_rx_le *le = sky2->rx_le + sky2->rx_put;
Stephen Hemmingercb5d9542006-05-08 15:11:29 -07001047 sky2->rx_put = RING_NEXT(sky2->rx_put, RX_LE_SIZE);
Stephen Hemminger291ea612006-09-26 11:57:41 -07001048 le->ctrl = 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001049 return le;
1050}
1051
Mike McCormack39ef1102010-02-12 06:58:02 +00001052static unsigned sky2_get_rx_threshold(struct sky2_port* sky2)
1053{
1054 unsigned size;
1055
1056 /* Space needed for frame data + headers rounded up */
1057 size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8);
1058
1059 /* Stopping point for hardware truncation */
1060 return (size - 8) / sizeof(u32);
1061}
1062
1063static unsigned sky2_get_rx_data_size(struct sky2_port* sky2)
1064{
1065 struct rx_ring_info *re;
1066 unsigned size;
1067
1068 /* Space needed for frame data + headers rounded up */
1069 size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8);
1070
1071 sky2->rx_nfrags = size >> PAGE_SHIFT;
1072 BUG_ON(sky2->rx_nfrags > ARRAY_SIZE(re->frag_addr));
1073
1074 /* Compute residue after pages */
1075 size -= sky2->rx_nfrags << PAGE_SHIFT;
1076
1077 /* Optimize to handle small packets and headers */
1078 if (size < copybreak)
1079 size = copybreak;
1080 if (size < ETH_HLEN)
1081 size = ETH_HLEN;
1082
1083 return size;
1084}
1085
Stephen Hemminger14d02632006-09-26 11:57:43 -07001086/* Build description to hardware for one receive segment */
1087static void sky2_rx_add(struct sky2_port *sky2, u8 op,
1088 dma_addr_t map, unsigned len)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001089{
1090 struct sky2_rx_le *le;
1091
Stephen Hemminger86c68872008-01-10 16:14:12 -08001092 if (sizeof(dma_addr_t) > sizeof(u32)) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001093 le = sky2_next_rx(sky2);
Stephen Hemminger86c68872008-01-10 16:14:12 -08001094 le->addr = cpu_to_le32(upper_32_bits(map));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001095 le->opcode = OP_ADDR64 | HW_OWNER;
1096 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07001097
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001098 le = sky2_next_rx(sky2);
Stephen Hemmingerd6e74b62009-08-18 15:17:05 +00001099 le->addr = cpu_to_le32(lower_32_bits(map));
Stephen Hemminger734d1862005-12-09 11:35:00 -08001100 le->length = cpu_to_le16(len);
Stephen Hemminger14d02632006-09-26 11:57:43 -07001101 le->opcode = op | HW_OWNER;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001102}
1103
Stephen Hemminger14d02632006-09-26 11:57:43 -07001104/* Build description to hardware for one possibly fragmented skb */
1105static void sky2_rx_submit(struct sky2_port *sky2,
1106 const struct rx_ring_info *re)
1107{
1108 int i;
1109
1110 sky2_rx_add(sky2, OP_PACKET, re->data_addr, sky2->rx_data_size);
1111
1112 for (i = 0; i < skb_shinfo(re->skb)->nr_frags; i++)
1113 sky2_rx_add(sky2, OP_BUFFER, re->frag_addr[i], PAGE_SIZE);
1114}
1115
1116
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001117static int sky2_rx_map_skb(struct pci_dev *pdev, struct rx_ring_info *re,
Stephen Hemminger14d02632006-09-26 11:57:43 -07001118 unsigned size)
1119{
1120 struct sk_buff *skb = re->skb;
1121 int i;
1122
1123 re->data_addr = pci_map_single(pdev, skb->data, size, PCI_DMA_FROMDEVICE);
stephen hemminger3fbd9182010-02-01 13:45:41 +00001124 if (pci_dma_mapping_error(pdev, re->data_addr))
1125 goto mapping_error;
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001126
Stephen Hemminger14d02632006-09-26 11:57:43 -07001127 pci_unmap_len_set(re, data_size, size);
1128
stephen hemminger3fbd9182010-02-01 13:45:41 +00001129 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1130 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1131
1132 re->frag_addr[i] = pci_map_page(pdev, frag->page,
1133 frag->page_offset,
1134 frag->size,
Stephen Hemminger14d02632006-09-26 11:57:43 -07001135 PCI_DMA_FROMDEVICE);
stephen hemminger3fbd9182010-02-01 13:45:41 +00001136
1137 if (pci_dma_mapping_error(pdev, re->frag_addr[i]))
1138 goto map_page_error;
1139 }
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001140 return 0;
stephen hemminger3fbd9182010-02-01 13:45:41 +00001141
1142map_page_error:
1143 while (--i >= 0) {
1144 pci_unmap_page(pdev, re->frag_addr[i],
1145 skb_shinfo(skb)->frags[i].size,
1146 PCI_DMA_FROMDEVICE);
1147 }
1148
1149 pci_unmap_single(pdev, re->data_addr, pci_unmap_len(re, data_size),
1150 PCI_DMA_FROMDEVICE);
1151
1152mapping_error:
1153 if (net_ratelimit())
1154 dev_warn(&pdev->dev, "%s: rx mapping error\n",
1155 skb->dev->name);
1156 return -EIO;
Stephen Hemminger14d02632006-09-26 11:57:43 -07001157}
1158
1159static void sky2_rx_unmap_skb(struct pci_dev *pdev, struct rx_ring_info *re)
1160{
1161 struct sk_buff *skb = re->skb;
1162 int i;
1163
1164 pci_unmap_single(pdev, re->data_addr, pci_unmap_len(re, data_size),
1165 PCI_DMA_FROMDEVICE);
1166
1167 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
1168 pci_unmap_page(pdev, re->frag_addr[i],
1169 skb_shinfo(skb)->frags[i].size,
1170 PCI_DMA_FROMDEVICE);
1171}
Stephen Hemminger793b8832005-09-14 16:06:14 -07001172
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001173/* Tell chip where to start receive checksum.
1174 * Actually has two checksums, but set both same to avoid possible byte
1175 * order problems.
1176 */
Stephen Hemminger793b8832005-09-14 16:06:14 -07001177static void rx_set_checksum(struct sky2_port *sky2)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001178{
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001179 struct sky2_rx_le *le = sky2_next_rx(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001180
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001181 le->addr = cpu_to_le32((ETH_HLEN << 16) | ETH_HLEN);
1182 le->ctrl = 0;
1183 le->opcode = OP_TCPSTART | HW_OWNER;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001184
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001185 sky2_write32(sky2->hw,
1186 Q_ADDR(rxqaddr[sky2->port], Q_CSR),
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07001187 (sky2->flags & SKY2_FLAG_RX_CHECKSUM)
1188 ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001189}
1190
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001191/*
1192 * The RX Stop command will not work for Yukon-2 if the BMU does not
1193 * reach the end of packet and since we can't make sure that we have
1194 * incoming data, we must reset the BMU while it is not doing a DMA
1195 * transfer. Since it is possible that the RX path is still active,
1196 * the RX RAM buffer will be stopped first, so any possible incoming
1197 * data will not trigger a DMA. After the RAM buffer is stopped, the
1198 * BMU is polled until any DMA in progress is ended and only then it
1199 * will be reset.
1200 */
1201static void sky2_rx_stop(struct sky2_port *sky2)
1202{
1203 struct sky2_hw *hw = sky2->hw;
1204 unsigned rxq = rxqaddr[sky2->port];
1205 int i;
1206
1207 /* disable the RAM Buffer receive queue */
1208 sky2_write8(hw, RB_ADDR(rxq, RB_CTRL), RB_DIS_OP_MD);
1209
1210 for (i = 0; i < 0xffff; i++)
1211 if (sky2_read8(hw, RB_ADDR(rxq, Q_RSL))
1212 == sky2_read8(hw, RB_ADDR(rxq, Q_RL)))
1213 goto stopped;
1214
1215 printk(KERN_WARNING PFX "%s: receiver stop failed\n",
1216 sky2->netdev->name);
1217stopped:
1218 sky2_write32(hw, Q_ADDR(rxq, Q_CSR), BMU_RST_SET | BMU_FIFO_RST);
1219
1220 /* reset the Rx prefetch unit */
1221 sky2_write32(hw, Y2_QADDR(rxq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
Stephen Hemminger3d1454dd2009-07-16 13:20:57 +00001222 mmiowb();
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001223}
Stephen Hemminger793b8832005-09-14 16:06:14 -07001224
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07001225/* Clean out receive buffer area, assumes receiver hardware stopped */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001226static void sky2_rx_clean(struct sky2_port *sky2)
1227{
1228 unsigned i;
1229
1230 memset(sky2->rx_le, 0, RX_LE_BYTES);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001231 for (i = 0; i < sky2->rx_pending; i++) {
Stephen Hemminger291ea612006-09-26 11:57:41 -07001232 struct rx_ring_info *re = sky2->rx_ring + i;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001233
1234 if (re->skb) {
Stephen Hemminger14d02632006-09-26 11:57:43 -07001235 sky2_rx_unmap_skb(sky2->hw->pdev, re);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001236 kfree_skb(re->skb);
1237 re->skb = NULL;
1238 }
1239 }
1240}
1241
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08001242/* Basic MII support */
1243static int sky2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1244{
1245 struct mii_ioctl_data *data = if_mii(ifr);
1246 struct sky2_port *sky2 = netdev_priv(dev);
1247 struct sky2_hw *hw = sky2->hw;
1248 int err = -EOPNOTSUPP;
1249
1250 if (!netif_running(dev))
1251 return -ENODEV; /* Phy still in reset */
1252
Stephen Hemmingerd89e1342006-03-20 15:48:20 -08001253 switch (cmd) {
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08001254 case SIOCGMIIPHY:
1255 data->phy_id = PHY_ADDR_MARV;
1256
1257 /* fallthru */
1258 case SIOCGMIIREG: {
1259 u16 val = 0;
Stephen Hemminger91c86df2005-12-09 11:34:57 -08001260
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001261 spin_lock_bh(&sky2->phy_lock);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08001262 err = __gm_phy_read(hw, sky2->port, data->reg_num & 0x1f, &val);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001263 spin_unlock_bh(&sky2->phy_lock);
Stephen Hemminger91c86df2005-12-09 11:34:57 -08001264
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08001265 data->val_out = val;
1266 break;
1267 }
1268
1269 case SIOCSMIIREG:
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001270 spin_lock_bh(&sky2->phy_lock);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08001271 err = gm_phy_write(hw, sky2->port, data->reg_num & 0x1f,
1272 data->val_in);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001273 spin_unlock_bh(&sky2->phy_lock);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08001274 break;
1275 }
1276 return err;
1277}
1278
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001279#ifdef SKY2_VLAN_TAG_USED
Stephen Hemmingerd494eac2008-05-14 17:04:13 -07001280static void sky2_set_vlan_mode(struct sky2_hw *hw, u16 port, bool onoff)
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001281{
Stephen Hemmingerd494eac2008-05-14 17:04:13 -07001282 if (onoff) {
Stephen Hemminger3d4e66f2007-06-01 09:43:58 -07001283 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T),
1284 RX_VLAN_STRIP_ON);
1285 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
1286 TX_VLAN_TAG_ON);
1287 } else {
1288 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T),
1289 RX_VLAN_STRIP_OFF);
1290 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
1291 TX_VLAN_TAG_OFF);
1292 }
Stephen Hemmingerd494eac2008-05-14 17:04:13 -07001293}
1294
1295static void sky2_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
1296{
1297 struct sky2_port *sky2 = netdev_priv(dev);
1298 struct sky2_hw *hw = sky2->hw;
1299 u16 port = sky2->port;
1300
1301 netif_tx_lock_bh(dev);
1302 napi_disable(&hw->napi);
1303
1304 sky2->vlgrp = grp;
1305 sky2_set_vlan_mode(hw, port, grp != NULL);
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001306
David S. Millerd1d08d12008-01-07 20:53:33 -08001307 sky2_read32(hw, B0_Y2_SP_LISR);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001308 napi_enable(&hw->napi);
Stephen Hemminger2bb8c262006-09-26 11:57:42 -07001309 netif_tx_unlock_bh(dev);
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001310}
1311#endif
1312
Stephen Hemmingerbd1c6862009-06-17 07:30:38 +00001313/* Amount of required worst case padding in rx buffer */
1314static inline unsigned sky2_rx_pad(const struct sky2_hw *hw)
1315{
1316 return (hw->flags & SKY2_HW_RAM_BUFFER) ? 8 : 2;
1317}
1318
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001319/*
Stephen Hemminger14d02632006-09-26 11:57:43 -07001320 * Allocate an skb for receiving. If the MTU is large enough
1321 * make the skb non-linear with a fragment list of pages.
Stephen Hemminger82788c72006-01-17 13:43:10 -08001322 */
Stephen Hemminger14d02632006-09-26 11:57:43 -07001323static struct sk_buff *sky2_rx_alloc(struct sky2_port *sky2)
Stephen Hemminger82788c72006-01-17 13:43:10 -08001324{
1325 struct sk_buff *skb;
Stephen Hemminger14d02632006-09-26 11:57:43 -07001326 int i;
Stephen Hemminger82788c72006-01-17 13:43:10 -08001327
Stephen Hemminger724b6942009-08-18 15:17:10 +00001328 skb = netdev_alloc_skb(sky2->netdev,
1329 sky2->rx_data_size + sky2_rx_pad(sky2->hw));
Stephen Hemmingerbd1c6862009-06-17 07:30:38 +00001330 if (!skb)
1331 goto nomem;
1332
Stephen Hemminger39dbd952008-02-04 19:45:13 -08001333 if (sky2->hw->flags & SKY2_HW_RAM_BUFFER) {
Stephen Hemmingerf03b8652007-11-28 14:27:03 -08001334 unsigned char *start;
1335 /*
1336 * Workaround for a bug in FIFO that cause hang
1337 * if the FIFO if the receive buffer is not 64 byte aligned.
1338 * The buffer returned from netdev_alloc_skb is
1339 * aligned except if slab debugging is enabled.
1340 */
Stephen Hemmingerf03b8652007-11-28 14:27:03 -08001341 start = PTR_ALIGN(skb->data, 8);
1342 skb_reserve(skb, start - skb->data);
Stephen Hemmingerbd1c6862009-06-17 07:30:38 +00001343 } else
Stephen Hemmingerf03b8652007-11-28 14:27:03 -08001344 skb_reserve(skb, NET_IP_ALIGN);
Stephen Hemminger14d02632006-09-26 11:57:43 -07001345
1346 for (i = 0; i < sky2->rx_nfrags; i++) {
1347 struct page *page = alloc_page(GFP_ATOMIC);
1348
1349 if (!page)
1350 goto free_partial;
1351 skb_fill_page_desc(skb, i, page, 0, PAGE_SIZE);
Stephen Hemminger82788c72006-01-17 13:43:10 -08001352 }
1353
1354 return skb;
Stephen Hemminger14d02632006-09-26 11:57:43 -07001355free_partial:
1356 kfree_skb(skb);
1357nomem:
1358 return NULL;
Stephen Hemminger82788c72006-01-17 13:43:10 -08001359}
1360
Stephen Hemminger55c9dd32007-07-09 15:33:37 -07001361static inline void sky2_rx_update(struct sky2_port *sky2, unsigned rxq)
1362{
1363 sky2_put_idx(sky2->hw, rxq, sky2->rx_put);
1364}
1365
Mike McCormack200ac492010-02-12 06:58:03 +00001366static int sky2_alloc_rx_skbs(struct sky2_port *sky2)
1367{
1368 struct sky2_hw *hw = sky2->hw;
1369 unsigned i;
1370
1371 sky2->rx_data_size = sky2_get_rx_data_size(sky2);
1372
1373 /* Fill Rx ring */
1374 for (i = 0; i < sky2->rx_pending; i++) {
1375 struct rx_ring_info *re = sky2->rx_ring + i;
1376
1377 re->skb = sky2_rx_alloc(sky2);
1378 if (!re->skb)
1379 return -ENOMEM;
1380
1381 if (sky2_rx_map_skb(hw->pdev, re, sky2->rx_data_size)) {
1382 dev_kfree_skb(re->skb);
1383 re->skb = NULL;
1384 return -ENOMEM;
1385 }
1386 }
1387 return 0;
1388}
1389
Stephen Hemminger82788c72006-01-17 13:43:10 -08001390/*
Mike McCormack200ac492010-02-12 06:58:03 +00001391 * Setup receiver buffer pool.
Stephen Hemminger14d02632006-09-26 11:57:43 -07001392 * Normal case this ends up creating one list element for skb
1393 * in the receive ring. Worst case if using large MTU and each
1394 * allocation falls on a different 64 bit region, that results
1395 * in 6 list elements per ring entry.
1396 * One element is used for checksum enable/disable, and one
1397 * extra to avoid wrap.
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001398 */
Mike McCormack200ac492010-02-12 06:58:03 +00001399static void sky2_rx_start(struct sky2_port *sky2)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001400{
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001401 struct sky2_hw *hw = sky2->hw;
Stephen Hemminger14d02632006-09-26 11:57:43 -07001402 struct rx_ring_info *re;
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001403 unsigned rxq = rxqaddr[sky2->port];
Mike McCormack39ef1102010-02-12 06:58:02 +00001404 unsigned i, thresh;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001405
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001406 sky2->rx_put = sky2->rx_next = 0;
shemminger@osdl.orgaf4ed7e2005-11-30 11:45:21 -08001407 sky2_qset(hw, rxq);
Stephen Hemminger977bdf02006-02-22 11:44:58 -08001408
Stephen Hemmingerc3905bc42006-12-04 17:08:19 -08001409 /* On PCI express lowering the watermark gives better performance */
1410 if (pci_find_capability(hw->pdev, PCI_CAP_ID_EXP))
1411 sky2_write32(hw, Q_ADDR(rxq, Q_WM), BMU_WM_PEX);
1412
1413 /* These chips have no ram buffer?
1414 * MAC Rx RAM Read is controlled by hardware */
Stephen Hemminger8df9a872006-12-01 14:29:35 -08001415 if (hw->chip_id == CHIP_ID_YUKON_EC_U &&
Joe Perches8e95a202009-12-03 07:58:21 +00001416 (hw->chip_rev == CHIP_REV_YU_EC_U_A1 ||
1417 hw->chip_rev == CHIP_REV_YU_EC_U_B0))
Stephen Hemmingerf449c7c2007-06-04 17:23:23 -07001418 sky2_write32(hw, Q_ADDR(rxq, Q_TEST), F_M_RX_RAM_DIS);
Stephen Hemminger977bdf02006-02-22 11:44:58 -08001419
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001420 sky2_prefetch_init(hw, rxq, sky2->rx_le_map, RX_LE_SIZE - 1);
1421
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001422 if (!(hw->flags & SKY2_HW_NEW_LE))
1423 rx_set_checksum(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001424
Mike McCormack200ac492010-02-12 06:58:03 +00001425 /* submit Rx ring */
Stephen Hemminger14d02632006-09-26 11:57:43 -07001426 for (i = 0; i < sky2->rx_pending; i++) {
1427 re = sky2->rx_ring + i;
Stephen Hemminger14d02632006-09-26 11:57:43 -07001428 sky2_rx_submit(sky2, re);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001429 }
1430
Stephen Hemmingera1433ac2006-05-22 12:03:42 -07001431 /*
1432 * The receiver hangs if it receives frames larger than the
1433 * packet buffer. As a workaround, truncate oversize frames, but
1434 * the register is limited to 9 bits, so if you do frames > 2052
1435 * you better get the MTU right!
1436 */
Mike McCormack39ef1102010-02-12 06:58:02 +00001437 thresh = sky2_get_rx_threshold(sky2);
Stephen Hemmingera1433ac2006-05-22 12:03:42 -07001438 if (thresh > 0x1ff)
1439 sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_OFF);
1440 else {
1441 sky2_write16(hw, SK_REG(sky2->port, RX_GMF_TR_THR), thresh);
1442 sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_ON);
1443 }
1444
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001445 /* Tell chip about available buffers */
Stephen Hemminger55c9dd32007-07-09 15:33:37 -07001446 sky2_rx_update(sky2, rxq);
Stephen Hemminger877c8572009-10-29 06:37:08 +00001447
1448 if (hw->chip_id == CHIP_ID_YUKON_EX ||
1449 hw->chip_id == CHIP_ID_YUKON_SUPR) {
1450 /*
1451 * Disable flushing of non ASF packets;
1452 * must be done after initializing the BMUs;
1453 * drivers without ASF support should do this too, otherwise
1454 * it may happen that they cannot run on ASF devices;
1455 * remember that the MAC FIFO isn't reset during initialization.
1456 */
1457 sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_MACSEC_FLUSH_OFF);
1458 }
1459
1460 if (hw->chip_id >= CHIP_ID_YUKON_SUPR) {
1461 /* Enable RX Home Address & Routing Header checksum fix */
1462 sky2_write16(hw, SK_REG(sky2->port, RX_GMF_FL_CTRL),
1463 RX_IPV6_SA_MOB_ENA | RX_IPV6_DA_MOB_ENA);
1464
1465 /* Enable TX Home Address & Routing Header checksum fix */
1466 sky2_write32(hw, Q_ADDR(txqaddr[sky2->port], Q_TEST),
1467 TBMU_TEST_HOME_ADD_FIX_EN | TBMU_TEST_ROUTING_ADD_FIX_EN);
1468 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001469}
1470
Mike McCormack90bbebb2009-09-01 03:21:35 +00001471static int sky2_alloc_buffers(struct sky2_port *sky2)
1472{
1473 struct sky2_hw *hw = sky2->hw;
1474
1475 /* must be power of 2 */
1476 sky2->tx_le = pci_alloc_consistent(hw->pdev,
1477 sky2->tx_ring_size *
1478 sizeof(struct sky2_tx_le),
1479 &sky2->tx_le_map);
1480 if (!sky2->tx_le)
1481 goto nomem;
1482
1483 sky2->tx_ring = kcalloc(sky2->tx_ring_size, sizeof(struct tx_ring_info),
1484 GFP_KERNEL);
1485 if (!sky2->tx_ring)
1486 goto nomem;
1487
1488 sky2->rx_le = pci_alloc_consistent(hw->pdev, RX_LE_BYTES,
1489 &sky2->rx_le_map);
1490 if (!sky2->rx_le)
1491 goto nomem;
1492 memset(sky2->rx_le, 0, RX_LE_BYTES);
1493
1494 sky2->rx_ring = kcalloc(sky2->rx_pending, sizeof(struct rx_ring_info),
1495 GFP_KERNEL);
1496 if (!sky2->rx_ring)
1497 goto nomem;
1498
Mike McCormack200ac492010-02-12 06:58:03 +00001499 return sky2_alloc_rx_skbs(sky2);
Mike McCormack90bbebb2009-09-01 03:21:35 +00001500nomem:
1501 return -ENOMEM;
1502}
1503
1504static void sky2_free_buffers(struct sky2_port *sky2)
1505{
1506 struct sky2_hw *hw = sky2->hw;
1507
Mike McCormack200ac492010-02-12 06:58:03 +00001508 sky2_rx_clean(sky2);
1509
Mike McCormack90bbebb2009-09-01 03:21:35 +00001510 if (sky2->rx_le) {
1511 pci_free_consistent(hw->pdev, RX_LE_BYTES,
1512 sky2->rx_le, sky2->rx_le_map);
1513 sky2->rx_le = NULL;
1514 }
1515 if (sky2->tx_le) {
1516 pci_free_consistent(hw->pdev,
1517 sky2->tx_ring_size * sizeof(struct sky2_tx_le),
1518 sky2->tx_le, sky2->tx_le_map);
1519 sky2->tx_le = NULL;
1520 }
1521 kfree(sky2->tx_ring);
1522 kfree(sky2->rx_ring);
1523
1524 sky2->tx_ring = NULL;
1525 sky2->rx_ring = NULL;
1526}
1527
Mike McCormackea0f71e2010-02-12 06:58:04 +00001528static void sky2_hw_up(struct sky2_port *sky2)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001529{
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001530 struct sky2_hw *hw = sky2->hw;
1531 unsigned port = sky2->port;
Mike McCormackea0f71e2010-02-12 06:58:04 +00001532 u32 ramsize;
1533 int cap;
Stephen Hemminger843a46f2006-05-11 15:07:28 -07001534 struct net_device *otherdev = hw->dev[sky2->port^1];
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001535
Mike McCormackea0f71e2010-02-12 06:58:04 +00001536 tx_init(sky2);
1537
Stephen Hemmingeree7abb02006-05-18 11:16:21 -07001538 /*
1539 * On dual port PCI-X card, there is an problem where status
1540 * can be received out of order due to split transactions
Stephen Hemminger843a46f2006-05-11 15:07:28 -07001541 */
Stephen Hemmingeree7abb02006-05-18 11:16:21 -07001542 if (otherdev && netif_running(otherdev) &&
1543 (cap = pci_find_capability(hw->pdev, PCI_CAP_ID_PCIX))) {
Stephen Hemmingeree7abb02006-05-18 11:16:21 -07001544 u16 cmd;
Stephen Hemminger843a46f2006-05-11 15:07:28 -07001545
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08001546 cmd = sky2_pci_read16(hw, cap + PCI_X_CMD);
Stephen Hemmingeree7abb02006-05-18 11:16:21 -07001547 cmd &= ~PCI_X_CMD_MAX_SPLIT;
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08001548 sky2_pci_write16(hw, cap + PCI_X_CMD, cmd);
Mike McCormackea0f71e2010-02-12 06:58:04 +00001549 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001550
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001551 sky2_mac_init(hw, port);
1552
Stephen Hemmingere0c28112007-09-20 13:03:49 -07001553 /* Register is number of 4K blocks on internal RAM buffer. */
1554 ramsize = sky2_read8(hw, B2_E_0) * 4;
1555 if (ramsize > 0) {
Stephen Hemminger67712902006-12-04 15:53:45 -08001556 u32 rxspace;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001557
Mike McCormackea0f71e2010-02-12 06:58:04 +00001558 pr_debug(PFX "%s: ram buffer %dK\n", sky2->netdev->name, ramsize);
Stephen Hemminger67712902006-12-04 15:53:45 -08001559 if (ramsize < 16)
1560 rxspace = ramsize / 2;
1561 else
1562 rxspace = 8 + (2*(ramsize - 16))/3;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001563
Stephen Hemminger67712902006-12-04 15:53:45 -08001564 sky2_ramset(hw, rxqaddr[port], 0, rxspace);
1565 sky2_ramset(hw, txqaddr[port], rxspace, ramsize - rxspace);
1566
1567 /* Make sure SyncQ is disabled */
1568 sky2_write8(hw, RB_ADDR(port == 0 ? Q_XS1 : Q_XS2, RB_CTRL),
1569 RB_RST_SET);
1570 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07001571
shemminger@osdl.orgaf4ed7e2005-11-30 11:45:21 -08001572 sky2_qset(hw, txqaddr[port]);
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -08001573
Stephen Hemminger69161612007-06-04 17:23:26 -07001574 /* This is copied from sk98lin 10.0.5.3; no one tells me about erratta's */
1575 if (hw->chip_id == CHIP_ID_YUKON_EX && hw->chip_rev == CHIP_REV_YU_EX_B0)
1576 sky2_write32(hw, Q_ADDR(txqaddr[port], Q_TEST), F_TX_CHK_AUTO_OFF);
1577
Stephen Hemminger977bdf02006-02-22 11:44:58 -08001578 /* Set almost empty threshold */
Joe Perches8e95a202009-12-03 07:58:21 +00001579 if (hw->chip_id == CHIP_ID_YUKON_EC_U &&
1580 hw->chip_rev == CHIP_REV_YU_EC_U_A0)
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07001581 sky2_write16(hw, Q_ADDR(txqaddr[port], Q_AL), ECU_TXFF_LEV);
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -08001582
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001583 sky2_prefetch_init(hw, txqaddr[port], sky2->tx_le_map,
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001584 sky2->tx_ring_size - 1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001585
Stephen Hemmingerd494eac2008-05-14 17:04:13 -07001586#ifdef SKY2_VLAN_TAG_USED
1587 sky2_set_vlan_mode(hw, port, sky2->vlgrp != NULL);
1588#endif
1589
Mike McCormack200ac492010-02-12 06:58:03 +00001590 sky2_rx_start(sky2);
Mike McCormackea0f71e2010-02-12 06:58:04 +00001591}
1592
1593/* Bring up network interface. */
1594static int sky2_up(struct net_device *dev)
1595{
1596 struct sky2_port *sky2 = netdev_priv(dev);
1597 struct sky2_hw *hw = sky2->hw;
1598 unsigned port = sky2->port;
1599 u32 imask;
1600 int err;
1601
1602 netif_carrier_off(dev);
1603
1604 err = sky2_alloc_buffers(sky2);
1605 if (err)
1606 goto err_out;
1607
1608 sky2_hw_up(sky2);
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001609
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001610 /* Enable interrupts from phy/mac for port */
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001611 imask = sky2_read32(hw, B0_IMSK);
Stephen Hemmingerf4ea4312006-05-09 14:46:54 -07001612 imask |= portirq_msk[port];
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001613 sky2_write32(hw, B0_IMSK, imask);
Stephen Hemminger1fd82f32009-06-17 07:30:34 +00001614 sky2_read32(hw, B0_IMSK);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001615
Alexey Dobriyana11da892009-01-30 13:45:31 -08001616 if (netif_msg_ifup(sky2))
1617 printk(KERN_INFO PFX "%s: enabling interface\n", dev->name);
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07001618
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001619 return 0;
1620
1621err_out:
Mike McCormack90bbebb2009-09-01 03:21:35 +00001622 sky2_free_buffers(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001623 return err;
1624}
1625
Stephen Hemminger793b8832005-09-14 16:06:14 -07001626/* Modular subtraction in ring */
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001627static inline int tx_inuse(const struct sky2_port *sky2)
Stephen Hemminger793b8832005-09-14 16:06:14 -07001628{
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001629 return (sky2->tx_prod - sky2->tx_cons) & (sky2->tx_ring_size - 1);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001630}
1631
1632/* Number of list elements available for next tx */
1633static inline int tx_avail(const struct sky2_port *sky2)
1634{
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001635 return sky2->tx_pending - tx_inuse(sky2);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001636}
1637
1638/* Estimate of number of transmit list elements required */
Stephen Hemminger28bd1812006-01-17 13:43:19 -08001639static unsigned tx_le_req(const struct sk_buff *skb)
Stephen Hemminger793b8832005-09-14 16:06:14 -07001640{
1641 unsigned count;
1642
Stephen Hemminger07e31632009-09-14 06:12:55 +00001643 count = (skb_shinfo(skb)->nr_frags + 1)
1644 * (sizeof(dma_addr_t) / sizeof(u32));
Stephen Hemminger793b8832005-09-14 16:06:14 -07001645
Herbert Xu89114af2006-07-08 13:34:32 -07001646 if (skb_is_gso(skb))
Stephen Hemminger793b8832005-09-14 16:06:14 -07001647 ++count;
Stephen Hemminger07e31632009-09-14 06:12:55 +00001648 else if (sizeof(dma_addr_t) == sizeof(u32))
1649 ++count; /* possible vlan */
Stephen Hemminger793b8832005-09-14 16:06:14 -07001650
Patrick McHardy84fa7932006-08-29 16:44:56 -07001651 if (skb->ip_summed == CHECKSUM_PARTIAL)
Stephen Hemminger793b8832005-09-14 16:06:14 -07001652 ++count;
1653
1654 return count;
1655}
1656
stephen hemmingerf6815072010-02-01 13:41:47 +00001657static void sky2_tx_unmap(struct pci_dev *pdev, struct tx_ring_info *re)
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001658{
1659 if (re->flags & TX_MAP_SINGLE)
1660 pci_unmap_single(pdev, pci_unmap_addr(re, mapaddr),
1661 pci_unmap_len(re, maplen),
1662 PCI_DMA_TODEVICE);
1663 else if (re->flags & TX_MAP_PAGE)
1664 pci_unmap_page(pdev, pci_unmap_addr(re, mapaddr),
1665 pci_unmap_len(re, maplen),
1666 PCI_DMA_TODEVICE);
stephen hemmingerf6815072010-02-01 13:41:47 +00001667 re->flags = 0;
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001668}
1669
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001670/*
Stephen Hemminger793b8832005-09-14 16:06:14 -07001671 * Put one packet in ring for transmit.
1672 * A single packet can generate multiple list elements, and
1673 * the number of ring elements will probably be less than the number
1674 * of list elements used.
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001675 */
Stephen Hemminger613573252009-08-31 19:50:58 +00001676static netdev_tx_t sky2_xmit_frame(struct sk_buff *skb,
1677 struct net_device *dev)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001678{
1679 struct sky2_port *sky2 = netdev_priv(dev);
1680 struct sky2_hw *hw = sky2->hw;
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001681 struct sky2_tx_le *le = NULL;
Stephen Hemminger6cdbbdf2005-12-09 11:35:01 -08001682 struct tx_ring_info *re;
Mike McCormack9b289c32009-08-14 05:15:12 +00001683 unsigned i, len;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001684 dma_addr_t mapping;
Stephen Hemminger5dce95e2009-08-18 15:17:06 +00001685 u32 upper;
1686 u16 slot;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001687 u16 mss;
1688 u8 ctrl;
1689
Stephen Hemminger2bb8c262006-09-26 11:57:42 -07001690 if (unlikely(tx_avail(sky2) < tx_le_req(skb)))
1691 return NETDEV_TX_BUSY;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001692
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001693 len = skb_headlen(skb);
1694 mapping = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001695
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001696 if (pci_dma_mapping_error(hw->pdev, mapping))
1697 goto mapping_error;
1698
Mike McCormack9b289c32009-08-14 05:15:12 +00001699 slot = sky2->tx_prod;
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001700 if (unlikely(netif_msg_tx_queued(sky2)))
1701 printk(KERN_DEBUG "%s: tx queued, slot %u, len %d\n",
Mike McCormack9b289c32009-08-14 05:15:12 +00001702 dev->name, slot, skb->len);
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001703
Stephen Hemminger86c68872008-01-10 16:14:12 -08001704 /* Send high bits if needed */
Stephen Hemminger5dce95e2009-08-18 15:17:06 +00001705 upper = upper_32_bits(mapping);
1706 if (upper != sky2->tx_last_upper) {
Mike McCormack9b289c32009-08-14 05:15:12 +00001707 le = get_tx_le(sky2, &slot);
Stephen Hemminger5dce95e2009-08-18 15:17:06 +00001708 le->addr = cpu_to_le32(upper);
1709 sky2->tx_last_upper = upper;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001710 le->opcode = OP_ADDR64 | HW_OWNER;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001711 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001712
1713 /* Check for TCP Segmentation Offload */
Herbert Xu79671682006-06-22 02:40:14 -07001714 mss = skb_shinfo(skb)->gso_size;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001715 if (mss != 0) {
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001716
1717 if (!(hw->flags & SKY2_HW_NEW_LE))
Stephen Hemminger69161612007-06-04 17:23:26 -07001718 mss += ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001719
Stephen Hemminger69161612007-06-04 17:23:26 -07001720 if (mss != sky2->tx_last_mss) {
Mike McCormack9b289c32009-08-14 05:15:12 +00001721 le = get_tx_le(sky2, &slot);
Stephen Hemminger69161612007-06-04 17:23:26 -07001722 le->addr = cpu_to_le32(mss);
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001723
1724 if (hw->flags & SKY2_HW_NEW_LE)
Stephen Hemminger69161612007-06-04 17:23:26 -07001725 le->opcode = OP_MSS | HW_OWNER;
1726 else
1727 le->opcode = OP_LRGLEN | HW_OWNER;
shemminger@osdl.orge07560c2006-08-28 10:00:49 -07001728 sky2->tx_last_mss = mss;
1729 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001730 }
1731
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001732 ctrl = 0;
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001733#ifdef SKY2_VLAN_TAG_USED
1734 /* Add VLAN tag, can piggyback on LRGLEN or ADDR64 */
1735 if (sky2->vlgrp && vlan_tx_tag_present(skb)) {
1736 if (!le) {
Mike McCormack9b289c32009-08-14 05:15:12 +00001737 le = get_tx_le(sky2, &slot);
Stephen Hemmingerf65b1382006-09-06 12:45:02 -07001738 le->addr = 0;
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001739 le->opcode = OP_VLAN|HW_OWNER;
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001740 } else
1741 le->opcode |= OP_VLAN;
1742 le->length = cpu_to_be16(vlan_tx_tag_get(skb));
1743 ctrl |= INS_VLAN;
1744 }
1745#endif
1746
1747 /* Handle TCP checksum offload */
Patrick McHardy84fa7932006-08-29 16:44:56 -07001748 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Stephen Hemminger69161612007-06-04 17:23:26 -07001749 /* On Yukon EX (some versions) encoding change. */
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001750 if (hw->flags & SKY2_HW_AUTO_TX_SUM)
Stephen Hemminger69161612007-06-04 17:23:26 -07001751 ctrl |= CALSUM; /* auto checksum */
1752 else {
1753 const unsigned offset = skb_transport_offset(skb);
1754 u32 tcpsum;
Stephen Hemmingerf65b1382006-09-06 12:45:02 -07001755
Stephen Hemminger69161612007-06-04 17:23:26 -07001756 tcpsum = offset << 16; /* sum start */
1757 tcpsum |= offset + skb->csum_offset; /* sum write */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001758
Stephen Hemminger69161612007-06-04 17:23:26 -07001759 ctrl |= CALSUM | WR_SUM | INIT_SUM | LOCK_SUM;
1760 if (ip_hdr(skb)->protocol == IPPROTO_UDP)
1761 ctrl |= UDPTCP;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001762
Stephen Hemminger69161612007-06-04 17:23:26 -07001763 if (tcpsum != sky2->tx_tcpsum) {
1764 sky2->tx_tcpsum = tcpsum;
shemminger@osdl.org1d179332006-08-28 10:00:50 -07001765
Mike McCormack9b289c32009-08-14 05:15:12 +00001766 le = get_tx_le(sky2, &slot);
Stephen Hemminger69161612007-06-04 17:23:26 -07001767 le->addr = cpu_to_le32(tcpsum);
1768 le->length = 0; /* initial checksum value */
1769 le->ctrl = 1; /* one packet */
1770 le->opcode = OP_TCPLISW | HW_OWNER;
1771 }
shemminger@osdl.org1d179332006-08-28 10:00:50 -07001772 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001773 }
1774
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001775 re = sky2->tx_ring + slot;
1776 re->flags = TX_MAP_SINGLE;
1777 pci_unmap_addr_set(re, mapaddr, mapping);
1778 pci_unmap_len_set(re, maplen, len);
1779
Mike McCormack9b289c32009-08-14 05:15:12 +00001780 le = get_tx_le(sky2, &slot);
Stephen Hemmingerd6e74b62009-08-18 15:17:05 +00001781 le->addr = cpu_to_le32(lower_32_bits(mapping));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001782 le->length = cpu_to_le16(len);
1783 le->ctrl = ctrl;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001784 le->opcode = mss ? (OP_LARGESEND | HW_OWNER) : (OP_PACKET | HW_OWNER);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001785
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001786
1787 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
Stephen Hemminger291ea612006-09-26 11:57:41 -07001788 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001789
1790 mapping = pci_map_page(hw->pdev, frag->page, frag->page_offset,
1791 frag->size, PCI_DMA_TODEVICE);
Stephen Hemminger86c68872008-01-10 16:14:12 -08001792
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001793 if (pci_dma_mapping_error(hw->pdev, mapping))
1794 goto mapping_unwind;
1795
Stephen Hemminger5dce95e2009-08-18 15:17:06 +00001796 upper = upper_32_bits(mapping);
1797 if (upper != sky2->tx_last_upper) {
Mike McCormack9b289c32009-08-14 05:15:12 +00001798 le = get_tx_le(sky2, &slot);
Stephen Hemminger5dce95e2009-08-18 15:17:06 +00001799 le->addr = cpu_to_le32(upper);
1800 sky2->tx_last_upper = upper;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001801 le->opcode = OP_ADDR64 | HW_OWNER;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001802 }
1803
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001804 re = sky2->tx_ring + slot;
1805 re->flags = TX_MAP_PAGE;
1806 pci_unmap_addr_set(re, mapaddr, mapping);
1807 pci_unmap_len_set(re, maplen, frag->size);
1808
Mike McCormack9b289c32009-08-14 05:15:12 +00001809 le = get_tx_le(sky2, &slot);
Stephen Hemmingerd6e74b62009-08-18 15:17:05 +00001810 le->addr = cpu_to_le32(lower_32_bits(mapping));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001811 le->length = cpu_to_le16(frag->size);
1812 le->ctrl = ctrl;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001813 le->opcode = OP_BUFFER | HW_OWNER;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001814 }
Stephen Hemminger6cdbbdf2005-12-09 11:35:01 -08001815
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001816 re->skb = skb;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001817 le->ctrl |= EOP;
1818
Mike McCormack9b289c32009-08-14 05:15:12 +00001819 sky2->tx_prod = slot;
1820
shemminger@osdl.org97bda702006-08-28 10:00:47 -07001821 if (tx_avail(sky2) <= MAX_SKB_TX_LE)
1822 netif_stop_queue(dev);
Stephen Hemmingerb19666d2006-03-07 11:06:36 -08001823
Stephen Hemminger290d4de2006-03-20 15:48:15 -08001824 sky2_put_idx(hw, txqaddr[sky2->port], sky2->tx_prod);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001825
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001826 return NETDEV_TX_OK;
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001827
1828mapping_unwind:
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001829 for (i = sky2->tx_prod; i != slot; i = RING_NEXT(i, sky2->tx_ring_size)) {
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001830 re = sky2->tx_ring + i;
1831
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001832 sky2_tx_unmap(hw->pdev, re);
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001833 }
1834
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001835mapping_error:
1836 if (net_ratelimit())
1837 dev_warn(&hw->pdev->dev, "%s: tx mapping error\n", dev->name);
1838 dev_kfree_skb(skb);
1839 return NETDEV_TX_OK;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001840}
1841
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001842/*
Stephen Hemminger793b8832005-09-14 16:06:14 -07001843 * Free ring elements from starting at tx_cons until "done"
1844 *
Stephen Hemminger481cea42009-08-14 15:33:19 -07001845 * NB:
1846 * 1. The hardware will tell us about partial completion of multi-part
Stephen Hemminger291ea612006-09-26 11:57:41 -07001847 * buffers so make sure not to free skb to early.
Stephen Hemminger481cea42009-08-14 15:33:19 -07001848 * 2. This may run in parallel start_xmit because the it only
1849 * looks at the tail of the queue of FIFO (tx_cons), not
1850 * the head (tx_prod)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001851 */
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001852static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001853{
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001854 struct net_device *dev = sky2->netdev;
Stephen Hemminger291ea612006-09-26 11:57:41 -07001855 unsigned idx;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001856
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001857 BUG_ON(done >= sky2->tx_ring_size);
shemminger@osdl.org22247952005-11-30 11:45:19 -08001858
Stephen Hemminger291ea612006-09-26 11:57:41 -07001859 for (idx = sky2->tx_cons; idx != done;
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001860 idx = RING_NEXT(idx, sky2->tx_ring_size)) {
Stephen Hemminger291ea612006-09-26 11:57:41 -07001861 struct tx_ring_info *re = sky2->tx_ring + idx;
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001862 struct sk_buff *skb = re->skb;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001863
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001864 sky2_tx_unmap(sky2->hw->pdev, re);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001865
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001866 if (skb) {
Stephen Hemminger291ea612006-09-26 11:57:41 -07001867 if (unlikely(netif_msg_tx_done(sky2)))
1868 printk(KERN_DEBUG "%s: tx done %u\n",
1869 dev->name, idx);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07001870
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07001871 dev->stats.tx_packets++;
Stephen Hemmingerbd1c6862009-06-17 07:30:38 +00001872 dev->stats.tx_bytes += skb->len;
shemminger@linux-foundation.org2bf56fe2007-01-26 11:38:39 -08001873
stephen hemmingerf6815072010-02-01 13:41:47 +00001874 re->skb = NULL;
Stephen Hemminger724b6942009-08-18 15:17:10 +00001875 dev_kfree_skb_any(skb);
Stephen Hemmingerbd1c6862009-06-17 07:30:38 +00001876
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001877 sky2->tx_next = RING_NEXT(idx, sky2->tx_ring_size);
Stephen Hemminger291ea612006-09-26 11:57:41 -07001878 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07001879 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07001880
Stephen Hemminger291ea612006-09-26 11:57:41 -07001881 sky2->tx_cons = idx;
Stephen Hemminger50432cb2007-05-14 12:38:15 -07001882 smp_mb();
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001883}
1884
Mike McCormack264bb4f2009-08-14 05:15:14 +00001885static void sky2_tx_reset(struct sky2_hw *hw, unsigned port)
Mike McCormacka5109962009-08-14 05:15:13 +00001886{
Mike McCormacka5109962009-08-14 05:15:13 +00001887 /* Disable Force Sync bit and Enable Alloc bit */
1888 sky2_write8(hw, SK_REG(port, TXA_CTRL),
1889 TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
1890
1891 /* Stop Interval Timer and Limit Counter of Tx Arbiter */
1892 sky2_write32(hw, SK_REG(port, TXA_ITI_INI), 0L);
1893 sky2_write32(hw, SK_REG(port, TXA_LIM_INI), 0L);
1894
1895 /* Reset the PCI FIFO of the async Tx queue */
1896 sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR),
1897 BMU_RST_SET | BMU_FIFO_RST);
1898
1899 /* Reset the Tx prefetch units */
1900 sky2_write32(hw, Y2_QADDR(txqaddr[port], PREF_UNIT_CTRL),
1901 PREF_UNIT_RST_SET);
1902
1903 sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET);
1904 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
1905}
1906
Mike McCormackf2b31cb2010-02-12 06:58:05 +00001907static void sky2_hw_down(struct sky2_port *sky2)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001908{
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001909 struct sky2_hw *hw = sky2->hw;
1910 unsigned port = sky2->port;
Mike McCormackf2b31cb2010-02-12 06:58:05 +00001911 u16 ctrl;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001912
Stephen Hemmingerd104aca2009-06-17 07:30:32 +00001913 /* Force flow control off */
1914 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001915
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001916 /* Stop transmitter */
1917 sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_STOP);
1918 sky2_read32(hw, Q_ADDR(txqaddr[port], Q_CSR));
1919
1920 sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL),
Stephen Hemminger793b8832005-09-14 16:06:14 -07001921 RB_RST_SET | RB_DIS_OP_MD);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001922
1923 ctrl = gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001924 ctrl &= ~(GM_GPCR_TX_ENA | GM_GPCR_RX_ENA);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001925 gma_write16(hw, port, GM_GP_CTRL, ctrl);
1926
1927 sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
1928
1929 /* Workaround shared GMAC reset */
Joe Perches8e95a202009-12-03 07:58:21 +00001930 if (!(hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0 &&
1931 port == 0 && hw->dev[1] && netif_running(hw->dev[1])))
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001932 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
1933
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001934 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001935
Stephen Hemminger6c835042009-06-17 07:30:35 +00001936 /* Force any delayed status interrrupt and NAPI */
1937 sky2_write32(hw, STAT_LEV_TIMER_CNT, 0);
1938 sky2_write32(hw, STAT_TX_TIMER_CNT, 0);
1939 sky2_write32(hw, STAT_ISR_TIMER_CNT, 0);
1940 sky2_read8(hw, STAT_ISR_TIMER_CTRL);
1941
Mike McCormacka947a392009-07-21 20:57:56 -07001942 sky2_rx_stop(sky2);
1943
Stephen Hemminger0da6d7b2009-08-14 05:15:15 +00001944 spin_lock_bh(&sky2->phy_lock);
Stephen Hemmingerb96936da72008-05-14 17:04:15 -07001945 sky2_phy_power_down(hw, port);
Stephen Hemminger0da6d7b2009-08-14 05:15:15 +00001946 spin_unlock_bh(&sky2->phy_lock);
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -07001947
Mike McCormack264bb4f2009-08-14 05:15:14 +00001948 sky2_tx_reset(hw, port);
1949
Stephen Hemminger481cea42009-08-14 15:33:19 -07001950 /* Free any pending frames stuck in HW queue */
1951 sky2_tx_complete(sky2, sky2->tx_prod);
Mike McCormackf2b31cb2010-02-12 06:58:05 +00001952}
1953
1954/* Network shutdown */
1955static int sky2_down(struct net_device *dev)
1956{
1957 struct sky2_port *sky2 = netdev_priv(dev);
Mike McCormack8a0c9222010-02-12 06:58:06 +00001958 struct sky2_hw *hw = sky2->hw;
Mike McCormackf2b31cb2010-02-12 06:58:05 +00001959
1960 /* Never really got started! */
1961 if (!sky2->tx_le)
1962 return 0;
1963
1964 if (netif_msg_ifdown(sky2))
1965 printk(KERN_INFO PFX "%s: disabling interface\n", dev->name);
1966
Mike McCormack8a0c9222010-02-12 06:58:06 +00001967 /* Disable port IRQ */
1968 sky2_write32(hw, B0_IMSK,
1969 sky2_read32(hw, B0_IMSK) & ~portirq_msk[sky2->port]);
1970 sky2_read32(hw, B0_IMSK);
1971
1972 synchronize_irq(hw->pdev->irq);
1973 napi_synchronize(&hw->napi);
1974
Mike McCormackf2b31cb2010-02-12 06:58:05 +00001975 sky2_hw_down(sky2);
Stephen Hemminger481cea42009-08-14 15:33:19 -07001976
Mike McCormack90bbebb2009-09-01 03:21:35 +00001977 sky2_free_buffers(sky2);
Stephen Hemminger1b537562005-12-20 15:08:07 -08001978
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001979 return 0;
1980}
1981
1982static u16 sky2_phy_speed(const struct sky2_hw *hw, u16 aux)
1983{
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001984 if (hw->flags & SKY2_HW_FIBRE_PHY)
Stephen Hemminger793b8832005-09-14 16:06:14 -07001985 return SPEED_1000;
1986
Stephen Hemminger05745c42007-09-19 15:36:45 -07001987 if (!(hw->flags & SKY2_HW_GIGABIT)) {
1988 if (aux & PHY_M_PS_SPEED_100)
1989 return SPEED_100;
1990 else
1991 return SPEED_10;
1992 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001993
1994 switch (aux & PHY_M_PS_SPEED_MSK) {
1995 case PHY_M_PS_SPEED_1000:
1996 return SPEED_1000;
1997 case PHY_M_PS_SPEED_100:
1998 return SPEED_100;
1999 default:
2000 return SPEED_10;
2001 }
2002}
2003
2004static void sky2_link_up(struct sky2_port *sky2)
2005{
2006 struct sky2_hw *hw = sky2->hw;
2007 unsigned port = sky2->port;
2008 u16 reg;
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07002009 static const char *fc_name[] = {
2010 [FC_NONE] = "none",
2011 [FC_TX] = "tx",
2012 [FC_RX] = "rx",
2013 [FC_BOTH] = "both",
2014 };
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002015
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002016 /* enable Rx/Tx */
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -07002017 reg = gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002018 reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA;
2019 gma_write16(hw, port, GM_GP_CTRL, reg);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002020
2021 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
2022
2023 netif_carrier_on(sky2->netdev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002024
Stephen Hemminger75e80682007-09-19 15:36:46 -07002025 mod_timer(&hw->watchdog_timer, jiffies + 1);
Stephen Hemminger32c2c302007-08-21 14:34:03 -07002026
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002027 /* Turn on link LED */
Stephen Hemminger793b8832005-09-14 16:06:14 -07002028 sky2_write8(hw, SK_REG(port, LNK_LED_REG),
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002029 LINKLED_ON | LINKLED_BLINK_OFF | LINKLED_LINKSYNC_OFF);
2030
2031 if (netif_msg_link(sky2))
2032 printk(KERN_INFO PFX
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07002033 "%s: Link is up at %d Mbps, %s duplex, flow control %s\n",
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002034 sky2->netdev->name, sky2->speed,
2035 sky2->duplex == DUPLEX_FULL ? "full" : "half",
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07002036 fc_name[sky2->flow_status]);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002037}
2038
2039static void sky2_link_down(struct sky2_port *sky2)
2040{
2041 struct sky2_hw *hw = sky2->hw;
2042 unsigned port = sky2->port;
2043 u16 reg;
2044
2045 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);
2046
2047 reg = gma_read16(hw, port, GM_GP_CTRL);
2048 reg &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
2049 gma_write16(hw, port, GM_GP_CTRL, reg);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002050
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002051 netif_carrier_off(sky2->netdev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002052
Brandon Philips809aaaa2009-10-29 17:01:49 -07002053 /* Turn off link LED */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002054 sky2_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
2055
2056 if (netif_msg_link(sky2))
2057 printk(KERN_INFO PFX "%s: Link is down.\n", sky2->netdev->name);
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -07002058
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002059 sky2_phy_init(hw, port);
2060}
2061
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07002062static enum flow_control sky2_flow(int rx, int tx)
2063{
2064 if (rx)
2065 return tx ? FC_BOTH : FC_RX;
2066 else
2067 return tx ? FC_TX : FC_NONE;
2068}
2069
Stephen Hemminger793b8832005-09-14 16:06:14 -07002070static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux)
2071{
2072 struct sky2_hw *hw = sky2->hw;
2073 unsigned port = sky2->port;
Stephen Hemmingerda4c1ff2007-02-15 16:40:32 -08002074 u16 advert, lpa;
Stephen Hemminger793b8832005-09-14 16:06:14 -07002075
Stephen Hemmingerda4c1ff2007-02-15 16:40:32 -08002076 advert = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002077 lpa = gm_phy_read(hw, port, PHY_MARV_AUNE_LP);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002078 if (lpa & PHY_M_AN_RF) {
2079 printk(KERN_ERR PFX "%s: remote fault", sky2->netdev->name);
2080 return -1;
2081 }
2082
Stephen Hemminger793b8832005-09-14 16:06:14 -07002083 if (!(aux & PHY_M_PS_SPDUP_RES)) {
2084 printk(KERN_ERR PFX "%s: speed/duplex mismatch",
2085 sky2->netdev->name);
2086 return -1;
2087 }
2088
Stephen Hemminger793b8832005-09-14 16:06:14 -07002089 sky2->speed = sky2_phy_speed(hw, aux);
Stephen Hemminger7c74ac12006-10-17 10:24:08 -07002090 sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
Stephen Hemminger793b8832005-09-14 16:06:14 -07002091
Stephen Hemmingerda4c1ff2007-02-15 16:40:32 -08002092 /* Since the pause result bits seem to in different positions on
2093 * different chips. look at registers.
2094 */
Stephen Hemmingerea76e632007-09-19 15:36:44 -07002095 if (hw->flags & SKY2_HW_FIBRE_PHY) {
Stephen Hemmingerda4c1ff2007-02-15 16:40:32 -08002096 /* Shift for bits in fiber PHY */
2097 advert &= ~(ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM);
2098 lpa &= ~(LPA_PAUSE_CAP|LPA_PAUSE_ASYM);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002099
Stephen Hemmingerda4c1ff2007-02-15 16:40:32 -08002100 if (advert & ADVERTISE_1000XPAUSE)
2101 advert |= ADVERTISE_PAUSE_CAP;
2102 if (advert & ADVERTISE_1000XPSE_ASYM)
2103 advert |= ADVERTISE_PAUSE_ASYM;
2104 if (lpa & LPA_1000XPAUSE)
2105 lpa |= LPA_PAUSE_CAP;
2106 if (lpa & LPA_1000XPAUSE_ASYM)
2107 lpa |= LPA_PAUSE_ASYM;
2108 }
2109
2110 sky2->flow_status = FC_NONE;
2111 if (advert & ADVERTISE_PAUSE_CAP) {
2112 if (lpa & LPA_PAUSE_CAP)
2113 sky2->flow_status = FC_BOTH;
2114 else if (advert & ADVERTISE_PAUSE_ASYM)
2115 sky2->flow_status = FC_RX;
2116 } else if (advert & ADVERTISE_PAUSE_ASYM) {
2117 if ((lpa & LPA_PAUSE_CAP) && (lpa & LPA_PAUSE_ASYM))
2118 sky2->flow_status = FC_TX;
2119 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07002120
Joe Perches8e95a202009-12-03 07:58:21 +00002121 if (sky2->duplex == DUPLEX_HALF && sky2->speed < SPEED_1000 &&
2122 !(hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX))
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07002123 sky2->flow_status = FC_NONE;
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -07002124
Stephen Hemmingerda4c1ff2007-02-15 16:40:32 -08002125 if (sky2->flow_status & FC_TX)
Stephen Hemminger793b8832005-09-14 16:06:14 -07002126 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
2127 else
2128 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
2129
2130 return 0;
2131}
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002132
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002133/* Interrupt from PHY */
2134static void sky2_phy_intr(struct sky2_hw *hw, unsigned port)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002135{
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002136 struct net_device *dev = hw->dev[port];
2137 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002138 u16 istatus, phystat;
2139
Stephen Hemmingerebc646f2006-10-17 10:23:56 -07002140 if (!netif_running(dev))
2141 return;
2142
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002143 spin_lock(&sky2->phy_lock);
2144 istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT);
2145 phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT);
2146
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002147 if (netif_msg_intr(sky2))
2148 printk(KERN_INFO PFX "%s: phy interrupt status 0x%x 0x%x\n",
2149 sky2->netdev->name, istatus, phystat);
2150
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07002151 if (istatus & PHY_M_IS_AN_COMPL) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07002152 if (sky2_autoneg_done(sky2, phystat) == 0)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002153 sky2_link_up(sky2);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002154 goto out;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002155 }
2156
Stephen Hemminger793b8832005-09-14 16:06:14 -07002157 if (istatus & PHY_M_IS_LSP_CHANGE)
2158 sky2->speed = sky2_phy_speed(hw, phystat);
2159
2160 if (istatus & PHY_M_IS_DUP_CHANGE)
2161 sky2->duplex =
2162 (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
2163
2164 if (istatus & PHY_M_IS_LST_CHANGE) {
2165 if (phystat & PHY_M_PS_LINK_UP)
2166 sky2_link_up(sky2);
2167 else
2168 sky2_link_down(sky2);
2169 }
2170out:
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002171 spin_unlock(&sky2->phy_lock);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002172}
2173
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00002174/* Special quick link interrupt (Yukon-2 Optima only) */
2175static void sky2_qlink_intr(struct sky2_hw *hw)
2176{
2177 struct sky2_port *sky2 = netdev_priv(hw->dev[0]);
2178 u32 imask;
2179 u16 phy;
2180
2181 /* disable irq */
2182 imask = sky2_read32(hw, B0_IMSK);
2183 imask &= ~Y2_IS_PHY_QLNK;
2184 sky2_write32(hw, B0_IMSK, imask);
2185
2186 /* reset PHY Link Detect */
2187 phy = sky2_pci_read16(hw, PSM_CONFIG_REG4);
stephen hemmingera40ccc62010-01-24 18:46:06 +00002188 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00002189 sky2_pci_write16(hw, PSM_CONFIG_REG4, phy | 1);
stephen hemmingera40ccc62010-01-24 18:46:06 +00002190 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00002191
2192 sky2_link_up(sky2);
2193}
2194
Stephen Hemminger62335ab2007-02-06 10:45:42 -08002195/* Transmit timeout is only called if we are running, carrier is up
Stephen Hemminger302d1252006-01-17 13:43:20 -08002196 * and tx queue is full (stopped).
2197 */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002198static void sky2_tx_timeout(struct net_device *dev)
2199{
2200 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger8cc048e2005-12-09 11:35:07 -08002201 struct sky2_hw *hw = sky2->hw;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002202
2203 if (netif_msg_timer(sky2))
2204 printk(KERN_ERR PFX "%s: tx timeout\n", dev->name);
2205
Stephen Hemminger8f246642006-03-20 15:48:21 -08002206 printk(KERN_DEBUG PFX "%s: transmit ring %u .. %u report=%u done=%u\n",
Stephen Hemminger62335ab2007-02-06 10:45:42 -08002207 dev->name, sky2->tx_cons, sky2->tx_prod,
2208 sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX),
2209 sky2_read16(hw, Q_ADDR(txqaddr[sky2->port], Q_DONE)));
Stephen Hemminger8cc048e2005-12-09 11:35:07 -08002210
Stephen Hemminger81906792007-02-15 16:40:33 -08002211 /* can't restart safely under softirq */
2212 schedule_work(&hw->restart_work);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002213}
2214
2215static int sky2_change_mtu(struct net_device *dev, int new_mtu)
2216{
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002217 struct sky2_port *sky2 = netdev_priv(dev);
2218 struct sky2_hw *hw = sky2->hw;
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07002219 unsigned port = sky2->port;
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002220 int err;
2221 u16 ctl, mode;
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002222 u32 imask;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002223
stephen hemminger44dde562010-02-12 06:58:01 +00002224 /* MTU size outside the spec */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002225 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
2226 return -EINVAL;
2227
stephen hemminger44dde562010-02-12 06:58:01 +00002228 /* MTU > 1500 on yukon FE and FE+ not allowed */
Stephen Hemminger05745c42007-09-19 15:36:45 -07002229 if (new_mtu > ETH_DATA_LEN &&
2230 (hw->chip_id == CHIP_ID_YUKON_FE ||
2231 hw->chip_id == CHIP_ID_YUKON_FE_P))
Stephen Hemmingerd2adf4f2007-04-11 14:48:02 -07002232 return -EINVAL;
2233
stephen hemminger44dde562010-02-12 06:58:01 +00002234 /* TSO, etc on Yukon Ultra and MTU > 1500 not supported */
2235 if (new_mtu > ETH_DATA_LEN && hw->chip_id == CHIP_ID_YUKON_EC_U)
2236 dev->features &= ~(NETIF_F_TSO|NETIF_F_SG|NETIF_F_ALL_CSUM);
2237
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002238 if (!netif_running(dev)) {
2239 dev->mtu = new_mtu;
2240 return 0;
2241 }
2242
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002243 imask = sky2_read32(hw, B0_IMSK);
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002244 sky2_write32(hw, B0_IMSK, 0);
2245
shemminger@osdl.org018d1c62005-11-30 11:45:18 -08002246 dev->trans_start = jiffies; /* prevent tx timeout */
2247 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002248 napi_disable(&hw->napi);
shemminger@osdl.org018d1c62005-11-30 11:45:18 -08002249
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002250 synchronize_irq(hw->pdev->irq);
2251
Stephen Hemminger39dbd952008-02-04 19:45:13 -08002252 if (!(hw->flags & SKY2_HW_RAM_BUFFER))
Stephen Hemminger69161612007-06-04 17:23:26 -07002253 sky2_set_tx_stfwd(hw, port);
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07002254
2255 ctl = gma_read16(hw, port, GM_GP_CTRL);
2256 gma_write16(hw, port, GM_GP_CTRL, ctl & ~GM_GPCR_RX_ENA);
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002257 sky2_rx_stop(sky2);
2258 sky2_rx_clean(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002259
2260 dev->mtu = new_mtu;
Stephen Hemminger14d02632006-09-26 11:57:43 -07002261
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002262 mode = DATA_BLIND_VAL(DATA_BLIND_DEF) |
2263 GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002264
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002265 if (dev->mtu > ETH_DATA_LEN)
2266 mode |= GM_SMOD_JUMBO_ENA;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002267
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07002268 gma_write16(hw, port, GM_SERIAL_MODE, mode);
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002269
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07002270 sky2_write8(hw, RB_ADDR(rxqaddr[port], RB_CTRL), RB_ENA_OP_MD);
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002271
Mike McCormack200ac492010-02-12 06:58:03 +00002272 err = sky2_alloc_rx_skbs(sky2);
2273 if (!err)
2274 sky2_rx_start(sky2);
2275 else
2276 sky2_rx_clean(sky2);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002277 sky2_write32(hw, B0_IMSK, imask);
shemminger@osdl.org018d1c62005-11-30 11:45:18 -08002278
David S. Millerd1d08d12008-01-07 20:53:33 -08002279 sky2_read32(hw, B0_Y2_SP_LISR);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002280 napi_enable(&hw->napi);
2281
Stephen Hemminger1b537562005-12-20 15:08:07 -08002282 if (err)
2283 dev_close(dev);
2284 else {
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07002285 gma_write16(hw, port, GM_GP_CTRL, ctl);
Stephen Hemminger1b537562005-12-20 15:08:07 -08002286
Stephen Hemminger1b537562005-12-20 15:08:07 -08002287 netif_wake_queue(dev);
2288 }
2289
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002290 return err;
2291}
2292
Stephen Hemminger14d02632006-09-26 11:57:43 -07002293/* For small just reuse existing skb for next receive */
2294static struct sk_buff *receive_copy(struct sky2_port *sky2,
2295 const struct rx_ring_info *re,
2296 unsigned length)
2297{
2298 struct sk_buff *skb;
2299
Eric Dumazet89d71a62009-10-13 05:34:20 +00002300 skb = netdev_alloc_skb_ip_align(sky2->netdev, length);
Stephen Hemminger14d02632006-09-26 11:57:43 -07002301 if (likely(skb)) {
Stephen Hemminger14d02632006-09-26 11:57:43 -07002302 pci_dma_sync_single_for_cpu(sky2->hw->pdev, re->data_addr,
2303 length, PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002304 skb_copy_from_linear_data(re->skb, skb->data, length);
Stephen Hemminger14d02632006-09-26 11:57:43 -07002305 skb->ip_summed = re->skb->ip_summed;
2306 skb->csum = re->skb->csum;
2307 pci_dma_sync_single_for_device(sky2->hw->pdev, re->data_addr,
2308 length, PCI_DMA_FROMDEVICE);
2309 re->skb->ip_summed = CHECKSUM_NONE;
Stephen Hemminger489b10c2006-10-03 16:39:12 -07002310 skb_put(skb, length);
Stephen Hemminger14d02632006-09-26 11:57:43 -07002311 }
2312 return skb;
2313}
2314
2315/* Adjust length of skb with fragments to match received data */
2316static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space,
2317 unsigned int length)
2318{
2319 int i, num_frags;
2320 unsigned int size;
2321
2322 /* put header into skb */
2323 size = min(length, hdr_space);
2324 skb->tail += size;
2325 skb->len += size;
2326 length -= size;
2327
2328 num_frags = skb_shinfo(skb)->nr_frags;
2329 for (i = 0; i < num_frags; i++) {
2330 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2331
2332 if (length == 0) {
2333 /* don't need this page */
2334 __free_page(frag->page);
2335 --skb_shinfo(skb)->nr_frags;
2336 } else {
2337 size = min(length, (unsigned) PAGE_SIZE);
2338
2339 frag->size = size;
2340 skb->data_len += size;
2341 skb->truesize += size;
2342 skb->len += size;
2343 length -= size;
2344 }
2345 }
2346}
2347
2348/* Normal packet - take skb from ring element and put in a new one */
2349static struct sk_buff *receive_new(struct sky2_port *sky2,
2350 struct rx_ring_info *re,
2351 unsigned int length)
2352{
stephen hemminger3fbd9182010-02-01 13:45:41 +00002353 struct sk_buff *skb;
2354 struct rx_ring_info nre;
Stephen Hemminger14d02632006-09-26 11:57:43 -07002355 unsigned hdr_space = sky2->rx_data_size;
2356
stephen hemminger3fbd9182010-02-01 13:45:41 +00002357 nre.skb = sky2_rx_alloc(sky2);
2358 if (unlikely(!nre.skb))
2359 goto nobuf;
2360
2361 if (sky2_rx_map_skb(sky2->hw->pdev, &nre, hdr_space))
2362 goto nomap;
Stephen Hemminger14d02632006-09-26 11:57:43 -07002363
2364 skb = re->skb;
2365 sky2_rx_unmap_skb(sky2->hw->pdev, re);
Stephen Hemminger14d02632006-09-26 11:57:43 -07002366 prefetch(skb->data);
stephen hemminger3fbd9182010-02-01 13:45:41 +00002367 *re = nre;
Stephen Hemminger14d02632006-09-26 11:57:43 -07002368
2369 if (skb_shinfo(skb)->nr_frags)
2370 skb_put_frags(skb, hdr_space, length);
2371 else
Stephen Hemminger489b10c2006-10-03 16:39:12 -07002372 skb_put(skb, length);
Stephen Hemminger14d02632006-09-26 11:57:43 -07002373 return skb;
stephen hemminger3fbd9182010-02-01 13:45:41 +00002374
2375nomap:
2376 dev_kfree_skb(nre.skb);
2377nobuf:
2378 return NULL;
Stephen Hemminger14d02632006-09-26 11:57:43 -07002379}
2380
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002381/*
2382 * Receive one packet.
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07002383 * For larger packets, get new buffer.
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002384 */
shemminger@osdl.org497d7c82006-08-28 10:00:46 -07002385static struct sk_buff *sky2_receive(struct net_device *dev,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002386 u16 length, u32 status)
2387{
shemminger@osdl.org497d7c82006-08-28 10:00:46 -07002388 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger291ea612006-09-26 11:57:41 -07002389 struct rx_ring_info *re = sky2->rx_ring + sky2->rx_next;
Stephen Hemminger79e57d32005-09-19 15:42:33 -07002390 struct sk_buff *skb = NULL;
Stephen Hemmingerd6532232007-09-19 15:36:42 -07002391 u16 count = (status & GMR_FS_LEN) >> 16;
2392
2393#ifdef SKY2_VLAN_TAG_USED
2394 /* Account for vlan tag */
2395 if (sky2->vlgrp && (status & GMR_FS_VLAN))
2396 count -= VLAN_HLEN;
2397#endif
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002398
2399 if (unlikely(netif_msg_rx_status(sky2)))
2400 printk(KERN_DEBUG PFX "%s: rx slot %u status 0x%x len %d\n",
shemminger@osdl.org497d7c82006-08-28 10:00:46 -07002401 dev->name, sky2->rx_next, status, length);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002402
Stephen Hemminger793b8832005-09-14 16:06:14 -07002403 sky2->rx_next = (sky2->rx_next + 1) % sky2->rx_pending;
Stephen Hemmingerd70cd512005-12-09 11:35:09 -08002404 prefetch(sky2->rx_ring + sky2->rx_next);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002405
Stephen Hemminger3b12e012007-09-26 17:58:47 -07002406 /* This chip has hardware problems that generates bogus status.
2407 * So do only marginal checking and expect higher level protocols
2408 * to handle crap frames.
2409 */
2410 if (sky2->hw->chip_id == CHIP_ID_YUKON_FE_P &&
2411 sky2->hw->chip_rev == CHIP_REV_YU_FE2_A0 &&
2412 length != count)
2413 goto okay;
2414
shemminger@osdl.org42eeea02005-11-30 11:45:13 -08002415 if (status & GMR_FS_ANY_ERR)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002416 goto error;
2417
shemminger@osdl.org42eeea02005-11-30 11:45:13 -08002418 if (!(status & GMR_FS_RX_OK))
2419 goto resubmit;
2420
Stephen Hemmingerd6532232007-09-19 15:36:42 -07002421 /* if length reported by DMA does not match PHY, packet was truncated */
2422 if (length != count)
Stephen Hemminger3b12e012007-09-26 17:58:47 -07002423 goto len_error;
Stephen Hemminger71749532007-07-09 15:33:40 -07002424
Stephen Hemminger3b12e012007-09-26 17:58:47 -07002425okay:
Stephen Hemminger14d02632006-09-26 11:57:43 -07002426 if (length < copybreak)
2427 skb = receive_copy(sky2, re, length);
2428 else
2429 skb = receive_new(sky2, re, length);
Stephen Hemminger90c30332010-02-03 08:31:12 +00002430
2431 dev->stats.rx_dropped += (skb == NULL);
2432
Stephen Hemminger793b8832005-09-14 16:06:14 -07002433resubmit:
Stephen Hemminger14d02632006-09-26 11:57:43 -07002434 sky2_rx_submit(sky2, re);
Stephen Hemminger79e57d32005-09-19 15:42:33 -07002435
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002436 return skb;
2437
Stephen Hemminger3b12e012007-09-26 17:58:47 -07002438len_error:
Stephen Hemminger71749532007-07-09 15:33:40 -07002439 /* Truncation of overlength packets
2440 causes PHY length to not match MAC length */
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002441 ++dev->stats.rx_length_errors;
Stephen Hemmingerd6532232007-09-19 15:36:42 -07002442 if (netif_msg_rx_err(sky2) && net_ratelimit())
Stephen Hemminger3b12e012007-09-26 17:58:47 -07002443 pr_info(PFX "%s: rx length error: status %#x length %d\n",
2444 dev->name, status, length);
Stephen Hemmingerd6532232007-09-19 15:36:42 -07002445 goto resubmit;
Stephen Hemminger71749532007-07-09 15:33:40 -07002446
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002447error:
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002448 ++dev->stats.rx_errors;
Stephen Hemmingerb6d77732006-10-17 10:24:16 -07002449 if (status & GMR_FS_RX_FF_OV) {
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002450 dev->stats.rx_over_errors++;
Stephen Hemmingerb6d77732006-10-17 10:24:16 -07002451 goto resubmit;
2452 }
Stephen Hemminger6e15b712005-12-20 15:08:09 -08002453
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002454 if (netif_msg_rx_err(sky2) && net_ratelimit())
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002455 printk(KERN_INFO PFX "%s: rx error, status 0x%x length %d\n",
shemminger@osdl.org497d7c82006-08-28 10:00:46 -07002456 dev->name, status, length);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002457
2458 if (status & (GMR_FS_LONG_ERR | GMR_FS_UN_SIZE))
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002459 dev->stats.rx_length_errors++;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002460 if (status & GMR_FS_FRAGMENT)
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002461 dev->stats.rx_frame_errors++;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002462 if (status & GMR_FS_CRC_ERR)
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002463 dev->stats.rx_crc_errors++;
Stephen Hemminger79e57d32005-09-19 15:42:33 -07002464
Stephen Hemminger793b8832005-09-14 16:06:14 -07002465 goto resubmit;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002466}
2467
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002468/* Transmit complete */
2469static inline void sky2_tx_done(struct net_device *dev, u16 last)
Stephen Hemminger13b97b72005-12-09 11:35:03 -08002470{
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002471 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger302d1252006-01-17 13:43:20 -08002472
Mike McCormack8a0c9222010-02-12 06:58:06 +00002473 if (netif_running(dev)) {
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002474 sky2_tx_complete(sky2, last);
Mike McCormack8a0c9222010-02-12 06:58:06 +00002475
2476 /* Wake unless it's detached, and called e.g. from sky2_down() */
2477 if (tx_avail(sky2) > MAX_SKB_TX_LE + 4)
2478 netif_wake_queue(dev);
2479 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002480}
2481
Stephen Hemminger37e5a242009-06-17 07:30:39 +00002482static inline void sky2_skb_rx(const struct sky2_port *sky2,
2483 u32 status, struct sk_buff *skb)
2484{
2485#ifdef SKY2_VLAN_TAG_USED
2486 u16 vlan_tag = be16_to_cpu(sky2->rx_tag);
2487 if (sky2->vlgrp && (status & GMR_FS_VLAN)) {
2488 if (skb->ip_summed == CHECKSUM_NONE)
2489 vlan_hwaccel_receive_skb(skb, sky2->vlgrp, vlan_tag);
2490 else
2491 vlan_gro_receive(&sky2->hw->napi, sky2->vlgrp,
2492 vlan_tag, skb);
2493 return;
2494 }
2495#endif
2496 if (skb->ip_summed == CHECKSUM_NONE)
2497 netif_receive_skb(skb);
2498 else
2499 napi_gro_receive(&sky2->hw->napi, skb);
2500}
2501
Stephen Hemmingerbf15fe92009-06-17 07:30:36 +00002502static inline void sky2_rx_done(struct sky2_hw *hw, unsigned port,
2503 unsigned packets, unsigned bytes)
2504{
2505 if (packets) {
2506 struct net_device *dev = hw->dev[port];
2507
2508 dev->stats.rx_packets += packets;
2509 dev->stats.rx_bytes += bytes;
2510 dev->last_rx = jiffies;
2511 sky2_rx_update(netdev_priv(dev), rxqaddr[port]);
2512 }
2513}
2514
stephen hemminger375c5682010-02-07 06:28:36 +00002515static void sky2_rx_checksum(struct sky2_port *sky2, u32 status)
2516{
2517 /* If this happens then driver assuming wrong format for chip type */
2518 BUG_ON(sky2->hw->flags & SKY2_HW_NEW_LE);
2519
2520 /* Both checksum counters are programmed to start at
2521 * the same offset, so unless there is a problem they
2522 * should match. This failure is an early indication that
2523 * hardware receive checksumming won't work.
2524 */
2525 if (likely((u16)(status >> 16) == (u16)status)) {
2526 struct sk_buff *skb = sky2->rx_ring[sky2->rx_next].skb;
2527 skb->ip_summed = CHECKSUM_COMPLETE;
2528 skb->csum = le16_to_cpu(status);
2529 } else {
2530 dev_notice(&sky2->hw->pdev->dev,
2531 "%s: receive checksum problem (status = %#x)\n",
2532 sky2->netdev->name, status);
2533
2534 /* Disable checksum offload */
2535 sky2->flags &= ~SKY2_FLAG_RX_CHECKSUM;
2536 sky2_write32(sky2->hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR),
2537 BMU_DIS_RX_CHKSUM);
2538 }
2539}
2540
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002541/* Process status response ring */
Stephen Hemminger26691832007-10-11 18:31:13 -07002542static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002543{
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002544 int work_done = 0;
Stephen Hemmingerbf15fe92009-06-17 07:30:36 +00002545 unsigned int total_bytes[2] = { 0 };
2546 unsigned int total_packets[2] = { 0 };
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002547
Stephen Hemmingeraf2a58a2005-12-09 11:35:04 -08002548 rmb();
Stephen Hemminger26691832007-10-11 18:31:13 -07002549 do {
Stephen Hemminger55c9dd32007-07-09 15:33:37 -07002550 struct sky2_port *sky2;
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002551 struct sky2_status_le *le = hw->st_le + hw->st_idx;
Stephen Hemmingerab5adec2007-11-05 15:52:09 -08002552 unsigned port;
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002553 struct net_device *dev;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002554 struct sk_buff *skb;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002555 u32 status;
2556 u16 length;
Stephen Hemmingerab5adec2007-11-05 15:52:09 -08002557 u8 opcode = le->opcode;
2558
2559 if (!(opcode & HW_OWNER))
2560 break;
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002561
Stephen Hemmingercb5d9542006-05-08 15:11:29 -07002562 hw->st_idx = RING_NEXT(hw->st_idx, STATUS_RING_SIZE);
shemminger@osdl.orgbea86102005-10-26 12:16:10 -07002563
Stephen Hemmingerab5adec2007-11-05 15:52:09 -08002564 port = le->css & CSS_LINK_BIT;
Stephen Hemminger69161612007-06-04 17:23:26 -07002565 dev = hw->dev[port];
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002566 sky2 = netdev_priv(dev);
Stephen Hemmingerf65b1382006-09-06 12:45:02 -07002567 length = le16_to_cpu(le->length);
2568 status = le32_to_cpu(le->status);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002569
Stephen Hemmingerab5adec2007-11-05 15:52:09 -08002570 le->opcode = 0;
2571 switch (opcode & ~HW_OWNER) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002572 case OP_RXSTAT:
Stephen Hemmingerbf15fe92009-06-17 07:30:36 +00002573 total_packets[port]++;
2574 total_bytes[port] += length;
Stephen Hemminger90c30332010-02-03 08:31:12 +00002575
shemminger@osdl.org497d7c82006-08-28 10:00:46 -07002576 skb = sky2_receive(dev, length, status);
Stephen Hemminger90c30332010-02-03 08:31:12 +00002577 if (!skb)
Stephen Hemminger55c9dd32007-07-09 15:33:37 -07002578 break;
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002579
Stephen Hemminger69161612007-06-04 17:23:26 -07002580 /* This chip reports checksum status differently */
Stephen Hemminger05745c42007-09-19 15:36:45 -07002581 if (hw->flags & SKY2_HW_NEW_LE) {
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07002582 if ((sky2->flags & SKY2_FLAG_RX_CHECKSUM) &&
Stephen Hemminger69161612007-06-04 17:23:26 -07002583 (le->css & (CSS_ISIPV4 | CSS_ISIPV6)) &&
2584 (le->css & CSS_TCPUDPCSOK))
2585 skb->ip_summed = CHECKSUM_UNNECESSARY;
2586 else
2587 skb->ip_summed = CHECKSUM_NONE;
2588 }
2589
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002590 skb->protocol = eth_type_trans(skb, dev);
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002591
Stephen Hemminger37e5a242009-06-17 07:30:39 +00002592 sky2_skb_rx(sky2, status, skb);
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002593
Stephen Hemminger22e11702006-07-12 15:23:48 -07002594 /* Stop after net poll weight */
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002595 if (++work_done >= to_do)
2596 goto exit_loop;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002597 break;
2598
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07002599#ifdef SKY2_VLAN_TAG_USED
2600 case OP_RXVLAN:
2601 sky2->rx_tag = length;
2602 break;
2603
2604 case OP_RXCHKSVLAN:
2605 sky2->rx_tag = length;
2606 /* fall through */
2607#endif
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002608 case OP_RXCHKS:
stephen hemminger375c5682010-02-07 06:28:36 +00002609 if (likely(sky2->flags & SKY2_FLAG_RX_CHECKSUM))
2610 sky2_rx_checksum(sky2, status);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002611 break;
2612
2613 case OP_TXINDEXLE:
Stephen Hemminger13b97b72005-12-09 11:35:03 -08002614 /* TX index reports status for both ports */
Stephen Hemmingerf55925d2006-05-08 15:11:28 -07002615 sky2_tx_done(hw->dev[0], status & 0xfff);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002616 if (hw->dev[1])
2617 sky2_tx_done(hw->dev[1],
2618 ((status >> 24) & 0xff)
2619 | (u16)(length & 0xf) << 8);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002620 break;
2621
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002622 default:
2623 if (net_ratelimit())
Stephen Hemminger793b8832005-09-14 16:06:14 -07002624 printk(KERN_WARNING PFX
Stephen Hemmingerab5adec2007-11-05 15:52:09 -08002625 "unknown status opcode 0x%x\n", opcode);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002626 }
Stephen Hemminger26691832007-10-11 18:31:13 -07002627 } while (hw->st_idx != idx);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002628
Stephen Hemmingerfe2a24d2006-08-01 11:55:23 -07002629 /* Fully processed status ring so clear irq */
2630 sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ);
2631
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002632exit_loop:
Stephen Hemmingerbf15fe92009-06-17 07:30:36 +00002633 sky2_rx_done(hw, 0, total_packets[0], total_bytes[0]);
2634 sky2_rx_done(hw, 1, total_packets[1], total_bytes[1]);
Stephen Hemminger22e11702006-07-12 15:23:48 -07002635
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002636 return work_done;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002637}
2638
2639static void sky2_hw_error(struct sky2_hw *hw, unsigned port, u32 status)
2640{
2641 struct net_device *dev = hw->dev[port];
2642
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002643 if (net_ratelimit())
2644 printk(KERN_INFO PFX "%s: hw error interrupt status 0x%x\n",
2645 dev->name, status);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002646
2647 if (status & Y2_IS_PAR_RD1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002648 if (net_ratelimit())
2649 printk(KERN_ERR PFX "%s: ram data read parity error\n",
2650 dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002651 /* Clear IRQ */
2652 sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_RD_PERR);
2653 }
2654
2655 if (status & Y2_IS_PAR_WR1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002656 if (net_ratelimit())
2657 printk(KERN_ERR PFX "%s: ram data write parity error\n",
2658 dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002659
2660 sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_WR_PERR);
2661 }
2662
2663 if (status & Y2_IS_PAR_MAC1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002664 if (net_ratelimit())
2665 printk(KERN_ERR PFX "%s: MAC parity error\n", dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002666 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_PE);
2667 }
2668
2669 if (status & Y2_IS_PAR_RX1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002670 if (net_ratelimit())
2671 printk(KERN_ERR PFX "%s: RX parity error\n", dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002672 sky2_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), BMU_CLR_IRQ_PAR);
2673 }
2674
2675 if (status & Y2_IS_TCP_TXA1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002676 if (net_ratelimit())
2677 printk(KERN_ERR PFX "%s: TCP segmentation error\n",
2678 dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002679 sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_CLR_IRQ_TCP);
2680 }
2681}
2682
2683static void sky2_hw_intr(struct sky2_hw *hw)
2684{
Stephen Hemminger555382c2007-08-29 12:58:14 -07002685 struct pci_dev *pdev = hw->pdev;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002686 u32 status = sky2_read32(hw, B0_HWE_ISRC);
Stephen Hemminger555382c2007-08-29 12:58:14 -07002687 u32 hwmsk = sky2_read32(hw, B0_HWE_IMSK);
2688
2689 status &= hwmsk;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002690
Stephen Hemminger793b8832005-09-14 16:06:14 -07002691 if (status & Y2_IS_TIST_OV)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002692 sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002693
2694 if (status & (Y2_IS_MST_ERR | Y2_IS_IRQ_STAT)) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07002695 u16 pci_err;
2696
stephen hemmingera40ccc62010-01-24 18:46:06 +00002697 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08002698 pci_err = sky2_pci_read16(hw, PCI_STATUS);
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002699 if (net_ratelimit())
Stephen Hemminger555382c2007-08-29 12:58:14 -07002700 dev_err(&pdev->dev, "PCI hardware error (0x%x)\n",
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08002701 pci_err);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002702
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08002703 sky2_pci_write16(hw, PCI_STATUS,
Stephen Hemminger167f53d2007-09-25 19:01:02 -07002704 pci_err | PCI_STATUS_ERROR_BITS);
stephen hemmingera40ccc62010-01-24 18:46:06 +00002705 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002706 }
2707
2708 if (status & Y2_IS_PCI_EXP) {
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07002709 /* PCI-Express uncorrectable Error occurred */
Stephen Hemminger555382c2007-08-29 12:58:14 -07002710 u32 err;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002711
stephen hemmingera40ccc62010-01-24 18:46:06 +00002712 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
Stephen Hemminger7782c8c2007-11-27 11:02:32 -08002713 err = sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
2714 sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
2715 0xfffffffful);
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002716 if (net_ratelimit())
Stephen Hemminger555382c2007-08-29 12:58:14 -07002717 dev_err(&pdev->dev, "PCI Express error (0x%x)\n", err);
Stephen Hemmingercf06ffb2007-11-05 15:52:13 -08002718
Stephen Hemminger7782c8c2007-11-27 11:02:32 -08002719 sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
stephen hemmingera40ccc62010-01-24 18:46:06 +00002720 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002721 }
2722
2723 if (status & Y2_HWE_L1_MASK)
2724 sky2_hw_error(hw, 0, status);
2725 status >>= 8;
2726 if (status & Y2_HWE_L1_MASK)
2727 sky2_hw_error(hw, 1, status);
2728}
2729
2730static void sky2_mac_intr(struct sky2_hw *hw, unsigned port)
2731{
2732 struct net_device *dev = hw->dev[port];
2733 struct sky2_port *sky2 = netdev_priv(dev);
2734 u8 status = sky2_read8(hw, SK_REG(port, GMAC_IRQ_SRC));
2735
2736 if (netif_msg_intr(sky2))
2737 printk(KERN_INFO PFX "%s: mac interrupt status 0x%x\n",
2738 dev->name, status);
2739
Stephen Hemmingera3caead2007-05-14 12:38:13 -07002740 if (status & GM_IS_RX_CO_OV)
2741 gma_read16(hw, port, GM_RX_IRQ_SRC);
2742
2743 if (status & GM_IS_TX_CO_OV)
2744 gma_read16(hw, port, GM_TX_IRQ_SRC);
2745
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002746 if (status & GM_IS_RX_FF_OR) {
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002747 ++dev->stats.rx_fifo_errors;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002748 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO);
2749 }
2750
2751 if (status & GM_IS_TX_FF_UR) {
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002752 ++dev->stats.tx_fifo_errors;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002753 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU);
2754 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002755}
2756
Stephen Hemminger40b01722007-04-11 14:47:59 -07002757/* This should never happen it is a bug. */
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002758static void sky2_le_error(struct sky2_hw *hw, unsigned port, u16 q)
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002759{
2760 struct net_device *dev = hw->dev[port];
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002761 u16 idx = sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_GET_IDX));
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002762
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002763 dev_err(&hw->pdev->dev, PFX
2764 "%s: descriptor error q=%#x get=%u put=%u\n",
2765 dev->name, (unsigned) q, (unsigned) idx,
2766 (unsigned) sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX)));
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002767
Stephen Hemminger40b01722007-04-11 14:47:59 -07002768 sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_IRQ_CHK);
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002769}
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002770
Stephen Hemminger75e80682007-09-19 15:36:46 -07002771static int sky2_rx_hung(struct net_device *dev)
2772{
2773 struct sky2_port *sky2 = netdev_priv(dev);
2774 struct sky2_hw *hw = sky2->hw;
2775 unsigned port = sky2->port;
2776 unsigned rxq = rxqaddr[port];
2777 u32 mac_rp = sky2_read32(hw, SK_REG(port, RX_GMF_RP));
2778 u8 mac_lev = sky2_read8(hw, SK_REG(port, RX_GMF_RLEV));
2779 u8 fifo_rp = sky2_read8(hw, Q_ADDR(rxq, Q_RP));
2780 u8 fifo_lev = sky2_read8(hw, Q_ADDR(rxq, Q_RL));
2781
2782 /* If idle and MAC or PCI is stuck */
2783 if (sky2->check.last == dev->last_rx &&
2784 ((mac_rp == sky2->check.mac_rp &&
2785 mac_lev != 0 && mac_lev >= sky2->check.mac_lev) ||
2786 /* Check if the PCI RX hang */
2787 (fifo_rp == sky2->check.fifo_rp &&
2788 fifo_lev != 0 && fifo_lev >= sky2->check.fifo_lev))) {
2789 printk(KERN_DEBUG PFX "%s: hung mac %d:%d fifo %d (%d:%d)\n",
2790 dev->name, mac_lev, mac_rp, fifo_lev, fifo_rp,
2791 sky2_read8(hw, Q_ADDR(rxq, Q_WP)));
2792 return 1;
2793 } else {
2794 sky2->check.last = dev->last_rx;
2795 sky2->check.mac_rp = mac_rp;
2796 sky2->check.mac_lev = mac_lev;
2797 sky2->check.fifo_rp = fifo_rp;
2798 sky2->check.fifo_lev = fifo_lev;
2799 return 0;
2800 }
2801}
2802
Stephen Hemminger32c2c302007-08-21 14:34:03 -07002803static void sky2_watchdog(unsigned long arg)
Stephen Hemmingerd27ed382006-04-25 10:58:51 -07002804{
Stephen Hemminger01bd7562006-05-08 15:11:30 -07002805 struct sky2_hw *hw = (struct sky2_hw *) arg;
Stephen Hemmingerd27ed382006-04-25 10:58:51 -07002806
Stephen Hemminger75e80682007-09-19 15:36:46 -07002807 /* Check for lost IRQ once a second */
Stephen Hemminger32c2c302007-08-21 14:34:03 -07002808 if (sky2_read32(hw, B0_ISRC)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002809 napi_schedule(&hw->napi);
Stephen Hemminger75e80682007-09-19 15:36:46 -07002810 } else {
2811 int i, active = 0;
2812
2813 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002814 struct net_device *dev = hw->dev[i];
Stephen Hemminger75e80682007-09-19 15:36:46 -07002815 if (!netif_running(dev))
2816 continue;
2817 ++active;
2818
2819 /* For chips with Rx FIFO, check if stuck */
Stephen Hemminger39dbd952008-02-04 19:45:13 -08002820 if ((hw->flags & SKY2_HW_RAM_BUFFER) &&
Stephen Hemminger75e80682007-09-19 15:36:46 -07002821 sky2_rx_hung(dev)) {
2822 pr_info(PFX "%s: receiver hang detected\n",
2823 dev->name);
2824 schedule_work(&hw->restart_work);
2825 return;
2826 }
2827 }
2828
2829 if (active == 0)
2830 return;
Stephen Hemminger32c2c302007-08-21 14:34:03 -07002831 }
2832
Stephen Hemminger75e80682007-09-19 15:36:46 -07002833 mod_timer(&hw->watchdog_timer, round_jiffies(jiffies + HZ));
Stephen Hemmingerd27ed382006-04-25 10:58:51 -07002834}
2835
Stephen Hemminger40b01722007-04-11 14:47:59 -07002836/* Hardware/software error handling */
2837static void sky2_err_intr(struct sky2_hw *hw, u32 status)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002838{
Stephen Hemminger40b01722007-04-11 14:47:59 -07002839 if (net_ratelimit())
2840 dev_warn(&hw->pdev->dev, "error interrupt status=%#x\n", status);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002841
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002842 if (status & Y2_IS_HW_ERR)
2843 sky2_hw_intr(hw);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002844
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002845 if (status & Y2_IS_IRQ_MAC1)
2846 sky2_mac_intr(hw, 0);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002847
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002848 if (status & Y2_IS_IRQ_MAC2)
2849 sky2_mac_intr(hw, 1);
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002850
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002851 if (status & Y2_IS_CHK_RX1)
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002852 sky2_le_error(hw, 0, Q_R1);
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002853
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002854 if (status & Y2_IS_CHK_RX2)
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002855 sky2_le_error(hw, 1, Q_R2);
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002856
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002857 if (status & Y2_IS_CHK_TXA1)
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002858 sky2_le_error(hw, 0, Q_XA1);
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002859
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002860 if (status & Y2_IS_CHK_TXA2)
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002861 sky2_le_error(hw, 1, Q_XA2);
Stephen Hemminger40b01722007-04-11 14:47:59 -07002862}
2863
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002864static int sky2_poll(struct napi_struct *napi, int work_limit)
Stephen Hemminger40b01722007-04-11 14:47:59 -07002865{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002866 struct sky2_hw *hw = container_of(napi, struct sky2_hw, napi);
Stephen Hemminger40b01722007-04-11 14:47:59 -07002867 u32 status = sky2_read32(hw, B0_Y2_SP_EISR);
David S. Miller6f535762007-10-11 18:08:29 -07002868 int work_done = 0;
Stephen Hemminger26691832007-10-11 18:31:13 -07002869 u16 idx;
Stephen Hemminger40b01722007-04-11 14:47:59 -07002870
2871 if (unlikely(status & Y2_IS_ERROR))
2872 sky2_err_intr(hw, status);
2873
2874 if (status & Y2_IS_IRQ_PHY1)
2875 sky2_phy_intr(hw, 0);
2876
2877 if (status & Y2_IS_IRQ_PHY2)
2878 sky2_phy_intr(hw, 1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002879
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00002880 if (status & Y2_IS_PHY_QLNK)
2881 sky2_qlink_intr(hw);
2882
Stephen Hemminger26691832007-10-11 18:31:13 -07002883 while ((idx = sky2_read16(hw, STAT_PUT_IDX)) != hw->st_idx) {
2884 work_done += sky2_status_intr(hw, work_limit - work_done, idx);
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002885
David S. Miller6f535762007-10-11 18:08:29 -07002886 if (work_done >= work_limit)
Stephen Hemminger26691832007-10-11 18:31:13 -07002887 goto done;
Stephen Hemmingerfe2a24d2006-08-01 11:55:23 -07002888 }
David S. Miller6f535762007-10-11 18:08:29 -07002889
Stephen Hemminger26691832007-10-11 18:31:13 -07002890 napi_complete(napi);
2891 sky2_read32(hw, B0_Y2_SP_LISR);
2892done:
2893
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002894 return work_done;
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002895}
2896
David Howells7d12e782006-10-05 14:55:46 +01002897static irqreturn_t sky2_intr(int irq, void *dev_id)
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002898{
2899 struct sky2_hw *hw = dev_id;
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002900 u32 status;
2901
2902 /* Reading this mask interrupts as side effect */
2903 status = sky2_read32(hw, B0_Y2_SP_ISRC2);
2904 if (status == 0 || status == ~0)
2905 return IRQ_NONE;
2906
2907 prefetch(&hw->st_le[hw->st_idx]);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002908
2909 napi_schedule(&hw->napi);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002910
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002911 return IRQ_HANDLED;
2912}
2913
2914#ifdef CONFIG_NET_POLL_CONTROLLER
2915static void sky2_netpoll(struct net_device *dev)
2916{
2917 struct sky2_port *sky2 = netdev_priv(dev);
2918
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002919 napi_schedule(&sky2->hw->napi);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002920}
2921#endif
2922
2923/* Chip internal frequency for clock calculations */
Stephen Hemminger05745c42007-09-19 15:36:45 -07002924static u32 sky2_mhz(const struct sky2_hw *hw)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002925{
Stephen Hemminger793b8832005-09-14 16:06:14 -07002926 switch (hw->chip_id) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002927 case CHIP_ID_YUKON_EC:
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -08002928 case CHIP_ID_YUKON_EC_U:
Stephen Hemminger93745492007-02-06 10:45:43 -08002929 case CHIP_ID_YUKON_EX:
Stephen Hemmingered4d4162008-01-10 16:14:14 -08002930 case CHIP_ID_YUKON_SUPR:
Stephen Hemminger0ce8b982008-06-17 09:04:27 -07002931 case CHIP_ID_YUKON_UL_2:
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00002932 case CHIP_ID_YUKON_OPT:
Stephen Hemminger05745c42007-09-19 15:36:45 -07002933 return 125;
2934
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002935 case CHIP_ID_YUKON_FE:
Stephen Hemminger05745c42007-09-19 15:36:45 -07002936 return 100;
2937
2938 case CHIP_ID_YUKON_FE_P:
2939 return 50;
2940
2941 case CHIP_ID_YUKON_XL:
2942 return 156;
2943
2944 default:
2945 BUG();
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002946 }
2947}
2948
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002949static inline u32 sky2_us2clk(const struct sky2_hw *hw, u32 us)
2950{
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08002951 return sky2_mhz(hw) * us;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002952}
2953
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08002954static inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk)
2955{
2956 return clk / sky2_mhz(hw);
2957}
2958
2959
Stephen Hemmingere3173832007-02-06 10:45:39 -08002960static int __devinit sky2_init(struct sky2_hw *hw)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002961{
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07002962 u8 t8;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002963
Stephen Hemminger167f53d2007-09-25 19:01:02 -07002964 /* Enable all clocks and check for bad PCI access */
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08002965 sky2_pci_write32(hw, PCI_DEV_REG3, 0);
Stephen Hemminger451af332007-06-04 17:23:24 -07002966
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002967 sky2_write8(hw, B0_CTST, CS_RST_CLR);
Stephen Hemminger08c06d82006-01-30 11:37:54 -08002968
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002969 hw->chip_id = sky2_read8(hw, B2_CHIP_ID);
Stephen Hemmingerea76e632007-09-19 15:36:44 -07002970 hw->chip_rev = (sky2_read8(hw, B2_MAC_CFG) & CFG_CHIP_R_MSK) >> 4;
2971
2972 switch(hw->chip_id) {
2973 case CHIP_ID_YUKON_XL:
Stephen Hemminger39dbd952008-02-04 19:45:13 -08002974 hw->flags = SKY2_HW_GIGABIT | SKY2_HW_NEWER_PHY;
Stephen Hemmingerea76e632007-09-19 15:36:44 -07002975 break;
2976
2977 case CHIP_ID_YUKON_EC_U:
2978 hw->flags = SKY2_HW_GIGABIT
2979 | SKY2_HW_NEWER_PHY
2980 | SKY2_HW_ADV_POWER_CTL;
2981 break;
2982
2983 case CHIP_ID_YUKON_EX:
2984 hw->flags = SKY2_HW_GIGABIT
2985 | SKY2_HW_NEWER_PHY
2986 | SKY2_HW_NEW_LE
2987 | SKY2_HW_ADV_POWER_CTL;
2988
2989 /* New transmit checksum */
2990 if (hw->chip_rev != CHIP_REV_YU_EX_B0)
2991 hw->flags |= SKY2_HW_AUTO_TX_SUM;
2992 break;
2993
2994 case CHIP_ID_YUKON_EC:
2995 /* This rev is really old, and requires untested workarounds */
2996 if (hw->chip_rev == CHIP_REV_YU_EC_A1) {
2997 dev_err(&hw->pdev->dev, "unsupported revision Yukon-EC rev A1\n");
2998 return -EOPNOTSUPP;
2999 }
Stephen Hemminger39dbd952008-02-04 19:45:13 -08003000 hw->flags = SKY2_HW_GIGABIT;
Stephen Hemmingerea76e632007-09-19 15:36:44 -07003001 break;
3002
3003 case CHIP_ID_YUKON_FE:
Stephen Hemmingerea76e632007-09-19 15:36:44 -07003004 break;
3005
Stephen Hemminger05745c42007-09-19 15:36:45 -07003006 case CHIP_ID_YUKON_FE_P:
3007 hw->flags = SKY2_HW_NEWER_PHY
3008 | SKY2_HW_NEW_LE
3009 | SKY2_HW_AUTO_TX_SUM
3010 | SKY2_HW_ADV_POWER_CTL;
3011 break;
Stephen Hemmingered4d4162008-01-10 16:14:14 -08003012
3013 case CHIP_ID_YUKON_SUPR:
3014 hw->flags = SKY2_HW_GIGABIT
3015 | SKY2_HW_NEWER_PHY
3016 | SKY2_HW_NEW_LE
3017 | SKY2_HW_AUTO_TX_SUM
3018 | SKY2_HW_ADV_POWER_CTL;
3019 break;
3020
Stephen Hemminger0ce8b982008-06-17 09:04:27 -07003021 case CHIP_ID_YUKON_UL_2:
Takashi Iwaib3386822009-12-03 05:12:01 +00003022 hw->flags = SKY2_HW_GIGABIT
3023 | SKY2_HW_ADV_POWER_CTL;
3024 break;
3025
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00003026 case CHIP_ID_YUKON_OPT:
Stephen Hemminger0ce8b982008-06-17 09:04:27 -07003027 hw->flags = SKY2_HW_GIGABIT
Takashi Iwaib3386822009-12-03 05:12:01 +00003028 | SKY2_HW_NEW_LE
Stephen Hemminger0ce8b982008-06-17 09:04:27 -07003029 | SKY2_HW_ADV_POWER_CTL;
3030 break;
3031
Stephen Hemmingerea76e632007-09-19 15:36:44 -07003032 default:
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08003033 dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n",
3034 hw->chip_id);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003035 return -EOPNOTSUPP;
3036 }
3037
Stephen Hemmingere3173832007-02-06 10:45:39 -08003038 hw->pmd_type = sky2_read8(hw, B2_PMD_TYP);
Stephen Hemmingerea76e632007-09-19 15:36:44 -07003039 if (hw->pmd_type == 'L' || hw->pmd_type == 'S' || hw->pmd_type == 'P')
3040 hw->flags |= SKY2_HW_FIBRE_PHY;
3041
Stephen Hemmingere3173832007-02-06 10:45:39 -08003042 hw->ports = 1;
3043 t8 = sky2_read8(hw, B2_Y2_HW_RES);
3044 if ((t8 & CFG_DUAL_MAC_MSK) == CFG_DUAL_MAC_MSK) {
3045 if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC))
3046 ++hw->ports;
3047 }
3048
Mike McCormack74a61eb2009-09-21 04:08:52 +00003049 if (sky2_read8(hw, B2_E_0))
3050 hw->flags |= SKY2_HW_RAM_BUFFER;
3051
Stephen Hemmingere3173832007-02-06 10:45:39 -08003052 return 0;
3053}
3054
3055static void sky2_reset(struct sky2_hw *hw)
3056{
Stephen Hemminger555382c2007-08-29 12:58:14 -07003057 struct pci_dev *pdev = hw->pdev;
Stephen Hemmingere3173832007-02-06 10:45:39 -08003058 u16 status;
Stephen Hemminger555382c2007-08-29 12:58:14 -07003059 int i, cap;
3060 u32 hwe_mask = Y2_HWE_ALL_MASK;
Stephen Hemmingere3173832007-02-06 10:45:39 -08003061
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003062 /* disable ASF */
stephen hemmingeracd12dd2010-02-07 06:24:50 +00003063 if (hw->chip_id == CHIP_ID_YUKON_EX
3064 || hw->chip_id == CHIP_ID_YUKON_SUPR) {
3065 sky2_write32(hw, CPU_WDOG, 0);
Stephen Hemminger4f44d8b2007-04-11 14:48:00 -07003066 status = sky2_read16(hw, HCU_CCSR);
3067 status &= ~(HCU_CCSR_AHB_RST | HCU_CCSR_CPU_RST_MODE |
3068 HCU_CCSR_UC_STATE_MSK);
stephen hemmingeracd12dd2010-02-07 06:24:50 +00003069 /*
3070 * CPU clock divider shouldn't be used because
3071 * - ASF firmware may malfunction
3072 * - Yukon-Supreme: Parallel FLASH doesn't support divided clocks
3073 */
3074 status &= ~HCU_CCSR_CPU_CLK_DIVIDE_MSK;
Stephen Hemminger4f44d8b2007-04-11 14:48:00 -07003075 sky2_write16(hw, HCU_CCSR, status);
stephen hemmingeracd12dd2010-02-07 06:24:50 +00003076 sky2_write32(hw, CPU_WDOG, 0);
Stephen Hemminger4f44d8b2007-04-11 14:48:00 -07003077 } else
3078 sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET);
3079 sky2_write16(hw, B0_CTST, Y2_ASF_DISABLE);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003080
3081 /* do a SW reset */
3082 sky2_write8(hw, B0_CTST, CS_RST_SET);
3083 sky2_write8(hw, B0_CTST, CS_RST_CLR);
3084
Stephen Hemmingerac93a392007-11-05 15:52:08 -08003085 /* allow writes to PCI config */
3086 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
3087
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003088 /* clear PCI errors, if any */
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08003089 status = sky2_pci_read16(hw, PCI_STATUS);
Stephen Hemminger167f53d2007-09-25 19:01:02 -07003090 status |= PCI_STATUS_ERROR_BITS;
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08003091 sky2_pci_write16(hw, PCI_STATUS, status);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003092
3093 sky2_write8(hw, B0_CTST, CS_MRST_CLR);
3094
Stephen Hemminger555382c2007-08-29 12:58:14 -07003095 cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
3096 if (cap) {
Stephen Hemminger7782c8c2007-11-27 11:02:32 -08003097 sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
3098 0xfffffffful);
Stephen Hemminger7bd656d2006-10-09 14:40:38 -07003099
Stephen Hemminger555382c2007-08-29 12:58:14 -07003100 /* If error bit is stuck on ignore it */
3101 if (sky2_read32(hw, B0_HWE_ISRC) & Y2_IS_PCI_EXP)
3102 dev_info(&pdev->dev, "ignoring stuck error report bit\n");
Stephen Hemminger7782c8c2007-11-27 11:02:32 -08003103 else
Stephen Hemminger555382c2007-08-29 12:58:14 -07003104 hwe_mask |= Y2_IS_PCI_EXP;
3105 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003106
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08003107 sky2_power_on(hw);
stephen hemmingera40ccc62010-01-24 18:46:06 +00003108 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003109
3110 for (i = 0; i < hw->ports; i++) {
3111 sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
3112 sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
Stephen Hemminger69161612007-06-04 17:23:26 -07003113
Stephen Hemmingered4d4162008-01-10 16:14:14 -08003114 if (hw->chip_id == CHIP_ID_YUKON_EX ||
3115 hw->chip_id == CHIP_ID_YUKON_SUPR)
Stephen Hemminger69161612007-06-04 17:23:26 -07003116 sky2_write16(hw, SK_REG(i, GMAC_CTRL),
3117 GMC_BYP_MACSECRX_ON | GMC_BYP_MACSECTX_ON
3118 | GMC_BYP_RETR_ON);
Stephen Hemminger877c8572009-10-29 06:37:08 +00003119
3120 }
3121
3122 if (hw->chip_id == CHIP_ID_YUKON_SUPR && hw->chip_rev > CHIP_REV_YU_SU_B0) {
3123 /* enable MACSec clock gating */
3124 sky2_pci_write32(hw, PCI_DEV_REG3, P_CLK_MACSEC_DIS);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003125 }
3126
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00003127 if (hw->chip_id == CHIP_ID_YUKON_OPT) {
3128 u16 reg;
3129 u32 msk;
3130
3131 if (hw->chip_rev == 0) {
3132 /* disable PCI-E PHY power down (set PHY reg 0x80, bit 7 */
3133 sky2_write32(hw, Y2_PEX_PHY_DATA, (0x80UL << 16) | (1 << 7));
3134
3135 /* set PHY Link Detect Timer to 1.1 second (11x 100ms) */
3136 reg = 10;
3137 } else {
3138 /* set PHY Link Detect Timer to 0.4 second (4x 100ms) */
3139 reg = 3;
3140 }
3141
3142 reg <<= PSM_CONFIG_REG4_TIMER_PHY_LINK_DETECT_BASE;
3143
3144 /* reset PHY Link Detect */
stephen hemmingera40ccc62010-01-24 18:46:06 +00003145 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00003146 sky2_pci_write16(hw, PSM_CONFIG_REG4,
3147 reg | PSM_CONFIG_REG4_RST_PHY_LINK_DETECT);
3148 sky2_pci_write16(hw, PSM_CONFIG_REG4, reg);
3149
3150
3151 /* enable PHY Quick Link */
3152 msk = sky2_read32(hw, B0_IMSK);
3153 msk |= Y2_IS_PHY_QLNK;
3154 sky2_write32(hw, B0_IMSK, msk);
3155
3156 /* check if PSMv2 was running before */
3157 reg = sky2_pci_read16(hw, PSM_CONFIG_REG3);
3158 if (reg & PCI_EXP_LNKCTL_ASPMC) {
stephen hemminger8b055432010-02-12 06:57:58 +00003159 cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00003160 /* restore the PCIe Link Control register */
3161 sky2_pci_write16(hw, cap + PCI_EXP_LNKCTL, reg);
3162 }
stephen hemmingera40ccc62010-01-24 18:46:06 +00003163 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00003164
3165 /* re-enable PEX PM in PEX PHY debug reg. 8 (clear bit 12) */
3166 sky2_write32(hw, Y2_PEX_PHY_DATA, PEX_DB_ACCESS | (0x08UL << 16));
3167 }
3168
Stephen Hemminger793b8832005-09-14 16:06:14 -07003169 /* Clear I2C IRQ noise */
3170 sky2_write32(hw, B2_I2C_IRQ, 1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003171
3172 /* turn off hardware timer (unused) */
3173 sky2_write8(hw, B2_TI_CTRL, TIM_STOP);
3174 sky2_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003175
Stephen Hemminger69634ee2005-12-09 11:35:06 -08003176 /* Turn off descriptor polling */
3177 sky2_write32(hw, B28_DPT_CTRL, DPT_STOP);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003178
3179 /* Turn off receive timestamp */
3180 sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_STOP);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003181 sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003182
3183 /* enable the Tx Arbiters */
3184 for (i = 0; i < hw->ports; i++)
3185 sky2_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB);
3186
3187 /* Initialize ram interface */
3188 for (i = 0; i < hw->ports; i++) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07003189 sky2_write8(hw, RAM_BUFFER(i, B3_RI_CTRL), RI_RST_CLR);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003190
3191 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R1), SK_RI_TO_53);
3192 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA1), SK_RI_TO_53);
3193 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS1), SK_RI_TO_53);
3194 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R1), SK_RI_TO_53);
3195 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA1), SK_RI_TO_53);
3196 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS1), SK_RI_TO_53);
3197 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R2), SK_RI_TO_53);
3198 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA2), SK_RI_TO_53);
3199 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS2), SK_RI_TO_53);
3200 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R2), SK_RI_TO_53);
3201 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA2), SK_RI_TO_53);
3202 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS2), SK_RI_TO_53);
3203 }
3204
Stephen Hemminger555382c2007-08-29 12:58:14 -07003205 sky2_write32(hw, B0_HWE_IMSK, hwe_mask);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003206
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003207 for (i = 0; i < hw->ports; i++)
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -07003208 sky2_gmac_reset(hw, i);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003209
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003210 memset(hw->st_le, 0, STATUS_LE_BYTES);
3211 hw->st_idx = 0;
3212
3213 sky2_write32(hw, STAT_CTRL, SC_STAT_RST_SET);
3214 sky2_write32(hw, STAT_CTRL, SC_STAT_RST_CLR);
3215
3216 sky2_write32(hw, STAT_LIST_ADDR_LO, hw->st_dma);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003217 sky2_write32(hw, STAT_LIST_ADDR_HI, (u64) hw->st_dma >> 32);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003218
3219 /* Set the list last index */
Stephen Hemminger793b8832005-09-14 16:06:14 -07003220 sky2_write16(hw, STAT_LAST_IDX, STATUS_RING_SIZE - 1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003221
Stephen Hemminger290d4de2006-03-20 15:48:15 -08003222 sky2_write16(hw, STAT_TX_IDX_TH, 10);
3223 sky2_write8(hw, STAT_FIFO_WM, 16);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003224
Stephen Hemminger290d4de2006-03-20 15:48:15 -08003225 /* set Status-FIFO ISR watermark */
3226 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0)
3227 sky2_write8(hw, STAT_FIFO_ISR_WM, 4);
3228 else
3229 sky2_write8(hw, STAT_FIFO_ISR_WM, 16);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003230
Stephen Hemminger290d4de2006-03-20 15:48:15 -08003231 sky2_write32(hw, STAT_TX_TIMER_INI, sky2_us2clk(hw, 1000));
Stephen Hemminger77b3d6a2006-03-20 15:48:18 -08003232 sky2_write32(hw, STAT_ISR_TIMER_INI, sky2_us2clk(hw, 20));
3233 sky2_write32(hw, STAT_LEV_TIMER_INI, sky2_us2clk(hw, 100));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003234
Stephen Hemminger793b8832005-09-14 16:06:14 -07003235 /* enable status unit */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003236 sky2_write32(hw, STAT_CTRL, SC_STAT_OP_ON);
3237
3238 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
3239 sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START);
3240 sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START);
Stephen Hemmingere3173832007-02-06 10:45:39 -08003241}
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003242
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07003243/* Take device down (offline).
3244 * Equivalent to doing dev_stop() but this does not
3245 * inform upper layers of the transistion.
3246 */
3247static void sky2_detach(struct net_device *dev)
3248{
3249 if (netif_running(dev)) {
Mike McCormackc36531b2009-12-31 00:55:31 +00003250 netif_tx_lock(dev);
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07003251 netif_device_detach(dev); /* stop txq */
Mike McCormackc36531b2009-12-31 00:55:31 +00003252 netif_tx_unlock(dev);
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07003253 sky2_down(dev);
3254 }
3255}
3256
3257/* Bring device back after doing sky2_detach */
3258static int sky2_reattach(struct net_device *dev)
3259{
3260 int err = 0;
3261
3262 if (netif_running(dev)) {
3263 err = sky2_up(dev);
3264 if (err) {
3265 printk(KERN_INFO PFX "%s: could not restart %d\n",
3266 dev->name, err);
3267 dev_close(dev);
3268 } else {
3269 netif_device_attach(dev);
3270 sky2_set_multicast(dev);
3271 }
3272 }
3273
3274 return err;
3275}
3276
Stephen Hemminger81906792007-02-15 16:40:33 -08003277static void sky2_restart(struct work_struct *work)
3278{
3279 struct sky2_hw *hw = container_of(work, struct sky2_hw, restart_work);
Mike McCormack8a0c9222010-02-12 06:58:06 +00003280 u32 imask;
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07003281 int i;
Stephen Hemminger81906792007-02-15 16:40:33 -08003282
Stephen Hemminger81906792007-02-15 16:40:33 -08003283 rtnl_lock();
Stephen Hemminger81906792007-02-15 16:40:33 -08003284
Stephen Hemminger8cfcbe92007-12-03 17:02:17 -08003285 napi_disable(&hw->napi);
Mike McCormack8a0c9222010-02-12 06:58:06 +00003286 synchronize_irq(hw->pdev->irq);
3287 imask = sky2_read32(hw, B0_IMSK);
Stephen Hemminger8cfcbe92007-12-03 17:02:17 -08003288 sky2_write32(hw, B0_IMSK, 0);
Stephen Hemminger81906792007-02-15 16:40:33 -08003289
Mike McCormack8a0c9222010-02-12 06:58:06 +00003290 for (i = 0; i < hw->ports; i++) {
3291 struct net_device *dev = hw->dev[i];
3292 struct sky2_port *sky2 = netdev_priv(dev);
3293
3294 if (!netif_running(dev))
3295 continue;
3296
3297 netif_carrier_off(dev);
3298 netif_tx_disable(dev);
3299 sky2_hw_down(sky2);
3300 }
3301
3302 sky2_reset(hw);
3303
3304 for (i = 0; i < hw->ports; i++) {
3305 struct net_device *dev = hw->dev[i];
3306 struct sky2_port *sky2 = netdev_priv(dev);
3307
3308 if (!netif_running(dev))
3309 continue;
3310
3311 sky2_hw_up(sky2);
3312 netif_wake_queue(dev);
3313 }
3314
3315 sky2_write32(hw, B0_IMSK, imask);
3316 sky2_read32(hw, B0_IMSK);
3317
3318 sky2_read32(hw, B0_Y2_SP_LISR);
3319 napi_enable(&hw->napi);
Stephen Hemminger81906792007-02-15 16:40:33 -08003320
Stephen Hemminger81906792007-02-15 16:40:33 -08003321 rtnl_unlock();
3322}
3323
Stephen Hemmingere3173832007-02-06 10:45:39 -08003324static inline u8 sky2_wol_supported(const struct sky2_hw *hw)
3325{
3326 return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0;
3327}
3328
3329static void sky2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
3330{
3331 const struct sky2_port *sky2 = netdev_priv(dev);
3332
3333 wol->supported = sky2_wol_supported(sky2->hw);
3334 wol->wolopts = sky2->wol;
3335}
3336
3337static int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
3338{
3339 struct sky2_port *sky2 = netdev_priv(dev);
3340 struct sky2_hw *hw = sky2->hw;
3341
Joe Perches8e95a202009-12-03 07:58:21 +00003342 if ((wol->wolopts & ~sky2_wol_supported(sky2->hw)) ||
3343 !device_can_wakeup(&hw->pdev->dev))
Stephen Hemmingere3173832007-02-06 10:45:39 -08003344 return -EOPNOTSUPP;
3345
3346 sky2->wol = wol->wolopts;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003347 return 0;
3348}
3349
Stephen Hemminger28bd1812006-01-17 13:43:19 -08003350static u32 sky2_supported_modes(const struct sky2_hw *hw)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003351{
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07003352 if (sky2_is_copper(hw)) {
3353 u32 modes = SUPPORTED_10baseT_Half
3354 | SUPPORTED_10baseT_Full
3355 | SUPPORTED_100baseT_Half
3356 | SUPPORTED_100baseT_Full
3357 | SUPPORTED_Autoneg | SUPPORTED_TP;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003358
Stephen Hemmingerea76e632007-09-19 15:36:44 -07003359 if (hw->flags & SKY2_HW_GIGABIT)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003360 modes |= SUPPORTED_1000baseT_Half
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07003361 | SUPPORTED_1000baseT_Full;
3362 return modes;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003363 } else
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07003364 return SUPPORTED_1000baseT_Half
3365 | SUPPORTED_1000baseT_Full
3366 | SUPPORTED_Autoneg
3367 | SUPPORTED_FIBRE;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003368}
3369
Stephen Hemminger793b8832005-09-14 16:06:14 -07003370static int sky2_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003371{
3372 struct sky2_port *sky2 = netdev_priv(dev);
3373 struct sky2_hw *hw = sky2->hw;
3374
3375 ecmd->transceiver = XCVR_INTERNAL;
3376 ecmd->supported = sky2_supported_modes(hw);
3377 ecmd->phy_address = PHY_ADDR_MARV;
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07003378 if (sky2_is_copper(hw)) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003379 ecmd->port = PORT_TP;
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07003380 ecmd->speed = sky2->speed;
3381 } else {
3382 ecmd->speed = SPEED_1000;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003383 ecmd->port = PORT_FIBRE;
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07003384 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003385
3386 ecmd->advertising = sky2->advertising;
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003387 ecmd->autoneg = (sky2->flags & SKY2_FLAG_AUTO_SPEED)
3388 ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003389 ecmd->duplex = sky2->duplex;
3390 return 0;
3391}
3392
3393static int sky2_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3394{
3395 struct sky2_port *sky2 = netdev_priv(dev);
3396 const struct sky2_hw *hw = sky2->hw;
3397 u32 supported = sky2_supported_modes(hw);
3398
3399 if (ecmd->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003400 sky2->flags |= SKY2_FLAG_AUTO_SPEED;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003401 ecmd->advertising = supported;
3402 sky2->duplex = -1;
3403 sky2->speed = -1;
3404 } else {
3405 u32 setting;
3406
Stephen Hemminger793b8832005-09-14 16:06:14 -07003407 switch (ecmd->speed) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003408 case SPEED_1000:
3409 if (ecmd->duplex == DUPLEX_FULL)
3410 setting = SUPPORTED_1000baseT_Full;
3411 else if (ecmd->duplex == DUPLEX_HALF)
3412 setting = SUPPORTED_1000baseT_Half;
3413 else
3414 return -EINVAL;
3415 break;
3416 case SPEED_100:
3417 if (ecmd->duplex == DUPLEX_FULL)
3418 setting = SUPPORTED_100baseT_Full;
3419 else if (ecmd->duplex == DUPLEX_HALF)
3420 setting = SUPPORTED_100baseT_Half;
3421 else
3422 return -EINVAL;
3423 break;
3424
3425 case SPEED_10:
3426 if (ecmd->duplex == DUPLEX_FULL)
3427 setting = SUPPORTED_10baseT_Full;
3428 else if (ecmd->duplex == DUPLEX_HALF)
3429 setting = SUPPORTED_10baseT_Half;
3430 else
3431 return -EINVAL;
3432 break;
3433 default:
3434 return -EINVAL;
3435 }
3436
3437 if ((setting & supported) == 0)
3438 return -EINVAL;
3439
3440 sky2->speed = ecmd->speed;
3441 sky2->duplex = ecmd->duplex;
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003442 sky2->flags &= ~SKY2_FLAG_AUTO_SPEED;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003443 }
3444
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003445 sky2->advertising = ecmd->advertising;
3446
Stephen Hemmingerd1b139c2007-09-05 16:56:19 +01003447 if (netif_running(dev)) {
Stephen Hemminger1b537562005-12-20 15:08:07 -08003448 sky2_phy_reinit(sky2);
Stephen Hemmingerd1b139c2007-09-05 16:56:19 +01003449 sky2_set_multicast(dev);
3450 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003451
3452 return 0;
3453}
3454
3455static void sky2_get_drvinfo(struct net_device *dev,
3456 struct ethtool_drvinfo *info)
3457{
3458 struct sky2_port *sky2 = netdev_priv(dev);
3459
3460 strcpy(info->driver, DRV_NAME);
3461 strcpy(info->version, DRV_VERSION);
3462 strcpy(info->fw_version, "N/A");
3463 strcpy(info->bus_info, pci_name(sky2->hw->pdev));
3464}
3465
3466static const struct sky2_stat {
Stephen Hemminger793b8832005-09-14 16:06:14 -07003467 char name[ETH_GSTRING_LEN];
3468 u16 offset;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003469} sky2_stats[] = {
3470 { "tx_bytes", GM_TXO_OK_HI },
3471 { "rx_bytes", GM_RXO_OK_HI },
3472 { "tx_broadcast", GM_TXF_BC_OK },
3473 { "rx_broadcast", GM_RXF_BC_OK },
3474 { "tx_multicast", GM_TXF_MC_OK },
3475 { "rx_multicast", GM_RXF_MC_OK },
3476 { "tx_unicast", GM_TXF_UC_OK },
3477 { "rx_unicast", GM_RXF_UC_OK },
3478 { "tx_mac_pause", GM_TXF_MPAUSE },
3479 { "rx_mac_pause", GM_RXF_MPAUSE },
Stephen Hemmingereadfa7d2006-03-22 10:38:45 -08003480 { "collisions", GM_TXF_COL },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003481 { "late_collision",GM_TXF_LAT_COL },
3482 { "aborted", GM_TXF_ABO_COL },
Stephen Hemmingereadfa7d2006-03-22 10:38:45 -08003483 { "single_collisions", GM_TXF_SNG_COL },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003484 { "multi_collisions", GM_TXF_MUL_COL },
Stephen Hemmingereadfa7d2006-03-22 10:38:45 -08003485
Stephen Hemmingerd2604542006-03-23 08:51:36 -08003486 { "rx_short", GM_RXF_SHT },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003487 { "rx_runt", GM_RXE_FRAG },
Stephen Hemmingereadfa7d2006-03-22 10:38:45 -08003488 { "rx_64_byte_packets", GM_RXF_64B },
3489 { "rx_65_to_127_byte_packets", GM_RXF_127B },
3490 { "rx_128_to_255_byte_packets", GM_RXF_255B },
3491 { "rx_256_to_511_byte_packets", GM_RXF_511B },
3492 { "rx_512_to_1023_byte_packets", GM_RXF_1023B },
3493 { "rx_1024_to_1518_byte_packets", GM_RXF_1518B },
3494 { "rx_1518_to_max_byte_packets", GM_RXF_MAX_SZ },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003495 { "rx_too_long", GM_RXF_LNG_ERR },
Stephen Hemmingereadfa7d2006-03-22 10:38:45 -08003496 { "rx_fifo_overflow", GM_RXE_FIFO_OV },
3497 { "rx_jabber", GM_RXF_JAB_PKT },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003498 { "rx_fcs_error", GM_RXF_FCS_ERR },
Stephen Hemmingereadfa7d2006-03-22 10:38:45 -08003499
3500 { "tx_64_byte_packets", GM_TXF_64B },
3501 { "tx_65_to_127_byte_packets", GM_TXF_127B },
3502 { "tx_128_to_255_byte_packets", GM_TXF_255B },
3503 { "tx_256_to_511_byte_packets", GM_TXF_511B },
3504 { "tx_512_to_1023_byte_packets", GM_TXF_1023B },
3505 { "tx_1024_to_1518_byte_packets", GM_TXF_1518B },
3506 { "tx_1519_to_max_byte_packets", GM_TXF_MAX_SZ },
3507 { "tx_fifo_underrun", GM_TXE_FIFO_UR },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003508};
3509
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003510static u32 sky2_get_rx_csum(struct net_device *dev)
3511{
3512 struct sky2_port *sky2 = netdev_priv(dev);
3513
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003514 return !!(sky2->flags & SKY2_FLAG_RX_CHECKSUM);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003515}
3516
3517static int sky2_set_rx_csum(struct net_device *dev, u32 data)
3518{
3519 struct sky2_port *sky2 = netdev_priv(dev);
3520
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003521 if (data)
3522 sky2->flags |= SKY2_FLAG_RX_CHECKSUM;
3523 else
3524 sky2->flags &= ~SKY2_FLAG_RX_CHECKSUM;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003525
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003526 sky2_write32(sky2->hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR),
3527 data ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM);
3528
3529 return 0;
3530}
3531
3532static u32 sky2_get_msglevel(struct net_device *netdev)
3533{
3534 struct sky2_port *sky2 = netdev_priv(netdev);
3535 return sky2->msg_enable;
3536}
3537
Stephen Hemminger9a7ae0a2005-09-27 15:28:42 -07003538static int sky2_nway_reset(struct net_device *dev)
3539{
3540 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger9a7ae0a2005-09-27 15:28:42 -07003541
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003542 if (!netif_running(dev) || !(sky2->flags & SKY2_FLAG_AUTO_SPEED))
Stephen Hemminger9a7ae0a2005-09-27 15:28:42 -07003543 return -EINVAL;
3544
Stephen Hemminger1b537562005-12-20 15:08:07 -08003545 sky2_phy_reinit(sky2);
Stephen Hemmingerd1b139c2007-09-05 16:56:19 +01003546 sky2_set_multicast(dev);
Stephen Hemminger9a7ae0a2005-09-27 15:28:42 -07003547
3548 return 0;
3549}
3550
Stephen Hemminger793b8832005-09-14 16:06:14 -07003551static void sky2_phy_stats(struct sky2_port *sky2, u64 * data, unsigned count)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003552{
3553 struct sky2_hw *hw = sky2->hw;
3554 unsigned port = sky2->port;
3555 int i;
3556
3557 data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32
Stephen Hemminger793b8832005-09-14 16:06:14 -07003558 | (u64) gma_read32(hw, port, GM_TXO_OK_LO);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003559 data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32
Stephen Hemminger793b8832005-09-14 16:06:14 -07003560 | (u64) gma_read32(hw, port, GM_RXO_OK_LO);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003561
Stephen Hemminger793b8832005-09-14 16:06:14 -07003562 for (i = 2; i < count; i++)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003563 data[i] = (u64) gma_read32(hw, port, sky2_stats[i].offset);
3564}
3565
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003566static void sky2_set_msglevel(struct net_device *netdev, u32 value)
3567{
3568 struct sky2_port *sky2 = netdev_priv(netdev);
3569 sky2->msg_enable = value;
3570}
3571
Jeff Garzikb9f2c042007-10-03 18:07:32 -07003572static int sky2_get_sset_count(struct net_device *dev, int sset)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003573{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07003574 switch (sset) {
3575 case ETH_SS_STATS:
3576 return ARRAY_SIZE(sky2_stats);
3577 default:
3578 return -EOPNOTSUPP;
3579 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003580}
3581
3582static void sky2_get_ethtool_stats(struct net_device *dev,
Stephen Hemminger793b8832005-09-14 16:06:14 -07003583 struct ethtool_stats *stats, u64 * data)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003584{
3585 struct sky2_port *sky2 = netdev_priv(dev);
3586
Stephen Hemminger793b8832005-09-14 16:06:14 -07003587 sky2_phy_stats(sky2, data, ARRAY_SIZE(sky2_stats));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003588}
3589
Stephen Hemminger793b8832005-09-14 16:06:14 -07003590static void sky2_get_strings(struct net_device *dev, u32 stringset, u8 * data)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003591{
3592 int i;
3593
3594 switch (stringset) {
3595 case ETH_SS_STATS:
3596 for (i = 0; i < ARRAY_SIZE(sky2_stats); i++)
3597 memcpy(data + i * ETH_GSTRING_LEN,
3598 sky2_stats[i].name, ETH_GSTRING_LEN);
3599 break;
3600 }
3601}
3602
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003603static int sky2_set_mac_address(struct net_device *dev, void *p)
3604{
3605 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingera8ab1ec2006-01-30 11:37:57 -08003606 struct sky2_hw *hw = sky2->hw;
3607 unsigned port = sky2->port;
3608 const struct sockaddr *addr = p;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003609
3610 if (!is_valid_ether_addr(addr->sa_data))
3611 return -EADDRNOTAVAIL;
3612
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003613 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
Stephen Hemmingera8ab1ec2006-01-30 11:37:57 -08003614 memcpy_toio(hw->regs + B2_MAC_1 + port * 8,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003615 dev->dev_addr, ETH_ALEN);
Stephen Hemmingera8ab1ec2006-01-30 11:37:57 -08003616 memcpy_toio(hw->regs + B2_MAC_2 + port * 8,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003617 dev->dev_addr, ETH_ALEN);
Stephen Hemminger1b537562005-12-20 15:08:07 -08003618
Stephen Hemmingera8ab1ec2006-01-30 11:37:57 -08003619 /* virtual address for data */
3620 gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr);
3621
3622 /* physical address: used for pause frames */
3623 gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr);
Stephen Hemminger1b537562005-12-20 15:08:07 -08003624
3625 return 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003626}
3627
Stephen Hemmingera052b522006-10-17 10:24:23 -07003628static void inline sky2_add_filter(u8 filter[8], const u8 *addr)
3629{
3630 u32 bit;
3631
3632 bit = ether_crc(ETH_ALEN, addr) & 63;
3633 filter[bit >> 3] |= 1 << (bit & 7);
3634}
3635
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003636static void sky2_set_multicast(struct net_device *dev)
3637{
3638 struct sky2_port *sky2 = netdev_priv(dev);
3639 struct sky2_hw *hw = sky2->hw;
3640 unsigned port = sky2->port;
3641 struct dev_mc_list *list = dev->mc_list;
3642 u16 reg;
3643 u8 filter[8];
Stephen Hemmingera052b522006-10-17 10:24:23 -07003644 int rx_pause;
3645 static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 };
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003646
Stephen Hemmingera052b522006-10-17 10:24:23 -07003647 rx_pause = (sky2->flow_status == FC_RX || sky2->flow_status == FC_BOTH);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003648 memset(filter, 0, sizeof(filter));
3649
3650 reg = gma_read16(hw, port, GM_RX_CTRL);
3651 reg |= GM_RXCR_UCF_ENA;
3652
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07003653 if (dev->flags & IFF_PROMISC) /* promiscuous */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003654 reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
Stephen Hemmingera052b522006-10-17 10:24:23 -07003655 else if (dev->flags & IFF_ALLMULTI)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003656 memset(filter, 0xff, sizeof(filter));
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00003657 else if (netdev_mc_empty(dev) && !rx_pause)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003658 reg &= ~GM_RXCR_MCF_ENA;
3659 else {
3660 int i;
3661 reg |= GM_RXCR_MCF_ENA;
3662
Stephen Hemmingera052b522006-10-17 10:24:23 -07003663 if (rx_pause)
3664 sky2_add_filter(filter, pause_mc_addr);
3665
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00003666 for (i = 0; list && i < netdev_mc_count(dev); i++, list = list->next)
Stephen Hemmingera052b522006-10-17 10:24:23 -07003667 sky2_add_filter(filter, list->dmi_addr);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003668 }
3669
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003670 gma_write16(hw, port, GM_MC_ADDR_H1,
Stephen Hemminger793b8832005-09-14 16:06:14 -07003671 (u16) filter[0] | ((u16) filter[1] << 8));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003672 gma_write16(hw, port, GM_MC_ADDR_H2,
Stephen Hemminger793b8832005-09-14 16:06:14 -07003673 (u16) filter[2] | ((u16) filter[3] << 8));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003674 gma_write16(hw, port, GM_MC_ADDR_H3,
Stephen Hemminger793b8832005-09-14 16:06:14 -07003675 (u16) filter[4] | ((u16) filter[5] << 8));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003676 gma_write16(hw, port, GM_MC_ADDR_H4,
Stephen Hemminger793b8832005-09-14 16:06:14 -07003677 (u16) filter[6] | ((u16) filter[7] << 8));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003678
3679 gma_write16(hw, port, GM_RX_CTRL, reg);
3680}
3681
3682/* Can have one global because blinking is controlled by
3683 * ethtool and that is always under RTNL mutex
3684 */
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003685static void sky2_led(struct sky2_port *sky2, enum led_mode mode)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003686{
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003687 struct sky2_hw *hw = sky2->hw;
3688 unsigned port = sky2->port;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003689
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003690 spin_lock_bh(&sky2->phy_lock);
3691 if (hw->chip_id == CHIP_ID_YUKON_EC_U ||
3692 hw->chip_id == CHIP_ID_YUKON_EX ||
3693 hw->chip_id == CHIP_ID_YUKON_SUPR) {
3694 u16 pg;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003695 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
3696 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003697
3698 switch (mode) {
3699 case MO_LED_OFF:
3700 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
3701 PHY_M_LEDC_LOS_CTRL(8) |
3702 PHY_M_LEDC_INIT_CTRL(8) |
3703 PHY_M_LEDC_STA1_CTRL(8) |
3704 PHY_M_LEDC_STA0_CTRL(8));
3705 break;
3706 case MO_LED_ON:
3707 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
3708 PHY_M_LEDC_LOS_CTRL(9) |
3709 PHY_M_LEDC_INIT_CTRL(9) |
3710 PHY_M_LEDC_STA1_CTRL(9) |
3711 PHY_M_LEDC_STA0_CTRL(9));
3712 break;
3713 case MO_LED_BLINK:
3714 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
3715 PHY_M_LEDC_LOS_CTRL(0xa) |
3716 PHY_M_LEDC_INIT_CTRL(0xa) |
3717 PHY_M_LEDC_STA1_CTRL(0xa) |
3718 PHY_M_LEDC_STA0_CTRL(0xa));
3719 break;
3720 case MO_LED_NORM:
3721 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
3722 PHY_M_LEDC_LOS_CTRL(1) |
3723 PHY_M_LEDC_INIT_CTRL(8) |
3724 PHY_M_LEDC_STA1_CTRL(7) |
3725 PHY_M_LEDC_STA0_CTRL(7));
3726 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07003727
3728 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003729 } else
Jeff Garzik7d2e3cb2008-05-13 01:41:58 -04003730 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003731 PHY_M_LED_MO_DUP(mode) |
3732 PHY_M_LED_MO_10(mode) |
3733 PHY_M_LED_MO_100(mode) |
3734 PHY_M_LED_MO_1000(mode) |
3735 PHY_M_LED_MO_RX(mode) |
3736 PHY_M_LED_MO_TX(mode));
3737
3738 spin_unlock_bh(&sky2->phy_lock);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003739}
3740
3741/* blink LED's for finding board */
3742static int sky2_phys_id(struct net_device *dev, u32 data)
3743{
3744 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003745 unsigned int i;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003746
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003747 if (data == 0)
3748 data = UINT_MAX;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003749
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003750 for (i = 0; i < data; i++) {
3751 sky2_led(sky2, MO_LED_ON);
3752 if (msleep_interruptible(500))
3753 break;
3754 sky2_led(sky2, MO_LED_OFF);
3755 if (msleep_interruptible(500))
3756 break;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003757 }
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003758 sky2_led(sky2, MO_LED_NORM);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003759
3760 return 0;
3761}
3762
3763static void sky2_get_pauseparam(struct net_device *dev,
3764 struct ethtool_pauseparam *ecmd)
3765{
3766 struct sky2_port *sky2 = netdev_priv(dev);
3767
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07003768 switch (sky2->flow_mode) {
3769 case FC_NONE:
3770 ecmd->tx_pause = ecmd->rx_pause = 0;
3771 break;
3772 case FC_TX:
3773 ecmd->tx_pause = 1, ecmd->rx_pause = 0;
3774 break;
3775 case FC_RX:
3776 ecmd->tx_pause = 0, ecmd->rx_pause = 1;
3777 break;
3778 case FC_BOTH:
3779 ecmd->tx_pause = ecmd->rx_pause = 1;
3780 }
3781
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003782 ecmd->autoneg = (sky2->flags & SKY2_FLAG_AUTO_PAUSE)
3783 ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003784}
3785
3786static int sky2_set_pauseparam(struct net_device *dev,
3787 struct ethtool_pauseparam *ecmd)
3788{
3789 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003790
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003791 if (ecmd->autoneg == AUTONEG_ENABLE)
3792 sky2->flags |= SKY2_FLAG_AUTO_PAUSE;
3793 else
3794 sky2->flags &= ~SKY2_FLAG_AUTO_PAUSE;
3795
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07003796 sky2->flow_mode = sky2_flow(ecmd->rx_pause, ecmd->tx_pause);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003797
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07003798 if (netif_running(dev))
3799 sky2_phy_reinit(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003800
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -07003801 return 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003802}
3803
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003804static int sky2_get_coalesce(struct net_device *dev,
3805 struct ethtool_coalesce *ecmd)
3806{
3807 struct sky2_port *sky2 = netdev_priv(dev);
3808 struct sky2_hw *hw = sky2->hw;
3809
3810 if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_STOP)
3811 ecmd->tx_coalesce_usecs = 0;
3812 else {
3813 u32 clks = sky2_read32(hw, STAT_TX_TIMER_INI);
3814 ecmd->tx_coalesce_usecs = sky2_clk2us(hw, clks);
3815 }
3816 ecmd->tx_max_coalesced_frames = sky2_read16(hw, STAT_TX_IDX_TH);
3817
3818 if (sky2_read8(hw, STAT_LEV_TIMER_CTRL) == TIM_STOP)
3819 ecmd->rx_coalesce_usecs = 0;
3820 else {
3821 u32 clks = sky2_read32(hw, STAT_LEV_TIMER_INI);
3822 ecmd->rx_coalesce_usecs = sky2_clk2us(hw, clks);
3823 }
3824 ecmd->rx_max_coalesced_frames = sky2_read8(hw, STAT_FIFO_WM);
3825
3826 if (sky2_read8(hw, STAT_ISR_TIMER_CTRL) == TIM_STOP)
3827 ecmd->rx_coalesce_usecs_irq = 0;
3828 else {
3829 u32 clks = sky2_read32(hw, STAT_ISR_TIMER_INI);
3830 ecmd->rx_coalesce_usecs_irq = sky2_clk2us(hw, clks);
3831 }
3832
3833 ecmd->rx_max_coalesced_frames_irq = sky2_read8(hw, STAT_FIFO_ISR_WM);
3834
3835 return 0;
3836}
3837
3838/* Note: this affect both ports */
3839static int sky2_set_coalesce(struct net_device *dev,
3840 struct ethtool_coalesce *ecmd)
3841{
3842 struct sky2_port *sky2 = netdev_priv(dev);
3843 struct sky2_hw *hw = sky2->hw;
Stephen Hemminger77b3d6a2006-03-20 15:48:18 -08003844 const u32 tmax = sky2_clk2us(hw, 0x0ffffff);
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003845
Stephen Hemminger77b3d6a2006-03-20 15:48:18 -08003846 if (ecmd->tx_coalesce_usecs > tmax ||
3847 ecmd->rx_coalesce_usecs > tmax ||
3848 ecmd->rx_coalesce_usecs_irq > tmax)
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003849 return -EINVAL;
3850
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00003851 if (ecmd->tx_max_coalesced_frames >= sky2->tx_ring_size-1)
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003852 return -EINVAL;
Stephen Hemmingerff81fbb2006-02-22 11:44:59 -08003853 if (ecmd->rx_max_coalesced_frames > RX_MAX_PENDING)
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003854 return -EINVAL;
Stephen Hemmingerff81fbb2006-02-22 11:44:59 -08003855 if (ecmd->rx_max_coalesced_frames_irq >RX_MAX_PENDING)
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003856 return -EINVAL;
3857
3858 if (ecmd->tx_coalesce_usecs == 0)
3859 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP);
3860 else {
3861 sky2_write32(hw, STAT_TX_TIMER_INI,
3862 sky2_us2clk(hw, ecmd->tx_coalesce_usecs));
3863 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
3864 }
3865 sky2_write16(hw, STAT_TX_IDX_TH, ecmd->tx_max_coalesced_frames);
3866
3867 if (ecmd->rx_coalesce_usecs == 0)
3868 sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_STOP);
3869 else {
3870 sky2_write32(hw, STAT_LEV_TIMER_INI,
3871 sky2_us2clk(hw, ecmd->rx_coalesce_usecs));
3872 sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START);
3873 }
3874 sky2_write8(hw, STAT_FIFO_WM, ecmd->rx_max_coalesced_frames);
3875
3876 if (ecmd->rx_coalesce_usecs_irq == 0)
3877 sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_STOP);
3878 else {
Stephen Hemmingerd28d4872006-01-30 11:37:56 -08003879 sky2_write32(hw, STAT_ISR_TIMER_INI,
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003880 sky2_us2clk(hw, ecmd->rx_coalesce_usecs_irq));
3881 sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START);
3882 }
3883 sky2_write8(hw, STAT_FIFO_ISR_WM, ecmd->rx_max_coalesced_frames_irq);
3884 return 0;
3885}
3886
Stephen Hemminger793b8832005-09-14 16:06:14 -07003887static void sky2_get_ringparam(struct net_device *dev,
3888 struct ethtool_ringparam *ering)
3889{
3890 struct sky2_port *sky2 = netdev_priv(dev);
3891
3892 ering->rx_max_pending = RX_MAX_PENDING;
3893 ering->rx_mini_max_pending = 0;
3894 ering->rx_jumbo_max_pending = 0;
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00003895 ering->tx_max_pending = TX_MAX_PENDING;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003896
3897 ering->rx_pending = sky2->rx_pending;
3898 ering->rx_mini_pending = 0;
3899 ering->rx_jumbo_pending = 0;
3900 ering->tx_pending = sky2->tx_pending;
3901}
3902
3903static int sky2_set_ringparam(struct net_device *dev,
3904 struct ethtool_ringparam *ering)
3905{
3906 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003907
3908 if (ering->rx_pending > RX_MAX_PENDING ||
3909 ering->rx_pending < 8 ||
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00003910 ering->tx_pending < TX_MIN_PENDING ||
3911 ering->tx_pending > TX_MAX_PENDING)
Stephen Hemminger793b8832005-09-14 16:06:14 -07003912 return -EINVAL;
3913
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07003914 sky2_detach(dev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003915
3916 sky2->rx_pending = ering->rx_pending;
3917 sky2->tx_pending = ering->tx_pending;
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00003918 sky2->tx_ring_size = roundup_pow_of_two(sky2->tx_pending+1);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003919
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07003920 return sky2_reattach(dev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003921}
3922
Stephen Hemminger793b8832005-09-14 16:06:14 -07003923static int sky2_get_regs_len(struct net_device *dev)
3924{
Stephen Hemminger6e4cbb32005-09-19 15:47:57 -07003925 return 0x4000;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003926}
3927
Mike McCormackc32bbff2009-12-31 00:49:43 +00003928static int sky2_reg_access_ok(struct sky2_hw *hw, unsigned int b)
3929{
3930 /* This complicated switch statement is to make sure and
3931 * only access regions that are unreserved.
3932 * Some blocks are only valid on dual port cards.
3933 */
3934 switch (b) {
3935 /* second port */
3936 case 5: /* Tx Arbiter 2 */
3937 case 9: /* RX2 */
3938 case 14 ... 15: /* TX2 */
3939 case 17: case 19: /* Ram Buffer 2 */
3940 case 22 ... 23: /* Tx Ram Buffer 2 */
3941 case 25: /* Rx MAC Fifo 1 */
3942 case 27: /* Tx MAC Fifo 2 */
3943 case 31: /* GPHY 2 */
3944 case 40 ... 47: /* Pattern Ram 2 */
3945 case 52: case 54: /* TCP Segmentation 2 */
3946 case 112 ... 116: /* GMAC 2 */
3947 return hw->ports > 1;
3948
3949 case 0: /* Control */
3950 case 2: /* Mac address */
3951 case 4: /* Tx Arbiter 1 */
3952 case 7: /* PCI express reg */
3953 case 8: /* RX1 */
3954 case 12 ... 13: /* TX1 */
3955 case 16: case 18:/* Rx Ram Buffer 1 */
3956 case 20 ... 21: /* Tx Ram Buffer 1 */
3957 case 24: /* Rx MAC Fifo 1 */
3958 case 26: /* Tx MAC Fifo 1 */
3959 case 28 ... 29: /* Descriptor and status unit */
3960 case 30: /* GPHY 1*/
3961 case 32 ... 39: /* Pattern Ram 1 */
3962 case 48: case 50: /* TCP Segmentation 1 */
3963 case 56 ... 60: /* PCI space */
3964 case 80 ... 84: /* GMAC 1 */
3965 return 1;
3966
3967 default:
3968 return 0;
3969 }
3970}
3971
Stephen Hemminger793b8832005-09-14 16:06:14 -07003972/*
3973 * Returns copy of control register region
Stephen Hemminger3ead5db2007-06-04 17:23:21 -07003974 * Note: ethtool_get_regs always provides full size (16k) buffer
Stephen Hemminger793b8832005-09-14 16:06:14 -07003975 */
3976static void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs,
3977 void *p)
3978{
3979 const struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003980 const void __iomem *io = sky2->hw->regs;
Stephen Hemminger295b54c2007-10-11 19:47:22 -07003981 unsigned int b;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003982
3983 regs->version = 1;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003984
Stephen Hemminger295b54c2007-10-11 19:47:22 -07003985 for (b = 0; b < 128; b++) {
Mike McCormackc32bbff2009-12-31 00:49:43 +00003986 /* skip poisonous diagnostic ram region in block 3 */
3987 if (b == 3)
Stephen Hemminger295b54c2007-10-11 19:47:22 -07003988 memcpy_fromio(p + 0x10, io + 0x10, 128 - 0x10);
Mike McCormackc32bbff2009-12-31 00:49:43 +00003989 else if (sky2_reg_access_ok(sky2->hw, b))
Stephen Hemminger295b54c2007-10-11 19:47:22 -07003990 memcpy_fromio(p, io, 128);
Mike McCormackc32bbff2009-12-31 00:49:43 +00003991 else
Stephen Hemminger295b54c2007-10-11 19:47:22 -07003992 memset(p, 0, 128);
Stephen Hemminger3ead5db2007-06-04 17:23:21 -07003993
Stephen Hemminger295b54c2007-10-11 19:47:22 -07003994 p += 128;
3995 io += 128;
3996 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07003997}
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003998
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07003999/* In order to do Jumbo packets on these chips, need to turn off the
4000 * transmit store/forward. Therefore checksum offload won't work.
4001 */
4002static int no_tx_offload(struct net_device *dev)
4003{
4004 const struct sky2_port *sky2 = netdev_priv(dev);
4005 const struct sky2_hw *hw = sky2->hw;
4006
Stephen Hemminger69161612007-06-04 17:23:26 -07004007 return dev->mtu > ETH_DATA_LEN && hw->chip_id == CHIP_ID_YUKON_EC_U;
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07004008}
4009
4010static int sky2_set_tx_csum(struct net_device *dev, u32 data)
4011{
4012 if (data && no_tx_offload(dev))
4013 return -EINVAL;
4014
4015 return ethtool_op_set_tx_csum(dev, data);
4016}
4017
4018
4019static int sky2_set_tso(struct net_device *dev, u32 data)
4020{
4021 if (data && no_tx_offload(dev))
4022 return -EINVAL;
4023
4024 return ethtool_op_set_tso(dev, data);
4025}
4026
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004027static int sky2_get_eeprom_len(struct net_device *dev)
4028{
4029 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08004030 struct sky2_hw *hw = sky2->hw;
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004031 u16 reg2;
4032
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08004033 reg2 = sky2_pci_read16(hw, PCI_DEV_REG2);
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004034 return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
4035}
4036
Stephen Hemminger14132352008-08-27 20:46:26 -07004037static int sky2_vpd_wait(const struct sky2_hw *hw, int cap, u16 busy)
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004038{
Stephen Hemminger14132352008-08-27 20:46:26 -07004039 unsigned long start = jiffies;
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004040
Stephen Hemminger14132352008-08-27 20:46:26 -07004041 while ( (sky2_pci_read16(hw, cap + PCI_VPD_ADDR) & PCI_VPD_ADDR_F) == busy) {
4042 /* Can take up to 10.6 ms for write */
4043 if (time_after(jiffies, start + HZ/4)) {
4044 dev_err(&hw->pdev->dev, PFX "VPD cycle timed out");
4045 return -ETIMEDOUT;
4046 }
4047 mdelay(1);
4048 }
Stephen Hemminger167f53d2007-09-25 19:01:02 -07004049
Stephen Hemminger14132352008-08-27 20:46:26 -07004050 return 0;
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004051}
4052
Stephen Hemminger14132352008-08-27 20:46:26 -07004053static int sky2_vpd_read(struct sky2_hw *hw, int cap, void *data,
4054 u16 offset, size_t length)
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004055{
Stephen Hemminger14132352008-08-27 20:46:26 -07004056 int rc = 0;
4057
4058 while (length > 0) {
4059 u32 val;
4060
4061 sky2_pci_write16(hw, cap + PCI_VPD_ADDR, offset);
4062 rc = sky2_vpd_wait(hw, cap, 0);
4063 if (rc)
4064 break;
4065
4066 val = sky2_pci_read32(hw, cap + PCI_VPD_DATA);
4067
4068 memcpy(data, &val, min(sizeof(val), length));
4069 offset += sizeof(u32);
4070 data += sizeof(u32);
4071 length -= sizeof(u32);
4072 }
4073
4074 return rc;
4075}
4076
4077static int sky2_vpd_write(struct sky2_hw *hw, int cap, const void *data,
4078 u16 offset, unsigned int length)
4079{
4080 unsigned int i;
4081 int rc = 0;
4082
4083 for (i = 0; i < length; i += sizeof(u32)) {
4084 u32 val = *(u32 *)(data + i);
4085
4086 sky2_pci_write32(hw, cap + PCI_VPD_DATA, val);
4087 sky2_pci_write32(hw, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F);
4088
4089 rc = sky2_vpd_wait(hw, cap, PCI_VPD_ADDR_F);
4090 if (rc)
4091 break;
4092 }
4093 return rc;
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004094}
4095
4096static int sky2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
4097 u8 *data)
4098{
4099 struct sky2_port *sky2 = netdev_priv(dev);
4100 int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD);
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004101
4102 if (!cap)
4103 return -EINVAL;
4104
4105 eeprom->magic = SKY2_EEPROM_MAGIC;
4106
Stephen Hemminger14132352008-08-27 20:46:26 -07004107 return sky2_vpd_read(sky2->hw, cap, data, eeprom->offset, eeprom->len);
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004108}
4109
4110static int sky2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
4111 u8 *data)
4112{
4113 struct sky2_port *sky2 = netdev_priv(dev);
4114 int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD);
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004115
4116 if (!cap)
4117 return -EINVAL;
4118
4119 if (eeprom->magic != SKY2_EEPROM_MAGIC)
4120 return -EINVAL;
4121
Stephen Hemminger14132352008-08-27 20:46:26 -07004122 /* Partial writes not supported */
4123 if ((eeprom->offset & 3) || (eeprom->len & 3))
4124 return -EINVAL;
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004125
Stephen Hemminger14132352008-08-27 20:46:26 -07004126 return sky2_vpd_write(sky2->hw, cap, data, eeprom->offset, eeprom->len);
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004127}
4128
4129
Jeff Garzik7282d492006-09-13 14:30:00 -04004130static const struct ethtool_ops sky2_ethtool_ops = {
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004131 .get_settings = sky2_get_settings,
4132 .set_settings = sky2_set_settings,
4133 .get_drvinfo = sky2_get_drvinfo,
4134 .get_wol = sky2_get_wol,
4135 .set_wol = sky2_set_wol,
4136 .get_msglevel = sky2_get_msglevel,
4137 .set_msglevel = sky2_set_msglevel,
4138 .nway_reset = sky2_nway_reset,
4139 .get_regs_len = sky2_get_regs_len,
4140 .get_regs = sky2_get_regs,
4141 .get_link = ethtool_op_get_link,
4142 .get_eeprom_len = sky2_get_eeprom_len,
4143 .get_eeprom = sky2_get_eeprom,
4144 .set_eeprom = sky2_set_eeprom,
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004145 .set_sg = ethtool_op_set_sg,
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004146 .set_tx_csum = sky2_set_tx_csum,
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004147 .set_tso = sky2_set_tso,
4148 .get_rx_csum = sky2_get_rx_csum,
4149 .set_rx_csum = sky2_set_rx_csum,
4150 .get_strings = sky2_get_strings,
4151 .get_coalesce = sky2_get_coalesce,
4152 .set_coalesce = sky2_set_coalesce,
4153 .get_ringparam = sky2_get_ringparam,
4154 .set_ringparam = sky2_set_ringparam,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004155 .get_pauseparam = sky2_get_pauseparam,
4156 .set_pauseparam = sky2_set_pauseparam,
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004157 .phys_id = sky2_phys_id,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004158 .get_sset_count = sky2_get_sset_count,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004159 .get_ethtool_stats = sky2_get_ethtool_stats,
4160};
4161
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004162#ifdef CONFIG_SKY2_DEBUG
4163
4164static struct dentry *sky2_debug;
4165
Stephen Hemmingere4c2abe2009-02-03 11:27:29 +00004166
4167/*
4168 * Read and parse the first part of Vital Product Data
4169 */
4170#define VPD_SIZE 128
4171#define VPD_MAGIC 0x82
4172
4173static const struct vpd_tag {
4174 char tag[2];
4175 char *label;
4176} vpd_tags[] = {
4177 { "PN", "Part Number" },
4178 { "EC", "Engineering Level" },
4179 { "MN", "Manufacturer" },
4180 { "SN", "Serial Number" },
4181 { "YA", "Asset Tag" },
4182 { "VL", "First Error Log Message" },
4183 { "VF", "Second Error Log Message" },
4184 { "VB", "Boot Agent ROM Configuration" },
4185 { "VE", "EFI UNDI Configuration" },
4186};
4187
4188static void sky2_show_vpd(struct seq_file *seq, struct sky2_hw *hw)
4189{
4190 size_t vpd_size;
4191 loff_t offs;
4192 u8 len;
4193 unsigned char *buf;
4194 u16 reg2;
4195
4196 reg2 = sky2_pci_read16(hw, PCI_DEV_REG2);
4197 vpd_size = 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
4198
4199 seq_printf(seq, "%s Product Data\n", pci_name(hw->pdev));
4200 buf = kmalloc(vpd_size, GFP_KERNEL);
4201 if (!buf) {
4202 seq_puts(seq, "no memory!\n");
4203 return;
4204 }
4205
4206 if (pci_read_vpd(hw->pdev, 0, vpd_size, buf) < 0) {
4207 seq_puts(seq, "VPD read failed\n");
4208 goto out;
4209 }
4210
4211 if (buf[0] != VPD_MAGIC) {
4212 seq_printf(seq, "VPD tag mismatch: %#x\n", buf[0]);
4213 goto out;
4214 }
4215 len = buf[1];
4216 if (len == 0 || len > vpd_size - 4) {
4217 seq_printf(seq, "Invalid id length: %d\n", len);
4218 goto out;
4219 }
4220
4221 seq_printf(seq, "%.*s\n", len, buf + 3);
4222 offs = len + 3;
4223
4224 while (offs < vpd_size - 4) {
4225 int i;
4226
4227 if (!memcmp("RW", buf + offs, 2)) /* end marker */
4228 break;
4229 len = buf[offs + 2];
4230 if (offs + len + 3 >= vpd_size)
4231 break;
4232
4233 for (i = 0; i < ARRAY_SIZE(vpd_tags); i++) {
4234 if (!memcmp(vpd_tags[i].tag, buf + offs, 2)) {
4235 seq_printf(seq, " %s: %.*s\n",
4236 vpd_tags[i].label, len, buf + offs + 3);
4237 break;
4238 }
4239 }
4240 offs += len + 3;
4241 }
4242out:
4243 kfree(buf);
4244}
4245
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004246static int sky2_debug_show(struct seq_file *seq, void *v)
4247{
4248 struct net_device *dev = seq->private;
4249 const struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004250 struct sky2_hw *hw = sky2->hw;
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004251 unsigned port = sky2->port;
4252 unsigned idx, last;
4253 int sop;
4254
Stephen Hemmingere4c2abe2009-02-03 11:27:29 +00004255 sky2_show_vpd(seq, hw);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004256
Stephen Hemmingere4c2abe2009-02-03 11:27:29 +00004257 seq_printf(seq, "\nIRQ src=%x mask=%x control=%x\n",
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004258 sky2_read32(hw, B0_ISRC),
4259 sky2_read32(hw, B0_IMSK),
4260 sky2_read32(hw, B0_Y2_SP_ICR));
4261
Stephen Hemmingere4c2abe2009-02-03 11:27:29 +00004262 if (!netif_running(dev)) {
4263 seq_printf(seq, "network not running\n");
4264 return 0;
4265 }
4266
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004267 napi_disable(&hw->napi);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004268 last = sky2_read16(hw, STAT_PUT_IDX);
4269
4270 if (hw->st_idx == last)
4271 seq_puts(seq, "Status ring (empty)\n");
4272 else {
4273 seq_puts(seq, "Status ring\n");
4274 for (idx = hw->st_idx; idx != last && idx < STATUS_RING_SIZE;
4275 idx = RING_NEXT(idx, STATUS_RING_SIZE)) {
4276 const struct sky2_status_le *le = hw->st_le + idx;
4277 seq_printf(seq, "[%d] %#x %d %#x\n",
4278 idx, le->opcode, le->length, le->status);
4279 }
4280 seq_puts(seq, "\n");
4281 }
4282
4283 seq_printf(seq, "Tx ring pending=%u...%u report=%d done=%d\n",
4284 sky2->tx_cons, sky2->tx_prod,
4285 sky2_read16(hw, port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX),
4286 sky2_read16(hw, Q_ADDR(txqaddr[port], Q_DONE)));
4287
4288 /* Dump contents of tx ring */
4289 sop = 1;
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00004290 for (idx = sky2->tx_next; idx != sky2->tx_prod && idx < sky2->tx_ring_size;
4291 idx = RING_NEXT(idx, sky2->tx_ring_size)) {
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004292 const struct sky2_tx_le *le = sky2->tx_le + idx;
4293 u32 a = le32_to_cpu(le->addr);
4294
4295 if (sop)
4296 seq_printf(seq, "%u:", idx);
4297 sop = 0;
4298
4299 switch(le->opcode & ~HW_OWNER) {
4300 case OP_ADDR64:
4301 seq_printf(seq, " %#x:", a);
4302 break;
4303 case OP_LRGLEN:
4304 seq_printf(seq, " mtu=%d", a);
4305 break;
4306 case OP_VLAN:
4307 seq_printf(seq, " vlan=%d", be16_to_cpu(le->length));
4308 break;
4309 case OP_TCPLISW:
4310 seq_printf(seq, " csum=%#x", a);
4311 break;
4312 case OP_LARGESEND:
4313 seq_printf(seq, " tso=%#x(%d)", a, le16_to_cpu(le->length));
4314 break;
4315 case OP_PACKET:
4316 seq_printf(seq, " %#x(%d)", a, le16_to_cpu(le->length));
4317 break;
4318 case OP_BUFFER:
4319 seq_printf(seq, " frag=%#x(%d)", a, le16_to_cpu(le->length));
4320 break;
4321 default:
4322 seq_printf(seq, " op=%#x,%#x(%d)", le->opcode,
4323 a, le16_to_cpu(le->length));
4324 }
4325
4326 if (le->ctrl & EOP) {
4327 seq_putc(seq, '\n');
4328 sop = 1;
4329 }
4330 }
4331
4332 seq_printf(seq, "\nRx ring hw get=%d put=%d last=%d\n",
4333 sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_GET_IDX)),
Mike McCormackc409c342009-07-21 14:51:20 +00004334 sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_PUT_IDX)),
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004335 sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_LAST_IDX)));
4336
David S. Millerd1d08d12008-01-07 20:53:33 -08004337 sky2_read32(hw, B0_Y2_SP_LISR);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004338 napi_enable(&hw->napi);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004339 return 0;
4340}
4341
4342static int sky2_debug_open(struct inode *inode, struct file *file)
4343{
4344 return single_open(file, sky2_debug_show, inode->i_private);
4345}
4346
4347static const struct file_operations sky2_debug_fops = {
4348 .owner = THIS_MODULE,
4349 .open = sky2_debug_open,
4350 .read = seq_read,
4351 .llseek = seq_lseek,
4352 .release = single_release,
4353};
4354
4355/*
4356 * Use network device events to create/remove/rename
4357 * debugfs file entries
4358 */
4359static int sky2_device_event(struct notifier_block *unused,
4360 unsigned long event, void *ptr)
4361{
4362 struct net_device *dev = ptr;
Stephen Hemminger5b296bc2007-08-29 12:58:11 -07004363 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004364
Stephen Hemminger1436b302008-11-19 21:59:54 -08004365 if (dev->netdev_ops->ndo_open != sky2_up || !sky2_debug)
Stephen Hemminger5b296bc2007-08-29 12:58:11 -07004366 return NOTIFY_DONE;
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004367
Stephen Hemminger5b296bc2007-08-29 12:58:11 -07004368 switch(event) {
4369 case NETDEV_CHANGENAME:
4370 if (sky2->debugfs) {
4371 sky2->debugfs = debugfs_rename(sky2_debug, sky2->debugfs,
4372 sky2_debug, dev->name);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004373 }
Stephen Hemminger5b296bc2007-08-29 12:58:11 -07004374 break;
4375
4376 case NETDEV_GOING_DOWN:
4377 if (sky2->debugfs) {
4378 printk(KERN_DEBUG PFX "%s: remove debugfs\n",
4379 dev->name);
4380 debugfs_remove(sky2->debugfs);
4381 sky2->debugfs = NULL;
4382 }
4383 break;
4384
4385 case NETDEV_UP:
4386 sky2->debugfs = debugfs_create_file(dev->name, S_IRUGO,
4387 sky2_debug, dev,
4388 &sky2_debug_fops);
4389 if (IS_ERR(sky2->debugfs))
4390 sky2->debugfs = NULL;
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004391 }
4392
4393 return NOTIFY_DONE;
4394}
4395
4396static struct notifier_block sky2_notifier = {
4397 .notifier_call = sky2_device_event,
4398};
4399
4400
4401static __init void sky2_debug_init(void)
4402{
4403 struct dentry *ent;
4404
4405 ent = debugfs_create_dir("sky2", NULL);
4406 if (!ent || IS_ERR(ent))
4407 return;
4408
4409 sky2_debug = ent;
4410 register_netdevice_notifier(&sky2_notifier);
4411}
4412
4413static __exit void sky2_debug_cleanup(void)
4414{
4415 if (sky2_debug) {
4416 unregister_netdevice_notifier(&sky2_notifier);
4417 debugfs_remove(sky2_debug);
4418 sky2_debug = NULL;
4419 }
4420}
4421
4422#else
4423#define sky2_debug_init()
4424#define sky2_debug_cleanup()
4425#endif
4426
Stephen Hemminger1436b302008-11-19 21:59:54 -08004427/* Two copies of network device operations to handle special case of
4428 not allowing netpoll on second port */
4429static const struct net_device_ops sky2_netdev_ops[2] = {
4430 {
4431 .ndo_open = sky2_up,
4432 .ndo_stop = sky2_down,
Stephen Hemminger00829822008-11-20 20:14:53 -08004433 .ndo_start_xmit = sky2_xmit_frame,
Stephen Hemminger1436b302008-11-19 21:59:54 -08004434 .ndo_do_ioctl = sky2_ioctl,
4435 .ndo_validate_addr = eth_validate_addr,
4436 .ndo_set_mac_address = sky2_set_mac_address,
4437 .ndo_set_multicast_list = sky2_set_multicast,
4438 .ndo_change_mtu = sky2_change_mtu,
4439 .ndo_tx_timeout = sky2_tx_timeout,
4440#ifdef SKY2_VLAN_TAG_USED
4441 .ndo_vlan_rx_register = sky2_vlan_rx_register,
4442#endif
4443#ifdef CONFIG_NET_POLL_CONTROLLER
4444 .ndo_poll_controller = sky2_netpoll,
4445#endif
4446 },
4447 {
4448 .ndo_open = sky2_up,
4449 .ndo_stop = sky2_down,
Stephen Hemminger00829822008-11-20 20:14:53 -08004450 .ndo_start_xmit = sky2_xmit_frame,
Stephen Hemminger1436b302008-11-19 21:59:54 -08004451 .ndo_do_ioctl = sky2_ioctl,
4452 .ndo_validate_addr = eth_validate_addr,
4453 .ndo_set_mac_address = sky2_set_mac_address,
4454 .ndo_set_multicast_list = sky2_set_multicast,
4455 .ndo_change_mtu = sky2_change_mtu,
4456 .ndo_tx_timeout = sky2_tx_timeout,
4457#ifdef SKY2_VLAN_TAG_USED
4458 .ndo_vlan_rx_register = sky2_vlan_rx_register,
4459#endif
4460 },
4461};
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004462
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004463/* Initialize network device */
4464static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
Stephen Hemmingere3173832007-02-06 10:45:39 -08004465 unsigned port,
Stephen Hemmingerbe63a212008-01-15 11:29:29 -08004466 int highmem, int wol)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004467{
4468 struct sky2_port *sky2;
4469 struct net_device *dev = alloc_etherdev(sizeof(*sky2));
4470
4471 if (!dev) {
Joe Perches898eb712007-10-18 03:06:30 -07004472 dev_err(&hw->pdev->dev, "etherdev alloc failed\n");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004473 return NULL;
4474 }
4475
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004476 SET_NETDEV_DEV(dev, &hw->pdev->dev);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08004477 dev->irq = hw->pdev->irq;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004478 SET_ETHTOOL_OPS(dev, &sky2_ethtool_ops);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004479 dev->watchdog_timeo = TX_WATCHDOG;
Stephen Hemminger1436b302008-11-19 21:59:54 -08004480 dev->netdev_ops = &sky2_netdev_ops[port];
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004481
4482 sky2 = netdev_priv(dev);
4483 sky2->netdev = dev;
4484 sky2->hw = hw;
4485 sky2->msg_enable = netif_msg_init(debug, default_msg);
4486
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004487 /* Auto speed and flow control */
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07004488 sky2->flags = SKY2_FLAG_AUTO_SPEED | SKY2_FLAG_AUTO_PAUSE;
4489 if (hw->chip_id != CHIP_ID_YUKON_XL)
4490 sky2->flags |= SKY2_FLAG_RX_CHECKSUM;
4491
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07004492 sky2->flow_mode = FC_BOTH;
4493
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004494 sky2->duplex = -1;
4495 sky2->speed = -1;
4496 sky2->advertising = sky2_supported_modes(hw);
Stephen Hemmingerbe63a212008-01-15 11:29:29 -08004497 sky2->wol = wol;
Stephen Hemminger75d070c2005-12-09 11:35:11 -08004498
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08004499 spin_lock_init(&sky2->phy_lock);
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00004500
Stephen Hemminger793b8832005-09-14 16:06:14 -07004501 sky2->tx_pending = TX_DEF_PENDING;
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00004502 sky2->tx_ring_size = roundup_pow_of_two(TX_DEF_PENDING+1);
Stephen Hemminger290d4de2006-03-20 15:48:15 -08004503 sky2->rx_pending = RX_DEF_PENDING;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004504
4505 hw->dev[port] = dev;
4506
4507 sky2->port = port;
4508
Stephen Hemminger4a50a872007-02-06 10:45:41 -08004509 dev->features |= NETIF_F_TSO | NETIF_F_IP_CSUM | NETIF_F_SG;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004510 if (highmem)
4511 dev->features |= NETIF_F_HIGHDMA;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004512
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07004513#ifdef SKY2_VLAN_TAG_USED
Stephen Hemmingerd6c9bc12007-09-27 12:32:44 -07004514 /* The workaround for FE+ status conflicts with VLAN tag detection. */
4515 if (!(sky2->hw->chip_id == CHIP_ID_YUKON_FE_P &&
4516 sky2->hw->chip_rev == CHIP_REV_YU_FE2_A0)) {
4517 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
Stephen Hemmingerd6c9bc12007-09-27 12:32:44 -07004518 }
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07004519#endif
4520
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004521 /* read the mac address */
Stephen Hemminger793b8832005-09-14 16:06:14 -07004522 memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8, ETH_ALEN);
Stephen Hemminger2995bfb72005-09-28 10:01:03 -07004523 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004524
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004525 return dev;
4526}
4527
Stephen Hemminger28bd1812006-01-17 13:43:19 -08004528static void __devinit sky2_show_addr(struct net_device *dev)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004529{
4530 const struct sky2_port *sky2 = netdev_priv(dev);
4531
4532 if (netif_msg_probe(sky2))
Johannes Berge1749612008-10-27 15:59:26 -07004533 printk(KERN_INFO PFX "%s: addr %pM\n",
4534 dev->name, dev->dev_addr);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004535}
4536
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004537/* Handle software interrupt used during MSI test */
David Howells7d12e782006-10-05 14:55:46 +01004538static irqreturn_t __devinit sky2_test_intr(int irq, void *dev_id)
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004539{
4540 struct sky2_hw *hw = dev_id;
4541 u32 status = sky2_read32(hw, B0_Y2_SP_ISRC2);
4542
4543 if (status == 0)
4544 return IRQ_NONE;
4545
4546 if (status & Y2_IS_IRQ_SW) {
Stephen Hemmingerea76e632007-09-19 15:36:44 -07004547 hw->flags |= SKY2_HW_USE_MSI;
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004548 wake_up(&hw->msi_wait);
4549 sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ);
4550 }
4551 sky2_write32(hw, B0_Y2_SP_ICR, 2);
4552
4553 return IRQ_HANDLED;
4554}
4555
4556/* Test interrupt path by forcing a a software IRQ */
4557static int __devinit sky2_test_msi(struct sky2_hw *hw)
4558{
4559 struct pci_dev *pdev = hw->pdev;
4560 int err;
4561
shemminger@osdl.orgbb507fe2006-08-28 10:00:48 -07004562 init_waitqueue_head (&hw->msi_wait);
4563
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004564 sky2_write32(hw, B0_IMSK, Y2_IS_IRQ_SW);
4565
Stephen Hemmingerb0a20de2006-12-01 14:29:37 -08004566 err = request_irq(pdev->irq, sky2_test_intr, 0, DRV_NAME, hw);
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004567 if (err) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004568 dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq);
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004569 return err;
4570 }
4571
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004572 sky2_write8(hw, B0_CTST, CS_ST_SW_IRQ);
shemminger@osdl.orgbb507fe2006-08-28 10:00:48 -07004573 sky2_read8(hw, B0_CTST);
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004574
Stephen Hemmingerea76e632007-09-19 15:36:44 -07004575 wait_event_timeout(hw->msi_wait, (hw->flags & SKY2_HW_USE_MSI), HZ/10);
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004576
Stephen Hemmingerea76e632007-09-19 15:36:44 -07004577 if (!(hw->flags & SKY2_HW_USE_MSI)) {
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004578 /* MSI test failed, go back to INTx mode */
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004579 dev_info(&pdev->dev, "No interrupt generated using MSI, "
4580 "switching to INTx mode.\n");
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004581
4582 err = -EOPNOTSUPP;
4583 sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ);
4584 }
4585
4586 sky2_write32(hw, B0_IMSK, 0);
Stephen Hemminger2bffc232006-10-17 10:17:18 -07004587 sky2_read32(hw, B0_IMSK);
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004588
4589 free_irq(pdev->irq, hw);
4590
4591 return err;
4592}
4593
Stephen Hemmingerc7127a32008-06-17 09:04:25 -07004594/* This driver supports yukon2 chipset only */
4595static const char *sky2_name(u8 chipid, char *buf, int sz)
4596{
4597 const char *name[] = {
4598 "XL", /* 0xb3 */
4599 "EC Ultra", /* 0xb4 */
4600 "Extreme", /* 0xb5 */
4601 "EC", /* 0xb6 */
4602 "FE", /* 0xb7 */
4603 "FE+", /* 0xb8 */
4604 "Supreme", /* 0xb9 */
Stephen Hemminger0ce8b982008-06-17 09:04:27 -07004605 "UL 2", /* 0xba */
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00004606 "Unknown", /* 0xbb */
4607 "Optima", /* 0xbc */
Stephen Hemmingerc7127a32008-06-17 09:04:25 -07004608 };
4609
stephen hemmingerdae3a512009-12-14 08:33:47 +00004610 if (chipid >= CHIP_ID_YUKON_XL && chipid <= CHIP_ID_YUKON_OPT)
Stephen Hemmingerc7127a32008-06-17 09:04:25 -07004611 strncpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz);
4612 else
4613 snprintf(buf, sz, "(chip %#x)", chipid);
4614 return buf;
4615}
4616
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004617static int __devinit sky2_probe(struct pci_dev *pdev,
4618 const struct pci_device_id *ent)
4619{
shemminger@linux-foundation.org7f60c64b2007-01-26 11:38:36 -08004620 struct net_device *dev;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004621 struct sky2_hw *hw;
Stephen Hemmingerbe63a212008-01-15 11:29:29 -08004622 int err, using_dac = 0, wol_default;
Stephen Hemminger38345072009-02-03 11:27:30 +00004623 u32 reg;
Stephen Hemmingerc7127a32008-06-17 09:04:25 -07004624 char buf1[16];
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004625
Stephen Hemminger793b8832005-09-14 16:06:14 -07004626 err = pci_enable_device(pdev);
4627 if (err) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004628 dev_err(&pdev->dev, "cannot enable PCI device\n");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004629 goto err_out;
4630 }
4631
Stephen Hemminger6cc90a52009-06-11 07:03:47 +00004632 /* Get configuration information
4633 * Note: only regular PCI config access once to test for HW issues
4634 * other PCI access through shared memory for speed and to
4635 * avoid MMCONFIG problems.
4636 */
4637 err = pci_read_config_dword(pdev, PCI_DEV_REG2, &reg);
4638 if (err) {
4639 dev_err(&pdev->dev, "PCI read config failed\n");
4640 goto err_out;
4641 }
4642
4643 if (~reg == 0) {
4644 dev_err(&pdev->dev, "PCI configuration read error\n");
4645 goto err_out;
4646 }
4647
Stephen Hemminger793b8832005-09-14 16:06:14 -07004648 err = pci_request_regions(pdev, DRV_NAME);
4649 if (err) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004650 dev_err(&pdev->dev, "cannot obtain PCI resources\n");
Stephen Hemminger44a1d2e2007-04-30 14:23:49 -07004651 goto err_out_disable;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004652 }
4653
4654 pci_set_master(pdev);
4655
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08004656 if (sizeof(dma_addr_t) > sizeof(u32) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07004657 !(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)))) {
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08004658 using_dac = 1;
Yang Hongyang6a355282009-04-06 19:01:13 -07004659 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08004660 if (err < 0) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004661 dev_err(&pdev->dev, "unable to obtain 64 bit DMA "
4662 "for consistent allocations\n");
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08004663 goto err_out_free_regions;
4664 }
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08004665 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07004666 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004667 if (err) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004668 dev_err(&pdev->dev, "no usable DMA configuration\n");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004669 goto err_out_free_regions;
4670 }
4671 }
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08004672
Stephen Hemminger38345072009-02-03 11:27:30 +00004673
4674#ifdef __BIG_ENDIAN
4675 /* The sk98lin vendor driver uses hardware byte swapping but
4676 * this driver uses software swapping.
4677 */
4678 reg &= ~PCI_REV_DESC;
4679 err = pci_write_config_dword(pdev,PCI_DEV_REG2, reg);
4680 if (err) {
4681 dev_err(&pdev->dev, "PCI write config failed\n");
4682 goto err_out_free_regions;
4683 }
4684#endif
4685
Rafael J. Wysocki9d731d72008-10-12 20:59:48 -07004686 wol_default = device_may_wakeup(&pdev->dev) ? WAKE_MAGIC : 0;
Stephen Hemmingerbe63a212008-01-15 11:29:29 -08004687
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004688 err = -ENOMEM;
Stephen Hemminger66466792009-10-01 07:11:46 +00004689
4690 hw = kzalloc(sizeof(*hw) + strlen(DRV_NAME "@pci:")
4691 + strlen(pci_name(pdev)) + 1, GFP_KERNEL);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004692 if (!hw) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004693 dev_err(&pdev->dev, "cannot allocate hardware struct\n");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004694 goto err_out_free_regions;
4695 }
4696
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004697 hw->pdev = pdev;
Stephen Hemminger66466792009-10-01 07:11:46 +00004698 sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004699
4700 hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
4701 if (!hw->regs) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004702 dev_err(&pdev->dev, "cannot map device registers\n");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004703 goto err_out_free_hw;
4704 }
4705
Stephen Hemminger08c06d82006-01-30 11:37:54 -08004706 /* ring for status responses */
Stephen Hemminger167f53d2007-09-25 19:01:02 -07004707 hw->st_le = pci_alloc_consistent(pdev, STATUS_LE_BYTES, &hw->st_dma);
Stephen Hemminger08c06d82006-01-30 11:37:54 -08004708 if (!hw->st_le)
4709 goto err_out_iounmap;
4710
Stephen Hemmingere3173832007-02-06 10:45:39 -08004711 err = sky2_init(hw);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004712 if (err)
Stephen Hemminger793b8832005-09-14 16:06:14 -07004713 goto err_out_iounmap;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004714
Stephen Hemmingerc844d482008-08-27 20:48:23 -07004715 dev_info(&pdev->dev, "Yukon-2 %s chip revision %d\n",
4716 sky2_name(hw->chip_id, buf1, sizeof(buf1)), hw->chip_rev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004717
Stephen Hemmingere3173832007-02-06 10:45:39 -08004718 sky2_reset(hw);
4719
Stephen Hemmingerbe63a212008-01-15 11:29:29 -08004720 dev = sky2_init_netdev(hw, 0, using_dac, wol_default);
shemminger@linux-foundation.org7f60c64b2007-01-26 11:38:36 -08004721 if (!dev) {
4722 err = -ENOMEM;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004723 goto err_out_free_pci;
shemminger@linux-foundation.org7f60c64b2007-01-26 11:38:36 -08004724 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004725
Stephen Hemminger9fa1b1f2006-09-26 11:57:40 -07004726 if (!disable_msi && pci_enable_msi(pdev) == 0) {
4727 err = sky2_test_msi(hw);
4728 if (err == -EOPNOTSUPP)
4729 pci_disable_msi(pdev);
4730 else if (err)
4731 goto err_out_free_netdev;
4732 }
4733
Stephen Hemminger793b8832005-09-14 16:06:14 -07004734 err = register_netdev(dev);
4735 if (err) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004736 dev_err(&pdev->dev, "cannot register net device\n");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004737 goto err_out_free_netdev;
4738 }
4739
Brandon Philips33cb7d32009-10-29 13:58:07 +00004740 netif_carrier_off(dev);
4741
Stephen Hemminger6de16232007-10-17 13:26:42 -07004742 netif_napi_add(dev, &hw->napi, sky2_poll, NAPI_WEIGHT);
4743
Stephen Hemmingerea76e632007-09-19 15:36:44 -07004744 err = request_irq(pdev->irq, sky2_intr,
4745 (hw->flags & SKY2_HW_USE_MSI) ? 0 : IRQF_SHARED,
Stephen Hemminger66466792009-10-01 07:11:46 +00004746 hw->irq_name, hw);
Stephen Hemminger9fa1b1f2006-09-26 11:57:40 -07004747 if (err) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004748 dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq);
Stephen Hemminger9fa1b1f2006-09-26 11:57:40 -07004749 goto err_out_unregister;
4750 }
4751 sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
Stephen Hemminger6de16232007-10-17 13:26:42 -07004752 napi_enable(&hw->napi);
Stephen Hemminger9fa1b1f2006-09-26 11:57:40 -07004753
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004754 sky2_show_addr(dev);
4755
shemminger@linux-foundation.org7f60c64b2007-01-26 11:38:36 -08004756 if (hw->ports > 1) {
4757 struct net_device *dev1;
4758
Stephen Hemmingerca519272009-09-14 06:22:29 +00004759 err = -ENOMEM;
Stephen Hemmingerbe63a212008-01-15 11:29:29 -08004760 dev1 = sky2_init_netdev(hw, 1, using_dac, wol_default);
Stephen Hemmingerca519272009-09-14 06:22:29 +00004761 if (dev1 && (err = register_netdev(dev1)) == 0)
4762 sky2_show_addr(dev1);
4763 else {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004764 dev_warn(&pdev->dev,
4765 "register of second port failed (%d)\n", err);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004766 hw->dev[1] = NULL;
Stephen Hemmingerca519272009-09-14 06:22:29 +00004767 hw->ports = 1;
4768 if (dev1)
4769 free_netdev(dev1);
4770 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004771 }
4772
Stephen Hemminger32c2c302007-08-21 14:34:03 -07004773 setup_timer(&hw->watchdog_timer, sky2_watchdog, (unsigned long) hw);
Stephen Hemminger81906792007-02-15 16:40:33 -08004774 INIT_WORK(&hw->restart_work, sky2_restart);
4775
Stephen Hemminger793b8832005-09-14 16:06:14 -07004776 pci_set_drvdata(pdev, hw);
Rafael J. Wysocki1ae861e2009-12-31 12:15:54 +01004777 pdev->d3_delay = 150;
Stephen Hemminger793b8832005-09-14 16:06:14 -07004778
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004779 return 0;
4780
Stephen Hemminger793b8832005-09-14 16:06:14 -07004781err_out_unregister:
Stephen Hemmingerea76e632007-09-19 15:36:44 -07004782 if (hw->flags & SKY2_HW_USE_MSI)
Stephen Hemmingerb0a20de2006-12-01 14:29:37 -08004783 pci_disable_msi(pdev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07004784 unregister_netdev(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004785err_out_free_netdev:
4786 free_netdev(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004787err_out_free_pci:
Stephen Hemminger793b8832005-09-14 16:06:14 -07004788 sky2_write8(hw, B0_CTST, CS_RST_SET);
Stephen Hemminger167f53d2007-09-25 19:01:02 -07004789 pci_free_consistent(pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004790err_out_iounmap:
4791 iounmap(hw->regs);
4792err_out_free_hw:
4793 kfree(hw);
4794err_out_free_regions:
4795 pci_release_regions(pdev);
Stephen Hemminger44a1d2e2007-04-30 14:23:49 -07004796err_out_disable:
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004797 pci_disable_device(pdev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004798err_out:
Stephen Hemminger549a68c2007-05-11 11:21:44 -07004799 pci_set_drvdata(pdev, NULL);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004800 return err;
4801}
4802
4803static void __devexit sky2_remove(struct pci_dev *pdev)
4804{
Stephen Hemminger793b8832005-09-14 16:06:14 -07004805 struct sky2_hw *hw = pci_get_drvdata(pdev);
Stephen Hemminger6de16232007-10-17 13:26:42 -07004806 int i;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004807
Stephen Hemminger793b8832005-09-14 16:06:14 -07004808 if (!hw)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004809 return;
4810
Stephen Hemminger32c2c302007-08-21 14:34:03 -07004811 del_timer_sync(&hw->watchdog_timer);
Stephen Hemminger6de16232007-10-17 13:26:42 -07004812 cancel_work_sync(&hw->restart_work);
Stephen Hemmingerd27ed382006-04-25 10:58:51 -07004813
Stephen Hemmingerb877fe22007-10-22 13:39:09 -07004814 for (i = hw->ports-1; i >= 0; --i)
Stephen Hemminger6de16232007-10-17 13:26:42 -07004815 unregister_netdev(hw->dev[i]);
Stephen Hemminger81906792007-02-15 16:40:33 -08004816
Stephen Hemmingerd27ed382006-04-25 10:58:51 -07004817 sky2_write32(hw, B0_IMSK, 0);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004818
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08004819 sky2_power_aux(hw);
4820
Stephen Hemminger793b8832005-09-14 16:06:14 -07004821 sky2_write8(hw, B0_CTST, CS_RST_SET);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07004822 sky2_read8(hw, B0_CTST);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004823
4824 free_irq(pdev->irq, hw);
Stephen Hemmingerea76e632007-09-19 15:36:44 -07004825 if (hw->flags & SKY2_HW_USE_MSI)
Stephen Hemmingerb0a20de2006-12-01 14:29:37 -08004826 pci_disable_msi(pdev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07004827 pci_free_consistent(pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004828 pci_release_regions(pdev);
4829 pci_disable_device(pdev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07004830
Stephen Hemmingerb877fe22007-10-22 13:39:09 -07004831 for (i = hw->ports-1; i >= 0; --i)
Stephen Hemminger6de16232007-10-17 13:26:42 -07004832 free_netdev(hw->dev[i]);
4833
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004834 iounmap(hw->regs);
4835 kfree(hw);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07004836
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004837 pci_set_drvdata(pdev, NULL);
4838}
4839
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004840static int sky2_suspend(struct pci_dev *pdev, pm_message_t state)
4841{
Stephen Hemminger793b8832005-09-14 16:06:14 -07004842 struct sky2_hw *hw = pci_get_drvdata(pdev);
Stephen Hemmingere3173832007-02-06 10:45:39 -08004843 int i, wol = 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004844
Stephen Hemminger549a68c2007-05-11 11:21:44 -07004845 if (!hw)
4846 return 0;
4847
Stephen Hemminger063a0b32008-04-02 09:03:23 -07004848 del_timer_sync(&hw->watchdog_timer);
4849 cancel_work_sync(&hw->restart_work);
4850
Stephen Hemminger19720732009-08-14 05:15:16 +00004851 rtnl_lock();
Stephen Hemmingerf05267e2006-06-13 17:17:28 +09004852 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004853 struct net_device *dev = hw->dev[i];
Stephen Hemmingere3173832007-02-06 10:45:39 -08004854 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004855
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07004856 sky2_detach(dev);
Stephen Hemmingere3173832007-02-06 10:45:39 -08004857
4858 if (sky2->wol)
4859 sky2_wol_init(sky2);
4860
4861 wol |= sky2->wol;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004862 }
4863
stephen hemminger5f8ae5c2010-02-12 06:57:59 +00004864 device_set_wakeup_enable(&pdev->dev, wol != 0);
4865
Stephen Hemminger8ab8fca2006-06-13 17:17:30 +09004866 sky2_write32(hw, B0_IMSK, 0);
Stephen Hemminger6de16232007-10-17 13:26:42 -07004867 napi_disable(&hw->napi);
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08004868 sky2_power_aux(hw);
Stephen Hemminger19720732009-08-14 05:15:16 +00004869 rtnl_unlock();
Stephen Hemmingere3173832007-02-06 10:45:39 -08004870
Linus Torvaldsd374c1c2006-06-12 12:53:27 -07004871 pci_save_state(pdev);
Stephen Hemmingere3173832007-02-06 10:45:39 -08004872 pci_enable_wake(pdev, pci_choose_state(pdev, state), wol);
Stephen Hemmingerf71eb1a2008-08-04 13:33:37 -07004873 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08004874
Stephen Hemminger2ccc99b2006-06-13 17:17:27 +09004875 return 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004876}
4877
stephen hemminger5f8ae5c2010-02-12 06:57:59 +00004878#ifdef CONFIG_PM
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004879static int sky2_resume(struct pci_dev *pdev)
4880{
Stephen Hemminger793b8832005-09-14 16:06:14 -07004881 struct sky2_hw *hw = pci_get_drvdata(pdev);
Stephen Hemminger08c06d82006-01-30 11:37:54 -08004882 int i, err;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004883
Stephen Hemminger549a68c2007-05-11 11:21:44 -07004884 if (!hw)
4885 return 0;
4886
Stephen Hemmingerf71eb1a2008-08-04 13:33:37 -07004887 err = pci_set_power_state(pdev, PCI_D0);
4888 if (err)
4889 goto out;
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08004890
4891 err = pci_restore_state(pdev);
4892 if (err)
4893 goto out;
4894
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004895 pci_enable_wake(pdev, PCI_D0, 0);
Stephen Hemminger1ad5b4a2007-04-07 16:02:27 -07004896
4897 /* Re-enable all clocks */
stephen hemmingera0db28b2010-02-07 06:23:53 +00004898 err = pci_write_config_dword(pdev, PCI_DEV_REG3, 0);
4899 if (err) {
4900 dev_err(&pdev->dev, "PCI write config failed\n");
4901 goto out;
4902 }
Stephen Hemminger1ad5b4a2007-04-07 16:02:27 -07004903
Stephen Hemmingere3173832007-02-06 10:45:39 -08004904 sky2_reset(hw);
Stephen Hemminger8ab8fca2006-06-13 17:17:30 +09004905 sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
Stephen Hemminger6de16232007-10-17 13:26:42 -07004906 napi_enable(&hw->napi);
Stephen Hemminger8ab8fca2006-06-13 17:17:30 +09004907
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07004908 rtnl_lock();
Stephen Hemmingerf05267e2006-06-13 17:17:28 +09004909 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07004910 err = sky2_reattach(hw->dev[i]);
4911 if (err)
4912 goto out;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004913 }
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07004914 rtnl_unlock();
Stephen Hemmingereb35cf62006-06-13 17:17:31 +09004915
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08004916 return 0;
Stephen Hemminger08c06d82006-01-30 11:37:54 -08004917out:
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07004918 rtnl_unlock();
4919
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004920 dev_err(&pdev->dev, "resume failed (%d)\n", err);
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08004921 pci_disable_device(pdev);
Stephen Hemminger08c06d82006-01-30 11:37:54 -08004922 return err;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004923}
4924#endif
4925
Stephen Hemmingere3173832007-02-06 10:45:39 -08004926static void sky2_shutdown(struct pci_dev *pdev)
4927{
stephen hemminger5f8ae5c2010-02-12 06:57:59 +00004928 sky2_suspend(pdev, PMSG_SUSPEND);
Stephen Hemmingere3173832007-02-06 10:45:39 -08004929}
4930
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004931static struct pci_driver sky2_driver = {
Stephen Hemminger793b8832005-09-14 16:06:14 -07004932 .name = DRV_NAME,
4933 .id_table = sky2_id_table,
4934 .probe = sky2_probe,
4935 .remove = __devexit_p(sky2_remove),
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004936#ifdef CONFIG_PM
Stephen Hemminger793b8832005-09-14 16:06:14 -07004937 .suspend = sky2_suspend,
4938 .resume = sky2_resume,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004939#endif
Stephen Hemmingere3173832007-02-06 10:45:39 -08004940 .shutdown = sky2_shutdown,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004941};
4942
4943static int __init sky2_init_module(void)
4944{
Stephen Hemmingerc844d482008-08-27 20:48:23 -07004945 pr_info(PFX "driver version " DRV_VERSION "\n");
4946
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004947 sky2_debug_init();
shemminger@osdl.org50241c42005-11-30 11:45:22 -08004948 return pci_register_driver(&sky2_driver);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004949}
4950
4951static void __exit sky2_cleanup_module(void)
4952{
4953 pci_unregister_driver(&sky2_driver);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004954 sky2_debug_cleanup();
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004955}
4956
4957module_init(sky2_init_module);
4958module_exit(sky2_cleanup_module);
4959
4960MODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver");
Stephen Hemminger65ebe6342007-01-23 11:38:57 -08004961MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004962MODULE_LICENSE("GPL");
shemminger@osdl.org5f4f9dc2005-11-30 11:45:23 -08004963MODULE_VERSION(DRV_VERSION);