blob: edb9bda55d556132d73e72ddcebef91ccf20c747 [file] [log] [blame]
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001/*
2 * New driver for Marvell Yukon chipset and SysKonnect Gigabit
3 * Ethernet adapters. Based on earlier sk98lin, e100 and
4 * FreeBSD if_sk drivers.
5 *
6 * This driver intentionally does not support all the features
7 * of the original driver such as link fail-over and link management because
8 * those should be done at higher levels.
9 *
Stephen Hemminger747802a2005-06-27 11:33:16 -070010 * Copyright (C) 2004, 2005 Stephen Hemminger <shemminger@osdl.org>
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
Stephen Hemminger798b6b12006-10-22 20:16:57 -070014 * the Free Software Foundation; either version 2 of the License.
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040015 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
Joe Perchesf15063c2010-02-17 15:01:57 +000026#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020028#include <linux/in.h>
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040029#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/netdevice.h>
33#include <linux/etherdevice.h>
34#include <linux/ethtool.h>
35#include <linux/pci.h>
36#include <linux/if_vlan.h>
37#include <linux/ip.h>
38#include <linux/delay.h>
39#include <linux/crc32.h>
Al Viro40754002005-04-03 09:15:52 +010040#include <linux/dma-mapping.h>
Stephen Hemminger678aa1f2007-10-16 12:15:54 -070041#include <linux/debugfs.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040042#include <linux/sched.h>
Stephen Hemminger678aa1f2007-10-16 12:15:54 -070043#include <linux/seq_file.h>
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -080044#include <linux/mii.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090045#include <linux/slab.h>
Stanislaw Gruszka392bd0c2010-10-05 15:11:40 -070046#include <linux/dmi.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040047#include <linux/prefetch.h>
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040048#include <asm/irq.h>
49
50#include "skge.h"
51
52#define DRV_NAME "skge"
stephen hemminger5a9d6912011-07-06 19:00:08 +000053#define DRV_VERSION "1.14"
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040054
55#define DEFAULT_TX_RING_SIZE 128
56#define DEFAULT_RX_RING_SIZE 512
57#define MAX_TX_RING_SIZE 1024
Stephen Hemminger9db96472006-06-06 10:11:12 -070058#define TX_LOW_WATER (MAX_SKB_FRAGS + 1)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040059#define MAX_RX_RING_SIZE 4096
Stephen Hemminger19a33d42005-06-27 11:33:15 -070060#define RX_COPY_THRESHOLD 128
61#define RX_BUF_SIZE 1536
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040062#define PHY_RETRIES 1000
63#define ETH_JUMBO_MTU 9000
64#define TX_WATCHDOG (5 * HZ)
65#define NAPI_WEIGHT 64
Stephen Hemminger6abebb52005-07-22 16:26:10 -070066#define BLINK_MS 250
Stephen Hemminger501fb722007-10-16 12:15:51 -070067#define LINK_HZ HZ
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040068
Stephen Hemmingerafa151b2007-10-16 12:15:53 -070069#define SKGE_EEPROM_MAGIC 0x9933aabb
70
71
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040072MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver");
Stephen Hemminger65ebe6342007-01-23 11:38:57 -080073MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040074MODULE_LICENSE("GPL");
75MODULE_VERSION(DRV_VERSION);
76
Joe Perches67777f92010-02-17 15:01:58 +000077static const u32 default_msg = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
78 NETIF_MSG_LINK | NETIF_MSG_IFUP |
79 NETIF_MSG_IFDOWN);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040080
81static int debug = -1; /* defaults above */
82module_param(debug, int, 0);
83MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
84
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000085static DEFINE_PCI_DEVICE_TABLE(skge_id_table) = {
stephen hemminger6f7d32f2011-07-06 19:00:05 +000086 { PCI_DEVICE(PCI_VENDOR_ID_3COM, 0x1700) }, /* 3Com 3C940 */
87 { PCI_DEVICE(PCI_VENDOR_ID_3COM, 0x80EB) }, /* 3Com 3C940B */
stephen hemminger57d6fa32011-07-06 19:00:07 +000088#ifdef CONFIG_SKGE_GENESIS
89 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x4300) }, /* SK-9xx */
90#endif
stephen hemminger6f7d32f2011-07-06 19:00:05 +000091 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x4320) }, /* SK-98xx V2.0 */
92 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b01) }, /* D-Link DGE-530T (rev.B) */
93 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4c00) }, /* D-Link DGE-530T */
stephen hemmingerc0743042011-07-06 19:00:06 +000094 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302) }, /* D-Link DGE-530T Rev C1 */
stephen hemminger6f7d32f2011-07-06 19:00:05 +000095 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) }, /* Marvell Yukon 88E8001/8003/8010 */
96 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */
97 { PCI_DEVICE(PCI_VENDOR_ID_CNET, 0x434E) }, /* CNet PowerG-2000 */
98 { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, 0x1064) }, /* Linksys EG1064 v2 */
99 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015 }, /* Linksys EG1032 v2 */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400100 { 0 }
101};
102MODULE_DEVICE_TABLE(pci, skge_id_table);
103
104static int skge_up(struct net_device *dev);
105static int skge_down(struct net_device *dev);
Stephen Hemmingeree294dc2005-12-14 15:47:44 -0800106static void skge_phy_reset(struct skge_port *skge);
Stephen Hemminger513f5332006-09-01 15:53:49 -0700107static void skge_tx_clean(struct net_device *dev);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -0800108static int xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val);
109static int gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400110static void genesis_get_stats(struct skge_port *skge, u64 *data);
111static void yukon_get_stats(struct skge_port *skge, u64 *data);
112static void yukon_init(struct skge_hw *hw, int port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400113static void genesis_mac_init(struct skge_hw *hw, int port);
Stephen Hemminger45bada62005-06-27 11:33:12 -0700114static void genesis_link_up(struct skge_port *skge);
Stephen Hemmingerf80d0322008-11-19 22:01:26 -0800115static void skge_set_multicast(struct net_device *dev);
Stephen Hemmingera9e9fd72011-09-27 13:41:37 -0400116static irqreturn_t skge_intr(int irq, void *dev_id);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400117
Stephen Hemminger7e676d92005-06-27 11:33:13 -0700118/* Avoid conditionals by using array */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400119static const int txqaddr[] = { Q_XA1, Q_XA2 };
120static const int rxqaddr[] = { Q_R1, Q_R2 };
121static const u32 rxirqmask[] = { IS_R1_F, IS_R2_F };
122static const u32 txirqmask[] = { IS_XA1_F, IS_XA2_F };
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -0700123static const u32 napimask[] = { IS_R1_F|IS_XA1_F, IS_R2_F|IS_XA2_F };
124static const u32 portmask[] = { IS_PORT_1, IS_PORT_2 };
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400125
stephen hemminger57d6fa32011-07-06 19:00:07 +0000126static inline bool is_genesis(const struct skge_hw *hw)
127{
128#ifdef CONFIG_SKGE_GENESIS
129 return hw->chip_id == CHIP_ID_GENESIS;
130#else
131 return false;
132#endif
133}
134
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400135static int skge_get_regs_len(struct net_device *dev)
136{
Stephen Hemmingerc3f8be92005-09-19 15:37:34 -0700137 return 0x4000;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400138}
139
140/*
Stephen Hemmingerc3f8be92005-09-19 15:37:34 -0700141 * Returns copy of whole control register region
142 * Note: skip RAM address register because accessing it will
143 * cause bus hangs!
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400144 */
145static void skge_get_regs(struct net_device *dev, struct ethtool_regs *regs,
146 void *p)
147{
148 const struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400149 const void __iomem *io = skge->hw->regs;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400150
151 regs->version = 1;
Stephen Hemmingerc3f8be92005-09-19 15:37:34 -0700152 memset(p, 0, regs->len);
153 memcpy_fromio(p, io, B3_RAM_ADDR);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400154
Stephen Hemmingerc3f8be92005-09-19 15:37:34 -0700155 memcpy_fromio(p + B3_RI_WTO_R1, io + B3_RI_WTO_R1,
156 regs->len - B3_RI_WTO_R1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400157}
158
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800159/* Wake on Lan only supported on Yukon chips with rev 1 or above */
Stephen Hemmingera504e642007-02-02 08:22:53 -0800160static u32 wol_supported(const struct skge_hw *hw)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400161{
stephen hemminger57d6fa32011-07-06 19:00:07 +0000162 if (is_genesis(hw))
Stephen Hemmingera504e642007-02-02 08:22:53 -0800163 return 0;
Stephen Hemmingerd17ecb22007-05-07 11:01:55 -0700164
165 if (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)
166 return 0;
167
168 return WAKE_MAGIC | WAKE_PHY;
Stephen Hemmingera504e642007-02-02 08:22:53 -0800169}
170
Stephen Hemmingera504e642007-02-02 08:22:53 -0800171static void skge_wol_init(struct skge_port *skge)
172{
173 struct skge_hw *hw = skge->hw;
174 int port = skge->port;
Stephen Hemminger692412b2007-04-09 15:32:45 -0700175 u16 ctrl;
Stephen Hemmingera504e642007-02-02 08:22:53 -0800176
Stephen Hemmingera504e642007-02-02 08:22:53 -0800177 skge_write16(hw, B0_CTST, CS_RST_CLR);
178 skge_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR);
179
Stephen Hemminger692412b2007-04-09 15:32:45 -0700180 /* Turn on Vaux */
181 skge_write8(hw, B0_POWER_CTRL,
182 PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_ON | PC_VCC_OFF);
183
184 /* WA code for COMA mode -- clear PHY reset */
185 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
186 hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
187 u32 reg = skge_read32(hw, B2_GP_IO);
188 reg |= GP_DIR_9;
189 reg &= ~GP_IO_9;
190 skge_write32(hw, B2_GP_IO, reg);
191 }
192
193 skge_write32(hw, SK_REG(port, GPHY_CTRL),
194 GPC_DIS_SLEEP |
195 GPC_HWCFG_M_3 | GPC_HWCFG_M_2 | GPC_HWCFG_M_1 | GPC_HWCFG_M_0 |
196 GPC_ANEG_1 | GPC_RST_SET);
197
198 skge_write32(hw, SK_REG(port, GPHY_CTRL),
199 GPC_DIS_SLEEP |
200 GPC_HWCFG_M_3 | GPC_HWCFG_M_2 | GPC_HWCFG_M_1 | GPC_HWCFG_M_0 |
201 GPC_ANEG_1 | GPC_RST_CLR);
202
203 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
Stephen Hemmingera504e642007-02-02 08:22:53 -0800204
205 /* Force to 10/100 skge_reset will re-enable on resume */
Stephen Hemminger692412b2007-04-09 15:32:45 -0700206 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV,
Joe Perches67777f92010-02-17 15:01:58 +0000207 (PHY_AN_100FULL | PHY_AN_100HALF |
208 PHY_AN_10FULL | PHY_AN_10HALF | PHY_AN_CSMA));
Stephen Hemminger692412b2007-04-09 15:32:45 -0700209 /* no 1000 HD/FD */
210 gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, 0);
211 gm_phy_write(hw, port, PHY_MARV_CTRL,
212 PHY_CT_RESET | PHY_CT_SPS_LSB | PHY_CT_ANE |
213 PHY_CT_RE_CFG | PHY_CT_DUP_MD);
Stephen Hemmingera504e642007-02-02 08:22:53 -0800214
Stephen Hemmingera504e642007-02-02 08:22:53 -0800215
216 /* Set GMAC to no flow control and auto update for speed/duplex */
217 gma_write16(hw, port, GM_GP_CTRL,
218 GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA|
219 GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS);
220
221 /* Set WOL address */
222 memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR),
223 skge->netdev->dev_addr, ETH_ALEN);
224
225 /* Turn on appropriate WOL control bits */
226 skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT);
227 ctrl = 0;
228 if (skge->wol & WAKE_PHY)
229 ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT;
230 else
231 ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT;
232
233 if (skge->wol & WAKE_MAGIC)
234 ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT;
235 else
Joe Perchesa419aef2009-08-18 11:18:35 -0700236 ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT;
Stephen Hemmingera504e642007-02-02 08:22:53 -0800237
238 ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT;
239 skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
240
241 /* block receiver */
242 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400243}
244
245static void skge_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
246{
247 struct skge_port *skge = netdev_priv(dev);
248
Stephen Hemmingera504e642007-02-02 08:22:53 -0800249 wol->supported = wol_supported(skge->hw);
250 wol->wolopts = skge->wol;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400251}
252
253static int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
254{
255 struct skge_port *skge = netdev_priv(dev);
256 struct skge_hw *hw = skge->hw;
257
Joe Perches8e95a202009-12-03 07:58:21 +0000258 if ((wol->wolopts & ~wol_supported(hw)) ||
259 !device_can_wakeup(&hw->pdev->dev))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400260 return -EOPNOTSUPP;
261
Stephen Hemmingera504e642007-02-02 08:22:53 -0800262 skge->wol = wol->wolopts;
Rafael J. Wysocki5177b322008-10-29 14:22:14 -0700263
264 device_set_wakeup_enable(&hw->pdev->dev, skge->wol);
265
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400266 return 0;
267}
268
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800269/* Determine supported/advertised modes based on hardware.
270 * Note: ethtool ADVERTISED_xxx == SUPPORTED_xxx
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700271 */
272static u32 skge_supported_modes(const struct skge_hw *hw)
273{
274 u32 supported;
275
Stephen Hemminger5e1705d2005-08-16 14:00:58 -0700276 if (hw->copper) {
Joe Perches67777f92010-02-17 15:01:58 +0000277 supported = (SUPPORTED_10baseT_Half |
278 SUPPORTED_10baseT_Full |
279 SUPPORTED_100baseT_Half |
280 SUPPORTED_100baseT_Full |
281 SUPPORTED_1000baseT_Half |
282 SUPPORTED_1000baseT_Full |
283 SUPPORTED_Autoneg |
284 SUPPORTED_TP);
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700285
stephen hemminger57d6fa32011-07-06 19:00:07 +0000286 if (is_genesis(hw))
Joe Perches67777f92010-02-17 15:01:58 +0000287 supported &= ~(SUPPORTED_10baseT_Half |
288 SUPPORTED_10baseT_Full |
289 SUPPORTED_100baseT_Half |
290 SUPPORTED_100baseT_Full);
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700291
292 else if (hw->chip_id == CHIP_ID_YUKON)
293 supported &= ~SUPPORTED_1000baseT_Half;
294 } else
Joe Perches67777f92010-02-17 15:01:58 +0000295 supported = (SUPPORTED_1000baseT_Full |
296 SUPPORTED_1000baseT_Half |
297 SUPPORTED_FIBRE |
298 SUPPORTED_Autoneg);
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700299
300 return supported;
301}
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400302
303static int skge_get_settings(struct net_device *dev,
304 struct ethtool_cmd *ecmd)
305{
306 struct skge_port *skge = netdev_priv(dev);
307 struct skge_hw *hw = skge->hw;
308
309 ecmd->transceiver = XCVR_INTERNAL;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700310 ecmd->supported = skge_supported_modes(hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400311
Stephen Hemminger5e1705d2005-08-16 14:00:58 -0700312 if (hw->copper) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400313 ecmd->port = PORT_TP;
314 ecmd->phy_address = hw->phy_addr;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700315 } else
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400316 ecmd->port = PORT_FIBRE;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400317
318 ecmd->advertising = skge->advertising;
319 ecmd->autoneg = skge->autoneg;
David Decotigny70739492011-04-27 18:32:40 +0000320 ethtool_cmd_speed_set(ecmd, skge->speed);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400321 ecmd->duplex = skge->duplex;
322 return 0;
323}
324
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400325static int skge_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
326{
327 struct skge_port *skge = netdev_priv(dev);
328 const struct skge_hw *hw = skge->hw;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700329 u32 supported = skge_supported_modes(hw);
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000330 int err = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400331
332 if (ecmd->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700333 ecmd->advertising = supported;
334 skge->duplex = -1;
335 skge->speed = -1;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400336 } else {
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700337 u32 setting;
David Decotigny25db0332011-04-27 18:32:39 +0000338 u32 speed = ethtool_cmd_speed(ecmd);
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700339
David Decotigny25db0332011-04-27 18:32:39 +0000340 switch (speed) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400341 case SPEED_1000:
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700342 if (ecmd->duplex == DUPLEX_FULL)
343 setting = SUPPORTED_1000baseT_Full;
344 else if (ecmd->duplex == DUPLEX_HALF)
345 setting = SUPPORTED_1000baseT_Half;
346 else
347 return -EINVAL;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400348 break;
349 case SPEED_100:
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700350 if (ecmd->duplex == DUPLEX_FULL)
351 setting = SUPPORTED_100baseT_Full;
352 else if (ecmd->duplex == DUPLEX_HALF)
353 setting = SUPPORTED_100baseT_Half;
354 else
355 return -EINVAL;
356 break;
357
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400358 case SPEED_10:
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700359 if (ecmd->duplex == DUPLEX_FULL)
360 setting = SUPPORTED_10baseT_Full;
361 else if (ecmd->duplex == DUPLEX_HALF)
362 setting = SUPPORTED_10baseT_Half;
363 else
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400364 return -EINVAL;
365 break;
366 default:
367 return -EINVAL;
368 }
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700369
370 if ((setting & supported) == 0)
371 return -EINVAL;
372
David Decotigny25db0332011-04-27 18:32:39 +0000373 skge->speed = speed;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700374 skge->duplex = ecmd->duplex;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400375 }
376
377 skge->autoneg = ecmd->autoneg;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400378 skge->advertising = ecmd->advertising;
379
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000380 if (netif_running(dev)) {
381 skge_down(dev);
382 err = skge_up(dev);
383 if (err) {
384 dev_close(dev);
385 return err;
386 }
387 }
Stephen Hemmingeree294dc2005-12-14 15:47:44 -0800388
Joe Perches67777f92010-02-17 15:01:58 +0000389 return 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400390}
391
392static void skge_get_drvinfo(struct net_device *dev,
393 struct ethtool_drvinfo *info)
394{
395 struct skge_port *skge = netdev_priv(dev);
396
Rick Jones68aad782011-11-07 13:29:27 +0000397 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
398 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
Rick Jones68aad782011-11-07 13:29:27 +0000399 strlcpy(info->bus_info, pci_name(skge->hw->pdev),
400 sizeof(info->bus_info));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400401}
402
403static const struct skge_stat {
404 char name[ETH_GSTRING_LEN];
405 u16 xmac_offset;
406 u16 gma_offset;
407} skge_stats[] = {
408 { "tx_bytes", XM_TXO_OK_HI, GM_TXO_OK_HI },
409 { "rx_bytes", XM_RXO_OK_HI, GM_RXO_OK_HI },
410
411 { "tx_broadcast", XM_TXF_BC_OK, GM_TXF_BC_OK },
412 { "rx_broadcast", XM_RXF_BC_OK, GM_RXF_BC_OK },
413 { "tx_multicast", XM_TXF_MC_OK, GM_TXF_MC_OK },
414 { "rx_multicast", XM_RXF_MC_OK, GM_RXF_MC_OK },
415 { "tx_unicast", XM_TXF_UC_OK, GM_TXF_UC_OK },
416 { "rx_unicast", XM_RXF_UC_OK, GM_RXF_UC_OK },
417 { "tx_mac_pause", XM_TXF_MPAUSE, GM_TXF_MPAUSE },
418 { "rx_mac_pause", XM_RXF_MPAUSE, GM_RXF_MPAUSE },
419
420 { "collisions", XM_TXF_SNG_COL, GM_TXF_SNG_COL },
421 { "multi_collisions", XM_TXF_MUL_COL, GM_TXF_MUL_COL },
422 { "aborted", XM_TXF_ABO_COL, GM_TXF_ABO_COL },
423 { "late_collision", XM_TXF_LAT_COL, GM_TXF_LAT_COL },
424 { "fifo_underrun", XM_TXE_FIFO_UR, GM_TXE_FIFO_UR },
425 { "fifo_overflow", XM_RXE_FIFO_OV, GM_RXE_FIFO_OV },
426
427 { "rx_toolong", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR },
428 { "rx_jabber", XM_RXF_JAB_PKT, GM_RXF_JAB_PKT },
429 { "rx_runt", XM_RXE_RUNT, GM_RXE_FRAG },
430 { "rx_too_long", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR },
431 { "rx_fcs_error", XM_RXF_FCS_ERR, GM_RXF_FCS_ERR },
432};
433
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700434static int skge_get_sset_count(struct net_device *dev, int sset)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400435{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700436 switch (sset) {
437 case ETH_SS_STATS:
438 return ARRAY_SIZE(skge_stats);
439 default:
440 return -EOPNOTSUPP;
441 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400442}
443
444static void skge_get_ethtool_stats(struct net_device *dev,
445 struct ethtool_stats *stats, u64 *data)
446{
447 struct skge_port *skge = netdev_priv(dev);
448
stephen hemminger57d6fa32011-07-06 19:00:07 +0000449 if (is_genesis(skge->hw))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400450 genesis_get_stats(skge, data);
451 else
452 yukon_get_stats(skge, data);
453}
454
455/* Use hardware MIB variables for critical path statistics and
456 * transmit feedback not reported at interrupt.
457 * Other errors are accounted for in interrupt handler.
458 */
459static struct net_device_stats *skge_get_stats(struct net_device *dev)
460{
461 struct skge_port *skge = netdev_priv(dev);
462 u64 data[ARRAY_SIZE(skge_stats)];
463
stephen hemminger57d6fa32011-07-06 19:00:07 +0000464 if (is_genesis(skge->hw))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400465 genesis_get_stats(skge, data);
466 else
467 yukon_get_stats(skge, data);
468
Stephen Hemmingerda007722007-10-16 12:15:52 -0700469 dev->stats.tx_bytes = data[0];
470 dev->stats.rx_bytes = data[1];
471 dev->stats.tx_packets = data[2] + data[4] + data[6];
472 dev->stats.rx_packets = data[3] + data[5] + data[7];
473 dev->stats.multicast = data[3] + data[5];
474 dev->stats.collisions = data[10];
475 dev->stats.tx_aborted_errors = data[12];
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400476
Stephen Hemmingerda007722007-10-16 12:15:52 -0700477 return &dev->stats;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400478}
479
480static void skge_get_strings(struct net_device *dev, u32 stringset, u8 *data)
481{
482 int i;
483
Stephen Hemminger95566062005-06-27 11:33:02 -0700484 switch (stringset) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400485 case ETH_SS_STATS:
486 for (i = 0; i < ARRAY_SIZE(skge_stats); i++)
487 memcpy(data + i * ETH_GSTRING_LEN,
488 skge_stats[i].name, ETH_GSTRING_LEN);
489 break;
490 }
491}
492
493static void skge_get_ring_param(struct net_device *dev,
494 struct ethtool_ringparam *p)
495{
496 struct skge_port *skge = netdev_priv(dev);
497
498 p->rx_max_pending = MAX_RX_RING_SIZE;
499 p->tx_max_pending = MAX_TX_RING_SIZE;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400500
501 p->rx_pending = skge->rx_ring.count;
502 p->tx_pending = skge->tx_ring.count;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400503}
504
505static int skge_set_ring_param(struct net_device *dev,
506 struct ethtool_ringparam *p)
507{
508 struct skge_port *skge = netdev_priv(dev);
Wang Chene824b3e2008-09-26 16:20:32 +0800509 int err = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400510
511 if (p->rx_pending == 0 || p->rx_pending > MAX_RX_RING_SIZE ||
Stephen Hemminger9db96472006-06-06 10:11:12 -0700512 p->tx_pending < TX_LOW_WATER || p->tx_pending > MAX_TX_RING_SIZE)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400513 return -EINVAL;
514
515 skge->rx_ring.count = p->rx_pending;
516 skge->tx_ring.count = p->tx_pending;
517
518 if (netif_running(dev)) {
519 skge_down(dev);
Stephen Hemminger3b8bb472005-12-14 15:47:48 -0800520 err = skge_up(dev);
521 if (err)
522 dev_close(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400523 }
524
Wang Chene824b3e2008-09-26 16:20:32 +0800525 return err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400526}
527
528static u32 skge_get_msglevel(struct net_device *netdev)
529{
530 struct skge_port *skge = netdev_priv(netdev);
531 return skge->msg_enable;
532}
533
534static void skge_set_msglevel(struct net_device *netdev, u32 value)
535{
536 struct skge_port *skge = netdev_priv(netdev);
537 skge->msg_enable = value;
538}
539
540static int skge_nway_reset(struct net_device *dev)
541{
542 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400543
544 if (skge->autoneg != AUTONEG_ENABLE || !netif_running(dev))
545 return -EINVAL;
546
Stephen Hemmingeree294dc2005-12-14 15:47:44 -0800547 skge_phy_reset(skge);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400548 return 0;
549}
550
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400551static void skge_get_pauseparam(struct net_device *dev,
552 struct ethtool_pauseparam *ecmd)
553{
554 struct skge_port *skge = netdev_priv(dev);
555
Joe Perches8e95a202009-12-03 07:58:21 +0000556 ecmd->rx_pause = ((skge->flow_control == FLOW_MODE_SYMMETRIC) ||
557 (skge->flow_control == FLOW_MODE_SYM_OR_REM));
558 ecmd->tx_pause = (ecmd->rx_pause ||
559 (skge->flow_control == FLOW_MODE_LOC_SEND));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400560
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700561 ecmd->autoneg = ecmd->rx_pause || ecmd->tx_pause;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400562}
563
564static int skge_set_pauseparam(struct net_device *dev,
565 struct ethtool_pauseparam *ecmd)
566{
567 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700568 struct ethtool_pauseparam old;
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000569 int err = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400570
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700571 skge_get_pauseparam(dev, &old);
572
573 if (ecmd->autoneg != old.autoneg)
574 skge->flow_control = ecmd->autoneg ? FLOW_MODE_NONE : FLOW_MODE_SYMMETRIC;
575 else {
576 if (ecmd->rx_pause && ecmd->tx_pause)
577 skge->flow_control = FLOW_MODE_SYMMETRIC;
578 else if (ecmd->rx_pause && !ecmd->tx_pause)
579 skge->flow_control = FLOW_MODE_SYM_OR_REM;
580 else if (!ecmd->rx_pause && ecmd->tx_pause)
581 skge->flow_control = FLOW_MODE_LOC_SEND;
582 else
583 skge->flow_control = FLOW_MODE_NONE;
584 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400585
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000586 if (netif_running(dev)) {
587 skge_down(dev);
588 err = skge_up(dev);
589 if (err) {
590 dev_close(dev);
591 return err;
592 }
593 }
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700594
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400595 return 0;
596}
597
598/* Chip internal frequency for clock calculations */
599static inline u32 hwkhz(const struct skge_hw *hw)
600{
stephen hemminger57d6fa32011-07-06 19:00:07 +0000601 return is_genesis(hw) ? 53125 : 78125;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400602}
603
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800604/* Chip HZ to microseconds */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400605static inline u32 skge_clk2usec(const struct skge_hw *hw, u32 ticks)
606{
607 return (ticks * 1000) / hwkhz(hw);
608}
609
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800610/* Microseconds to chip HZ */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400611static inline u32 skge_usecs2clk(const struct skge_hw *hw, u32 usec)
612{
613 return hwkhz(hw) * usec / 1000;
614}
615
616static int skge_get_coalesce(struct net_device *dev,
617 struct ethtool_coalesce *ecmd)
618{
619 struct skge_port *skge = netdev_priv(dev);
620 struct skge_hw *hw = skge->hw;
621 int port = skge->port;
622
623 ecmd->rx_coalesce_usecs = 0;
624 ecmd->tx_coalesce_usecs = 0;
625
626 if (skge_read32(hw, B2_IRQM_CTRL) & TIM_START) {
627 u32 delay = skge_clk2usec(hw, skge_read32(hw, B2_IRQM_INI));
628 u32 msk = skge_read32(hw, B2_IRQM_MSK);
629
630 if (msk & rxirqmask[port])
631 ecmd->rx_coalesce_usecs = delay;
632 if (msk & txirqmask[port])
633 ecmd->tx_coalesce_usecs = delay;
634 }
635
636 return 0;
637}
638
639/* Note: interrupt timer is per board, but can turn on/off per port */
640static int skge_set_coalesce(struct net_device *dev,
641 struct ethtool_coalesce *ecmd)
642{
643 struct skge_port *skge = netdev_priv(dev);
644 struct skge_hw *hw = skge->hw;
645 int port = skge->port;
646 u32 msk = skge_read32(hw, B2_IRQM_MSK);
647 u32 delay = 25;
648
649 if (ecmd->rx_coalesce_usecs == 0)
650 msk &= ~rxirqmask[port];
651 else if (ecmd->rx_coalesce_usecs < 25 ||
652 ecmd->rx_coalesce_usecs > 33333)
653 return -EINVAL;
654 else {
655 msk |= rxirqmask[port];
656 delay = ecmd->rx_coalesce_usecs;
657 }
658
659 if (ecmd->tx_coalesce_usecs == 0)
660 msk &= ~txirqmask[port];
661 else if (ecmd->tx_coalesce_usecs < 25 ||
662 ecmd->tx_coalesce_usecs > 33333)
663 return -EINVAL;
664 else {
665 msk |= txirqmask[port];
666 delay = min(delay, ecmd->rx_coalesce_usecs);
667 }
668
669 skge_write32(hw, B2_IRQM_MSK, msk);
670 if (msk == 0)
671 skge_write32(hw, B2_IRQM_CTRL, TIM_STOP);
672 else {
673 skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, delay));
674 skge_write32(hw, B2_IRQM_CTRL, TIM_START);
675 }
676 return 0;
677}
678
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700679enum led_mode { LED_MODE_OFF, LED_MODE_ON, LED_MODE_TST };
680static void skge_led(struct skge_port *skge, enum led_mode mode)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400681{
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400682 struct skge_hw *hw = skge->hw;
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700683 int port = skge->port;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400684
Stephen Hemminger9cbe3302007-03-16 14:01:28 -0700685 spin_lock_bh(&hw->phy_lock);
stephen hemminger57d6fa32011-07-06 19:00:07 +0000686 if (is_genesis(hw)) {
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700687 switch (mode) {
688 case LED_MODE_OFF:
Stephen Hemminger64f6b642006-09-23 21:25:28 -0700689 if (hw->phy_type == SK_PHY_BCOM)
690 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF);
691 else {
692 skge_write32(hw, SK_REG(port, TX_LED_VAL), 0);
693 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_T_OFF);
694 }
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700695 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
696 skge_write32(hw, SK_REG(port, RX_LED_VAL), 0);
697 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF);
698 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400699
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700700 case LED_MODE_ON:
701 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON);
702 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON);
703
704 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
705 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
706
707 break;
708
709 case LED_MODE_TST:
710 skge_write8(hw, SK_REG(port, RX_LED_TST), LED_T_ON);
711 skge_write32(hw, SK_REG(port, RX_LED_VAL), 100);
712 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
713
Stephen Hemminger64f6b642006-09-23 21:25:28 -0700714 if (hw->phy_type == SK_PHY_BCOM)
715 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON);
716 else {
717 skge_write8(hw, SK_REG(port, TX_LED_TST), LED_T_ON);
718 skge_write32(hw, SK_REG(port, TX_LED_VAL), 100);
719 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
720 }
721
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700722 }
723 } else {
724 switch (mode) {
725 case LED_MODE_OFF:
726 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
727 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
728 PHY_M_LED_MO_DUP(MO_LED_OFF) |
729 PHY_M_LED_MO_10(MO_LED_OFF) |
730 PHY_M_LED_MO_100(MO_LED_OFF) |
731 PHY_M_LED_MO_1000(MO_LED_OFF) |
732 PHY_M_LED_MO_RX(MO_LED_OFF));
733 break;
734 case LED_MODE_ON:
735 gm_phy_write(hw, port, PHY_MARV_LED_CTRL,
736 PHY_M_LED_PULS_DUR(PULS_170MS) |
737 PHY_M_LED_BLINK_RT(BLINK_84MS) |
738 PHY_M_LEDC_TX_CTRL |
739 PHY_M_LEDC_DP_CTRL);
Stephen Hemminger46a60f22005-09-09 12:54:56 -0700740
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700741 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
742 PHY_M_LED_MO_RX(MO_LED_OFF) |
743 (skge->speed == SPEED_100 ?
744 PHY_M_LED_MO_100(MO_LED_ON) : 0));
745 break;
746 case LED_MODE_TST:
747 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
748 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
749 PHY_M_LED_MO_DUP(MO_LED_ON) |
750 PHY_M_LED_MO_10(MO_LED_ON) |
751 PHY_M_LED_MO_100(MO_LED_ON) |
752 PHY_M_LED_MO_1000(MO_LED_ON) |
753 PHY_M_LED_MO_RX(MO_LED_ON));
754 }
755 }
Stephen Hemminger9cbe3302007-03-16 14:01:28 -0700756 spin_unlock_bh(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400757}
758
759/* blink LED's for finding board */
stephen hemmingera5b9f412011-04-04 08:43:42 +0000760static int skge_set_phys_id(struct net_device *dev,
761 enum ethtool_phys_id_state state)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400762{
763 struct skge_port *skge = netdev_priv(dev);
764
stephen hemmingera5b9f412011-04-04 08:43:42 +0000765 switch (state) {
766 case ETHTOOL_ID_ACTIVE:
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000767 return 2; /* cycle on/off twice per second */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400768
stephen hemmingera5b9f412011-04-04 08:43:42 +0000769 case ETHTOOL_ID_ON:
770 skge_led(skge, LED_MODE_TST);
771 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400772
stephen hemmingera5b9f412011-04-04 08:43:42 +0000773 case ETHTOOL_ID_OFF:
774 skge_led(skge, LED_MODE_OFF);
775 break;
776
777 case ETHTOOL_ID_INACTIVE:
778 /* back to regular LED state */
779 skge_led(skge, netif_running(dev) ? LED_MODE_ON : LED_MODE_OFF);
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700780 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400781
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400782 return 0;
783}
784
Stephen Hemmingerafa151b2007-10-16 12:15:53 -0700785static int skge_get_eeprom_len(struct net_device *dev)
786{
787 struct skge_port *skge = netdev_priv(dev);
788 u32 reg2;
789
790 pci_read_config_dword(skge->hw->pdev, PCI_DEV_REG2, &reg2);
Joe Perches67777f92010-02-17 15:01:58 +0000791 return 1 << (((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
Stephen Hemmingerafa151b2007-10-16 12:15:53 -0700792}
793
794static u32 skge_vpd_read(struct pci_dev *pdev, int cap, u16 offset)
795{
796 u32 val;
797
798 pci_write_config_word(pdev, cap + PCI_VPD_ADDR, offset);
799
800 do {
801 pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
802 } while (!(offset & PCI_VPD_ADDR_F));
803
804 pci_read_config_dword(pdev, cap + PCI_VPD_DATA, &val);
805 return val;
806}
807
808static void skge_vpd_write(struct pci_dev *pdev, int cap, u16 offset, u32 val)
809{
810 pci_write_config_dword(pdev, cap + PCI_VPD_DATA, val);
811 pci_write_config_word(pdev, cap + PCI_VPD_ADDR,
812 offset | PCI_VPD_ADDR_F);
813
814 do {
815 pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
816 } while (offset & PCI_VPD_ADDR_F);
817}
818
819static int skge_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
820 u8 *data)
821{
822 struct skge_port *skge = netdev_priv(dev);
823 struct pci_dev *pdev = skge->hw->pdev;
824 int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD);
825 int length = eeprom->len;
826 u16 offset = eeprom->offset;
827
828 if (!cap)
829 return -EINVAL;
830
831 eeprom->magic = SKGE_EEPROM_MAGIC;
832
833 while (length > 0) {
834 u32 val = skge_vpd_read(pdev, cap, offset);
835 int n = min_t(int, length, sizeof(val));
836
837 memcpy(data, &val, n);
838 length -= n;
839 data += n;
840 offset += n;
841 }
842 return 0;
843}
844
845static int skge_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
846 u8 *data)
847{
848 struct skge_port *skge = netdev_priv(dev);
849 struct pci_dev *pdev = skge->hw->pdev;
850 int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD);
851 int length = eeprom->len;
852 u16 offset = eeprom->offset;
853
854 if (!cap)
855 return -EINVAL;
856
857 if (eeprom->magic != SKGE_EEPROM_MAGIC)
858 return -EINVAL;
859
860 while (length > 0) {
861 u32 val;
862 int n = min_t(int, length, sizeof(val));
863
864 if (n < sizeof(val))
865 val = skge_vpd_read(pdev, cap, offset);
866 memcpy(&val, data, n);
867
868 skge_vpd_write(pdev, cap, offset, val);
869
870 length -= n;
871 data += n;
872 offset += n;
873 }
874 return 0;
875}
876
Jeff Garzik7282d492006-09-13 14:30:00 -0400877static const struct ethtool_ops skge_ethtool_ops = {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400878 .get_settings = skge_get_settings,
879 .set_settings = skge_set_settings,
880 .get_drvinfo = skge_get_drvinfo,
881 .get_regs_len = skge_get_regs_len,
882 .get_regs = skge_get_regs,
883 .get_wol = skge_get_wol,
884 .set_wol = skge_set_wol,
885 .get_msglevel = skge_get_msglevel,
886 .set_msglevel = skge_set_msglevel,
887 .nway_reset = skge_nway_reset,
888 .get_link = ethtool_op_get_link,
Stephen Hemmingerafa151b2007-10-16 12:15:53 -0700889 .get_eeprom_len = skge_get_eeprom_len,
890 .get_eeprom = skge_get_eeprom,
891 .set_eeprom = skge_set_eeprom,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400892 .get_ringparam = skge_get_ring_param,
893 .set_ringparam = skge_set_ring_param,
894 .get_pauseparam = skge_get_pauseparam,
895 .set_pauseparam = skge_set_pauseparam,
896 .get_coalesce = skge_get_coalesce,
897 .set_coalesce = skge_set_coalesce,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400898 .get_strings = skge_get_strings,
stephen hemmingera5b9f412011-04-04 08:43:42 +0000899 .set_phys_id = skge_set_phys_id,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700900 .get_sset_count = skge_get_sset_count,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400901 .get_ethtool_stats = skge_get_ethtool_stats,
902};
903
904/*
905 * Allocate ring elements and chain them together
906 * One-to-one association of board descriptors with ring elements
907 */
Stephen Hemmingerc3da1442006-03-21 10:57:01 -0800908static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u32 base)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400909{
910 struct skge_tx_desc *d;
911 struct skge_element *e;
912 int i;
913
Robert P. J. Daycd861282006-12-13 00:34:52 -0800914 ring->start = kcalloc(ring->count, sizeof(*e), GFP_KERNEL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400915 if (!ring->start)
916 return -ENOMEM;
917
918 for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) {
919 e->desc = d;
920 if (i == ring->count - 1) {
921 e->next = ring->start;
922 d->next_offset = base;
923 } else {
924 e->next = e + 1;
925 d->next_offset = base + (i+1) * sizeof(*d);
926 }
927 }
928 ring->to_use = ring->to_clean = ring->start;
929
930 return 0;
931}
932
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700933/* Allocate and setup a new buffer for receiving */
stephen hemmingerd0249e442012-01-19 14:37:18 +0000934static int skge_rx_setup(struct pci_dev *pdev,
935 struct skge_element *e,
936 struct sk_buff *skb, unsigned int bufsize)
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700937{
938 struct skge_rx_desc *rd = e->desc;
stephen hemmingerd0249e442012-01-19 14:37:18 +0000939 dma_addr_t map;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400940
stephen hemmingerd0249e442012-01-19 14:37:18 +0000941 map = pci_map_single(pdev, skb->data, bufsize,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400942 PCI_DMA_FROMDEVICE);
stephen hemmingerd0249e442012-01-19 14:37:18 +0000943 if (pci_dma_mapping_error(pdev, map))
944 goto mapping_error;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400945
stephen hemmingerd0249e442012-01-19 14:37:18 +0000946 rd->dma_lo = lower_32_bits(map);
947 rd->dma_hi = upper_32_bits(map);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400948 e->skb = skb;
949 rd->csum1_start = ETH_HLEN;
950 rd->csum2_start = ETH_HLEN;
951 rd->csum1 = 0;
952 rd->csum2 = 0;
953
954 wmb();
955
956 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | bufsize;
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +0000957 dma_unmap_addr_set(e, mapaddr, map);
958 dma_unmap_len_set(e, maplen, bufsize);
stephen hemmingerd0249e442012-01-19 14:37:18 +0000959 return 0;
960
961mapping_error:
962 if (net_ratelimit())
963 dev_warn(&pdev->dev, "%s: rx mapping error\n",
964 skb->dev->name);
965 return -EIO;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400966}
967
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700968/* Resume receiving using existing skb,
969 * Note: DMA address is not changed by chip.
970 * MTU not changed while receiver active.
971 */
Stephen Hemminger5a011442006-03-23 11:07:25 -0800972static inline void skge_rx_reuse(struct skge_element *e, unsigned int size)
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700973{
974 struct skge_rx_desc *rd = e->desc;
975
976 rd->csum2 = 0;
977 rd->csum2_start = ETH_HLEN;
978
979 wmb();
980
981 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | size;
982}
983
984
985/* Free all buffers in receive ring, assumes receiver stopped */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400986static void skge_rx_clean(struct skge_port *skge)
987{
988 struct skge_hw *hw = skge->hw;
989 struct skge_ring *ring = &skge->rx_ring;
990 struct skge_element *e;
991
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700992 e = ring->start;
993 do {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400994 struct skge_rx_desc *rd = e->desc;
995 rd->control = 0;
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700996 if (e->skb) {
997 pci_unmap_single(hw->pdev,
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +0000998 dma_unmap_addr(e, mapaddr),
999 dma_unmap_len(e, maplen),
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001000 PCI_DMA_FROMDEVICE);
1001 dev_kfree_skb(e->skb);
1002 e->skb = NULL;
1003 }
1004 } while ((e = e->next) != ring->start);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001005}
1006
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001007
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001008/* Allocate buffers for receive ring
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001009 * For receive: to_clean is next received frame.
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001010 */
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07001011static int skge_rx_fill(struct net_device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001012{
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07001013 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001014 struct skge_ring *ring = &skge->rx_ring;
1015 struct skge_element *e;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001016
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001017 e = ring->start;
1018 do {
Stephen Hemminger383181a2005-09-19 15:37:16 -07001019 struct sk_buff *skb;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001020
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07001021 skb = __netdev_alloc_skb(dev, skge->rx_buf_size + NET_IP_ALIGN,
1022 GFP_KERNEL);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001023 if (!skb)
1024 return -ENOMEM;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001025
Stephen Hemminger383181a2005-09-19 15:37:16 -07001026 skb_reserve(skb, NET_IP_ALIGN);
stephen hemmingerd0249e442012-01-19 14:37:18 +00001027 if (skge_rx_setup(skge->hw->pdev, e, skb, skge->rx_buf_size)) {
1028 kfree_skb(skb);
1029 return -ENOMEM;
1030 }
1031
Joe Perches67777f92010-02-17 15:01:58 +00001032 } while ((e = e->next) != ring->start);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001033
1034 ring->to_clean = ring->start;
1035 return 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001036}
1037
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001038static const char *skge_pause(enum pause_status status)
1039{
Joe Perches67777f92010-02-17 15:01:58 +00001040 switch (status) {
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001041 case FLOW_STAT_NONE:
1042 return "none";
1043 case FLOW_STAT_REM_SEND:
1044 return "rx only";
1045 case FLOW_STAT_LOC_SEND:
1046 return "tx_only";
1047 case FLOW_STAT_SYMMETRIC: /* Both station may send PAUSE */
1048 return "both";
1049 default:
1050 return "indeterminated";
1051 }
1052}
1053
1054
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001055static void skge_link_up(struct skge_port *skge)
1056{
Stephen Hemminger46a60f22005-09-09 12:54:56 -07001057 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG),
Stephen Hemminger54cfb5a2005-08-16 14:01:05 -07001058 LED_BLK_OFF|LED_SYNC_OFF|LED_ON);
1059
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001060 netif_carrier_on(skge->netdev);
Stephen Hemminger29b4e882006-03-23 11:07:28 -08001061 netif_wake_queue(skge->netdev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001062
Joe Perchesd7072042010-02-09 11:49:53 +00001063 netif_info(skge, link, skge->netdev,
1064 "Link is up at %d Mbps, %s duplex, flow control %s\n",
1065 skge->speed,
1066 skge->duplex == DUPLEX_FULL ? "full" : "half",
1067 skge_pause(skge->flow_status));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001068}
1069
1070static void skge_link_down(struct skge_port *skge)
1071{
Stephen Hemminger54cfb5a2005-08-16 14:01:05 -07001072 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001073 netif_carrier_off(skge->netdev);
1074 netif_stop_queue(skge->netdev);
1075
Joe Perchesd7072042010-02-09 11:49:53 +00001076 netif_info(skge, link, skge->netdev, "Link is down\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001077}
1078
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001079static void xm_link_down(struct skge_hw *hw, int port)
1080{
1081 struct net_device *dev = hw->dev[port];
1082 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001083
Stephen Hemminger501fb722007-10-16 12:15:51 -07001084 xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE);
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001085
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001086 if (netif_carrier_ok(dev))
1087 skge_link_down(skge);
1088}
1089
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001090static int __xm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001091{
1092 int i;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001093
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001094 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
Stephen Hemminger07811912006-02-22 10:28:34 -08001095 *val = xm_read16(hw, port, XM_PHY_DATA);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001096
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001097 if (hw->phy_type == SK_PHY_XMAC)
1098 goto ready;
1099
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001100 for (i = 0; i < PHY_RETRIES; i++) {
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001101 if (xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_RDY)
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001102 goto ready;
Stephen Hemminger07811912006-02-22 10:28:34 -08001103 udelay(1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001104 }
1105
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001106 return -ETIMEDOUT;
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001107 ready:
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001108 *val = xm_read16(hw, port, XM_PHY_DATA);
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001109
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001110 return 0;
1111}
1112
1113static u16 xm_phy_read(struct skge_hw *hw, int port, u16 reg)
1114{
1115 u16 v = 0;
1116 if (__xm_phy_read(hw, port, reg, &v))
Joe Perchesf15063c2010-02-17 15:01:57 +00001117 pr_warning("%s: phy read timed out\n", hw->dev[port]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001118 return v;
1119}
1120
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001121static int xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001122{
1123 int i;
1124
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001125 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001126 for (i = 0; i < PHY_RETRIES; i++) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001127 if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001128 goto ready;
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001129 udelay(1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001130 }
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001131 return -EIO;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001132
1133 ready:
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001134 xm_write16(hw, port, XM_PHY_DATA, val);
Stephen Hemminger07811912006-02-22 10:28:34 -08001135 for (i = 0; i < PHY_RETRIES; i++) {
1136 if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
1137 return 0;
1138 udelay(1);
1139 }
1140 return -ETIMEDOUT;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001141}
1142
1143static void genesis_init(struct skge_hw *hw)
1144{
1145 /* set blink source counter */
1146 skge_write32(hw, B2_BSC_INI, (SK_BLK_DUR * SK_FACT_53) / 100);
1147 skge_write8(hw, B2_BSC_CTRL, BSC_START);
1148
1149 /* configure mac arbiter */
1150 skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR);
1151
1152 /* configure mac arbiter timeout values */
1153 skge_write8(hw, B3_MA_TOINI_RX1, SK_MAC_TO_53);
1154 skge_write8(hw, B3_MA_TOINI_RX2, SK_MAC_TO_53);
1155 skge_write8(hw, B3_MA_TOINI_TX1, SK_MAC_TO_53);
1156 skge_write8(hw, B3_MA_TOINI_TX2, SK_MAC_TO_53);
1157
1158 skge_write8(hw, B3_MA_RCINI_RX1, 0);
1159 skge_write8(hw, B3_MA_RCINI_RX2, 0);
1160 skge_write8(hw, B3_MA_RCINI_TX1, 0);
1161 skge_write8(hw, B3_MA_RCINI_TX2, 0);
1162
1163 /* configure packet arbiter timeout */
1164 skge_write16(hw, B3_PA_CTRL, PA_RST_CLR);
1165 skge_write16(hw, B3_PA_TOINI_RX1, SK_PKT_TO_MAX);
1166 skge_write16(hw, B3_PA_TOINI_TX1, SK_PKT_TO_MAX);
1167 skge_write16(hw, B3_PA_TOINI_RX2, SK_PKT_TO_MAX);
1168 skge_write16(hw, B3_PA_TOINI_TX2, SK_PKT_TO_MAX);
1169}
1170
1171static void genesis_reset(struct skge_hw *hw, int port)
1172{
Joe Perchesb6bc7652010-12-21 02:16:08 -08001173 static const u8 zero[8] = { 0 };
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001174 u32 reg;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001175
Stephen Hemminger46a60f22005-09-09 12:54:56 -07001176 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
1177
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001178 /* reset the statistics module */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001179 xm_write32(hw, port, XM_GP_PORT, XM_GP_RES_STAT);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001180 xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001181 xm_write32(hw, port, XM_MODE, 0); /* clear Mode Reg */
1182 xm_write16(hw, port, XM_TX_CMD, 0); /* reset TX CMD Reg */
1183 xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001184
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001185 /* disable Broadcom PHY IRQ */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001186 if (hw->phy_type == SK_PHY_BCOM)
1187 xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001188
Stephen Hemminger45bada62005-06-27 11:33:12 -07001189 xm_outhash(hw, port, XM_HSM, zero);
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001190
1191 /* Flush TX and RX fifo */
1192 reg = xm_read32(hw, port, XM_MODE);
1193 xm_write32(hw, port, XM_MODE, reg | XM_MD_FTF);
1194 xm_write32(hw, port, XM_MODE, reg | XM_MD_FRF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001195}
1196
Stephen Hemminger45bada62005-06-27 11:33:12 -07001197/* Convert mode to MII values */
1198static const u16 phy_pause_map[] = {
1199 [FLOW_MODE_NONE] = 0,
1200 [FLOW_MODE_LOC_SEND] = PHY_AN_PAUSE_ASYM,
1201 [FLOW_MODE_SYMMETRIC] = PHY_AN_PAUSE_CAP,
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001202 [FLOW_MODE_SYM_OR_REM] = PHY_AN_PAUSE_CAP | PHY_AN_PAUSE_ASYM,
Stephen Hemminger45bada62005-06-27 11:33:12 -07001203};
1204
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001205/* special defines for FIBER (88E1011S only) */
1206static const u16 fiber_pause_map[] = {
1207 [FLOW_MODE_NONE] = PHY_X_P_NO_PAUSE,
1208 [FLOW_MODE_LOC_SEND] = PHY_X_P_ASYM_MD,
1209 [FLOW_MODE_SYMMETRIC] = PHY_X_P_SYM_MD,
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001210 [FLOW_MODE_SYM_OR_REM] = PHY_X_P_BOTH_MD,
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001211};
1212
Stephen Hemminger45bada62005-06-27 11:33:12 -07001213
1214/* Check status of Broadcom phy link */
1215static void bcom_check_link(struct skge_hw *hw, int port)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001216{
Stephen Hemminger45bada62005-06-27 11:33:12 -07001217 struct net_device *dev = hw->dev[port];
1218 struct skge_port *skge = netdev_priv(dev);
1219 u16 status;
1220
1221 /* read twice because of latch */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001222 xm_phy_read(hw, port, PHY_BCOM_STAT);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001223 status = xm_phy_read(hw, port, PHY_BCOM_STAT);
1224
Stephen Hemminger45bada62005-06-27 11:33:12 -07001225 if ((status & PHY_ST_LSYNC) == 0) {
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001226 xm_link_down(hw, port);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001227 return;
1228 }
Stephen Hemminger45bada62005-06-27 11:33:12 -07001229
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001230 if (skge->autoneg == AUTONEG_ENABLE) {
1231 u16 lpa, aux;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001232
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001233 if (!(status & PHY_ST_AN_OVER))
1234 return;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001235
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001236 lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP);
1237 if (lpa & PHY_B_AN_RF) {
Joe Perchesf15063c2010-02-17 15:01:57 +00001238 netdev_notice(dev, "remote fault\n");
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001239 return;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001240 }
1241
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001242 aux = xm_phy_read(hw, port, PHY_BCOM_AUX_STAT);
1243
1244 /* Check Duplex mismatch */
1245 switch (aux & PHY_B_AS_AN_RES_MSK) {
1246 case PHY_B_RES_1000FD:
1247 skge->duplex = DUPLEX_FULL;
1248 break;
1249 case PHY_B_RES_1000HD:
1250 skge->duplex = DUPLEX_HALF;
1251 break;
1252 default:
Joe Perchesf15063c2010-02-17 15:01:57 +00001253 netdev_notice(dev, "duplex mismatch\n");
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001254 return;
1255 }
1256
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001257 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
1258 switch (aux & PHY_B_AS_PAUSE_MSK) {
1259 case PHY_B_AS_PAUSE_MSK:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001260 skge->flow_status = FLOW_STAT_SYMMETRIC;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001261 break;
1262 case PHY_B_AS_PRR:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001263 skge->flow_status = FLOW_STAT_REM_SEND;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001264 break;
1265 case PHY_B_AS_PRT:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001266 skge->flow_status = FLOW_STAT_LOC_SEND;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001267 break;
1268 default:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001269 skge->flow_status = FLOW_STAT_NONE;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001270 }
1271 skge->speed = SPEED_1000;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001272 }
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001273
1274 if (!netif_carrier_ok(dev))
1275 genesis_link_up(skge);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001276}
1277
1278/* Broadcom 5400 only supports giagabit! SysKonnect did not put an additional
1279 * Phy on for 100 or 10Mbit operation
1280 */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001281static void bcom_phy_init(struct skge_port *skge)
Stephen Hemminger45bada62005-06-27 11:33:12 -07001282{
1283 struct skge_hw *hw = skge->hw;
1284 int port = skge->port;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001285 int i;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001286 u16 id1, r, ext, ctl;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001287
1288 /* magic workaround patterns for Broadcom */
1289 static const struct {
1290 u16 reg;
1291 u16 val;
1292 } A1hack[] = {
1293 { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1104 },
1294 { 0x17, 0x0013 }, { 0x15, 0x0404 }, { 0x17, 0x8006 },
1295 { 0x15, 0x0132 }, { 0x17, 0x8006 }, { 0x15, 0x0232 },
1296 { 0x17, 0x800D }, { 0x15, 0x000F }, { 0x18, 0x0420 },
1297 }, C0hack[] = {
1298 { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1204 },
1299 { 0x17, 0x0013 }, { 0x15, 0x0A04 }, { 0x18, 0x0420 },
1300 };
1301
Stephen Hemminger45bada62005-06-27 11:33:12 -07001302 /* read Id from external PHY (all have the same address) */
1303 id1 = xm_phy_read(hw, port, PHY_XMAC_ID1);
1304
1305 /* Optimize MDIO transfer by suppressing preamble. */
1306 r = xm_read16(hw, port, XM_MMU_CMD);
1307 r |= XM_MMU_NO_PRE;
Joe Perches67777f92010-02-17 15:01:58 +00001308 xm_write16(hw, port, XM_MMU_CMD, r);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001309
Stephen Hemminger2c668512005-07-22 16:26:07 -07001310 switch (id1) {
Stephen Hemminger45bada62005-06-27 11:33:12 -07001311 case PHY_BCOM_ID1_C0:
1312 /*
1313 * Workaround BCOM Errata for the C0 type.
1314 * Write magic patterns to reserved registers.
1315 */
1316 for (i = 0; i < ARRAY_SIZE(C0hack); i++)
1317 xm_phy_write(hw, port,
1318 C0hack[i].reg, C0hack[i].val);
1319
1320 break;
1321 case PHY_BCOM_ID1_A1:
1322 /*
1323 * Workaround BCOM Errata for the A1 type.
1324 * Write magic patterns to reserved registers.
1325 */
1326 for (i = 0; i < ARRAY_SIZE(A1hack); i++)
1327 xm_phy_write(hw, port,
1328 A1hack[i].reg, A1hack[i].val);
1329 break;
1330 }
1331
1332 /*
1333 * Workaround BCOM Errata (#10523) for all BCom PHYs.
1334 * Disable Power Management after reset.
1335 */
1336 r = xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL);
1337 r |= PHY_B_AC_DIS_PM;
1338 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, r);
1339
1340 /* Dummy read */
1341 xm_read16(hw, port, XM_ISRC);
1342
1343 ext = PHY_B_PEC_EN_LTR; /* enable tx led */
1344 ctl = PHY_CT_SP1000; /* always 1000mbit */
1345
1346 if (skge->autoneg == AUTONEG_ENABLE) {
1347 /*
1348 * Workaround BCOM Errata #1 for the C5 type.
1349 * 1000Base-T Link Acquisition Failure in Slave Mode
1350 * Set Repeater/DTE bit 10 of the 1000Base-T Control Register
1351 */
1352 u16 adv = PHY_B_1000C_RD;
1353 if (skge->advertising & ADVERTISED_1000baseT_Half)
1354 adv |= PHY_B_1000C_AHD;
1355 if (skge->advertising & ADVERTISED_1000baseT_Full)
1356 adv |= PHY_B_1000C_AFD;
1357 xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, adv);
1358
1359 ctl |= PHY_CT_ANE | PHY_CT_RE_CFG;
1360 } else {
1361 if (skge->duplex == DUPLEX_FULL)
1362 ctl |= PHY_CT_DUP_MD;
1363 /* Force to slave */
1364 xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, PHY_B_1000C_MSE);
1365 }
1366
1367 /* Set autonegotiation pause parameters */
1368 xm_phy_write(hw, port, PHY_BCOM_AUNE_ADV,
1369 phy_pause_map[skge->flow_control] | PHY_AN_CSMA);
1370
1371 /* Handle Jumbo frames */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001372 if (hw->dev[port]->mtu > ETH_DATA_LEN) {
Stephen Hemminger45bada62005-06-27 11:33:12 -07001373 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1374 PHY_B_AC_TX_TST | PHY_B_AC_LONG_PACK);
1375
1376 ext |= PHY_B_PEC_HIGH_LA;
1377
1378 }
1379
1380 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, ext);
1381 xm_phy_write(hw, port, PHY_BCOM_CTRL, ctl);
1382
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08001383 /* Use link status change interrupt */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001384 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001385}
Stephen Hemminger45bada62005-06-27 11:33:12 -07001386
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001387static void xm_phy_init(struct skge_port *skge)
1388{
1389 struct skge_hw *hw = skge->hw;
1390 int port = skge->port;
1391 u16 ctrl = 0;
1392
1393 if (skge->autoneg == AUTONEG_ENABLE) {
1394 if (skge->advertising & ADVERTISED_1000baseT_Half)
1395 ctrl |= PHY_X_AN_HD;
1396 if (skge->advertising & ADVERTISED_1000baseT_Full)
1397 ctrl |= PHY_X_AN_FD;
1398
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001399 ctrl |= fiber_pause_map[skge->flow_control];
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001400
1401 xm_phy_write(hw, port, PHY_XMAC_AUNE_ADV, ctrl);
1402
1403 /* Restart Auto-negotiation */
1404 ctrl = PHY_CT_ANE | PHY_CT_RE_CFG;
1405 } else {
1406 /* Set DuplexMode in Config register */
1407 if (skge->duplex == DUPLEX_FULL)
1408 ctrl |= PHY_CT_DUP_MD;
1409 /*
1410 * Do NOT enable Auto-negotiation here. This would hold
1411 * the link down because no IDLEs are transmitted
1412 */
1413 }
1414
1415 xm_phy_write(hw, port, PHY_XMAC_CTRL, ctrl);
1416
1417 /* Poll PHY for status changes */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07001418 mod_timer(&skge->link_timer, jiffies + LINK_HZ);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001419}
1420
Stephen Hemminger501fb722007-10-16 12:15:51 -07001421static int xm_check_link(struct net_device *dev)
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001422{
1423 struct skge_port *skge = netdev_priv(dev);
1424 struct skge_hw *hw = skge->hw;
1425 int port = skge->port;
1426 u16 status;
1427
1428 /* read twice because of latch */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001429 xm_phy_read(hw, port, PHY_XMAC_STAT);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001430 status = xm_phy_read(hw, port, PHY_XMAC_STAT);
1431
1432 if ((status & PHY_ST_LSYNC) == 0) {
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001433 xm_link_down(hw, port);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001434 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001435 }
1436
1437 if (skge->autoneg == AUTONEG_ENABLE) {
1438 u16 lpa, res;
1439
1440 if (!(status & PHY_ST_AN_OVER))
Stephen Hemminger501fb722007-10-16 12:15:51 -07001441 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001442
1443 lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP);
1444 if (lpa & PHY_B_AN_RF) {
Joe Perchesf15063c2010-02-17 15:01:57 +00001445 netdev_notice(dev, "remote fault\n");
Stephen Hemminger501fb722007-10-16 12:15:51 -07001446 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001447 }
1448
1449 res = xm_phy_read(hw, port, PHY_XMAC_RES_ABI);
1450
1451 /* Check Duplex mismatch */
1452 switch (res & (PHY_X_RS_HD | PHY_X_RS_FD)) {
1453 case PHY_X_RS_FD:
1454 skge->duplex = DUPLEX_FULL;
1455 break;
1456 case PHY_X_RS_HD:
1457 skge->duplex = DUPLEX_HALF;
1458 break;
1459 default:
Joe Perchesf15063c2010-02-17 15:01:57 +00001460 netdev_notice(dev, "duplex mismatch\n");
Stephen Hemminger501fb722007-10-16 12:15:51 -07001461 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001462 }
1463
1464 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001465 if ((skge->flow_control == FLOW_MODE_SYMMETRIC ||
1466 skge->flow_control == FLOW_MODE_SYM_OR_REM) &&
1467 (lpa & PHY_X_P_SYM_MD))
1468 skge->flow_status = FLOW_STAT_SYMMETRIC;
1469 else if (skge->flow_control == FLOW_MODE_SYM_OR_REM &&
1470 (lpa & PHY_X_RS_PAUSE) == PHY_X_P_ASYM_MD)
1471 /* Enable PAUSE receive, disable PAUSE transmit */
1472 skge->flow_status = FLOW_STAT_REM_SEND;
1473 else if (skge->flow_control == FLOW_MODE_LOC_SEND &&
1474 (lpa & PHY_X_RS_PAUSE) == PHY_X_P_BOTH_MD)
1475 /* Disable PAUSE receive, enable PAUSE transmit */
1476 skge->flow_status = FLOW_STAT_LOC_SEND;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001477 else
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001478 skge->flow_status = FLOW_STAT_NONE;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001479
1480 skge->speed = SPEED_1000;
1481 }
1482
1483 if (!netif_carrier_ok(dev))
1484 genesis_link_up(skge);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001485 return 1;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001486}
1487
1488/* Poll to check for link coming up.
Stephen Hemminger501fb722007-10-16 12:15:51 -07001489 *
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001490 * Since internal PHY is wired to a level triggered pin, can't
Stephen Hemminger501fb722007-10-16 12:15:51 -07001491 * get an interrupt when carrier is detected, need to poll for
1492 * link coming up.
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001493 */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07001494static void xm_link_timer(unsigned long arg)
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001495{
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07001496 struct skge_port *skge = (struct skge_port *) arg;
David Howellsc4028952006-11-22 14:57:56 +00001497 struct net_device *dev = skge->netdev;
Joe Perches67777f92010-02-17 15:01:58 +00001498 struct skge_hw *hw = skge->hw;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001499 int port = skge->port;
Stephen Hemminger501fb722007-10-16 12:15:51 -07001500 int i;
1501 unsigned long flags;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001502
1503 if (!netif_running(dev))
1504 return;
1505
Stephen Hemminger501fb722007-10-16 12:15:51 -07001506 spin_lock_irqsave(&hw->phy_lock, flags);
1507
1508 /*
1509 * Verify that the link by checking GPIO register three times.
1510 * This pin has the signal from the link_sync pin connected to it.
1511 */
1512 for (i = 0; i < 3; i++) {
1513 if (xm_read16(hw, port, XM_GP_PORT) & XM_GP_INP_ASS)
1514 goto link_down;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001515 }
1516
Joe Perches67777f92010-02-17 15:01:58 +00001517 /* Re-enable interrupt to detect link down */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001518 if (xm_check_link(dev)) {
1519 u16 msk = xm_read16(hw, port, XM_IMSK);
1520 msk &= ~XM_IS_INP_ASS;
1521 xm_write16(hw, port, XM_IMSK, msk);
1522 xm_read16(hw, port, XM_ISRC);
1523 } else {
1524link_down:
1525 mod_timer(&skge->link_timer,
1526 round_jiffies(jiffies + LINK_HZ));
1527 }
1528 spin_unlock_irqrestore(&hw->phy_lock, flags);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001529}
1530
1531static void genesis_mac_init(struct skge_hw *hw, int port)
1532{
1533 struct net_device *dev = hw->dev[port];
1534 struct skge_port *skge = netdev_priv(dev);
1535 int jumbo = hw->dev[port]->mtu > ETH_DATA_LEN;
1536 int i;
1537 u32 r;
Joe Perchesb6bc7652010-12-21 02:16:08 -08001538 static const u8 zero[6] = { 0 };
Stephen Hemminger45bada62005-06-27 11:33:12 -07001539
Stephen Hemminger07811912006-02-22 10:28:34 -08001540 for (i = 0; i < 10; i++) {
1541 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1),
1542 MFF_SET_MAC_RST);
1543 if (skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST)
1544 goto reset_ok;
1545 udelay(1);
1546 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001547
Joe Perchesf15063c2010-02-17 15:01:57 +00001548 netdev_warn(dev, "genesis reset failed\n");
Stephen Hemminger07811912006-02-22 10:28:34 -08001549
1550 reset_ok:
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001551 /* Unreset the XMAC. */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001552 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001553
1554 /*
1555 * Perform additional initialization for external PHYs,
1556 * namely for the 1000baseTX cards that use the XMAC's
1557 * GMII mode.
1558 */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001559 if (hw->phy_type != SK_PHY_XMAC) {
1560 /* Take external Phy out of reset */
1561 r = skge_read32(hw, B2_GP_IO);
1562 if (port == 0)
1563 r |= GP_DIR_0|GP_IO_0;
1564 else
1565 r |= GP_DIR_2|GP_IO_2;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001566
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001567 skge_write32(hw, B2_GP_IO, r);
1568
1569 /* Enable GMII interface */
1570 xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD);
1571 }
Stephen Hemminger07811912006-02-22 10:28:34 -08001572
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001573
Joe Perches67777f92010-02-17 15:01:58 +00001574 switch (hw->phy_type) {
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001575 case SK_PHY_XMAC:
1576 xm_phy_init(skge);
1577 break;
1578 case SK_PHY_BCOM:
1579 bcom_phy_init(skge);
1580 bcom_check_link(hw, port);
1581 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001582
Stephen Hemminger45bada62005-06-27 11:33:12 -07001583 /* Set Station Address */
1584 xm_outaddr(hw, port, XM_SA, dev->dev_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001585
Stephen Hemminger45bada62005-06-27 11:33:12 -07001586 /* We don't use match addresses so clear */
1587 for (i = 1; i < 16; i++)
1588 xm_outaddr(hw, port, XM_EXM(i), zero);
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001589
Stephen Hemminger07811912006-02-22 10:28:34 -08001590 /* Clear MIB counters */
1591 xm_write16(hw, port, XM_STAT_CMD,
1592 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1593 /* Clear two times according to Errata #3 */
1594 xm_write16(hw, port, XM_STAT_CMD,
1595 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1596
Stephen Hemminger45bada62005-06-27 11:33:12 -07001597 /* configure Rx High Water Mark (XM_RX_HI_WM) */
1598 xm_write16(hw, port, XM_RX_HI_WM, 1450);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001599
1600 /* We don't need the FCS appended to the packet. */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001601 r = XM_RX_LENERR_OK | XM_RX_STRIP_FCS;
1602 if (jumbo)
1603 r |= XM_RX_BIG_PK_OK;
1604
1605 if (skge->duplex == DUPLEX_HALF) {
1606 /*
1607 * If in manual half duplex mode the other side might be in
1608 * full duplex mode, so ignore if a carrier extension is not seen
1609 * on frames received
1610 */
1611 r |= XM_RX_DIS_CEXT;
1612 }
1613 xm_write16(hw, port, XM_RX_CMD, r);
1614
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001615 /* We want short frames padded to 60 bytes. */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001616 xm_write16(hw, port, XM_TX_CMD, XM_TX_AUTO_PAD);
1617
Stephen Hemminger485982a2007-11-26 11:54:52 -08001618 /* Increase threshold for jumbo frames on dual port */
1619 if (hw->ports > 1 && jumbo)
1620 xm_write16(hw, port, XM_TX_THR, 1020);
1621 else
1622 xm_write16(hw, port, XM_TX_THR, 512);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001623
1624 /*
1625 * Enable the reception of all error frames. This is is
1626 * a necessary evil due to the design of the XMAC. The
1627 * XMAC's receive FIFO is only 8K in size, however jumbo
1628 * frames can be up to 9000 bytes in length. When bad
1629 * frame filtering is enabled, the XMAC's RX FIFO operates
1630 * in 'store and forward' mode. For this to work, the
1631 * entire frame has to fit into the FIFO, but that means
1632 * that jumbo frames larger than 8192 bytes will be
1633 * truncated. Disabling all bad frame filtering causes
1634 * the RX FIFO to operate in streaming mode, in which
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08001635 * case the XMAC will start transferring frames out of the
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001636 * RX FIFO as soon as the FIFO threshold is reached.
1637 */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001638 xm_write32(hw, port, XM_MODE, XM_DEF_MODE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001639
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001640
1641 /*
Stephen Hemminger45bada62005-06-27 11:33:12 -07001642 * Initialize the Receive Counter Event Mask (XM_RX_EV_MSK)
1643 * - Enable all bits excepting 'Octets Rx OK Low CntOv'
1644 * and 'Octets Rx OK Hi Cnt Ov'.
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001645 */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001646 xm_write32(hw, port, XM_RX_EV_MSK, XMR_DEF_MSK);
1647
1648 /*
1649 * Initialize the Transmit Counter Event Mask (XM_TX_EV_MSK)
1650 * - Enable all bits excepting 'Octets Tx OK Low CntOv'
1651 * and 'Octets Tx OK Hi Cnt Ov'.
1652 */
1653 xm_write32(hw, port, XM_TX_EV_MSK, XMT_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001654
1655 /* Configure MAC arbiter */
1656 skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR);
1657
1658 /* configure timeout values */
1659 skge_write8(hw, B3_MA_TOINI_RX1, 72);
1660 skge_write8(hw, B3_MA_TOINI_RX2, 72);
1661 skge_write8(hw, B3_MA_TOINI_TX1, 72);
1662 skge_write8(hw, B3_MA_TOINI_TX2, 72);
1663
1664 skge_write8(hw, B3_MA_RCINI_RX1, 0);
1665 skge_write8(hw, B3_MA_RCINI_RX2, 0);
1666 skge_write8(hw, B3_MA_RCINI_TX1, 0);
1667 skge_write8(hw, B3_MA_RCINI_TX2, 0);
1668
1669 /* Configure Rx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001670 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_CLR);
1671 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_TIM_PAT);
1672 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_ENA_OP_MD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001673
1674 /* Configure Tx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001675 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_CLR);
1676 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF);
1677 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_ENA_OP_MD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001678
Stephen Hemminger45bada62005-06-27 11:33:12 -07001679 if (jumbo) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001680 /* Enable frame flushing if jumbo frames used */
Joe Perches67777f92010-02-17 15:01:58 +00001681 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_FLUSH);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001682 } else {
1683 /* enable timeout timers if normal frames */
1684 skge_write16(hw, B3_PA_CTRL,
Stephen Hemminger45bada62005-06-27 11:33:12 -07001685 (port == 0) ? PA_ENA_TO_TX1 : PA_ENA_TO_TX2);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001686 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001687}
1688
1689static void genesis_stop(struct skge_port *skge)
1690{
1691 struct skge_hw *hw = skge->hw;
1692 int port = skge->port;
Stephen Hemminger799b21d2007-11-26 11:54:50 -08001693 unsigned retries = 1000;
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001694 u16 cmd;
1695
Joe Perches67777f92010-02-17 15:01:58 +00001696 /* Disable Tx and Rx */
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001697 cmd = xm_read16(hw, port, XM_MMU_CMD);
1698 cmd &= ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1699 xm_write16(hw, port, XM_MMU_CMD, cmd);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001700
Stephen Hemminger46a60f22005-09-09 12:54:56 -07001701 genesis_reset(hw, port);
1702
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001703 /* Clear Tx packet arbiter timeout IRQ */
1704 skge_write16(hw, B3_PA_CTRL,
1705 port == 0 ? PA_CLR_TO_TX1 : PA_CLR_TO_TX2);
1706
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001707 /* Reset the MAC */
Stephen Hemminger799b21d2007-11-26 11:54:50 -08001708 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
1709 do {
1710 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST);
1711 if (!(skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST))
1712 break;
1713 } while (--retries > 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001714
1715 /* For external PHYs there must be special handling */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001716 if (hw->phy_type != SK_PHY_XMAC) {
Stephen Hemminger799b21d2007-11-26 11:54:50 -08001717 u32 reg = skge_read32(hw, B2_GP_IO);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001718 if (port == 0) {
1719 reg |= GP_DIR_0;
1720 reg &= ~GP_IO_0;
1721 } else {
1722 reg |= GP_DIR_2;
1723 reg &= ~GP_IO_2;
1724 }
1725 skge_write32(hw, B2_GP_IO, reg);
1726 skge_read32(hw, B2_GP_IO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001727 }
1728
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001729 xm_write16(hw, port, XM_MMU_CMD,
1730 xm_read16(hw, port, XM_MMU_CMD)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001731 & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX));
1732
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001733 xm_read16(hw, port, XM_MMU_CMD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001734}
1735
1736
1737static void genesis_get_stats(struct skge_port *skge, u64 *data)
1738{
1739 struct skge_hw *hw = skge->hw;
1740 int port = skge->port;
1741 int i;
1742 unsigned long timeout = jiffies + HZ;
1743
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001744 xm_write16(hw, port,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001745 XM_STAT_CMD, XM_SC_SNP_TXC | XM_SC_SNP_RXC);
1746
1747 /* wait for update to complete */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001748 while (xm_read16(hw, port, XM_STAT_CMD)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001749 & (XM_SC_SNP_TXC | XM_SC_SNP_RXC)) {
1750 if (time_after(jiffies, timeout))
1751 break;
1752 udelay(10);
1753 }
1754
1755 /* special case for 64 bit octet counter */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001756 data[0] = (u64) xm_read32(hw, port, XM_TXO_OK_HI) << 32
1757 | xm_read32(hw, port, XM_TXO_OK_LO);
1758 data[1] = (u64) xm_read32(hw, port, XM_RXO_OK_HI) << 32
1759 | xm_read32(hw, port, XM_RXO_OK_LO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001760
1761 for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001762 data[i] = xm_read32(hw, port, skge_stats[i].xmac_offset);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001763}
1764
1765static void genesis_mac_intr(struct skge_hw *hw, int port)
1766{
Stephen Hemmingerda007722007-10-16 12:15:52 -07001767 struct net_device *dev = hw->dev[port];
1768 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001769 u16 status = xm_read16(hw, port, XM_ISRC);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001770
Joe Perchesd7072042010-02-09 11:49:53 +00001771 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
1772 "mac interrupt status 0x%x\n", status);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001773
Stephen Hemminger501fb722007-10-16 12:15:51 -07001774 if (hw->phy_type == SK_PHY_XMAC && (status & XM_IS_INP_ASS)) {
Joe Perches67777f92010-02-17 15:01:58 +00001775 xm_link_down(hw, port);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001776 mod_timer(&skge->link_timer, jiffies + 1);
1777 }
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001778
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001779 if (status & XM_IS_TXF_UR) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001780 xm_write32(hw, port, XM_MODE, XM_MD_FTF);
Stephen Hemmingerda007722007-10-16 12:15:52 -07001781 ++dev->stats.tx_fifo_errors;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001782 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001783}
1784
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001785static void genesis_link_up(struct skge_port *skge)
1786{
1787 struct skge_hw *hw = skge->hw;
1788 int port = skge->port;
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001789 u16 cmd, msk;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001790 u32 mode;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001791
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001792 cmd = xm_read16(hw, port, XM_MMU_CMD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001793
1794 /*
1795 * enabling pause frame reception is required for 1000BT
1796 * because the XMAC is not reset if the link is going down
1797 */
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001798 if (skge->flow_status == FLOW_STAT_NONE ||
1799 skge->flow_status == FLOW_STAT_LOC_SEND)
Stephen Hemminger7e676d92005-06-27 11:33:13 -07001800 /* Disable Pause Frame Reception */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001801 cmd |= XM_MMU_IGN_PF;
1802 else
1803 /* Enable Pause Frame Reception */
1804 cmd &= ~XM_MMU_IGN_PF;
1805
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001806 xm_write16(hw, port, XM_MMU_CMD, cmd);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001807
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001808 mode = xm_read32(hw, port, XM_MODE);
Joe Perches67777f92010-02-17 15:01:58 +00001809 if (skge->flow_status == FLOW_STAT_SYMMETRIC ||
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001810 skge->flow_status == FLOW_STAT_LOC_SEND) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001811 /*
1812 * Configure Pause Frame Generation
1813 * Use internal and external Pause Frame Generation.
1814 * Sending pause frames is edge triggered.
1815 * Send a Pause frame with the maximum pause time if
1816 * internal oder external FIFO full condition occurs.
1817 * Send a zero pause time frame to re-start transmission.
1818 */
1819 /* XM_PAUSE_DA = '010000C28001' (default) */
1820 /* XM_MAC_PTIME = 0xffff (maximum) */
1821 /* remember this value is defined in big endian (!) */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001822 xm_write16(hw, port, XM_MAC_PTIME, 0xffff);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001823
1824 mode |= XM_PAUSE_MODE;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001825 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_PAUSE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001826 } else {
1827 /*
1828 * disable pause frame generation is required for 1000BT
1829 * because the XMAC is not reset if the link is going down
1830 */
1831 /* Disable Pause Mode in Mode Register */
1832 mode &= ~XM_PAUSE_MODE;
1833
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001834 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_DIS_PAUSE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001835 }
1836
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001837 xm_write32(hw, port, XM_MODE, mode);
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001838
Stephen Hemmingerd08b9bd2007-11-26 11:54:49 -08001839 /* Turn on detection of Tx underrun */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001840 msk = xm_read16(hw, port, XM_IMSK);
Stephen Hemmingerd08b9bd2007-11-26 11:54:49 -08001841 msk &= ~XM_IS_TXF_UR;
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001842 xm_write16(hw, port, XM_IMSK, msk);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001843
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001844 xm_read16(hw, port, XM_ISRC);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001845
1846 /* get MMU Command Reg. */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001847 cmd = xm_read16(hw, port, XM_MMU_CMD);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001848 if (hw->phy_type != SK_PHY_XMAC && skge->duplex == DUPLEX_FULL)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001849 cmd |= XM_MMU_GMII_FD;
1850
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001851 /*
1852 * Workaround BCOM Errata (#10523) for all BCom Phys
1853 * Enable Power Management after link up
1854 */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001855 if (hw->phy_type == SK_PHY_BCOM) {
1856 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1857 xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL)
1858 & ~PHY_B_AC_DIS_PM);
1859 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
1860 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001861
1862 /* enable Rx/Tx */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001863 xm_write16(hw, port, XM_MMU_CMD,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001864 cmd | XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1865 skge_link_up(skge);
1866}
1867
1868
Stephen Hemminger45bada62005-06-27 11:33:12 -07001869static inline void bcom_phy_intr(struct skge_port *skge)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001870{
1871 struct skge_hw *hw = skge->hw;
1872 int port = skge->port;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001873 u16 isrc;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001874
Stephen Hemminger45bada62005-06-27 11:33:12 -07001875 isrc = xm_phy_read(hw, port, PHY_BCOM_INT_STAT);
Joe Perchesd7072042010-02-09 11:49:53 +00001876 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
1877 "phy interrupt status 0x%x\n", isrc);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001878
1879 if (isrc & PHY_B_IS_PSE)
Joe Perchesf15063c2010-02-17 15:01:57 +00001880 pr_err("%s: uncorrectable pair swap error\n",
Stephen Hemminger45bada62005-06-27 11:33:12 -07001881 hw->dev[port]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001882
1883 /* Workaround BCom Errata:
1884 * enable and disable loopback mode if "NO HCD" occurs.
1885 */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001886 if (isrc & PHY_B_IS_NO_HDCL) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001887 u16 ctrl = xm_phy_read(hw, port, PHY_BCOM_CTRL);
1888 xm_phy_write(hw, port, PHY_BCOM_CTRL,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001889 ctrl | PHY_CT_LOOP);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001890 xm_phy_write(hw, port, PHY_BCOM_CTRL,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001891 ctrl & ~PHY_CT_LOOP);
1892 }
1893
Stephen Hemminger45bada62005-06-27 11:33:12 -07001894 if (isrc & (PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE))
1895 bcom_check_link(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001896
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001897}
1898
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001899static int gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
1900{
1901 int i;
1902
1903 gma_write16(hw, port, GM_SMI_DATA, val);
1904 gma_write16(hw, port, GM_SMI_CTRL,
1905 GM_SMI_CT_PHY_AD(hw->phy_addr) | GM_SMI_CT_REG_AD(reg));
1906 for (i = 0; i < PHY_RETRIES; i++) {
1907 udelay(1);
1908
1909 if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY))
1910 return 0;
1911 }
1912
Joe Perchesf15063c2010-02-17 15:01:57 +00001913 pr_warning("%s: phy write timeout\n", hw->dev[port]->name);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001914 return -EIO;
1915}
1916
1917static int __gm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val)
1918{
1919 int i;
1920
1921 gma_write16(hw, port, GM_SMI_CTRL,
1922 GM_SMI_CT_PHY_AD(hw->phy_addr)
1923 | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD);
1924
1925 for (i = 0; i < PHY_RETRIES; i++) {
1926 udelay(1);
1927 if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL)
1928 goto ready;
1929 }
1930
1931 return -ETIMEDOUT;
1932 ready:
1933 *val = gma_read16(hw, port, GM_SMI_DATA);
1934 return 0;
1935}
1936
1937static u16 gm_phy_read(struct skge_hw *hw, int port, u16 reg)
1938{
1939 u16 v = 0;
1940 if (__gm_phy_read(hw, port, reg, &v))
Joe Perchesf15063c2010-02-17 15:01:57 +00001941 pr_warning("%s: phy read timeout\n", hw->dev[port]->name);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001942 return v;
1943}
1944
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08001945/* Marvell Phy Initialization */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001946static void yukon_init(struct skge_hw *hw, int port)
1947{
1948 struct skge_port *skge = netdev_priv(hw->dev[port]);
1949 u16 ctrl, ct1000, adv;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001950
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001951 if (skge->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001952 u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001953
1954 ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
1955 PHY_M_EC_MAC_S_MSK);
1956 ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ);
1957
Stephen Hemmingerc506a502005-06-27 11:33:09 -07001958 ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001959
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001960 gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001961 }
1962
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001963 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001964 if (skge->autoneg == AUTONEG_DISABLE)
1965 ctrl &= ~PHY_CT_ANE;
1966
1967 ctrl |= PHY_CT_RESET;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001968 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001969
1970 ctrl = 0;
1971 ct1000 = 0;
Stephen Hemmingerb18f2092005-06-27 11:33:08 -07001972 adv = PHY_AN_CSMA;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001973
1974 if (skge->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07001975 if (hw->copper) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001976 if (skge->advertising & ADVERTISED_1000baseT_Full)
1977 ct1000 |= PHY_M_1000C_AFD;
1978 if (skge->advertising & ADVERTISED_1000baseT_Half)
1979 ct1000 |= PHY_M_1000C_AHD;
1980 if (skge->advertising & ADVERTISED_100baseT_Full)
1981 adv |= PHY_M_AN_100_FD;
1982 if (skge->advertising & ADVERTISED_100baseT_Half)
1983 adv |= PHY_M_AN_100_HD;
1984 if (skge->advertising & ADVERTISED_10baseT_Full)
1985 adv |= PHY_M_AN_10_FD;
1986 if (skge->advertising & ADVERTISED_10baseT_Half)
1987 adv |= PHY_M_AN_10_HD;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001988
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001989 /* Set Flow-control capabilities */
1990 adv |= phy_pause_map[skge->flow_control];
1991 } else {
1992 if (skge->advertising & ADVERTISED_1000baseT_Full)
1993 adv |= PHY_M_AN_1000X_AFD;
1994 if (skge->advertising & ADVERTISED_1000baseT_Half)
1995 adv |= PHY_M_AN_1000X_AHD;
1996
1997 adv |= fiber_pause_map[skge->flow_control];
1998 }
Stephen Hemminger45bada62005-06-27 11:33:12 -07001999
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002000 /* Restart Auto-negotiation */
2001 ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG;
2002 } else {
2003 /* forced speed/duplex settings */
2004 ct1000 = PHY_M_1000C_MSE;
2005
2006 if (skge->duplex == DUPLEX_FULL)
2007 ctrl |= PHY_CT_DUP_MD;
2008
2009 switch (skge->speed) {
2010 case SPEED_1000:
2011 ctrl |= PHY_CT_SP1000;
2012 break;
2013 case SPEED_100:
2014 ctrl |= PHY_CT_SP100;
2015 break;
2016 }
2017
2018 ctrl |= PHY_CT_RESET;
2019 }
2020
Stephen Hemmingerc506a502005-06-27 11:33:09 -07002021 gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002022
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002023 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv);
2024 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002025
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002026 /* Enable phy interrupt on autonegotiation complete (or link up) */
2027 if (skge->autoneg == AUTONEG_ENABLE)
Stephen Hemminger4cde06e2005-07-22 16:26:09 -07002028 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002029 else
Stephen Hemminger4cde06e2005-07-22 16:26:09 -07002030 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002031}
2032
2033static void yukon_reset(struct skge_hw *hw, int port)
2034{
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002035 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);/* disable PHY IRQs */
2036 gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */
2037 gma_write16(hw, port, GM_MC_ADDR_H2, 0);
2038 gma_write16(hw, port, GM_MC_ADDR_H3, 0);
2039 gma_write16(hw, port, GM_MC_ADDR_H4, 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002040
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002041 gma_write16(hw, port, GM_RX_CTRL,
2042 gma_read16(hw, port, GM_RX_CTRL)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002043 | GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
2044}
2045
Stephen Hemmingerc8868612005-09-23 09:08:30 -07002046/* Apparently, early versions of Yukon-Lite had wrong chip_id? */
2047static int is_yukon_lite_a0(struct skge_hw *hw)
2048{
2049 u32 reg;
2050 int ret;
2051
2052 if (hw->chip_id != CHIP_ID_YUKON)
2053 return 0;
2054
2055 reg = skge_read32(hw, B2_FAR);
2056 skge_write8(hw, B2_FAR + 3, 0xff);
2057 ret = (skge_read8(hw, B2_FAR + 3) != 0);
2058 skge_write32(hw, B2_FAR, reg);
2059 return ret;
2060}
2061
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002062static void yukon_mac_init(struct skge_hw *hw, int port)
2063{
2064 struct skge_port *skge = netdev_priv(hw->dev[port]);
2065 int i;
2066 u32 reg;
2067 const u8 *addr = hw->dev[port]->dev_addr;
2068
2069 /* WA code for COMA mode -- set PHY reset */
2070 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002071 hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
2072 reg = skge_read32(hw, B2_GP_IO);
2073 reg |= GP_DIR_9 | GP_IO_9;
2074 skge_write32(hw, B2_GP_IO, reg);
2075 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002076
2077 /* hard reset */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002078 skge_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
2079 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002080
2081 /* WA code for COMA mode -- clear PHY reset */
2082 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002083 hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
2084 reg = skge_read32(hw, B2_GP_IO);
2085 reg |= GP_DIR_9;
2086 reg &= ~GP_IO_9;
2087 skge_write32(hw, B2_GP_IO, reg);
2088 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002089
2090 /* Set hardware config mode */
2091 reg = GPC_INT_POL_HI | GPC_DIS_FC | GPC_DIS_SLEEP |
2092 GPC_ENA_XC | GPC_ANEG_ADV_ALL_M | GPC_ENA_PAUSE;
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07002093 reg |= hw->copper ? GPC_HWCFG_GMII_COP : GPC_HWCFG_GMII_FIB;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002094
2095 /* Clear GMC reset */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002096 skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_SET);
2097 skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_CLR);
2098 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR);
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002099
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002100 if (skge->autoneg == AUTONEG_DISABLE) {
2101 reg = GM_GPCR_AU_ALL_DIS;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002102 gma_write16(hw, port, GM_GP_CTRL,
2103 gma_read16(hw, port, GM_GP_CTRL) | reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002104
2105 switch (skge->speed) {
2106 case SPEED_1000:
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002107 reg &= ~GM_GPCR_SPEED_100;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002108 reg |= GM_GPCR_SPEED_1000;
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002109 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002110 case SPEED_100:
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002111 reg &= ~GM_GPCR_SPEED_1000;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002112 reg |= GM_GPCR_SPEED_100;
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002113 break;
2114 case SPEED_10:
2115 reg &= ~(GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100);
2116 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002117 }
2118
2119 if (skge->duplex == DUPLEX_FULL)
2120 reg |= GM_GPCR_DUP_FULL;
2121 } else
2122 reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL;
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002123
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002124 switch (skge->flow_control) {
2125 case FLOW_MODE_NONE:
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002126 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002127 reg |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
2128 break;
2129 case FLOW_MODE_LOC_SEND:
2130 /* disable Rx flow-control */
2131 reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002132 break;
2133 case FLOW_MODE_SYMMETRIC:
2134 case FLOW_MODE_SYM_OR_REM:
2135 /* enable Tx & Rx flow-control */
2136 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002137 }
2138
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002139 gma_write16(hw, port, GM_GP_CTRL, reg);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002140 skge_read16(hw, SK_REG(port, GMAC_IRQ_SRC));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002141
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002142 yukon_init(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002143
2144 /* MIB clear */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002145 reg = gma_read16(hw, port, GM_PHY_ADDR);
2146 gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002147
2148 for (i = 0; i < GM_MIB_CNT_SIZE; i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002149 gma_read16(hw, port, GM_MIB_CNT_BASE + 8*i);
2150 gma_write16(hw, port, GM_PHY_ADDR, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002151
2152 /* transmit control */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002153 gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002154
2155 /* receive control reg: unicast + multicast + no FCS */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002156 gma_write16(hw, port, GM_RX_CTRL,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002157 GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA);
2158
2159 /* transmit flow control */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002160 gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002161
2162 /* transmit parameter */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002163 gma_write16(hw, port, GM_TX_PARAM,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002164 TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) |
2165 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) |
2166 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF));
2167
Stephen Hemminger44c7fcc2007-11-28 14:23:01 -08002168 /* configure the Serial Mode Register */
2169 reg = DATA_BLIND_VAL(DATA_BLIND_DEF)
2170 | GM_SMOD_VLAN_ENA
2171 | IPG_DATA_VAL(IPG_DATA_DEF);
2172
2173 if (hw->dev[port]->mtu > ETH_DATA_LEN)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002174 reg |= GM_SMOD_JUMBO_ENA;
2175
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002176 gma_write16(hw, port, GM_SERIAL_MODE, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002177
2178 /* physical address: used for pause frames */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002179 gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002180 /* virtual address for data */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002181 gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002182
2183 /* enable interrupt mask for counter overflows */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002184 gma_write16(hw, port, GM_TX_IRQ_MSK, 0);
2185 gma_write16(hw, port, GM_RX_IRQ_MSK, 0);
2186 gma_write16(hw, port, GM_TR_IRQ_MSK, 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002187
2188 /* Initialize Mac Fifo */
2189
2190 /* Configure Rx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002191 skge_write16(hw, SK_REG(port, RX_GMF_FL_MSK), RX_FF_FL_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002192 reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
Stephen Hemmingerc8868612005-09-23 09:08:30 -07002193
2194 /* disable Rx GMAC FIFO Flush for YUKON-Lite Rev. A0 only */
2195 if (is_yukon_lite_a0(hw))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002196 reg &= ~GMF_RX_F_FL_ON;
Stephen Hemmingerc8868612005-09-23 09:08:30 -07002197
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002198 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
2199 skge_write16(hw, SK_REG(port, RX_GMF_CTRL_T), reg);
Stephen Hemmingerc5923082005-08-16 14:01:02 -07002200 /*
2201 * because Pause Packet Truncation in GMAC is not working
2202 * we have to increase the Flush Threshold to 64 bytes
2203 * in order to flush pause packets in Rx FIFO on Yukon-1
2204 */
2205 skge_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF+1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002206
2207 /* Configure Tx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002208 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
2209 skge_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002210}
2211
Stephen Hemminger355ec572005-11-08 10:33:43 -08002212/* Go into power down mode */
2213static void yukon_suspend(struct skge_hw *hw, int port)
2214{
2215 u16 ctrl;
2216
2217 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
2218 ctrl |= PHY_M_PC_POL_R_DIS;
2219 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
2220
2221 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
2222 ctrl |= PHY_CT_RESET;
2223 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
2224
2225 /* switch IEEE compatible power down mode on */
2226 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
2227 ctrl |= PHY_CT_PDOWN;
2228 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
2229}
2230
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002231static void yukon_stop(struct skge_port *skge)
2232{
2233 struct skge_hw *hw = skge->hw;
2234 int port = skge->port;
2235
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002236 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
2237 yukon_reset(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002238
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002239 gma_write16(hw, port, GM_GP_CTRL,
2240 gma_read16(hw, port, GM_GP_CTRL)
Stephen Hemminger0eedf4a2005-07-22 16:26:04 -07002241 & ~(GM_GPCR_TX_ENA|GM_GPCR_RX_ENA));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002242 gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002243
Stephen Hemminger355ec572005-11-08 10:33:43 -08002244 yukon_suspend(hw, port);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002245
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002246 /* set GPHY Control reset */
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002247 skge_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
2248 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002249}
2250
2251static void yukon_get_stats(struct skge_port *skge, u64 *data)
2252{
2253 struct skge_hw *hw = skge->hw;
2254 int port = skge->port;
2255 int i;
2256
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002257 data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32
2258 | gma_read32(hw, port, GM_TXO_OK_LO);
2259 data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32
2260 | gma_read32(hw, port, GM_RXO_OK_LO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002261
2262 for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002263 data[i] = gma_read32(hw, port,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002264 skge_stats[i].gma_offset);
2265}
2266
2267static void yukon_mac_intr(struct skge_hw *hw, int port)
2268{
Stephen Hemminger7e676d92005-06-27 11:33:13 -07002269 struct net_device *dev = hw->dev[port];
2270 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002271 u8 status = skge_read8(hw, SK_REG(port, GMAC_IRQ_SRC));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002272
Joe Perchesd7072042010-02-09 11:49:53 +00002273 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
2274 "mac interrupt status 0x%x\n", status);
Stephen Hemminger7e676d92005-06-27 11:33:13 -07002275
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002276 if (status & GM_IS_RX_FF_OR) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07002277 ++dev->stats.rx_fifo_errors;
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002278 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002279 }
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002280
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002281 if (status & GM_IS_TX_FF_UR) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07002282 ++dev->stats.tx_fifo_errors;
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002283 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002284 }
2285
2286}
2287
2288static u16 yukon_speed(const struct skge_hw *hw, u16 aux)
2289{
Stephen Hemminger95566062005-06-27 11:33:02 -07002290 switch (aux & PHY_M_PS_SPEED_MSK) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002291 case PHY_M_PS_SPEED_1000:
2292 return SPEED_1000;
2293 case PHY_M_PS_SPEED_100:
2294 return SPEED_100;
2295 default:
2296 return SPEED_10;
2297 }
2298}
2299
2300static void yukon_link_up(struct skge_port *skge)
2301{
2302 struct skge_hw *hw = skge->hw;
2303 int port = skge->port;
2304 u16 reg;
2305
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002306 /* Enable Transmit FIFO Underrun */
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002307 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002308
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002309 reg = gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002310 if (skge->duplex == DUPLEX_FULL || skge->autoneg == AUTONEG_ENABLE)
2311 reg |= GM_GPCR_DUP_FULL;
2312
2313 /* enable Rx/Tx */
2314 reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002315 gma_write16(hw, port, GM_GP_CTRL, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002316
Stephen Hemminger4cde06e2005-07-22 16:26:09 -07002317 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002318 skge_link_up(skge);
2319}
2320
2321static void yukon_link_down(struct skge_port *skge)
2322{
2323 struct skge_hw *hw = skge->hw;
2324 int port = skge->port;
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002325 u16 ctrl;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002326
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002327 ctrl = gma_read16(hw, port, GM_GP_CTRL);
2328 ctrl &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
2329 gma_write16(hw, port, GM_GP_CTRL, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002330
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002331 if (skge->flow_status == FLOW_STAT_REM_SEND) {
2332 ctrl = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV);
2333 ctrl |= PHY_M_AN_ASP;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002334 /* restore Asymmetric Pause bit */
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002335 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002336 }
2337
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002338 skge_link_down(skge);
2339
2340 yukon_init(hw, port);
2341}
2342
2343static void yukon_phy_intr(struct skge_port *skge)
2344{
2345 struct skge_hw *hw = skge->hw;
2346 int port = skge->port;
2347 const char *reason = NULL;
2348 u16 istatus, phystat;
2349
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002350 istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT);
2351 phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT);
Stephen Hemminger7e676d92005-06-27 11:33:13 -07002352
Joe Perchesd7072042010-02-09 11:49:53 +00002353 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
2354 "phy interrupt status 0x%x 0x%x\n", istatus, phystat);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002355
2356 if (istatus & PHY_M_IS_AN_COMPL) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002357 if (gm_phy_read(hw, port, PHY_MARV_AUNE_LP)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002358 & PHY_M_AN_RF) {
2359 reason = "remote fault";
2360 goto failed;
2361 }
2362
Stephen Hemmingerc506a502005-06-27 11:33:09 -07002363 if (gm_phy_read(hw, port, PHY_MARV_1000T_STAT) & PHY_B_1000S_MSF) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002364 reason = "master/slave fault";
2365 goto failed;
2366 }
2367
2368 if (!(phystat & PHY_M_PS_SPDUP_RES)) {
2369 reason = "speed/duplex";
2370 goto failed;
2371 }
2372
2373 skge->duplex = (phystat & PHY_M_PS_FULL_DUP)
2374 ? DUPLEX_FULL : DUPLEX_HALF;
2375 skge->speed = yukon_speed(hw, phystat);
2376
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002377 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
2378 switch (phystat & PHY_M_PS_PAUSE_MSK) {
2379 case PHY_M_PS_PAUSE_MSK:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002380 skge->flow_status = FLOW_STAT_SYMMETRIC;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002381 break;
2382 case PHY_M_PS_RX_P_EN:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002383 skge->flow_status = FLOW_STAT_REM_SEND;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002384 break;
2385 case PHY_M_PS_TX_P_EN:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002386 skge->flow_status = FLOW_STAT_LOC_SEND;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002387 break;
2388 default:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002389 skge->flow_status = FLOW_STAT_NONE;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002390 }
2391
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002392 if (skge->flow_status == FLOW_STAT_NONE ||
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002393 (skge->speed < SPEED_1000 && skge->duplex == DUPLEX_HALF))
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002394 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002395 else
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002396 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002397 yukon_link_up(skge);
2398 return;
2399 }
2400
2401 if (istatus & PHY_M_IS_LSP_CHANGE)
2402 skge->speed = yukon_speed(hw, phystat);
2403
2404 if (istatus & PHY_M_IS_DUP_CHANGE)
2405 skge->duplex = (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
2406 if (istatus & PHY_M_IS_LST_CHANGE) {
2407 if (phystat & PHY_M_PS_LINK_UP)
2408 yukon_link_up(skge);
2409 else
2410 yukon_link_down(skge);
2411 }
2412 return;
2413 failed:
Joe Perchesf15063c2010-02-17 15:01:57 +00002414 pr_err("%s: autonegotiation failed (%s)\n", skge->netdev->name, reason);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002415
2416 /* XXX restart autonegotiation? */
2417}
2418
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002419static void skge_phy_reset(struct skge_port *skge)
2420{
2421 struct skge_hw *hw = skge->hw;
2422 int port = skge->port;
Jeff Garzikaae343d2006-12-02 07:14:39 -05002423 struct net_device *dev = hw->dev[port];
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002424
2425 netif_stop_queue(skge->netdev);
2426 netif_carrier_off(skge->netdev);
2427
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002428 spin_lock_bh(&hw->phy_lock);
stephen hemminger57d6fa32011-07-06 19:00:07 +00002429 if (is_genesis(hw)) {
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002430 genesis_reset(hw, port);
2431 genesis_mac_init(hw, port);
2432 } else {
2433 yukon_reset(hw, port);
2434 yukon_init(hw, port);
2435 }
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002436 spin_unlock_bh(&hw->phy_lock);
Stephen Hemminger75814092006-12-01 11:41:08 -08002437
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08002438 skge_set_multicast(dev);
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002439}
2440
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002441/* Basic MII support */
2442static int skge_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2443{
2444 struct mii_ioctl_data *data = if_mii(ifr);
2445 struct skge_port *skge = netdev_priv(dev);
2446 struct skge_hw *hw = skge->hw;
2447 int err = -EOPNOTSUPP;
2448
2449 if (!netif_running(dev))
2450 return -ENODEV; /* Phy still in reset */
2451
Joe Perches67777f92010-02-17 15:01:58 +00002452 switch (cmd) {
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002453 case SIOCGMIIPHY:
2454 data->phy_id = hw->phy_addr;
2455
2456 /* fallthru */
2457 case SIOCGMIIREG: {
2458 u16 val = 0;
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002459 spin_lock_bh(&hw->phy_lock);
stephen hemminger57d6fa32011-07-06 19:00:07 +00002460
2461 if (is_genesis(hw))
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002462 err = __xm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val);
2463 else
2464 err = __gm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002465 spin_unlock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002466 data->val_out = val;
2467 break;
2468 }
2469
2470 case SIOCSMIIREG:
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002471 spin_lock_bh(&hw->phy_lock);
stephen hemminger57d6fa32011-07-06 19:00:07 +00002472 if (is_genesis(hw))
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002473 err = xm_phy_write(hw, skge->port, data->reg_num & 0x1f,
2474 data->val_in);
2475 else
2476 err = gm_phy_write(hw, skge->port, data->reg_num & 0x1f,
2477 data->val_in);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002478 spin_unlock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002479 break;
2480 }
2481 return err;
2482}
2483
Linus Torvalds279e1da2007-11-15 08:44:36 -08002484static void skge_ramset(struct skge_hw *hw, u16 q, u32 start, size_t len)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002485{
2486 u32 end;
2487
Linus Torvalds279e1da2007-11-15 08:44:36 -08002488 start /= 8;
2489 len /= 8;
2490 end = start + len - 1;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002491
2492 skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR);
2493 skge_write32(hw, RB_ADDR(q, RB_START), start);
2494 skge_write32(hw, RB_ADDR(q, RB_WP), start);
2495 skge_write32(hw, RB_ADDR(q, RB_RP), start);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002496 skge_write32(hw, RB_ADDR(q, RB_END), end);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002497
2498 if (q == Q_R1 || q == Q_R2) {
2499 /* Set thresholds on receive queue's */
Linus Torvalds279e1da2007-11-15 08:44:36 -08002500 skge_write32(hw, RB_ADDR(q, RB_RX_UTPP),
2501 start + (2*len)/3);
2502 skge_write32(hw, RB_ADDR(q, RB_RX_LTPP),
2503 start + (len/3));
2504 } else {
2505 /* Enable store & forward on Tx queue's because
2506 * Tx FIFO is only 4K on Genesis and 1K on Yukon
2507 */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002508 skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002509 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002510
2511 skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD);
2512}
2513
2514/* Setup Bus Memory Interface */
2515static void skge_qset(struct skge_port *skge, u16 q,
2516 const struct skge_element *e)
2517{
2518 struct skge_hw *hw = skge->hw;
2519 u32 watermark = 0x600;
2520 u64 base = skge->dma + (e->desc - skge->mem);
2521
2522 /* optimization to reduce window on 32bit/33mhz */
2523 if ((skge_read16(hw, B0_CTST) & (CS_BUS_CLOCK | CS_BUS_SLOT_SZ)) == 0)
2524 watermark /= 2;
2525
2526 skge_write32(hw, Q_ADDR(q, Q_CSR), CSR_CLR_RESET);
2527 skge_write32(hw, Q_ADDR(q, Q_F), watermark);
2528 skge_write32(hw, Q_ADDR(q, Q_DA_H), (u32)(base >> 32));
2529 skge_write32(hw, Q_ADDR(q, Q_DA_L), (u32)base);
2530}
2531
2532static int skge_up(struct net_device *dev)
2533{
2534 struct skge_port *skge = netdev_priv(dev);
2535 struct skge_hw *hw = skge->hw;
2536 int port = skge->port;
Linus Torvalds279e1da2007-11-15 08:44:36 -08002537 u32 chunk, ram_addr;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002538 size_t rx_size, tx_size;
2539 int err;
2540
Stephen Hemmingerfae87592007-02-02 08:22:51 -08002541 if (!is_valid_ether_addr(dev->dev_addr))
2542 return -EINVAL;
2543
Joe Perchesd7072042010-02-09 11:49:53 +00002544 netif_info(skge, ifup, skge->netdev, "enabling interface\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002545
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002546 if (dev->mtu > RX_BUF_SIZE)
Stephen Hemminger901ccef2006-03-23 11:07:23 -08002547 skge->rx_buf_size = dev->mtu + ETH_HLEN;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002548 else
2549 skge->rx_buf_size = RX_BUF_SIZE;
2550
2551
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002552 rx_size = skge->rx_ring.count * sizeof(struct skge_rx_desc);
2553 tx_size = skge->tx_ring.count * sizeof(struct skge_tx_desc);
2554 skge->mem_size = tx_size + rx_size;
2555 skge->mem = pci_alloc_consistent(hw->pdev, skge->mem_size, &skge->dma);
2556 if (!skge->mem)
2557 return -ENOMEM;
2558
Stephen Hemmingerc3da1442006-03-21 10:57:01 -08002559 BUG_ON(skge->dma & 7);
2560
2561 if ((u64)skge->dma >> 32 != ((u64) skge->dma + skge->mem_size) >> 32) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08002562 dev_err(&hw->pdev->dev, "pci_alloc_consistent region crosses 4G boundary\n");
Stephen Hemmingerc3da1442006-03-21 10:57:01 -08002563 err = -EINVAL;
2564 goto free_pci_mem;
2565 }
2566
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002567 memset(skge->mem, 0, skge->mem_size);
2568
Stephen Hemminger203babb2006-03-21 10:57:05 -08002569 err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma);
2570 if (err)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002571 goto free_pci_mem;
2572
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07002573 err = skge_rx_fill(dev);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002574 if (err)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002575 goto free_rx_ring;
2576
Stephen Hemminger203babb2006-03-21 10:57:05 -08002577 err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size,
2578 skge->dma + rx_size);
2579 if (err)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002580 goto free_rx_ring;
2581
Stephen Hemmingera9e9fd72011-09-27 13:41:37 -04002582 if (hw->ports == 1) {
2583 err = request_irq(hw->pdev->irq, skge_intr, IRQF_SHARED,
2584 dev->name, hw);
2585 if (err) {
2586 netdev_err(dev, "Unable to allocate interrupt %d error: %d\n",
2587 hw->pdev->irq, err);
2588 goto free_tx_ring;
2589 }
2590 }
2591
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08002592 /* Initialize MAC */
stephen hemminger19f9ad72012-01-19 14:35:25 +00002593 netif_carrier_off(dev);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002594 spin_lock_bh(&hw->phy_lock);
stephen hemminger57d6fa32011-07-06 19:00:07 +00002595 if (is_genesis(hw))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002596 genesis_mac_init(hw, port);
2597 else
2598 yukon_mac_init(hw, port);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002599 spin_unlock_bh(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002600
Stephen Hemminger29816d92007-11-26 11:54:48 -08002601 /* Configure RAMbuffers - equally between ports and tx/rx */
2602 chunk = (hw->ram_size - hw->ram_offset) / (hw->ports * 2);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002603 ram_addr = hw->ram_offset + 2 * chunk * port;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002604
Linus Torvalds279e1da2007-11-15 08:44:36 -08002605 skge_ramset(hw, rxqaddr[port], ram_addr, chunk);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002606 skge_qset(skge, rxqaddr[port], skge->rx_ring.to_clean);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002607
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002608 BUG_ON(skge->tx_ring.to_use != skge->tx_ring.to_clean);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002609 skge_ramset(hw, txqaddr[port], ram_addr+chunk, chunk);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002610 skge_qset(skge, txqaddr[port], skge->tx_ring.to_use);
2611
2612 /* Start receiver BMU */
2613 wmb();
2614 skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_START | CSR_IRQ_CL_F);
Stephen Hemminger6abebb52005-07-22 16:26:10 -07002615 skge_led(skge, LED_MODE_ON);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002616
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07002617 spin_lock_irq(&hw->hw_lock);
2618 hw->intr_mask |= portmask[port];
2619 skge_write32(hw, B0_IMSK, hw->intr_mask);
Stephen Hemmingera9e9fd72011-09-27 13:41:37 -04002620 skge_read32(hw, B0_IMSK);
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07002621 spin_unlock_irq(&hw->hw_lock);
2622
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002623 napi_enable(&skge->napi);
Florian Zumbiehlfe3c8cc2011-12-30 17:30:09 +00002624
2625 skge_set_multicast(dev);
2626
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002627 return 0;
2628
Stephen Hemmingera9e9fd72011-09-27 13:41:37 -04002629 free_tx_ring:
2630 kfree(skge->tx_ring.start);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002631 free_rx_ring:
2632 skge_rx_clean(skge);
2633 kfree(skge->rx_ring.start);
2634 free_pci_mem:
2635 pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002636 skge->mem = NULL;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002637
2638 return err;
2639}
2640
Stephen Hemminger60b24b52007-10-16 12:15:50 -07002641/* stop receiver */
2642static void skge_rx_stop(struct skge_hw *hw, int port)
2643{
2644 skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_STOP);
2645 skge_write32(hw, RB_ADDR(port ? Q_R2 : Q_R1, RB_CTRL),
2646 RB_RST_SET|RB_DIS_OP_MD);
2647 skge_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_SET_RESET);
2648}
2649
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002650static int skge_down(struct net_device *dev)
2651{
2652 struct skge_port *skge = netdev_priv(dev);
2653 struct skge_hw *hw = skge->hw;
2654 int port = skge->port;
2655
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002656 if (skge->mem == NULL)
2657 return 0;
2658
Joe Perchesd7072042010-02-09 11:49:53 +00002659 netif_info(skge, ifdown, skge->netdev, "disabling interface\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002660
Michal Schmidtd119b392009-04-14 15:16:55 -07002661 netif_tx_disable(dev);
Stephen Hemminger692412b2007-04-09 15:32:45 -07002662
stephen hemminger57d6fa32011-07-06 19:00:07 +00002663 if (is_genesis(hw) && hw->phy_type == SK_PHY_XMAC)
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002664 del_timer_sync(&skge->link_timer);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002665
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002666 napi_disable(&skge->napi);
Stephen Hemminger692412b2007-04-09 15:32:45 -07002667 netif_carrier_off(dev);
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07002668
2669 spin_lock_irq(&hw->hw_lock);
2670 hw->intr_mask &= ~portmask[port];
Stephen Hemmingera9e9fd72011-09-27 13:41:37 -04002671 skge_write32(hw, B0_IMSK, (hw->ports == 1) ? 0 : hw->intr_mask);
2672 skge_read32(hw, B0_IMSK);
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07002673 spin_unlock_irq(&hw->hw_lock);
2674
Stephen Hemmingera9e9fd72011-09-27 13:41:37 -04002675 if (hw->ports == 1)
2676 free_irq(hw->pdev->irq, hw);
2677
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002678 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF);
stephen hemminger57d6fa32011-07-06 19:00:07 +00002679 if (is_genesis(hw))
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002680 genesis_stop(skge);
2681 else
2682 yukon_stop(skge);
2683
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002684 /* Stop transmitter */
2685 skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP);
2686 skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL),
2687 RB_RST_SET|RB_DIS_OP_MD);
2688
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002689
2690 /* Disable Force Sync bit and Enable Alloc bit */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002691 skge_write8(hw, SK_REG(port, TXA_CTRL),
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002692 TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
2693
2694 /* Stop Interval Timer and Limit Counter of Tx Arbiter */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002695 skge_write32(hw, SK_REG(port, TXA_ITI_INI), 0L);
2696 skge_write32(hw, SK_REG(port, TXA_LIM_INI), 0L);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002697
2698 /* Reset PCI FIFO */
2699 skge_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_SET_RESET);
2700 skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET);
2701
2702 /* Reset the RAM Buffer async Tx queue */
2703 skge_write8(hw, RB_ADDR(port == 0 ? Q_XA1 : Q_XA2, RB_CTRL), RB_RST_SET);
Stephen Hemminger60b24b52007-10-16 12:15:50 -07002704
2705 skge_rx_stop(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002706
stephen hemminger57d6fa32011-07-06 19:00:07 +00002707 if (is_genesis(hw)) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002708 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_SET);
2709 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002710 } else {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002711 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
2712 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002713 }
2714
Stephen Hemminger6abebb52005-07-22 16:26:10 -07002715 skge_led(skge, LED_MODE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002716
Stephen Hemmingere3a1b992007-03-16 14:01:26 -07002717 netif_tx_lock_bh(dev);
Stephen Hemminger513f5332006-09-01 15:53:49 -07002718 skge_tx_clean(dev);
Stephen Hemmingere3a1b992007-03-16 14:01:26 -07002719 netif_tx_unlock_bh(dev);
2720
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002721 skge_rx_clean(skge);
2722
2723 kfree(skge->rx_ring.start);
2724 kfree(skge->tx_ring.start);
2725 pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002726 skge->mem = NULL;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002727 return 0;
2728}
2729
Stephen Hemminger29b4e882006-03-23 11:07:28 -08002730static inline int skge_avail(const struct skge_ring *ring)
2731{
Stephen Hemminger992c9622007-03-16 14:01:30 -07002732 smp_mb();
Stephen Hemminger29b4e882006-03-23 11:07:28 -08002733 return ((ring->to_clean > ring->to_use) ? 0 : ring->count)
2734 + (ring->to_clean - ring->to_use) - 1;
2735}
2736
Stephen Hemminger613573252009-08-31 19:50:58 +00002737static netdev_tx_t skge_xmit_frame(struct sk_buff *skb,
2738 struct net_device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002739{
2740 struct skge_port *skge = netdev_priv(dev);
2741 struct skge_hw *hw = skge->hw;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002742 struct skge_element *e;
2743 struct skge_tx_desc *td;
2744 int i;
2745 u32 control, len;
stephen hemmingerd0249e442012-01-19 14:37:18 +00002746 dma_addr_t map;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002747
Herbert Xu5b057c62006-06-23 02:06:41 -07002748 if (skb_padto(skb, ETH_ZLEN))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002749 return NETDEV_TX_OK;
2750
Stephen Hemminger513f5332006-09-01 15:53:49 -07002751 if (unlikely(skge_avail(&skge->tx_ring) < skb_shinfo(skb)->nr_frags + 1))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002752 return NETDEV_TX_BUSY;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002753
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002754 e = skge->tx_ring.to_use;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002755 td = e->desc;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002756 BUG_ON(td->control & BMU_OWN);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002757 e->skb = skb;
2758 len = skb_headlen(skb);
2759 map = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE);
stephen hemmingerd0249e442012-01-19 14:37:18 +00002760 if (pci_dma_mapping_error(hw->pdev, map))
2761 goto mapping_error;
2762
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00002763 dma_unmap_addr_set(e, mapaddr, map);
2764 dma_unmap_len_set(e, maplen, len);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002765
stephen hemmingerd0249e442012-01-19 14:37:18 +00002766 td->dma_lo = lower_32_bits(map);
2767 td->dma_hi = upper_32_bits(map);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002768
Patrick McHardy84fa7932006-08-29 16:44:56 -07002769 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Michał Mirosław0d0b1672010-12-14 15:24:08 +00002770 const int offset = skb_checksum_start_offset(skb);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002771
2772 /* This seems backwards, but it is what the sk98lin
2773 * does. Looks like hardware is wrong?
2774 */
Joe Perches8e95a202009-12-03 07:58:21 +00002775 if (ipip_hdr(skb)->protocol == IPPROTO_UDP &&
Joe Perches67777f92010-02-17 15:01:58 +00002776 hw->chip_rev == 0 && hw->chip_id == CHIP_ID_YUKON)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002777 control = BMU_TCP_CHECK;
2778 else
2779 control = BMU_UDP_CHECK;
2780
2781 td->csum_offs = 0;
2782 td->csum_start = offset;
Al Viroff1dcad2006-11-20 18:07:29 -08002783 td->csum_write = offset + skb->csum_offset;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002784 } else
2785 control = BMU_CHECK;
2786
2787 if (!skb_shinfo(skb)->nr_frags) /* single buffer i.e. no fragments */
Joe Perches67777f92010-02-17 15:01:58 +00002788 control |= BMU_EOF | BMU_IRQ_EOF;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002789 else {
2790 struct skge_tx_desc *tf = td;
2791
2792 control |= BMU_STFWD;
2793 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00002794 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002795
Ian Campbell516733c2011-09-21 21:53:17 +00002796 map = skb_frag_dma_map(&hw->pdev->dev, frag, 0,
Eric Dumazet9e903e02011-10-18 21:00:24 +00002797 skb_frag_size(frag), DMA_TO_DEVICE);
stephen hemmingerd0249e442012-01-19 14:37:18 +00002798 if (dma_mapping_error(&hw->pdev->dev, map))
2799 goto mapping_unwind;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002800
2801 e = e->next;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002802 e->skb = skb;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002803 tf = e->desc;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002804 BUG_ON(tf->control & BMU_OWN);
2805
stephen hemmingerd0249e442012-01-19 14:37:18 +00002806 tf->dma_lo = lower_32_bits(map);
2807 tf->dma_hi = upper_32_bits(map);
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00002808 dma_unmap_addr_set(e, mapaddr, map);
Eric Dumazet9e903e02011-10-18 21:00:24 +00002809 dma_unmap_len_set(e, maplen, skb_frag_size(frag));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002810
Eric Dumazet9e903e02011-10-18 21:00:24 +00002811 tf->control = BMU_OWN | BMU_SW | control | skb_frag_size(frag);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002812 }
2813 tf->control |= BMU_EOF | BMU_IRQ_EOF;
2814 }
2815 /* Make sure all the descriptors written */
2816 wmb();
2817 td->control = BMU_OWN | BMU_SW | BMU_STF | control | len;
2818 wmb();
2819
stephen hemmingerda057fb2012-01-22 09:40:40 +00002820 netdev_sent_queue(dev, skb->len);
2821
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002822 skge_write8(hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_START);
2823
Joe Perchesd7072042010-02-09 11:49:53 +00002824 netif_printk(skge, tx_queued, KERN_DEBUG, skge->netdev,
2825 "tx queued, slot %td, len %d\n",
2826 e - skge->tx_ring.start, skb->len);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002827
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002828 skge->tx_ring.to_use = e->next;
Stephen Hemminger992c9622007-03-16 14:01:30 -07002829 smp_wmb();
2830
Stephen Hemminger9db96472006-06-06 10:11:12 -07002831 if (skge_avail(&skge->tx_ring) <= TX_LOW_WATER) {
Joe Perchesf15063c2010-02-17 15:01:57 +00002832 netdev_dbg(dev, "transmit queue full\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002833 netif_stop_queue(dev);
2834 }
2835
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002836 return NETDEV_TX_OK;
stephen hemmingerd0249e442012-01-19 14:37:18 +00002837
2838mapping_unwind:
2839 /* unroll any pages that were already mapped. */
2840 if (e != skge->tx_ring.to_use) {
2841 struct skge_element *u;
2842
2843 for (u = skge->tx_ring.to_use->next; u != e; u = u->next)
2844 pci_unmap_page(hw->pdev, dma_unmap_addr(u, mapaddr),
2845 dma_unmap_len(u, maplen),
2846 PCI_DMA_TODEVICE);
2847 e = skge->tx_ring.to_use;
2848 }
2849 /* undo the mapping for the skb header */
2850 pci_unmap_single(hw->pdev, dma_unmap_addr(e, mapaddr),
2851 dma_unmap_len(e, maplen),
2852 PCI_DMA_TODEVICE);
2853mapping_error:
2854 /* mapping error causes error message and packet to be discarded. */
2855 if (net_ratelimit())
2856 dev_warn(&hw->pdev->dev, "%s: tx mapping error\n", dev->name);
2857 dev_kfree_skb(skb);
2858 return NETDEV_TX_OK;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002859}
2860
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002861
2862/* Free resources associated with this reing element */
stephen hemmingerda057fb2012-01-22 09:40:40 +00002863static inline void skge_tx_unmap(struct pci_dev *pdev, struct skge_element *e,
2864 u32 control)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002865{
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002866 /* skb header vs. fragment */
2867 if (control & BMU_STF)
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00002868 pci_unmap_single(pdev, dma_unmap_addr(e, mapaddr),
2869 dma_unmap_len(e, maplen),
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002870 PCI_DMA_TODEVICE);
2871 else
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00002872 pci_unmap_page(pdev, dma_unmap_addr(e, mapaddr),
2873 dma_unmap_len(e, maplen),
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002874 PCI_DMA_TODEVICE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002875}
2876
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002877/* Free all buffers in transmit ring */
Stephen Hemminger513f5332006-09-01 15:53:49 -07002878static void skge_tx_clean(struct net_device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002879{
Stephen Hemminger513f5332006-09-01 15:53:49 -07002880 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002881 struct skge_element *e;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002882
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002883 for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) {
2884 struct skge_tx_desc *td = e->desc;
stephen hemmingerda057fb2012-01-22 09:40:40 +00002885
2886 skge_tx_unmap(skge->hw->pdev, e, td->control);
2887
2888 if (td->control & BMU_EOF)
2889 dev_kfree_skb(e->skb);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002890 td->control = 0;
2891 }
2892
stephen hemmingerda057fb2012-01-22 09:40:40 +00002893 netdev_reset_queue(dev);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002894 skge->tx_ring.to_clean = e;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002895}
2896
2897static void skge_tx_timeout(struct net_device *dev)
2898{
2899 struct skge_port *skge = netdev_priv(dev);
2900
Joe Perchesd7072042010-02-09 11:49:53 +00002901 netif_printk(skge, timer, KERN_DEBUG, skge->netdev, "tx timeout\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002902
2903 skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_STOP);
Stephen Hemminger513f5332006-09-01 15:53:49 -07002904 skge_tx_clean(dev);
Michal Schmidtd119b392009-04-14 15:16:55 -07002905 netif_wake_queue(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002906}
2907
2908static int skge_change_mtu(struct net_device *dev, int new_mtu)
2909{
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002910 int err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002911
Stephen Hemminger95566062005-06-27 11:33:02 -07002912 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002913 return -EINVAL;
2914
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002915 if (!netif_running(dev)) {
2916 dev->mtu = new_mtu;
2917 return 0;
2918 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002919
Stephen Hemminger1a8098b2007-11-28 14:25:05 -08002920 skge_down(dev);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002921
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002922 dev->mtu = new_mtu;
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002923
Stephen Hemminger1a8098b2007-11-28 14:25:05 -08002924 err = skge_up(dev);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002925 if (err)
2926 dev_close(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002927
2928 return err;
2929}
2930
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002931static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 };
2932
2933static void genesis_add_filter(u8 filter[8], const u8 *addr)
2934{
2935 u32 crc, bit;
2936
2937 crc = ether_crc_le(ETH_ALEN, addr);
2938 bit = ~crc & 0x3f;
2939 filter[bit/8] |= 1 << (bit%8);
2940}
2941
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002942static void genesis_set_multicast(struct net_device *dev)
2943{
2944 struct skge_port *skge = netdev_priv(dev);
2945 struct skge_hw *hw = skge->hw;
2946 int port = skge->port;
Jiri Pirko22bedad32010-04-01 21:22:57 +00002947 struct netdev_hw_addr *ha;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002948 u32 mode;
2949 u8 filter[8];
2950
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002951 mode = xm_read32(hw, port, XM_MODE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002952 mode |= XM_MD_ENA_HASH;
2953 if (dev->flags & IFF_PROMISC)
2954 mode |= XM_MD_ENA_PROM;
2955 else
2956 mode &= ~XM_MD_ENA_PROM;
2957
2958 if (dev->flags & IFF_ALLMULTI)
2959 memset(filter, 0xff, sizeof(filter));
2960 else {
2961 memset(filter, 0, sizeof(filter));
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002962
Joe Perches8e95a202009-12-03 07:58:21 +00002963 if (skge->flow_status == FLOW_STAT_REM_SEND ||
2964 skge->flow_status == FLOW_STAT_SYMMETRIC)
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002965 genesis_add_filter(filter, pause_mc_addr);
2966
Jiri Pirko22bedad32010-04-01 21:22:57 +00002967 netdev_for_each_mc_addr(ha, dev)
2968 genesis_add_filter(filter, ha->addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002969 }
2970
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002971 xm_write32(hw, port, XM_MODE, mode);
Stephen Hemminger45bada62005-06-27 11:33:12 -07002972 xm_outhash(hw, port, XM_HSM, filter);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002973}
2974
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002975static void yukon_add_filter(u8 filter[8], const u8 *addr)
2976{
2977 u32 bit = ether_crc(ETH_ALEN, addr) & 0x3f;
2978 filter[bit/8] |= 1 << (bit%8);
2979}
2980
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002981static void yukon_set_multicast(struct net_device *dev)
2982{
2983 struct skge_port *skge = netdev_priv(dev);
2984 struct skge_hw *hw = skge->hw;
2985 int port = skge->port;
Jiri Pirko22bedad32010-04-01 21:22:57 +00002986 struct netdev_hw_addr *ha;
Joe Perches8e95a202009-12-03 07:58:21 +00002987 int rx_pause = (skge->flow_status == FLOW_STAT_REM_SEND ||
2988 skge->flow_status == FLOW_STAT_SYMMETRIC);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002989 u16 reg;
2990 u8 filter[8];
2991
2992 memset(filter, 0, sizeof(filter));
2993
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002994 reg = gma_read16(hw, port, GM_RX_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002995 reg |= GM_RXCR_UCF_ENA;
2996
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08002997 if (dev->flags & IFF_PROMISC) /* promiscuous */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002998 reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
2999 else if (dev->flags & IFF_ALLMULTI) /* all multicast */
3000 memset(filter, 0xff, sizeof(filter));
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00003001 else if (netdev_mc_empty(dev) && !rx_pause)/* no multicast */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003002 reg &= ~GM_RXCR_MCF_ENA;
3003 else {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003004 reg |= GM_RXCR_MCF_ENA;
3005
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08003006 if (rx_pause)
3007 yukon_add_filter(filter, pause_mc_addr);
3008
Jiri Pirko22bedad32010-04-01 21:22:57 +00003009 netdev_for_each_mc_addr(ha, dev)
3010 yukon_add_filter(filter, ha->addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003011 }
3012
3013
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003014 gma_write16(hw, port, GM_MC_ADDR_H1,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003015 (u16)filter[0] | ((u16)filter[1] << 8));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003016 gma_write16(hw, port, GM_MC_ADDR_H2,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003017 (u16)filter[2] | ((u16)filter[3] << 8));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003018 gma_write16(hw, port, GM_MC_ADDR_H3,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003019 (u16)filter[4] | ((u16)filter[5] << 8));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003020 gma_write16(hw, port, GM_MC_ADDR_H4,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003021 (u16)filter[6] | ((u16)filter[7] << 8));
3022
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003023 gma_write16(hw, port, GM_RX_CTRL, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003024}
3025
Stephen Hemminger383181a2005-09-19 15:37:16 -07003026static inline u16 phy_length(const struct skge_hw *hw, u32 status)
3027{
stephen hemminger57d6fa32011-07-06 19:00:07 +00003028 if (is_genesis(hw))
Stephen Hemminger383181a2005-09-19 15:37:16 -07003029 return status >> XMR_FS_LEN_SHIFT;
3030 else
3031 return status >> GMR_FS_LEN_SHIFT;
3032}
3033
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003034static inline int bad_phy_status(const struct skge_hw *hw, u32 status)
3035{
stephen hemminger57d6fa32011-07-06 19:00:07 +00003036 if (is_genesis(hw))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003037 return (status & (XMR_FS_ERR | XMR_FS_2L_VLAN)) != 0;
3038 else
3039 return (status & GMR_FS_ANY_ERR) ||
3040 (status & GMR_FS_RX_OK) == 0;
3041}
3042
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003043static void skge_set_multicast(struct net_device *dev)
3044{
3045 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003046
stephen hemminger57d6fa32011-07-06 19:00:07 +00003047 if (is_genesis(skge->hw))
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003048 genesis_set_multicast(dev);
3049 else
3050 yukon_set_multicast(dev);
3051
3052}
3053
Stephen Hemminger383181a2005-09-19 15:37:16 -07003054
3055/* Get receive buffer from descriptor.
3056 * Handles copy of small buffers and reallocation failures
3057 */
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003058static struct sk_buff *skge_rx_get(struct net_device *dev,
3059 struct skge_element *e,
3060 u32 control, u32 status, u16 csum)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003061{
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003062 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003063 struct sk_buff *skb;
3064 u16 len = control & BMU_BBC;
3065
Joe Perchesd7072042010-02-09 11:49:53 +00003066 netif_printk(skge, rx_status, KERN_DEBUG, skge->netdev,
3067 "rx slot %td status 0x%x len %d\n",
3068 e - skge->rx_ring.start, status, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003069
3070 if (len > skge->rx_buf_size)
3071 goto error;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003072
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003073 if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF))
Stephen Hemminger383181a2005-09-19 15:37:16 -07003074 goto error;
3075
3076 if (bad_phy_status(skge->hw, status))
3077 goto error;
3078
3079 if (phy_length(skge->hw, status) != len)
3080 goto error;
3081
3082 if (len < RX_COPY_THRESHOLD) {
Eric Dumazet89d71a62009-10-13 05:34:20 +00003083 skb = netdev_alloc_skb_ip_align(dev, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003084 if (!skb)
3085 goto resubmit;
3086
Stephen Hemminger383181a2005-09-19 15:37:16 -07003087 pci_dma_sync_single_for_cpu(skge->hw->pdev,
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00003088 dma_unmap_addr(e, mapaddr),
Stephen Hemminger383181a2005-09-19 15:37:16 -07003089 len, PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03003090 skb_copy_from_linear_data(e->skb, skb->data, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003091 pci_dma_sync_single_for_device(skge->hw->pdev,
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00003092 dma_unmap_addr(e, mapaddr),
Stephen Hemminger383181a2005-09-19 15:37:16 -07003093 len, PCI_DMA_FROMDEVICE);
3094 skge_rx_reuse(e, skge->rx_buf_size);
3095 } else {
3096 struct sk_buff *nskb;
Eric Dumazet89d71a62009-10-13 05:34:20 +00003097
3098 nskb = netdev_alloc_skb_ip_align(dev, skge->rx_buf_size);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003099 if (!nskb)
3100 goto resubmit;
3101
stephen hemmingerd0249e442012-01-19 14:37:18 +00003102 if (unlikely(skge_rx_setup(skge->hw->pdev, e, nskb, skge->rx_buf_size))) {
3103 dev_kfree_skb(nskb);
3104 goto resubmit;
3105 }
3106
Stephen Hemminger383181a2005-09-19 15:37:16 -07003107 pci_unmap_single(skge->hw->pdev,
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00003108 dma_unmap_addr(e, mapaddr),
3109 dma_unmap_len(e, maplen),
Stephen Hemminger383181a2005-09-19 15:37:16 -07003110 PCI_DMA_FROMDEVICE);
3111 skb = e->skb;
Joe Perches67777f92010-02-17 15:01:58 +00003112 prefetch(skb->data);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003113 }
3114
3115 skb_put(skb, len);
Michał Mirosławe92702b2011-03-31 01:01:35 +00003116
3117 if (dev->features & NETIF_F_RXCSUM) {
Stephen Hemminger383181a2005-09-19 15:37:16 -07003118 skb->csum = csum;
Patrick McHardy84fa7932006-08-29 16:44:56 -07003119 skb->ip_summed = CHECKSUM_COMPLETE;
Stephen Hemminger383181a2005-09-19 15:37:16 -07003120 }
3121
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003122 skb->protocol = eth_type_trans(skb, dev);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003123
3124 return skb;
3125error:
3126
Joe Perchesd7072042010-02-09 11:49:53 +00003127 netif_printk(skge, rx_err, KERN_DEBUG, skge->netdev,
3128 "rx err, slot %td control 0x%x status 0x%x\n",
3129 e - skge->rx_ring.start, control, status);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003130
stephen hemminger57d6fa32011-07-06 19:00:07 +00003131 if (is_genesis(skge->hw)) {
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003132 if (status & (XMR_FS_RUNT|XMR_FS_LNG_ERR))
Stephen Hemmingerda007722007-10-16 12:15:52 -07003133 dev->stats.rx_length_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003134 if (status & XMR_FS_FRA_ERR)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003135 dev->stats.rx_frame_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003136 if (status & XMR_FS_FCS_ERR)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003137 dev->stats.rx_crc_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003138 } else {
3139 if (status & (GMR_FS_LONG_ERR|GMR_FS_UN_SIZE))
Stephen Hemmingerda007722007-10-16 12:15:52 -07003140 dev->stats.rx_length_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003141 if (status & GMR_FS_FRAGMENT)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003142 dev->stats.rx_frame_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003143 if (status & GMR_FS_CRC_ERR)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003144 dev->stats.rx_crc_errors++;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003145 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003146
Stephen Hemminger383181a2005-09-19 15:37:16 -07003147resubmit:
3148 skge_rx_reuse(e, skge->rx_buf_size);
3149 return NULL;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003150}
3151
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003152/* Free all buffers in Tx ring which are no longer owned by device */
Stephen Hemminger513f5332006-09-01 15:53:49 -07003153static void skge_tx_done(struct net_device *dev)
Stephen Hemminger00a6cae22006-03-21 10:56:59 -08003154{
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003155 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger00a6cae22006-03-21 10:56:59 -08003156 struct skge_ring *ring = &skge->tx_ring;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003157 struct skge_element *e;
stephen hemmingerda057fb2012-01-22 09:40:40 +00003158 unsigned int bytes_compl = 0, pkts_compl = 0;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003159
Stephen Hemminger513f5332006-09-01 15:53:49 -07003160 skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F);
Stephen Hemminger00a6cae22006-03-21 10:56:59 -08003161
Stephen Hemminger866b4f32006-03-23 11:07:27 -08003162 for (e = ring->to_clean; e != ring->to_use; e = e->next) {
Stephen Hemminger992c9622007-03-16 14:01:30 -07003163 u32 control = ((const struct skge_tx_desc *) e->desc)->control;
Stephen Hemminger00a6cae22006-03-21 10:56:59 -08003164
Stephen Hemminger992c9622007-03-16 14:01:30 -07003165 if (control & BMU_OWN)
Stephen Hemminger00a6cae22006-03-21 10:56:59 -08003166 break;
3167
stephen hemmingerda057fb2012-01-22 09:40:40 +00003168 skge_tx_unmap(skge->hw->pdev, e, control);
3169
3170 if (control & BMU_EOF) {
3171 netif_printk(skge, tx_done, KERN_DEBUG, skge->netdev,
3172 "tx done slot %td\n",
3173 e - skge->tx_ring.start);
3174
3175 pkts_compl++;
3176 bytes_compl += e->skb->len;
3177
3178 dev_kfree_skb(e->skb);
3179 }
Stephen Hemminger00a6cae22006-03-21 10:56:59 -08003180 }
stephen hemmingerda057fb2012-01-22 09:40:40 +00003181 netdev_completed_queue(dev, pkts_compl, bytes_compl);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003182 skge->tx_ring.to_clean = e;
Stephen Hemminger866b4f32006-03-23 11:07:27 -08003183
Stephen Hemminger992c9622007-03-16 14:01:30 -07003184 /* Can run lockless until we need to synchronize to restart queue. */
3185 smp_mb();
Stephen Hemminger00a6cae22006-03-21 10:56:59 -08003186
Stephen Hemminger992c9622007-03-16 14:01:30 -07003187 if (unlikely(netif_queue_stopped(dev) &&
3188 skge_avail(&skge->tx_ring) > TX_LOW_WATER)) {
3189 netif_tx_lock(dev);
3190 if (unlikely(netif_queue_stopped(dev) &&
3191 skge_avail(&skge->tx_ring) > TX_LOW_WATER)) {
3192 netif_wake_queue(dev);
3193
3194 }
3195 netif_tx_unlock(dev);
3196 }
Stephen Hemminger00a6cae22006-03-21 10:56:59 -08003197}
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003198
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003199static int skge_poll(struct napi_struct *napi, int to_do)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003200{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003201 struct skge_port *skge = container_of(napi, struct skge_port, napi);
3202 struct net_device *dev = skge->netdev;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003203 struct skge_hw *hw = skge->hw;
3204 struct skge_ring *ring = &skge->rx_ring;
3205 struct skge_element *e;
Stephen Hemminger00a6cae22006-03-21 10:56:59 -08003206 int work_done = 0;
3207
Stephen Hemminger513f5332006-09-01 15:53:49 -07003208 skge_tx_done(dev);
3209
3210 skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F);
3211
Stephen Hemminger1631aef2005-11-08 10:33:44 -08003212 for (e = ring->to_clean; prefetch(e->next), work_done < to_do; e = e->next) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003213 struct skge_rx_desc *rd = e->desc;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003214 struct sk_buff *skb;
Stephen Hemminger383181a2005-09-19 15:37:16 -07003215 u32 control;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003216
3217 rmb();
3218 control = rd->control;
3219 if (control & BMU_OWN)
3220 break;
3221
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003222 skb = skge_rx_get(dev, e, control, rd->status, rd->csum2);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003223 if (likely(skb)) {
Eric Dumazet86cac582010-08-31 18:25:32 +00003224 napi_gro_receive(napi, skb);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003225 ++work_done;
Stephen Hemminger5a011442006-03-23 11:07:25 -08003226 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003227 }
3228 ring->to_clean = e;
3229
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003230 /* restart receiver */
3231 wmb();
Stephen Hemmingera9cdab82006-02-22 10:28:33 -08003232 skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_START);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003233
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003234 if (work_done < to_do) {
Marin Mitov6ef29772008-03-23 10:20:09 +02003235 unsigned long flags;
Jeff Garzikf0c88f92008-03-25 23:53:24 -04003236
Eric Dumazet86cac582010-08-31 18:25:32 +00003237 napi_gro_flush(napi);
Marin Mitov6ef29772008-03-23 10:20:09 +02003238 spin_lock_irqsave(&hw->hw_lock, flags);
Ben Hutchings288379f2009-01-19 16:43:59 -08003239 __napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003240 hw->intr_mask |= napimask[skge->port];
3241 skge_write32(hw, B0_IMSK, hw->intr_mask);
3242 skge_read32(hw, B0_IMSK);
Marin Mitov6ef29772008-03-23 10:20:09 +02003243 spin_unlock_irqrestore(&hw->hw_lock, flags);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003244 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003245
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003246 return work_done;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003247}
3248
Stephen Hemmingerf6620ca2005-07-22 16:26:02 -07003249/* Parity errors seem to happen when Genesis is connected to a switch
3250 * with no other ports present. Heartbeat error??
3251 */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003252static void skge_mac_parity(struct skge_hw *hw, int port)
3253{
Stephen Hemmingerf6620ca2005-07-22 16:26:02 -07003254 struct net_device *dev = hw->dev[port];
3255
Stephen Hemmingerda007722007-10-16 12:15:52 -07003256 ++dev->stats.tx_heartbeat_errors;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003257
stephen hemminger57d6fa32011-07-06 19:00:07 +00003258 if (is_genesis(hw))
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003259 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1),
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003260 MFF_CLR_PERR);
3261 else
3262 /* HW-Bug #8: cleared by GMF_CLI_TX_FC instead of GMF_CLI_TX_PE */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003263 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T),
Stephen Hemminger981d0372005-06-27 11:33:06 -07003264 (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003265 ? GMF_CLI_TX_FC : GMF_CLI_TX_PE);
3266}
3267
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003268static void skge_mac_intr(struct skge_hw *hw, int port)
3269{
stephen hemminger57d6fa32011-07-06 19:00:07 +00003270 if (is_genesis(hw))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003271 genesis_mac_intr(hw, port);
3272 else
3273 yukon_mac_intr(hw, port);
3274}
3275
3276/* Handle device specific framing and timeout interrupts */
3277static void skge_error_irq(struct skge_hw *hw)
3278{
Stephen Hemminger1479d132007-02-02 08:22:52 -08003279 struct pci_dev *pdev = hw->pdev;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003280 u32 hwstatus = skge_read32(hw, B0_HWE_ISRC);
3281
stephen hemminger57d6fa32011-07-06 19:00:07 +00003282 if (is_genesis(hw)) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003283 /* clear xmac errors */
3284 if (hwstatus & (IS_NO_STAT_M1|IS_NO_TIST_M1))
Stephen Hemminger46a60f22005-09-09 12:54:56 -07003285 skge_write16(hw, RX_MFF_CTRL1, MFF_CLR_INSTAT);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003286 if (hwstatus & (IS_NO_STAT_M2|IS_NO_TIST_M2))
Stephen Hemminger46a60f22005-09-09 12:54:56 -07003287 skge_write16(hw, RX_MFF_CTRL2, MFF_CLR_INSTAT);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003288 } else {
3289 /* Timestamp (unused) overflow */
3290 if (hwstatus & IS_IRQ_TIST_OV)
3291 skge_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003292 }
3293
3294 if (hwstatus & IS_RAM_RD_PAR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003295 dev_err(&pdev->dev, "Ram read data parity error\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003296 skge_write16(hw, B3_RI_CTRL, RI_CLR_RD_PERR);
3297 }
3298
3299 if (hwstatus & IS_RAM_WR_PAR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003300 dev_err(&pdev->dev, "Ram write data parity error\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003301 skge_write16(hw, B3_RI_CTRL, RI_CLR_WR_PERR);
3302 }
3303
3304 if (hwstatus & IS_M1_PAR_ERR)
3305 skge_mac_parity(hw, 0);
3306
3307 if (hwstatus & IS_M2_PAR_ERR)
3308 skge_mac_parity(hw, 1);
3309
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003310 if (hwstatus & IS_R1_PAR_ERR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003311 dev_err(&pdev->dev, "%s: receive queue parity error\n",
3312 hw->dev[0]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003313 skge_write32(hw, B0_R1_CSR, CSR_IRQ_CL_P);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003314 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003315
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003316 if (hwstatus & IS_R2_PAR_ERR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003317 dev_err(&pdev->dev, "%s: receive queue parity error\n",
3318 hw->dev[1]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003319 skge_write32(hw, B0_R2_CSR, CSR_IRQ_CL_P);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003320 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003321
3322 if (hwstatus & (IS_IRQ_MST_ERR|IS_IRQ_STAT)) {
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003323 u16 pci_status, pci_cmd;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003324
Stephen Hemminger1479d132007-02-02 08:22:52 -08003325 pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
3326 pci_read_config_word(pdev, PCI_STATUS, &pci_status);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003327
Stephen Hemminger1479d132007-02-02 08:22:52 -08003328 dev_err(&pdev->dev, "PCI error cmd=%#x status=%#x\n",
3329 pci_cmd, pci_status);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003330
3331 /* Write the error bits back to clear them. */
3332 pci_status &= PCI_STATUS_ERROR_BITS;
3333 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
Stephen Hemminger1479d132007-02-02 08:22:52 -08003334 pci_write_config_word(pdev, PCI_COMMAND,
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003335 pci_cmd | PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
Stephen Hemminger1479d132007-02-02 08:22:52 -08003336 pci_write_config_word(pdev, PCI_STATUS, pci_status);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003337 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003338
Stephen Hemminger050ec182005-08-16 14:00:54 -07003339 /* if error still set then just ignore it */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003340 hwstatus = skge_read32(hw, B0_HWE_ISRC);
3341 if (hwstatus & IS_IRQ_STAT) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003342 dev_warn(&hw->pdev->dev, "unable to clear error (so ignoring them)\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003343 hw->intr_mask &= ~IS_HW_ERR;
3344 }
3345 }
3346}
3347
3348/*
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003349 * Interrupt from PHY are handled in tasklet (softirq)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003350 * because accessing phy registers requires spin wait which might
3351 * cause excess interrupt latency.
3352 */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003353static void skge_extirq(unsigned long arg)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003354{
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003355 struct skge_hw *hw = (struct skge_hw *) arg;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003356 int port;
3357
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003358 for (port = 0; port < hw->ports; port++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003359 struct net_device *dev = hw->dev[port];
3360
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003361 if (netif_running(dev)) {
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003362 struct skge_port *skge = netdev_priv(dev);
3363
3364 spin_lock(&hw->phy_lock);
stephen hemminger57d6fa32011-07-06 19:00:07 +00003365 if (!is_genesis(hw))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003366 yukon_phy_intr(skge);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003367 else if (hw->phy_type == SK_PHY_BCOM)
Stephen Hemminger45bada62005-06-27 11:33:12 -07003368 bcom_phy_intr(skge);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003369 spin_unlock(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003370 }
3371 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003372
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003373 spin_lock_irq(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003374 hw->intr_mask |= IS_EXT_REG;
3375 skge_write32(hw, B0_IMSK, hw->intr_mask);
Stephen Hemminger78bc2182006-08-28 16:19:36 -07003376 skge_read32(hw, B0_IMSK);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003377 spin_unlock_irq(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003378}
3379
David Howells7d12e782006-10-05 14:55:46 +01003380static irqreturn_t skge_intr(int irq, void *dev_id)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003381{
3382 struct skge_hw *hw = dev_id;
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003383 u32 status;
Stephen Hemminger29365c92006-09-01 15:53:48 -07003384 int handled = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003385
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003386 spin_lock(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003387 /* Reading this register masks IRQ */
3388 status = skge_read32(hw, B0_SP_ISRC);
Stephen Hemminger0486a8c2006-09-06 11:06:10 -07003389 if (status == 0 || status == ~0)
Stephen Hemminger29365c92006-09-01 15:53:48 -07003390 goto out;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003391
Stephen Hemminger29365c92006-09-01 15:53:48 -07003392 handled = 1;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003393 status &= hw->intr_mask;
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003394 if (status & IS_EXT_REG) {
3395 hw->intr_mask &= ~IS_EXT_REG;
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003396 tasklet_schedule(&hw->phy_task);
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003397 }
3398
Stephen Hemminger513f5332006-09-01 15:53:49 -07003399 if (status & (IS_XA1_F|IS_R1_F)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003400 struct skge_port *skge = netdev_priv(hw->dev[0]);
Stephen Hemminger513f5332006-09-01 15:53:49 -07003401 hw->intr_mask &= ~(IS_XA1_F|IS_R1_F);
Ben Hutchings288379f2009-01-19 16:43:59 -08003402 napi_schedule(&skge->napi);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003403 }
3404
Stephen Hemmingerd25f5a62005-06-27 11:33:14 -07003405 if (status & IS_PA_TO_TX1)
3406 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX1);
3407
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003408 if (status & IS_PA_TO_RX1) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07003409 ++hw->dev[0]->stats.rx_over_errors;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003410 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX1);
3411 }
3412
Stephen Hemmingerd25f5a62005-06-27 11:33:14 -07003413
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003414 if (status & IS_MAC1)
3415 skge_mac_intr(hw, 0);
Stephen Hemminger95566062005-06-27 11:33:02 -07003416
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003417 if (hw->dev[1]) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003418 struct skge_port *skge = netdev_priv(hw->dev[1]);
3419
Stephen Hemminger513f5332006-09-01 15:53:49 -07003420 if (status & (IS_XA2_F|IS_R2_F)) {
3421 hw->intr_mask &= ~(IS_XA2_F|IS_R2_F);
Ben Hutchings288379f2009-01-19 16:43:59 -08003422 napi_schedule(&skge->napi);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003423 }
3424
3425 if (status & IS_PA_TO_RX2) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07003426 ++hw->dev[1]->stats.rx_over_errors;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003427 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX2);
3428 }
3429
3430 if (status & IS_PA_TO_TX2)
3431 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX2);
3432
3433 if (status & IS_MAC2)
3434 skge_mac_intr(hw, 1);
3435 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003436
3437 if (status & IS_HW_ERR)
3438 skge_error_irq(hw);
3439
Stephen Hemminger7e676d92005-06-27 11:33:13 -07003440 skge_write32(hw, B0_IMSK, hw->intr_mask);
Stephen Hemminger78bc2182006-08-28 16:19:36 -07003441 skge_read32(hw, B0_IMSK);
Stephen Hemminger29365c92006-09-01 15:53:48 -07003442out:
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003443 spin_unlock(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003444
Stephen Hemminger29365c92006-09-01 15:53:48 -07003445 return IRQ_RETVAL(handled);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003446}
3447
3448#ifdef CONFIG_NET_POLL_CONTROLLER
3449static void skge_netpoll(struct net_device *dev)
3450{
3451 struct skge_port *skge = netdev_priv(dev);
3452
3453 disable_irq(dev->irq);
David Howells7d12e782006-10-05 14:55:46 +01003454 skge_intr(dev->irq, skge->hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003455 enable_irq(dev->irq);
3456}
3457#endif
3458
3459static int skge_set_mac_address(struct net_device *dev, void *p)
3460{
3461 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerc2681dd2005-10-03 12:03:13 -07003462 struct skge_hw *hw = skge->hw;
3463 unsigned port = skge->port;
3464 const struct sockaddr *addr = p;
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003465 u16 ctrl;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003466
3467 if (!is_valid_ether_addr(addr->sa_data))
3468 return -EADDRNOTAVAIL;
3469
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003470 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
Stephen Hemmingerc2681dd2005-10-03 12:03:13 -07003471
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003472 if (!netif_running(dev)) {
3473 memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN);
3474 memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN);
3475 } else {
3476 /* disable Rx */
3477 spin_lock_bh(&hw->phy_lock);
3478 ctrl = gma_read16(hw, port, GM_GP_CTRL);
3479 gma_write16(hw, port, GM_GP_CTRL, ctrl & ~GM_GPCR_RX_ENA);
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003480
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003481 memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN);
3482 memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN);
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003483
stephen hemminger57d6fa32011-07-06 19:00:07 +00003484 if (is_genesis(hw))
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003485 xm_outaddr(hw, port, XM_SA, dev->dev_addr);
3486 else {
3487 gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr);
3488 gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr);
3489 }
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003490
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003491 gma_write16(hw, port, GM_GP_CTRL, ctrl);
3492 spin_unlock_bh(&hw->phy_lock);
3493 }
Stephen Hemmingerc2681dd2005-10-03 12:03:13 -07003494
3495 return 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003496}
3497
3498static const struct {
3499 u8 id;
3500 const char *name;
3501} skge_chips[] = {
3502 { CHIP_ID_GENESIS, "Genesis" },
3503 { CHIP_ID_YUKON, "Yukon" },
3504 { CHIP_ID_YUKON_LITE, "Yukon-Lite"},
3505 { CHIP_ID_YUKON_LP, "Yukon-LP"},
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003506};
3507
3508static const char *skge_board_name(const struct skge_hw *hw)
3509{
3510 int i;
3511 static char buf[16];
3512
3513 for (i = 0; i < ARRAY_SIZE(skge_chips); i++)
3514 if (skge_chips[i].id == hw->chip_id)
3515 return skge_chips[i].name;
3516
3517 snprintf(buf, sizeof buf, "chipid 0x%x", hw->chip_id);
3518 return buf;
3519}
3520
3521
3522/*
3523 * Setup the board data structure, but don't bring up
3524 * the port(s)
3525 */
3526static int skge_reset(struct skge_hw *hw)
3527{
Stephen Hemmingeradba9e22005-11-08 10:33:40 -08003528 u32 reg;
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003529 u16 ctst, pci_status;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003530 u8 t8, mac_cfg, pmd_type;
Stephen Hemminger981d0372005-06-27 11:33:06 -07003531 int i;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003532
3533 ctst = skge_read16(hw, B0_CTST);
3534
3535 /* do a SW reset */
3536 skge_write8(hw, B0_CTST, CS_RST_SET);
3537 skge_write8(hw, B0_CTST, CS_RST_CLR);
3538
3539 /* clear PCI errors, if any */
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003540 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
3541 skge_write8(hw, B2_TST_CTRL2, 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003542
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003543 pci_read_config_word(hw->pdev, PCI_STATUS, &pci_status);
3544 pci_write_config_word(hw->pdev, PCI_STATUS,
3545 pci_status | PCI_STATUS_ERROR_BITS);
3546 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003547 skge_write8(hw, B0_CTST, CS_MRST_CLR);
3548
3549 /* restore CLK_RUN bits (for Yukon-Lite) */
3550 skge_write16(hw, B0_CTST,
3551 ctst & (CS_CLK_RUN_HOT|CS_CLK_RUN_RST|CS_CLK_RUN_ENA));
3552
3553 hw->chip_id = skge_read8(hw, B2_CHIP_ID);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003554 hw->phy_type = skge_read8(hw, B2_E_1) & 0xf;
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07003555 pmd_type = skge_read8(hw, B2_PMD_TYP);
3556 hw->copper = (pmd_type == 'T' || pmd_type == '1');
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003557
Stephen Hemminger95566062005-06-27 11:33:02 -07003558 switch (hw->chip_id) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003559 case CHIP_ID_GENESIS:
stephen hemminger57d6fa32011-07-06 19:00:07 +00003560#ifdef CONFIG_SKGE_GENESIS
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003561 switch (hw->phy_type) {
3562 case SK_PHY_XMAC:
3563 hw->phy_addr = PHY_ADDR_XMAC;
3564 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003565 case SK_PHY_BCOM:
3566 hw->phy_addr = PHY_ADDR_BCOM;
3567 break;
3568 default:
Stephen Hemminger1479d132007-02-02 08:22:52 -08003569 dev_err(&hw->pdev->dev, "unsupported phy type 0x%x\n",
3570 hw->phy_type);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003571 return -EOPNOTSUPP;
3572 }
3573 break;
stephen hemminger57d6fa32011-07-06 19:00:07 +00003574#else
3575 dev_err(&hw->pdev->dev, "Genesis chip detected but not configured\n");
3576 return -EOPNOTSUPP;
3577#endif
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003578
3579 case CHIP_ID_YUKON:
3580 case CHIP_ID_YUKON_LITE:
3581 case CHIP_ID_YUKON_LP:
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003582 if (hw->phy_type < SK_PHY_MARV_COPPER && pmd_type != 'S')
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07003583 hw->copper = 1;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003584
3585 hw->phy_addr = PHY_ADDR_MARV;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003586 break;
3587
3588 default:
Stephen Hemminger1479d132007-02-02 08:22:52 -08003589 dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n",
3590 hw->chip_id);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003591 return -EOPNOTSUPP;
3592 }
3593
Stephen Hemminger981d0372005-06-27 11:33:06 -07003594 mac_cfg = skge_read8(hw, B2_MAC_CFG);
3595 hw->ports = (mac_cfg & CFG_SNG_MAC) ? 1 : 2;
3596 hw->chip_rev = (mac_cfg & CFG_CHIP_R_MSK) >> 4;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003597
3598 /* read the adapters RAM size */
3599 t8 = skge_read8(hw, B2_E_0);
stephen hemminger57d6fa32011-07-06 19:00:07 +00003600 if (is_genesis(hw)) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003601 if (t8 == 3) {
3602 /* special case: 4 x 64k x 36, offset = 0x80000 */
Linus Torvalds279e1da2007-11-15 08:44:36 -08003603 hw->ram_size = 0x100000;
3604 hw->ram_offset = 0x80000;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003605 } else
3606 hw->ram_size = t8 * 512;
Joe Perches67777f92010-02-17 15:01:58 +00003607 } else if (t8 == 0)
Linus Torvalds279e1da2007-11-15 08:44:36 -08003608 hw->ram_size = 0x20000;
3609 else
3610 hw->ram_size = t8 * 4096;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003611
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07003612 hw->intr_mask = IS_HW_ERR;
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003613
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07003614 /* Use PHY IRQ for all but fiber based Genesis board */
stephen hemminger57d6fa32011-07-06 19:00:07 +00003615 if (!(is_genesis(hw) && hw->phy_type == SK_PHY_XMAC))
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003616 hw->intr_mask |= IS_EXT_REG;
3617
stephen hemminger57d6fa32011-07-06 19:00:07 +00003618 if (is_genesis(hw))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003619 genesis_init(hw);
3620 else {
3621 /* switch power to VCC (WA for VAUX problem) */
3622 skge_write8(hw, B0_POWER_CTRL,
3623 PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
Stephen Hemmingeradba9e22005-11-08 10:33:40 -08003624
Stephen Hemminger050ec182005-08-16 14:00:54 -07003625 /* avoid boards with stuck Hardware error bits */
3626 if ((skge_read32(hw, B0_ISRC) & IS_HW_ERR) &&
3627 (skge_read32(hw, B0_HWE_ISRC) & IS_IRQ_SENSOR)) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003628 dev_warn(&hw->pdev->dev, "stuck hardware sensor bit\n");
Stephen Hemminger050ec182005-08-16 14:00:54 -07003629 hw->intr_mask &= ~IS_HW_ERR;
3630 }
3631
Stephen Hemmingeradba9e22005-11-08 10:33:40 -08003632 /* Clear PHY COMA */
3633 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
3634 pci_read_config_dword(hw->pdev, PCI_DEV_REG1, &reg);
3635 reg &= ~PCI_PHY_COMA;
3636 pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg);
3637 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
3638
3639
Stephen Hemminger981d0372005-06-27 11:33:06 -07003640 for (i = 0; i < hw->ports; i++) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003641 skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
3642 skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003643 }
3644 }
3645
3646 /* turn off hardware timer (unused) */
3647 skge_write8(hw, B2_TI_CTRL, TIM_STOP);
3648 skge_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ);
3649 skge_write8(hw, B0_LED, LED_STAT_ON);
3650
3651 /* enable the Tx Arbiters */
Stephen Hemminger981d0372005-06-27 11:33:06 -07003652 for (i = 0; i < hw->ports; i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003653 skge_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003654
3655 /* Initialize ram interface */
3656 skge_write16(hw, B3_RI_CTRL, RI_RST_CLR);
3657
3658 skge_write8(hw, B3_RI_WTO_R1, SK_RI_TO_53);
3659 skge_write8(hw, B3_RI_WTO_XA1, SK_RI_TO_53);
3660 skge_write8(hw, B3_RI_WTO_XS1, SK_RI_TO_53);
3661 skge_write8(hw, B3_RI_RTO_R1, SK_RI_TO_53);
3662 skge_write8(hw, B3_RI_RTO_XA1, SK_RI_TO_53);
3663 skge_write8(hw, B3_RI_RTO_XS1, SK_RI_TO_53);
3664 skge_write8(hw, B3_RI_WTO_R2, SK_RI_TO_53);
3665 skge_write8(hw, B3_RI_WTO_XA2, SK_RI_TO_53);
3666 skge_write8(hw, B3_RI_WTO_XS2, SK_RI_TO_53);
3667 skge_write8(hw, B3_RI_RTO_R2, SK_RI_TO_53);
3668 skge_write8(hw, B3_RI_RTO_XA2, SK_RI_TO_53);
3669 skge_write8(hw, B3_RI_RTO_XS2, SK_RI_TO_53);
3670
3671 skge_write32(hw, B0_HWE_IMSK, IS_ERR_MSK);
3672
3673 /* Set interrupt moderation for Transmit only
3674 * Receive interrupts avoided by NAPI
3675 */
3676 skge_write32(hw, B2_IRQM_MSK, IS_XA1_F|IS_XA2_F);
3677 skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, 100));
3678 skge_write32(hw, B2_IRQM_CTRL, TIM_START);
3679
Stephen Hemmingera9e9fd72011-09-27 13:41:37 -04003680 /* Leave irq disabled until first port is brought up. */
3681 skge_write32(hw, B0_IMSK, 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003682
Stephen Hemminger981d0372005-06-27 11:33:06 -07003683 for (i = 0; i < hw->ports; i++) {
stephen hemminger57d6fa32011-07-06 19:00:07 +00003684 if (is_genesis(hw))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003685 genesis_reset(hw, i);
3686 else
3687 yukon_reset(hw, i);
3688 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003689
3690 return 0;
3691}
3692
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003693
3694#ifdef CONFIG_SKGE_DEBUG
3695
3696static struct dentry *skge_debug;
3697
3698static int skge_debug_show(struct seq_file *seq, void *v)
3699{
3700 struct net_device *dev = seq->private;
3701 const struct skge_port *skge = netdev_priv(dev);
3702 const struct skge_hw *hw = skge->hw;
3703 const struct skge_element *e;
3704
3705 if (!netif_running(dev))
3706 return -ENETDOWN;
3707
3708 seq_printf(seq, "IRQ src=%x mask=%x\n", skge_read32(hw, B0_ISRC),
3709 skge_read32(hw, B0_IMSK));
3710
3711 seq_printf(seq, "Tx Ring: (%d)\n", skge_avail(&skge->tx_ring));
3712 for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) {
3713 const struct skge_tx_desc *t = e->desc;
3714 seq_printf(seq, "%#x dma=%#x%08x %#x csum=%#x/%x/%x\n",
3715 t->control, t->dma_hi, t->dma_lo, t->status,
3716 t->csum_offs, t->csum_write, t->csum_start);
3717 }
3718
Frans Pop2381a552010-03-24 07:57:36 +00003719 seq_printf(seq, "\nRx Ring:\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003720 for (e = skge->rx_ring.to_clean; ; e = e->next) {
3721 const struct skge_rx_desc *r = e->desc;
3722
3723 if (r->control & BMU_OWN)
3724 break;
3725
3726 seq_printf(seq, "%#x dma=%#x%08x %#x %#x csum=%#x/%x\n",
3727 r->control, r->dma_hi, r->dma_lo, r->status,
3728 r->timestamp, r->csum1, r->csum1_start);
3729 }
3730
3731 return 0;
3732}
3733
3734static int skge_debug_open(struct inode *inode, struct file *file)
3735{
3736 return single_open(file, skge_debug_show, inode->i_private);
3737}
3738
3739static const struct file_operations skge_debug_fops = {
3740 .owner = THIS_MODULE,
3741 .open = skge_debug_open,
3742 .read = seq_read,
3743 .llseek = seq_lseek,
3744 .release = single_release,
3745};
3746
3747/*
3748 * Use network device events to create/remove/rename
3749 * debugfs file entries
3750 */
3751static int skge_device_event(struct notifier_block *unused,
3752 unsigned long event, void *ptr)
3753{
3754 struct net_device *dev = ptr;
3755 struct skge_port *skge;
3756 struct dentry *d;
3757
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003758 if (dev->netdev_ops->ndo_open != &skge_up || !skge_debug)
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003759 goto done;
3760
3761 skge = netdev_priv(dev);
Joe Perches67777f92010-02-17 15:01:58 +00003762 switch (event) {
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003763 case NETDEV_CHANGENAME:
3764 if (skge->debugfs) {
3765 d = debugfs_rename(skge_debug, skge->debugfs,
3766 skge_debug, dev->name);
3767 if (d)
3768 skge->debugfs = d;
3769 else {
Joe Perchesf15063c2010-02-17 15:01:57 +00003770 netdev_info(dev, "rename failed\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003771 debugfs_remove(skge->debugfs);
3772 }
3773 }
3774 break;
3775
3776 case NETDEV_GOING_DOWN:
3777 if (skge->debugfs) {
3778 debugfs_remove(skge->debugfs);
3779 skge->debugfs = NULL;
3780 }
3781 break;
3782
3783 case NETDEV_UP:
3784 d = debugfs_create_file(dev->name, S_IRUGO,
3785 skge_debug, dev,
3786 &skge_debug_fops);
3787 if (!d || IS_ERR(d))
Joe Perchesf15063c2010-02-17 15:01:57 +00003788 netdev_info(dev, "debugfs create failed\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003789 else
3790 skge->debugfs = d;
3791 break;
3792 }
3793
3794done:
3795 return NOTIFY_DONE;
3796}
3797
3798static struct notifier_block skge_notifier = {
3799 .notifier_call = skge_device_event,
3800};
3801
3802
3803static __init void skge_debug_init(void)
3804{
3805 struct dentry *ent;
3806
3807 ent = debugfs_create_dir("skge", NULL);
3808 if (!ent || IS_ERR(ent)) {
Joe Perchesf15063c2010-02-17 15:01:57 +00003809 pr_info("debugfs create directory failed\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003810 return;
3811 }
3812
3813 skge_debug = ent;
3814 register_netdevice_notifier(&skge_notifier);
3815}
3816
3817static __exit void skge_debug_cleanup(void)
3818{
3819 if (skge_debug) {
3820 unregister_netdevice_notifier(&skge_notifier);
3821 debugfs_remove(skge_debug);
3822 skge_debug = NULL;
3823 }
3824}
3825
3826#else
3827#define skge_debug_init()
3828#define skge_debug_cleanup()
3829#endif
3830
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003831static const struct net_device_ops skge_netdev_ops = {
3832 .ndo_open = skge_up,
3833 .ndo_stop = skge_down,
Stephen Hemminger00829822008-11-20 20:14:53 -08003834 .ndo_start_xmit = skge_xmit_frame,
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003835 .ndo_do_ioctl = skge_ioctl,
3836 .ndo_get_stats = skge_get_stats,
3837 .ndo_tx_timeout = skge_tx_timeout,
3838 .ndo_change_mtu = skge_change_mtu,
3839 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003840 .ndo_set_rx_mode = skge_set_multicast,
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003841 .ndo_set_mac_address = skge_set_mac_address,
3842#ifdef CONFIG_NET_POLL_CONTROLLER
3843 .ndo_poll_controller = skge_netpoll,
3844#endif
3845};
3846
3847
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003848/* Initialize network device */
Stephen Hemminger981d0372005-06-27 11:33:06 -07003849static struct net_device *skge_devinit(struct skge_hw *hw, int port,
3850 int highmem)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003851{
3852 struct skge_port *skge;
3853 struct net_device *dev = alloc_etherdev(sizeof(*skge));
3854
3855 if (!dev) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003856 dev_err(&hw->pdev->dev, "etherdev alloc failed\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003857 return NULL;
3858 }
3859
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003860 SET_NETDEV_DEV(dev, &hw->pdev->dev);
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003861 dev->netdev_ops = &skge_netdev_ops;
3862 dev->ethtool_ops = &skge_ethtool_ops;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003863 dev->watchdog_timeo = TX_WATCHDOG;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003864 dev->irq = hw->pdev->irq;
Stephen Hemminger513f5332006-09-01 15:53:49 -07003865
Stephen Hemminger981d0372005-06-27 11:33:06 -07003866 if (highmem)
3867 dev->features |= NETIF_F_HIGHDMA;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003868
3869 skge = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003870 netif_napi_add(dev, &skge->napi, skge_poll, NAPI_WEIGHT);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003871 skge->netdev = dev;
3872 skge->hw = hw;
3873 skge->msg_enable = netif_msg_init(debug, default_msg);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003874
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003875 skge->tx_ring.count = DEFAULT_TX_RING_SIZE;
3876 skge->rx_ring.count = DEFAULT_RX_RING_SIZE;
3877
3878 /* Auto speed and flow control */
3879 skge->autoneg = AUTONEG_ENABLE;
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07003880 skge->flow_control = FLOW_MODE_SYM_OR_REM;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003881 skge->duplex = -1;
3882 skge->speed = -1;
Stephen Hemminger31b619c2005-06-27 11:33:11 -07003883 skge->advertising = skge_supported_modes(hw);
Stephen Hemminger5b982c52007-05-08 13:36:20 -07003884
Rafael J. Wysocki7b55a4a2009-07-22 02:58:55 +00003885 if (device_can_wakeup(&hw->pdev->dev)) {
Stephen Hemminger5b982c52007-05-08 13:36:20 -07003886 skge->wol = wol_supported(hw) & WAKE_MAGIC;
Rafael J. Wysocki7b55a4a2009-07-22 02:58:55 +00003887 device_set_wakeup_enable(&hw->pdev->dev, skge->wol);
3888 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003889
3890 hw->dev[port] = dev;
3891
3892 skge->port = port;
3893
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003894 /* Only used for Genesis XMAC */
stephen hemminger57d6fa32011-07-06 19:00:07 +00003895 if (is_genesis(hw))
3896 setup_timer(&skge->link_timer, xm_link_timer, (unsigned long) skge);
3897 else {
Michał Mirosławe92702b2011-03-31 01:01:35 +00003898 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
3899 NETIF_F_RXCSUM;
3900 dev->features |= dev->hw_features;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003901 }
3902
3903 /* read the mac address */
3904 memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port*8, ETH_ALEN);
John W. Linville56230d52005-09-12 10:48:57 -04003905 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003906
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003907 return dev;
3908}
3909
3910static void __devinit skge_show_addr(struct net_device *dev)
3911{
3912 const struct skge_port *skge = netdev_priv(dev);
3913
Joe Perchesd7072042010-02-09 11:49:53 +00003914 netif_info(skge, probe, skge->netdev, "addr %pM\n", dev->dev_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003915}
3916
Stanislaw Gruszka392bd0c2010-10-05 15:11:40 -07003917static int only_32bit_dma;
3918
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003919static int __devinit skge_probe(struct pci_dev *pdev,
3920 const struct pci_device_id *ent)
3921{
3922 struct net_device *dev, *dev1;
3923 struct skge_hw *hw;
3924 int err, using_dac = 0;
3925
Stephen Hemminger203babb2006-03-21 10:57:05 -08003926 err = pci_enable_device(pdev);
3927 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003928 dev_err(&pdev->dev, "cannot enable PCI device\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003929 goto err_out;
3930 }
3931
Stephen Hemminger203babb2006-03-21 10:57:05 -08003932 err = pci_request_regions(pdev, DRV_NAME);
3933 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003934 dev_err(&pdev->dev, "cannot obtain PCI resources\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003935 goto err_out_disable_pdev;
3936 }
3937
3938 pci_set_master(pdev);
3939
Stanislaw Gruszka392bd0c2010-10-05 15:11:40 -07003940 if (!only_32bit_dma && !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003941 using_dac = 1;
Yang Hongyang6a355282009-04-06 19:01:13 -07003942 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
Yang Hongyang284901a2009-04-06 19:01:15 -07003943 } else if (!(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))) {
Stephen Hemminger93aea712006-03-21 10:57:02 -08003944 using_dac = 0;
Yang Hongyang284901a2009-04-06 19:01:15 -07003945 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Stephen Hemminger93aea712006-03-21 10:57:02 -08003946 }
3947
3948 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003949 dev_err(&pdev->dev, "no usable DMA configuration\n");
Stephen Hemminger93aea712006-03-21 10:57:02 -08003950 goto err_out_free_regions;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003951 }
3952
3953#ifdef __BIG_ENDIAN
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08003954 /* byte swap descriptors in hardware */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003955 {
3956 u32 reg;
3957
3958 pci_read_config_dword(pdev, PCI_DEV_REG2, &reg);
3959 reg |= PCI_REV_DESC;
3960 pci_write_config_dword(pdev, PCI_DEV_REG2, reg);
3961 }
3962#endif
3963
3964 err = -ENOMEM;
Michal Schmidt415e69e2009-10-01 08:13:23 +00003965 /* space for skge@pci:0000:04:00.0 */
Joe Perches67777f92010-02-17 15:01:58 +00003966 hw = kzalloc(sizeof(*hw) + strlen(DRV_NAME "@pci:")
Michal Schmidt415e69e2009-10-01 08:13:23 +00003967 + strlen(pci_name(pdev)) + 1, GFP_KERNEL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003968 if (!hw) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003969 dev_err(&pdev->dev, "cannot allocate hardware struct\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003970 goto err_out_free_regions;
3971 }
Michal Schmidt415e69e2009-10-01 08:13:23 +00003972 sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003973
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003974 hw->pdev = pdev;
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07003975 spin_lock_init(&hw->hw_lock);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003976 spin_lock_init(&hw->phy_lock);
Joe Perches164165d2009-11-19 09:30:10 +00003977 tasklet_init(&hw->phy_task, skge_extirq, (unsigned long) hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003978
3979 hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
3980 if (!hw->regs) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003981 dev_err(&pdev->dev, "cannot map device registers\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003982 goto err_out_free_hw;
3983 }
3984
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003985 err = skge_reset(hw);
3986 if (err)
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003987 goto err_out_iounmap;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003988
Joe Perchesf15063c2010-02-17 15:01:57 +00003989 pr_info("%s addr 0x%llx irq %d chip %s rev %d\n",
3990 DRV_VERSION,
3991 (unsigned long long)pci_resource_start(pdev, 0), pdev->irq,
3992 skge_board_name(hw), hw->chip_rev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003993
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003994 dev = skge_devinit(hw, 0, using_dac);
3995 if (!dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003996 goto err_out_led_off;
3997
Stephen Hemmingerfae87592007-02-02 08:22:51 -08003998 /* Some motherboards are broken and has zero in ROM. */
Stephen Hemminger1479d132007-02-02 08:22:52 -08003999 if (!is_valid_ether_addr(dev->dev_addr))
4000 dev_warn(&pdev->dev, "bad (zero?) ethernet address in rom\n");
Stephen Hemminger631ae322006-06-06 10:11:14 -07004001
Stephen Hemminger203babb2006-03-21 10:57:05 -08004002 err = register_netdev(dev);
4003 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08004004 dev_err(&pdev->dev, "cannot register net device\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004005 goto err_out_free_netdev;
4006 }
4007
4008 skge_show_addr(dev);
4009
Mike McCormackf1914222009-09-23 03:50:36 +00004010 if (hw->ports > 1) {
4011 dev1 = skge_devinit(hw, 1, using_dac);
Stephen Hemmingera9e9fd72011-09-27 13:41:37 -04004012 if (!dev1) {
4013 err = -ENOMEM;
4014 goto err_out_unregister;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004015 }
Stephen Hemmingera9e9fd72011-09-27 13:41:37 -04004016
4017 err = register_netdev(dev1);
4018 if (err) {
4019 dev_err(&pdev->dev, "cannot register second net device\n");
4020 goto err_out_free_dev1;
4021 }
4022
4023 err = request_irq(pdev->irq, skge_intr, IRQF_SHARED,
4024 hw->irq_name, hw);
4025 if (err) {
4026 dev_err(&pdev->dev, "cannot assign irq %d\n",
4027 pdev->irq);
4028 goto err_out_unregister_dev1;
4029 }
4030
4031 skge_show_addr(dev1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004032 }
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07004033 pci_set_drvdata(pdev, hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004034
4035 return 0;
4036
Stephen Hemmingera9e9fd72011-09-27 13:41:37 -04004037err_out_unregister_dev1:
4038 unregister_netdev(dev1);
4039err_out_free_dev1:
4040 free_netdev(dev1);
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07004041err_out_unregister:
4042 unregister_netdev(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004043err_out_free_netdev:
4044 free_netdev(dev);
4045err_out_led_off:
4046 skge_write16(hw, B0_LED, LED_STAT_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004047err_out_iounmap:
4048 iounmap(hw->regs);
4049err_out_free_hw:
4050 kfree(hw);
4051err_out_free_regions:
4052 pci_release_regions(pdev);
4053err_out_disable_pdev:
4054 pci_disable_device(pdev);
4055 pci_set_drvdata(pdev, NULL);
4056err_out:
4057 return err;
4058}
4059
4060static void __devexit skge_remove(struct pci_dev *pdev)
4061{
4062 struct skge_hw *hw = pci_get_drvdata(pdev);
4063 struct net_device *dev0, *dev1;
4064
Stephen Hemminger95566062005-06-27 11:33:02 -07004065 if (!hw)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004066 return;
4067
Joe Perches67777f92010-02-17 15:01:58 +00004068 dev1 = hw->dev[1];
4069 if (dev1)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004070 unregister_netdev(dev1);
4071 dev0 = hw->dev[0];
4072 unregister_netdev(dev0);
4073
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07004074 tasklet_disable(&hw->phy_task);
4075
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07004076 spin_lock_irq(&hw->hw_lock);
4077 hw->intr_mask = 0;
Stephen Hemmingera9e9fd72011-09-27 13:41:37 -04004078
4079 if (hw->ports > 1) {
4080 skge_write32(hw, B0_IMSK, 0);
4081 skge_read32(hw, B0_IMSK);
4082 free_irq(pdev->irq, hw);
4083 }
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07004084 spin_unlock_irq(&hw->hw_lock);
4085
Stephen Hemminger46a60f22005-09-09 12:54:56 -07004086 skge_write16(hw, B0_LED, LED_STAT_OFF);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07004087 skge_write8(hw, B0_CTST, CS_RST_SET);
4088
Stephen Hemmingera9e9fd72011-09-27 13:41:37 -04004089 if (hw->ports > 1)
4090 free_irq(pdev->irq, hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004091 pci_release_regions(pdev);
4092 pci_disable_device(pdev);
4093 if (dev1)
4094 free_netdev(dev1);
4095 free_netdev(dev0);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07004096
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004097 iounmap(hw->regs);
4098 kfree(hw);
4099 pci_set_drvdata(pdev, NULL);
4100}
4101
Daniel Halperinfaa85aa2012-01-03 13:53:16 -05004102#ifdef CONFIG_PM_SLEEP
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004103static int skge_suspend(struct device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004104{
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004105 struct pci_dev *pdev = to_pci_dev(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004106 struct skge_hw *hw = pci_get_drvdata(pdev);
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004107 int i;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004108
Stephen Hemmingere3b7df12007-05-11 11:21:45 -07004109 if (!hw)
4110 return 0;
4111
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004112 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004113 struct net_device *dev = hw->dev[i];
Stephen Hemmingera504e642007-02-02 08:22:53 -08004114 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004115
Stephen Hemmingera504e642007-02-02 08:22:53 -08004116 if (netif_running(dev))
4117 skge_down(dev);
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004118
Stephen Hemmingera504e642007-02-02 08:22:53 -08004119 if (skge->wol)
4120 skge_wol_init(skge);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004121 }
4122
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004123 skge_write32(hw, B0_IMSK, 0);
Rafael J. Wysocki5177b322008-10-29 14:22:14 -07004124
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004125 return 0;
4126}
4127
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004128static int skge_resume(struct device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004129{
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004130 struct pci_dev *pdev = to_pci_dev(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004131 struct skge_hw *hw = pci_get_drvdata(pdev);
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004132 int i, err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004133
Stephen Hemmingere3b7df12007-05-11 11:21:45 -07004134 if (!hw)
4135 return 0;
4136
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004137 err = skge_reset(hw);
4138 if (err)
4139 goto out;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004140
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004141 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004142 struct net_device *dev = hw->dev[i];
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004143
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004144 if (netif_running(dev)) {
4145 err = skge_up(dev);
4146
4147 if (err) {
Joe Perchesf15063c2010-02-17 15:01:57 +00004148 netdev_err(dev, "could not up: %d\n", err);
Stephen Hemmingeredd702e2005-12-15 12:18:00 -08004149 dev_close(dev);
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004150 goto out;
4151 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004152 }
4153 }
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004154out:
4155 return err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004156}
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004157
4158static SIMPLE_DEV_PM_OPS(skge_pm_ops, skge_suspend, skge_resume);
4159#define SKGE_PM_OPS (&skge_pm_ops)
4160
4161#else
4162
4163#define SKGE_PM_OPS NULL
Daniel Halperinfaa85aa2012-01-03 13:53:16 -05004164#endif /* CONFIG_PM_SLEEP */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004165
Stephen Hemminger692412b2007-04-09 15:32:45 -07004166static void skge_shutdown(struct pci_dev *pdev)
4167{
4168 struct skge_hw *hw = pci_get_drvdata(pdev);
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004169 int i;
Stephen Hemminger692412b2007-04-09 15:32:45 -07004170
Stephen Hemmingere3b7df12007-05-11 11:21:45 -07004171 if (!hw)
4172 return;
4173
Stephen Hemminger692412b2007-04-09 15:32:45 -07004174 for (i = 0; i < hw->ports; i++) {
4175 struct net_device *dev = hw->dev[i];
4176 struct skge_port *skge = netdev_priv(dev);
4177
4178 if (skge->wol)
4179 skge_wol_init(skge);
Stephen Hemminger692412b2007-04-09 15:32:45 -07004180 }
4181
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004182 pci_wake_from_d3(pdev, device_may_wakeup(&pdev->dev));
Stephen Hemminger692412b2007-04-09 15:32:45 -07004183 pci_set_power_state(pdev, PCI_D3hot);
Stephen Hemminger692412b2007-04-09 15:32:45 -07004184}
4185
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004186static struct pci_driver skge_driver = {
4187 .name = DRV_NAME,
4188 .id_table = skge_id_table,
4189 .probe = skge_probe,
4190 .remove = __devexit_p(skge_remove),
Stephen Hemminger692412b2007-04-09 15:32:45 -07004191 .shutdown = skge_shutdown,
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004192 .driver.pm = SKGE_PM_OPS,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004193};
4194
Stanislaw Gruszka392bd0c2010-10-05 15:11:40 -07004195static struct dmi_system_id skge_32bit_dma_boards[] = {
4196 {
4197 .ident = "Gigabyte nForce boards",
4198 .matches = {
4199 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co"),
4200 DMI_MATCH(DMI_BOARD_NAME, "nForce"),
4201 },
4202 },
4203 {}
4204};
4205
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004206static int __init skge_init_module(void)
4207{
Stanislaw Gruszka392bd0c2010-10-05 15:11:40 -07004208 if (dmi_check_system(skge_32bit_dma_boards))
4209 only_32bit_dma = 1;
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07004210 skge_debug_init();
Jeff Garzik29917622006-08-19 17:48:59 -04004211 return pci_register_driver(&skge_driver);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004212}
4213
4214static void __exit skge_cleanup_module(void)
4215{
4216 pci_unregister_driver(&skge_driver);
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07004217 skge_debug_cleanup();
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004218}
4219
4220module_init(skge_init_module);
4221module_exit(skge_cleanup_module);