blob: 720af1c7854b1af1a2179c35b958e5e54a2c6cb5 [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>
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040045#include <asm/irq.h>
46
47#include "skge.h"
48
49#define DRV_NAME "skge"
Stephen Hemmingerbf9f56d2007-11-26 11:54:53 -080050#define DRV_VERSION "1.13"
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040051
52#define DEFAULT_TX_RING_SIZE 128
53#define DEFAULT_RX_RING_SIZE 512
54#define MAX_TX_RING_SIZE 1024
Stephen Hemminger9db96472006-06-06 10:11:12 -070055#define TX_LOW_WATER (MAX_SKB_FRAGS + 1)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040056#define MAX_RX_RING_SIZE 4096
Stephen Hemminger19a33d42005-06-27 11:33:15 -070057#define RX_COPY_THRESHOLD 128
58#define RX_BUF_SIZE 1536
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040059#define PHY_RETRIES 1000
60#define ETH_JUMBO_MTU 9000
61#define TX_WATCHDOG (5 * HZ)
62#define NAPI_WEIGHT 64
Stephen Hemminger6abebb52005-07-22 16:26:10 -070063#define BLINK_MS 250
Stephen Hemminger501fb722007-10-16 12:15:51 -070064#define LINK_HZ HZ
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040065
Stephen Hemmingerafa151b2007-10-16 12:15:53 -070066#define SKGE_EEPROM_MAGIC 0x9933aabb
67
68
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040069MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver");
Stephen Hemminger65ebe6342007-01-23 11:38:57 -080070MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040071MODULE_LICENSE("GPL");
72MODULE_VERSION(DRV_VERSION);
73
Joe Perches67777f92010-02-17 15:01:58 +000074static const u32 default_msg = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
75 NETIF_MSG_LINK | NETIF_MSG_IFUP |
76 NETIF_MSG_IFDOWN);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040077
78static int debug = -1; /* defaults above */
79module_param(debug, int, 0);
80MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
81
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000082static DEFINE_PCI_DEVICE_TABLE(skge_id_table) = {
Stephen Hemminger275834d2005-06-27 11:33:03 -070083 { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940) },
84 { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940B) },
85 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE) },
86 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU) },
Stephen Hemmingerf19841f2007-02-23 14:04:54 -080087 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T) },
Stephen Hemminger2d2a3872006-05-17 14:37:04 -070088 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b01) }, /* DGE-530T */
Stephen Hemminger275834d2005-06-27 11:33:03 -070089 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) },
90 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */
91 { PCI_DEVICE(PCI_VENDOR_ID_CNET, PCI_DEVICE_ID_CNET_GIGACARD) },
Stephen Hemminger275834d2005-06-27 11:33:03 -070092 { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1064) },
Stephen Hemmingerf19841f2007-02-23 14:04:54 -080093 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015 },
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -040094 { 0 }
95};
96MODULE_DEVICE_TABLE(pci, skge_id_table);
97
98static int skge_up(struct net_device *dev);
99static int skge_down(struct net_device *dev);
Stephen Hemmingeree294dc2005-12-14 15:47:44 -0800100static void skge_phy_reset(struct skge_port *skge);
Stephen Hemminger513f5332006-09-01 15:53:49 -0700101static void skge_tx_clean(struct net_device *dev);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -0800102static int xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val);
103static int gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400104static void genesis_get_stats(struct skge_port *skge, u64 *data);
105static void yukon_get_stats(struct skge_port *skge, u64 *data);
106static void yukon_init(struct skge_hw *hw, int port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400107static void genesis_mac_init(struct skge_hw *hw, int port);
Stephen Hemminger45bada62005-06-27 11:33:12 -0700108static void genesis_link_up(struct skge_port *skge);
Stephen Hemmingerf80d0322008-11-19 22:01:26 -0800109static void skge_set_multicast(struct net_device *dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400110
Stephen Hemminger7e676d92005-06-27 11:33:13 -0700111/* Avoid conditionals by using array */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400112static const int txqaddr[] = { Q_XA1, Q_XA2 };
113static const int rxqaddr[] = { Q_R1, Q_R2 };
114static const u32 rxirqmask[] = { IS_R1_F, IS_R2_F };
115static const u32 txirqmask[] = { IS_XA1_F, IS_XA2_F };
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -0700116static const u32 napimask[] = { IS_R1_F|IS_XA1_F, IS_R2_F|IS_XA2_F };
117static const u32 portmask[] = { IS_PORT_1, IS_PORT_2 };
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400118
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400119static int skge_get_regs_len(struct net_device *dev)
120{
Stephen Hemmingerc3f8be92005-09-19 15:37:34 -0700121 return 0x4000;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400122}
123
124/*
Stephen Hemmingerc3f8be92005-09-19 15:37:34 -0700125 * Returns copy of whole control register region
126 * Note: skip RAM address register because accessing it will
127 * cause bus hangs!
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400128 */
129static void skge_get_regs(struct net_device *dev, struct ethtool_regs *regs,
130 void *p)
131{
132 const struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400133 const void __iomem *io = skge->hw->regs;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400134
135 regs->version = 1;
Stephen Hemmingerc3f8be92005-09-19 15:37:34 -0700136 memset(p, 0, regs->len);
137 memcpy_fromio(p, io, B3_RAM_ADDR);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400138
Stephen Hemmingerc3f8be92005-09-19 15:37:34 -0700139 memcpy_fromio(p + B3_RI_WTO_R1, io + B3_RI_WTO_R1,
140 regs->len - B3_RI_WTO_R1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400141}
142
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800143/* Wake on Lan only supported on Yukon chips with rev 1 or above */
Stephen Hemmingera504e642007-02-02 08:22:53 -0800144static u32 wol_supported(const struct skge_hw *hw)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400145{
Stephen Hemmingerd17ecb22007-05-07 11:01:55 -0700146 if (hw->chip_id == CHIP_ID_GENESIS)
Stephen Hemmingera504e642007-02-02 08:22:53 -0800147 return 0;
Stephen Hemmingerd17ecb22007-05-07 11:01:55 -0700148
149 if (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)
150 return 0;
151
152 return WAKE_MAGIC | WAKE_PHY;
Stephen Hemmingera504e642007-02-02 08:22:53 -0800153}
154
Stephen Hemmingera504e642007-02-02 08:22:53 -0800155static void skge_wol_init(struct skge_port *skge)
156{
157 struct skge_hw *hw = skge->hw;
158 int port = skge->port;
Stephen Hemminger692412b2007-04-09 15:32:45 -0700159 u16 ctrl;
Stephen Hemmingera504e642007-02-02 08:22:53 -0800160
Stephen Hemmingera504e642007-02-02 08:22:53 -0800161 skge_write16(hw, B0_CTST, CS_RST_CLR);
162 skge_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR);
163
Stephen Hemminger692412b2007-04-09 15:32:45 -0700164 /* Turn on Vaux */
165 skge_write8(hw, B0_POWER_CTRL,
166 PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_ON | PC_VCC_OFF);
167
168 /* WA code for COMA mode -- clear PHY reset */
169 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
170 hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
171 u32 reg = skge_read32(hw, B2_GP_IO);
172 reg |= GP_DIR_9;
173 reg &= ~GP_IO_9;
174 skge_write32(hw, B2_GP_IO, reg);
175 }
176
177 skge_write32(hw, SK_REG(port, GPHY_CTRL),
178 GPC_DIS_SLEEP |
179 GPC_HWCFG_M_3 | GPC_HWCFG_M_2 | GPC_HWCFG_M_1 | GPC_HWCFG_M_0 |
180 GPC_ANEG_1 | GPC_RST_SET);
181
182 skge_write32(hw, SK_REG(port, GPHY_CTRL),
183 GPC_DIS_SLEEP |
184 GPC_HWCFG_M_3 | GPC_HWCFG_M_2 | GPC_HWCFG_M_1 | GPC_HWCFG_M_0 |
185 GPC_ANEG_1 | GPC_RST_CLR);
186
187 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
Stephen Hemmingera504e642007-02-02 08:22:53 -0800188
189 /* Force to 10/100 skge_reset will re-enable on resume */
Stephen Hemminger692412b2007-04-09 15:32:45 -0700190 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV,
Joe Perches67777f92010-02-17 15:01:58 +0000191 (PHY_AN_100FULL | PHY_AN_100HALF |
192 PHY_AN_10FULL | PHY_AN_10HALF | PHY_AN_CSMA));
Stephen Hemminger692412b2007-04-09 15:32:45 -0700193 /* no 1000 HD/FD */
194 gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, 0);
195 gm_phy_write(hw, port, PHY_MARV_CTRL,
196 PHY_CT_RESET | PHY_CT_SPS_LSB | PHY_CT_ANE |
197 PHY_CT_RE_CFG | PHY_CT_DUP_MD);
Stephen Hemmingera504e642007-02-02 08:22:53 -0800198
Stephen Hemmingera504e642007-02-02 08:22:53 -0800199
200 /* Set GMAC to no flow control and auto update for speed/duplex */
201 gma_write16(hw, port, GM_GP_CTRL,
202 GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA|
203 GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS);
204
205 /* Set WOL address */
206 memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR),
207 skge->netdev->dev_addr, ETH_ALEN);
208
209 /* Turn on appropriate WOL control bits */
210 skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT);
211 ctrl = 0;
212 if (skge->wol & WAKE_PHY)
213 ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT;
214 else
215 ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT;
216
217 if (skge->wol & WAKE_MAGIC)
218 ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT;
219 else
Joe Perchesa419aef2009-08-18 11:18:35 -0700220 ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT;
Stephen Hemmingera504e642007-02-02 08:22:53 -0800221
222 ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT;
223 skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
224
225 /* block receiver */
226 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400227}
228
229static void skge_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
230{
231 struct skge_port *skge = netdev_priv(dev);
232
Stephen Hemmingera504e642007-02-02 08:22:53 -0800233 wol->supported = wol_supported(skge->hw);
234 wol->wolopts = skge->wol;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400235}
236
237static int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
238{
239 struct skge_port *skge = netdev_priv(dev);
240 struct skge_hw *hw = skge->hw;
241
Joe Perches8e95a202009-12-03 07:58:21 +0000242 if ((wol->wolopts & ~wol_supported(hw)) ||
243 !device_can_wakeup(&hw->pdev->dev))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400244 return -EOPNOTSUPP;
245
Stephen Hemmingera504e642007-02-02 08:22:53 -0800246 skge->wol = wol->wolopts;
Rafael J. Wysocki5177b322008-10-29 14:22:14 -0700247
248 device_set_wakeup_enable(&hw->pdev->dev, skge->wol);
249
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400250 return 0;
251}
252
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800253/* Determine supported/advertised modes based on hardware.
254 * Note: ethtool ADVERTISED_xxx == SUPPORTED_xxx
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700255 */
256static u32 skge_supported_modes(const struct skge_hw *hw)
257{
258 u32 supported;
259
Stephen Hemminger5e1705d2005-08-16 14:00:58 -0700260 if (hw->copper) {
Joe Perches67777f92010-02-17 15:01:58 +0000261 supported = (SUPPORTED_10baseT_Half |
262 SUPPORTED_10baseT_Full |
263 SUPPORTED_100baseT_Half |
264 SUPPORTED_100baseT_Full |
265 SUPPORTED_1000baseT_Half |
266 SUPPORTED_1000baseT_Full |
267 SUPPORTED_Autoneg |
268 SUPPORTED_TP);
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700269
270 if (hw->chip_id == CHIP_ID_GENESIS)
Joe Perches67777f92010-02-17 15:01:58 +0000271 supported &= ~(SUPPORTED_10baseT_Half |
272 SUPPORTED_10baseT_Full |
273 SUPPORTED_100baseT_Half |
274 SUPPORTED_100baseT_Full);
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700275
276 else if (hw->chip_id == CHIP_ID_YUKON)
277 supported &= ~SUPPORTED_1000baseT_Half;
278 } else
Joe Perches67777f92010-02-17 15:01:58 +0000279 supported = (SUPPORTED_1000baseT_Full |
280 SUPPORTED_1000baseT_Half |
281 SUPPORTED_FIBRE |
282 SUPPORTED_Autoneg);
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700283
284 return supported;
285}
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400286
287static int skge_get_settings(struct net_device *dev,
288 struct ethtool_cmd *ecmd)
289{
290 struct skge_port *skge = netdev_priv(dev);
291 struct skge_hw *hw = skge->hw;
292
293 ecmd->transceiver = XCVR_INTERNAL;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700294 ecmd->supported = skge_supported_modes(hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400295
Stephen Hemminger5e1705d2005-08-16 14:00:58 -0700296 if (hw->copper) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400297 ecmd->port = PORT_TP;
298 ecmd->phy_address = hw->phy_addr;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700299 } else
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400300 ecmd->port = PORT_FIBRE;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400301
302 ecmd->advertising = skge->advertising;
303 ecmd->autoneg = skge->autoneg;
304 ecmd->speed = skge->speed;
305 ecmd->duplex = skge->duplex;
306 return 0;
307}
308
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400309static int skge_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
310{
311 struct skge_port *skge = netdev_priv(dev);
312 const struct skge_hw *hw = skge->hw;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700313 u32 supported = skge_supported_modes(hw);
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000314 int err = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400315
316 if (ecmd->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700317 ecmd->advertising = supported;
318 skge->duplex = -1;
319 skge->speed = -1;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400320 } else {
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700321 u32 setting;
322
Stephen Hemminger2c668512005-07-22 16:26:07 -0700323 switch (ecmd->speed) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400324 case SPEED_1000:
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700325 if (ecmd->duplex == DUPLEX_FULL)
326 setting = SUPPORTED_1000baseT_Full;
327 else if (ecmd->duplex == DUPLEX_HALF)
328 setting = SUPPORTED_1000baseT_Half;
329 else
330 return -EINVAL;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400331 break;
332 case SPEED_100:
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700333 if (ecmd->duplex == DUPLEX_FULL)
334 setting = SUPPORTED_100baseT_Full;
335 else if (ecmd->duplex == DUPLEX_HALF)
336 setting = SUPPORTED_100baseT_Half;
337 else
338 return -EINVAL;
339 break;
340
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400341 case SPEED_10:
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700342 if (ecmd->duplex == DUPLEX_FULL)
343 setting = SUPPORTED_10baseT_Full;
344 else if (ecmd->duplex == DUPLEX_HALF)
345 setting = SUPPORTED_10baseT_Half;
346 else
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400347 return -EINVAL;
348 break;
349 default:
350 return -EINVAL;
351 }
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700352
353 if ((setting & supported) == 0)
354 return -EINVAL;
355
356 skge->speed = ecmd->speed;
357 skge->duplex = ecmd->duplex;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400358 }
359
360 skge->autoneg = ecmd->autoneg;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400361 skge->advertising = ecmd->advertising;
362
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000363 if (netif_running(dev)) {
364 skge_down(dev);
365 err = skge_up(dev);
366 if (err) {
367 dev_close(dev);
368 return err;
369 }
370 }
Stephen Hemmingeree294dc2005-12-14 15:47:44 -0800371
Joe Perches67777f92010-02-17 15:01:58 +0000372 return 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400373}
374
375static void skge_get_drvinfo(struct net_device *dev,
376 struct ethtool_drvinfo *info)
377{
378 struct skge_port *skge = netdev_priv(dev);
379
380 strcpy(info->driver, DRV_NAME);
381 strcpy(info->version, DRV_VERSION);
382 strcpy(info->fw_version, "N/A");
383 strcpy(info->bus_info, pci_name(skge->hw->pdev));
384}
385
386static const struct skge_stat {
387 char name[ETH_GSTRING_LEN];
388 u16 xmac_offset;
389 u16 gma_offset;
390} skge_stats[] = {
391 { "tx_bytes", XM_TXO_OK_HI, GM_TXO_OK_HI },
392 { "rx_bytes", XM_RXO_OK_HI, GM_RXO_OK_HI },
393
394 { "tx_broadcast", XM_TXF_BC_OK, GM_TXF_BC_OK },
395 { "rx_broadcast", XM_RXF_BC_OK, GM_RXF_BC_OK },
396 { "tx_multicast", XM_TXF_MC_OK, GM_TXF_MC_OK },
397 { "rx_multicast", XM_RXF_MC_OK, GM_RXF_MC_OK },
398 { "tx_unicast", XM_TXF_UC_OK, GM_TXF_UC_OK },
399 { "rx_unicast", XM_RXF_UC_OK, GM_RXF_UC_OK },
400 { "tx_mac_pause", XM_TXF_MPAUSE, GM_TXF_MPAUSE },
401 { "rx_mac_pause", XM_RXF_MPAUSE, GM_RXF_MPAUSE },
402
403 { "collisions", XM_TXF_SNG_COL, GM_TXF_SNG_COL },
404 { "multi_collisions", XM_TXF_MUL_COL, GM_TXF_MUL_COL },
405 { "aborted", XM_TXF_ABO_COL, GM_TXF_ABO_COL },
406 { "late_collision", XM_TXF_LAT_COL, GM_TXF_LAT_COL },
407 { "fifo_underrun", XM_TXE_FIFO_UR, GM_TXE_FIFO_UR },
408 { "fifo_overflow", XM_RXE_FIFO_OV, GM_RXE_FIFO_OV },
409
410 { "rx_toolong", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR },
411 { "rx_jabber", XM_RXF_JAB_PKT, GM_RXF_JAB_PKT },
412 { "rx_runt", XM_RXE_RUNT, GM_RXE_FRAG },
413 { "rx_too_long", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR },
414 { "rx_fcs_error", XM_RXF_FCS_ERR, GM_RXF_FCS_ERR },
415};
416
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700417static int skge_get_sset_count(struct net_device *dev, int sset)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400418{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700419 switch (sset) {
420 case ETH_SS_STATS:
421 return ARRAY_SIZE(skge_stats);
422 default:
423 return -EOPNOTSUPP;
424 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400425}
426
427static void skge_get_ethtool_stats(struct net_device *dev,
428 struct ethtool_stats *stats, u64 *data)
429{
430 struct skge_port *skge = netdev_priv(dev);
431
432 if (skge->hw->chip_id == CHIP_ID_GENESIS)
433 genesis_get_stats(skge, data);
434 else
435 yukon_get_stats(skge, data);
436}
437
438/* Use hardware MIB variables for critical path statistics and
439 * transmit feedback not reported at interrupt.
440 * Other errors are accounted for in interrupt handler.
441 */
442static struct net_device_stats *skge_get_stats(struct net_device *dev)
443{
444 struct skge_port *skge = netdev_priv(dev);
445 u64 data[ARRAY_SIZE(skge_stats)];
446
447 if (skge->hw->chip_id == CHIP_ID_GENESIS)
448 genesis_get_stats(skge, data);
449 else
450 yukon_get_stats(skge, data);
451
Stephen Hemmingerda007722007-10-16 12:15:52 -0700452 dev->stats.tx_bytes = data[0];
453 dev->stats.rx_bytes = data[1];
454 dev->stats.tx_packets = data[2] + data[4] + data[6];
455 dev->stats.rx_packets = data[3] + data[5] + data[7];
456 dev->stats.multicast = data[3] + data[5];
457 dev->stats.collisions = data[10];
458 dev->stats.tx_aborted_errors = data[12];
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400459
Stephen Hemmingerda007722007-10-16 12:15:52 -0700460 return &dev->stats;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400461}
462
463static void skge_get_strings(struct net_device *dev, u32 stringset, u8 *data)
464{
465 int i;
466
Stephen Hemminger95566062005-06-27 11:33:02 -0700467 switch (stringset) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400468 case ETH_SS_STATS:
469 for (i = 0; i < ARRAY_SIZE(skge_stats); i++)
470 memcpy(data + i * ETH_GSTRING_LEN,
471 skge_stats[i].name, ETH_GSTRING_LEN);
472 break;
473 }
474}
475
476static void skge_get_ring_param(struct net_device *dev,
477 struct ethtool_ringparam *p)
478{
479 struct skge_port *skge = netdev_priv(dev);
480
481 p->rx_max_pending = MAX_RX_RING_SIZE;
482 p->tx_max_pending = MAX_TX_RING_SIZE;
483 p->rx_mini_max_pending = 0;
484 p->rx_jumbo_max_pending = 0;
485
486 p->rx_pending = skge->rx_ring.count;
487 p->tx_pending = skge->tx_ring.count;
488 p->rx_mini_pending = 0;
489 p->rx_jumbo_pending = 0;
490}
491
492static int skge_set_ring_param(struct net_device *dev,
493 struct ethtool_ringparam *p)
494{
495 struct skge_port *skge = netdev_priv(dev);
Wang Chene824b3e2008-09-26 16:20:32 +0800496 int err = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400497
498 if (p->rx_pending == 0 || p->rx_pending > MAX_RX_RING_SIZE ||
Stephen Hemminger9db96472006-06-06 10:11:12 -0700499 p->tx_pending < TX_LOW_WATER || p->tx_pending > MAX_TX_RING_SIZE)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400500 return -EINVAL;
501
502 skge->rx_ring.count = p->rx_pending;
503 skge->tx_ring.count = p->tx_pending;
504
505 if (netif_running(dev)) {
506 skge_down(dev);
Stephen Hemminger3b8bb472005-12-14 15:47:48 -0800507 err = skge_up(dev);
508 if (err)
509 dev_close(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400510 }
511
Wang Chene824b3e2008-09-26 16:20:32 +0800512 return err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400513}
514
515static u32 skge_get_msglevel(struct net_device *netdev)
516{
517 struct skge_port *skge = netdev_priv(netdev);
518 return skge->msg_enable;
519}
520
521static void skge_set_msglevel(struct net_device *netdev, u32 value)
522{
523 struct skge_port *skge = netdev_priv(netdev);
524 skge->msg_enable = value;
525}
526
527static int skge_nway_reset(struct net_device *dev)
528{
529 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400530
531 if (skge->autoneg != AUTONEG_ENABLE || !netif_running(dev))
532 return -EINVAL;
533
Stephen Hemmingeree294dc2005-12-14 15:47:44 -0800534 skge_phy_reset(skge);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400535 return 0;
536}
537
538static int skge_set_sg(struct net_device *dev, u32 data)
539{
540 struct skge_port *skge = netdev_priv(dev);
541 struct skge_hw *hw = skge->hw;
542
543 if (hw->chip_id == CHIP_ID_GENESIS && data)
544 return -EOPNOTSUPP;
545 return ethtool_op_set_sg(dev, data);
546}
547
548static int skge_set_tx_csum(struct net_device *dev, u32 data)
549{
550 struct skge_port *skge = netdev_priv(dev);
551 struct skge_hw *hw = skge->hw;
552
553 if (hw->chip_id == CHIP_ID_GENESIS && data)
554 return -EOPNOTSUPP;
555
556 return ethtool_op_set_tx_csum(dev, data);
557}
558
559static u32 skge_get_rx_csum(struct net_device *dev)
560{
561 struct skge_port *skge = netdev_priv(dev);
562
563 return skge->rx_csum;
564}
565
566/* Only Yukon supports checksum offload. */
567static int skge_set_rx_csum(struct net_device *dev, u32 data)
568{
569 struct skge_port *skge = netdev_priv(dev);
570
571 if (skge->hw->chip_id == CHIP_ID_GENESIS && data)
572 return -EOPNOTSUPP;
573
574 skge->rx_csum = data;
575 return 0;
576}
577
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400578static void skge_get_pauseparam(struct net_device *dev,
579 struct ethtool_pauseparam *ecmd)
580{
581 struct skge_port *skge = netdev_priv(dev);
582
Joe Perches8e95a202009-12-03 07:58:21 +0000583 ecmd->rx_pause = ((skge->flow_control == FLOW_MODE_SYMMETRIC) ||
584 (skge->flow_control == FLOW_MODE_SYM_OR_REM));
585 ecmd->tx_pause = (ecmd->rx_pause ||
586 (skge->flow_control == FLOW_MODE_LOC_SEND));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400587
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700588 ecmd->autoneg = ecmd->rx_pause || ecmd->tx_pause;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400589}
590
591static int skge_set_pauseparam(struct net_device *dev,
592 struct ethtool_pauseparam *ecmd)
593{
594 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700595 struct ethtool_pauseparam old;
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000596 int err = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400597
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700598 skge_get_pauseparam(dev, &old);
599
600 if (ecmd->autoneg != old.autoneg)
601 skge->flow_control = ecmd->autoneg ? FLOW_MODE_NONE : FLOW_MODE_SYMMETRIC;
602 else {
603 if (ecmd->rx_pause && ecmd->tx_pause)
604 skge->flow_control = FLOW_MODE_SYMMETRIC;
605 else if (ecmd->rx_pause && !ecmd->tx_pause)
606 skge->flow_control = FLOW_MODE_SYM_OR_REM;
607 else if (!ecmd->rx_pause && ecmd->tx_pause)
608 skge->flow_control = FLOW_MODE_LOC_SEND;
609 else
610 skge->flow_control = FLOW_MODE_NONE;
611 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400612
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000613 if (netif_running(dev)) {
614 skge_down(dev);
615 err = skge_up(dev);
616 if (err) {
617 dev_close(dev);
618 return err;
619 }
620 }
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700621
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400622 return 0;
623}
624
625/* Chip internal frequency for clock calculations */
626static inline u32 hwkhz(const struct skge_hw *hw)
627{
Stephen Hemminger187ff3b2006-07-19 14:08:42 -0700628 return (hw->chip_id == CHIP_ID_GENESIS) ? 53125 : 78125;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400629}
630
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800631/* Chip HZ to microseconds */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400632static inline u32 skge_clk2usec(const struct skge_hw *hw, u32 ticks)
633{
634 return (ticks * 1000) / hwkhz(hw);
635}
636
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800637/* Microseconds to chip HZ */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400638static inline u32 skge_usecs2clk(const struct skge_hw *hw, u32 usec)
639{
640 return hwkhz(hw) * usec / 1000;
641}
642
643static int skge_get_coalesce(struct net_device *dev,
644 struct ethtool_coalesce *ecmd)
645{
646 struct skge_port *skge = netdev_priv(dev);
647 struct skge_hw *hw = skge->hw;
648 int port = skge->port;
649
650 ecmd->rx_coalesce_usecs = 0;
651 ecmd->tx_coalesce_usecs = 0;
652
653 if (skge_read32(hw, B2_IRQM_CTRL) & TIM_START) {
654 u32 delay = skge_clk2usec(hw, skge_read32(hw, B2_IRQM_INI));
655 u32 msk = skge_read32(hw, B2_IRQM_MSK);
656
657 if (msk & rxirqmask[port])
658 ecmd->rx_coalesce_usecs = delay;
659 if (msk & txirqmask[port])
660 ecmd->tx_coalesce_usecs = delay;
661 }
662
663 return 0;
664}
665
666/* Note: interrupt timer is per board, but can turn on/off per port */
667static int skge_set_coalesce(struct net_device *dev,
668 struct ethtool_coalesce *ecmd)
669{
670 struct skge_port *skge = netdev_priv(dev);
671 struct skge_hw *hw = skge->hw;
672 int port = skge->port;
673 u32 msk = skge_read32(hw, B2_IRQM_MSK);
674 u32 delay = 25;
675
676 if (ecmd->rx_coalesce_usecs == 0)
677 msk &= ~rxirqmask[port];
678 else if (ecmd->rx_coalesce_usecs < 25 ||
679 ecmd->rx_coalesce_usecs > 33333)
680 return -EINVAL;
681 else {
682 msk |= rxirqmask[port];
683 delay = ecmd->rx_coalesce_usecs;
684 }
685
686 if (ecmd->tx_coalesce_usecs == 0)
687 msk &= ~txirqmask[port];
688 else if (ecmd->tx_coalesce_usecs < 25 ||
689 ecmd->tx_coalesce_usecs > 33333)
690 return -EINVAL;
691 else {
692 msk |= txirqmask[port];
693 delay = min(delay, ecmd->rx_coalesce_usecs);
694 }
695
696 skge_write32(hw, B2_IRQM_MSK, msk);
697 if (msk == 0)
698 skge_write32(hw, B2_IRQM_CTRL, TIM_STOP);
699 else {
700 skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, delay));
701 skge_write32(hw, B2_IRQM_CTRL, TIM_START);
702 }
703 return 0;
704}
705
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700706enum led_mode { LED_MODE_OFF, LED_MODE_ON, LED_MODE_TST };
707static void skge_led(struct skge_port *skge, enum led_mode mode)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400708{
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400709 struct skge_hw *hw = skge->hw;
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700710 int port = skge->port;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400711
Stephen Hemminger9cbe3302007-03-16 14:01:28 -0700712 spin_lock_bh(&hw->phy_lock);
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700713 if (hw->chip_id == CHIP_ID_GENESIS) {
714 switch (mode) {
715 case LED_MODE_OFF:
Stephen Hemminger64f6b642006-09-23 21:25:28 -0700716 if (hw->phy_type == SK_PHY_BCOM)
717 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF);
718 else {
719 skge_write32(hw, SK_REG(port, TX_LED_VAL), 0);
720 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_T_OFF);
721 }
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700722 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
723 skge_write32(hw, SK_REG(port, RX_LED_VAL), 0);
724 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF);
725 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400726
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700727 case LED_MODE_ON:
728 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON);
729 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON);
730
731 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
732 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
733
734 break;
735
736 case LED_MODE_TST:
737 skge_write8(hw, SK_REG(port, RX_LED_TST), LED_T_ON);
738 skge_write32(hw, SK_REG(port, RX_LED_VAL), 100);
739 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
740
Stephen Hemminger64f6b642006-09-23 21:25:28 -0700741 if (hw->phy_type == SK_PHY_BCOM)
742 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON);
743 else {
744 skge_write8(hw, SK_REG(port, TX_LED_TST), LED_T_ON);
745 skge_write32(hw, SK_REG(port, TX_LED_VAL), 100);
746 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
747 }
748
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700749 }
750 } else {
751 switch (mode) {
752 case LED_MODE_OFF:
753 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
754 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
755 PHY_M_LED_MO_DUP(MO_LED_OFF) |
756 PHY_M_LED_MO_10(MO_LED_OFF) |
757 PHY_M_LED_MO_100(MO_LED_OFF) |
758 PHY_M_LED_MO_1000(MO_LED_OFF) |
759 PHY_M_LED_MO_RX(MO_LED_OFF));
760 break;
761 case LED_MODE_ON:
762 gm_phy_write(hw, port, PHY_MARV_LED_CTRL,
763 PHY_M_LED_PULS_DUR(PULS_170MS) |
764 PHY_M_LED_BLINK_RT(BLINK_84MS) |
765 PHY_M_LEDC_TX_CTRL |
766 PHY_M_LEDC_DP_CTRL);
Stephen Hemminger46a60f22005-09-09 12:54:56 -0700767
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700768 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
769 PHY_M_LED_MO_RX(MO_LED_OFF) |
770 (skge->speed == SPEED_100 ?
771 PHY_M_LED_MO_100(MO_LED_ON) : 0));
772 break;
773 case LED_MODE_TST:
774 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
775 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
776 PHY_M_LED_MO_DUP(MO_LED_ON) |
777 PHY_M_LED_MO_10(MO_LED_ON) |
778 PHY_M_LED_MO_100(MO_LED_ON) |
779 PHY_M_LED_MO_1000(MO_LED_ON) |
780 PHY_M_LED_MO_RX(MO_LED_ON));
781 }
782 }
Stephen Hemminger9cbe3302007-03-16 14:01:28 -0700783 spin_unlock_bh(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400784}
785
786/* blink LED's for finding board */
787static int skge_phys_id(struct net_device *dev, u32 data)
788{
789 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700790 unsigned long ms;
791 enum led_mode mode = LED_MODE_TST;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400792
Stephen Hemminger95566062005-06-27 11:33:02 -0700793 if (!data || data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ))
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700794 ms = jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT / HZ) * 1000;
795 else
796 ms = data * 1000;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400797
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700798 while (ms > 0) {
799 skge_led(skge, mode);
800 mode ^= LED_MODE_TST;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400801
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700802 if (msleep_interruptible(BLINK_MS))
803 break;
804 ms -= BLINK_MS;
805 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400806
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700807 /* back to regular LED state */
808 skge_led(skge, netif_running(dev) ? LED_MODE_ON : LED_MODE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400809
810 return 0;
811}
812
Stephen Hemmingerafa151b2007-10-16 12:15:53 -0700813static int skge_get_eeprom_len(struct net_device *dev)
814{
815 struct skge_port *skge = netdev_priv(dev);
816 u32 reg2;
817
818 pci_read_config_dword(skge->hw->pdev, PCI_DEV_REG2, &reg2);
Joe Perches67777f92010-02-17 15:01:58 +0000819 return 1 << (((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
Stephen Hemmingerafa151b2007-10-16 12:15:53 -0700820}
821
822static u32 skge_vpd_read(struct pci_dev *pdev, int cap, u16 offset)
823{
824 u32 val;
825
826 pci_write_config_word(pdev, cap + PCI_VPD_ADDR, offset);
827
828 do {
829 pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
830 } while (!(offset & PCI_VPD_ADDR_F));
831
832 pci_read_config_dword(pdev, cap + PCI_VPD_DATA, &val);
833 return val;
834}
835
836static void skge_vpd_write(struct pci_dev *pdev, int cap, u16 offset, u32 val)
837{
838 pci_write_config_dword(pdev, cap + PCI_VPD_DATA, val);
839 pci_write_config_word(pdev, cap + PCI_VPD_ADDR,
840 offset | PCI_VPD_ADDR_F);
841
842 do {
843 pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
844 } while (offset & PCI_VPD_ADDR_F);
845}
846
847static int skge_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
848 u8 *data)
849{
850 struct skge_port *skge = netdev_priv(dev);
851 struct pci_dev *pdev = skge->hw->pdev;
852 int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD);
853 int length = eeprom->len;
854 u16 offset = eeprom->offset;
855
856 if (!cap)
857 return -EINVAL;
858
859 eeprom->magic = SKGE_EEPROM_MAGIC;
860
861 while (length > 0) {
862 u32 val = skge_vpd_read(pdev, cap, offset);
863 int n = min_t(int, length, sizeof(val));
864
865 memcpy(data, &val, n);
866 length -= n;
867 data += n;
868 offset += n;
869 }
870 return 0;
871}
872
873static int skge_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
874 u8 *data)
875{
876 struct skge_port *skge = netdev_priv(dev);
877 struct pci_dev *pdev = skge->hw->pdev;
878 int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD);
879 int length = eeprom->len;
880 u16 offset = eeprom->offset;
881
882 if (!cap)
883 return -EINVAL;
884
885 if (eeprom->magic != SKGE_EEPROM_MAGIC)
886 return -EINVAL;
887
888 while (length > 0) {
889 u32 val;
890 int n = min_t(int, length, sizeof(val));
891
892 if (n < sizeof(val))
893 val = skge_vpd_read(pdev, cap, offset);
894 memcpy(&val, data, n);
895
896 skge_vpd_write(pdev, cap, offset, val);
897
898 length -= n;
899 data += n;
900 offset += n;
901 }
902 return 0;
903}
904
Jeff Garzik7282d492006-09-13 14:30:00 -0400905static const struct ethtool_ops skge_ethtool_ops = {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400906 .get_settings = skge_get_settings,
907 .set_settings = skge_set_settings,
908 .get_drvinfo = skge_get_drvinfo,
909 .get_regs_len = skge_get_regs_len,
910 .get_regs = skge_get_regs,
911 .get_wol = skge_get_wol,
912 .set_wol = skge_set_wol,
913 .get_msglevel = skge_get_msglevel,
914 .set_msglevel = skge_set_msglevel,
915 .nway_reset = skge_nway_reset,
916 .get_link = ethtool_op_get_link,
Stephen Hemmingerafa151b2007-10-16 12:15:53 -0700917 .get_eeprom_len = skge_get_eeprom_len,
918 .get_eeprom = skge_get_eeprom,
919 .set_eeprom = skge_set_eeprom,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400920 .get_ringparam = skge_get_ring_param,
921 .set_ringparam = skge_set_ring_param,
922 .get_pauseparam = skge_get_pauseparam,
923 .set_pauseparam = skge_set_pauseparam,
924 .get_coalesce = skge_get_coalesce,
925 .set_coalesce = skge_set_coalesce,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400926 .set_sg = skge_set_sg,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400927 .set_tx_csum = skge_set_tx_csum,
928 .get_rx_csum = skge_get_rx_csum,
929 .set_rx_csum = skge_set_rx_csum,
930 .get_strings = skge_get_strings,
931 .phys_id = skge_phys_id,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700932 .get_sset_count = skge_get_sset_count,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400933 .get_ethtool_stats = skge_get_ethtool_stats,
934};
935
936/*
937 * Allocate ring elements and chain them together
938 * One-to-one association of board descriptors with ring elements
939 */
Stephen Hemmingerc3da1442006-03-21 10:57:01 -0800940static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u32 base)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400941{
942 struct skge_tx_desc *d;
943 struct skge_element *e;
944 int i;
945
Robert P. J. Daycd861282006-12-13 00:34:52 -0800946 ring->start = kcalloc(ring->count, sizeof(*e), GFP_KERNEL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400947 if (!ring->start)
948 return -ENOMEM;
949
950 for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) {
951 e->desc = d;
952 if (i == ring->count - 1) {
953 e->next = ring->start;
954 d->next_offset = base;
955 } else {
956 e->next = e + 1;
957 d->next_offset = base + (i+1) * sizeof(*d);
958 }
959 }
960 ring->to_use = ring->to_clean = ring->start;
961
962 return 0;
963}
964
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700965/* Allocate and setup a new buffer for receiving */
966static void skge_rx_setup(struct skge_port *skge, struct skge_element *e,
967 struct sk_buff *skb, unsigned int bufsize)
968{
969 struct skge_rx_desc *rd = e->desc;
970 u64 map;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400971
972 map = pci_map_single(skge->hw->pdev, skb->data, bufsize,
973 PCI_DMA_FROMDEVICE);
974
975 rd->dma_lo = map;
976 rd->dma_hi = map >> 32;
977 e->skb = skb;
978 rd->csum1_start = ETH_HLEN;
979 rd->csum2_start = ETH_HLEN;
980 rd->csum1 = 0;
981 rd->csum2 = 0;
982
983 wmb();
984
985 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | bufsize;
986 pci_unmap_addr_set(e, mapaddr, map);
987 pci_unmap_len_set(e, maplen, bufsize);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400988}
989
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700990/* Resume receiving using existing skb,
991 * Note: DMA address is not changed by chip.
992 * MTU not changed while receiver active.
993 */
Stephen Hemminger5a011442006-03-23 11:07:25 -0800994static inline void skge_rx_reuse(struct skge_element *e, unsigned int size)
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700995{
996 struct skge_rx_desc *rd = e->desc;
997
998 rd->csum2 = 0;
999 rd->csum2_start = ETH_HLEN;
1000
1001 wmb();
1002
1003 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | size;
1004}
1005
1006
1007/* Free all buffers in receive ring, assumes receiver stopped */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001008static void skge_rx_clean(struct skge_port *skge)
1009{
1010 struct skge_hw *hw = skge->hw;
1011 struct skge_ring *ring = &skge->rx_ring;
1012 struct skge_element *e;
1013
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001014 e = ring->start;
1015 do {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001016 struct skge_rx_desc *rd = e->desc;
1017 rd->control = 0;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001018 if (e->skb) {
1019 pci_unmap_single(hw->pdev,
1020 pci_unmap_addr(e, mapaddr),
1021 pci_unmap_len(e, maplen),
1022 PCI_DMA_FROMDEVICE);
1023 dev_kfree_skb(e->skb);
1024 e->skb = NULL;
1025 }
1026 } while ((e = e->next) != ring->start);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001027}
1028
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001029
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001030/* Allocate buffers for receive ring
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001031 * For receive: to_clean is next received frame.
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001032 */
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07001033static int skge_rx_fill(struct net_device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001034{
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07001035 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001036 struct skge_ring *ring = &skge->rx_ring;
1037 struct skge_element *e;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001038
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001039 e = ring->start;
1040 do {
Stephen Hemminger383181a2005-09-19 15:37:16 -07001041 struct sk_buff *skb;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001042
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07001043 skb = __netdev_alloc_skb(dev, skge->rx_buf_size + NET_IP_ALIGN,
1044 GFP_KERNEL);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001045 if (!skb)
1046 return -ENOMEM;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001047
Stephen Hemminger383181a2005-09-19 15:37:16 -07001048 skb_reserve(skb, NET_IP_ALIGN);
1049 skge_rx_setup(skge, e, skb, skge->rx_buf_size);
Joe Perches67777f92010-02-17 15:01:58 +00001050 } while ((e = e->next) != ring->start);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001051
1052 ring->to_clean = ring->start;
1053 return 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001054}
1055
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001056static const char *skge_pause(enum pause_status status)
1057{
Joe Perches67777f92010-02-17 15:01:58 +00001058 switch (status) {
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001059 case FLOW_STAT_NONE:
1060 return "none";
1061 case FLOW_STAT_REM_SEND:
1062 return "rx only";
1063 case FLOW_STAT_LOC_SEND:
1064 return "tx_only";
1065 case FLOW_STAT_SYMMETRIC: /* Both station may send PAUSE */
1066 return "both";
1067 default:
1068 return "indeterminated";
1069 }
1070}
1071
1072
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001073static void skge_link_up(struct skge_port *skge)
1074{
Stephen Hemminger46a60f22005-09-09 12:54:56 -07001075 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG),
Stephen Hemminger54cfb5a2005-08-16 14:01:05 -07001076 LED_BLK_OFF|LED_SYNC_OFF|LED_ON);
1077
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001078 netif_carrier_on(skge->netdev);
Stephen Hemminger29b4e882006-03-23 11:07:28 -08001079 netif_wake_queue(skge->netdev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001080
Joe Perchesd7072042010-02-09 11:49:53 +00001081 netif_info(skge, link, skge->netdev,
1082 "Link is up at %d Mbps, %s duplex, flow control %s\n",
1083 skge->speed,
1084 skge->duplex == DUPLEX_FULL ? "full" : "half",
1085 skge_pause(skge->flow_status));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001086}
1087
1088static void skge_link_down(struct skge_port *skge)
1089{
Stephen Hemminger54cfb5a2005-08-16 14:01:05 -07001090 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001091 netif_carrier_off(skge->netdev);
1092 netif_stop_queue(skge->netdev);
1093
Joe Perchesd7072042010-02-09 11:49:53 +00001094 netif_info(skge, link, skge->netdev, "Link is down\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001095}
1096
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001097
1098static void xm_link_down(struct skge_hw *hw, int port)
1099{
1100 struct net_device *dev = hw->dev[port];
1101 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001102
Stephen Hemminger501fb722007-10-16 12:15:51 -07001103 xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE);
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001104
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001105 if (netif_carrier_ok(dev))
1106 skge_link_down(skge);
1107}
1108
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001109static int __xm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001110{
1111 int i;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001112
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001113 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
Stephen Hemminger07811912006-02-22 10:28:34 -08001114 *val = xm_read16(hw, port, XM_PHY_DATA);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001115
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001116 if (hw->phy_type == SK_PHY_XMAC)
1117 goto ready;
1118
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001119 for (i = 0; i < PHY_RETRIES; i++) {
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001120 if (xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_RDY)
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001121 goto ready;
Stephen Hemminger07811912006-02-22 10:28:34 -08001122 udelay(1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001123 }
1124
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001125 return -ETIMEDOUT;
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001126 ready:
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001127 *val = xm_read16(hw, port, XM_PHY_DATA);
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001128
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001129 return 0;
1130}
1131
1132static u16 xm_phy_read(struct skge_hw *hw, int port, u16 reg)
1133{
1134 u16 v = 0;
1135 if (__xm_phy_read(hw, port, reg, &v))
Joe Perchesf15063c2010-02-17 15:01:57 +00001136 pr_warning("%s: phy read timed out\n", hw->dev[port]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001137 return v;
1138}
1139
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001140static int xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001141{
1142 int i;
1143
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001144 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001145 for (i = 0; i < PHY_RETRIES; i++) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001146 if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001147 goto ready;
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001148 udelay(1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001149 }
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001150 return -EIO;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001151
1152 ready:
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001153 xm_write16(hw, port, XM_PHY_DATA, val);
Stephen Hemminger07811912006-02-22 10:28:34 -08001154 for (i = 0; i < PHY_RETRIES; i++) {
1155 if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
1156 return 0;
1157 udelay(1);
1158 }
1159 return -ETIMEDOUT;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001160}
1161
1162static void genesis_init(struct skge_hw *hw)
1163{
1164 /* set blink source counter */
1165 skge_write32(hw, B2_BSC_INI, (SK_BLK_DUR * SK_FACT_53) / 100);
1166 skge_write8(hw, B2_BSC_CTRL, BSC_START);
1167
1168 /* configure mac arbiter */
1169 skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR);
1170
1171 /* configure mac arbiter timeout values */
1172 skge_write8(hw, B3_MA_TOINI_RX1, SK_MAC_TO_53);
1173 skge_write8(hw, B3_MA_TOINI_RX2, SK_MAC_TO_53);
1174 skge_write8(hw, B3_MA_TOINI_TX1, SK_MAC_TO_53);
1175 skge_write8(hw, B3_MA_TOINI_TX2, SK_MAC_TO_53);
1176
1177 skge_write8(hw, B3_MA_RCINI_RX1, 0);
1178 skge_write8(hw, B3_MA_RCINI_RX2, 0);
1179 skge_write8(hw, B3_MA_RCINI_TX1, 0);
1180 skge_write8(hw, B3_MA_RCINI_TX2, 0);
1181
1182 /* configure packet arbiter timeout */
1183 skge_write16(hw, B3_PA_CTRL, PA_RST_CLR);
1184 skge_write16(hw, B3_PA_TOINI_RX1, SK_PKT_TO_MAX);
1185 skge_write16(hw, B3_PA_TOINI_TX1, SK_PKT_TO_MAX);
1186 skge_write16(hw, B3_PA_TOINI_RX2, SK_PKT_TO_MAX);
1187 skge_write16(hw, B3_PA_TOINI_TX2, SK_PKT_TO_MAX);
1188}
1189
1190static void genesis_reset(struct skge_hw *hw, int port)
1191{
Stephen Hemminger45bada62005-06-27 11:33:12 -07001192 const u8 zero[8] = { 0 };
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001193 u32 reg;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001194
Stephen Hemminger46a60f22005-09-09 12:54:56 -07001195 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
1196
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001197 /* reset the statistics module */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001198 xm_write32(hw, port, XM_GP_PORT, XM_GP_RES_STAT);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001199 xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001200 xm_write32(hw, port, XM_MODE, 0); /* clear Mode Reg */
1201 xm_write16(hw, port, XM_TX_CMD, 0); /* reset TX CMD Reg */
1202 xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001203
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001204 /* disable Broadcom PHY IRQ */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001205 if (hw->phy_type == SK_PHY_BCOM)
1206 xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001207
Stephen Hemminger45bada62005-06-27 11:33:12 -07001208 xm_outhash(hw, port, XM_HSM, zero);
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001209
1210 /* Flush TX and RX fifo */
1211 reg = xm_read32(hw, port, XM_MODE);
1212 xm_write32(hw, port, XM_MODE, reg | XM_MD_FTF);
1213 xm_write32(hw, port, XM_MODE, reg | XM_MD_FRF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001214}
1215
1216
Stephen Hemminger45bada62005-06-27 11:33:12 -07001217/* Convert mode to MII values */
1218static const u16 phy_pause_map[] = {
1219 [FLOW_MODE_NONE] = 0,
1220 [FLOW_MODE_LOC_SEND] = PHY_AN_PAUSE_ASYM,
1221 [FLOW_MODE_SYMMETRIC] = PHY_AN_PAUSE_CAP,
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001222 [FLOW_MODE_SYM_OR_REM] = PHY_AN_PAUSE_CAP | PHY_AN_PAUSE_ASYM,
Stephen Hemminger45bada62005-06-27 11:33:12 -07001223};
1224
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001225/* special defines for FIBER (88E1011S only) */
1226static const u16 fiber_pause_map[] = {
1227 [FLOW_MODE_NONE] = PHY_X_P_NO_PAUSE,
1228 [FLOW_MODE_LOC_SEND] = PHY_X_P_ASYM_MD,
1229 [FLOW_MODE_SYMMETRIC] = PHY_X_P_SYM_MD,
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001230 [FLOW_MODE_SYM_OR_REM] = PHY_X_P_BOTH_MD,
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001231};
1232
Stephen Hemminger45bada62005-06-27 11:33:12 -07001233
1234/* Check status of Broadcom phy link */
1235static void bcom_check_link(struct skge_hw *hw, int port)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001236{
Stephen Hemminger45bada62005-06-27 11:33:12 -07001237 struct net_device *dev = hw->dev[port];
1238 struct skge_port *skge = netdev_priv(dev);
1239 u16 status;
1240
1241 /* read twice because of latch */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001242 xm_phy_read(hw, port, PHY_BCOM_STAT);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001243 status = xm_phy_read(hw, port, PHY_BCOM_STAT);
1244
Stephen Hemminger45bada62005-06-27 11:33:12 -07001245 if ((status & PHY_ST_LSYNC) == 0) {
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001246 xm_link_down(hw, port);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001247 return;
1248 }
Stephen Hemminger45bada62005-06-27 11:33:12 -07001249
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001250 if (skge->autoneg == AUTONEG_ENABLE) {
1251 u16 lpa, aux;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001252
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001253 if (!(status & PHY_ST_AN_OVER))
1254 return;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001255
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001256 lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP);
1257 if (lpa & PHY_B_AN_RF) {
Joe Perchesf15063c2010-02-17 15:01:57 +00001258 netdev_notice(dev, "remote fault\n");
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001259 return;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001260 }
1261
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001262 aux = xm_phy_read(hw, port, PHY_BCOM_AUX_STAT);
1263
1264 /* Check Duplex mismatch */
1265 switch (aux & PHY_B_AS_AN_RES_MSK) {
1266 case PHY_B_RES_1000FD:
1267 skge->duplex = DUPLEX_FULL;
1268 break;
1269 case PHY_B_RES_1000HD:
1270 skge->duplex = DUPLEX_HALF;
1271 break;
1272 default:
Joe Perchesf15063c2010-02-17 15:01:57 +00001273 netdev_notice(dev, "duplex mismatch\n");
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001274 return;
1275 }
1276
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001277 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
1278 switch (aux & PHY_B_AS_PAUSE_MSK) {
1279 case PHY_B_AS_PAUSE_MSK:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001280 skge->flow_status = FLOW_STAT_SYMMETRIC;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001281 break;
1282 case PHY_B_AS_PRR:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001283 skge->flow_status = FLOW_STAT_REM_SEND;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001284 break;
1285 case PHY_B_AS_PRT:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001286 skge->flow_status = FLOW_STAT_LOC_SEND;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001287 break;
1288 default:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001289 skge->flow_status = FLOW_STAT_NONE;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001290 }
1291 skge->speed = SPEED_1000;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001292 }
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001293
1294 if (!netif_carrier_ok(dev))
1295 genesis_link_up(skge);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001296}
1297
1298/* Broadcom 5400 only supports giagabit! SysKonnect did not put an additional
1299 * Phy on for 100 or 10Mbit operation
1300 */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001301static void bcom_phy_init(struct skge_port *skge)
Stephen Hemminger45bada62005-06-27 11:33:12 -07001302{
1303 struct skge_hw *hw = skge->hw;
1304 int port = skge->port;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001305 int i;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001306 u16 id1, r, ext, ctl;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001307
1308 /* magic workaround patterns for Broadcom */
1309 static const struct {
1310 u16 reg;
1311 u16 val;
1312 } A1hack[] = {
1313 { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1104 },
1314 { 0x17, 0x0013 }, { 0x15, 0x0404 }, { 0x17, 0x8006 },
1315 { 0x15, 0x0132 }, { 0x17, 0x8006 }, { 0x15, 0x0232 },
1316 { 0x17, 0x800D }, { 0x15, 0x000F }, { 0x18, 0x0420 },
1317 }, C0hack[] = {
1318 { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1204 },
1319 { 0x17, 0x0013 }, { 0x15, 0x0A04 }, { 0x18, 0x0420 },
1320 };
1321
Stephen Hemminger45bada62005-06-27 11:33:12 -07001322 /* read Id from external PHY (all have the same address) */
1323 id1 = xm_phy_read(hw, port, PHY_XMAC_ID1);
1324
1325 /* Optimize MDIO transfer by suppressing preamble. */
1326 r = xm_read16(hw, port, XM_MMU_CMD);
1327 r |= XM_MMU_NO_PRE;
Joe Perches67777f92010-02-17 15:01:58 +00001328 xm_write16(hw, port, XM_MMU_CMD, r);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001329
Stephen Hemminger2c668512005-07-22 16:26:07 -07001330 switch (id1) {
Stephen Hemminger45bada62005-06-27 11:33:12 -07001331 case PHY_BCOM_ID1_C0:
1332 /*
1333 * Workaround BCOM Errata for the C0 type.
1334 * Write magic patterns to reserved registers.
1335 */
1336 for (i = 0; i < ARRAY_SIZE(C0hack); i++)
1337 xm_phy_write(hw, port,
1338 C0hack[i].reg, C0hack[i].val);
1339
1340 break;
1341 case PHY_BCOM_ID1_A1:
1342 /*
1343 * Workaround BCOM Errata for the A1 type.
1344 * Write magic patterns to reserved registers.
1345 */
1346 for (i = 0; i < ARRAY_SIZE(A1hack); i++)
1347 xm_phy_write(hw, port,
1348 A1hack[i].reg, A1hack[i].val);
1349 break;
1350 }
1351
1352 /*
1353 * Workaround BCOM Errata (#10523) for all BCom PHYs.
1354 * Disable Power Management after reset.
1355 */
1356 r = xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL);
1357 r |= PHY_B_AC_DIS_PM;
1358 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, r);
1359
1360 /* Dummy read */
1361 xm_read16(hw, port, XM_ISRC);
1362
1363 ext = PHY_B_PEC_EN_LTR; /* enable tx led */
1364 ctl = PHY_CT_SP1000; /* always 1000mbit */
1365
1366 if (skge->autoneg == AUTONEG_ENABLE) {
1367 /*
1368 * Workaround BCOM Errata #1 for the C5 type.
1369 * 1000Base-T Link Acquisition Failure in Slave Mode
1370 * Set Repeater/DTE bit 10 of the 1000Base-T Control Register
1371 */
1372 u16 adv = PHY_B_1000C_RD;
1373 if (skge->advertising & ADVERTISED_1000baseT_Half)
1374 adv |= PHY_B_1000C_AHD;
1375 if (skge->advertising & ADVERTISED_1000baseT_Full)
1376 adv |= PHY_B_1000C_AFD;
1377 xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, adv);
1378
1379 ctl |= PHY_CT_ANE | PHY_CT_RE_CFG;
1380 } else {
1381 if (skge->duplex == DUPLEX_FULL)
1382 ctl |= PHY_CT_DUP_MD;
1383 /* Force to slave */
1384 xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, PHY_B_1000C_MSE);
1385 }
1386
1387 /* Set autonegotiation pause parameters */
1388 xm_phy_write(hw, port, PHY_BCOM_AUNE_ADV,
1389 phy_pause_map[skge->flow_control] | PHY_AN_CSMA);
1390
1391 /* Handle Jumbo frames */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001392 if (hw->dev[port]->mtu > ETH_DATA_LEN) {
Stephen Hemminger45bada62005-06-27 11:33:12 -07001393 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1394 PHY_B_AC_TX_TST | PHY_B_AC_LONG_PACK);
1395
1396 ext |= PHY_B_PEC_HIGH_LA;
1397
1398 }
1399
1400 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, ext);
1401 xm_phy_write(hw, port, PHY_BCOM_CTRL, ctl);
1402
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08001403 /* Use link status change interrupt */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001404 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001405}
Stephen Hemminger45bada62005-06-27 11:33:12 -07001406
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001407static void xm_phy_init(struct skge_port *skge)
1408{
1409 struct skge_hw *hw = skge->hw;
1410 int port = skge->port;
1411 u16 ctrl = 0;
1412
1413 if (skge->autoneg == AUTONEG_ENABLE) {
1414 if (skge->advertising & ADVERTISED_1000baseT_Half)
1415 ctrl |= PHY_X_AN_HD;
1416 if (skge->advertising & ADVERTISED_1000baseT_Full)
1417 ctrl |= PHY_X_AN_FD;
1418
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001419 ctrl |= fiber_pause_map[skge->flow_control];
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001420
1421 xm_phy_write(hw, port, PHY_XMAC_AUNE_ADV, ctrl);
1422
1423 /* Restart Auto-negotiation */
1424 ctrl = PHY_CT_ANE | PHY_CT_RE_CFG;
1425 } else {
1426 /* Set DuplexMode in Config register */
1427 if (skge->duplex == DUPLEX_FULL)
1428 ctrl |= PHY_CT_DUP_MD;
1429 /*
1430 * Do NOT enable Auto-negotiation here. This would hold
1431 * the link down because no IDLEs are transmitted
1432 */
1433 }
1434
1435 xm_phy_write(hw, port, PHY_XMAC_CTRL, ctrl);
1436
1437 /* Poll PHY for status changes */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07001438 mod_timer(&skge->link_timer, jiffies + LINK_HZ);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001439}
1440
Stephen Hemminger501fb722007-10-16 12:15:51 -07001441static int xm_check_link(struct net_device *dev)
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001442{
1443 struct skge_port *skge = netdev_priv(dev);
1444 struct skge_hw *hw = skge->hw;
1445 int port = skge->port;
1446 u16 status;
1447
1448 /* read twice because of latch */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001449 xm_phy_read(hw, port, PHY_XMAC_STAT);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001450 status = xm_phy_read(hw, port, PHY_XMAC_STAT);
1451
1452 if ((status & PHY_ST_LSYNC) == 0) {
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001453 xm_link_down(hw, port);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001454 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001455 }
1456
1457 if (skge->autoneg == AUTONEG_ENABLE) {
1458 u16 lpa, res;
1459
1460 if (!(status & PHY_ST_AN_OVER))
Stephen Hemminger501fb722007-10-16 12:15:51 -07001461 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001462
1463 lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP);
1464 if (lpa & PHY_B_AN_RF) {
Joe Perchesf15063c2010-02-17 15:01:57 +00001465 netdev_notice(dev, "remote fault\n");
Stephen Hemminger501fb722007-10-16 12:15:51 -07001466 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001467 }
1468
1469 res = xm_phy_read(hw, port, PHY_XMAC_RES_ABI);
1470
1471 /* Check Duplex mismatch */
1472 switch (res & (PHY_X_RS_HD | PHY_X_RS_FD)) {
1473 case PHY_X_RS_FD:
1474 skge->duplex = DUPLEX_FULL;
1475 break;
1476 case PHY_X_RS_HD:
1477 skge->duplex = DUPLEX_HALF;
1478 break;
1479 default:
Joe Perchesf15063c2010-02-17 15:01:57 +00001480 netdev_notice(dev, "duplex mismatch\n");
Stephen Hemminger501fb722007-10-16 12:15:51 -07001481 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001482 }
1483
1484 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001485 if ((skge->flow_control == FLOW_MODE_SYMMETRIC ||
1486 skge->flow_control == FLOW_MODE_SYM_OR_REM) &&
1487 (lpa & PHY_X_P_SYM_MD))
1488 skge->flow_status = FLOW_STAT_SYMMETRIC;
1489 else if (skge->flow_control == FLOW_MODE_SYM_OR_REM &&
1490 (lpa & PHY_X_RS_PAUSE) == PHY_X_P_ASYM_MD)
1491 /* Enable PAUSE receive, disable PAUSE transmit */
1492 skge->flow_status = FLOW_STAT_REM_SEND;
1493 else if (skge->flow_control == FLOW_MODE_LOC_SEND &&
1494 (lpa & PHY_X_RS_PAUSE) == PHY_X_P_BOTH_MD)
1495 /* Disable PAUSE receive, enable PAUSE transmit */
1496 skge->flow_status = FLOW_STAT_LOC_SEND;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001497 else
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001498 skge->flow_status = FLOW_STAT_NONE;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001499
1500 skge->speed = SPEED_1000;
1501 }
1502
1503 if (!netif_carrier_ok(dev))
1504 genesis_link_up(skge);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001505 return 1;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001506}
1507
1508/* Poll to check for link coming up.
Stephen Hemminger501fb722007-10-16 12:15:51 -07001509 *
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001510 * Since internal PHY is wired to a level triggered pin, can't
Stephen Hemminger501fb722007-10-16 12:15:51 -07001511 * get an interrupt when carrier is detected, need to poll for
1512 * link coming up.
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001513 */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07001514static void xm_link_timer(unsigned long arg)
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001515{
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07001516 struct skge_port *skge = (struct skge_port *) arg;
David Howellsc4028952006-11-22 14:57:56 +00001517 struct net_device *dev = skge->netdev;
Joe Perches67777f92010-02-17 15:01:58 +00001518 struct skge_hw *hw = skge->hw;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001519 int port = skge->port;
Stephen Hemminger501fb722007-10-16 12:15:51 -07001520 int i;
1521 unsigned long flags;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001522
1523 if (!netif_running(dev))
1524 return;
1525
Stephen Hemminger501fb722007-10-16 12:15:51 -07001526 spin_lock_irqsave(&hw->phy_lock, flags);
1527
1528 /*
1529 * Verify that the link by checking GPIO register three times.
1530 * This pin has the signal from the link_sync pin connected to it.
1531 */
1532 for (i = 0; i < 3; i++) {
1533 if (xm_read16(hw, port, XM_GP_PORT) & XM_GP_INP_ASS)
1534 goto link_down;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001535 }
1536
Joe Perches67777f92010-02-17 15:01:58 +00001537 /* Re-enable interrupt to detect link down */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001538 if (xm_check_link(dev)) {
1539 u16 msk = xm_read16(hw, port, XM_IMSK);
1540 msk &= ~XM_IS_INP_ASS;
1541 xm_write16(hw, port, XM_IMSK, msk);
1542 xm_read16(hw, port, XM_ISRC);
1543 } else {
1544link_down:
1545 mod_timer(&skge->link_timer,
1546 round_jiffies(jiffies + LINK_HZ));
1547 }
1548 spin_unlock_irqrestore(&hw->phy_lock, flags);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001549}
1550
1551static void genesis_mac_init(struct skge_hw *hw, int port)
1552{
1553 struct net_device *dev = hw->dev[port];
1554 struct skge_port *skge = netdev_priv(dev);
1555 int jumbo = hw->dev[port]->mtu > ETH_DATA_LEN;
1556 int i;
1557 u32 r;
1558 const u8 zero[6] = { 0 };
1559
Stephen Hemminger07811912006-02-22 10:28:34 -08001560 for (i = 0; i < 10; i++) {
1561 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1),
1562 MFF_SET_MAC_RST);
1563 if (skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST)
1564 goto reset_ok;
1565 udelay(1);
1566 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001567
Joe Perchesf15063c2010-02-17 15:01:57 +00001568 netdev_warn(dev, "genesis reset failed\n");
Stephen Hemminger07811912006-02-22 10:28:34 -08001569
1570 reset_ok:
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001571 /* Unreset the XMAC. */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001572 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001573
1574 /*
1575 * Perform additional initialization for external PHYs,
1576 * namely for the 1000baseTX cards that use the XMAC's
1577 * GMII mode.
1578 */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001579 if (hw->phy_type != SK_PHY_XMAC) {
1580 /* Take external Phy out of reset */
1581 r = skge_read32(hw, B2_GP_IO);
1582 if (port == 0)
1583 r |= GP_DIR_0|GP_IO_0;
1584 else
1585 r |= GP_DIR_2|GP_IO_2;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001586
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001587 skge_write32(hw, B2_GP_IO, r);
1588
1589 /* Enable GMII interface */
1590 xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD);
1591 }
Stephen Hemminger07811912006-02-22 10:28:34 -08001592
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001593
Joe Perches67777f92010-02-17 15:01:58 +00001594 switch (hw->phy_type) {
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001595 case SK_PHY_XMAC:
1596 xm_phy_init(skge);
1597 break;
1598 case SK_PHY_BCOM:
1599 bcom_phy_init(skge);
1600 bcom_check_link(hw, port);
1601 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001602
Stephen Hemminger45bada62005-06-27 11:33:12 -07001603 /* Set Station Address */
1604 xm_outaddr(hw, port, XM_SA, dev->dev_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001605
Stephen Hemminger45bada62005-06-27 11:33:12 -07001606 /* We don't use match addresses so clear */
1607 for (i = 1; i < 16; i++)
1608 xm_outaddr(hw, port, XM_EXM(i), zero);
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001609
Stephen Hemminger07811912006-02-22 10:28:34 -08001610 /* Clear MIB counters */
1611 xm_write16(hw, port, XM_STAT_CMD,
1612 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1613 /* Clear two times according to Errata #3 */
1614 xm_write16(hw, port, XM_STAT_CMD,
1615 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1616
Stephen Hemminger45bada62005-06-27 11:33:12 -07001617 /* configure Rx High Water Mark (XM_RX_HI_WM) */
1618 xm_write16(hw, port, XM_RX_HI_WM, 1450);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001619
1620 /* We don't need the FCS appended to the packet. */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001621 r = XM_RX_LENERR_OK | XM_RX_STRIP_FCS;
1622 if (jumbo)
1623 r |= XM_RX_BIG_PK_OK;
1624
1625 if (skge->duplex == DUPLEX_HALF) {
1626 /*
1627 * If in manual half duplex mode the other side might be in
1628 * full duplex mode, so ignore if a carrier extension is not seen
1629 * on frames received
1630 */
1631 r |= XM_RX_DIS_CEXT;
1632 }
1633 xm_write16(hw, port, XM_RX_CMD, r);
1634
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001635 /* We want short frames padded to 60 bytes. */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001636 xm_write16(hw, port, XM_TX_CMD, XM_TX_AUTO_PAD);
1637
Stephen Hemminger485982a2007-11-26 11:54:52 -08001638 /* Increase threshold for jumbo frames on dual port */
1639 if (hw->ports > 1 && jumbo)
1640 xm_write16(hw, port, XM_TX_THR, 1020);
1641 else
1642 xm_write16(hw, port, XM_TX_THR, 512);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001643
1644 /*
1645 * Enable the reception of all error frames. This is is
1646 * a necessary evil due to the design of the XMAC. The
1647 * XMAC's receive FIFO is only 8K in size, however jumbo
1648 * frames can be up to 9000 bytes in length. When bad
1649 * frame filtering is enabled, the XMAC's RX FIFO operates
1650 * in 'store and forward' mode. For this to work, the
1651 * entire frame has to fit into the FIFO, but that means
1652 * that jumbo frames larger than 8192 bytes will be
1653 * truncated. Disabling all bad frame filtering causes
1654 * the RX FIFO to operate in streaming mode, in which
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08001655 * case the XMAC will start transferring frames out of the
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001656 * RX FIFO as soon as the FIFO threshold is reached.
1657 */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001658 xm_write32(hw, port, XM_MODE, XM_DEF_MODE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001659
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001660
1661 /*
Stephen Hemminger45bada62005-06-27 11:33:12 -07001662 * Initialize the Receive Counter Event Mask (XM_RX_EV_MSK)
1663 * - Enable all bits excepting 'Octets Rx OK Low CntOv'
1664 * and 'Octets Rx OK Hi Cnt Ov'.
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001665 */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001666 xm_write32(hw, port, XM_RX_EV_MSK, XMR_DEF_MSK);
1667
1668 /*
1669 * Initialize the Transmit Counter Event Mask (XM_TX_EV_MSK)
1670 * - Enable all bits excepting 'Octets Tx OK Low CntOv'
1671 * and 'Octets Tx OK Hi Cnt Ov'.
1672 */
1673 xm_write32(hw, port, XM_TX_EV_MSK, XMT_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001674
1675 /* Configure MAC arbiter */
1676 skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR);
1677
1678 /* configure timeout values */
1679 skge_write8(hw, B3_MA_TOINI_RX1, 72);
1680 skge_write8(hw, B3_MA_TOINI_RX2, 72);
1681 skge_write8(hw, B3_MA_TOINI_TX1, 72);
1682 skge_write8(hw, B3_MA_TOINI_TX2, 72);
1683
1684 skge_write8(hw, B3_MA_RCINI_RX1, 0);
1685 skge_write8(hw, B3_MA_RCINI_RX2, 0);
1686 skge_write8(hw, B3_MA_RCINI_TX1, 0);
1687 skge_write8(hw, B3_MA_RCINI_TX2, 0);
1688
1689 /* Configure Rx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001690 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_CLR);
1691 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_TIM_PAT);
1692 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_ENA_OP_MD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001693
1694 /* Configure Tx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001695 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_CLR);
1696 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF);
1697 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_ENA_OP_MD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001698
Stephen Hemminger45bada62005-06-27 11:33:12 -07001699 if (jumbo) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001700 /* Enable frame flushing if jumbo frames used */
Joe Perches67777f92010-02-17 15:01:58 +00001701 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_FLUSH);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001702 } else {
1703 /* enable timeout timers if normal frames */
1704 skge_write16(hw, B3_PA_CTRL,
Stephen Hemminger45bada62005-06-27 11:33:12 -07001705 (port == 0) ? PA_ENA_TO_TX1 : PA_ENA_TO_TX2);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001706 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001707}
1708
1709static void genesis_stop(struct skge_port *skge)
1710{
1711 struct skge_hw *hw = skge->hw;
1712 int port = skge->port;
Stephen Hemminger799b21d2007-11-26 11:54:50 -08001713 unsigned retries = 1000;
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001714 u16 cmd;
1715
Joe Perches67777f92010-02-17 15:01:58 +00001716 /* Disable Tx and Rx */
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001717 cmd = xm_read16(hw, port, XM_MMU_CMD);
1718 cmd &= ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1719 xm_write16(hw, port, XM_MMU_CMD, cmd);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001720
Stephen Hemminger46a60f22005-09-09 12:54:56 -07001721 genesis_reset(hw, port);
1722
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001723 /* Clear Tx packet arbiter timeout IRQ */
1724 skge_write16(hw, B3_PA_CTRL,
1725 port == 0 ? PA_CLR_TO_TX1 : PA_CLR_TO_TX2);
1726
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001727 /* Reset the MAC */
Stephen Hemminger799b21d2007-11-26 11:54:50 -08001728 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
1729 do {
1730 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST);
1731 if (!(skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST))
1732 break;
1733 } while (--retries > 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001734
1735 /* For external PHYs there must be special handling */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001736 if (hw->phy_type != SK_PHY_XMAC) {
Stephen Hemminger799b21d2007-11-26 11:54:50 -08001737 u32 reg = skge_read32(hw, B2_GP_IO);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001738 if (port == 0) {
1739 reg |= GP_DIR_0;
1740 reg &= ~GP_IO_0;
1741 } else {
1742 reg |= GP_DIR_2;
1743 reg &= ~GP_IO_2;
1744 }
1745 skge_write32(hw, B2_GP_IO, reg);
1746 skge_read32(hw, B2_GP_IO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001747 }
1748
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001749 xm_write16(hw, port, XM_MMU_CMD,
1750 xm_read16(hw, port, XM_MMU_CMD)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001751 & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX));
1752
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001753 xm_read16(hw, port, XM_MMU_CMD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001754}
1755
1756
1757static void genesis_get_stats(struct skge_port *skge, u64 *data)
1758{
1759 struct skge_hw *hw = skge->hw;
1760 int port = skge->port;
1761 int i;
1762 unsigned long timeout = jiffies + HZ;
1763
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001764 xm_write16(hw, port,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001765 XM_STAT_CMD, XM_SC_SNP_TXC | XM_SC_SNP_RXC);
1766
1767 /* wait for update to complete */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001768 while (xm_read16(hw, port, XM_STAT_CMD)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001769 & (XM_SC_SNP_TXC | XM_SC_SNP_RXC)) {
1770 if (time_after(jiffies, timeout))
1771 break;
1772 udelay(10);
1773 }
1774
1775 /* special case for 64 bit octet counter */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001776 data[0] = (u64) xm_read32(hw, port, XM_TXO_OK_HI) << 32
1777 | xm_read32(hw, port, XM_TXO_OK_LO);
1778 data[1] = (u64) xm_read32(hw, port, XM_RXO_OK_HI) << 32
1779 | xm_read32(hw, port, XM_RXO_OK_LO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001780
1781 for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001782 data[i] = xm_read32(hw, port, skge_stats[i].xmac_offset);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001783}
1784
1785static void genesis_mac_intr(struct skge_hw *hw, int port)
1786{
Stephen Hemmingerda007722007-10-16 12:15:52 -07001787 struct net_device *dev = hw->dev[port];
1788 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001789 u16 status = xm_read16(hw, port, XM_ISRC);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001790
Joe Perchesd7072042010-02-09 11:49:53 +00001791 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
1792 "mac interrupt status 0x%x\n", status);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001793
Stephen Hemminger501fb722007-10-16 12:15:51 -07001794 if (hw->phy_type == SK_PHY_XMAC && (status & XM_IS_INP_ASS)) {
Joe Perches67777f92010-02-17 15:01:58 +00001795 xm_link_down(hw, port);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001796 mod_timer(&skge->link_timer, jiffies + 1);
1797 }
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001798
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001799 if (status & XM_IS_TXF_UR) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001800 xm_write32(hw, port, XM_MODE, XM_MD_FTF);
Stephen Hemmingerda007722007-10-16 12:15:52 -07001801 ++dev->stats.tx_fifo_errors;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001802 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001803}
1804
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001805static void genesis_link_up(struct skge_port *skge)
1806{
1807 struct skge_hw *hw = skge->hw;
1808 int port = skge->port;
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001809 u16 cmd, msk;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001810 u32 mode;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001811
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001812 cmd = xm_read16(hw, port, XM_MMU_CMD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001813
1814 /*
1815 * enabling pause frame reception is required for 1000BT
1816 * because the XMAC is not reset if the link is going down
1817 */
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001818 if (skge->flow_status == FLOW_STAT_NONE ||
1819 skge->flow_status == FLOW_STAT_LOC_SEND)
Stephen Hemminger7e676d92005-06-27 11:33:13 -07001820 /* Disable Pause Frame Reception */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001821 cmd |= XM_MMU_IGN_PF;
1822 else
1823 /* Enable Pause Frame Reception */
1824 cmd &= ~XM_MMU_IGN_PF;
1825
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001826 xm_write16(hw, port, XM_MMU_CMD, cmd);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001827
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001828 mode = xm_read32(hw, port, XM_MODE);
Joe Perches67777f92010-02-17 15:01:58 +00001829 if (skge->flow_status == FLOW_STAT_SYMMETRIC ||
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001830 skge->flow_status == FLOW_STAT_LOC_SEND) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001831 /*
1832 * Configure Pause Frame Generation
1833 * Use internal and external Pause Frame Generation.
1834 * Sending pause frames is edge triggered.
1835 * Send a Pause frame with the maximum pause time if
1836 * internal oder external FIFO full condition occurs.
1837 * Send a zero pause time frame to re-start transmission.
1838 */
1839 /* XM_PAUSE_DA = '010000C28001' (default) */
1840 /* XM_MAC_PTIME = 0xffff (maximum) */
1841 /* remember this value is defined in big endian (!) */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001842 xm_write16(hw, port, XM_MAC_PTIME, 0xffff);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001843
1844 mode |= XM_PAUSE_MODE;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001845 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_PAUSE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001846 } else {
1847 /*
1848 * disable pause frame generation is required for 1000BT
1849 * because the XMAC is not reset if the link is going down
1850 */
1851 /* Disable Pause Mode in Mode Register */
1852 mode &= ~XM_PAUSE_MODE;
1853
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001854 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_DIS_PAUSE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001855 }
1856
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001857 xm_write32(hw, port, XM_MODE, mode);
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001858
Stephen Hemmingerd08b9bd2007-11-26 11:54:49 -08001859 /* Turn on detection of Tx underrun */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001860 msk = xm_read16(hw, port, XM_IMSK);
Stephen Hemmingerd08b9bd2007-11-26 11:54:49 -08001861 msk &= ~XM_IS_TXF_UR;
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001862 xm_write16(hw, port, XM_IMSK, msk);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001863
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001864 xm_read16(hw, port, XM_ISRC);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001865
1866 /* get MMU Command Reg. */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001867 cmd = xm_read16(hw, port, XM_MMU_CMD);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001868 if (hw->phy_type != SK_PHY_XMAC && skge->duplex == DUPLEX_FULL)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001869 cmd |= XM_MMU_GMII_FD;
1870
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001871 /*
1872 * Workaround BCOM Errata (#10523) for all BCom Phys
1873 * Enable Power Management after link up
1874 */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001875 if (hw->phy_type == SK_PHY_BCOM) {
1876 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1877 xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL)
1878 & ~PHY_B_AC_DIS_PM);
1879 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
1880 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001881
1882 /* enable Rx/Tx */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001883 xm_write16(hw, port, XM_MMU_CMD,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001884 cmd | XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1885 skge_link_up(skge);
1886}
1887
1888
Stephen Hemminger45bada62005-06-27 11:33:12 -07001889static inline void bcom_phy_intr(struct skge_port *skge)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001890{
1891 struct skge_hw *hw = skge->hw;
1892 int port = skge->port;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001893 u16 isrc;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001894
Stephen Hemminger45bada62005-06-27 11:33:12 -07001895 isrc = xm_phy_read(hw, port, PHY_BCOM_INT_STAT);
Joe Perchesd7072042010-02-09 11:49:53 +00001896 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
1897 "phy interrupt status 0x%x\n", isrc);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001898
1899 if (isrc & PHY_B_IS_PSE)
Joe Perchesf15063c2010-02-17 15:01:57 +00001900 pr_err("%s: uncorrectable pair swap error\n",
Stephen Hemminger45bada62005-06-27 11:33:12 -07001901 hw->dev[port]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001902
1903 /* Workaround BCom Errata:
1904 * enable and disable loopback mode if "NO HCD" occurs.
1905 */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001906 if (isrc & PHY_B_IS_NO_HDCL) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001907 u16 ctrl = xm_phy_read(hw, port, PHY_BCOM_CTRL);
1908 xm_phy_write(hw, port, PHY_BCOM_CTRL,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001909 ctrl | PHY_CT_LOOP);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001910 xm_phy_write(hw, port, PHY_BCOM_CTRL,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001911 ctrl & ~PHY_CT_LOOP);
1912 }
1913
Stephen Hemminger45bada62005-06-27 11:33:12 -07001914 if (isrc & (PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE))
1915 bcom_check_link(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001916
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001917}
1918
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001919static int gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
1920{
1921 int i;
1922
1923 gma_write16(hw, port, GM_SMI_DATA, val);
1924 gma_write16(hw, port, GM_SMI_CTRL,
1925 GM_SMI_CT_PHY_AD(hw->phy_addr) | GM_SMI_CT_REG_AD(reg));
1926 for (i = 0; i < PHY_RETRIES; i++) {
1927 udelay(1);
1928
1929 if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY))
1930 return 0;
1931 }
1932
Joe Perchesf15063c2010-02-17 15:01:57 +00001933 pr_warning("%s: phy write timeout\n", hw->dev[port]->name);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001934 return -EIO;
1935}
1936
1937static int __gm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val)
1938{
1939 int i;
1940
1941 gma_write16(hw, port, GM_SMI_CTRL,
1942 GM_SMI_CT_PHY_AD(hw->phy_addr)
1943 | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD);
1944
1945 for (i = 0; i < PHY_RETRIES; i++) {
1946 udelay(1);
1947 if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL)
1948 goto ready;
1949 }
1950
1951 return -ETIMEDOUT;
1952 ready:
1953 *val = gma_read16(hw, port, GM_SMI_DATA);
1954 return 0;
1955}
1956
1957static u16 gm_phy_read(struct skge_hw *hw, int port, u16 reg)
1958{
1959 u16 v = 0;
1960 if (__gm_phy_read(hw, port, reg, &v))
Joe Perchesf15063c2010-02-17 15:01:57 +00001961 pr_warning("%s: phy read timeout\n", hw->dev[port]->name);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001962 return v;
1963}
1964
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08001965/* Marvell Phy Initialization */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001966static void yukon_init(struct skge_hw *hw, int port)
1967{
1968 struct skge_port *skge = netdev_priv(hw->dev[port]);
1969 u16 ctrl, ct1000, adv;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001970
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001971 if (skge->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001972 u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001973
1974 ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
1975 PHY_M_EC_MAC_S_MSK);
1976 ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ);
1977
Stephen Hemmingerc506a502005-06-27 11:33:09 -07001978 ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001979
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001980 gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001981 }
1982
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001983 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001984 if (skge->autoneg == AUTONEG_DISABLE)
1985 ctrl &= ~PHY_CT_ANE;
1986
1987 ctrl |= PHY_CT_RESET;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001988 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001989
1990 ctrl = 0;
1991 ct1000 = 0;
Stephen Hemmingerb18f2092005-06-27 11:33:08 -07001992 adv = PHY_AN_CSMA;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001993
1994 if (skge->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07001995 if (hw->copper) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001996 if (skge->advertising & ADVERTISED_1000baseT_Full)
1997 ct1000 |= PHY_M_1000C_AFD;
1998 if (skge->advertising & ADVERTISED_1000baseT_Half)
1999 ct1000 |= PHY_M_1000C_AHD;
2000 if (skge->advertising & ADVERTISED_100baseT_Full)
2001 adv |= PHY_M_AN_100_FD;
2002 if (skge->advertising & ADVERTISED_100baseT_Half)
2003 adv |= PHY_M_AN_100_HD;
2004 if (skge->advertising & ADVERTISED_10baseT_Full)
2005 adv |= PHY_M_AN_10_FD;
2006 if (skge->advertising & ADVERTISED_10baseT_Half)
2007 adv |= PHY_M_AN_10_HD;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002008
Stephen Hemminger4b67be92006-10-05 15:49:51 -07002009 /* Set Flow-control capabilities */
2010 adv |= phy_pause_map[skge->flow_control];
2011 } else {
2012 if (skge->advertising & ADVERTISED_1000baseT_Full)
2013 adv |= PHY_M_AN_1000X_AFD;
2014 if (skge->advertising & ADVERTISED_1000baseT_Half)
2015 adv |= PHY_M_AN_1000X_AHD;
2016
2017 adv |= fiber_pause_map[skge->flow_control];
2018 }
Stephen Hemminger45bada62005-06-27 11:33:12 -07002019
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002020 /* Restart Auto-negotiation */
2021 ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG;
2022 } else {
2023 /* forced speed/duplex settings */
2024 ct1000 = PHY_M_1000C_MSE;
2025
2026 if (skge->duplex == DUPLEX_FULL)
2027 ctrl |= PHY_CT_DUP_MD;
2028
2029 switch (skge->speed) {
2030 case SPEED_1000:
2031 ctrl |= PHY_CT_SP1000;
2032 break;
2033 case SPEED_100:
2034 ctrl |= PHY_CT_SP100;
2035 break;
2036 }
2037
2038 ctrl |= PHY_CT_RESET;
2039 }
2040
Stephen Hemmingerc506a502005-06-27 11:33:09 -07002041 gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002042
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002043 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv);
2044 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002045
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002046 /* Enable phy interrupt on autonegotiation complete (or link up) */
2047 if (skge->autoneg == AUTONEG_ENABLE)
Stephen Hemminger4cde06e2005-07-22 16:26:09 -07002048 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002049 else
Stephen Hemminger4cde06e2005-07-22 16:26:09 -07002050 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002051}
2052
2053static void yukon_reset(struct skge_hw *hw, int port)
2054{
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002055 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);/* disable PHY IRQs */
2056 gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */
2057 gma_write16(hw, port, GM_MC_ADDR_H2, 0);
2058 gma_write16(hw, port, GM_MC_ADDR_H3, 0);
2059 gma_write16(hw, port, GM_MC_ADDR_H4, 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002060
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002061 gma_write16(hw, port, GM_RX_CTRL,
2062 gma_read16(hw, port, GM_RX_CTRL)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002063 | GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
2064}
2065
Stephen Hemmingerc8868612005-09-23 09:08:30 -07002066/* Apparently, early versions of Yukon-Lite had wrong chip_id? */
2067static int is_yukon_lite_a0(struct skge_hw *hw)
2068{
2069 u32 reg;
2070 int ret;
2071
2072 if (hw->chip_id != CHIP_ID_YUKON)
2073 return 0;
2074
2075 reg = skge_read32(hw, B2_FAR);
2076 skge_write8(hw, B2_FAR + 3, 0xff);
2077 ret = (skge_read8(hw, B2_FAR + 3) != 0);
2078 skge_write32(hw, B2_FAR, reg);
2079 return ret;
2080}
2081
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002082static void yukon_mac_init(struct skge_hw *hw, int port)
2083{
2084 struct skge_port *skge = netdev_priv(hw->dev[port]);
2085 int i;
2086 u32 reg;
2087 const u8 *addr = hw->dev[port]->dev_addr;
2088
2089 /* WA code for COMA mode -- set PHY reset */
2090 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002091 hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
2092 reg = skge_read32(hw, B2_GP_IO);
2093 reg |= GP_DIR_9 | GP_IO_9;
2094 skge_write32(hw, B2_GP_IO, reg);
2095 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002096
2097 /* hard reset */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002098 skge_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
2099 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002100
2101 /* WA code for COMA mode -- clear PHY reset */
2102 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002103 hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
2104 reg = skge_read32(hw, B2_GP_IO);
2105 reg |= GP_DIR_9;
2106 reg &= ~GP_IO_9;
2107 skge_write32(hw, B2_GP_IO, reg);
2108 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002109
2110 /* Set hardware config mode */
2111 reg = GPC_INT_POL_HI | GPC_DIS_FC | GPC_DIS_SLEEP |
2112 GPC_ENA_XC | GPC_ANEG_ADV_ALL_M | GPC_ENA_PAUSE;
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07002113 reg |= hw->copper ? GPC_HWCFG_GMII_COP : GPC_HWCFG_GMII_FIB;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002114
2115 /* Clear GMC reset */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002116 skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_SET);
2117 skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_CLR);
2118 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR);
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002119
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002120 if (skge->autoneg == AUTONEG_DISABLE) {
2121 reg = GM_GPCR_AU_ALL_DIS;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002122 gma_write16(hw, port, GM_GP_CTRL,
2123 gma_read16(hw, port, GM_GP_CTRL) | reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002124
2125 switch (skge->speed) {
2126 case SPEED_1000:
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002127 reg &= ~GM_GPCR_SPEED_100;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002128 reg |= GM_GPCR_SPEED_1000;
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002129 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002130 case SPEED_100:
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002131 reg &= ~GM_GPCR_SPEED_1000;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002132 reg |= GM_GPCR_SPEED_100;
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002133 break;
2134 case SPEED_10:
2135 reg &= ~(GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100);
2136 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002137 }
2138
2139 if (skge->duplex == DUPLEX_FULL)
2140 reg |= GM_GPCR_DUP_FULL;
2141 } else
2142 reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL;
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002143
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002144 switch (skge->flow_control) {
2145 case FLOW_MODE_NONE:
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002146 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002147 reg |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
2148 break;
2149 case FLOW_MODE_LOC_SEND:
2150 /* disable Rx flow-control */
2151 reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002152 break;
2153 case FLOW_MODE_SYMMETRIC:
2154 case FLOW_MODE_SYM_OR_REM:
2155 /* enable Tx & Rx flow-control */
2156 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002157 }
2158
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002159 gma_write16(hw, port, GM_GP_CTRL, reg);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002160 skge_read16(hw, SK_REG(port, GMAC_IRQ_SRC));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002161
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002162 yukon_init(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002163
2164 /* MIB clear */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002165 reg = gma_read16(hw, port, GM_PHY_ADDR);
2166 gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002167
2168 for (i = 0; i < GM_MIB_CNT_SIZE; i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002169 gma_read16(hw, port, GM_MIB_CNT_BASE + 8*i);
2170 gma_write16(hw, port, GM_PHY_ADDR, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002171
2172 /* transmit control */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002173 gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002174
2175 /* receive control reg: unicast + multicast + no FCS */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002176 gma_write16(hw, port, GM_RX_CTRL,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002177 GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA);
2178
2179 /* transmit flow control */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002180 gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002181
2182 /* transmit parameter */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002183 gma_write16(hw, port, GM_TX_PARAM,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002184 TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) |
2185 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) |
2186 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF));
2187
Stephen Hemminger44c7fcc2007-11-28 14:23:01 -08002188 /* configure the Serial Mode Register */
2189 reg = DATA_BLIND_VAL(DATA_BLIND_DEF)
2190 | GM_SMOD_VLAN_ENA
2191 | IPG_DATA_VAL(IPG_DATA_DEF);
2192
2193 if (hw->dev[port]->mtu > ETH_DATA_LEN)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002194 reg |= GM_SMOD_JUMBO_ENA;
2195
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002196 gma_write16(hw, port, GM_SERIAL_MODE, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002197
2198 /* physical address: used for pause frames */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002199 gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002200 /* virtual address for data */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002201 gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002202
2203 /* enable interrupt mask for counter overflows */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002204 gma_write16(hw, port, GM_TX_IRQ_MSK, 0);
2205 gma_write16(hw, port, GM_RX_IRQ_MSK, 0);
2206 gma_write16(hw, port, GM_TR_IRQ_MSK, 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002207
2208 /* Initialize Mac Fifo */
2209
2210 /* Configure Rx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002211 skge_write16(hw, SK_REG(port, RX_GMF_FL_MSK), RX_FF_FL_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002212 reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
Stephen Hemmingerc8868612005-09-23 09:08:30 -07002213
2214 /* disable Rx GMAC FIFO Flush for YUKON-Lite Rev. A0 only */
2215 if (is_yukon_lite_a0(hw))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002216 reg &= ~GMF_RX_F_FL_ON;
Stephen Hemmingerc8868612005-09-23 09:08:30 -07002217
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002218 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
2219 skge_write16(hw, SK_REG(port, RX_GMF_CTRL_T), reg);
Stephen Hemmingerc5923082005-08-16 14:01:02 -07002220 /*
2221 * because Pause Packet Truncation in GMAC is not working
2222 * we have to increase the Flush Threshold to 64 bytes
2223 * in order to flush pause packets in Rx FIFO on Yukon-1
2224 */
2225 skge_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF+1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002226
2227 /* Configure Tx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002228 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
2229 skge_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002230}
2231
Stephen Hemminger355ec572005-11-08 10:33:43 -08002232/* Go into power down mode */
2233static void yukon_suspend(struct skge_hw *hw, int port)
2234{
2235 u16 ctrl;
2236
2237 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
2238 ctrl |= PHY_M_PC_POL_R_DIS;
2239 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
2240
2241 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
2242 ctrl |= PHY_CT_RESET;
2243 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
2244
2245 /* switch IEEE compatible power down mode on */
2246 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
2247 ctrl |= PHY_CT_PDOWN;
2248 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
2249}
2250
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002251static void yukon_stop(struct skge_port *skge)
2252{
2253 struct skge_hw *hw = skge->hw;
2254 int port = skge->port;
2255
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002256 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
2257 yukon_reset(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002258
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002259 gma_write16(hw, port, GM_GP_CTRL,
2260 gma_read16(hw, port, GM_GP_CTRL)
Stephen Hemminger0eedf4a2005-07-22 16:26:04 -07002261 & ~(GM_GPCR_TX_ENA|GM_GPCR_RX_ENA));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002262 gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002263
Stephen Hemminger355ec572005-11-08 10:33:43 -08002264 yukon_suspend(hw, port);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002265
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002266 /* set GPHY Control reset */
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002267 skge_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
2268 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002269}
2270
2271static void yukon_get_stats(struct skge_port *skge, u64 *data)
2272{
2273 struct skge_hw *hw = skge->hw;
2274 int port = skge->port;
2275 int i;
2276
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002277 data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32
2278 | gma_read32(hw, port, GM_TXO_OK_LO);
2279 data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32
2280 | gma_read32(hw, port, GM_RXO_OK_LO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002281
2282 for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002283 data[i] = gma_read32(hw, port,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002284 skge_stats[i].gma_offset);
2285}
2286
2287static void yukon_mac_intr(struct skge_hw *hw, int port)
2288{
Stephen Hemminger7e676d92005-06-27 11:33:13 -07002289 struct net_device *dev = hw->dev[port];
2290 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002291 u8 status = skge_read8(hw, SK_REG(port, GMAC_IRQ_SRC));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002292
Joe Perchesd7072042010-02-09 11:49:53 +00002293 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
2294 "mac interrupt status 0x%x\n", status);
Stephen Hemminger7e676d92005-06-27 11:33:13 -07002295
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002296 if (status & GM_IS_RX_FF_OR) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07002297 ++dev->stats.rx_fifo_errors;
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002298 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002299 }
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002300
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002301 if (status & GM_IS_TX_FF_UR) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07002302 ++dev->stats.tx_fifo_errors;
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002303 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002304 }
2305
2306}
2307
2308static u16 yukon_speed(const struct skge_hw *hw, u16 aux)
2309{
Stephen Hemminger95566062005-06-27 11:33:02 -07002310 switch (aux & PHY_M_PS_SPEED_MSK) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002311 case PHY_M_PS_SPEED_1000:
2312 return SPEED_1000;
2313 case PHY_M_PS_SPEED_100:
2314 return SPEED_100;
2315 default:
2316 return SPEED_10;
2317 }
2318}
2319
2320static void yukon_link_up(struct skge_port *skge)
2321{
2322 struct skge_hw *hw = skge->hw;
2323 int port = skge->port;
2324 u16 reg;
2325
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002326 /* Enable Transmit FIFO Underrun */
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002327 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002328
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002329 reg = gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002330 if (skge->duplex == DUPLEX_FULL || skge->autoneg == AUTONEG_ENABLE)
2331 reg |= GM_GPCR_DUP_FULL;
2332
2333 /* enable Rx/Tx */
2334 reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002335 gma_write16(hw, port, GM_GP_CTRL, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002336
Stephen Hemminger4cde06e2005-07-22 16:26:09 -07002337 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002338 skge_link_up(skge);
2339}
2340
2341static void yukon_link_down(struct skge_port *skge)
2342{
2343 struct skge_hw *hw = skge->hw;
2344 int port = skge->port;
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002345 u16 ctrl;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002346
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002347 ctrl = gma_read16(hw, port, GM_GP_CTRL);
2348 ctrl &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
2349 gma_write16(hw, port, GM_GP_CTRL, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002350
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002351 if (skge->flow_status == FLOW_STAT_REM_SEND) {
2352 ctrl = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV);
2353 ctrl |= PHY_M_AN_ASP;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002354 /* restore Asymmetric Pause bit */
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002355 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002356 }
2357
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002358 skge_link_down(skge);
2359
2360 yukon_init(hw, port);
2361}
2362
2363static void yukon_phy_intr(struct skge_port *skge)
2364{
2365 struct skge_hw *hw = skge->hw;
2366 int port = skge->port;
2367 const char *reason = NULL;
2368 u16 istatus, phystat;
2369
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002370 istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT);
2371 phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT);
Stephen Hemminger7e676d92005-06-27 11:33:13 -07002372
Joe Perchesd7072042010-02-09 11:49:53 +00002373 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
2374 "phy interrupt status 0x%x 0x%x\n", istatus, phystat);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002375
2376 if (istatus & PHY_M_IS_AN_COMPL) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002377 if (gm_phy_read(hw, port, PHY_MARV_AUNE_LP)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002378 & PHY_M_AN_RF) {
2379 reason = "remote fault";
2380 goto failed;
2381 }
2382
Stephen Hemmingerc506a502005-06-27 11:33:09 -07002383 if (gm_phy_read(hw, port, PHY_MARV_1000T_STAT) & PHY_B_1000S_MSF) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002384 reason = "master/slave fault";
2385 goto failed;
2386 }
2387
2388 if (!(phystat & PHY_M_PS_SPDUP_RES)) {
2389 reason = "speed/duplex";
2390 goto failed;
2391 }
2392
2393 skge->duplex = (phystat & PHY_M_PS_FULL_DUP)
2394 ? DUPLEX_FULL : DUPLEX_HALF;
2395 skge->speed = yukon_speed(hw, phystat);
2396
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002397 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
2398 switch (phystat & PHY_M_PS_PAUSE_MSK) {
2399 case PHY_M_PS_PAUSE_MSK:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002400 skge->flow_status = FLOW_STAT_SYMMETRIC;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002401 break;
2402 case PHY_M_PS_RX_P_EN:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002403 skge->flow_status = FLOW_STAT_REM_SEND;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002404 break;
2405 case PHY_M_PS_TX_P_EN:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002406 skge->flow_status = FLOW_STAT_LOC_SEND;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002407 break;
2408 default:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002409 skge->flow_status = FLOW_STAT_NONE;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002410 }
2411
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002412 if (skge->flow_status == FLOW_STAT_NONE ||
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002413 (skge->speed < SPEED_1000 && skge->duplex == DUPLEX_HALF))
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002414 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002415 else
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002416 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002417 yukon_link_up(skge);
2418 return;
2419 }
2420
2421 if (istatus & PHY_M_IS_LSP_CHANGE)
2422 skge->speed = yukon_speed(hw, phystat);
2423
2424 if (istatus & PHY_M_IS_DUP_CHANGE)
2425 skge->duplex = (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
2426 if (istatus & PHY_M_IS_LST_CHANGE) {
2427 if (phystat & PHY_M_PS_LINK_UP)
2428 yukon_link_up(skge);
2429 else
2430 yukon_link_down(skge);
2431 }
2432 return;
2433 failed:
Joe Perchesf15063c2010-02-17 15:01:57 +00002434 pr_err("%s: autonegotiation failed (%s)\n", skge->netdev->name, reason);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002435
2436 /* XXX restart autonegotiation? */
2437}
2438
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002439static void skge_phy_reset(struct skge_port *skge)
2440{
2441 struct skge_hw *hw = skge->hw;
2442 int port = skge->port;
Jeff Garzikaae343d2006-12-02 07:14:39 -05002443 struct net_device *dev = hw->dev[port];
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002444
2445 netif_stop_queue(skge->netdev);
2446 netif_carrier_off(skge->netdev);
2447
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002448 spin_lock_bh(&hw->phy_lock);
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002449 if (hw->chip_id == CHIP_ID_GENESIS) {
2450 genesis_reset(hw, port);
2451 genesis_mac_init(hw, port);
2452 } else {
2453 yukon_reset(hw, port);
2454 yukon_init(hw, port);
2455 }
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002456 spin_unlock_bh(&hw->phy_lock);
Stephen Hemminger75814092006-12-01 11:41:08 -08002457
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08002458 skge_set_multicast(dev);
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002459}
2460
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002461/* Basic MII support */
2462static int skge_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2463{
2464 struct mii_ioctl_data *data = if_mii(ifr);
2465 struct skge_port *skge = netdev_priv(dev);
2466 struct skge_hw *hw = skge->hw;
2467 int err = -EOPNOTSUPP;
2468
2469 if (!netif_running(dev))
2470 return -ENODEV; /* Phy still in reset */
2471
Joe Perches67777f92010-02-17 15:01:58 +00002472 switch (cmd) {
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002473 case SIOCGMIIPHY:
2474 data->phy_id = hw->phy_addr;
2475
2476 /* fallthru */
2477 case SIOCGMIIREG: {
2478 u16 val = 0;
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002479 spin_lock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002480 if (hw->chip_id == CHIP_ID_GENESIS)
2481 err = __xm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val);
2482 else
2483 err = __gm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002484 spin_unlock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002485 data->val_out = val;
2486 break;
2487 }
2488
2489 case SIOCSMIIREG:
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002490 spin_lock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002491 if (hw->chip_id == CHIP_ID_GENESIS)
2492 err = xm_phy_write(hw, skge->port, data->reg_num & 0x1f,
2493 data->val_in);
2494 else
2495 err = gm_phy_write(hw, skge->port, data->reg_num & 0x1f,
2496 data->val_in);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002497 spin_unlock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002498 break;
2499 }
2500 return err;
2501}
2502
Linus Torvalds279e1da2007-11-15 08:44:36 -08002503static void skge_ramset(struct skge_hw *hw, u16 q, u32 start, size_t len)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002504{
2505 u32 end;
2506
Linus Torvalds279e1da2007-11-15 08:44:36 -08002507 start /= 8;
2508 len /= 8;
2509 end = start + len - 1;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002510
2511 skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR);
2512 skge_write32(hw, RB_ADDR(q, RB_START), start);
2513 skge_write32(hw, RB_ADDR(q, RB_WP), start);
2514 skge_write32(hw, RB_ADDR(q, RB_RP), start);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002515 skge_write32(hw, RB_ADDR(q, RB_END), end);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002516
2517 if (q == Q_R1 || q == Q_R2) {
2518 /* Set thresholds on receive queue's */
Linus Torvalds279e1da2007-11-15 08:44:36 -08002519 skge_write32(hw, RB_ADDR(q, RB_RX_UTPP),
2520 start + (2*len)/3);
2521 skge_write32(hw, RB_ADDR(q, RB_RX_LTPP),
2522 start + (len/3));
2523 } else {
2524 /* Enable store & forward on Tx queue's because
2525 * Tx FIFO is only 4K on Genesis and 1K on Yukon
2526 */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002527 skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002528 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002529
2530 skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD);
2531}
2532
2533/* Setup Bus Memory Interface */
2534static void skge_qset(struct skge_port *skge, u16 q,
2535 const struct skge_element *e)
2536{
2537 struct skge_hw *hw = skge->hw;
2538 u32 watermark = 0x600;
2539 u64 base = skge->dma + (e->desc - skge->mem);
2540
2541 /* optimization to reduce window on 32bit/33mhz */
2542 if ((skge_read16(hw, B0_CTST) & (CS_BUS_CLOCK | CS_BUS_SLOT_SZ)) == 0)
2543 watermark /= 2;
2544
2545 skge_write32(hw, Q_ADDR(q, Q_CSR), CSR_CLR_RESET);
2546 skge_write32(hw, Q_ADDR(q, Q_F), watermark);
2547 skge_write32(hw, Q_ADDR(q, Q_DA_H), (u32)(base >> 32));
2548 skge_write32(hw, Q_ADDR(q, Q_DA_L), (u32)base);
2549}
2550
2551static int skge_up(struct net_device *dev)
2552{
2553 struct skge_port *skge = netdev_priv(dev);
2554 struct skge_hw *hw = skge->hw;
2555 int port = skge->port;
Linus Torvalds279e1da2007-11-15 08:44:36 -08002556 u32 chunk, ram_addr;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002557 size_t rx_size, tx_size;
2558 int err;
2559
Stephen Hemmingerfae87592007-02-02 08:22:51 -08002560 if (!is_valid_ether_addr(dev->dev_addr))
2561 return -EINVAL;
2562
Joe Perchesd7072042010-02-09 11:49:53 +00002563 netif_info(skge, ifup, skge->netdev, "enabling interface\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002564
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002565 if (dev->mtu > RX_BUF_SIZE)
Stephen Hemminger901ccef2006-03-23 11:07:23 -08002566 skge->rx_buf_size = dev->mtu + ETH_HLEN;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002567 else
2568 skge->rx_buf_size = RX_BUF_SIZE;
2569
2570
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002571 rx_size = skge->rx_ring.count * sizeof(struct skge_rx_desc);
2572 tx_size = skge->tx_ring.count * sizeof(struct skge_tx_desc);
2573 skge->mem_size = tx_size + rx_size;
2574 skge->mem = pci_alloc_consistent(hw->pdev, skge->mem_size, &skge->dma);
2575 if (!skge->mem)
2576 return -ENOMEM;
2577
Stephen Hemmingerc3da1442006-03-21 10:57:01 -08002578 BUG_ON(skge->dma & 7);
2579
2580 if ((u64)skge->dma >> 32 != ((u64) skge->dma + skge->mem_size) >> 32) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08002581 dev_err(&hw->pdev->dev, "pci_alloc_consistent region crosses 4G boundary\n");
Stephen Hemmingerc3da1442006-03-21 10:57:01 -08002582 err = -EINVAL;
2583 goto free_pci_mem;
2584 }
2585
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002586 memset(skge->mem, 0, skge->mem_size);
2587
Stephen Hemminger203babb2006-03-21 10:57:05 -08002588 err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma);
2589 if (err)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002590 goto free_pci_mem;
2591
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07002592 err = skge_rx_fill(dev);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002593 if (err)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002594 goto free_rx_ring;
2595
Stephen Hemminger203babb2006-03-21 10:57:05 -08002596 err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size,
2597 skge->dma + rx_size);
2598 if (err)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002599 goto free_rx_ring;
2600
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08002601 /* Initialize MAC */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002602 spin_lock_bh(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002603 if (hw->chip_id == CHIP_ID_GENESIS)
2604 genesis_mac_init(hw, port);
2605 else
2606 yukon_mac_init(hw, port);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002607 spin_unlock_bh(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002608
Stephen Hemminger29816d92007-11-26 11:54:48 -08002609 /* Configure RAMbuffers - equally between ports and tx/rx */
2610 chunk = (hw->ram_size - hw->ram_offset) / (hw->ports * 2);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002611 ram_addr = hw->ram_offset + 2 * chunk * port;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002612
Linus Torvalds279e1da2007-11-15 08:44:36 -08002613 skge_ramset(hw, rxqaddr[port], ram_addr, chunk);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002614 skge_qset(skge, rxqaddr[port], skge->rx_ring.to_clean);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002615
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002616 BUG_ON(skge->tx_ring.to_use != skge->tx_ring.to_clean);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002617 skge_ramset(hw, txqaddr[port], ram_addr+chunk, chunk);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002618 skge_qset(skge, txqaddr[port], skge->tx_ring.to_use);
2619
2620 /* Start receiver BMU */
2621 wmb();
2622 skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_START | CSR_IRQ_CL_F);
Stephen Hemminger6abebb52005-07-22 16:26:10 -07002623 skge_led(skge, LED_MODE_ON);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002624
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07002625 spin_lock_irq(&hw->hw_lock);
2626 hw->intr_mask |= portmask[port];
2627 skge_write32(hw, B0_IMSK, hw->intr_mask);
2628 spin_unlock_irq(&hw->hw_lock);
2629
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002630 napi_enable(&skge->napi);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002631 return 0;
2632
2633 free_rx_ring:
2634 skge_rx_clean(skge);
2635 kfree(skge->rx_ring.start);
2636 free_pci_mem:
2637 pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002638 skge->mem = NULL;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002639
2640 return err;
2641}
2642
Stephen Hemminger60b24b52007-10-16 12:15:50 -07002643/* stop receiver */
2644static void skge_rx_stop(struct skge_hw *hw, int port)
2645{
2646 skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_STOP);
2647 skge_write32(hw, RB_ADDR(port ? Q_R2 : Q_R1, RB_CTRL),
2648 RB_RST_SET|RB_DIS_OP_MD);
2649 skge_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_SET_RESET);
2650}
2651
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002652static int skge_down(struct net_device *dev)
2653{
2654 struct skge_port *skge = netdev_priv(dev);
2655 struct skge_hw *hw = skge->hw;
2656 int port = skge->port;
2657
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002658 if (skge->mem == NULL)
2659 return 0;
2660
Joe Perchesd7072042010-02-09 11:49:53 +00002661 netif_info(skge, ifdown, skge->netdev, "disabling interface\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002662
Michal Schmidtd119b392009-04-14 15:16:55 -07002663 netif_tx_disable(dev);
Stephen Hemminger692412b2007-04-09 15:32:45 -07002664
Stephen Hemminger64f6b642006-09-23 21:25:28 -07002665 if (hw->chip_id == CHIP_ID_GENESIS && hw->phy_type == SK_PHY_XMAC)
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002666 del_timer_sync(&skge->link_timer);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002667
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002668 napi_disable(&skge->napi);
Stephen Hemminger692412b2007-04-09 15:32:45 -07002669 netif_carrier_off(dev);
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07002670
2671 spin_lock_irq(&hw->hw_lock);
2672 hw->intr_mask &= ~portmask[port];
2673 skge_write32(hw, B0_IMSK, hw->intr_mask);
2674 spin_unlock_irq(&hw->hw_lock);
2675
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002676 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF);
2677 if (hw->chip_id == CHIP_ID_GENESIS)
2678 genesis_stop(skge);
2679 else
2680 yukon_stop(skge);
2681
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002682 /* Stop transmitter */
2683 skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP);
2684 skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL),
2685 RB_RST_SET|RB_DIS_OP_MD);
2686
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002687
2688 /* Disable Force Sync bit and Enable Alloc bit */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002689 skge_write8(hw, SK_REG(port, TXA_CTRL),
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002690 TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
2691
2692 /* Stop Interval Timer and Limit Counter of Tx Arbiter */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002693 skge_write32(hw, SK_REG(port, TXA_ITI_INI), 0L);
2694 skge_write32(hw, SK_REG(port, TXA_LIM_INI), 0L);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002695
2696 /* Reset PCI FIFO */
2697 skge_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_SET_RESET);
2698 skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET);
2699
2700 /* Reset the RAM Buffer async Tx queue */
2701 skge_write8(hw, RB_ADDR(port == 0 ? Q_XA1 : Q_XA2, RB_CTRL), RB_RST_SET);
Stephen Hemminger60b24b52007-10-16 12:15:50 -07002702
2703 skge_rx_stop(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002704
2705 if (hw->chip_id == CHIP_ID_GENESIS) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002706 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_SET);
2707 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002708 } else {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002709 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
2710 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002711 }
2712
Stephen Hemminger6abebb52005-07-22 16:26:10 -07002713 skge_led(skge, LED_MODE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002714
Stephen Hemmingere3a1b992007-03-16 14:01:26 -07002715 netif_tx_lock_bh(dev);
Stephen Hemminger513f5332006-09-01 15:53:49 -07002716 skge_tx_clean(dev);
Stephen Hemmingere3a1b992007-03-16 14:01:26 -07002717 netif_tx_unlock_bh(dev);
2718
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002719 skge_rx_clean(skge);
2720
2721 kfree(skge->rx_ring.start);
2722 kfree(skge->tx_ring.start);
2723 pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002724 skge->mem = NULL;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002725 return 0;
2726}
2727
Stephen Hemminger29b4e882006-03-23 11:07:28 -08002728static inline int skge_avail(const struct skge_ring *ring)
2729{
Stephen Hemminger992c9622007-03-16 14:01:30 -07002730 smp_mb();
Stephen Hemminger29b4e882006-03-23 11:07:28 -08002731 return ((ring->to_clean > ring->to_use) ? 0 : ring->count)
2732 + (ring->to_clean - ring->to_use) - 1;
2733}
2734
Stephen Hemminger613573252009-08-31 19:50:58 +00002735static netdev_tx_t skge_xmit_frame(struct sk_buff *skb,
2736 struct net_device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002737{
2738 struct skge_port *skge = netdev_priv(dev);
2739 struct skge_hw *hw = skge->hw;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002740 struct skge_element *e;
2741 struct skge_tx_desc *td;
2742 int i;
2743 u32 control, len;
2744 u64 map;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002745
Herbert Xu5b057c62006-06-23 02:06:41 -07002746 if (skb_padto(skb, ETH_ZLEN))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002747 return NETDEV_TX_OK;
2748
Stephen Hemminger513f5332006-09-01 15:53:49 -07002749 if (unlikely(skge_avail(&skge->tx_ring) < skb_shinfo(skb)->nr_frags + 1))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002750 return NETDEV_TX_BUSY;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002751
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002752 e = skge->tx_ring.to_use;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002753 td = e->desc;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002754 BUG_ON(td->control & BMU_OWN);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002755 e->skb = skb;
2756 len = skb_headlen(skb);
2757 map = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE);
2758 pci_unmap_addr_set(e, mapaddr, map);
2759 pci_unmap_len_set(e, maplen, len);
2760
2761 td->dma_lo = map;
2762 td->dma_hi = map >> 32;
2763
Patrick McHardy84fa7932006-08-29 16:44:56 -07002764 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002765 const int offset = skb_transport_offset(skb);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002766
2767 /* This seems backwards, but it is what the sk98lin
2768 * does. Looks like hardware is wrong?
2769 */
Joe Perches8e95a202009-12-03 07:58:21 +00002770 if (ipip_hdr(skb)->protocol == IPPROTO_UDP &&
Joe Perches67777f92010-02-17 15:01:58 +00002771 hw->chip_rev == 0 && hw->chip_id == CHIP_ID_YUKON)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002772 control = BMU_TCP_CHECK;
2773 else
2774 control = BMU_UDP_CHECK;
2775
2776 td->csum_offs = 0;
2777 td->csum_start = offset;
Al Viroff1dcad2006-11-20 18:07:29 -08002778 td->csum_write = offset + skb->csum_offset;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002779 } else
2780 control = BMU_CHECK;
2781
2782 if (!skb_shinfo(skb)->nr_frags) /* single buffer i.e. no fragments */
Joe Perches67777f92010-02-17 15:01:58 +00002783 control |= BMU_EOF | BMU_IRQ_EOF;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002784 else {
2785 struct skge_tx_desc *tf = td;
2786
2787 control |= BMU_STFWD;
2788 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2789 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2790
2791 map = pci_map_page(hw->pdev, frag->page, frag->page_offset,
2792 frag->size, PCI_DMA_TODEVICE);
2793
2794 e = e->next;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002795 e->skb = skb;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002796 tf = e->desc;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002797 BUG_ON(tf->control & BMU_OWN);
2798
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002799 tf->dma_lo = map;
2800 tf->dma_hi = (u64) map >> 32;
2801 pci_unmap_addr_set(e, mapaddr, map);
2802 pci_unmap_len_set(e, maplen, frag->size);
2803
2804 tf->control = BMU_OWN | BMU_SW | control | frag->size;
2805 }
2806 tf->control |= BMU_EOF | BMU_IRQ_EOF;
2807 }
2808 /* Make sure all the descriptors written */
2809 wmb();
2810 td->control = BMU_OWN | BMU_SW | BMU_STF | control | len;
2811 wmb();
2812
2813 skge_write8(hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_START);
2814
Joe Perchesd7072042010-02-09 11:49:53 +00002815 netif_printk(skge, tx_queued, KERN_DEBUG, skge->netdev,
2816 "tx queued, slot %td, len %d\n",
2817 e - skge->tx_ring.start, skb->len);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002818
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002819 skge->tx_ring.to_use = e->next;
Stephen Hemminger992c9622007-03-16 14:01:30 -07002820 smp_wmb();
2821
Stephen Hemminger9db96472006-06-06 10:11:12 -07002822 if (skge_avail(&skge->tx_ring) <= TX_LOW_WATER) {
Joe Perchesf15063c2010-02-17 15:01:57 +00002823 netdev_dbg(dev, "transmit queue full\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002824 netif_stop_queue(dev);
2825 }
2826
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002827 return NETDEV_TX_OK;
2828}
2829
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002830
2831/* Free resources associated with this reing element */
2832static void skge_tx_free(struct skge_port *skge, struct skge_element *e,
2833 u32 control)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002834{
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002835 struct pci_dev *pdev = skge->hw->pdev;
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002836
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002837 /* skb header vs. fragment */
2838 if (control & BMU_STF)
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002839 pci_unmap_single(pdev, pci_unmap_addr(e, mapaddr),
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002840 pci_unmap_len(e, maplen),
2841 PCI_DMA_TODEVICE);
2842 else
2843 pci_unmap_page(pdev, pci_unmap_addr(e, mapaddr),
2844 pci_unmap_len(e, maplen),
2845 PCI_DMA_TODEVICE);
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002846
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002847 if (control & BMU_EOF) {
Joe Perchesd7072042010-02-09 11:49:53 +00002848 netif_printk(skge, tx_done, KERN_DEBUG, skge->netdev,
2849 "tx done slot %td\n", e - skge->tx_ring.start);
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002850
Stephen Hemminger513f5332006-09-01 15:53:49 -07002851 dev_kfree_skb(e->skb);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002852 }
2853}
2854
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002855/* Free all buffers in transmit ring */
Stephen Hemminger513f5332006-09-01 15:53:49 -07002856static void skge_tx_clean(struct net_device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002857{
Stephen Hemminger513f5332006-09-01 15:53:49 -07002858 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002859 struct skge_element *e;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002860
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002861 for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) {
2862 struct skge_tx_desc *td = e->desc;
2863 skge_tx_free(skge, e, td->control);
2864 td->control = 0;
2865 }
2866
2867 skge->tx_ring.to_clean = e;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002868}
2869
2870static void skge_tx_timeout(struct net_device *dev)
2871{
2872 struct skge_port *skge = netdev_priv(dev);
2873
Joe Perchesd7072042010-02-09 11:49:53 +00002874 netif_printk(skge, timer, KERN_DEBUG, skge->netdev, "tx timeout\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002875
2876 skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_STOP);
Stephen Hemminger513f5332006-09-01 15:53:49 -07002877 skge_tx_clean(dev);
Michal Schmidtd119b392009-04-14 15:16:55 -07002878 netif_wake_queue(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002879}
2880
2881static int skge_change_mtu(struct net_device *dev, int new_mtu)
2882{
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002883 int err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002884
Stephen Hemminger95566062005-06-27 11:33:02 -07002885 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002886 return -EINVAL;
2887
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002888 if (!netif_running(dev)) {
2889 dev->mtu = new_mtu;
2890 return 0;
2891 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002892
Stephen Hemminger1a8098b2007-11-28 14:25:05 -08002893 skge_down(dev);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002894
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002895 dev->mtu = new_mtu;
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002896
Stephen Hemminger1a8098b2007-11-28 14:25:05 -08002897 err = skge_up(dev);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002898 if (err)
2899 dev_close(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002900
2901 return err;
2902}
2903
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002904static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 };
2905
2906static void genesis_add_filter(u8 filter[8], const u8 *addr)
2907{
2908 u32 crc, bit;
2909
2910 crc = ether_crc_le(ETH_ALEN, addr);
2911 bit = ~crc & 0x3f;
2912 filter[bit/8] |= 1 << (bit%8);
2913}
2914
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002915static void genesis_set_multicast(struct net_device *dev)
2916{
2917 struct skge_port *skge = netdev_priv(dev);
2918 struct skge_hw *hw = skge->hw;
2919 int port = skge->port;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002920 int i, count = netdev_mc_count(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002921 struct dev_mc_list *list = dev->mc_list;
2922 u32 mode;
2923 u8 filter[8];
2924
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002925 mode = xm_read32(hw, port, XM_MODE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002926 mode |= XM_MD_ENA_HASH;
2927 if (dev->flags & IFF_PROMISC)
2928 mode |= XM_MD_ENA_PROM;
2929 else
2930 mode &= ~XM_MD_ENA_PROM;
2931
2932 if (dev->flags & IFF_ALLMULTI)
2933 memset(filter, 0xff, sizeof(filter));
2934 else {
2935 memset(filter, 0, sizeof(filter));
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002936
Joe Perches8e95a202009-12-03 07:58:21 +00002937 if (skge->flow_status == FLOW_STAT_REM_SEND ||
2938 skge->flow_status == FLOW_STAT_SYMMETRIC)
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002939 genesis_add_filter(filter, pause_mc_addr);
2940
2941 for (i = 0; list && i < count; i++, list = list->next)
2942 genesis_add_filter(filter, list->dmi_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002943 }
2944
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002945 xm_write32(hw, port, XM_MODE, mode);
Stephen Hemminger45bada62005-06-27 11:33:12 -07002946 xm_outhash(hw, port, XM_HSM, filter);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002947}
2948
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002949static void yukon_add_filter(u8 filter[8], const u8 *addr)
2950{
2951 u32 bit = ether_crc(ETH_ALEN, addr) & 0x3f;
2952 filter[bit/8] |= 1 << (bit%8);
2953}
2954
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002955static void yukon_set_multicast(struct net_device *dev)
2956{
2957 struct skge_port *skge = netdev_priv(dev);
2958 struct skge_hw *hw = skge->hw;
2959 int port = skge->port;
2960 struct dev_mc_list *list = dev->mc_list;
Joe Perches8e95a202009-12-03 07:58:21 +00002961 int rx_pause = (skge->flow_status == FLOW_STAT_REM_SEND ||
2962 skge->flow_status == FLOW_STAT_SYMMETRIC);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002963 u16 reg;
2964 u8 filter[8];
2965
2966 memset(filter, 0, sizeof(filter));
2967
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002968 reg = gma_read16(hw, port, GM_RX_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002969 reg |= GM_RXCR_UCF_ENA;
2970
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08002971 if (dev->flags & IFF_PROMISC) /* promiscuous */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002972 reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
2973 else if (dev->flags & IFF_ALLMULTI) /* all multicast */
2974 memset(filter, 0xff, sizeof(filter));
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002975 else if (netdev_mc_empty(dev) && !rx_pause)/* no multicast */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002976 reg &= ~GM_RXCR_MCF_ENA;
2977 else {
2978 int i;
2979 reg |= GM_RXCR_MCF_ENA;
2980
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002981 if (rx_pause)
2982 yukon_add_filter(filter, pause_mc_addr);
2983
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002984 for (i = 0; list && i < netdev_mc_count(dev); i++, list = list->next)
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002985 yukon_add_filter(filter, list->dmi_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002986 }
2987
2988
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002989 gma_write16(hw, port, GM_MC_ADDR_H1,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002990 (u16)filter[0] | ((u16)filter[1] << 8));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002991 gma_write16(hw, port, GM_MC_ADDR_H2,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002992 (u16)filter[2] | ((u16)filter[3] << 8));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002993 gma_write16(hw, port, GM_MC_ADDR_H3,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002994 (u16)filter[4] | ((u16)filter[5] << 8));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002995 gma_write16(hw, port, GM_MC_ADDR_H4,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002996 (u16)filter[6] | ((u16)filter[7] << 8));
2997
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002998 gma_write16(hw, port, GM_RX_CTRL, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002999}
3000
Stephen Hemminger383181a2005-09-19 15:37:16 -07003001static inline u16 phy_length(const struct skge_hw *hw, u32 status)
3002{
3003 if (hw->chip_id == CHIP_ID_GENESIS)
3004 return status >> XMR_FS_LEN_SHIFT;
3005 else
3006 return status >> GMR_FS_LEN_SHIFT;
3007}
3008
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003009static inline int bad_phy_status(const struct skge_hw *hw, u32 status)
3010{
3011 if (hw->chip_id == CHIP_ID_GENESIS)
3012 return (status & (XMR_FS_ERR | XMR_FS_2L_VLAN)) != 0;
3013 else
3014 return (status & GMR_FS_ANY_ERR) ||
3015 (status & GMR_FS_RX_OK) == 0;
3016}
3017
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003018static void skge_set_multicast(struct net_device *dev)
3019{
3020 struct skge_port *skge = netdev_priv(dev);
3021 struct skge_hw *hw = skge->hw;
3022
3023 if (hw->chip_id == CHIP_ID_GENESIS)
3024 genesis_set_multicast(dev);
3025 else
3026 yukon_set_multicast(dev);
3027
3028}
3029
Stephen Hemminger383181a2005-09-19 15:37:16 -07003030
3031/* Get receive buffer from descriptor.
3032 * Handles copy of small buffers and reallocation failures
3033 */
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003034static struct sk_buff *skge_rx_get(struct net_device *dev,
3035 struct skge_element *e,
3036 u32 control, u32 status, u16 csum)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003037{
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003038 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003039 struct sk_buff *skb;
3040 u16 len = control & BMU_BBC;
3041
Joe Perchesd7072042010-02-09 11:49:53 +00003042 netif_printk(skge, rx_status, KERN_DEBUG, skge->netdev,
3043 "rx slot %td status 0x%x len %d\n",
3044 e - skge->rx_ring.start, status, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003045
3046 if (len > skge->rx_buf_size)
3047 goto error;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003048
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003049 if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF))
Stephen Hemminger383181a2005-09-19 15:37:16 -07003050 goto error;
3051
3052 if (bad_phy_status(skge->hw, status))
3053 goto error;
3054
3055 if (phy_length(skge->hw, status) != len)
3056 goto error;
3057
3058 if (len < RX_COPY_THRESHOLD) {
Eric Dumazet89d71a62009-10-13 05:34:20 +00003059 skb = netdev_alloc_skb_ip_align(dev, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003060 if (!skb)
3061 goto resubmit;
3062
Stephen Hemminger383181a2005-09-19 15:37:16 -07003063 pci_dma_sync_single_for_cpu(skge->hw->pdev,
3064 pci_unmap_addr(e, mapaddr),
3065 len, PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03003066 skb_copy_from_linear_data(e->skb, skb->data, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003067 pci_dma_sync_single_for_device(skge->hw->pdev,
3068 pci_unmap_addr(e, mapaddr),
3069 len, PCI_DMA_FROMDEVICE);
3070 skge_rx_reuse(e, skge->rx_buf_size);
3071 } else {
3072 struct sk_buff *nskb;
Eric Dumazet89d71a62009-10-13 05:34:20 +00003073
3074 nskb = netdev_alloc_skb_ip_align(dev, skge->rx_buf_size);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003075 if (!nskb)
3076 goto resubmit;
3077
3078 pci_unmap_single(skge->hw->pdev,
3079 pci_unmap_addr(e, mapaddr),
3080 pci_unmap_len(e, maplen),
3081 PCI_DMA_FROMDEVICE);
3082 skb = e->skb;
Joe Perches67777f92010-02-17 15:01:58 +00003083 prefetch(skb->data);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003084 skge_rx_setup(skge, e, nskb, skge->rx_buf_size);
3085 }
3086
3087 skb_put(skb, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003088 if (skge->rx_csum) {
3089 skb->csum = csum;
Patrick McHardy84fa7932006-08-29 16:44:56 -07003090 skb->ip_summed = CHECKSUM_COMPLETE;
Stephen Hemminger383181a2005-09-19 15:37:16 -07003091 }
3092
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003093 skb->protocol = eth_type_trans(skb, dev);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003094
3095 return skb;
3096error:
3097
Joe Perchesd7072042010-02-09 11:49:53 +00003098 netif_printk(skge, rx_err, KERN_DEBUG, skge->netdev,
3099 "rx err, slot %td control 0x%x status 0x%x\n",
3100 e - skge->rx_ring.start, control, status);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003101
3102 if (skge->hw->chip_id == CHIP_ID_GENESIS) {
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003103 if (status & (XMR_FS_RUNT|XMR_FS_LNG_ERR))
Stephen Hemmingerda007722007-10-16 12:15:52 -07003104 dev->stats.rx_length_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003105 if (status & XMR_FS_FRA_ERR)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003106 dev->stats.rx_frame_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003107 if (status & XMR_FS_FCS_ERR)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003108 dev->stats.rx_crc_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003109 } else {
3110 if (status & (GMR_FS_LONG_ERR|GMR_FS_UN_SIZE))
Stephen Hemmingerda007722007-10-16 12:15:52 -07003111 dev->stats.rx_length_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003112 if (status & GMR_FS_FRAGMENT)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003113 dev->stats.rx_frame_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003114 if (status & GMR_FS_CRC_ERR)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003115 dev->stats.rx_crc_errors++;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003116 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003117
Stephen Hemminger383181a2005-09-19 15:37:16 -07003118resubmit:
3119 skge_rx_reuse(e, skge->rx_buf_size);
3120 return NULL;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003121}
3122
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003123/* Free all buffers in Tx ring which are no longer owned by device */
Stephen Hemminger513f5332006-09-01 15:53:49 -07003124static void skge_tx_done(struct net_device *dev)
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003125{
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003126 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003127 struct skge_ring *ring = &skge->tx_ring;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003128 struct skge_element *e;
3129
Stephen Hemminger513f5332006-09-01 15:53:49 -07003130 skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F);
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003131
Stephen Hemminger866b4f32006-03-23 11:07:27 -08003132 for (e = ring->to_clean; e != ring->to_use; e = e->next) {
Stephen Hemminger992c9622007-03-16 14:01:30 -07003133 u32 control = ((const struct skge_tx_desc *) e->desc)->control;
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003134
Stephen Hemminger992c9622007-03-16 14:01:30 -07003135 if (control & BMU_OWN)
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003136 break;
3137
Stephen Hemminger992c9622007-03-16 14:01:30 -07003138 skge_tx_free(skge, e, control);
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003139 }
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003140 skge->tx_ring.to_clean = e;
Stephen Hemminger866b4f32006-03-23 11:07:27 -08003141
Stephen Hemminger992c9622007-03-16 14:01:30 -07003142 /* Can run lockless until we need to synchronize to restart queue. */
3143 smp_mb();
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003144
Stephen Hemminger992c9622007-03-16 14:01:30 -07003145 if (unlikely(netif_queue_stopped(dev) &&
3146 skge_avail(&skge->tx_ring) > TX_LOW_WATER)) {
3147 netif_tx_lock(dev);
3148 if (unlikely(netif_queue_stopped(dev) &&
3149 skge_avail(&skge->tx_ring) > TX_LOW_WATER)) {
3150 netif_wake_queue(dev);
3151
3152 }
3153 netif_tx_unlock(dev);
3154 }
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003155}
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003156
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003157static int skge_poll(struct napi_struct *napi, int to_do)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003158{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003159 struct skge_port *skge = container_of(napi, struct skge_port, napi);
3160 struct net_device *dev = skge->netdev;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003161 struct skge_hw *hw = skge->hw;
3162 struct skge_ring *ring = &skge->rx_ring;
3163 struct skge_element *e;
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003164 int work_done = 0;
3165
Stephen Hemminger513f5332006-09-01 15:53:49 -07003166 skge_tx_done(dev);
3167
3168 skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F);
3169
Stephen Hemminger1631aef2005-11-08 10:33:44 -08003170 for (e = ring->to_clean; prefetch(e->next), work_done < to_do; e = e->next) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003171 struct skge_rx_desc *rd = e->desc;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003172 struct sk_buff *skb;
Stephen Hemminger383181a2005-09-19 15:37:16 -07003173 u32 control;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003174
3175 rmb();
3176 control = rd->control;
3177 if (control & BMU_OWN)
3178 break;
3179
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003180 skb = skge_rx_get(dev, e, control, rd->status, rd->csum2);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003181 if (likely(skb)) {
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003182 netif_receive_skb(skb);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003183
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003184 ++work_done;
Stephen Hemminger5a011442006-03-23 11:07:25 -08003185 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003186 }
3187 ring->to_clean = e;
3188
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003189 /* restart receiver */
3190 wmb();
Stephen Hemmingera9cdab82006-02-22 10:28:33 -08003191 skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_START);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003192
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003193 if (work_done < to_do) {
Marin Mitov6ef29772008-03-23 10:20:09 +02003194 unsigned long flags;
Jeff Garzikf0c88f92008-03-25 23:53:24 -04003195
Marin Mitov6ef29772008-03-23 10:20:09 +02003196 spin_lock_irqsave(&hw->hw_lock, flags);
Ben Hutchings288379f2009-01-19 16:43:59 -08003197 __napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003198 hw->intr_mask |= napimask[skge->port];
3199 skge_write32(hw, B0_IMSK, hw->intr_mask);
3200 skge_read32(hw, B0_IMSK);
Marin Mitov6ef29772008-03-23 10:20:09 +02003201 spin_unlock_irqrestore(&hw->hw_lock, flags);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003202 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003203
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003204 return work_done;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003205}
3206
Stephen Hemmingerf6620ca2005-07-22 16:26:02 -07003207/* Parity errors seem to happen when Genesis is connected to a switch
3208 * with no other ports present. Heartbeat error??
3209 */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003210static void skge_mac_parity(struct skge_hw *hw, int port)
3211{
Stephen Hemmingerf6620ca2005-07-22 16:26:02 -07003212 struct net_device *dev = hw->dev[port];
3213
Stephen Hemmingerda007722007-10-16 12:15:52 -07003214 ++dev->stats.tx_heartbeat_errors;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003215
3216 if (hw->chip_id == CHIP_ID_GENESIS)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003217 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1),
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003218 MFF_CLR_PERR);
3219 else
3220 /* HW-Bug #8: cleared by GMF_CLI_TX_FC instead of GMF_CLI_TX_PE */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003221 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T),
Stephen Hemminger981d0372005-06-27 11:33:06 -07003222 (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003223 ? GMF_CLI_TX_FC : GMF_CLI_TX_PE);
3224}
3225
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003226static void skge_mac_intr(struct skge_hw *hw, int port)
3227{
Stephen Hemminger95566062005-06-27 11:33:02 -07003228 if (hw->chip_id == CHIP_ID_GENESIS)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003229 genesis_mac_intr(hw, port);
3230 else
3231 yukon_mac_intr(hw, port);
3232}
3233
3234/* Handle device specific framing and timeout interrupts */
3235static void skge_error_irq(struct skge_hw *hw)
3236{
Stephen Hemminger1479d132007-02-02 08:22:52 -08003237 struct pci_dev *pdev = hw->pdev;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003238 u32 hwstatus = skge_read32(hw, B0_HWE_ISRC);
3239
3240 if (hw->chip_id == CHIP_ID_GENESIS) {
3241 /* clear xmac errors */
3242 if (hwstatus & (IS_NO_STAT_M1|IS_NO_TIST_M1))
Stephen Hemminger46a60f22005-09-09 12:54:56 -07003243 skge_write16(hw, RX_MFF_CTRL1, MFF_CLR_INSTAT);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003244 if (hwstatus & (IS_NO_STAT_M2|IS_NO_TIST_M2))
Stephen Hemminger46a60f22005-09-09 12:54:56 -07003245 skge_write16(hw, RX_MFF_CTRL2, MFF_CLR_INSTAT);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003246 } else {
3247 /* Timestamp (unused) overflow */
3248 if (hwstatus & IS_IRQ_TIST_OV)
3249 skge_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003250 }
3251
3252 if (hwstatus & IS_RAM_RD_PAR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003253 dev_err(&pdev->dev, "Ram read data parity error\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003254 skge_write16(hw, B3_RI_CTRL, RI_CLR_RD_PERR);
3255 }
3256
3257 if (hwstatus & IS_RAM_WR_PAR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003258 dev_err(&pdev->dev, "Ram write data parity error\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003259 skge_write16(hw, B3_RI_CTRL, RI_CLR_WR_PERR);
3260 }
3261
3262 if (hwstatus & IS_M1_PAR_ERR)
3263 skge_mac_parity(hw, 0);
3264
3265 if (hwstatus & IS_M2_PAR_ERR)
3266 skge_mac_parity(hw, 1);
3267
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003268 if (hwstatus & IS_R1_PAR_ERR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003269 dev_err(&pdev->dev, "%s: receive queue parity error\n",
3270 hw->dev[0]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003271 skge_write32(hw, B0_R1_CSR, CSR_IRQ_CL_P);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003272 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003273
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003274 if (hwstatus & IS_R2_PAR_ERR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003275 dev_err(&pdev->dev, "%s: receive queue parity error\n",
3276 hw->dev[1]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003277 skge_write32(hw, B0_R2_CSR, CSR_IRQ_CL_P);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003278 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003279
3280 if (hwstatus & (IS_IRQ_MST_ERR|IS_IRQ_STAT)) {
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003281 u16 pci_status, pci_cmd;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003282
Stephen Hemminger1479d132007-02-02 08:22:52 -08003283 pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
3284 pci_read_config_word(pdev, PCI_STATUS, &pci_status);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003285
Stephen Hemminger1479d132007-02-02 08:22:52 -08003286 dev_err(&pdev->dev, "PCI error cmd=%#x status=%#x\n",
3287 pci_cmd, pci_status);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003288
3289 /* Write the error bits back to clear them. */
3290 pci_status &= PCI_STATUS_ERROR_BITS;
3291 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
Stephen Hemminger1479d132007-02-02 08:22:52 -08003292 pci_write_config_word(pdev, PCI_COMMAND,
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003293 pci_cmd | PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
Stephen Hemminger1479d132007-02-02 08:22:52 -08003294 pci_write_config_word(pdev, PCI_STATUS, pci_status);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003295 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003296
Stephen Hemminger050ec182005-08-16 14:00:54 -07003297 /* if error still set then just ignore it */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003298 hwstatus = skge_read32(hw, B0_HWE_ISRC);
3299 if (hwstatus & IS_IRQ_STAT) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003300 dev_warn(&hw->pdev->dev, "unable to clear error (so ignoring them)\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003301 hw->intr_mask &= ~IS_HW_ERR;
3302 }
3303 }
3304}
3305
3306/*
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003307 * Interrupt from PHY are handled in tasklet (softirq)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003308 * because accessing phy registers requires spin wait which might
3309 * cause excess interrupt latency.
3310 */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003311static void skge_extirq(unsigned long arg)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003312{
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003313 struct skge_hw *hw = (struct skge_hw *) arg;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003314 int port;
3315
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003316 for (port = 0; port < hw->ports; port++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003317 struct net_device *dev = hw->dev[port];
3318
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003319 if (netif_running(dev)) {
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003320 struct skge_port *skge = netdev_priv(dev);
3321
3322 spin_lock(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003323 if (hw->chip_id != CHIP_ID_GENESIS)
3324 yukon_phy_intr(skge);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003325 else if (hw->phy_type == SK_PHY_BCOM)
Stephen Hemminger45bada62005-06-27 11:33:12 -07003326 bcom_phy_intr(skge);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003327 spin_unlock(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003328 }
3329 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003330
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003331 spin_lock_irq(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003332 hw->intr_mask |= IS_EXT_REG;
3333 skge_write32(hw, B0_IMSK, hw->intr_mask);
Stephen Hemminger78bc2182006-08-28 16:19:36 -07003334 skge_read32(hw, B0_IMSK);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003335 spin_unlock_irq(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003336}
3337
David Howells7d12e782006-10-05 14:55:46 +01003338static irqreturn_t skge_intr(int irq, void *dev_id)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003339{
3340 struct skge_hw *hw = dev_id;
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003341 u32 status;
Stephen Hemminger29365c92006-09-01 15:53:48 -07003342 int handled = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003343
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003344 spin_lock(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003345 /* Reading this register masks IRQ */
3346 status = skge_read32(hw, B0_SP_ISRC);
Stephen Hemminger0486a8c2006-09-06 11:06:10 -07003347 if (status == 0 || status == ~0)
Stephen Hemminger29365c92006-09-01 15:53:48 -07003348 goto out;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003349
Stephen Hemminger29365c92006-09-01 15:53:48 -07003350 handled = 1;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003351 status &= hw->intr_mask;
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003352 if (status & IS_EXT_REG) {
3353 hw->intr_mask &= ~IS_EXT_REG;
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003354 tasklet_schedule(&hw->phy_task);
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003355 }
3356
Stephen Hemminger513f5332006-09-01 15:53:49 -07003357 if (status & (IS_XA1_F|IS_R1_F)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003358 struct skge_port *skge = netdev_priv(hw->dev[0]);
Stephen Hemminger513f5332006-09-01 15:53:49 -07003359 hw->intr_mask &= ~(IS_XA1_F|IS_R1_F);
Ben Hutchings288379f2009-01-19 16:43:59 -08003360 napi_schedule(&skge->napi);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003361 }
3362
Stephen Hemmingerd25f5a62005-06-27 11:33:14 -07003363 if (status & IS_PA_TO_TX1)
3364 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX1);
3365
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003366 if (status & IS_PA_TO_RX1) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07003367 ++hw->dev[0]->stats.rx_over_errors;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003368 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX1);
3369 }
3370
Stephen Hemmingerd25f5a62005-06-27 11:33:14 -07003371
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003372 if (status & IS_MAC1)
3373 skge_mac_intr(hw, 0);
Stephen Hemminger95566062005-06-27 11:33:02 -07003374
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003375 if (hw->dev[1]) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003376 struct skge_port *skge = netdev_priv(hw->dev[1]);
3377
Stephen Hemminger513f5332006-09-01 15:53:49 -07003378 if (status & (IS_XA2_F|IS_R2_F)) {
3379 hw->intr_mask &= ~(IS_XA2_F|IS_R2_F);
Ben Hutchings288379f2009-01-19 16:43:59 -08003380 napi_schedule(&skge->napi);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003381 }
3382
3383 if (status & IS_PA_TO_RX2) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07003384 ++hw->dev[1]->stats.rx_over_errors;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003385 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX2);
3386 }
3387
3388 if (status & IS_PA_TO_TX2)
3389 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX2);
3390
3391 if (status & IS_MAC2)
3392 skge_mac_intr(hw, 1);
3393 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003394
3395 if (status & IS_HW_ERR)
3396 skge_error_irq(hw);
3397
Stephen Hemminger7e676d92005-06-27 11:33:13 -07003398 skge_write32(hw, B0_IMSK, hw->intr_mask);
Stephen Hemminger78bc2182006-08-28 16:19:36 -07003399 skge_read32(hw, B0_IMSK);
Stephen Hemminger29365c92006-09-01 15:53:48 -07003400out:
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003401 spin_unlock(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003402
Stephen Hemminger29365c92006-09-01 15:53:48 -07003403 return IRQ_RETVAL(handled);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003404}
3405
3406#ifdef CONFIG_NET_POLL_CONTROLLER
3407static void skge_netpoll(struct net_device *dev)
3408{
3409 struct skge_port *skge = netdev_priv(dev);
3410
3411 disable_irq(dev->irq);
David Howells7d12e782006-10-05 14:55:46 +01003412 skge_intr(dev->irq, skge->hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003413 enable_irq(dev->irq);
3414}
3415#endif
3416
3417static int skge_set_mac_address(struct net_device *dev, void *p)
3418{
3419 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerc2681dd2005-10-03 12:03:13 -07003420 struct skge_hw *hw = skge->hw;
3421 unsigned port = skge->port;
3422 const struct sockaddr *addr = p;
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003423 u16 ctrl;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003424
3425 if (!is_valid_ether_addr(addr->sa_data))
3426 return -EADDRNOTAVAIL;
3427
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003428 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
Stephen Hemmingerc2681dd2005-10-03 12:03:13 -07003429
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003430 if (!netif_running(dev)) {
3431 memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN);
3432 memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN);
3433 } else {
3434 /* disable Rx */
3435 spin_lock_bh(&hw->phy_lock);
3436 ctrl = gma_read16(hw, port, GM_GP_CTRL);
3437 gma_write16(hw, port, GM_GP_CTRL, ctrl & ~GM_GPCR_RX_ENA);
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003438
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003439 memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN);
3440 memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN);
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003441
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003442 if (hw->chip_id == CHIP_ID_GENESIS)
3443 xm_outaddr(hw, port, XM_SA, dev->dev_addr);
3444 else {
3445 gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr);
3446 gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr);
3447 }
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003448
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003449 gma_write16(hw, port, GM_GP_CTRL, ctrl);
3450 spin_unlock_bh(&hw->phy_lock);
3451 }
Stephen Hemmingerc2681dd2005-10-03 12:03:13 -07003452
3453 return 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003454}
3455
3456static const struct {
3457 u8 id;
3458 const char *name;
3459} skge_chips[] = {
3460 { CHIP_ID_GENESIS, "Genesis" },
3461 { CHIP_ID_YUKON, "Yukon" },
3462 { CHIP_ID_YUKON_LITE, "Yukon-Lite"},
3463 { CHIP_ID_YUKON_LP, "Yukon-LP"},
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003464};
3465
3466static const char *skge_board_name(const struct skge_hw *hw)
3467{
3468 int i;
3469 static char buf[16];
3470
3471 for (i = 0; i < ARRAY_SIZE(skge_chips); i++)
3472 if (skge_chips[i].id == hw->chip_id)
3473 return skge_chips[i].name;
3474
3475 snprintf(buf, sizeof buf, "chipid 0x%x", hw->chip_id);
3476 return buf;
3477}
3478
3479
3480/*
3481 * Setup the board data structure, but don't bring up
3482 * the port(s)
3483 */
3484static int skge_reset(struct skge_hw *hw)
3485{
Stephen Hemmingeradba9e22005-11-08 10:33:40 -08003486 u32 reg;
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003487 u16 ctst, pci_status;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003488 u8 t8, mac_cfg, pmd_type;
Stephen Hemminger981d0372005-06-27 11:33:06 -07003489 int i;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003490
3491 ctst = skge_read16(hw, B0_CTST);
3492
3493 /* do a SW reset */
3494 skge_write8(hw, B0_CTST, CS_RST_SET);
3495 skge_write8(hw, B0_CTST, CS_RST_CLR);
3496
3497 /* clear PCI errors, if any */
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003498 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
3499 skge_write8(hw, B2_TST_CTRL2, 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003500
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003501 pci_read_config_word(hw->pdev, PCI_STATUS, &pci_status);
3502 pci_write_config_word(hw->pdev, PCI_STATUS,
3503 pci_status | PCI_STATUS_ERROR_BITS);
3504 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003505 skge_write8(hw, B0_CTST, CS_MRST_CLR);
3506
3507 /* restore CLK_RUN bits (for Yukon-Lite) */
3508 skge_write16(hw, B0_CTST,
3509 ctst & (CS_CLK_RUN_HOT|CS_CLK_RUN_RST|CS_CLK_RUN_ENA));
3510
3511 hw->chip_id = skge_read8(hw, B2_CHIP_ID);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003512 hw->phy_type = skge_read8(hw, B2_E_1) & 0xf;
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07003513 pmd_type = skge_read8(hw, B2_PMD_TYP);
3514 hw->copper = (pmd_type == 'T' || pmd_type == '1');
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003515
Stephen Hemminger95566062005-06-27 11:33:02 -07003516 switch (hw->chip_id) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003517 case CHIP_ID_GENESIS:
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003518 switch (hw->phy_type) {
3519 case SK_PHY_XMAC:
3520 hw->phy_addr = PHY_ADDR_XMAC;
3521 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003522 case SK_PHY_BCOM:
3523 hw->phy_addr = PHY_ADDR_BCOM;
3524 break;
3525 default:
Stephen Hemminger1479d132007-02-02 08:22:52 -08003526 dev_err(&hw->pdev->dev, "unsupported phy type 0x%x\n",
3527 hw->phy_type);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003528 return -EOPNOTSUPP;
3529 }
3530 break;
3531
3532 case CHIP_ID_YUKON:
3533 case CHIP_ID_YUKON_LITE:
3534 case CHIP_ID_YUKON_LP:
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003535 if (hw->phy_type < SK_PHY_MARV_COPPER && pmd_type != 'S')
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07003536 hw->copper = 1;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003537
3538 hw->phy_addr = PHY_ADDR_MARV;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003539 break;
3540
3541 default:
Stephen Hemminger1479d132007-02-02 08:22:52 -08003542 dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n",
3543 hw->chip_id);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003544 return -EOPNOTSUPP;
3545 }
3546
Stephen Hemminger981d0372005-06-27 11:33:06 -07003547 mac_cfg = skge_read8(hw, B2_MAC_CFG);
3548 hw->ports = (mac_cfg & CFG_SNG_MAC) ? 1 : 2;
3549 hw->chip_rev = (mac_cfg & CFG_CHIP_R_MSK) >> 4;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003550
3551 /* read the adapters RAM size */
3552 t8 = skge_read8(hw, B2_E_0);
3553 if (hw->chip_id == CHIP_ID_GENESIS) {
3554 if (t8 == 3) {
3555 /* special case: 4 x 64k x 36, offset = 0x80000 */
Linus Torvalds279e1da2007-11-15 08:44:36 -08003556 hw->ram_size = 0x100000;
3557 hw->ram_offset = 0x80000;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003558 } else
3559 hw->ram_size = t8 * 512;
Joe Perches67777f92010-02-17 15:01:58 +00003560 } else if (t8 == 0)
Linus Torvalds279e1da2007-11-15 08:44:36 -08003561 hw->ram_size = 0x20000;
3562 else
3563 hw->ram_size = t8 * 4096;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003564
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07003565 hw->intr_mask = IS_HW_ERR;
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003566
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07003567 /* Use PHY IRQ for all but fiber based Genesis board */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003568 if (!(hw->chip_id == CHIP_ID_GENESIS && hw->phy_type == SK_PHY_XMAC))
3569 hw->intr_mask |= IS_EXT_REG;
3570
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003571 if (hw->chip_id == CHIP_ID_GENESIS)
3572 genesis_init(hw);
3573 else {
3574 /* switch power to VCC (WA for VAUX problem) */
3575 skge_write8(hw, B0_POWER_CTRL,
3576 PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
Stephen Hemmingeradba9e22005-11-08 10:33:40 -08003577
Stephen Hemminger050ec182005-08-16 14:00:54 -07003578 /* avoid boards with stuck Hardware error bits */
3579 if ((skge_read32(hw, B0_ISRC) & IS_HW_ERR) &&
3580 (skge_read32(hw, B0_HWE_ISRC) & IS_IRQ_SENSOR)) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003581 dev_warn(&hw->pdev->dev, "stuck hardware sensor bit\n");
Stephen Hemminger050ec182005-08-16 14:00:54 -07003582 hw->intr_mask &= ~IS_HW_ERR;
3583 }
3584
Stephen Hemmingeradba9e22005-11-08 10:33:40 -08003585 /* Clear PHY COMA */
3586 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
3587 pci_read_config_dword(hw->pdev, PCI_DEV_REG1, &reg);
3588 reg &= ~PCI_PHY_COMA;
3589 pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg);
3590 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
3591
3592
Stephen Hemminger981d0372005-06-27 11:33:06 -07003593 for (i = 0; i < hw->ports; i++) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003594 skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
3595 skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003596 }
3597 }
3598
3599 /* turn off hardware timer (unused) */
3600 skge_write8(hw, B2_TI_CTRL, TIM_STOP);
3601 skge_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ);
3602 skge_write8(hw, B0_LED, LED_STAT_ON);
3603
3604 /* enable the Tx Arbiters */
Stephen Hemminger981d0372005-06-27 11:33:06 -07003605 for (i = 0; i < hw->ports; i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003606 skge_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003607
3608 /* Initialize ram interface */
3609 skge_write16(hw, B3_RI_CTRL, RI_RST_CLR);
3610
3611 skge_write8(hw, B3_RI_WTO_R1, SK_RI_TO_53);
3612 skge_write8(hw, B3_RI_WTO_XA1, SK_RI_TO_53);
3613 skge_write8(hw, B3_RI_WTO_XS1, SK_RI_TO_53);
3614 skge_write8(hw, B3_RI_RTO_R1, SK_RI_TO_53);
3615 skge_write8(hw, B3_RI_RTO_XA1, SK_RI_TO_53);
3616 skge_write8(hw, B3_RI_RTO_XS1, SK_RI_TO_53);
3617 skge_write8(hw, B3_RI_WTO_R2, SK_RI_TO_53);
3618 skge_write8(hw, B3_RI_WTO_XA2, SK_RI_TO_53);
3619 skge_write8(hw, B3_RI_WTO_XS2, SK_RI_TO_53);
3620 skge_write8(hw, B3_RI_RTO_R2, SK_RI_TO_53);
3621 skge_write8(hw, B3_RI_RTO_XA2, SK_RI_TO_53);
3622 skge_write8(hw, B3_RI_RTO_XS2, SK_RI_TO_53);
3623
3624 skge_write32(hw, B0_HWE_IMSK, IS_ERR_MSK);
3625
3626 /* Set interrupt moderation for Transmit only
3627 * Receive interrupts avoided by NAPI
3628 */
3629 skge_write32(hw, B2_IRQM_MSK, IS_XA1_F|IS_XA2_F);
3630 skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, 100));
3631 skge_write32(hw, B2_IRQM_CTRL, TIM_START);
3632
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003633 skge_write32(hw, B0_IMSK, hw->intr_mask);
3634
Stephen Hemminger981d0372005-06-27 11:33:06 -07003635 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003636 if (hw->chip_id == CHIP_ID_GENESIS)
3637 genesis_reset(hw, i);
3638 else
3639 yukon_reset(hw, i);
3640 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003641
3642 return 0;
3643}
3644
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003645
3646#ifdef CONFIG_SKGE_DEBUG
3647
3648static struct dentry *skge_debug;
3649
3650static int skge_debug_show(struct seq_file *seq, void *v)
3651{
3652 struct net_device *dev = seq->private;
3653 const struct skge_port *skge = netdev_priv(dev);
3654 const struct skge_hw *hw = skge->hw;
3655 const struct skge_element *e;
3656
3657 if (!netif_running(dev))
3658 return -ENETDOWN;
3659
3660 seq_printf(seq, "IRQ src=%x mask=%x\n", skge_read32(hw, B0_ISRC),
3661 skge_read32(hw, B0_IMSK));
3662
3663 seq_printf(seq, "Tx Ring: (%d)\n", skge_avail(&skge->tx_ring));
3664 for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) {
3665 const struct skge_tx_desc *t = e->desc;
3666 seq_printf(seq, "%#x dma=%#x%08x %#x csum=%#x/%x/%x\n",
3667 t->control, t->dma_hi, t->dma_lo, t->status,
3668 t->csum_offs, t->csum_write, t->csum_start);
3669 }
3670
3671 seq_printf(seq, "\nRx Ring: \n");
3672 for (e = skge->rx_ring.to_clean; ; e = e->next) {
3673 const struct skge_rx_desc *r = e->desc;
3674
3675 if (r->control & BMU_OWN)
3676 break;
3677
3678 seq_printf(seq, "%#x dma=%#x%08x %#x %#x csum=%#x/%x\n",
3679 r->control, r->dma_hi, r->dma_lo, r->status,
3680 r->timestamp, r->csum1, r->csum1_start);
3681 }
3682
3683 return 0;
3684}
3685
3686static int skge_debug_open(struct inode *inode, struct file *file)
3687{
3688 return single_open(file, skge_debug_show, inode->i_private);
3689}
3690
3691static const struct file_operations skge_debug_fops = {
3692 .owner = THIS_MODULE,
3693 .open = skge_debug_open,
3694 .read = seq_read,
3695 .llseek = seq_lseek,
3696 .release = single_release,
3697};
3698
3699/*
3700 * Use network device events to create/remove/rename
3701 * debugfs file entries
3702 */
3703static int skge_device_event(struct notifier_block *unused,
3704 unsigned long event, void *ptr)
3705{
3706 struct net_device *dev = ptr;
3707 struct skge_port *skge;
3708 struct dentry *d;
3709
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003710 if (dev->netdev_ops->ndo_open != &skge_up || !skge_debug)
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003711 goto done;
3712
3713 skge = netdev_priv(dev);
Joe Perches67777f92010-02-17 15:01:58 +00003714 switch (event) {
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003715 case NETDEV_CHANGENAME:
3716 if (skge->debugfs) {
3717 d = debugfs_rename(skge_debug, skge->debugfs,
3718 skge_debug, dev->name);
3719 if (d)
3720 skge->debugfs = d;
3721 else {
Joe Perchesf15063c2010-02-17 15:01:57 +00003722 netdev_info(dev, "rename failed\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003723 debugfs_remove(skge->debugfs);
3724 }
3725 }
3726 break;
3727
3728 case NETDEV_GOING_DOWN:
3729 if (skge->debugfs) {
3730 debugfs_remove(skge->debugfs);
3731 skge->debugfs = NULL;
3732 }
3733 break;
3734
3735 case NETDEV_UP:
3736 d = debugfs_create_file(dev->name, S_IRUGO,
3737 skge_debug, dev,
3738 &skge_debug_fops);
3739 if (!d || IS_ERR(d))
Joe Perchesf15063c2010-02-17 15:01:57 +00003740 netdev_info(dev, "debugfs create failed\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003741 else
3742 skge->debugfs = d;
3743 break;
3744 }
3745
3746done:
3747 return NOTIFY_DONE;
3748}
3749
3750static struct notifier_block skge_notifier = {
3751 .notifier_call = skge_device_event,
3752};
3753
3754
3755static __init void skge_debug_init(void)
3756{
3757 struct dentry *ent;
3758
3759 ent = debugfs_create_dir("skge", NULL);
3760 if (!ent || IS_ERR(ent)) {
Joe Perchesf15063c2010-02-17 15:01:57 +00003761 pr_info("debugfs create directory failed\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003762 return;
3763 }
3764
3765 skge_debug = ent;
3766 register_netdevice_notifier(&skge_notifier);
3767}
3768
3769static __exit void skge_debug_cleanup(void)
3770{
3771 if (skge_debug) {
3772 unregister_netdevice_notifier(&skge_notifier);
3773 debugfs_remove(skge_debug);
3774 skge_debug = NULL;
3775 }
3776}
3777
3778#else
3779#define skge_debug_init()
3780#define skge_debug_cleanup()
3781#endif
3782
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003783static const struct net_device_ops skge_netdev_ops = {
3784 .ndo_open = skge_up,
3785 .ndo_stop = skge_down,
Stephen Hemminger00829822008-11-20 20:14:53 -08003786 .ndo_start_xmit = skge_xmit_frame,
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003787 .ndo_do_ioctl = skge_ioctl,
3788 .ndo_get_stats = skge_get_stats,
3789 .ndo_tx_timeout = skge_tx_timeout,
3790 .ndo_change_mtu = skge_change_mtu,
3791 .ndo_validate_addr = eth_validate_addr,
3792 .ndo_set_multicast_list = skge_set_multicast,
3793 .ndo_set_mac_address = skge_set_mac_address,
3794#ifdef CONFIG_NET_POLL_CONTROLLER
3795 .ndo_poll_controller = skge_netpoll,
3796#endif
3797};
3798
3799
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003800/* Initialize network device */
Stephen Hemminger981d0372005-06-27 11:33:06 -07003801static struct net_device *skge_devinit(struct skge_hw *hw, int port,
3802 int highmem)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003803{
3804 struct skge_port *skge;
3805 struct net_device *dev = alloc_etherdev(sizeof(*skge));
3806
3807 if (!dev) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003808 dev_err(&hw->pdev->dev, "etherdev alloc failed\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003809 return NULL;
3810 }
3811
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003812 SET_NETDEV_DEV(dev, &hw->pdev->dev);
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003813 dev->netdev_ops = &skge_netdev_ops;
3814 dev->ethtool_ops = &skge_ethtool_ops;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003815 dev->watchdog_timeo = TX_WATCHDOG;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003816 dev->irq = hw->pdev->irq;
Stephen Hemminger513f5332006-09-01 15:53:49 -07003817
Stephen Hemminger981d0372005-06-27 11:33:06 -07003818 if (highmem)
3819 dev->features |= NETIF_F_HIGHDMA;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003820
3821 skge = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003822 netif_napi_add(dev, &skge->napi, skge_poll, NAPI_WEIGHT);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003823 skge->netdev = dev;
3824 skge->hw = hw;
3825 skge->msg_enable = netif_msg_init(debug, default_msg);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003826
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003827 skge->tx_ring.count = DEFAULT_TX_RING_SIZE;
3828 skge->rx_ring.count = DEFAULT_RX_RING_SIZE;
3829
3830 /* Auto speed and flow control */
3831 skge->autoneg = AUTONEG_ENABLE;
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07003832 skge->flow_control = FLOW_MODE_SYM_OR_REM;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003833 skge->duplex = -1;
3834 skge->speed = -1;
Stephen Hemminger31b619c2005-06-27 11:33:11 -07003835 skge->advertising = skge_supported_modes(hw);
Stephen Hemminger5b982c52007-05-08 13:36:20 -07003836
Rafael J. Wysocki7b55a4a2009-07-22 02:58:55 +00003837 if (device_can_wakeup(&hw->pdev->dev)) {
Stephen Hemminger5b982c52007-05-08 13:36:20 -07003838 skge->wol = wol_supported(hw) & WAKE_MAGIC;
Rafael J. Wysocki7b55a4a2009-07-22 02:58:55 +00003839 device_set_wakeup_enable(&hw->pdev->dev, skge->wol);
3840 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003841
3842 hw->dev[port] = dev;
3843
3844 skge->port = port;
3845
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003846 /* Only used for Genesis XMAC */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003847 setup_timer(&skge->link_timer, xm_link_timer, (unsigned long) skge);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003848
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003849 if (hw->chip_id != CHIP_ID_GENESIS) {
3850 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
3851 skge->rx_csum = 1;
3852 }
3853
3854 /* read the mac address */
3855 memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port*8, ETH_ALEN);
John W. Linville56230d52005-09-12 10:48:57 -04003856 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003857
3858 /* device is off until link detection */
3859 netif_carrier_off(dev);
3860 netif_stop_queue(dev);
3861
3862 return dev;
3863}
3864
3865static void __devinit skge_show_addr(struct net_device *dev)
3866{
3867 const struct skge_port *skge = netdev_priv(dev);
3868
Joe Perchesd7072042010-02-09 11:49:53 +00003869 netif_info(skge, probe, skge->netdev, "addr %pM\n", dev->dev_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003870}
3871
3872static int __devinit skge_probe(struct pci_dev *pdev,
3873 const struct pci_device_id *ent)
3874{
3875 struct net_device *dev, *dev1;
3876 struct skge_hw *hw;
3877 int err, using_dac = 0;
3878
Stephen Hemminger203babb2006-03-21 10:57:05 -08003879 err = pci_enable_device(pdev);
3880 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003881 dev_err(&pdev->dev, "cannot enable PCI device\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003882 goto err_out;
3883 }
3884
Stephen Hemminger203babb2006-03-21 10:57:05 -08003885 err = pci_request_regions(pdev, DRV_NAME);
3886 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003887 dev_err(&pdev->dev, "cannot obtain PCI resources\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003888 goto err_out_disable_pdev;
3889 }
3890
3891 pci_set_master(pdev);
3892
Yang Hongyang6a355282009-04-06 19:01:13 -07003893 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003894 using_dac = 1;
Yang Hongyang6a355282009-04-06 19:01:13 -07003895 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
Yang Hongyang284901a2009-04-06 19:01:15 -07003896 } else if (!(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))) {
Stephen Hemminger93aea712006-03-21 10:57:02 -08003897 using_dac = 0;
Yang Hongyang284901a2009-04-06 19:01:15 -07003898 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Stephen Hemminger93aea712006-03-21 10:57:02 -08003899 }
3900
3901 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003902 dev_err(&pdev->dev, "no usable DMA configuration\n");
Stephen Hemminger93aea712006-03-21 10:57:02 -08003903 goto err_out_free_regions;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003904 }
3905
3906#ifdef __BIG_ENDIAN
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08003907 /* byte swap descriptors in hardware */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003908 {
3909 u32 reg;
3910
3911 pci_read_config_dword(pdev, PCI_DEV_REG2, &reg);
3912 reg |= PCI_REV_DESC;
3913 pci_write_config_dword(pdev, PCI_DEV_REG2, reg);
3914 }
3915#endif
3916
3917 err = -ENOMEM;
Michal Schmidt415e69e2009-10-01 08:13:23 +00003918 /* space for skge@pci:0000:04:00.0 */
Joe Perches67777f92010-02-17 15:01:58 +00003919 hw = kzalloc(sizeof(*hw) + strlen(DRV_NAME "@pci:")
Michal Schmidt415e69e2009-10-01 08:13:23 +00003920 + strlen(pci_name(pdev)) + 1, GFP_KERNEL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003921 if (!hw) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003922 dev_err(&pdev->dev, "cannot allocate hardware struct\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003923 goto err_out_free_regions;
3924 }
Michal Schmidt415e69e2009-10-01 08:13:23 +00003925 sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003926
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003927 hw->pdev = pdev;
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07003928 spin_lock_init(&hw->hw_lock);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003929 spin_lock_init(&hw->phy_lock);
Joe Perches164165d2009-11-19 09:30:10 +00003930 tasklet_init(&hw->phy_task, skge_extirq, (unsigned long) hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003931
3932 hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
3933 if (!hw->regs) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003934 dev_err(&pdev->dev, "cannot map device registers\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003935 goto err_out_free_hw;
3936 }
3937
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003938 err = skge_reset(hw);
3939 if (err)
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003940 goto err_out_iounmap;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003941
Joe Perchesf15063c2010-02-17 15:01:57 +00003942 pr_info("%s addr 0x%llx irq %d chip %s rev %d\n",
3943 DRV_VERSION,
3944 (unsigned long long)pci_resource_start(pdev, 0), pdev->irq,
3945 skge_board_name(hw), hw->chip_rev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003946
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003947 dev = skge_devinit(hw, 0, using_dac);
3948 if (!dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003949 goto err_out_led_off;
3950
Stephen Hemmingerfae87592007-02-02 08:22:51 -08003951 /* Some motherboards are broken and has zero in ROM. */
Stephen Hemminger1479d132007-02-02 08:22:52 -08003952 if (!is_valid_ether_addr(dev->dev_addr))
3953 dev_warn(&pdev->dev, "bad (zero?) ethernet address in rom\n");
Stephen Hemminger631ae322006-06-06 10:11:14 -07003954
Stephen Hemminger203babb2006-03-21 10:57:05 -08003955 err = register_netdev(dev);
3956 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003957 dev_err(&pdev->dev, "cannot register net device\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003958 goto err_out_free_netdev;
3959 }
3960
Michal Schmidt415e69e2009-10-01 08:13:23 +00003961 err = request_irq(pdev->irq, skge_intr, IRQF_SHARED, hw->irq_name, hw);
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003962 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003963 dev_err(&pdev->dev, "%s: cannot assign irq %d\n",
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003964 dev->name, pdev->irq);
3965 goto err_out_unregister;
3966 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003967 skge_show_addr(dev);
3968
Mike McCormackf1914222009-09-23 03:50:36 +00003969 if (hw->ports > 1) {
3970 dev1 = skge_devinit(hw, 1, using_dac);
3971 if (dev1 && register_netdev(dev1) == 0)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003972 skge_show_addr(dev1);
3973 else {
3974 /* Failure to register second port need not be fatal */
Stephen Hemminger1479d132007-02-02 08:22:52 -08003975 dev_warn(&pdev->dev, "register of second port failed\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003976 hw->dev[1] = NULL;
Mike McCormackf1914222009-09-23 03:50:36 +00003977 hw->ports = 1;
3978 if (dev1)
3979 free_netdev(dev1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003980 }
3981 }
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003982 pci_set_drvdata(pdev, hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003983
3984 return 0;
3985
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003986err_out_unregister:
3987 unregister_netdev(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003988err_out_free_netdev:
3989 free_netdev(dev);
3990err_out_led_off:
3991 skge_write16(hw, B0_LED, LED_STAT_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003992err_out_iounmap:
3993 iounmap(hw->regs);
3994err_out_free_hw:
3995 kfree(hw);
3996err_out_free_regions:
3997 pci_release_regions(pdev);
3998err_out_disable_pdev:
3999 pci_disable_device(pdev);
4000 pci_set_drvdata(pdev, NULL);
4001err_out:
4002 return err;
4003}
4004
4005static void __devexit skge_remove(struct pci_dev *pdev)
4006{
4007 struct skge_hw *hw = pci_get_drvdata(pdev);
4008 struct net_device *dev0, *dev1;
4009
Stephen Hemminger95566062005-06-27 11:33:02 -07004010 if (!hw)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004011 return;
4012
Stephen Hemminger208491d82007-02-16 15:37:39 -08004013 flush_scheduled_work();
4014
Joe Perches67777f92010-02-17 15:01:58 +00004015 dev1 = hw->dev[1];
4016 if (dev1)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004017 unregister_netdev(dev1);
4018 dev0 = hw->dev[0];
4019 unregister_netdev(dev0);
4020
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07004021 tasklet_disable(&hw->phy_task);
4022
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07004023 spin_lock_irq(&hw->hw_lock);
4024 hw->intr_mask = 0;
Stephen Hemminger46a60f22005-09-09 12:54:56 -07004025 skge_write32(hw, B0_IMSK, 0);
Stephen Hemminger78bc2182006-08-28 16:19:36 -07004026 skge_read32(hw, B0_IMSK);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07004027 spin_unlock_irq(&hw->hw_lock);
4028
Stephen Hemminger46a60f22005-09-09 12:54:56 -07004029 skge_write16(hw, B0_LED, LED_STAT_OFF);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07004030 skge_write8(hw, B0_CTST, CS_RST_SET);
4031
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004032 free_irq(pdev->irq, hw);
4033 pci_release_regions(pdev);
4034 pci_disable_device(pdev);
4035 if (dev1)
4036 free_netdev(dev1);
4037 free_netdev(dev0);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07004038
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004039 iounmap(hw->regs);
4040 kfree(hw);
4041 pci_set_drvdata(pdev, NULL);
4042}
4043
4044#ifdef CONFIG_PM
Pavel Machek2a569572005-07-07 17:56:40 -07004045static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004046{
4047 struct skge_hw *hw = pci_get_drvdata(pdev);
Stephen Hemmingera504e642007-02-02 08:22:53 -08004048 int i, err, wol = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004049
Stephen Hemmingere3b7df12007-05-11 11:21:45 -07004050 if (!hw)
4051 return 0;
4052
Stephen Hemmingera504e642007-02-02 08:22:53 -08004053 err = pci_save_state(pdev);
4054 if (err)
4055 return err;
4056
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004057 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004058 struct net_device *dev = hw->dev[i];
Stephen Hemmingera504e642007-02-02 08:22:53 -08004059 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004060
Stephen Hemmingera504e642007-02-02 08:22:53 -08004061 if (netif_running(dev))
4062 skge_down(dev);
4063 if (skge->wol)
4064 skge_wol_init(skge);
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004065
Stephen Hemmingera504e642007-02-02 08:22:53 -08004066 wol |= skge->wol;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004067 }
4068
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004069 skge_write32(hw, B0_IMSK, 0);
Rafael J. Wysocki5177b322008-10-29 14:22:14 -07004070
4071 pci_prepare_to_sleep(pdev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004072
4073 return 0;
4074}
4075
4076static int skge_resume(struct pci_dev *pdev)
4077{
4078 struct skge_hw *hw = pci_get_drvdata(pdev);
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004079 int i, err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004080
Stephen Hemmingere3b7df12007-05-11 11:21:45 -07004081 if (!hw)
4082 return 0;
4083
Rafael J. Wysocki5177b322008-10-29 14:22:14 -07004084 err = pci_back_from_sleep(pdev);
Stephen Hemmingera504e642007-02-02 08:22:53 -08004085 if (err)
4086 goto out;
4087
4088 err = pci_restore_state(pdev);
4089 if (err)
4090 goto out;
4091
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004092 err = skge_reset(hw);
4093 if (err)
4094 goto out;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004095
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004096 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004097 struct net_device *dev = hw->dev[i];
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004098
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004099 if (netif_running(dev)) {
4100 err = skge_up(dev);
4101
4102 if (err) {
Joe Perchesf15063c2010-02-17 15:01:57 +00004103 netdev_err(dev, "could not up: %d\n", err);
Stephen Hemmingeredd702e2005-12-15 12:18:00 -08004104 dev_close(dev);
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004105 goto out;
4106 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004107 }
4108 }
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004109out:
4110 return err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004111}
4112#endif
4113
Stephen Hemminger692412b2007-04-09 15:32:45 -07004114static void skge_shutdown(struct pci_dev *pdev)
4115{
4116 struct skge_hw *hw = pci_get_drvdata(pdev);
4117 int i, wol = 0;
4118
Stephen Hemmingere3b7df12007-05-11 11:21:45 -07004119 if (!hw)
4120 return;
4121
Stephen Hemminger692412b2007-04-09 15:32:45 -07004122 for (i = 0; i < hw->ports; i++) {
4123 struct net_device *dev = hw->dev[i];
4124 struct skge_port *skge = netdev_priv(dev);
4125
4126 if (skge->wol)
4127 skge_wol_init(skge);
4128 wol |= skge->wol;
4129 }
4130
Rafael J. Wysocki5177b322008-10-29 14:22:14 -07004131 if (pci_enable_wake(pdev, PCI_D3cold, wol))
4132 pci_enable_wake(pdev, PCI_D3hot, wol);
Stephen Hemminger692412b2007-04-09 15:32:45 -07004133
4134 pci_disable_device(pdev);
4135 pci_set_power_state(pdev, PCI_D3hot);
4136
4137}
4138
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004139static struct pci_driver skge_driver = {
4140 .name = DRV_NAME,
4141 .id_table = skge_id_table,
4142 .probe = skge_probe,
4143 .remove = __devexit_p(skge_remove),
4144#ifdef CONFIG_PM
4145 .suspend = skge_suspend,
4146 .resume = skge_resume,
4147#endif
Stephen Hemminger692412b2007-04-09 15:32:45 -07004148 .shutdown = skge_shutdown,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004149};
4150
4151static int __init skge_init_module(void)
4152{
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07004153 skge_debug_init();
Jeff Garzik29917622006-08-19 17:48:59 -04004154 return pci_register_driver(&skge_driver);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004155}
4156
4157static void __exit skge_cleanup_module(void)
4158{
4159 pci_unregister_driver(&skge_driver);
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07004160 skge_debug_cleanup();
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004161}
4162
4163module_init(skge_init_module);
4164module_exit(skge_cleanup_module);