blob: 8aa24c52f319dbd1550002233609b1796ef5fbf5 [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
74static const u32 default_msg
75 = NETIF_MSG_DRV| NETIF_MSG_PROBE| NETIF_MSG_LINK
76 | NETIF_MSG_IFUP| NETIF_MSG_IFDOWN;
77
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,
191 PHY_AN_100FULL | PHY_AN_100HALF |
192 PHY_AN_10FULL | PHY_AN_10HALF| PHY_AN_CSMA);
193 /* 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) {
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700261 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| SUPPORTED_TP;
268
269 if (hw->chip_id == CHIP_ID_GENESIS)
270 supported &= ~(SUPPORTED_10baseT_Half
271 | SUPPORTED_10baseT_Full
272 | SUPPORTED_100baseT_Half
273 | SUPPORTED_100baseT_Full);
274
275 else if (hw->chip_id == CHIP_ID_YUKON)
276 supported &= ~SUPPORTED_1000baseT_Half;
277 } else
Stephen Hemminger4b67be92006-10-05 15:49:51 -0700278 supported = SUPPORTED_1000baseT_Full | SUPPORTED_1000baseT_Half
279 | SUPPORTED_FIBRE | SUPPORTED_Autoneg;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700280
281 return supported;
282}
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400283
284static int skge_get_settings(struct net_device *dev,
285 struct ethtool_cmd *ecmd)
286{
287 struct skge_port *skge = netdev_priv(dev);
288 struct skge_hw *hw = skge->hw;
289
290 ecmd->transceiver = XCVR_INTERNAL;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700291 ecmd->supported = skge_supported_modes(hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400292
Stephen Hemminger5e1705d2005-08-16 14:00:58 -0700293 if (hw->copper) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400294 ecmd->port = PORT_TP;
295 ecmd->phy_address = hw->phy_addr;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700296 } else
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400297 ecmd->port = PORT_FIBRE;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400298
299 ecmd->advertising = skge->advertising;
300 ecmd->autoneg = skge->autoneg;
301 ecmd->speed = skge->speed;
302 ecmd->duplex = skge->duplex;
303 return 0;
304}
305
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400306static int skge_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
307{
308 struct skge_port *skge = netdev_priv(dev);
309 const struct skge_hw *hw = skge->hw;
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700310 u32 supported = skge_supported_modes(hw);
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000311 int err = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400312
313 if (ecmd->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700314 ecmd->advertising = supported;
315 skge->duplex = -1;
316 skge->speed = -1;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400317 } else {
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700318 u32 setting;
319
Stephen Hemminger2c668512005-07-22 16:26:07 -0700320 switch (ecmd->speed) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400321 case SPEED_1000:
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700322 if (ecmd->duplex == DUPLEX_FULL)
323 setting = SUPPORTED_1000baseT_Full;
324 else if (ecmd->duplex == DUPLEX_HALF)
325 setting = SUPPORTED_1000baseT_Half;
326 else
327 return -EINVAL;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400328 break;
329 case SPEED_100:
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700330 if (ecmd->duplex == DUPLEX_FULL)
331 setting = SUPPORTED_100baseT_Full;
332 else if (ecmd->duplex == DUPLEX_HALF)
333 setting = SUPPORTED_100baseT_Half;
334 else
335 return -EINVAL;
336 break;
337
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400338 case SPEED_10:
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700339 if (ecmd->duplex == DUPLEX_FULL)
340 setting = SUPPORTED_10baseT_Full;
341 else if (ecmd->duplex == DUPLEX_HALF)
342 setting = SUPPORTED_10baseT_Half;
343 else
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400344 return -EINVAL;
345 break;
346 default:
347 return -EINVAL;
348 }
Stephen Hemminger31b619c2005-06-27 11:33:11 -0700349
350 if ((setting & supported) == 0)
351 return -EINVAL;
352
353 skge->speed = ecmd->speed;
354 skge->duplex = ecmd->duplex;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400355 }
356
357 skge->autoneg = ecmd->autoneg;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400358 skge->advertising = ecmd->advertising;
359
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000360 if (netif_running(dev)) {
361 skge_down(dev);
362 err = skge_up(dev);
363 if (err) {
364 dev_close(dev);
365 return err;
366 }
367 }
Stephen Hemmingeree294dc2005-12-14 15:47:44 -0800368
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400369 return (0);
370}
371
372static void skge_get_drvinfo(struct net_device *dev,
373 struct ethtool_drvinfo *info)
374{
375 struct skge_port *skge = netdev_priv(dev);
376
377 strcpy(info->driver, DRV_NAME);
378 strcpy(info->version, DRV_VERSION);
379 strcpy(info->fw_version, "N/A");
380 strcpy(info->bus_info, pci_name(skge->hw->pdev));
381}
382
383static const struct skge_stat {
384 char name[ETH_GSTRING_LEN];
385 u16 xmac_offset;
386 u16 gma_offset;
387} skge_stats[] = {
388 { "tx_bytes", XM_TXO_OK_HI, GM_TXO_OK_HI },
389 { "rx_bytes", XM_RXO_OK_HI, GM_RXO_OK_HI },
390
391 { "tx_broadcast", XM_TXF_BC_OK, GM_TXF_BC_OK },
392 { "rx_broadcast", XM_RXF_BC_OK, GM_RXF_BC_OK },
393 { "tx_multicast", XM_TXF_MC_OK, GM_TXF_MC_OK },
394 { "rx_multicast", XM_RXF_MC_OK, GM_RXF_MC_OK },
395 { "tx_unicast", XM_TXF_UC_OK, GM_TXF_UC_OK },
396 { "rx_unicast", XM_RXF_UC_OK, GM_RXF_UC_OK },
397 { "tx_mac_pause", XM_TXF_MPAUSE, GM_TXF_MPAUSE },
398 { "rx_mac_pause", XM_RXF_MPAUSE, GM_RXF_MPAUSE },
399
400 { "collisions", XM_TXF_SNG_COL, GM_TXF_SNG_COL },
401 { "multi_collisions", XM_TXF_MUL_COL, GM_TXF_MUL_COL },
402 { "aborted", XM_TXF_ABO_COL, GM_TXF_ABO_COL },
403 { "late_collision", XM_TXF_LAT_COL, GM_TXF_LAT_COL },
404 { "fifo_underrun", XM_TXE_FIFO_UR, GM_TXE_FIFO_UR },
405 { "fifo_overflow", XM_RXE_FIFO_OV, GM_RXE_FIFO_OV },
406
407 { "rx_toolong", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR },
408 { "rx_jabber", XM_RXF_JAB_PKT, GM_RXF_JAB_PKT },
409 { "rx_runt", XM_RXE_RUNT, GM_RXE_FRAG },
410 { "rx_too_long", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR },
411 { "rx_fcs_error", XM_RXF_FCS_ERR, GM_RXF_FCS_ERR },
412};
413
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700414static int skge_get_sset_count(struct net_device *dev, int sset)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400415{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700416 switch (sset) {
417 case ETH_SS_STATS:
418 return ARRAY_SIZE(skge_stats);
419 default:
420 return -EOPNOTSUPP;
421 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400422}
423
424static void skge_get_ethtool_stats(struct net_device *dev,
425 struct ethtool_stats *stats, u64 *data)
426{
427 struct skge_port *skge = netdev_priv(dev);
428
429 if (skge->hw->chip_id == CHIP_ID_GENESIS)
430 genesis_get_stats(skge, data);
431 else
432 yukon_get_stats(skge, data);
433}
434
435/* Use hardware MIB variables for critical path statistics and
436 * transmit feedback not reported at interrupt.
437 * Other errors are accounted for in interrupt handler.
438 */
439static struct net_device_stats *skge_get_stats(struct net_device *dev)
440{
441 struct skge_port *skge = netdev_priv(dev);
442 u64 data[ARRAY_SIZE(skge_stats)];
443
444 if (skge->hw->chip_id == CHIP_ID_GENESIS)
445 genesis_get_stats(skge, data);
446 else
447 yukon_get_stats(skge, data);
448
Stephen Hemmingerda007722007-10-16 12:15:52 -0700449 dev->stats.tx_bytes = data[0];
450 dev->stats.rx_bytes = data[1];
451 dev->stats.tx_packets = data[2] + data[4] + data[6];
452 dev->stats.rx_packets = data[3] + data[5] + data[7];
453 dev->stats.multicast = data[3] + data[5];
454 dev->stats.collisions = data[10];
455 dev->stats.tx_aborted_errors = data[12];
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400456
Stephen Hemmingerda007722007-10-16 12:15:52 -0700457 return &dev->stats;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400458}
459
460static void skge_get_strings(struct net_device *dev, u32 stringset, u8 *data)
461{
462 int i;
463
Stephen Hemminger95566062005-06-27 11:33:02 -0700464 switch (stringset) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400465 case ETH_SS_STATS:
466 for (i = 0; i < ARRAY_SIZE(skge_stats); i++)
467 memcpy(data + i * ETH_GSTRING_LEN,
468 skge_stats[i].name, ETH_GSTRING_LEN);
469 break;
470 }
471}
472
473static void skge_get_ring_param(struct net_device *dev,
474 struct ethtool_ringparam *p)
475{
476 struct skge_port *skge = netdev_priv(dev);
477
478 p->rx_max_pending = MAX_RX_RING_SIZE;
479 p->tx_max_pending = MAX_TX_RING_SIZE;
480 p->rx_mini_max_pending = 0;
481 p->rx_jumbo_max_pending = 0;
482
483 p->rx_pending = skge->rx_ring.count;
484 p->tx_pending = skge->tx_ring.count;
485 p->rx_mini_pending = 0;
486 p->rx_jumbo_pending = 0;
487}
488
489static int skge_set_ring_param(struct net_device *dev,
490 struct ethtool_ringparam *p)
491{
492 struct skge_port *skge = netdev_priv(dev);
Wang Chene824b3e2008-09-26 16:20:32 +0800493 int err = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400494
495 if (p->rx_pending == 0 || p->rx_pending > MAX_RX_RING_SIZE ||
Stephen Hemminger9db96472006-06-06 10:11:12 -0700496 p->tx_pending < TX_LOW_WATER || p->tx_pending > MAX_TX_RING_SIZE)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400497 return -EINVAL;
498
499 skge->rx_ring.count = p->rx_pending;
500 skge->tx_ring.count = p->tx_pending;
501
502 if (netif_running(dev)) {
503 skge_down(dev);
Stephen Hemminger3b8bb472005-12-14 15:47:48 -0800504 err = skge_up(dev);
505 if (err)
506 dev_close(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400507 }
508
Wang Chene824b3e2008-09-26 16:20:32 +0800509 return err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400510}
511
512static u32 skge_get_msglevel(struct net_device *netdev)
513{
514 struct skge_port *skge = netdev_priv(netdev);
515 return skge->msg_enable;
516}
517
518static void skge_set_msglevel(struct net_device *netdev, u32 value)
519{
520 struct skge_port *skge = netdev_priv(netdev);
521 skge->msg_enable = value;
522}
523
524static int skge_nway_reset(struct net_device *dev)
525{
526 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400527
528 if (skge->autoneg != AUTONEG_ENABLE || !netif_running(dev))
529 return -EINVAL;
530
Stephen Hemmingeree294dc2005-12-14 15:47:44 -0800531 skge_phy_reset(skge);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400532 return 0;
533}
534
535static int skge_set_sg(struct net_device *dev, u32 data)
536{
537 struct skge_port *skge = netdev_priv(dev);
538 struct skge_hw *hw = skge->hw;
539
540 if (hw->chip_id == CHIP_ID_GENESIS && data)
541 return -EOPNOTSUPP;
542 return ethtool_op_set_sg(dev, data);
543}
544
545static int skge_set_tx_csum(struct net_device *dev, u32 data)
546{
547 struct skge_port *skge = netdev_priv(dev);
548 struct skge_hw *hw = skge->hw;
549
550 if (hw->chip_id == CHIP_ID_GENESIS && data)
551 return -EOPNOTSUPP;
552
553 return ethtool_op_set_tx_csum(dev, data);
554}
555
556static u32 skge_get_rx_csum(struct net_device *dev)
557{
558 struct skge_port *skge = netdev_priv(dev);
559
560 return skge->rx_csum;
561}
562
563/* Only Yukon supports checksum offload. */
564static int skge_set_rx_csum(struct net_device *dev, u32 data)
565{
566 struct skge_port *skge = netdev_priv(dev);
567
568 if (skge->hw->chip_id == CHIP_ID_GENESIS && data)
569 return -EOPNOTSUPP;
570
571 skge->rx_csum = data;
572 return 0;
573}
574
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400575static void skge_get_pauseparam(struct net_device *dev,
576 struct ethtool_pauseparam *ecmd)
577{
578 struct skge_port *skge = netdev_priv(dev);
579
Joe Perches8e95a202009-12-03 07:58:21 +0000580 ecmd->rx_pause = ((skge->flow_control == FLOW_MODE_SYMMETRIC) ||
581 (skge->flow_control == FLOW_MODE_SYM_OR_REM));
582 ecmd->tx_pause = (ecmd->rx_pause ||
583 (skge->flow_control == FLOW_MODE_LOC_SEND));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400584
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700585 ecmd->autoneg = ecmd->rx_pause || ecmd->tx_pause;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400586}
587
588static int skge_set_pauseparam(struct net_device *dev,
589 struct ethtool_pauseparam *ecmd)
590{
591 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700592 struct ethtool_pauseparam old;
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000593 int err = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400594
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700595 skge_get_pauseparam(dev, &old);
596
597 if (ecmd->autoneg != old.autoneg)
598 skge->flow_control = ecmd->autoneg ? FLOW_MODE_NONE : FLOW_MODE_SYMMETRIC;
599 else {
600 if (ecmd->rx_pause && ecmd->tx_pause)
601 skge->flow_control = FLOW_MODE_SYMMETRIC;
602 else if (ecmd->rx_pause && !ecmd->tx_pause)
603 skge->flow_control = FLOW_MODE_SYM_OR_REM;
604 else if (!ecmd->rx_pause && ecmd->tx_pause)
605 skge->flow_control = FLOW_MODE_LOC_SEND;
606 else
607 skge->flow_control = FLOW_MODE_NONE;
608 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400609
Xiaoming.Zhang9ac13532008-09-25 20:28:05 +0000610 if (netif_running(dev)) {
611 skge_down(dev);
612 err = skge_up(dev);
613 if (err) {
614 dev_close(dev);
615 return err;
616 }
617 }
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -0700618
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400619 return 0;
620}
621
622/* Chip internal frequency for clock calculations */
623static inline u32 hwkhz(const struct skge_hw *hw)
624{
Stephen Hemminger187ff3b2006-07-19 14:08:42 -0700625 return (hw->chip_id == CHIP_ID_GENESIS) ? 53125 : 78125;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400626}
627
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800628/* Chip HZ to microseconds */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400629static inline u32 skge_clk2usec(const struct skge_hw *hw, u32 ticks)
630{
631 return (ticks * 1000) / hwkhz(hw);
632}
633
Stephen Hemminger8f3f8192005-11-08 10:33:45 -0800634/* Microseconds to chip HZ */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400635static inline u32 skge_usecs2clk(const struct skge_hw *hw, u32 usec)
636{
637 return hwkhz(hw) * usec / 1000;
638}
639
640static int skge_get_coalesce(struct net_device *dev,
641 struct ethtool_coalesce *ecmd)
642{
643 struct skge_port *skge = netdev_priv(dev);
644 struct skge_hw *hw = skge->hw;
645 int port = skge->port;
646
647 ecmd->rx_coalesce_usecs = 0;
648 ecmd->tx_coalesce_usecs = 0;
649
650 if (skge_read32(hw, B2_IRQM_CTRL) & TIM_START) {
651 u32 delay = skge_clk2usec(hw, skge_read32(hw, B2_IRQM_INI));
652 u32 msk = skge_read32(hw, B2_IRQM_MSK);
653
654 if (msk & rxirqmask[port])
655 ecmd->rx_coalesce_usecs = delay;
656 if (msk & txirqmask[port])
657 ecmd->tx_coalesce_usecs = delay;
658 }
659
660 return 0;
661}
662
663/* Note: interrupt timer is per board, but can turn on/off per port */
664static int skge_set_coalesce(struct net_device *dev,
665 struct ethtool_coalesce *ecmd)
666{
667 struct skge_port *skge = netdev_priv(dev);
668 struct skge_hw *hw = skge->hw;
669 int port = skge->port;
670 u32 msk = skge_read32(hw, B2_IRQM_MSK);
671 u32 delay = 25;
672
673 if (ecmd->rx_coalesce_usecs == 0)
674 msk &= ~rxirqmask[port];
675 else if (ecmd->rx_coalesce_usecs < 25 ||
676 ecmd->rx_coalesce_usecs > 33333)
677 return -EINVAL;
678 else {
679 msk |= rxirqmask[port];
680 delay = ecmd->rx_coalesce_usecs;
681 }
682
683 if (ecmd->tx_coalesce_usecs == 0)
684 msk &= ~txirqmask[port];
685 else if (ecmd->tx_coalesce_usecs < 25 ||
686 ecmd->tx_coalesce_usecs > 33333)
687 return -EINVAL;
688 else {
689 msk |= txirqmask[port];
690 delay = min(delay, ecmd->rx_coalesce_usecs);
691 }
692
693 skge_write32(hw, B2_IRQM_MSK, msk);
694 if (msk == 0)
695 skge_write32(hw, B2_IRQM_CTRL, TIM_STOP);
696 else {
697 skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, delay));
698 skge_write32(hw, B2_IRQM_CTRL, TIM_START);
699 }
700 return 0;
701}
702
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700703enum led_mode { LED_MODE_OFF, LED_MODE_ON, LED_MODE_TST };
704static void skge_led(struct skge_port *skge, enum led_mode mode)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400705{
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400706 struct skge_hw *hw = skge->hw;
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700707 int port = skge->port;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400708
Stephen Hemminger9cbe3302007-03-16 14:01:28 -0700709 spin_lock_bh(&hw->phy_lock);
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700710 if (hw->chip_id == CHIP_ID_GENESIS) {
711 switch (mode) {
712 case LED_MODE_OFF:
Stephen Hemminger64f6b642006-09-23 21:25:28 -0700713 if (hw->phy_type == SK_PHY_BCOM)
714 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF);
715 else {
716 skge_write32(hw, SK_REG(port, TX_LED_VAL), 0);
717 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_T_OFF);
718 }
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700719 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
720 skge_write32(hw, SK_REG(port, RX_LED_VAL), 0);
721 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF);
722 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400723
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700724 case LED_MODE_ON:
725 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON);
726 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON);
727
728 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
729 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
730
731 break;
732
733 case LED_MODE_TST:
734 skge_write8(hw, SK_REG(port, RX_LED_TST), LED_T_ON);
735 skge_write32(hw, SK_REG(port, RX_LED_VAL), 100);
736 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
737
Stephen Hemminger64f6b642006-09-23 21:25:28 -0700738 if (hw->phy_type == SK_PHY_BCOM)
739 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON);
740 else {
741 skge_write8(hw, SK_REG(port, TX_LED_TST), LED_T_ON);
742 skge_write32(hw, SK_REG(port, TX_LED_VAL), 100);
743 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
744 }
745
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700746 }
747 } else {
748 switch (mode) {
749 case LED_MODE_OFF:
750 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
751 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
752 PHY_M_LED_MO_DUP(MO_LED_OFF) |
753 PHY_M_LED_MO_10(MO_LED_OFF) |
754 PHY_M_LED_MO_100(MO_LED_OFF) |
755 PHY_M_LED_MO_1000(MO_LED_OFF) |
756 PHY_M_LED_MO_RX(MO_LED_OFF));
757 break;
758 case LED_MODE_ON:
759 gm_phy_write(hw, port, PHY_MARV_LED_CTRL,
760 PHY_M_LED_PULS_DUR(PULS_170MS) |
761 PHY_M_LED_BLINK_RT(BLINK_84MS) |
762 PHY_M_LEDC_TX_CTRL |
763 PHY_M_LEDC_DP_CTRL);
Stephen Hemminger46a60f22005-09-09 12:54:56 -0700764
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700765 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
766 PHY_M_LED_MO_RX(MO_LED_OFF) |
767 (skge->speed == SPEED_100 ?
768 PHY_M_LED_MO_100(MO_LED_ON) : 0));
769 break;
770 case LED_MODE_TST:
771 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
772 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
773 PHY_M_LED_MO_DUP(MO_LED_ON) |
774 PHY_M_LED_MO_10(MO_LED_ON) |
775 PHY_M_LED_MO_100(MO_LED_ON) |
776 PHY_M_LED_MO_1000(MO_LED_ON) |
777 PHY_M_LED_MO_RX(MO_LED_ON));
778 }
779 }
Stephen Hemminger9cbe3302007-03-16 14:01:28 -0700780 spin_unlock_bh(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400781}
782
783/* blink LED's for finding board */
784static int skge_phys_id(struct net_device *dev, u32 data)
785{
786 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700787 unsigned long ms;
788 enum led_mode mode = LED_MODE_TST;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400789
Stephen Hemminger95566062005-06-27 11:33:02 -0700790 if (!data || data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ))
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700791 ms = jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT / HZ) * 1000;
792 else
793 ms = data * 1000;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400794
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700795 while (ms > 0) {
796 skge_led(skge, mode);
797 mode ^= LED_MODE_TST;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400798
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700799 if (msleep_interruptible(BLINK_MS))
800 break;
801 ms -= BLINK_MS;
802 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400803
Stephen Hemminger6abebb52005-07-22 16:26:10 -0700804 /* back to regular LED state */
805 skge_led(skge, netif_running(dev) ? LED_MODE_ON : LED_MODE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400806
807 return 0;
808}
809
Stephen Hemmingerafa151b2007-10-16 12:15:53 -0700810static int skge_get_eeprom_len(struct net_device *dev)
811{
812 struct skge_port *skge = netdev_priv(dev);
813 u32 reg2;
814
815 pci_read_config_dword(skge->hw->pdev, PCI_DEV_REG2, &reg2);
816 return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
817}
818
819static u32 skge_vpd_read(struct pci_dev *pdev, int cap, u16 offset)
820{
821 u32 val;
822
823 pci_write_config_word(pdev, cap + PCI_VPD_ADDR, offset);
824
825 do {
826 pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
827 } while (!(offset & PCI_VPD_ADDR_F));
828
829 pci_read_config_dword(pdev, cap + PCI_VPD_DATA, &val);
830 return val;
831}
832
833static void skge_vpd_write(struct pci_dev *pdev, int cap, u16 offset, u32 val)
834{
835 pci_write_config_dword(pdev, cap + PCI_VPD_DATA, val);
836 pci_write_config_word(pdev, cap + PCI_VPD_ADDR,
837 offset | PCI_VPD_ADDR_F);
838
839 do {
840 pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
841 } while (offset & PCI_VPD_ADDR_F);
842}
843
844static int skge_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
845 u8 *data)
846{
847 struct skge_port *skge = netdev_priv(dev);
848 struct pci_dev *pdev = skge->hw->pdev;
849 int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD);
850 int length = eeprom->len;
851 u16 offset = eeprom->offset;
852
853 if (!cap)
854 return -EINVAL;
855
856 eeprom->magic = SKGE_EEPROM_MAGIC;
857
858 while (length > 0) {
859 u32 val = skge_vpd_read(pdev, cap, offset);
860 int n = min_t(int, length, sizeof(val));
861
862 memcpy(data, &val, n);
863 length -= n;
864 data += n;
865 offset += n;
866 }
867 return 0;
868}
869
870static int skge_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
871 u8 *data)
872{
873 struct skge_port *skge = netdev_priv(dev);
874 struct pci_dev *pdev = skge->hw->pdev;
875 int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD);
876 int length = eeprom->len;
877 u16 offset = eeprom->offset;
878
879 if (!cap)
880 return -EINVAL;
881
882 if (eeprom->magic != SKGE_EEPROM_MAGIC)
883 return -EINVAL;
884
885 while (length > 0) {
886 u32 val;
887 int n = min_t(int, length, sizeof(val));
888
889 if (n < sizeof(val))
890 val = skge_vpd_read(pdev, cap, offset);
891 memcpy(&val, data, n);
892
893 skge_vpd_write(pdev, cap, offset, val);
894
895 length -= n;
896 data += n;
897 offset += n;
898 }
899 return 0;
900}
901
Jeff Garzik7282d492006-09-13 14:30:00 -0400902static const struct ethtool_ops skge_ethtool_ops = {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400903 .get_settings = skge_get_settings,
904 .set_settings = skge_set_settings,
905 .get_drvinfo = skge_get_drvinfo,
906 .get_regs_len = skge_get_regs_len,
907 .get_regs = skge_get_regs,
908 .get_wol = skge_get_wol,
909 .set_wol = skge_set_wol,
910 .get_msglevel = skge_get_msglevel,
911 .set_msglevel = skge_set_msglevel,
912 .nway_reset = skge_nway_reset,
913 .get_link = ethtool_op_get_link,
Stephen Hemmingerafa151b2007-10-16 12:15:53 -0700914 .get_eeprom_len = skge_get_eeprom_len,
915 .get_eeprom = skge_get_eeprom,
916 .set_eeprom = skge_set_eeprom,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400917 .get_ringparam = skge_get_ring_param,
918 .set_ringparam = skge_set_ring_param,
919 .get_pauseparam = skge_get_pauseparam,
920 .set_pauseparam = skge_set_pauseparam,
921 .get_coalesce = skge_get_coalesce,
922 .set_coalesce = skge_set_coalesce,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400923 .set_sg = skge_set_sg,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400924 .set_tx_csum = skge_set_tx_csum,
925 .get_rx_csum = skge_get_rx_csum,
926 .set_rx_csum = skge_set_rx_csum,
927 .get_strings = skge_get_strings,
928 .phys_id = skge_phys_id,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700929 .get_sset_count = skge_get_sset_count,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400930 .get_ethtool_stats = skge_get_ethtool_stats,
931};
932
933/*
934 * Allocate ring elements and chain them together
935 * One-to-one association of board descriptors with ring elements
936 */
Stephen Hemmingerc3da1442006-03-21 10:57:01 -0800937static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u32 base)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400938{
939 struct skge_tx_desc *d;
940 struct skge_element *e;
941 int i;
942
Robert P. J. Daycd861282006-12-13 00:34:52 -0800943 ring->start = kcalloc(ring->count, sizeof(*e), GFP_KERNEL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400944 if (!ring->start)
945 return -ENOMEM;
946
947 for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) {
948 e->desc = d;
949 if (i == ring->count - 1) {
950 e->next = ring->start;
951 d->next_offset = base;
952 } else {
953 e->next = e + 1;
954 d->next_offset = base + (i+1) * sizeof(*d);
955 }
956 }
957 ring->to_use = ring->to_clean = ring->start;
958
959 return 0;
960}
961
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700962/* Allocate and setup a new buffer for receiving */
963static void skge_rx_setup(struct skge_port *skge, struct skge_element *e,
964 struct sk_buff *skb, unsigned int bufsize)
965{
966 struct skge_rx_desc *rd = e->desc;
967 u64 map;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400968
969 map = pci_map_single(skge->hw->pdev, skb->data, bufsize,
970 PCI_DMA_FROMDEVICE);
971
972 rd->dma_lo = map;
973 rd->dma_hi = map >> 32;
974 e->skb = skb;
975 rd->csum1_start = ETH_HLEN;
976 rd->csum2_start = ETH_HLEN;
977 rd->csum1 = 0;
978 rd->csum2 = 0;
979
980 wmb();
981
982 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | bufsize;
983 pci_unmap_addr_set(e, mapaddr, map);
984 pci_unmap_len_set(e, maplen, bufsize);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -0400985}
986
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700987/* Resume receiving using existing skb,
988 * Note: DMA address is not changed by chip.
989 * MTU not changed while receiver active.
990 */
Stephen Hemminger5a011442006-03-23 11:07:25 -0800991static inline void skge_rx_reuse(struct skge_element *e, unsigned int size)
Stephen Hemminger19a33d42005-06-27 11:33:15 -0700992{
993 struct skge_rx_desc *rd = e->desc;
994
995 rd->csum2 = 0;
996 rd->csum2_start = ETH_HLEN;
997
998 wmb();
999
1000 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | size;
1001}
1002
1003
1004/* Free all buffers in receive ring, assumes receiver stopped */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001005static void skge_rx_clean(struct skge_port *skge)
1006{
1007 struct skge_hw *hw = skge->hw;
1008 struct skge_ring *ring = &skge->rx_ring;
1009 struct skge_element *e;
1010
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001011 e = ring->start;
1012 do {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001013 struct skge_rx_desc *rd = e->desc;
1014 rd->control = 0;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001015 if (e->skb) {
1016 pci_unmap_single(hw->pdev,
1017 pci_unmap_addr(e, mapaddr),
1018 pci_unmap_len(e, maplen),
1019 PCI_DMA_FROMDEVICE);
1020 dev_kfree_skb(e->skb);
1021 e->skb = NULL;
1022 }
1023 } while ((e = e->next) != ring->start);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001024}
1025
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001026
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001027/* Allocate buffers for receive ring
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001028 * For receive: to_clean is next received frame.
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001029 */
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07001030static int skge_rx_fill(struct net_device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001031{
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07001032 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001033 struct skge_ring *ring = &skge->rx_ring;
1034 struct skge_element *e;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001035
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001036 e = ring->start;
1037 do {
Stephen Hemminger383181a2005-09-19 15:37:16 -07001038 struct sk_buff *skb;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001039
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07001040 skb = __netdev_alloc_skb(dev, skge->rx_buf_size + NET_IP_ALIGN,
1041 GFP_KERNEL);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001042 if (!skb)
1043 return -ENOMEM;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001044
Stephen Hemminger383181a2005-09-19 15:37:16 -07001045 skb_reserve(skb, NET_IP_ALIGN);
1046 skge_rx_setup(skge, e, skb, skge->rx_buf_size);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07001047 } while ( (e = e->next) != ring->start);
1048
1049 ring->to_clean = ring->start;
1050 return 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001051}
1052
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001053static const char *skge_pause(enum pause_status status)
1054{
1055 switch(status) {
1056 case FLOW_STAT_NONE:
1057 return "none";
1058 case FLOW_STAT_REM_SEND:
1059 return "rx only";
1060 case FLOW_STAT_LOC_SEND:
1061 return "tx_only";
1062 case FLOW_STAT_SYMMETRIC: /* Both station may send PAUSE */
1063 return "both";
1064 default:
1065 return "indeterminated";
1066 }
1067}
1068
1069
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001070static void skge_link_up(struct skge_port *skge)
1071{
Stephen Hemminger46a60f22005-09-09 12:54:56 -07001072 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG),
Stephen Hemminger54cfb5a2005-08-16 14:01:05 -07001073 LED_BLK_OFF|LED_SYNC_OFF|LED_ON);
1074
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001075 netif_carrier_on(skge->netdev);
Stephen Hemminger29b4e882006-03-23 11:07:28 -08001076 netif_wake_queue(skge->netdev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001077
Joe Perchesd7072042010-02-09 11:49:53 +00001078 netif_info(skge, link, skge->netdev,
1079 "Link is up at %d Mbps, %s duplex, flow control %s\n",
1080 skge->speed,
1081 skge->duplex == DUPLEX_FULL ? "full" : "half",
1082 skge_pause(skge->flow_status));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001083}
1084
1085static void skge_link_down(struct skge_port *skge)
1086{
Stephen Hemminger54cfb5a2005-08-16 14:01:05 -07001087 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001088 netif_carrier_off(skge->netdev);
1089 netif_stop_queue(skge->netdev);
1090
Joe Perchesd7072042010-02-09 11:49:53 +00001091 netif_info(skge, link, skge->netdev, "Link is down\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001092}
1093
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001094
1095static void xm_link_down(struct skge_hw *hw, int port)
1096{
1097 struct net_device *dev = hw->dev[port];
1098 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001099
Stephen Hemminger501fb722007-10-16 12:15:51 -07001100 xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE);
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001101
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001102 if (netif_carrier_ok(dev))
1103 skge_link_down(skge);
1104}
1105
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001106static int __xm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001107{
1108 int i;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001109
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001110 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
Stephen Hemminger07811912006-02-22 10:28:34 -08001111 *val = xm_read16(hw, port, XM_PHY_DATA);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001112
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001113 if (hw->phy_type == SK_PHY_XMAC)
1114 goto ready;
1115
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001116 for (i = 0; i < PHY_RETRIES; i++) {
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001117 if (xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_RDY)
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001118 goto ready;
Stephen Hemminger07811912006-02-22 10:28:34 -08001119 udelay(1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001120 }
1121
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001122 return -ETIMEDOUT;
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001123 ready:
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001124 *val = xm_read16(hw, port, XM_PHY_DATA);
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001125
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001126 return 0;
1127}
1128
1129static u16 xm_phy_read(struct skge_hw *hw, int port, u16 reg)
1130{
1131 u16 v = 0;
1132 if (__xm_phy_read(hw, port, reg, &v))
Joe Perchesf15063c2010-02-17 15:01:57 +00001133 pr_warning("%s: phy read timed out\n", hw->dev[port]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001134 return v;
1135}
1136
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001137static int xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001138{
1139 int i;
1140
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001141 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001142 for (i = 0; i < PHY_RETRIES; i++) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001143 if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001144 goto ready;
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001145 udelay(1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001146 }
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001147 return -EIO;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001148
1149 ready:
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001150 xm_write16(hw, port, XM_PHY_DATA, val);
Stephen Hemminger07811912006-02-22 10:28:34 -08001151 for (i = 0; i < PHY_RETRIES; i++) {
1152 if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
1153 return 0;
1154 udelay(1);
1155 }
1156 return -ETIMEDOUT;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001157}
1158
1159static void genesis_init(struct skge_hw *hw)
1160{
1161 /* set blink source counter */
1162 skge_write32(hw, B2_BSC_INI, (SK_BLK_DUR * SK_FACT_53) / 100);
1163 skge_write8(hw, B2_BSC_CTRL, BSC_START);
1164
1165 /* configure mac arbiter */
1166 skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR);
1167
1168 /* configure mac arbiter timeout values */
1169 skge_write8(hw, B3_MA_TOINI_RX1, SK_MAC_TO_53);
1170 skge_write8(hw, B3_MA_TOINI_RX2, SK_MAC_TO_53);
1171 skge_write8(hw, B3_MA_TOINI_TX1, SK_MAC_TO_53);
1172 skge_write8(hw, B3_MA_TOINI_TX2, SK_MAC_TO_53);
1173
1174 skge_write8(hw, B3_MA_RCINI_RX1, 0);
1175 skge_write8(hw, B3_MA_RCINI_RX2, 0);
1176 skge_write8(hw, B3_MA_RCINI_TX1, 0);
1177 skge_write8(hw, B3_MA_RCINI_TX2, 0);
1178
1179 /* configure packet arbiter timeout */
1180 skge_write16(hw, B3_PA_CTRL, PA_RST_CLR);
1181 skge_write16(hw, B3_PA_TOINI_RX1, SK_PKT_TO_MAX);
1182 skge_write16(hw, B3_PA_TOINI_TX1, SK_PKT_TO_MAX);
1183 skge_write16(hw, B3_PA_TOINI_RX2, SK_PKT_TO_MAX);
1184 skge_write16(hw, B3_PA_TOINI_TX2, SK_PKT_TO_MAX);
1185}
1186
1187static void genesis_reset(struct skge_hw *hw, int port)
1188{
Stephen Hemminger45bada62005-06-27 11:33:12 -07001189 const u8 zero[8] = { 0 };
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001190 u32 reg;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001191
Stephen Hemminger46a60f22005-09-09 12:54:56 -07001192 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
1193
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001194 /* reset the statistics module */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001195 xm_write32(hw, port, XM_GP_PORT, XM_GP_RES_STAT);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001196 xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001197 xm_write32(hw, port, XM_MODE, 0); /* clear Mode Reg */
1198 xm_write16(hw, port, XM_TX_CMD, 0); /* reset TX CMD Reg */
1199 xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001200
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001201 /* disable Broadcom PHY IRQ */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001202 if (hw->phy_type == SK_PHY_BCOM)
1203 xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001204
Stephen Hemminger45bada62005-06-27 11:33:12 -07001205 xm_outhash(hw, port, XM_HSM, zero);
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001206
1207 /* Flush TX and RX fifo */
1208 reg = xm_read32(hw, port, XM_MODE);
1209 xm_write32(hw, port, XM_MODE, reg | XM_MD_FTF);
1210 xm_write32(hw, port, XM_MODE, reg | XM_MD_FRF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001211}
1212
1213
Stephen Hemminger45bada62005-06-27 11:33:12 -07001214/* Convert mode to MII values */
1215static const u16 phy_pause_map[] = {
1216 [FLOW_MODE_NONE] = 0,
1217 [FLOW_MODE_LOC_SEND] = PHY_AN_PAUSE_ASYM,
1218 [FLOW_MODE_SYMMETRIC] = PHY_AN_PAUSE_CAP,
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001219 [FLOW_MODE_SYM_OR_REM] = PHY_AN_PAUSE_CAP | PHY_AN_PAUSE_ASYM,
Stephen Hemminger45bada62005-06-27 11:33:12 -07001220};
1221
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001222/* special defines for FIBER (88E1011S only) */
1223static const u16 fiber_pause_map[] = {
1224 [FLOW_MODE_NONE] = PHY_X_P_NO_PAUSE,
1225 [FLOW_MODE_LOC_SEND] = PHY_X_P_ASYM_MD,
1226 [FLOW_MODE_SYMMETRIC] = PHY_X_P_SYM_MD,
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001227 [FLOW_MODE_SYM_OR_REM] = PHY_X_P_BOTH_MD,
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001228};
1229
Stephen Hemminger45bada62005-06-27 11:33:12 -07001230
1231/* Check status of Broadcom phy link */
1232static void bcom_check_link(struct skge_hw *hw, int port)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001233{
Stephen Hemminger45bada62005-06-27 11:33:12 -07001234 struct net_device *dev = hw->dev[port];
1235 struct skge_port *skge = netdev_priv(dev);
1236 u16 status;
1237
1238 /* read twice because of latch */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001239 xm_phy_read(hw, port, PHY_BCOM_STAT);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001240 status = xm_phy_read(hw, port, PHY_BCOM_STAT);
1241
Stephen Hemminger45bada62005-06-27 11:33:12 -07001242 if ((status & PHY_ST_LSYNC) == 0) {
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001243 xm_link_down(hw, port);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001244 return;
1245 }
Stephen Hemminger45bada62005-06-27 11:33:12 -07001246
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001247 if (skge->autoneg == AUTONEG_ENABLE) {
1248 u16 lpa, aux;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001249
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001250 if (!(status & PHY_ST_AN_OVER))
1251 return;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001252
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001253 lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP);
1254 if (lpa & PHY_B_AN_RF) {
Joe Perchesf15063c2010-02-17 15:01:57 +00001255 netdev_notice(dev, "remote fault\n");
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001256 return;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001257 }
1258
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001259 aux = xm_phy_read(hw, port, PHY_BCOM_AUX_STAT);
1260
1261 /* Check Duplex mismatch */
1262 switch (aux & PHY_B_AS_AN_RES_MSK) {
1263 case PHY_B_RES_1000FD:
1264 skge->duplex = DUPLEX_FULL;
1265 break;
1266 case PHY_B_RES_1000HD:
1267 skge->duplex = DUPLEX_HALF;
1268 break;
1269 default:
Joe Perchesf15063c2010-02-17 15:01:57 +00001270 netdev_notice(dev, "duplex mismatch\n");
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001271 return;
1272 }
1273
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001274 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
1275 switch (aux & PHY_B_AS_PAUSE_MSK) {
1276 case PHY_B_AS_PAUSE_MSK:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001277 skge->flow_status = FLOW_STAT_SYMMETRIC;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001278 break;
1279 case PHY_B_AS_PRR:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001280 skge->flow_status = FLOW_STAT_REM_SEND;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001281 break;
1282 case PHY_B_AS_PRT:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001283 skge->flow_status = FLOW_STAT_LOC_SEND;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001284 break;
1285 default:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001286 skge->flow_status = FLOW_STAT_NONE;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001287 }
1288 skge->speed = SPEED_1000;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001289 }
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001290
1291 if (!netif_carrier_ok(dev))
1292 genesis_link_up(skge);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001293}
1294
1295/* Broadcom 5400 only supports giagabit! SysKonnect did not put an additional
1296 * Phy on for 100 or 10Mbit operation
1297 */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001298static void bcom_phy_init(struct skge_port *skge)
Stephen Hemminger45bada62005-06-27 11:33:12 -07001299{
1300 struct skge_hw *hw = skge->hw;
1301 int port = skge->port;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001302 int i;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001303 u16 id1, r, ext, ctl;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001304
1305 /* magic workaround patterns for Broadcom */
1306 static const struct {
1307 u16 reg;
1308 u16 val;
1309 } A1hack[] = {
1310 { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1104 },
1311 { 0x17, 0x0013 }, { 0x15, 0x0404 }, { 0x17, 0x8006 },
1312 { 0x15, 0x0132 }, { 0x17, 0x8006 }, { 0x15, 0x0232 },
1313 { 0x17, 0x800D }, { 0x15, 0x000F }, { 0x18, 0x0420 },
1314 }, C0hack[] = {
1315 { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1204 },
1316 { 0x17, 0x0013 }, { 0x15, 0x0A04 }, { 0x18, 0x0420 },
1317 };
1318
Stephen Hemminger45bada62005-06-27 11:33:12 -07001319 /* read Id from external PHY (all have the same address) */
1320 id1 = xm_phy_read(hw, port, PHY_XMAC_ID1);
1321
1322 /* Optimize MDIO transfer by suppressing preamble. */
1323 r = xm_read16(hw, port, XM_MMU_CMD);
1324 r |= XM_MMU_NO_PRE;
1325 xm_write16(hw, port, XM_MMU_CMD,r);
1326
Stephen Hemminger2c668512005-07-22 16:26:07 -07001327 switch (id1) {
Stephen Hemminger45bada62005-06-27 11:33:12 -07001328 case PHY_BCOM_ID1_C0:
1329 /*
1330 * Workaround BCOM Errata for the C0 type.
1331 * Write magic patterns to reserved registers.
1332 */
1333 for (i = 0; i < ARRAY_SIZE(C0hack); i++)
1334 xm_phy_write(hw, port,
1335 C0hack[i].reg, C0hack[i].val);
1336
1337 break;
1338 case PHY_BCOM_ID1_A1:
1339 /*
1340 * Workaround BCOM Errata for the A1 type.
1341 * Write magic patterns to reserved registers.
1342 */
1343 for (i = 0; i < ARRAY_SIZE(A1hack); i++)
1344 xm_phy_write(hw, port,
1345 A1hack[i].reg, A1hack[i].val);
1346 break;
1347 }
1348
1349 /*
1350 * Workaround BCOM Errata (#10523) for all BCom PHYs.
1351 * Disable Power Management after reset.
1352 */
1353 r = xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL);
1354 r |= PHY_B_AC_DIS_PM;
1355 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, r);
1356
1357 /* Dummy read */
1358 xm_read16(hw, port, XM_ISRC);
1359
1360 ext = PHY_B_PEC_EN_LTR; /* enable tx led */
1361 ctl = PHY_CT_SP1000; /* always 1000mbit */
1362
1363 if (skge->autoneg == AUTONEG_ENABLE) {
1364 /*
1365 * Workaround BCOM Errata #1 for the C5 type.
1366 * 1000Base-T Link Acquisition Failure in Slave Mode
1367 * Set Repeater/DTE bit 10 of the 1000Base-T Control Register
1368 */
1369 u16 adv = PHY_B_1000C_RD;
1370 if (skge->advertising & ADVERTISED_1000baseT_Half)
1371 adv |= PHY_B_1000C_AHD;
1372 if (skge->advertising & ADVERTISED_1000baseT_Full)
1373 adv |= PHY_B_1000C_AFD;
1374 xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, adv);
1375
1376 ctl |= PHY_CT_ANE | PHY_CT_RE_CFG;
1377 } else {
1378 if (skge->duplex == DUPLEX_FULL)
1379 ctl |= PHY_CT_DUP_MD;
1380 /* Force to slave */
1381 xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, PHY_B_1000C_MSE);
1382 }
1383
1384 /* Set autonegotiation pause parameters */
1385 xm_phy_write(hw, port, PHY_BCOM_AUNE_ADV,
1386 phy_pause_map[skge->flow_control] | PHY_AN_CSMA);
1387
1388 /* Handle Jumbo frames */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001389 if (hw->dev[port]->mtu > ETH_DATA_LEN) {
Stephen Hemminger45bada62005-06-27 11:33:12 -07001390 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1391 PHY_B_AC_TX_TST | PHY_B_AC_LONG_PACK);
1392
1393 ext |= PHY_B_PEC_HIGH_LA;
1394
1395 }
1396
1397 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, ext);
1398 xm_phy_write(hw, port, PHY_BCOM_CTRL, ctl);
1399
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08001400 /* Use link status change interrupt */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001401 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001402}
Stephen Hemminger45bada62005-06-27 11:33:12 -07001403
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001404static void xm_phy_init(struct skge_port *skge)
1405{
1406 struct skge_hw *hw = skge->hw;
1407 int port = skge->port;
1408 u16 ctrl = 0;
1409
1410 if (skge->autoneg == AUTONEG_ENABLE) {
1411 if (skge->advertising & ADVERTISED_1000baseT_Half)
1412 ctrl |= PHY_X_AN_HD;
1413 if (skge->advertising & ADVERTISED_1000baseT_Full)
1414 ctrl |= PHY_X_AN_FD;
1415
Stephen Hemminger4b67be92006-10-05 15:49:51 -07001416 ctrl |= fiber_pause_map[skge->flow_control];
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001417
1418 xm_phy_write(hw, port, PHY_XMAC_AUNE_ADV, ctrl);
1419
1420 /* Restart Auto-negotiation */
1421 ctrl = PHY_CT_ANE | PHY_CT_RE_CFG;
1422 } else {
1423 /* Set DuplexMode in Config register */
1424 if (skge->duplex == DUPLEX_FULL)
1425 ctrl |= PHY_CT_DUP_MD;
1426 /*
1427 * Do NOT enable Auto-negotiation here. This would hold
1428 * the link down because no IDLEs are transmitted
1429 */
1430 }
1431
1432 xm_phy_write(hw, port, PHY_XMAC_CTRL, ctrl);
1433
1434 /* Poll PHY for status changes */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07001435 mod_timer(&skge->link_timer, jiffies + LINK_HZ);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001436}
1437
Stephen Hemminger501fb722007-10-16 12:15:51 -07001438static int xm_check_link(struct net_device *dev)
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001439{
1440 struct skge_port *skge = netdev_priv(dev);
1441 struct skge_hw *hw = skge->hw;
1442 int port = skge->port;
1443 u16 status;
1444
1445 /* read twice because of latch */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001446 xm_phy_read(hw, port, PHY_XMAC_STAT);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001447 status = xm_phy_read(hw, port, PHY_XMAC_STAT);
1448
1449 if ((status & PHY_ST_LSYNC) == 0) {
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001450 xm_link_down(hw, port);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001451 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001452 }
1453
1454 if (skge->autoneg == AUTONEG_ENABLE) {
1455 u16 lpa, res;
1456
1457 if (!(status & PHY_ST_AN_OVER))
Stephen Hemminger501fb722007-10-16 12:15:51 -07001458 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001459
1460 lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP);
1461 if (lpa & PHY_B_AN_RF) {
Joe Perchesf15063c2010-02-17 15:01:57 +00001462 netdev_notice(dev, "remote fault\n");
Stephen Hemminger501fb722007-10-16 12:15:51 -07001463 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001464 }
1465
1466 res = xm_phy_read(hw, port, PHY_XMAC_RES_ABI);
1467
1468 /* Check Duplex mismatch */
1469 switch (res & (PHY_X_RS_HD | PHY_X_RS_FD)) {
1470 case PHY_X_RS_FD:
1471 skge->duplex = DUPLEX_FULL;
1472 break;
1473 case PHY_X_RS_HD:
1474 skge->duplex = DUPLEX_HALF;
1475 break;
1476 default:
Joe Perchesf15063c2010-02-17 15:01:57 +00001477 netdev_notice(dev, "duplex mismatch\n");
Stephen Hemminger501fb722007-10-16 12:15:51 -07001478 return 0;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001479 }
1480
1481 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001482 if ((skge->flow_control == FLOW_MODE_SYMMETRIC ||
1483 skge->flow_control == FLOW_MODE_SYM_OR_REM) &&
1484 (lpa & PHY_X_P_SYM_MD))
1485 skge->flow_status = FLOW_STAT_SYMMETRIC;
1486 else if (skge->flow_control == FLOW_MODE_SYM_OR_REM &&
1487 (lpa & PHY_X_RS_PAUSE) == PHY_X_P_ASYM_MD)
1488 /* Enable PAUSE receive, disable PAUSE transmit */
1489 skge->flow_status = FLOW_STAT_REM_SEND;
1490 else if (skge->flow_control == FLOW_MODE_LOC_SEND &&
1491 (lpa & PHY_X_RS_PAUSE) == PHY_X_P_BOTH_MD)
1492 /* Disable PAUSE receive, enable PAUSE transmit */
1493 skge->flow_status = FLOW_STAT_LOC_SEND;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001494 else
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001495 skge->flow_status = FLOW_STAT_NONE;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001496
1497 skge->speed = SPEED_1000;
1498 }
1499
1500 if (!netif_carrier_ok(dev))
1501 genesis_link_up(skge);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001502 return 1;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001503}
1504
1505/* Poll to check for link coming up.
Stephen Hemminger501fb722007-10-16 12:15:51 -07001506 *
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001507 * Since internal PHY is wired to a level triggered pin, can't
Stephen Hemminger501fb722007-10-16 12:15:51 -07001508 * get an interrupt when carrier is detected, need to poll for
1509 * link coming up.
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001510 */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07001511static void xm_link_timer(unsigned long arg)
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001512{
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07001513 struct skge_port *skge = (struct skge_port *) arg;
David Howellsc4028952006-11-22 14:57:56 +00001514 struct net_device *dev = skge->netdev;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001515 struct skge_hw *hw = skge->hw;
1516 int port = skge->port;
Stephen Hemminger501fb722007-10-16 12:15:51 -07001517 int i;
1518 unsigned long flags;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001519
1520 if (!netif_running(dev))
1521 return;
1522
Stephen Hemminger501fb722007-10-16 12:15:51 -07001523 spin_lock_irqsave(&hw->phy_lock, flags);
1524
1525 /*
1526 * Verify that the link by checking GPIO register three times.
1527 * This pin has the signal from the link_sync pin connected to it.
1528 */
1529 for (i = 0; i < 3; i++) {
1530 if (xm_read16(hw, port, XM_GP_PORT) & XM_GP_INP_ASS)
1531 goto link_down;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001532 }
1533
Stephen Hemminger501fb722007-10-16 12:15:51 -07001534 /* Re-enable interrupt to detect link down */
1535 if (xm_check_link(dev)) {
1536 u16 msk = xm_read16(hw, port, XM_IMSK);
1537 msk &= ~XM_IS_INP_ASS;
1538 xm_write16(hw, port, XM_IMSK, msk);
1539 xm_read16(hw, port, XM_ISRC);
1540 } else {
1541link_down:
1542 mod_timer(&skge->link_timer,
1543 round_jiffies(jiffies + LINK_HZ));
1544 }
1545 spin_unlock_irqrestore(&hw->phy_lock, flags);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001546}
1547
1548static void genesis_mac_init(struct skge_hw *hw, int port)
1549{
1550 struct net_device *dev = hw->dev[port];
1551 struct skge_port *skge = netdev_priv(dev);
1552 int jumbo = hw->dev[port]->mtu > ETH_DATA_LEN;
1553 int i;
1554 u32 r;
1555 const u8 zero[6] = { 0 };
1556
Stephen Hemminger07811912006-02-22 10:28:34 -08001557 for (i = 0; i < 10; i++) {
1558 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1),
1559 MFF_SET_MAC_RST);
1560 if (skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST)
1561 goto reset_ok;
1562 udelay(1);
1563 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001564
Joe Perchesf15063c2010-02-17 15:01:57 +00001565 netdev_warn(dev, "genesis reset failed\n");
Stephen Hemminger07811912006-02-22 10:28:34 -08001566
1567 reset_ok:
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001568 /* Unreset the XMAC. */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001569 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001570
1571 /*
1572 * Perform additional initialization for external PHYs,
1573 * namely for the 1000baseTX cards that use the XMAC's
1574 * GMII mode.
1575 */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001576 if (hw->phy_type != SK_PHY_XMAC) {
1577 /* Take external Phy out of reset */
1578 r = skge_read32(hw, B2_GP_IO);
1579 if (port == 0)
1580 r |= GP_DIR_0|GP_IO_0;
1581 else
1582 r |= GP_DIR_2|GP_IO_2;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001583
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001584 skge_write32(hw, B2_GP_IO, r);
1585
1586 /* Enable GMII interface */
1587 xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD);
1588 }
Stephen Hemminger07811912006-02-22 10:28:34 -08001589
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001590
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001591 switch(hw->phy_type) {
1592 case SK_PHY_XMAC:
1593 xm_phy_init(skge);
1594 break;
1595 case SK_PHY_BCOM:
1596 bcom_phy_init(skge);
1597 bcom_check_link(hw, port);
1598 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001599
Stephen Hemminger45bada62005-06-27 11:33:12 -07001600 /* Set Station Address */
1601 xm_outaddr(hw, port, XM_SA, dev->dev_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001602
Stephen Hemminger45bada62005-06-27 11:33:12 -07001603 /* We don't use match addresses so clear */
1604 for (i = 1; i < 16; i++)
1605 xm_outaddr(hw, port, XM_EXM(i), zero);
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001606
Stephen Hemminger07811912006-02-22 10:28:34 -08001607 /* Clear MIB counters */
1608 xm_write16(hw, port, XM_STAT_CMD,
1609 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1610 /* Clear two times according to Errata #3 */
1611 xm_write16(hw, port, XM_STAT_CMD,
1612 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1613
Stephen Hemminger45bada62005-06-27 11:33:12 -07001614 /* configure Rx High Water Mark (XM_RX_HI_WM) */
1615 xm_write16(hw, port, XM_RX_HI_WM, 1450);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001616
1617 /* We don't need the FCS appended to the packet. */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001618 r = XM_RX_LENERR_OK | XM_RX_STRIP_FCS;
1619 if (jumbo)
1620 r |= XM_RX_BIG_PK_OK;
1621
1622 if (skge->duplex == DUPLEX_HALF) {
1623 /*
1624 * If in manual half duplex mode the other side might be in
1625 * full duplex mode, so ignore if a carrier extension is not seen
1626 * on frames received
1627 */
1628 r |= XM_RX_DIS_CEXT;
1629 }
1630 xm_write16(hw, port, XM_RX_CMD, r);
1631
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001632 /* We want short frames padded to 60 bytes. */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001633 xm_write16(hw, port, XM_TX_CMD, XM_TX_AUTO_PAD);
1634
Stephen Hemminger485982a2007-11-26 11:54:52 -08001635 /* Increase threshold for jumbo frames on dual port */
1636 if (hw->ports > 1 && jumbo)
1637 xm_write16(hw, port, XM_TX_THR, 1020);
1638 else
1639 xm_write16(hw, port, XM_TX_THR, 512);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001640
1641 /*
1642 * Enable the reception of all error frames. This is is
1643 * a necessary evil due to the design of the XMAC. The
1644 * XMAC's receive FIFO is only 8K in size, however jumbo
1645 * frames can be up to 9000 bytes in length. When bad
1646 * frame filtering is enabled, the XMAC's RX FIFO operates
1647 * in 'store and forward' mode. For this to work, the
1648 * entire frame has to fit into the FIFO, but that means
1649 * that jumbo frames larger than 8192 bytes will be
1650 * truncated. Disabling all bad frame filtering causes
1651 * the RX FIFO to operate in streaming mode, in which
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08001652 * case the XMAC will start transferring frames out of the
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001653 * RX FIFO as soon as the FIFO threshold is reached.
1654 */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001655 xm_write32(hw, port, XM_MODE, XM_DEF_MODE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001656
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001657
1658 /*
Stephen Hemminger45bada62005-06-27 11:33:12 -07001659 * Initialize the Receive Counter Event Mask (XM_RX_EV_MSK)
1660 * - Enable all bits excepting 'Octets Rx OK Low CntOv'
1661 * and 'Octets Rx OK Hi Cnt Ov'.
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001662 */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001663 xm_write32(hw, port, XM_RX_EV_MSK, XMR_DEF_MSK);
1664
1665 /*
1666 * Initialize the Transmit Counter Event Mask (XM_TX_EV_MSK)
1667 * - Enable all bits excepting 'Octets Tx OK Low CntOv'
1668 * and 'Octets Tx OK Hi Cnt Ov'.
1669 */
1670 xm_write32(hw, port, XM_TX_EV_MSK, XMT_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001671
1672 /* Configure MAC arbiter */
1673 skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR);
1674
1675 /* configure timeout values */
1676 skge_write8(hw, B3_MA_TOINI_RX1, 72);
1677 skge_write8(hw, B3_MA_TOINI_RX2, 72);
1678 skge_write8(hw, B3_MA_TOINI_TX1, 72);
1679 skge_write8(hw, B3_MA_TOINI_TX2, 72);
1680
1681 skge_write8(hw, B3_MA_RCINI_RX1, 0);
1682 skge_write8(hw, B3_MA_RCINI_RX2, 0);
1683 skge_write8(hw, B3_MA_RCINI_TX1, 0);
1684 skge_write8(hw, B3_MA_RCINI_TX2, 0);
1685
1686 /* Configure Rx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001687 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_CLR);
1688 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_TIM_PAT);
1689 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_ENA_OP_MD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001690
1691 /* Configure Tx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001692 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_CLR);
1693 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF);
1694 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_ENA_OP_MD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001695
Stephen Hemminger45bada62005-06-27 11:33:12 -07001696 if (jumbo) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001697 /* Enable frame flushing if jumbo frames used */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001698 skge_write16(hw, SK_REG(port,RX_MFF_CTRL1), MFF_ENA_FLUSH);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001699 } else {
1700 /* enable timeout timers if normal frames */
1701 skge_write16(hw, B3_PA_CTRL,
Stephen Hemminger45bada62005-06-27 11:33:12 -07001702 (port == 0) ? PA_ENA_TO_TX1 : PA_ENA_TO_TX2);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001703 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001704}
1705
1706static void genesis_stop(struct skge_port *skge)
1707{
1708 struct skge_hw *hw = skge->hw;
1709 int port = skge->port;
Stephen Hemminger799b21d2007-11-26 11:54:50 -08001710 unsigned retries = 1000;
Stephen Hemminger21d7f672007-11-26 11:54:51 -08001711 u16 cmd;
1712
1713 /* Disable Tx and Rx */
1714 cmd = xm_read16(hw, port, XM_MMU_CMD);
1715 cmd &= ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1716 xm_write16(hw, port, XM_MMU_CMD, cmd);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001717
Stephen Hemminger46a60f22005-09-09 12:54:56 -07001718 genesis_reset(hw, port);
1719
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001720 /* Clear Tx packet arbiter timeout IRQ */
1721 skge_write16(hw, B3_PA_CTRL,
1722 port == 0 ? PA_CLR_TO_TX1 : PA_CLR_TO_TX2);
1723
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001724 /* Reset the MAC */
Stephen Hemminger799b21d2007-11-26 11:54:50 -08001725 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
1726 do {
1727 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST);
1728 if (!(skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST))
1729 break;
1730 } while (--retries > 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001731
1732 /* For external PHYs there must be special handling */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001733 if (hw->phy_type != SK_PHY_XMAC) {
Stephen Hemminger799b21d2007-11-26 11:54:50 -08001734 u32 reg = skge_read32(hw, B2_GP_IO);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001735 if (port == 0) {
1736 reg |= GP_DIR_0;
1737 reg &= ~GP_IO_0;
1738 } else {
1739 reg |= GP_DIR_2;
1740 reg &= ~GP_IO_2;
1741 }
1742 skge_write32(hw, B2_GP_IO, reg);
1743 skge_read32(hw, B2_GP_IO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001744 }
1745
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001746 xm_write16(hw, port, XM_MMU_CMD,
1747 xm_read16(hw, port, XM_MMU_CMD)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001748 & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX));
1749
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001750 xm_read16(hw, port, XM_MMU_CMD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001751}
1752
1753
1754static void genesis_get_stats(struct skge_port *skge, u64 *data)
1755{
1756 struct skge_hw *hw = skge->hw;
1757 int port = skge->port;
1758 int i;
1759 unsigned long timeout = jiffies + HZ;
1760
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001761 xm_write16(hw, port,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001762 XM_STAT_CMD, XM_SC_SNP_TXC | XM_SC_SNP_RXC);
1763
1764 /* wait for update to complete */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001765 while (xm_read16(hw, port, XM_STAT_CMD)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001766 & (XM_SC_SNP_TXC | XM_SC_SNP_RXC)) {
1767 if (time_after(jiffies, timeout))
1768 break;
1769 udelay(10);
1770 }
1771
1772 /* special case for 64 bit octet counter */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001773 data[0] = (u64) xm_read32(hw, port, XM_TXO_OK_HI) << 32
1774 | xm_read32(hw, port, XM_TXO_OK_LO);
1775 data[1] = (u64) xm_read32(hw, port, XM_RXO_OK_HI) << 32
1776 | xm_read32(hw, port, XM_RXO_OK_LO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001777
1778 for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001779 data[i] = xm_read32(hw, port, skge_stats[i].xmac_offset);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001780}
1781
1782static void genesis_mac_intr(struct skge_hw *hw, int port)
1783{
Stephen Hemmingerda007722007-10-16 12:15:52 -07001784 struct net_device *dev = hw->dev[port];
1785 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001786 u16 status = xm_read16(hw, port, XM_ISRC);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001787
Joe Perchesd7072042010-02-09 11:49:53 +00001788 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
1789 "mac interrupt status 0x%x\n", status);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001790
Stephen Hemminger501fb722007-10-16 12:15:51 -07001791 if (hw->phy_type == SK_PHY_XMAC && (status & XM_IS_INP_ASS)) {
1792 xm_link_down(hw, port);
1793 mod_timer(&skge->link_timer, jiffies + 1);
1794 }
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001795
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001796 if (status & XM_IS_TXF_UR) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001797 xm_write32(hw, port, XM_MODE, XM_MD_FTF);
Stephen Hemmingerda007722007-10-16 12:15:52 -07001798 ++dev->stats.tx_fifo_errors;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001799 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001800}
1801
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001802static void genesis_link_up(struct skge_port *skge)
1803{
1804 struct skge_hw *hw = skge->hw;
1805 int port = skge->port;
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001806 u16 cmd, msk;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001807 u32 mode;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001808
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001809 cmd = xm_read16(hw, port, XM_MMU_CMD);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001810
1811 /*
1812 * enabling pause frame reception is required for 1000BT
1813 * because the XMAC is not reset if the link is going down
1814 */
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001815 if (skge->flow_status == FLOW_STAT_NONE ||
1816 skge->flow_status == FLOW_STAT_LOC_SEND)
Stephen Hemminger7e676d92005-06-27 11:33:13 -07001817 /* Disable Pause Frame Reception */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001818 cmd |= XM_MMU_IGN_PF;
1819 else
1820 /* Enable Pause Frame Reception */
1821 cmd &= ~XM_MMU_IGN_PF;
1822
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001823 xm_write16(hw, port, XM_MMU_CMD, cmd);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001824
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001825 mode = xm_read32(hw, port, XM_MODE);
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07001826 if (skge->flow_status== FLOW_STAT_SYMMETRIC ||
1827 skge->flow_status == FLOW_STAT_LOC_SEND) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001828 /*
1829 * Configure Pause Frame Generation
1830 * Use internal and external Pause Frame Generation.
1831 * Sending pause frames is edge triggered.
1832 * Send a Pause frame with the maximum pause time if
1833 * internal oder external FIFO full condition occurs.
1834 * Send a zero pause time frame to re-start transmission.
1835 */
1836 /* XM_PAUSE_DA = '010000C28001' (default) */
1837 /* XM_MAC_PTIME = 0xffff (maximum) */
1838 /* remember this value is defined in big endian (!) */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001839 xm_write16(hw, port, XM_MAC_PTIME, 0xffff);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001840
1841 mode |= XM_PAUSE_MODE;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001842 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_PAUSE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001843 } else {
1844 /*
1845 * disable pause frame generation is required for 1000BT
1846 * because the XMAC is not reset if the link is going down
1847 */
1848 /* Disable Pause Mode in Mode Register */
1849 mode &= ~XM_PAUSE_MODE;
1850
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001851 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_DIS_PAUSE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001852 }
1853
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001854 xm_write32(hw, port, XM_MODE, mode);
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001855
Stephen Hemmingerd08b9bd2007-11-26 11:54:49 -08001856 /* Turn on detection of Tx underrun */
Stephen Hemminger501fb722007-10-16 12:15:51 -07001857 msk = xm_read16(hw, port, XM_IMSK);
Stephen Hemmingerd08b9bd2007-11-26 11:54:49 -08001858 msk &= ~XM_IS_TXF_UR;
Stephen Hemmingera1bc9b82006-10-05 15:49:50 -07001859 xm_write16(hw, port, XM_IMSK, msk);
Stephen Hemminger501fb722007-10-16 12:15:51 -07001860
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001861 xm_read16(hw, port, XM_ISRC);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001862
1863 /* get MMU Command Reg. */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001864 cmd = xm_read16(hw, port, XM_MMU_CMD);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001865 if (hw->phy_type != SK_PHY_XMAC && skge->duplex == DUPLEX_FULL)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001866 cmd |= XM_MMU_GMII_FD;
1867
Stephen Hemminger89bf5f22005-06-27 11:33:10 -07001868 /*
1869 * Workaround BCOM Errata (#10523) for all BCom Phys
1870 * Enable Power Management after link up
1871 */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07001872 if (hw->phy_type == SK_PHY_BCOM) {
1873 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1874 xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL)
1875 & ~PHY_B_AC_DIS_PM);
1876 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
1877 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001878
1879 /* enable Rx/Tx */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001880 xm_write16(hw, port, XM_MMU_CMD,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001881 cmd | XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1882 skge_link_up(skge);
1883}
1884
1885
Stephen Hemminger45bada62005-06-27 11:33:12 -07001886static inline void bcom_phy_intr(struct skge_port *skge)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001887{
1888 struct skge_hw *hw = skge->hw;
1889 int port = skge->port;
Stephen Hemminger45bada62005-06-27 11:33:12 -07001890 u16 isrc;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001891
Stephen Hemminger45bada62005-06-27 11:33:12 -07001892 isrc = xm_phy_read(hw, port, PHY_BCOM_INT_STAT);
Joe Perchesd7072042010-02-09 11:49:53 +00001893 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
1894 "phy interrupt status 0x%x\n", isrc);
Stephen Hemminger45bada62005-06-27 11:33:12 -07001895
1896 if (isrc & PHY_B_IS_PSE)
Joe Perchesf15063c2010-02-17 15:01:57 +00001897 pr_err("%s: uncorrectable pair swap error\n",
Stephen Hemminger45bada62005-06-27 11:33:12 -07001898 hw->dev[port]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001899
1900 /* Workaround BCom Errata:
1901 * enable and disable loopback mode if "NO HCD" occurs.
1902 */
Stephen Hemminger45bada62005-06-27 11:33:12 -07001903 if (isrc & PHY_B_IS_NO_HDCL) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001904 u16 ctrl = xm_phy_read(hw, port, PHY_BCOM_CTRL);
1905 xm_phy_write(hw, port, PHY_BCOM_CTRL,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001906 ctrl | PHY_CT_LOOP);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001907 xm_phy_write(hw, port, PHY_BCOM_CTRL,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001908 ctrl & ~PHY_CT_LOOP);
1909 }
1910
Stephen Hemminger45bada62005-06-27 11:33:12 -07001911 if (isrc & (PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE))
1912 bcom_check_link(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001913
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001914}
1915
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001916static int gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
1917{
1918 int i;
1919
1920 gma_write16(hw, port, GM_SMI_DATA, val);
1921 gma_write16(hw, port, GM_SMI_CTRL,
1922 GM_SMI_CT_PHY_AD(hw->phy_addr) | GM_SMI_CT_REG_AD(reg));
1923 for (i = 0; i < PHY_RETRIES; i++) {
1924 udelay(1);
1925
1926 if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY))
1927 return 0;
1928 }
1929
Joe Perchesf15063c2010-02-17 15:01:57 +00001930 pr_warning("%s: phy write timeout\n", hw->dev[port]->name);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001931 return -EIO;
1932}
1933
1934static int __gm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val)
1935{
1936 int i;
1937
1938 gma_write16(hw, port, GM_SMI_CTRL,
1939 GM_SMI_CT_PHY_AD(hw->phy_addr)
1940 | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD);
1941
1942 for (i = 0; i < PHY_RETRIES; i++) {
1943 udelay(1);
1944 if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL)
1945 goto ready;
1946 }
1947
1948 return -ETIMEDOUT;
1949 ready:
1950 *val = gma_read16(hw, port, GM_SMI_DATA);
1951 return 0;
1952}
1953
1954static u16 gm_phy_read(struct skge_hw *hw, int port, u16 reg)
1955{
1956 u16 v = 0;
1957 if (__gm_phy_read(hw, port, reg, &v))
Joe Perchesf15063c2010-02-17 15:01:57 +00001958 pr_warning("%s: phy read timeout\n", hw->dev[port]->name);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08001959 return v;
1960}
1961
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08001962/* Marvell Phy Initialization */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001963static void yukon_init(struct skge_hw *hw, int port)
1964{
1965 struct skge_port *skge = netdev_priv(hw->dev[port]);
1966 u16 ctrl, ct1000, adv;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001967
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001968 if (skge->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001969 u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001970
1971 ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
1972 PHY_M_EC_MAC_S_MSK);
1973 ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ);
1974
Stephen Hemmingerc506a502005-06-27 11:33:09 -07001975 ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001976
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001977 gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001978 }
1979
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001980 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001981 if (skge->autoneg == AUTONEG_DISABLE)
1982 ctrl &= ~PHY_CT_ANE;
1983
1984 ctrl |= PHY_CT_RESET;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07001985 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001986
1987 ctrl = 0;
1988 ct1000 = 0;
Stephen Hemmingerb18f2092005-06-27 11:33:08 -07001989 adv = PHY_AN_CSMA;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001990
1991 if (skge->autoneg == AUTONEG_ENABLE) {
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07001992 if (hw->copper) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04001993 if (skge->advertising & ADVERTISED_1000baseT_Full)
1994 ct1000 |= PHY_M_1000C_AFD;
1995 if (skge->advertising & ADVERTISED_1000baseT_Half)
1996 ct1000 |= PHY_M_1000C_AHD;
1997 if (skge->advertising & ADVERTISED_100baseT_Full)
1998 adv |= PHY_M_AN_100_FD;
1999 if (skge->advertising & ADVERTISED_100baseT_Half)
2000 adv |= PHY_M_AN_100_HD;
2001 if (skge->advertising & ADVERTISED_10baseT_Full)
2002 adv |= PHY_M_AN_10_FD;
2003 if (skge->advertising & ADVERTISED_10baseT_Half)
2004 adv |= PHY_M_AN_10_HD;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002005
Stephen Hemminger4b67be92006-10-05 15:49:51 -07002006 /* Set Flow-control capabilities */
2007 adv |= phy_pause_map[skge->flow_control];
2008 } else {
2009 if (skge->advertising & ADVERTISED_1000baseT_Full)
2010 adv |= PHY_M_AN_1000X_AFD;
2011 if (skge->advertising & ADVERTISED_1000baseT_Half)
2012 adv |= PHY_M_AN_1000X_AHD;
2013
2014 adv |= fiber_pause_map[skge->flow_control];
2015 }
Stephen Hemminger45bada62005-06-27 11:33:12 -07002016
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002017 /* Restart Auto-negotiation */
2018 ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG;
2019 } else {
2020 /* forced speed/duplex settings */
2021 ct1000 = PHY_M_1000C_MSE;
2022
2023 if (skge->duplex == DUPLEX_FULL)
2024 ctrl |= PHY_CT_DUP_MD;
2025
2026 switch (skge->speed) {
2027 case SPEED_1000:
2028 ctrl |= PHY_CT_SP1000;
2029 break;
2030 case SPEED_100:
2031 ctrl |= PHY_CT_SP100;
2032 break;
2033 }
2034
2035 ctrl |= PHY_CT_RESET;
2036 }
2037
Stephen Hemmingerc506a502005-06-27 11:33:09 -07002038 gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002039
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002040 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv);
2041 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002042
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002043 /* Enable phy interrupt on autonegotiation complete (or link up) */
2044 if (skge->autoneg == AUTONEG_ENABLE)
Stephen Hemminger4cde06e2005-07-22 16:26:09 -07002045 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002046 else
Stephen Hemminger4cde06e2005-07-22 16:26:09 -07002047 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002048}
2049
2050static void yukon_reset(struct skge_hw *hw, int port)
2051{
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002052 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);/* disable PHY IRQs */
2053 gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */
2054 gma_write16(hw, port, GM_MC_ADDR_H2, 0);
2055 gma_write16(hw, port, GM_MC_ADDR_H3, 0);
2056 gma_write16(hw, port, GM_MC_ADDR_H4, 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002057
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002058 gma_write16(hw, port, GM_RX_CTRL,
2059 gma_read16(hw, port, GM_RX_CTRL)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002060 | GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
2061}
2062
Stephen Hemmingerc8868612005-09-23 09:08:30 -07002063/* Apparently, early versions of Yukon-Lite had wrong chip_id? */
2064static int is_yukon_lite_a0(struct skge_hw *hw)
2065{
2066 u32 reg;
2067 int ret;
2068
2069 if (hw->chip_id != CHIP_ID_YUKON)
2070 return 0;
2071
2072 reg = skge_read32(hw, B2_FAR);
2073 skge_write8(hw, B2_FAR + 3, 0xff);
2074 ret = (skge_read8(hw, B2_FAR + 3) != 0);
2075 skge_write32(hw, B2_FAR, reg);
2076 return ret;
2077}
2078
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002079static void yukon_mac_init(struct skge_hw *hw, int port)
2080{
2081 struct skge_port *skge = netdev_priv(hw->dev[port]);
2082 int i;
2083 u32 reg;
2084 const u8 *addr = hw->dev[port]->dev_addr;
2085
2086 /* WA code for COMA mode -- set PHY reset */
2087 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002088 hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
2089 reg = skge_read32(hw, B2_GP_IO);
2090 reg |= GP_DIR_9 | GP_IO_9;
2091 skge_write32(hw, B2_GP_IO, reg);
2092 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002093
2094 /* hard reset */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002095 skge_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
2096 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002097
2098 /* WA code for COMA mode -- clear PHY reset */
2099 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002100 hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
2101 reg = skge_read32(hw, B2_GP_IO);
2102 reg |= GP_DIR_9;
2103 reg &= ~GP_IO_9;
2104 skge_write32(hw, B2_GP_IO, reg);
2105 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002106
2107 /* Set hardware config mode */
2108 reg = GPC_INT_POL_HI | GPC_DIS_FC | GPC_DIS_SLEEP |
2109 GPC_ENA_XC | GPC_ANEG_ADV_ALL_M | GPC_ENA_PAUSE;
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07002110 reg |= hw->copper ? GPC_HWCFG_GMII_COP : GPC_HWCFG_GMII_FIB;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002111
2112 /* Clear GMC reset */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002113 skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_SET);
2114 skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_CLR);
2115 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR);
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002116
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002117 if (skge->autoneg == AUTONEG_DISABLE) {
2118 reg = GM_GPCR_AU_ALL_DIS;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002119 gma_write16(hw, port, GM_GP_CTRL,
2120 gma_read16(hw, port, GM_GP_CTRL) | reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002121
2122 switch (skge->speed) {
2123 case SPEED_1000:
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002124 reg &= ~GM_GPCR_SPEED_100;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002125 reg |= GM_GPCR_SPEED_1000;
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002126 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002127 case SPEED_100:
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002128 reg &= ~GM_GPCR_SPEED_1000;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002129 reg |= GM_GPCR_SPEED_100;
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002130 break;
2131 case SPEED_10:
2132 reg &= ~(GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100);
2133 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002134 }
2135
2136 if (skge->duplex == DUPLEX_FULL)
2137 reg |= GM_GPCR_DUP_FULL;
2138 } else
2139 reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL;
Stephen Hemminger564f9ab2006-02-13 15:46:48 -08002140
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002141 switch (skge->flow_control) {
2142 case FLOW_MODE_NONE:
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002143 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002144 reg |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
2145 break;
2146 case FLOW_MODE_LOC_SEND:
2147 /* disable Rx flow-control */
2148 reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002149 break;
2150 case FLOW_MODE_SYMMETRIC:
2151 case FLOW_MODE_SYM_OR_REM:
2152 /* enable Tx & Rx flow-control */
2153 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002154 }
2155
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002156 gma_write16(hw, port, GM_GP_CTRL, reg);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002157 skge_read16(hw, SK_REG(port, GMAC_IRQ_SRC));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002158
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002159 yukon_init(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002160
2161 /* MIB clear */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002162 reg = gma_read16(hw, port, GM_PHY_ADDR);
2163 gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002164
2165 for (i = 0; i < GM_MIB_CNT_SIZE; i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002166 gma_read16(hw, port, GM_MIB_CNT_BASE + 8*i);
2167 gma_write16(hw, port, GM_PHY_ADDR, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002168
2169 /* transmit control */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002170 gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002171
2172 /* receive control reg: unicast + multicast + no FCS */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002173 gma_write16(hw, port, GM_RX_CTRL,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002174 GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA);
2175
2176 /* transmit flow control */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002177 gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002178
2179 /* transmit parameter */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002180 gma_write16(hw, port, GM_TX_PARAM,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002181 TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) |
2182 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) |
2183 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF));
2184
Stephen Hemminger44c7fcc2007-11-28 14:23:01 -08002185 /* configure the Serial Mode Register */
2186 reg = DATA_BLIND_VAL(DATA_BLIND_DEF)
2187 | GM_SMOD_VLAN_ENA
2188 | IPG_DATA_VAL(IPG_DATA_DEF);
2189
2190 if (hw->dev[port]->mtu > ETH_DATA_LEN)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002191 reg |= GM_SMOD_JUMBO_ENA;
2192
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002193 gma_write16(hw, port, GM_SERIAL_MODE, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002194
2195 /* physical address: used for pause frames */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002196 gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002197 /* virtual address for data */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002198 gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002199
2200 /* enable interrupt mask for counter overflows */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002201 gma_write16(hw, port, GM_TX_IRQ_MSK, 0);
2202 gma_write16(hw, port, GM_RX_IRQ_MSK, 0);
2203 gma_write16(hw, port, GM_TR_IRQ_MSK, 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002204
2205 /* Initialize Mac Fifo */
2206
2207 /* Configure Rx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002208 skge_write16(hw, SK_REG(port, RX_GMF_FL_MSK), RX_FF_FL_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002209 reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
Stephen Hemmingerc8868612005-09-23 09:08:30 -07002210
2211 /* disable Rx GMAC FIFO Flush for YUKON-Lite Rev. A0 only */
2212 if (is_yukon_lite_a0(hw))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002213 reg &= ~GMF_RX_F_FL_ON;
Stephen Hemmingerc8868612005-09-23 09:08:30 -07002214
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002215 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
2216 skge_write16(hw, SK_REG(port, RX_GMF_CTRL_T), reg);
Stephen Hemmingerc5923082005-08-16 14:01:02 -07002217 /*
2218 * because Pause Packet Truncation in GMAC is not working
2219 * we have to increase the Flush Threshold to 64 bytes
2220 * in order to flush pause packets in Rx FIFO on Yukon-1
2221 */
2222 skge_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF+1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002223
2224 /* Configure Tx MAC FIFO */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002225 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
2226 skge_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002227}
2228
Stephen Hemminger355ec572005-11-08 10:33:43 -08002229/* Go into power down mode */
2230static void yukon_suspend(struct skge_hw *hw, int port)
2231{
2232 u16 ctrl;
2233
2234 ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
2235 ctrl |= PHY_M_PC_POL_R_DIS;
2236 gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
2237
2238 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
2239 ctrl |= PHY_CT_RESET;
2240 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
2241
2242 /* switch IEEE compatible power down mode on */
2243 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
2244 ctrl |= PHY_CT_PDOWN;
2245 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
2246}
2247
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002248static void yukon_stop(struct skge_port *skge)
2249{
2250 struct skge_hw *hw = skge->hw;
2251 int port = skge->port;
2252
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002253 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
2254 yukon_reset(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002255
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002256 gma_write16(hw, port, GM_GP_CTRL,
2257 gma_read16(hw, port, GM_GP_CTRL)
Stephen Hemminger0eedf4a2005-07-22 16:26:04 -07002258 & ~(GM_GPCR_TX_ENA|GM_GPCR_RX_ENA));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002259 gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002260
Stephen Hemminger355ec572005-11-08 10:33:43 -08002261 yukon_suspend(hw, port);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002262
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002263 /* set GPHY Control reset */
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002264 skge_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
2265 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002266}
2267
2268static void yukon_get_stats(struct skge_port *skge, u64 *data)
2269{
2270 struct skge_hw *hw = skge->hw;
2271 int port = skge->port;
2272 int i;
2273
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002274 data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32
2275 | gma_read32(hw, port, GM_TXO_OK_LO);
2276 data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32
2277 | gma_read32(hw, port, GM_RXO_OK_LO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002278
2279 for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002280 data[i] = gma_read32(hw, port,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002281 skge_stats[i].gma_offset);
2282}
2283
2284static void yukon_mac_intr(struct skge_hw *hw, int port)
2285{
Stephen Hemminger7e676d92005-06-27 11:33:13 -07002286 struct net_device *dev = hw->dev[port];
2287 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002288 u8 status = skge_read8(hw, SK_REG(port, GMAC_IRQ_SRC));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002289
Joe Perchesd7072042010-02-09 11:49:53 +00002290 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
2291 "mac interrupt status 0x%x\n", status);
Stephen Hemminger7e676d92005-06-27 11:33:13 -07002292
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002293 if (status & GM_IS_RX_FF_OR) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07002294 ++dev->stats.rx_fifo_errors;
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002295 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002296 }
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002297
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002298 if (status & GM_IS_TX_FF_UR) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07002299 ++dev->stats.tx_fifo_errors;
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002300 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002301 }
2302
2303}
2304
2305static u16 yukon_speed(const struct skge_hw *hw, u16 aux)
2306{
Stephen Hemminger95566062005-06-27 11:33:02 -07002307 switch (aux & PHY_M_PS_SPEED_MSK) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002308 case PHY_M_PS_SPEED_1000:
2309 return SPEED_1000;
2310 case PHY_M_PS_SPEED_100:
2311 return SPEED_100;
2312 default:
2313 return SPEED_10;
2314 }
2315}
2316
2317static void yukon_link_up(struct skge_port *skge)
2318{
2319 struct skge_hw *hw = skge->hw;
2320 int port = skge->port;
2321 u16 reg;
2322
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002323 /* Enable Transmit FIFO Underrun */
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002324 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002325
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002326 reg = gma_read16(hw, port, GM_GP_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002327 if (skge->duplex == DUPLEX_FULL || skge->autoneg == AUTONEG_ENABLE)
2328 reg |= GM_GPCR_DUP_FULL;
2329
2330 /* enable Rx/Tx */
2331 reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA;
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002332 gma_write16(hw, port, GM_GP_CTRL, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002333
Stephen Hemminger4cde06e2005-07-22 16:26:09 -07002334 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002335 skge_link_up(skge);
2336}
2337
2338static void yukon_link_down(struct skge_port *skge)
2339{
2340 struct skge_hw *hw = skge->hw;
2341 int port = skge->port;
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002342 u16 ctrl;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002343
Stephen Hemmingerd8a09942005-07-22 16:26:08 -07002344 ctrl = gma_read16(hw, port, GM_GP_CTRL);
2345 ctrl &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
2346 gma_write16(hw, port, GM_GP_CTRL, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002347
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002348 if (skge->flow_status == FLOW_STAT_REM_SEND) {
2349 ctrl = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV);
2350 ctrl |= PHY_M_AN_ASP;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002351 /* restore Asymmetric Pause bit */
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002352 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, ctrl);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002353 }
2354
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002355 skge_link_down(skge);
2356
2357 yukon_init(hw, port);
2358}
2359
2360static void yukon_phy_intr(struct skge_port *skge)
2361{
2362 struct skge_hw *hw = skge->hw;
2363 int port = skge->port;
2364 const char *reason = NULL;
2365 u16 istatus, phystat;
2366
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002367 istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT);
2368 phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT);
Stephen Hemminger7e676d92005-06-27 11:33:13 -07002369
Joe Perchesd7072042010-02-09 11:49:53 +00002370 netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
2371 "phy interrupt status 0x%x 0x%x\n", istatus, phystat);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002372
2373 if (istatus & PHY_M_IS_AN_COMPL) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002374 if (gm_phy_read(hw, port, PHY_MARV_AUNE_LP)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002375 & PHY_M_AN_RF) {
2376 reason = "remote fault";
2377 goto failed;
2378 }
2379
Stephen Hemmingerc506a502005-06-27 11:33:09 -07002380 if (gm_phy_read(hw, port, PHY_MARV_1000T_STAT) & PHY_B_1000S_MSF) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002381 reason = "master/slave fault";
2382 goto failed;
2383 }
2384
2385 if (!(phystat & PHY_M_PS_SPDUP_RES)) {
2386 reason = "speed/duplex";
2387 goto failed;
2388 }
2389
2390 skge->duplex = (phystat & PHY_M_PS_FULL_DUP)
2391 ? DUPLEX_FULL : DUPLEX_HALF;
2392 skge->speed = yukon_speed(hw, phystat);
2393
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002394 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
2395 switch (phystat & PHY_M_PS_PAUSE_MSK) {
2396 case PHY_M_PS_PAUSE_MSK:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002397 skge->flow_status = FLOW_STAT_SYMMETRIC;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002398 break;
2399 case PHY_M_PS_RX_P_EN:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002400 skge->flow_status = FLOW_STAT_REM_SEND;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002401 break;
2402 case PHY_M_PS_TX_P_EN:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002403 skge->flow_status = FLOW_STAT_LOC_SEND;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002404 break;
2405 default:
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002406 skge->flow_status = FLOW_STAT_NONE;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002407 }
2408
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07002409 if (skge->flow_status == FLOW_STAT_NONE ||
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002410 (skge->speed < SPEED_1000 && skge->duplex == DUPLEX_HALF))
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002411 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002412 else
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002413 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002414 yukon_link_up(skge);
2415 return;
2416 }
2417
2418 if (istatus & PHY_M_IS_LSP_CHANGE)
2419 skge->speed = yukon_speed(hw, phystat);
2420
2421 if (istatus & PHY_M_IS_DUP_CHANGE)
2422 skge->duplex = (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
2423 if (istatus & PHY_M_IS_LST_CHANGE) {
2424 if (phystat & PHY_M_PS_LINK_UP)
2425 yukon_link_up(skge);
2426 else
2427 yukon_link_down(skge);
2428 }
2429 return;
2430 failed:
Joe Perchesf15063c2010-02-17 15:01:57 +00002431 pr_err("%s: autonegotiation failed (%s)\n", skge->netdev->name, reason);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002432
2433 /* XXX restart autonegotiation? */
2434}
2435
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002436static void skge_phy_reset(struct skge_port *skge)
2437{
2438 struct skge_hw *hw = skge->hw;
2439 int port = skge->port;
Jeff Garzikaae343d2006-12-02 07:14:39 -05002440 struct net_device *dev = hw->dev[port];
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002441
2442 netif_stop_queue(skge->netdev);
2443 netif_carrier_off(skge->netdev);
2444
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002445 spin_lock_bh(&hw->phy_lock);
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002446 if (hw->chip_id == CHIP_ID_GENESIS) {
2447 genesis_reset(hw, port);
2448 genesis_mac_init(hw, port);
2449 } else {
2450 yukon_reset(hw, port);
2451 yukon_init(hw, port);
2452 }
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002453 spin_unlock_bh(&hw->phy_lock);
Stephen Hemminger75814092006-12-01 11:41:08 -08002454
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08002455 skge_set_multicast(dev);
Stephen Hemmingeree294dc2005-12-14 15:47:44 -08002456}
2457
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002458/* Basic MII support */
2459static int skge_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2460{
2461 struct mii_ioctl_data *data = if_mii(ifr);
2462 struct skge_port *skge = netdev_priv(dev);
2463 struct skge_hw *hw = skge->hw;
2464 int err = -EOPNOTSUPP;
2465
2466 if (!netif_running(dev))
2467 return -ENODEV; /* Phy still in reset */
2468
2469 switch(cmd) {
2470 case SIOCGMIIPHY:
2471 data->phy_id = hw->phy_addr;
2472
2473 /* fallthru */
2474 case SIOCGMIIREG: {
2475 u16 val = 0;
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002476 spin_lock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002477 if (hw->chip_id == CHIP_ID_GENESIS)
2478 err = __xm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val);
2479 else
2480 err = __gm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002481 spin_unlock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002482 data->val_out = val;
2483 break;
2484 }
2485
2486 case SIOCSMIIREG:
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002487 spin_lock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002488 if (hw->chip_id == CHIP_ID_GENESIS)
2489 err = xm_phy_write(hw, skge->port, data->reg_num & 0x1f,
2490 data->val_in);
2491 else
2492 err = gm_phy_write(hw, skge->port, data->reg_num & 0x1f,
2493 data->val_in);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002494 spin_unlock_bh(&hw->phy_lock);
Stephen Hemminger2cd8e5d2005-11-08 10:33:42 -08002495 break;
2496 }
2497 return err;
2498}
2499
Linus Torvalds279e1da2007-11-15 08:44:36 -08002500static void skge_ramset(struct skge_hw *hw, u16 q, u32 start, size_t len)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002501{
2502 u32 end;
2503
Linus Torvalds279e1da2007-11-15 08:44:36 -08002504 start /= 8;
2505 len /= 8;
2506 end = start + len - 1;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002507
2508 skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR);
2509 skge_write32(hw, RB_ADDR(q, RB_START), start);
2510 skge_write32(hw, RB_ADDR(q, RB_WP), start);
2511 skge_write32(hw, RB_ADDR(q, RB_RP), start);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002512 skge_write32(hw, RB_ADDR(q, RB_END), end);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002513
2514 if (q == Q_R1 || q == Q_R2) {
2515 /* Set thresholds on receive queue's */
Linus Torvalds279e1da2007-11-15 08:44:36 -08002516 skge_write32(hw, RB_ADDR(q, RB_RX_UTPP),
2517 start + (2*len)/3);
2518 skge_write32(hw, RB_ADDR(q, RB_RX_LTPP),
2519 start + (len/3));
2520 } else {
2521 /* Enable store & forward on Tx queue's because
2522 * Tx FIFO is only 4K on Genesis and 1K on Yukon
2523 */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002524 skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002525 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002526
2527 skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD);
2528}
2529
2530/* Setup Bus Memory Interface */
2531static void skge_qset(struct skge_port *skge, u16 q,
2532 const struct skge_element *e)
2533{
2534 struct skge_hw *hw = skge->hw;
2535 u32 watermark = 0x600;
2536 u64 base = skge->dma + (e->desc - skge->mem);
2537
2538 /* optimization to reduce window on 32bit/33mhz */
2539 if ((skge_read16(hw, B0_CTST) & (CS_BUS_CLOCK | CS_BUS_SLOT_SZ)) == 0)
2540 watermark /= 2;
2541
2542 skge_write32(hw, Q_ADDR(q, Q_CSR), CSR_CLR_RESET);
2543 skge_write32(hw, Q_ADDR(q, Q_F), watermark);
2544 skge_write32(hw, Q_ADDR(q, Q_DA_H), (u32)(base >> 32));
2545 skge_write32(hw, Q_ADDR(q, Q_DA_L), (u32)base);
2546}
2547
2548static int skge_up(struct net_device *dev)
2549{
2550 struct skge_port *skge = netdev_priv(dev);
2551 struct skge_hw *hw = skge->hw;
2552 int port = skge->port;
Linus Torvalds279e1da2007-11-15 08:44:36 -08002553 u32 chunk, ram_addr;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002554 size_t rx_size, tx_size;
2555 int err;
2556
Stephen Hemmingerfae87592007-02-02 08:22:51 -08002557 if (!is_valid_ether_addr(dev->dev_addr))
2558 return -EINVAL;
2559
Joe Perchesd7072042010-02-09 11:49:53 +00002560 netif_info(skge, ifup, skge->netdev, "enabling interface\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002561
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002562 if (dev->mtu > RX_BUF_SIZE)
Stephen Hemminger901ccef2006-03-23 11:07:23 -08002563 skge->rx_buf_size = dev->mtu + ETH_HLEN;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002564 else
2565 skge->rx_buf_size = RX_BUF_SIZE;
2566
2567
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002568 rx_size = skge->rx_ring.count * sizeof(struct skge_rx_desc);
2569 tx_size = skge->tx_ring.count * sizeof(struct skge_tx_desc);
2570 skge->mem_size = tx_size + rx_size;
2571 skge->mem = pci_alloc_consistent(hw->pdev, skge->mem_size, &skge->dma);
2572 if (!skge->mem)
2573 return -ENOMEM;
2574
Stephen Hemmingerc3da1442006-03-21 10:57:01 -08002575 BUG_ON(skge->dma & 7);
2576
2577 if ((u64)skge->dma >> 32 != ((u64) skge->dma + skge->mem_size) >> 32) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08002578 dev_err(&hw->pdev->dev, "pci_alloc_consistent region crosses 4G boundary\n");
Stephen Hemmingerc3da1442006-03-21 10:57:01 -08002579 err = -EINVAL;
2580 goto free_pci_mem;
2581 }
2582
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002583 memset(skge->mem, 0, skge->mem_size);
2584
Stephen Hemminger203babb2006-03-21 10:57:05 -08002585 err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma);
2586 if (err)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002587 goto free_pci_mem;
2588
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07002589 err = skge_rx_fill(dev);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002590 if (err)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002591 goto free_rx_ring;
2592
Stephen Hemminger203babb2006-03-21 10:57:05 -08002593 err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size,
2594 skge->dma + rx_size);
2595 if (err)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002596 goto free_rx_ring;
2597
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08002598 /* Initialize MAC */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002599 spin_lock_bh(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002600 if (hw->chip_id == CHIP_ID_GENESIS)
2601 genesis_mac_init(hw, port);
2602 else
2603 yukon_mac_init(hw, port);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002604 spin_unlock_bh(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002605
Stephen Hemminger29816d92007-11-26 11:54:48 -08002606 /* Configure RAMbuffers - equally between ports and tx/rx */
2607 chunk = (hw->ram_size - hw->ram_offset) / (hw->ports * 2);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002608 ram_addr = hw->ram_offset + 2 * chunk * port;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002609
Linus Torvalds279e1da2007-11-15 08:44:36 -08002610 skge_ramset(hw, rxqaddr[port], ram_addr, chunk);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002611 skge_qset(skge, rxqaddr[port], skge->rx_ring.to_clean);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002612
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002613 BUG_ON(skge->tx_ring.to_use != skge->tx_ring.to_clean);
Linus Torvalds279e1da2007-11-15 08:44:36 -08002614 skge_ramset(hw, txqaddr[port], ram_addr+chunk, chunk);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002615 skge_qset(skge, txqaddr[port], skge->tx_ring.to_use);
2616
2617 /* Start receiver BMU */
2618 wmb();
2619 skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_START | CSR_IRQ_CL_F);
Stephen Hemminger6abebb52005-07-22 16:26:10 -07002620 skge_led(skge, LED_MODE_ON);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002621
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07002622 spin_lock_irq(&hw->hw_lock);
2623 hw->intr_mask |= portmask[port];
2624 skge_write32(hw, B0_IMSK, hw->intr_mask);
2625 spin_unlock_irq(&hw->hw_lock);
2626
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002627 napi_enable(&skge->napi);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002628 return 0;
2629
2630 free_rx_ring:
2631 skge_rx_clean(skge);
2632 kfree(skge->rx_ring.start);
2633 free_pci_mem:
2634 pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002635 skge->mem = NULL;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002636
2637 return err;
2638}
2639
Stephen Hemminger60b24b52007-10-16 12:15:50 -07002640/* stop receiver */
2641static void skge_rx_stop(struct skge_hw *hw, int port)
2642{
2643 skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_STOP);
2644 skge_write32(hw, RB_ADDR(port ? Q_R2 : Q_R1, RB_CTRL),
2645 RB_RST_SET|RB_DIS_OP_MD);
2646 skge_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_SET_RESET);
2647}
2648
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002649static int skge_down(struct net_device *dev)
2650{
2651 struct skge_port *skge = netdev_priv(dev);
2652 struct skge_hw *hw = skge->hw;
2653 int port = skge->port;
2654
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002655 if (skge->mem == NULL)
2656 return 0;
2657
Joe Perchesd7072042010-02-09 11:49:53 +00002658 netif_info(skge, ifdown, skge->netdev, "disabling interface\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002659
Michal Schmidtd119b392009-04-14 15:16:55 -07002660 netif_tx_disable(dev);
Stephen Hemminger692412b2007-04-09 15:32:45 -07002661
Stephen Hemminger64f6b642006-09-23 21:25:28 -07002662 if (hw->chip_id == CHIP_ID_GENESIS && hw->phy_type == SK_PHY_XMAC)
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07002663 del_timer_sync(&skge->link_timer);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002664
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002665 napi_disable(&skge->napi);
Stephen Hemminger692412b2007-04-09 15:32:45 -07002666 netif_carrier_off(dev);
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07002667
2668 spin_lock_irq(&hw->hw_lock);
2669 hw->intr_mask &= ~portmask[port];
2670 skge_write32(hw, B0_IMSK, hw->intr_mask);
2671 spin_unlock_irq(&hw->hw_lock);
2672
Stephen Hemminger46a60f22005-09-09 12:54:56 -07002673 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF);
2674 if (hw->chip_id == CHIP_ID_GENESIS)
2675 genesis_stop(skge);
2676 else
2677 yukon_stop(skge);
2678
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002679 /* Stop transmitter */
2680 skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP);
2681 skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL),
2682 RB_RST_SET|RB_DIS_OP_MD);
2683
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002684
2685 /* Disable Force Sync bit and Enable Alloc bit */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002686 skge_write8(hw, SK_REG(port, TXA_CTRL),
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002687 TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
2688
2689 /* Stop Interval Timer and Limit Counter of Tx Arbiter */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002690 skge_write32(hw, SK_REG(port, TXA_ITI_INI), 0L);
2691 skge_write32(hw, SK_REG(port, TXA_LIM_INI), 0L);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002692
2693 /* Reset PCI FIFO */
2694 skge_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_SET_RESET);
2695 skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET);
2696
2697 /* Reset the RAM Buffer async Tx queue */
2698 skge_write8(hw, RB_ADDR(port == 0 ? Q_XA1 : Q_XA2, RB_CTRL), RB_RST_SET);
Stephen Hemminger60b24b52007-10-16 12:15:50 -07002699
2700 skge_rx_stop(hw, port);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002701
2702 if (hw->chip_id == CHIP_ID_GENESIS) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002703 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_SET);
2704 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002705 } else {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002706 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
2707 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002708 }
2709
Stephen Hemminger6abebb52005-07-22 16:26:10 -07002710 skge_led(skge, LED_MODE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002711
Stephen Hemmingere3a1b992007-03-16 14:01:26 -07002712 netif_tx_lock_bh(dev);
Stephen Hemminger513f5332006-09-01 15:53:49 -07002713 skge_tx_clean(dev);
Stephen Hemmingere3a1b992007-03-16 14:01:26 -07002714 netif_tx_unlock_bh(dev);
2715
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002716 skge_rx_clean(skge);
2717
2718 kfree(skge->rx_ring.start);
2719 kfree(skge->tx_ring.start);
2720 pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002721 skge->mem = NULL;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002722 return 0;
2723}
2724
Stephen Hemminger29b4e882006-03-23 11:07:28 -08002725static inline int skge_avail(const struct skge_ring *ring)
2726{
Stephen Hemminger992c9622007-03-16 14:01:30 -07002727 smp_mb();
Stephen Hemminger29b4e882006-03-23 11:07:28 -08002728 return ((ring->to_clean > ring->to_use) ? 0 : ring->count)
2729 + (ring->to_clean - ring->to_use) - 1;
2730}
2731
Stephen Hemminger613573252009-08-31 19:50:58 +00002732static netdev_tx_t skge_xmit_frame(struct sk_buff *skb,
2733 struct net_device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002734{
2735 struct skge_port *skge = netdev_priv(dev);
2736 struct skge_hw *hw = skge->hw;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002737 struct skge_element *e;
2738 struct skge_tx_desc *td;
2739 int i;
2740 u32 control, len;
2741 u64 map;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002742
Herbert Xu5b057c62006-06-23 02:06:41 -07002743 if (skb_padto(skb, ETH_ZLEN))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002744 return NETDEV_TX_OK;
2745
Stephen Hemminger513f5332006-09-01 15:53:49 -07002746 if (unlikely(skge_avail(&skge->tx_ring) < skb_shinfo(skb)->nr_frags + 1))
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002747 return NETDEV_TX_BUSY;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002748
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002749 e = skge->tx_ring.to_use;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002750 td = e->desc;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002751 BUG_ON(td->control & BMU_OWN);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002752 e->skb = skb;
2753 len = skb_headlen(skb);
2754 map = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE);
2755 pci_unmap_addr_set(e, mapaddr, map);
2756 pci_unmap_len_set(e, maplen, len);
2757
2758 td->dma_lo = map;
2759 td->dma_hi = map >> 32;
2760
Patrick McHardy84fa7932006-08-29 16:44:56 -07002761 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002762 const int offset = skb_transport_offset(skb);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002763
2764 /* This seems backwards, but it is what the sk98lin
2765 * does. Looks like hardware is wrong?
2766 */
Joe Perches8e95a202009-12-03 07:58:21 +00002767 if (ipip_hdr(skb)->protocol == IPPROTO_UDP &&
2768 hw->chip_rev == 0 && hw->chip_id == CHIP_ID_YUKON)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002769 control = BMU_TCP_CHECK;
2770 else
2771 control = BMU_UDP_CHECK;
2772
2773 td->csum_offs = 0;
2774 td->csum_start = offset;
Al Viroff1dcad2006-11-20 18:07:29 -08002775 td->csum_write = offset + skb->csum_offset;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002776 } else
2777 control = BMU_CHECK;
2778
2779 if (!skb_shinfo(skb)->nr_frags) /* single buffer i.e. no fragments */
2780 control |= BMU_EOF| BMU_IRQ_EOF;
2781 else {
2782 struct skge_tx_desc *tf = td;
2783
2784 control |= BMU_STFWD;
2785 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2786 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2787
2788 map = pci_map_page(hw->pdev, frag->page, frag->page_offset,
2789 frag->size, PCI_DMA_TODEVICE);
2790
2791 e = e->next;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002792 e->skb = skb;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002793 tf = e->desc;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002794 BUG_ON(tf->control & BMU_OWN);
2795
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002796 tf->dma_lo = map;
2797 tf->dma_hi = (u64) map >> 32;
2798 pci_unmap_addr_set(e, mapaddr, map);
2799 pci_unmap_len_set(e, maplen, frag->size);
2800
2801 tf->control = BMU_OWN | BMU_SW | control | frag->size;
2802 }
2803 tf->control |= BMU_EOF | BMU_IRQ_EOF;
2804 }
2805 /* Make sure all the descriptors written */
2806 wmb();
2807 td->control = BMU_OWN | BMU_SW | BMU_STF | control | len;
2808 wmb();
2809
2810 skge_write8(hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_START);
2811
Joe Perchesd7072042010-02-09 11:49:53 +00002812 netif_printk(skge, tx_queued, KERN_DEBUG, skge->netdev,
2813 "tx queued, slot %td, len %d\n",
2814 e - skge->tx_ring.start, skb->len);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002815
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002816 skge->tx_ring.to_use = e->next;
Stephen Hemminger992c9622007-03-16 14:01:30 -07002817 smp_wmb();
2818
Stephen Hemminger9db96472006-06-06 10:11:12 -07002819 if (skge_avail(&skge->tx_ring) <= TX_LOW_WATER) {
Joe Perchesf15063c2010-02-17 15:01:57 +00002820 netdev_dbg(dev, "transmit queue full\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002821 netif_stop_queue(dev);
2822 }
2823
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002824 return NETDEV_TX_OK;
2825}
2826
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002827
2828/* Free resources associated with this reing element */
2829static void skge_tx_free(struct skge_port *skge, struct skge_element *e,
2830 u32 control)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002831{
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002832 struct pci_dev *pdev = skge->hw->pdev;
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002833
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002834 /* skb header vs. fragment */
2835 if (control & BMU_STF)
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002836 pci_unmap_single(pdev, pci_unmap_addr(e, mapaddr),
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002837 pci_unmap_len(e, maplen),
2838 PCI_DMA_TODEVICE);
2839 else
2840 pci_unmap_page(pdev, pci_unmap_addr(e, mapaddr),
2841 pci_unmap_len(e, maplen),
2842 PCI_DMA_TODEVICE);
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002843
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002844 if (control & BMU_EOF) {
Joe Perchesd7072042010-02-09 11:49:53 +00002845 netif_printk(skge, tx_done, KERN_DEBUG, skge->netdev,
2846 "tx done slot %td\n", e - skge->tx_ring.start);
Stephen Hemminger866b4f32006-03-23 11:07:27 -08002847
Stephen Hemminger513f5332006-09-01 15:53:49 -07002848 dev_kfree_skb(e->skb);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002849 }
2850}
2851
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002852/* Free all buffers in transmit ring */
Stephen Hemminger513f5332006-09-01 15:53:49 -07002853static void skge_tx_clean(struct net_device *dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002854{
Stephen Hemminger513f5332006-09-01 15:53:49 -07002855 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002856 struct skge_element *e;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002857
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07002858 for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) {
2859 struct skge_tx_desc *td = e->desc;
2860 skge_tx_free(skge, e, td->control);
2861 td->control = 0;
2862 }
2863
2864 skge->tx_ring.to_clean = e;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002865}
2866
2867static void skge_tx_timeout(struct net_device *dev)
2868{
2869 struct skge_port *skge = netdev_priv(dev);
2870
Joe Perchesd7072042010-02-09 11:49:53 +00002871 netif_printk(skge, timer, KERN_DEBUG, skge->netdev, "tx timeout\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002872
2873 skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_STOP);
Stephen Hemminger513f5332006-09-01 15:53:49 -07002874 skge_tx_clean(dev);
Michal Schmidtd119b392009-04-14 15:16:55 -07002875 netif_wake_queue(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002876}
2877
2878static int skge_change_mtu(struct net_device *dev, int new_mtu)
2879{
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002880 int err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002881
Stephen Hemminger95566062005-06-27 11:33:02 -07002882 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002883 return -EINVAL;
2884
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002885 if (!netif_running(dev)) {
2886 dev->mtu = new_mtu;
2887 return 0;
2888 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002889
Stephen Hemminger1a8098b2007-11-28 14:25:05 -08002890 skge_down(dev);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002891
Stephen Hemminger19a33d42005-06-27 11:33:15 -07002892 dev->mtu = new_mtu;
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002893
Stephen Hemminger1a8098b2007-11-28 14:25:05 -08002894 err = skge_up(dev);
Stephen Hemminger7731a4e2005-12-14 15:47:46 -08002895 if (err)
2896 dev_close(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002897
2898 return err;
2899}
2900
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002901static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 };
2902
2903static void genesis_add_filter(u8 filter[8], const u8 *addr)
2904{
2905 u32 crc, bit;
2906
2907 crc = ether_crc_le(ETH_ALEN, addr);
2908 bit = ~crc & 0x3f;
2909 filter[bit/8] |= 1 << (bit%8);
2910}
2911
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002912static void genesis_set_multicast(struct net_device *dev)
2913{
2914 struct skge_port *skge = netdev_priv(dev);
2915 struct skge_hw *hw = skge->hw;
2916 int port = skge->port;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002917 int i, count = netdev_mc_count(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002918 struct dev_mc_list *list = dev->mc_list;
2919 u32 mode;
2920 u8 filter[8];
2921
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002922 mode = xm_read32(hw, port, XM_MODE);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002923 mode |= XM_MD_ENA_HASH;
2924 if (dev->flags & IFF_PROMISC)
2925 mode |= XM_MD_ENA_PROM;
2926 else
2927 mode &= ~XM_MD_ENA_PROM;
2928
2929 if (dev->flags & IFF_ALLMULTI)
2930 memset(filter, 0xff, sizeof(filter));
2931 else {
2932 memset(filter, 0, sizeof(filter));
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002933
Joe Perches8e95a202009-12-03 07:58:21 +00002934 if (skge->flow_status == FLOW_STAT_REM_SEND ||
2935 skge->flow_status == FLOW_STAT_SYMMETRIC)
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002936 genesis_add_filter(filter, pause_mc_addr);
2937
2938 for (i = 0; list && i < count; i++, list = list->next)
2939 genesis_add_filter(filter, list->dmi_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002940 }
2941
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002942 xm_write32(hw, port, XM_MODE, mode);
Stephen Hemminger45bada62005-06-27 11:33:12 -07002943 xm_outhash(hw, port, XM_HSM, filter);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002944}
2945
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002946static void yukon_add_filter(u8 filter[8], const u8 *addr)
2947{
2948 u32 bit = ether_crc(ETH_ALEN, addr) & 0x3f;
2949 filter[bit/8] |= 1 << (bit%8);
2950}
2951
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002952static void yukon_set_multicast(struct net_device *dev)
2953{
2954 struct skge_port *skge = netdev_priv(dev);
2955 struct skge_hw *hw = skge->hw;
2956 int port = skge->port;
2957 struct dev_mc_list *list = dev->mc_list;
Joe Perches8e95a202009-12-03 07:58:21 +00002958 int rx_pause = (skge->flow_status == FLOW_STAT_REM_SEND ||
2959 skge->flow_status == FLOW_STAT_SYMMETRIC);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002960 u16 reg;
2961 u8 filter[8];
2962
2963 memset(filter, 0, sizeof(filter));
2964
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002965 reg = gma_read16(hw, port, GM_RX_CTRL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002966 reg |= GM_RXCR_UCF_ENA;
2967
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08002968 if (dev->flags & IFF_PROMISC) /* promiscuous */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002969 reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
2970 else if (dev->flags & IFF_ALLMULTI) /* all multicast */
2971 memset(filter, 0xff, sizeof(filter));
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002972 else if (netdev_mc_empty(dev) && !rx_pause)/* no multicast */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002973 reg &= ~GM_RXCR_MCF_ENA;
2974 else {
2975 int i;
2976 reg |= GM_RXCR_MCF_ENA;
2977
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002978 if (rx_pause)
2979 yukon_add_filter(filter, pause_mc_addr);
2980
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002981 for (i = 0; list && i < netdev_mc_count(dev); i++, list = list->next)
Stephen Hemmingerc4cd29d2007-02-23 14:03:00 -08002982 yukon_add_filter(filter, list->dmi_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002983 }
2984
2985
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002986 gma_write16(hw, port, GM_MC_ADDR_H1,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002987 (u16)filter[0] | ((u16)filter[1] << 8));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002988 gma_write16(hw, port, GM_MC_ADDR_H2,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002989 (u16)filter[2] | ((u16)filter[3] << 8));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002990 gma_write16(hw, port, GM_MC_ADDR_H3,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002991 (u16)filter[4] | ((u16)filter[5] << 8));
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002992 gma_write16(hw, port, GM_MC_ADDR_H4,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002993 (u16)filter[6] | ((u16)filter[7] << 8));
2994
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07002995 gma_write16(hw, port, GM_RX_CTRL, reg);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04002996}
2997
Stephen Hemminger383181a2005-09-19 15:37:16 -07002998static inline u16 phy_length(const struct skge_hw *hw, u32 status)
2999{
3000 if (hw->chip_id == CHIP_ID_GENESIS)
3001 return status >> XMR_FS_LEN_SHIFT;
3002 else
3003 return status >> GMR_FS_LEN_SHIFT;
3004}
3005
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003006static inline int bad_phy_status(const struct skge_hw *hw, u32 status)
3007{
3008 if (hw->chip_id == CHIP_ID_GENESIS)
3009 return (status & (XMR_FS_ERR | XMR_FS_2L_VLAN)) != 0;
3010 else
3011 return (status & GMR_FS_ANY_ERR) ||
3012 (status & GMR_FS_RX_OK) == 0;
3013}
3014
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003015static void skge_set_multicast(struct net_device *dev)
3016{
3017 struct skge_port *skge = netdev_priv(dev);
3018 struct skge_hw *hw = skge->hw;
3019
3020 if (hw->chip_id == CHIP_ID_GENESIS)
3021 genesis_set_multicast(dev);
3022 else
3023 yukon_set_multicast(dev);
3024
3025}
3026
Stephen Hemminger383181a2005-09-19 15:37:16 -07003027
3028/* Get receive buffer from descriptor.
3029 * Handles copy of small buffers and reallocation failures
3030 */
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003031static struct sk_buff *skge_rx_get(struct net_device *dev,
3032 struct skge_element *e,
3033 u32 control, u32 status, u16 csum)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003034{
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003035 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003036 struct sk_buff *skb;
3037 u16 len = control & BMU_BBC;
3038
Joe Perchesd7072042010-02-09 11:49:53 +00003039 netif_printk(skge, rx_status, KERN_DEBUG, skge->netdev,
3040 "rx slot %td status 0x%x len %d\n",
3041 e - skge->rx_ring.start, status, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003042
3043 if (len > skge->rx_buf_size)
3044 goto error;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003045
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003046 if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF))
Stephen Hemminger383181a2005-09-19 15:37:16 -07003047 goto error;
3048
3049 if (bad_phy_status(skge->hw, status))
3050 goto error;
3051
3052 if (phy_length(skge->hw, status) != len)
3053 goto error;
3054
3055 if (len < RX_COPY_THRESHOLD) {
Eric Dumazet89d71a62009-10-13 05:34:20 +00003056 skb = netdev_alloc_skb_ip_align(dev, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003057 if (!skb)
3058 goto resubmit;
3059
Stephen Hemminger383181a2005-09-19 15:37:16 -07003060 pci_dma_sync_single_for_cpu(skge->hw->pdev,
3061 pci_unmap_addr(e, mapaddr),
3062 len, PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03003063 skb_copy_from_linear_data(e->skb, skb->data, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003064 pci_dma_sync_single_for_device(skge->hw->pdev,
3065 pci_unmap_addr(e, mapaddr),
3066 len, PCI_DMA_FROMDEVICE);
3067 skge_rx_reuse(e, skge->rx_buf_size);
3068 } else {
3069 struct sk_buff *nskb;
Eric Dumazet89d71a62009-10-13 05:34:20 +00003070
3071 nskb = netdev_alloc_skb_ip_align(dev, skge->rx_buf_size);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003072 if (!nskb)
3073 goto resubmit;
3074
3075 pci_unmap_single(skge->hw->pdev,
3076 pci_unmap_addr(e, mapaddr),
3077 pci_unmap_len(e, maplen),
3078 PCI_DMA_FROMDEVICE);
3079 skb = e->skb;
3080 prefetch(skb->data);
3081 skge_rx_setup(skge, e, nskb, skge->rx_buf_size);
3082 }
3083
3084 skb_put(skb, len);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003085 if (skge->rx_csum) {
3086 skb->csum = csum;
Patrick McHardy84fa7932006-08-29 16:44:56 -07003087 skb->ip_summed = CHECKSUM_COMPLETE;
Stephen Hemminger383181a2005-09-19 15:37:16 -07003088 }
3089
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003090 skb->protocol = eth_type_trans(skb, dev);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003091
3092 return skb;
3093error:
3094
Joe Perchesd7072042010-02-09 11:49:53 +00003095 netif_printk(skge, rx_err, KERN_DEBUG, skge->netdev,
3096 "rx err, slot %td control 0x%x status 0x%x\n",
3097 e - skge->rx_ring.start, control, status);
Stephen Hemminger383181a2005-09-19 15:37:16 -07003098
3099 if (skge->hw->chip_id == CHIP_ID_GENESIS) {
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003100 if (status & (XMR_FS_RUNT|XMR_FS_LNG_ERR))
Stephen Hemmingerda007722007-10-16 12:15:52 -07003101 dev->stats.rx_length_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003102 if (status & XMR_FS_FRA_ERR)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003103 dev->stats.rx_frame_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003104 if (status & XMR_FS_FCS_ERR)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003105 dev->stats.rx_crc_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003106 } else {
3107 if (status & (GMR_FS_LONG_ERR|GMR_FS_UN_SIZE))
Stephen Hemmingerda007722007-10-16 12:15:52 -07003108 dev->stats.rx_length_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003109 if (status & GMR_FS_FRAGMENT)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003110 dev->stats.rx_frame_errors++;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003111 if (status & GMR_FS_CRC_ERR)
Stephen Hemmingerda007722007-10-16 12:15:52 -07003112 dev->stats.rx_crc_errors++;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003113 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003114
Stephen Hemminger383181a2005-09-19 15:37:16 -07003115resubmit:
3116 skge_rx_reuse(e, skge->rx_buf_size);
3117 return NULL;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003118}
3119
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003120/* Free all buffers in Tx ring which are no longer owned by device */
Stephen Hemminger513f5332006-09-01 15:53:49 -07003121static void skge_tx_done(struct net_device *dev)
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003122{
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003123 struct skge_port *skge = netdev_priv(dev);
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003124 struct skge_ring *ring = &skge->tx_ring;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003125 struct skge_element *e;
3126
Stephen Hemminger513f5332006-09-01 15:53:49 -07003127 skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F);
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003128
Stephen Hemminger866b4f32006-03-23 11:07:27 -08003129 for (e = ring->to_clean; e != ring->to_use; e = e->next) {
Stephen Hemminger992c9622007-03-16 14:01:30 -07003130 u32 control = ((const struct skge_tx_desc *) e->desc)->control;
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003131
Stephen Hemminger992c9622007-03-16 14:01:30 -07003132 if (control & BMU_OWN)
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003133 break;
3134
Stephen Hemminger992c9622007-03-16 14:01:30 -07003135 skge_tx_free(skge, e, control);
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003136 }
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003137 skge->tx_ring.to_clean = e;
Stephen Hemminger866b4f32006-03-23 11:07:27 -08003138
Stephen Hemminger992c9622007-03-16 14:01:30 -07003139 /* Can run lockless until we need to synchronize to restart queue. */
3140 smp_mb();
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003141
Stephen Hemminger992c9622007-03-16 14:01:30 -07003142 if (unlikely(netif_queue_stopped(dev) &&
3143 skge_avail(&skge->tx_ring) > TX_LOW_WATER)) {
3144 netif_tx_lock(dev);
3145 if (unlikely(netif_queue_stopped(dev) &&
3146 skge_avail(&skge->tx_ring) > TX_LOW_WATER)) {
3147 netif_wake_queue(dev);
3148
3149 }
3150 netif_tx_unlock(dev);
3151 }
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003152}
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003153
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003154static int skge_poll(struct napi_struct *napi, int to_do)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003155{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003156 struct skge_port *skge = container_of(napi, struct skge_port, napi);
3157 struct net_device *dev = skge->netdev;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003158 struct skge_hw *hw = skge->hw;
3159 struct skge_ring *ring = &skge->rx_ring;
3160 struct skge_element *e;
Stephen Hemminger00a6cae2006-03-21 10:56:59 -08003161 int work_done = 0;
3162
Stephen Hemminger513f5332006-09-01 15:53:49 -07003163 skge_tx_done(dev);
3164
3165 skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F);
3166
Stephen Hemminger1631aef2005-11-08 10:33:44 -08003167 for (e = ring->to_clean; prefetch(e->next), work_done < to_do; e = e->next) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003168 struct skge_rx_desc *rd = e->desc;
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003169 struct sk_buff *skb;
Stephen Hemminger383181a2005-09-19 15:37:16 -07003170 u32 control;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003171
3172 rmb();
3173 control = rd->control;
3174 if (control & BMU_OWN)
3175 break;
3176
Stephen Hemmingerc54f9762006-09-01 15:53:47 -07003177 skb = skge_rx_get(dev, e, control, rd->status, rd->csum2);
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003178 if (likely(skb)) {
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003179 netif_receive_skb(skb);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003180
Stephen Hemminger19a33d42005-06-27 11:33:15 -07003181 ++work_done;
Stephen Hemminger5a011442006-03-23 11:07:25 -08003182 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003183 }
3184 ring->to_clean = e;
3185
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003186 /* restart receiver */
3187 wmb();
Stephen Hemmingera9cdab82006-02-22 10:28:33 -08003188 skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_START);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003189
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003190 if (work_done < to_do) {
Marin Mitov6ef29772008-03-23 10:20:09 +02003191 unsigned long flags;
Jeff Garzikf0c88f92008-03-25 23:53:24 -04003192
Marin Mitov6ef29772008-03-23 10:20:09 +02003193 spin_lock_irqsave(&hw->hw_lock, flags);
Ben Hutchings288379f2009-01-19 16:43:59 -08003194 __napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003195 hw->intr_mask |= napimask[skge->port];
3196 skge_write32(hw, B0_IMSK, hw->intr_mask);
3197 skge_read32(hw, B0_IMSK);
Marin Mitov6ef29772008-03-23 10:20:09 +02003198 spin_unlock_irqrestore(&hw->hw_lock, flags);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003199 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003200
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003201 return work_done;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003202}
3203
Stephen Hemmingerf6620ca2005-07-22 16:26:02 -07003204/* Parity errors seem to happen when Genesis is connected to a switch
3205 * with no other ports present. Heartbeat error??
3206 */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003207static void skge_mac_parity(struct skge_hw *hw, int port)
3208{
Stephen Hemmingerf6620ca2005-07-22 16:26:02 -07003209 struct net_device *dev = hw->dev[port];
3210
Stephen Hemmingerda007722007-10-16 12:15:52 -07003211 ++dev->stats.tx_heartbeat_errors;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003212
3213 if (hw->chip_id == CHIP_ID_GENESIS)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003214 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1),
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003215 MFF_CLR_PERR);
3216 else
3217 /* HW-Bug #8: cleared by GMF_CLI_TX_FC instead of GMF_CLI_TX_PE */
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003218 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T),
Stephen Hemminger981d0372005-06-27 11:33:06 -07003219 (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003220 ? GMF_CLI_TX_FC : GMF_CLI_TX_PE);
3221}
3222
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003223static void skge_mac_intr(struct skge_hw *hw, int port)
3224{
Stephen Hemminger95566062005-06-27 11:33:02 -07003225 if (hw->chip_id == CHIP_ID_GENESIS)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003226 genesis_mac_intr(hw, port);
3227 else
3228 yukon_mac_intr(hw, port);
3229}
3230
3231/* Handle device specific framing and timeout interrupts */
3232static void skge_error_irq(struct skge_hw *hw)
3233{
Stephen Hemminger1479d132007-02-02 08:22:52 -08003234 struct pci_dev *pdev = hw->pdev;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003235 u32 hwstatus = skge_read32(hw, B0_HWE_ISRC);
3236
3237 if (hw->chip_id == CHIP_ID_GENESIS) {
3238 /* clear xmac errors */
3239 if (hwstatus & (IS_NO_STAT_M1|IS_NO_TIST_M1))
Stephen Hemminger46a60f22005-09-09 12:54:56 -07003240 skge_write16(hw, RX_MFF_CTRL1, MFF_CLR_INSTAT);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003241 if (hwstatus & (IS_NO_STAT_M2|IS_NO_TIST_M2))
Stephen Hemminger46a60f22005-09-09 12:54:56 -07003242 skge_write16(hw, RX_MFF_CTRL2, MFF_CLR_INSTAT);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003243 } else {
3244 /* Timestamp (unused) overflow */
3245 if (hwstatus & IS_IRQ_TIST_OV)
3246 skge_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003247 }
3248
3249 if (hwstatus & IS_RAM_RD_PAR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003250 dev_err(&pdev->dev, "Ram read data parity error\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003251 skge_write16(hw, B3_RI_CTRL, RI_CLR_RD_PERR);
3252 }
3253
3254 if (hwstatus & IS_RAM_WR_PAR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003255 dev_err(&pdev->dev, "Ram write data parity error\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003256 skge_write16(hw, B3_RI_CTRL, RI_CLR_WR_PERR);
3257 }
3258
3259 if (hwstatus & IS_M1_PAR_ERR)
3260 skge_mac_parity(hw, 0);
3261
3262 if (hwstatus & IS_M2_PAR_ERR)
3263 skge_mac_parity(hw, 1);
3264
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003265 if (hwstatus & IS_R1_PAR_ERR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003266 dev_err(&pdev->dev, "%s: receive queue parity error\n",
3267 hw->dev[0]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003268 skge_write32(hw, B0_R1_CSR, CSR_IRQ_CL_P);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003269 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003270
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003271 if (hwstatus & IS_R2_PAR_ERR) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003272 dev_err(&pdev->dev, "%s: receive queue parity error\n",
3273 hw->dev[1]->name);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003274 skge_write32(hw, B0_R2_CSR, CSR_IRQ_CL_P);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003275 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003276
3277 if (hwstatus & (IS_IRQ_MST_ERR|IS_IRQ_STAT)) {
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003278 u16 pci_status, pci_cmd;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003279
Stephen Hemminger1479d132007-02-02 08:22:52 -08003280 pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
3281 pci_read_config_word(pdev, PCI_STATUS, &pci_status);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003282
Stephen Hemminger1479d132007-02-02 08:22:52 -08003283 dev_err(&pdev->dev, "PCI error cmd=%#x status=%#x\n",
3284 pci_cmd, pci_status);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003285
3286 /* Write the error bits back to clear them. */
3287 pci_status &= PCI_STATUS_ERROR_BITS;
3288 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
Stephen Hemminger1479d132007-02-02 08:22:52 -08003289 pci_write_config_word(pdev, PCI_COMMAND,
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003290 pci_cmd | PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
Stephen Hemminger1479d132007-02-02 08:22:52 -08003291 pci_write_config_word(pdev, PCI_STATUS, pci_status);
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003292 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003293
Stephen Hemminger050ec182005-08-16 14:00:54 -07003294 /* if error still set then just ignore it */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003295 hwstatus = skge_read32(hw, B0_HWE_ISRC);
3296 if (hwstatus & IS_IRQ_STAT) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003297 dev_warn(&hw->pdev->dev, "unable to clear error (so ignoring them)\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003298 hw->intr_mask &= ~IS_HW_ERR;
3299 }
3300 }
3301}
3302
3303/*
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003304 * Interrupt from PHY are handled in tasklet (softirq)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003305 * because accessing phy registers requires spin wait which might
3306 * cause excess interrupt latency.
3307 */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003308static void skge_extirq(unsigned long arg)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003309{
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003310 struct skge_hw *hw = (struct skge_hw *) arg;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003311 int port;
3312
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003313 for (port = 0; port < hw->ports; port++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003314 struct net_device *dev = hw->dev[port];
3315
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003316 if (netif_running(dev)) {
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003317 struct skge_port *skge = netdev_priv(dev);
3318
3319 spin_lock(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003320 if (hw->chip_id != CHIP_ID_GENESIS)
3321 yukon_phy_intr(skge);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003322 else if (hw->phy_type == SK_PHY_BCOM)
Stephen Hemminger45bada62005-06-27 11:33:12 -07003323 bcom_phy_intr(skge);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003324 spin_unlock(&hw->phy_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003325 }
3326 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003327
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003328 spin_lock_irq(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003329 hw->intr_mask |= IS_EXT_REG;
3330 skge_write32(hw, B0_IMSK, hw->intr_mask);
Stephen Hemminger78bc2182006-08-28 16:19:36 -07003331 skge_read32(hw, B0_IMSK);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003332 spin_unlock_irq(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003333}
3334
David Howells7d12e782006-10-05 14:55:46 +01003335static irqreturn_t skge_intr(int irq, void *dev_id)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003336{
3337 struct skge_hw *hw = dev_id;
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003338 u32 status;
Stephen Hemminger29365c92006-09-01 15:53:48 -07003339 int handled = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003340
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003341 spin_lock(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003342 /* Reading this register masks IRQ */
3343 status = skge_read32(hw, B0_SP_ISRC);
Stephen Hemminger0486a8c2006-09-06 11:06:10 -07003344 if (status == 0 || status == ~0)
Stephen Hemminger29365c92006-09-01 15:53:48 -07003345 goto out;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003346
Stephen Hemminger29365c92006-09-01 15:53:48 -07003347 handled = 1;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003348 status &= hw->intr_mask;
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003349 if (status & IS_EXT_REG) {
3350 hw->intr_mask &= ~IS_EXT_REG;
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003351 tasklet_schedule(&hw->phy_task);
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003352 }
3353
Stephen Hemminger513f5332006-09-01 15:53:49 -07003354 if (status & (IS_XA1_F|IS_R1_F)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003355 struct skge_port *skge = netdev_priv(hw->dev[0]);
Stephen Hemminger513f5332006-09-01 15:53:49 -07003356 hw->intr_mask &= ~(IS_XA1_F|IS_R1_F);
Ben Hutchings288379f2009-01-19 16:43:59 -08003357 napi_schedule(&skge->napi);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003358 }
3359
Stephen Hemmingerd25f5a62005-06-27 11:33:14 -07003360 if (status & IS_PA_TO_TX1)
3361 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX1);
3362
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003363 if (status & IS_PA_TO_RX1) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07003364 ++hw->dev[0]->stats.rx_over_errors;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003365 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX1);
3366 }
3367
Stephen Hemmingerd25f5a62005-06-27 11:33:14 -07003368
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003369 if (status & IS_MAC1)
3370 skge_mac_intr(hw, 0);
Stephen Hemminger95566062005-06-27 11:33:02 -07003371
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003372 if (hw->dev[1]) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003373 struct skge_port *skge = netdev_priv(hw->dev[1]);
3374
Stephen Hemminger513f5332006-09-01 15:53:49 -07003375 if (status & (IS_XA2_F|IS_R2_F)) {
3376 hw->intr_mask &= ~(IS_XA2_F|IS_R2_F);
Ben Hutchings288379f2009-01-19 16:43:59 -08003377 napi_schedule(&skge->napi);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003378 }
3379
3380 if (status & IS_PA_TO_RX2) {
Stephen Hemmingerda007722007-10-16 12:15:52 -07003381 ++hw->dev[1]->stats.rx_over_errors;
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003382 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX2);
3383 }
3384
3385 if (status & IS_PA_TO_TX2)
3386 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX2);
3387
3388 if (status & IS_MAC2)
3389 skge_mac_intr(hw, 1);
3390 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003391
3392 if (status & IS_HW_ERR)
3393 skge_error_irq(hw);
3394
Stephen Hemminger7e676d92005-06-27 11:33:13 -07003395 skge_write32(hw, B0_IMSK, hw->intr_mask);
Stephen Hemminger78bc2182006-08-28 16:19:36 -07003396 skge_read32(hw, B0_IMSK);
Stephen Hemminger29365c92006-09-01 15:53:48 -07003397out:
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07003398 spin_unlock(&hw->hw_lock);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003399
Stephen Hemminger29365c92006-09-01 15:53:48 -07003400 return IRQ_RETVAL(handled);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003401}
3402
3403#ifdef CONFIG_NET_POLL_CONTROLLER
3404static void skge_netpoll(struct net_device *dev)
3405{
3406 struct skge_port *skge = netdev_priv(dev);
3407
3408 disable_irq(dev->irq);
David Howells7d12e782006-10-05 14:55:46 +01003409 skge_intr(dev->irq, skge->hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003410 enable_irq(dev->irq);
3411}
3412#endif
3413
3414static int skge_set_mac_address(struct net_device *dev, void *p)
3415{
3416 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerc2681dd2005-10-03 12:03:13 -07003417 struct skge_hw *hw = skge->hw;
3418 unsigned port = skge->port;
3419 const struct sockaddr *addr = p;
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003420 u16 ctrl;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003421
3422 if (!is_valid_ether_addr(addr->sa_data))
3423 return -EADDRNOTAVAIL;
3424
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003425 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
Stephen Hemmingerc2681dd2005-10-03 12:03:13 -07003426
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003427 if (!netif_running(dev)) {
3428 memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN);
3429 memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN);
3430 } else {
3431 /* disable Rx */
3432 spin_lock_bh(&hw->phy_lock);
3433 ctrl = gma_read16(hw, port, GM_GP_CTRL);
3434 gma_write16(hw, port, GM_GP_CTRL, ctrl & ~GM_GPCR_RX_ENA);
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003435
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003436 memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN);
3437 memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN);
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003438
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003439 if (hw->chip_id == CHIP_ID_GENESIS)
3440 xm_outaddr(hw, port, XM_SA, dev->dev_addr);
3441 else {
3442 gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr);
3443 gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr);
3444 }
Stephen Hemminger2eb3e622007-03-12 15:16:26 -07003445
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003446 gma_write16(hw, port, GM_GP_CTRL, ctrl);
3447 spin_unlock_bh(&hw->phy_lock);
3448 }
Stephen Hemmingerc2681dd2005-10-03 12:03:13 -07003449
3450 return 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003451}
3452
3453static const struct {
3454 u8 id;
3455 const char *name;
3456} skge_chips[] = {
3457 { CHIP_ID_GENESIS, "Genesis" },
3458 { CHIP_ID_YUKON, "Yukon" },
3459 { CHIP_ID_YUKON_LITE, "Yukon-Lite"},
3460 { CHIP_ID_YUKON_LP, "Yukon-LP"},
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003461};
3462
3463static const char *skge_board_name(const struct skge_hw *hw)
3464{
3465 int i;
3466 static char buf[16];
3467
3468 for (i = 0; i < ARRAY_SIZE(skge_chips); i++)
3469 if (skge_chips[i].id == hw->chip_id)
3470 return skge_chips[i].name;
3471
3472 snprintf(buf, sizeof buf, "chipid 0x%x", hw->chip_id);
3473 return buf;
3474}
3475
3476
3477/*
3478 * Setup the board data structure, but don't bring up
3479 * the port(s)
3480 */
3481static int skge_reset(struct skge_hw *hw)
3482{
Stephen Hemmingeradba9e22005-11-08 10:33:40 -08003483 u32 reg;
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003484 u16 ctst, pci_status;
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003485 u8 t8, mac_cfg, pmd_type;
Stephen Hemminger981d0372005-06-27 11:33:06 -07003486 int i;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003487
3488 ctst = skge_read16(hw, B0_CTST);
3489
3490 /* do a SW reset */
3491 skge_write8(hw, B0_CTST, CS_RST_SET);
3492 skge_write8(hw, B0_CTST, CS_RST_CLR);
3493
3494 /* clear PCI errors, if any */
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003495 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
3496 skge_write8(hw, B2_TST_CTRL2, 0);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003497
Stephen Hemmingerb9d64ac2006-03-21 10:57:06 -08003498 pci_read_config_word(hw->pdev, PCI_STATUS, &pci_status);
3499 pci_write_config_word(hw->pdev, PCI_STATUS,
3500 pci_status | PCI_STATUS_ERROR_BITS);
3501 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003502 skge_write8(hw, B0_CTST, CS_MRST_CLR);
3503
3504 /* restore CLK_RUN bits (for Yukon-Lite) */
3505 skge_write16(hw, B0_CTST,
3506 ctst & (CS_CLK_RUN_HOT|CS_CLK_RUN_RST|CS_CLK_RUN_ENA));
3507
3508 hw->chip_id = skge_read8(hw, B2_CHIP_ID);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003509 hw->phy_type = skge_read8(hw, B2_E_1) & 0xf;
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07003510 pmd_type = skge_read8(hw, B2_PMD_TYP);
3511 hw->copper = (pmd_type == 'T' || pmd_type == '1');
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003512
Stephen Hemminger95566062005-06-27 11:33:02 -07003513 switch (hw->chip_id) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003514 case CHIP_ID_GENESIS:
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003515 switch (hw->phy_type) {
3516 case SK_PHY_XMAC:
3517 hw->phy_addr = PHY_ADDR_XMAC;
3518 break;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003519 case SK_PHY_BCOM:
3520 hw->phy_addr = PHY_ADDR_BCOM;
3521 break;
3522 default:
Stephen Hemminger1479d132007-02-02 08:22:52 -08003523 dev_err(&hw->pdev->dev, "unsupported phy type 0x%x\n",
3524 hw->phy_type);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003525 return -EOPNOTSUPP;
3526 }
3527 break;
3528
3529 case CHIP_ID_YUKON:
3530 case CHIP_ID_YUKON_LITE:
3531 case CHIP_ID_YUKON_LP:
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003532 if (hw->phy_type < SK_PHY_MARV_COPPER && pmd_type != 'S')
Stephen Hemminger5e1705d2005-08-16 14:00:58 -07003533 hw->copper = 1;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003534
3535 hw->phy_addr = PHY_ADDR_MARV;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003536 break;
3537
3538 default:
Stephen Hemminger1479d132007-02-02 08:22:52 -08003539 dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n",
3540 hw->chip_id);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003541 return -EOPNOTSUPP;
3542 }
3543
Stephen Hemminger981d0372005-06-27 11:33:06 -07003544 mac_cfg = skge_read8(hw, B2_MAC_CFG);
3545 hw->ports = (mac_cfg & CFG_SNG_MAC) ? 1 : 2;
3546 hw->chip_rev = (mac_cfg & CFG_CHIP_R_MSK) >> 4;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003547
3548 /* read the adapters RAM size */
3549 t8 = skge_read8(hw, B2_E_0);
3550 if (hw->chip_id == CHIP_ID_GENESIS) {
3551 if (t8 == 3) {
3552 /* special case: 4 x 64k x 36, offset = 0x80000 */
Linus Torvalds279e1da2007-11-15 08:44:36 -08003553 hw->ram_size = 0x100000;
3554 hw->ram_offset = 0x80000;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003555 } else
3556 hw->ram_size = t8 * 512;
Linus Torvalds279e1da2007-11-15 08:44:36 -08003557 }
3558 else if (t8 == 0)
3559 hw->ram_size = 0x20000;
3560 else
3561 hw->ram_size = t8 * 4096;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003562
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07003563 hw->intr_mask = IS_HW_ERR;
Stephen Hemmingercfc3ed72006-03-21 10:57:00 -08003564
Stephen Hemminger4ebabfc2007-03-16 14:01:27 -07003565 /* Use PHY IRQ for all but fiber based Genesis board */
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003566 if (!(hw->chip_id == CHIP_ID_GENESIS && hw->phy_type == SK_PHY_XMAC))
3567 hw->intr_mask |= IS_EXT_REG;
3568
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003569 if (hw->chip_id == CHIP_ID_GENESIS)
3570 genesis_init(hw);
3571 else {
3572 /* switch power to VCC (WA for VAUX problem) */
3573 skge_write8(hw, B0_POWER_CTRL,
3574 PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
Stephen Hemmingeradba9e22005-11-08 10:33:40 -08003575
Stephen Hemminger050ec182005-08-16 14:00:54 -07003576 /* avoid boards with stuck Hardware error bits */
3577 if ((skge_read32(hw, B0_ISRC) & IS_HW_ERR) &&
3578 (skge_read32(hw, B0_HWE_ISRC) & IS_IRQ_SENSOR)) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003579 dev_warn(&hw->pdev->dev, "stuck hardware sensor bit\n");
Stephen Hemminger050ec182005-08-16 14:00:54 -07003580 hw->intr_mask &= ~IS_HW_ERR;
3581 }
3582
Stephen Hemmingeradba9e22005-11-08 10:33:40 -08003583 /* Clear PHY COMA */
3584 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
3585 pci_read_config_dword(hw->pdev, PCI_DEV_REG1, &reg);
3586 reg &= ~PCI_PHY_COMA;
3587 pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg);
3588 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
3589
3590
Stephen Hemminger981d0372005-06-27 11:33:06 -07003591 for (i = 0; i < hw->ports; i++) {
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003592 skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
3593 skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003594 }
3595 }
3596
3597 /* turn off hardware timer (unused) */
3598 skge_write8(hw, B2_TI_CTRL, TIM_STOP);
3599 skge_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ);
3600 skge_write8(hw, B0_LED, LED_STAT_ON);
3601
3602 /* enable the Tx Arbiters */
Stephen Hemminger981d0372005-06-27 11:33:06 -07003603 for (i = 0; i < hw->ports; i++)
Stephen Hemminger6b0c1482005-06-27 11:33:04 -07003604 skge_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003605
3606 /* Initialize ram interface */
3607 skge_write16(hw, B3_RI_CTRL, RI_RST_CLR);
3608
3609 skge_write8(hw, B3_RI_WTO_R1, SK_RI_TO_53);
3610 skge_write8(hw, B3_RI_WTO_XA1, SK_RI_TO_53);
3611 skge_write8(hw, B3_RI_WTO_XS1, SK_RI_TO_53);
3612 skge_write8(hw, B3_RI_RTO_R1, SK_RI_TO_53);
3613 skge_write8(hw, B3_RI_RTO_XA1, SK_RI_TO_53);
3614 skge_write8(hw, B3_RI_RTO_XS1, SK_RI_TO_53);
3615 skge_write8(hw, B3_RI_WTO_R2, SK_RI_TO_53);
3616 skge_write8(hw, B3_RI_WTO_XA2, SK_RI_TO_53);
3617 skge_write8(hw, B3_RI_WTO_XS2, SK_RI_TO_53);
3618 skge_write8(hw, B3_RI_RTO_R2, SK_RI_TO_53);
3619 skge_write8(hw, B3_RI_RTO_XA2, SK_RI_TO_53);
3620 skge_write8(hw, B3_RI_RTO_XS2, SK_RI_TO_53);
3621
3622 skge_write32(hw, B0_HWE_IMSK, IS_ERR_MSK);
3623
3624 /* Set interrupt moderation for Transmit only
3625 * Receive interrupts avoided by NAPI
3626 */
3627 skge_write32(hw, B2_IRQM_MSK, IS_XA1_F|IS_XA2_F);
3628 skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, 100));
3629 skge_write32(hw, B2_IRQM_CTRL, TIM_START);
3630
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003631 skge_write32(hw, B0_IMSK, hw->intr_mask);
3632
Stephen Hemminger981d0372005-06-27 11:33:06 -07003633 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003634 if (hw->chip_id == CHIP_ID_GENESIS)
3635 genesis_reset(hw, i);
3636 else
3637 yukon_reset(hw, i);
3638 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003639
3640 return 0;
3641}
3642
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003643
3644#ifdef CONFIG_SKGE_DEBUG
3645
3646static struct dentry *skge_debug;
3647
3648static int skge_debug_show(struct seq_file *seq, void *v)
3649{
3650 struct net_device *dev = seq->private;
3651 const struct skge_port *skge = netdev_priv(dev);
3652 const struct skge_hw *hw = skge->hw;
3653 const struct skge_element *e;
3654
3655 if (!netif_running(dev))
3656 return -ENETDOWN;
3657
3658 seq_printf(seq, "IRQ src=%x mask=%x\n", skge_read32(hw, B0_ISRC),
3659 skge_read32(hw, B0_IMSK));
3660
3661 seq_printf(seq, "Tx Ring: (%d)\n", skge_avail(&skge->tx_ring));
3662 for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) {
3663 const struct skge_tx_desc *t = e->desc;
3664 seq_printf(seq, "%#x dma=%#x%08x %#x csum=%#x/%x/%x\n",
3665 t->control, t->dma_hi, t->dma_lo, t->status,
3666 t->csum_offs, t->csum_write, t->csum_start);
3667 }
3668
3669 seq_printf(seq, "\nRx Ring: \n");
3670 for (e = skge->rx_ring.to_clean; ; e = e->next) {
3671 const struct skge_rx_desc *r = e->desc;
3672
3673 if (r->control & BMU_OWN)
3674 break;
3675
3676 seq_printf(seq, "%#x dma=%#x%08x %#x %#x csum=%#x/%x\n",
3677 r->control, r->dma_hi, r->dma_lo, r->status,
3678 r->timestamp, r->csum1, r->csum1_start);
3679 }
3680
3681 return 0;
3682}
3683
3684static int skge_debug_open(struct inode *inode, struct file *file)
3685{
3686 return single_open(file, skge_debug_show, inode->i_private);
3687}
3688
3689static const struct file_operations skge_debug_fops = {
3690 .owner = THIS_MODULE,
3691 .open = skge_debug_open,
3692 .read = seq_read,
3693 .llseek = seq_lseek,
3694 .release = single_release,
3695};
3696
3697/*
3698 * Use network device events to create/remove/rename
3699 * debugfs file entries
3700 */
3701static int skge_device_event(struct notifier_block *unused,
3702 unsigned long event, void *ptr)
3703{
3704 struct net_device *dev = ptr;
3705 struct skge_port *skge;
3706 struct dentry *d;
3707
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003708 if (dev->netdev_ops->ndo_open != &skge_up || !skge_debug)
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003709 goto done;
3710
3711 skge = netdev_priv(dev);
3712 switch(event) {
3713 case NETDEV_CHANGENAME:
3714 if (skge->debugfs) {
3715 d = debugfs_rename(skge_debug, skge->debugfs,
3716 skge_debug, dev->name);
3717 if (d)
3718 skge->debugfs = d;
3719 else {
Joe Perchesf15063c2010-02-17 15:01:57 +00003720 netdev_info(dev, "rename failed\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003721 debugfs_remove(skge->debugfs);
3722 }
3723 }
3724 break;
3725
3726 case NETDEV_GOING_DOWN:
3727 if (skge->debugfs) {
3728 debugfs_remove(skge->debugfs);
3729 skge->debugfs = NULL;
3730 }
3731 break;
3732
3733 case NETDEV_UP:
3734 d = debugfs_create_file(dev->name, S_IRUGO,
3735 skge_debug, dev,
3736 &skge_debug_fops);
3737 if (!d || IS_ERR(d))
Joe Perchesf15063c2010-02-17 15:01:57 +00003738 netdev_info(dev, "debugfs create failed\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003739 else
3740 skge->debugfs = d;
3741 break;
3742 }
3743
3744done:
3745 return NOTIFY_DONE;
3746}
3747
3748static struct notifier_block skge_notifier = {
3749 .notifier_call = skge_device_event,
3750};
3751
3752
3753static __init void skge_debug_init(void)
3754{
3755 struct dentry *ent;
3756
3757 ent = debugfs_create_dir("skge", NULL);
3758 if (!ent || IS_ERR(ent)) {
Joe Perchesf15063c2010-02-17 15:01:57 +00003759 pr_info("debugfs create directory failed\n");
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07003760 return;
3761 }
3762
3763 skge_debug = ent;
3764 register_netdevice_notifier(&skge_notifier);
3765}
3766
3767static __exit void skge_debug_cleanup(void)
3768{
3769 if (skge_debug) {
3770 unregister_netdevice_notifier(&skge_notifier);
3771 debugfs_remove(skge_debug);
3772 skge_debug = NULL;
3773 }
3774}
3775
3776#else
3777#define skge_debug_init()
3778#define skge_debug_cleanup()
3779#endif
3780
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003781static const struct net_device_ops skge_netdev_ops = {
3782 .ndo_open = skge_up,
3783 .ndo_stop = skge_down,
Stephen Hemminger00829822008-11-20 20:14:53 -08003784 .ndo_start_xmit = skge_xmit_frame,
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003785 .ndo_do_ioctl = skge_ioctl,
3786 .ndo_get_stats = skge_get_stats,
3787 .ndo_tx_timeout = skge_tx_timeout,
3788 .ndo_change_mtu = skge_change_mtu,
3789 .ndo_validate_addr = eth_validate_addr,
3790 .ndo_set_multicast_list = skge_set_multicast,
3791 .ndo_set_mac_address = skge_set_mac_address,
3792#ifdef CONFIG_NET_POLL_CONTROLLER
3793 .ndo_poll_controller = skge_netpoll,
3794#endif
3795};
3796
3797
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003798/* Initialize network device */
Stephen Hemminger981d0372005-06-27 11:33:06 -07003799static struct net_device *skge_devinit(struct skge_hw *hw, int port,
3800 int highmem)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003801{
3802 struct skge_port *skge;
3803 struct net_device *dev = alloc_etherdev(sizeof(*skge));
3804
3805 if (!dev) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003806 dev_err(&hw->pdev->dev, "etherdev alloc failed\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003807 return NULL;
3808 }
3809
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003810 SET_NETDEV_DEV(dev, &hw->pdev->dev);
Stephen Hemmingerf80d0322008-11-19 22:01:26 -08003811 dev->netdev_ops = &skge_netdev_ops;
3812 dev->ethtool_ops = &skge_ethtool_ops;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003813 dev->watchdog_timeo = TX_WATCHDOG;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003814 dev->irq = hw->pdev->irq;
Stephen Hemminger513f5332006-09-01 15:53:49 -07003815
Stephen Hemminger981d0372005-06-27 11:33:06 -07003816 if (highmem)
3817 dev->features |= NETIF_F_HIGHDMA;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003818
3819 skge = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003820 netif_napi_add(dev, &skge->napi, skge_poll, NAPI_WEIGHT);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003821 skge->netdev = dev;
3822 skge->hw = hw;
3823 skge->msg_enable = netif_msg_init(debug, default_msg);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003824
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003825 skge->tx_ring.count = DEFAULT_TX_RING_SIZE;
3826 skge->rx_ring.count = DEFAULT_RX_RING_SIZE;
3827
3828 /* Auto speed and flow control */
3829 skge->autoneg = AUTONEG_ENABLE;
Stephen Hemminger5d5c8e02006-10-05 15:49:52 -07003830 skge->flow_control = FLOW_MODE_SYM_OR_REM;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003831 skge->duplex = -1;
3832 skge->speed = -1;
Stephen Hemminger31b619c2005-06-27 11:33:11 -07003833 skge->advertising = skge_supported_modes(hw);
Stephen Hemminger5b982c52007-05-08 13:36:20 -07003834
Rafael J. Wysocki7b55a4a2009-07-22 02:58:55 +00003835 if (device_can_wakeup(&hw->pdev->dev)) {
Stephen Hemminger5b982c52007-05-08 13:36:20 -07003836 skge->wol = wol_supported(hw) & WAKE_MAGIC;
Rafael J. Wysocki7b55a4a2009-07-22 02:58:55 +00003837 device_set_wakeup_enable(&hw->pdev->dev, skge->wol);
3838 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003839
3840 hw->dev[port] = dev;
3841
3842 skge->port = port;
3843
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003844 /* Only used for Genesis XMAC */
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003845 setup_timer(&skge->link_timer, xm_link_timer, (unsigned long) skge);
Stephen Hemminger64f6b642006-09-23 21:25:28 -07003846
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003847 if (hw->chip_id != CHIP_ID_GENESIS) {
3848 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
3849 skge->rx_csum = 1;
3850 }
3851
3852 /* read the mac address */
3853 memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port*8, ETH_ALEN);
John W. Linville56230d52005-09-12 10:48:57 -04003854 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003855
3856 /* device is off until link detection */
3857 netif_carrier_off(dev);
3858 netif_stop_queue(dev);
3859
3860 return dev;
3861}
3862
3863static void __devinit skge_show_addr(struct net_device *dev)
3864{
3865 const struct skge_port *skge = netdev_priv(dev);
3866
Joe Perchesd7072042010-02-09 11:49:53 +00003867 netif_info(skge, probe, skge->netdev, "addr %pM\n", dev->dev_addr);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003868}
3869
3870static int __devinit skge_probe(struct pci_dev *pdev,
3871 const struct pci_device_id *ent)
3872{
3873 struct net_device *dev, *dev1;
3874 struct skge_hw *hw;
3875 int err, using_dac = 0;
3876
Stephen Hemminger203babb2006-03-21 10:57:05 -08003877 err = pci_enable_device(pdev);
3878 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003879 dev_err(&pdev->dev, "cannot enable PCI device\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003880 goto err_out;
3881 }
3882
Stephen Hemminger203babb2006-03-21 10:57:05 -08003883 err = pci_request_regions(pdev, DRV_NAME);
3884 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003885 dev_err(&pdev->dev, "cannot obtain PCI resources\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003886 goto err_out_disable_pdev;
3887 }
3888
3889 pci_set_master(pdev);
3890
Yang Hongyang6a355282009-04-06 19:01:13 -07003891 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003892 using_dac = 1;
Yang Hongyang6a355282009-04-06 19:01:13 -07003893 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
Yang Hongyang284901a2009-04-06 19:01:15 -07003894 } else if (!(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))) {
Stephen Hemminger93aea712006-03-21 10:57:02 -08003895 using_dac = 0;
Yang Hongyang284901a2009-04-06 19:01:15 -07003896 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Stephen Hemminger93aea712006-03-21 10:57:02 -08003897 }
3898
3899 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003900 dev_err(&pdev->dev, "no usable DMA configuration\n");
Stephen Hemminger93aea712006-03-21 10:57:02 -08003901 goto err_out_free_regions;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003902 }
3903
3904#ifdef __BIG_ENDIAN
Stephen Hemminger8f3f8192005-11-08 10:33:45 -08003905 /* byte swap descriptors in hardware */
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003906 {
3907 u32 reg;
3908
3909 pci_read_config_dword(pdev, PCI_DEV_REG2, &reg);
3910 reg |= PCI_REV_DESC;
3911 pci_write_config_dword(pdev, PCI_DEV_REG2, reg);
3912 }
3913#endif
3914
3915 err = -ENOMEM;
Michal Schmidt415e69e2009-10-01 08:13:23 +00003916 /* space for skge@pci:0000:04:00.0 */
3917 hw = kzalloc(sizeof(*hw) + strlen(DRV_NAME "@pci:" )
3918 + strlen(pci_name(pdev)) + 1, GFP_KERNEL);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003919 if (!hw) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003920 dev_err(&pdev->dev, "cannot allocate hardware struct\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003921 goto err_out_free_regions;
3922 }
Michal Schmidt415e69e2009-10-01 08:13:23 +00003923 sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev));
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003924
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003925 hw->pdev = pdev;
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07003926 spin_lock_init(&hw->hw_lock);
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07003927 spin_lock_init(&hw->phy_lock);
Joe Perches164165d2009-11-19 09:30:10 +00003928 tasklet_init(&hw->phy_task, skge_extirq, (unsigned long) hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003929
3930 hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
3931 if (!hw->regs) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003932 dev_err(&pdev->dev, "cannot map device registers\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003933 goto err_out_free_hw;
3934 }
3935
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003936 err = skge_reset(hw);
3937 if (err)
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003938 goto err_out_iounmap;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003939
Joe Perchesf15063c2010-02-17 15:01:57 +00003940 pr_info("%s addr 0x%llx irq %d chip %s rev %d\n",
3941 DRV_VERSION,
3942 (unsigned long long)pci_resource_start(pdev, 0), pdev->irq,
3943 skge_board_name(hw), hw->chip_rev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003944
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003945 dev = skge_devinit(hw, 0, using_dac);
3946 if (!dev)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003947 goto err_out_led_off;
3948
Stephen Hemmingerfae87592007-02-02 08:22:51 -08003949 /* Some motherboards are broken and has zero in ROM. */
Stephen Hemminger1479d132007-02-02 08:22:52 -08003950 if (!is_valid_ether_addr(dev->dev_addr))
3951 dev_warn(&pdev->dev, "bad (zero?) ethernet address in rom\n");
Stephen Hemminger631ae322006-06-06 10:11:14 -07003952
Stephen Hemminger203babb2006-03-21 10:57:05 -08003953 err = register_netdev(dev);
3954 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003955 dev_err(&pdev->dev, "cannot register net device\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003956 goto err_out_free_netdev;
3957 }
3958
Michal Schmidt415e69e2009-10-01 08:13:23 +00003959 err = request_irq(pdev->irq, skge_intr, IRQF_SHARED, hw->irq_name, hw);
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003960 if (err) {
Stephen Hemminger1479d132007-02-02 08:22:52 -08003961 dev_err(&pdev->dev, "%s: cannot assign irq %d\n",
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003962 dev->name, pdev->irq);
3963 goto err_out_unregister;
3964 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003965 skge_show_addr(dev);
3966
Mike McCormackf1914222009-09-23 03:50:36 +00003967 if (hw->ports > 1) {
3968 dev1 = skge_devinit(hw, 1, using_dac);
3969 if (dev1 && register_netdev(dev1) == 0)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003970 skge_show_addr(dev1);
3971 else {
3972 /* Failure to register second port need not be fatal */
Stephen Hemminger1479d132007-02-02 08:22:52 -08003973 dev_warn(&pdev->dev, "register of second port failed\n");
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003974 hw->dev[1] = NULL;
Mike McCormackf1914222009-09-23 03:50:36 +00003975 hw->ports = 1;
3976 if (dev1)
3977 free_netdev(dev1);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003978 }
3979 }
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003980 pci_set_drvdata(pdev, hw);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003981
3982 return 0;
3983
Stephen Hemmingerccdaa2a2006-08-28 16:19:38 -07003984err_out_unregister:
3985 unregister_netdev(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003986err_out_free_netdev:
3987 free_netdev(dev);
3988err_out_led_off:
3989 skge_write16(hw, B0_LED, LED_STAT_OFF);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04003990err_out_iounmap:
3991 iounmap(hw->regs);
3992err_out_free_hw:
3993 kfree(hw);
3994err_out_free_regions:
3995 pci_release_regions(pdev);
3996err_out_disable_pdev:
3997 pci_disable_device(pdev);
3998 pci_set_drvdata(pdev, NULL);
3999err_out:
4000 return err;
4001}
4002
4003static void __devexit skge_remove(struct pci_dev *pdev)
4004{
4005 struct skge_hw *hw = pci_get_drvdata(pdev);
4006 struct net_device *dev0, *dev1;
4007
Stephen Hemminger95566062005-06-27 11:33:02 -07004008 if (!hw)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004009 return;
4010
Stephen Hemminger208491d82007-02-16 15:37:39 -08004011 flush_scheduled_work();
4012
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004013 if ((dev1 = hw->dev[1]))
4014 unregister_netdev(dev1);
4015 dev0 = hw->dev[0];
4016 unregister_netdev(dev0);
4017
Stephen Hemminger9cbe3302007-03-16 14:01:28 -07004018 tasklet_disable(&hw->phy_task);
4019
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07004020 spin_lock_irq(&hw->hw_lock);
4021 hw->intr_mask = 0;
Stephen Hemminger46a60f22005-09-09 12:54:56 -07004022 skge_write32(hw, B0_IMSK, 0);
Stephen Hemminger78bc2182006-08-28 16:19:36 -07004023 skge_read32(hw, B0_IMSK);
Stephen Hemminger7c442fa2006-06-06 10:11:13 -07004024 spin_unlock_irq(&hw->hw_lock);
4025
Stephen Hemminger46a60f22005-09-09 12:54:56 -07004026 skge_write16(hw, B0_LED, LED_STAT_OFF);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07004027 skge_write8(hw, B0_CTST, CS_RST_SET);
4028
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004029 free_irq(pdev->irq, hw);
4030 pci_release_regions(pdev);
4031 pci_disable_device(pdev);
4032 if (dev1)
4033 free_netdev(dev1);
4034 free_netdev(dev0);
Stephen Hemminger46a60f22005-09-09 12:54:56 -07004035
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004036 iounmap(hw->regs);
4037 kfree(hw);
4038 pci_set_drvdata(pdev, NULL);
4039}
4040
4041#ifdef CONFIG_PM
Pavel Machek2a569572005-07-07 17:56:40 -07004042static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004043{
4044 struct skge_hw *hw = pci_get_drvdata(pdev);
Stephen Hemmingera504e642007-02-02 08:22:53 -08004045 int i, err, wol = 0;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004046
Stephen Hemmingere3b7df12007-05-11 11:21:45 -07004047 if (!hw)
4048 return 0;
4049
Stephen Hemmingera504e642007-02-02 08:22:53 -08004050 err = pci_save_state(pdev);
4051 if (err)
4052 return err;
4053
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004054 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004055 struct net_device *dev = hw->dev[i];
Stephen Hemmingera504e642007-02-02 08:22:53 -08004056 struct skge_port *skge = netdev_priv(dev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004057
Stephen Hemmingera504e642007-02-02 08:22:53 -08004058 if (netif_running(dev))
4059 skge_down(dev);
4060 if (skge->wol)
4061 skge_wol_init(skge);
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004062
Stephen Hemmingera504e642007-02-02 08:22:53 -08004063 wol |= skge->wol;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004064 }
4065
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004066 skge_write32(hw, B0_IMSK, 0);
Rafael J. Wysocki5177b322008-10-29 14:22:14 -07004067
4068 pci_prepare_to_sleep(pdev);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004069
4070 return 0;
4071}
4072
4073static int skge_resume(struct pci_dev *pdev)
4074{
4075 struct skge_hw *hw = pci_get_drvdata(pdev);
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004076 int i, err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004077
Stephen Hemmingere3b7df12007-05-11 11:21:45 -07004078 if (!hw)
4079 return 0;
4080
Rafael J. Wysocki5177b322008-10-29 14:22:14 -07004081 err = pci_back_from_sleep(pdev);
Stephen Hemmingera504e642007-02-02 08:22:53 -08004082 if (err)
4083 goto out;
4084
4085 err = pci_restore_state(pdev);
4086 if (err)
4087 goto out;
4088
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004089 err = skge_reset(hw);
4090 if (err)
4091 goto out;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004092
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004093 for (i = 0; i < hw->ports; i++) {
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004094 struct net_device *dev = hw->dev[i];
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004095
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004096 if (netif_running(dev)) {
4097 err = skge_up(dev);
4098
4099 if (err) {
Joe Perchesf15063c2010-02-17 15:01:57 +00004100 netdev_err(dev, "could not up: %d\n", err);
Stephen Hemmingeredd702e2005-12-15 12:18:00 -08004101 dev_close(dev);
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004102 goto out;
4103 }
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004104 }
4105 }
Stephen Hemmingerd38efdd2006-08-28 16:19:35 -07004106out:
4107 return err;
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004108}
4109#endif
4110
Stephen Hemminger692412b2007-04-09 15:32:45 -07004111static void skge_shutdown(struct pci_dev *pdev)
4112{
4113 struct skge_hw *hw = pci_get_drvdata(pdev);
4114 int i, wol = 0;
4115
Stephen Hemmingere3b7df12007-05-11 11:21:45 -07004116 if (!hw)
4117 return;
4118
Stephen Hemminger692412b2007-04-09 15:32:45 -07004119 for (i = 0; i < hw->ports; i++) {
4120 struct net_device *dev = hw->dev[i];
4121 struct skge_port *skge = netdev_priv(dev);
4122
4123 if (skge->wol)
4124 skge_wol_init(skge);
4125 wol |= skge->wol;
4126 }
4127
Rafael J. Wysocki5177b322008-10-29 14:22:14 -07004128 if (pci_enable_wake(pdev, PCI_D3cold, wol))
4129 pci_enable_wake(pdev, PCI_D3hot, wol);
Stephen Hemminger692412b2007-04-09 15:32:45 -07004130
4131 pci_disable_device(pdev);
4132 pci_set_power_state(pdev, PCI_D3hot);
4133
4134}
4135
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004136static struct pci_driver skge_driver = {
4137 .name = DRV_NAME,
4138 .id_table = skge_id_table,
4139 .probe = skge_probe,
4140 .remove = __devexit_p(skge_remove),
4141#ifdef CONFIG_PM
4142 .suspend = skge_suspend,
4143 .resume = skge_resume,
4144#endif
Stephen Hemminger692412b2007-04-09 15:32:45 -07004145 .shutdown = skge_shutdown,
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004146};
4147
4148static int __init skge_init_module(void)
4149{
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07004150 skge_debug_init();
Jeff Garzik29917622006-08-19 17:48:59 -04004151 return pci_register_driver(&skge_driver);
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004152}
4153
4154static void __exit skge_cleanup_module(void)
4155{
4156 pci_unregister_driver(&skge_driver);
Stephen Hemminger678aa1f2007-10-16 12:15:54 -07004157 skge_debug_cleanup();
Stephen Hemmingerbaef58b2005-05-12 20:14:36 -04004158}
4159
4160module_init(skge_init_module);
4161module_exit(skge_cleanup_module);