blob: 02d0b42e436ce61e13fc0309f46471f77a190b04 [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 Hemmingerac9581542009-10-29 06:37:10 +000053#define DRV_VERSION "1.26"
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
254 /* Enable workaround for dev 4.107 on Yukon-Ultra & Extreme */
255 reg = sky2_read32(hw, B2_GP_IO);
256 reg |= GLB_GPIO_STAT_RACE_DIS;
257 sky2_write32(hw, B2_GP_IO, reg);
Stephen Hemmingerb2345772007-08-21 14:34:02 -0700258
259 sky2_read32(hw, B2_GP_IO);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700260 }
Stephen Hemminger10547ae2009-08-31 07:31:41 +0000261
262 /* Turn on "driver loaded" LED */
263 sky2_write16(hw, B0_CTST, Y2_LED_STAT_ON);
Stephen Hemmingerae306cc2006-12-20 13:06:36 -0800264}
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700265
Stephen Hemmingerae306cc2006-12-20 13:06:36 -0800266static void sky2_power_aux(struct sky2_hw *hw)
267{
268 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
269 sky2_write8(hw, B2_Y2_CLK_GATE, 0);
270 else
271 /* enable bits are inverted */
272 sky2_write8(hw, B2_Y2_CLK_GATE,
273 Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
274 Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
275 Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
276
Stephen Hemmingerc23ddf82009-09-03 06:16:25 +0000277 /* switch power to VAUX if supported and PME from D3cold */
278 if ( (sky2_read32(hw, B0_CTST) & Y2_VAUX_AVAIL) &&
279 pci_pme_capable(hw->pdev, PCI_D3cold))
Stephen Hemmingerae306cc2006-12-20 13:06:36 -0800280 sky2_write8(hw, B0_POWER_CTRL,
281 (PC_VAUX_ENA | PC_VCC_ENA |
282 PC_VAUX_ON | PC_VCC_OFF));
Stephen Hemminger10547ae2009-08-31 07:31:41 +0000283
284 /* turn off "driver loaded LED" */
285 sky2_write16(hw, B0_CTST, Y2_LED_STAT_OFF);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -0700286}
287
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -0700288static void sky2_gmac_reset(struct sky2_hw *hw, unsigned port)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700289{
290 u16 reg;
291
292 /* disable all GMAC IRQ's */
293 sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700294
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700295 gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */
296 gma_write16(hw, port, GM_MC_ADDR_H2, 0);
297 gma_write16(hw, port, GM_MC_ADDR_H3, 0);
298 gma_write16(hw, port, GM_MC_ADDR_H4, 0);
299
300 reg = gma_read16(hw, port, GM_RX_CTRL);
301 reg |= GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA;
302 gma_write16(hw, port, GM_RX_CTRL, reg);
303}
304
Stephen Hemminger16ad91e2006-10-17 10:24:13 -0700305/* flow control to advertise bits */
306static const u16 copper_fc_adv[] = {
307 [FC_NONE] = 0,
308 [FC_TX] = PHY_M_AN_ASP,
309 [FC_RX] = PHY_M_AN_PC,
310 [FC_BOTH] = PHY_M_AN_PC | PHY_M_AN_ASP,
311};
312
313/* flow control to advertise bits when using 1000BaseX */
314static const u16 fiber_fc_adv[] = {
Stephen Hemmingerdf3fe1f2007-10-11 19:48:04 -0700315 [FC_NONE] = PHY_M_P_NO_PAUSE_X,
Stephen Hemminger16ad91e2006-10-17 10:24:13 -0700316 [FC_TX] = PHY_M_P_ASYM_MD_X,
317 [FC_RX] = PHY_M_P_SYM_MD_X,
Stephen Hemmingerdf3fe1f2007-10-11 19:48:04 -0700318 [FC_BOTH] = PHY_M_P_BOTH_MD_X,
Stephen Hemminger16ad91e2006-10-17 10:24:13 -0700319};
320
321/* flow control to GMA disable bits */
322static const u16 gm_fc_disable[] = {
323 [FC_NONE] = GM_GPCR_FC_RX_DIS | GM_GPCR_FC_TX_DIS,
324 [FC_TX] = GM_GPCR_FC_RX_DIS,
325 [FC_RX] = GM_GPCR_FC_TX_DIS,
326 [FC_BOTH] = 0,
327};
328
329
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700330static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
331{
332 struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700333 u16 ctrl, ct1000, adv, pg, ledctrl, ledover, reg;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700334
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700335 if ( (sky2->flags & SKY2_FLAG_AUTO_SPEED) &&
Stephen Hemmingerea76e632007-09-19 15:36:44 -0700336 !(hw->flags & SKY2_HW_NEWER_PHY)) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700337 u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
338
339 ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
Stephen Hemminger793b8832005-09-14 16:06:14 -0700340 PHY_M_EC_MAC_S_MSK);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700341 ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ);
342
Stephen Hemminger53419c62007-05-14 12:38:11 -0700343 /* on PHY 88E1040 Rev.D0 (and newer) downshift control changed */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700344 if (hw->chip_id == CHIP_ID_YUKON_EC)
Stephen Hemminger53419c62007-05-14 12:38:11 -0700345 /* set downshift counter to 3x and enable downshift */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700346 ectrl |= PHY_M_EC_DSC_2(2) | PHY_M_EC_DOWN_S_ENA;
347 else
Stephen Hemminger53419c62007-05-14 12:38:11 -0700348 /* set master & slave downshift counter to 1x */
349 ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700350
351 gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl);
352 }
353
354 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700355 if (sky2_is_copper(hw)) {
Stephen Hemminger05745c42007-09-19 15:36:45 -0700356 if (!(hw->flags & SKY2_HW_GIGABIT)) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700357 /* enable automatic crossover */
358 ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO) >> 1;
Stephen Hemminger6d3105d2007-09-24 19:34:51 -0700359
360 if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
361 hw->chip_rev == CHIP_REV_YU_FE2_A0) {
362 u16 spec;
363
364 /* Enable Class A driver for FE+ A0 */
365 spec = gm_phy_read(hw, port, PHY_MARV_FE_SPEC_2);
366 spec |= PHY_M_FESC_SEL_CL_A;
367 gm_phy_write(hw, port, PHY_MARV_FE_SPEC_2, spec);
368 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700369 } else {
370 /* disable energy detect */
371 ctrl &= ~PHY_M_PC_EN_DET_MSK;
372
373 /* enable automatic crossover */
374 ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO);
375
Stephen Hemminger53419c62007-05-14 12:38:11 -0700376 /* downshift on PHY 88E1112 and 88E1149 is changed */
Joe Perches8e95a202009-12-03 07:58:21 +0000377 if ( (sky2->flags & SKY2_FLAG_AUTO_SPEED) &&
378 (hw->flags & SKY2_HW_NEWER_PHY)) {
Stephen Hemminger53419c62007-05-14 12:38:11 -0700379 /* set downshift counter to 3x and enable downshift */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700380 ctrl &= ~PHY_M_PC_DSC_MSK;
381 ctrl |= PHY_M_PC_DSC(2) | PHY_M_PC_DOWN_S_ENA;
382 }
383 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700384 } else {
385 /* workaround for deviation #4.88 (CRC errors) */
386 /* disable Automatic Crossover */
387
388 ctrl &= ~PHY_M_PC_MDIX_MSK;
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700389 }
390
391 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
392
393 /* special setup for PHY 88E1112 Fiber */
Stephen Hemmingerea76e632007-09-19 15:36:44 -0700394 if (hw->chip_id == CHIP_ID_YUKON_XL && (hw->flags & SKY2_HW_FIBRE_PHY)) {
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700395 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
396
397 /* Fiber: select 1000BASE-X only mode MAC Specific Ctrl Reg. */
398 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2);
399 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
400 ctrl &= ~PHY_M_MAC_MD_MSK;
401 ctrl |= PHY_M_MAC_MODE_SEL(PHY_M_MAC_MD_1000BX);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700402 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
403
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700404 if (hw->pmd_type == 'P') {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700405 /* select page 1 to access Fiber registers */
406 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 1);
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700407
408 /* for SFP-module set SIGDET polarity to low */
409 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
410 ctrl |= PHY_M_FIB_SIGD_POL;
Stephen Hemminger34dd9622007-05-24 15:22:45 -0700411 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700412 }
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700413
414 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700415 }
416
Stephen Hemminger7800fdd2006-10-17 10:24:10 -0700417 ctrl = PHY_CT_RESET;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700418 ct1000 = 0;
419 adv = PHY_AN_CSMA;
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700420 reg = 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700421
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700422 if (sky2->flags & SKY2_FLAG_AUTO_SPEED) {
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700423 if (sky2_is_copper(hw)) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700424 if (sky2->advertising & ADVERTISED_1000baseT_Full)
425 ct1000 |= PHY_M_1000C_AFD;
426 if (sky2->advertising & ADVERTISED_1000baseT_Half)
427 ct1000 |= PHY_M_1000C_AHD;
428 if (sky2->advertising & ADVERTISED_100baseT_Full)
429 adv |= PHY_M_AN_100_FD;
430 if (sky2->advertising & ADVERTISED_100baseT_Half)
431 adv |= PHY_M_AN_100_HD;
432 if (sky2->advertising & ADVERTISED_10baseT_Full)
433 adv |= PHY_M_AN_10_FD;
434 if (sky2->advertising & ADVERTISED_10baseT_Half)
435 adv |= PHY_M_AN_10_HD;
Stephen Hemminger709c6e72006-10-17 10:24:04 -0700436
Stephen Hemmingerb89165f2006-09-06 12:44:53 -0700437 } else { /* special defines for FIBER (88E1040S only) */
438 if (sky2->advertising & ADVERTISED_1000baseT_Full)
439 adv |= PHY_M_AN_1000X_AFD;
440 if (sky2->advertising & ADVERTISED_1000baseT_Half)
441 adv |= PHY_M_AN_1000X_AHD;
Stephen Hemminger709c6e72006-10-17 10:24:04 -0700442 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700443
444 /* Restart Auto-negotiation */
445 ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG;
446 } else {
447 /* forced speed/duplex settings */
448 ct1000 = PHY_M_1000C_MSE;
449
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700450 /* Disable auto update for duplex flow control and duplex */
451 reg |= GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_SPD_DIS;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700452
453 switch (sky2->speed) {
454 case SPEED_1000:
455 ctrl |= PHY_CT_SP1000;
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700456 reg |= GM_GPCR_SPEED_1000;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700457 break;
458 case SPEED_100:
459 ctrl |= PHY_CT_SP100;
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700460 reg |= GM_GPCR_SPEED_100;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700461 break;
462 }
463
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700464 if (sky2->duplex == DUPLEX_FULL) {
465 reg |= GM_GPCR_DUP_FULL;
466 ctrl |= PHY_CT_DUP_MD;
Stephen Hemminger16ad91e2006-10-17 10:24:13 -0700467 } else if (sky2->speed < SPEED_1000)
468 sky2->flow_mode = FC_NONE;
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700469 }
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700470
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700471 if (sky2->flags & SKY2_FLAG_AUTO_PAUSE) {
472 if (sky2_is_copper(hw))
473 adv |= copper_fc_adv[sky2->flow_mode];
474 else
475 adv |= fiber_fc_adv[sky2->flow_mode];
476 } else {
477 reg |= GM_GPCR_AU_FCT_DIS;
Stephen Hemminger16ad91e2006-10-17 10:24:13 -0700478 reg |= gm_fc_disable[sky2->flow_mode];
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700479
480 /* Forward pause packets to GMAC? */
Stephen Hemminger16ad91e2006-10-17 10:24:13 -0700481 if (sky2->flow_mode & FC_RX)
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700482 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
483 else
484 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700485 }
486
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700487 gma_write16(hw, port, GM_GP_CTRL, reg);
488
Stephen Hemminger05745c42007-09-19 15:36:45 -0700489 if (hw->flags & SKY2_HW_GIGABIT)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700490 gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000);
491
492 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv);
493 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
494
495 /* Setup Phy LED's */
496 ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS);
497 ledover = 0;
498
499 switch (hw->chip_id) {
500 case CHIP_ID_YUKON_FE:
501 /* on 88E3082 these bits are at 11..9 (shifted left) */
502 ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) << 1;
503
504 ctrl = gm_phy_read(hw, port, PHY_MARV_FE_LED_PAR);
505
506 /* delete ACT LED control bits */
507 ctrl &= ~PHY_M_FELP_LED1_MSK;
508 /* change ACT LED control to blink mode */
509 ctrl |= PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_ACT_BL);
510 gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl);
511 break;
512
Stephen Hemminger05745c42007-09-19 15:36:45 -0700513 case CHIP_ID_YUKON_FE_P:
514 /* Enable Link Partner Next Page */
515 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
516 ctrl |= PHY_M_PC_ENA_LIP_NP;
517
518 /* disable Energy Detect and enable scrambler */
519 ctrl &= ~(PHY_M_PC_ENA_ENE_DT | PHY_M_PC_DIS_SCRAMB);
520 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
521
522 /* set LED2 -> ACT, LED1 -> LINK, LED0 -> SPEED */
523 ctrl = PHY_M_FELP_LED2_CTRL(LED_PAR_CTRL_ACT_BL) |
524 PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_LINK) |
525 PHY_M_FELP_LED0_CTRL(LED_PAR_CTRL_SPEED);
526
527 gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl);
528 break;
529
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700530 case CHIP_ID_YUKON_XL:
Stephen Hemminger793b8832005-09-14 16:06:14 -0700531 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700532
533 /* select page 3 to access LED control register */
534 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
535
536 /* set LED Function Control register */
Stephen Hemmingered6d32c2006-05-08 15:11:33 -0700537 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
538 (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */
539 PHY_M_LEDC_INIT_CTRL(7) | /* 10 Mbps */
540 PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */
541 PHY_M_LEDC_STA0_CTRL(7))); /* 1000 Mbps */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700542
543 /* set Polarity Control register */
544 gm_phy_write(hw, port, PHY_MARV_PHY_STAT,
Stephen Hemminger793b8832005-09-14 16:06:14 -0700545 (PHY_M_POLC_LS1_P_MIX(4) |
546 PHY_M_POLC_IS0_P_MIX(4) |
547 PHY_M_POLC_LOS_CTRL(2) |
548 PHY_M_POLC_INIT_CTRL(2) |
549 PHY_M_POLC_STA1_CTRL(2) |
550 PHY_M_POLC_STA0_CTRL(2)));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700551
552 /* restore page register */
Stephen Hemminger793b8832005-09-14 16:06:14 -0700553 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700554 break;
Stephen Hemminger93745492007-02-06 10:45:43 -0800555
Stephen Hemmingered6d32c2006-05-08 15:11:33 -0700556 case CHIP_ID_YUKON_EC_U:
Stephen Hemminger93745492007-02-06 10:45:43 -0800557 case CHIP_ID_YUKON_EX:
Stephen Hemmingered4d4162008-01-10 16:14:14 -0800558 case CHIP_ID_YUKON_SUPR:
Stephen Hemmingered6d32c2006-05-08 15:11:33 -0700559 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
560
561 /* select page 3 to access LED control register */
562 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
563
564 /* set LED Function Control register */
565 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
566 (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */
567 PHY_M_LEDC_INIT_CTRL(8) | /* 10 Mbps */
568 PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */
569 PHY_M_LEDC_STA0_CTRL(7)));/* 1000 Mbps */
570
571 /* set Blink Rate in LED Timer Control Register */
572 gm_phy_write(hw, port, PHY_MARV_INT_MASK,
573 ledctrl | PHY_M_LED_BLINK_RT(BLINK_84MS));
574 /* restore page register */
575 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
576 break;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700577
578 default:
579 /* set Tx LED (LED_TX) to blink mode on Rx OR Tx activity */
580 ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL;
Stephen Hemmingera84d0a32008-02-22 16:00:33 -0800581
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700582 /* turn off the Rx LED (LED_RX) */
Stephen Hemmingera84d0a32008-02-22 16:00:33 -0800583 ledover |= PHY_M_LED_MO_RX(MO_LED_OFF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700584 }
585
Stephen Hemminger0ce8b982008-06-17 09:04:27 -0700586 if (hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_UL_2) {
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800587 /* apply fixes in PHY AFE */
Stephen Hemmingered6d32c2006-05-08 15:11:33 -0700588 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 255);
589
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800590 /* increase differential signal amplitude in 10BASE-T */
Stephen Hemmingered6d32c2006-05-08 15:11:33 -0700591 gm_phy_write(hw, port, 0x18, 0xaa99);
592 gm_phy_write(hw, port, 0x17, 0x2011);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700593
Stephen Hemminger0ce8b982008-06-17 09:04:27 -0700594 if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
595 /* fix for IEEE A/B Symmetry failure in 1000BASE-T */
596 gm_phy_write(hw, port, 0x18, 0xa204);
597 gm_phy_write(hw, port, 0x17, 0x2002);
598 }
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800599
600 /* set page register to 0 */
Stephen Hemminger9467a8f2007-04-07 16:02:28 -0700601 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
Stephen Hemminger05745c42007-09-19 15:36:45 -0700602 } else if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
603 hw->chip_rev == CHIP_REV_YU_FE2_A0) {
604 /* apply workaround for integrated resistors calibration */
605 gm_phy_write(hw, port, PHY_MARV_PAGE_ADDR, 17);
606 gm_phy_write(hw, port, PHY_MARV_PAGE_DATA, 0x3f60);
Stephen Hemminger0f5aac72009-10-29 06:37:09 +0000607 } else if (hw->chip_id == CHIP_ID_YUKON_OPT && hw->chip_rev == 0) {
608 /* apply fixes in PHY AFE */
609 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0x00ff);
610
611 /* apply RDAC termination workaround */
612 gm_phy_write(hw, port, 24, 0x2800);
613 gm_phy_write(hw, port, 23, 0x2001);
614
615 /* set page register back to 0 */
616 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
Stephen Hemmingere1a74b32008-06-17 09:04:24 -0700617 } else if (hw->chip_id != CHIP_ID_YUKON_EX &&
618 hw->chip_id < CHIP_ID_YUKON_SUPR) {
Stephen Hemminger05745c42007-09-19 15:36:45 -0700619 /* no effect on Yukon-XL */
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800620 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl);
621
Joe Perches8e95a202009-12-03 07:58:21 +0000622 if (!(sky2->flags & SKY2_FLAG_AUTO_SPEED) ||
623 sky2->speed == SPEED_100) {
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800624 /* turn on 100 Mbps LED (LED_LINK100) */
Stephen Hemmingera84d0a32008-02-22 16:00:33 -0800625 ledover |= PHY_M_LED_MO_100(MO_LED_ON);
Stephen Hemminger977bdf02006-02-22 11:44:58 -0800626 }
627
628 if (ledover)
629 gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover);
630
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700631 }
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700632
shemminger@osdl.orgd571b692005-10-26 12:16:09 -0700633 /* Enable phy interrupt on auto-negotiation complete (or link up) */
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700634 if (sky2->flags & SKY2_FLAG_AUTO_SPEED)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700635 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL);
636 else
637 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
638}
639
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700640static const u32 phy_power[] = { PCI_Y2_PHY1_POWD, PCI_Y2_PHY2_POWD };
641static const u32 coma_mode[] = { PCI_Y2_PHY1_COMA, PCI_Y2_PHY2_COMA };
642
643static void sky2_phy_power_up(struct sky2_hw *hw, unsigned port)
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -0700644{
645 u32 reg1;
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -0700646
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -0800647 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700648 reg1 &= ~phy_power[port];
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -0700649
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700650 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
Stephen Hemmingerff35164e2007-10-11 19:47:44 -0700651 reg1 |= coma_mode[port];
652
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -0800653 sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
Stephen Hemminger82637e82008-01-23 19:16:04 -0800654 sky2_pci_read32(hw, PCI_DEV_REG1);
Stephen Hemmingerf71eb1a2008-08-04 13:33:37 -0700655
656 if (hw->chip_id == CHIP_ID_YUKON_FE)
657 gm_phy_write(hw, port, PHY_MARV_CTRL, PHY_CT_ANE);
658 else if (hw->flags & SKY2_HW_ADV_POWER_CTL)
659 sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700660}
Stephen Hemminger167f53d2007-09-25 19:01:02 -0700661
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700662static void sky2_phy_power_down(struct sky2_hw *hw, unsigned port)
663{
664 u32 reg1;
Stephen Hemmingerdb99b982008-05-14 17:04:16 -0700665 u16 ctrl;
666
667 /* release GPHY Control reset */
668 sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
669
670 /* release GMAC reset */
671 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
672
673 if (hw->flags & SKY2_HW_NEWER_PHY) {
674 /* select page 2 to access MAC control register */
675 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2);
676
677 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
678 /* allow GMII Power Down */
679 ctrl &= ~PHY_M_MAC_GMIF_PUP;
680 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
681
682 /* set page register back to 0 */
683 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
684 }
685
686 /* setup General Purpose Control Register */
687 gma_write16(hw, port, GM_GP_CTRL,
Stephen Hemminger0ea065e2009-08-14 15:36:41 -0700688 GM_GPCR_FL_PASS | GM_GPCR_SPEED_100 |
689 GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_FCT_DIS |
690 GM_GPCR_AU_SPD_DIS);
Stephen Hemmingerdb99b982008-05-14 17:04:16 -0700691
692 if (hw->chip_id != CHIP_ID_YUKON_EC) {
693 if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
Rafael J. Wysockie484d5f2008-08-10 19:30:28 +0200694 /* select page 2 to access MAC control register */
695 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2);
Stephen Hemmingerdb99b982008-05-14 17:04:16 -0700696
Rafael J. Wysockie484d5f2008-08-10 19:30:28 +0200697 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
Stephen Hemmingerdb99b982008-05-14 17:04:16 -0700698 /* enable Power Down */
699 ctrl |= PHY_M_PC_POW_D_ENA;
700 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
Rafael J. Wysockie484d5f2008-08-10 19:30:28 +0200701
702 /* set page register back to 0 */
703 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
Stephen Hemmingerdb99b982008-05-14 17:04:16 -0700704 }
705
706 /* set IEEE compatible Power Down Mode (dev. #4.99) */
707 gm_phy_write(hw, port, PHY_MARV_CTRL, PHY_CT_PDOWN);
708 }
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700709
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700710 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
Stephen Hemmingerdb99b982008-05-14 17:04:16 -0700711 reg1 |= phy_power[port]; /* set PHY to PowerDown/COMA Mode */
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700712 sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -0700713}
714
Stephen Hemminger1b537562005-12-20 15:08:07 -0800715/* Force a renegotiation */
716static void sky2_phy_reinit(struct sky2_port *sky2)
717{
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -0800718 spin_lock_bh(&sky2->phy_lock);
Stephen Hemminger1b537562005-12-20 15:08:07 -0800719 sky2_phy_init(sky2->hw, sky2->port);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -0800720 spin_unlock_bh(&sky2->phy_lock);
Stephen Hemminger1b537562005-12-20 15:08:07 -0800721}
722
Stephen Hemmingere3173832007-02-06 10:45:39 -0800723/* Put device in state to listen for Wake On Lan */
724static void sky2_wol_init(struct sky2_port *sky2)
725{
726 struct sky2_hw *hw = sky2->hw;
727 unsigned port = sky2->port;
728 enum flow_control save_mode;
729 u16 ctrl;
730 u32 reg1;
731
732 /* Bring hardware out of reset */
733 sky2_write16(hw, B0_CTST, CS_RST_CLR);
734 sky2_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR);
735
736 sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
737 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
738
739 /* Force to 10/100
740 * sky2_reset will re-enable on resume
741 */
742 save_mode = sky2->flow_mode;
743 ctrl = sky2->advertising;
744
745 sky2->advertising &= ~(ADVERTISED_1000baseT_Half|ADVERTISED_1000baseT_Full);
746 sky2->flow_mode = FC_NONE;
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700747
748 spin_lock_bh(&sky2->phy_lock);
749 sky2_phy_power_up(hw, port);
750 sky2_phy_init(hw, port);
751 spin_unlock_bh(&sky2->phy_lock);
Stephen Hemmingere3173832007-02-06 10:45:39 -0800752
753 sky2->flow_mode = save_mode;
754 sky2->advertising = ctrl;
755
756 /* Set GMAC to no flow control and auto update for speed/duplex */
757 gma_write16(hw, port, GM_GP_CTRL,
758 GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA|
759 GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS);
760
761 /* Set WOL address */
762 memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR),
763 sky2->netdev->dev_addr, ETH_ALEN);
764
765 /* Turn on appropriate WOL control bits */
766 sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT);
767 ctrl = 0;
768 if (sky2->wol & WAKE_PHY)
769 ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT;
770 else
771 ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT;
772
773 if (sky2->wol & WAKE_MAGIC)
774 ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT;
775 else
Joe Perchesa419aef2009-08-18 11:18:35 -0700776 ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT;
Stephen Hemmingere3173832007-02-06 10:45:39 -0800777
778 ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT;
779 sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
780
781 /* Turn on legacy PCI-Express PME mode */
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -0800782 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
Stephen Hemmingere3173832007-02-06 10:45:39 -0800783 reg1 |= PCI_Y2_PME_LEGACY;
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -0800784 sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
Stephen Hemmingere3173832007-02-06 10:45:39 -0800785
786 /* block receiver */
787 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
788
789}
790
Stephen Hemminger69161612007-06-04 17:23:26 -0700791static void sky2_set_tx_stfwd(struct sky2_hw *hw, unsigned port)
792{
Stephen Hemminger05745c42007-09-19 15:36:45 -0700793 struct net_device *dev = hw->dev[port];
794
Stephen Hemmingered4d4162008-01-10 16:14:14 -0800795 if ( (hw->chip_id == CHIP_ID_YUKON_EX &&
796 hw->chip_rev != CHIP_REV_YU_EX_A0) ||
Stephen Hemminger877c8572009-10-29 06:37:08 +0000797 hw->chip_id >= CHIP_ID_YUKON_FE_P) {
Stephen Hemmingered4d4162008-01-10 16:14:14 -0800798 /* Yukon-Extreme B0 and further Extreme devices */
799 /* enable Store & Forward mode for TX */
Stephen Hemminger69161612007-06-04 17:23:26 -0700800
Stephen Hemmingered4d4162008-01-10 16:14:14 -0800801 if (dev->mtu <= ETH_DATA_LEN)
802 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
803 TX_JUMBO_DIS | TX_STFW_ENA);
Stephen Hemminger69161612007-06-04 17:23:26 -0700804
Stephen Hemmingered4d4162008-01-10 16:14:14 -0800805 else
806 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
807 TX_JUMBO_ENA| TX_STFW_ENA);
808 } else {
809 if (dev->mtu <= ETH_DATA_LEN)
810 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_ENA);
811 else {
812 /* set Tx GMAC FIFO Almost Empty Threshold */
813 sky2_write32(hw, SK_REG(port, TX_GMF_AE_THR),
814 (ECU_JUMBO_WM << 16) | ECU_AE_THR);
Stephen Hemminger05745c42007-09-19 15:36:45 -0700815
Stephen Hemmingered4d4162008-01-10 16:14:14 -0800816 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_DIS);
817
818 /* Can't do offload because of lack of store/forward */
819 dev->features &= ~(NETIF_F_TSO | NETIF_F_SG | NETIF_F_ALL_CSUM);
820 }
Stephen Hemminger69161612007-06-04 17:23:26 -0700821 }
822}
823
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700824static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
825{
826 struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
827 u16 reg;
Al Viro25cccec2007-07-20 16:07:33 +0100828 u32 rx_reg;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700829 int i;
830 const u8 *addr = hw->dev[port]->dev_addr;
831
Stephen Hemmingerf3503392007-08-21 11:10:22 -0700832 sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
833 sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700834
835 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
836
Stephen Hemminger793b8832005-09-14 16:06:14 -0700837 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0 && port == 1) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700838 /* WA DEV_472 -- looks like crossed wires on port 2 */
839 /* clear GMAC 1 Control reset */
840 sky2_write8(hw, SK_REG(0, GMAC_CTRL), GMC_RST_CLR);
841 do {
842 sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_SET);
843 sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_CLR);
844 } while (gm_phy_read(hw, 1, PHY_MARV_ID0) != PHY_MARV_ID0_VAL ||
845 gm_phy_read(hw, 1, PHY_MARV_ID1) != PHY_MARV_ID1_Y2 ||
846 gm_phy_read(hw, 1, PHY_MARV_INT_MASK) != 0);
847 }
848
Stephen Hemminger793b8832005-09-14 16:06:14 -0700849 sky2_read16(hw, SK_REG(port, GMAC_IRQ_SRC));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700850
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -0700851 /* Enable Transmit FIFO Underrun */
852 sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK);
853
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -0800854 spin_lock_bh(&sky2->phy_lock);
Stephen Hemmingerb96936da72008-05-14 17:04:15 -0700855 sky2_phy_power_up(hw, port);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700856 sky2_phy_init(hw, port);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -0800857 spin_unlock_bh(&sky2->phy_lock);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700858
859 /* MIB clear */
860 reg = gma_read16(hw, port, GM_PHY_ADDR);
861 gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR);
862
Stephen Hemminger43f2f102006-04-05 17:47:15 -0700863 for (i = GM_MIB_CNT_BASE; i <= GM_MIB_CNT_END; i += 4)
864 gma_read16(hw, port, i);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700865 gma_write16(hw, port, GM_PHY_ADDR, reg);
866
867 /* transmit control */
868 gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF));
869
870 /* receive control reg: unicast + multicast + no FCS */
871 gma_write16(hw, port, GM_RX_CTRL,
Stephen Hemminger793b8832005-09-14 16:06:14 -0700872 GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700873
874 /* transmit flow control */
875 gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff);
876
877 /* transmit parameter */
878 gma_write16(hw, port, GM_TX_PARAM,
879 TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) |
880 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) |
881 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF) |
882 TX_BACK_OFF_LIM(TX_BOF_LIM_DEF));
883
884 /* serial mode register */
885 reg = DATA_BLIND_VAL(DATA_BLIND_DEF) |
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -0700886 GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700887
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -0700888 if (hw->dev[port]->mtu > ETH_DATA_LEN)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700889 reg |= GM_SMOD_JUMBO_ENA;
890
891 gma_write16(hw, port, GM_SERIAL_MODE, reg);
892
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700893 /* virtual address for data */
894 gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr);
895
Stephen Hemminger793b8832005-09-14 16:06:14 -0700896 /* physical address: used for pause frames */
897 gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr);
898
899 /* ignore counter overflows */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700900 gma_write16(hw, port, GM_TX_IRQ_MSK, 0);
901 gma_write16(hw, port, GM_RX_IRQ_MSK, 0);
902 gma_write16(hw, port, GM_TR_IRQ_MSK, 0);
903
904 /* Configure Rx MAC FIFO */
905 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
Al Viro25cccec2007-07-20 16:07:33 +0100906 rx_reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
Stephen Hemminger05745c42007-09-19 15:36:45 -0700907 if (hw->chip_id == CHIP_ID_YUKON_EX ||
908 hw->chip_id == CHIP_ID_YUKON_FE_P)
Al Viro25cccec2007-07-20 16:07:33 +0100909 rx_reg |= GMF_RX_OVER_ON;
Stephen Hemminger69161612007-06-04 17:23:26 -0700910
Al Viro25cccec2007-07-20 16:07:33 +0100911 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), rx_reg);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700912
Stephen Hemminger798fdd02007-12-07 15:22:15 -0800913 if (hw->chip_id == CHIP_ID_YUKON_XL) {
914 /* Hardware errata - clear flush mask */
915 sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), 0);
916 } else {
917 /* Flush Rx MAC FIFO on any flow control or error */
918 sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR);
919 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700920
Stephen Hemminger8df9a872006-12-01 14:29:35 -0800921 /* Set threshold to 0xa (64 bytes) + 1 to workaround pause bug */
Stephen Hemminger05745c42007-09-19 15:36:45 -0700922 reg = RX_GMF_FL_THR_DEF + 1;
923 /* Another magic mystery workaround from sk98lin */
924 if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
925 hw->chip_rev == CHIP_REV_YU_FE2_A0)
926 reg = 0x178;
927 sky2_write16(hw, SK_REG(port, RX_GMF_FL_THR), reg);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700928
929 /* Configure Tx MAC FIFO */
930 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
931 sky2_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -0800932
Stephen Hemmingere0c28112007-09-20 13:03:49 -0700933 /* On chips without ram buffer, pause is controled by MAC level */
Stephen Hemminger39dbd952008-02-04 19:45:13 -0800934 if (!(hw->flags & SKY2_HW_RAM_BUFFER)) {
Stephen Hemmingerd6b54d22009-10-29 06:37:07 +0000935 /* Pause threshold is scaled by 8 in bytes */
Joe Perches8e95a202009-12-03 07:58:21 +0000936 if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
937 hw->chip_rev == CHIP_REV_YU_FE2_A0)
Stephen Hemmingerd6b54d22009-10-29 06:37:07 +0000938 reg = 1568 / 8;
939 else
940 reg = 1024 / 8;
941 sky2_write16(hw, SK_REG(port, RX_GMF_UP_THR), reg);
942 sky2_write16(hw, SK_REG(port, RX_GMF_LP_THR), 768 / 8);
Stephen Hemmingerb628ed982007-04-11 14:48:01 -0700943
Stephen Hemminger69161612007-06-04 17:23:26 -0700944 sky2_set_tx_stfwd(hw, port);
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -0800945 }
946
Stephen Hemmingere970d1f2007-11-27 11:02:07 -0800947 if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
948 hw->chip_rev == CHIP_REV_YU_FE2_A0) {
949 /* disable dynamic watermark */
950 reg = sky2_read16(hw, SK_REG(port, TX_GMF_EA));
951 reg &= ~TX_DYN_WM_ENA;
952 sky2_write16(hw, SK_REG(port, TX_GMF_EA), reg);
953 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700954}
955
Stephen Hemminger67712902006-12-04 15:53:45 -0800956/* Assign Ram Buffer allocation to queue */
957static void sky2_ramset(struct sky2_hw *hw, u16 q, u32 start, u32 space)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700958{
Stephen Hemminger67712902006-12-04 15:53:45 -0800959 u32 end;
960
961 /* convert from K bytes to qwords used for hw register */
962 start *= 1024/8;
963 space *= 1024/8;
964 end = start + space - 1;
Stephen Hemminger793b8832005-09-14 16:06:14 -0700965
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700966 sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR);
967 sky2_write32(hw, RB_ADDR(q, RB_START), start);
968 sky2_write32(hw, RB_ADDR(q, RB_END), end);
969 sky2_write32(hw, RB_ADDR(q, RB_WP), start);
970 sky2_write32(hw, RB_ADDR(q, RB_RP), start);
971
972 if (q == Q_R1 || q == Q_R2) {
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -0800973 u32 tp = space - space/4;
Stephen Hemminger793b8832005-09-14 16:06:14 -0700974
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -0800975 /* On receive queue's set the thresholds
976 * give receiver priority when > 3/4 full
977 * send pause when down to 2K
978 */
979 sky2_write32(hw, RB_ADDR(q, RB_RX_UTHP), tp);
980 sky2_write32(hw, RB_ADDR(q, RB_RX_LTHP), space/2);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700981
Stephen Hemminger1c28f6b2006-01-17 13:43:13 -0800982 tp = space - 2048/8;
983 sky2_write32(hw, RB_ADDR(q, RB_RX_UTPP), tp);
984 sky2_write32(hw, RB_ADDR(q, RB_RX_LTPP), space/4);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700985 } else {
986 /* Enable store & forward on Tx queue's because
987 * Tx FIFO is only 1K on Yukon
988 */
989 sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD);
990 }
991
992 sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD);
Stephen Hemminger793b8832005-09-14 16:06:14 -0700993 sky2_read8(hw, RB_ADDR(q, RB_CTRL));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700994}
995
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700996/* Setup Bus Memory Interface */
shemminger@osdl.orgaf4ed7e2005-11-30 11:45:21 -0800997static void sky2_qset(struct sky2_hw *hw, u16 q)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -0700998{
999 sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_RESET);
1000 sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_OPER_INIT);
1001 sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_FIFO_OP_ON);
shemminger@osdl.orgaf4ed7e2005-11-30 11:45:21 -08001002 sky2_write32(hw, Q_ADDR(q, Q_WM), BMU_WM_DEFAULT);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001003}
1004
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001005/* Setup prefetch unit registers. This is the interface between
1006 * hardware and driver list elements
1007 */
Stephen Hemminger8cc048e2005-12-09 11:35:07 -08001008static void sky2_prefetch_init(struct sky2_hw *hw, u32 qaddr,
Stephen Hemmingerd6e74b62009-08-18 15:17:05 +00001009 dma_addr_t addr, u32 last)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001010{
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001011 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
1012 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_CLR);
Stephen Hemmingerd6e74b62009-08-18 15:17:05 +00001013 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_HI), upper_32_bits(addr));
1014 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_LO), lower_32_bits(addr));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001015 sky2_write16(hw, Y2_QADDR(qaddr, PREF_UNIT_LAST_IDX), last);
1016 sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_OP_ON);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001017
1018 sky2_read32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001019}
1020
Mike McCormack9b289c32009-08-14 05:15:12 +00001021static inline struct sky2_tx_le *get_tx_le(struct sky2_port *sky2, u16 *slot)
Stephen Hemminger793b8832005-09-14 16:06:14 -07001022{
Mike McCormack9b289c32009-08-14 05:15:12 +00001023 struct sky2_tx_le *le = sky2->tx_le + *slot;
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001024 struct tx_ring_info *re = sky2->tx_ring + *slot;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001025
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001026 *slot = RING_NEXT(*slot, sky2->tx_ring_size);
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001027 re->flags = 0;
1028 re->skb = NULL;
Stephen Hemminger291ea612006-09-26 11:57:41 -07001029 le->ctrl = 0;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001030 return le;
1031}
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001032
Stephen Hemminger88f5f0c2007-09-27 12:38:12 -07001033static void tx_init(struct sky2_port *sky2)
1034{
1035 struct sky2_tx_le *le;
1036
1037 sky2->tx_prod = sky2->tx_cons = 0;
1038 sky2->tx_tcpsum = 0;
1039 sky2->tx_last_mss = 0;
1040
Mike McCormack9b289c32009-08-14 05:15:12 +00001041 le = get_tx_le(sky2, &sky2->tx_prod);
Stephen Hemminger88f5f0c2007-09-27 12:38:12 -07001042 le->addr = 0;
1043 le->opcode = OP_ADDR64 | HW_OWNER;
Stephen Hemminger5dce95e2009-08-18 15:17:06 +00001044 sky2->tx_last_upper = 0;
Stephen Hemminger88f5f0c2007-09-27 12:38:12 -07001045}
1046
Stephen Hemminger290d4de2006-03-20 15:48:15 -08001047/* Update chip's next pointer */
1048static inline void sky2_put_idx(struct sky2_hw *hw, unsigned q, u16 idx)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001049{
Stephen Hemminger50432cb2007-05-14 12:38:15 -07001050 /* Make sure write' to descriptors are complete before we tell hardware */
Stephen Hemminger762c2de2006-01-17 13:43:14 -08001051 wmb();
Stephen Hemminger50432cb2007-05-14 12:38:15 -07001052 sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), idx);
1053
1054 /* Synchronize I/O on since next processor may write to tail */
1055 mmiowb();
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001056}
1057
Stephen Hemminger793b8832005-09-14 16:06:14 -07001058
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001059static inline struct sky2_rx_le *sky2_next_rx(struct sky2_port *sky2)
1060{
1061 struct sky2_rx_le *le = sky2->rx_le + sky2->rx_put;
Stephen Hemmingercb5d9542006-05-08 15:11:29 -07001062 sky2->rx_put = RING_NEXT(sky2->rx_put, RX_LE_SIZE);
Stephen Hemminger291ea612006-09-26 11:57:41 -07001063 le->ctrl = 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001064 return le;
1065}
1066
Stephen Hemminger14d02632006-09-26 11:57:43 -07001067/* Build description to hardware for one receive segment */
1068static void sky2_rx_add(struct sky2_port *sky2, u8 op,
1069 dma_addr_t map, unsigned len)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001070{
1071 struct sky2_rx_le *le;
1072
Stephen Hemminger86c68872008-01-10 16:14:12 -08001073 if (sizeof(dma_addr_t) > sizeof(u32)) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001074 le = sky2_next_rx(sky2);
Stephen Hemminger86c68872008-01-10 16:14:12 -08001075 le->addr = cpu_to_le32(upper_32_bits(map));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001076 le->opcode = OP_ADDR64 | HW_OWNER;
1077 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07001078
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001079 le = sky2_next_rx(sky2);
Stephen Hemmingerd6e74b62009-08-18 15:17:05 +00001080 le->addr = cpu_to_le32(lower_32_bits(map));
Stephen Hemminger734d1862005-12-09 11:35:00 -08001081 le->length = cpu_to_le16(len);
Stephen Hemminger14d02632006-09-26 11:57:43 -07001082 le->opcode = op | HW_OWNER;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001083}
1084
Stephen Hemminger14d02632006-09-26 11:57:43 -07001085/* Build description to hardware for one possibly fragmented skb */
1086static void sky2_rx_submit(struct sky2_port *sky2,
1087 const struct rx_ring_info *re)
1088{
1089 int i;
1090
1091 sky2_rx_add(sky2, OP_PACKET, re->data_addr, sky2->rx_data_size);
1092
1093 for (i = 0; i < skb_shinfo(re->skb)->nr_frags; i++)
1094 sky2_rx_add(sky2, OP_BUFFER, re->frag_addr[i], PAGE_SIZE);
1095}
1096
1097
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001098static int sky2_rx_map_skb(struct pci_dev *pdev, struct rx_ring_info *re,
Stephen Hemminger14d02632006-09-26 11:57:43 -07001099 unsigned size)
1100{
1101 struct sk_buff *skb = re->skb;
1102 int i;
1103
1104 re->data_addr = pci_map_single(pdev, skb->data, size, PCI_DMA_FROMDEVICE);
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001105 if (unlikely(pci_dma_mapping_error(pdev, re->data_addr)))
1106 return -EIO;
1107
Stephen Hemminger14d02632006-09-26 11:57:43 -07001108 pci_unmap_len_set(re, data_size, size);
1109
1110 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
1111 re->frag_addr[i] = pci_map_page(pdev,
1112 skb_shinfo(skb)->frags[i].page,
1113 skb_shinfo(skb)->frags[i].page_offset,
1114 skb_shinfo(skb)->frags[i].size,
1115 PCI_DMA_FROMDEVICE);
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001116 return 0;
Stephen Hemminger14d02632006-09-26 11:57:43 -07001117}
1118
1119static void sky2_rx_unmap_skb(struct pci_dev *pdev, struct rx_ring_info *re)
1120{
1121 struct sk_buff *skb = re->skb;
1122 int i;
1123
1124 pci_unmap_single(pdev, re->data_addr, pci_unmap_len(re, data_size),
1125 PCI_DMA_FROMDEVICE);
1126
1127 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
1128 pci_unmap_page(pdev, re->frag_addr[i],
1129 skb_shinfo(skb)->frags[i].size,
1130 PCI_DMA_FROMDEVICE);
1131}
Stephen Hemminger793b8832005-09-14 16:06:14 -07001132
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001133/* Tell chip where to start receive checksum.
1134 * Actually has two checksums, but set both same to avoid possible byte
1135 * order problems.
1136 */
Stephen Hemminger793b8832005-09-14 16:06:14 -07001137static void rx_set_checksum(struct sky2_port *sky2)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001138{
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001139 struct sky2_rx_le *le = sky2_next_rx(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001140
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001141 le->addr = cpu_to_le32((ETH_HLEN << 16) | ETH_HLEN);
1142 le->ctrl = 0;
1143 le->opcode = OP_TCPSTART | HW_OWNER;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001144
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001145 sky2_write32(sky2->hw,
1146 Q_ADDR(rxqaddr[sky2->port], Q_CSR),
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07001147 (sky2->flags & SKY2_FLAG_RX_CHECKSUM)
1148 ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001149}
1150
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001151/*
1152 * The RX Stop command will not work for Yukon-2 if the BMU does not
1153 * reach the end of packet and since we can't make sure that we have
1154 * incoming data, we must reset the BMU while it is not doing a DMA
1155 * transfer. Since it is possible that the RX path is still active,
1156 * the RX RAM buffer will be stopped first, so any possible incoming
1157 * data will not trigger a DMA. After the RAM buffer is stopped, the
1158 * BMU is polled until any DMA in progress is ended and only then it
1159 * will be reset.
1160 */
1161static void sky2_rx_stop(struct sky2_port *sky2)
1162{
1163 struct sky2_hw *hw = sky2->hw;
1164 unsigned rxq = rxqaddr[sky2->port];
1165 int i;
1166
1167 /* disable the RAM Buffer receive queue */
1168 sky2_write8(hw, RB_ADDR(rxq, RB_CTRL), RB_DIS_OP_MD);
1169
1170 for (i = 0; i < 0xffff; i++)
1171 if (sky2_read8(hw, RB_ADDR(rxq, Q_RSL))
1172 == sky2_read8(hw, RB_ADDR(rxq, Q_RL)))
1173 goto stopped;
1174
1175 printk(KERN_WARNING PFX "%s: receiver stop failed\n",
1176 sky2->netdev->name);
1177stopped:
1178 sky2_write32(hw, Q_ADDR(rxq, Q_CSR), BMU_RST_SET | BMU_FIFO_RST);
1179
1180 /* reset the Rx prefetch unit */
1181 sky2_write32(hw, Y2_QADDR(rxq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
Stephen Hemminger3d1454dd2009-07-16 13:20:57 +00001182 mmiowb();
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001183}
Stephen Hemminger793b8832005-09-14 16:06:14 -07001184
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07001185/* Clean out receive buffer area, assumes receiver hardware stopped */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001186static void sky2_rx_clean(struct sky2_port *sky2)
1187{
1188 unsigned i;
1189
1190 memset(sky2->rx_le, 0, RX_LE_BYTES);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001191 for (i = 0; i < sky2->rx_pending; i++) {
Stephen Hemminger291ea612006-09-26 11:57:41 -07001192 struct rx_ring_info *re = sky2->rx_ring + i;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001193
1194 if (re->skb) {
Stephen Hemminger14d02632006-09-26 11:57:43 -07001195 sky2_rx_unmap_skb(sky2->hw->pdev, re);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001196 kfree_skb(re->skb);
1197 re->skb = NULL;
1198 }
1199 }
1200}
1201
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08001202/* Basic MII support */
1203static int sky2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1204{
1205 struct mii_ioctl_data *data = if_mii(ifr);
1206 struct sky2_port *sky2 = netdev_priv(dev);
1207 struct sky2_hw *hw = sky2->hw;
1208 int err = -EOPNOTSUPP;
1209
1210 if (!netif_running(dev))
1211 return -ENODEV; /* Phy still in reset */
1212
Stephen Hemmingerd89e1342006-03-20 15:48:20 -08001213 switch (cmd) {
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08001214 case SIOCGMIIPHY:
1215 data->phy_id = PHY_ADDR_MARV;
1216
1217 /* fallthru */
1218 case SIOCGMIIREG: {
1219 u16 val = 0;
Stephen Hemminger91c86df2005-12-09 11:34:57 -08001220
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001221 spin_lock_bh(&sky2->phy_lock);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08001222 err = __gm_phy_read(hw, sky2->port, data->reg_num & 0x1f, &val);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001223 spin_unlock_bh(&sky2->phy_lock);
Stephen Hemminger91c86df2005-12-09 11:34:57 -08001224
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08001225 data->val_out = val;
1226 break;
1227 }
1228
1229 case SIOCSMIIREG:
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001230 spin_lock_bh(&sky2->phy_lock);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08001231 err = gm_phy_write(hw, sky2->port, data->reg_num & 0x1f,
1232 data->val_in);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001233 spin_unlock_bh(&sky2->phy_lock);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08001234 break;
1235 }
1236 return err;
1237}
1238
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001239#ifdef SKY2_VLAN_TAG_USED
Stephen Hemmingerd494eac2008-05-14 17:04:13 -07001240static void sky2_set_vlan_mode(struct sky2_hw *hw, u16 port, bool onoff)
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001241{
Stephen Hemmingerd494eac2008-05-14 17:04:13 -07001242 if (onoff) {
Stephen Hemminger3d4e66f2007-06-01 09:43:58 -07001243 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T),
1244 RX_VLAN_STRIP_ON);
1245 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
1246 TX_VLAN_TAG_ON);
1247 } else {
1248 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T),
1249 RX_VLAN_STRIP_OFF);
1250 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
1251 TX_VLAN_TAG_OFF);
1252 }
Stephen Hemmingerd494eac2008-05-14 17:04:13 -07001253}
1254
1255static void sky2_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
1256{
1257 struct sky2_port *sky2 = netdev_priv(dev);
1258 struct sky2_hw *hw = sky2->hw;
1259 u16 port = sky2->port;
1260
1261 netif_tx_lock_bh(dev);
1262 napi_disable(&hw->napi);
1263
1264 sky2->vlgrp = grp;
1265 sky2_set_vlan_mode(hw, port, grp != NULL);
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001266
David S. Millerd1d08d12008-01-07 20:53:33 -08001267 sky2_read32(hw, B0_Y2_SP_LISR);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001268 napi_enable(&hw->napi);
Stephen Hemminger2bb8c262006-09-26 11:57:42 -07001269 netif_tx_unlock_bh(dev);
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001270}
1271#endif
1272
Stephen Hemmingerbd1c6862009-06-17 07:30:38 +00001273/* Amount of required worst case padding in rx buffer */
1274static inline unsigned sky2_rx_pad(const struct sky2_hw *hw)
1275{
1276 return (hw->flags & SKY2_HW_RAM_BUFFER) ? 8 : 2;
1277}
1278
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001279/*
Stephen Hemminger14d02632006-09-26 11:57:43 -07001280 * Allocate an skb for receiving. If the MTU is large enough
1281 * make the skb non-linear with a fragment list of pages.
Stephen Hemminger82788c72006-01-17 13:43:10 -08001282 */
Stephen Hemminger14d02632006-09-26 11:57:43 -07001283static struct sk_buff *sky2_rx_alloc(struct sky2_port *sky2)
Stephen Hemminger82788c72006-01-17 13:43:10 -08001284{
1285 struct sk_buff *skb;
Stephen Hemminger14d02632006-09-26 11:57:43 -07001286 int i;
Stephen Hemminger82788c72006-01-17 13:43:10 -08001287
Stephen Hemminger724b6942009-08-18 15:17:10 +00001288 skb = netdev_alloc_skb(sky2->netdev,
1289 sky2->rx_data_size + sky2_rx_pad(sky2->hw));
Stephen Hemmingerbd1c6862009-06-17 07:30:38 +00001290 if (!skb)
1291 goto nomem;
1292
Stephen Hemminger39dbd952008-02-04 19:45:13 -08001293 if (sky2->hw->flags & SKY2_HW_RAM_BUFFER) {
Stephen Hemmingerf03b8652007-11-28 14:27:03 -08001294 unsigned char *start;
1295 /*
1296 * Workaround for a bug in FIFO that cause hang
1297 * if the FIFO if the receive buffer is not 64 byte aligned.
1298 * The buffer returned from netdev_alloc_skb is
1299 * aligned except if slab debugging is enabled.
1300 */
Stephen Hemmingerf03b8652007-11-28 14:27:03 -08001301 start = PTR_ALIGN(skb->data, 8);
1302 skb_reserve(skb, start - skb->data);
Stephen Hemmingerbd1c6862009-06-17 07:30:38 +00001303 } else
Stephen Hemmingerf03b8652007-11-28 14:27:03 -08001304 skb_reserve(skb, NET_IP_ALIGN);
Stephen Hemminger14d02632006-09-26 11:57:43 -07001305
1306 for (i = 0; i < sky2->rx_nfrags; i++) {
1307 struct page *page = alloc_page(GFP_ATOMIC);
1308
1309 if (!page)
1310 goto free_partial;
1311 skb_fill_page_desc(skb, i, page, 0, PAGE_SIZE);
Stephen Hemminger82788c72006-01-17 13:43:10 -08001312 }
1313
1314 return skb;
Stephen Hemminger14d02632006-09-26 11:57:43 -07001315free_partial:
1316 kfree_skb(skb);
1317nomem:
1318 return NULL;
Stephen Hemminger82788c72006-01-17 13:43:10 -08001319}
1320
Stephen Hemminger55c9dd32007-07-09 15:33:37 -07001321static inline void sky2_rx_update(struct sky2_port *sky2, unsigned rxq)
1322{
1323 sky2_put_idx(sky2->hw, rxq, sky2->rx_put);
1324}
1325
Stephen Hemminger82788c72006-01-17 13:43:10 -08001326/*
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001327 * Allocate and setup receiver buffer pool.
Stephen Hemminger14d02632006-09-26 11:57:43 -07001328 * Normal case this ends up creating one list element for skb
1329 * in the receive ring. Worst case if using large MTU and each
1330 * allocation falls on a different 64 bit region, that results
1331 * in 6 list elements per ring entry.
1332 * One element is used for checksum enable/disable, and one
1333 * extra to avoid wrap.
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001334 */
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001335static int sky2_rx_start(struct sky2_port *sky2)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001336{
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001337 struct sky2_hw *hw = sky2->hw;
Stephen Hemminger14d02632006-09-26 11:57:43 -07001338 struct rx_ring_info *re;
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001339 unsigned rxq = rxqaddr[sky2->port];
Stephen Hemminger5f06eba2007-11-28 14:50:16 -08001340 unsigned i, size, thresh;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001341
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001342 sky2->rx_put = sky2->rx_next = 0;
shemminger@osdl.orgaf4ed7e2005-11-30 11:45:21 -08001343 sky2_qset(hw, rxq);
Stephen Hemminger977bdf02006-02-22 11:44:58 -08001344
Stephen Hemmingerc3905bc42006-12-04 17:08:19 -08001345 /* On PCI express lowering the watermark gives better performance */
1346 if (pci_find_capability(hw->pdev, PCI_CAP_ID_EXP))
1347 sky2_write32(hw, Q_ADDR(rxq, Q_WM), BMU_WM_PEX);
1348
1349 /* These chips have no ram buffer?
1350 * MAC Rx RAM Read is controlled by hardware */
Stephen Hemminger8df9a872006-12-01 14:29:35 -08001351 if (hw->chip_id == CHIP_ID_YUKON_EC_U &&
Joe Perches8e95a202009-12-03 07:58:21 +00001352 (hw->chip_rev == CHIP_REV_YU_EC_U_A1 ||
1353 hw->chip_rev == CHIP_REV_YU_EC_U_B0))
Stephen Hemmingerf449c7c2007-06-04 17:23:23 -07001354 sky2_write32(hw, Q_ADDR(rxq, Q_TEST), F_M_RX_RAM_DIS);
Stephen Hemminger977bdf02006-02-22 11:44:58 -08001355
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001356 sky2_prefetch_init(hw, rxq, sky2->rx_le_map, RX_LE_SIZE - 1);
1357
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001358 if (!(hw->flags & SKY2_HW_NEW_LE))
1359 rx_set_checksum(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001360
Stephen Hemminger14d02632006-09-26 11:57:43 -07001361 /* Space needed for frame data + headers rounded up */
Stephen Hemmingerf957da22007-07-09 15:33:41 -07001362 size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8);
Stephen Hemminger14d02632006-09-26 11:57:43 -07001363
1364 /* Stopping point for hardware truncation */
1365 thresh = (size - 8) / sizeof(u32);
1366
Stephen Hemminger5f06eba2007-11-28 14:50:16 -08001367 sky2->rx_nfrags = size >> PAGE_SHIFT;
Stephen Hemminger14d02632006-09-26 11:57:43 -07001368 BUG_ON(sky2->rx_nfrags > ARRAY_SIZE(re->frag_addr));
1369
Stephen Hemminger5f06eba2007-11-28 14:50:16 -08001370 /* Compute residue after pages */
1371 size -= sky2->rx_nfrags << PAGE_SHIFT;
Stephen Hemminger14d02632006-09-26 11:57:43 -07001372
Stephen Hemminger5f06eba2007-11-28 14:50:16 -08001373 /* Optimize to handle small packets and headers */
1374 if (size < copybreak)
1375 size = copybreak;
1376 if (size < ETH_HLEN)
1377 size = ETH_HLEN;
Stephen Hemminger14d02632006-09-26 11:57:43 -07001378
Stephen Hemminger14d02632006-09-26 11:57:43 -07001379 sky2->rx_data_size = size;
1380
1381 /* Fill Rx ring */
1382 for (i = 0; i < sky2->rx_pending; i++) {
1383 re = sky2->rx_ring + i;
1384
1385 re->skb = sky2_rx_alloc(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001386 if (!re->skb)
1387 goto nomem;
1388
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001389 if (sky2_rx_map_skb(hw->pdev, re, sky2->rx_data_size)) {
1390 dev_kfree_skb(re->skb);
1391 re->skb = NULL;
1392 goto nomem;
1393 }
1394
Stephen Hemminger14d02632006-09-26 11:57:43 -07001395 sky2_rx_submit(sky2, re);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001396 }
1397
Stephen Hemmingera1433ac2006-05-22 12:03:42 -07001398 /*
1399 * The receiver hangs if it receives frames larger than the
1400 * packet buffer. As a workaround, truncate oversize frames, but
1401 * the register is limited to 9 bits, so if you do frames > 2052
1402 * you better get the MTU right!
1403 */
Stephen Hemmingera1433ac2006-05-22 12:03:42 -07001404 if (thresh > 0x1ff)
1405 sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_OFF);
1406 else {
1407 sky2_write16(hw, SK_REG(sky2->port, RX_GMF_TR_THR), thresh);
1408 sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_ON);
1409 }
1410
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001411 /* Tell chip about available buffers */
Stephen Hemminger55c9dd32007-07-09 15:33:37 -07001412 sky2_rx_update(sky2, rxq);
Stephen Hemminger877c8572009-10-29 06:37:08 +00001413
1414 if (hw->chip_id == CHIP_ID_YUKON_EX ||
1415 hw->chip_id == CHIP_ID_YUKON_SUPR) {
1416 /*
1417 * Disable flushing of non ASF packets;
1418 * must be done after initializing the BMUs;
1419 * drivers without ASF support should do this too, otherwise
1420 * it may happen that they cannot run on ASF devices;
1421 * remember that the MAC FIFO isn't reset during initialization.
1422 */
1423 sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_MACSEC_FLUSH_OFF);
1424 }
1425
1426 if (hw->chip_id >= CHIP_ID_YUKON_SUPR) {
1427 /* Enable RX Home Address & Routing Header checksum fix */
1428 sky2_write16(hw, SK_REG(sky2->port, RX_GMF_FL_CTRL),
1429 RX_IPV6_SA_MOB_ENA | RX_IPV6_DA_MOB_ENA);
1430
1431 /* Enable TX Home Address & Routing Header checksum fix */
1432 sky2_write32(hw, Q_ADDR(txqaddr[sky2->port], Q_TEST),
1433 TBMU_TEST_HOME_ADD_FIX_EN | TBMU_TEST_ROUTING_ADD_FIX_EN);
1434 }
1435
1436
1437
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001438 return 0;
1439nomem:
1440 sky2_rx_clean(sky2);
1441 return -ENOMEM;
1442}
1443
Mike McCormack90bbebb2009-09-01 03:21:35 +00001444static int sky2_alloc_buffers(struct sky2_port *sky2)
1445{
1446 struct sky2_hw *hw = sky2->hw;
1447
1448 /* must be power of 2 */
1449 sky2->tx_le = pci_alloc_consistent(hw->pdev,
1450 sky2->tx_ring_size *
1451 sizeof(struct sky2_tx_le),
1452 &sky2->tx_le_map);
1453 if (!sky2->tx_le)
1454 goto nomem;
1455
1456 sky2->tx_ring = kcalloc(sky2->tx_ring_size, sizeof(struct tx_ring_info),
1457 GFP_KERNEL);
1458 if (!sky2->tx_ring)
1459 goto nomem;
1460
1461 sky2->rx_le = pci_alloc_consistent(hw->pdev, RX_LE_BYTES,
1462 &sky2->rx_le_map);
1463 if (!sky2->rx_le)
1464 goto nomem;
1465 memset(sky2->rx_le, 0, RX_LE_BYTES);
1466
1467 sky2->rx_ring = kcalloc(sky2->rx_pending, sizeof(struct rx_ring_info),
1468 GFP_KERNEL);
1469 if (!sky2->rx_ring)
1470 goto nomem;
1471
1472 return 0;
1473nomem:
1474 return -ENOMEM;
1475}
1476
1477static void sky2_free_buffers(struct sky2_port *sky2)
1478{
1479 struct sky2_hw *hw = sky2->hw;
1480
1481 if (sky2->rx_le) {
1482 pci_free_consistent(hw->pdev, RX_LE_BYTES,
1483 sky2->rx_le, sky2->rx_le_map);
1484 sky2->rx_le = NULL;
1485 }
1486 if (sky2->tx_le) {
1487 pci_free_consistent(hw->pdev,
1488 sky2->tx_ring_size * sizeof(struct sky2_tx_le),
1489 sky2->tx_le, sky2->tx_le_map);
1490 sky2->tx_le = NULL;
1491 }
1492 kfree(sky2->tx_ring);
1493 kfree(sky2->rx_ring);
1494
1495 sky2->tx_ring = NULL;
1496 sky2->rx_ring = NULL;
1497}
1498
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001499/* Bring up network interface. */
1500static int sky2_up(struct net_device *dev)
1501{
1502 struct sky2_port *sky2 = netdev_priv(dev);
1503 struct sky2_hw *hw = sky2->hw;
1504 unsigned port = sky2->port;
Stephen Hemmingere0c28112007-09-20 13:03:49 -07001505 u32 imask, ramsize;
Mike McCormack90bbebb2009-09-01 03:21:35 +00001506 int cap, err;
Stephen Hemminger843a46f2006-05-11 15:07:28 -07001507 struct net_device *otherdev = hw->dev[sky2->port^1];
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001508
Stephen Hemmingeree7abb02006-05-18 11:16:21 -07001509 /*
1510 * On dual port PCI-X card, there is an problem where status
1511 * can be received out of order due to split transactions
Stephen Hemminger843a46f2006-05-11 15:07:28 -07001512 */
Stephen Hemmingeree7abb02006-05-18 11:16:21 -07001513 if (otherdev && netif_running(otherdev) &&
1514 (cap = pci_find_capability(hw->pdev, PCI_CAP_ID_PCIX))) {
Stephen Hemmingeree7abb02006-05-18 11:16:21 -07001515 u16 cmd;
Stephen Hemminger843a46f2006-05-11 15:07:28 -07001516
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08001517 cmd = sky2_pci_read16(hw, cap + PCI_X_CMD);
Stephen Hemmingeree7abb02006-05-18 11:16:21 -07001518 cmd &= ~PCI_X_CMD_MAX_SPLIT;
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08001519 sky2_pci_write16(hw, cap + PCI_X_CMD, cmd);
1520
Stephen Hemmingeree7abb02006-05-18 11:16:21 -07001521 }
1522
Stephen Hemminger55d7b4e2007-07-09 15:33:34 -07001523 netif_carrier_off(dev);
1524
Mike McCormack90bbebb2009-09-01 03:21:35 +00001525 err = sky2_alloc_buffers(sky2);
1526 if (err)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001527 goto err_out;
Stephen Hemminger88f5f0c2007-09-27 12:38:12 -07001528
1529 tx_init(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001530
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001531 sky2_mac_init(hw, port);
1532
Stephen Hemmingere0c28112007-09-20 13:03:49 -07001533 /* Register is number of 4K blocks on internal RAM buffer. */
1534 ramsize = sky2_read8(hw, B2_E_0) * 4;
1535 if (ramsize > 0) {
Stephen Hemminger67712902006-12-04 15:53:45 -08001536 u32 rxspace;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001537
Stephen Hemmingere0c28112007-09-20 13:03:49 -07001538 pr_debug(PFX "%s: ram buffer %dK\n", dev->name, ramsize);
Stephen Hemminger67712902006-12-04 15:53:45 -08001539 if (ramsize < 16)
1540 rxspace = ramsize / 2;
1541 else
1542 rxspace = 8 + (2*(ramsize - 16))/3;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001543
Stephen Hemminger67712902006-12-04 15:53:45 -08001544 sky2_ramset(hw, rxqaddr[port], 0, rxspace);
1545 sky2_ramset(hw, txqaddr[port], rxspace, ramsize - rxspace);
1546
1547 /* Make sure SyncQ is disabled */
1548 sky2_write8(hw, RB_ADDR(port == 0 ? Q_XS1 : Q_XS2, RB_CTRL),
1549 RB_RST_SET);
1550 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07001551
shemminger@osdl.orgaf4ed7e2005-11-30 11:45:21 -08001552 sky2_qset(hw, txqaddr[port]);
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -08001553
Stephen Hemminger69161612007-06-04 17:23:26 -07001554 /* This is copied from sk98lin 10.0.5.3; no one tells me about erratta's */
1555 if (hw->chip_id == CHIP_ID_YUKON_EX && hw->chip_rev == CHIP_REV_YU_EX_B0)
1556 sky2_write32(hw, Q_ADDR(txqaddr[port], Q_TEST), F_TX_CHK_AUTO_OFF);
1557
Stephen Hemminger977bdf02006-02-22 11:44:58 -08001558 /* Set almost empty threshold */
Joe Perches8e95a202009-12-03 07:58:21 +00001559 if (hw->chip_id == CHIP_ID_YUKON_EC_U &&
1560 hw->chip_rev == CHIP_REV_YU_EC_U_A0)
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07001561 sky2_write16(hw, Q_ADDR(txqaddr[port], Q_AL), ECU_TXFF_LEV);
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -08001562
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001563 sky2_prefetch_init(hw, txqaddr[port], sky2->tx_le_map,
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001564 sky2->tx_ring_size - 1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001565
Stephen Hemmingerd494eac2008-05-14 17:04:13 -07001566#ifdef SKY2_VLAN_TAG_USED
1567 sky2_set_vlan_mode(hw, port, sky2->vlgrp != NULL);
1568#endif
1569
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001570 err = sky2_rx_start(sky2);
Stephen Hemminger6de16232007-10-17 13:26:42 -07001571 if (err)
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07001572 goto err_out;
1573
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001574 /* Enable interrupts from phy/mac for port */
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001575 imask = sky2_read32(hw, B0_IMSK);
Stephen Hemmingerf4ea4312006-05-09 14:46:54 -07001576 imask |= portirq_msk[port];
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001577 sky2_write32(hw, B0_IMSK, imask);
Stephen Hemminger1fd82f32009-06-17 07:30:34 +00001578 sky2_read32(hw, B0_IMSK);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001579
Alexey Dobriyana11da892009-01-30 13:45:31 -08001580 if (netif_msg_ifup(sky2))
1581 printk(KERN_INFO PFX "%s: enabling interface\n", dev->name);
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07001582
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001583 return 0;
1584
1585err_out:
Mike McCormack90bbebb2009-09-01 03:21:35 +00001586 sky2_free_buffers(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001587 return err;
1588}
1589
Stephen Hemminger793b8832005-09-14 16:06:14 -07001590/* Modular subtraction in ring */
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001591static inline int tx_inuse(const struct sky2_port *sky2)
Stephen Hemminger793b8832005-09-14 16:06:14 -07001592{
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001593 return (sky2->tx_prod - sky2->tx_cons) & (sky2->tx_ring_size - 1);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001594}
1595
1596/* Number of list elements available for next tx */
1597static inline int tx_avail(const struct sky2_port *sky2)
1598{
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001599 return sky2->tx_pending - tx_inuse(sky2);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001600}
1601
1602/* Estimate of number of transmit list elements required */
Stephen Hemminger28bd1812006-01-17 13:43:19 -08001603static unsigned tx_le_req(const struct sk_buff *skb)
Stephen Hemminger793b8832005-09-14 16:06:14 -07001604{
1605 unsigned count;
1606
Stephen Hemminger07e31632009-09-14 06:12:55 +00001607 count = (skb_shinfo(skb)->nr_frags + 1)
1608 * (sizeof(dma_addr_t) / sizeof(u32));
Stephen Hemminger793b8832005-09-14 16:06:14 -07001609
Herbert Xu89114af2006-07-08 13:34:32 -07001610 if (skb_is_gso(skb))
Stephen Hemminger793b8832005-09-14 16:06:14 -07001611 ++count;
Stephen Hemminger07e31632009-09-14 06:12:55 +00001612 else if (sizeof(dma_addr_t) == sizeof(u32))
1613 ++count; /* possible vlan */
Stephen Hemminger793b8832005-09-14 16:06:14 -07001614
Patrick McHardy84fa7932006-08-29 16:44:56 -07001615 if (skb->ip_summed == CHECKSUM_PARTIAL)
Stephen Hemminger793b8832005-09-14 16:06:14 -07001616 ++count;
1617
1618 return count;
1619}
1620
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001621static void sky2_tx_unmap(struct pci_dev *pdev,
1622 const struct tx_ring_info *re)
1623{
1624 if (re->flags & TX_MAP_SINGLE)
1625 pci_unmap_single(pdev, pci_unmap_addr(re, mapaddr),
1626 pci_unmap_len(re, maplen),
1627 PCI_DMA_TODEVICE);
1628 else if (re->flags & TX_MAP_PAGE)
1629 pci_unmap_page(pdev, pci_unmap_addr(re, mapaddr),
1630 pci_unmap_len(re, maplen),
1631 PCI_DMA_TODEVICE);
1632}
1633
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001634/*
Stephen Hemminger793b8832005-09-14 16:06:14 -07001635 * Put one packet in ring for transmit.
1636 * A single packet can generate multiple list elements, and
1637 * the number of ring elements will probably be less than the number
1638 * of list elements used.
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001639 */
Stephen Hemminger613573252009-08-31 19:50:58 +00001640static netdev_tx_t sky2_xmit_frame(struct sk_buff *skb,
1641 struct net_device *dev)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001642{
1643 struct sky2_port *sky2 = netdev_priv(dev);
1644 struct sky2_hw *hw = sky2->hw;
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001645 struct sky2_tx_le *le = NULL;
Stephen Hemminger6cdbbdf2005-12-09 11:35:01 -08001646 struct tx_ring_info *re;
Mike McCormack9b289c32009-08-14 05:15:12 +00001647 unsigned i, len;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001648 dma_addr_t mapping;
Stephen Hemminger5dce95e2009-08-18 15:17:06 +00001649 u32 upper;
1650 u16 slot;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001651 u16 mss;
1652 u8 ctrl;
1653
Stephen Hemminger2bb8c262006-09-26 11:57:42 -07001654 if (unlikely(tx_avail(sky2) < tx_le_req(skb)))
1655 return NETDEV_TX_BUSY;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001656
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001657 len = skb_headlen(skb);
1658 mapping = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001659
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001660 if (pci_dma_mapping_error(hw->pdev, mapping))
1661 goto mapping_error;
1662
Mike McCormack9b289c32009-08-14 05:15:12 +00001663 slot = sky2->tx_prod;
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001664 if (unlikely(netif_msg_tx_queued(sky2)))
1665 printk(KERN_DEBUG "%s: tx queued, slot %u, len %d\n",
Mike McCormack9b289c32009-08-14 05:15:12 +00001666 dev->name, slot, skb->len);
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001667
Stephen Hemminger86c68872008-01-10 16:14:12 -08001668 /* Send high bits if needed */
Stephen Hemminger5dce95e2009-08-18 15:17:06 +00001669 upper = upper_32_bits(mapping);
1670 if (upper != sky2->tx_last_upper) {
Mike McCormack9b289c32009-08-14 05:15:12 +00001671 le = get_tx_le(sky2, &slot);
Stephen Hemminger5dce95e2009-08-18 15:17:06 +00001672 le->addr = cpu_to_le32(upper);
1673 sky2->tx_last_upper = upper;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001674 le->opcode = OP_ADDR64 | HW_OWNER;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001675 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001676
1677 /* Check for TCP Segmentation Offload */
Herbert Xu79671682006-06-22 02:40:14 -07001678 mss = skb_shinfo(skb)->gso_size;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001679 if (mss != 0) {
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001680
1681 if (!(hw->flags & SKY2_HW_NEW_LE))
Stephen Hemminger69161612007-06-04 17:23:26 -07001682 mss += ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001683
Stephen Hemminger69161612007-06-04 17:23:26 -07001684 if (mss != sky2->tx_last_mss) {
Mike McCormack9b289c32009-08-14 05:15:12 +00001685 le = get_tx_le(sky2, &slot);
Stephen Hemminger69161612007-06-04 17:23:26 -07001686 le->addr = cpu_to_le32(mss);
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001687
1688 if (hw->flags & SKY2_HW_NEW_LE)
Stephen Hemminger69161612007-06-04 17:23:26 -07001689 le->opcode = OP_MSS | HW_OWNER;
1690 else
1691 le->opcode = OP_LRGLEN | HW_OWNER;
shemminger@osdl.orge07560c2006-08-28 10:00:49 -07001692 sky2->tx_last_mss = mss;
1693 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001694 }
1695
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001696 ctrl = 0;
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001697#ifdef SKY2_VLAN_TAG_USED
1698 /* Add VLAN tag, can piggyback on LRGLEN or ADDR64 */
1699 if (sky2->vlgrp && vlan_tx_tag_present(skb)) {
1700 if (!le) {
Mike McCormack9b289c32009-08-14 05:15:12 +00001701 le = get_tx_le(sky2, &slot);
Stephen Hemmingerf65b1382006-09-06 12:45:02 -07001702 le->addr = 0;
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001703 le->opcode = OP_VLAN|HW_OWNER;
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07001704 } else
1705 le->opcode |= OP_VLAN;
1706 le->length = cpu_to_be16(vlan_tx_tag_get(skb));
1707 ctrl |= INS_VLAN;
1708 }
1709#endif
1710
1711 /* Handle TCP checksum offload */
Patrick McHardy84fa7932006-08-29 16:44:56 -07001712 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Stephen Hemminger69161612007-06-04 17:23:26 -07001713 /* On Yukon EX (some versions) encoding change. */
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001714 if (hw->flags & SKY2_HW_AUTO_TX_SUM)
Stephen Hemminger69161612007-06-04 17:23:26 -07001715 ctrl |= CALSUM; /* auto checksum */
1716 else {
1717 const unsigned offset = skb_transport_offset(skb);
1718 u32 tcpsum;
Stephen Hemmingerf65b1382006-09-06 12:45:02 -07001719
Stephen Hemminger69161612007-06-04 17:23:26 -07001720 tcpsum = offset << 16; /* sum start */
1721 tcpsum |= offset + skb->csum_offset; /* sum write */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001722
Stephen Hemminger69161612007-06-04 17:23:26 -07001723 ctrl |= CALSUM | WR_SUM | INIT_SUM | LOCK_SUM;
1724 if (ip_hdr(skb)->protocol == IPPROTO_UDP)
1725 ctrl |= UDPTCP;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001726
Stephen Hemminger69161612007-06-04 17:23:26 -07001727 if (tcpsum != sky2->tx_tcpsum) {
1728 sky2->tx_tcpsum = tcpsum;
shemminger@osdl.org1d179332006-08-28 10:00:50 -07001729
Mike McCormack9b289c32009-08-14 05:15:12 +00001730 le = get_tx_le(sky2, &slot);
Stephen Hemminger69161612007-06-04 17:23:26 -07001731 le->addr = cpu_to_le32(tcpsum);
1732 le->length = 0; /* initial checksum value */
1733 le->ctrl = 1; /* one packet */
1734 le->opcode = OP_TCPLISW | HW_OWNER;
1735 }
shemminger@osdl.org1d179332006-08-28 10:00:50 -07001736 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001737 }
1738
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001739 re = sky2->tx_ring + slot;
1740 re->flags = TX_MAP_SINGLE;
1741 pci_unmap_addr_set(re, mapaddr, mapping);
1742 pci_unmap_len_set(re, maplen, len);
1743
Mike McCormack9b289c32009-08-14 05:15:12 +00001744 le = get_tx_le(sky2, &slot);
Stephen Hemmingerd6e74b62009-08-18 15:17:05 +00001745 le->addr = cpu_to_le32(lower_32_bits(mapping));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001746 le->length = cpu_to_le16(len);
1747 le->ctrl = ctrl;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001748 le->opcode = mss ? (OP_LARGESEND | HW_OWNER) : (OP_PACKET | HW_OWNER);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001749
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001750
1751 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
Stephen Hemminger291ea612006-09-26 11:57:41 -07001752 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001753
1754 mapping = pci_map_page(hw->pdev, frag->page, frag->page_offset,
1755 frag->size, PCI_DMA_TODEVICE);
Stephen Hemminger86c68872008-01-10 16:14:12 -08001756
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001757 if (pci_dma_mapping_error(hw->pdev, mapping))
1758 goto mapping_unwind;
1759
Stephen Hemminger5dce95e2009-08-18 15:17:06 +00001760 upper = upper_32_bits(mapping);
1761 if (upper != sky2->tx_last_upper) {
Mike McCormack9b289c32009-08-14 05:15:12 +00001762 le = get_tx_le(sky2, &slot);
Stephen Hemminger5dce95e2009-08-18 15:17:06 +00001763 le->addr = cpu_to_le32(upper);
1764 sky2->tx_last_upper = upper;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001765 le->opcode = OP_ADDR64 | HW_OWNER;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001766 }
1767
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001768 re = sky2->tx_ring + slot;
1769 re->flags = TX_MAP_PAGE;
1770 pci_unmap_addr_set(re, mapaddr, mapping);
1771 pci_unmap_len_set(re, maplen, frag->size);
1772
Mike McCormack9b289c32009-08-14 05:15:12 +00001773 le = get_tx_le(sky2, &slot);
Stephen Hemmingerd6e74b62009-08-18 15:17:05 +00001774 le->addr = cpu_to_le32(lower_32_bits(mapping));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001775 le->length = cpu_to_le16(frag->size);
1776 le->ctrl = ctrl;
Stephen Hemminger793b8832005-09-14 16:06:14 -07001777 le->opcode = OP_BUFFER | HW_OWNER;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001778 }
Stephen Hemminger6cdbbdf2005-12-09 11:35:01 -08001779
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001780 re->skb = skb;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001781 le->ctrl |= EOP;
1782
Mike McCormack9b289c32009-08-14 05:15:12 +00001783 sky2->tx_prod = slot;
1784
shemminger@osdl.org97bda702006-08-28 10:00:47 -07001785 if (tx_avail(sky2) <= MAX_SKB_TX_LE)
1786 netif_stop_queue(dev);
Stephen Hemmingerb19666d2006-03-07 11:06:36 -08001787
Stephen Hemminger290d4de2006-03-20 15:48:15 -08001788 sky2_put_idx(hw, txqaddr[sky2->port], sky2->tx_prod);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001789
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001790 return NETDEV_TX_OK;
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001791
1792mapping_unwind:
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001793 for (i = sky2->tx_prod; i != slot; i = RING_NEXT(i, sky2->tx_ring_size)) {
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001794 re = sky2->tx_ring + i;
1795
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001796 sky2_tx_unmap(hw->pdev, re);
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001797 }
1798
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00001799mapping_error:
1800 if (net_ratelimit())
1801 dev_warn(&hw->pdev->dev, "%s: tx mapping error\n", dev->name);
1802 dev_kfree_skb(skb);
1803 return NETDEV_TX_OK;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001804}
1805
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001806/*
Stephen Hemminger793b8832005-09-14 16:06:14 -07001807 * Free ring elements from starting at tx_cons until "done"
1808 *
Stephen Hemminger481cea42009-08-14 15:33:19 -07001809 * NB:
1810 * 1. The hardware will tell us about partial completion of multi-part
Stephen Hemminger291ea612006-09-26 11:57:41 -07001811 * buffers so make sure not to free skb to early.
Stephen Hemminger481cea42009-08-14 15:33:19 -07001812 * 2. This may run in parallel start_xmit because the it only
1813 * looks at the tail of the queue of FIFO (tx_cons), not
1814 * the head (tx_prod)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001815 */
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001816static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001817{
shemminger@osdl.orgd11c13e2005-09-27 15:02:56 -07001818 struct net_device *dev = sky2->netdev;
Stephen Hemminger291ea612006-09-26 11:57:41 -07001819 unsigned idx;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001820
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001821 BUG_ON(done >= sky2->tx_ring_size);
shemminger@osdl.org22247952005-11-30 11:45:19 -08001822
Stephen Hemminger291ea612006-09-26 11:57:41 -07001823 for (idx = sky2->tx_cons; idx != done;
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001824 idx = RING_NEXT(idx, sky2->tx_ring_size)) {
Stephen Hemminger291ea612006-09-26 11:57:41 -07001825 struct tx_ring_info *re = sky2->tx_ring + idx;
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001826 struct sk_buff *skb = re->skb;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001827
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001828 sky2_tx_unmap(sky2->hw->pdev, re);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001829
Stephen Hemminger6b84dac2009-08-18 15:17:09 +00001830 if (skb) {
Stephen Hemminger291ea612006-09-26 11:57:41 -07001831 if (unlikely(netif_msg_tx_done(sky2)))
1832 printk(KERN_DEBUG "%s: tx done %u\n",
1833 dev->name, idx);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07001834
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07001835 dev->stats.tx_packets++;
Stephen Hemmingerbd1c6862009-06-17 07:30:38 +00001836 dev->stats.tx_bytes += skb->len;
shemminger@linux-foundation.org2bf56fe2007-01-26 11:38:39 -08001837
Stephen Hemminger724b6942009-08-18 15:17:10 +00001838 dev_kfree_skb_any(skb);
Stephen Hemmingerbd1c6862009-06-17 07:30:38 +00001839
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00001840 sky2->tx_next = RING_NEXT(idx, sky2->tx_ring_size);
Stephen Hemminger291ea612006-09-26 11:57:41 -07001841 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07001842 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07001843
Stephen Hemminger291ea612006-09-26 11:57:41 -07001844 sky2->tx_cons = idx;
Stephen Hemminger50432cb2007-05-14 12:38:15 -07001845 smp_mb();
1846
Jarek Poplawski9db2f1b2010-01-04 08:48:41 +00001847 /* Wake unless it's detached, and called e.g. from sky2_down() */
1848 if (tx_avail(sky2) > MAX_SKB_TX_LE + 4 && netif_device_present(dev))
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001849 netif_wake_queue(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001850}
1851
Mike McCormack264bb4f2009-08-14 05:15:14 +00001852static void sky2_tx_reset(struct sky2_hw *hw, unsigned port)
Mike McCormacka5109962009-08-14 05:15:13 +00001853{
Mike McCormacka5109962009-08-14 05:15:13 +00001854 /* Disable Force Sync bit and Enable Alloc bit */
1855 sky2_write8(hw, SK_REG(port, TXA_CTRL),
1856 TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
1857
1858 /* Stop Interval Timer and Limit Counter of Tx Arbiter */
1859 sky2_write32(hw, SK_REG(port, TXA_ITI_INI), 0L);
1860 sky2_write32(hw, SK_REG(port, TXA_LIM_INI), 0L);
1861
1862 /* Reset the PCI FIFO of the async Tx queue */
1863 sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR),
1864 BMU_RST_SET | BMU_FIFO_RST);
1865
1866 /* Reset the Tx prefetch units */
1867 sky2_write32(hw, Y2_QADDR(txqaddr[port], PREF_UNIT_CTRL),
1868 PREF_UNIT_RST_SET);
1869
1870 sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET);
1871 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
1872}
1873
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001874/* Network shutdown */
1875static int sky2_down(struct net_device *dev)
1876{
1877 struct sky2_port *sky2 = netdev_priv(dev);
1878 struct sky2_hw *hw = sky2->hw;
1879 unsigned port = sky2->port;
1880 u16 ctrl;
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08001881 u32 imask;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001882
Stephen Hemminger1b537562005-12-20 15:08:07 -08001883 /* Never really got started! */
1884 if (!sky2->tx_le)
1885 return 0;
1886
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001887 if (netif_msg_ifdown(sky2))
1888 printk(KERN_INFO PFX "%s: disabling interface\n", dev->name);
1889
Stephen Hemmingerd104aca2009-06-17 07:30:32 +00001890 /* Force flow control off */
1891 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001892
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001893 /* Stop transmitter */
1894 sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_STOP);
1895 sky2_read32(hw, Q_ADDR(txqaddr[port], Q_CSR));
1896
1897 sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL),
Stephen Hemminger793b8832005-09-14 16:06:14 -07001898 RB_RST_SET | RB_DIS_OP_MD);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001899
1900 ctrl = gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemminger793b8832005-09-14 16:06:14 -07001901 ctrl &= ~(GM_GPCR_TX_ENA | GM_GPCR_RX_ENA);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001902 gma_write16(hw, port, GM_GP_CTRL, ctrl);
1903
1904 sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
1905
1906 /* Workaround shared GMAC reset */
Joe Perches8e95a202009-12-03 07:58:21 +00001907 if (!(hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0 &&
1908 port == 0 && hw->dev[1] && netif_running(hw->dev[1])))
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001909 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
1910
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001911 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001912
Stephen Hemminger6c835042009-06-17 07:30:35 +00001913 /* Force any delayed status interrrupt and NAPI */
1914 sky2_write32(hw, STAT_LEV_TIMER_CNT, 0);
1915 sky2_write32(hw, STAT_TX_TIMER_CNT, 0);
1916 sky2_write32(hw, STAT_ISR_TIMER_CNT, 0);
1917 sky2_read8(hw, STAT_ISR_TIMER_CTRL);
1918
Mike McCormacka947a392009-07-21 20:57:56 -07001919 sky2_rx_stop(sky2);
1920
1921 /* Disable port IRQ */
1922 imask = sky2_read32(hw, B0_IMSK);
1923 imask &= ~portirq_msk[port];
1924 sky2_write32(hw, B0_IMSK, imask);
1925 sky2_read32(hw, B0_IMSK);
1926
Stephen Hemminger6c835042009-06-17 07:30:35 +00001927 synchronize_irq(hw->pdev->irq);
1928 napi_synchronize(&hw->napi);
1929
Stephen Hemminger0da6d7b2009-08-14 05:15:15 +00001930 spin_lock_bh(&sky2->phy_lock);
Stephen Hemmingerb96936da72008-05-14 17:04:15 -07001931 sky2_phy_power_down(hw, port);
Stephen Hemminger0da6d7b2009-08-14 05:15:15 +00001932 spin_unlock_bh(&sky2->phy_lock);
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -07001933
Mike McCormack264bb4f2009-08-14 05:15:14 +00001934 sky2_tx_reset(hw, port);
1935
Stephen Hemminger481cea42009-08-14 15:33:19 -07001936 /* Free any pending frames stuck in HW queue */
1937 sky2_tx_complete(sky2, sky2->tx_prod);
1938
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001939 sky2_rx_clean(sky2);
1940
Mike McCormack90bbebb2009-09-01 03:21:35 +00001941 sky2_free_buffers(sky2);
Stephen Hemminger1b537562005-12-20 15:08:07 -08001942
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001943 return 0;
1944}
1945
1946static u16 sky2_phy_speed(const struct sky2_hw *hw, u16 aux)
1947{
Stephen Hemmingerea76e632007-09-19 15:36:44 -07001948 if (hw->flags & SKY2_HW_FIBRE_PHY)
Stephen Hemminger793b8832005-09-14 16:06:14 -07001949 return SPEED_1000;
1950
Stephen Hemminger05745c42007-09-19 15:36:45 -07001951 if (!(hw->flags & SKY2_HW_GIGABIT)) {
1952 if (aux & PHY_M_PS_SPEED_100)
1953 return SPEED_100;
1954 else
1955 return SPEED_10;
1956 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001957
1958 switch (aux & PHY_M_PS_SPEED_MSK) {
1959 case PHY_M_PS_SPEED_1000:
1960 return SPEED_1000;
1961 case PHY_M_PS_SPEED_100:
1962 return SPEED_100;
1963 default:
1964 return SPEED_10;
1965 }
1966}
1967
1968static void sky2_link_up(struct sky2_port *sky2)
1969{
1970 struct sky2_hw *hw = sky2->hw;
1971 unsigned port = sky2->port;
1972 u16 reg;
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07001973 static const char *fc_name[] = {
1974 [FC_NONE] = "none",
1975 [FC_TX] = "tx",
1976 [FC_RX] = "rx",
1977 [FC_BOTH] = "both",
1978 };
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001979
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001980 /* enable Rx/Tx */
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -07001981 reg = gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001982 reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA;
1983 gma_write16(hw, port, GM_GP_CTRL, reg);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001984
1985 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
1986
1987 netif_carrier_on(sky2->netdev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001988
Stephen Hemminger75e80682007-09-19 15:36:46 -07001989 mod_timer(&hw->watchdog_timer, jiffies + 1);
Stephen Hemminger32c2c302007-08-21 14:34:03 -07001990
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001991 /* Turn on link LED */
Stephen Hemminger793b8832005-09-14 16:06:14 -07001992 sky2_write8(hw, SK_REG(port, LNK_LED_REG),
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001993 LINKLED_ON | LINKLED_BLINK_OFF | LINKLED_LINKSYNC_OFF);
1994
1995 if (netif_msg_link(sky2))
1996 printk(KERN_INFO PFX
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07001997 "%s: Link is up at %d Mbps, %s duplex, flow control %s\n",
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07001998 sky2->netdev->name, sky2->speed,
1999 sky2->duplex == DUPLEX_FULL ? "full" : "half",
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07002000 fc_name[sky2->flow_status]);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002001}
2002
2003static void sky2_link_down(struct sky2_port *sky2)
2004{
2005 struct sky2_hw *hw = sky2->hw;
2006 unsigned port = sky2->port;
2007 u16 reg;
2008
2009 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);
2010
2011 reg = gma_read16(hw, port, GM_GP_CTRL);
2012 reg &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
2013 gma_write16(hw, port, GM_GP_CTRL, reg);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002014
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002015 netif_carrier_off(sky2->netdev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002016
Brandon Philips809aaaa2009-10-29 17:01:49 -07002017 /* Turn off link LED */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002018 sky2_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
2019
2020 if (netif_msg_link(sky2))
2021 printk(KERN_INFO PFX "%s: Link is down.\n", sky2->netdev->name);
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -07002022
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002023 sky2_phy_init(hw, port);
2024}
2025
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07002026static enum flow_control sky2_flow(int rx, int tx)
2027{
2028 if (rx)
2029 return tx ? FC_BOTH : FC_RX;
2030 else
2031 return tx ? FC_TX : FC_NONE;
2032}
2033
Stephen Hemminger793b8832005-09-14 16:06:14 -07002034static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux)
2035{
2036 struct sky2_hw *hw = sky2->hw;
2037 unsigned port = sky2->port;
Stephen Hemmingerda4c1ff2007-02-15 16:40:32 -08002038 u16 advert, lpa;
Stephen Hemminger793b8832005-09-14 16:06:14 -07002039
Stephen Hemmingerda4c1ff2007-02-15 16:40:32 -08002040 advert = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002041 lpa = gm_phy_read(hw, port, PHY_MARV_AUNE_LP);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002042 if (lpa & PHY_M_AN_RF) {
2043 printk(KERN_ERR PFX "%s: remote fault", sky2->netdev->name);
2044 return -1;
2045 }
2046
Stephen Hemminger793b8832005-09-14 16:06:14 -07002047 if (!(aux & PHY_M_PS_SPDUP_RES)) {
2048 printk(KERN_ERR PFX "%s: speed/duplex mismatch",
2049 sky2->netdev->name);
2050 return -1;
2051 }
2052
Stephen Hemminger793b8832005-09-14 16:06:14 -07002053 sky2->speed = sky2_phy_speed(hw, aux);
Stephen Hemminger7c74ac12006-10-17 10:24:08 -07002054 sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
Stephen Hemminger793b8832005-09-14 16:06:14 -07002055
Stephen Hemmingerda4c1ff2007-02-15 16:40:32 -08002056 /* Since the pause result bits seem to in different positions on
2057 * different chips. look at registers.
2058 */
Stephen Hemmingerea76e632007-09-19 15:36:44 -07002059 if (hw->flags & SKY2_HW_FIBRE_PHY) {
Stephen Hemmingerda4c1ff2007-02-15 16:40:32 -08002060 /* Shift for bits in fiber PHY */
2061 advert &= ~(ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM);
2062 lpa &= ~(LPA_PAUSE_CAP|LPA_PAUSE_ASYM);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002063
Stephen Hemmingerda4c1ff2007-02-15 16:40:32 -08002064 if (advert & ADVERTISE_1000XPAUSE)
2065 advert |= ADVERTISE_PAUSE_CAP;
2066 if (advert & ADVERTISE_1000XPSE_ASYM)
2067 advert |= ADVERTISE_PAUSE_ASYM;
2068 if (lpa & LPA_1000XPAUSE)
2069 lpa |= LPA_PAUSE_CAP;
2070 if (lpa & LPA_1000XPAUSE_ASYM)
2071 lpa |= LPA_PAUSE_ASYM;
2072 }
2073
2074 sky2->flow_status = FC_NONE;
2075 if (advert & ADVERTISE_PAUSE_CAP) {
2076 if (lpa & LPA_PAUSE_CAP)
2077 sky2->flow_status = FC_BOTH;
2078 else if (advert & ADVERTISE_PAUSE_ASYM)
2079 sky2->flow_status = FC_RX;
2080 } else if (advert & ADVERTISE_PAUSE_ASYM) {
2081 if ((lpa & LPA_PAUSE_CAP) && (lpa & LPA_PAUSE_ASYM))
2082 sky2->flow_status = FC_TX;
2083 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07002084
Joe Perches8e95a202009-12-03 07:58:21 +00002085 if (sky2->duplex == DUPLEX_HALF && sky2->speed < SPEED_1000 &&
2086 !(hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX))
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07002087 sky2->flow_status = FC_NONE;
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -07002088
Stephen Hemmingerda4c1ff2007-02-15 16:40:32 -08002089 if (sky2->flow_status & FC_TX)
Stephen Hemminger793b8832005-09-14 16:06:14 -07002090 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
2091 else
2092 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
2093
2094 return 0;
2095}
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002096
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002097/* Interrupt from PHY */
2098static void sky2_phy_intr(struct sky2_hw *hw, unsigned port)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002099{
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002100 struct net_device *dev = hw->dev[port];
2101 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002102 u16 istatus, phystat;
2103
Stephen Hemmingerebc646f2006-10-17 10:23:56 -07002104 if (!netif_running(dev))
2105 return;
2106
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002107 spin_lock(&sky2->phy_lock);
2108 istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT);
2109 phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT);
2110
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002111 if (netif_msg_intr(sky2))
2112 printk(KERN_INFO PFX "%s: phy interrupt status 0x%x 0x%x\n",
2113 sky2->netdev->name, istatus, phystat);
2114
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07002115 if (istatus & PHY_M_IS_AN_COMPL) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07002116 if (sky2_autoneg_done(sky2, phystat) == 0)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002117 sky2_link_up(sky2);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002118 goto out;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002119 }
2120
Stephen Hemminger793b8832005-09-14 16:06:14 -07002121 if (istatus & PHY_M_IS_LSP_CHANGE)
2122 sky2->speed = sky2_phy_speed(hw, phystat);
2123
2124 if (istatus & PHY_M_IS_DUP_CHANGE)
2125 sky2->duplex =
2126 (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
2127
2128 if (istatus & PHY_M_IS_LST_CHANGE) {
2129 if (phystat & PHY_M_PS_LINK_UP)
2130 sky2_link_up(sky2);
2131 else
2132 sky2_link_down(sky2);
2133 }
2134out:
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002135 spin_unlock(&sky2->phy_lock);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002136}
2137
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00002138/* Special quick link interrupt (Yukon-2 Optima only) */
2139static void sky2_qlink_intr(struct sky2_hw *hw)
2140{
2141 struct sky2_port *sky2 = netdev_priv(hw->dev[0]);
2142 u32 imask;
2143 u16 phy;
2144
2145 /* disable irq */
2146 imask = sky2_read32(hw, B0_IMSK);
2147 imask &= ~Y2_IS_PHY_QLNK;
2148 sky2_write32(hw, B0_IMSK, imask);
2149
2150 /* reset PHY Link Detect */
2151 phy = sky2_pci_read16(hw, PSM_CONFIG_REG4);
2152 sky2_pci_write16(hw, PSM_CONFIG_REG4, phy | 1);
2153
2154 sky2_link_up(sky2);
2155}
2156
Stephen Hemminger62335ab2007-02-06 10:45:42 -08002157/* Transmit timeout is only called if we are running, carrier is up
Stephen Hemminger302d1252006-01-17 13:43:20 -08002158 * and tx queue is full (stopped).
2159 */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002160static void sky2_tx_timeout(struct net_device *dev)
2161{
2162 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger8cc048e2005-12-09 11:35:07 -08002163 struct sky2_hw *hw = sky2->hw;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002164
2165 if (netif_msg_timer(sky2))
2166 printk(KERN_ERR PFX "%s: tx timeout\n", dev->name);
2167
Stephen Hemminger8f246642006-03-20 15:48:21 -08002168 printk(KERN_DEBUG PFX "%s: transmit ring %u .. %u report=%u done=%u\n",
Stephen Hemminger62335ab2007-02-06 10:45:42 -08002169 dev->name, sky2->tx_cons, sky2->tx_prod,
2170 sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX),
2171 sky2_read16(hw, Q_ADDR(txqaddr[sky2->port], Q_DONE)));
Stephen Hemminger8cc048e2005-12-09 11:35:07 -08002172
Stephen Hemminger81906792007-02-15 16:40:33 -08002173 /* can't restart safely under softirq */
2174 schedule_work(&hw->restart_work);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002175}
2176
2177static int sky2_change_mtu(struct net_device *dev, int new_mtu)
2178{
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002179 struct sky2_port *sky2 = netdev_priv(dev);
2180 struct sky2_hw *hw = sky2->hw;
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07002181 unsigned port = sky2->port;
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002182 int err;
2183 u16 ctl, mode;
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002184 u32 imask;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002185
2186 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
2187 return -EINVAL;
2188
Stephen Hemminger05745c42007-09-19 15:36:45 -07002189 if (new_mtu > ETH_DATA_LEN &&
2190 (hw->chip_id == CHIP_ID_YUKON_FE ||
2191 hw->chip_id == CHIP_ID_YUKON_FE_P))
Stephen Hemmingerd2adf4f2007-04-11 14:48:02 -07002192 return -EINVAL;
2193
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002194 if (!netif_running(dev)) {
2195 dev->mtu = new_mtu;
2196 return 0;
2197 }
2198
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002199 imask = sky2_read32(hw, B0_IMSK);
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002200 sky2_write32(hw, B0_IMSK, 0);
2201
shemminger@osdl.org018d1c62005-11-30 11:45:18 -08002202 dev->trans_start = jiffies; /* prevent tx timeout */
2203 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002204 napi_disable(&hw->napi);
shemminger@osdl.org018d1c62005-11-30 11:45:18 -08002205
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002206 synchronize_irq(hw->pdev->irq);
2207
Stephen Hemminger39dbd952008-02-04 19:45:13 -08002208 if (!(hw->flags & SKY2_HW_RAM_BUFFER))
Stephen Hemminger69161612007-06-04 17:23:26 -07002209 sky2_set_tx_stfwd(hw, port);
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07002210
2211 ctl = gma_read16(hw, port, GM_GP_CTRL);
2212 gma_write16(hw, port, GM_GP_CTRL, ctl & ~GM_GPCR_RX_ENA);
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002213 sky2_rx_stop(sky2);
2214 sky2_rx_clean(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002215
2216 dev->mtu = new_mtu;
Stephen Hemminger14d02632006-09-26 11:57:43 -07002217
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002218 mode = DATA_BLIND_VAL(DATA_BLIND_DEF) |
2219 GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002220
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002221 if (dev->mtu > ETH_DATA_LEN)
2222 mode |= GM_SMOD_JUMBO_ENA;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002223
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07002224 gma_write16(hw, port, GM_SERIAL_MODE, mode);
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002225
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07002226 sky2_write8(hw, RB_ADDR(rxqaddr[port], RB_CTRL), RB_ENA_OP_MD);
shemminger@osdl.org6b1a3ae2005-09-27 15:02:55 -07002227
2228 err = sky2_rx_start(sky2);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002229 sky2_write32(hw, B0_IMSK, imask);
shemminger@osdl.org018d1c62005-11-30 11:45:18 -08002230
David S. Millerd1d08d12008-01-07 20:53:33 -08002231 sky2_read32(hw, B0_Y2_SP_LISR);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002232 napi_enable(&hw->napi);
2233
Stephen Hemminger1b537562005-12-20 15:08:07 -08002234 if (err)
2235 dev_close(dev);
2236 else {
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07002237 gma_write16(hw, port, GM_GP_CTRL, ctl);
Stephen Hemminger1b537562005-12-20 15:08:07 -08002238
Stephen Hemminger1b537562005-12-20 15:08:07 -08002239 netif_wake_queue(dev);
2240 }
2241
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002242 return err;
2243}
2244
Stephen Hemminger14d02632006-09-26 11:57:43 -07002245/* For small just reuse existing skb for next receive */
2246static struct sk_buff *receive_copy(struct sky2_port *sky2,
2247 const struct rx_ring_info *re,
2248 unsigned length)
2249{
2250 struct sk_buff *skb;
2251
Eric Dumazet89d71a62009-10-13 05:34:20 +00002252 skb = netdev_alloc_skb_ip_align(sky2->netdev, length);
Stephen Hemminger14d02632006-09-26 11:57:43 -07002253 if (likely(skb)) {
Stephen Hemminger14d02632006-09-26 11:57:43 -07002254 pci_dma_sync_single_for_cpu(sky2->hw->pdev, re->data_addr,
2255 length, PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002256 skb_copy_from_linear_data(re->skb, skb->data, length);
Stephen Hemminger14d02632006-09-26 11:57:43 -07002257 skb->ip_summed = re->skb->ip_summed;
2258 skb->csum = re->skb->csum;
2259 pci_dma_sync_single_for_device(sky2->hw->pdev, re->data_addr,
2260 length, PCI_DMA_FROMDEVICE);
2261 re->skb->ip_summed = CHECKSUM_NONE;
Stephen Hemminger489b10c2006-10-03 16:39:12 -07002262 skb_put(skb, length);
Stephen Hemminger14d02632006-09-26 11:57:43 -07002263 }
2264 return skb;
2265}
2266
2267/* Adjust length of skb with fragments to match received data */
2268static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space,
2269 unsigned int length)
2270{
2271 int i, num_frags;
2272 unsigned int size;
2273
2274 /* put header into skb */
2275 size = min(length, hdr_space);
2276 skb->tail += size;
2277 skb->len += size;
2278 length -= size;
2279
2280 num_frags = skb_shinfo(skb)->nr_frags;
2281 for (i = 0; i < num_frags; i++) {
2282 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2283
2284 if (length == 0) {
2285 /* don't need this page */
2286 __free_page(frag->page);
2287 --skb_shinfo(skb)->nr_frags;
2288 } else {
2289 size = min(length, (unsigned) PAGE_SIZE);
2290
2291 frag->size = size;
2292 skb->data_len += size;
2293 skb->truesize += size;
2294 skb->len += size;
2295 length -= size;
2296 }
2297 }
2298}
2299
2300/* Normal packet - take skb from ring element and put in a new one */
2301static struct sk_buff *receive_new(struct sky2_port *sky2,
2302 struct rx_ring_info *re,
2303 unsigned int length)
2304{
2305 struct sk_buff *skb, *nskb;
2306 unsigned hdr_space = sky2->rx_data_size;
2307
Stephen Hemminger14d02632006-09-26 11:57:43 -07002308 /* Don't be tricky about reusing pages (yet) */
2309 nskb = sky2_rx_alloc(sky2);
2310 if (unlikely(!nskb))
2311 return NULL;
2312
2313 skb = re->skb;
2314 sky2_rx_unmap_skb(sky2->hw->pdev, re);
2315
2316 prefetch(skb->data);
2317 re->skb = nskb;
Stephen Hemminger454e6cb62009-02-03 11:27:28 +00002318 if (sky2_rx_map_skb(sky2->hw->pdev, re, hdr_space)) {
2319 dev_kfree_skb(nskb);
2320 re->skb = skb;
2321 return NULL;
2322 }
Stephen Hemminger14d02632006-09-26 11:57:43 -07002323
2324 if (skb_shinfo(skb)->nr_frags)
2325 skb_put_frags(skb, hdr_space, length);
2326 else
Stephen Hemminger489b10c2006-10-03 16:39:12 -07002327 skb_put(skb, length);
Stephen Hemminger14d02632006-09-26 11:57:43 -07002328 return skb;
2329}
2330
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002331/*
2332 * Receive one packet.
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07002333 * For larger packets, get new buffer.
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002334 */
shemminger@osdl.org497d7c82006-08-28 10:00:46 -07002335static struct sk_buff *sky2_receive(struct net_device *dev,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002336 u16 length, u32 status)
2337{
shemminger@osdl.org497d7c82006-08-28 10:00:46 -07002338 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger291ea612006-09-26 11:57:41 -07002339 struct rx_ring_info *re = sky2->rx_ring + sky2->rx_next;
Stephen Hemminger79e57d32005-09-19 15:42:33 -07002340 struct sk_buff *skb = NULL;
Stephen Hemmingerd6532232007-09-19 15:36:42 -07002341 u16 count = (status & GMR_FS_LEN) >> 16;
2342
2343#ifdef SKY2_VLAN_TAG_USED
2344 /* Account for vlan tag */
2345 if (sky2->vlgrp && (status & GMR_FS_VLAN))
2346 count -= VLAN_HLEN;
2347#endif
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002348
2349 if (unlikely(netif_msg_rx_status(sky2)))
2350 printk(KERN_DEBUG PFX "%s: rx slot %u status 0x%x len %d\n",
shemminger@osdl.org497d7c82006-08-28 10:00:46 -07002351 dev->name, sky2->rx_next, status, length);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002352
Stephen Hemminger793b8832005-09-14 16:06:14 -07002353 sky2->rx_next = (sky2->rx_next + 1) % sky2->rx_pending;
Stephen Hemmingerd70cd512005-12-09 11:35:09 -08002354 prefetch(sky2->rx_ring + sky2->rx_next);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002355
Stephen Hemminger3b12e012007-09-26 17:58:47 -07002356 /* This chip has hardware problems that generates bogus status.
2357 * So do only marginal checking and expect higher level protocols
2358 * to handle crap frames.
2359 */
2360 if (sky2->hw->chip_id == CHIP_ID_YUKON_FE_P &&
2361 sky2->hw->chip_rev == CHIP_REV_YU_FE2_A0 &&
2362 length != count)
2363 goto okay;
2364
shemminger@osdl.org42eeea02005-11-30 11:45:13 -08002365 if (status & GMR_FS_ANY_ERR)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002366 goto error;
2367
shemminger@osdl.org42eeea02005-11-30 11:45:13 -08002368 if (!(status & GMR_FS_RX_OK))
2369 goto resubmit;
2370
Stephen Hemmingerd6532232007-09-19 15:36:42 -07002371 /* if length reported by DMA does not match PHY, packet was truncated */
2372 if (length != count)
Stephen Hemminger3b12e012007-09-26 17:58:47 -07002373 goto len_error;
Stephen Hemminger71749532007-07-09 15:33:40 -07002374
Stephen Hemminger3b12e012007-09-26 17:58:47 -07002375okay:
Stephen Hemminger14d02632006-09-26 11:57:43 -07002376 if (length < copybreak)
2377 skb = receive_copy(sky2, re, length);
2378 else
2379 skb = receive_new(sky2, re, length);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002380resubmit:
Stephen Hemminger14d02632006-09-26 11:57:43 -07002381 sky2_rx_submit(sky2, re);
Stephen Hemminger79e57d32005-09-19 15:42:33 -07002382
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002383 return skb;
2384
Stephen Hemminger3b12e012007-09-26 17:58:47 -07002385len_error:
Stephen Hemminger71749532007-07-09 15:33:40 -07002386 /* Truncation of overlength packets
2387 causes PHY length to not match MAC length */
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002388 ++dev->stats.rx_length_errors;
Stephen Hemmingerd6532232007-09-19 15:36:42 -07002389 if (netif_msg_rx_err(sky2) && net_ratelimit())
Stephen Hemminger3b12e012007-09-26 17:58:47 -07002390 pr_info(PFX "%s: rx length error: status %#x length %d\n",
2391 dev->name, status, length);
Stephen Hemmingerd6532232007-09-19 15:36:42 -07002392 goto resubmit;
Stephen Hemminger71749532007-07-09 15:33:40 -07002393
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002394error:
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002395 ++dev->stats.rx_errors;
Stephen Hemmingerb6d77732006-10-17 10:24:16 -07002396 if (status & GMR_FS_RX_FF_OV) {
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002397 dev->stats.rx_over_errors++;
Stephen Hemmingerb6d77732006-10-17 10:24:16 -07002398 goto resubmit;
2399 }
Stephen Hemminger6e15b712005-12-20 15:08:09 -08002400
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002401 if (netif_msg_rx_err(sky2) && net_ratelimit())
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002402 printk(KERN_INFO PFX "%s: rx error, status 0x%x length %d\n",
shemminger@osdl.org497d7c82006-08-28 10:00:46 -07002403 dev->name, status, length);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002404
2405 if (status & (GMR_FS_LONG_ERR | GMR_FS_UN_SIZE))
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002406 dev->stats.rx_length_errors++;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002407 if (status & GMR_FS_FRAGMENT)
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002408 dev->stats.rx_frame_errors++;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002409 if (status & GMR_FS_CRC_ERR)
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002410 dev->stats.rx_crc_errors++;
Stephen Hemminger79e57d32005-09-19 15:42:33 -07002411
Stephen Hemminger793b8832005-09-14 16:06:14 -07002412 goto resubmit;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002413}
2414
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002415/* Transmit complete */
2416static inline void sky2_tx_done(struct net_device *dev, u16 last)
Stephen Hemminger13b97b72005-12-09 11:35:03 -08002417{
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002418 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger302d1252006-01-17 13:43:20 -08002419
Stephen Hemminger49d4b8b2009-08-14 13:33:17 +00002420 if (netif_running(dev))
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002421 sky2_tx_complete(sky2, last);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002422}
2423
Stephen Hemminger37e5a242009-06-17 07:30:39 +00002424static inline void sky2_skb_rx(const struct sky2_port *sky2,
2425 u32 status, struct sk_buff *skb)
2426{
2427#ifdef SKY2_VLAN_TAG_USED
2428 u16 vlan_tag = be16_to_cpu(sky2->rx_tag);
2429 if (sky2->vlgrp && (status & GMR_FS_VLAN)) {
2430 if (skb->ip_summed == CHECKSUM_NONE)
2431 vlan_hwaccel_receive_skb(skb, sky2->vlgrp, vlan_tag);
2432 else
2433 vlan_gro_receive(&sky2->hw->napi, sky2->vlgrp,
2434 vlan_tag, skb);
2435 return;
2436 }
2437#endif
2438 if (skb->ip_summed == CHECKSUM_NONE)
2439 netif_receive_skb(skb);
2440 else
2441 napi_gro_receive(&sky2->hw->napi, skb);
2442}
2443
Stephen Hemmingerbf15fe92009-06-17 07:30:36 +00002444static inline void sky2_rx_done(struct sky2_hw *hw, unsigned port,
2445 unsigned packets, unsigned bytes)
2446{
2447 if (packets) {
2448 struct net_device *dev = hw->dev[port];
2449
2450 dev->stats.rx_packets += packets;
2451 dev->stats.rx_bytes += bytes;
2452 dev->last_rx = jiffies;
2453 sky2_rx_update(netdev_priv(dev), rxqaddr[port]);
2454 }
2455}
2456
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002457/* Process status response ring */
Stephen Hemminger26691832007-10-11 18:31:13 -07002458static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002459{
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002460 int work_done = 0;
Stephen Hemmingerbf15fe92009-06-17 07:30:36 +00002461 unsigned int total_bytes[2] = { 0 };
2462 unsigned int total_packets[2] = { 0 };
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002463
Stephen Hemmingeraf2a58a2005-12-09 11:35:04 -08002464 rmb();
Stephen Hemminger26691832007-10-11 18:31:13 -07002465 do {
Stephen Hemminger55c9dd32007-07-09 15:33:37 -07002466 struct sky2_port *sky2;
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002467 struct sky2_status_le *le = hw->st_le + hw->st_idx;
Stephen Hemmingerab5adec2007-11-05 15:52:09 -08002468 unsigned port;
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002469 struct net_device *dev;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002470 struct sk_buff *skb;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002471 u32 status;
2472 u16 length;
Stephen Hemmingerab5adec2007-11-05 15:52:09 -08002473 u8 opcode = le->opcode;
2474
2475 if (!(opcode & HW_OWNER))
2476 break;
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002477
Stephen Hemmingercb5d9542006-05-08 15:11:29 -07002478 hw->st_idx = RING_NEXT(hw->st_idx, STATUS_RING_SIZE);
shemminger@osdl.orgbea86102005-10-26 12:16:10 -07002479
Stephen Hemmingerab5adec2007-11-05 15:52:09 -08002480 port = le->css & CSS_LINK_BIT;
Stephen Hemminger69161612007-06-04 17:23:26 -07002481 dev = hw->dev[port];
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002482 sky2 = netdev_priv(dev);
Stephen Hemmingerf65b1382006-09-06 12:45:02 -07002483 length = le16_to_cpu(le->length);
2484 status = le32_to_cpu(le->status);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002485
Stephen Hemmingerab5adec2007-11-05 15:52:09 -08002486 le->opcode = 0;
2487 switch (opcode & ~HW_OWNER) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002488 case OP_RXSTAT:
Stephen Hemmingerbf15fe92009-06-17 07:30:36 +00002489 total_packets[port]++;
2490 total_bytes[port] += length;
shemminger@osdl.org497d7c82006-08-28 10:00:46 -07002491 skb = sky2_receive(dev, length, status);
Stephen Hemminger3225b912007-05-14 12:38:12 -07002492 if (unlikely(!skb)) {
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002493 dev->stats.rx_dropped++;
Stephen Hemminger55c9dd32007-07-09 15:33:37 -07002494 break;
Stephen Hemminger3225b912007-05-14 12:38:12 -07002495 }
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002496
Stephen Hemminger69161612007-06-04 17:23:26 -07002497 /* This chip reports checksum status differently */
Stephen Hemminger05745c42007-09-19 15:36:45 -07002498 if (hw->flags & SKY2_HW_NEW_LE) {
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07002499 if ((sky2->flags & SKY2_FLAG_RX_CHECKSUM) &&
Stephen Hemminger69161612007-06-04 17:23:26 -07002500 (le->css & (CSS_ISIPV4 | CSS_ISIPV6)) &&
2501 (le->css & CSS_TCPUDPCSOK))
2502 skb->ip_summed = CHECKSUM_UNNECESSARY;
2503 else
2504 skb->ip_summed = CHECKSUM_NONE;
2505 }
2506
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002507 skb->protocol = eth_type_trans(skb, dev);
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002508
Stephen Hemminger37e5a242009-06-17 07:30:39 +00002509 sky2_skb_rx(sky2, status, skb);
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002510
Stephen Hemminger22e11702006-07-12 15:23:48 -07002511 /* Stop after net poll weight */
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002512 if (++work_done >= to_do)
2513 goto exit_loop;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002514 break;
2515
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07002516#ifdef SKY2_VLAN_TAG_USED
2517 case OP_RXVLAN:
2518 sky2->rx_tag = length;
2519 break;
2520
2521 case OP_RXCHKSVLAN:
2522 sky2->rx_tag = length;
2523 /* fall through */
2524#endif
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002525 case OP_RXCHKS:
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07002526 if (!(sky2->flags & SKY2_FLAG_RX_CHECKSUM))
Stephen Hemminger87418302007-03-08 12:42:30 -08002527 break;
2528
Stephen Hemminger05745c42007-09-19 15:36:45 -07002529 /* If this happens then driver assuming wrong format */
2530 if (unlikely(hw->flags & SKY2_HW_NEW_LE)) {
2531 if (net_ratelimit())
2532 printk(KERN_NOTICE "%s: unexpected"
2533 " checksum status\n",
2534 dev->name);
Stephen Hemminger69161612007-06-04 17:23:26 -07002535 break;
Stephen Hemminger05745c42007-09-19 15:36:45 -07002536 }
Stephen Hemminger69161612007-06-04 17:23:26 -07002537
Stephen Hemminger87418302007-03-08 12:42:30 -08002538 /* Both checksum counters are programmed to start at
2539 * the same offset, so unless there is a problem they
2540 * should match. This failure is an early indication that
2541 * hardware receive checksumming won't work.
2542 */
2543 if (likely(status >> 16 == (status & 0xffff))) {
2544 skb = sky2->rx_ring[sky2->rx_next].skb;
2545 skb->ip_summed = CHECKSUM_COMPLETE;
Anton Vorontsovb9389792009-06-26 09:28:42 -07002546 skb->csum = le16_to_cpu(status);
Stephen Hemminger87418302007-03-08 12:42:30 -08002547 } else {
2548 printk(KERN_NOTICE PFX "%s: hardware receive "
2549 "checksum problem (status = %#x)\n",
2550 dev->name, status);
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07002551 sky2->flags &= ~SKY2_FLAG_RX_CHECKSUM;
2552
Stephen Hemminger87418302007-03-08 12:42:30 -08002553 sky2_write32(sky2->hw,
Stephen Hemminger69161612007-06-04 17:23:26 -07002554 Q_ADDR(rxqaddr[port], Q_CSR),
Stephen Hemminger87418302007-03-08 12:42:30 -08002555 BMU_DIS_RX_CHKSUM);
2556 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002557 break;
2558
2559 case OP_TXINDEXLE:
Stephen Hemminger13b97b72005-12-09 11:35:03 -08002560 /* TX index reports status for both ports */
Stephen Hemmingerf55925d2006-05-08 15:11:28 -07002561 sky2_tx_done(hw->dev[0], status & 0xfff);
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002562 if (hw->dev[1])
2563 sky2_tx_done(hw->dev[1],
2564 ((status >> 24) & 0xff)
2565 | (u16)(length & 0xf) << 8);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002566 break;
2567
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002568 default:
2569 if (net_ratelimit())
Stephen Hemminger793b8832005-09-14 16:06:14 -07002570 printk(KERN_WARNING PFX
Stephen Hemmingerab5adec2007-11-05 15:52:09 -08002571 "unknown status opcode 0x%x\n", opcode);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002572 }
Stephen Hemminger26691832007-10-11 18:31:13 -07002573 } while (hw->st_idx != idx);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002574
Stephen Hemmingerfe2a24d2006-08-01 11:55:23 -07002575 /* Fully processed status ring so clear irq */
2576 sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ);
2577
shemminger@osdl.org13210ce2005-11-30 11:45:14 -08002578exit_loop:
Stephen Hemmingerbf15fe92009-06-17 07:30:36 +00002579 sky2_rx_done(hw, 0, total_packets[0], total_bytes[0]);
2580 sky2_rx_done(hw, 1, total_packets[1], total_bytes[1]);
Stephen Hemminger22e11702006-07-12 15:23:48 -07002581
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002582 return work_done;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002583}
2584
2585static void sky2_hw_error(struct sky2_hw *hw, unsigned port, u32 status)
2586{
2587 struct net_device *dev = hw->dev[port];
2588
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002589 if (net_ratelimit())
2590 printk(KERN_INFO PFX "%s: hw error interrupt status 0x%x\n",
2591 dev->name, status);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002592
2593 if (status & Y2_IS_PAR_RD1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002594 if (net_ratelimit())
2595 printk(KERN_ERR PFX "%s: ram data read parity error\n",
2596 dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002597 /* Clear IRQ */
2598 sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_RD_PERR);
2599 }
2600
2601 if (status & Y2_IS_PAR_WR1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002602 if (net_ratelimit())
2603 printk(KERN_ERR PFX "%s: ram data write parity error\n",
2604 dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002605
2606 sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_WR_PERR);
2607 }
2608
2609 if (status & Y2_IS_PAR_MAC1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002610 if (net_ratelimit())
2611 printk(KERN_ERR PFX "%s: MAC parity error\n", dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002612 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_PE);
2613 }
2614
2615 if (status & Y2_IS_PAR_RX1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002616 if (net_ratelimit())
2617 printk(KERN_ERR PFX "%s: RX parity error\n", dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002618 sky2_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), BMU_CLR_IRQ_PAR);
2619 }
2620
2621 if (status & Y2_IS_TCP_TXA1) {
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002622 if (net_ratelimit())
2623 printk(KERN_ERR PFX "%s: TCP segmentation error\n",
2624 dev->name);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002625 sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_CLR_IRQ_TCP);
2626 }
2627}
2628
2629static void sky2_hw_intr(struct sky2_hw *hw)
2630{
Stephen Hemminger555382c2007-08-29 12:58:14 -07002631 struct pci_dev *pdev = hw->pdev;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002632 u32 status = sky2_read32(hw, B0_HWE_ISRC);
Stephen Hemminger555382c2007-08-29 12:58:14 -07002633 u32 hwmsk = sky2_read32(hw, B0_HWE_IMSK);
2634
2635 status &= hwmsk;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002636
Stephen Hemminger793b8832005-09-14 16:06:14 -07002637 if (status & Y2_IS_TIST_OV)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002638 sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002639
2640 if (status & (Y2_IS_MST_ERR | Y2_IS_IRQ_STAT)) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07002641 u16 pci_err;
2642
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08002643 pci_err = sky2_pci_read16(hw, PCI_STATUS);
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002644 if (net_ratelimit())
Stephen Hemminger555382c2007-08-29 12:58:14 -07002645 dev_err(&pdev->dev, "PCI hardware error (0x%x)\n",
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08002646 pci_err);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002647
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08002648 sky2_pci_write16(hw, PCI_STATUS,
Stephen Hemminger167f53d2007-09-25 19:01:02 -07002649 pci_err | PCI_STATUS_ERROR_BITS);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002650 }
2651
2652 if (status & Y2_IS_PCI_EXP) {
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07002653 /* PCI-Express uncorrectable Error occurred */
Stephen Hemminger555382c2007-08-29 12:58:14 -07002654 u32 err;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002655
Stephen Hemminger7782c8c2007-11-27 11:02:32 -08002656 err = sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
2657 sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
2658 0xfffffffful);
Stephen Hemminger3be92a72006-01-17 13:43:17 -08002659 if (net_ratelimit())
Stephen Hemminger555382c2007-08-29 12:58:14 -07002660 dev_err(&pdev->dev, "PCI Express error (0x%x)\n", err);
Stephen Hemmingercf06ffb2007-11-05 15:52:13 -08002661
Stephen Hemminger7782c8c2007-11-27 11:02:32 -08002662 sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002663 }
2664
2665 if (status & Y2_HWE_L1_MASK)
2666 sky2_hw_error(hw, 0, status);
2667 status >>= 8;
2668 if (status & Y2_HWE_L1_MASK)
2669 sky2_hw_error(hw, 1, status);
2670}
2671
2672static void sky2_mac_intr(struct sky2_hw *hw, unsigned port)
2673{
2674 struct net_device *dev = hw->dev[port];
2675 struct sky2_port *sky2 = netdev_priv(dev);
2676 u8 status = sky2_read8(hw, SK_REG(port, GMAC_IRQ_SRC));
2677
2678 if (netif_msg_intr(sky2))
2679 printk(KERN_INFO PFX "%s: mac interrupt status 0x%x\n",
2680 dev->name, status);
2681
Stephen Hemmingera3caead2007-05-14 12:38:13 -07002682 if (status & GM_IS_RX_CO_OV)
2683 gma_read16(hw, port, GM_RX_IRQ_SRC);
2684
2685 if (status & GM_IS_TX_CO_OV)
2686 gma_read16(hw, port, GM_TX_IRQ_SRC);
2687
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002688 if (status & GM_IS_RX_FF_OR) {
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002689 ++dev->stats.rx_fifo_errors;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002690 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO);
2691 }
2692
2693 if (status & GM_IS_TX_FF_UR) {
Stephen Hemminger7138a0f2007-10-11 19:48:22 -07002694 ++dev->stats.tx_fifo_errors;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002695 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU);
2696 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002697}
2698
Stephen Hemminger40b01722007-04-11 14:47:59 -07002699/* This should never happen it is a bug. */
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002700static void sky2_le_error(struct sky2_hw *hw, unsigned port, u16 q)
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002701{
2702 struct net_device *dev = hw->dev[port];
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002703 u16 idx = sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_GET_IDX));
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002704
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002705 dev_err(&hw->pdev->dev, PFX
2706 "%s: descriptor error q=%#x get=%u put=%u\n",
2707 dev->name, (unsigned) q, (unsigned) idx,
2708 (unsigned) sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX)));
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002709
Stephen Hemminger40b01722007-04-11 14:47:59 -07002710 sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_IRQ_CHK);
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002711}
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002712
Stephen Hemminger75e80682007-09-19 15:36:46 -07002713static int sky2_rx_hung(struct net_device *dev)
2714{
2715 struct sky2_port *sky2 = netdev_priv(dev);
2716 struct sky2_hw *hw = sky2->hw;
2717 unsigned port = sky2->port;
2718 unsigned rxq = rxqaddr[port];
2719 u32 mac_rp = sky2_read32(hw, SK_REG(port, RX_GMF_RP));
2720 u8 mac_lev = sky2_read8(hw, SK_REG(port, RX_GMF_RLEV));
2721 u8 fifo_rp = sky2_read8(hw, Q_ADDR(rxq, Q_RP));
2722 u8 fifo_lev = sky2_read8(hw, Q_ADDR(rxq, Q_RL));
2723
2724 /* If idle and MAC or PCI is stuck */
2725 if (sky2->check.last == dev->last_rx &&
2726 ((mac_rp == sky2->check.mac_rp &&
2727 mac_lev != 0 && mac_lev >= sky2->check.mac_lev) ||
2728 /* Check if the PCI RX hang */
2729 (fifo_rp == sky2->check.fifo_rp &&
2730 fifo_lev != 0 && fifo_lev >= sky2->check.fifo_lev))) {
2731 printk(KERN_DEBUG PFX "%s: hung mac %d:%d fifo %d (%d:%d)\n",
2732 dev->name, mac_lev, mac_rp, fifo_lev, fifo_rp,
2733 sky2_read8(hw, Q_ADDR(rxq, Q_WP)));
2734 return 1;
2735 } else {
2736 sky2->check.last = dev->last_rx;
2737 sky2->check.mac_rp = mac_rp;
2738 sky2->check.mac_lev = mac_lev;
2739 sky2->check.fifo_rp = fifo_rp;
2740 sky2->check.fifo_lev = fifo_lev;
2741 return 0;
2742 }
2743}
2744
Stephen Hemminger32c2c302007-08-21 14:34:03 -07002745static void sky2_watchdog(unsigned long arg)
Stephen Hemmingerd27ed382006-04-25 10:58:51 -07002746{
Stephen Hemminger01bd7562006-05-08 15:11:30 -07002747 struct sky2_hw *hw = (struct sky2_hw *) arg;
Stephen Hemmingerd27ed382006-04-25 10:58:51 -07002748
Stephen Hemminger75e80682007-09-19 15:36:46 -07002749 /* Check for lost IRQ once a second */
Stephen Hemminger32c2c302007-08-21 14:34:03 -07002750 if (sky2_read32(hw, B0_ISRC)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002751 napi_schedule(&hw->napi);
Stephen Hemminger75e80682007-09-19 15:36:46 -07002752 } else {
2753 int i, active = 0;
2754
2755 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002756 struct net_device *dev = hw->dev[i];
Stephen Hemminger75e80682007-09-19 15:36:46 -07002757 if (!netif_running(dev))
2758 continue;
2759 ++active;
2760
2761 /* For chips with Rx FIFO, check if stuck */
Stephen Hemminger39dbd952008-02-04 19:45:13 -08002762 if ((hw->flags & SKY2_HW_RAM_BUFFER) &&
Stephen Hemminger75e80682007-09-19 15:36:46 -07002763 sky2_rx_hung(dev)) {
2764 pr_info(PFX "%s: receiver hang detected\n",
2765 dev->name);
2766 schedule_work(&hw->restart_work);
2767 return;
2768 }
2769 }
2770
2771 if (active == 0)
2772 return;
Stephen Hemminger32c2c302007-08-21 14:34:03 -07002773 }
2774
Stephen Hemminger75e80682007-09-19 15:36:46 -07002775 mod_timer(&hw->watchdog_timer, round_jiffies(jiffies + HZ));
Stephen Hemmingerd27ed382006-04-25 10:58:51 -07002776}
2777
Stephen Hemminger40b01722007-04-11 14:47:59 -07002778/* Hardware/software error handling */
2779static void sky2_err_intr(struct sky2_hw *hw, u32 status)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002780{
Stephen Hemminger40b01722007-04-11 14:47:59 -07002781 if (net_ratelimit())
2782 dev_warn(&hw->pdev->dev, "error interrupt status=%#x\n", status);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002783
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002784 if (status & Y2_IS_HW_ERR)
2785 sky2_hw_intr(hw);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002786
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002787 if (status & Y2_IS_IRQ_MAC1)
2788 sky2_mac_intr(hw, 0);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002789
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002790 if (status & Y2_IS_IRQ_MAC2)
2791 sky2_mac_intr(hw, 1);
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002792
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002793 if (status & Y2_IS_CHK_RX1)
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002794 sky2_le_error(hw, 0, Q_R1);
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002795
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002796 if (status & Y2_IS_CHK_RX2)
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002797 sky2_le_error(hw, 1, Q_R2);
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002798
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002799 if (status & Y2_IS_CHK_TXA1)
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002800 sky2_le_error(hw, 0, Q_XA1);
Stephen Hemmingerd2579242006-03-20 15:48:22 -08002801
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002802 if (status & Y2_IS_CHK_TXA2)
Stephen Hemmingerc1197312009-08-18 15:17:07 +00002803 sky2_le_error(hw, 1, Q_XA2);
Stephen Hemminger40b01722007-04-11 14:47:59 -07002804}
2805
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002806static int sky2_poll(struct napi_struct *napi, int work_limit)
Stephen Hemminger40b01722007-04-11 14:47:59 -07002807{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002808 struct sky2_hw *hw = container_of(napi, struct sky2_hw, napi);
Stephen Hemminger40b01722007-04-11 14:47:59 -07002809 u32 status = sky2_read32(hw, B0_Y2_SP_EISR);
David S. Miller6f535762007-10-11 18:08:29 -07002810 int work_done = 0;
Stephen Hemminger26691832007-10-11 18:31:13 -07002811 u16 idx;
Stephen Hemminger40b01722007-04-11 14:47:59 -07002812
2813 if (unlikely(status & Y2_IS_ERROR))
2814 sky2_err_intr(hw, status);
2815
2816 if (status & Y2_IS_IRQ_PHY1)
2817 sky2_phy_intr(hw, 0);
2818
2819 if (status & Y2_IS_IRQ_PHY2)
2820 sky2_phy_intr(hw, 1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002821
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00002822 if (status & Y2_IS_PHY_QLNK)
2823 sky2_qlink_intr(hw);
2824
Stephen Hemminger26691832007-10-11 18:31:13 -07002825 while ((idx = sky2_read16(hw, STAT_PUT_IDX)) != hw->st_idx) {
2826 work_done += sky2_status_intr(hw, work_limit - work_done, idx);
Stephen Hemminger1e5f1282006-05-08 15:11:27 -07002827
David S. Miller6f535762007-10-11 18:08:29 -07002828 if (work_done >= work_limit)
Stephen Hemminger26691832007-10-11 18:31:13 -07002829 goto done;
Stephen Hemmingerfe2a24d2006-08-01 11:55:23 -07002830 }
David S. Miller6f535762007-10-11 18:08:29 -07002831
Stephen Hemminger26691832007-10-11 18:31:13 -07002832 napi_complete(napi);
2833 sky2_read32(hw, B0_Y2_SP_LISR);
2834done:
2835
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002836 return work_done;
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002837}
2838
David Howells7d12e782006-10-05 14:55:46 +01002839static irqreturn_t sky2_intr(int irq, void *dev_id)
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002840{
2841 struct sky2_hw *hw = dev_id;
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08002842 u32 status;
2843
2844 /* Reading this mask interrupts as side effect */
2845 status = sky2_read32(hw, B0_Y2_SP_ISRC2);
2846 if (status == 0 || status == ~0)
2847 return IRQ_NONE;
2848
2849 prefetch(&hw->st_le[hw->st_idx]);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002850
2851 napi_schedule(&hw->napi);
Stephen Hemminger793b8832005-09-14 16:06:14 -07002852
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002853 return IRQ_HANDLED;
2854}
2855
2856#ifdef CONFIG_NET_POLL_CONTROLLER
2857static void sky2_netpoll(struct net_device *dev)
2858{
2859 struct sky2_port *sky2 = netdev_priv(dev);
2860
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002861 napi_schedule(&sky2->hw->napi);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002862}
2863#endif
2864
2865/* Chip internal frequency for clock calculations */
Stephen Hemminger05745c42007-09-19 15:36:45 -07002866static u32 sky2_mhz(const struct sky2_hw *hw)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002867{
Stephen Hemminger793b8832005-09-14 16:06:14 -07002868 switch (hw->chip_id) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002869 case CHIP_ID_YUKON_EC:
shemminger@osdl.org5a5b1ea2005-11-30 11:45:15 -08002870 case CHIP_ID_YUKON_EC_U:
Stephen Hemminger93745492007-02-06 10:45:43 -08002871 case CHIP_ID_YUKON_EX:
Stephen Hemmingered4d4162008-01-10 16:14:14 -08002872 case CHIP_ID_YUKON_SUPR:
Stephen Hemminger0ce8b982008-06-17 09:04:27 -07002873 case CHIP_ID_YUKON_UL_2:
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00002874 case CHIP_ID_YUKON_OPT:
Stephen Hemminger05745c42007-09-19 15:36:45 -07002875 return 125;
2876
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002877 case CHIP_ID_YUKON_FE:
Stephen Hemminger05745c42007-09-19 15:36:45 -07002878 return 100;
2879
2880 case CHIP_ID_YUKON_FE_P:
2881 return 50;
2882
2883 case CHIP_ID_YUKON_XL:
2884 return 156;
2885
2886 default:
2887 BUG();
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002888 }
2889}
2890
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002891static inline u32 sky2_us2clk(const struct sky2_hw *hw, u32 us)
2892{
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08002893 return sky2_mhz(hw) * us;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002894}
2895
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08002896static inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk)
2897{
2898 return clk / sky2_mhz(hw);
2899}
2900
2901
Stephen Hemmingere3173832007-02-06 10:45:39 -08002902static int __devinit sky2_init(struct sky2_hw *hw)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002903{
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07002904 u8 t8;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002905
Stephen Hemminger167f53d2007-09-25 19:01:02 -07002906 /* Enable all clocks and check for bad PCI access */
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08002907 sky2_pci_write32(hw, PCI_DEV_REG3, 0);
Stephen Hemminger451af332007-06-04 17:23:24 -07002908
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002909 sky2_write8(hw, B0_CTST, CS_RST_CLR);
Stephen Hemminger08c06d82006-01-30 11:37:54 -08002910
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002911 hw->chip_id = sky2_read8(hw, B2_CHIP_ID);
Stephen Hemmingerea76e632007-09-19 15:36:44 -07002912 hw->chip_rev = (sky2_read8(hw, B2_MAC_CFG) & CFG_CHIP_R_MSK) >> 4;
2913
2914 switch(hw->chip_id) {
2915 case CHIP_ID_YUKON_XL:
Stephen Hemminger39dbd952008-02-04 19:45:13 -08002916 hw->flags = SKY2_HW_GIGABIT | SKY2_HW_NEWER_PHY;
Stephen Hemmingerea76e632007-09-19 15:36:44 -07002917 break;
2918
2919 case CHIP_ID_YUKON_EC_U:
2920 hw->flags = SKY2_HW_GIGABIT
2921 | SKY2_HW_NEWER_PHY
2922 | SKY2_HW_ADV_POWER_CTL;
2923 break;
2924
2925 case CHIP_ID_YUKON_EX:
2926 hw->flags = SKY2_HW_GIGABIT
2927 | SKY2_HW_NEWER_PHY
2928 | SKY2_HW_NEW_LE
2929 | SKY2_HW_ADV_POWER_CTL;
2930
2931 /* New transmit checksum */
2932 if (hw->chip_rev != CHIP_REV_YU_EX_B0)
2933 hw->flags |= SKY2_HW_AUTO_TX_SUM;
2934 break;
2935
2936 case CHIP_ID_YUKON_EC:
2937 /* This rev is really old, and requires untested workarounds */
2938 if (hw->chip_rev == CHIP_REV_YU_EC_A1) {
2939 dev_err(&hw->pdev->dev, "unsupported revision Yukon-EC rev A1\n");
2940 return -EOPNOTSUPP;
2941 }
Stephen Hemminger39dbd952008-02-04 19:45:13 -08002942 hw->flags = SKY2_HW_GIGABIT;
Stephen Hemmingerea76e632007-09-19 15:36:44 -07002943 break;
2944
2945 case CHIP_ID_YUKON_FE:
Stephen Hemmingerea76e632007-09-19 15:36:44 -07002946 break;
2947
Stephen Hemminger05745c42007-09-19 15:36:45 -07002948 case CHIP_ID_YUKON_FE_P:
2949 hw->flags = SKY2_HW_NEWER_PHY
2950 | SKY2_HW_NEW_LE
2951 | SKY2_HW_AUTO_TX_SUM
2952 | SKY2_HW_ADV_POWER_CTL;
2953 break;
Stephen Hemmingered4d4162008-01-10 16:14:14 -08002954
2955 case CHIP_ID_YUKON_SUPR:
2956 hw->flags = SKY2_HW_GIGABIT
2957 | SKY2_HW_NEWER_PHY
2958 | SKY2_HW_NEW_LE
2959 | SKY2_HW_AUTO_TX_SUM
2960 | SKY2_HW_ADV_POWER_CTL;
2961 break;
2962
Stephen Hemminger0ce8b982008-06-17 09:04:27 -07002963 case CHIP_ID_YUKON_UL_2:
Takashi Iwaib3386822009-12-03 05:12:01 +00002964 hw->flags = SKY2_HW_GIGABIT
2965 | SKY2_HW_ADV_POWER_CTL;
2966 break;
2967
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00002968 case CHIP_ID_YUKON_OPT:
Stephen Hemminger0ce8b982008-06-17 09:04:27 -07002969 hw->flags = SKY2_HW_GIGABIT
Takashi Iwaib3386822009-12-03 05:12:01 +00002970 | SKY2_HW_NEW_LE
Stephen Hemminger0ce8b982008-06-17 09:04:27 -07002971 | SKY2_HW_ADV_POWER_CTL;
2972 break;
2973
Stephen Hemmingerea76e632007-09-19 15:36:44 -07002974 default:
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08002975 dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n",
2976 hw->chip_id);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07002977 return -EOPNOTSUPP;
2978 }
2979
Stephen Hemmingere3173832007-02-06 10:45:39 -08002980 hw->pmd_type = sky2_read8(hw, B2_PMD_TYP);
Stephen Hemmingerea76e632007-09-19 15:36:44 -07002981 if (hw->pmd_type == 'L' || hw->pmd_type == 'S' || hw->pmd_type == 'P')
2982 hw->flags |= SKY2_HW_FIBRE_PHY;
2983
Stephen Hemmingere3173832007-02-06 10:45:39 -08002984 hw->ports = 1;
2985 t8 = sky2_read8(hw, B2_Y2_HW_RES);
2986 if ((t8 & CFG_DUAL_MAC_MSK) == CFG_DUAL_MAC_MSK) {
2987 if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC))
2988 ++hw->ports;
2989 }
2990
Mike McCormack74a61eb2009-09-21 04:08:52 +00002991 if (sky2_read8(hw, B2_E_0))
2992 hw->flags |= SKY2_HW_RAM_BUFFER;
2993
Stephen Hemmingere3173832007-02-06 10:45:39 -08002994 return 0;
2995}
2996
2997static void sky2_reset(struct sky2_hw *hw)
2998{
Stephen Hemminger555382c2007-08-29 12:58:14 -07002999 struct pci_dev *pdev = hw->pdev;
Stephen Hemmingere3173832007-02-06 10:45:39 -08003000 u16 status;
Stephen Hemminger555382c2007-08-29 12:58:14 -07003001 int i, cap;
3002 u32 hwe_mask = Y2_HWE_ALL_MASK;
Stephen Hemmingere3173832007-02-06 10:45:39 -08003003
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003004 /* disable ASF */
Stephen Hemminger4f44d8b2007-04-11 14:48:00 -07003005 if (hw->chip_id == CHIP_ID_YUKON_EX) {
3006 status = sky2_read16(hw, HCU_CCSR);
3007 status &= ~(HCU_CCSR_AHB_RST | HCU_CCSR_CPU_RST_MODE |
3008 HCU_CCSR_UC_STATE_MSK);
3009 sky2_write16(hw, HCU_CCSR, status);
3010 } else
3011 sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET);
3012 sky2_write16(hw, B0_CTST, Y2_ASF_DISABLE);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003013
3014 /* do a SW reset */
3015 sky2_write8(hw, B0_CTST, CS_RST_SET);
3016 sky2_write8(hw, B0_CTST, CS_RST_CLR);
3017
Stephen Hemmingerac93a392007-11-05 15:52:08 -08003018 /* allow writes to PCI config */
3019 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
3020
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003021 /* clear PCI errors, if any */
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08003022 status = sky2_pci_read16(hw, PCI_STATUS);
Stephen Hemminger167f53d2007-09-25 19:01:02 -07003023 status |= PCI_STATUS_ERROR_BITS;
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08003024 sky2_pci_write16(hw, PCI_STATUS, status);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003025
3026 sky2_write8(hw, B0_CTST, CS_MRST_CLR);
3027
Stephen Hemminger555382c2007-08-29 12:58:14 -07003028 cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
3029 if (cap) {
Stephen Hemminger7782c8c2007-11-27 11:02:32 -08003030 sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
3031 0xfffffffful);
Stephen Hemminger7bd656d2006-10-09 14:40:38 -07003032
Stephen Hemminger555382c2007-08-29 12:58:14 -07003033 /* If error bit is stuck on ignore it */
3034 if (sky2_read32(hw, B0_HWE_ISRC) & Y2_IS_PCI_EXP)
3035 dev_info(&pdev->dev, "ignoring stuck error report bit\n");
Stephen Hemminger7782c8c2007-11-27 11:02:32 -08003036 else
Stephen Hemminger555382c2007-08-29 12:58:14 -07003037 hwe_mask |= Y2_IS_PCI_EXP;
3038 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003039
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08003040 sky2_power_on(hw);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003041
3042 for (i = 0; i < hw->ports; i++) {
3043 sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
3044 sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
Stephen Hemminger69161612007-06-04 17:23:26 -07003045
Stephen Hemmingered4d4162008-01-10 16:14:14 -08003046 if (hw->chip_id == CHIP_ID_YUKON_EX ||
3047 hw->chip_id == CHIP_ID_YUKON_SUPR)
Stephen Hemminger69161612007-06-04 17:23:26 -07003048 sky2_write16(hw, SK_REG(i, GMAC_CTRL),
3049 GMC_BYP_MACSECRX_ON | GMC_BYP_MACSECTX_ON
3050 | GMC_BYP_RETR_ON);
Stephen Hemminger877c8572009-10-29 06:37:08 +00003051
3052 }
3053
3054 if (hw->chip_id == CHIP_ID_YUKON_SUPR && hw->chip_rev > CHIP_REV_YU_SU_B0) {
3055 /* enable MACSec clock gating */
3056 sky2_pci_write32(hw, PCI_DEV_REG3, P_CLK_MACSEC_DIS);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003057 }
3058
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00003059 if (hw->chip_id == CHIP_ID_YUKON_OPT) {
3060 u16 reg;
3061 u32 msk;
3062
3063 if (hw->chip_rev == 0) {
3064 /* disable PCI-E PHY power down (set PHY reg 0x80, bit 7 */
3065 sky2_write32(hw, Y2_PEX_PHY_DATA, (0x80UL << 16) | (1 << 7));
3066
3067 /* set PHY Link Detect Timer to 1.1 second (11x 100ms) */
3068 reg = 10;
3069 } else {
3070 /* set PHY Link Detect Timer to 0.4 second (4x 100ms) */
3071 reg = 3;
3072 }
3073
3074 reg <<= PSM_CONFIG_REG4_TIMER_PHY_LINK_DETECT_BASE;
3075
3076 /* reset PHY Link Detect */
3077 sky2_pci_write16(hw, PSM_CONFIG_REG4,
3078 reg | PSM_CONFIG_REG4_RST_PHY_LINK_DETECT);
3079 sky2_pci_write16(hw, PSM_CONFIG_REG4, reg);
3080
3081
3082 /* enable PHY Quick Link */
3083 msk = sky2_read32(hw, B0_IMSK);
3084 msk |= Y2_IS_PHY_QLNK;
3085 sky2_write32(hw, B0_IMSK, msk);
3086
3087 /* check if PSMv2 was running before */
3088 reg = sky2_pci_read16(hw, PSM_CONFIG_REG3);
3089 if (reg & PCI_EXP_LNKCTL_ASPMC) {
3090 int cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
3091 /* restore the PCIe Link Control register */
3092 sky2_pci_write16(hw, cap + PCI_EXP_LNKCTL, reg);
3093 }
3094
3095 /* re-enable PEX PM in PEX PHY debug reg. 8 (clear bit 12) */
3096 sky2_write32(hw, Y2_PEX_PHY_DATA, PEX_DB_ACCESS | (0x08UL << 16));
3097 }
3098
Stephen Hemminger793b8832005-09-14 16:06:14 -07003099 /* Clear I2C IRQ noise */
3100 sky2_write32(hw, B2_I2C_IRQ, 1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003101
3102 /* turn off hardware timer (unused) */
3103 sky2_write8(hw, B2_TI_CTRL, TIM_STOP);
3104 sky2_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003105
Stephen Hemminger69634ee2005-12-09 11:35:06 -08003106 /* Turn off descriptor polling */
3107 sky2_write32(hw, B28_DPT_CTRL, DPT_STOP);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003108
3109 /* Turn off receive timestamp */
3110 sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_STOP);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003111 sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003112
3113 /* enable the Tx Arbiters */
3114 for (i = 0; i < hw->ports; i++)
3115 sky2_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB);
3116
3117 /* Initialize ram interface */
3118 for (i = 0; i < hw->ports; i++) {
Stephen Hemminger793b8832005-09-14 16:06:14 -07003119 sky2_write8(hw, RAM_BUFFER(i, B3_RI_CTRL), RI_RST_CLR);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003120
3121 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R1), SK_RI_TO_53);
3122 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA1), SK_RI_TO_53);
3123 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS1), SK_RI_TO_53);
3124 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R1), SK_RI_TO_53);
3125 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA1), SK_RI_TO_53);
3126 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS1), SK_RI_TO_53);
3127 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R2), SK_RI_TO_53);
3128 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA2), SK_RI_TO_53);
3129 sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS2), SK_RI_TO_53);
3130 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R2), SK_RI_TO_53);
3131 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA2), SK_RI_TO_53);
3132 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS2), SK_RI_TO_53);
3133 }
3134
Stephen Hemminger555382c2007-08-29 12:58:14 -07003135 sky2_write32(hw, B0_HWE_IMSK, hwe_mask);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003136
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003137 for (i = 0; i < hw->ports; i++)
shemminger@osdl.orgd3bcfbe2006-08-28 10:00:51 -07003138 sky2_gmac_reset(hw, i);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003139
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003140 memset(hw->st_le, 0, STATUS_LE_BYTES);
3141 hw->st_idx = 0;
3142
3143 sky2_write32(hw, STAT_CTRL, SC_STAT_RST_SET);
3144 sky2_write32(hw, STAT_CTRL, SC_STAT_RST_CLR);
3145
3146 sky2_write32(hw, STAT_LIST_ADDR_LO, hw->st_dma);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003147 sky2_write32(hw, STAT_LIST_ADDR_HI, (u64) hw->st_dma >> 32);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003148
3149 /* Set the list last index */
Stephen Hemminger793b8832005-09-14 16:06:14 -07003150 sky2_write16(hw, STAT_LAST_IDX, STATUS_RING_SIZE - 1);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003151
Stephen Hemminger290d4de2006-03-20 15:48:15 -08003152 sky2_write16(hw, STAT_TX_IDX_TH, 10);
3153 sky2_write8(hw, STAT_FIFO_WM, 16);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003154
Stephen Hemminger290d4de2006-03-20 15:48:15 -08003155 /* set Status-FIFO ISR watermark */
3156 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0)
3157 sky2_write8(hw, STAT_FIFO_ISR_WM, 4);
3158 else
3159 sky2_write8(hw, STAT_FIFO_ISR_WM, 16);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003160
Stephen Hemminger290d4de2006-03-20 15:48:15 -08003161 sky2_write32(hw, STAT_TX_TIMER_INI, sky2_us2clk(hw, 1000));
Stephen Hemminger77b3d6a2006-03-20 15:48:18 -08003162 sky2_write32(hw, STAT_ISR_TIMER_INI, sky2_us2clk(hw, 20));
3163 sky2_write32(hw, STAT_LEV_TIMER_INI, sky2_us2clk(hw, 100));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003164
Stephen Hemminger793b8832005-09-14 16:06:14 -07003165 /* enable status unit */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003166 sky2_write32(hw, STAT_CTRL, SC_STAT_OP_ON);
3167
3168 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
3169 sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START);
3170 sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START);
Stephen Hemmingere3173832007-02-06 10:45:39 -08003171}
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003172
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07003173/* Take device down (offline).
3174 * Equivalent to doing dev_stop() but this does not
3175 * inform upper layers of the transistion.
3176 */
3177static void sky2_detach(struct net_device *dev)
3178{
3179 if (netif_running(dev)) {
3180 netif_device_detach(dev); /* stop txq */
3181 sky2_down(dev);
3182 }
3183}
3184
3185/* Bring device back after doing sky2_detach */
3186static int sky2_reattach(struct net_device *dev)
3187{
3188 int err = 0;
3189
3190 if (netif_running(dev)) {
3191 err = sky2_up(dev);
3192 if (err) {
3193 printk(KERN_INFO PFX "%s: could not restart %d\n",
3194 dev->name, err);
3195 dev_close(dev);
3196 } else {
3197 netif_device_attach(dev);
3198 sky2_set_multicast(dev);
3199 }
3200 }
3201
3202 return err;
3203}
3204
Stephen Hemminger81906792007-02-15 16:40:33 -08003205static void sky2_restart(struct work_struct *work)
3206{
3207 struct sky2_hw *hw = container_of(work, struct sky2_hw, restart_work);
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07003208 int i;
Stephen Hemminger81906792007-02-15 16:40:33 -08003209
Stephen Hemminger81906792007-02-15 16:40:33 -08003210 rtnl_lock();
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07003211 for (i = 0; i < hw->ports; i++)
3212 sky2_detach(hw->dev[i]);
Stephen Hemminger81906792007-02-15 16:40:33 -08003213
Stephen Hemminger8cfcbe92007-12-03 17:02:17 -08003214 napi_disable(&hw->napi);
3215 sky2_write32(hw, B0_IMSK, 0);
Stephen Hemminger81906792007-02-15 16:40:33 -08003216 sky2_reset(hw);
3217 sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
Stephen Hemminger6de16232007-10-17 13:26:42 -07003218 napi_enable(&hw->napi);
Stephen Hemminger81906792007-02-15 16:40:33 -08003219
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07003220 for (i = 0; i < hw->ports; i++)
3221 sky2_reattach(hw->dev[i]);
Stephen Hemminger81906792007-02-15 16:40:33 -08003222
Stephen Hemminger81906792007-02-15 16:40:33 -08003223 rtnl_unlock();
3224}
3225
Stephen Hemmingere3173832007-02-06 10:45:39 -08003226static inline u8 sky2_wol_supported(const struct sky2_hw *hw)
3227{
3228 return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0;
3229}
3230
Mike McCormack2ca42312010-01-23 02:09:26 -08003231static void sky2_hw_set_wol(struct sky2_hw *hw)
3232{
3233 int wol = 0;
3234 int i;
3235
3236 for (i = 0; i < hw->ports; i++) {
3237 struct net_device *dev = hw->dev[i];
3238 struct sky2_port *sky2 = netdev_priv(dev);
3239
3240 if (sky2->wol)
3241 wol = 1;
3242 }
3243
3244 if (hw->chip_id == CHIP_ID_YUKON_EC_U ||
3245 hw->chip_id == CHIP_ID_YUKON_EX ||
3246 hw->chip_id == CHIP_ID_YUKON_FE_P)
3247 sky2_write32(hw, B0_CTST, wol ? Y2_HW_WOL_ON : Y2_HW_WOL_OFF);
3248
3249 device_set_wakeup_enable(&hw->pdev->dev, wol);
3250}
3251
Stephen Hemmingere3173832007-02-06 10:45:39 -08003252static void sky2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
3253{
3254 const struct sky2_port *sky2 = netdev_priv(dev);
3255
3256 wol->supported = sky2_wol_supported(sky2->hw);
3257 wol->wolopts = sky2->wol;
3258}
3259
3260static int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
3261{
3262 struct sky2_port *sky2 = netdev_priv(dev);
3263 struct sky2_hw *hw = sky2->hw;
3264
Joe Perches8e95a202009-12-03 07:58:21 +00003265 if ((wol->wolopts & ~sky2_wol_supported(sky2->hw)) ||
3266 !device_can_wakeup(&hw->pdev->dev))
Stephen Hemmingere3173832007-02-06 10:45:39 -08003267 return -EOPNOTSUPP;
3268
3269 sky2->wol = wol->wolopts;
3270
Mike McCormack2ca42312010-01-23 02:09:26 -08003271 sky2_hw_set_wol(hw);
Rafael J. Wysocki9d731d72008-10-12 20:59:48 -07003272
Stephen Hemmingere3173832007-02-06 10:45:39 -08003273 if (!netif_running(dev))
3274 sky2_wol_init(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003275 return 0;
3276}
3277
Stephen Hemminger28bd1812006-01-17 13:43:19 -08003278static u32 sky2_supported_modes(const struct sky2_hw *hw)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003279{
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07003280 if (sky2_is_copper(hw)) {
3281 u32 modes = SUPPORTED_10baseT_Half
3282 | SUPPORTED_10baseT_Full
3283 | SUPPORTED_100baseT_Half
3284 | SUPPORTED_100baseT_Full
3285 | SUPPORTED_Autoneg | SUPPORTED_TP;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003286
Stephen Hemmingerea76e632007-09-19 15:36:44 -07003287 if (hw->flags & SKY2_HW_GIGABIT)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003288 modes |= SUPPORTED_1000baseT_Half
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07003289 | SUPPORTED_1000baseT_Full;
3290 return modes;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003291 } else
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07003292 return SUPPORTED_1000baseT_Half
3293 | SUPPORTED_1000baseT_Full
3294 | SUPPORTED_Autoneg
3295 | SUPPORTED_FIBRE;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003296}
3297
Stephen Hemminger793b8832005-09-14 16:06:14 -07003298static int sky2_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003299{
3300 struct sky2_port *sky2 = netdev_priv(dev);
3301 struct sky2_hw *hw = sky2->hw;
3302
3303 ecmd->transceiver = XCVR_INTERNAL;
3304 ecmd->supported = sky2_supported_modes(hw);
3305 ecmd->phy_address = PHY_ADDR_MARV;
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07003306 if (sky2_is_copper(hw)) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003307 ecmd->port = PORT_TP;
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07003308 ecmd->speed = sky2->speed;
3309 } else {
3310 ecmd->speed = SPEED_1000;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003311 ecmd->port = PORT_FIBRE;
Stephen Hemmingerb89165f2006-09-06 12:44:53 -07003312 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003313
3314 ecmd->advertising = sky2->advertising;
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003315 ecmd->autoneg = (sky2->flags & SKY2_FLAG_AUTO_SPEED)
3316 ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003317 ecmd->duplex = sky2->duplex;
3318 return 0;
3319}
3320
3321static int sky2_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3322{
3323 struct sky2_port *sky2 = netdev_priv(dev);
3324 const struct sky2_hw *hw = sky2->hw;
3325 u32 supported = sky2_supported_modes(hw);
3326
3327 if (ecmd->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003328 sky2->flags |= SKY2_FLAG_AUTO_SPEED;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003329 ecmd->advertising = supported;
3330 sky2->duplex = -1;
3331 sky2->speed = -1;
3332 } else {
3333 u32 setting;
3334
Stephen Hemminger793b8832005-09-14 16:06:14 -07003335 switch (ecmd->speed) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003336 case SPEED_1000:
3337 if (ecmd->duplex == DUPLEX_FULL)
3338 setting = SUPPORTED_1000baseT_Full;
3339 else if (ecmd->duplex == DUPLEX_HALF)
3340 setting = SUPPORTED_1000baseT_Half;
3341 else
3342 return -EINVAL;
3343 break;
3344 case SPEED_100:
3345 if (ecmd->duplex == DUPLEX_FULL)
3346 setting = SUPPORTED_100baseT_Full;
3347 else if (ecmd->duplex == DUPLEX_HALF)
3348 setting = SUPPORTED_100baseT_Half;
3349 else
3350 return -EINVAL;
3351 break;
3352
3353 case SPEED_10:
3354 if (ecmd->duplex == DUPLEX_FULL)
3355 setting = SUPPORTED_10baseT_Full;
3356 else if (ecmd->duplex == DUPLEX_HALF)
3357 setting = SUPPORTED_10baseT_Half;
3358 else
3359 return -EINVAL;
3360 break;
3361 default:
3362 return -EINVAL;
3363 }
3364
3365 if ((setting & supported) == 0)
3366 return -EINVAL;
3367
3368 sky2->speed = ecmd->speed;
3369 sky2->duplex = ecmd->duplex;
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003370 sky2->flags &= ~SKY2_FLAG_AUTO_SPEED;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003371 }
3372
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003373 sky2->advertising = ecmd->advertising;
3374
Stephen Hemmingerd1b139c2007-09-05 16:56:19 +01003375 if (netif_running(dev)) {
Stephen Hemminger1b537562005-12-20 15:08:07 -08003376 sky2_phy_reinit(sky2);
Stephen Hemmingerd1b139c2007-09-05 16:56:19 +01003377 sky2_set_multicast(dev);
3378 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003379
3380 return 0;
3381}
3382
3383static void sky2_get_drvinfo(struct net_device *dev,
3384 struct ethtool_drvinfo *info)
3385{
3386 struct sky2_port *sky2 = netdev_priv(dev);
3387
3388 strcpy(info->driver, DRV_NAME);
3389 strcpy(info->version, DRV_VERSION);
3390 strcpy(info->fw_version, "N/A");
3391 strcpy(info->bus_info, pci_name(sky2->hw->pdev));
3392}
3393
3394static const struct sky2_stat {
Stephen Hemminger793b8832005-09-14 16:06:14 -07003395 char name[ETH_GSTRING_LEN];
3396 u16 offset;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003397} sky2_stats[] = {
3398 { "tx_bytes", GM_TXO_OK_HI },
3399 { "rx_bytes", GM_RXO_OK_HI },
3400 { "tx_broadcast", GM_TXF_BC_OK },
3401 { "rx_broadcast", GM_RXF_BC_OK },
3402 { "tx_multicast", GM_TXF_MC_OK },
3403 { "rx_multicast", GM_RXF_MC_OK },
3404 { "tx_unicast", GM_TXF_UC_OK },
3405 { "rx_unicast", GM_RXF_UC_OK },
3406 { "tx_mac_pause", GM_TXF_MPAUSE },
3407 { "rx_mac_pause", GM_RXF_MPAUSE },
Stephen Hemmingereadfa7d2006-03-22 10:38:45 -08003408 { "collisions", GM_TXF_COL },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003409 { "late_collision",GM_TXF_LAT_COL },
3410 { "aborted", GM_TXF_ABO_COL },
Stephen Hemmingereadfa7d2006-03-22 10:38:45 -08003411 { "single_collisions", GM_TXF_SNG_COL },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003412 { "multi_collisions", GM_TXF_MUL_COL },
Stephen Hemmingereadfa7d2006-03-22 10:38:45 -08003413
Stephen Hemmingerd2604542006-03-23 08:51:36 -08003414 { "rx_short", GM_RXF_SHT },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003415 { "rx_runt", GM_RXE_FRAG },
Stephen Hemmingereadfa7d2006-03-22 10:38:45 -08003416 { "rx_64_byte_packets", GM_RXF_64B },
3417 { "rx_65_to_127_byte_packets", GM_RXF_127B },
3418 { "rx_128_to_255_byte_packets", GM_RXF_255B },
3419 { "rx_256_to_511_byte_packets", GM_RXF_511B },
3420 { "rx_512_to_1023_byte_packets", GM_RXF_1023B },
3421 { "rx_1024_to_1518_byte_packets", GM_RXF_1518B },
3422 { "rx_1518_to_max_byte_packets", GM_RXF_MAX_SZ },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003423 { "rx_too_long", GM_RXF_LNG_ERR },
Stephen Hemmingereadfa7d2006-03-22 10:38:45 -08003424 { "rx_fifo_overflow", GM_RXE_FIFO_OV },
3425 { "rx_jabber", GM_RXF_JAB_PKT },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003426 { "rx_fcs_error", GM_RXF_FCS_ERR },
Stephen Hemmingereadfa7d2006-03-22 10:38:45 -08003427
3428 { "tx_64_byte_packets", GM_TXF_64B },
3429 { "tx_65_to_127_byte_packets", GM_TXF_127B },
3430 { "tx_128_to_255_byte_packets", GM_TXF_255B },
3431 { "tx_256_to_511_byte_packets", GM_TXF_511B },
3432 { "tx_512_to_1023_byte_packets", GM_TXF_1023B },
3433 { "tx_1024_to_1518_byte_packets", GM_TXF_1518B },
3434 { "tx_1519_to_max_byte_packets", GM_TXF_MAX_SZ },
3435 { "tx_fifo_underrun", GM_TXE_FIFO_UR },
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003436};
3437
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003438static u32 sky2_get_rx_csum(struct net_device *dev)
3439{
3440 struct sky2_port *sky2 = netdev_priv(dev);
3441
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003442 return !!(sky2->flags & SKY2_FLAG_RX_CHECKSUM);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003443}
3444
3445static int sky2_set_rx_csum(struct net_device *dev, u32 data)
3446{
3447 struct sky2_port *sky2 = netdev_priv(dev);
3448
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003449 if (data)
3450 sky2->flags |= SKY2_FLAG_RX_CHECKSUM;
3451 else
3452 sky2->flags &= ~SKY2_FLAG_RX_CHECKSUM;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003453
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003454 sky2_write32(sky2->hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR),
3455 data ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM);
3456
3457 return 0;
3458}
3459
3460static u32 sky2_get_msglevel(struct net_device *netdev)
3461{
3462 struct sky2_port *sky2 = netdev_priv(netdev);
3463 return sky2->msg_enable;
3464}
3465
Stephen Hemminger9a7ae0a2005-09-27 15:28:42 -07003466static int sky2_nway_reset(struct net_device *dev)
3467{
3468 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger9a7ae0a2005-09-27 15:28:42 -07003469
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003470 if (!netif_running(dev) || !(sky2->flags & SKY2_FLAG_AUTO_SPEED))
Stephen Hemminger9a7ae0a2005-09-27 15:28:42 -07003471 return -EINVAL;
3472
Stephen Hemminger1b537562005-12-20 15:08:07 -08003473 sky2_phy_reinit(sky2);
Stephen Hemmingerd1b139c2007-09-05 16:56:19 +01003474 sky2_set_multicast(dev);
Stephen Hemminger9a7ae0a2005-09-27 15:28:42 -07003475
3476 return 0;
3477}
3478
Stephen Hemminger793b8832005-09-14 16:06:14 -07003479static void sky2_phy_stats(struct sky2_port *sky2, u64 * data, unsigned count)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003480{
3481 struct sky2_hw *hw = sky2->hw;
3482 unsigned port = sky2->port;
3483 int i;
3484
3485 data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32
Stephen Hemminger793b8832005-09-14 16:06:14 -07003486 | (u64) gma_read32(hw, port, GM_TXO_OK_LO);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003487 data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32
Stephen Hemminger793b8832005-09-14 16:06:14 -07003488 | (u64) gma_read32(hw, port, GM_RXO_OK_LO);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003489
Stephen Hemminger793b8832005-09-14 16:06:14 -07003490 for (i = 2; i < count; i++)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003491 data[i] = (u64) gma_read32(hw, port, sky2_stats[i].offset);
3492}
3493
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003494static void sky2_set_msglevel(struct net_device *netdev, u32 value)
3495{
3496 struct sky2_port *sky2 = netdev_priv(netdev);
3497 sky2->msg_enable = value;
3498}
3499
Jeff Garzikb9f2c042007-10-03 18:07:32 -07003500static int sky2_get_sset_count(struct net_device *dev, int sset)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003501{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07003502 switch (sset) {
3503 case ETH_SS_STATS:
3504 return ARRAY_SIZE(sky2_stats);
3505 default:
3506 return -EOPNOTSUPP;
3507 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003508}
3509
3510static void sky2_get_ethtool_stats(struct net_device *dev,
Stephen Hemminger793b8832005-09-14 16:06:14 -07003511 struct ethtool_stats *stats, u64 * data)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003512{
3513 struct sky2_port *sky2 = netdev_priv(dev);
3514
Stephen Hemminger793b8832005-09-14 16:06:14 -07003515 sky2_phy_stats(sky2, data, ARRAY_SIZE(sky2_stats));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003516}
3517
Stephen Hemminger793b8832005-09-14 16:06:14 -07003518static void sky2_get_strings(struct net_device *dev, u32 stringset, u8 * data)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003519{
3520 int i;
3521
3522 switch (stringset) {
3523 case ETH_SS_STATS:
3524 for (i = 0; i < ARRAY_SIZE(sky2_stats); i++)
3525 memcpy(data + i * ETH_GSTRING_LEN,
3526 sky2_stats[i].name, ETH_GSTRING_LEN);
3527 break;
3528 }
3529}
3530
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003531static int sky2_set_mac_address(struct net_device *dev, void *p)
3532{
3533 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingera8ab1ec2006-01-30 11:37:57 -08003534 struct sky2_hw *hw = sky2->hw;
3535 unsigned port = sky2->port;
3536 const struct sockaddr *addr = p;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003537
3538 if (!is_valid_ether_addr(addr->sa_data))
3539 return -EADDRNOTAVAIL;
3540
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003541 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
Stephen Hemmingera8ab1ec2006-01-30 11:37:57 -08003542 memcpy_toio(hw->regs + B2_MAC_1 + port * 8,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003543 dev->dev_addr, ETH_ALEN);
Stephen Hemmingera8ab1ec2006-01-30 11:37:57 -08003544 memcpy_toio(hw->regs + B2_MAC_2 + port * 8,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003545 dev->dev_addr, ETH_ALEN);
Stephen Hemminger1b537562005-12-20 15:08:07 -08003546
Stephen Hemmingera8ab1ec2006-01-30 11:37:57 -08003547 /* virtual address for data */
3548 gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr);
3549
3550 /* physical address: used for pause frames */
3551 gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr);
Stephen Hemminger1b537562005-12-20 15:08:07 -08003552
3553 return 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003554}
3555
Stephen Hemmingera052b522006-10-17 10:24:23 -07003556static void inline sky2_add_filter(u8 filter[8], const u8 *addr)
3557{
3558 u32 bit;
3559
3560 bit = ether_crc(ETH_ALEN, addr) & 63;
3561 filter[bit >> 3] |= 1 << (bit & 7);
3562}
3563
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003564static void sky2_set_multicast(struct net_device *dev)
3565{
3566 struct sky2_port *sky2 = netdev_priv(dev);
3567 struct sky2_hw *hw = sky2->hw;
3568 unsigned port = sky2->port;
3569 struct dev_mc_list *list = dev->mc_list;
3570 u16 reg;
3571 u8 filter[8];
Stephen Hemmingera052b522006-10-17 10:24:23 -07003572 int rx_pause;
3573 static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 };
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003574
Stephen Hemmingera052b522006-10-17 10:24:23 -07003575 rx_pause = (sky2->flow_status == FC_RX || sky2->flow_status == FC_BOTH);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003576 memset(filter, 0, sizeof(filter));
3577
3578 reg = gma_read16(hw, port, GM_RX_CTRL);
3579 reg |= GM_RXCR_UCF_ENA;
3580
shemminger@osdl.orgd571b692005-10-26 12:16:09 -07003581 if (dev->flags & IFF_PROMISC) /* promiscuous */
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003582 reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
Stephen Hemmingera052b522006-10-17 10:24:23 -07003583 else if (dev->flags & IFF_ALLMULTI)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003584 memset(filter, 0xff, sizeof(filter));
Stephen Hemmingera052b522006-10-17 10:24:23 -07003585 else if (dev->mc_count == 0 && !rx_pause)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003586 reg &= ~GM_RXCR_MCF_ENA;
3587 else {
3588 int i;
3589 reg |= GM_RXCR_MCF_ENA;
3590
Stephen Hemmingera052b522006-10-17 10:24:23 -07003591 if (rx_pause)
3592 sky2_add_filter(filter, pause_mc_addr);
3593
3594 for (i = 0; list && i < dev->mc_count; i++, list = list->next)
3595 sky2_add_filter(filter, list->dmi_addr);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003596 }
3597
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003598 gma_write16(hw, port, GM_MC_ADDR_H1,
Stephen Hemminger793b8832005-09-14 16:06:14 -07003599 (u16) filter[0] | ((u16) filter[1] << 8));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003600 gma_write16(hw, port, GM_MC_ADDR_H2,
Stephen Hemminger793b8832005-09-14 16:06:14 -07003601 (u16) filter[2] | ((u16) filter[3] << 8));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003602 gma_write16(hw, port, GM_MC_ADDR_H3,
Stephen Hemminger793b8832005-09-14 16:06:14 -07003603 (u16) filter[4] | ((u16) filter[5] << 8));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003604 gma_write16(hw, port, GM_MC_ADDR_H4,
Stephen Hemminger793b8832005-09-14 16:06:14 -07003605 (u16) filter[6] | ((u16) filter[7] << 8));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003606
3607 gma_write16(hw, port, GM_RX_CTRL, reg);
3608}
3609
3610/* Can have one global because blinking is controlled by
3611 * ethtool and that is always under RTNL mutex
3612 */
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003613static void sky2_led(struct sky2_port *sky2, enum led_mode mode)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003614{
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003615 struct sky2_hw *hw = sky2->hw;
3616 unsigned port = sky2->port;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003617
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003618 spin_lock_bh(&sky2->phy_lock);
3619 if (hw->chip_id == CHIP_ID_YUKON_EC_U ||
3620 hw->chip_id == CHIP_ID_YUKON_EX ||
3621 hw->chip_id == CHIP_ID_YUKON_SUPR) {
3622 u16 pg;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003623 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
3624 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003625
3626 switch (mode) {
3627 case MO_LED_OFF:
3628 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
3629 PHY_M_LEDC_LOS_CTRL(8) |
3630 PHY_M_LEDC_INIT_CTRL(8) |
3631 PHY_M_LEDC_STA1_CTRL(8) |
3632 PHY_M_LEDC_STA0_CTRL(8));
3633 break;
3634 case MO_LED_ON:
3635 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
3636 PHY_M_LEDC_LOS_CTRL(9) |
3637 PHY_M_LEDC_INIT_CTRL(9) |
3638 PHY_M_LEDC_STA1_CTRL(9) |
3639 PHY_M_LEDC_STA0_CTRL(9));
3640 break;
3641 case MO_LED_BLINK:
3642 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
3643 PHY_M_LEDC_LOS_CTRL(0xa) |
3644 PHY_M_LEDC_INIT_CTRL(0xa) |
3645 PHY_M_LEDC_STA1_CTRL(0xa) |
3646 PHY_M_LEDC_STA0_CTRL(0xa));
3647 break;
3648 case MO_LED_NORM:
3649 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
3650 PHY_M_LEDC_LOS_CTRL(1) |
3651 PHY_M_LEDC_INIT_CTRL(8) |
3652 PHY_M_LEDC_STA1_CTRL(7) |
3653 PHY_M_LEDC_STA0_CTRL(7));
3654 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07003655
3656 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003657 } else
Jeff Garzik7d2e3cb2008-05-13 01:41:58 -04003658 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003659 PHY_M_LED_MO_DUP(mode) |
3660 PHY_M_LED_MO_10(mode) |
3661 PHY_M_LED_MO_100(mode) |
3662 PHY_M_LED_MO_1000(mode) |
3663 PHY_M_LED_MO_RX(mode) |
3664 PHY_M_LED_MO_TX(mode));
3665
3666 spin_unlock_bh(&sky2->phy_lock);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003667}
3668
3669/* blink LED's for finding board */
3670static int sky2_phys_id(struct net_device *dev, u32 data)
3671{
3672 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003673 unsigned int i;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003674
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003675 if (data == 0)
3676 data = UINT_MAX;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003677
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003678 for (i = 0; i < data; i++) {
3679 sky2_led(sky2, MO_LED_ON);
3680 if (msleep_interruptible(500))
3681 break;
3682 sky2_led(sky2, MO_LED_OFF);
3683 if (msleep_interruptible(500))
3684 break;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003685 }
Stephen Hemmingera84d0a32008-02-22 16:00:33 -08003686 sky2_led(sky2, MO_LED_NORM);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003687
3688 return 0;
3689}
3690
3691static void sky2_get_pauseparam(struct net_device *dev,
3692 struct ethtool_pauseparam *ecmd)
3693{
3694 struct sky2_port *sky2 = netdev_priv(dev);
3695
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07003696 switch (sky2->flow_mode) {
3697 case FC_NONE:
3698 ecmd->tx_pause = ecmd->rx_pause = 0;
3699 break;
3700 case FC_TX:
3701 ecmd->tx_pause = 1, ecmd->rx_pause = 0;
3702 break;
3703 case FC_RX:
3704 ecmd->tx_pause = 0, ecmd->rx_pause = 1;
3705 break;
3706 case FC_BOTH:
3707 ecmd->tx_pause = ecmd->rx_pause = 1;
3708 }
3709
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003710 ecmd->autoneg = (sky2->flags & SKY2_FLAG_AUTO_PAUSE)
3711 ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003712}
3713
3714static int sky2_set_pauseparam(struct net_device *dev,
3715 struct ethtool_pauseparam *ecmd)
3716{
3717 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003718
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07003719 if (ecmd->autoneg == AUTONEG_ENABLE)
3720 sky2->flags |= SKY2_FLAG_AUTO_PAUSE;
3721 else
3722 sky2->flags &= ~SKY2_FLAG_AUTO_PAUSE;
3723
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07003724 sky2->flow_mode = sky2_flow(ecmd->rx_pause, ecmd->tx_pause);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003725
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07003726 if (netif_running(dev))
3727 sky2_phy_reinit(sky2);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003728
Stephen Hemminger2eaba1a2006-09-06 12:44:47 -07003729 return 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003730}
3731
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003732static int sky2_get_coalesce(struct net_device *dev,
3733 struct ethtool_coalesce *ecmd)
3734{
3735 struct sky2_port *sky2 = netdev_priv(dev);
3736 struct sky2_hw *hw = sky2->hw;
3737
3738 if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_STOP)
3739 ecmd->tx_coalesce_usecs = 0;
3740 else {
3741 u32 clks = sky2_read32(hw, STAT_TX_TIMER_INI);
3742 ecmd->tx_coalesce_usecs = sky2_clk2us(hw, clks);
3743 }
3744 ecmd->tx_max_coalesced_frames = sky2_read16(hw, STAT_TX_IDX_TH);
3745
3746 if (sky2_read8(hw, STAT_LEV_TIMER_CTRL) == TIM_STOP)
3747 ecmd->rx_coalesce_usecs = 0;
3748 else {
3749 u32 clks = sky2_read32(hw, STAT_LEV_TIMER_INI);
3750 ecmd->rx_coalesce_usecs = sky2_clk2us(hw, clks);
3751 }
3752 ecmd->rx_max_coalesced_frames = sky2_read8(hw, STAT_FIFO_WM);
3753
3754 if (sky2_read8(hw, STAT_ISR_TIMER_CTRL) == TIM_STOP)
3755 ecmd->rx_coalesce_usecs_irq = 0;
3756 else {
3757 u32 clks = sky2_read32(hw, STAT_ISR_TIMER_INI);
3758 ecmd->rx_coalesce_usecs_irq = sky2_clk2us(hw, clks);
3759 }
3760
3761 ecmd->rx_max_coalesced_frames_irq = sky2_read8(hw, STAT_FIFO_ISR_WM);
3762
3763 return 0;
3764}
3765
3766/* Note: this affect both ports */
3767static int sky2_set_coalesce(struct net_device *dev,
3768 struct ethtool_coalesce *ecmd)
3769{
3770 struct sky2_port *sky2 = netdev_priv(dev);
3771 struct sky2_hw *hw = sky2->hw;
Stephen Hemminger77b3d6a2006-03-20 15:48:18 -08003772 const u32 tmax = sky2_clk2us(hw, 0x0ffffff);
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003773
Stephen Hemminger77b3d6a2006-03-20 15:48:18 -08003774 if (ecmd->tx_coalesce_usecs > tmax ||
3775 ecmd->rx_coalesce_usecs > tmax ||
3776 ecmd->rx_coalesce_usecs_irq > tmax)
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003777 return -EINVAL;
3778
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00003779 if (ecmd->tx_max_coalesced_frames >= sky2->tx_ring_size-1)
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003780 return -EINVAL;
Stephen Hemmingerff81fbb2006-02-22 11:44:59 -08003781 if (ecmd->rx_max_coalesced_frames > RX_MAX_PENDING)
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003782 return -EINVAL;
Stephen Hemmingerff81fbb2006-02-22 11:44:59 -08003783 if (ecmd->rx_max_coalesced_frames_irq >RX_MAX_PENDING)
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003784 return -EINVAL;
3785
3786 if (ecmd->tx_coalesce_usecs == 0)
3787 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP);
3788 else {
3789 sky2_write32(hw, STAT_TX_TIMER_INI,
3790 sky2_us2clk(hw, ecmd->tx_coalesce_usecs));
3791 sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
3792 }
3793 sky2_write16(hw, STAT_TX_IDX_TH, ecmd->tx_max_coalesced_frames);
3794
3795 if (ecmd->rx_coalesce_usecs == 0)
3796 sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_STOP);
3797 else {
3798 sky2_write32(hw, STAT_LEV_TIMER_INI,
3799 sky2_us2clk(hw, ecmd->rx_coalesce_usecs));
3800 sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START);
3801 }
3802 sky2_write8(hw, STAT_FIFO_WM, ecmd->rx_max_coalesced_frames);
3803
3804 if (ecmd->rx_coalesce_usecs_irq == 0)
3805 sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_STOP);
3806 else {
Stephen Hemmingerd28d4872006-01-30 11:37:56 -08003807 sky2_write32(hw, STAT_ISR_TIMER_INI,
Stephen Hemmingerfb17358f2005-12-09 11:34:56 -08003808 sky2_us2clk(hw, ecmd->rx_coalesce_usecs_irq));
3809 sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START);
3810 }
3811 sky2_write8(hw, STAT_FIFO_ISR_WM, ecmd->rx_max_coalesced_frames_irq);
3812 return 0;
3813}
3814
Stephen Hemminger793b8832005-09-14 16:06:14 -07003815static void sky2_get_ringparam(struct net_device *dev,
3816 struct ethtool_ringparam *ering)
3817{
3818 struct sky2_port *sky2 = netdev_priv(dev);
3819
3820 ering->rx_max_pending = RX_MAX_PENDING;
3821 ering->rx_mini_max_pending = 0;
3822 ering->rx_jumbo_max_pending = 0;
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00003823 ering->tx_max_pending = TX_MAX_PENDING;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003824
3825 ering->rx_pending = sky2->rx_pending;
3826 ering->rx_mini_pending = 0;
3827 ering->rx_jumbo_pending = 0;
3828 ering->tx_pending = sky2->tx_pending;
3829}
3830
3831static int sky2_set_ringparam(struct net_device *dev,
3832 struct ethtool_ringparam *ering)
3833{
3834 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003835
3836 if (ering->rx_pending > RX_MAX_PENDING ||
3837 ering->rx_pending < 8 ||
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00003838 ering->tx_pending < TX_MIN_PENDING ||
3839 ering->tx_pending > TX_MAX_PENDING)
Stephen Hemminger793b8832005-09-14 16:06:14 -07003840 return -EINVAL;
3841
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07003842 sky2_detach(dev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003843
3844 sky2->rx_pending = ering->rx_pending;
3845 sky2->tx_pending = ering->tx_pending;
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00003846 sky2->tx_ring_size = roundup_pow_of_two(sky2->tx_pending+1);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003847
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07003848 return sky2_reattach(dev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003849}
3850
Stephen Hemminger793b8832005-09-14 16:06:14 -07003851static int sky2_get_regs_len(struct net_device *dev)
3852{
Stephen Hemminger6e4cbb32005-09-19 15:47:57 -07003853 return 0x4000;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003854}
3855
3856/*
3857 * Returns copy of control register region
Stephen Hemminger3ead5db2007-06-04 17:23:21 -07003858 * Note: ethtool_get_regs always provides full size (16k) buffer
Stephen Hemminger793b8832005-09-14 16:06:14 -07003859 */
3860static void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs,
3861 void *p)
3862{
3863 const struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07003864 const void __iomem *io = sky2->hw->regs;
Stephen Hemminger295b54c2007-10-11 19:47:22 -07003865 unsigned int b;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003866
3867 regs->version = 1;
Stephen Hemminger793b8832005-09-14 16:06:14 -07003868
Stephen Hemminger295b54c2007-10-11 19:47:22 -07003869 for (b = 0; b < 128; b++) {
3870 /* This complicated switch statement is to make sure and
3871 * only access regions that are unreserved.
3872 * Some blocks are only valid on dual port cards.
3873 * and block 3 has some special diagnostic registers that
3874 * are poison.
3875 */
3876 switch (b) {
3877 case 3:
3878 /* skip diagnostic ram region */
3879 memcpy_fromio(p + 0x10, io + 0x10, 128 - 0x10);
3880 break;
Stephen Hemminger6e4cbb32005-09-19 15:47:57 -07003881
Stephen Hemminger295b54c2007-10-11 19:47:22 -07003882 /* dual port cards only */
3883 case 5: /* Tx Arbiter 2 */
3884 case 9: /* RX2 */
3885 case 14 ... 15: /* TX2 */
3886 case 17: case 19: /* Ram Buffer 2 */
3887 case 22 ... 23: /* Tx Ram Buffer 2 */
3888 case 25: /* Rx MAC Fifo 1 */
3889 case 27: /* Tx MAC Fifo 2 */
3890 case 31: /* GPHY 2 */
3891 case 40 ... 47: /* Pattern Ram 2 */
3892 case 52: case 54: /* TCP Segmentation 2 */
3893 case 112 ... 116: /* GMAC 2 */
3894 if (sky2->hw->ports == 1)
3895 goto reserved;
3896 /* fall through */
3897 case 0: /* Control */
3898 case 2: /* Mac address */
3899 case 4: /* Tx Arbiter 1 */
3900 case 7: /* PCI express reg */
3901 case 8: /* RX1 */
3902 case 12 ... 13: /* TX1 */
3903 case 16: case 18:/* Rx Ram Buffer 1 */
3904 case 20 ... 21: /* Tx Ram Buffer 1 */
3905 case 24: /* Rx MAC Fifo 1 */
3906 case 26: /* Tx MAC Fifo 1 */
3907 case 28 ... 29: /* Descriptor and status unit */
3908 case 30: /* GPHY 1*/
3909 case 32 ... 39: /* Pattern Ram 1 */
3910 case 48: case 50: /* TCP Segmentation 1 */
3911 case 56 ... 60: /* PCI space */
3912 case 80 ... 84: /* GMAC 1 */
3913 memcpy_fromio(p, io, 128);
3914 break;
3915 default:
3916reserved:
3917 memset(p, 0, 128);
3918 }
Stephen Hemminger3ead5db2007-06-04 17:23:21 -07003919
Stephen Hemminger295b54c2007-10-11 19:47:22 -07003920 p += 128;
3921 io += 128;
3922 }
Stephen Hemminger793b8832005-09-14 16:06:14 -07003923}
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07003924
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07003925/* In order to do Jumbo packets on these chips, need to turn off the
3926 * transmit store/forward. Therefore checksum offload won't work.
3927 */
3928static int no_tx_offload(struct net_device *dev)
3929{
3930 const struct sky2_port *sky2 = netdev_priv(dev);
3931 const struct sky2_hw *hw = sky2->hw;
3932
Stephen Hemminger69161612007-06-04 17:23:26 -07003933 return dev->mtu > ETH_DATA_LEN && hw->chip_id == CHIP_ID_YUKON_EC_U;
Stephen Hemmingerb628ed982007-04-11 14:48:01 -07003934}
3935
3936static int sky2_set_tx_csum(struct net_device *dev, u32 data)
3937{
3938 if (data && no_tx_offload(dev))
3939 return -EINVAL;
3940
3941 return ethtool_op_set_tx_csum(dev, data);
3942}
3943
3944
3945static int sky2_set_tso(struct net_device *dev, u32 data)
3946{
3947 if (data && no_tx_offload(dev))
3948 return -EINVAL;
3949
3950 return ethtool_op_set_tso(dev, data);
3951}
3952
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07003953static int sky2_get_eeprom_len(struct net_device *dev)
3954{
3955 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08003956 struct sky2_hw *hw = sky2->hw;
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07003957 u16 reg2;
3958
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08003959 reg2 = sky2_pci_read16(hw, PCI_DEV_REG2);
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07003960 return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
3961}
3962
Stephen Hemminger14132352008-08-27 20:46:26 -07003963static int sky2_vpd_wait(const struct sky2_hw *hw, int cap, u16 busy)
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07003964{
Stephen Hemminger14132352008-08-27 20:46:26 -07003965 unsigned long start = jiffies;
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07003966
Stephen Hemminger14132352008-08-27 20:46:26 -07003967 while ( (sky2_pci_read16(hw, cap + PCI_VPD_ADDR) & PCI_VPD_ADDR_F) == busy) {
3968 /* Can take up to 10.6 ms for write */
3969 if (time_after(jiffies, start + HZ/4)) {
3970 dev_err(&hw->pdev->dev, PFX "VPD cycle timed out");
3971 return -ETIMEDOUT;
3972 }
3973 mdelay(1);
3974 }
Stephen Hemminger167f53d2007-09-25 19:01:02 -07003975
Stephen Hemminger14132352008-08-27 20:46:26 -07003976 return 0;
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07003977}
3978
Stephen Hemminger14132352008-08-27 20:46:26 -07003979static int sky2_vpd_read(struct sky2_hw *hw, int cap, void *data,
3980 u16 offset, size_t length)
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07003981{
Stephen Hemminger14132352008-08-27 20:46:26 -07003982 int rc = 0;
3983
3984 while (length > 0) {
3985 u32 val;
3986
3987 sky2_pci_write16(hw, cap + PCI_VPD_ADDR, offset);
3988 rc = sky2_vpd_wait(hw, cap, 0);
3989 if (rc)
3990 break;
3991
3992 val = sky2_pci_read32(hw, cap + PCI_VPD_DATA);
3993
3994 memcpy(data, &val, min(sizeof(val), length));
3995 offset += sizeof(u32);
3996 data += sizeof(u32);
3997 length -= sizeof(u32);
3998 }
3999
4000 return rc;
4001}
4002
4003static int sky2_vpd_write(struct sky2_hw *hw, int cap, const void *data,
4004 u16 offset, unsigned int length)
4005{
4006 unsigned int i;
4007 int rc = 0;
4008
4009 for (i = 0; i < length; i += sizeof(u32)) {
4010 u32 val = *(u32 *)(data + i);
4011
4012 sky2_pci_write32(hw, cap + PCI_VPD_DATA, val);
4013 sky2_pci_write32(hw, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F);
4014
4015 rc = sky2_vpd_wait(hw, cap, PCI_VPD_ADDR_F);
4016 if (rc)
4017 break;
4018 }
4019 return rc;
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004020}
4021
4022static int sky2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
4023 u8 *data)
4024{
4025 struct sky2_port *sky2 = netdev_priv(dev);
4026 int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD);
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004027
4028 if (!cap)
4029 return -EINVAL;
4030
4031 eeprom->magic = SKY2_EEPROM_MAGIC;
4032
Stephen Hemminger14132352008-08-27 20:46:26 -07004033 return sky2_vpd_read(sky2->hw, cap, data, eeprom->offset, eeprom->len);
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004034}
4035
4036static int sky2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
4037 u8 *data)
4038{
4039 struct sky2_port *sky2 = netdev_priv(dev);
4040 int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD);
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004041
4042 if (!cap)
4043 return -EINVAL;
4044
4045 if (eeprom->magic != SKY2_EEPROM_MAGIC)
4046 return -EINVAL;
4047
Stephen Hemminger14132352008-08-27 20:46:26 -07004048 /* Partial writes not supported */
4049 if ((eeprom->offset & 3) || (eeprom->len & 3))
4050 return -EINVAL;
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004051
Stephen Hemminger14132352008-08-27 20:46:26 -07004052 return sky2_vpd_write(sky2->hw, cap, data, eeprom->offset, eeprom->len);
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004053}
4054
4055
Jeff Garzik7282d492006-09-13 14:30:00 -04004056static const struct ethtool_ops sky2_ethtool_ops = {
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004057 .get_settings = sky2_get_settings,
4058 .set_settings = sky2_set_settings,
4059 .get_drvinfo = sky2_get_drvinfo,
4060 .get_wol = sky2_get_wol,
4061 .set_wol = sky2_set_wol,
4062 .get_msglevel = sky2_get_msglevel,
4063 .set_msglevel = sky2_set_msglevel,
4064 .nway_reset = sky2_nway_reset,
4065 .get_regs_len = sky2_get_regs_len,
4066 .get_regs = sky2_get_regs,
4067 .get_link = ethtool_op_get_link,
4068 .get_eeprom_len = sky2_get_eeprom_len,
4069 .get_eeprom = sky2_get_eeprom,
4070 .set_eeprom = sky2_set_eeprom,
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004071 .set_sg = ethtool_op_set_sg,
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004072 .set_tx_csum = sky2_set_tx_csum,
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004073 .set_tso = sky2_set_tso,
4074 .get_rx_csum = sky2_get_rx_csum,
4075 .set_rx_csum = sky2_set_rx_csum,
4076 .get_strings = sky2_get_strings,
4077 .get_coalesce = sky2_get_coalesce,
4078 .set_coalesce = sky2_set_coalesce,
4079 .get_ringparam = sky2_get_ringparam,
4080 .set_ringparam = sky2_set_ringparam,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004081 .get_pauseparam = sky2_get_pauseparam,
4082 .set_pauseparam = sky2_set_pauseparam,
Stephen Hemmingerf4331a62007-07-09 15:33:39 -07004083 .phys_id = sky2_phys_id,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004084 .get_sset_count = sky2_get_sset_count,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004085 .get_ethtool_stats = sky2_get_ethtool_stats,
4086};
4087
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004088#ifdef CONFIG_SKY2_DEBUG
4089
4090static struct dentry *sky2_debug;
4091
Stephen Hemmingere4c2abe2009-02-03 11:27:29 +00004092
4093/*
4094 * Read and parse the first part of Vital Product Data
4095 */
4096#define VPD_SIZE 128
4097#define VPD_MAGIC 0x82
4098
4099static const struct vpd_tag {
4100 char tag[2];
4101 char *label;
4102} vpd_tags[] = {
4103 { "PN", "Part Number" },
4104 { "EC", "Engineering Level" },
4105 { "MN", "Manufacturer" },
4106 { "SN", "Serial Number" },
4107 { "YA", "Asset Tag" },
4108 { "VL", "First Error Log Message" },
4109 { "VF", "Second Error Log Message" },
4110 { "VB", "Boot Agent ROM Configuration" },
4111 { "VE", "EFI UNDI Configuration" },
4112};
4113
4114static void sky2_show_vpd(struct seq_file *seq, struct sky2_hw *hw)
4115{
4116 size_t vpd_size;
4117 loff_t offs;
4118 u8 len;
4119 unsigned char *buf;
4120 u16 reg2;
4121
4122 reg2 = sky2_pci_read16(hw, PCI_DEV_REG2);
4123 vpd_size = 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
4124
4125 seq_printf(seq, "%s Product Data\n", pci_name(hw->pdev));
4126 buf = kmalloc(vpd_size, GFP_KERNEL);
4127 if (!buf) {
4128 seq_puts(seq, "no memory!\n");
4129 return;
4130 }
4131
4132 if (pci_read_vpd(hw->pdev, 0, vpd_size, buf) < 0) {
4133 seq_puts(seq, "VPD read failed\n");
4134 goto out;
4135 }
4136
4137 if (buf[0] != VPD_MAGIC) {
4138 seq_printf(seq, "VPD tag mismatch: %#x\n", buf[0]);
4139 goto out;
4140 }
4141 len = buf[1];
4142 if (len == 0 || len > vpd_size - 4) {
4143 seq_printf(seq, "Invalid id length: %d\n", len);
4144 goto out;
4145 }
4146
4147 seq_printf(seq, "%.*s\n", len, buf + 3);
4148 offs = len + 3;
4149
4150 while (offs < vpd_size - 4) {
4151 int i;
4152
4153 if (!memcmp("RW", buf + offs, 2)) /* end marker */
4154 break;
4155 len = buf[offs + 2];
4156 if (offs + len + 3 >= vpd_size)
4157 break;
4158
4159 for (i = 0; i < ARRAY_SIZE(vpd_tags); i++) {
4160 if (!memcmp(vpd_tags[i].tag, buf + offs, 2)) {
4161 seq_printf(seq, " %s: %.*s\n",
4162 vpd_tags[i].label, len, buf + offs + 3);
4163 break;
4164 }
4165 }
4166 offs += len + 3;
4167 }
4168out:
4169 kfree(buf);
4170}
4171
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004172static int sky2_debug_show(struct seq_file *seq, void *v)
4173{
4174 struct net_device *dev = seq->private;
4175 const struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004176 struct sky2_hw *hw = sky2->hw;
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004177 unsigned port = sky2->port;
4178 unsigned idx, last;
4179 int sop;
4180
Stephen Hemmingere4c2abe2009-02-03 11:27:29 +00004181 sky2_show_vpd(seq, hw);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004182
Stephen Hemmingere4c2abe2009-02-03 11:27:29 +00004183 seq_printf(seq, "\nIRQ src=%x mask=%x control=%x\n",
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004184 sky2_read32(hw, B0_ISRC),
4185 sky2_read32(hw, B0_IMSK),
4186 sky2_read32(hw, B0_Y2_SP_ICR));
4187
Stephen Hemmingere4c2abe2009-02-03 11:27:29 +00004188 if (!netif_running(dev)) {
4189 seq_printf(seq, "network not running\n");
4190 return 0;
4191 }
4192
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004193 napi_disable(&hw->napi);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004194 last = sky2_read16(hw, STAT_PUT_IDX);
4195
4196 if (hw->st_idx == last)
4197 seq_puts(seq, "Status ring (empty)\n");
4198 else {
4199 seq_puts(seq, "Status ring\n");
4200 for (idx = hw->st_idx; idx != last && idx < STATUS_RING_SIZE;
4201 idx = RING_NEXT(idx, STATUS_RING_SIZE)) {
4202 const struct sky2_status_le *le = hw->st_le + idx;
4203 seq_printf(seq, "[%d] %#x %d %#x\n",
4204 idx, le->opcode, le->length, le->status);
4205 }
4206 seq_puts(seq, "\n");
4207 }
4208
4209 seq_printf(seq, "Tx ring pending=%u...%u report=%d done=%d\n",
4210 sky2->tx_cons, sky2->tx_prod,
4211 sky2_read16(hw, port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX),
4212 sky2_read16(hw, Q_ADDR(txqaddr[port], Q_DONE)));
4213
4214 /* Dump contents of tx ring */
4215 sop = 1;
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00004216 for (idx = sky2->tx_next; idx != sky2->tx_prod && idx < sky2->tx_ring_size;
4217 idx = RING_NEXT(idx, sky2->tx_ring_size)) {
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004218 const struct sky2_tx_le *le = sky2->tx_le + idx;
4219 u32 a = le32_to_cpu(le->addr);
4220
4221 if (sop)
4222 seq_printf(seq, "%u:", idx);
4223 sop = 0;
4224
4225 switch(le->opcode & ~HW_OWNER) {
4226 case OP_ADDR64:
4227 seq_printf(seq, " %#x:", a);
4228 break;
4229 case OP_LRGLEN:
4230 seq_printf(seq, " mtu=%d", a);
4231 break;
4232 case OP_VLAN:
4233 seq_printf(seq, " vlan=%d", be16_to_cpu(le->length));
4234 break;
4235 case OP_TCPLISW:
4236 seq_printf(seq, " csum=%#x", a);
4237 break;
4238 case OP_LARGESEND:
4239 seq_printf(seq, " tso=%#x(%d)", a, le16_to_cpu(le->length));
4240 break;
4241 case OP_PACKET:
4242 seq_printf(seq, " %#x(%d)", a, le16_to_cpu(le->length));
4243 break;
4244 case OP_BUFFER:
4245 seq_printf(seq, " frag=%#x(%d)", a, le16_to_cpu(le->length));
4246 break;
4247 default:
4248 seq_printf(seq, " op=%#x,%#x(%d)", le->opcode,
4249 a, le16_to_cpu(le->length));
4250 }
4251
4252 if (le->ctrl & EOP) {
4253 seq_putc(seq, '\n');
4254 sop = 1;
4255 }
4256 }
4257
4258 seq_printf(seq, "\nRx ring hw get=%d put=%d last=%d\n",
4259 sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_GET_IDX)),
Mike McCormackc409c342009-07-21 14:51:20 +00004260 sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_PUT_IDX)),
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004261 sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_LAST_IDX)));
4262
David S. Millerd1d08d12008-01-07 20:53:33 -08004263 sky2_read32(hw, B0_Y2_SP_LISR);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004264 napi_enable(&hw->napi);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004265 return 0;
4266}
4267
4268static int sky2_debug_open(struct inode *inode, struct file *file)
4269{
4270 return single_open(file, sky2_debug_show, inode->i_private);
4271}
4272
4273static const struct file_operations sky2_debug_fops = {
4274 .owner = THIS_MODULE,
4275 .open = sky2_debug_open,
4276 .read = seq_read,
4277 .llseek = seq_lseek,
4278 .release = single_release,
4279};
4280
4281/*
4282 * Use network device events to create/remove/rename
4283 * debugfs file entries
4284 */
4285static int sky2_device_event(struct notifier_block *unused,
4286 unsigned long event, void *ptr)
4287{
4288 struct net_device *dev = ptr;
Stephen Hemminger5b296bc2007-08-29 12:58:11 -07004289 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004290
Stephen Hemminger1436b302008-11-19 21:59:54 -08004291 if (dev->netdev_ops->ndo_open != sky2_up || !sky2_debug)
Stephen Hemminger5b296bc2007-08-29 12:58:11 -07004292 return NOTIFY_DONE;
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004293
Stephen Hemminger5b296bc2007-08-29 12:58:11 -07004294 switch(event) {
4295 case NETDEV_CHANGENAME:
4296 if (sky2->debugfs) {
4297 sky2->debugfs = debugfs_rename(sky2_debug, sky2->debugfs,
4298 sky2_debug, dev->name);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004299 }
Stephen Hemminger5b296bc2007-08-29 12:58:11 -07004300 break;
4301
4302 case NETDEV_GOING_DOWN:
4303 if (sky2->debugfs) {
4304 printk(KERN_DEBUG PFX "%s: remove debugfs\n",
4305 dev->name);
4306 debugfs_remove(sky2->debugfs);
4307 sky2->debugfs = NULL;
4308 }
4309 break;
4310
4311 case NETDEV_UP:
4312 sky2->debugfs = debugfs_create_file(dev->name, S_IRUGO,
4313 sky2_debug, dev,
4314 &sky2_debug_fops);
4315 if (IS_ERR(sky2->debugfs))
4316 sky2->debugfs = NULL;
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004317 }
4318
4319 return NOTIFY_DONE;
4320}
4321
4322static struct notifier_block sky2_notifier = {
4323 .notifier_call = sky2_device_event,
4324};
4325
4326
4327static __init void sky2_debug_init(void)
4328{
4329 struct dentry *ent;
4330
4331 ent = debugfs_create_dir("sky2", NULL);
4332 if (!ent || IS_ERR(ent))
4333 return;
4334
4335 sky2_debug = ent;
4336 register_netdevice_notifier(&sky2_notifier);
4337}
4338
4339static __exit void sky2_debug_cleanup(void)
4340{
4341 if (sky2_debug) {
4342 unregister_netdevice_notifier(&sky2_notifier);
4343 debugfs_remove(sky2_debug);
4344 sky2_debug = NULL;
4345 }
4346}
4347
4348#else
4349#define sky2_debug_init()
4350#define sky2_debug_cleanup()
4351#endif
4352
Stephen Hemminger1436b302008-11-19 21:59:54 -08004353/* Two copies of network device operations to handle special case of
4354 not allowing netpoll on second port */
4355static const struct net_device_ops sky2_netdev_ops[2] = {
4356 {
4357 .ndo_open = sky2_up,
4358 .ndo_stop = sky2_down,
Stephen Hemminger00829822008-11-20 20:14:53 -08004359 .ndo_start_xmit = sky2_xmit_frame,
Stephen Hemminger1436b302008-11-19 21:59:54 -08004360 .ndo_do_ioctl = sky2_ioctl,
4361 .ndo_validate_addr = eth_validate_addr,
4362 .ndo_set_mac_address = sky2_set_mac_address,
4363 .ndo_set_multicast_list = sky2_set_multicast,
4364 .ndo_change_mtu = sky2_change_mtu,
4365 .ndo_tx_timeout = sky2_tx_timeout,
4366#ifdef SKY2_VLAN_TAG_USED
4367 .ndo_vlan_rx_register = sky2_vlan_rx_register,
4368#endif
4369#ifdef CONFIG_NET_POLL_CONTROLLER
4370 .ndo_poll_controller = sky2_netpoll,
4371#endif
4372 },
4373 {
4374 .ndo_open = sky2_up,
4375 .ndo_stop = sky2_down,
Stephen Hemminger00829822008-11-20 20:14:53 -08004376 .ndo_start_xmit = sky2_xmit_frame,
Stephen Hemminger1436b302008-11-19 21:59:54 -08004377 .ndo_do_ioctl = sky2_ioctl,
4378 .ndo_validate_addr = eth_validate_addr,
4379 .ndo_set_mac_address = sky2_set_mac_address,
4380 .ndo_set_multicast_list = sky2_set_multicast,
4381 .ndo_change_mtu = sky2_change_mtu,
4382 .ndo_tx_timeout = sky2_tx_timeout,
4383#ifdef SKY2_VLAN_TAG_USED
4384 .ndo_vlan_rx_register = sky2_vlan_rx_register,
4385#endif
4386 },
4387};
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004388
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004389/* Initialize network device */
4390static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
Stephen Hemmingere3173832007-02-06 10:45:39 -08004391 unsigned port,
Stephen Hemmingerbe63a212008-01-15 11:29:29 -08004392 int highmem, int wol)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004393{
4394 struct sky2_port *sky2;
4395 struct net_device *dev = alloc_etherdev(sizeof(*sky2));
4396
4397 if (!dev) {
Joe Perches898eb712007-10-18 03:06:30 -07004398 dev_err(&hw->pdev->dev, "etherdev alloc failed\n");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004399 return NULL;
4400 }
4401
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004402 SET_NETDEV_DEV(dev, &hw->pdev->dev);
shemminger@osdl.orgef743d32005-11-30 11:45:12 -08004403 dev->irq = hw->pdev->irq;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004404 SET_ETHTOOL_OPS(dev, &sky2_ethtool_ops);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004405 dev->watchdog_timeo = TX_WATCHDOG;
Stephen Hemminger1436b302008-11-19 21:59:54 -08004406 dev->netdev_ops = &sky2_netdev_ops[port];
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004407
4408 sky2 = netdev_priv(dev);
4409 sky2->netdev = dev;
4410 sky2->hw = hw;
4411 sky2->msg_enable = netif_msg_init(debug, default_msg);
4412
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004413 /* Auto speed and flow control */
Stephen Hemminger0ea065e2009-08-14 15:36:41 -07004414 sky2->flags = SKY2_FLAG_AUTO_SPEED | SKY2_FLAG_AUTO_PAUSE;
4415 if (hw->chip_id != CHIP_ID_YUKON_XL)
4416 sky2->flags |= SKY2_FLAG_RX_CHECKSUM;
4417
Stephen Hemminger16ad91e2006-10-17 10:24:13 -07004418 sky2->flow_mode = FC_BOTH;
4419
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004420 sky2->duplex = -1;
4421 sky2->speed = -1;
4422 sky2->advertising = sky2_supported_modes(hw);
Stephen Hemmingerbe63a212008-01-15 11:29:29 -08004423 sky2->wol = wol;
Stephen Hemminger75d070c2005-12-09 11:35:11 -08004424
Stephen Hemmingere07b1aa2006-03-20 15:48:17 -08004425 spin_lock_init(&sky2->phy_lock);
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00004426
Stephen Hemminger793b8832005-09-14 16:06:14 -07004427 sky2->tx_pending = TX_DEF_PENDING;
Stephen Hemmingeree5f68f2009-08-18 15:17:08 +00004428 sky2->tx_ring_size = roundup_pow_of_two(TX_DEF_PENDING+1);
Stephen Hemminger290d4de2006-03-20 15:48:15 -08004429 sky2->rx_pending = RX_DEF_PENDING;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004430
4431 hw->dev[port] = dev;
4432
4433 sky2->port = port;
4434
Stephen Hemminger4a50a872007-02-06 10:45:41 -08004435 dev->features |= NETIF_F_TSO | NETIF_F_IP_CSUM | NETIF_F_SG;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004436 if (highmem)
4437 dev->features |= NETIF_F_HIGHDMA;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004438
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07004439#ifdef SKY2_VLAN_TAG_USED
Stephen Hemmingerd6c9bc12007-09-27 12:32:44 -07004440 /* The workaround for FE+ status conflicts with VLAN tag detection. */
4441 if (!(sky2->hw->chip_id == CHIP_ID_YUKON_FE_P &&
4442 sky2->hw->chip_rev == CHIP_REV_YU_FE2_A0)) {
4443 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
Stephen Hemmingerd6c9bc12007-09-27 12:32:44 -07004444 }
shemminger@osdl.orgd1f13702005-09-27 15:02:57 -07004445#endif
4446
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004447 /* read the mac address */
Stephen Hemminger793b8832005-09-14 16:06:14 -07004448 memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8, ETH_ALEN);
Stephen Hemminger2995bfb72005-09-28 10:01:03 -07004449 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004450
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004451 return dev;
4452}
4453
Stephen Hemminger28bd1812006-01-17 13:43:19 -08004454static void __devinit sky2_show_addr(struct net_device *dev)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004455{
4456 const struct sky2_port *sky2 = netdev_priv(dev);
4457
4458 if (netif_msg_probe(sky2))
Johannes Berge1749612008-10-27 15:59:26 -07004459 printk(KERN_INFO PFX "%s: addr %pM\n",
4460 dev->name, dev->dev_addr);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004461}
4462
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004463/* Handle software interrupt used during MSI test */
David Howells7d12e782006-10-05 14:55:46 +01004464static irqreturn_t __devinit sky2_test_intr(int irq, void *dev_id)
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004465{
4466 struct sky2_hw *hw = dev_id;
4467 u32 status = sky2_read32(hw, B0_Y2_SP_ISRC2);
4468
4469 if (status == 0)
4470 return IRQ_NONE;
4471
4472 if (status & Y2_IS_IRQ_SW) {
Stephen Hemmingerea76e632007-09-19 15:36:44 -07004473 hw->flags |= SKY2_HW_USE_MSI;
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004474 wake_up(&hw->msi_wait);
4475 sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ);
4476 }
4477 sky2_write32(hw, B0_Y2_SP_ICR, 2);
4478
4479 return IRQ_HANDLED;
4480}
4481
4482/* Test interrupt path by forcing a a software IRQ */
4483static int __devinit sky2_test_msi(struct sky2_hw *hw)
4484{
4485 struct pci_dev *pdev = hw->pdev;
4486 int err;
4487
shemminger@osdl.orgbb507fe2006-08-28 10:00:48 -07004488 init_waitqueue_head (&hw->msi_wait);
4489
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004490 sky2_write32(hw, B0_IMSK, Y2_IS_IRQ_SW);
4491
Stephen Hemmingerb0a20de2006-12-01 14:29:37 -08004492 err = request_irq(pdev->irq, sky2_test_intr, 0, DRV_NAME, hw);
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004493 if (err) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004494 dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq);
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004495 return err;
4496 }
4497
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004498 sky2_write8(hw, B0_CTST, CS_ST_SW_IRQ);
shemminger@osdl.orgbb507fe2006-08-28 10:00:48 -07004499 sky2_read8(hw, B0_CTST);
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004500
Stephen Hemmingerea76e632007-09-19 15:36:44 -07004501 wait_event_timeout(hw->msi_wait, (hw->flags & SKY2_HW_USE_MSI), HZ/10);
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004502
Stephen Hemmingerea76e632007-09-19 15:36:44 -07004503 if (!(hw->flags & SKY2_HW_USE_MSI)) {
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004504 /* MSI test failed, go back to INTx mode */
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004505 dev_info(&pdev->dev, "No interrupt generated using MSI, "
4506 "switching to INTx mode.\n");
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004507
4508 err = -EOPNOTSUPP;
4509 sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ);
4510 }
4511
4512 sky2_write32(hw, B0_IMSK, 0);
Stephen Hemminger2bffc232006-10-17 10:17:18 -07004513 sky2_read32(hw, B0_IMSK);
Stephen Hemmingerfb2690a2006-03-20 15:48:19 -08004514
4515 free_irq(pdev->irq, hw);
4516
4517 return err;
4518}
4519
Stephen Hemmingerc7127a32008-06-17 09:04:25 -07004520/* This driver supports yukon2 chipset only */
4521static const char *sky2_name(u8 chipid, char *buf, int sz)
4522{
4523 const char *name[] = {
4524 "XL", /* 0xb3 */
4525 "EC Ultra", /* 0xb4 */
4526 "Extreme", /* 0xb5 */
4527 "EC", /* 0xb6 */
4528 "FE", /* 0xb7 */
4529 "FE+", /* 0xb8 */
4530 "Supreme", /* 0xb9 */
Stephen Hemminger0ce8b982008-06-17 09:04:27 -07004531 "UL 2", /* 0xba */
Stephen Hemminger0f5aac72009-10-29 06:37:09 +00004532 "Unknown", /* 0xbb */
4533 "Optima", /* 0xbc */
Stephen Hemmingerc7127a32008-06-17 09:04:25 -07004534 };
4535
stephen hemmingerdae3a512009-12-14 08:33:47 +00004536 if (chipid >= CHIP_ID_YUKON_XL && chipid <= CHIP_ID_YUKON_OPT)
Stephen Hemmingerc7127a32008-06-17 09:04:25 -07004537 strncpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz);
4538 else
4539 snprintf(buf, sz, "(chip %#x)", chipid);
4540 return buf;
4541}
4542
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004543static int __devinit sky2_probe(struct pci_dev *pdev,
4544 const struct pci_device_id *ent)
4545{
shemminger@linux-foundation.org7f60c64b2007-01-26 11:38:36 -08004546 struct net_device *dev;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004547 struct sky2_hw *hw;
Stephen Hemmingerbe63a212008-01-15 11:29:29 -08004548 int err, using_dac = 0, wol_default;
Stephen Hemminger38345072009-02-03 11:27:30 +00004549 u32 reg;
Stephen Hemmingerc7127a32008-06-17 09:04:25 -07004550 char buf1[16];
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004551
Stephen Hemminger793b8832005-09-14 16:06:14 -07004552 err = pci_enable_device(pdev);
4553 if (err) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004554 dev_err(&pdev->dev, "cannot enable PCI device\n");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004555 goto err_out;
4556 }
4557
Stephen Hemminger6cc90a52009-06-11 07:03:47 +00004558 /* Get configuration information
4559 * Note: only regular PCI config access once to test for HW issues
4560 * other PCI access through shared memory for speed and to
4561 * avoid MMCONFIG problems.
4562 */
4563 err = pci_read_config_dword(pdev, PCI_DEV_REG2, &reg);
4564 if (err) {
4565 dev_err(&pdev->dev, "PCI read config failed\n");
4566 goto err_out;
4567 }
4568
4569 if (~reg == 0) {
4570 dev_err(&pdev->dev, "PCI configuration read error\n");
4571 goto err_out;
4572 }
4573
Stephen Hemminger793b8832005-09-14 16:06:14 -07004574 err = pci_request_regions(pdev, DRV_NAME);
4575 if (err) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004576 dev_err(&pdev->dev, "cannot obtain PCI resources\n");
Stephen Hemminger44a1d2e2007-04-30 14:23:49 -07004577 goto err_out_disable;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004578 }
4579
4580 pci_set_master(pdev);
4581
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08004582 if (sizeof(dma_addr_t) > sizeof(u32) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07004583 !(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)))) {
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08004584 using_dac = 1;
Yang Hongyang6a355282009-04-06 19:01:13 -07004585 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08004586 if (err < 0) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004587 dev_err(&pdev->dev, "unable to obtain 64 bit DMA "
4588 "for consistent allocations\n");
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08004589 goto err_out_free_regions;
4590 }
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08004591 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07004592 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004593 if (err) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004594 dev_err(&pdev->dev, "no usable DMA configuration\n");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004595 goto err_out_free_regions;
4596 }
4597 }
Stephen Hemmingerd1f3d4d2006-01-17 13:43:11 -08004598
Stephen Hemminger38345072009-02-03 11:27:30 +00004599
4600#ifdef __BIG_ENDIAN
4601 /* The sk98lin vendor driver uses hardware byte swapping but
4602 * this driver uses software swapping.
4603 */
4604 reg &= ~PCI_REV_DESC;
4605 err = pci_write_config_dword(pdev,PCI_DEV_REG2, reg);
4606 if (err) {
4607 dev_err(&pdev->dev, "PCI write config failed\n");
4608 goto err_out_free_regions;
4609 }
4610#endif
4611
Rafael J. Wysocki9d731d72008-10-12 20:59:48 -07004612 wol_default = device_may_wakeup(&pdev->dev) ? WAKE_MAGIC : 0;
Stephen Hemmingerbe63a212008-01-15 11:29:29 -08004613
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004614 err = -ENOMEM;
Stephen Hemminger66466792009-10-01 07:11:46 +00004615
4616 hw = kzalloc(sizeof(*hw) + strlen(DRV_NAME "@pci:")
4617 + strlen(pci_name(pdev)) + 1, GFP_KERNEL);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004618 if (!hw) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004619 dev_err(&pdev->dev, "cannot allocate hardware struct\n");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004620 goto err_out_free_regions;
4621 }
4622
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004623 hw->pdev = pdev;
Stephen Hemminger66466792009-10-01 07:11:46 +00004624 sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev));
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004625
4626 hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
4627 if (!hw->regs) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004628 dev_err(&pdev->dev, "cannot map device registers\n");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004629 goto err_out_free_hw;
4630 }
4631
Stephen Hemminger08c06d82006-01-30 11:37:54 -08004632 /* ring for status responses */
Stephen Hemminger167f53d2007-09-25 19:01:02 -07004633 hw->st_le = pci_alloc_consistent(pdev, STATUS_LE_BYTES, &hw->st_dma);
Stephen Hemminger08c06d82006-01-30 11:37:54 -08004634 if (!hw->st_le)
4635 goto err_out_iounmap;
4636
Stephen Hemmingere3173832007-02-06 10:45:39 -08004637 err = sky2_init(hw);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004638 if (err)
Stephen Hemminger793b8832005-09-14 16:06:14 -07004639 goto err_out_iounmap;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004640
Stephen Hemmingerc844d482008-08-27 20:48:23 -07004641 dev_info(&pdev->dev, "Yukon-2 %s chip revision %d\n",
4642 sky2_name(hw->chip_id, buf1, sizeof(buf1)), hw->chip_rev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004643
Stephen Hemmingere3173832007-02-06 10:45:39 -08004644 sky2_reset(hw);
4645
Stephen Hemmingerbe63a212008-01-15 11:29:29 -08004646 dev = sky2_init_netdev(hw, 0, using_dac, wol_default);
shemminger@linux-foundation.org7f60c64b2007-01-26 11:38:36 -08004647 if (!dev) {
4648 err = -ENOMEM;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004649 goto err_out_free_pci;
shemminger@linux-foundation.org7f60c64b2007-01-26 11:38:36 -08004650 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004651
Stephen Hemminger9fa1b1f2006-09-26 11:57:40 -07004652 if (!disable_msi && pci_enable_msi(pdev) == 0) {
4653 err = sky2_test_msi(hw);
4654 if (err == -EOPNOTSUPP)
4655 pci_disable_msi(pdev);
4656 else if (err)
4657 goto err_out_free_netdev;
4658 }
4659
Stephen Hemminger793b8832005-09-14 16:06:14 -07004660 err = register_netdev(dev);
4661 if (err) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004662 dev_err(&pdev->dev, "cannot register net device\n");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004663 goto err_out_free_netdev;
4664 }
4665
Brandon Philips33cb7d32009-10-29 13:58:07 +00004666 netif_carrier_off(dev);
4667
Stephen Hemminger6de16232007-10-17 13:26:42 -07004668 netif_napi_add(dev, &hw->napi, sky2_poll, NAPI_WEIGHT);
4669
Stephen Hemmingerea76e632007-09-19 15:36:44 -07004670 err = request_irq(pdev->irq, sky2_intr,
4671 (hw->flags & SKY2_HW_USE_MSI) ? 0 : IRQF_SHARED,
Stephen Hemminger66466792009-10-01 07:11:46 +00004672 hw->irq_name, hw);
Stephen Hemminger9fa1b1f2006-09-26 11:57:40 -07004673 if (err) {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004674 dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq);
Stephen Hemminger9fa1b1f2006-09-26 11:57:40 -07004675 goto err_out_unregister;
4676 }
4677 sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
Stephen Hemminger6de16232007-10-17 13:26:42 -07004678 napi_enable(&hw->napi);
Stephen Hemminger9fa1b1f2006-09-26 11:57:40 -07004679
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004680 sky2_show_addr(dev);
4681
shemminger@linux-foundation.org7f60c64b2007-01-26 11:38:36 -08004682 if (hw->ports > 1) {
4683 struct net_device *dev1;
4684
Stephen Hemmingerca519272009-09-14 06:22:29 +00004685 err = -ENOMEM;
Stephen Hemmingerbe63a212008-01-15 11:29:29 -08004686 dev1 = sky2_init_netdev(hw, 1, using_dac, wol_default);
Stephen Hemmingerca519272009-09-14 06:22:29 +00004687 if (dev1 && (err = register_netdev(dev1)) == 0)
4688 sky2_show_addr(dev1);
4689 else {
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004690 dev_warn(&pdev->dev,
4691 "register of second port failed (%d)\n", err);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004692 hw->dev[1] = NULL;
Stephen Hemmingerca519272009-09-14 06:22:29 +00004693 hw->ports = 1;
4694 if (dev1)
4695 free_netdev(dev1);
4696 }
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004697 }
4698
Stephen Hemminger32c2c302007-08-21 14:34:03 -07004699 setup_timer(&hw->watchdog_timer, sky2_watchdog, (unsigned long) hw);
Stephen Hemminger81906792007-02-15 16:40:33 -08004700 INIT_WORK(&hw->restart_work, sky2_restart);
4701
Stephen Hemminger793b8832005-09-14 16:06:14 -07004702 pci_set_drvdata(pdev, hw);
Rafael J. Wysocki1ae861e2009-12-31 12:15:54 +01004703 pdev->d3_delay = 150;
Stephen Hemminger793b8832005-09-14 16:06:14 -07004704
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004705 return 0;
4706
Stephen Hemminger793b8832005-09-14 16:06:14 -07004707err_out_unregister:
Stephen Hemmingerea76e632007-09-19 15:36:44 -07004708 if (hw->flags & SKY2_HW_USE_MSI)
Stephen Hemmingerb0a20de2006-12-01 14:29:37 -08004709 pci_disable_msi(pdev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07004710 unregister_netdev(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004711err_out_free_netdev:
4712 free_netdev(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004713err_out_free_pci:
Stephen Hemminger793b8832005-09-14 16:06:14 -07004714 sky2_write8(hw, B0_CTST, CS_RST_SET);
Stephen Hemminger167f53d2007-09-25 19:01:02 -07004715 pci_free_consistent(pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004716err_out_iounmap:
4717 iounmap(hw->regs);
4718err_out_free_hw:
4719 kfree(hw);
4720err_out_free_regions:
4721 pci_release_regions(pdev);
Stephen Hemminger44a1d2e2007-04-30 14:23:49 -07004722err_out_disable:
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004723 pci_disable_device(pdev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004724err_out:
Stephen Hemminger549a68c2007-05-11 11:21:44 -07004725 pci_set_drvdata(pdev, NULL);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004726 return err;
4727}
4728
4729static void __devexit sky2_remove(struct pci_dev *pdev)
4730{
Stephen Hemminger793b8832005-09-14 16:06:14 -07004731 struct sky2_hw *hw = pci_get_drvdata(pdev);
Stephen Hemminger6de16232007-10-17 13:26:42 -07004732 int i;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004733
Stephen Hemminger793b8832005-09-14 16:06:14 -07004734 if (!hw)
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004735 return;
4736
Stephen Hemminger32c2c302007-08-21 14:34:03 -07004737 del_timer_sync(&hw->watchdog_timer);
Stephen Hemminger6de16232007-10-17 13:26:42 -07004738 cancel_work_sync(&hw->restart_work);
Stephen Hemmingerd27ed382006-04-25 10:58:51 -07004739
Stephen Hemmingerb877fe22007-10-22 13:39:09 -07004740 for (i = hw->ports-1; i >= 0; --i)
Stephen Hemminger6de16232007-10-17 13:26:42 -07004741 unregister_netdev(hw->dev[i]);
Stephen Hemminger81906792007-02-15 16:40:33 -08004742
Stephen Hemmingerd27ed382006-04-25 10:58:51 -07004743 sky2_write32(hw, B0_IMSK, 0);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004744
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08004745 sky2_power_aux(hw);
4746
Stephen Hemminger793b8832005-09-14 16:06:14 -07004747 sky2_write8(hw, B0_CTST, CS_RST_SET);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07004748 sky2_read8(hw, B0_CTST);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004749
4750 free_irq(pdev->irq, hw);
Stephen Hemmingerea76e632007-09-19 15:36:44 -07004751 if (hw->flags & SKY2_HW_USE_MSI)
Stephen Hemmingerb0a20de2006-12-01 14:29:37 -08004752 pci_disable_msi(pdev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07004753 pci_free_consistent(pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004754 pci_release_regions(pdev);
4755 pci_disable_device(pdev);
Stephen Hemminger793b8832005-09-14 16:06:14 -07004756
Stephen Hemmingerb877fe22007-10-22 13:39:09 -07004757 for (i = hw->ports-1; i >= 0; --i)
Stephen Hemminger6de16232007-10-17 13:26:42 -07004758 free_netdev(hw->dev[i]);
4759
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004760 iounmap(hw->regs);
4761 kfree(hw);
shemminger@osdl.org5afa0a92005-09-27 15:03:00 -07004762
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004763 pci_set_drvdata(pdev, NULL);
4764}
4765
4766#ifdef CONFIG_PM
4767static int sky2_suspend(struct pci_dev *pdev, pm_message_t state)
4768{
Stephen Hemminger793b8832005-09-14 16:06:14 -07004769 struct sky2_hw *hw = pci_get_drvdata(pdev);
Stephen Hemmingere3173832007-02-06 10:45:39 -08004770 int i, wol = 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004771
Stephen Hemminger549a68c2007-05-11 11:21:44 -07004772 if (!hw)
4773 return 0;
4774
Stephen Hemminger063a0b32008-04-02 09:03:23 -07004775 del_timer_sync(&hw->watchdog_timer);
4776 cancel_work_sync(&hw->restart_work);
4777
Stephen Hemminger19720732009-08-14 05:15:16 +00004778 rtnl_lock();
Stephen Hemmingerf05267e2006-06-13 17:17:28 +09004779 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004780 struct net_device *dev = hw->dev[i];
Stephen Hemmingere3173832007-02-06 10:45:39 -08004781 struct sky2_port *sky2 = netdev_priv(dev);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004782
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07004783 sky2_detach(dev);
Stephen Hemmingere3173832007-02-06 10:45:39 -08004784
4785 if (sky2->wol)
4786 sky2_wol_init(sky2);
4787
4788 wol |= sky2->wol;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004789 }
4790
Stephen Hemminger8ab8fca2006-06-13 17:17:30 +09004791 sky2_write32(hw, B0_IMSK, 0);
Stephen Hemminger6de16232007-10-17 13:26:42 -07004792 napi_disable(&hw->napi);
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08004793 sky2_power_aux(hw);
Stephen Hemminger19720732009-08-14 05:15:16 +00004794 rtnl_unlock();
Stephen Hemmingere3173832007-02-06 10:45:39 -08004795
Linus Torvaldsd374c1c2006-06-12 12:53:27 -07004796 pci_save_state(pdev);
Stephen Hemmingere3173832007-02-06 10:45:39 -08004797 pci_enable_wake(pdev, pci_choose_state(pdev, state), wol);
Stephen Hemmingerf71eb1a2008-08-04 13:33:37 -07004798 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08004799
Stephen Hemminger2ccc99b2006-06-13 17:17:27 +09004800 return 0;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004801}
4802
4803static int sky2_resume(struct pci_dev *pdev)
4804{
Stephen Hemminger793b8832005-09-14 16:06:14 -07004805 struct sky2_hw *hw = pci_get_drvdata(pdev);
Stephen Hemminger08c06d82006-01-30 11:37:54 -08004806 int i, err;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004807
Stephen Hemminger549a68c2007-05-11 11:21:44 -07004808 if (!hw)
4809 return 0;
4810
Stephen Hemmingerf71eb1a2008-08-04 13:33:37 -07004811 err = pci_set_power_state(pdev, PCI_D0);
4812 if (err)
4813 goto out;
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08004814
4815 err = pci_restore_state(pdev);
4816 if (err)
4817 goto out;
4818
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004819 pci_enable_wake(pdev, PCI_D0, 0);
Stephen Hemminger1ad5b4a2007-04-07 16:02:27 -07004820
4821 /* Re-enable all clocks */
Stephen Hemminger05745c42007-09-19 15:36:45 -07004822 if (hw->chip_id == CHIP_ID_YUKON_EX ||
4823 hw->chip_id == CHIP_ID_YUKON_EC_U ||
4824 hw->chip_id == CHIP_ID_YUKON_FE_P)
Stephen Hemmingerb32f40c2007-11-27 10:57:27 -08004825 sky2_pci_write32(hw, PCI_DEV_REG3, 0);
Stephen Hemminger1ad5b4a2007-04-07 16:02:27 -07004826
Stephen Hemmingere3173832007-02-06 10:45:39 -08004827 sky2_reset(hw);
Stephen Hemminger8ab8fca2006-06-13 17:17:30 +09004828 sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
Stephen Hemminger6de16232007-10-17 13:26:42 -07004829 napi_enable(&hw->napi);
Stephen Hemminger8ab8fca2006-06-13 17:17:30 +09004830
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07004831 rtnl_lock();
Stephen Hemmingerf05267e2006-06-13 17:17:28 +09004832 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07004833 err = sky2_reattach(hw->dev[i]);
4834 if (err)
4835 goto out;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004836 }
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07004837 rtnl_unlock();
Stephen Hemmingereb35cf62006-06-13 17:17:31 +09004838
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08004839 return 0;
Stephen Hemminger08c06d82006-01-30 11:37:54 -08004840out:
Stephen Hemmingeraf18d8b2009-08-14 15:31:25 -07004841 rtnl_unlock();
4842
Stephen Hemmingerb02a9252007-02-06 10:45:40 -08004843 dev_err(&pdev->dev, "resume failed (%d)\n", err);
Stephen Hemmingerae306cc2006-12-20 13:06:36 -08004844 pci_disable_device(pdev);
Stephen Hemminger08c06d82006-01-30 11:37:54 -08004845 return err;
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004846}
4847#endif
4848
Stephen Hemmingere3173832007-02-06 10:45:39 -08004849static void sky2_shutdown(struct pci_dev *pdev)
4850{
4851 struct sky2_hw *hw = pci_get_drvdata(pdev);
4852 int i, wol = 0;
4853
Stephen Hemminger549a68c2007-05-11 11:21:44 -07004854 if (!hw)
4855 return;
4856
Stephen Hemminger19720732009-08-14 05:15:16 +00004857 rtnl_lock();
Stephen Hemminger5c0d6b32007-10-14 13:25:22 -07004858 del_timer_sync(&hw->watchdog_timer);
Stephen Hemmingere3173832007-02-06 10:45:39 -08004859
4860 for (i = 0; i < hw->ports; i++) {
4861 struct net_device *dev = hw->dev[i];
4862 struct sky2_port *sky2 = netdev_priv(dev);
4863
4864 if (sky2->wol) {
4865 wol = 1;
4866 sky2_wol_init(sky2);
4867 }
4868 }
4869
4870 if (wol)
4871 sky2_power_aux(hw);
Stephen Hemminger19720732009-08-14 05:15:16 +00004872 rtnl_unlock();
Stephen Hemmingere3173832007-02-06 10:45:39 -08004873
4874 pci_enable_wake(pdev, PCI_D3hot, wol);
4875 pci_enable_wake(pdev, PCI_D3cold, wol);
4876
4877 pci_disable_device(pdev);
Stephen Hemmingerf71eb1a2008-08-04 13:33:37 -07004878 pci_set_power_state(pdev, PCI_D3hot);
Stephen Hemmingere3173832007-02-06 10:45:39 -08004879}
4880
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004881static struct pci_driver sky2_driver = {
Stephen Hemminger793b8832005-09-14 16:06:14 -07004882 .name = DRV_NAME,
4883 .id_table = sky2_id_table,
4884 .probe = sky2_probe,
4885 .remove = __devexit_p(sky2_remove),
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004886#ifdef CONFIG_PM
Stephen Hemminger793b8832005-09-14 16:06:14 -07004887 .suspend = sky2_suspend,
4888 .resume = sky2_resume,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004889#endif
Stephen Hemmingere3173832007-02-06 10:45:39 -08004890 .shutdown = sky2_shutdown,
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004891};
4892
4893static int __init sky2_init_module(void)
4894{
Stephen Hemmingerc844d482008-08-27 20:48:23 -07004895 pr_info(PFX "driver version " DRV_VERSION "\n");
4896
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004897 sky2_debug_init();
shemminger@osdl.org50241c42005-11-30 11:45:22 -08004898 return pci_register_driver(&sky2_driver);
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004899}
4900
4901static void __exit sky2_cleanup_module(void)
4902{
4903 pci_unregister_driver(&sky2_driver);
Stephen Hemminger3cf26752007-07-09 15:33:35 -07004904 sky2_debug_cleanup();
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004905}
4906
4907module_init(sky2_init_module);
4908module_exit(sky2_cleanup_module);
4909
4910MODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver");
Stephen Hemminger65ebe6342007-01-23 11:38:57 -08004911MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
Stephen Hemmingercd28ab62005-08-16 16:36:49 -07004912MODULE_LICENSE("GPL");
shemminger@osdl.org5f4f9dc2005-11-30 11:45:23 -08004913MODULE_VERSION(DRV_VERSION);