blob: 52a48cb75440abecaaf18b81f3aab26dd63b2169 [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>
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040047#include <asm/irq.h>
48
49#include "skge.h"
50
51#define DRV_NAME "skge"
Stephen Hemmingerbf9f56d2007-11-26 11:54:53 -080052#define DRV_VERSION "1.13"
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040053
54#define DEFAULT_TX_RING_SIZE 128
55#define DEFAULT_RX_RING_SIZE 512
56#define MAX_TX_RING_SIZE 1024
Stephen Hemminger9db96472006-06-06 10:11:12 -070057#define TX_LOW_WATER (MAX_SKB_FRAGS + 1)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040058#define MAX_RX_RING_SIZE 4096
Stephen Hemminger19a33d42005-06-27 11:33:15 -070059#define RX_COPY_THRESHOLD 128
60#define RX_BUF_SIZE 1536
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040061#define PHY_RETRIES 1000
62#define ETH_JUMBO_MTU 9000
63#define TX_WATCHDOG (5 * HZ)
64#define NAPI_WEIGHT 64
Stephen Hemminger6abebb52005-07-22 16:26:10 -070065#define BLINK_MS 250
Stephen Hemminger501fb722007-10-16 12:15:51 -070066#define LINK_HZ HZ
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040067
Stephen Hemmingerafa151b2007-10-16 12:15:53 -070068#define SKGE_EEPROM_MAGIC 0x9933aabb
69
70
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040071MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver");
Stephen Hemminger65ebe6342007-01-23 11:38:57 -080072MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040073MODULE_LICENSE("GPL");
74MODULE_VERSION(DRV_VERSION);
75
Joe Perches67777f92010-02-17 15:01:58 +000076static const u32 default_msg = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
77 NETIF_MSG_LINK | NETIF_MSG_IFUP |
78 NETIF_MSG_IFDOWN);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040079
80static int debug = -1; /* defaults above */
81module_param(debug, int, 0);
82MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
83
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000084static DEFINE_PCI_DEVICE_TABLE(skge_id_table) = {
Stephen Hemminger275834d2005-06-27 11:33:03 -070085 { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940) },
86 { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940B) },
87 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE) },
88 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU) },
Stephen Hemmingerf19841f2007-02-23 14:04:54 -080089 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T) },
Stephen Hemminger2d2a3872006-05-17 14:37:04 -070090 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b01) }, /* DGE-530T */
Stephen Hemminger275834d2005-06-27 11:33:03 -070091 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) },
92 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */
93 { PCI_DEVICE(PCI_VENDOR_ID_CNET, PCI_DEVICE_ID_CNET_GIGACARD) },
Stephen Hemminger275834d2005-06-27 11:33:03 -070094 { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1064) },
Stephen Hemmingerf19841f2007-02-23 14:04:54 -080095 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015 },
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040096 { 0 }
97};
98MODULE_DEVICE_TABLE(pci, skge_id_table);
99
100static int skge_up(struct net_device *dev);
101static int skge_down(struct net_device *dev);
Stephen Hemmingeree294dc2005-12-14 15:47:44 -0800102static void skge_phy_reset(struct skge_port *skge);
Stephen Hemminger513f5332006-09-01 15:53:49 -0700103static void skge_tx_clean(struct net_device *dev);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -0800104static int xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val);
105static int gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400106static void genesis_get_stats(struct skge_port *skge, u64 *data);
107static void yukon_get_stats(struct skge_port *skge, u64 *data);
108static void yukon_init(struct skge_hw *hw, int port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400109static void genesis_mac_init(struct skge_hw *hw, int port);
Stephen Hemminger45bada62005-06-27 11:33:12 -0700110static void genesis_link_up(struct skge_port *skge);
Stephen Hemmingerf80d0322008-11-19 22:01:26 -0800111static void skge_set_multicast(struct net_device *dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400112
Stephen Hemminger7e676d92005-06-27 11:33:13 -0700113/* Avoid conditionals by using array */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400114static const int txqaddr[] = { Q_XA1, Q_XA2 };
115static const int rxqaddr[] = { Q_R1, Q_R2 };
116static const u32 rxirqmask[] = { IS_R1_F, IS_R2_F };
117static const u32 txirqmask[] = { IS_XA1_F, IS_XA2_F };
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -0700118static const u32 napimask[] = { IS_R1_F|IS_XA1_F, IS_R2_F|IS_XA2_F };
119static const u32 portmask[] = { IS_PORT_1, IS_PORT_2 };
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400120
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400121static int skge_get_regs_len(struct net_device *dev)
122{
Stephen Hemmingerc3f8be92005-09-19 15:37:34 -0700123 return 0x4000;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400124}
125
126/*
Stephen Hemmingerc3f8be92005-09-19 15:37:34 -0700127 * Returns copy of whole control register region
128 * Note: skip RAM address register because accessing it will
129 * cause bus hangs!
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400130 */
131static void skge_get_regs(struct net_device *dev, struct ethtool_regs *regs,
132 void *p)
133{
134 const struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400135 const void __iomem *io = skge->hw->regs;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400136
137 regs->version = 1;
Stephen Hemmingerc3f8be92005-09-19 15:37:34 -0700138 memset(p, 0, regs->len);
139 memcpy_fromio(p, io, B3_RAM_ADDR);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400140
Stephen Hemmingerc3f8be92005-09-19 15:37:34 -0700141 memcpy_fromio(p + B3_RI_WTO_R1, io + B3_RI_WTO_R1,
142 regs->len - B3_RI_WTO_R1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400143}
144
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800145/* Wake on Lan only supported on Yukon chips with rev 1 or above */
Stephen Hemmingera504e642007-02-02 08:22:53 -0800146static u32 wol_supported(const struct skge_hw *hw)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400147{
Stephen Hemmingerd17ecb22007-05-07 11:01:55 -0700148 if (hw->chip_id == CHIP_ID_GENESIS)
Stephen Hemmingera504e642007-02-02 08:22:53 -0800149 return 0;
Stephen Hemmingerd17ecb22007-05-07 11:01:55 -0700150
151 if (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)
152 return 0;
153
154 return WAKE_MAGIC | WAKE_PHY;
Stephen Hemmingera504e642007-02-02 08:22:53 -0800155}
156
Stephen Hemmingera504e642007-02-02 08:22:53 -0800157static void skge_wol_init(struct skge_port *skge)
158{
159 struct skge_hw *hw = skge->hw;
160 int port = skge->port;
Stephen Hemminger692412b2007-04-09 15:32:45 -0700161 u16 ctrl;
Stephen Hemmingera504e642007-02-02 08:22:53 -0800162
Stephen Hemmingera504e642007-02-02 08:22:53 -0800163 skge_write16(hw, B0_CTST, CS_RST_CLR);
164 skge_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR);
165
Stephen Hemminger692412b2007-04-09 15:32:45 -0700166 /* Turn on Vaux */
167 skge_write8(hw, B0_POWER_CTRL,
168 PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_ON | PC_VCC_OFF);
169
170 /* WA code for COMA mode -- clear PHY reset */
171 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
172 hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
173 u32 reg = skge_read32(hw, B2_GP_IO);
174 reg |= GP_DIR_9;
175 reg &= ~GP_IO_9;
176 skge_write32(hw, B2_GP_IO, reg);
177 }
178
179 skge_write32(hw, SK_REG(port, GPHY_CTRL),
180 GPC_DIS_SLEEP |
181 GPC_HWCFG_M_3 | GPC_HWCFG_M_2 | GPC_HWCFG_M_1 | GPC_HWCFG_M_0 |
182 GPC_ANEG_1 | GPC_RST_SET);
183
184 skge_write32(hw, SK_REG(port, GPHY_CTRL),
185 GPC_DIS_SLEEP |
186 GPC_HWCFG_M_3 | GPC_HWCFG_M_2 | GPC_HWCFG_M_1 | GPC_HWCFG_M_0 |
187 GPC_ANEG_1 | GPC_RST_CLR);
188
189 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
Stephen Hemmingera504e642007-02-02 08:22:53 -0800190
191 /* Force to 10/100 skge_reset will re-enable on resume */
Stephen Hemminger692412b2007-04-09 15:32:45 -0700192 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV,
Joe Perches67777f92010-02-17 15:01:58 +0000193 (PHY_AN_100FULL | PHY_AN_100HALF |
194 PHY_AN_10FULL | PHY_AN_10HALF | PHY_AN_CSMA));
Stephen Hemminger692412b2007-04-09 15:32:45 -0700195 /* no 1000 HD/FD */
196 gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, 0);
197 gm_phy_write(hw, port, PHY_MARV_CTRL,
198 PHY_CT_RESET | PHY_CT_SPS_LSB | PHY_CT_ANE |
199 PHY_CT_RE_CFG | PHY_CT_DUP_MD);
Stephen Hemmingera504e642007-02-02 08:22:53 -0800200
Stephen Hemmingera504e642007-02-02 08:22:53 -0800201
202 /* Set GMAC to no flow control and auto update for speed/duplex */
203 gma_write16(hw, port, GM_GP_CTRL,
204 GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA|
205 GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS);
206
207 /* Set WOL address */
208 memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR),
209 skge->netdev->dev_addr, ETH_ALEN);
210
211 /* Turn on appropriate WOL control bits */
212 skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT);
213 ctrl = 0;
214 if (skge->wol & WAKE_PHY)
215 ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT;
216 else
217 ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT;
218
219 if (skge->wol & WAKE_MAGIC)
220 ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT;
221 else
Joe Perchesa419aef2009-08-18 11:18:35 -0700222 ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT;
Stephen Hemmingera504e642007-02-02 08:22:53 -0800223
224 ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT;
225 skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
226
227 /* block receiver */
228 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400229}
230
231static void skge_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
232{
233 struct skge_port *skge = netdev_priv(dev);
234
Stephen Hemmingera504e642007-02-02 08:22:53 -0800235 wol->supported = wol_supported(skge->hw);
236 wol->wolopts = skge->wol;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400237}
238
239static int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
240{
241 struct skge_port *skge = netdev_priv(dev);
242 struct skge_hw *hw = skge->hw;
243
Joe Perches8e95a202009-12-03 07:58:21 +0000244 if ((wol->wolopts & ~wol_supported(hw)) ||
245 !device_can_wakeup(&hw->pdev->dev))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400246 return -EOPNOTSUPP;
247
Stephen Hemmingera504e642007-02-02 08:22:53 -0800248 skge->wol = wol->wolopts;
Rafael J. Wysocki5177b322008-10-29 14:22:14 -0700249
250 device_set_wakeup_enable(&hw->pdev->dev, skge->wol);
251
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400252 return 0;
253}
254
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800255/* Determine supported/advertised modes based on hardware.
256 * Note: ethtool ADVERTISED_xxx == SUPPORTED_xxx
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700257 */
258static u32 skge_supported_modes(const struct skge_hw *hw)
259{
260 u32 supported;
261
Stephen Hemminger5e1705d2005-08-16 14:00:58 -0700262 if (hw->copper) {
Joe Perches67777f92010-02-17 15:01:58 +0000263 supported = (SUPPORTED_10baseT_Half |
264 SUPPORTED_10baseT_Full |
265 SUPPORTED_100baseT_Half |
266 SUPPORTED_100baseT_Full |
267 SUPPORTED_1000baseT_Half |
268 SUPPORTED_1000baseT_Full |
269 SUPPORTED_Autoneg |
270 SUPPORTED_TP);
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700271
272 if (hw->chip_id == CHIP_ID_GENESIS)
Joe Perches67777f92010-02-17 15:01:58 +0000273 supported &= ~(SUPPORTED_10baseT_Half |
274 SUPPORTED_10baseT_Full |
275 SUPPORTED_100baseT_Half |
276 SUPPORTED_100baseT_Full);
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700277
278 else if (hw->chip_id == CHIP_ID_YUKON)
279 supported &= ~SUPPORTED_1000baseT_Half;
280 } else
Joe Perches67777f92010-02-17 15:01:58 +0000281 supported = (SUPPORTED_1000baseT_Full |
282 SUPPORTED_1000baseT_Half |
283 SUPPORTED_FIBRE |
284 SUPPORTED_Autoneg);
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700285
286 return supported;
287}
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400288
289static int skge_get_settings(struct net_device *dev,
290 struct ethtool_cmd *ecmd)
291{
292 struct skge_port *skge = netdev_priv(dev);
293 struct skge_hw *hw = skge->hw;
294
295 ecmd->transceiver = XCVR_INTERNAL;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700296 ecmd->supported = skge_supported_modes(hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400297
Stephen Hemminger5e1705d2005-08-16 14:00:58 -0700298 if (hw->copper) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400299 ecmd->port = PORT_TP;
300 ecmd->phy_address = hw->phy_addr;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700301 } else
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400302 ecmd->port = PORT_FIBRE;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400303
304 ecmd->advertising = skge->advertising;
305 ecmd->autoneg = skge->autoneg;
David Decotigny70739492011-04-27 18:32:40 +0000306 ethtool_cmd_speed_set(ecmd, skge->speed);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400307 ecmd->duplex = skge->duplex;
308 return 0;
309}
310
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400311static int skge_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
312{
313 struct skge_port *skge = netdev_priv(dev);
314 const struct skge_hw *hw = skge->hw;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700315 u32 supported = skge_supported_modes(hw);
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000316 int err = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400317
318 if (ecmd->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700319 ecmd->advertising = supported;
320 skge->duplex = -1;
321 skge->speed = -1;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400322 } else {
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700323 u32 setting;
David Decotigny25db0332011-04-27 18:32:39 +0000324 u32 speed = ethtool_cmd_speed(ecmd);
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700325
David Decotigny25db0332011-04-27 18:32:39 +0000326 switch (speed) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400327 case SPEED_1000:
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700328 if (ecmd->duplex == DUPLEX_FULL)
329 setting = SUPPORTED_1000baseT_Full;
330 else if (ecmd->duplex == DUPLEX_HALF)
331 setting = SUPPORTED_1000baseT_Half;
332 else
333 return -EINVAL;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400334 break;
335 case SPEED_100:
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700336 if (ecmd->duplex == DUPLEX_FULL)
337 setting = SUPPORTED_100baseT_Full;
338 else if (ecmd->duplex == DUPLEX_HALF)
339 setting = SUPPORTED_100baseT_Half;
340 else
341 return -EINVAL;
342 break;
343
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400344 case SPEED_10:
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700345 if (ecmd->duplex == DUPLEX_FULL)
346 setting = SUPPORTED_10baseT_Full;
347 else if (ecmd->duplex == DUPLEX_HALF)
348 setting = SUPPORTED_10baseT_Half;
349 else
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400350 return -EINVAL;
351 break;
352 default:
353 return -EINVAL;
354 }
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700355
356 if ((setting & supported) == 0)
357 return -EINVAL;
358
David Decotigny25db0332011-04-27 18:32:39 +0000359 skge->speed = speed;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700360 skge->duplex = ecmd->duplex;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400361 }
362
363 skge->autoneg = ecmd->autoneg;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400364 skge->advertising = ecmd->advertising;
365
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000366 if (netif_running(dev)) {
367 skge_down(dev);
368 err = skge_up(dev);
369 if (err) {
370 dev_close(dev);
371 return err;
372 }
373 }
Stephen Hemmingeree294dc2005-12-14 15:47:44 -0800374
Joe Perches67777f92010-02-17 15:01:58 +0000375 return 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400376}
377
378static void skge_get_drvinfo(struct net_device *dev,
379 struct ethtool_drvinfo *info)
380{
381 struct skge_port *skge = netdev_priv(dev);
382
383 strcpy(info->driver, DRV_NAME);
384 strcpy(info->version, DRV_VERSION);
385 strcpy(info->fw_version, "N/A");
386 strcpy(info->bus_info, pci_name(skge->hw->pdev));
387}
388
389static const struct skge_stat {
390 char name[ETH_GSTRING_LEN];
391 u16 xmac_offset;
392 u16 gma_offset;
393} skge_stats[] = {
394 { "tx_bytes", XM_TXO_OK_HI, GM_TXO_OK_HI },
395 { "rx_bytes", XM_RXO_OK_HI, GM_RXO_OK_HI },
396
397 { "tx_broadcast", XM_TXF_BC_OK, GM_TXF_BC_OK },
398 { "rx_broadcast", XM_RXF_BC_OK, GM_RXF_BC_OK },
399 { "tx_multicast", XM_TXF_MC_OK, GM_TXF_MC_OK },
400 { "rx_multicast", XM_RXF_MC_OK, GM_RXF_MC_OK },
401 { "tx_unicast", XM_TXF_UC_OK, GM_TXF_UC_OK },
402 { "rx_unicast", XM_RXF_UC_OK, GM_RXF_UC_OK },
403 { "tx_mac_pause", XM_TXF_MPAUSE, GM_TXF_MPAUSE },
404 { "rx_mac_pause", XM_RXF_MPAUSE, GM_RXF_MPAUSE },
405
406 { "collisions", XM_TXF_SNG_COL, GM_TXF_SNG_COL },
407 { "multi_collisions", XM_TXF_MUL_COL, GM_TXF_MUL_COL },
408 { "aborted", XM_TXF_ABO_COL, GM_TXF_ABO_COL },
409 { "late_collision", XM_TXF_LAT_COL, GM_TXF_LAT_COL },
410 { "fifo_underrun", XM_TXE_FIFO_UR, GM_TXE_FIFO_UR },
411 { "fifo_overflow", XM_RXE_FIFO_OV, GM_RXE_FIFO_OV },
412
413 { "rx_toolong", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR },
414 { "rx_jabber", XM_RXF_JAB_PKT, GM_RXF_JAB_PKT },
415 { "rx_runt", XM_RXE_RUNT, GM_RXE_FRAG },
416 { "rx_too_long", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR },
417 { "rx_fcs_error", XM_RXF_FCS_ERR, GM_RXF_FCS_ERR },
418};
419
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700420static int skge_get_sset_count(struct net_device *dev, int sset)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400421{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700422 switch (sset) {
423 case ETH_SS_STATS:
424 return ARRAY_SIZE(skge_stats);
425 default:
426 return -EOPNOTSUPP;
427 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400428}
429
430static void skge_get_ethtool_stats(struct net_device *dev,
431 struct ethtool_stats *stats, u64 *data)
432{
433 struct skge_port *skge = netdev_priv(dev);
434
435 if (skge->hw->chip_id == CHIP_ID_GENESIS)
436 genesis_get_stats(skge, data);
437 else
438 yukon_get_stats(skge, data);
439}
440
441/* Use hardware MIB variables for critical path statistics and
442 * transmit feedback not reported at interrupt.
443 * Other errors are accounted for in interrupt handler.
444 */
445static struct net_device_stats *skge_get_stats(struct net_device *dev)
446{
447 struct skge_port *skge = netdev_priv(dev);
448 u64 data[ARRAY_SIZE(skge_stats)];
449
450 if (skge->hw->chip_id == CHIP_ID_GENESIS)
451 genesis_get_stats(skge, data);
452 else
453 yukon_get_stats(skge, data);
454
Stephen Hemmingerda007722007-10-16 12:15:52 -0700455 dev->stats.tx_bytes = data[0];
456 dev->stats.rx_bytes = data[1];
457 dev->stats.tx_packets = data[2] + data[4] + data[6];
458 dev->stats.rx_packets = data[3] + data[5] + data[7];
459 dev->stats.multicast = data[3] + data[5];
460 dev->stats.collisions = data[10];
461 dev->stats.tx_aborted_errors = data[12];
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400462
Stephen Hemmingerda007722007-10-16 12:15:52 -0700463 return &dev->stats;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400464}
465
466static void skge_get_strings(struct net_device *dev, u32 stringset, u8 *data)
467{
468 int i;
469
Stephen Hemminger95566062005-06-27 11:33:02 -0700470 switch (stringset) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400471 case ETH_SS_STATS:
472 for (i = 0; i < ARRAY_SIZE(skge_stats); i++)
473 memcpy(data + i * ETH_GSTRING_LEN,
474 skge_stats[i].name, ETH_GSTRING_LEN);
475 break;
476 }
477}
478
479static void skge_get_ring_param(struct net_device *dev,
480 struct ethtool_ringparam *p)
481{
482 struct skge_port *skge = netdev_priv(dev);
483
484 p->rx_max_pending = MAX_RX_RING_SIZE;
485 p->tx_max_pending = MAX_TX_RING_SIZE;
486 p->rx_mini_max_pending = 0;
487 p->rx_jumbo_max_pending = 0;
488
489 p->rx_pending = skge->rx_ring.count;
490 p->tx_pending = skge->tx_ring.count;
491 p->rx_mini_pending = 0;
492 p->rx_jumbo_pending = 0;
493}
494
495static int skge_set_ring_param(struct net_device *dev,
496 struct ethtool_ringparam *p)
497{
498 struct skge_port *skge = netdev_priv(dev);
Wang Chene824b3e2008-09-26 16:20:32 +0800499 int err = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400500
501 if (p->rx_pending == 0 || p->rx_pending > MAX_RX_RING_SIZE ||
Stephen Hemminger9db96472006-06-06 10:11:12 -0700502 p->tx_pending < TX_LOW_WATER || p->tx_pending > MAX_TX_RING_SIZE)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400503 return -EINVAL;
504
505 skge->rx_ring.count = p->rx_pending;
506 skge->tx_ring.count = p->tx_pending;
507
508 if (netif_running(dev)) {
509 skge_down(dev);
Stephen Hemminger3b8bb472005-12-14 15:47:48 -0800510 err = skge_up(dev);
511 if (err)
512 dev_close(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400513 }
514
Wang Chene824b3e2008-09-26 16:20:32 +0800515 return err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400516}
517
518static u32 skge_get_msglevel(struct net_device *netdev)
519{
520 struct skge_port *skge = netdev_priv(netdev);
521 return skge->msg_enable;
522}
523
524static void skge_set_msglevel(struct net_device *netdev, u32 value)
525{
526 struct skge_port *skge = netdev_priv(netdev);
527 skge->msg_enable = value;
528}
529
530static int skge_nway_reset(struct net_device *dev)
531{
532 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400533
534 if (skge->autoneg != AUTONEG_ENABLE || !netif_running(dev))
535 return -EINVAL;
536
Stephen Hemmingeree294dc2005-12-14 15:47:44 -0800537 skge_phy_reset(skge);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400538 return 0;
539}
540
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400541static void skge_get_pauseparam(struct net_device *dev,
542 struct ethtool_pauseparam *ecmd)
543{
544 struct skge_port *skge = netdev_priv(dev);
545
Joe Perches8e95a202009-12-03 07:58:21 +0000546 ecmd->rx_pause = ((skge->flow_control == FLOW_MODE_SYMMETRIC) ||
547 (skge->flow_control == FLOW_MODE_SYM_OR_REM));
548 ecmd->tx_pause = (ecmd->rx_pause ||
549 (skge->flow_control == FLOW_MODE_LOC_SEND));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400550
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700551 ecmd->autoneg = ecmd->rx_pause || ecmd->tx_pause;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400552}
553
554static int skge_set_pauseparam(struct net_device *dev,
555 struct ethtool_pauseparam *ecmd)
556{
557 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700558 struct ethtool_pauseparam old;
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000559 int err = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400560
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700561 skge_get_pauseparam(dev, &old);
562
563 if (ecmd->autoneg != old.autoneg)
564 skge->flow_control = ecmd->autoneg ? FLOW_MODE_NONE : FLOW_MODE_SYMMETRIC;
565 else {
566 if (ecmd->rx_pause && ecmd->tx_pause)
567 skge->flow_control = FLOW_MODE_SYMMETRIC;
568 else if (ecmd->rx_pause && !ecmd->tx_pause)
569 skge->flow_control = FLOW_MODE_SYM_OR_REM;
570 else if (!ecmd->rx_pause && ecmd->tx_pause)
571 skge->flow_control = FLOW_MODE_LOC_SEND;
572 else
573 skge->flow_control = FLOW_MODE_NONE;
574 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400575
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000576 if (netif_running(dev)) {
577 skge_down(dev);
578 err = skge_up(dev);
579 if (err) {
580 dev_close(dev);
581 return err;
582 }
583 }
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700584
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400585 return 0;
586}
587
588/* Chip internal frequency for clock calculations */
589static inline u32 hwkhz(const struct skge_hw *hw)
590{
Stephen Hemminger187ff3b2006-07-19 14:08:42 -0700591 return (hw->chip_id == CHIP_ID_GENESIS) ? 53125 : 78125;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400592}
593
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800594/* Chip HZ to microseconds */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400595static inline u32 skge_clk2usec(const struct skge_hw *hw, u32 ticks)
596{
597 return (ticks * 1000) / hwkhz(hw);
598}
599
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800600/* Microseconds to chip HZ */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400601static inline u32 skge_usecs2clk(const struct skge_hw *hw, u32 usec)
602{
603 return hwkhz(hw) * usec / 1000;
604}
605
606static int skge_get_coalesce(struct net_device *dev,
607 struct ethtool_coalesce *ecmd)
608{
609 struct skge_port *skge = netdev_priv(dev);
610 struct skge_hw *hw = skge->hw;
611 int port = skge->port;
612
613 ecmd->rx_coalesce_usecs = 0;
614 ecmd->tx_coalesce_usecs = 0;
615
616 if (skge_read32(hw, B2_IRQM_CTRL) & TIM_START) {
617 u32 delay = skge_clk2usec(hw, skge_read32(hw, B2_IRQM_INI));
618 u32 msk = skge_read32(hw, B2_IRQM_MSK);
619
620 if (msk & rxirqmask[port])
621 ecmd->rx_coalesce_usecs = delay;
622 if (msk & txirqmask[port])
623 ecmd->tx_coalesce_usecs = delay;
624 }
625
626 return 0;
627}
628
629/* Note: interrupt timer is per board, but can turn on/off per port */
630static int skge_set_coalesce(struct net_device *dev,
631 struct ethtool_coalesce *ecmd)
632{
633 struct skge_port *skge = netdev_priv(dev);
634 struct skge_hw *hw = skge->hw;
635 int port = skge->port;
636 u32 msk = skge_read32(hw, B2_IRQM_MSK);
637 u32 delay = 25;
638
639 if (ecmd->rx_coalesce_usecs == 0)
640 msk &= ~rxirqmask[port];
641 else if (ecmd->rx_coalesce_usecs < 25 ||
642 ecmd->rx_coalesce_usecs > 33333)
643 return -EINVAL;
644 else {
645 msk |= rxirqmask[port];
646 delay = ecmd->rx_coalesce_usecs;
647 }
648
649 if (ecmd->tx_coalesce_usecs == 0)
650 msk &= ~txirqmask[port];
651 else if (ecmd->tx_coalesce_usecs < 25 ||
652 ecmd->tx_coalesce_usecs > 33333)
653 return -EINVAL;
654 else {
655 msk |= txirqmask[port];
656 delay = min(delay, ecmd->rx_coalesce_usecs);
657 }
658
659 skge_write32(hw, B2_IRQM_MSK, msk);
660 if (msk == 0)
661 skge_write32(hw, B2_IRQM_CTRL, TIM_STOP);
662 else {
663 skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, delay));
664 skge_write32(hw, B2_IRQM_CTRL, TIM_START);
665 }
666 return 0;
667}
668
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700669enum led_mode { LED_MODE_OFF, LED_MODE_ON, LED_MODE_TST };
670static void skge_led(struct skge_port *skge, enum led_mode mode)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400671{
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400672 struct skge_hw *hw = skge->hw;
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700673 int port = skge->port;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400674
Stephen Hemminger9cbe3302007-03-16 14:01:28 -0700675 spin_lock_bh(&hw->phy_lock);
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700676 if (hw->chip_id == CHIP_ID_GENESIS) {
677 switch (mode) {
678 case LED_MODE_OFF:
Stephen Hemminger64f6b642006-09-23 21:25:28 -0700679 if (hw->phy_type == SK_PHY_BCOM)
680 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF);
681 else {
682 skge_write32(hw, SK_REG(port, TX_LED_VAL), 0);
683 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_T_OFF);
684 }
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700685 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
686 skge_write32(hw, SK_REG(port, RX_LED_VAL), 0);
687 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF);
688 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400689
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700690 case LED_MODE_ON:
691 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON);
692 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON);
693
694 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
695 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
696
697 break;
698
699 case LED_MODE_TST:
700 skge_write8(hw, SK_REG(port, RX_LED_TST), LED_T_ON);
701 skge_write32(hw, SK_REG(port, RX_LED_VAL), 100);
702 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
703
Stephen Hemminger64f6b642006-09-23 21:25:28 -0700704 if (hw->phy_type == SK_PHY_BCOM)
705 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON);
706 else {
707 skge_write8(hw, SK_REG(port, TX_LED_TST), LED_T_ON);
708 skge_write32(hw, SK_REG(port, TX_LED_VAL), 100);
709 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
710 }
711
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700712 }
713 } else {
714 switch (mode) {
715 case LED_MODE_OFF:
716 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
717 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
718 PHY_M_LED_MO_DUP(MO_LED_OFF) |
719 PHY_M_LED_MO_10(MO_LED_OFF) |
720 PHY_M_LED_MO_100(MO_LED_OFF) |
721 PHY_M_LED_MO_1000(MO_LED_OFF) |
722 PHY_M_LED_MO_RX(MO_LED_OFF));
723 break;
724 case LED_MODE_ON:
725 gm_phy_write(hw, port, PHY_MARV_LED_CTRL,
726 PHY_M_LED_PULS_DUR(PULS_170MS) |
727 PHY_M_LED_BLINK_RT(BLINK_84MS) |
728 PHY_M_LEDC_TX_CTRL |
729 PHY_M_LEDC_DP_CTRL);
Stephen Hemminger46a60f22005-09-09 12:54:56 -0700730
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700731 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
732 PHY_M_LED_MO_RX(MO_LED_OFF) |
733 (skge->speed == SPEED_100 ?
734 PHY_M_LED_MO_100(MO_LED_ON) : 0));
735 break;
736 case LED_MODE_TST:
737 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
738 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
739 PHY_M_LED_MO_DUP(MO_LED_ON) |
740 PHY_M_LED_MO_10(MO_LED_ON) |
741 PHY_M_LED_MO_100(MO_LED_ON) |
742 PHY_M_LED_MO_1000(MO_LED_ON) |
743 PHY_M_LED_MO_RX(MO_LED_ON));
744 }
745 }
Stephen Hemminger9cbe3302007-03-16 14:01:28 -0700746 spin_unlock_bh(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400747}
748
749/* blink LED's for finding board */
stephen hemmingera5b9f412011-04-04 08:43:42 +0000750static int skge_set_phys_id(struct net_device *dev,
751 enum ethtool_phys_id_state state)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400752{
753 struct skge_port *skge = netdev_priv(dev);
754
stephen hemmingera5b9f412011-04-04 08:43:42 +0000755 switch (state) {
756 case ETHTOOL_ID_ACTIVE:
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000757 return 2; /* cycle on/off twice per second */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400758
stephen hemmingera5b9f412011-04-04 08:43:42 +0000759 case ETHTOOL_ID_ON:
760 skge_led(skge, LED_MODE_TST);
761 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400762
stephen hemmingera5b9f412011-04-04 08:43:42 +0000763 case ETHTOOL_ID_OFF:
764 skge_led(skge, LED_MODE_OFF);
765 break;
766
767 case ETHTOOL_ID_INACTIVE:
768 /* back to regular LED state */
769 skge_led(skge, netif_running(dev) ? LED_MODE_ON : LED_MODE_OFF);
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700770 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400771
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400772 return 0;
773}
774
Stephen Hemmingerafa151b2007-10-16 12:15:53 -0700775static int skge_get_eeprom_len(struct net_device *dev)
776{
777 struct skge_port *skge = netdev_priv(dev);
778 u32 reg2;
779
780 pci_read_config_dword(skge->hw->pdev, PCI_DEV_REG2, &reg2);
Joe Perches67777f92010-02-17 15:01:58 +0000781 return 1 << (((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
Stephen Hemmingerafa151b2007-10-16 12:15:53 -0700782}
783
784static u32 skge_vpd_read(struct pci_dev *pdev, int cap, u16 offset)
785{
786 u32 val;
787
788 pci_write_config_word(pdev, cap + PCI_VPD_ADDR, offset);
789
790 do {
791 pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
792 } while (!(offset & PCI_VPD_ADDR_F));
793
794 pci_read_config_dword(pdev, cap + PCI_VPD_DATA, &val);
795 return val;
796}
797
798static void skge_vpd_write(struct pci_dev *pdev, int cap, u16 offset, u32 val)
799{
800 pci_write_config_dword(pdev, cap + PCI_VPD_DATA, val);
801 pci_write_config_word(pdev, cap + PCI_VPD_ADDR,
802 offset | PCI_VPD_ADDR_F);
803
804 do {
805 pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
806 } while (offset & PCI_VPD_ADDR_F);
807}
808
809static int skge_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
810 u8 *data)
811{
812 struct skge_port *skge = netdev_priv(dev);
813 struct pci_dev *pdev = skge->hw->pdev;
814 int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD);
815 int length = eeprom->len;
816 u16 offset = eeprom->offset;
817
818 if (!cap)
819 return -EINVAL;
820
821 eeprom->magic = SKGE_EEPROM_MAGIC;
822
823 while (length > 0) {
824 u32 val = skge_vpd_read(pdev, cap, offset);
825 int n = min_t(int, length, sizeof(val));
826
827 memcpy(data, &val, n);
828 length -= n;
829 data += n;
830 offset += n;
831 }
832 return 0;
833}
834
835static int skge_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
836 u8 *data)
837{
838 struct skge_port *skge = netdev_priv(dev);
839 struct pci_dev *pdev = skge->hw->pdev;
840 int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD);
841 int length = eeprom->len;
842 u16 offset = eeprom->offset;
843
844 if (!cap)
845 return -EINVAL;
846
847 if (eeprom->magic != SKGE_EEPROM_MAGIC)
848 return -EINVAL;
849
850 while (length > 0) {
851 u32 val;
852 int n = min_t(int, length, sizeof(val));
853
854 if (n < sizeof(val))
855 val = skge_vpd_read(pdev, cap, offset);
856 memcpy(&val, data, n);
857
858 skge_vpd_write(pdev, cap, offset, val);
859
860 length -= n;
861 data += n;
862 offset += n;
863 }
864 return 0;
865}
866
Jeff Garzik7282d492006-09-13 14:30:00 -0400867static const struct ethtool_ops skge_ethtool_ops = {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400868 .get_settings = skge_get_settings,
869 .set_settings = skge_set_settings,
870 .get_drvinfo = skge_get_drvinfo,
871 .get_regs_len = skge_get_regs_len,
872 .get_regs = skge_get_regs,
873 .get_wol = skge_get_wol,
874 .set_wol = skge_set_wol,
875 .get_msglevel = skge_get_msglevel,
876 .set_msglevel = skge_set_msglevel,
877 .nway_reset = skge_nway_reset,
878 .get_link = ethtool_op_get_link,
Stephen Hemmingerafa151b2007-10-16 12:15:53 -0700879 .get_eeprom_len = skge_get_eeprom_len,
880 .get_eeprom = skge_get_eeprom,
881 .set_eeprom = skge_set_eeprom,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400882 .get_ringparam = skge_get_ring_param,
883 .set_ringparam = skge_set_ring_param,
884 .get_pauseparam = skge_get_pauseparam,
885 .set_pauseparam = skge_set_pauseparam,
886 .get_coalesce = skge_get_coalesce,
887 .set_coalesce = skge_set_coalesce,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400888 .get_strings = skge_get_strings,
stephen hemmingera5b9f412011-04-04 08:43:42 +0000889 .set_phys_id = skge_set_phys_id,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700890 .get_sset_count = skge_get_sset_count,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400891 .get_ethtool_stats = skge_get_ethtool_stats,
892};
893
894/*
895 * Allocate ring elements and chain them together
896 * One-to-one association of board descriptors with ring elements
897 */
Stephen Hemmingerc3da1442006-03-21 10:57:01 -0800898static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u32 base)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400899{
900 struct skge_tx_desc *d;
901 struct skge_element *e;
902 int i;
903
Robert P. J. Daycd861282006-12-13 00:34:52 -0800904 ring->start = kcalloc(ring->count, sizeof(*e), GFP_KERNEL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400905 if (!ring->start)
906 return -ENOMEM;
907
908 for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) {
909 e->desc = d;
910 if (i == ring->count - 1) {
911 e->next = ring->start;
912 d->next_offset = base;
913 } else {
914 e->next = e + 1;
915 d->next_offset = base + (i+1) * sizeof(*d);
916 }
917 }
918 ring->to_use = ring->to_clean = ring->start;
919
920 return 0;
921}
922
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700923/* Allocate and setup a new buffer for receiving */
924static void skge_rx_setup(struct skge_port *skge, struct skge_element *e,
925 struct sk_buff *skb, unsigned int bufsize)
926{
927 struct skge_rx_desc *rd = e->desc;
928 u64 map;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400929
930 map = pci_map_single(skge->hw->pdev, skb->data, bufsize,
931 PCI_DMA_FROMDEVICE);
932
933 rd->dma_lo = map;
934 rd->dma_hi = map >> 32;
935 e->skb = skb;
936 rd->csum1_start = ETH_HLEN;
937 rd->csum2_start = ETH_HLEN;
938 rd->csum1 = 0;
939 rd->csum2 = 0;
940
941 wmb();
942
943 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | bufsize;
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +0000944 dma_unmap_addr_set(e, mapaddr, map);
945 dma_unmap_len_set(e, maplen, bufsize);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400946}
947
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700948/* Resume receiving using existing skb,
949 * Note: DMA address is not changed by chip.
950 * MTU not changed while receiver active.
951 */
Stephen Hemminger5a011442006-03-23 11:07:25 -0800952static inline void skge_rx_reuse(struct skge_element *e, unsigned int size)
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700953{
954 struct skge_rx_desc *rd = e->desc;
955
956 rd->csum2 = 0;
957 rd->csum2_start = ETH_HLEN;
958
959 wmb();
960
961 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | size;
962}
963
964
965/* Free all buffers in receive ring, assumes receiver stopped */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400966static void skge_rx_clean(struct skge_port *skge)
967{
968 struct skge_hw *hw = skge->hw;
969 struct skge_ring *ring = &skge->rx_ring;
970 struct skge_element *e;
971
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700972 e = ring->start;
973 do {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400974 struct skge_rx_desc *rd = e->desc;
975 rd->control = 0;
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700976 if (e->skb) {
977 pci_unmap_single(hw->pdev,
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +0000978 dma_unmap_addr(e, mapaddr),
979 dma_unmap_len(e, maplen),
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700980 PCI_DMA_FROMDEVICE);
981 dev_kfree_skb(e->skb);
982 e->skb = NULL;
983 }
984 } while ((e = e->next) != ring->start);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400985}
986
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700987
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400988/* Allocate buffers for receive ring
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700989 * For receive: to_clean is next received frame.
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400990 */
Stephen Hemmingerc54f9762006-09-01 15:53:47 -0700991static int skge_rx_fill(struct net_device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400992{
Stephen Hemmingerc54f9762006-09-01 15:53:47 -0700993 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400994 struct skge_ring *ring = &skge->rx_ring;
995 struct skge_element *e;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400996
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700997 e = ring->start;
998 do {
Stephen Hemminger383181a2005-09-19 15:37:16 -0700999 struct sk_buff *skb;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001000
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07001001 skb = __netdev_alloc_skb(dev, skge->rx_buf_size + NET_IP_ALIGN,
1002 GFP_KERNEL);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001003 if (!skb)
1004 return -ENOMEM;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001005
Stephen Hemminger383181a2005-09-19 15:37:16 -07001006 skb_reserve(skb, NET_IP_ALIGN);
1007 skge_rx_setup(skge, e, skb, skge->rx_buf_size);
Joe Perches67777f92010-02-17 15:01:58 +00001008 } while ((e = e->next) != ring->start);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001009
1010 ring->to_clean = ring->start;
1011 return 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001012}
1013
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001014static const char *skge_pause(enum pause_status status)
1015{
Joe Perches67777f92010-02-17 15:01:58 +00001016 switch (status) {
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001017 case FLOW_STAT_NONE:
1018 return "none";
1019 case FLOW_STAT_REM_SEND:
1020 return "rx only";
1021 case FLOW_STAT_LOC_SEND:
1022 return "tx_only";
1023 case FLOW_STAT_SYMMETRIC: /* Both station may send PAUSE */
1024 return "both";
1025 default:
1026 return "indeterminated";
1027 }
1028}
1029
1030
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001031static void skge_link_up(struct skge_port *skge)
1032{
Stephen Hemminger46a60f22005-09-09 12:54:56 -07001033 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG),
Stephen Hemminger54cfb5a2005-08-16 14:01:05 -07001034 LED_BLK_OFF|LED_SYNC_OFF|LED_ON);
1035
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001036 netif_carrier_on(skge->netdev);
Stephen Hemminger29b4e882006-03-23 11:07:28 -08001037 netif_wake_queue(skge->netdev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001038
Joe Perchesd7072042010-02-09 11:49:53 +00001039 netif_info(skge, link, skge->netdev,
1040 "Link is up at %d Mbps, %s duplex, flow control %s\n",
1041 skge->speed,
1042 skge->duplex == DUPLEX_FULL ? "full" : "half",
1043 skge_pause(skge->flow_status));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001044}
1045
1046static void skge_link_down(struct skge_port *skge)
1047{
Stephen Hemminger54cfb5a2005-08-16 14:01:05 -07001048 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001049 netif_carrier_off(skge->netdev);
1050 netif_stop_queue(skge->netdev);
1051
Joe Perchesd7072042010-02-09 11:49:53 +00001052 netif_info(skge, link, skge->netdev, "Link is down\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001053}
1054
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001055
1056static void xm_link_down(struct skge_hw *hw, int port)
1057{
1058 struct net_device *dev = hw->dev[port];
1059 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001060
Stephen Hemminger501fb722007-10-16 12:15:51 -07001061 xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE);
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001062
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001063 if (netif_carrier_ok(dev))
1064 skge_link_down(skge);
1065}
1066
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001067static int __xm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001068{
1069 int i;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001070
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001071 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
Stephen Hemminger07811912006-02-22 10:28:34 -08001072 *val = xm_read16(hw, port, XM_PHY_DATA);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001073
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001074 if (hw->phy_type == SK_PHY_XMAC)
1075 goto ready;
1076
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001077 for (i = 0; i < PHY_RETRIES; i++) {
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001078 if (xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_RDY)
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001079 goto ready;
Stephen Hemminger07811912006-02-22 10:28:34 -08001080 udelay(1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001081 }
1082
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001083 return -ETIMEDOUT;
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001084 ready:
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001085 *val = xm_read16(hw, port, XM_PHY_DATA);
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001086
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001087 return 0;
1088}
1089
1090static u16 xm_phy_read(struct skge_hw *hw, int port, u16 reg)
1091{
1092 u16 v = 0;
1093 if (__xm_phy_read(hw, port, reg, &v))
Joe Perchesf15063c2010-02-17 15:01:57 +00001094 pr_warning("%s: phy read timed out\n", hw->dev[port]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001095 return v;
1096}
1097
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001098static int xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001099{
1100 int i;
1101
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001102 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001103 for (i = 0; i < PHY_RETRIES; i++) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001104 if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001105 goto ready;
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001106 udelay(1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001107 }
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001108 return -EIO;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001109
1110 ready:
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001111 xm_write16(hw, port, XM_PHY_DATA, val);
Stephen Hemminger07811912006-02-22 10:28:34 -08001112 for (i = 0; i < PHY_RETRIES; i++) {
1113 if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
1114 return 0;
1115 udelay(1);
1116 }
1117 return -ETIMEDOUT;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001118}
1119
1120static void genesis_init(struct skge_hw *hw)
1121{
1122 /* set blink source counter */
1123 skge_write32(hw, B2_BSC_INI, (SK_BLK_DUR * SK_FACT_53) / 100);
1124 skge_write8(hw, B2_BSC_CTRL, BSC_START);
1125
1126 /* configure mac arbiter */
1127 skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR);
1128
1129 /* configure mac arbiter timeout values */
1130 skge_write8(hw, B3_MA_TOINI_RX1, SK_MAC_TO_53);
1131 skge_write8(hw, B3_MA_TOINI_RX2, SK_MAC_TO_53);
1132 skge_write8(hw, B3_MA_TOINI_TX1, SK_MAC_TO_53);
1133 skge_write8(hw, B3_MA_TOINI_TX2, SK_MAC_TO_53);
1134
1135 skge_write8(hw, B3_MA_RCINI_RX1, 0);
1136 skge_write8(hw, B3_MA_RCINI_RX2, 0);
1137 skge_write8(hw, B3_MA_RCINI_TX1, 0);
1138 skge_write8(hw, B3_MA_RCINI_TX2, 0);
1139
1140 /* configure packet arbiter timeout */
1141 skge_write16(hw, B3_PA_CTRL, PA_RST_CLR);
1142 skge_write16(hw, B3_PA_TOINI_RX1, SK_PKT_TO_MAX);
1143 skge_write16(hw, B3_PA_TOINI_TX1, SK_PKT_TO_MAX);
1144 skge_write16(hw, B3_PA_TOINI_RX2, SK_PKT_TO_MAX);
1145 skge_write16(hw, B3_PA_TOINI_TX2, SK_PKT_TO_MAX);
1146}
1147
1148static void genesis_reset(struct skge_hw *hw, int port)
1149{
Joe Perchesb6bc7652010-12-21 02:16:08 -08001150 static const u8 zero[8] = { 0 };
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001151 u32 reg;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001152
Stephen Hemminger46a60f22005-09-09 12:54:56 -07001153 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
1154
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001155 /* reset the statistics module */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001156 xm_write32(hw, port, XM_GP_PORT, XM_GP_RES_STAT);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001157 xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001158 xm_write32(hw, port, XM_MODE, 0); /* clear Mode Reg */
1159 xm_write16(hw, port, XM_TX_CMD, 0); /* reset TX CMD Reg */
1160 xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001161
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001162 /* disable Broadcom PHY IRQ */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001163 if (hw->phy_type == SK_PHY_BCOM)
1164 xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001165
Stephen Hemminger45bada62005-06-27 11:33:12 -07001166 xm_outhash(hw, port, XM_HSM, zero);
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001167
1168 /* Flush TX and RX fifo */
1169 reg = xm_read32(hw, port, XM_MODE);
1170 xm_write32(hw, port, XM_MODE, reg | XM_MD_FTF);
1171 xm_write32(hw, port, XM_MODE, reg | XM_MD_FRF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001172}
1173
1174
Stephen Hemminger45bada62005-06-27 11:33:12 -07001175/* Convert mode to MII values */
1176static const u16 phy_pause_map[] = {
1177 [FLOW_MODE_NONE] = 0,
1178 [FLOW_MODE_LOC_SEND] = PHY_AN_PAUSE_ASYM,
1179 [FLOW_MODE_SYMMETRIC] = PHY_AN_PAUSE_CAP,
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001180 [FLOW_MODE_SYM_OR_REM] = PHY_AN_PAUSE_CAP | PHY_AN_PAUSE_ASYM,
Stephen Hemminger45bada62005-06-27 11:33:12 -07001181};
1182
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001183/* special defines for FIBER (88E1011S only) */
1184static const u16 fiber_pause_map[] = {
1185 [FLOW_MODE_NONE] = PHY_X_P_NO_PAUSE,
1186 [FLOW_MODE_LOC_SEND] = PHY_X_P_ASYM_MD,
1187 [FLOW_MODE_SYMMETRIC] = PHY_X_P_SYM_MD,
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001188 [FLOW_MODE_SYM_OR_REM] = PHY_X_P_BOTH_MD,
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001189};
1190
Stephen Hemminger45bada62005-06-27 11:33:12 -07001191
1192/* Check status of Broadcom phy link */
1193static void bcom_check_link(struct skge_hw *hw, int port)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001194{
Stephen Hemminger45bada62005-06-27 11:33:12 -07001195 struct net_device *dev = hw->dev[port];
1196 struct skge_port *skge = netdev_priv(dev);
1197 u16 status;
1198
1199 /* read twice because of latch */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001200 xm_phy_read(hw, port, PHY_BCOM_STAT);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001201 status = xm_phy_read(hw, port, PHY_BCOM_STAT);
1202
Stephen Hemminger45bada62005-06-27 11:33:12 -07001203 if ((status & PHY_ST_LSYNC) == 0) {
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001204 xm_link_down(hw, port);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001205 return;
1206 }
Stephen Hemminger45bada62005-06-27 11:33:12 -07001207
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001208 if (skge->autoneg == AUTONEG_ENABLE) {
1209 u16 lpa, aux;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001210
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001211 if (!(status & PHY_ST_AN_OVER))
1212 return;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001213
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001214 lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP);
1215 if (lpa & PHY_B_AN_RF) {
Joe Perchesf15063c2010-02-17 15:01:57 +00001216 netdev_notice(dev, "remote fault\n");
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001217 return;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001218 }
1219
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001220 aux = xm_phy_read(hw, port, PHY_BCOM_AUX_STAT);
1221
1222 /* Check Duplex mismatch */
1223 switch (aux & PHY_B_AS_AN_RES_MSK) {
1224 case PHY_B_RES_1000FD:
1225 skge->duplex = DUPLEX_FULL;
1226 break;
1227 case PHY_B_RES_1000HD:
1228 skge->duplex = DUPLEX_HALF;
1229 break;
1230 default:
Joe Perchesf15063c2010-02-17 15:01:57 +00001231 netdev_notice(dev, "duplex mismatch\n");
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001232 return;
1233 }
1234
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001235 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
1236 switch (aux & PHY_B_AS_PAUSE_MSK) {
1237 case PHY_B_AS_PAUSE_MSK:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001238 skge->flow_status = FLOW_STAT_SYMMETRIC;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001239 break;
1240 case PHY_B_AS_PRR:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001241 skge->flow_status = FLOW_STAT_REM_SEND;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001242 break;
1243 case PHY_B_AS_PRT:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001244 skge->flow_status = FLOW_STAT_LOC_SEND;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001245 break;
1246 default:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001247 skge->flow_status = FLOW_STAT_NONE;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001248 }
1249 skge->speed = SPEED_1000;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001250 }
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001251
1252 if (!netif_carrier_ok(dev))
1253 genesis_link_up(skge);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001254}
1255
1256/* Broadcom 5400 only supports giagabit! SysKonnect did not put an additional
1257 * Phy on for 100 or 10Mbit operation
1258 */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001259static void bcom_phy_init(struct skge_port *skge)
Stephen Hemminger45bada62005-06-27 11:33:12 -07001260{
1261 struct skge_hw *hw = skge->hw;
1262 int port = skge->port;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001263 int i;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001264 u16 id1, r, ext, ctl;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001265
1266 /* magic workaround patterns for Broadcom */
1267 static const struct {
1268 u16 reg;
1269 u16 val;
1270 } A1hack[] = {
1271 { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1104 },
1272 { 0x17, 0x0013 }, { 0x15, 0x0404 }, { 0x17, 0x8006 },
1273 { 0x15, 0x0132 }, { 0x17, 0x8006 }, { 0x15, 0x0232 },
1274 { 0x17, 0x800D }, { 0x15, 0x000F }, { 0x18, 0x0420 },
1275 }, C0hack[] = {
1276 { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1204 },
1277 { 0x17, 0x0013 }, { 0x15, 0x0A04 }, { 0x18, 0x0420 },
1278 };
1279
Stephen Hemminger45bada62005-06-27 11:33:12 -07001280 /* read Id from external PHY (all have the same address) */
1281 id1 = xm_phy_read(hw, port, PHY_XMAC_ID1);
1282
1283 /* Optimize MDIO transfer by suppressing preamble. */
1284 r = xm_read16(hw, port, XM_MMU_CMD);
1285 r |= XM_MMU_NO_PRE;
Joe Perches67777f92010-02-17 15:01:58 +00001286 xm_write16(hw, port, XM_MMU_CMD, r);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001287
Stephen Hemminger2c668512005-07-22 16:26:07 -07001288 switch (id1) {
Stephen Hemminger45bada62005-06-27 11:33:12 -07001289 case PHY_BCOM_ID1_C0:
1290 /*
1291 * Workaround BCOM Errata for the C0 type.
1292 * Write magic patterns to reserved registers.
1293 */
1294 for (i = 0; i < ARRAY_SIZE(C0hack); i++)
1295 xm_phy_write(hw, port,
1296 C0hack[i].reg, C0hack[i].val);
1297
1298 break;
1299 case PHY_BCOM_ID1_A1:
1300 /*
1301 * Workaround BCOM Errata for the A1 type.
1302 * Write magic patterns to reserved registers.
1303 */
1304 for (i = 0; i < ARRAY_SIZE(A1hack); i++)
1305 xm_phy_write(hw, port,
1306 A1hack[i].reg, A1hack[i].val);
1307 break;
1308 }
1309
1310 /*
1311 * Workaround BCOM Errata (#10523) for all BCom PHYs.
1312 * Disable Power Management after reset.
1313 */
1314 r = xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL);
1315 r |= PHY_B_AC_DIS_PM;
1316 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, r);
1317
1318 /* Dummy read */
1319 xm_read16(hw, port, XM_ISRC);
1320
1321 ext = PHY_B_PEC_EN_LTR; /* enable tx led */
1322 ctl = PHY_CT_SP1000; /* always 1000mbit */
1323
1324 if (skge->autoneg == AUTONEG_ENABLE) {
1325 /*
1326 * Workaround BCOM Errata #1 for the C5 type.
1327 * 1000Base-T Link Acquisition Failure in Slave Mode
1328 * Set Repeater/DTE bit 10 of the 1000Base-T Control Register
1329 */
1330 u16 adv = PHY_B_1000C_RD;
1331 if (skge->advertising & ADVERTISED_1000baseT_Half)
1332 adv |= PHY_B_1000C_AHD;
1333 if (skge->advertising & ADVERTISED_1000baseT_Full)
1334 adv |= PHY_B_1000C_AFD;
1335 xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, adv);
1336
1337 ctl |= PHY_CT_ANE | PHY_CT_RE_CFG;
1338 } else {
1339 if (skge->duplex == DUPLEX_FULL)
1340 ctl |= PHY_CT_DUP_MD;
1341 /* Force to slave */
1342 xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, PHY_B_1000C_MSE);
1343 }
1344
1345 /* Set autonegotiation pause parameters */
1346 xm_phy_write(hw, port, PHY_BCOM_AUNE_ADV,
1347 phy_pause_map[skge->flow_control] | PHY_AN_CSMA);
1348
1349 /* Handle Jumbo frames */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001350 if (hw->dev[port]->mtu > ETH_DATA_LEN) {
Stephen Hemminger45bada62005-06-27 11:33:12 -07001351 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1352 PHY_B_AC_TX_TST | PHY_B_AC_LONG_PACK);
1353
1354 ext |= PHY_B_PEC_HIGH_LA;
1355
1356 }
1357
1358 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, ext);
1359 xm_phy_write(hw, port, PHY_BCOM_CTRL, ctl);
1360
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08001361 /* Use link status change interrupt */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001362 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001363}
Stephen Hemminger45bada62005-06-27 11:33:12 -07001364
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001365static void xm_phy_init(struct skge_port *skge)
1366{
1367 struct skge_hw *hw = skge->hw;
1368 int port = skge->port;
1369 u16 ctrl = 0;
1370
1371 if (skge->autoneg == AUTONEG_ENABLE) {
1372 if (skge->advertising & ADVERTISED_1000baseT_Half)
1373 ctrl |= PHY_X_AN_HD;
1374 if (skge->advertising & ADVERTISED_1000baseT_Full)
1375 ctrl |= PHY_X_AN_FD;
1376
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001377 ctrl |= fiber_pause_map[skge->flow_control];
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001378
1379 xm_phy_write(hw, port, PHY_XMAC_AUNE_ADV, ctrl);
1380
1381 /* Restart Auto-negotiation */
1382 ctrl = PHY_CT_ANE | PHY_CT_RE_CFG;
1383 } else {
1384 /* Set DuplexMode in Config register */
1385 if (skge->duplex == DUPLEX_FULL)
1386 ctrl |= PHY_CT_DUP_MD;
1387 /*
1388 * Do NOT enable Auto-negotiation here. This would hold
1389 * the link down because no IDLEs are transmitted
1390 */
1391 }
1392
1393 xm_phy_write(hw, port, PHY_XMAC_CTRL, ctrl);
1394
1395 /* Poll PHY for status changes */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07001396 mod_timer(&skge->link_timer, jiffies + LINK_HZ);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001397}
1398
Stephen Hemminger501fb722007-10-16 12:15:51 -07001399static int xm_check_link(struct net_device *dev)
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001400{
1401 struct skge_port *skge = netdev_priv(dev);
1402 struct skge_hw *hw = skge->hw;
1403 int port = skge->port;
1404 u16 status;
1405
1406 /* read twice because of latch */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001407 xm_phy_read(hw, port, PHY_XMAC_STAT);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001408 status = xm_phy_read(hw, port, PHY_XMAC_STAT);
1409
1410 if ((status & PHY_ST_LSYNC) == 0) {
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001411 xm_link_down(hw, port);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001412 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001413 }
1414
1415 if (skge->autoneg == AUTONEG_ENABLE) {
1416 u16 lpa, res;
1417
1418 if (!(status & PHY_ST_AN_OVER))
Stephen Hemminger501fb722007-10-16 12:15:51 -07001419 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001420
1421 lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP);
1422 if (lpa & PHY_B_AN_RF) {
Joe Perchesf15063c2010-02-17 15:01:57 +00001423 netdev_notice(dev, "remote fault\n");
Stephen Hemminger501fb722007-10-16 12:15:51 -07001424 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001425 }
1426
1427 res = xm_phy_read(hw, port, PHY_XMAC_RES_ABI);
1428
1429 /* Check Duplex mismatch */
1430 switch (res & (PHY_X_RS_HD | PHY_X_RS_FD)) {
1431 case PHY_X_RS_FD:
1432 skge->duplex = DUPLEX_FULL;
1433 break;
1434 case PHY_X_RS_HD:
1435 skge->duplex = DUPLEX_HALF;
1436 break;
1437 default:
Joe Perchesf15063c2010-02-17 15:01:57 +00001438 netdev_notice(dev, "duplex mismatch\n");
Stephen Hemminger501fb722007-10-16 12:15:51 -07001439 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001440 }
1441
1442 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001443 if ((skge->flow_control == FLOW_MODE_SYMMETRIC ||
1444 skge->flow_control == FLOW_MODE_SYM_OR_REM) &&
1445 (lpa & PHY_X_P_SYM_MD))
1446 skge->flow_status = FLOW_STAT_SYMMETRIC;
1447 else if (skge->flow_control == FLOW_MODE_SYM_OR_REM &&
1448 (lpa & PHY_X_RS_PAUSE) == PHY_X_P_ASYM_MD)
1449 /* Enable PAUSE receive, disable PAUSE transmit */
1450 skge->flow_status = FLOW_STAT_REM_SEND;
1451 else if (skge->flow_control == FLOW_MODE_LOC_SEND &&
1452 (lpa & PHY_X_RS_PAUSE) == PHY_X_P_BOTH_MD)
1453 /* Disable PAUSE receive, enable PAUSE transmit */
1454 skge->flow_status = FLOW_STAT_LOC_SEND;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001455 else
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001456 skge->flow_status = FLOW_STAT_NONE;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001457
1458 skge->speed = SPEED_1000;
1459 }
1460
1461 if (!netif_carrier_ok(dev))
1462 genesis_link_up(skge);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001463 return 1;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001464}
1465
1466/* Poll to check for link coming up.
Stephen Hemminger501fb722007-10-16 12:15:51 -07001467 *
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001468 * Since internal PHY is wired to a level triggered pin, can't
Stephen Hemminger501fb722007-10-16 12:15:51 -07001469 * get an interrupt when carrier is detected, need to poll for
1470 * link coming up.
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001471 */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07001472static void xm_link_timer(unsigned long arg)
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001473{
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07001474 struct skge_port *skge = (struct skge_port *) arg;
David Howellsc4028952006-11-22 14:57:56 +00001475 struct net_device *dev = skge->netdev;
Joe Perches67777f92010-02-17 15:01:58 +00001476 struct skge_hw *hw = skge->hw;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001477 int port = skge->port;
Stephen Hemminger501fb722007-10-16 12:15:51 -07001478 int i;
1479 unsigned long flags;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001480
1481 if (!netif_running(dev))
1482 return;
1483
Stephen Hemminger501fb722007-10-16 12:15:51 -07001484 spin_lock_irqsave(&hw->phy_lock, flags);
1485
1486 /*
1487 * Verify that the link by checking GPIO register three times.
1488 * This pin has the signal from the link_sync pin connected to it.
1489 */
1490 for (i = 0; i < 3; i++) {
1491 if (xm_read16(hw, port, XM_GP_PORT) & XM_GP_INP_ASS)
1492 goto link_down;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001493 }
1494
Joe Perches67777f92010-02-17 15:01:58 +00001495 /* Re-enable interrupt to detect link down */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001496 if (xm_check_link(dev)) {
1497 u16 msk = xm_read16(hw, port, XM_IMSK);
1498 msk &= ~XM_IS_INP_ASS;
1499 xm_write16(hw, port, XM_IMSK, msk);
1500 xm_read16(hw, port, XM_ISRC);
1501 } else {
1502link_down:
1503 mod_timer(&skge->link_timer,
1504 round_jiffies(jiffies + LINK_HZ));
1505 }
1506 spin_unlock_irqrestore(&hw->phy_lock, flags);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001507}
1508
1509static void genesis_mac_init(struct skge_hw *hw, int port)
1510{
1511 struct net_device *dev = hw->dev[port];
1512 struct skge_port *skge = netdev_priv(dev);
1513 int jumbo = hw->dev[port]->mtu > ETH_DATA_LEN;
1514 int i;
1515 u32 r;
Joe Perchesb6bc7652010-12-21 02:16:08 -08001516 static const u8 zero[6] = { 0 };
Stephen Hemminger45bada62005-06-27 11:33:12 -07001517
Stephen Hemminger07811912006-02-22 10:28:34 -08001518 for (i = 0; i < 10; i++) {
1519 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1),
1520 MFF_SET_MAC_RST);
1521 if (skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST)
1522 goto reset_ok;
1523 udelay(1);
1524 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001525
Joe Perchesf15063c2010-02-17 15:01:57 +00001526 netdev_warn(dev, "genesis reset failed\n");
Stephen Hemminger07811912006-02-22 10:28:34 -08001527
1528 reset_ok:
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001529 /* Unreset the XMAC. */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001530 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001531
1532 /*
1533 * Perform additional initialization for external PHYs,
1534 * namely for the 1000baseTX cards that use the XMAC's
1535 * GMII mode.
1536 */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001537 if (hw->phy_type != SK_PHY_XMAC) {
1538 /* Take external Phy out of reset */
1539 r = skge_read32(hw, B2_GP_IO);
1540 if (port == 0)
1541 r |= GP_DIR_0|GP_IO_0;
1542 else
1543 r |= GP_DIR_2|GP_IO_2;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001544
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001545 skge_write32(hw, B2_GP_IO, r);
1546
1547 /* Enable GMII interface */
1548 xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD);
1549 }
Stephen Hemminger07811912006-02-22 10:28:34 -08001550
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001551
Joe Perches67777f92010-02-17 15:01:58 +00001552 switch (hw->phy_type) {
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001553 case SK_PHY_XMAC:
1554 xm_phy_init(skge);
1555 break;
1556 case SK_PHY_BCOM:
1557 bcom_phy_init(skge);
1558 bcom_check_link(hw, port);
1559 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001560
Stephen Hemminger45bada62005-06-27 11:33:12 -07001561 /* Set Station Address */
1562 xm_outaddr(hw, port, XM_SA, dev->dev_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001563
Stephen Hemminger45bada62005-06-27 11:33:12 -07001564 /* We don't use match addresses so clear */
1565 for (i = 1; i < 16; i++)
1566 xm_outaddr(hw, port, XM_EXM(i), zero);
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001567
Stephen Hemminger07811912006-02-22 10:28:34 -08001568 /* Clear MIB counters */
1569 xm_write16(hw, port, XM_STAT_CMD,
1570 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1571 /* Clear two times according to Errata #3 */
1572 xm_write16(hw, port, XM_STAT_CMD,
1573 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1574
Stephen Hemminger45bada62005-06-27 11:33:12 -07001575 /* configure Rx High Water Mark (XM_RX_HI_WM) */
1576 xm_write16(hw, port, XM_RX_HI_WM, 1450);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001577
1578 /* We don't need the FCS appended to the packet. */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001579 r = XM_RX_LENERR_OK | XM_RX_STRIP_FCS;
1580 if (jumbo)
1581 r |= XM_RX_BIG_PK_OK;
1582
1583 if (skge->duplex == DUPLEX_HALF) {
1584 /*
1585 * If in manual half duplex mode the other side might be in
1586 * full duplex mode, so ignore if a carrier extension is not seen
1587 * on frames received
1588 */
1589 r |= XM_RX_DIS_CEXT;
1590 }
1591 xm_write16(hw, port, XM_RX_CMD, r);
1592
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001593 /* We want short frames padded to 60 bytes. */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001594 xm_write16(hw, port, XM_TX_CMD, XM_TX_AUTO_PAD);
1595
Stephen Hemminger485982a2007-11-26 11:54:52 -08001596 /* Increase threshold for jumbo frames on dual port */
1597 if (hw->ports > 1 && jumbo)
1598 xm_write16(hw, port, XM_TX_THR, 1020);
1599 else
1600 xm_write16(hw, port, XM_TX_THR, 512);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001601
1602 /*
1603 * Enable the reception of all error frames. This is is
1604 * a necessary evil due to the design of the XMAC. The
1605 * XMAC's receive FIFO is only 8K in size, however jumbo
1606 * frames can be up to 9000 bytes in length. When bad
1607 * frame filtering is enabled, the XMAC's RX FIFO operates
1608 * in 'store and forward' mode. For this to work, the
1609 * entire frame has to fit into the FIFO, but that means
1610 * that jumbo frames larger than 8192 bytes will be
1611 * truncated. Disabling all bad frame filtering causes
1612 * the RX FIFO to operate in streaming mode, in which
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08001613 * case the XMAC will start transferring frames out of the
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001614 * RX FIFO as soon as the FIFO threshold is reached.
1615 */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001616 xm_write32(hw, port, XM_MODE, XM_DEF_MODE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001617
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001618
1619 /*
Stephen Hemminger45bada62005-06-27 11:33:12 -07001620 * Initialize the Receive Counter Event Mask (XM_RX_EV_MSK)
1621 * - Enable all bits excepting 'Octets Rx OK Low CntOv'
1622 * and 'Octets Rx OK Hi Cnt Ov'.
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001623 */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001624 xm_write32(hw, port, XM_RX_EV_MSK, XMR_DEF_MSK);
1625
1626 /*
1627 * Initialize the Transmit Counter Event Mask (XM_TX_EV_MSK)
1628 * - Enable all bits excepting 'Octets Tx OK Low CntOv'
1629 * and 'Octets Tx OK Hi Cnt Ov'.
1630 */
1631 xm_write32(hw, port, XM_TX_EV_MSK, XMT_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001632
1633 /* Configure MAC arbiter */
1634 skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR);
1635
1636 /* configure timeout values */
1637 skge_write8(hw, B3_MA_TOINI_RX1, 72);
1638 skge_write8(hw, B3_MA_TOINI_RX2, 72);
1639 skge_write8(hw, B3_MA_TOINI_TX1, 72);
1640 skge_write8(hw, B3_MA_TOINI_TX2, 72);
1641
1642 skge_write8(hw, B3_MA_RCINI_RX1, 0);
1643 skge_write8(hw, B3_MA_RCINI_RX2, 0);
1644 skge_write8(hw, B3_MA_RCINI_TX1, 0);
1645 skge_write8(hw, B3_MA_RCINI_TX2, 0);
1646
1647 /* Configure Rx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001648 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_CLR);
1649 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_TIM_PAT);
1650 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_ENA_OP_MD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001651
1652 /* Configure Tx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001653 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_CLR);
1654 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF);
1655 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_ENA_OP_MD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001656
Stephen Hemminger45bada62005-06-27 11:33:12 -07001657 if (jumbo) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001658 /* Enable frame flushing if jumbo frames used */
Joe Perches67777f92010-02-17 15:01:58 +00001659 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_FLUSH);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001660 } else {
1661 /* enable timeout timers if normal frames */
1662 skge_write16(hw, B3_PA_CTRL,
Stephen Hemminger45bada62005-06-27 11:33:12 -07001663 (port == 0) ? PA_ENA_TO_TX1 : PA_ENA_TO_TX2);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001664 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001665}
1666
1667static void genesis_stop(struct skge_port *skge)
1668{
1669 struct skge_hw *hw = skge->hw;
1670 int port = skge->port;
Stephen Hemminger799b21d2007-11-26 11:54:50 -08001671 unsigned retries = 1000;
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001672 u16 cmd;
1673
Joe Perches67777f92010-02-17 15:01:58 +00001674 /* Disable Tx and Rx */
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001675 cmd = xm_read16(hw, port, XM_MMU_CMD);
1676 cmd &= ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1677 xm_write16(hw, port, XM_MMU_CMD, cmd);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001678
Stephen Hemminger46a60f22005-09-09 12:54:56 -07001679 genesis_reset(hw, port);
1680
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001681 /* Clear Tx packet arbiter timeout IRQ */
1682 skge_write16(hw, B3_PA_CTRL,
1683 port == 0 ? PA_CLR_TO_TX1 : PA_CLR_TO_TX2);
1684
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001685 /* Reset the MAC */
Stephen Hemminger799b21d2007-11-26 11:54:50 -08001686 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
1687 do {
1688 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST);
1689 if (!(skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST))
1690 break;
1691 } while (--retries > 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001692
1693 /* For external PHYs there must be special handling */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001694 if (hw->phy_type != SK_PHY_XMAC) {
Stephen Hemminger799b21d2007-11-26 11:54:50 -08001695 u32 reg = skge_read32(hw, B2_GP_IO);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001696 if (port == 0) {
1697 reg |= GP_DIR_0;
1698 reg &= ~GP_IO_0;
1699 } else {
1700 reg |= GP_DIR_2;
1701 reg &= ~GP_IO_2;
1702 }
1703 skge_write32(hw, B2_GP_IO, reg);
1704 skge_read32(hw, B2_GP_IO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001705 }
1706
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001707 xm_write16(hw, port, XM_MMU_CMD,
1708 xm_read16(hw, port, XM_MMU_CMD)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001709 & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX));
1710
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001711 xm_read16(hw, port, XM_MMU_CMD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001712}
1713
1714
1715static void genesis_get_stats(struct skge_port *skge, u64 *data)
1716{
1717 struct skge_hw *hw = skge->hw;
1718 int port = skge->port;
1719 int i;
1720 unsigned long timeout = jiffies + HZ;
1721
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001722 xm_write16(hw, port,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001723 XM_STAT_CMD, XM_SC_SNP_TXC | XM_SC_SNP_RXC);
1724
1725 /* wait for update to complete */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001726 while (xm_read16(hw, port, XM_STAT_CMD)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001727 & (XM_SC_SNP_TXC | XM_SC_SNP_RXC)) {
1728 if (time_after(jiffies, timeout))
1729 break;
1730 udelay(10);
1731 }
1732
1733 /* special case for 64 bit octet counter */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001734 data[0] = (u64) xm_read32(hw, port, XM_TXO_OK_HI) << 32
1735 | xm_read32(hw, port, XM_TXO_OK_LO);
1736 data[1] = (u64) xm_read32(hw, port, XM_RXO_OK_HI) << 32
1737 | xm_read32(hw, port, XM_RXO_OK_LO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001738
1739 for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001740 data[i] = xm_read32(hw, port, skge_stats[i].xmac_offset);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001741}
1742
1743static void genesis_mac_intr(struct skge_hw *hw, int port)
1744{
Stephen Hemmingerda007722007-10-16 12:15:52 -07001745 struct net_device *dev = hw->dev[port];
1746 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001747 u16 status = xm_read16(hw, port, XM_ISRC);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001748
Joe Perchesd7072042010-02-09 11:49:53 +00001749 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
1750 "mac interrupt status 0x%x\n", status);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001751
Stephen Hemminger501fb722007-10-16 12:15:51 -07001752 if (hw->phy_type == SK_PHY_XMAC && (status & XM_IS_INP_ASS)) {
Joe Perches67777f92010-02-17 15:01:58 +00001753 xm_link_down(hw, port);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001754 mod_timer(&skge->link_timer, jiffies + 1);
1755 }
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001756
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001757 if (status & XM_IS_TXF_UR) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001758 xm_write32(hw, port, XM_MODE, XM_MD_FTF);
Stephen Hemmingerda007722007-10-16 12:15:52 -07001759 ++dev->stats.tx_fifo_errors;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001760 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001761}
1762
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001763static void genesis_link_up(struct skge_port *skge)
1764{
1765 struct skge_hw *hw = skge->hw;
1766 int port = skge->port;
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001767 u16 cmd, msk;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001768 u32 mode;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001769
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001770 cmd = xm_read16(hw, port, XM_MMU_CMD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001771
1772 /*
1773 * enabling pause frame reception is required for 1000BT
1774 * because the XMAC is not reset if the link is going down
1775 */
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001776 if (skge->flow_status == FLOW_STAT_NONE ||
1777 skge->flow_status == FLOW_STAT_LOC_SEND)
Stephen Hemminger7e676d92005-06-27 11:33:13 -07001778 /* Disable Pause Frame Reception */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001779 cmd |= XM_MMU_IGN_PF;
1780 else
1781 /* Enable Pause Frame Reception */
1782 cmd &= ~XM_MMU_IGN_PF;
1783
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001784 xm_write16(hw, port, XM_MMU_CMD, cmd);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001785
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001786 mode = xm_read32(hw, port, XM_MODE);
Joe Perches67777f92010-02-17 15:01:58 +00001787 if (skge->flow_status == FLOW_STAT_SYMMETRIC ||
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001788 skge->flow_status == FLOW_STAT_LOC_SEND) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001789 /*
1790 * Configure Pause Frame Generation
1791 * Use internal and external Pause Frame Generation.
1792 * Sending pause frames is edge triggered.
1793 * Send a Pause frame with the maximum pause time if
1794 * internal oder external FIFO full condition occurs.
1795 * Send a zero pause time frame to re-start transmission.
1796 */
1797 /* XM_PAUSE_DA = '010000C28001' (default) */
1798 /* XM_MAC_PTIME = 0xffff (maximum) */
1799 /* remember this value is defined in big endian (!) */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001800 xm_write16(hw, port, XM_MAC_PTIME, 0xffff);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001801
1802 mode |= XM_PAUSE_MODE;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001803 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_PAUSE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001804 } else {
1805 /*
1806 * disable pause frame generation is required for 1000BT
1807 * because the XMAC is not reset if the link is going down
1808 */
1809 /* Disable Pause Mode in Mode Register */
1810 mode &= ~XM_PAUSE_MODE;
1811
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001812 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_DIS_PAUSE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001813 }
1814
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001815 xm_write32(hw, port, XM_MODE, mode);
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001816
Stephen Hemmingerd08b9bd2007-11-26 11:54:49 -08001817 /* Turn on detection of Tx underrun */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001818 msk = xm_read16(hw, port, XM_IMSK);
Stephen Hemmingerd08b9bd2007-11-26 11:54:49 -08001819 msk &= ~XM_IS_TXF_UR;
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001820 xm_write16(hw, port, XM_IMSK, msk);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001821
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001822 xm_read16(hw, port, XM_ISRC);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001823
1824 /* get MMU Command Reg. */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001825 cmd = xm_read16(hw, port, XM_MMU_CMD);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001826 if (hw->phy_type != SK_PHY_XMAC && skge->duplex == DUPLEX_FULL)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001827 cmd |= XM_MMU_GMII_FD;
1828
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001829 /*
1830 * Workaround BCOM Errata (#10523) for all BCom Phys
1831 * Enable Power Management after link up
1832 */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001833 if (hw->phy_type == SK_PHY_BCOM) {
1834 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1835 xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL)
1836 & ~PHY_B_AC_DIS_PM);
1837 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
1838 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001839
1840 /* enable Rx/Tx */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001841 xm_write16(hw, port, XM_MMU_CMD,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001842 cmd | XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1843 skge_link_up(skge);
1844}
1845
1846
Stephen Hemminger45bada62005-06-27 11:33:12 -07001847static inline void bcom_phy_intr(struct skge_port *skge)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001848{
1849 struct skge_hw *hw = skge->hw;
1850 int port = skge->port;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001851 u16 isrc;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001852
Stephen Hemminger45bada62005-06-27 11:33:12 -07001853 isrc = xm_phy_read(hw, port, PHY_BCOM_INT_STAT);
Joe Perchesd7072042010-02-09 11:49:53 +00001854 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
1855 "phy interrupt status 0x%x\n", isrc);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001856
1857 if (isrc & PHY_B_IS_PSE)
Joe Perchesf15063c2010-02-17 15:01:57 +00001858 pr_err("%s: uncorrectable pair swap error\n",
Stephen Hemminger45bada62005-06-27 11:33:12 -07001859 hw->dev[port]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001860
1861 /* Workaround BCom Errata:
1862 * enable and disable loopback mode if "NO HCD" occurs.
1863 */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001864 if (isrc & PHY_B_IS_NO_HDCL) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001865 u16 ctrl = xm_phy_read(hw, port, PHY_BCOM_CTRL);
1866 xm_phy_write(hw, port, PHY_BCOM_CTRL,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001867 ctrl | PHY_CT_LOOP);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001868 xm_phy_write(hw, port, PHY_BCOM_CTRL,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001869 ctrl & ~PHY_CT_LOOP);
1870 }
1871
Stephen Hemminger45bada62005-06-27 11:33:12 -07001872 if (isrc & (PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE))
1873 bcom_check_link(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001874
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001875}
1876
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001877static int gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
1878{
1879 int i;
1880
1881 gma_write16(hw, port, GM_SMI_DATA, val);
1882 gma_write16(hw, port, GM_SMI_CTRL,
1883 GM_SMI_CT_PHY_AD(hw->phy_addr) | GM_SMI_CT_REG_AD(reg));
1884 for (i = 0; i < PHY_RETRIES; i++) {
1885 udelay(1);
1886
1887 if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY))
1888 return 0;
1889 }
1890
Joe Perchesf15063c2010-02-17 15:01:57 +00001891 pr_warning("%s: phy write timeout\n", hw->dev[port]->name);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001892 return -EIO;
1893}
1894
1895static int __gm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val)
1896{
1897 int i;
1898
1899 gma_write16(hw, port, GM_SMI_CTRL,
1900 GM_SMI_CT_PHY_AD(hw->phy_addr)
1901 | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD);
1902
1903 for (i = 0; i < PHY_RETRIES; i++) {
1904 udelay(1);
1905 if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL)
1906 goto ready;
1907 }
1908
1909 return -ETIMEDOUT;
1910 ready:
1911 *val = gma_read16(hw, port, GM_SMI_DATA);
1912 return 0;
1913}
1914
1915static u16 gm_phy_read(struct skge_hw *hw, int port, u16 reg)
1916{
1917 u16 v = 0;
1918 if (__gm_phy_read(hw, port, reg, &v))
Joe Perchesf15063c2010-02-17 15:01:57 +00001919 pr_warning("%s: phy read timeout\n", hw->dev[port]->name);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001920 return v;
1921}
1922
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08001923/* Marvell Phy Initialization */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001924static void yukon_init(struct skge_hw *hw, int port)
1925{
1926 struct skge_port *skge = netdev_priv(hw->dev[port]);
1927 u16 ctrl, ct1000, adv;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001928
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001929 if (skge->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001930 u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001931
1932 ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
1933 PHY_M_EC_MAC_S_MSK);
1934 ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ);
1935
Stephen Hemmingerc506a502005-06-27 11:33:09 -07001936 ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001937
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001938 gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001939 }
1940
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001941 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001942 if (skge->autoneg == AUTONEG_DISABLE)
1943 ctrl &= ~PHY_CT_ANE;
1944
1945 ctrl |= PHY_CT_RESET;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001946 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001947
1948 ctrl = 0;
1949 ct1000 = 0;
Stephen Hemmingerb18f2092005-06-27 11:33:08 -07001950 adv = PHY_AN_CSMA;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001951
1952 if (skge->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07001953 if (hw->copper) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001954 if (skge->advertising & ADVERTISED_1000baseT_Full)
1955 ct1000 |= PHY_M_1000C_AFD;
1956 if (skge->advertising & ADVERTISED_1000baseT_Half)
1957 ct1000 |= PHY_M_1000C_AHD;
1958 if (skge->advertising & ADVERTISED_100baseT_Full)
1959 adv |= PHY_M_AN_100_FD;
1960 if (skge->advertising & ADVERTISED_100baseT_Half)
1961 adv |= PHY_M_AN_100_HD;
1962 if (skge->advertising & ADVERTISED_10baseT_Full)
1963 adv |= PHY_M_AN_10_FD;
1964 if (skge->advertising & ADVERTISED_10baseT_Half)
1965 adv |= PHY_M_AN_10_HD;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001966
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001967 /* Set Flow-control capabilities */
1968 adv |= phy_pause_map[skge->flow_control];
1969 } else {
1970 if (skge->advertising & ADVERTISED_1000baseT_Full)
1971 adv |= PHY_M_AN_1000X_AFD;
1972 if (skge->advertising & ADVERTISED_1000baseT_Half)
1973 adv |= PHY_M_AN_1000X_AHD;
1974
1975 adv |= fiber_pause_map[skge->flow_control];
1976 }
Stephen Hemminger45bada62005-06-27 11:33:12 -07001977
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001978 /* Restart Auto-negotiation */
1979 ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG;
1980 } else {
1981 /* forced speed/duplex settings */
1982 ct1000 = PHY_M_1000C_MSE;
1983
1984 if (skge->duplex == DUPLEX_FULL)
1985 ctrl |= PHY_CT_DUP_MD;
1986
1987 switch (skge->speed) {
1988 case SPEED_1000:
1989 ctrl |= PHY_CT_SP1000;
1990 break;
1991 case SPEED_100:
1992 ctrl |= PHY_CT_SP100;
1993 break;
1994 }
1995
1996 ctrl |= PHY_CT_RESET;
1997 }
1998
Stephen Hemmingerc506a502005-06-27 11:33:09 -07001999 gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002000
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002001 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv);
2002 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002003
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002004 /* Enable phy interrupt on autonegotiation complete (or link up) */
2005 if (skge->autoneg == AUTONEG_ENABLE)
Stephen Hemminger4cde06e2005-07-22 16:26:09 -07002006 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002007 else
Stephen Hemminger4cde06e2005-07-22 16:26:09 -07002008 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002009}
2010
2011static void yukon_reset(struct skge_hw *hw, int port)
2012{
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002013 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);/* disable PHY IRQs */
2014 gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */
2015 gma_write16(hw, port, GM_MC_ADDR_H2, 0);
2016 gma_write16(hw, port, GM_MC_ADDR_H3, 0);
2017 gma_write16(hw, port, GM_MC_ADDR_H4, 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002018
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002019 gma_write16(hw, port, GM_RX_CTRL,
2020 gma_read16(hw, port, GM_RX_CTRL)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002021 | GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
2022}
2023
Stephen Hemmingerc8868612005-09-23 09:08:30 -07002024/* Apparently, early versions of Yukon-Lite had wrong chip_id? */
2025static int is_yukon_lite_a0(struct skge_hw *hw)
2026{
2027 u32 reg;
2028 int ret;
2029
2030 if (hw->chip_id != CHIP_ID_YUKON)
2031 return 0;
2032
2033 reg = skge_read32(hw, B2_FAR);
2034 skge_write8(hw, B2_FAR + 3, 0xff);
2035 ret = (skge_read8(hw, B2_FAR + 3) != 0);
2036 skge_write32(hw, B2_FAR, reg);
2037 return ret;
2038}
2039
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002040static void yukon_mac_init(struct skge_hw *hw, int port)
2041{
2042 struct skge_port *skge = netdev_priv(hw->dev[port]);
2043 int i;
2044 u32 reg;
2045 const u8 *addr = hw->dev[port]->dev_addr;
2046
2047 /* WA code for COMA mode -- set PHY reset */
2048 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002049 hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
2050 reg = skge_read32(hw, B2_GP_IO);
2051 reg |= GP_DIR_9 | GP_IO_9;
2052 skge_write32(hw, B2_GP_IO, reg);
2053 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002054
2055 /* hard reset */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002056 skge_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
2057 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002058
2059 /* WA code for COMA mode -- clear PHY reset */
2060 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002061 hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
2062 reg = skge_read32(hw, B2_GP_IO);
2063 reg |= GP_DIR_9;
2064 reg &= ~GP_IO_9;
2065 skge_write32(hw, B2_GP_IO, reg);
2066 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002067
2068 /* Set hardware config mode */
2069 reg = GPC_INT_POL_HI | GPC_DIS_FC | GPC_DIS_SLEEP |
2070 GPC_ENA_XC | GPC_ANEG_ADV_ALL_M | GPC_ENA_PAUSE;
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07002071 reg |= hw->copper ? GPC_HWCFG_GMII_COP : GPC_HWCFG_GMII_FIB;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002072
2073 /* Clear GMC reset */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002074 skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_SET);
2075 skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_CLR);
2076 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR);
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002077
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002078 if (skge->autoneg == AUTONEG_DISABLE) {
2079 reg = GM_GPCR_AU_ALL_DIS;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002080 gma_write16(hw, port, GM_GP_CTRL,
2081 gma_read16(hw, port, GM_GP_CTRL) | reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002082
2083 switch (skge->speed) {
2084 case SPEED_1000:
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002085 reg &= ~GM_GPCR_SPEED_100;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002086 reg |= GM_GPCR_SPEED_1000;
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002087 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002088 case SPEED_100:
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002089 reg &= ~GM_GPCR_SPEED_1000;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002090 reg |= GM_GPCR_SPEED_100;
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002091 break;
2092 case SPEED_10:
2093 reg &= ~(GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100);
2094 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002095 }
2096
2097 if (skge->duplex == DUPLEX_FULL)
2098 reg |= GM_GPCR_DUP_FULL;
2099 } else
2100 reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL;
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002101
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002102 switch (skge->flow_control) {
2103 case FLOW_MODE_NONE:
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002104 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002105 reg |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
2106 break;
2107 case FLOW_MODE_LOC_SEND:
2108 /* disable Rx flow-control */
2109 reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002110 break;
2111 case FLOW_MODE_SYMMETRIC:
2112 case FLOW_MODE_SYM_OR_REM:
2113 /* enable Tx & Rx flow-control */
2114 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002115 }
2116
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002117 gma_write16(hw, port, GM_GP_CTRL, reg);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002118 skge_read16(hw, SK_REG(port, GMAC_IRQ_SRC));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002119
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002120 yukon_init(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002121
2122 /* MIB clear */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002123 reg = gma_read16(hw, port, GM_PHY_ADDR);
2124 gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002125
2126 for (i = 0; i < GM_MIB_CNT_SIZE; i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002127 gma_read16(hw, port, GM_MIB_CNT_BASE + 8*i);
2128 gma_write16(hw, port, GM_PHY_ADDR, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002129
2130 /* transmit control */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002131 gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002132
2133 /* receive control reg: unicast + multicast + no FCS */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002134 gma_write16(hw, port, GM_RX_CTRL,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002135 GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA);
2136
2137 /* transmit flow control */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002138 gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002139
2140 /* transmit parameter */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002141 gma_write16(hw, port, GM_TX_PARAM,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002142 TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) |
2143 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) |
2144 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF));
2145
Stephen Hemminger44c7fcc2007-11-28 14:23:01 -08002146 /* configure the Serial Mode Register */
2147 reg = DATA_BLIND_VAL(DATA_BLIND_DEF)
2148 | GM_SMOD_VLAN_ENA
2149 | IPG_DATA_VAL(IPG_DATA_DEF);
2150
2151 if (hw->dev[port]->mtu > ETH_DATA_LEN)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002152 reg |= GM_SMOD_JUMBO_ENA;
2153
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002154 gma_write16(hw, port, GM_SERIAL_MODE, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002155
2156 /* physical address: used for pause frames */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002157 gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002158 /* virtual address for data */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002159 gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002160
2161 /* enable interrupt mask for counter overflows */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002162 gma_write16(hw, port, GM_TX_IRQ_MSK, 0);
2163 gma_write16(hw, port, GM_RX_IRQ_MSK, 0);
2164 gma_write16(hw, port, GM_TR_IRQ_MSK, 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002165
2166 /* Initialize Mac Fifo */
2167
2168 /* Configure Rx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002169 skge_write16(hw, SK_REG(port, RX_GMF_FL_MSK), RX_FF_FL_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002170 reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
Stephen Hemmingerc8868612005-09-23 09:08:30 -07002171
2172 /* disable Rx GMAC FIFO Flush for YUKON-Lite Rev. A0 only */
2173 if (is_yukon_lite_a0(hw))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002174 reg &= ~GMF_RX_F_FL_ON;
Stephen Hemmingerc8868612005-09-23 09:08:30 -07002175
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002176 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
2177 skge_write16(hw, SK_REG(port, RX_GMF_CTRL_T), reg);
Stephen Hemmingerc5923082005-08-16 14:01:02 -07002178 /*
2179 * because Pause Packet Truncation in GMAC is not working
2180 * we have to increase the Flush Threshold to 64 bytes
2181 * in order to flush pause packets in Rx FIFO on Yukon-1
2182 */
2183 skge_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF+1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002184
2185 /* Configure Tx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002186 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
2187 skge_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002188}
2189
Stephen Hemminger355ec572005-11-08 10:33:43 -08002190/* Go into power down mode */
2191static void yukon_suspend(struct skge_hw *hw, int port)
2192{
2193 u16 ctrl;
2194
2195 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
2196 ctrl |= PHY_M_PC_POL_R_DIS;
2197 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
2198
2199 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
2200 ctrl |= PHY_CT_RESET;
2201 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
2202
2203 /* switch IEEE compatible power down mode on */
2204 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
2205 ctrl |= PHY_CT_PDOWN;
2206 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
2207}
2208
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002209static void yukon_stop(struct skge_port *skge)
2210{
2211 struct skge_hw *hw = skge->hw;
2212 int port = skge->port;
2213
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002214 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
2215 yukon_reset(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002216
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002217 gma_write16(hw, port, GM_GP_CTRL,
2218 gma_read16(hw, port, GM_GP_CTRL)
Stephen Hemminger0eedf4a2005-07-22 16:26:04 -07002219 & ~(GM_GPCR_TX_ENA|GM_GPCR_RX_ENA));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002220 gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002221
Stephen Hemminger355ec572005-11-08 10:33:43 -08002222 yukon_suspend(hw, port);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002223
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002224 /* set GPHY Control reset */
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002225 skge_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
2226 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002227}
2228
2229static void yukon_get_stats(struct skge_port *skge, u64 *data)
2230{
2231 struct skge_hw *hw = skge->hw;
2232 int port = skge->port;
2233 int i;
2234
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002235 data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32
2236 | gma_read32(hw, port, GM_TXO_OK_LO);
2237 data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32
2238 | gma_read32(hw, port, GM_RXO_OK_LO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002239
2240 for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002241 data[i] = gma_read32(hw, port,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002242 skge_stats[i].gma_offset);
2243}
2244
2245static void yukon_mac_intr(struct skge_hw *hw, int port)
2246{
Stephen Hemminger7e676d92005-06-27 11:33:13 -07002247 struct net_device *dev = hw->dev[port];
2248 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002249 u8 status = skge_read8(hw, SK_REG(port, GMAC_IRQ_SRC));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002250
Joe Perchesd7072042010-02-09 11:49:53 +00002251 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
2252 "mac interrupt status 0x%x\n", status);
Stephen Hemminger7e676d92005-06-27 11:33:13 -07002253
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002254 if (status & GM_IS_RX_FF_OR) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07002255 ++dev->stats.rx_fifo_errors;
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002256 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002257 }
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002258
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002259 if (status & GM_IS_TX_FF_UR) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07002260 ++dev->stats.tx_fifo_errors;
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002261 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002262 }
2263
2264}
2265
2266static u16 yukon_speed(const struct skge_hw *hw, u16 aux)
2267{
Stephen Hemminger95566062005-06-27 11:33:02 -07002268 switch (aux & PHY_M_PS_SPEED_MSK) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002269 case PHY_M_PS_SPEED_1000:
2270 return SPEED_1000;
2271 case PHY_M_PS_SPEED_100:
2272 return SPEED_100;
2273 default:
2274 return SPEED_10;
2275 }
2276}
2277
2278static void yukon_link_up(struct skge_port *skge)
2279{
2280 struct skge_hw *hw = skge->hw;
2281 int port = skge->port;
2282 u16 reg;
2283
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002284 /* Enable Transmit FIFO Underrun */
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002285 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002286
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002287 reg = gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002288 if (skge->duplex == DUPLEX_FULL || skge->autoneg == AUTONEG_ENABLE)
2289 reg |= GM_GPCR_DUP_FULL;
2290
2291 /* enable Rx/Tx */
2292 reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002293 gma_write16(hw, port, GM_GP_CTRL, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002294
Stephen Hemminger4cde06e2005-07-22 16:26:09 -07002295 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002296 skge_link_up(skge);
2297}
2298
2299static void yukon_link_down(struct skge_port *skge)
2300{
2301 struct skge_hw *hw = skge->hw;
2302 int port = skge->port;
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002303 u16 ctrl;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002304
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002305 ctrl = gma_read16(hw, port, GM_GP_CTRL);
2306 ctrl &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
2307 gma_write16(hw, port, GM_GP_CTRL, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002308
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002309 if (skge->flow_status == FLOW_STAT_REM_SEND) {
2310 ctrl = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV);
2311 ctrl |= PHY_M_AN_ASP;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002312 /* restore Asymmetric Pause bit */
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002313 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002314 }
2315
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002316 skge_link_down(skge);
2317
2318 yukon_init(hw, port);
2319}
2320
2321static void yukon_phy_intr(struct skge_port *skge)
2322{
2323 struct skge_hw *hw = skge->hw;
2324 int port = skge->port;
2325 const char *reason = NULL;
2326 u16 istatus, phystat;
2327
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002328 istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT);
2329 phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT);
Stephen Hemminger7e676d92005-06-27 11:33:13 -07002330
Joe Perchesd7072042010-02-09 11:49:53 +00002331 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
2332 "phy interrupt status 0x%x 0x%x\n", istatus, phystat);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002333
2334 if (istatus & PHY_M_IS_AN_COMPL) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002335 if (gm_phy_read(hw, port, PHY_MARV_AUNE_LP)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002336 & PHY_M_AN_RF) {
2337 reason = "remote fault";
2338 goto failed;
2339 }
2340
Stephen Hemmingerc506a502005-06-27 11:33:09 -07002341 if (gm_phy_read(hw, port, PHY_MARV_1000T_STAT) & PHY_B_1000S_MSF) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002342 reason = "master/slave fault";
2343 goto failed;
2344 }
2345
2346 if (!(phystat & PHY_M_PS_SPDUP_RES)) {
2347 reason = "speed/duplex";
2348 goto failed;
2349 }
2350
2351 skge->duplex = (phystat & PHY_M_PS_FULL_DUP)
2352 ? DUPLEX_FULL : DUPLEX_HALF;
2353 skge->speed = yukon_speed(hw, phystat);
2354
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002355 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
2356 switch (phystat & PHY_M_PS_PAUSE_MSK) {
2357 case PHY_M_PS_PAUSE_MSK:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002358 skge->flow_status = FLOW_STAT_SYMMETRIC;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002359 break;
2360 case PHY_M_PS_RX_P_EN:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002361 skge->flow_status = FLOW_STAT_REM_SEND;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002362 break;
2363 case PHY_M_PS_TX_P_EN:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002364 skge->flow_status = FLOW_STAT_LOC_SEND;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002365 break;
2366 default:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002367 skge->flow_status = FLOW_STAT_NONE;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002368 }
2369
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002370 if (skge->flow_status == FLOW_STAT_NONE ||
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002371 (skge->speed < SPEED_1000 && skge->duplex == DUPLEX_HALF))
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002372 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002373 else
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002374 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002375 yukon_link_up(skge);
2376 return;
2377 }
2378
2379 if (istatus & PHY_M_IS_LSP_CHANGE)
2380 skge->speed = yukon_speed(hw, phystat);
2381
2382 if (istatus & PHY_M_IS_DUP_CHANGE)
2383 skge->duplex = (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
2384 if (istatus & PHY_M_IS_LST_CHANGE) {
2385 if (phystat & PHY_M_PS_LINK_UP)
2386 yukon_link_up(skge);
2387 else
2388 yukon_link_down(skge);
2389 }
2390 return;
2391 failed:
Joe Perchesf15063c2010-02-17 15:01:57 +00002392 pr_err("%s: autonegotiation failed (%s)\n", skge->netdev->name, reason);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002393
2394 /* XXX restart autonegotiation? */
2395}
2396
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002397static void skge_phy_reset(struct skge_port *skge)
2398{
2399 struct skge_hw *hw = skge->hw;
2400 int port = skge->port;
Jeff Garzikaae343d2006-12-02 07:14:39 -05002401 struct net_device *dev = hw->dev[port];
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002402
2403 netif_stop_queue(skge->netdev);
2404 netif_carrier_off(skge->netdev);
2405
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002406 spin_lock_bh(&hw->phy_lock);
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002407 if (hw->chip_id == CHIP_ID_GENESIS) {
2408 genesis_reset(hw, port);
2409 genesis_mac_init(hw, port);
2410 } else {
2411 yukon_reset(hw, port);
2412 yukon_init(hw, port);
2413 }
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002414 spin_unlock_bh(&hw->phy_lock);
Stephen Hemminger75814092006-12-01 11:41:08 -08002415
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08002416 skge_set_multicast(dev);
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002417}
2418
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002419/* Basic MII support */
2420static int skge_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2421{
2422 struct mii_ioctl_data *data = if_mii(ifr);
2423 struct skge_port *skge = netdev_priv(dev);
2424 struct skge_hw *hw = skge->hw;
2425 int err = -EOPNOTSUPP;
2426
2427 if (!netif_running(dev))
2428 return -ENODEV; /* Phy still in reset */
2429
Joe Perches67777f92010-02-17 15:01:58 +00002430 switch (cmd) {
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002431 case SIOCGMIIPHY:
2432 data->phy_id = hw->phy_addr;
2433
2434 /* fallthru */
2435 case SIOCGMIIREG: {
2436 u16 val = 0;
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002437 spin_lock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002438 if (hw->chip_id == CHIP_ID_GENESIS)
2439 err = __xm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val);
2440 else
2441 err = __gm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002442 spin_unlock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002443 data->val_out = val;
2444 break;
2445 }
2446
2447 case SIOCSMIIREG:
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002448 spin_lock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002449 if (hw->chip_id == CHIP_ID_GENESIS)
2450 err = xm_phy_write(hw, skge->port, data->reg_num & 0x1f,
2451 data->val_in);
2452 else
2453 err = gm_phy_write(hw, skge->port, data->reg_num & 0x1f,
2454 data->val_in);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002455 spin_unlock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002456 break;
2457 }
2458 return err;
2459}
2460
Linus Torvalds279e1da2007-11-15 08:44:36 -08002461static void skge_ramset(struct skge_hw *hw, u16 q, u32 start, size_t len)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002462{
2463 u32 end;
2464
Linus Torvalds279e1da2007-11-15 08:44:36 -08002465 start /= 8;
2466 len /= 8;
2467 end = start + len - 1;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002468
2469 skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR);
2470 skge_write32(hw, RB_ADDR(q, RB_START), start);
2471 skge_write32(hw, RB_ADDR(q, RB_WP), start);
2472 skge_write32(hw, RB_ADDR(q, RB_RP), start);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002473 skge_write32(hw, RB_ADDR(q, RB_END), end);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002474
2475 if (q == Q_R1 || q == Q_R2) {
2476 /* Set thresholds on receive queue's */
Linus Torvalds279e1da2007-11-15 08:44:36 -08002477 skge_write32(hw, RB_ADDR(q, RB_RX_UTPP),
2478 start + (2*len)/3);
2479 skge_write32(hw, RB_ADDR(q, RB_RX_LTPP),
2480 start + (len/3));
2481 } else {
2482 /* Enable store & forward on Tx queue's because
2483 * Tx FIFO is only 4K on Genesis and 1K on Yukon
2484 */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002485 skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002486 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002487
2488 skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD);
2489}
2490
2491/* Setup Bus Memory Interface */
2492static void skge_qset(struct skge_port *skge, u16 q,
2493 const struct skge_element *e)
2494{
2495 struct skge_hw *hw = skge->hw;
2496 u32 watermark = 0x600;
2497 u64 base = skge->dma + (e->desc - skge->mem);
2498
2499 /* optimization to reduce window on 32bit/33mhz */
2500 if ((skge_read16(hw, B0_CTST) & (CS_BUS_CLOCK | CS_BUS_SLOT_SZ)) == 0)
2501 watermark /= 2;
2502
2503 skge_write32(hw, Q_ADDR(q, Q_CSR), CSR_CLR_RESET);
2504 skge_write32(hw, Q_ADDR(q, Q_F), watermark);
2505 skge_write32(hw, Q_ADDR(q, Q_DA_H), (u32)(base >> 32));
2506 skge_write32(hw, Q_ADDR(q, Q_DA_L), (u32)base);
2507}
2508
2509static int skge_up(struct net_device *dev)
2510{
2511 struct skge_port *skge = netdev_priv(dev);
2512 struct skge_hw *hw = skge->hw;
2513 int port = skge->port;
Linus Torvalds279e1da2007-11-15 08:44:36 -08002514 u32 chunk, ram_addr;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002515 size_t rx_size, tx_size;
2516 int err;
2517
Stephen Hemmingerfae87592007-02-02 08:22:51 -08002518 if (!is_valid_ether_addr(dev->dev_addr))
2519 return -EINVAL;
2520
Joe Perchesd7072042010-02-09 11:49:53 +00002521 netif_info(skge, ifup, skge->netdev, "enabling interface\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002522
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002523 if (dev->mtu > RX_BUF_SIZE)
Stephen Hemminger901ccef2006-03-23 11:07:23 -08002524 skge->rx_buf_size = dev->mtu + ETH_HLEN;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002525 else
2526 skge->rx_buf_size = RX_BUF_SIZE;
2527
2528
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002529 rx_size = skge->rx_ring.count * sizeof(struct skge_rx_desc);
2530 tx_size = skge->tx_ring.count * sizeof(struct skge_tx_desc);
2531 skge->mem_size = tx_size + rx_size;
2532 skge->mem = pci_alloc_consistent(hw->pdev, skge->mem_size, &skge->dma);
2533 if (!skge->mem)
2534 return -ENOMEM;
2535
Stephen Hemmingerc3da1442006-03-21 10:57:01 -08002536 BUG_ON(skge->dma & 7);
2537
2538 if ((u64)skge->dma >> 32 != ((u64) skge->dma + skge->mem_size) >> 32) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08002539 dev_err(&hw->pdev->dev, "pci_alloc_consistent region crosses 4G boundary\n");
Stephen Hemmingerc3da1442006-03-21 10:57:01 -08002540 err = -EINVAL;
2541 goto free_pci_mem;
2542 }
2543
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002544 memset(skge->mem, 0, skge->mem_size);
2545
Stephen Hemminger203babb2006-03-21 10:57:05 -08002546 err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma);
2547 if (err)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002548 goto free_pci_mem;
2549
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07002550 err = skge_rx_fill(dev);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002551 if (err)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002552 goto free_rx_ring;
2553
Stephen Hemminger203babb2006-03-21 10:57:05 -08002554 err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size,
2555 skge->dma + rx_size);
2556 if (err)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002557 goto free_rx_ring;
2558
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08002559 /* Initialize MAC */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002560 spin_lock_bh(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002561 if (hw->chip_id == CHIP_ID_GENESIS)
2562 genesis_mac_init(hw, port);
2563 else
2564 yukon_mac_init(hw, port);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002565 spin_unlock_bh(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002566
Stephen Hemminger29816d92007-11-26 11:54:48 -08002567 /* Configure RAMbuffers - equally between ports and tx/rx */
2568 chunk = (hw->ram_size - hw->ram_offset) / (hw->ports * 2);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002569 ram_addr = hw->ram_offset + 2 * chunk * port;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002570
Linus Torvalds279e1da2007-11-15 08:44:36 -08002571 skge_ramset(hw, rxqaddr[port], ram_addr, chunk);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002572 skge_qset(skge, rxqaddr[port], skge->rx_ring.to_clean);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002573
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002574 BUG_ON(skge->tx_ring.to_use != skge->tx_ring.to_clean);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002575 skge_ramset(hw, txqaddr[port], ram_addr+chunk, chunk);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002576 skge_qset(skge, txqaddr[port], skge->tx_ring.to_use);
2577
2578 /* Start receiver BMU */
2579 wmb();
2580 skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_START | CSR_IRQ_CL_F);
Stephen Hemminger6abebb52005-07-22 16:26:10 -07002581 skge_led(skge, LED_MODE_ON);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002582
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07002583 spin_lock_irq(&hw->hw_lock);
2584 hw->intr_mask |= portmask[port];
2585 skge_write32(hw, B0_IMSK, hw->intr_mask);
2586 spin_unlock_irq(&hw->hw_lock);
2587
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002588 napi_enable(&skge->napi);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002589 return 0;
2590
2591 free_rx_ring:
2592 skge_rx_clean(skge);
2593 kfree(skge->rx_ring.start);
2594 free_pci_mem:
2595 pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002596 skge->mem = NULL;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002597
2598 return err;
2599}
2600
Stephen Hemminger60b24b52007-10-16 12:15:50 -07002601/* stop receiver */
2602static void skge_rx_stop(struct skge_hw *hw, int port)
2603{
2604 skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_STOP);
2605 skge_write32(hw, RB_ADDR(port ? Q_R2 : Q_R1, RB_CTRL),
2606 RB_RST_SET|RB_DIS_OP_MD);
2607 skge_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_SET_RESET);
2608}
2609
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002610static int skge_down(struct net_device *dev)
2611{
2612 struct skge_port *skge = netdev_priv(dev);
2613 struct skge_hw *hw = skge->hw;
2614 int port = skge->port;
2615
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002616 if (skge->mem == NULL)
2617 return 0;
2618
Joe Perchesd7072042010-02-09 11:49:53 +00002619 netif_info(skge, ifdown, skge->netdev, "disabling interface\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002620
Michal Schmidtd119b392009-04-14 15:16:55 -07002621 netif_tx_disable(dev);
Stephen Hemminger692412b2007-04-09 15:32:45 -07002622
Stephen Hemminger64f6b642006-09-23 21:25:28 -07002623 if (hw->chip_id == CHIP_ID_GENESIS && hw->phy_type == SK_PHY_XMAC)
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002624 del_timer_sync(&skge->link_timer);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002625
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002626 napi_disable(&skge->napi);
Stephen Hemminger692412b2007-04-09 15:32:45 -07002627 netif_carrier_off(dev);
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07002628
2629 spin_lock_irq(&hw->hw_lock);
2630 hw->intr_mask &= ~portmask[port];
2631 skge_write32(hw, B0_IMSK, hw->intr_mask);
2632 spin_unlock_irq(&hw->hw_lock);
2633
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002634 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF);
2635 if (hw->chip_id == CHIP_ID_GENESIS)
2636 genesis_stop(skge);
2637 else
2638 yukon_stop(skge);
2639
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002640 /* Stop transmitter */
2641 skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP);
2642 skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL),
2643 RB_RST_SET|RB_DIS_OP_MD);
2644
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002645
2646 /* Disable Force Sync bit and Enable Alloc bit */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002647 skge_write8(hw, SK_REG(port, TXA_CTRL),
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002648 TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
2649
2650 /* Stop Interval Timer and Limit Counter of Tx Arbiter */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002651 skge_write32(hw, SK_REG(port, TXA_ITI_INI), 0L);
2652 skge_write32(hw, SK_REG(port, TXA_LIM_INI), 0L);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002653
2654 /* Reset PCI FIFO */
2655 skge_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_SET_RESET);
2656 skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET);
2657
2658 /* Reset the RAM Buffer async Tx queue */
2659 skge_write8(hw, RB_ADDR(port == 0 ? Q_XA1 : Q_XA2, RB_CTRL), RB_RST_SET);
Stephen Hemminger60b24b52007-10-16 12:15:50 -07002660
2661 skge_rx_stop(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002662
2663 if (hw->chip_id == CHIP_ID_GENESIS) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002664 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_SET);
2665 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002666 } else {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002667 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
2668 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002669 }
2670
Stephen Hemminger6abebb52005-07-22 16:26:10 -07002671 skge_led(skge, LED_MODE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002672
Stephen Hemmingere3a1b992007-03-16 14:01:26 -07002673 netif_tx_lock_bh(dev);
Stephen Hemminger513f5332006-09-01 15:53:49 -07002674 skge_tx_clean(dev);
Stephen Hemmingere3a1b992007-03-16 14:01:26 -07002675 netif_tx_unlock_bh(dev);
2676
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002677 skge_rx_clean(skge);
2678
2679 kfree(skge->rx_ring.start);
2680 kfree(skge->tx_ring.start);
2681 pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002682 skge->mem = NULL;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002683 return 0;
2684}
2685
Stephen Hemminger29b4e882006-03-23 11:07:28 -08002686static inline int skge_avail(const struct skge_ring *ring)
2687{
Stephen Hemminger992c9622007-03-16 14:01:30 -07002688 smp_mb();
Stephen Hemminger29b4e882006-03-23 11:07:28 -08002689 return ((ring->to_clean > ring->to_use) ? 0 : ring->count)
2690 + (ring->to_clean - ring->to_use) - 1;
2691}
2692
Stephen Hemminger613573252009-08-31 19:50:58 +00002693static netdev_tx_t skge_xmit_frame(struct sk_buff *skb,
2694 struct net_device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002695{
2696 struct skge_port *skge = netdev_priv(dev);
2697 struct skge_hw *hw = skge->hw;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002698 struct skge_element *e;
2699 struct skge_tx_desc *td;
2700 int i;
2701 u32 control, len;
2702 u64 map;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002703
Herbert Xu5b057c62006-06-23 02:06:41 -07002704 if (skb_padto(skb, ETH_ZLEN))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002705 return NETDEV_TX_OK;
2706
Stephen Hemminger513f5332006-09-01 15:53:49 -07002707 if (unlikely(skge_avail(&skge->tx_ring) < skb_shinfo(skb)->nr_frags + 1))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002708 return NETDEV_TX_BUSY;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002709
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002710 e = skge->tx_ring.to_use;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002711 td = e->desc;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002712 BUG_ON(td->control & BMU_OWN);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002713 e->skb = skb;
2714 len = skb_headlen(skb);
2715 map = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE);
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00002716 dma_unmap_addr_set(e, mapaddr, map);
2717 dma_unmap_len_set(e, maplen, len);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002718
2719 td->dma_lo = map;
2720 td->dma_hi = map >> 32;
2721
Patrick McHardy84fa7932006-08-29 16:44:56 -07002722 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Michał Mirosław0d0b1672010-12-14 15:24:08 +00002723 const int offset = skb_checksum_start_offset(skb);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002724
2725 /* This seems backwards, but it is what the sk98lin
2726 * does. Looks like hardware is wrong?
2727 */
Joe Perches8e95a202009-12-03 07:58:21 +00002728 if (ipip_hdr(skb)->protocol == IPPROTO_UDP &&
Joe Perches67777f92010-02-17 15:01:58 +00002729 hw->chip_rev == 0 && hw->chip_id == CHIP_ID_YUKON)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002730 control = BMU_TCP_CHECK;
2731 else
2732 control = BMU_UDP_CHECK;
2733
2734 td->csum_offs = 0;
2735 td->csum_start = offset;
Al Viroff1dcad2006-11-20 18:07:29 -08002736 td->csum_write = offset + skb->csum_offset;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002737 } else
2738 control = BMU_CHECK;
2739
2740 if (!skb_shinfo(skb)->nr_frags) /* single buffer i.e. no fragments */
Joe Perches67777f92010-02-17 15:01:58 +00002741 control |= BMU_EOF | BMU_IRQ_EOF;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002742 else {
2743 struct skge_tx_desc *tf = td;
2744
2745 control |= BMU_STFWD;
2746 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2747 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2748
2749 map = pci_map_page(hw->pdev, frag->page, frag->page_offset,
2750 frag->size, PCI_DMA_TODEVICE);
2751
2752 e = e->next;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002753 e->skb = skb;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002754 tf = e->desc;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002755 BUG_ON(tf->control & BMU_OWN);
2756
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002757 tf->dma_lo = map;
2758 tf->dma_hi = (u64) map >> 32;
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00002759 dma_unmap_addr_set(e, mapaddr, map);
2760 dma_unmap_len_set(e, maplen, frag->size);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002761
2762 tf->control = BMU_OWN | BMU_SW | control | frag->size;
2763 }
2764 tf->control |= BMU_EOF | BMU_IRQ_EOF;
2765 }
2766 /* Make sure all the descriptors written */
2767 wmb();
2768 td->control = BMU_OWN | BMU_SW | BMU_STF | control | len;
2769 wmb();
2770
2771 skge_write8(hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_START);
2772
Joe Perchesd7072042010-02-09 11:49:53 +00002773 netif_printk(skge, tx_queued, KERN_DEBUG, skge->netdev,
2774 "tx queued, slot %td, len %d\n",
2775 e - skge->tx_ring.start, skb->len);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002776
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002777 skge->tx_ring.to_use = e->next;
Stephen Hemminger992c9622007-03-16 14:01:30 -07002778 smp_wmb();
2779
Stephen Hemminger9db96472006-06-06 10:11:12 -07002780 if (skge_avail(&skge->tx_ring) <= TX_LOW_WATER) {
Joe Perchesf15063c2010-02-17 15:01:57 +00002781 netdev_dbg(dev, "transmit queue full\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002782 netif_stop_queue(dev);
2783 }
2784
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002785 return NETDEV_TX_OK;
2786}
2787
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002788
2789/* Free resources associated with this reing element */
2790static void skge_tx_free(struct skge_port *skge, struct skge_element *e,
2791 u32 control)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002792{
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002793 struct pci_dev *pdev = skge->hw->pdev;
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002794
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002795 /* skb header vs. fragment */
2796 if (control & BMU_STF)
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00002797 pci_unmap_single(pdev, dma_unmap_addr(e, mapaddr),
2798 dma_unmap_len(e, maplen),
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002799 PCI_DMA_TODEVICE);
2800 else
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00002801 pci_unmap_page(pdev, dma_unmap_addr(e, mapaddr),
2802 dma_unmap_len(e, maplen),
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002803 PCI_DMA_TODEVICE);
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002804
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002805 if (control & BMU_EOF) {
Joe Perchesd7072042010-02-09 11:49:53 +00002806 netif_printk(skge, tx_done, KERN_DEBUG, skge->netdev,
2807 "tx done slot %td\n", e - skge->tx_ring.start);
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002808
Stephen Hemminger513f5332006-09-01 15:53:49 -07002809 dev_kfree_skb(e->skb);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002810 }
2811}
2812
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002813/* Free all buffers in transmit ring */
Stephen Hemminger513f5332006-09-01 15:53:49 -07002814static void skge_tx_clean(struct net_device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002815{
Stephen Hemminger513f5332006-09-01 15:53:49 -07002816 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002817 struct skge_element *e;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002818
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002819 for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) {
2820 struct skge_tx_desc *td = e->desc;
2821 skge_tx_free(skge, e, td->control);
2822 td->control = 0;
2823 }
2824
2825 skge->tx_ring.to_clean = e;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002826}
2827
2828static void skge_tx_timeout(struct net_device *dev)
2829{
2830 struct skge_port *skge = netdev_priv(dev);
2831
Joe Perchesd7072042010-02-09 11:49:53 +00002832 netif_printk(skge, timer, KERN_DEBUG, skge->netdev, "tx timeout\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002833
2834 skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_STOP);
Stephen Hemminger513f5332006-09-01 15:53:49 -07002835 skge_tx_clean(dev);
Michal Schmidtd119b392009-04-14 15:16:55 -07002836 netif_wake_queue(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002837}
2838
2839static int skge_change_mtu(struct net_device *dev, int new_mtu)
2840{
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002841 int err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002842
Stephen Hemminger95566062005-06-27 11:33:02 -07002843 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002844 return -EINVAL;
2845
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002846 if (!netif_running(dev)) {
2847 dev->mtu = new_mtu;
2848 return 0;
2849 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002850
Stephen Hemminger1a8098b2007-11-28 14:25:05 -08002851 skge_down(dev);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002852
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002853 dev->mtu = new_mtu;
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002854
Stephen Hemminger1a8098b2007-11-28 14:25:05 -08002855 err = skge_up(dev);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002856 if (err)
2857 dev_close(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002858
2859 return err;
2860}
2861
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002862static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 };
2863
2864static void genesis_add_filter(u8 filter[8], const u8 *addr)
2865{
2866 u32 crc, bit;
2867
2868 crc = ether_crc_le(ETH_ALEN, addr);
2869 bit = ~crc & 0x3f;
2870 filter[bit/8] |= 1 << (bit%8);
2871}
2872
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002873static void genesis_set_multicast(struct net_device *dev)
2874{
2875 struct skge_port *skge = netdev_priv(dev);
2876 struct skge_hw *hw = skge->hw;
2877 int port = skge->port;
Jiri Pirko22bedad32010-04-01 21:22:57 +00002878 struct netdev_hw_addr *ha;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002879 u32 mode;
2880 u8 filter[8];
2881
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002882 mode = xm_read32(hw, port, XM_MODE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002883 mode |= XM_MD_ENA_HASH;
2884 if (dev->flags & IFF_PROMISC)
2885 mode |= XM_MD_ENA_PROM;
2886 else
2887 mode &= ~XM_MD_ENA_PROM;
2888
2889 if (dev->flags & IFF_ALLMULTI)
2890 memset(filter, 0xff, sizeof(filter));
2891 else {
2892 memset(filter, 0, sizeof(filter));
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002893
Joe Perches8e95a202009-12-03 07:58:21 +00002894 if (skge->flow_status == FLOW_STAT_REM_SEND ||
2895 skge->flow_status == FLOW_STAT_SYMMETRIC)
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002896 genesis_add_filter(filter, pause_mc_addr);
2897
Jiri Pirko22bedad32010-04-01 21:22:57 +00002898 netdev_for_each_mc_addr(ha, dev)
2899 genesis_add_filter(filter, ha->addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002900 }
2901
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002902 xm_write32(hw, port, XM_MODE, mode);
Stephen Hemminger45bada62005-06-27 11:33:12 -07002903 xm_outhash(hw, port, XM_HSM, filter);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002904}
2905
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002906static void yukon_add_filter(u8 filter[8], const u8 *addr)
2907{
2908 u32 bit = ether_crc(ETH_ALEN, addr) & 0x3f;
2909 filter[bit/8] |= 1 << (bit%8);
2910}
2911
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002912static void yukon_set_multicast(struct net_device *dev)
2913{
2914 struct skge_port *skge = netdev_priv(dev);
2915 struct skge_hw *hw = skge->hw;
2916 int port = skge->port;
Jiri Pirko22bedad32010-04-01 21:22:57 +00002917 struct netdev_hw_addr *ha;
Joe Perches8e95a202009-12-03 07:58:21 +00002918 int rx_pause = (skge->flow_status == FLOW_STAT_REM_SEND ||
2919 skge->flow_status == FLOW_STAT_SYMMETRIC);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002920 u16 reg;
2921 u8 filter[8];
2922
2923 memset(filter, 0, sizeof(filter));
2924
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002925 reg = gma_read16(hw, port, GM_RX_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002926 reg |= GM_RXCR_UCF_ENA;
2927
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08002928 if (dev->flags & IFF_PROMISC) /* promiscuous */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002929 reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
2930 else if (dev->flags & IFF_ALLMULTI) /* all multicast */
2931 memset(filter, 0xff, sizeof(filter));
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002932 else if (netdev_mc_empty(dev) && !rx_pause)/* no multicast */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002933 reg &= ~GM_RXCR_MCF_ENA;
2934 else {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002935 reg |= GM_RXCR_MCF_ENA;
2936
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002937 if (rx_pause)
2938 yukon_add_filter(filter, pause_mc_addr);
2939
Jiri Pirko22bedad32010-04-01 21:22:57 +00002940 netdev_for_each_mc_addr(ha, dev)
2941 yukon_add_filter(filter, ha->addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002942 }
2943
2944
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002945 gma_write16(hw, port, GM_MC_ADDR_H1,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002946 (u16)filter[0] | ((u16)filter[1] << 8));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002947 gma_write16(hw, port, GM_MC_ADDR_H2,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002948 (u16)filter[2] | ((u16)filter[3] << 8));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002949 gma_write16(hw, port, GM_MC_ADDR_H3,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002950 (u16)filter[4] | ((u16)filter[5] << 8));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002951 gma_write16(hw, port, GM_MC_ADDR_H4,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002952 (u16)filter[6] | ((u16)filter[7] << 8));
2953
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002954 gma_write16(hw, port, GM_RX_CTRL, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002955}
2956
Stephen Hemminger383181a2005-09-19 15:37:16 -07002957static inline u16 phy_length(const struct skge_hw *hw, u32 status)
2958{
2959 if (hw->chip_id == CHIP_ID_GENESIS)
2960 return status >> XMR_FS_LEN_SHIFT;
2961 else
2962 return status >> GMR_FS_LEN_SHIFT;
2963}
2964
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002965static inline int bad_phy_status(const struct skge_hw *hw, u32 status)
2966{
2967 if (hw->chip_id == CHIP_ID_GENESIS)
2968 return (status & (XMR_FS_ERR | XMR_FS_2L_VLAN)) != 0;
2969 else
2970 return (status & GMR_FS_ANY_ERR) ||
2971 (status & GMR_FS_RX_OK) == 0;
2972}
2973
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08002974static void skge_set_multicast(struct net_device *dev)
2975{
2976 struct skge_port *skge = netdev_priv(dev);
2977 struct skge_hw *hw = skge->hw;
2978
2979 if (hw->chip_id == CHIP_ID_GENESIS)
2980 genesis_set_multicast(dev);
2981 else
2982 yukon_set_multicast(dev);
2983
2984}
2985
Stephen Hemminger383181a2005-09-19 15:37:16 -07002986
2987/* Get receive buffer from descriptor.
2988 * Handles copy of small buffers and reallocation failures
2989 */
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07002990static struct sk_buff *skge_rx_get(struct net_device *dev,
2991 struct skge_element *e,
2992 u32 control, u32 status, u16 csum)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002993{
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07002994 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger383181a2005-09-19 15:37:16 -07002995 struct sk_buff *skb;
2996 u16 len = control & BMU_BBC;
2997
Joe Perchesd7072042010-02-09 11:49:53 +00002998 netif_printk(skge, rx_status, KERN_DEBUG, skge->netdev,
2999 "rx slot %td status 0x%x len %d\n",
3000 e - skge->rx_ring.start, status, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003001
3002 if (len > skge->rx_buf_size)
3003 goto error;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003004
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003005 if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF))
Stephen Hemminger383181a2005-09-19 15:37:16 -07003006 goto error;
3007
3008 if (bad_phy_status(skge->hw, status))
3009 goto error;
3010
3011 if (phy_length(skge->hw, status) != len)
3012 goto error;
3013
3014 if (len < RX_COPY_THRESHOLD) {
Eric Dumazet89d71a62009-10-13 05:34:20 +00003015 skb = netdev_alloc_skb_ip_align(dev, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003016 if (!skb)
3017 goto resubmit;
3018
Stephen Hemminger383181a2005-09-19 15:37:16 -07003019 pci_dma_sync_single_for_cpu(skge->hw->pdev,
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00003020 dma_unmap_addr(e, mapaddr),
Stephen Hemminger383181a2005-09-19 15:37:16 -07003021 len, PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03003022 skb_copy_from_linear_data(e->skb, skb->data, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003023 pci_dma_sync_single_for_device(skge->hw->pdev,
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00003024 dma_unmap_addr(e, mapaddr),
Stephen Hemminger383181a2005-09-19 15:37:16 -07003025 len, PCI_DMA_FROMDEVICE);
3026 skge_rx_reuse(e, skge->rx_buf_size);
3027 } else {
3028 struct sk_buff *nskb;
Eric Dumazet89d71a62009-10-13 05:34:20 +00003029
3030 nskb = netdev_alloc_skb_ip_align(dev, skge->rx_buf_size);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003031 if (!nskb)
3032 goto resubmit;
3033
3034 pci_unmap_single(skge->hw->pdev,
FUJITA Tomonori10fc51b2010-04-27 14:57:04 +00003035 dma_unmap_addr(e, mapaddr),
3036 dma_unmap_len(e, maplen),
Stephen Hemminger383181a2005-09-19 15:37:16 -07003037 PCI_DMA_FROMDEVICE);
3038 skb = e->skb;
Joe Perches67777f92010-02-17 15:01:58 +00003039 prefetch(skb->data);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003040 skge_rx_setup(skge, e, nskb, skge->rx_buf_size);
3041 }
3042
3043 skb_put(skb, len);
Michał Mirosławe92702b2011-03-31 01:01:35 +00003044
3045 if (dev->features & NETIF_F_RXCSUM) {
Stephen Hemminger383181a2005-09-19 15:37:16 -07003046 skb->csum = csum;
Patrick McHardy84fa7932006-08-29 16:44:56 -07003047 skb->ip_summed = CHECKSUM_COMPLETE;
Stephen Hemminger383181a2005-09-19 15:37:16 -07003048 }
3049
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003050 skb->protocol = eth_type_trans(skb, dev);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003051
3052 return skb;
3053error:
3054
Joe Perchesd7072042010-02-09 11:49:53 +00003055 netif_printk(skge, rx_err, KERN_DEBUG, skge->netdev,
3056 "rx err, slot %td control 0x%x status 0x%x\n",
3057 e - skge->rx_ring.start, control, status);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003058
3059 if (skge->hw->chip_id == CHIP_ID_GENESIS) {
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003060 if (status & (XMR_FS_RUNT|XMR_FS_LNG_ERR))
Stephen Hemmingerda007722007-10-16 12:15:52 -07003061 dev->stats.rx_length_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003062 if (status & XMR_FS_FRA_ERR)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003063 dev->stats.rx_frame_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003064 if (status & XMR_FS_FCS_ERR)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003065 dev->stats.rx_crc_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003066 } else {
3067 if (status & (GMR_FS_LONG_ERR|GMR_FS_UN_SIZE))
Stephen Hemmingerda007722007-10-16 12:15:52 -07003068 dev->stats.rx_length_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003069 if (status & GMR_FS_FRAGMENT)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003070 dev->stats.rx_frame_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003071 if (status & GMR_FS_CRC_ERR)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003072 dev->stats.rx_crc_errors++;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003073 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003074
Stephen Hemminger383181a2005-09-19 15:37:16 -07003075resubmit:
3076 skge_rx_reuse(e, skge->rx_buf_size);
3077 return NULL;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003078}
3079
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003080/* Free all buffers in Tx ring which are no longer owned by device */
Stephen Hemminger513f5332006-09-01 15:53:49 -07003081static void skge_tx_done(struct net_device *dev)
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003082{
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003083 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003084 struct skge_ring *ring = &skge->tx_ring;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003085 struct skge_element *e;
3086
Stephen Hemminger513f5332006-09-01 15:53:49 -07003087 skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F);
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003088
Stephen Hemminger866b4f32006-03-23 11:07:27 -08003089 for (e = ring->to_clean; e != ring->to_use; e = e->next) {
Stephen Hemminger992c9622007-03-16 14:01:30 -07003090 u32 control = ((const struct skge_tx_desc *) e->desc)->control;
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003091
Stephen Hemminger992c9622007-03-16 14:01:30 -07003092 if (control & BMU_OWN)
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003093 break;
3094
Stephen Hemminger992c9622007-03-16 14:01:30 -07003095 skge_tx_free(skge, e, control);
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003096 }
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003097 skge->tx_ring.to_clean = e;
Stephen Hemminger866b4f32006-03-23 11:07:27 -08003098
Stephen Hemminger992c9622007-03-16 14:01:30 -07003099 /* Can run lockless until we need to synchronize to restart queue. */
3100 smp_mb();
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003101
Stephen Hemminger992c9622007-03-16 14:01:30 -07003102 if (unlikely(netif_queue_stopped(dev) &&
3103 skge_avail(&skge->tx_ring) > TX_LOW_WATER)) {
3104 netif_tx_lock(dev);
3105 if (unlikely(netif_queue_stopped(dev) &&
3106 skge_avail(&skge->tx_ring) > TX_LOW_WATER)) {
3107 netif_wake_queue(dev);
3108
3109 }
3110 netif_tx_unlock(dev);
3111 }
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003112}
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003113
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003114static int skge_poll(struct napi_struct *napi, int to_do)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003115{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003116 struct skge_port *skge = container_of(napi, struct skge_port, napi);
3117 struct net_device *dev = skge->netdev;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003118 struct skge_hw *hw = skge->hw;
3119 struct skge_ring *ring = &skge->rx_ring;
3120 struct skge_element *e;
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003121 int work_done = 0;
3122
Stephen Hemminger513f5332006-09-01 15:53:49 -07003123 skge_tx_done(dev);
3124
3125 skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F);
3126
Stephen Hemminger1631aef2005-11-08 10:33:44 -08003127 for (e = ring->to_clean; prefetch(e->next), work_done < to_do; e = e->next) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003128 struct skge_rx_desc *rd = e->desc;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003129 struct sk_buff *skb;
Stephen Hemminger383181a2005-09-19 15:37:16 -07003130 u32 control;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003131
3132 rmb();
3133 control = rd->control;
3134 if (control & BMU_OWN)
3135 break;
3136
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003137 skb = skge_rx_get(dev, e, control, rd->status, rd->csum2);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003138 if (likely(skb)) {
Eric Dumazet86cac582010-08-31 18:25:32 +00003139 napi_gro_receive(napi, skb);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003140 ++work_done;
Stephen Hemminger5a011442006-03-23 11:07:25 -08003141 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003142 }
3143 ring->to_clean = e;
3144
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003145 /* restart receiver */
3146 wmb();
Stephen Hemmingera9cdab82006-02-22 10:28:33 -08003147 skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_START);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003148
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003149 if (work_done < to_do) {
Marin Mitov6ef29772008-03-23 10:20:09 +02003150 unsigned long flags;
Jeff Garzikf0c88f92008-03-25 23:53:24 -04003151
Eric Dumazet86cac582010-08-31 18:25:32 +00003152 napi_gro_flush(napi);
Marin Mitov6ef29772008-03-23 10:20:09 +02003153 spin_lock_irqsave(&hw->hw_lock, flags);
Ben Hutchings288379f2009-01-19 16:43:59 -08003154 __napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003155 hw->intr_mask |= napimask[skge->port];
3156 skge_write32(hw, B0_IMSK, hw->intr_mask);
3157 skge_read32(hw, B0_IMSK);
Marin Mitov6ef29772008-03-23 10:20:09 +02003158 spin_unlock_irqrestore(&hw->hw_lock, flags);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003159 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003160
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003161 return work_done;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003162}
3163
Stephen Hemmingerf6620ca2005-07-22 16:26:02 -07003164/* Parity errors seem to happen when Genesis is connected to a switch
3165 * with no other ports present. Heartbeat error??
3166 */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003167static void skge_mac_parity(struct skge_hw *hw, int port)
3168{
Stephen Hemmingerf6620ca2005-07-22 16:26:02 -07003169 struct net_device *dev = hw->dev[port];
3170
Stephen Hemmingerda007722007-10-16 12:15:52 -07003171 ++dev->stats.tx_heartbeat_errors;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003172
3173 if (hw->chip_id == CHIP_ID_GENESIS)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003174 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1),
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003175 MFF_CLR_PERR);
3176 else
3177 /* HW-Bug #8: cleared by GMF_CLI_TX_FC instead of GMF_CLI_TX_PE */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003178 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T),
Stephen Hemminger981d0372005-06-27 11:33:06 -07003179 (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003180 ? GMF_CLI_TX_FC : GMF_CLI_TX_PE);
3181}
3182
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003183static void skge_mac_intr(struct skge_hw *hw, int port)
3184{
Stephen Hemminger95566062005-06-27 11:33:02 -07003185 if (hw->chip_id == CHIP_ID_GENESIS)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003186 genesis_mac_intr(hw, port);
3187 else
3188 yukon_mac_intr(hw, port);
3189}
3190
3191/* Handle device specific framing and timeout interrupts */
3192static void skge_error_irq(struct skge_hw *hw)
3193{
Stephen Hemminger1479d132007-02-02 08:22:52 -08003194 struct pci_dev *pdev = hw->pdev;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003195 u32 hwstatus = skge_read32(hw, B0_HWE_ISRC);
3196
3197 if (hw->chip_id == CHIP_ID_GENESIS) {
3198 /* clear xmac errors */
3199 if (hwstatus & (IS_NO_STAT_M1|IS_NO_TIST_M1))
Stephen Hemminger46a60f22005-09-09 12:54:56 -07003200 skge_write16(hw, RX_MFF_CTRL1, MFF_CLR_INSTAT);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003201 if (hwstatus & (IS_NO_STAT_M2|IS_NO_TIST_M2))
Stephen Hemminger46a60f22005-09-09 12:54:56 -07003202 skge_write16(hw, RX_MFF_CTRL2, MFF_CLR_INSTAT);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003203 } else {
3204 /* Timestamp (unused) overflow */
3205 if (hwstatus & IS_IRQ_TIST_OV)
3206 skge_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003207 }
3208
3209 if (hwstatus & IS_RAM_RD_PAR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003210 dev_err(&pdev->dev, "Ram read data parity error\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003211 skge_write16(hw, B3_RI_CTRL, RI_CLR_RD_PERR);
3212 }
3213
3214 if (hwstatus & IS_RAM_WR_PAR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003215 dev_err(&pdev->dev, "Ram write data parity error\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003216 skge_write16(hw, B3_RI_CTRL, RI_CLR_WR_PERR);
3217 }
3218
3219 if (hwstatus & IS_M1_PAR_ERR)
3220 skge_mac_parity(hw, 0);
3221
3222 if (hwstatus & IS_M2_PAR_ERR)
3223 skge_mac_parity(hw, 1);
3224
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003225 if (hwstatus & IS_R1_PAR_ERR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003226 dev_err(&pdev->dev, "%s: receive queue parity error\n",
3227 hw->dev[0]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003228 skge_write32(hw, B0_R1_CSR, CSR_IRQ_CL_P);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003229 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003230
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003231 if (hwstatus & IS_R2_PAR_ERR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003232 dev_err(&pdev->dev, "%s: receive queue parity error\n",
3233 hw->dev[1]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003234 skge_write32(hw, B0_R2_CSR, CSR_IRQ_CL_P);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003235 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003236
3237 if (hwstatus & (IS_IRQ_MST_ERR|IS_IRQ_STAT)) {
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003238 u16 pci_status, pci_cmd;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003239
Stephen Hemminger1479d132007-02-02 08:22:52 -08003240 pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
3241 pci_read_config_word(pdev, PCI_STATUS, &pci_status);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003242
Stephen Hemminger1479d132007-02-02 08:22:52 -08003243 dev_err(&pdev->dev, "PCI error cmd=%#x status=%#x\n",
3244 pci_cmd, pci_status);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003245
3246 /* Write the error bits back to clear them. */
3247 pci_status &= PCI_STATUS_ERROR_BITS;
3248 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
Stephen Hemminger1479d132007-02-02 08:22:52 -08003249 pci_write_config_word(pdev, PCI_COMMAND,
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003250 pci_cmd | PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
Stephen Hemminger1479d132007-02-02 08:22:52 -08003251 pci_write_config_word(pdev, PCI_STATUS, pci_status);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003252 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003253
Stephen Hemminger050ec182005-08-16 14:00:54 -07003254 /* if error still set then just ignore it */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003255 hwstatus = skge_read32(hw, B0_HWE_ISRC);
3256 if (hwstatus & IS_IRQ_STAT) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003257 dev_warn(&hw->pdev->dev, "unable to clear error (so ignoring them)\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003258 hw->intr_mask &= ~IS_HW_ERR;
3259 }
3260 }
3261}
3262
3263/*
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003264 * Interrupt from PHY are handled in tasklet (softirq)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003265 * because accessing phy registers requires spin wait which might
3266 * cause excess interrupt latency.
3267 */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003268static void skge_extirq(unsigned long arg)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003269{
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003270 struct skge_hw *hw = (struct skge_hw *) arg;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003271 int port;
3272
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003273 for (port = 0; port < hw->ports; port++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003274 struct net_device *dev = hw->dev[port];
3275
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003276 if (netif_running(dev)) {
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003277 struct skge_port *skge = netdev_priv(dev);
3278
3279 spin_lock(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003280 if (hw->chip_id != CHIP_ID_GENESIS)
3281 yukon_phy_intr(skge);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003282 else if (hw->phy_type == SK_PHY_BCOM)
Stephen Hemminger45bada62005-06-27 11:33:12 -07003283 bcom_phy_intr(skge);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003284 spin_unlock(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003285 }
3286 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003287
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003288 spin_lock_irq(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003289 hw->intr_mask |= IS_EXT_REG;
3290 skge_write32(hw, B0_IMSK, hw->intr_mask);
Stephen Hemminger78bc2182006-08-28 16:19:36 -07003291 skge_read32(hw, B0_IMSK);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003292 spin_unlock_irq(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003293}
3294
David Howells7d12e782006-10-05 14:55:46 +01003295static irqreturn_t skge_intr(int irq, void *dev_id)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003296{
3297 struct skge_hw *hw = dev_id;
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003298 u32 status;
Stephen Hemminger29365c92006-09-01 15:53:48 -07003299 int handled = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003300
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003301 spin_lock(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003302 /* Reading this register masks IRQ */
3303 status = skge_read32(hw, B0_SP_ISRC);
Stephen Hemminger0486a8c2006-09-06 11:06:10 -07003304 if (status == 0 || status == ~0)
Stephen Hemminger29365c92006-09-01 15:53:48 -07003305 goto out;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003306
Stephen Hemminger29365c92006-09-01 15:53:48 -07003307 handled = 1;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003308 status &= hw->intr_mask;
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003309 if (status & IS_EXT_REG) {
3310 hw->intr_mask &= ~IS_EXT_REG;
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003311 tasklet_schedule(&hw->phy_task);
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003312 }
3313
Stephen Hemminger513f5332006-09-01 15:53:49 -07003314 if (status & (IS_XA1_F|IS_R1_F)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003315 struct skge_port *skge = netdev_priv(hw->dev[0]);
Stephen Hemminger513f5332006-09-01 15:53:49 -07003316 hw->intr_mask &= ~(IS_XA1_F|IS_R1_F);
Ben Hutchings288379f2009-01-19 16:43:59 -08003317 napi_schedule(&skge->napi);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003318 }
3319
Stephen Hemmingerd25f5a62005-06-27 11:33:14 -07003320 if (status & IS_PA_TO_TX1)
3321 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX1);
3322
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003323 if (status & IS_PA_TO_RX1) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07003324 ++hw->dev[0]->stats.rx_over_errors;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003325 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX1);
3326 }
3327
Stephen Hemmingerd25f5a62005-06-27 11:33:14 -07003328
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003329 if (status & IS_MAC1)
3330 skge_mac_intr(hw, 0);
Stephen Hemminger95566062005-06-27 11:33:02 -07003331
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003332 if (hw->dev[1]) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003333 struct skge_port *skge = netdev_priv(hw->dev[1]);
3334
Stephen Hemminger513f5332006-09-01 15:53:49 -07003335 if (status & (IS_XA2_F|IS_R2_F)) {
3336 hw->intr_mask &= ~(IS_XA2_F|IS_R2_F);
Ben Hutchings288379f2009-01-19 16:43:59 -08003337 napi_schedule(&skge->napi);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003338 }
3339
3340 if (status & IS_PA_TO_RX2) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07003341 ++hw->dev[1]->stats.rx_over_errors;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003342 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX2);
3343 }
3344
3345 if (status & IS_PA_TO_TX2)
3346 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX2);
3347
3348 if (status & IS_MAC2)
3349 skge_mac_intr(hw, 1);
3350 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003351
3352 if (status & IS_HW_ERR)
3353 skge_error_irq(hw);
3354
Stephen Hemminger7e676d92005-06-27 11:33:13 -07003355 skge_write32(hw, B0_IMSK, hw->intr_mask);
Stephen Hemminger78bc2182006-08-28 16:19:36 -07003356 skge_read32(hw, B0_IMSK);
Stephen Hemminger29365c92006-09-01 15:53:48 -07003357out:
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003358 spin_unlock(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003359
Stephen Hemminger29365c92006-09-01 15:53:48 -07003360 return IRQ_RETVAL(handled);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003361}
3362
3363#ifdef CONFIG_NET_POLL_CONTROLLER
3364static void skge_netpoll(struct net_device *dev)
3365{
3366 struct skge_port *skge = netdev_priv(dev);
3367
3368 disable_irq(dev->irq);
David Howells7d12e782006-10-05 14:55:46 +01003369 skge_intr(dev->irq, skge->hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003370 enable_irq(dev->irq);
3371}
3372#endif
3373
3374static int skge_set_mac_address(struct net_device *dev, void *p)
3375{
3376 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerc2681dd2005-10-03 12:03:13 -07003377 struct skge_hw *hw = skge->hw;
3378 unsigned port = skge->port;
3379 const struct sockaddr *addr = p;
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003380 u16 ctrl;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003381
3382 if (!is_valid_ether_addr(addr->sa_data))
3383 return -EADDRNOTAVAIL;
3384
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003385 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
Stephen Hemmingerc2681dd2005-10-03 12:03:13 -07003386
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003387 if (!netif_running(dev)) {
3388 memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN);
3389 memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN);
3390 } else {
3391 /* disable Rx */
3392 spin_lock_bh(&hw->phy_lock);
3393 ctrl = gma_read16(hw, port, GM_GP_CTRL);
3394 gma_write16(hw, port, GM_GP_CTRL, ctrl & ~GM_GPCR_RX_ENA);
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003395
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003396 memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN);
3397 memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN);
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003398
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003399 if (hw->chip_id == CHIP_ID_GENESIS)
3400 xm_outaddr(hw, port, XM_SA, dev->dev_addr);
3401 else {
3402 gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr);
3403 gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr);
3404 }
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003405
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003406 gma_write16(hw, port, GM_GP_CTRL, ctrl);
3407 spin_unlock_bh(&hw->phy_lock);
3408 }
Stephen Hemmingerc2681dd2005-10-03 12:03:13 -07003409
3410 return 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003411}
3412
3413static const struct {
3414 u8 id;
3415 const char *name;
3416} skge_chips[] = {
3417 { CHIP_ID_GENESIS, "Genesis" },
3418 { CHIP_ID_YUKON, "Yukon" },
3419 { CHIP_ID_YUKON_LITE, "Yukon-Lite"},
3420 { CHIP_ID_YUKON_LP, "Yukon-LP"},
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003421};
3422
3423static const char *skge_board_name(const struct skge_hw *hw)
3424{
3425 int i;
3426 static char buf[16];
3427
3428 for (i = 0; i < ARRAY_SIZE(skge_chips); i++)
3429 if (skge_chips[i].id == hw->chip_id)
3430 return skge_chips[i].name;
3431
3432 snprintf(buf, sizeof buf, "chipid 0x%x", hw->chip_id);
3433 return buf;
3434}
3435
3436
3437/*
3438 * Setup the board data structure, but don't bring up
3439 * the port(s)
3440 */
3441static int skge_reset(struct skge_hw *hw)
3442{
Stephen Hemmingeradba9e22005-11-08 10:33:40 -08003443 u32 reg;
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003444 u16 ctst, pci_status;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003445 u8 t8, mac_cfg, pmd_type;
Stephen Hemminger981d0372005-06-27 11:33:06 -07003446 int i;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003447
3448 ctst = skge_read16(hw, B0_CTST);
3449
3450 /* do a SW reset */
3451 skge_write8(hw, B0_CTST, CS_RST_SET);
3452 skge_write8(hw, B0_CTST, CS_RST_CLR);
3453
3454 /* clear PCI errors, if any */
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003455 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
3456 skge_write8(hw, B2_TST_CTRL2, 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003457
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003458 pci_read_config_word(hw->pdev, PCI_STATUS, &pci_status);
3459 pci_write_config_word(hw->pdev, PCI_STATUS,
3460 pci_status | PCI_STATUS_ERROR_BITS);
3461 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003462 skge_write8(hw, B0_CTST, CS_MRST_CLR);
3463
3464 /* restore CLK_RUN bits (for Yukon-Lite) */
3465 skge_write16(hw, B0_CTST,
3466 ctst & (CS_CLK_RUN_HOT|CS_CLK_RUN_RST|CS_CLK_RUN_ENA));
3467
3468 hw->chip_id = skge_read8(hw, B2_CHIP_ID);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003469 hw->phy_type = skge_read8(hw, B2_E_1) & 0xf;
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07003470 pmd_type = skge_read8(hw, B2_PMD_TYP);
3471 hw->copper = (pmd_type == 'T' || pmd_type == '1');
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003472
Stephen Hemminger95566062005-06-27 11:33:02 -07003473 switch (hw->chip_id) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003474 case CHIP_ID_GENESIS:
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003475 switch (hw->phy_type) {
3476 case SK_PHY_XMAC:
3477 hw->phy_addr = PHY_ADDR_XMAC;
3478 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003479 case SK_PHY_BCOM:
3480 hw->phy_addr = PHY_ADDR_BCOM;
3481 break;
3482 default:
Stephen Hemminger1479d132007-02-02 08:22:52 -08003483 dev_err(&hw->pdev->dev, "unsupported phy type 0x%x\n",
3484 hw->phy_type);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003485 return -EOPNOTSUPP;
3486 }
3487 break;
3488
3489 case CHIP_ID_YUKON:
3490 case CHIP_ID_YUKON_LITE:
3491 case CHIP_ID_YUKON_LP:
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003492 if (hw->phy_type < SK_PHY_MARV_COPPER && pmd_type != 'S')
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07003493 hw->copper = 1;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003494
3495 hw->phy_addr = PHY_ADDR_MARV;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003496 break;
3497
3498 default:
Stephen Hemminger1479d132007-02-02 08:22:52 -08003499 dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n",
3500 hw->chip_id);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003501 return -EOPNOTSUPP;
3502 }
3503
Stephen Hemminger981d0372005-06-27 11:33:06 -07003504 mac_cfg = skge_read8(hw, B2_MAC_CFG);
3505 hw->ports = (mac_cfg & CFG_SNG_MAC) ? 1 : 2;
3506 hw->chip_rev = (mac_cfg & CFG_CHIP_R_MSK) >> 4;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003507
3508 /* read the adapters RAM size */
3509 t8 = skge_read8(hw, B2_E_0);
3510 if (hw->chip_id == CHIP_ID_GENESIS) {
3511 if (t8 == 3) {
3512 /* special case: 4 x 64k x 36, offset = 0x80000 */
Linus Torvalds279e1da2007-11-15 08:44:36 -08003513 hw->ram_size = 0x100000;
3514 hw->ram_offset = 0x80000;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003515 } else
3516 hw->ram_size = t8 * 512;
Joe Perches67777f92010-02-17 15:01:58 +00003517 } else if (t8 == 0)
Linus Torvalds279e1da2007-11-15 08:44:36 -08003518 hw->ram_size = 0x20000;
3519 else
3520 hw->ram_size = t8 * 4096;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003521
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07003522 hw->intr_mask = IS_HW_ERR;
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003523
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07003524 /* Use PHY IRQ for all but fiber based Genesis board */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003525 if (!(hw->chip_id == CHIP_ID_GENESIS && hw->phy_type == SK_PHY_XMAC))
3526 hw->intr_mask |= IS_EXT_REG;
3527
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003528 if (hw->chip_id == CHIP_ID_GENESIS)
3529 genesis_init(hw);
3530 else {
3531 /* switch power to VCC (WA for VAUX problem) */
3532 skge_write8(hw, B0_POWER_CTRL,
3533 PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
Stephen Hemmingeradba9e22005-11-08 10:33:40 -08003534
Stephen Hemminger050ec182005-08-16 14:00:54 -07003535 /* avoid boards with stuck Hardware error bits */
3536 if ((skge_read32(hw, B0_ISRC) & IS_HW_ERR) &&
3537 (skge_read32(hw, B0_HWE_ISRC) & IS_IRQ_SENSOR)) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003538 dev_warn(&hw->pdev->dev, "stuck hardware sensor bit\n");
Stephen Hemminger050ec182005-08-16 14:00:54 -07003539 hw->intr_mask &= ~IS_HW_ERR;
3540 }
3541
Stephen Hemmingeradba9e22005-11-08 10:33:40 -08003542 /* Clear PHY COMA */
3543 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
3544 pci_read_config_dword(hw->pdev, PCI_DEV_REG1, &reg);
3545 reg &= ~PCI_PHY_COMA;
3546 pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg);
3547 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
3548
3549
Stephen Hemminger981d0372005-06-27 11:33:06 -07003550 for (i = 0; i < hw->ports; i++) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003551 skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
3552 skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003553 }
3554 }
3555
3556 /* turn off hardware timer (unused) */
3557 skge_write8(hw, B2_TI_CTRL, TIM_STOP);
3558 skge_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ);
3559 skge_write8(hw, B0_LED, LED_STAT_ON);
3560
3561 /* enable the Tx Arbiters */
Stephen Hemminger981d0372005-06-27 11:33:06 -07003562 for (i = 0; i < hw->ports; i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003563 skge_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003564
3565 /* Initialize ram interface */
3566 skge_write16(hw, B3_RI_CTRL, RI_RST_CLR);
3567
3568 skge_write8(hw, B3_RI_WTO_R1, SK_RI_TO_53);
3569 skge_write8(hw, B3_RI_WTO_XA1, SK_RI_TO_53);
3570 skge_write8(hw, B3_RI_WTO_XS1, SK_RI_TO_53);
3571 skge_write8(hw, B3_RI_RTO_R1, SK_RI_TO_53);
3572 skge_write8(hw, B3_RI_RTO_XA1, SK_RI_TO_53);
3573 skge_write8(hw, B3_RI_RTO_XS1, SK_RI_TO_53);
3574 skge_write8(hw, B3_RI_WTO_R2, SK_RI_TO_53);
3575 skge_write8(hw, B3_RI_WTO_XA2, SK_RI_TO_53);
3576 skge_write8(hw, B3_RI_WTO_XS2, SK_RI_TO_53);
3577 skge_write8(hw, B3_RI_RTO_R2, SK_RI_TO_53);
3578 skge_write8(hw, B3_RI_RTO_XA2, SK_RI_TO_53);
3579 skge_write8(hw, B3_RI_RTO_XS2, SK_RI_TO_53);
3580
3581 skge_write32(hw, B0_HWE_IMSK, IS_ERR_MSK);
3582
3583 /* Set interrupt moderation for Transmit only
3584 * Receive interrupts avoided by NAPI
3585 */
3586 skge_write32(hw, B2_IRQM_MSK, IS_XA1_F|IS_XA2_F);
3587 skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, 100));
3588 skge_write32(hw, B2_IRQM_CTRL, TIM_START);
3589
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003590 skge_write32(hw, B0_IMSK, hw->intr_mask);
3591
Stephen Hemminger981d0372005-06-27 11:33:06 -07003592 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003593 if (hw->chip_id == CHIP_ID_GENESIS)
3594 genesis_reset(hw, i);
3595 else
3596 yukon_reset(hw, i);
3597 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003598
3599 return 0;
3600}
3601
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003602
3603#ifdef CONFIG_SKGE_DEBUG
3604
3605static struct dentry *skge_debug;
3606
3607static int skge_debug_show(struct seq_file *seq, void *v)
3608{
3609 struct net_device *dev = seq->private;
3610 const struct skge_port *skge = netdev_priv(dev);
3611 const struct skge_hw *hw = skge->hw;
3612 const struct skge_element *e;
3613
3614 if (!netif_running(dev))
3615 return -ENETDOWN;
3616
3617 seq_printf(seq, "IRQ src=%x mask=%x\n", skge_read32(hw, B0_ISRC),
3618 skge_read32(hw, B0_IMSK));
3619
3620 seq_printf(seq, "Tx Ring: (%d)\n", skge_avail(&skge->tx_ring));
3621 for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) {
3622 const struct skge_tx_desc *t = e->desc;
3623 seq_printf(seq, "%#x dma=%#x%08x %#x csum=%#x/%x/%x\n",
3624 t->control, t->dma_hi, t->dma_lo, t->status,
3625 t->csum_offs, t->csum_write, t->csum_start);
3626 }
3627
Frans Pop2381a552010-03-24 07:57:36 +00003628 seq_printf(seq, "\nRx Ring:\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003629 for (e = skge->rx_ring.to_clean; ; e = e->next) {
3630 const struct skge_rx_desc *r = e->desc;
3631
3632 if (r->control & BMU_OWN)
3633 break;
3634
3635 seq_printf(seq, "%#x dma=%#x%08x %#x %#x csum=%#x/%x\n",
3636 r->control, r->dma_hi, r->dma_lo, r->status,
3637 r->timestamp, r->csum1, r->csum1_start);
3638 }
3639
3640 return 0;
3641}
3642
3643static int skge_debug_open(struct inode *inode, struct file *file)
3644{
3645 return single_open(file, skge_debug_show, inode->i_private);
3646}
3647
3648static const struct file_operations skge_debug_fops = {
3649 .owner = THIS_MODULE,
3650 .open = skge_debug_open,
3651 .read = seq_read,
3652 .llseek = seq_lseek,
3653 .release = single_release,
3654};
3655
3656/*
3657 * Use network device events to create/remove/rename
3658 * debugfs file entries
3659 */
3660static int skge_device_event(struct notifier_block *unused,
3661 unsigned long event, void *ptr)
3662{
3663 struct net_device *dev = ptr;
3664 struct skge_port *skge;
3665 struct dentry *d;
3666
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003667 if (dev->netdev_ops->ndo_open != &skge_up || !skge_debug)
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003668 goto done;
3669
3670 skge = netdev_priv(dev);
Joe Perches67777f92010-02-17 15:01:58 +00003671 switch (event) {
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003672 case NETDEV_CHANGENAME:
3673 if (skge->debugfs) {
3674 d = debugfs_rename(skge_debug, skge->debugfs,
3675 skge_debug, dev->name);
3676 if (d)
3677 skge->debugfs = d;
3678 else {
Joe Perchesf15063c2010-02-17 15:01:57 +00003679 netdev_info(dev, "rename failed\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003680 debugfs_remove(skge->debugfs);
3681 }
3682 }
3683 break;
3684
3685 case NETDEV_GOING_DOWN:
3686 if (skge->debugfs) {
3687 debugfs_remove(skge->debugfs);
3688 skge->debugfs = NULL;
3689 }
3690 break;
3691
3692 case NETDEV_UP:
3693 d = debugfs_create_file(dev->name, S_IRUGO,
3694 skge_debug, dev,
3695 &skge_debug_fops);
3696 if (!d || IS_ERR(d))
Joe Perchesf15063c2010-02-17 15:01:57 +00003697 netdev_info(dev, "debugfs create failed\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003698 else
3699 skge->debugfs = d;
3700 break;
3701 }
3702
3703done:
3704 return NOTIFY_DONE;
3705}
3706
3707static struct notifier_block skge_notifier = {
3708 .notifier_call = skge_device_event,
3709};
3710
3711
3712static __init void skge_debug_init(void)
3713{
3714 struct dentry *ent;
3715
3716 ent = debugfs_create_dir("skge", NULL);
3717 if (!ent || IS_ERR(ent)) {
Joe Perchesf15063c2010-02-17 15:01:57 +00003718 pr_info("debugfs create directory failed\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003719 return;
3720 }
3721
3722 skge_debug = ent;
3723 register_netdevice_notifier(&skge_notifier);
3724}
3725
3726static __exit void skge_debug_cleanup(void)
3727{
3728 if (skge_debug) {
3729 unregister_netdevice_notifier(&skge_notifier);
3730 debugfs_remove(skge_debug);
3731 skge_debug = NULL;
3732 }
3733}
3734
3735#else
3736#define skge_debug_init()
3737#define skge_debug_cleanup()
3738#endif
3739
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003740static const struct net_device_ops skge_netdev_ops = {
3741 .ndo_open = skge_up,
3742 .ndo_stop = skge_down,
Stephen Hemminger00829822008-11-20 20:14:53 -08003743 .ndo_start_xmit = skge_xmit_frame,
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003744 .ndo_do_ioctl = skge_ioctl,
3745 .ndo_get_stats = skge_get_stats,
3746 .ndo_tx_timeout = skge_tx_timeout,
3747 .ndo_change_mtu = skge_change_mtu,
3748 .ndo_validate_addr = eth_validate_addr,
3749 .ndo_set_multicast_list = skge_set_multicast,
3750 .ndo_set_mac_address = skge_set_mac_address,
3751#ifdef CONFIG_NET_POLL_CONTROLLER
3752 .ndo_poll_controller = skge_netpoll,
3753#endif
3754};
3755
3756
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003757/* Initialize network device */
Stephen Hemminger981d0372005-06-27 11:33:06 -07003758static struct net_device *skge_devinit(struct skge_hw *hw, int port,
3759 int highmem)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003760{
3761 struct skge_port *skge;
3762 struct net_device *dev = alloc_etherdev(sizeof(*skge));
3763
3764 if (!dev) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003765 dev_err(&hw->pdev->dev, "etherdev alloc failed\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003766 return NULL;
3767 }
3768
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003769 SET_NETDEV_DEV(dev, &hw->pdev->dev);
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003770 dev->netdev_ops = &skge_netdev_ops;
3771 dev->ethtool_ops = &skge_ethtool_ops;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003772 dev->watchdog_timeo = TX_WATCHDOG;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003773 dev->irq = hw->pdev->irq;
Stephen Hemminger513f5332006-09-01 15:53:49 -07003774
Stephen Hemminger981d0372005-06-27 11:33:06 -07003775 if (highmem)
3776 dev->features |= NETIF_F_HIGHDMA;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003777
3778 skge = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003779 netif_napi_add(dev, &skge->napi, skge_poll, NAPI_WEIGHT);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003780 skge->netdev = dev;
3781 skge->hw = hw;
3782 skge->msg_enable = netif_msg_init(debug, default_msg);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003783
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003784 skge->tx_ring.count = DEFAULT_TX_RING_SIZE;
3785 skge->rx_ring.count = DEFAULT_RX_RING_SIZE;
3786
3787 /* Auto speed and flow control */
3788 skge->autoneg = AUTONEG_ENABLE;
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07003789 skge->flow_control = FLOW_MODE_SYM_OR_REM;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003790 skge->duplex = -1;
3791 skge->speed = -1;
Stephen Hemminger31b619c2005-06-27 11:33:11 -07003792 skge->advertising = skge_supported_modes(hw);
Stephen Hemminger5b982c52007-05-08 13:36:20 -07003793
Rafael J. Wysocki7b55a4a2009-07-22 02:58:55 +00003794 if (device_can_wakeup(&hw->pdev->dev)) {
Stephen Hemminger5b982c52007-05-08 13:36:20 -07003795 skge->wol = wol_supported(hw) & WAKE_MAGIC;
Rafael J. Wysocki7b55a4a2009-07-22 02:58:55 +00003796 device_set_wakeup_enable(&hw->pdev->dev, skge->wol);
3797 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003798
3799 hw->dev[port] = dev;
3800
3801 skge->port = port;
3802
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003803 /* Only used for Genesis XMAC */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003804 setup_timer(&skge->link_timer, xm_link_timer, (unsigned long) skge);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003805
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003806 if (hw->chip_id != CHIP_ID_GENESIS) {
Michał Mirosławe92702b2011-03-31 01:01:35 +00003807 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
3808 NETIF_F_RXCSUM;
3809 dev->features |= dev->hw_features;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003810 }
3811
3812 /* read the mac address */
3813 memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port*8, ETH_ALEN);
John W. Linville56230d52005-09-12 10:48:57 -04003814 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003815
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003816 return dev;
3817}
3818
3819static void __devinit skge_show_addr(struct net_device *dev)
3820{
3821 const struct skge_port *skge = netdev_priv(dev);
3822
Joe Perchesd7072042010-02-09 11:49:53 +00003823 netif_info(skge, probe, skge->netdev, "addr %pM\n", dev->dev_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003824}
3825
Stanislaw Gruszka392bd0c2010-10-05 15:11:40 -07003826static int only_32bit_dma;
3827
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003828static int __devinit skge_probe(struct pci_dev *pdev,
3829 const struct pci_device_id *ent)
3830{
3831 struct net_device *dev, *dev1;
3832 struct skge_hw *hw;
3833 int err, using_dac = 0;
3834
Stephen Hemminger203babb2006-03-21 10:57:05 -08003835 err = pci_enable_device(pdev);
3836 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003837 dev_err(&pdev->dev, "cannot enable PCI device\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003838 goto err_out;
3839 }
3840
Stephen Hemminger203babb2006-03-21 10:57:05 -08003841 err = pci_request_regions(pdev, DRV_NAME);
3842 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003843 dev_err(&pdev->dev, "cannot obtain PCI resources\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003844 goto err_out_disable_pdev;
3845 }
3846
3847 pci_set_master(pdev);
3848
Stanislaw Gruszka392bd0c2010-10-05 15:11:40 -07003849 if (!only_32bit_dma && !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003850 using_dac = 1;
Yang Hongyang6a355282009-04-06 19:01:13 -07003851 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
Yang Hongyang284901a2009-04-06 19:01:15 -07003852 } else if (!(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))) {
Stephen Hemminger93aea712006-03-21 10:57:02 -08003853 using_dac = 0;
Yang Hongyang284901a2009-04-06 19:01:15 -07003854 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Stephen Hemminger93aea712006-03-21 10:57:02 -08003855 }
3856
3857 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003858 dev_err(&pdev->dev, "no usable DMA configuration\n");
Stephen Hemminger93aea712006-03-21 10:57:02 -08003859 goto err_out_free_regions;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003860 }
3861
3862#ifdef __BIG_ENDIAN
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08003863 /* byte swap descriptors in hardware */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003864 {
3865 u32 reg;
3866
3867 pci_read_config_dword(pdev, PCI_DEV_REG2, &reg);
3868 reg |= PCI_REV_DESC;
3869 pci_write_config_dword(pdev, PCI_DEV_REG2, reg);
3870 }
3871#endif
3872
3873 err = -ENOMEM;
Michal Schmidt415e69e2009-10-01 08:13:23 +00003874 /* space for skge@pci:0000:04:00.0 */
Joe Perches67777f92010-02-17 15:01:58 +00003875 hw = kzalloc(sizeof(*hw) + strlen(DRV_NAME "@pci:")
Michal Schmidt415e69e2009-10-01 08:13:23 +00003876 + strlen(pci_name(pdev)) + 1, GFP_KERNEL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003877 if (!hw) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003878 dev_err(&pdev->dev, "cannot allocate hardware struct\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003879 goto err_out_free_regions;
3880 }
Michal Schmidt415e69e2009-10-01 08:13:23 +00003881 sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003882
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003883 hw->pdev = pdev;
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07003884 spin_lock_init(&hw->hw_lock);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003885 spin_lock_init(&hw->phy_lock);
Joe Perches164165d2009-11-19 09:30:10 +00003886 tasklet_init(&hw->phy_task, skge_extirq, (unsigned long) hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003887
3888 hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
3889 if (!hw->regs) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003890 dev_err(&pdev->dev, "cannot map device registers\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003891 goto err_out_free_hw;
3892 }
3893
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003894 err = skge_reset(hw);
3895 if (err)
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003896 goto err_out_iounmap;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003897
Joe Perchesf15063c2010-02-17 15:01:57 +00003898 pr_info("%s addr 0x%llx irq %d chip %s rev %d\n",
3899 DRV_VERSION,
3900 (unsigned long long)pci_resource_start(pdev, 0), pdev->irq,
3901 skge_board_name(hw), hw->chip_rev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003902
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003903 dev = skge_devinit(hw, 0, using_dac);
3904 if (!dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003905 goto err_out_led_off;
3906
Stephen Hemmingerfae87592007-02-02 08:22:51 -08003907 /* Some motherboards are broken and has zero in ROM. */
Stephen Hemminger1479d132007-02-02 08:22:52 -08003908 if (!is_valid_ether_addr(dev->dev_addr))
3909 dev_warn(&pdev->dev, "bad (zero?) ethernet address in rom\n");
Stephen Hemminger631ae322006-06-06 10:11:14 -07003910
Stephen Hemminger203babb2006-03-21 10:57:05 -08003911 err = register_netdev(dev);
3912 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003913 dev_err(&pdev->dev, "cannot register net device\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003914 goto err_out_free_netdev;
3915 }
3916
Michal Schmidt415e69e2009-10-01 08:13:23 +00003917 err = request_irq(pdev->irq, skge_intr, IRQF_SHARED, hw->irq_name, hw);
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003918 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003919 dev_err(&pdev->dev, "%s: cannot assign irq %d\n",
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003920 dev->name, pdev->irq);
3921 goto err_out_unregister;
3922 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003923 skge_show_addr(dev);
3924
Mike McCormackf1914222009-09-23 03:50:36 +00003925 if (hw->ports > 1) {
3926 dev1 = skge_devinit(hw, 1, using_dac);
3927 if (dev1 && register_netdev(dev1) == 0)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003928 skge_show_addr(dev1);
3929 else {
3930 /* Failure to register second port need not be fatal */
Stephen Hemminger1479d132007-02-02 08:22:52 -08003931 dev_warn(&pdev->dev, "register of second port failed\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003932 hw->dev[1] = NULL;
Mike McCormackf1914222009-09-23 03:50:36 +00003933 hw->ports = 1;
3934 if (dev1)
3935 free_netdev(dev1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003936 }
3937 }
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003938 pci_set_drvdata(pdev, hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003939
3940 return 0;
3941
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003942err_out_unregister:
3943 unregister_netdev(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003944err_out_free_netdev:
3945 free_netdev(dev);
3946err_out_led_off:
3947 skge_write16(hw, B0_LED, LED_STAT_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003948err_out_iounmap:
3949 iounmap(hw->regs);
3950err_out_free_hw:
3951 kfree(hw);
3952err_out_free_regions:
3953 pci_release_regions(pdev);
3954err_out_disable_pdev:
3955 pci_disable_device(pdev);
3956 pci_set_drvdata(pdev, NULL);
3957err_out:
3958 return err;
3959}
3960
3961static void __devexit skge_remove(struct pci_dev *pdev)
3962{
3963 struct skge_hw *hw = pci_get_drvdata(pdev);
3964 struct net_device *dev0, *dev1;
3965
Stephen Hemminger95566062005-06-27 11:33:02 -07003966 if (!hw)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003967 return;
3968
Joe Perches67777f92010-02-17 15:01:58 +00003969 dev1 = hw->dev[1];
3970 if (dev1)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003971 unregister_netdev(dev1);
3972 dev0 = hw->dev[0];
3973 unregister_netdev(dev0);
3974
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003975 tasklet_disable(&hw->phy_task);
3976
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003977 spin_lock_irq(&hw->hw_lock);
3978 hw->intr_mask = 0;
Stephen Hemminger46a60f22005-09-09 12:54:56 -07003979 skge_write32(hw, B0_IMSK, 0);
Stephen Hemminger78bc2182006-08-28 16:19:36 -07003980 skge_read32(hw, B0_IMSK);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003981 spin_unlock_irq(&hw->hw_lock);
3982
Stephen Hemminger46a60f22005-09-09 12:54:56 -07003983 skge_write16(hw, B0_LED, LED_STAT_OFF);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07003984 skge_write8(hw, B0_CTST, CS_RST_SET);
3985
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003986 free_irq(pdev->irq, hw);
3987 pci_release_regions(pdev);
3988 pci_disable_device(pdev);
3989 if (dev1)
3990 free_netdev(dev1);
3991 free_netdev(dev0);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07003992
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003993 iounmap(hw->regs);
3994 kfree(hw);
3995 pci_set_drvdata(pdev, NULL);
3996}
3997
3998#ifdef CONFIG_PM
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00003999static int skge_suspend(struct device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004000{
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004001 struct pci_dev *pdev = to_pci_dev(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004002 struct skge_hw *hw = pci_get_drvdata(pdev);
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004003 int i;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004004
Stephen Hemmingere3b7df12007-05-11 11:21:45 -07004005 if (!hw)
4006 return 0;
4007
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004008 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004009 struct net_device *dev = hw->dev[i];
Stephen Hemmingera504e642007-02-02 08:22:53 -08004010 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004011
Stephen Hemmingera504e642007-02-02 08:22:53 -08004012 if (netif_running(dev))
4013 skge_down(dev);
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004014
Stephen Hemmingera504e642007-02-02 08:22:53 -08004015 if (skge->wol)
4016 skge_wol_init(skge);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004017 }
4018
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004019 skge_write32(hw, B0_IMSK, 0);
Rafael J. Wysocki5177b322008-10-29 14:22:14 -07004020
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004021 return 0;
4022}
4023
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004024static int skge_resume(struct device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004025{
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004026 struct pci_dev *pdev = to_pci_dev(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004027 struct skge_hw *hw = pci_get_drvdata(pdev);
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004028 int i, err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004029
Stephen Hemmingere3b7df12007-05-11 11:21:45 -07004030 if (!hw)
4031 return 0;
4032
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004033 err = skge_reset(hw);
4034 if (err)
4035 goto out;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004036
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004037 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004038 struct net_device *dev = hw->dev[i];
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004039
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004040 if (netif_running(dev)) {
4041 err = skge_up(dev);
4042
4043 if (err) {
Joe Perchesf15063c2010-02-17 15:01:57 +00004044 netdev_err(dev, "could not up: %d\n", err);
Stephen Hemmingeredd702e2005-12-15 12:18:00 -08004045 dev_close(dev);
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004046 goto out;
4047 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004048 }
4049 }
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004050out:
4051 return err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004052}
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004053
4054static SIMPLE_DEV_PM_OPS(skge_pm_ops, skge_suspend, skge_resume);
4055#define SKGE_PM_OPS (&skge_pm_ops)
4056
4057#else
4058
4059#define SKGE_PM_OPS NULL
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004060#endif
4061
Stephen Hemminger692412b2007-04-09 15:32:45 -07004062static void skge_shutdown(struct pci_dev *pdev)
4063{
4064 struct skge_hw *hw = pci_get_drvdata(pdev);
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004065 int i;
Stephen Hemminger692412b2007-04-09 15:32:45 -07004066
Stephen Hemmingere3b7df12007-05-11 11:21:45 -07004067 if (!hw)
4068 return;
4069
Stephen Hemminger692412b2007-04-09 15:32:45 -07004070 for (i = 0; i < hw->ports; i++) {
4071 struct net_device *dev = hw->dev[i];
4072 struct skge_port *skge = netdev_priv(dev);
4073
4074 if (skge->wol)
4075 skge_wol_init(skge);
Stephen Hemminger692412b2007-04-09 15:32:45 -07004076 }
4077
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004078 pci_wake_from_d3(pdev, device_may_wakeup(&pdev->dev));
Stephen Hemminger692412b2007-04-09 15:32:45 -07004079 pci_set_power_state(pdev, PCI_D3hot);
Stephen Hemminger692412b2007-04-09 15:32:45 -07004080}
4081
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004082static struct pci_driver skge_driver = {
4083 .name = DRV_NAME,
4084 .id_table = skge_id_table,
4085 .probe = skge_probe,
4086 .remove = __devexit_p(skge_remove),
Stephen Hemminger692412b2007-04-09 15:32:45 -07004087 .shutdown = skge_shutdown,
stephen hemminger7dbf6ac2010-12-30 08:52:29 +00004088 .driver.pm = SKGE_PM_OPS,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004089};
4090
Stanislaw Gruszka392bd0c2010-10-05 15:11:40 -07004091static struct dmi_system_id skge_32bit_dma_boards[] = {
4092 {
4093 .ident = "Gigabyte nForce boards",
4094 .matches = {
4095 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co"),
4096 DMI_MATCH(DMI_BOARD_NAME, "nForce"),
4097 },
4098 },
4099 {}
4100};
4101
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004102static int __init skge_init_module(void)
4103{
Stanislaw Gruszka392bd0c2010-10-05 15:11:40 -07004104 if (dmi_check_system(skge_32bit_dma_boards))
4105 only_32bit_dma = 1;
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07004106 skge_debug_init();
Jeff Garzik29917622006-08-19 17:48:59 -04004107 return pci_register_driver(&skge_driver);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004108}
4109
4110static void __exit skge_cleanup_module(void)
4111{
4112 pci_unregister_driver(&skge_driver);
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07004113 skge_debug_cleanup();
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004114}
4115
4116module_init(skge_init_module);
4117module_exit(skge_cleanup_module);