Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * New driver for Marvell Yukon 2 chipset. |
| 3 | * Based on earlier sk98lin, and skge driver. |
| 4 | * |
| 5 | * This driver intentionally does not support all the features |
| 6 | * of the original driver such as link fail-over and link management because |
| 7 | * those should be done at higher levels. |
| 8 | * |
| 9 | * Copyright (C) 2005 Stephen Hemminger <shemminger@osdl.org> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
Stephen Hemminger | 798b6b1 | 2006-10-22 20:16:57 -0700 | [diff] [blame] | 13 | * the Free Software Foundation; either version 2 of the License. |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | */ |
| 24 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 25 | #include <linux/crc32.h> |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 26 | #include <linux/kernel.h> |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 27 | #include <linux/module.h> |
| 28 | #include <linux/netdevice.h> |
Andrew Morton | d0bbccf | 2005-11-10 15:29:27 -0800 | [diff] [blame] | 29 | #include <linux/dma-mapping.h> |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 30 | #include <linux/etherdevice.h> |
| 31 | #include <linux/ethtool.h> |
| 32 | #include <linux/pci.h> |
| 33 | #include <linux/ip.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 34 | #include <net/ip.h> |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 35 | #include <linux/tcp.h> |
| 36 | #include <linux/in.h> |
| 37 | #include <linux/delay.h> |
Stephen Hemminger | 91c86df | 2005-12-09 11:34:57 -0800 | [diff] [blame] | 38 | #include <linux/workqueue.h> |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 39 | #include <linux/if_vlan.h> |
Stephen Hemminger | d70cd51 | 2005-12-09 11:35:09 -0800 | [diff] [blame] | 40 | #include <linux/prefetch.h> |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 41 | #include <linux/debugfs.h> |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 42 | #include <linux/mii.h> |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 43 | |
| 44 | #include <asm/irq.h> |
| 45 | |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 46 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) |
| 47 | #define SKY2_VLAN_TAG_USED 1 |
| 48 | #endif |
| 49 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 50 | #include "sky2.h" |
| 51 | |
| 52 | #define DRV_NAME "sky2" |
Stephen Hemminger | ac95815 | 2009-10-29 06:37:10 +0000 | [diff] [blame] | 53 | #define DRV_VERSION "1.26" |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 54 | #define PFX DRV_NAME " " |
| 55 | |
| 56 | /* |
| 57 | * The Yukon II chipset takes 64 bit command blocks (called list elements) |
| 58 | * that are organized into three (receive, transmit, status) different rings |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 59 | * similar to Tigon3. |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 60 | */ |
| 61 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 62 | #define RX_LE_SIZE 1024 |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 63 | #define RX_LE_BYTES (RX_LE_SIZE*sizeof(struct sky2_rx_le)) |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 64 | #define RX_MAX_PENDING (RX_LE_SIZE/6 - 2) |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 65 | #define RX_DEF_PENDING RX_MAX_PENDING |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 66 | |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 67 | /* This is the worst case number of transmit list elements for a single skb: |
Stephen Hemminger | 07e3163 | 2009-09-14 06:12:55 +0000 | [diff] [blame] | 68 | VLAN:GSO + CKSUM + Data + skb_frags * DMA */ |
| 69 | #define MAX_SKB_TX_LE (2 + (sizeof(dma_addr_t)/sizeof(u32))*(MAX_SKB_FRAGS+1)) |
Stephen Hemminger | e9c1be8 | 2009-06-17 07:30:37 +0000 | [diff] [blame] | 70 | #define TX_MIN_PENDING (MAX_SKB_TX_LE+1) |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 71 | #define TX_MAX_PENDING 4096 |
| 72 | #define TX_DEF_PENDING 127 |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 73 | |
| 74 | #define STATUS_RING_SIZE 2048 /* 2 ports * (TX + 2*RX) */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 75 | #define STATUS_LE_BYTES (STATUS_RING_SIZE*sizeof(struct sky2_status_le)) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 76 | #define TX_WATCHDOG (5 * HZ) |
| 77 | #define NAPI_WEIGHT 64 |
| 78 | #define PHY_RETRIES 1000 |
| 79 | |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 80 | #define SKY2_EEPROM_MAGIC 0x9955aabb |
| 81 | |
| 82 | |
Stephen Hemminger | cb5d954 | 2006-05-08 15:11:29 -0700 | [diff] [blame] | 83 | #define RING_NEXT(x,s) (((x)+1) & ((s)-1)) |
| 84 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 85 | static const u32 default_msg = |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 86 | NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK |
| 87 | | NETIF_MSG_TIMER | NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 88 | | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 89 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 90 | static int debug = -1; /* defaults above */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 91 | module_param(debug, int, 0); |
| 92 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 93 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 94 | static int copybreak __read_mostly = 128; |
Stephen Hemminger | bdb5c58 | 2005-12-09 11:34:55 -0800 | [diff] [blame] | 95 | module_param(copybreak, int, 0); |
| 96 | MODULE_PARM_DESC(copybreak, "Receive copy threshold"); |
| 97 | |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 98 | static int disable_msi = 0; |
| 99 | module_param(disable_msi, int, 0); |
| 100 | MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)"); |
| 101 | |
Stephen Hemminger | e6cac9b | 2008-06-17 09:04:26 -0700 | [diff] [blame] | 102 | static DEFINE_PCI_DEVICE_TABLE(sky2_id_table) = { |
Stephen Hemminger | e5b74c7 | 2006-12-04 15:53:36 -0800 | [diff] [blame] | 103 | { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9000) }, /* SK-9Sxx */ |
| 104 | { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) }, /* SK-9Exx */ |
Stephen Hemminger | e30a4ac | 2009-10-29 06:37:05 +0000 | [diff] [blame] | 105 | { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E01) }, /* SK-9E21M */ |
Stephen Hemminger | 2d2a387 | 2006-05-17 14:37:04 -0700 | [diff] [blame] | 106 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b00) }, /* DGE-560T */ |
Stephen Hemminger | 2f4a66a | 2006-09-01 14:52:04 -0700 | [diff] [blame] | 107 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4001) }, /* DGE-550SX */ |
Stephen Hemminger | 508f89e | 2006-12-01 14:29:34 -0800 | [diff] [blame] | 108 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B02) }, /* DGE-560SX */ |
Stephen Hemminger | f1a0b6f | 2007-02-06 10:45:44 -0800 | [diff] [blame] | 109 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B03) }, /* DGE-550T */ |
Stephen Hemminger | e5b74c7 | 2006-12-04 15:53:36 -0800 | [diff] [blame] | 110 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4340) }, /* 88E8021 */ |
| 111 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4341) }, /* 88E8022 */ |
| 112 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4342) }, /* 88E8061 */ |
| 113 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4343) }, /* 88E8062 */ |
| 114 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4344) }, /* 88E8021 */ |
| 115 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4345) }, /* 88E8022 */ |
| 116 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4346) }, /* 88E8061 */ |
| 117 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4347) }, /* 88E8062 */ |
| 118 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4350) }, /* 88E8035 */ |
| 119 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4351) }, /* 88E8036 */ |
| 120 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4352) }, /* 88E8038 */ |
| 121 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4353) }, /* 88E8039 */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 122 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4354) }, /* 88E8040 */ |
Stephen Hemminger | a3b4fce | 2008-06-14 10:32:15 -0700 | [diff] [blame] | 123 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4355) }, /* 88E8040T */ |
Stephen Hemminger | e5b74c7 | 2006-12-04 15:53:36 -0800 | [diff] [blame] | 124 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4356) }, /* 88EC033 */ |
Stephen Hemminger | 5a37a68 | 2007-11-08 08:20:17 -0800 | [diff] [blame] | 125 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4357) }, /* 88E8042 */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 126 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x435A) }, /* 88E8048 */ |
Stephen Hemminger | e5b74c7 | 2006-12-04 15:53:36 -0800 | [diff] [blame] | 127 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4360) }, /* 88E8052 */ |
| 128 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4361) }, /* 88E8050 */ |
| 129 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4362) }, /* 88E8053 */ |
| 130 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4363) }, /* 88E8055 */ |
| 131 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4364) }, /* 88E8056 */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 132 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4365) }, /* 88E8070 */ |
Stephen Hemminger | e5b74c7 | 2006-12-04 15:53:36 -0800 | [diff] [blame] | 133 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4366) }, /* 88EC036 */ |
| 134 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4367) }, /* 88EC032 */ |
| 135 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4368) }, /* 88EC034 */ |
Stephen Hemminger | f1a0b6f | 2007-02-06 10:45:44 -0800 | [diff] [blame] | 136 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4369) }, /* 88EC042 */ |
| 137 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436A) }, /* 88E8058 */ |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 138 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436B) }, /* 88E8071 */ |
Stephen Hemminger | 5a37a68 | 2007-11-08 08:20:17 -0800 | [diff] [blame] | 139 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436C) }, /* 88E8072 */ |
Stephen Hemminger | ed4d416 | 2008-01-10 16:14:14 -0800 | [diff] [blame] | 140 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436D) }, /* 88E8055 */ |
| 141 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4370) }, /* 88E8075 */ |
Stephen Hemminger | 0ce8b98 | 2008-06-17 09:04:27 -0700 | [diff] [blame] | 142 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4380) }, /* 88E8057 */ |
Stephen Hemminger | 0f5aac7 | 2009-10-29 06:37:09 +0000 | [diff] [blame] | 143 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4381) }, /* 88E8059 */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 144 | { 0 } |
| 145 | }; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 146 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 147 | MODULE_DEVICE_TABLE(pci, sky2_id_table); |
| 148 | |
| 149 | /* Avoid conditionals by using array */ |
| 150 | static const unsigned txqaddr[] = { Q_XA1, Q_XA2 }; |
| 151 | static const unsigned rxqaddr[] = { Q_R1, Q_R2 }; |
Stephen Hemminger | f4ea431 | 2006-05-09 14:46:54 -0700 | [diff] [blame] | 152 | static const u32 portirq_msk[] = { Y2_IS_PORT_1, Y2_IS_PORT_2 }; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 153 | |
Stephen Hemminger | d1b139c | 2007-09-05 16:56:19 +0100 | [diff] [blame] | 154 | static void sky2_set_multicast(struct net_device *dev); |
| 155 | |
Stephen Hemminger | af043aa | 2007-11-05 15:52:10 -0800 | [diff] [blame] | 156 | /* Access to PHY via serial interconnect */ |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 157 | static int gm_phy_write(struct sky2_hw *hw, unsigned port, u16 reg, u16 val) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 158 | { |
| 159 | int i; |
| 160 | |
| 161 | gma_write16(hw, port, GM_SMI_DATA, val); |
| 162 | gma_write16(hw, port, GM_SMI_CTRL, |
| 163 | GM_SMI_CT_PHY_AD(PHY_ADDR_MARV) | GM_SMI_CT_REG_AD(reg)); |
| 164 | |
| 165 | for (i = 0; i < PHY_RETRIES; i++) { |
Stephen Hemminger | af043aa | 2007-11-05 15:52:10 -0800 | [diff] [blame] | 166 | u16 ctrl = gma_read16(hw, port, GM_SMI_CTRL); |
| 167 | if (ctrl == 0xffff) |
| 168 | goto io_error; |
| 169 | |
| 170 | if (!(ctrl & GM_SMI_CT_BUSY)) |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 171 | return 0; |
Stephen Hemminger | af043aa | 2007-11-05 15:52:10 -0800 | [diff] [blame] | 172 | |
| 173 | udelay(10); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 174 | } |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 175 | |
Stephen Hemminger | af043aa | 2007-11-05 15:52:10 -0800 | [diff] [blame] | 176 | dev_warn(&hw->pdev->dev,"%s: phy write timeout\n", hw->dev[port]->name); |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 177 | return -ETIMEDOUT; |
Stephen Hemminger | af043aa | 2007-11-05 15:52:10 -0800 | [diff] [blame] | 178 | |
| 179 | io_error: |
| 180 | dev_err(&hw->pdev->dev, "%s: phy I/O error\n", hw->dev[port]->name); |
| 181 | return -EIO; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 182 | } |
| 183 | |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 184 | static int __gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg, u16 *val) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 185 | { |
| 186 | int i; |
| 187 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 188 | gma_write16(hw, port, GM_SMI_CTRL, GM_SMI_CT_PHY_AD(PHY_ADDR_MARV) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 189 | | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD); |
| 190 | |
| 191 | for (i = 0; i < PHY_RETRIES; i++) { |
Stephen Hemminger | af043aa | 2007-11-05 15:52:10 -0800 | [diff] [blame] | 192 | u16 ctrl = gma_read16(hw, port, GM_SMI_CTRL); |
| 193 | if (ctrl == 0xffff) |
| 194 | goto io_error; |
| 195 | |
| 196 | if (ctrl & GM_SMI_CT_RD_VAL) { |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 197 | *val = gma_read16(hw, port, GM_SMI_DATA); |
| 198 | return 0; |
| 199 | } |
| 200 | |
Stephen Hemminger | af043aa | 2007-11-05 15:52:10 -0800 | [diff] [blame] | 201 | udelay(10); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Stephen Hemminger | af043aa | 2007-11-05 15:52:10 -0800 | [diff] [blame] | 204 | dev_warn(&hw->pdev->dev, "%s: phy read timeout\n", hw->dev[port]->name); |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 205 | return -ETIMEDOUT; |
Stephen Hemminger | af043aa | 2007-11-05 15:52:10 -0800 | [diff] [blame] | 206 | io_error: |
| 207 | dev_err(&hw->pdev->dev, "%s: phy I/O error\n", hw->dev[port]->name); |
| 208 | return -EIO; |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 209 | } |
| 210 | |
Stephen Hemminger | af043aa | 2007-11-05 15:52:10 -0800 | [diff] [blame] | 211 | static inline u16 gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg) |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 212 | { |
| 213 | u16 v; |
Stephen Hemminger | af043aa | 2007-11-05 15:52:10 -0800 | [diff] [blame] | 214 | __gm_phy_read(hw, port, reg, &v); |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 215 | return v; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 218 | |
| 219 | static void sky2_power_on(struct sky2_hw *hw) |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 220 | { |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 221 | /* switch power to VCC (WA for VAUX problem) */ |
| 222 | sky2_write8(hw, B0_POWER_CTRL, |
| 223 | PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 224 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 225 | /* disable Core Clock Division, */ |
| 226 | sky2_write32(hw, B2_Y2_CLK_CTRL, Y2_CLK_DIV_DIS); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 227 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 228 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) |
| 229 | /* enable bits are inverted */ |
| 230 | sky2_write8(hw, B2_Y2_CLK_GATE, |
| 231 | Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS | |
| 232 | Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS | |
| 233 | Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS); |
| 234 | else |
| 235 | sky2_write8(hw, B2_Y2_CLK_GATE, 0); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 236 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 237 | if (hw->flags & SKY2_HW_ADV_POWER_CTL) { |
Stephen Hemminger | fc99fe0 | 2007-06-04 17:23:22 -0700 | [diff] [blame] | 238 | u32 reg; |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 239 | |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 240 | sky2_pci_write32(hw, PCI_DEV_REG3, 0); |
Stephen Hemminger | b234577 | 2007-08-21 14:34:02 -0700 | [diff] [blame] | 241 | |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 242 | reg = sky2_pci_read32(hw, PCI_DEV_REG4); |
Stephen Hemminger | fc99fe0 | 2007-06-04 17:23:22 -0700 | [diff] [blame] | 243 | /* set all bits to 0 except bits 15..12 and 8 */ |
| 244 | reg &= P_ASPM_CONTROL_MSK; |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 245 | sky2_pci_write32(hw, PCI_DEV_REG4, reg); |
Stephen Hemminger | fc99fe0 | 2007-06-04 17:23:22 -0700 | [diff] [blame] | 246 | |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 247 | reg = sky2_pci_read32(hw, PCI_DEV_REG5); |
Stephen Hemminger | fc99fe0 | 2007-06-04 17:23:22 -0700 | [diff] [blame] | 248 | /* set all bits to 0 except bits 28 & 27 */ |
| 249 | reg &= P_CTL_TIM_VMAIN_AV_MSK; |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 250 | sky2_pci_write32(hw, PCI_DEV_REG5, reg); |
Stephen Hemminger | fc99fe0 | 2007-06-04 17:23:22 -0700 | [diff] [blame] | 251 | |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 252 | sky2_pci_write32(hw, PCI_CFG_REG_1, 0); |
Stephen Hemminger | 8f70920 | 2007-06-04 17:23:25 -0700 | [diff] [blame] | 253 | |
stephen hemminger | 5f8ae5c | 2010-02-12 06:57:59 +0000 | [diff] [blame] | 254 | sky2_write16(hw, B0_CTST, Y2_HW_WOL_ON); |
| 255 | |
Stephen Hemminger | 8f70920 | 2007-06-04 17:23:25 -0700 | [diff] [blame] | 256 | /* Enable workaround for dev 4.107 on Yukon-Ultra & Extreme */ |
| 257 | reg = sky2_read32(hw, B2_GP_IO); |
| 258 | reg |= GLB_GPIO_STAT_RACE_DIS; |
| 259 | sky2_write32(hw, B2_GP_IO, reg); |
Stephen Hemminger | b234577 | 2007-08-21 14:34:02 -0700 | [diff] [blame] | 260 | |
| 261 | sky2_read32(hw, B2_GP_IO); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 262 | } |
Stephen Hemminger | 10547ae | 2009-08-31 07:31:41 +0000 | [diff] [blame] | 263 | |
| 264 | /* Turn on "driver loaded" LED */ |
| 265 | sky2_write16(hw, B0_CTST, Y2_LED_STAT_ON); |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 266 | } |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 267 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 268 | static void sky2_power_aux(struct sky2_hw *hw) |
| 269 | { |
| 270 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) |
| 271 | sky2_write8(hw, B2_Y2_CLK_GATE, 0); |
| 272 | else |
| 273 | /* enable bits are inverted */ |
| 274 | sky2_write8(hw, B2_Y2_CLK_GATE, |
| 275 | Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS | |
| 276 | Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS | |
| 277 | Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS); |
| 278 | |
Stephen Hemminger | c23ddf8 | 2009-09-03 06:16:25 +0000 | [diff] [blame] | 279 | /* switch power to VAUX if supported and PME from D3cold */ |
| 280 | if ( (sky2_read32(hw, B0_CTST) & Y2_VAUX_AVAIL) && |
| 281 | pci_pme_capable(hw->pdev, PCI_D3cold)) |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 282 | sky2_write8(hw, B0_POWER_CTRL, |
| 283 | (PC_VAUX_ENA | PC_VCC_ENA | |
| 284 | PC_VAUX_ON | PC_VCC_OFF)); |
Stephen Hemminger | 10547ae | 2009-08-31 07:31:41 +0000 | [diff] [blame] | 285 | |
| 286 | /* turn off "driver loaded LED" */ |
| 287 | sky2_write16(hw, B0_CTST, Y2_LED_STAT_OFF); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 288 | } |
| 289 | |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 290 | static void sky2_gmac_reset(struct sky2_hw *hw, unsigned port) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 291 | { |
| 292 | u16 reg; |
| 293 | |
| 294 | /* disable all GMAC IRQ's */ |
| 295 | sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 296 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 297 | gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */ |
| 298 | gma_write16(hw, port, GM_MC_ADDR_H2, 0); |
| 299 | gma_write16(hw, port, GM_MC_ADDR_H3, 0); |
| 300 | gma_write16(hw, port, GM_MC_ADDR_H4, 0); |
| 301 | |
| 302 | reg = gma_read16(hw, port, GM_RX_CTRL); |
| 303 | reg |= GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA; |
| 304 | gma_write16(hw, port, GM_RX_CTRL, reg); |
| 305 | } |
| 306 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 307 | /* flow control to advertise bits */ |
| 308 | static const u16 copper_fc_adv[] = { |
| 309 | [FC_NONE] = 0, |
| 310 | [FC_TX] = PHY_M_AN_ASP, |
| 311 | [FC_RX] = PHY_M_AN_PC, |
| 312 | [FC_BOTH] = PHY_M_AN_PC | PHY_M_AN_ASP, |
| 313 | }; |
| 314 | |
| 315 | /* flow control to advertise bits when using 1000BaseX */ |
| 316 | static const u16 fiber_fc_adv[] = { |
Stephen Hemminger | df3fe1f | 2007-10-11 19:48:04 -0700 | [diff] [blame] | 317 | [FC_NONE] = PHY_M_P_NO_PAUSE_X, |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 318 | [FC_TX] = PHY_M_P_ASYM_MD_X, |
| 319 | [FC_RX] = PHY_M_P_SYM_MD_X, |
Stephen Hemminger | df3fe1f | 2007-10-11 19:48:04 -0700 | [diff] [blame] | 320 | [FC_BOTH] = PHY_M_P_BOTH_MD_X, |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 321 | }; |
| 322 | |
| 323 | /* flow control to GMA disable bits */ |
| 324 | static const u16 gm_fc_disable[] = { |
| 325 | [FC_NONE] = GM_GPCR_FC_RX_DIS | GM_GPCR_FC_TX_DIS, |
| 326 | [FC_TX] = GM_GPCR_FC_RX_DIS, |
| 327 | [FC_RX] = GM_GPCR_FC_TX_DIS, |
| 328 | [FC_BOTH] = 0, |
| 329 | }; |
| 330 | |
| 331 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 332 | static void sky2_phy_init(struct sky2_hw *hw, unsigned port) |
| 333 | { |
| 334 | struct sky2_port *sky2 = netdev_priv(hw->dev[port]); |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 335 | u16 ctrl, ct1000, adv, pg, ledctrl, ledover, reg; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 336 | |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 337 | if ( (sky2->flags & SKY2_FLAG_AUTO_SPEED) && |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 338 | !(hw->flags & SKY2_HW_NEWER_PHY)) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 339 | u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL); |
| 340 | |
| 341 | ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 342 | PHY_M_EC_MAC_S_MSK); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 343 | ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ); |
| 344 | |
Stephen Hemminger | 53419c6 | 2007-05-14 12:38:11 -0700 | [diff] [blame] | 345 | /* on PHY 88E1040 Rev.D0 (and newer) downshift control changed */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 346 | if (hw->chip_id == CHIP_ID_YUKON_EC) |
Stephen Hemminger | 53419c6 | 2007-05-14 12:38:11 -0700 | [diff] [blame] | 347 | /* set downshift counter to 3x and enable downshift */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 348 | ectrl |= PHY_M_EC_DSC_2(2) | PHY_M_EC_DOWN_S_ENA; |
| 349 | else |
Stephen Hemminger | 53419c6 | 2007-05-14 12:38:11 -0700 | [diff] [blame] | 350 | /* set master & slave downshift counter to 1x */ |
| 351 | ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 352 | |
| 353 | gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl); |
| 354 | } |
| 355 | |
| 356 | ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 357 | if (sky2_is_copper(hw)) { |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 358 | if (!(hw->flags & SKY2_HW_GIGABIT)) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 359 | /* enable automatic crossover */ |
| 360 | ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO) >> 1; |
Stephen Hemminger | 6d3105d | 2007-09-24 19:34:51 -0700 | [diff] [blame] | 361 | |
| 362 | if (hw->chip_id == CHIP_ID_YUKON_FE_P && |
| 363 | hw->chip_rev == CHIP_REV_YU_FE2_A0) { |
| 364 | u16 spec; |
| 365 | |
| 366 | /* Enable Class A driver for FE+ A0 */ |
| 367 | spec = gm_phy_read(hw, port, PHY_MARV_FE_SPEC_2); |
| 368 | spec |= PHY_M_FESC_SEL_CL_A; |
| 369 | gm_phy_write(hw, port, PHY_MARV_FE_SPEC_2, spec); |
| 370 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 371 | } else { |
| 372 | /* disable energy detect */ |
| 373 | ctrl &= ~PHY_M_PC_EN_DET_MSK; |
| 374 | |
| 375 | /* enable automatic crossover */ |
| 376 | ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO); |
| 377 | |
Stephen Hemminger | 53419c6 | 2007-05-14 12:38:11 -0700 | [diff] [blame] | 378 | /* downshift on PHY 88E1112 and 88E1149 is changed */ |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 379 | if ( (sky2->flags & SKY2_FLAG_AUTO_SPEED) && |
| 380 | (hw->flags & SKY2_HW_NEWER_PHY)) { |
Stephen Hemminger | 53419c6 | 2007-05-14 12:38:11 -0700 | [diff] [blame] | 381 | /* set downshift counter to 3x and enable downshift */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 382 | ctrl &= ~PHY_M_PC_DSC_MSK; |
| 383 | ctrl |= PHY_M_PC_DSC(2) | PHY_M_PC_DOWN_S_ENA; |
| 384 | } |
| 385 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 386 | } else { |
| 387 | /* workaround for deviation #4.88 (CRC errors) */ |
| 388 | /* disable Automatic Crossover */ |
| 389 | |
| 390 | ctrl &= ~PHY_M_PC_MDIX_MSK; |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); |
| 394 | |
| 395 | /* special setup for PHY 88E1112 Fiber */ |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 396 | if (hw->chip_id == CHIP_ID_YUKON_XL && (hw->flags & SKY2_HW_FIBRE_PHY)) { |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 397 | pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); |
| 398 | |
| 399 | /* Fiber: select 1000BASE-X only mode MAC Specific Ctrl Reg. */ |
| 400 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2); |
| 401 | ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); |
| 402 | ctrl &= ~PHY_M_MAC_MD_MSK; |
| 403 | ctrl |= PHY_M_MAC_MODE_SEL(PHY_M_MAC_MD_1000BX); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 404 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); |
| 405 | |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 406 | if (hw->pmd_type == 'P') { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 407 | /* select page 1 to access Fiber registers */ |
| 408 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 1); |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 409 | |
| 410 | /* for SFP-module set SIGDET polarity to low */ |
| 411 | ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); |
| 412 | ctrl |= PHY_M_FIB_SIGD_POL; |
Stephen Hemminger | 34dd962 | 2007-05-24 15:22:45 -0700 | [diff] [blame] | 413 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 414 | } |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 415 | |
| 416 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Stephen Hemminger | 7800fdd | 2006-10-17 10:24:10 -0700 | [diff] [blame] | 419 | ctrl = PHY_CT_RESET; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 420 | ct1000 = 0; |
| 421 | adv = PHY_AN_CSMA; |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 422 | reg = 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 423 | |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 424 | if (sky2->flags & SKY2_FLAG_AUTO_SPEED) { |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 425 | if (sky2_is_copper(hw)) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 426 | if (sky2->advertising & ADVERTISED_1000baseT_Full) |
| 427 | ct1000 |= PHY_M_1000C_AFD; |
| 428 | if (sky2->advertising & ADVERTISED_1000baseT_Half) |
| 429 | ct1000 |= PHY_M_1000C_AHD; |
| 430 | if (sky2->advertising & ADVERTISED_100baseT_Full) |
| 431 | adv |= PHY_M_AN_100_FD; |
| 432 | if (sky2->advertising & ADVERTISED_100baseT_Half) |
| 433 | adv |= PHY_M_AN_100_HD; |
| 434 | if (sky2->advertising & ADVERTISED_10baseT_Full) |
| 435 | adv |= PHY_M_AN_10_FD; |
| 436 | if (sky2->advertising & ADVERTISED_10baseT_Half) |
| 437 | adv |= PHY_M_AN_10_HD; |
Stephen Hemminger | 709c6e7 | 2006-10-17 10:24:04 -0700 | [diff] [blame] | 438 | |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 439 | } else { /* special defines for FIBER (88E1040S only) */ |
| 440 | if (sky2->advertising & ADVERTISED_1000baseT_Full) |
| 441 | adv |= PHY_M_AN_1000X_AFD; |
| 442 | if (sky2->advertising & ADVERTISED_1000baseT_Half) |
| 443 | adv |= PHY_M_AN_1000X_AHD; |
Stephen Hemminger | 709c6e7 | 2006-10-17 10:24:04 -0700 | [diff] [blame] | 444 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 445 | |
| 446 | /* Restart Auto-negotiation */ |
| 447 | ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG; |
| 448 | } else { |
| 449 | /* forced speed/duplex settings */ |
| 450 | ct1000 = PHY_M_1000C_MSE; |
| 451 | |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 452 | /* Disable auto update for duplex flow control and duplex */ |
| 453 | reg |= GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_SPD_DIS; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 454 | |
| 455 | switch (sky2->speed) { |
| 456 | case SPEED_1000: |
| 457 | ctrl |= PHY_CT_SP1000; |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 458 | reg |= GM_GPCR_SPEED_1000; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 459 | break; |
| 460 | case SPEED_100: |
| 461 | ctrl |= PHY_CT_SP100; |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 462 | reg |= GM_GPCR_SPEED_100; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 463 | break; |
| 464 | } |
| 465 | |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 466 | if (sky2->duplex == DUPLEX_FULL) { |
| 467 | reg |= GM_GPCR_DUP_FULL; |
| 468 | ctrl |= PHY_CT_DUP_MD; |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 469 | } else if (sky2->speed < SPEED_1000) |
| 470 | sky2->flow_mode = FC_NONE; |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 471 | } |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 472 | |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 473 | if (sky2->flags & SKY2_FLAG_AUTO_PAUSE) { |
| 474 | if (sky2_is_copper(hw)) |
| 475 | adv |= copper_fc_adv[sky2->flow_mode]; |
| 476 | else |
| 477 | adv |= fiber_fc_adv[sky2->flow_mode]; |
| 478 | } else { |
| 479 | reg |= GM_GPCR_AU_FCT_DIS; |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 480 | reg |= gm_fc_disable[sky2->flow_mode]; |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 481 | |
| 482 | /* Forward pause packets to GMAC? */ |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 483 | if (sky2->flow_mode & FC_RX) |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 484 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON); |
| 485 | else |
| 486 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 489 | gma_write16(hw, port, GM_GP_CTRL, reg); |
| 490 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 491 | if (hw->flags & SKY2_HW_GIGABIT) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 492 | gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000); |
| 493 | |
| 494 | gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv); |
| 495 | gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); |
| 496 | |
| 497 | /* Setup Phy LED's */ |
| 498 | ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS); |
| 499 | ledover = 0; |
| 500 | |
| 501 | switch (hw->chip_id) { |
| 502 | case CHIP_ID_YUKON_FE: |
| 503 | /* on 88E3082 these bits are at 11..9 (shifted left) */ |
| 504 | ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) << 1; |
| 505 | |
| 506 | ctrl = gm_phy_read(hw, port, PHY_MARV_FE_LED_PAR); |
| 507 | |
| 508 | /* delete ACT LED control bits */ |
| 509 | ctrl &= ~PHY_M_FELP_LED1_MSK; |
| 510 | /* change ACT LED control to blink mode */ |
| 511 | ctrl |= PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_ACT_BL); |
| 512 | gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl); |
| 513 | break; |
| 514 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 515 | case CHIP_ID_YUKON_FE_P: |
| 516 | /* Enable Link Partner Next Page */ |
| 517 | ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); |
| 518 | ctrl |= PHY_M_PC_ENA_LIP_NP; |
| 519 | |
| 520 | /* disable Energy Detect and enable scrambler */ |
| 521 | ctrl &= ~(PHY_M_PC_ENA_ENE_DT | PHY_M_PC_DIS_SCRAMB); |
| 522 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); |
| 523 | |
| 524 | /* set LED2 -> ACT, LED1 -> LINK, LED0 -> SPEED */ |
| 525 | ctrl = PHY_M_FELP_LED2_CTRL(LED_PAR_CTRL_ACT_BL) | |
| 526 | PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_LINK) | |
| 527 | PHY_M_FELP_LED0_CTRL(LED_PAR_CTRL_SPEED); |
| 528 | |
| 529 | gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl); |
| 530 | break; |
| 531 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 532 | case CHIP_ID_YUKON_XL: |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 533 | pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 534 | |
| 535 | /* select page 3 to access LED control register */ |
| 536 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); |
| 537 | |
| 538 | /* set LED Function Control register */ |
Stephen Hemminger | ed6d32c | 2006-05-08 15:11:33 -0700 | [diff] [blame] | 539 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, |
| 540 | (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */ |
| 541 | PHY_M_LEDC_INIT_CTRL(7) | /* 10 Mbps */ |
| 542 | PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */ |
| 543 | PHY_M_LEDC_STA0_CTRL(7))); /* 1000 Mbps */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 544 | |
| 545 | /* set Polarity Control register */ |
| 546 | gm_phy_write(hw, port, PHY_MARV_PHY_STAT, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 547 | (PHY_M_POLC_LS1_P_MIX(4) | |
| 548 | PHY_M_POLC_IS0_P_MIX(4) | |
| 549 | PHY_M_POLC_LOS_CTRL(2) | |
| 550 | PHY_M_POLC_INIT_CTRL(2) | |
| 551 | PHY_M_POLC_STA1_CTRL(2) | |
| 552 | PHY_M_POLC_STA0_CTRL(2))); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 553 | |
| 554 | /* restore page register */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 555 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 556 | break; |
Stephen Hemminger | 9374549 | 2007-02-06 10:45:43 -0800 | [diff] [blame] | 557 | |
Stephen Hemminger | ed6d32c | 2006-05-08 15:11:33 -0700 | [diff] [blame] | 558 | case CHIP_ID_YUKON_EC_U: |
Stephen Hemminger | 9374549 | 2007-02-06 10:45:43 -0800 | [diff] [blame] | 559 | case CHIP_ID_YUKON_EX: |
Stephen Hemminger | ed4d416 | 2008-01-10 16:14:14 -0800 | [diff] [blame] | 560 | case CHIP_ID_YUKON_SUPR: |
Stephen Hemminger | ed6d32c | 2006-05-08 15:11:33 -0700 | [diff] [blame] | 561 | pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); |
| 562 | |
| 563 | /* select page 3 to access LED control register */ |
| 564 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); |
| 565 | |
| 566 | /* set LED Function Control register */ |
| 567 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, |
| 568 | (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */ |
| 569 | PHY_M_LEDC_INIT_CTRL(8) | /* 10 Mbps */ |
| 570 | PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */ |
| 571 | PHY_M_LEDC_STA0_CTRL(7)));/* 1000 Mbps */ |
| 572 | |
| 573 | /* set Blink Rate in LED Timer Control Register */ |
| 574 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, |
| 575 | ledctrl | PHY_M_LED_BLINK_RT(BLINK_84MS)); |
| 576 | /* restore page register */ |
| 577 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); |
| 578 | break; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 579 | |
| 580 | default: |
| 581 | /* set Tx LED (LED_TX) to blink mode on Rx OR Tx activity */ |
| 582 | ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL; |
Stephen Hemminger | a84d0a3 | 2008-02-22 16:00:33 -0800 | [diff] [blame] | 583 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 584 | /* turn off the Rx LED (LED_RX) */ |
Stephen Hemminger | a84d0a3 | 2008-02-22 16:00:33 -0800 | [diff] [blame] | 585 | ledover |= PHY_M_LED_MO_RX(MO_LED_OFF); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Stephen Hemminger | 0ce8b98 | 2008-06-17 09:04:27 -0700 | [diff] [blame] | 588 | if (hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_UL_2) { |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 589 | /* apply fixes in PHY AFE */ |
Stephen Hemminger | ed6d32c | 2006-05-08 15:11:33 -0700 | [diff] [blame] | 590 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 255); |
| 591 | |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 592 | /* increase differential signal amplitude in 10BASE-T */ |
Stephen Hemminger | ed6d32c | 2006-05-08 15:11:33 -0700 | [diff] [blame] | 593 | gm_phy_write(hw, port, 0x18, 0xaa99); |
| 594 | gm_phy_write(hw, port, 0x17, 0x2011); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 595 | |
Stephen Hemminger | 0ce8b98 | 2008-06-17 09:04:27 -0700 | [diff] [blame] | 596 | if (hw->chip_id == CHIP_ID_YUKON_EC_U) { |
| 597 | /* fix for IEEE A/B Symmetry failure in 1000BASE-T */ |
| 598 | gm_phy_write(hw, port, 0x18, 0xa204); |
| 599 | gm_phy_write(hw, port, 0x17, 0x2002); |
| 600 | } |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 601 | |
| 602 | /* set page register to 0 */ |
Stephen Hemminger | 9467a8f | 2007-04-07 16:02:28 -0700 | [diff] [blame] | 603 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0); |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 604 | } else if (hw->chip_id == CHIP_ID_YUKON_FE_P && |
| 605 | hw->chip_rev == CHIP_REV_YU_FE2_A0) { |
| 606 | /* apply workaround for integrated resistors calibration */ |
| 607 | gm_phy_write(hw, port, PHY_MARV_PAGE_ADDR, 17); |
| 608 | gm_phy_write(hw, port, PHY_MARV_PAGE_DATA, 0x3f60); |
Stephen Hemminger | 0f5aac7 | 2009-10-29 06:37:09 +0000 | [diff] [blame] | 609 | } else if (hw->chip_id == CHIP_ID_YUKON_OPT && hw->chip_rev == 0) { |
| 610 | /* apply fixes in PHY AFE */ |
| 611 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0x00ff); |
| 612 | |
| 613 | /* apply RDAC termination workaround */ |
| 614 | gm_phy_write(hw, port, 24, 0x2800); |
| 615 | gm_phy_write(hw, port, 23, 0x2001); |
| 616 | |
| 617 | /* set page register back to 0 */ |
| 618 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0); |
Stephen Hemminger | e1a74b3 | 2008-06-17 09:04:24 -0700 | [diff] [blame] | 619 | } else if (hw->chip_id != CHIP_ID_YUKON_EX && |
| 620 | hw->chip_id < CHIP_ID_YUKON_SUPR) { |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 621 | /* no effect on Yukon-XL */ |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 622 | gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl); |
| 623 | |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 624 | if (!(sky2->flags & SKY2_FLAG_AUTO_SPEED) || |
| 625 | sky2->speed == SPEED_100) { |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 626 | /* turn on 100 Mbps LED (LED_LINK100) */ |
Stephen Hemminger | a84d0a3 | 2008-02-22 16:00:33 -0800 | [diff] [blame] | 627 | ledover |= PHY_M_LED_MO_100(MO_LED_ON); |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | if (ledover) |
| 631 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover); |
| 632 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 633 | } |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 634 | |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 635 | /* Enable phy interrupt on auto-negotiation complete (or link up) */ |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 636 | if (sky2->flags & SKY2_FLAG_AUTO_SPEED) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 637 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL); |
| 638 | else |
| 639 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); |
| 640 | } |
| 641 | |
Stephen Hemminger | b96936da7 | 2008-05-14 17:04:15 -0700 | [diff] [blame] | 642 | static const u32 phy_power[] = { PCI_Y2_PHY1_POWD, PCI_Y2_PHY2_POWD }; |
| 643 | static const u32 coma_mode[] = { PCI_Y2_PHY1_COMA, PCI_Y2_PHY2_COMA }; |
| 644 | |
| 645 | static void sky2_phy_power_up(struct sky2_hw *hw, unsigned port) |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 646 | { |
| 647 | u32 reg1; |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 648 | |
stephen hemminger | a40ccc6 | 2010-01-24 18:46:06 +0000 | [diff] [blame] | 649 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 650 | reg1 = sky2_pci_read32(hw, PCI_DEV_REG1); |
Stephen Hemminger | b96936da7 | 2008-05-14 17:04:15 -0700 | [diff] [blame] | 651 | reg1 &= ~phy_power[port]; |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 652 | |
Stephen Hemminger | b96936da7 | 2008-05-14 17:04:15 -0700 | [diff] [blame] | 653 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) |
Stephen Hemminger | ff35164e | 2007-10-11 19:47:44 -0700 | [diff] [blame] | 654 | reg1 |= coma_mode[port]; |
| 655 | |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 656 | sky2_pci_write32(hw, PCI_DEV_REG1, reg1); |
stephen hemminger | a40ccc6 | 2010-01-24 18:46:06 +0000 | [diff] [blame] | 657 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
Stephen Hemminger | 82637e8 | 2008-01-23 19:16:04 -0800 | [diff] [blame] | 658 | sky2_pci_read32(hw, PCI_DEV_REG1); |
Stephen Hemminger | f71eb1a | 2008-08-04 13:33:37 -0700 | [diff] [blame] | 659 | |
| 660 | if (hw->chip_id == CHIP_ID_YUKON_FE) |
| 661 | gm_phy_write(hw, port, PHY_MARV_CTRL, PHY_CT_ANE); |
| 662 | else if (hw->flags & SKY2_HW_ADV_POWER_CTL) |
| 663 | sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR); |
Stephen Hemminger | b96936da7 | 2008-05-14 17:04:15 -0700 | [diff] [blame] | 664 | } |
Stephen Hemminger | 167f53d | 2007-09-25 19:01:02 -0700 | [diff] [blame] | 665 | |
Stephen Hemminger | b96936da7 | 2008-05-14 17:04:15 -0700 | [diff] [blame] | 666 | static void sky2_phy_power_down(struct sky2_hw *hw, unsigned port) |
| 667 | { |
| 668 | u32 reg1; |
Stephen Hemminger | db99b98 | 2008-05-14 17:04:16 -0700 | [diff] [blame] | 669 | u16 ctrl; |
| 670 | |
| 671 | /* release GPHY Control reset */ |
| 672 | sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR); |
| 673 | |
| 674 | /* release GMAC reset */ |
| 675 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR); |
| 676 | |
| 677 | if (hw->flags & SKY2_HW_NEWER_PHY) { |
| 678 | /* select page 2 to access MAC control register */ |
| 679 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2); |
| 680 | |
| 681 | ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); |
| 682 | /* allow GMII Power Down */ |
| 683 | ctrl &= ~PHY_M_MAC_GMIF_PUP; |
| 684 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); |
| 685 | |
| 686 | /* set page register back to 0 */ |
| 687 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0); |
| 688 | } |
| 689 | |
| 690 | /* setup General Purpose Control Register */ |
| 691 | gma_write16(hw, port, GM_GP_CTRL, |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 692 | GM_GPCR_FL_PASS | GM_GPCR_SPEED_100 | |
| 693 | GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_FCT_DIS | |
| 694 | GM_GPCR_AU_SPD_DIS); |
Stephen Hemminger | db99b98 | 2008-05-14 17:04:16 -0700 | [diff] [blame] | 695 | |
| 696 | if (hw->chip_id != CHIP_ID_YUKON_EC) { |
| 697 | if (hw->chip_id == CHIP_ID_YUKON_EC_U) { |
Rafael J. Wysocki | e484d5f | 2008-08-10 19:30:28 +0200 | [diff] [blame] | 698 | /* select page 2 to access MAC control register */ |
| 699 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2); |
Stephen Hemminger | db99b98 | 2008-05-14 17:04:16 -0700 | [diff] [blame] | 700 | |
Rafael J. Wysocki | e484d5f | 2008-08-10 19:30:28 +0200 | [diff] [blame] | 701 | ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); |
Stephen Hemminger | db99b98 | 2008-05-14 17:04:16 -0700 | [diff] [blame] | 702 | /* enable Power Down */ |
| 703 | ctrl |= PHY_M_PC_POW_D_ENA; |
| 704 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); |
Rafael J. Wysocki | e484d5f | 2008-08-10 19:30:28 +0200 | [diff] [blame] | 705 | |
| 706 | /* set page register back to 0 */ |
| 707 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0); |
Stephen Hemminger | db99b98 | 2008-05-14 17:04:16 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | /* set IEEE compatible Power Down Mode (dev. #4.99) */ |
| 711 | gm_phy_write(hw, port, PHY_MARV_CTRL, PHY_CT_PDOWN); |
| 712 | } |
Stephen Hemminger | b96936da7 | 2008-05-14 17:04:15 -0700 | [diff] [blame] | 713 | |
stephen hemminger | a40ccc6 | 2010-01-24 18:46:06 +0000 | [diff] [blame] | 714 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
Stephen Hemminger | b96936da7 | 2008-05-14 17:04:15 -0700 | [diff] [blame] | 715 | reg1 = sky2_pci_read32(hw, PCI_DEV_REG1); |
Stephen Hemminger | db99b98 | 2008-05-14 17:04:16 -0700 | [diff] [blame] | 716 | reg1 |= phy_power[port]; /* set PHY to PowerDown/COMA Mode */ |
Stephen Hemminger | b96936da7 | 2008-05-14 17:04:15 -0700 | [diff] [blame] | 717 | sky2_pci_write32(hw, PCI_DEV_REG1, reg1); |
stephen hemminger | a40ccc6 | 2010-01-24 18:46:06 +0000 | [diff] [blame] | 718 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 721 | /* Force a renegotiation */ |
| 722 | static void sky2_phy_reinit(struct sky2_port *sky2) |
| 723 | { |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 724 | spin_lock_bh(&sky2->phy_lock); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 725 | sky2_phy_init(sky2->hw, sky2->port); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 726 | spin_unlock_bh(&sky2->phy_lock); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 727 | } |
| 728 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 729 | /* Put device in state to listen for Wake On Lan */ |
| 730 | static void sky2_wol_init(struct sky2_port *sky2) |
| 731 | { |
| 732 | struct sky2_hw *hw = sky2->hw; |
| 733 | unsigned port = sky2->port; |
| 734 | enum flow_control save_mode; |
| 735 | u16 ctrl; |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 736 | |
| 737 | /* Bring hardware out of reset */ |
| 738 | sky2_write16(hw, B0_CTST, CS_RST_CLR); |
| 739 | sky2_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR); |
| 740 | |
| 741 | sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR); |
| 742 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR); |
| 743 | |
| 744 | /* Force to 10/100 |
| 745 | * sky2_reset will re-enable on resume |
| 746 | */ |
| 747 | save_mode = sky2->flow_mode; |
| 748 | ctrl = sky2->advertising; |
| 749 | |
| 750 | sky2->advertising &= ~(ADVERTISED_1000baseT_Half|ADVERTISED_1000baseT_Full); |
| 751 | sky2->flow_mode = FC_NONE; |
Stephen Hemminger | b96936da7 | 2008-05-14 17:04:15 -0700 | [diff] [blame] | 752 | |
| 753 | spin_lock_bh(&sky2->phy_lock); |
| 754 | sky2_phy_power_up(hw, port); |
| 755 | sky2_phy_init(hw, port); |
| 756 | spin_unlock_bh(&sky2->phy_lock); |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 757 | |
| 758 | sky2->flow_mode = save_mode; |
| 759 | sky2->advertising = ctrl; |
| 760 | |
| 761 | /* Set GMAC to no flow control and auto update for speed/duplex */ |
| 762 | gma_write16(hw, port, GM_GP_CTRL, |
| 763 | GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA| |
| 764 | GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS); |
| 765 | |
| 766 | /* Set WOL address */ |
| 767 | memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR), |
| 768 | sky2->netdev->dev_addr, ETH_ALEN); |
| 769 | |
| 770 | /* Turn on appropriate WOL control bits */ |
| 771 | sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT); |
| 772 | ctrl = 0; |
| 773 | if (sky2->wol & WAKE_PHY) |
| 774 | ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT; |
| 775 | else |
| 776 | ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT; |
| 777 | |
| 778 | if (sky2->wol & WAKE_MAGIC) |
| 779 | ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT; |
| 780 | else |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 781 | ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT; |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 782 | |
| 783 | ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT; |
| 784 | sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl); |
| 785 | |
stephen hemminger | 5f8ae5c | 2010-02-12 06:57:59 +0000 | [diff] [blame] | 786 | /* Disable PiG firmware */ |
| 787 | sky2_write16(hw, B0_CTST, Y2_HW_WOL_OFF); |
| 788 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 789 | /* block receiver */ |
| 790 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 791 | } |
| 792 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 793 | static void sky2_set_tx_stfwd(struct sky2_hw *hw, unsigned port) |
| 794 | { |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 795 | struct net_device *dev = hw->dev[port]; |
| 796 | |
Stephen Hemminger | ed4d416 | 2008-01-10 16:14:14 -0800 | [diff] [blame] | 797 | if ( (hw->chip_id == CHIP_ID_YUKON_EX && |
| 798 | hw->chip_rev != CHIP_REV_YU_EX_A0) || |
Stephen Hemminger | 877c857 | 2009-10-29 06:37:08 +0000 | [diff] [blame] | 799 | hw->chip_id >= CHIP_ID_YUKON_FE_P) { |
Stephen Hemminger | ed4d416 | 2008-01-10 16:14:14 -0800 | [diff] [blame] | 800 | /* Yukon-Extreme B0 and further Extreme devices */ |
stephen hemminger | 44dde56 | 2010-02-12 06:58:01 +0000 | [diff] [blame] | 801 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_ENA); |
| 802 | } else if (dev->mtu > ETH_DATA_LEN) { |
| 803 | /* set Tx GMAC FIFO Almost Empty Threshold */ |
| 804 | sky2_write32(hw, SK_REG(port, TX_GMF_AE_THR), |
| 805 | (ECU_JUMBO_WM << 16) | ECU_AE_THR); |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 806 | |
stephen hemminger | 44dde56 | 2010-02-12 06:58:01 +0000 | [diff] [blame] | 807 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_DIS); |
| 808 | } else |
| 809 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_ENA); |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 812 | static void sky2_mac_init(struct sky2_hw *hw, unsigned port) |
| 813 | { |
| 814 | struct sky2_port *sky2 = netdev_priv(hw->dev[port]); |
| 815 | u16 reg; |
Al Viro | 25cccec | 2007-07-20 16:07:33 +0100 | [diff] [blame] | 816 | u32 rx_reg; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 817 | int i; |
| 818 | const u8 *addr = hw->dev[port]->dev_addr; |
| 819 | |
Stephen Hemminger | f350339 | 2007-08-21 11:10:22 -0700 | [diff] [blame] | 820 | sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET); |
| 821 | sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 822 | |
| 823 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR); |
| 824 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 825 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0 && port == 1) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 826 | /* WA DEV_472 -- looks like crossed wires on port 2 */ |
| 827 | /* clear GMAC 1 Control reset */ |
| 828 | sky2_write8(hw, SK_REG(0, GMAC_CTRL), GMC_RST_CLR); |
| 829 | do { |
| 830 | sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_SET); |
| 831 | sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_CLR); |
| 832 | } while (gm_phy_read(hw, 1, PHY_MARV_ID0) != PHY_MARV_ID0_VAL || |
| 833 | gm_phy_read(hw, 1, PHY_MARV_ID1) != PHY_MARV_ID1_Y2 || |
| 834 | gm_phy_read(hw, 1, PHY_MARV_INT_MASK) != 0); |
| 835 | } |
| 836 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 837 | sky2_read16(hw, SK_REG(port, GMAC_IRQ_SRC)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 838 | |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 839 | /* Enable Transmit FIFO Underrun */ |
| 840 | sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK); |
| 841 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 842 | spin_lock_bh(&sky2->phy_lock); |
Stephen Hemminger | b96936da7 | 2008-05-14 17:04:15 -0700 | [diff] [blame] | 843 | sky2_phy_power_up(hw, port); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 844 | sky2_phy_init(hw, port); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 845 | spin_unlock_bh(&sky2->phy_lock); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 846 | |
| 847 | /* MIB clear */ |
| 848 | reg = gma_read16(hw, port, GM_PHY_ADDR); |
| 849 | gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR); |
| 850 | |
Stephen Hemminger | 43f2f10 | 2006-04-05 17:47:15 -0700 | [diff] [blame] | 851 | for (i = GM_MIB_CNT_BASE; i <= GM_MIB_CNT_END; i += 4) |
| 852 | gma_read16(hw, port, i); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 853 | gma_write16(hw, port, GM_PHY_ADDR, reg); |
| 854 | |
| 855 | /* transmit control */ |
| 856 | gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF)); |
| 857 | |
| 858 | /* receive control reg: unicast + multicast + no FCS */ |
| 859 | gma_write16(hw, port, GM_RX_CTRL, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 860 | GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 861 | |
| 862 | /* transmit flow control */ |
| 863 | gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff); |
| 864 | |
| 865 | /* transmit parameter */ |
| 866 | gma_write16(hw, port, GM_TX_PARAM, |
| 867 | TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) | |
| 868 | TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) | |
| 869 | TX_IPG_JAM_DATA(TX_IPG_JAM_DEF) | |
| 870 | TX_BACK_OFF_LIM(TX_BOF_LIM_DEF)); |
| 871 | |
| 872 | /* serial mode register */ |
| 873 | reg = DATA_BLIND_VAL(DATA_BLIND_DEF) | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 874 | GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 875 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 876 | if (hw->dev[port]->mtu > ETH_DATA_LEN) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 877 | reg |= GM_SMOD_JUMBO_ENA; |
| 878 | |
| 879 | gma_write16(hw, port, GM_SERIAL_MODE, reg); |
| 880 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 881 | /* virtual address for data */ |
| 882 | gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr); |
| 883 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 884 | /* physical address: used for pause frames */ |
| 885 | gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr); |
| 886 | |
| 887 | /* ignore counter overflows */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 888 | gma_write16(hw, port, GM_TX_IRQ_MSK, 0); |
| 889 | gma_write16(hw, port, GM_RX_IRQ_MSK, 0); |
| 890 | gma_write16(hw, port, GM_TR_IRQ_MSK, 0); |
| 891 | |
| 892 | /* Configure Rx MAC FIFO */ |
| 893 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR); |
Al Viro | 25cccec | 2007-07-20 16:07:33 +0100 | [diff] [blame] | 894 | rx_reg = GMF_OPER_ON | GMF_RX_F_FL_ON; |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 895 | if (hw->chip_id == CHIP_ID_YUKON_EX || |
| 896 | hw->chip_id == CHIP_ID_YUKON_FE_P) |
Al Viro | 25cccec | 2007-07-20 16:07:33 +0100 | [diff] [blame] | 897 | rx_reg |= GMF_RX_OVER_ON; |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 898 | |
Al Viro | 25cccec | 2007-07-20 16:07:33 +0100 | [diff] [blame] | 899 | sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), rx_reg); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 900 | |
Stephen Hemminger | 798fdd0 | 2007-12-07 15:22:15 -0800 | [diff] [blame] | 901 | if (hw->chip_id == CHIP_ID_YUKON_XL) { |
| 902 | /* Hardware errata - clear flush mask */ |
| 903 | sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), 0); |
| 904 | } else { |
| 905 | /* Flush Rx MAC FIFO on any flow control or error */ |
| 906 | sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR); |
| 907 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 908 | |
Stephen Hemminger | 8df9a87 | 2006-12-01 14:29:35 -0800 | [diff] [blame] | 909 | /* Set threshold to 0xa (64 bytes) + 1 to workaround pause bug */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 910 | reg = RX_GMF_FL_THR_DEF + 1; |
| 911 | /* Another magic mystery workaround from sk98lin */ |
| 912 | if (hw->chip_id == CHIP_ID_YUKON_FE_P && |
| 913 | hw->chip_rev == CHIP_REV_YU_FE2_A0) |
| 914 | reg = 0x178; |
| 915 | sky2_write16(hw, SK_REG(port, RX_GMF_FL_THR), reg); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 916 | |
| 917 | /* Configure Tx MAC FIFO */ |
| 918 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR); |
| 919 | sky2_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON); |
shemminger@osdl.org | 5a5b1ea | 2005-11-30 11:45:15 -0800 | [diff] [blame] | 920 | |
Stephen Hemminger | e0c2811 | 2007-09-20 13:03:49 -0700 | [diff] [blame] | 921 | /* On chips without ram buffer, pause is controled by MAC level */ |
Stephen Hemminger | 39dbd95 | 2008-02-04 19:45:13 -0800 | [diff] [blame] | 922 | if (!(hw->flags & SKY2_HW_RAM_BUFFER)) { |
Stephen Hemminger | d6b54d2 | 2009-10-29 06:37:07 +0000 | [diff] [blame] | 923 | /* Pause threshold is scaled by 8 in bytes */ |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 924 | if (hw->chip_id == CHIP_ID_YUKON_FE_P && |
| 925 | hw->chip_rev == CHIP_REV_YU_FE2_A0) |
Stephen Hemminger | d6b54d2 | 2009-10-29 06:37:07 +0000 | [diff] [blame] | 926 | reg = 1568 / 8; |
| 927 | else |
| 928 | reg = 1024 / 8; |
| 929 | sky2_write16(hw, SK_REG(port, RX_GMF_UP_THR), reg); |
| 930 | sky2_write16(hw, SK_REG(port, RX_GMF_LP_THR), 768 / 8); |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 931 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 932 | sky2_set_tx_stfwd(hw, port); |
shemminger@osdl.org | 5a5b1ea | 2005-11-30 11:45:15 -0800 | [diff] [blame] | 933 | } |
| 934 | |
Stephen Hemminger | e970d1f | 2007-11-27 11:02:07 -0800 | [diff] [blame] | 935 | if (hw->chip_id == CHIP_ID_YUKON_FE_P && |
| 936 | hw->chip_rev == CHIP_REV_YU_FE2_A0) { |
| 937 | /* disable dynamic watermark */ |
| 938 | reg = sky2_read16(hw, SK_REG(port, TX_GMF_EA)); |
| 939 | reg &= ~TX_DYN_WM_ENA; |
| 940 | sky2_write16(hw, SK_REG(port, TX_GMF_EA), reg); |
| 941 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Stephen Hemminger | 6771290 | 2006-12-04 15:53:45 -0800 | [diff] [blame] | 944 | /* Assign Ram Buffer allocation to queue */ |
| 945 | static void sky2_ramset(struct sky2_hw *hw, u16 q, u32 start, u32 space) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 946 | { |
Stephen Hemminger | 6771290 | 2006-12-04 15:53:45 -0800 | [diff] [blame] | 947 | u32 end; |
| 948 | |
| 949 | /* convert from K bytes to qwords used for hw register */ |
| 950 | start *= 1024/8; |
| 951 | space *= 1024/8; |
| 952 | end = start + space - 1; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 953 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 954 | sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR); |
| 955 | sky2_write32(hw, RB_ADDR(q, RB_START), start); |
| 956 | sky2_write32(hw, RB_ADDR(q, RB_END), end); |
| 957 | sky2_write32(hw, RB_ADDR(q, RB_WP), start); |
| 958 | sky2_write32(hw, RB_ADDR(q, RB_RP), start); |
| 959 | |
| 960 | if (q == Q_R1 || q == Q_R2) { |
Stephen Hemminger | 1c28f6b | 2006-01-17 13:43:13 -0800 | [diff] [blame] | 961 | u32 tp = space - space/4; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 962 | |
Stephen Hemminger | 1c28f6b | 2006-01-17 13:43:13 -0800 | [diff] [blame] | 963 | /* On receive queue's set the thresholds |
| 964 | * give receiver priority when > 3/4 full |
| 965 | * send pause when down to 2K |
| 966 | */ |
| 967 | sky2_write32(hw, RB_ADDR(q, RB_RX_UTHP), tp); |
| 968 | sky2_write32(hw, RB_ADDR(q, RB_RX_LTHP), space/2); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 969 | |
Stephen Hemminger | 1c28f6b | 2006-01-17 13:43:13 -0800 | [diff] [blame] | 970 | tp = space - 2048/8; |
| 971 | sky2_write32(hw, RB_ADDR(q, RB_RX_UTPP), tp); |
| 972 | sky2_write32(hw, RB_ADDR(q, RB_RX_LTPP), space/4); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 973 | } else { |
| 974 | /* Enable store & forward on Tx queue's because |
| 975 | * Tx FIFO is only 1K on Yukon |
| 976 | */ |
| 977 | sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD); |
| 978 | } |
| 979 | |
| 980 | sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 981 | sky2_read8(hw, RB_ADDR(q, RB_CTRL)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 982 | } |
| 983 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 984 | /* Setup Bus Memory Interface */ |
shemminger@osdl.org | af4ed7e | 2005-11-30 11:45:21 -0800 | [diff] [blame] | 985 | static void sky2_qset(struct sky2_hw *hw, u16 q) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 986 | { |
| 987 | sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_RESET); |
| 988 | sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_OPER_INIT); |
| 989 | sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_FIFO_OP_ON); |
shemminger@osdl.org | af4ed7e | 2005-11-30 11:45:21 -0800 | [diff] [blame] | 990 | sky2_write32(hw, Q_ADDR(q, Q_WM), BMU_WM_DEFAULT); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 993 | /* Setup prefetch unit registers. This is the interface between |
| 994 | * hardware and driver list elements |
| 995 | */ |
Stephen Hemminger | 8cc048e | 2005-12-09 11:35:07 -0800 | [diff] [blame] | 996 | static void sky2_prefetch_init(struct sky2_hw *hw, u32 qaddr, |
Stephen Hemminger | d6e74b6 | 2009-08-18 15:17:05 +0000 | [diff] [blame] | 997 | dma_addr_t addr, u32 last) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 998 | { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 999 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_SET); |
| 1000 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_CLR); |
Stephen Hemminger | d6e74b6 | 2009-08-18 15:17:05 +0000 | [diff] [blame] | 1001 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_HI), upper_32_bits(addr)); |
| 1002 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_LO), lower_32_bits(addr)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1003 | sky2_write16(hw, Y2_QADDR(qaddr, PREF_UNIT_LAST_IDX), last); |
| 1004 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_OP_ON); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1005 | |
| 1006 | sky2_read32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1009 | static inline struct sky2_tx_le *get_tx_le(struct sky2_port *sky2, u16 *slot) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1010 | { |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1011 | struct sky2_tx_le *le = sky2->tx_le + *slot; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1012 | |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 1013 | *slot = RING_NEXT(*slot, sky2->tx_ring_size); |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1014 | le->ctrl = 0; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1015 | return le; |
| 1016 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1017 | |
Stephen Hemminger | 88f5f0c | 2007-09-27 12:38:12 -0700 | [diff] [blame] | 1018 | static void tx_init(struct sky2_port *sky2) |
| 1019 | { |
| 1020 | struct sky2_tx_le *le; |
| 1021 | |
| 1022 | sky2->tx_prod = sky2->tx_cons = 0; |
| 1023 | sky2->tx_tcpsum = 0; |
| 1024 | sky2->tx_last_mss = 0; |
| 1025 | |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1026 | le = get_tx_le(sky2, &sky2->tx_prod); |
Stephen Hemminger | 88f5f0c | 2007-09-27 12:38:12 -0700 | [diff] [blame] | 1027 | le->addr = 0; |
| 1028 | le->opcode = OP_ADDR64 | HW_OWNER; |
Stephen Hemminger | 5dce95e | 2009-08-18 15:17:06 +0000 | [diff] [blame] | 1029 | sky2->tx_last_upper = 0; |
Stephen Hemminger | 88f5f0c | 2007-09-27 12:38:12 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
Stephen Hemminger | 290d4de | 2006-03-20 15:48:15 -0800 | [diff] [blame] | 1032 | /* Update chip's next pointer */ |
| 1033 | static inline void sky2_put_idx(struct sky2_hw *hw, unsigned q, u16 idx) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1034 | { |
Stephen Hemminger | 50432cb | 2007-05-14 12:38:15 -0700 | [diff] [blame] | 1035 | /* Make sure write' to descriptors are complete before we tell hardware */ |
Stephen Hemminger | 762c2de | 2006-01-17 13:43:14 -0800 | [diff] [blame] | 1036 | wmb(); |
Stephen Hemminger | 50432cb | 2007-05-14 12:38:15 -0700 | [diff] [blame] | 1037 | sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), idx); |
| 1038 | |
| 1039 | /* Synchronize I/O on since next processor may write to tail */ |
| 1040 | mmiowb(); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1043 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1044 | static inline struct sky2_rx_le *sky2_next_rx(struct sky2_port *sky2) |
| 1045 | { |
| 1046 | struct sky2_rx_le *le = sky2->rx_le + sky2->rx_put; |
Stephen Hemminger | cb5d954 | 2006-05-08 15:11:29 -0700 | [diff] [blame] | 1047 | sky2->rx_put = RING_NEXT(sky2->rx_put, RX_LE_SIZE); |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1048 | le->ctrl = 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1049 | return le; |
| 1050 | } |
| 1051 | |
Mike McCormack | 39ef110 | 2010-02-12 06:58:02 +0000 | [diff] [blame] | 1052 | static unsigned sky2_get_rx_threshold(struct sky2_port* sky2) |
| 1053 | { |
| 1054 | unsigned size; |
| 1055 | |
| 1056 | /* Space needed for frame data + headers rounded up */ |
| 1057 | size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8); |
| 1058 | |
| 1059 | /* Stopping point for hardware truncation */ |
| 1060 | return (size - 8) / sizeof(u32); |
| 1061 | } |
| 1062 | |
| 1063 | static unsigned sky2_get_rx_data_size(struct sky2_port* sky2) |
| 1064 | { |
| 1065 | struct rx_ring_info *re; |
| 1066 | unsigned size; |
| 1067 | |
| 1068 | /* Space needed for frame data + headers rounded up */ |
| 1069 | size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8); |
| 1070 | |
| 1071 | sky2->rx_nfrags = size >> PAGE_SHIFT; |
| 1072 | BUG_ON(sky2->rx_nfrags > ARRAY_SIZE(re->frag_addr)); |
| 1073 | |
| 1074 | /* Compute residue after pages */ |
| 1075 | size -= sky2->rx_nfrags << PAGE_SHIFT; |
| 1076 | |
| 1077 | /* Optimize to handle small packets and headers */ |
| 1078 | if (size < copybreak) |
| 1079 | size = copybreak; |
| 1080 | if (size < ETH_HLEN) |
| 1081 | size = ETH_HLEN; |
| 1082 | |
| 1083 | return size; |
| 1084 | } |
| 1085 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1086 | /* Build description to hardware for one receive segment */ |
| 1087 | static void sky2_rx_add(struct sky2_port *sky2, u8 op, |
| 1088 | dma_addr_t map, unsigned len) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1089 | { |
| 1090 | struct sky2_rx_le *le; |
| 1091 | |
Stephen Hemminger | 86c6887 | 2008-01-10 16:14:12 -0800 | [diff] [blame] | 1092 | if (sizeof(dma_addr_t) > sizeof(u32)) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1093 | le = sky2_next_rx(sky2); |
Stephen Hemminger | 86c6887 | 2008-01-10 16:14:12 -0800 | [diff] [blame] | 1094 | le->addr = cpu_to_le32(upper_32_bits(map)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1095 | le->opcode = OP_ADDR64 | HW_OWNER; |
| 1096 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1097 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1098 | le = sky2_next_rx(sky2); |
Stephen Hemminger | d6e74b6 | 2009-08-18 15:17:05 +0000 | [diff] [blame] | 1099 | le->addr = cpu_to_le32(lower_32_bits(map)); |
Stephen Hemminger | 734d186 | 2005-12-09 11:35:00 -0800 | [diff] [blame] | 1100 | le->length = cpu_to_le16(len); |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1101 | le->opcode = op | HW_OWNER; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1104 | /* Build description to hardware for one possibly fragmented skb */ |
| 1105 | static void sky2_rx_submit(struct sky2_port *sky2, |
| 1106 | const struct rx_ring_info *re) |
| 1107 | { |
| 1108 | int i; |
| 1109 | |
| 1110 | sky2_rx_add(sky2, OP_PACKET, re->data_addr, sky2->rx_data_size); |
| 1111 | |
| 1112 | for (i = 0; i < skb_shinfo(re->skb)->nr_frags; i++) |
| 1113 | sky2_rx_add(sky2, OP_BUFFER, re->frag_addr[i], PAGE_SIZE); |
| 1114 | } |
| 1115 | |
| 1116 | |
Stephen Hemminger | 454e6cb6 | 2009-02-03 11:27:28 +0000 | [diff] [blame] | 1117 | static int sky2_rx_map_skb(struct pci_dev *pdev, struct rx_ring_info *re, |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1118 | unsigned size) |
| 1119 | { |
| 1120 | struct sk_buff *skb = re->skb; |
| 1121 | int i; |
| 1122 | |
| 1123 | re->data_addr = pci_map_single(pdev, skb->data, size, PCI_DMA_FROMDEVICE); |
stephen hemminger | 3fbd918 | 2010-02-01 13:45:41 +0000 | [diff] [blame] | 1124 | if (pci_dma_mapping_error(pdev, re->data_addr)) |
| 1125 | goto mapping_error; |
Stephen Hemminger | 454e6cb6 | 2009-02-03 11:27:28 +0000 | [diff] [blame] | 1126 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1127 | pci_unmap_len_set(re, data_size, size); |
| 1128 | |
stephen hemminger | 3fbd918 | 2010-02-01 13:45:41 +0000 | [diff] [blame] | 1129 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 1130 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 1131 | |
| 1132 | re->frag_addr[i] = pci_map_page(pdev, frag->page, |
| 1133 | frag->page_offset, |
| 1134 | frag->size, |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1135 | PCI_DMA_FROMDEVICE); |
stephen hemminger | 3fbd918 | 2010-02-01 13:45:41 +0000 | [diff] [blame] | 1136 | |
| 1137 | if (pci_dma_mapping_error(pdev, re->frag_addr[i])) |
| 1138 | goto map_page_error; |
| 1139 | } |
Stephen Hemminger | 454e6cb6 | 2009-02-03 11:27:28 +0000 | [diff] [blame] | 1140 | return 0; |
stephen hemminger | 3fbd918 | 2010-02-01 13:45:41 +0000 | [diff] [blame] | 1141 | |
| 1142 | map_page_error: |
| 1143 | while (--i >= 0) { |
| 1144 | pci_unmap_page(pdev, re->frag_addr[i], |
| 1145 | skb_shinfo(skb)->frags[i].size, |
| 1146 | PCI_DMA_FROMDEVICE); |
| 1147 | } |
| 1148 | |
| 1149 | pci_unmap_single(pdev, re->data_addr, pci_unmap_len(re, data_size), |
| 1150 | PCI_DMA_FROMDEVICE); |
| 1151 | |
| 1152 | mapping_error: |
| 1153 | if (net_ratelimit()) |
| 1154 | dev_warn(&pdev->dev, "%s: rx mapping error\n", |
| 1155 | skb->dev->name); |
| 1156 | return -EIO; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | static void sky2_rx_unmap_skb(struct pci_dev *pdev, struct rx_ring_info *re) |
| 1160 | { |
| 1161 | struct sk_buff *skb = re->skb; |
| 1162 | int i; |
| 1163 | |
| 1164 | pci_unmap_single(pdev, re->data_addr, pci_unmap_len(re, data_size), |
| 1165 | PCI_DMA_FROMDEVICE); |
| 1166 | |
| 1167 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) |
| 1168 | pci_unmap_page(pdev, re->frag_addr[i], |
| 1169 | skb_shinfo(skb)->frags[i].size, |
| 1170 | PCI_DMA_FROMDEVICE); |
| 1171 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1172 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1173 | /* Tell chip where to start receive checksum. |
| 1174 | * Actually has two checksums, but set both same to avoid possible byte |
| 1175 | * order problems. |
| 1176 | */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1177 | static void rx_set_checksum(struct sky2_port *sky2) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1178 | { |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1179 | struct sky2_rx_le *le = sky2_next_rx(sky2); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1180 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1181 | le->addr = cpu_to_le32((ETH_HLEN << 16) | ETH_HLEN); |
| 1182 | le->ctrl = 0; |
| 1183 | le->opcode = OP_TCPSTART | HW_OWNER; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1184 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1185 | sky2_write32(sky2->hw, |
| 1186 | Q_ADDR(rxqaddr[sky2->port], Q_CSR), |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 1187 | (sky2->flags & SKY2_FLAG_RX_CHECKSUM) |
| 1188 | ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1191 | /* |
| 1192 | * The RX Stop command will not work for Yukon-2 if the BMU does not |
| 1193 | * reach the end of packet and since we can't make sure that we have |
| 1194 | * incoming data, we must reset the BMU while it is not doing a DMA |
| 1195 | * transfer. Since it is possible that the RX path is still active, |
| 1196 | * the RX RAM buffer will be stopped first, so any possible incoming |
| 1197 | * data will not trigger a DMA. After the RAM buffer is stopped, the |
| 1198 | * BMU is polled until any DMA in progress is ended and only then it |
| 1199 | * will be reset. |
| 1200 | */ |
| 1201 | static void sky2_rx_stop(struct sky2_port *sky2) |
| 1202 | { |
| 1203 | struct sky2_hw *hw = sky2->hw; |
| 1204 | unsigned rxq = rxqaddr[sky2->port]; |
| 1205 | int i; |
| 1206 | |
| 1207 | /* disable the RAM Buffer receive queue */ |
| 1208 | sky2_write8(hw, RB_ADDR(rxq, RB_CTRL), RB_DIS_OP_MD); |
| 1209 | |
| 1210 | for (i = 0; i < 0xffff; i++) |
| 1211 | if (sky2_read8(hw, RB_ADDR(rxq, Q_RSL)) |
| 1212 | == sky2_read8(hw, RB_ADDR(rxq, Q_RL))) |
| 1213 | goto stopped; |
| 1214 | |
| 1215 | printk(KERN_WARNING PFX "%s: receiver stop failed\n", |
| 1216 | sky2->netdev->name); |
| 1217 | stopped: |
| 1218 | sky2_write32(hw, Q_ADDR(rxq, Q_CSR), BMU_RST_SET | BMU_FIFO_RST); |
| 1219 | |
| 1220 | /* reset the Rx prefetch unit */ |
| 1221 | sky2_write32(hw, Y2_QADDR(rxq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET); |
Stephen Hemminger | 3d1454dd | 2009-07-16 13:20:57 +0000 | [diff] [blame] | 1222 | mmiowb(); |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1223 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1224 | |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 1225 | /* Clean out receive buffer area, assumes receiver hardware stopped */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1226 | static void sky2_rx_clean(struct sky2_port *sky2) |
| 1227 | { |
| 1228 | unsigned i; |
| 1229 | |
| 1230 | memset(sky2->rx_le, 0, RX_LE_BYTES); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1231 | for (i = 0; i < sky2->rx_pending; i++) { |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1232 | struct rx_ring_info *re = sky2->rx_ring + i; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1233 | |
| 1234 | if (re->skb) { |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1235 | sky2_rx_unmap_skb(sky2->hw->pdev, re); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1236 | kfree_skb(re->skb); |
| 1237 | re->skb = NULL; |
| 1238 | } |
| 1239 | } |
| 1240 | } |
| 1241 | |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 1242 | /* Basic MII support */ |
| 1243 | static int sky2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 1244 | { |
| 1245 | struct mii_ioctl_data *data = if_mii(ifr); |
| 1246 | struct sky2_port *sky2 = netdev_priv(dev); |
| 1247 | struct sky2_hw *hw = sky2->hw; |
| 1248 | int err = -EOPNOTSUPP; |
| 1249 | |
| 1250 | if (!netif_running(dev)) |
| 1251 | return -ENODEV; /* Phy still in reset */ |
| 1252 | |
Stephen Hemminger | d89e134 | 2006-03-20 15:48:20 -0800 | [diff] [blame] | 1253 | switch (cmd) { |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 1254 | case SIOCGMIIPHY: |
| 1255 | data->phy_id = PHY_ADDR_MARV; |
| 1256 | |
| 1257 | /* fallthru */ |
| 1258 | case SIOCGMIIREG: { |
| 1259 | u16 val = 0; |
Stephen Hemminger | 91c86df | 2005-12-09 11:34:57 -0800 | [diff] [blame] | 1260 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1261 | spin_lock_bh(&sky2->phy_lock); |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 1262 | err = __gm_phy_read(hw, sky2->port, data->reg_num & 0x1f, &val); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1263 | spin_unlock_bh(&sky2->phy_lock); |
Stephen Hemminger | 91c86df | 2005-12-09 11:34:57 -0800 | [diff] [blame] | 1264 | |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 1265 | data->val_out = val; |
| 1266 | break; |
| 1267 | } |
| 1268 | |
| 1269 | case SIOCSMIIREG: |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1270 | spin_lock_bh(&sky2->phy_lock); |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 1271 | err = gm_phy_write(hw, sky2->port, data->reg_num & 0x1f, |
| 1272 | data->val_in); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1273 | spin_unlock_bh(&sky2->phy_lock); |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 1274 | break; |
| 1275 | } |
| 1276 | return err; |
| 1277 | } |
| 1278 | |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1279 | #ifdef SKY2_VLAN_TAG_USED |
Stephen Hemminger | d494eac | 2008-05-14 17:04:13 -0700 | [diff] [blame] | 1280 | static void sky2_set_vlan_mode(struct sky2_hw *hw, u16 port, bool onoff) |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1281 | { |
Stephen Hemminger | d494eac | 2008-05-14 17:04:13 -0700 | [diff] [blame] | 1282 | if (onoff) { |
Stephen Hemminger | 3d4e66f | 2007-06-01 09:43:58 -0700 | [diff] [blame] | 1283 | sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), |
| 1284 | RX_VLAN_STRIP_ON); |
| 1285 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), |
| 1286 | TX_VLAN_TAG_ON); |
| 1287 | } else { |
| 1288 | sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), |
| 1289 | RX_VLAN_STRIP_OFF); |
| 1290 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), |
| 1291 | TX_VLAN_TAG_OFF); |
| 1292 | } |
Stephen Hemminger | d494eac | 2008-05-14 17:04:13 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | static void sky2_vlan_rx_register(struct net_device *dev, struct vlan_group *grp) |
| 1296 | { |
| 1297 | struct sky2_port *sky2 = netdev_priv(dev); |
| 1298 | struct sky2_hw *hw = sky2->hw; |
| 1299 | u16 port = sky2->port; |
| 1300 | |
| 1301 | netif_tx_lock_bh(dev); |
| 1302 | napi_disable(&hw->napi); |
| 1303 | |
| 1304 | sky2->vlgrp = grp; |
| 1305 | sky2_set_vlan_mode(hw, port, grp != NULL); |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1306 | |
David S. Miller | d1d08d1 | 2008-01-07 20:53:33 -0800 | [diff] [blame] | 1307 | sky2_read32(hw, B0_Y2_SP_LISR); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1308 | napi_enable(&hw->napi); |
Stephen Hemminger | 2bb8c26 | 2006-09-26 11:57:42 -0700 | [diff] [blame] | 1309 | netif_tx_unlock_bh(dev); |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1310 | } |
| 1311 | #endif |
| 1312 | |
Stephen Hemminger | bd1c686 | 2009-06-17 07:30:38 +0000 | [diff] [blame] | 1313 | /* Amount of required worst case padding in rx buffer */ |
| 1314 | static inline unsigned sky2_rx_pad(const struct sky2_hw *hw) |
| 1315 | { |
| 1316 | return (hw->flags & SKY2_HW_RAM_BUFFER) ? 8 : 2; |
| 1317 | } |
| 1318 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1319 | /* |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1320 | * Allocate an skb for receiving. If the MTU is large enough |
| 1321 | * make the skb non-linear with a fragment list of pages. |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 1322 | */ |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1323 | static struct sk_buff *sky2_rx_alloc(struct sky2_port *sky2) |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 1324 | { |
| 1325 | struct sk_buff *skb; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1326 | int i; |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 1327 | |
Stephen Hemminger | 724b694 | 2009-08-18 15:17:10 +0000 | [diff] [blame] | 1328 | skb = netdev_alloc_skb(sky2->netdev, |
| 1329 | sky2->rx_data_size + sky2_rx_pad(sky2->hw)); |
Stephen Hemminger | bd1c686 | 2009-06-17 07:30:38 +0000 | [diff] [blame] | 1330 | if (!skb) |
| 1331 | goto nomem; |
| 1332 | |
Stephen Hemminger | 39dbd95 | 2008-02-04 19:45:13 -0800 | [diff] [blame] | 1333 | if (sky2->hw->flags & SKY2_HW_RAM_BUFFER) { |
Stephen Hemminger | f03b865 | 2007-11-28 14:27:03 -0800 | [diff] [blame] | 1334 | unsigned char *start; |
| 1335 | /* |
| 1336 | * Workaround for a bug in FIFO that cause hang |
| 1337 | * if the FIFO if the receive buffer is not 64 byte aligned. |
| 1338 | * The buffer returned from netdev_alloc_skb is |
| 1339 | * aligned except if slab debugging is enabled. |
| 1340 | */ |
Stephen Hemminger | f03b865 | 2007-11-28 14:27:03 -0800 | [diff] [blame] | 1341 | start = PTR_ALIGN(skb->data, 8); |
| 1342 | skb_reserve(skb, start - skb->data); |
Stephen Hemminger | bd1c686 | 2009-06-17 07:30:38 +0000 | [diff] [blame] | 1343 | } else |
Stephen Hemminger | f03b865 | 2007-11-28 14:27:03 -0800 | [diff] [blame] | 1344 | skb_reserve(skb, NET_IP_ALIGN); |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1345 | |
| 1346 | for (i = 0; i < sky2->rx_nfrags; i++) { |
| 1347 | struct page *page = alloc_page(GFP_ATOMIC); |
| 1348 | |
| 1349 | if (!page) |
| 1350 | goto free_partial; |
| 1351 | skb_fill_page_desc(skb, i, page, 0, PAGE_SIZE); |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | return skb; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1355 | free_partial: |
| 1356 | kfree_skb(skb); |
| 1357 | nomem: |
| 1358 | return NULL; |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 1359 | } |
| 1360 | |
Stephen Hemminger | 55c9dd3 | 2007-07-09 15:33:37 -0700 | [diff] [blame] | 1361 | static inline void sky2_rx_update(struct sky2_port *sky2, unsigned rxq) |
| 1362 | { |
| 1363 | sky2_put_idx(sky2->hw, rxq, sky2->rx_put); |
| 1364 | } |
| 1365 | |
Mike McCormack | 200ac49 | 2010-02-12 06:58:03 +0000 | [diff] [blame] | 1366 | static int sky2_alloc_rx_skbs(struct sky2_port *sky2) |
| 1367 | { |
| 1368 | struct sky2_hw *hw = sky2->hw; |
| 1369 | unsigned i; |
| 1370 | |
| 1371 | sky2->rx_data_size = sky2_get_rx_data_size(sky2); |
| 1372 | |
| 1373 | /* Fill Rx ring */ |
| 1374 | for (i = 0; i < sky2->rx_pending; i++) { |
| 1375 | struct rx_ring_info *re = sky2->rx_ring + i; |
| 1376 | |
| 1377 | re->skb = sky2_rx_alloc(sky2); |
| 1378 | if (!re->skb) |
| 1379 | return -ENOMEM; |
| 1380 | |
| 1381 | if (sky2_rx_map_skb(hw->pdev, re, sky2->rx_data_size)) { |
| 1382 | dev_kfree_skb(re->skb); |
| 1383 | re->skb = NULL; |
| 1384 | return -ENOMEM; |
| 1385 | } |
| 1386 | } |
| 1387 | return 0; |
| 1388 | } |
| 1389 | |
Stephen Hemminger | 82788c7 | 2006-01-17 13:43:10 -0800 | [diff] [blame] | 1390 | /* |
Mike McCormack | 200ac49 | 2010-02-12 06:58:03 +0000 | [diff] [blame] | 1391 | * Setup receiver buffer pool. |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1392 | * Normal case this ends up creating one list element for skb |
| 1393 | * in the receive ring. Worst case if using large MTU and each |
| 1394 | * allocation falls on a different 64 bit region, that results |
| 1395 | * in 6 list elements per ring entry. |
| 1396 | * One element is used for checksum enable/disable, and one |
| 1397 | * extra to avoid wrap. |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1398 | */ |
Mike McCormack | 200ac49 | 2010-02-12 06:58:03 +0000 | [diff] [blame] | 1399 | static void sky2_rx_start(struct sky2_port *sky2) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1400 | { |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1401 | struct sky2_hw *hw = sky2->hw; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1402 | struct rx_ring_info *re; |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1403 | unsigned rxq = rxqaddr[sky2->port]; |
Mike McCormack | 39ef110 | 2010-02-12 06:58:02 +0000 | [diff] [blame] | 1404 | unsigned i, thresh; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1405 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1406 | sky2->rx_put = sky2->rx_next = 0; |
shemminger@osdl.org | af4ed7e | 2005-11-30 11:45:21 -0800 | [diff] [blame] | 1407 | sky2_qset(hw, rxq); |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 1408 | |
Stephen Hemminger | c3905bc | 2006-12-04 17:08:19 -0800 | [diff] [blame] | 1409 | /* On PCI express lowering the watermark gives better performance */ |
| 1410 | if (pci_find_capability(hw->pdev, PCI_CAP_ID_EXP)) |
| 1411 | sky2_write32(hw, Q_ADDR(rxq, Q_WM), BMU_WM_PEX); |
| 1412 | |
| 1413 | /* These chips have no ram buffer? |
| 1414 | * MAC Rx RAM Read is controlled by hardware */ |
Stephen Hemminger | 8df9a87 | 2006-12-01 14:29:35 -0800 | [diff] [blame] | 1415 | if (hw->chip_id == CHIP_ID_YUKON_EC_U && |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1416 | (hw->chip_rev == CHIP_REV_YU_EC_U_A1 || |
| 1417 | hw->chip_rev == CHIP_REV_YU_EC_U_B0)) |
Stephen Hemminger | f449c7c | 2007-06-04 17:23:23 -0700 | [diff] [blame] | 1418 | sky2_write32(hw, Q_ADDR(rxq, Q_TEST), F_M_RX_RAM_DIS); |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 1419 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1420 | sky2_prefetch_init(hw, rxq, sky2->rx_le_map, RX_LE_SIZE - 1); |
| 1421 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1422 | if (!(hw->flags & SKY2_HW_NEW_LE)) |
| 1423 | rx_set_checksum(sky2); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1424 | |
Mike McCormack | 200ac49 | 2010-02-12 06:58:03 +0000 | [diff] [blame] | 1425 | /* submit Rx ring */ |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1426 | for (i = 0; i < sky2->rx_pending; i++) { |
| 1427 | re = sky2->rx_ring + i; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 1428 | sky2_rx_submit(sky2, re); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
Stephen Hemminger | a1433ac | 2006-05-22 12:03:42 -0700 | [diff] [blame] | 1431 | /* |
| 1432 | * The receiver hangs if it receives frames larger than the |
| 1433 | * packet buffer. As a workaround, truncate oversize frames, but |
| 1434 | * the register is limited to 9 bits, so if you do frames > 2052 |
| 1435 | * you better get the MTU right! |
| 1436 | */ |
Mike McCormack | 39ef110 | 2010-02-12 06:58:02 +0000 | [diff] [blame] | 1437 | thresh = sky2_get_rx_threshold(sky2); |
Stephen Hemminger | a1433ac | 2006-05-22 12:03:42 -0700 | [diff] [blame] | 1438 | if (thresh > 0x1ff) |
| 1439 | sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_OFF); |
| 1440 | else { |
| 1441 | sky2_write16(hw, SK_REG(sky2->port, RX_GMF_TR_THR), thresh); |
| 1442 | sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_ON); |
| 1443 | } |
| 1444 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1445 | /* Tell chip about available buffers */ |
Stephen Hemminger | 55c9dd3 | 2007-07-09 15:33:37 -0700 | [diff] [blame] | 1446 | sky2_rx_update(sky2, rxq); |
Stephen Hemminger | 877c857 | 2009-10-29 06:37:08 +0000 | [diff] [blame] | 1447 | |
| 1448 | if (hw->chip_id == CHIP_ID_YUKON_EX || |
| 1449 | hw->chip_id == CHIP_ID_YUKON_SUPR) { |
| 1450 | /* |
| 1451 | * Disable flushing of non ASF packets; |
| 1452 | * must be done after initializing the BMUs; |
| 1453 | * drivers without ASF support should do this too, otherwise |
| 1454 | * it may happen that they cannot run on ASF devices; |
| 1455 | * remember that the MAC FIFO isn't reset during initialization. |
| 1456 | */ |
| 1457 | sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_MACSEC_FLUSH_OFF); |
| 1458 | } |
| 1459 | |
| 1460 | if (hw->chip_id >= CHIP_ID_YUKON_SUPR) { |
| 1461 | /* Enable RX Home Address & Routing Header checksum fix */ |
| 1462 | sky2_write16(hw, SK_REG(sky2->port, RX_GMF_FL_CTRL), |
| 1463 | RX_IPV6_SA_MOB_ENA | RX_IPV6_DA_MOB_ENA); |
| 1464 | |
| 1465 | /* Enable TX Home Address & Routing Header checksum fix */ |
| 1466 | sky2_write32(hw, Q_ADDR(txqaddr[sky2->port], Q_TEST), |
| 1467 | TBMU_TEST_HOME_ADD_FIX_EN | TBMU_TEST_ROUTING_ADD_FIX_EN); |
| 1468 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
Mike McCormack | 90bbebb | 2009-09-01 03:21:35 +0000 | [diff] [blame] | 1471 | static int sky2_alloc_buffers(struct sky2_port *sky2) |
| 1472 | { |
| 1473 | struct sky2_hw *hw = sky2->hw; |
| 1474 | |
| 1475 | /* must be power of 2 */ |
| 1476 | sky2->tx_le = pci_alloc_consistent(hw->pdev, |
| 1477 | sky2->tx_ring_size * |
| 1478 | sizeof(struct sky2_tx_le), |
| 1479 | &sky2->tx_le_map); |
| 1480 | if (!sky2->tx_le) |
| 1481 | goto nomem; |
| 1482 | |
| 1483 | sky2->tx_ring = kcalloc(sky2->tx_ring_size, sizeof(struct tx_ring_info), |
| 1484 | GFP_KERNEL); |
| 1485 | if (!sky2->tx_ring) |
| 1486 | goto nomem; |
| 1487 | |
| 1488 | sky2->rx_le = pci_alloc_consistent(hw->pdev, RX_LE_BYTES, |
| 1489 | &sky2->rx_le_map); |
| 1490 | if (!sky2->rx_le) |
| 1491 | goto nomem; |
| 1492 | memset(sky2->rx_le, 0, RX_LE_BYTES); |
| 1493 | |
| 1494 | sky2->rx_ring = kcalloc(sky2->rx_pending, sizeof(struct rx_ring_info), |
| 1495 | GFP_KERNEL); |
| 1496 | if (!sky2->rx_ring) |
| 1497 | goto nomem; |
| 1498 | |
Mike McCormack | 200ac49 | 2010-02-12 06:58:03 +0000 | [diff] [blame] | 1499 | return sky2_alloc_rx_skbs(sky2); |
Mike McCormack | 90bbebb | 2009-09-01 03:21:35 +0000 | [diff] [blame] | 1500 | nomem: |
| 1501 | return -ENOMEM; |
| 1502 | } |
| 1503 | |
| 1504 | static void sky2_free_buffers(struct sky2_port *sky2) |
| 1505 | { |
| 1506 | struct sky2_hw *hw = sky2->hw; |
| 1507 | |
Mike McCormack | 200ac49 | 2010-02-12 06:58:03 +0000 | [diff] [blame] | 1508 | sky2_rx_clean(sky2); |
| 1509 | |
Mike McCormack | 90bbebb | 2009-09-01 03:21:35 +0000 | [diff] [blame] | 1510 | if (sky2->rx_le) { |
| 1511 | pci_free_consistent(hw->pdev, RX_LE_BYTES, |
| 1512 | sky2->rx_le, sky2->rx_le_map); |
| 1513 | sky2->rx_le = NULL; |
| 1514 | } |
| 1515 | if (sky2->tx_le) { |
| 1516 | pci_free_consistent(hw->pdev, |
| 1517 | sky2->tx_ring_size * sizeof(struct sky2_tx_le), |
| 1518 | sky2->tx_le, sky2->tx_le_map); |
| 1519 | sky2->tx_le = NULL; |
| 1520 | } |
| 1521 | kfree(sky2->tx_ring); |
| 1522 | kfree(sky2->rx_ring); |
| 1523 | |
| 1524 | sky2->tx_ring = NULL; |
| 1525 | sky2->rx_ring = NULL; |
| 1526 | } |
| 1527 | |
Mike McCormack | ea0f71e | 2010-02-12 06:58:04 +0000 | [diff] [blame] | 1528 | static void sky2_hw_up(struct sky2_port *sky2) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1529 | { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1530 | struct sky2_hw *hw = sky2->hw; |
| 1531 | unsigned port = sky2->port; |
Mike McCormack | ea0f71e | 2010-02-12 06:58:04 +0000 | [diff] [blame] | 1532 | u32 ramsize; |
| 1533 | int cap; |
Stephen Hemminger | 843a46f | 2006-05-11 15:07:28 -0700 | [diff] [blame] | 1534 | struct net_device *otherdev = hw->dev[sky2->port^1]; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1535 | |
Mike McCormack | ea0f71e | 2010-02-12 06:58:04 +0000 | [diff] [blame] | 1536 | tx_init(sky2); |
| 1537 | |
Stephen Hemminger | ee7abb0 | 2006-05-18 11:16:21 -0700 | [diff] [blame] | 1538 | /* |
| 1539 | * On dual port PCI-X card, there is an problem where status |
| 1540 | * can be received out of order due to split transactions |
Stephen Hemminger | 843a46f | 2006-05-11 15:07:28 -0700 | [diff] [blame] | 1541 | */ |
Stephen Hemminger | ee7abb0 | 2006-05-18 11:16:21 -0700 | [diff] [blame] | 1542 | if (otherdev && netif_running(otherdev) && |
| 1543 | (cap = pci_find_capability(hw->pdev, PCI_CAP_ID_PCIX))) { |
Stephen Hemminger | ee7abb0 | 2006-05-18 11:16:21 -0700 | [diff] [blame] | 1544 | u16 cmd; |
Stephen Hemminger | 843a46f | 2006-05-11 15:07:28 -0700 | [diff] [blame] | 1545 | |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 1546 | cmd = sky2_pci_read16(hw, cap + PCI_X_CMD); |
Stephen Hemminger | ee7abb0 | 2006-05-18 11:16:21 -0700 | [diff] [blame] | 1547 | cmd &= ~PCI_X_CMD_MAX_SPLIT; |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 1548 | sky2_pci_write16(hw, cap + PCI_X_CMD, cmd); |
Mike McCormack | ea0f71e | 2010-02-12 06:58:04 +0000 | [diff] [blame] | 1549 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1550 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1551 | sky2_mac_init(hw, port); |
| 1552 | |
Stephen Hemminger | e0c2811 | 2007-09-20 13:03:49 -0700 | [diff] [blame] | 1553 | /* Register is number of 4K blocks on internal RAM buffer. */ |
| 1554 | ramsize = sky2_read8(hw, B2_E_0) * 4; |
| 1555 | if (ramsize > 0) { |
Stephen Hemminger | 6771290 | 2006-12-04 15:53:45 -0800 | [diff] [blame] | 1556 | u32 rxspace; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1557 | |
Mike McCormack | ea0f71e | 2010-02-12 06:58:04 +0000 | [diff] [blame] | 1558 | pr_debug(PFX "%s: ram buffer %dK\n", sky2->netdev->name, ramsize); |
Stephen Hemminger | 6771290 | 2006-12-04 15:53:45 -0800 | [diff] [blame] | 1559 | if (ramsize < 16) |
| 1560 | rxspace = ramsize / 2; |
| 1561 | else |
| 1562 | rxspace = 8 + (2*(ramsize - 16))/3; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1563 | |
Stephen Hemminger | 6771290 | 2006-12-04 15:53:45 -0800 | [diff] [blame] | 1564 | sky2_ramset(hw, rxqaddr[port], 0, rxspace); |
| 1565 | sky2_ramset(hw, txqaddr[port], rxspace, ramsize - rxspace); |
| 1566 | |
| 1567 | /* Make sure SyncQ is disabled */ |
| 1568 | sky2_write8(hw, RB_ADDR(port == 0 ? Q_XS1 : Q_XS2, RB_CTRL), |
| 1569 | RB_RST_SET); |
| 1570 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1571 | |
shemminger@osdl.org | af4ed7e | 2005-11-30 11:45:21 -0800 | [diff] [blame] | 1572 | sky2_qset(hw, txqaddr[port]); |
shemminger@osdl.org | 5a5b1ea | 2005-11-30 11:45:15 -0800 | [diff] [blame] | 1573 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1574 | /* This is copied from sk98lin 10.0.5.3; no one tells me about erratta's */ |
| 1575 | if (hw->chip_id == CHIP_ID_YUKON_EX && hw->chip_rev == CHIP_REV_YU_EX_B0) |
| 1576 | sky2_write32(hw, Q_ADDR(txqaddr[port], Q_TEST), F_TX_CHK_AUTO_OFF); |
| 1577 | |
Stephen Hemminger | 977bdf0 | 2006-02-22 11:44:58 -0800 | [diff] [blame] | 1578 | /* Set almost empty threshold */ |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1579 | if (hw->chip_id == CHIP_ID_YUKON_EC_U && |
| 1580 | hw->chip_rev == CHIP_REV_YU_EC_U_A0) |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 1581 | sky2_write16(hw, Q_ADDR(txqaddr[port], Q_AL), ECU_TXFF_LEV); |
shemminger@osdl.org | 5a5b1ea | 2005-11-30 11:45:15 -0800 | [diff] [blame] | 1582 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1583 | sky2_prefetch_init(hw, txqaddr[port], sky2->tx_le_map, |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 1584 | sky2->tx_ring_size - 1); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1585 | |
Stephen Hemminger | d494eac | 2008-05-14 17:04:13 -0700 | [diff] [blame] | 1586 | #ifdef SKY2_VLAN_TAG_USED |
| 1587 | sky2_set_vlan_mode(hw, port, sky2->vlgrp != NULL); |
| 1588 | #endif |
| 1589 | |
Mike McCormack | 200ac49 | 2010-02-12 06:58:03 +0000 | [diff] [blame] | 1590 | sky2_rx_start(sky2); |
Mike McCormack | ea0f71e | 2010-02-12 06:58:04 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | /* Bring up network interface. */ |
| 1594 | static int sky2_up(struct net_device *dev) |
| 1595 | { |
| 1596 | struct sky2_port *sky2 = netdev_priv(dev); |
| 1597 | struct sky2_hw *hw = sky2->hw; |
| 1598 | unsigned port = sky2->port; |
| 1599 | u32 imask; |
| 1600 | int err; |
| 1601 | |
| 1602 | netif_carrier_off(dev); |
| 1603 | |
| 1604 | err = sky2_alloc_buffers(sky2); |
| 1605 | if (err) |
| 1606 | goto err_out; |
| 1607 | |
| 1608 | sky2_hw_up(sky2); |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 1609 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1610 | /* Enable interrupts from phy/mac for port */ |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1611 | imask = sky2_read32(hw, B0_IMSK); |
Stephen Hemminger | f4ea431 | 2006-05-09 14:46:54 -0700 | [diff] [blame] | 1612 | imask |= portirq_msk[port]; |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1613 | sky2_write32(hw, B0_IMSK, imask); |
Stephen Hemminger | 1fd82f3 | 2009-06-17 07:30:34 +0000 | [diff] [blame] | 1614 | sky2_read32(hw, B0_IMSK); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1615 | |
Alexey Dobriyan | a11da89 | 2009-01-30 13:45:31 -0800 | [diff] [blame] | 1616 | if (netif_msg_ifup(sky2)) |
| 1617 | printk(KERN_INFO PFX "%s: enabling interface\n", dev->name); |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 1618 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1619 | return 0; |
| 1620 | |
| 1621 | err_out: |
Mike McCormack | 90bbebb | 2009-09-01 03:21:35 +0000 | [diff] [blame] | 1622 | sky2_free_buffers(sky2); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1623 | return err; |
| 1624 | } |
| 1625 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1626 | /* Modular subtraction in ring */ |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 1627 | static inline int tx_inuse(const struct sky2_port *sky2) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1628 | { |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 1629 | return (sky2->tx_prod - sky2->tx_cons) & (sky2->tx_ring_size - 1); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | /* Number of list elements available for next tx */ |
| 1633 | static inline int tx_avail(const struct sky2_port *sky2) |
| 1634 | { |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 1635 | return sky2->tx_pending - tx_inuse(sky2); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | /* Estimate of number of transmit list elements required */ |
Stephen Hemminger | 28bd181 | 2006-01-17 13:43:19 -0800 | [diff] [blame] | 1639 | static unsigned tx_le_req(const struct sk_buff *skb) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1640 | { |
| 1641 | unsigned count; |
| 1642 | |
Stephen Hemminger | 07e3163 | 2009-09-14 06:12:55 +0000 | [diff] [blame] | 1643 | count = (skb_shinfo(skb)->nr_frags + 1) |
| 1644 | * (sizeof(dma_addr_t) / sizeof(u32)); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1645 | |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 1646 | if (skb_is_gso(skb)) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1647 | ++count; |
Stephen Hemminger | 07e3163 | 2009-09-14 06:12:55 +0000 | [diff] [blame] | 1648 | else if (sizeof(dma_addr_t) == sizeof(u32)) |
| 1649 | ++count; /* possible vlan */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1650 | |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 1651 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1652 | ++count; |
| 1653 | |
| 1654 | return count; |
| 1655 | } |
| 1656 | |
stephen hemminger | f681507 | 2010-02-01 13:41:47 +0000 | [diff] [blame] | 1657 | static void sky2_tx_unmap(struct pci_dev *pdev, struct tx_ring_info *re) |
Stephen Hemminger | 6b84dac | 2009-08-18 15:17:09 +0000 | [diff] [blame] | 1658 | { |
| 1659 | if (re->flags & TX_MAP_SINGLE) |
| 1660 | pci_unmap_single(pdev, pci_unmap_addr(re, mapaddr), |
| 1661 | pci_unmap_len(re, maplen), |
| 1662 | PCI_DMA_TODEVICE); |
| 1663 | else if (re->flags & TX_MAP_PAGE) |
| 1664 | pci_unmap_page(pdev, pci_unmap_addr(re, mapaddr), |
| 1665 | pci_unmap_len(re, maplen), |
| 1666 | PCI_DMA_TODEVICE); |
stephen hemminger | f681507 | 2010-02-01 13:41:47 +0000 | [diff] [blame] | 1667 | re->flags = 0; |
Stephen Hemminger | 6b84dac | 2009-08-18 15:17:09 +0000 | [diff] [blame] | 1668 | } |
| 1669 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1670 | /* |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1671 | * Put one packet in ring for transmit. |
| 1672 | * A single packet can generate multiple list elements, and |
| 1673 | * the number of ring elements will probably be less than the number |
| 1674 | * of list elements used. |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1675 | */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 1676 | static netdev_tx_t sky2_xmit_frame(struct sk_buff *skb, |
| 1677 | struct net_device *dev) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1678 | { |
| 1679 | struct sky2_port *sky2 = netdev_priv(dev); |
| 1680 | struct sky2_hw *hw = sky2->hw; |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1681 | struct sky2_tx_le *le = NULL; |
Stephen Hemminger | 6cdbbdf | 2005-12-09 11:35:01 -0800 | [diff] [blame] | 1682 | struct tx_ring_info *re; |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1683 | unsigned i, len; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1684 | dma_addr_t mapping; |
Stephen Hemminger | 5dce95e | 2009-08-18 15:17:06 +0000 | [diff] [blame] | 1685 | u32 upper; |
| 1686 | u16 slot; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1687 | u16 mss; |
| 1688 | u8 ctrl; |
| 1689 | |
Stephen Hemminger | 2bb8c26 | 2006-09-26 11:57:42 -0700 | [diff] [blame] | 1690 | if (unlikely(tx_avail(sky2) < tx_le_req(skb))) |
| 1691 | return NETDEV_TX_BUSY; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1692 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1693 | len = skb_headlen(skb); |
| 1694 | mapping = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1695 | |
Stephen Hemminger | 454e6cb6 | 2009-02-03 11:27:28 +0000 | [diff] [blame] | 1696 | if (pci_dma_mapping_error(hw->pdev, mapping)) |
| 1697 | goto mapping_error; |
| 1698 | |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1699 | slot = sky2->tx_prod; |
Stephen Hemminger | 454e6cb6 | 2009-02-03 11:27:28 +0000 | [diff] [blame] | 1700 | if (unlikely(netif_msg_tx_queued(sky2))) |
| 1701 | printk(KERN_DEBUG "%s: tx queued, slot %u, len %d\n", |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1702 | dev->name, slot, skb->len); |
Stephen Hemminger | 454e6cb6 | 2009-02-03 11:27:28 +0000 | [diff] [blame] | 1703 | |
Stephen Hemminger | 86c6887 | 2008-01-10 16:14:12 -0800 | [diff] [blame] | 1704 | /* Send high bits if needed */ |
Stephen Hemminger | 5dce95e | 2009-08-18 15:17:06 +0000 | [diff] [blame] | 1705 | upper = upper_32_bits(mapping); |
| 1706 | if (upper != sky2->tx_last_upper) { |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1707 | le = get_tx_le(sky2, &slot); |
Stephen Hemminger | 5dce95e | 2009-08-18 15:17:06 +0000 | [diff] [blame] | 1708 | le->addr = cpu_to_le32(upper); |
| 1709 | sky2->tx_last_upper = upper; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1710 | le->opcode = OP_ADDR64 | HW_OWNER; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1711 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1712 | |
| 1713 | /* Check for TCP Segmentation Offload */ |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 1714 | mss = skb_shinfo(skb)->gso_size; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1715 | if (mss != 0) { |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1716 | |
| 1717 | if (!(hw->flags & SKY2_HW_NEW_LE)) |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1718 | mss += ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1719 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1720 | if (mss != sky2->tx_last_mss) { |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1721 | le = get_tx_le(sky2, &slot); |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1722 | le->addr = cpu_to_le32(mss); |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1723 | |
| 1724 | if (hw->flags & SKY2_HW_NEW_LE) |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1725 | le->opcode = OP_MSS | HW_OWNER; |
| 1726 | else |
| 1727 | le->opcode = OP_LRGLEN | HW_OWNER; |
shemminger@osdl.org | e07560c | 2006-08-28 10:00:49 -0700 | [diff] [blame] | 1728 | sky2->tx_last_mss = mss; |
| 1729 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1732 | ctrl = 0; |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1733 | #ifdef SKY2_VLAN_TAG_USED |
| 1734 | /* Add VLAN tag, can piggyback on LRGLEN or ADDR64 */ |
| 1735 | if (sky2->vlgrp && vlan_tx_tag_present(skb)) { |
| 1736 | if (!le) { |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1737 | le = get_tx_le(sky2, &slot); |
Stephen Hemminger | f65b138 | 2006-09-06 12:45:02 -0700 | [diff] [blame] | 1738 | le->addr = 0; |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1739 | le->opcode = OP_VLAN|HW_OWNER; |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 1740 | } else |
| 1741 | le->opcode |= OP_VLAN; |
| 1742 | le->length = cpu_to_be16(vlan_tx_tag_get(skb)); |
| 1743 | ctrl |= INS_VLAN; |
| 1744 | } |
| 1745 | #endif |
| 1746 | |
| 1747 | /* Handle TCP checksum offload */ |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 1748 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1749 | /* On Yukon EX (some versions) encoding change. */ |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1750 | if (hw->flags & SKY2_HW_AUTO_TX_SUM) |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1751 | ctrl |= CALSUM; /* auto checksum */ |
| 1752 | else { |
| 1753 | const unsigned offset = skb_transport_offset(skb); |
| 1754 | u32 tcpsum; |
Stephen Hemminger | f65b138 | 2006-09-06 12:45:02 -0700 | [diff] [blame] | 1755 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1756 | tcpsum = offset << 16; /* sum start */ |
| 1757 | tcpsum |= offset + skb->csum_offset; /* sum write */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1758 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1759 | ctrl |= CALSUM | WR_SUM | INIT_SUM | LOCK_SUM; |
| 1760 | if (ip_hdr(skb)->protocol == IPPROTO_UDP) |
| 1761 | ctrl |= UDPTCP; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1762 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1763 | if (tcpsum != sky2->tx_tcpsum) { |
| 1764 | sky2->tx_tcpsum = tcpsum; |
shemminger@osdl.org | 1d17933 | 2006-08-28 10:00:50 -0700 | [diff] [blame] | 1765 | |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1766 | le = get_tx_le(sky2, &slot); |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 1767 | le->addr = cpu_to_le32(tcpsum); |
| 1768 | le->length = 0; /* initial checksum value */ |
| 1769 | le->ctrl = 1; /* one packet */ |
| 1770 | le->opcode = OP_TCPLISW | HW_OWNER; |
| 1771 | } |
shemminger@osdl.org | 1d17933 | 2006-08-28 10:00:50 -0700 | [diff] [blame] | 1772 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
Stephen Hemminger | 6b84dac | 2009-08-18 15:17:09 +0000 | [diff] [blame] | 1775 | re = sky2->tx_ring + slot; |
| 1776 | re->flags = TX_MAP_SINGLE; |
| 1777 | pci_unmap_addr_set(re, mapaddr, mapping); |
| 1778 | pci_unmap_len_set(re, maplen, len); |
| 1779 | |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1780 | le = get_tx_le(sky2, &slot); |
Stephen Hemminger | d6e74b6 | 2009-08-18 15:17:05 +0000 | [diff] [blame] | 1781 | le->addr = cpu_to_le32(lower_32_bits(mapping)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1782 | le->length = cpu_to_le16(len); |
| 1783 | le->ctrl = ctrl; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1784 | le->opcode = mss ? (OP_LARGESEND | HW_OWNER) : (OP_PACKET | HW_OWNER); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1785 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1786 | |
| 1787 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1788 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1789 | |
| 1790 | mapping = pci_map_page(hw->pdev, frag->page, frag->page_offset, |
| 1791 | frag->size, PCI_DMA_TODEVICE); |
Stephen Hemminger | 86c6887 | 2008-01-10 16:14:12 -0800 | [diff] [blame] | 1792 | |
Stephen Hemminger | 454e6cb6 | 2009-02-03 11:27:28 +0000 | [diff] [blame] | 1793 | if (pci_dma_mapping_error(hw->pdev, mapping)) |
| 1794 | goto mapping_unwind; |
| 1795 | |
Stephen Hemminger | 5dce95e | 2009-08-18 15:17:06 +0000 | [diff] [blame] | 1796 | upper = upper_32_bits(mapping); |
| 1797 | if (upper != sky2->tx_last_upper) { |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1798 | le = get_tx_le(sky2, &slot); |
Stephen Hemminger | 5dce95e | 2009-08-18 15:17:06 +0000 | [diff] [blame] | 1799 | le->addr = cpu_to_le32(upper); |
| 1800 | sky2->tx_last_upper = upper; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1801 | le->opcode = OP_ADDR64 | HW_OWNER; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
Stephen Hemminger | 6b84dac | 2009-08-18 15:17:09 +0000 | [diff] [blame] | 1804 | re = sky2->tx_ring + slot; |
| 1805 | re->flags = TX_MAP_PAGE; |
| 1806 | pci_unmap_addr_set(re, mapaddr, mapping); |
| 1807 | pci_unmap_len_set(re, maplen, frag->size); |
| 1808 | |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1809 | le = get_tx_le(sky2, &slot); |
Stephen Hemminger | d6e74b6 | 2009-08-18 15:17:05 +0000 | [diff] [blame] | 1810 | le->addr = cpu_to_le32(lower_32_bits(mapping)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1811 | le->length = cpu_to_le16(frag->size); |
| 1812 | le->ctrl = ctrl; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1813 | le->opcode = OP_BUFFER | HW_OWNER; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1814 | } |
Stephen Hemminger | 6cdbbdf | 2005-12-09 11:35:01 -0800 | [diff] [blame] | 1815 | |
Stephen Hemminger | 6b84dac | 2009-08-18 15:17:09 +0000 | [diff] [blame] | 1816 | re->skb = skb; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1817 | le->ctrl |= EOP; |
| 1818 | |
Mike McCormack | 9b289c3 | 2009-08-14 05:15:12 +0000 | [diff] [blame] | 1819 | sky2->tx_prod = slot; |
| 1820 | |
shemminger@osdl.org | 97bda70 | 2006-08-28 10:00:47 -0700 | [diff] [blame] | 1821 | if (tx_avail(sky2) <= MAX_SKB_TX_LE) |
| 1822 | netif_stop_queue(dev); |
Stephen Hemminger | b19666d | 2006-03-07 11:06:36 -0800 | [diff] [blame] | 1823 | |
Stephen Hemminger | 290d4de | 2006-03-20 15:48:15 -0800 | [diff] [blame] | 1824 | sky2_put_idx(hw, txqaddr[sky2->port], sky2->tx_prod); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1825 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1826 | return NETDEV_TX_OK; |
Stephen Hemminger | 454e6cb6 | 2009-02-03 11:27:28 +0000 | [diff] [blame] | 1827 | |
| 1828 | mapping_unwind: |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 1829 | for (i = sky2->tx_prod; i != slot; i = RING_NEXT(i, sky2->tx_ring_size)) { |
Stephen Hemminger | 454e6cb6 | 2009-02-03 11:27:28 +0000 | [diff] [blame] | 1830 | re = sky2->tx_ring + i; |
| 1831 | |
Stephen Hemminger | 6b84dac | 2009-08-18 15:17:09 +0000 | [diff] [blame] | 1832 | sky2_tx_unmap(hw->pdev, re); |
Stephen Hemminger | 454e6cb6 | 2009-02-03 11:27:28 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
Stephen Hemminger | 454e6cb6 | 2009-02-03 11:27:28 +0000 | [diff] [blame] | 1835 | mapping_error: |
| 1836 | if (net_ratelimit()) |
| 1837 | dev_warn(&hw->pdev->dev, "%s: tx mapping error\n", dev->name); |
| 1838 | dev_kfree_skb(skb); |
| 1839 | return NETDEV_TX_OK; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1842 | /* |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1843 | * Free ring elements from starting at tx_cons until "done" |
| 1844 | * |
Stephen Hemminger | 481cea4 | 2009-08-14 15:33:19 -0700 | [diff] [blame] | 1845 | * NB: |
| 1846 | * 1. The hardware will tell us about partial completion of multi-part |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1847 | * buffers so make sure not to free skb to early. |
Stephen Hemminger | 481cea4 | 2009-08-14 15:33:19 -0700 | [diff] [blame] | 1848 | * 2. This may run in parallel start_xmit because the it only |
| 1849 | * looks at the tail of the queue of FIFO (tx_cons), not |
| 1850 | * the head (tx_prod) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1851 | */ |
shemminger@osdl.org | d11c13e | 2005-09-27 15:02:56 -0700 | [diff] [blame] | 1852 | static void sky2_tx_complete(struct sky2_port *sky2, u16 done) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1853 | { |
shemminger@osdl.org | d11c13e | 2005-09-27 15:02:56 -0700 | [diff] [blame] | 1854 | struct net_device *dev = sky2->netdev; |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1855 | unsigned idx; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1856 | |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 1857 | BUG_ON(done >= sky2->tx_ring_size); |
shemminger@osdl.org | 2224795 | 2005-11-30 11:45:19 -0800 | [diff] [blame] | 1858 | |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1859 | for (idx = sky2->tx_cons; idx != done; |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 1860 | idx = RING_NEXT(idx, sky2->tx_ring_size)) { |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1861 | struct tx_ring_info *re = sky2->tx_ring + idx; |
Stephen Hemminger | 6b84dac | 2009-08-18 15:17:09 +0000 | [diff] [blame] | 1862 | struct sk_buff *skb = re->skb; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1863 | |
Stephen Hemminger | 6b84dac | 2009-08-18 15:17:09 +0000 | [diff] [blame] | 1864 | sky2_tx_unmap(sky2->hw->pdev, re); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1865 | |
Stephen Hemminger | 6b84dac | 2009-08-18 15:17:09 +0000 | [diff] [blame] | 1866 | if (skb) { |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1867 | if (unlikely(netif_msg_tx_done(sky2))) |
| 1868 | printk(KERN_DEBUG "%s: tx done %u\n", |
| 1869 | dev->name, idx); |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 1870 | |
Stephen Hemminger | 7138a0f | 2007-10-11 19:48:22 -0700 | [diff] [blame] | 1871 | dev->stats.tx_packets++; |
Stephen Hemminger | bd1c686 | 2009-06-17 07:30:38 +0000 | [diff] [blame] | 1872 | dev->stats.tx_bytes += skb->len; |
shemminger@linux-foundation.org | 2bf56fe | 2007-01-26 11:38:39 -0800 | [diff] [blame] | 1873 | |
stephen hemminger | f681507 | 2010-02-01 13:41:47 +0000 | [diff] [blame] | 1874 | re->skb = NULL; |
Stephen Hemminger | 724b694 | 2009-08-18 15:17:10 +0000 | [diff] [blame] | 1875 | dev_kfree_skb_any(skb); |
Stephen Hemminger | bd1c686 | 2009-06-17 07:30:38 +0000 | [diff] [blame] | 1876 | |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 1877 | sky2->tx_next = RING_NEXT(idx, sky2->tx_ring_size); |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1878 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1879 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1880 | |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 1881 | sky2->tx_cons = idx; |
Stephen Hemminger | 50432cb | 2007-05-14 12:38:15 -0700 | [diff] [blame] | 1882 | smp_mb(); |
| 1883 | |
Jarek Poplawski | 9db2f1b | 2010-01-04 08:48:41 +0000 | [diff] [blame] | 1884 | /* Wake unless it's detached, and called e.g. from sky2_down() */ |
| 1885 | if (tx_avail(sky2) > MAX_SKB_TX_LE + 4 && netif_device_present(dev)) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1886 | netif_wake_queue(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1887 | } |
| 1888 | |
Mike McCormack | 264bb4f | 2009-08-14 05:15:14 +0000 | [diff] [blame] | 1889 | static void sky2_tx_reset(struct sky2_hw *hw, unsigned port) |
Mike McCormack | a510996 | 2009-08-14 05:15:13 +0000 | [diff] [blame] | 1890 | { |
Mike McCormack | a510996 | 2009-08-14 05:15:13 +0000 | [diff] [blame] | 1891 | /* Disable Force Sync bit and Enable Alloc bit */ |
| 1892 | sky2_write8(hw, SK_REG(port, TXA_CTRL), |
| 1893 | TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC); |
| 1894 | |
| 1895 | /* Stop Interval Timer and Limit Counter of Tx Arbiter */ |
| 1896 | sky2_write32(hw, SK_REG(port, TXA_ITI_INI), 0L); |
| 1897 | sky2_write32(hw, SK_REG(port, TXA_LIM_INI), 0L); |
| 1898 | |
| 1899 | /* Reset the PCI FIFO of the async Tx queue */ |
| 1900 | sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), |
| 1901 | BMU_RST_SET | BMU_FIFO_RST); |
| 1902 | |
| 1903 | /* Reset the Tx prefetch units */ |
| 1904 | sky2_write32(hw, Y2_QADDR(txqaddr[port], PREF_UNIT_CTRL), |
| 1905 | PREF_UNIT_RST_SET); |
| 1906 | |
| 1907 | sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET); |
| 1908 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET); |
| 1909 | } |
| 1910 | |
Mike McCormack | f2b31cb | 2010-02-12 06:58:05 +0000 | [diff] [blame^] | 1911 | static void sky2_hw_down(struct sky2_port *sky2) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1912 | { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1913 | struct sky2_hw *hw = sky2->hw; |
| 1914 | unsigned port = sky2->port; |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 1915 | u32 imask; |
Mike McCormack | f2b31cb | 2010-02-12 06:58:05 +0000 | [diff] [blame^] | 1916 | u16 ctrl; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1917 | |
Stephen Hemminger | d104aca | 2009-06-17 07:30:32 +0000 | [diff] [blame] | 1918 | /* Force flow control off */ |
| 1919 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1920 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1921 | /* Stop transmitter */ |
| 1922 | sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_STOP); |
| 1923 | sky2_read32(hw, Q_ADDR(txqaddr[port], Q_CSR)); |
| 1924 | |
| 1925 | sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1926 | RB_RST_SET | RB_DIS_OP_MD); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1927 | |
| 1928 | ctrl = gma_read16(hw, port, GM_GP_CTRL); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1929 | ctrl &= ~(GM_GPCR_TX_ENA | GM_GPCR_RX_ENA); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1930 | gma_write16(hw, port, GM_GP_CTRL, ctrl); |
| 1931 | |
| 1932 | sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET); |
| 1933 | |
| 1934 | /* Workaround shared GMAC reset */ |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1935 | if (!(hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0 && |
| 1936 | port == 0 && hw->dev[1] && netif_running(hw->dev[1]))) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1937 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET); |
| 1938 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1939 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1940 | |
Stephen Hemminger | 6c83504 | 2009-06-17 07:30:35 +0000 | [diff] [blame] | 1941 | /* Force any delayed status interrrupt and NAPI */ |
| 1942 | sky2_write32(hw, STAT_LEV_TIMER_CNT, 0); |
| 1943 | sky2_write32(hw, STAT_TX_TIMER_CNT, 0); |
| 1944 | sky2_write32(hw, STAT_ISR_TIMER_CNT, 0); |
| 1945 | sky2_read8(hw, STAT_ISR_TIMER_CTRL); |
| 1946 | |
Mike McCormack | a947a39 | 2009-07-21 20:57:56 -0700 | [diff] [blame] | 1947 | sky2_rx_stop(sky2); |
| 1948 | |
| 1949 | /* Disable port IRQ */ |
| 1950 | imask = sky2_read32(hw, B0_IMSK); |
| 1951 | imask &= ~portirq_msk[port]; |
| 1952 | sky2_write32(hw, B0_IMSK, imask); |
| 1953 | sky2_read32(hw, B0_IMSK); |
| 1954 | |
Stephen Hemminger | 6c83504 | 2009-06-17 07:30:35 +0000 | [diff] [blame] | 1955 | synchronize_irq(hw->pdev->irq); |
| 1956 | napi_synchronize(&hw->napi); |
| 1957 | |
Stephen Hemminger | 0da6d7b | 2009-08-14 05:15:15 +0000 | [diff] [blame] | 1958 | spin_lock_bh(&sky2->phy_lock); |
Stephen Hemminger | b96936da7 | 2008-05-14 17:04:15 -0700 | [diff] [blame] | 1959 | sky2_phy_power_down(hw, port); |
Stephen Hemminger | 0da6d7b | 2009-08-14 05:15:15 +0000 | [diff] [blame] | 1960 | spin_unlock_bh(&sky2->phy_lock); |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 1961 | |
Mike McCormack | 264bb4f | 2009-08-14 05:15:14 +0000 | [diff] [blame] | 1962 | sky2_tx_reset(hw, port); |
| 1963 | |
Stephen Hemminger | 481cea4 | 2009-08-14 15:33:19 -0700 | [diff] [blame] | 1964 | /* Free any pending frames stuck in HW queue */ |
| 1965 | sky2_tx_complete(sky2, sky2->tx_prod); |
Mike McCormack | f2b31cb | 2010-02-12 06:58:05 +0000 | [diff] [blame^] | 1966 | } |
| 1967 | |
| 1968 | /* Network shutdown */ |
| 1969 | static int sky2_down(struct net_device *dev) |
| 1970 | { |
| 1971 | struct sky2_port *sky2 = netdev_priv(dev); |
| 1972 | |
| 1973 | /* Never really got started! */ |
| 1974 | if (!sky2->tx_le) |
| 1975 | return 0; |
| 1976 | |
| 1977 | if (netif_msg_ifdown(sky2)) |
| 1978 | printk(KERN_INFO PFX "%s: disabling interface\n", dev->name); |
| 1979 | |
| 1980 | sky2_hw_down(sky2); |
Stephen Hemminger | 481cea4 | 2009-08-14 15:33:19 -0700 | [diff] [blame] | 1981 | |
Mike McCormack | 90bbebb | 2009-09-01 03:21:35 +0000 | [diff] [blame] | 1982 | sky2_free_buffers(sky2); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 1983 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1984 | return 0; |
| 1985 | } |
| 1986 | |
| 1987 | static u16 sky2_phy_speed(const struct sky2_hw *hw, u16 aux) |
| 1988 | { |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 1989 | if (hw->flags & SKY2_HW_FIBRE_PHY) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 1990 | return SPEED_1000; |
| 1991 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 1992 | if (!(hw->flags & SKY2_HW_GIGABIT)) { |
| 1993 | if (aux & PHY_M_PS_SPEED_100) |
| 1994 | return SPEED_100; |
| 1995 | else |
| 1996 | return SPEED_10; |
| 1997 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 1998 | |
| 1999 | switch (aux & PHY_M_PS_SPEED_MSK) { |
| 2000 | case PHY_M_PS_SPEED_1000: |
| 2001 | return SPEED_1000; |
| 2002 | case PHY_M_PS_SPEED_100: |
| 2003 | return SPEED_100; |
| 2004 | default: |
| 2005 | return SPEED_10; |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | static void sky2_link_up(struct sky2_port *sky2) |
| 2010 | { |
| 2011 | struct sky2_hw *hw = sky2->hw; |
| 2012 | unsigned port = sky2->port; |
| 2013 | u16 reg; |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 2014 | static const char *fc_name[] = { |
| 2015 | [FC_NONE] = "none", |
| 2016 | [FC_TX] = "tx", |
| 2017 | [FC_RX] = "rx", |
| 2018 | [FC_BOTH] = "both", |
| 2019 | }; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2020 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2021 | /* enable Rx/Tx */ |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 2022 | reg = gma_read16(hw, port, GM_GP_CTRL); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2023 | reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA; |
| 2024 | gma_write16(hw, port, GM_GP_CTRL, reg); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2025 | |
| 2026 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); |
| 2027 | |
| 2028 | netif_carrier_on(sky2->netdev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2029 | |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2030 | mod_timer(&hw->watchdog_timer, jiffies + 1); |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 2031 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2032 | /* Turn on link LED */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2033 | sky2_write8(hw, SK_REG(port, LNK_LED_REG), |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2034 | LINKLED_ON | LINKLED_BLINK_OFF | LINKLED_LINKSYNC_OFF); |
| 2035 | |
| 2036 | if (netif_msg_link(sky2)) |
| 2037 | printk(KERN_INFO PFX |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 2038 | "%s: Link is up at %d Mbps, %s duplex, flow control %s\n", |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2039 | sky2->netdev->name, sky2->speed, |
| 2040 | sky2->duplex == DUPLEX_FULL ? "full" : "half", |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 2041 | fc_name[sky2->flow_status]); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | static void sky2_link_down(struct sky2_port *sky2) |
| 2045 | { |
| 2046 | struct sky2_hw *hw = sky2->hw; |
| 2047 | unsigned port = sky2->port; |
| 2048 | u16 reg; |
| 2049 | |
| 2050 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0); |
| 2051 | |
| 2052 | reg = gma_read16(hw, port, GM_GP_CTRL); |
| 2053 | reg &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA); |
| 2054 | gma_write16(hw, port, GM_GP_CTRL, reg); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2055 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2056 | netif_carrier_off(sky2->netdev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2057 | |
Brandon Philips | 809aaaa | 2009-10-29 17:01:49 -0700 | [diff] [blame] | 2058 | /* Turn off link LED */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2059 | sky2_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF); |
| 2060 | |
| 2061 | if (netif_msg_link(sky2)) |
| 2062 | printk(KERN_INFO PFX "%s: Link is down.\n", sky2->netdev->name); |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 2063 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2064 | sky2_phy_init(hw, port); |
| 2065 | } |
| 2066 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 2067 | static enum flow_control sky2_flow(int rx, int tx) |
| 2068 | { |
| 2069 | if (rx) |
| 2070 | return tx ? FC_BOTH : FC_RX; |
| 2071 | else |
| 2072 | return tx ? FC_TX : FC_NONE; |
| 2073 | } |
| 2074 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2075 | static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux) |
| 2076 | { |
| 2077 | struct sky2_hw *hw = sky2->hw; |
| 2078 | unsigned port = sky2->port; |
Stephen Hemminger | da4c1ff | 2007-02-15 16:40:32 -0800 | [diff] [blame] | 2079 | u16 advert, lpa; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2080 | |
Stephen Hemminger | da4c1ff | 2007-02-15 16:40:32 -0800 | [diff] [blame] | 2081 | advert = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2082 | lpa = gm_phy_read(hw, port, PHY_MARV_AUNE_LP); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2083 | if (lpa & PHY_M_AN_RF) { |
| 2084 | printk(KERN_ERR PFX "%s: remote fault", sky2->netdev->name); |
| 2085 | return -1; |
| 2086 | } |
| 2087 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2088 | if (!(aux & PHY_M_PS_SPDUP_RES)) { |
| 2089 | printk(KERN_ERR PFX "%s: speed/duplex mismatch", |
| 2090 | sky2->netdev->name); |
| 2091 | return -1; |
| 2092 | } |
| 2093 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2094 | sky2->speed = sky2_phy_speed(hw, aux); |
Stephen Hemminger | 7c74ac1 | 2006-10-17 10:24:08 -0700 | [diff] [blame] | 2095 | sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2096 | |
Stephen Hemminger | da4c1ff | 2007-02-15 16:40:32 -0800 | [diff] [blame] | 2097 | /* Since the pause result bits seem to in different positions on |
| 2098 | * different chips. look at registers. |
| 2099 | */ |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 2100 | if (hw->flags & SKY2_HW_FIBRE_PHY) { |
Stephen Hemminger | da4c1ff | 2007-02-15 16:40:32 -0800 | [diff] [blame] | 2101 | /* Shift for bits in fiber PHY */ |
| 2102 | advert &= ~(ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM); |
| 2103 | lpa &= ~(LPA_PAUSE_CAP|LPA_PAUSE_ASYM); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2104 | |
Stephen Hemminger | da4c1ff | 2007-02-15 16:40:32 -0800 | [diff] [blame] | 2105 | if (advert & ADVERTISE_1000XPAUSE) |
| 2106 | advert |= ADVERTISE_PAUSE_CAP; |
| 2107 | if (advert & ADVERTISE_1000XPSE_ASYM) |
| 2108 | advert |= ADVERTISE_PAUSE_ASYM; |
| 2109 | if (lpa & LPA_1000XPAUSE) |
| 2110 | lpa |= LPA_PAUSE_CAP; |
| 2111 | if (lpa & LPA_1000XPAUSE_ASYM) |
| 2112 | lpa |= LPA_PAUSE_ASYM; |
| 2113 | } |
| 2114 | |
| 2115 | sky2->flow_status = FC_NONE; |
| 2116 | if (advert & ADVERTISE_PAUSE_CAP) { |
| 2117 | if (lpa & LPA_PAUSE_CAP) |
| 2118 | sky2->flow_status = FC_BOTH; |
| 2119 | else if (advert & ADVERTISE_PAUSE_ASYM) |
| 2120 | sky2->flow_status = FC_RX; |
| 2121 | } else if (advert & ADVERTISE_PAUSE_ASYM) { |
| 2122 | if ((lpa & LPA_PAUSE_CAP) && (lpa & LPA_PAUSE_ASYM)) |
| 2123 | sky2->flow_status = FC_TX; |
| 2124 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2125 | |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 2126 | if (sky2->duplex == DUPLEX_HALF && sky2->speed < SPEED_1000 && |
| 2127 | !(hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX)) |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 2128 | sky2->flow_status = FC_NONE; |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 2129 | |
Stephen Hemminger | da4c1ff | 2007-02-15 16:40:32 -0800 | [diff] [blame] | 2130 | if (sky2->flow_status & FC_TX) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2131 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON); |
| 2132 | else |
| 2133 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); |
| 2134 | |
| 2135 | return 0; |
| 2136 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2137 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2138 | /* Interrupt from PHY */ |
| 2139 | static void sky2_phy_intr(struct sky2_hw *hw, unsigned port) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2140 | { |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2141 | struct net_device *dev = hw->dev[port]; |
| 2142 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2143 | u16 istatus, phystat; |
| 2144 | |
Stephen Hemminger | ebc646f | 2006-10-17 10:23:56 -0700 | [diff] [blame] | 2145 | if (!netif_running(dev)) |
| 2146 | return; |
| 2147 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2148 | spin_lock(&sky2->phy_lock); |
| 2149 | istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT); |
| 2150 | phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT); |
| 2151 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2152 | if (netif_msg_intr(sky2)) |
| 2153 | printk(KERN_INFO PFX "%s: phy interrupt status 0x%x 0x%x\n", |
| 2154 | sky2->netdev->name, istatus, phystat); |
| 2155 | |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 2156 | if (istatus & PHY_M_IS_AN_COMPL) { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2157 | if (sky2_autoneg_done(sky2, phystat) == 0) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2158 | sky2_link_up(sky2); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2159 | goto out; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2162 | if (istatus & PHY_M_IS_LSP_CHANGE) |
| 2163 | sky2->speed = sky2_phy_speed(hw, phystat); |
| 2164 | |
| 2165 | if (istatus & PHY_M_IS_DUP_CHANGE) |
| 2166 | sky2->duplex = |
| 2167 | (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF; |
| 2168 | |
| 2169 | if (istatus & PHY_M_IS_LST_CHANGE) { |
| 2170 | if (phystat & PHY_M_PS_LINK_UP) |
| 2171 | sky2_link_up(sky2); |
| 2172 | else |
| 2173 | sky2_link_down(sky2); |
| 2174 | } |
| 2175 | out: |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2176 | spin_unlock(&sky2->phy_lock); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
Stephen Hemminger | 0f5aac7 | 2009-10-29 06:37:09 +0000 | [diff] [blame] | 2179 | /* Special quick link interrupt (Yukon-2 Optima only) */ |
| 2180 | static void sky2_qlink_intr(struct sky2_hw *hw) |
| 2181 | { |
| 2182 | struct sky2_port *sky2 = netdev_priv(hw->dev[0]); |
| 2183 | u32 imask; |
| 2184 | u16 phy; |
| 2185 | |
| 2186 | /* disable irq */ |
| 2187 | imask = sky2_read32(hw, B0_IMSK); |
| 2188 | imask &= ~Y2_IS_PHY_QLNK; |
| 2189 | sky2_write32(hw, B0_IMSK, imask); |
| 2190 | |
| 2191 | /* reset PHY Link Detect */ |
| 2192 | phy = sky2_pci_read16(hw, PSM_CONFIG_REG4); |
stephen hemminger | a40ccc6 | 2010-01-24 18:46:06 +0000 | [diff] [blame] | 2193 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
Stephen Hemminger | 0f5aac7 | 2009-10-29 06:37:09 +0000 | [diff] [blame] | 2194 | sky2_pci_write16(hw, PSM_CONFIG_REG4, phy | 1); |
stephen hemminger | a40ccc6 | 2010-01-24 18:46:06 +0000 | [diff] [blame] | 2195 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
Stephen Hemminger | 0f5aac7 | 2009-10-29 06:37:09 +0000 | [diff] [blame] | 2196 | |
| 2197 | sky2_link_up(sky2); |
| 2198 | } |
| 2199 | |
Stephen Hemminger | 62335ab | 2007-02-06 10:45:42 -0800 | [diff] [blame] | 2200 | /* Transmit timeout is only called if we are running, carrier is up |
Stephen Hemminger | 302d125 | 2006-01-17 13:43:20 -0800 | [diff] [blame] | 2201 | * and tx queue is full (stopped). |
| 2202 | */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2203 | static void sky2_tx_timeout(struct net_device *dev) |
| 2204 | { |
| 2205 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 8cc048e | 2005-12-09 11:35:07 -0800 | [diff] [blame] | 2206 | struct sky2_hw *hw = sky2->hw; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2207 | |
| 2208 | if (netif_msg_timer(sky2)) |
| 2209 | printk(KERN_ERR PFX "%s: tx timeout\n", dev->name); |
| 2210 | |
Stephen Hemminger | 8f24664 | 2006-03-20 15:48:21 -0800 | [diff] [blame] | 2211 | printk(KERN_DEBUG PFX "%s: transmit ring %u .. %u report=%u done=%u\n", |
Stephen Hemminger | 62335ab | 2007-02-06 10:45:42 -0800 | [diff] [blame] | 2212 | dev->name, sky2->tx_cons, sky2->tx_prod, |
| 2213 | sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX), |
| 2214 | sky2_read16(hw, Q_ADDR(txqaddr[sky2->port], Q_DONE))); |
Stephen Hemminger | 8cc048e | 2005-12-09 11:35:07 -0800 | [diff] [blame] | 2215 | |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 2216 | /* can't restart safely under softirq */ |
| 2217 | schedule_work(&hw->restart_work); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | static int sky2_change_mtu(struct net_device *dev, int new_mtu) |
| 2221 | { |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2222 | struct sky2_port *sky2 = netdev_priv(dev); |
| 2223 | struct sky2_hw *hw = sky2->hw; |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 2224 | unsigned port = sky2->port; |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2225 | int err; |
| 2226 | u16 ctl, mode; |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2227 | u32 imask; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2228 | |
stephen hemminger | 44dde56 | 2010-02-12 06:58:01 +0000 | [diff] [blame] | 2229 | /* MTU size outside the spec */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2230 | if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU) |
| 2231 | return -EINVAL; |
| 2232 | |
stephen hemminger | 44dde56 | 2010-02-12 06:58:01 +0000 | [diff] [blame] | 2233 | /* MTU > 1500 on yukon FE and FE+ not allowed */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 2234 | if (new_mtu > ETH_DATA_LEN && |
| 2235 | (hw->chip_id == CHIP_ID_YUKON_FE || |
| 2236 | hw->chip_id == CHIP_ID_YUKON_FE_P)) |
Stephen Hemminger | d2adf4f | 2007-04-11 14:48:02 -0700 | [diff] [blame] | 2237 | return -EINVAL; |
| 2238 | |
stephen hemminger | 44dde56 | 2010-02-12 06:58:01 +0000 | [diff] [blame] | 2239 | /* TSO, etc on Yukon Ultra and MTU > 1500 not supported */ |
| 2240 | if (new_mtu > ETH_DATA_LEN && hw->chip_id == CHIP_ID_YUKON_EC_U) |
| 2241 | dev->features &= ~(NETIF_F_TSO|NETIF_F_SG|NETIF_F_ALL_CSUM); |
| 2242 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2243 | if (!netif_running(dev)) { |
| 2244 | dev->mtu = new_mtu; |
| 2245 | return 0; |
| 2246 | } |
| 2247 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2248 | imask = sky2_read32(hw, B0_IMSK); |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2249 | sky2_write32(hw, B0_IMSK, 0); |
| 2250 | |
shemminger@osdl.org | 018d1c6 | 2005-11-30 11:45:18 -0800 | [diff] [blame] | 2251 | dev->trans_start = jiffies; /* prevent tx timeout */ |
| 2252 | netif_stop_queue(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2253 | napi_disable(&hw->napi); |
shemminger@osdl.org | 018d1c6 | 2005-11-30 11:45:18 -0800 | [diff] [blame] | 2254 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2255 | synchronize_irq(hw->pdev->irq); |
| 2256 | |
Stephen Hemminger | 39dbd95 | 2008-02-04 19:45:13 -0800 | [diff] [blame] | 2257 | if (!(hw->flags & SKY2_HW_RAM_BUFFER)) |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 2258 | sky2_set_tx_stfwd(hw, port); |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 2259 | |
| 2260 | ctl = gma_read16(hw, port, GM_GP_CTRL); |
| 2261 | gma_write16(hw, port, GM_GP_CTRL, ctl & ~GM_GPCR_RX_ENA); |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2262 | sky2_rx_stop(sky2); |
| 2263 | sky2_rx_clean(sky2); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2264 | |
| 2265 | dev->mtu = new_mtu; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2266 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2267 | mode = DATA_BLIND_VAL(DATA_BLIND_DEF) | |
| 2268 | GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2269 | |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2270 | if (dev->mtu > ETH_DATA_LEN) |
| 2271 | mode |= GM_SMOD_JUMBO_ENA; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2272 | |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 2273 | gma_write16(hw, port, GM_SERIAL_MODE, mode); |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2274 | |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 2275 | sky2_write8(hw, RB_ADDR(rxqaddr[port], RB_CTRL), RB_ENA_OP_MD); |
shemminger@osdl.org | 6b1a3ae | 2005-09-27 15:02:55 -0700 | [diff] [blame] | 2276 | |
Mike McCormack | 200ac49 | 2010-02-12 06:58:03 +0000 | [diff] [blame] | 2277 | err = sky2_alloc_rx_skbs(sky2); |
| 2278 | if (!err) |
| 2279 | sky2_rx_start(sky2); |
| 2280 | else |
| 2281 | sky2_rx_clean(sky2); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2282 | sky2_write32(hw, B0_IMSK, imask); |
shemminger@osdl.org | 018d1c6 | 2005-11-30 11:45:18 -0800 | [diff] [blame] | 2283 | |
David S. Miller | d1d08d1 | 2008-01-07 20:53:33 -0800 | [diff] [blame] | 2284 | sky2_read32(hw, B0_Y2_SP_LISR); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2285 | napi_enable(&hw->napi); |
| 2286 | |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 2287 | if (err) |
| 2288 | dev_close(dev); |
| 2289 | else { |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 2290 | gma_write16(hw, port, GM_GP_CTRL, ctl); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 2291 | |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 2292 | netif_wake_queue(dev); |
| 2293 | } |
| 2294 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2295 | return err; |
| 2296 | } |
| 2297 | |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2298 | /* For small just reuse existing skb for next receive */ |
| 2299 | static struct sk_buff *receive_copy(struct sky2_port *sky2, |
| 2300 | const struct rx_ring_info *re, |
| 2301 | unsigned length) |
| 2302 | { |
| 2303 | struct sk_buff *skb; |
| 2304 | |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 2305 | skb = netdev_alloc_skb_ip_align(sky2->netdev, length); |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2306 | if (likely(skb)) { |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2307 | pci_dma_sync_single_for_cpu(sky2->hw->pdev, re->data_addr, |
| 2308 | length, PCI_DMA_FROMDEVICE); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 2309 | skb_copy_from_linear_data(re->skb, skb->data, length); |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2310 | skb->ip_summed = re->skb->ip_summed; |
| 2311 | skb->csum = re->skb->csum; |
| 2312 | pci_dma_sync_single_for_device(sky2->hw->pdev, re->data_addr, |
| 2313 | length, PCI_DMA_FROMDEVICE); |
| 2314 | re->skb->ip_summed = CHECKSUM_NONE; |
Stephen Hemminger | 489b10c | 2006-10-03 16:39:12 -0700 | [diff] [blame] | 2315 | skb_put(skb, length); |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2316 | } |
| 2317 | return skb; |
| 2318 | } |
| 2319 | |
| 2320 | /* Adjust length of skb with fragments to match received data */ |
| 2321 | static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space, |
| 2322 | unsigned int length) |
| 2323 | { |
| 2324 | int i, num_frags; |
| 2325 | unsigned int size; |
| 2326 | |
| 2327 | /* put header into skb */ |
| 2328 | size = min(length, hdr_space); |
| 2329 | skb->tail += size; |
| 2330 | skb->len += size; |
| 2331 | length -= size; |
| 2332 | |
| 2333 | num_frags = skb_shinfo(skb)->nr_frags; |
| 2334 | for (i = 0; i < num_frags; i++) { |
| 2335 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 2336 | |
| 2337 | if (length == 0) { |
| 2338 | /* don't need this page */ |
| 2339 | __free_page(frag->page); |
| 2340 | --skb_shinfo(skb)->nr_frags; |
| 2341 | } else { |
| 2342 | size = min(length, (unsigned) PAGE_SIZE); |
| 2343 | |
| 2344 | frag->size = size; |
| 2345 | skb->data_len += size; |
| 2346 | skb->truesize += size; |
| 2347 | skb->len += size; |
| 2348 | length -= size; |
| 2349 | } |
| 2350 | } |
| 2351 | } |
| 2352 | |
| 2353 | /* Normal packet - take skb from ring element and put in a new one */ |
| 2354 | static struct sk_buff *receive_new(struct sky2_port *sky2, |
| 2355 | struct rx_ring_info *re, |
| 2356 | unsigned int length) |
| 2357 | { |
stephen hemminger | 3fbd918 | 2010-02-01 13:45:41 +0000 | [diff] [blame] | 2358 | struct sk_buff *skb; |
| 2359 | struct rx_ring_info nre; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2360 | unsigned hdr_space = sky2->rx_data_size; |
| 2361 | |
stephen hemminger | 3fbd918 | 2010-02-01 13:45:41 +0000 | [diff] [blame] | 2362 | nre.skb = sky2_rx_alloc(sky2); |
| 2363 | if (unlikely(!nre.skb)) |
| 2364 | goto nobuf; |
| 2365 | |
| 2366 | if (sky2_rx_map_skb(sky2->hw->pdev, &nre, hdr_space)) |
| 2367 | goto nomap; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2368 | |
| 2369 | skb = re->skb; |
| 2370 | sky2_rx_unmap_skb(sky2->hw->pdev, re); |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2371 | prefetch(skb->data); |
stephen hemminger | 3fbd918 | 2010-02-01 13:45:41 +0000 | [diff] [blame] | 2372 | *re = nre; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2373 | |
| 2374 | if (skb_shinfo(skb)->nr_frags) |
| 2375 | skb_put_frags(skb, hdr_space, length); |
| 2376 | else |
Stephen Hemminger | 489b10c | 2006-10-03 16:39:12 -0700 | [diff] [blame] | 2377 | skb_put(skb, length); |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2378 | return skb; |
stephen hemminger | 3fbd918 | 2010-02-01 13:45:41 +0000 | [diff] [blame] | 2379 | |
| 2380 | nomap: |
| 2381 | dev_kfree_skb(nre.skb); |
| 2382 | nobuf: |
| 2383 | return NULL; |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2384 | } |
| 2385 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2386 | /* |
| 2387 | * Receive one packet. |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 2388 | * For larger packets, get new buffer. |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2389 | */ |
shemminger@osdl.org | 497d7c8 | 2006-08-28 10:00:46 -0700 | [diff] [blame] | 2390 | static struct sk_buff *sky2_receive(struct net_device *dev, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2391 | u16 length, u32 status) |
| 2392 | { |
shemminger@osdl.org | 497d7c8 | 2006-08-28 10:00:46 -0700 | [diff] [blame] | 2393 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 291ea61 | 2006-09-26 11:57:41 -0700 | [diff] [blame] | 2394 | struct rx_ring_info *re = sky2->rx_ring + sky2->rx_next; |
Stephen Hemminger | 79e57d3 | 2005-09-19 15:42:33 -0700 | [diff] [blame] | 2395 | struct sk_buff *skb = NULL; |
Stephen Hemminger | d653223 | 2007-09-19 15:36:42 -0700 | [diff] [blame] | 2396 | u16 count = (status & GMR_FS_LEN) >> 16; |
| 2397 | |
| 2398 | #ifdef SKY2_VLAN_TAG_USED |
| 2399 | /* Account for vlan tag */ |
| 2400 | if (sky2->vlgrp && (status & GMR_FS_VLAN)) |
| 2401 | count -= VLAN_HLEN; |
| 2402 | #endif |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2403 | |
| 2404 | if (unlikely(netif_msg_rx_status(sky2))) |
| 2405 | printk(KERN_DEBUG PFX "%s: rx slot %u status 0x%x len %d\n", |
shemminger@osdl.org | 497d7c8 | 2006-08-28 10:00:46 -0700 | [diff] [blame] | 2406 | dev->name, sky2->rx_next, status, length); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2407 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2408 | sky2->rx_next = (sky2->rx_next + 1) % sky2->rx_pending; |
Stephen Hemminger | d70cd51 | 2005-12-09 11:35:09 -0800 | [diff] [blame] | 2409 | prefetch(sky2->rx_ring + sky2->rx_next); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2410 | |
Stephen Hemminger | 3b12e01 | 2007-09-26 17:58:47 -0700 | [diff] [blame] | 2411 | /* This chip has hardware problems that generates bogus status. |
| 2412 | * So do only marginal checking and expect higher level protocols |
| 2413 | * to handle crap frames. |
| 2414 | */ |
| 2415 | if (sky2->hw->chip_id == CHIP_ID_YUKON_FE_P && |
| 2416 | sky2->hw->chip_rev == CHIP_REV_YU_FE2_A0 && |
| 2417 | length != count) |
| 2418 | goto okay; |
| 2419 | |
shemminger@osdl.org | 42eeea0 | 2005-11-30 11:45:13 -0800 | [diff] [blame] | 2420 | if (status & GMR_FS_ANY_ERR) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2421 | goto error; |
| 2422 | |
shemminger@osdl.org | 42eeea0 | 2005-11-30 11:45:13 -0800 | [diff] [blame] | 2423 | if (!(status & GMR_FS_RX_OK)) |
| 2424 | goto resubmit; |
| 2425 | |
Stephen Hemminger | d653223 | 2007-09-19 15:36:42 -0700 | [diff] [blame] | 2426 | /* if length reported by DMA does not match PHY, packet was truncated */ |
| 2427 | if (length != count) |
Stephen Hemminger | 3b12e01 | 2007-09-26 17:58:47 -0700 | [diff] [blame] | 2428 | goto len_error; |
Stephen Hemminger | 7174953 | 2007-07-09 15:33:40 -0700 | [diff] [blame] | 2429 | |
Stephen Hemminger | 3b12e01 | 2007-09-26 17:58:47 -0700 | [diff] [blame] | 2430 | okay: |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2431 | if (length < copybreak) |
| 2432 | skb = receive_copy(sky2, re, length); |
| 2433 | else |
| 2434 | skb = receive_new(sky2, re, length); |
Stephen Hemminger | 90c3033 | 2010-02-03 08:31:12 +0000 | [diff] [blame] | 2435 | |
| 2436 | dev->stats.rx_dropped += (skb == NULL); |
| 2437 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2438 | resubmit: |
Stephen Hemminger | 14d0263 | 2006-09-26 11:57:43 -0700 | [diff] [blame] | 2439 | sky2_rx_submit(sky2, re); |
Stephen Hemminger | 79e57d3 | 2005-09-19 15:42:33 -0700 | [diff] [blame] | 2440 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2441 | return skb; |
| 2442 | |
Stephen Hemminger | 3b12e01 | 2007-09-26 17:58:47 -0700 | [diff] [blame] | 2443 | len_error: |
Stephen Hemminger | 7174953 | 2007-07-09 15:33:40 -0700 | [diff] [blame] | 2444 | /* Truncation of overlength packets |
| 2445 | causes PHY length to not match MAC length */ |
Stephen Hemminger | 7138a0f | 2007-10-11 19:48:22 -0700 | [diff] [blame] | 2446 | ++dev->stats.rx_length_errors; |
Stephen Hemminger | d653223 | 2007-09-19 15:36:42 -0700 | [diff] [blame] | 2447 | if (netif_msg_rx_err(sky2) && net_ratelimit()) |
Stephen Hemminger | 3b12e01 | 2007-09-26 17:58:47 -0700 | [diff] [blame] | 2448 | pr_info(PFX "%s: rx length error: status %#x length %d\n", |
| 2449 | dev->name, status, length); |
Stephen Hemminger | d653223 | 2007-09-19 15:36:42 -0700 | [diff] [blame] | 2450 | goto resubmit; |
Stephen Hemminger | 7174953 | 2007-07-09 15:33:40 -0700 | [diff] [blame] | 2451 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2452 | error: |
Stephen Hemminger | 7138a0f | 2007-10-11 19:48:22 -0700 | [diff] [blame] | 2453 | ++dev->stats.rx_errors; |
Stephen Hemminger | b6d7773 | 2006-10-17 10:24:16 -0700 | [diff] [blame] | 2454 | if (status & GMR_FS_RX_FF_OV) { |
Stephen Hemminger | 7138a0f | 2007-10-11 19:48:22 -0700 | [diff] [blame] | 2455 | dev->stats.rx_over_errors++; |
Stephen Hemminger | b6d7773 | 2006-10-17 10:24:16 -0700 | [diff] [blame] | 2456 | goto resubmit; |
| 2457 | } |
Stephen Hemminger | 6e15b71 | 2005-12-20 15:08:09 -0800 | [diff] [blame] | 2458 | |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2459 | if (netif_msg_rx_err(sky2) && net_ratelimit()) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2460 | printk(KERN_INFO PFX "%s: rx error, status 0x%x length %d\n", |
shemminger@osdl.org | 497d7c8 | 2006-08-28 10:00:46 -0700 | [diff] [blame] | 2461 | dev->name, status, length); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2462 | |
| 2463 | if (status & (GMR_FS_LONG_ERR | GMR_FS_UN_SIZE)) |
Stephen Hemminger | 7138a0f | 2007-10-11 19:48:22 -0700 | [diff] [blame] | 2464 | dev->stats.rx_length_errors++; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2465 | if (status & GMR_FS_FRAGMENT) |
Stephen Hemminger | 7138a0f | 2007-10-11 19:48:22 -0700 | [diff] [blame] | 2466 | dev->stats.rx_frame_errors++; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2467 | if (status & GMR_FS_CRC_ERR) |
Stephen Hemminger | 7138a0f | 2007-10-11 19:48:22 -0700 | [diff] [blame] | 2468 | dev->stats.rx_crc_errors++; |
Stephen Hemminger | 79e57d3 | 2005-09-19 15:42:33 -0700 | [diff] [blame] | 2469 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2470 | goto resubmit; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2473 | /* Transmit complete */ |
| 2474 | static inline void sky2_tx_done(struct net_device *dev, u16 last) |
Stephen Hemminger | 13b97b7 | 2005-12-09 11:35:03 -0800 | [diff] [blame] | 2475 | { |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2476 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 302d125 | 2006-01-17 13:43:20 -0800 | [diff] [blame] | 2477 | |
Stephen Hemminger | 49d4b8b | 2009-08-14 13:33:17 +0000 | [diff] [blame] | 2478 | if (netif_running(dev)) |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2479 | sky2_tx_complete(sky2, last); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2480 | } |
| 2481 | |
Stephen Hemminger | 37e5a24 | 2009-06-17 07:30:39 +0000 | [diff] [blame] | 2482 | static inline void sky2_skb_rx(const struct sky2_port *sky2, |
| 2483 | u32 status, struct sk_buff *skb) |
| 2484 | { |
| 2485 | #ifdef SKY2_VLAN_TAG_USED |
| 2486 | u16 vlan_tag = be16_to_cpu(sky2->rx_tag); |
| 2487 | if (sky2->vlgrp && (status & GMR_FS_VLAN)) { |
| 2488 | if (skb->ip_summed == CHECKSUM_NONE) |
| 2489 | vlan_hwaccel_receive_skb(skb, sky2->vlgrp, vlan_tag); |
| 2490 | else |
| 2491 | vlan_gro_receive(&sky2->hw->napi, sky2->vlgrp, |
| 2492 | vlan_tag, skb); |
| 2493 | return; |
| 2494 | } |
| 2495 | #endif |
| 2496 | if (skb->ip_summed == CHECKSUM_NONE) |
| 2497 | netif_receive_skb(skb); |
| 2498 | else |
| 2499 | napi_gro_receive(&sky2->hw->napi, skb); |
| 2500 | } |
| 2501 | |
Stephen Hemminger | bf15fe9 | 2009-06-17 07:30:36 +0000 | [diff] [blame] | 2502 | static inline void sky2_rx_done(struct sky2_hw *hw, unsigned port, |
| 2503 | unsigned packets, unsigned bytes) |
| 2504 | { |
| 2505 | if (packets) { |
| 2506 | struct net_device *dev = hw->dev[port]; |
| 2507 | |
| 2508 | dev->stats.rx_packets += packets; |
| 2509 | dev->stats.rx_bytes += bytes; |
| 2510 | dev->last_rx = jiffies; |
| 2511 | sky2_rx_update(netdev_priv(dev), rxqaddr[port]); |
| 2512 | } |
| 2513 | } |
| 2514 | |
stephen hemminger | 375c568 | 2010-02-07 06:28:36 +0000 | [diff] [blame] | 2515 | static void sky2_rx_checksum(struct sky2_port *sky2, u32 status) |
| 2516 | { |
| 2517 | /* If this happens then driver assuming wrong format for chip type */ |
| 2518 | BUG_ON(sky2->hw->flags & SKY2_HW_NEW_LE); |
| 2519 | |
| 2520 | /* Both checksum counters are programmed to start at |
| 2521 | * the same offset, so unless there is a problem they |
| 2522 | * should match. This failure is an early indication that |
| 2523 | * hardware receive checksumming won't work. |
| 2524 | */ |
| 2525 | if (likely((u16)(status >> 16) == (u16)status)) { |
| 2526 | struct sk_buff *skb = sky2->rx_ring[sky2->rx_next].skb; |
| 2527 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 2528 | skb->csum = le16_to_cpu(status); |
| 2529 | } else { |
| 2530 | dev_notice(&sky2->hw->pdev->dev, |
| 2531 | "%s: receive checksum problem (status = %#x)\n", |
| 2532 | sky2->netdev->name, status); |
| 2533 | |
| 2534 | /* Disable checksum offload */ |
| 2535 | sky2->flags &= ~SKY2_FLAG_RX_CHECKSUM; |
| 2536 | sky2_write32(sky2->hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR), |
| 2537 | BMU_DIS_RX_CHKSUM); |
| 2538 | } |
| 2539 | } |
| 2540 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2541 | /* Process status response ring */ |
Stephen Hemminger | 2669183 | 2007-10-11 18:31:13 -0700 | [diff] [blame] | 2542 | static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2543 | { |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2544 | int work_done = 0; |
Stephen Hemminger | bf15fe9 | 2009-06-17 07:30:36 +0000 | [diff] [blame] | 2545 | unsigned int total_bytes[2] = { 0 }; |
| 2546 | unsigned int total_packets[2] = { 0 }; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2547 | |
Stephen Hemminger | af2a58a | 2005-12-09 11:35:04 -0800 | [diff] [blame] | 2548 | rmb(); |
Stephen Hemminger | 2669183 | 2007-10-11 18:31:13 -0700 | [diff] [blame] | 2549 | do { |
Stephen Hemminger | 55c9dd3 | 2007-07-09 15:33:37 -0700 | [diff] [blame] | 2550 | struct sky2_port *sky2; |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2551 | struct sky2_status_le *le = hw->st_le + hw->st_idx; |
Stephen Hemminger | ab5adec | 2007-11-05 15:52:09 -0800 | [diff] [blame] | 2552 | unsigned port; |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2553 | struct net_device *dev; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2554 | struct sk_buff *skb; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2555 | u32 status; |
| 2556 | u16 length; |
Stephen Hemminger | ab5adec | 2007-11-05 15:52:09 -0800 | [diff] [blame] | 2557 | u8 opcode = le->opcode; |
| 2558 | |
| 2559 | if (!(opcode & HW_OWNER)) |
| 2560 | break; |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2561 | |
Stephen Hemminger | cb5d954 | 2006-05-08 15:11:29 -0700 | [diff] [blame] | 2562 | hw->st_idx = RING_NEXT(hw->st_idx, STATUS_RING_SIZE); |
shemminger@osdl.org | bea8610 | 2005-10-26 12:16:10 -0700 | [diff] [blame] | 2563 | |
Stephen Hemminger | ab5adec | 2007-11-05 15:52:09 -0800 | [diff] [blame] | 2564 | port = le->css & CSS_LINK_BIT; |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 2565 | dev = hw->dev[port]; |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2566 | sky2 = netdev_priv(dev); |
Stephen Hemminger | f65b138 | 2006-09-06 12:45:02 -0700 | [diff] [blame] | 2567 | length = le16_to_cpu(le->length); |
| 2568 | status = le32_to_cpu(le->status); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2569 | |
Stephen Hemminger | ab5adec | 2007-11-05 15:52:09 -0800 | [diff] [blame] | 2570 | le->opcode = 0; |
| 2571 | switch (opcode & ~HW_OWNER) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2572 | case OP_RXSTAT: |
Stephen Hemminger | bf15fe9 | 2009-06-17 07:30:36 +0000 | [diff] [blame] | 2573 | total_packets[port]++; |
| 2574 | total_bytes[port] += length; |
Stephen Hemminger | 90c3033 | 2010-02-03 08:31:12 +0000 | [diff] [blame] | 2575 | |
shemminger@osdl.org | 497d7c8 | 2006-08-28 10:00:46 -0700 | [diff] [blame] | 2576 | skb = sky2_receive(dev, length, status); |
Stephen Hemminger | 90c3033 | 2010-02-03 08:31:12 +0000 | [diff] [blame] | 2577 | if (!skb) |
Stephen Hemminger | 55c9dd3 | 2007-07-09 15:33:37 -0700 | [diff] [blame] | 2578 | break; |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2579 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 2580 | /* This chip reports checksum status differently */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 2581 | if (hw->flags & SKY2_HW_NEW_LE) { |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 2582 | if ((sky2->flags & SKY2_FLAG_RX_CHECKSUM) && |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 2583 | (le->css & (CSS_ISIPV4 | CSS_ISIPV6)) && |
| 2584 | (le->css & CSS_TCPUDPCSOK)) |
| 2585 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2586 | else |
| 2587 | skb->ip_summed = CHECKSUM_NONE; |
| 2588 | } |
| 2589 | |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2590 | skb->protocol = eth_type_trans(skb, dev); |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2591 | |
Stephen Hemminger | 37e5a24 | 2009-06-17 07:30:39 +0000 | [diff] [blame] | 2592 | sky2_skb_rx(sky2, status, skb); |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2593 | |
Stephen Hemminger | 22e1170 | 2006-07-12 15:23:48 -0700 | [diff] [blame] | 2594 | /* Stop after net poll weight */ |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2595 | if (++work_done >= to_do) |
| 2596 | goto exit_loop; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2597 | break; |
| 2598 | |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 2599 | #ifdef SKY2_VLAN_TAG_USED |
| 2600 | case OP_RXVLAN: |
| 2601 | sky2->rx_tag = length; |
| 2602 | break; |
| 2603 | |
| 2604 | case OP_RXCHKSVLAN: |
| 2605 | sky2->rx_tag = length; |
| 2606 | /* fall through */ |
| 2607 | #endif |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2608 | case OP_RXCHKS: |
stephen hemminger | 375c568 | 2010-02-07 06:28:36 +0000 | [diff] [blame] | 2609 | if (likely(sky2->flags & SKY2_FLAG_RX_CHECKSUM)) |
| 2610 | sky2_rx_checksum(sky2, status); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2611 | break; |
| 2612 | |
| 2613 | case OP_TXINDEXLE: |
Stephen Hemminger | 13b97b7 | 2005-12-09 11:35:03 -0800 | [diff] [blame] | 2614 | /* TX index reports status for both ports */ |
Stephen Hemminger | f55925d | 2006-05-08 15:11:28 -0700 | [diff] [blame] | 2615 | sky2_tx_done(hw->dev[0], status & 0xfff); |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2616 | if (hw->dev[1]) |
| 2617 | sky2_tx_done(hw->dev[1], |
| 2618 | ((status >> 24) & 0xff) |
| 2619 | | (u16)(length & 0xf) << 8); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2620 | break; |
| 2621 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2622 | default: |
| 2623 | if (net_ratelimit()) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2624 | printk(KERN_WARNING PFX |
Stephen Hemminger | ab5adec | 2007-11-05 15:52:09 -0800 | [diff] [blame] | 2625 | "unknown status opcode 0x%x\n", opcode); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2626 | } |
Stephen Hemminger | 2669183 | 2007-10-11 18:31:13 -0700 | [diff] [blame] | 2627 | } while (hw->st_idx != idx); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2628 | |
Stephen Hemminger | fe2a24d | 2006-08-01 11:55:23 -0700 | [diff] [blame] | 2629 | /* Fully processed status ring so clear irq */ |
| 2630 | sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ); |
| 2631 | |
shemminger@osdl.org | 13210ce | 2005-11-30 11:45:14 -0800 | [diff] [blame] | 2632 | exit_loop: |
Stephen Hemminger | bf15fe9 | 2009-06-17 07:30:36 +0000 | [diff] [blame] | 2633 | sky2_rx_done(hw, 0, total_packets[0], total_bytes[0]); |
| 2634 | sky2_rx_done(hw, 1, total_packets[1], total_bytes[1]); |
Stephen Hemminger | 22e1170 | 2006-07-12 15:23:48 -0700 | [diff] [blame] | 2635 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2636 | return work_done; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | static void sky2_hw_error(struct sky2_hw *hw, unsigned port, u32 status) |
| 2640 | { |
| 2641 | struct net_device *dev = hw->dev[port]; |
| 2642 | |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2643 | if (net_ratelimit()) |
| 2644 | printk(KERN_INFO PFX "%s: hw error interrupt status 0x%x\n", |
| 2645 | dev->name, status); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2646 | |
| 2647 | if (status & Y2_IS_PAR_RD1) { |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2648 | if (net_ratelimit()) |
| 2649 | printk(KERN_ERR PFX "%s: ram data read parity error\n", |
| 2650 | dev->name); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2651 | /* Clear IRQ */ |
| 2652 | sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_RD_PERR); |
| 2653 | } |
| 2654 | |
| 2655 | if (status & Y2_IS_PAR_WR1) { |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2656 | if (net_ratelimit()) |
| 2657 | printk(KERN_ERR PFX "%s: ram data write parity error\n", |
| 2658 | dev->name); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2659 | |
| 2660 | sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_WR_PERR); |
| 2661 | } |
| 2662 | |
| 2663 | if (status & Y2_IS_PAR_MAC1) { |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2664 | if (net_ratelimit()) |
| 2665 | printk(KERN_ERR PFX "%s: MAC parity error\n", dev->name); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2666 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_PE); |
| 2667 | } |
| 2668 | |
| 2669 | if (status & Y2_IS_PAR_RX1) { |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2670 | if (net_ratelimit()) |
| 2671 | printk(KERN_ERR PFX "%s: RX parity error\n", dev->name); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2672 | sky2_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), BMU_CLR_IRQ_PAR); |
| 2673 | } |
| 2674 | |
| 2675 | if (status & Y2_IS_TCP_TXA1) { |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2676 | if (net_ratelimit()) |
| 2677 | printk(KERN_ERR PFX "%s: TCP segmentation error\n", |
| 2678 | dev->name); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2679 | sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_CLR_IRQ_TCP); |
| 2680 | } |
| 2681 | } |
| 2682 | |
| 2683 | static void sky2_hw_intr(struct sky2_hw *hw) |
| 2684 | { |
Stephen Hemminger | 555382c | 2007-08-29 12:58:14 -0700 | [diff] [blame] | 2685 | struct pci_dev *pdev = hw->pdev; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2686 | u32 status = sky2_read32(hw, B0_HWE_ISRC); |
Stephen Hemminger | 555382c | 2007-08-29 12:58:14 -0700 | [diff] [blame] | 2687 | u32 hwmsk = sky2_read32(hw, B0_HWE_IMSK); |
| 2688 | |
| 2689 | status &= hwmsk; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2690 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2691 | if (status & Y2_IS_TIST_OV) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2692 | sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2693 | |
| 2694 | if (status & (Y2_IS_MST_ERR | Y2_IS_IRQ_STAT)) { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2695 | u16 pci_err; |
| 2696 | |
stephen hemminger | a40ccc6 | 2010-01-24 18:46:06 +0000 | [diff] [blame] | 2697 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 2698 | pci_err = sky2_pci_read16(hw, PCI_STATUS); |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2699 | if (net_ratelimit()) |
Stephen Hemminger | 555382c | 2007-08-29 12:58:14 -0700 | [diff] [blame] | 2700 | dev_err(&pdev->dev, "PCI hardware error (0x%x)\n", |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 2701 | pci_err); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2702 | |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 2703 | sky2_pci_write16(hw, PCI_STATUS, |
Stephen Hemminger | 167f53d | 2007-09-25 19:01:02 -0700 | [diff] [blame] | 2704 | pci_err | PCI_STATUS_ERROR_BITS); |
stephen hemminger | a40ccc6 | 2010-01-24 18:46:06 +0000 | [diff] [blame] | 2705 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | if (status & Y2_IS_PCI_EXP) { |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 2709 | /* PCI-Express uncorrectable Error occurred */ |
Stephen Hemminger | 555382c | 2007-08-29 12:58:14 -0700 | [diff] [blame] | 2710 | u32 err; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2711 | |
stephen hemminger | a40ccc6 | 2010-01-24 18:46:06 +0000 | [diff] [blame] | 2712 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
Stephen Hemminger | 7782c8c | 2007-11-27 11:02:32 -0800 | [diff] [blame] | 2713 | err = sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS); |
| 2714 | sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS, |
| 2715 | 0xfffffffful); |
Stephen Hemminger | 3be92a7 | 2006-01-17 13:43:17 -0800 | [diff] [blame] | 2716 | if (net_ratelimit()) |
Stephen Hemminger | 555382c | 2007-08-29 12:58:14 -0700 | [diff] [blame] | 2717 | dev_err(&pdev->dev, "PCI Express error (0x%x)\n", err); |
Stephen Hemminger | cf06ffb | 2007-11-05 15:52:13 -0800 | [diff] [blame] | 2718 | |
Stephen Hemminger | 7782c8c | 2007-11-27 11:02:32 -0800 | [diff] [blame] | 2719 | sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS); |
stephen hemminger | a40ccc6 | 2010-01-24 18:46:06 +0000 | [diff] [blame] | 2720 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | if (status & Y2_HWE_L1_MASK) |
| 2724 | sky2_hw_error(hw, 0, status); |
| 2725 | status >>= 8; |
| 2726 | if (status & Y2_HWE_L1_MASK) |
| 2727 | sky2_hw_error(hw, 1, status); |
| 2728 | } |
| 2729 | |
| 2730 | static void sky2_mac_intr(struct sky2_hw *hw, unsigned port) |
| 2731 | { |
| 2732 | struct net_device *dev = hw->dev[port]; |
| 2733 | struct sky2_port *sky2 = netdev_priv(dev); |
| 2734 | u8 status = sky2_read8(hw, SK_REG(port, GMAC_IRQ_SRC)); |
| 2735 | |
| 2736 | if (netif_msg_intr(sky2)) |
| 2737 | printk(KERN_INFO PFX "%s: mac interrupt status 0x%x\n", |
| 2738 | dev->name, status); |
| 2739 | |
Stephen Hemminger | a3caead | 2007-05-14 12:38:13 -0700 | [diff] [blame] | 2740 | if (status & GM_IS_RX_CO_OV) |
| 2741 | gma_read16(hw, port, GM_RX_IRQ_SRC); |
| 2742 | |
| 2743 | if (status & GM_IS_TX_CO_OV) |
| 2744 | gma_read16(hw, port, GM_TX_IRQ_SRC); |
| 2745 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2746 | if (status & GM_IS_RX_FF_OR) { |
Stephen Hemminger | 7138a0f | 2007-10-11 19:48:22 -0700 | [diff] [blame] | 2747 | ++dev->stats.rx_fifo_errors; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2748 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO); |
| 2749 | } |
| 2750 | |
| 2751 | if (status & GM_IS_TX_FF_UR) { |
Stephen Hemminger | 7138a0f | 2007-10-11 19:48:22 -0700 | [diff] [blame] | 2752 | ++dev->stats.tx_fifo_errors; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2753 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU); |
| 2754 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2755 | } |
| 2756 | |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2757 | /* This should never happen it is a bug. */ |
Stephen Hemminger | c119731 | 2009-08-18 15:17:07 +0000 | [diff] [blame] | 2758 | static void sky2_le_error(struct sky2_hw *hw, unsigned port, u16 q) |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2759 | { |
| 2760 | struct net_device *dev = hw->dev[port]; |
Stephen Hemminger | c119731 | 2009-08-18 15:17:07 +0000 | [diff] [blame] | 2761 | u16 idx = sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_GET_IDX)); |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2762 | |
Stephen Hemminger | c119731 | 2009-08-18 15:17:07 +0000 | [diff] [blame] | 2763 | dev_err(&hw->pdev->dev, PFX |
| 2764 | "%s: descriptor error q=%#x get=%u put=%u\n", |
| 2765 | dev->name, (unsigned) q, (unsigned) idx, |
| 2766 | (unsigned) sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX))); |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2767 | |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2768 | sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_IRQ_CHK); |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2769 | } |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2770 | |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2771 | static int sky2_rx_hung(struct net_device *dev) |
| 2772 | { |
| 2773 | struct sky2_port *sky2 = netdev_priv(dev); |
| 2774 | struct sky2_hw *hw = sky2->hw; |
| 2775 | unsigned port = sky2->port; |
| 2776 | unsigned rxq = rxqaddr[port]; |
| 2777 | u32 mac_rp = sky2_read32(hw, SK_REG(port, RX_GMF_RP)); |
| 2778 | u8 mac_lev = sky2_read8(hw, SK_REG(port, RX_GMF_RLEV)); |
| 2779 | u8 fifo_rp = sky2_read8(hw, Q_ADDR(rxq, Q_RP)); |
| 2780 | u8 fifo_lev = sky2_read8(hw, Q_ADDR(rxq, Q_RL)); |
| 2781 | |
| 2782 | /* If idle and MAC or PCI is stuck */ |
| 2783 | if (sky2->check.last == dev->last_rx && |
| 2784 | ((mac_rp == sky2->check.mac_rp && |
| 2785 | mac_lev != 0 && mac_lev >= sky2->check.mac_lev) || |
| 2786 | /* Check if the PCI RX hang */ |
| 2787 | (fifo_rp == sky2->check.fifo_rp && |
| 2788 | fifo_lev != 0 && fifo_lev >= sky2->check.fifo_lev))) { |
| 2789 | printk(KERN_DEBUG PFX "%s: hung mac %d:%d fifo %d (%d:%d)\n", |
| 2790 | dev->name, mac_lev, mac_rp, fifo_lev, fifo_rp, |
| 2791 | sky2_read8(hw, Q_ADDR(rxq, Q_WP))); |
| 2792 | return 1; |
| 2793 | } else { |
| 2794 | sky2->check.last = dev->last_rx; |
| 2795 | sky2->check.mac_rp = mac_rp; |
| 2796 | sky2->check.mac_lev = mac_lev; |
| 2797 | sky2->check.fifo_rp = fifo_rp; |
| 2798 | sky2->check.fifo_lev = fifo_lev; |
| 2799 | return 0; |
| 2800 | } |
| 2801 | } |
| 2802 | |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 2803 | static void sky2_watchdog(unsigned long arg) |
Stephen Hemminger | d27ed38 | 2006-04-25 10:58:51 -0700 | [diff] [blame] | 2804 | { |
Stephen Hemminger | 01bd756 | 2006-05-08 15:11:30 -0700 | [diff] [blame] | 2805 | struct sky2_hw *hw = (struct sky2_hw *) arg; |
Stephen Hemminger | d27ed38 | 2006-04-25 10:58:51 -0700 | [diff] [blame] | 2806 | |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2807 | /* Check for lost IRQ once a second */ |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 2808 | if (sky2_read32(hw, B0_ISRC)) { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2809 | napi_schedule(&hw->napi); |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2810 | } else { |
| 2811 | int i, active = 0; |
| 2812 | |
| 2813 | for (i = 0; i < hw->ports; i++) { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2814 | struct net_device *dev = hw->dev[i]; |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2815 | if (!netif_running(dev)) |
| 2816 | continue; |
| 2817 | ++active; |
| 2818 | |
| 2819 | /* For chips with Rx FIFO, check if stuck */ |
Stephen Hemminger | 39dbd95 | 2008-02-04 19:45:13 -0800 | [diff] [blame] | 2820 | if ((hw->flags & SKY2_HW_RAM_BUFFER) && |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2821 | sky2_rx_hung(dev)) { |
| 2822 | pr_info(PFX "%s: receiver hang detected\n", |
| 2823 | dev->name); |
| 2824 | schedule_work(&hw->restart_work); |
| 2825 | return; |
| 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | if (active == 0) |
| 2830 | return; |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
Stephen Hemminger | 75e8068 | 2007-09-19 15:36:46 -0700 | [diff] [blame] | 2833 | mod_timer(&hw->watchdog_timer, round_jiffies(jiffies + HZ)); |
Stephen Hemminger | d27ed38 | 2006-04-25 10:58:51 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2836 | /* Hardware/software error handling */ |
| 2837 | static void sky2_err_intr(struct sky2_hw *hw, u32 status) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2838 | { |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2839 | if (net_ratelimit()) |
| 2840 | dev_warn(&hw->pdev->dev, "error interrupt status=%#x\n", status); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2841 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2842 | if (status & Y2_IS_HW_ERR) |
| 2843 | sky2_hw_intr(hw); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2844 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2845 | if (status & Y2_IS_IRQ_MAC1) |
| 2846 | sky2_mac_intr(hw, 0); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2847 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2848 | if (status & Y2_IS_IRQ_MAC2) |
| 2849 | sky2_mac_intr(hw, 1); |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2850 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2851 | if (status & Y2_IS_CHK_RX1) |
Stephen Hemminger | c119731 | 2009-08-18 15:17:07 +0000 | [diff] [blame] | 2852 | sky2_le_error(hw, 0, Q_R1); |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2853 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2854 | if (status & Y2_IS_CHK_RX2) |
Stephen Hemminger | c119731 | 2009-08-18 15:17:07 +0000 | [diff] [blame] | 2855 | sky2_le_error(hw, 1, Q_R2); |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2856 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2857 | if (status & Y2_IS_CHK_TXA1) |
Stephen Hemminger | c119731 | 2009-08-18 15:17:07 +0000 | [diff] [blame] | 2858 | sky2_le_error(hw, 0, Q_XA1); |
Stephen Hemminger | d257924 | 2006-03-20 15:48:22 -0800 | [diff] [blame] | 2859 | |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2860 | if (status & Y2_IS_CHK_TXA2) |
Stephen Hemminger | c119731 | 2009-08-18 15:17:07 +0000 | [diff] [blame] | 2861 | sky2_le_error(hw, 1, Q_XA2); |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2862 | } |
| 2863 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2864 | static int sky2_poll(struct napi_struct *napi, int work_limit) |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2865 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2866 | struct sky2_hw *hw = container_of(napi, struct sky2_hw, napi); |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2867 | u32 status = sky2_read32(hw, B0_Y2_SP_EISR); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 2868 | int work_done = 0; |
Stephen Hemminger | 2669183 | 2007-10-11 18:31:13 -0700 | [diff] [blame] | 2869 | u16 idx; |
Stephen Hemminger | 40b0172 | 2007-04-11 14:47:59 -0700 | [diff] [blame] | 2870 | |
| 2871 | if (unlikely(status & Y2_IS_ERROR)) |
| 2872 | sky2_err_intr(hw, status); |
| 2873 | |
| 2874 | if (status & Y2_IS_IRQ_PHY1) |
| 2875 | sky2_phy_intr(hw, 0); |
| 2876 | |
| 2877 | if (status & Y2_IS_IRQ_PHY2) |
| 2878 | sky2_phy_intr(hw, 1); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2879 | |
Stephen Hemminger | 0f5aac7 | 2009-10-29 06:37:09 +0000 | [diff] [blame] | 2880 | if (status & Y2_IS_PHY_QLNK) |
| 2881 | sky2_qlink_intr(hw); |
| 2882 | |
Stephen Hemminger | 2669183 | 2007-10-11 18:31:13 -0700 | [diff] [blame] | 2883 | while ((idx = sky2_read16(hw, STAT_PUT_IDX)) != hw->st_idx) { |
| 2884 | work_done += sky2_status_intr(hw, work_limit - work_done, idx); |
Stephen Hemminger | 1e5f128 | 2006-05-08 15:11:27 -0700 | [diff] [blame] | 2885 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 2886 | if (work_done >= work_limit) |
Stephen Hemminger | 2669183 | 2007-10-11 18:31:13 -0700 | [diff] [blame] | 2887 | goto done; |
Stephen Hemminger | fe2a24d | 2006-08-01 11:55:23 -0700 | [diff] [blame] | 2888 | } |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 2889 | |
Stephen Hemminger | 2669183 | 2007-10-11 18:31:13 -0700 | [diff] [blame] | 2890 | napi_complete(napi); |
| 2891 | sky2_read32(hw, B0_Y2_SP_LISR); |
| 2892 | done: |
| 2893 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2894 | return work_done; |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2895 | } |
| 2896 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 2897 | static irqreturn_t sky2_intr(int irq, void *dev_id) |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2898 | { |
| 2899 | struct sky2_hw *hw = dev_id; |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 2900 | u32 status; |
| 2901 | |
| 2902 | /* Reading this mask interrupts as side effect */ |
| 2903 | status = sky2_read32(hw, B0_Y2_SP_ISRC2); |
| 2904 | if (status == 0 || status == ~0) |
| 2905 | return IRQ_NONE; |
| 2906 | |
| 2907 | prefetch(&hw->st_le[hw->st_idx]); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2908 | |
| 2909 | napi_schedule(&hw->napi); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2910 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2911 | return IRQ_HANDLED; |
| 2912 | } |
| 2913 | |
| 2914 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2915 | static void sky2_netpoll(struct net_device *dev) |
| 2916 | { |
| 2917 | struct sky2_port *sky2 = netdev_priv(dev); |
| 2918 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2919 | napi_schedule(&sky2->hw->napi); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2920 | } |
| 2921 | #endif |
| 2922 | |
| 2923 | /* Chip internal frequency for clock calculations */ |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 2924 | static u32 sky2_mhz(const struct sky2_hw *hw) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2925 | { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 2926 | switch (hw->chip_id) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2927 | case CHIP_ID_YUKON_EC: |
shemminger@osdl.org | 5a5b1ea | 2005-11-30 11:45:15 -0800 | [diff] [blame] | 2928 | case CHIP_ID_YUKON_EC_U: |
Stephen Hemminger | 9374549 | 2007-02-06 10:45:43 -0800 | [diff] [blame] | 2929 | case CHIP_ID_YUKON_EX: |
Stephen Hemminger | ed4d416 | 2008-01-10 16:14:14 -0800 | [diff] [blame] | 2930 | case CHIP_ID_YUKON_SUPR: |
Stephen Hemminger | 0ce8b98 | 2008-06-17 09:04:27 -0700 | [diff] [blame] | 2931 | case CHIP_ID_YUKON_UL_2: |
Stephen Hemminger | 0f5aac7 | 2009-10-29 06:37:09 +0000 | [diff] [blame] | 2932 | case CHIP_ID_YUKON_OPT: |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 2933 | return 125; |
| 2934 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2935 | case CHIP_ID_YUKON_FE: |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 2936 | return 100; |
| 2937 | |
| 2938 | case CHIP_ID_YUKON_FE_P: |
| 2939 | return 50; |
| 2940 | |
| 2941 | case CHIP_ID_YUKON_XL: |
| 2942 | return 156; |
| 2943 | |
| 2944 | default: |
| 2945 | BUG(); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2946 | } |
| 2947 | } |
| 2948 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2949 | static inline u32 sky2_us2clk(const struct sky2_hw *hw, u32 us) |
| 2950 | { |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 2951 | return sky2_mhz(hw) * us; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 2954 | static inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk) |
| 2955 | { |
| 2956 | return clk / sky2_mhz(hw); |
| 2957 | } |
| 2958 | |
| 2959 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 2960 | static int __devinit sky2_init(struct sky2_hw *hw) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2961 | { |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 2962 | u8 t8; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2963 | |
Stephen Hemminger | 167f53d | 2007-09-25 19:01:02 -0700 | [diff] [blame] | 2964 | /* Enable all clocks and check for bad PCI access */ |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 2965 | sky2_pci_write32(hw, PCI_DEV_REG3, 0); |
Stephen Hemminger | 451af33 | 2007-06-04 17:23:24 -0700 | [diff] [blame] | 2966 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2967 | sky2_write8(hw, B0_CTST, CS_RST_CLR); |
Stephen Hemminger | 08c06d8 | 2006-01-30 11:37:54 -0800 | [diff] [blame] | 2968 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 2969 | hw->chip_id = sky2_read8(hw, B2_CHIP_ID); |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 2970 | hw->chip_rev = (sky2_read8(hw, B2_MAC_CFG) & CFG_CHIP_R_MSK) >> 4; |
| 2971 | |
| 2972 | switch(hw->chip_id) { |
| 2973 | case CHIP_ID_YUKON_XL: |
Stephen Hemminger | 39dbd95 | 2008-02-04 19:45:13 -0800 | [diff] [blame] | 2974 | hw->flags = SKY2_HW_GIGABIT | SKY2_HW_NEWER_PHY; |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 2975 | break; |
| 2976 | |
| 2977 | case CHIP_ID_YUKON_EC_U: |
| 2978 | hw->flags = SKY2_HW_GIGABIT |
| 2979 | | SKY2_HW_NEWER_PHY |
| 2980 | | SKY2_HW_ADV_POWER_CTL; |
| 2981 | break; |
| 2982 | |
| 2983 | case CHIP_ID_YUKON_EX: |
| 2984 | hw->flags = SKY2_HW_GIGABIT |
| 2985 | | SKY2_HW_NEWER_PHY |
| 2986 | | SKY2_HW_NEW_LE |
| 2987 | | SKY2_HW_ADV_POWER_CTL; |
| 2988 | |
| 2989 | /* New transmit checksum */ |
| 2990 | if (hw->chip_rev != CHIP_REV_YU_EX_B0) |
| 2991 | hw->flags |= SKY2_HW_AUTO_TX_SUM; |
| 2992 | break; |
| 2993 | |
| 2994 | case CHIP_ID_YUKON_EC: |
| 2995 | /* This rev is really old, and requires untested workarounds */ |
| 2996 | if (hw->chip_rev == CHIP_REV_YU_EC_A1) { |
| 2997 | dev_err(&hw->pdev->dev, "unsupported revision Yukon-EC rev A1\n"); |
| 2998 | return -EOPNOTSUPP; |
| 2999 | } |
Stephen Hemminger | 39dbd95 | 2008-02-04 19:45:13 -0800 | [diff] [blame] | 3000 | hw->flags = SKY2_HW_GIGABIT; |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 3001 | break; |
| 3002 | |
| 3003 | case CHIP_ID_YUKON_FE: |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 3004 | break; |
| 3005 | |
Stephen Hemminger | 05745c4 | 2007-09-19 15:36:45 -0700 | [diff] [blame] | 3006 | case CHIP_ID_YUKON_FE_P: |
| 3007 | hw->flags = SKY2_HW_NEWER_PHY |
| 3008 | | SKY2_HW_NEW_LE |
| 3009 | | SKY2_HW_AUTO_TX_SUM |
| 3010 | | SKY2_HW_ADV_POWER_CTL; |
| 3011 | break; |
Stephen Hemminger | ed4d416 | 2008-01-10 16:14:14 -0800 | [diff] [blame] | 3012 | |
| 3013 | case CHIP_ID_YUKON_SUPR: |
| 3014 | hw->flags = SKY2_HW_GIGABIT |
| 3015 | | SKY2_HW_NEWER_PHY |
| 3016 | | SKY2_HW_NEW_LE |
| 3017 | | SKY2_HW_AUTO_TX_SUM |
| 3018 | | SKY2_HW_ADV_POWER_CTL; |
| 3019 | break; |
| 3020 | |
Stephen Hemminger | 0ce8b98 | 2008-06-17 09:04:27 -0700 | [diff] [blame] | 3021 | case CHIP_ID_YUKON_UL_2: |
Takashi Iwai | b338682 | 2009-12-03 05:12:01 +0000 | [diff] [blame] | 3022 | hw->flags = SKY2_HW_GIGABIT |
| 3023 | | SKY2_HW_ADV_POWER_CTL; |
| 3024 | break; |
| 3025 | |
Stephen Hemminger | 0f5aac7 | 2009-10-29 06:37:09 +0000 | [diff] [blame] | 3026 | case CHIP_ID_YUKON_OPT: |
Stephen Hemminger | 0ce8b98 | 2008-06-17 09:04:27 -0700 | [diff] [blame] | 3027 | hw->flags = SKY2_HW_GIGABIT |
Takashi Iwai | b338682 | 2009-12-03 05:12:01 +0000 | [diff] [blame] | 3028 | | SKY2_HW_NEW_LE |
Stephen Hemminger | 0ce8b98 | 2008-06-17 09:04:27 -0700 | [diff] [blame] | 3029 | | SKY2_HW_ADV_POWER_CTL; |
| 3030 | break; |
| 3031 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 3032 | default: |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 3033 | dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n", |
| 3034 | hw->chip_id); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3035 | return -EOPNOTSUPP; |
| 3036 | } |
| 3037 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 3038 | hw->pmd_type = sky2_read8(hw, B2_PMD_TYP); |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 3039 | if (hw->pmd_type == 'L' || hw->pmd_type == 'S' || hw->pmd_type == 'P') |
| 3040 | hw->flags |= SKY2_HW_FIBRE_PHY; |
| 3041 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 3042 | hw->ports = 1; |
| 3043 | t8 = sky2_read8(hw, B2_Y2_HW_RES); |
| 3044 | if ((t8 & CFG_DUAL_MAC_MSK) == CFG_DUAL_MAC_MSK) { |
| 3045 | if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC)) |
| 3046 | ++hw->ports; |
| 3047 | } |
| 3048 | |
Mike McCormack | 74a61eb | 2009-09-21 04:08:52 +0000 | [diff] [blame] | 3049 | if (sky2_read8(hw, B2_E_0)) |
| 3050 | hw->flags |= SKY2_HW_RAM_BUFFER; |
| 3051 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 3052 | return 0; |
| 3053 | } |
| 3054 | |
| 3055 | static void sky2_reset(struct sky2_hw *hw) |
| 3056 | { |
Stephen Hemminger | 555382c | 2007-08-29 12:58:14 -0700 | [diff] [blame] | 3057 | struct pci_dev *pdev = hw->pdev; |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 3058 | u16 status; |
Stephen Hemminger | 555382c | 2007-08-29 12:58:14 -0700 | [diff] [blame] | 3059 | int i, cap; |
| 3060 | u32 hwe_mask = Y2_HWE_ALL_MASK; |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 3061 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3062 | /* disable ASF */ |
stephen hemminger | acd12dd | 2010-02-07 06:24:50 +0000 | [diff] [blame] | 3063 | if (hw->chip_id == CHIP_ID_YUKON_EX |
| 3064 | || hw->chip_id == CHIP_ID_YUKON_SUPR) { |
| 3065 | sky2_write32(hw, CPU_WDOG, 0); |
Stephen Hemminger | 4f44d8b | 2007-04-11 14:48:00 -0700 | [diff] [blame] | 3066 | status = sky2_read16(hw, HCU_CCSR); |
| 3067 | status &= ~(HCU_CCSR_AHB_RST | HCU_CCSR_CPU_RST_MODE | |
| 3068 | HCU_CCSR_UC_STATE_MSK); |
stephen hemminger | acd12dd | 2010-02-07 06:24:50 +0000 | [diff] [blame] | 3069 | /* |
| 3070 | * CPU clock divider shouldn't be used because |
| 3071 | * - ASF firmware may malfunction |
| 3072 | * - Yukon-Supreme: Parallel FLASH doesn't support divided clocks |
| 3073 | */ |
| 3074 | status &= ~HCU_CCSR_CPU_CLK_DIVIDE_MSK; |
Stephen Hemminger | 4f44d8b | 2007-04-11 14:48:00 -0700 | [diff] [blame] | 3075 | sky2_write16(hw, HCU_CCSR, status); |
stephen hemminger | acd12dd | 2010-02-07 06:24:50 +0000 | [diff] [blame] | 3076 | sky2_write32(hw, CPU_WDOG, 0); |
Stephen Hemminger | 4f44d8b | 2007-04-11 14:48:00 -0700 | [diff] [blame] | 3077 | } else |
| 3078 | sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET); |
| 3079 | sky2_write16(hw, B0_CTST, Y2_ASF_DISABLE); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3080 | |
| 3081 | /* do a SW reset */ |
| 3082 | sky2_write8(hw, B0_CTST, CS_RST_SET); |
| 3083 | sky2_write8(hw, B0_CTST, CS_RST_CLR); |
| 3084 | |
Stephen Hemminger | ac93a39 | 2007-11-05 15:52:08 -0800 | [diff] [blame] | 3085 | /* allow writes to PCI config */ |
| 3086 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
| 3087 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3088 | /* clear PCI errors, if any */ |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 3089 | status = sky2_pci_read16(hw, PCI_STATUS); |
Stephen Hemminger | 167f53d | 2007-09-25 19:01:02 -0700 | [diff] [blame] | 3090 | status |= PCI_STATUS_ERROR_BITS; |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 3091 | sky2_pci_write16(hw, PCI_STATUS, status); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3092 | |
| 3093 | sky2_write8(hw, B0_CTST, CS_MRST_CLR); |
| 3094 | |
Stephen Hemminger | 555382c | 2007-08-29 12:58:14 -0700 | [diff] [blame] | 3095 | cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
| 3096 | if (cap) { |
Stephen Hemminger | 7782c8c | 2007-11-27 11:02:32 -0800 | [diff] [blame] | 3097 | sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS, |
| 3098 | 0xfffffffful); |
Stephen Hemminger | 7bd656d | 2006-10-09 14:40:38 -0700 | [diff] [blame] | 3099 | |
Stephen Hemminger | 555382c | 2007-08-29 12:58:14 -0700 | [diff] [blame] | 3100 | /* If error bit is stuck on ignore it */ |
| 3101 | if (sky2_read32(hw, B0_HWE_ISRC) & Y2_IS_PCI_EXP) |
| 3102 | dev_info(&pdev->dev, "ignoring stuck error report bit\n"); |
Stephen Hemminger | 7782c8c | 2007-11-27 11:02:32 -0800 | [diff] [blame] | 3103 | else |
Stephen Hemminger | 555382c | 2007-08-29 12:58:14 -0700 | [diff] [blame] | 3104 | hwe_mask |= Y2_IS_PCI_EXP; |
| 3105 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3106 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 3107 | sky2_power_on(hw); |
stephen hemminger | a40ccc6 | 2010-01-24 18:46:06 +0000 | [diff] [blame] | 3108 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3109 | |
| 3110 | for (i = 0; i < hw->ports; i++) { |
| 3111 | sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET); |
| 3112 | sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR); |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 3113 | |
Stephen Hemminger | ed4d416 | 2008-01-10 16:14:14 -0800 | [diff] [blame] | 3114 | if (hw->chip_id == CHIP_ID_YUKON_EX || |
| 3115 | hw->chip_id == CHIP_ID_YUKON_SUPR) |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 3116 | sky2_write16(hw, SK_REG(i, GMAC_CTRL), |
| 3117 | GMC_BYP_MACSECRX_ON | GMC_BYP_MACSECTX_ON |
| 3118 | | GMC_BYP_RETR_ON); |
Stephen Hemminger | 877c857 | 2009-10-29 06:37:08 +0000 | [diff] [blame] | 3119 | |
| 3120 | } |
| 3121 | |
| 3122 | if (hw->chip_id == CHIP_ID_YUKON_SUPR && hw->chip_rev > CHIP_REV_YU_SU_B0) { |
| 3123 | /* enable MACSec clock gating */ |
| 3124 | sky2_pci_write32(hw, PCI_DEV_REG3, P_CLK_MACSEC_DIS); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3125 | } |
| 3126 | |
Stephen Hemminger | 0f5aac7 | 2009-10-29 06:37:09 +0000 | [diff] [blame] | 3127 | if (hw->chip_id == CHIP_ID_YUKON_OPT) { |
| 3128 | u16 reg; |
| 3129 | u32 msk; |
| 3130 | |
| 3131 | if (hw->chip_rev == 0) { |
| 3132 | /* disable PCI-E PHY power down (set PHY reg 0x80, bit 7 */ |
| 3133 | sky2_write32(hw, Y2_PEX_PHY_DATA, (0x80UL << 16) | (1 << 7)); |
| 3134 | |
| 3135 | /* set PHY Link Detect Timer to 1.1 second (11x 100ms) */ |
| 3136 | reg = 10; |
| 3137 | } else { |
| 3138 | /* set PHY Link Detect Timer to 0.4 second (4x 100ms) */ |
| 3139 | reg = 3; |
| 3140 | } |
| 3141 | |
| 3142 | reg <<= PSM_CONFIG_REG4_TIMER_PHY_LINK_DETECT_BASE; |
| 3143 | |
| 3144 | /* reset PHY Link Detect */ |
stephen hemminger | a40ccc6 | 2010-01-24 18:46:06 +0000 | [diff] [blame] | 3145 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
Stephen Hemminger | 0f5aac7 | 2009-10-29 06:37:09 +0000 | [diff] [blame] | 3146 | sky2_pci_write16(hw, PSM_CONFIG_REG4, |
| 3147 | reg | PSM_CONFIG_REG4_RST_PHY_LINK_DETECT); |
| 3148 | sky2_pci_write16(hw, PSM_CONFIG_REG4, reg); |
| 3149 | |
| 3150 | |
| 3151 | /* enable PHY Quick Link */ |
| 3152 | msk = sky2_read32(hw, B0_IMSK); |
| 3153 | msk |= Y2_IS_PHY_QLNK; |
| 3154 | sky2_write32(hw, B0_IMSK, msk); |
| 3155 | |
| 3156 | /* check if PSMv2 was running before */ |
| 3157 | reg = sky2_pci_read16(hw, PSM_CONFIG_REG3); |
| 3158 | if (reg & PCI_EXP_LNKCTL_ASPMC) { |
stephen hemminger | 8b05543 | 2010-02-12 06:57:58 +0000 | [diff] [blame] | 3159 | cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
Stephen Hemminger | 0f5aac7 | 2009-10-29 06:37:09 +0000 | [diff] [blame] | 3160 | /* restore the PCIe Link Control register */ |
| 3161 | sky2_pci_write16(hw, cap + PCI_EXP_LNKCTL, reg); |
| 3162 | } |
stephen hemminger | a40ccc6 | 2010-01-24 18:46:06 +0000 | [diff] [blame] | 3163 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
Stephen Hemminger | 0f5aac7 | 2009-10-29 06:37:09 +0000 | [diff] [blame] | 3164 | |
| 3165 | /* re-enable PEX PM in PEX PHY debug reg. 8 (clear bit 12) */ |
| 3166 | sky2_write32(hw, Y2_PEX_PHY_DATA, PEX_DB_ACCESS | (0x08UL << 16)); |
| 3167 | } |
| 3168 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3169 | /* Clear I2C IRQ noise */ |
| 3170 | sky2_write32(hw, B2_I2C_IRQ, 1); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3171 | |
| 3172 | /* turn off hardware timer (unused) */ |
| 3173 | sky2_write8(hw, B2_TI_CTRL, TIM_STOP); |
| 3174 | sky2_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3175 | |
Stephen Hemminger | 69634ee | 2005-12-09 11:35:06 -0800 | [diff] [blame] | 3176 | /* Turn off descriptor polling */ |
| 3177 | sky2_write32(hw, B28_DPT_CTRL, DPT_STOP); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3178 | |
| 3179 | /* Turn off receive timestamp */ |
| 3180 | sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_STOP); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3181 | sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3182 | |
| 3183 | /* enable the Tx Arbiters */ |
| 3184 | for (i = 0; i < hw->ports; i++) |
| 3185 | sky2_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB); |
| 3186 | |
| 3187 | /* Initialize ram interface */ |
| 3188 | for (i = 0; i < hw->ports; i++) { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3189 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_CTRL), RI_RST_CLR); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3190 | |
| 3191 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R1), SK_RI_TO_53); |
| 3192 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA1), SK_RI_TO_53); |
| 3193 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS1), SK_RI_TO_53); |
| 3194 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R1), SK_RI_TO_53); |
| 3195 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA1), SK_RI_TO_53); |
| 3196 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS1), SK_RI_TO_53); |
| 3197 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R2), SK_RI_TO_53); |
| 3198 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA2), SK_RI_TO_53); |
| 3199 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS2), SK_RI_TO_53); |
| 3200 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R2), SK_RI_TO_53); |
| 3201 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA2), SK_RI_TO_53); |
| 3202 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS2), SK_RI_TO_53); |
| 3203 | } |
| 3204 | |
Stephen Hemminger | 555382c | 2007-08-29 12:58:14 -0700 | [diff] [blame] | 3205 | sky2_write32(hw, B0_HWE_IMSK, hwe_mask); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3206 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3207 | for (i = 0; i < hw->ports; i++) |
shemminger@osdl.org | d3bcfbe | 2006-08-28 10:00:51 -0700 | [diff] [blame] | 3208 | sky2_gmac_reset(hw, i); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3209 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3210 | memset(hw->st_le, 0, STATUS_LE_BYTES); |
| 3211 | hw->st_idx = 0; |
| 3212 | |
| 3213 | sky2_write32(hw, STAT_CTRL, SC_STAT_RST_SET); |
| 3214 | sky2_write32(hw, STAT_CTRL, SC_STAT_RST_CLR); |
| 3215 | |
| 3216 | sky2_write32(hw, STAT_LIST_ADDR_LO, hw->st_dma); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3217 | sky2_write32(hw, STAT_LIST_ADDR_HI, (u64) hw->st_dma >> 32); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3218 | |
| 3219 | /* Set the list last index */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3220 | sky2_write16(hw, STAT_LAST_IDX, STATUS_RING_SIZE - 1); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3221 | |
Stephen Hemminger | 290d4de | 2006-03-20 15:48:15 -0800 | [diff] [blame] | 3222 | sky2_write16(hw, STAT_TX_IDX_TH, 10); |
| 3223 | sky2_write8(hw, STAT_FIFO_WM, 16); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3224 | |
Stephen Hemminger | 290d4de | 2006-03-20 15:48:15 -0800 | [diff] [blame] | 3225 | /* set Status-FIFO ISR watermark */ |
| 3226 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0) |
| 3227 | sky2_write8(hw, STAT_FIFO_ISR_WM, 4); |
| 3228 | else |
| 3229 | sky2_write8(hw, STAT_FIFO_ISR_WM, 16); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3230 | |
Stephen Hemminger | 290d4de | 2006-03-20 15:48:15 -0800 | [diff] [blame] | 3231 | sky2_write32(hw, STAT_TX_TIMER_INI, sky2_us2clk(hw, 1000)); |
Stephen Hemminger | 77b3d6a | 2006-03-20 15:48:18 -0800 | [diff] [blame] | 3232 | sky2_write32(hw, STAT_ISR_TIMER_INI, sky2_us2clk(hw, 20)); |
| 3233 | sky2_write32(hw, STAT_LEV_TIMER_INI, sky2_us2clk(hw, 100)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3234 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3235 | /* enable status unit */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3236 | sky2_write32(hw, STAT_CTRL, SC_STAT_OP_ON); |
| 3237 | |
| 3238 | sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START); |
| 3239 | sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START); |
| 3240 | sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START); |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 3241 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3242 | |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 3243 | /* Take device down (offline). |
| 3244 | * Equivalent to doing dev_stop() but this does not |
| 3245 | * inform upper layers of the transistion. |
| 3246 | */ |
| 3247 | static void sky2_detach(struct net_device *dev) |
| 3248 | { |
| 3249 | if (netif_running(dev)) { |
Mike McCormack | c36531b | 2009-12-31 00:55:31 +0000 | [diff] [blame] | 3250 | netif_tx_lock(dev); |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 3251 | netif_device_detach(dev); /* stop txq */ |
Mike McCormack | c36531b | 2009-12-31 00:55:31 +0000 | [diff] [blame] | 3252 | netif_tx_unlock(dev); |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 3253 | sky2_down(dev); |
| 3254 | } |
| 3255 | } |
| 3256 | |
| 3257 | /* Bring device back after doing sky2_detach */ |
| 3258 | static int sky2_reattach(struct net_device *dev) |
| 3259 | { |
| 3260 | int err = 0; |
| 3261 | |
| 3262 | if (netif_running(dev)) { |
| 3263 | err = sky2_up(dev); |
| 3264 | if (err) { |
| 3265 | printk(KERN_INFO PFX "%s: could not restart %d\n", |
| 3266 | dev->name, err); |
| 3267 | dev_close(dev); |
| 3268 | } else { |
| 3269 | netif_device_attach(dev); |
| 3270 | sky2_set_multicast(dev); |
| 3271 | } |
| 3272 | } |
| 3273 | |
| 3274 | return err; |
| 3275 | } |
| 3276 | |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 3277 | static void sky2_restart(struct work_struct *work) |
| 3278 | { |
| 3279 | struct sky2_hw *hw = container_of(work, struct sky2_hw, restart_work); |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 3280 | int i; |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 3281 | |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 3282 | rtnl_lock(); |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 3283 | for (i = 0; i < hw->ports; i++) |
| 3284 | sky2_detach(hw->dev[i]); |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 3285 | |
Stephen Hemminger | 8cfcbe9 | 2007-12-03 17:02:17 -0800 | [diff] [blame] | 3286 | napi_disable(&hw->napi); |
| 3287 | sky2_write32(hw, B0_IMSK, 0); |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 3288 | sky2_reset(hw); |
| 3289 | sky2_write32(hw, B0_IMSK, Y2_IS_BASE); |
Stephen Hemminger | 6de1623 | 2007-10-17 13:26:42 -0700 | [diff] [blame] | 3290 | napi_enable(&hw->napi); |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 3291 | |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 3292 | for (i = 0; i < hw->ports; i++) |
| 3293 | sky2_reattach(hw->dev[i]); |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 3294 | |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 3295 | rtnl_unlock(); |
| 3296 | } |
| 3297 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 3298 | static inline u8 sky2_wol_supported(const struct sky2_hw *hw) |
| 3299 | { |
| 3300 | return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0; |
| 3301 | } |
| 3302 | |
| 3303 | static void sky2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 3304 | { |
| 3305 | const struct sky2_port *sky2 = netdev_priv(dev); |
| 3306 | |
| 3307 | wol->supported = sky2_wol_supported(sky2->hw); |
| 3308 | wol->wolopts = sky2->wol; |
| 3309 | } |
| 3310 | |
| 3311 | static int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 3312 | { |
| 3313 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3314 | struct sky2_hw *hw = sky2->hw; |
| 3315 | |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 3316 | if ((wol->wolopts & ~sky2_wol_supported(sky2->hw)) || |
| 3317 | !device_can_wakeup(&hw->pdev->dev)) |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 3318 | return -EOPNOTSUPP; |
| 3319 | |
| 3320 | sky2->wol = wol->wolopts; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3321 | return 0; |
| 3322 | } |
| 3323 | |
Stephen Hemminger | 28bd181 | 2006-01-17 13:43:19 -0800 | [diff] [blame] | 3324 | static u32 sky2_supported_modes(const struct sky2_hw *hw) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3325 | { |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 3326 | if (sky2_is_copper(hw)) { |
| 3327 | u32 modes = SUPPORTED_10baseT_Half |
| 3328 | | SUPPORTED_10baseT_Full |
| 3329 | | SUPPORTED_100baseT_Half |
| 3330 | | SUPPORTED_100baseT_Full |
| 3331 | | SUPPORTED_Autoneg | SUPPORTED_TP; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3332 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 3333 | if (hw->flags & SKY2_HW_GIGABIT) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3334 | modes |= SUPPORTED_1000baseT_Half |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 3335 | | SUPPORTED_1000baseT_Full; |
| 3336 | return modes; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3337 | } else |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 3338 | return SUPPORTED_1000baseT_Half |
| 3339 | | SUPPORTED_1000baseT_Full |
| 3340 | | SUPPORTED_Autoneg |
| 3341 | | SUPPORTED_FIBRE; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3342 | } |
| 3343 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3344 | static int sky2_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3345 | { |
| 3346 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3347 | struct sky2_hw *hw = sky2->hw; |
| 3348 | |
| 3349 | ecmd->transceiver = XCVR_INTERNAL; |
| 3350 | ecmd->supported = sky2_supported_modes(hw); |
| 3351 | ecmd->phy_address = PHY_ADDR_MARV; |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 3352 | if (sky2_is_copper(hw)) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3353 | ecmd->port = PORT_TP; |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 3354 | ecmd->speed = sky2->speed; |
| 3355 | } else { |
| 3356 | ecmd->speed = SPEED_1000; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3357 | ecmd->port = PORT_FIBRE; |
Stephen Hemminger | b89165f | 2006-09-06 12:44:53 -0700 | [diff] [blame] | 3358 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3359 | |
| 3360 | ecmd->advertising = sky2->advertising; |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 3361 | ecmd->autoneg = (sky2->flags & SKY2_FLAG_AUTO_SPEED) |
| 3362 | ? AUTONEG_ENABLE : AUTONEG_DISABLE; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3363 | ecmd->duplex = sky2->duplex; |
| 3364 | return 0; |
| 3365 | } |
| 3366 | |
| 3367 | static int sky2_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 3368 | { |
| 3369 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3370 | const struct sky2_hw *hw = sky2->hw; |
| 3371 | u32 supported = sky2_supported_modes(hw); |
| 3372 | |
| 3373 | if (ecmd->autoneg == AUTONEG_ENABLE) { |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 3374 | sky2->flags |= SKY2_FLAG_AUTO_SPEED; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3375 | ecmd->advertising = supported; |
| 3376 | sky2->duplex = -1; |
| 3377 | sky2->speed = -1; |
| 3378 | } else { |
| 3379 | u32 setting; |
| 3380 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3381 | switch (ecmd->speed) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3382 | case SPEED_1000: |
| 3383 | if (ecmd->duplex == DUPLEX_FULL) |
| 3384 | setting = SUPPORTED_1000baseT_Full; |
| 3385 | else if (ecmd->duplex == DUPLEX_HALF) |
| 3386 | setting = SUPPORTED_1000baseT_Half; |
| 3387 | else |
| 3388 | return -EINVAL; |
| 3389 | break; |
| 3390 | case SPEED_100: |
| 3391 | if (ecmd->duplex == DUPLEX_FULL) |
| 3392 | setting = SUPPORTED_100baseT_Full; |
| 3393 | else if (ecmd->duplex == DUPLEX_HALF) |
| 3394 | setting = SUPPORTED_100baseT_Half; |
| 3395 | else |
| 3396 | return -EINVAL; |
| 3397 | break; |
| 3398 | |
| 3399 | case SPEED_10: |
| 3400 | if (ecmd->duplex == DUPLEX_FULL) |
| 3401 | setting = SUPPORTED_10baseT_Full; |
| 3402 | else if (ecmd->duplex == DUPLEX_HALF) |
| 3403 | setting = SUPPORTED_10baseT_Half; |
| 3404 | else |
| 3405 | return -EINVAL; |
| 3406 | break; |
| 3407 | default: |
| 3408 | return -EINVAL; |
| 3409 | } |
| 3410 | |
| 3411 | if ((setting & supported) == 0) |
| 3412 | return -EINVAL; |
| 3413 | |
| 3414 | sky2->speed = ecmd->speed; |
| 3415 | sky2->duplex = ecmd->duplex; |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 3416 | sky2->flags &= ~SKY2_FLAG_AUTO_SPEED; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3417 | } |
| 3418 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3419 | sky2->advertising = ecmd->advertising; |
| 3420 | |
Stephen Hemminger | d1b139c | 2007-09-05 16:56:19 +0100 | [diff] [blame] | 3421 | if (netif_running(dev)) { |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 3422 | sky2_phy_reinit(sky2); |
Stephen Hemminger | d1b139c | 2007-09-05 16:56:19 +0100 | [diff] [blame] | 3423 | sky2_set_multicast(dev); |
| 3424 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3425 | |
| 3426 | return 0; |
| 3427 | } |
| 3428 | |
| 3429 | static void sky2_get_drvinfo(struct net_device *dev, |
| 3430 | struct ethtool_drvinfo *info) |
| 3431 | { |
| 3432 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3433 | |
| 3434 | strcpy(info->driver, DRV_NAME); |
| 3435 | strcpy(info->version, DRV_VERSION); |
| 3436 | strcpy(info->fw_version, "N/A"); |
| 3437 | strcpy(info->bus_info, pci_name(sky2->hw->pdev)); |
| 3438 | } |
| 3439 | |
| 3440 | static const struct sky2_stat { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3441 | char name[ETH_GSTRING_LEN]; |
| 3442 | u16 offset; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3443 | } sky2_stats[] = { |
| 3444 | { "tx_bytes", GM_TXO_OK_HI }, |
| 3445 | { "rx_bytes", GM_RXO_OK_HI }, |
| 3446 | { "tx_broadcast", GM_TXF_BC_OK }, |
| 3447 | { "rx_broadcast", GM_RXF_BC_OK }, |
| 3448 | { "tx_multicast", GM_TXF_MC_OK }, |
| 3449 | { "rx_multicast", GM_RXF_MC_OK }, |
| 3450 | { "tx_unicast", GM_TXF_UC_OK }, |
| 3451 | { "rx_unicast", GM_RXF_UC_OK }, |
| 3452 | { "tx_mac_pause", GM_TXF_MPAUSE }, |
| 3453 | { "rx_mac_pause", GM_RXF_MPAUSE }, |
Stephen Hemminger | eadfa7d | 2006-03-22 10:38:45 -0800 | [diff] [blame] | 3454 | { "collisions", GM_TXF_COL }, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3455 | { "late_collision",GM_TXF_LAT_COL }, |
| 3456 | { "aborted", GM_TXF_ABO_COL }, |
Stephen Hemminger | eadfa7d | 2006-03-22 10:38:45 -0800 | [diff] [blame] | 3457 | { "single_collisions", GM_TXF_SNG_COL }, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3458 | { "multi_collisions", GM_TXF_MUL_COL }, |
Stephen Hemminger | eadfa7d | 2006-03-22 10:38:45 -0800 | [diff] [blame] | 3459 | |
Stephen Hemminger | d260454 | 2006-03-23 08:51:36 -0800 | [diff] [blame] | 3460 | { "rx_short", GM_RXF_SHT }, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3461 | { "rx_runt", GM_RXE_FRAG }, |
Stephen Hemminger | eadfa7d | 2006-03-22 10:38:45 -0800 | [diff] [blame] | 3462 | { "rx_64_byte_packets", GM_RXF_64B }, |
| 3463 | { "rx_65_to_127_byte_packets", GM_RXF_127B }, |
| 3464 | { "rx_128_to_255_byte_packets", GM_RXF_255B }, |
| 3465 | { "rx_256_to_511_byte_packets", GM_RXF_511B }, |
| 3466 | { "rx_512_to_1023_byte_packets", GM_RXF_1023B }, |
| 3467 | { "rx_1024_to_1518_byte_packets", GM_RXF_1518B }, |
| 3468 | { "rx_1518_to_max_byte_packets", GM_RXF_MAX_SZ }, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3469 | { "rx_too_long", GM_RXF_LNG_ERR }, |
Stephen Hemminger | eadfa7d | 2006-03-22 10:38:45 -0800 | [diff] [blame] | 3470 | { "rx_fifo_overflow", GM_RXE_FIFO_OV }, |
| 3471 | { "rx_jabber", GM_RXF_JAB_PKT }, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3472 | { "rx_fcs_error", GM_RXF_FCS_ERR }, |
Stephen Hemminger | eadfa7d | 2006-03-22 10:38:45 -0800 | [diff] [blame] | 3473 | |
| 3474 | { "tx_64_byte_packets", GM_TXF_64B }, |
| 3475 | { "tx_65_to_127_byte_packets", GM_TXF_127B }, |
| 3476 | { "tx_128_to_255_byte_packets", GM_TXF_255B }, |
| 3477 | { "tx_256_to_511_byte_packets", GM_TXF_511B }, |
| 3478 | { "tx_512_to_1023_byte_packets", GM_TXF_1023B }, |
| 3479 | { "tx_1024_to_1518_byte_packets", GM_TXF_1518B }, |
| 3480 | { "tx_1519_to_max_byte_packets", GM_TXF_MAX_SZ }, |
| 3481 | { "tx_fifo_underrun", GM_TXE_FIFO_UR }, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3482 | }; |
| 3483 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3484 | static u32 sky2_get_rx_csum(struct net_device *dev) |
| 3485 | { |
| 3486 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3487 | |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 3488 | return !!(sky2->flags & SKY2_FLAG_RX_CHECKSUM); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3489 | } |
| 3490 | |
| 3491 | static int sky2_set_rx_csum(struct net_device *dev, u32 data) |
| 3492 | { |
| 3493 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3494 | |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 3495 | if (data) |
| 3496 | sky2->flags |= SKY2_FLAG_RX_CHECKSUM; |
| 3497 | else |
| 3498 | sky2->flags &= ~SKY2_FLAG_RX_CHECKSUM; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3499 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3500 | sky2_write32(sky2->hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR), |
| 3501 | data ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM); |
| 3502 | |
| 3503 | return 0; |
| 3504 | } |
| 3505 | |
| 3506 | static u32 sky2_get_msglevel(struct net_device *netdev) |
| 3507 | { |
| 3508 | struct sky2_port *sky2 = netdev_priv(netdev); |
| 3509 | return sky2->msg_enable; |
| 3510 | } |
| 3511 | |
Stephen Hemminger | 9a7ae0a | 2005-09-27 15:28:42 -0700 | [diff] [blame] | 3512 | static int sky2_nway_reset(struct net_device *dev) |
| 3513 | { |
| 3514 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 9a7ae0a | 2005-09-27 15:28:42 -0700 | [diff] [blame] | 3515 | |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 3516 | if (!netif_running(dev) || !(sky2->flags & SKY2_FLAG_AUTO_SPEED)) |
Stephen Hemminger | 9a7ae0a | 2005-09-27 15:28:42 -0700 | [diff] [blame] | 3517 | return -EINVAL; |
| 3518 | |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 3519 | sky2_phy_reinit(sky2); |
Stephen Hemminger | d1b139c | 2007-09-05 16:56:19 +0100 | [diff] [blame] | 3520 | sky2_set_multicast(dev); |
Stephen Hemminger | 9a7ae0a | 2005-09-27 15:28:42 -0700 | [diff] [blame] | 3521 | |
| 3522 | return 0; |
| 3523 | } |
| 3524 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3525 | static void sky2_phy_stats(struct sky2_port *sky2, u64 * data, unsigned count) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3526 | { |
| 3527 | struct sky2_hw *hw = sky2->hw; |
| 3528 | unsigned port = sky2->port; |
| 3529 | int i; |
| 3530 | |
| 3531 | data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32 |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3532 | | (u64) gma_read32(hw, port, GM_TXO_OK_LO); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3533 | data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32 |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3534 | | (u64) gma_read32(hw, port, GM_RXO_OK_LO); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3535 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3536 | for (i = 2; i < count; i++) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3537 | data[i] = (u64) gma_read32(hw, port, sky2_stats[i].offset); |
| 3538 | } |
| 3539 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3540 | static void sky2_set_msglevel(struct net_device *netdev, u32 value) |
| 3541 | { |
| 3542 | struct sky2_port *sky2 = netdev_priv(netdev); |
| 3543 | sky2->msg_enable = value; |
| 3544 | } |
| 3545 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 3546 | static int sky2_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3547 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 3548 | switch (sset) { |
| 3549 | case ETH_SS_STATS: |
| 3550 | return ARRAY_SIZE(sky2_stats); |
| 3551 | default: |
| 3552 | return -EOPNOTSUPP; |
| 3553 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | static void sky2_get_ethtool_stats(struct net_device *dev, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3557 | struct ethtool_stats *stats, u64 * data) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3558 | { |
| 3559 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3560 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3561 | sky2_phy_stats(sky2, data, ARRAY_SIZE(sky2_stats)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3562 | } |
| 3563 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3564 | static void sky2_get_strings(struct net_device *dev, u32 stringset, u8 * data) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3565 | { |
| 3566 | int i; |
| 3567 | |
| 3568 | switch (stringset) { |
| 3569 | case ETH_SS_STATS: |
| 3570 | for (i = 0; i < ARRAY_SIZE(sky2_stats); i++) |
| 3571 | memcpy(data + i * ETH_GSTRING_LEN, |
| 3572 | sky2_stats[i].name, ETH_GSTRING_LEN); |
| 3573 | break; |
| 3574 | } |
| 3575 | } |
| 3576 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3577 | static int sky2_set_mac_address(struct net_device *dev, void *p) |
| 3578 | { |
| 3579 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | a8ab1ec | 2006-01-30 11:37:57 -0800 | [diff] [blame] | 3580 | struct sky2_hw *hw = sky2->hw; |
| 3581 | unsigned port = sky2->port; |
| 3582 | const struct sockaddr *addr = p; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3583 | |
| 3584 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3585 | return -EADDRNOTAVAIL; |
| 3586 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3587 | memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); |
Stephen Hemminger | a8ab1ec | 2006-01-30 11:37:57 -0800 | [diff] [blame] | 3588 | memcpy_toio(hw->regs + B2_MAC_1 + port * 8, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3589 | dev->dev_addr, ETH_ALEN); |
Stephen Hemminger | a8ab1ec | 2006-01-30 11:37:57 -0800 | [diff] [blame] | 3590 | memcpy_toio(hw->regs + B2_MAC_2 + port * 8, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3591 | dev->dev_addr, ETH_ALEN); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 3592 | |
Stephen Hemminger | a8ab1ec | 2006-01-30 11:37:57 -0800 | [diff] [blame] | 3593 | /* virtual address for data */ |
| 3594 | gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr); |
| 3595 | |
| 3596 | /* physical address: used for pause frames */ |
| 3597 | gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr); |
Stephen Hemminger | 1b53756 | 2005-12-20 15:08:07 -0800 | [diff] [blame] | 3598 | |
| 3599 | return 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3600 | } |
| 3601 | |
Stephen Hemminger | a052b52 | 2006-10-17 10:24:23 -0700 | [diff] [blame] | 3602 | static void inline sky2_add_filter(u8 filter[8], const u8 *addr) |
| 3603 | { |
| 3604 | u32 bit; |
| 3605 | |
| 3606 | bit = ether_crc(ETH_ALEN, addr) & 63; |
| 3607 | filter[bit >> 3] |= 1 << (bit & 7); |
| 3608 | } |
| 3609 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3610 | static void sky2_set_multicast(struct net_device *dev) |
| 3611 | { |
| 3612 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3613 | struct sky2_hw *hw = sky2->hw; |
| 3614 | unsigned port = sky2->port; |
| 3615 | struct dev_mc_list *list = dev->mc_list; |
| 3616 | u16 reg; |
| 3617 | u8 filter[8]; |
Stephen Hemminger | a052b52 | 2006-10-17 10:24:23 -0700 | [diff] [blame] | 3618 | int rx_pause; |
| 3619 | static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 }; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3620 | |
Stephen Hemminger | a052b52 | 2006-10-17 10:24:23 -0700 | [diff] [blame] | 3621 | rx_pause = (sky2->flow_status == FC_RX || sky2->flow_status == FC_BOTH); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3622 | memset(filter, 0, sizeof(filter)); |
| 3623 | |
| 3624 | reg = gma_read16(hw, port, GM_RX_CTRL); |
| 3625 | reg |= GM_RXCR_UCF_ENA; |
| 3626 | |
shemminger@osdl.org | d571b69 | 2005-10-26 12:16:09 -0700 | [diff] [blame] | 3627 | if (dev->flags & IFF_PROMISC) /* promiscuous */ |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3628 | reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); |
Stephen Hemminger | a052b52 | 2006-10-17 10:24:23 -0700 | [diff] [blame] | 3629 | else if (dev->flags & IFF_ALLMULTI) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3630 | memset(filter, 0xff, sizeof(filter)); |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 3631 | else if (netdev_mc_empty(dev) && !rx_pause) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3632 | reg &= ~GM_RXCR_MCF_ENA; |
| 3633 | else { |
| 3634 | int i; |
| 3635 | reg |= GM_RXCR_MCF_ENA; |
| 3636 | |
Stephen Hemminger | a052b52 | 2006-10-17 10:24:23 -0700 | [diff] [blame] | 3637 | if (rx_pause) |
| 3638 | sky2_add_filter(filter, pause_mc_addr); |
| 3639 | |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 3640 | for (i = 0; list && i < netdev_mc_count(dev); i++, list = list->next) |
Stephen Hemminger | a052b52 | 2006-10-17 10:24:23 -0700 | [diff] [blame] | 3641 | sky2_add_filter(filter, list->dmi_addr); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3642 | } |
| 3643 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3644 | gma_write16(hw, port, GM_MC_ADDR_H1, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3645 | (u16) filter[0] | ((u16) filter[1] << 8)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3646 | gma_write16(hw, port, GM_MC_ADDR_H2, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3647 | (u16) filter[2] | ((u16) filter[3] << 8)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3648 | gma_write16(hw, port, GM_MC_ADDR_H3, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3649 | (u16) filter[4] | ((u16) filter[5] << 8)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3650 | gma_write16(hw, port, GM_MC_ADDR_H4, |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3651 | (u16) filter[6] | ((u16) filter[7] << 8)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3652 | |
| 3653 | gma_write16(hw, port, GM_RX_CTRL, reg); |
| 3654 | } |
| 3655 | |
| 3656 | /* Can have one global because blinking is controlled by |
| 3657 | * ethtool and that is always under RTNL mutex |
| 3658 | */ |
Stephen Hemminger | a84d0a3 | 2008-02-22 16:00:33 -0800 | [diff] [blame] | 3659 | static void sky2_led(struct sky2_port *sky2, enum led_mode mode) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3660 | { |
Stephen Hemminger | a84d0a3 | 2008-02-22 16:00:33 -0800 | [diff] [blame] | 3661 | struct sky2_hw *hw = sky2->hw; |
| 3662 | unsigned port = sky2->port; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3663 | |
Stephen Hemminger | a84d0a3 | 2008-02-22 16:00:33 -0800 | [diff] [blame] | 3664 | spin_lock_bh(&sky2->phy_lock); |
| 3665 | if (hw->chip_id == CHIP_ID_YUKON_EC_U || |
| 3666 | hw->chip_id == CHIP_ID_YUKON_EX || |
| 3667 | hw->chip_id == CHIP_ID_YUKON_SUPR) { |
| 3668 | u16 pg; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3669 | pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); |
| 3670 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); |
Stephen Hemminger | a84d0a3 | 2008-02-22 16:00:33 -0800 | [diff] [blame] | 3671 | |
| 3672 | switch (mode) { |
| 3673 | case MO_LED_OFF: |
| 3674 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, |
| 3675 | PHY_M_LEDC_LOS_CTRL(8) | |
| 3676 | PHY_M_LEDC_INIT_CTRL(8) | |
| 3677 | PHY_M_LEDC_STA1_CTRL(8) | |
| 3678 | PHY_M_LEDC_STA0_CTRL(8)); |
| 3679 | break; |
| 3680 | case MO_LED_ON: |
| 3681 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, |
| 3682 | PHY_M_LEDC_LOS_CTRL(9) | |
| 3683 | PHY_M_LEDC_INIT_CTRL(9) | |
| 3684 | PHY_M_LEDC_STA1_CTRL(9) | |
| 3685 | PHY_M_LEDC_STA0_CTRL(9)); |
| 3686 | break; |
| 3687 | case MO_LED_BLINK: |
| 3688 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, |
| 3689 | PHY_M_LEDC_LOS_CTRL(0xa) | |
| 3690 | PHY_M_LEDC_INIT_CTRL(0xa) | |
| 3691 | PHY_M_LEDC_STA1_CTRL(0xa) | |
| 3692 | PHY_M_LEDC_STA0_CTRL(0xa)); |
| 3693 | break; |
| 3694 | case MO_LED_NORM: |
| 3695 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, |
| 3696 | PHY_M_LEDC_LOS_CTRL(1) | |
| 3697 | PHY_M_LEDC_INIT_CTRL(8) | |
| 3698 | PHY_M_LEDC_STA1_CTRL(7) | |
| 3699 | PHY_M_LEDC_STA0_CTRL(7)); |
| 3700 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3701 | |
| 3702 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); |
Stephen Hemminger | a84d0a3 | 2008-02-22 16:00:33 -0800 | [diff] [blame] | 3703 | } else |
Jeff Garzik | 7d2e3cb | 2008-05-13 01:41:58 -0400 | [diff] [blame] | 3704 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, |
Stephen Hemminger | a84d0a3 | 2008-02-22 16:00:33 -0800 | [diff] [blame] | 3705 | PHY_M_LED_MO_DUP(mode) | |
| 3706 | PHY_M_LED_MO_10(mode) | |
| 3707 | PHY_M_LED_MO_100(mode) | |
| 3708 | PHY_M_LED_MO_1000(mode) | |
| 3709 | PHY_M_LED_MO_RX(mode) | |
| 3710 | PHY_M_LED_MO_TX(mode)); |
| 3711 | |
| 3712 | spin_unlock_bh(&sky2->phy_lock); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | /* blink LED's for finding board */ |
| 3716 | static int sky2_phys_id(struct net_device *dev, u32 data) |
| 3717 | { |
| 3718 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | a84d0a3 | 2008-02-22 16:00:33 -0800 | [diff] [blame] | 3719 | unsigned int i; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3720 | |
Stephen Hemminger | a84d0a3 | 2008-02-22 16:00:33 -0800 | [diff] [blame] | 3721 | if (data == 0) |
| 3722 | data = UINT_MAX; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3723 | |
Stephen Hemminger | a84d0a3 | 2008-02-22 16:00:33 -0800 | [diff] [blame] | 3724 | for (i = 0; i < data; i++) { |
| 3725 | sky2_led(sky2, MO_LED_ON); |
| 3726 | if (msleep_interruptible(500)) |
| 3727 | break; |
| 3728 | sky2_led(sky2, MO_LED_OFF); |
| 3729 | if (msleep_interruptible(500)) |
| 3730 | break; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3731 | } |
Stephen Hemminger | a84d0a3 | 2008-02-22 16:00:33 -0800 | [diff] [blame] | 3732 | sky2_led(sky2, MO_LED_NORM); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3733 | |
| 3734 | return 0; |
| 3735 | } |
| 3736 | |
| 3737 | static void sky2_get_pauseparam(struct net_device *dev, |
| 3738 | struct ethtool_pauseparam *ecmd) |
| 3739 | { |
| 3740 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3741 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 3742 | switch (sky2->flow_mode) { |
| 3743 | case FC_NONE: |
| 3744 | ecmd->tx_pause = ecmd->rx_pause = 0; |
| 3745 | break; |
| 3746 | case FC_TX: |
| 3747 | ecmd->tx_pause = 1, ecmd->rx_pause = 0; |
| 3748 | break; |
| 3749 | case FC_RX: |
| 3750 | ecmd->tx_pause = 0, ecmd->rx_pause = 1; |
| 3751 | break; |
| 3752 | case FC_BOTH: |
| 3753 | ecmd->tx_pause = ecmd->rx_pause = 1; |
| 3754 | } |
| 3755 | |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 3756 | ecmd->autoneg = (sky2->flags & SKY2_FLAG_AUTO_PAUSE) |
| 3757 | ? AUTONEG_ENABLE : AUTONEG_DISABLE; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | static int sky2_set_pauseparam(struct net_device *dev, |
| 3761 | struct ethtool_pauseparam *ecmd) |
| 3762 | { |
| 3763 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3764 | |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 3765 | if (ecmd->autoneg == AUTONEG_ENABLE) |
| 3766 | sky2->flags |= SKY2_FLAG_AUTO_PAUSE; |
| 3767 | else |
| 3768 | sky2->flags &= ~SKY2_FLAG_AUTO_PAUSE; |
| 3769 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 3770 | sky2->flow_mode = sky2_flow(ecmd->rx_pause, ecmd->tx_pause); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3771 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 3772 | if (netif_running(dev)) |
| 3773 | sky2_phy_reinit(sky2); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3774 | |
Stephen Hemminger | 2eaba1a | 2006-09-06 12:44:47 -0700 | [diff] [blame] | 3775 | return 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3776 | } |
| 3777 | |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3778 | static int sky2_get_coalesce(struct net_device *dev, |
| 3779 | struct ethtool_coalesce *ecmd) |
| 3780 | { |
| 3781 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3782 | struct sky2_hw *hw = sky2->hw; |
| 3783 | |
| 3784 | if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_STOP) |
| 3785 | ecmd->tx_coalesce_usecs = 0; |
| 3786 | else { |
| 3787 | u32 clks = sky2_read32(hw, STAT_TX_TIMER_INI); |
| 3788 | ecmd->tx_coalesce_usecs = sky2_clk2us(hw, clks); |
| 3789 | } |
| 3790 | ecmd->tx_max_coalesced_frames = sky2_read16(hw, STAT_TX_IDX_TH); |
| 3791 | |
| 3792 | if (sky2_read8(hw, STAT_LEV_TIMER_CTRL) == TIM_STOP) |
| 3793 | ecmd->rx_coalesce_usecs = 0; |
| 3794 | else { |
| 3795 | u32 clks = sky2_read32(hw, STAT_LEV_TIMER_INI); |
| 3796 | ecmd->rx_coalesce_usecs = sky2_clk2us(hw, clks); |
| 3797 | } |
| 3798 | ecmd->rx_max_coalesced_frames = sky2_read8(hw, STAT_FIFO_WM); |
| 3799 | |
| 3800 | if (sky2_read8(hw, STAT_ISR_TIMER_CTRL) == TIM_STOP) |
| 3801 | ecmd->rx_coalesce_usecs_irq = 0; |
| 3802 | else { |
| 3803 | u32 clks = sky2_read32(hw, STAT_ISR_TIMER_INI); |
| 3804 | ecmd->rx_coalesce_usecs_irq = sky2_clk2us(hw, clks); |
| 3805 | } |
| 3806 | |
| 3807 | ecmd->rx_max_coalesced_frames_irq = sky2_read8(hw, STAT_FIFO_ISR_WM); |
| 3808 | |
| 3809 | return 0; |
| 3810 | } |
| 3811 | |
| 3812 | /* Note: this affect both ports */ |
| 3813 | static int sky2_set_coalesce(struct net_device *dev, |
| 3814 | struct ethtool_coalesce *ecmd) |
| 3815 | { |
| 3816 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3817 | struct sky2_hw *hw = sky2->hw; |
Stephen Hemminger | 77b3d6a | 2006-03-20 15:48:18 -0800 | [diff] [blame] | 3818 | const u32 tmax = sky2_clk2us(hw, 0x0ffffff); |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3819 | |
Stephen Hemminger | 77b3d6a | 2006-03-20 15:48:18 -0800 | [diff] [blame] | 3820 | if (ecmd->tx_coalesce_usecs > tmax || |
| 3821 | ecmd->rx_coalesce_usecs > tmax || |
| 3822 | ecmd->rx_coalesce_usecs_irq > tmax) |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3823 | return -EINVAL; |
| 3824 | |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 3825 | if (ecmd->tx_max_coalesced_frames >= sky2->tx_ring_size-1) |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3826 | return -EINVAL; |
Stephen Hemminger | ff81fbb | 2006-02-22 11:44:59 -0800 | [diff] [blame] | 3827 | if (ecmd->rx_max_coalesced_frames > RX_MAX_PENDING) |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3828 | return -EINVAL; |
Stephen Hemminger | ff81fbb | 2006-02-22 11:44:59 -0800 | [diff] [blame] | 3829 | if (ecmd->rx_max_coalesced_frames_irq >RX_MAX_PENDING) |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3830 | return -EINVAL; |
| 3831 | |
| 3832 | if (ecmd->tx_coalesce_usecs == 0) |
| 3833 | sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP); |
| 3834 | else { |
| 3835 | sky2_write32(hw, STAT_TX_TIMER_INI, |
| 3836 | sky2_us2clk(hw, ecmd->tx_coalesce_usecs)); |
| 3837 | sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START); |
| 3838 | } |
| 3839 | sky2_write16(hw, STAT_TX_IDX_TH, ecmd->tx_max_coalesced_frames); |
| 3840 | |
| 3841 | if (ecmd->rx_coalesce_usecs == 0) |
| 3842 | sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_STOP); |
| 3843 | else { |
| 3844 | sky2_write32(hw, STAT_LEV_TIMER_INI, |
| 3845 | sky2_us2clk(hw, ecmd->rx_coalesce_usecs)); |
| 3846 | sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START); |
| 3847 | } |
| 3848 | sky2_write8(hw, STAT_FIFO_WM, ecmd->rx_max_coalesced_frames); |
| 3849 | |
| 3850 | if (ecmd->rx_coalesce_usecs_irq == 0) |
| 3851 | sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_STOP); |
| 3852 | else { |
Stephen Hemminger | d28d487 | 2006-01-30 11:37:56 -0800 | [diff] [blame] | 3853 | sky2_write32(hw, STAT_ISR_TIMER_INI, |
Stephen Hemminger | fb17358 | 2005-12-09 11:34:56 -0800 | [diff] [blame] | 3854 | sky2_us2clk(hw, ecmd->rx_coalesce_usecs_irq)); |
| 3855 | sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START); |
| 3856 | } |
| 3857 | sky2_write8(hw, STAT_FIFO_ISR_WM, ecmd->rx_max_coalesced_frames_irq); |
| 3858 | return 0; |
| 3859 | } |
| 3860 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3861 | static void sky2_get_ringparam(struct net_device *dev, |
| 3862 | struct ethtool_ringparam *ering) |
| 3863 | { |
| 3864 | struct sky2_port *sky2 = netdev_priv(dev); |
| 3865 | |
| 3866 | ering->rx_max_pending = RX_MAX_PENDING; |
| 3867 | ering->rx_mini_max_pending = 0; |
| 3868 | ering->rx_jumbo_max_pending = 0; |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 3869 | ering->tx_max_pending = TX_MAX_PENDING; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3870 | |
| 3871 | ering->rx_pending = sky2->rx_pending; |
| 3872 | ering->rx_mini_pending = 0; |
| 3873 | ering->rx_jumbo_pending = 0; |
| 3874 | ering->tx_pending = sky2->tx_pending; |
| 3875 | } |
| 3876 | |
| 3877 | static int sky2_set_ringparam(struct net_device *dev, |
| 3878 | struct ethtool_ringparam *ering) |
| 3879 | { |
| 3880 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3881 | |
| 3882 | if (ering->rx_pending > RX_MAX_PENDING || |
| 3883 | ering->rx_pending < 8 || |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 3884 | ering->tx_pending < TX_MIN_PENDING || |
| 3885 | ering->tx_pending > TX_MAX_PENDING) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3886 | return -EINVAL; |
| 3887 | |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 3888 | sky2_detach(dev); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3889 | |
| 3890 | sky2->rx_pending = ering->rx_pending; |
| 3891 | sky2->tx_pending = ering->tx_pending; |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 3892 | sky2->tx_ring_size = roundup_pow_of_two(sky2->tx_pending+1); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3893 | |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 3894 | return sky2_reattach(dev); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3897 | static int sky2_get_regs_len(struct net_device *dev) |
| 3898 | { |
Stephen Hemminger | 6e4cbb3 | 2005-09-19 15:47:57 -0700 | [diff] [blame] | 3899 | return 0x4000; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3900 | } |
| 3901 | |
Mike McCormack | c32bbff | 2009-12-31 00:49:43 +0000 | [diff] [blame] | 3902 | static int sky2_reg_access_ok(struct sky2_hw *hw, unsigned int b) |
| 3903 | { |
| 3904 | /* This complicated switch statement is to make sure and |
| 3905 | * only access regions that are unreserved. |
| 3906 | * Some blocks are only valid on dual port cards. |
| 3907 | */ |
| 3908 | switch (b) { |
| 3909 | /* second port */ |
| 3910 | case 5: /* Tx Arbiter 2 */ |
| 3911 | case 9: /* RX2 */ |
| 3912 | case 14 ... 15: /* TX2 */ |
| 3913 | case 17: case 19: /* Ram Buffer 2 */ |
| 3914 | case 22 ... 23: /* Tx Ram Buffer 2 */ |
| 3915 | case 25: /* Rx MAC Fifo 1 */ |
| 3916 | case 27: /* Tx MAC Fifo 2 */ |
| 3917 | case 31: /* GPHY 2 */ |
| 3918 | case 40 ... 47: /* Pattern Ram 2 */ |
| 3919 | case 52: case 54: /* TCP Segmentation 2 */ |
| 3920 | case 112 ... 116: /* GMAC 2 */ |
| 3921 | return hw->ports > 1; |
| 3922 | |
| 3923 | case 0: /* Control */ |
| 3924 | case 2: /* Mac address */ |
| 3925 | case 4: /* Tx Arbiter 1 */ |
| 3926 | case 7: /* PCI express reg */ |
| 3927 | case 8: /* RX1 */ |
| 3928 | case 12 ... 13: /* TX1 */ |
| 3929 | case 16: case 18:/* Rx Ram Buffer 1 */ |
| 3930 | case 20 ... 21: /* Tx Ram Buffer 1 */ |
| 3931 | case 24: /* Rx MAC Fifo 1 */ |
| 3932 | case 26: /* Tx MAC Fifo 1 */ |
| 3933 | case 28 ... 29: /* Descriptor and status unit */ |
| 3934 | case 30: /* GPHY 1*/ |
| 3935 | case 32 ... 39: /* Pattern Ram 1 */ |
| 3936 | case 48: case 50: /* TCP Segmentation 1 */ |
| 3937 | case 56 ... 60: /* PCI space */ |
| 3938 | case 80 ... 84: /* GMAC 1 */ |
| 3939 | return 1; |
| 3940 | |
| 3941 | default: |
| 3942 | return 0; |
| 3943 | } |
| 3944 | } |
| 3945 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3946 | /* |
| 3947 | * Returns copy of control register region |
Stephen Hemminger | 3ead5db | 2007-06-04 17:23:21 -0700 | [diff] [blame] | 3948 | * Note: ethtool_get_regs always provides full size (16k) buffer |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3949 | */ |
| 3950 | static void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 3951 | void *p) |
| 3952 | { |
| 3953 | const struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3954 | const void __iomem *io = sky2->hw->regs; |
Stephen Hemminger | 295b54c | 2007-10-11 19:47:22 -0700 | [diff] [blame] | 3955 | unsigned int b; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3956 | |
| 3957 | regs->version = 1; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3958 | |
Stephen Hemminger | 295b54c | 2007-10-11 19:47:22 -0700 | [diff] [blame] | 3959 | for (b = 0; b < 128; b++) { |
Mike McCormack | c32bbff | 2009-12-31 00:49:43 +0000 | [diff] [blame] | 3960 | /* skip poisonous diagnostic ram region in block 3 */ |
| 3961 | if (b == 3) |
Stephen Hemminger | 295b54c | 2007-10-11 19:47:22 -0700 | [diff] [blame] | 3962 | memcpy_fromio(p + 0x10, io + 0x10, 128 - 0x10); |
Mike McCormack | c32bbff | 2009-12-31 00:49:43 +0000 | [diff] [blame] | 3963 | else if (sky2_reg_access_ok(sky2->hw, b)) |
Stephen Hemminger | 295b54c | 2007-10-11 19:47:22 -0700 | [diff] [blame] | 3964 | memcpy_fromio(p, io, 128); |
Mike McCormack | c32bbff | 2009-12-31 00:49:43 +0000 | [diff] [blame] | 3965 | else |
Stephen Hemminger | 295b54c | 2007-10-11 19:47:22 -0700 | [diff] [blame] | 3966 | memset(p, 0, 128); |
Stephen Hemminger | 3ead5db | 2007-06-04 17:23:21 -0700 | [diff] [blame] | 3967 | |
Stephen Hemminger | 295b54c | 2007-10-11 19:47:22 -0700 | [diff] [blame] | 3968 | p += 128; |
| 3969 | io += 128; |
| 3970 | } |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 3971 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 3972 | |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 3973 | /* In order to do Jumbo packets on these chips, need to turn off the |
| 3974 | * transmit store/forward. Therefore checksum offload won't work. |
| 3975 | */ |
| 3976 | static int no_tx_offload(struct net_device *dev) |
| 3977 | { |
| 3978 | const struct sky2_port *sky2 = netdev_priv(dev); |
| 3979 | const struct sky2_hw *hw = sky2->hw; |
| 3980 | |
Stephen Hemminger | 6916161 | 2007-06-04 17:23:26 -0700 | [diff] [blame] | 3981 | return dev->mtu > ETH_DATA_LEN && hw->chip_id == CHIP_ID_YUKON_EC_U; |
Stephen Hemminger | b628ed9 | 2007-04-11 14:48:01 -0700 | [diff] [blame] | 3982 | } |
| 3983 | |
| 3984 | static int sky2_set_tx_csum(struct net_device *dev, u32 data) |
| 3985 | { |
| 3986 | if (data && no_tx_offload(dev)) |
| 3987 | return -EINVAL; |
| 3988 | |
| 3989 | return ethtool_op_set_tx_csum(dev, data); |
| 3990 | } |
| 3991 | |
| 3992 | |
| 3993 | static int sky2_set_tso(struct net_device *dev, u32 data) |
| 3994 | { |
| 3995 | if (data && no_tx_offload(dev)) |
| 3996 | return -EINVAL; |
| 3997 | |
| 3998 | return ethtool_op_set_tso(dev, data); |
| 3999 | } |
| 4000 | |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4001 | static int sky2_get_eeprom_len(struct net_device *dev) |
| 4002 | { |
| 4003 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 4004 | struct sky2_hw *hw = sky2->hw; |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4005 | u16 reg2; |
| 4006 | |
Stephen Hemminger | b32f40c | 2007-11-27 10:57:27 -0800 | [diff] [blame] | 4007 | reg2 = sky2_pci_read16(hw, PCI_DEV_REG2); |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4008 | return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8); |
| 4009 | } |
| 4010 | |
Stephen Hemminger | 1413235 | 2008-08-27 20:46:26 -0700 | [diff] [blame] | 4011 | static int sky2_vpd_wait(const struct sky2_hw *hw, int cap, u16 busy) |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4012 | { |
Stephen Hemminger | 1413235 | 2008-08-27 20:46:26 -0700 | [diff] [blame] | 4013 | unsigned long start = jiffies; |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4014 | |
Stephen Hemminger | 1413235 | 2008-08-27 20:46:26 -0700 | [diff] [blame] | 4015 | while ( (sky2_pci_read16(hw, cap + PCI_VPD_ADDR) & PCI_VPD_ADDR_F) == busy) { |
| 4016 | /* Can take up to 10.6 ms for write */ |
| 4017 | if (time_after(jiffies, start + HZ/4)) { |
| 4018 | dev_err(&hw->pdev->dev, PFX "VPD cycle timed out"); |
| 4019 | return -ETIMEDOUT; |
| 4020 | } |
| 4021 | mdelay(1); |
| 4022 | } |
Stephen Hemminger | 167f53d | 2007-09-25 19:01:02 -0700 | [diff] [blame] | 4023 | |
Stephen Hemminger | 1413235 | 2008-08-27 20:46:26 -0700 | [diff] [blame] | 4024 | return 0; |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4025 | } |
| 4026 | |
Stephen Hemminger | 1413235 | 2008-08-27 20:46:26 -0700 | [diff] [blame] | 4027 | static int sky2_vpd_read(struct sky2_hw *hw, int cap, void *data, |
| 4028 | u16 offset, size_t length) |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4029 | { |
Stephen Hemminger | 1413235 | 2008-08-27 20:46:26 -0700 | [diff] [blame] | 4030 | int rc = 0; |
| 4031 | |
| 4032 | while (length > 0) { |
| 4033 | u32 val; |
| 4034 | |
| 4035 | sky2_pci_write16(hw, cap + PCI_VPD_ADDR, offset); |
| 4036 | rc = sky2_vpd_wait(hw, cap, 0); |
| 4037 | if (rc) |
| 4038 | break; |
| 4039 | |
| 4040 | val = sky2_pci_read32(hw, cap + PCI_VPD_DATA); |
| 4041 | |
| 4042 | memcpy(data, &val, min(sizeof(val), length)); |
| 4043 | offset += sizeof(u32); |
| 4044 | data += sizeof(u32); |
| 4045 | length -= sizeof(u32); |
| 4046 | } |
| 4047 | |
| 4048 | return rc; |
| 4049 | } |
| 4050 | |
| 4051 | static int sky2_vpd_write(struct sky2_hw *hw, int cap, const void *data, |
| 4052 | u16 offset, unsigned int length) |
| 4053 | { |
| 4054 | unsigned int i; |
| 4055 | int rc = 0; |
| 4056 | |
| 4057 | for (i = 0; i < length; i += sizeof(u32)) { |
| 4058 | u32 val = *(u32 *)(data + i); |
| 4059 | |
| 4060 | sky2_pci_write32(hw, cap + PCI_VPD_DATA, val); |
| 4061 | sky2_pci_write32(hw, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F); |
| 4062 | |
| 4063 | rc = sky2_vpd_wait(hw, cap, PCI_VPD_ADDR_F); |
| 4064 | if (rc) |
| 4065 | break; |
| 4066 | } |
| 4067 | return rc; |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4068 | } |
| 4069 | |
| 4070 | static int sky2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, |
| 4071 | u8 *data) |
| 4072 | { |
| 4073 | struct sky2_port *sky2 = netdev_priv(dev); |
| 4074 | int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD); |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4075 | |
| 4076 | if (!cap) |
| 4077 | return -EINVAL; |
| 4078 | |
| 4079 | eeprom->magic = SKY2_EEPROM_MAGIC; |
| 4080 | |
Stephen Hemminger | 1413235 | 2008-08-27 20:46:26 -0700 | [diff] [blame] | 4081 | return sky2_vpd_read(sky2->hw, cap, data, eeprom->offset, eeprom->len); |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | static int sky2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, |
| 4085 | u8 *data) |
| 4086 | { |
| 4087 | struct sky2_port *sky2 = netdev_priv(dev); |
| 4088 | int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD); |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4089 | |
| 4090 | if (!cap) |
| 4091 | return -EINVAL; |
| 4092 | |
| 4093 | if (eeprom->magic != SKY2_EEPROM_MAGIC) |
| 4094 | return -EINVAL; |
| 4095 | |
Stephen Hemminger | 1413235 | 2008-08-27 20:46:26 -0700 | [diff] [blame] | 4096 | /* Partial writes not supported */ |
| 4097 | if ((eeprom->offset & 3) || (eeprom->len & 3)) |
| 4098 | return -EINVAL; |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4099 | |
Stephen Hemminger | 1413235 | 2008-08-27 20:46:26 -0700 | [diff] [blame] | 4100 | return sky2_vpd_write(sky2->hw, cap, data, eeprom->offset, eeprom->len); |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 4104 | static const struct ethtool_ops sky2_ethtool_ops = { |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4105 | .get_settings = sky2_get_settings, |
| 4106 | .set_settings = sky2_set_settings, |
| 4107 | .get_drvinfo = sky2_get_drvinfo, |
| 4108 | .get_wol = sky2_get_wol, |
| 4109 | .set_wol = sky2_set_wol, |
| 4110 | .get_msglevel = sky2_get_msglevel, |
| 4111 | .set_msglevel = sky2_set_msglevel, |
| 4112 | .nway_reset = sky2_nway_reset, |
| 4113 | .get_regs_len = sky2_get_regs_len, |
| 4114 | .get_regs = sky2_get_regs, |
| 4115 | .get_link = ethtool_op_get_link, |
| 4116 | .get_eeprom_len = sky2_get_eeprom_len, |
| 4117 | .get_eeprom = sky2_get_eeprom, |
| 4118 | .set_eeprom = sky2_set_eeprom, |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4119 | .set_sg = ethtool_op_set_sg, |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4120 | .set_tx_csum = sky2_set_tx_csum, |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4121 | .set_tso = sky2_set_tso, |
| 4122 | .get_rx_csum = sky2_get_rx_csum, |
| 4123 | .set_rx_csum = sky2_set_rx_csum, |
| 4124 | .get_strings = sky2_get_strings, |
| 4125 | .get_coalesce = sky2_get_coalesce, |
| 4126 | .set_coalesce = sky2_set_coalesce, |
| 4127 | .get_ringparam = sky2_get_ringparam, |
| 4128 | .set_ringparam = sky2_set_ringparam, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4129 | .get_pauseparam = sky2_get_pauseparam, |
| 4130 | .set_pauseparam = sky2_set_pauseparam, |
Stephen Hemminger | f4331a6 | 2007-07-09 15:33:39 -0700 | [diff] [blame] | 4131 | .phys_id = sky2_phys_id, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 4132 | .get_sset_count = sky2_get_sset_count, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4133 | .get_ethtool_stats = sky2_get_ethtool_stats, |
| 4134 | }; |
| 4135 | |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4136 | #ifdef CONFIG_SKY2_DEBUG |
| 4137 | |
| 4138 | static struct dentry *sky2_debug; |
| 4139 | |
Stephen Hemminger | e4c2abe | 2009-02-03 11:27:29 +0000 | [diff] [blame] | 4140 | |
| 4141 | /* |
| 4142 | * Read and parse the first part of Vital Product Data |
| 4143 | */ |
| 4144 | #define VPD_SIZE 128 |
| 4145 | #define VPD_MAGIC 0x82 |
| 4146 | |
| 4147 | static const struct vpd_tag { |
| 4148 | char tag[2]; |
| 4149 | char *label; |
| 4150 | } vpd_tags[] = { |
| 4151 | { "PN", "Part Number" }, |
| 4152 | { "EC", "Engineering Level" }, |
| 4153 | { "MN", "Manufacturer" }, |
| 4154 | { "SN", "Serial Number" }, |
| 4155 | { "YA", "Asset Tag" }, |
| 4156 | { "VL", "First Error Log Message" }, |
| 4157 | { "VF", "Second Error Log Message" }, |
| 4158 | { "VB", "Boot Agent ROM Configuration" }, |
| 4159 | { "VE", "EFI UNDI Configuration" }, |
| 4160 | }; |
| 4161 | |
| 4162 | static void sky2_show_vpd(struct seq_file *seq, struct sky2_hw *hw) |
| 4163 | { |
| 4164 | size_t vpd_size; |
| 4165 | loff_t offs; |
| 4166 | u8 len; |
| 4167 | unsigned char *buf; |
| 4168 | u16 reg2; |
| 4169 | |
| 4170 | reg2 = sky2_pci_read16(hw, PCI_DEV_REG2); |
| 4171 | vpd_size = 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8); |
| 4172 | |
| 4173 | seq_printf(seq, "%s Product Data\n", pci_name(hw->pdev)); |
| 4174 | buf = kmalloc(vpd_size, GFP_KERNEL); |
| 4175 | if (!buf) { |
| 4176 | seq_puts(seq, "no memory!\n"); |
| 4177 | return; |
| 4178 | } |
| 4179 | |
| 4180 | if (pci_read_vpd(hw->pdev, 0, vpd_size, buf) < 0) { |
| 4181 | seq_puts(seq, "VPD read failed\n"); |
| 4182 | goto out; |
| 4183 | } |
| 4184 | |
| 4185 | if (buf[0] != VPD_MAGIC) { |
| 4186 | seq_printf(seq, "VPD tag mismatch: %#x\n", buf[0]); |
| 4187 | goto out; |
| 4188 | } |
| 4189 | len = buf[1]; |
| 4190 | if (len == 0 || len > vpd_size - 4) { |
| 4191 | seq_printf(seq, "Invalid id length: %d\n", len); |
| 4192 | goto out; |
| 4193 | } |
| 4194 | |
| 4195 | seq_printf(seq, "%.*s\n", len, buf + 3); |
| 4196 | offs = len + 3; |
| 4197 | |
| 4198 | while (offs < vpd_size - 4) { |
| 4199 | int i; |
| 4200 | |
| 4201 | if (!memcmp("RW", buf + offs, 2)) /* end marker */ |
| 4202 | break; |
| 4203 | len = buf[offs + 2]; |
| 4204 | if (offs + len + 3 >= vpd_size) |
| 4205 | break; |
| 4206 | |
| 4207 | for (i = 0; i < ARRAY_SIZE(vpd_tags); i++) { |
| 4208 | if (!memcmp(vpd_tags[i].tag, buf + offs, 2)) { |
| 4209 | seq_printf(seq, " %s: %.*s\n", |
| 4210 | vpd_tags[i].label, len, buf + offs + 3); |
| 4211 | break; |
| 4212 | } |
| 4213 | } |
| 4214 | offs += len + 3; |
| 4215 | } |
| 4216 | out: |
| 4217 | kfree(buf); |
| 4218 | } |
| 4219 | |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4220 | static int sky2_debug_show(struct seq_file *seq, void *v) |
| 4221 | { |
| 4222 | struct net_device *dev = seq->private; |
| 4223 | const struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4224 | struct sky2_hw *hw = sky2->hw; |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4225 | unsigned port = sky2->port; |
| 4226 | unsigned idx, last; |
| 4227 | int sop; |
| 4228 | |
Stephen Hemminger | e4c2abe | 2009-02-03 11:27:29 +0000 | [diff] [blame] | 4229 | sky2_show_vpd(seq, hw); |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4230 | |
Stephen Hemminger | e4c2abe | 2009-02-03 11:27:29 +0000 | [diff] [blame] | 4231 | seq_printf(seq, "\nIRQ src=%x mask=%x control=%x\n", |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4232 | sky2_read32(hw, B0_ISRC), |
| 4233 | sky2_read32(hw, B0_IMSK), |
| 4234 | sky2_read32(hw, B0_Y2_SP_ICR)); |
| 4235 | |
Stephen Hemminger | e4c2abe | 2009-02-03 11:27:29 +0000 | [diff] [blame] | 4236 | if (!netif_running(dev)) { |
| 4237 | seq_printf(seq, "network not running\n"); |
| 4238 | return 0; |
| 4239 | } |
| 4240 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4241 | napi_disable(&hw->napi); |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4242 | last = sky2_read16(hw, STAT_PUT_IDX); |
| 4243 | |
| 4244 | if (hw->st_idx == last) |
| 4245 | seq_puts(seq, "Status ring (empty)\n"); |
| 4246 | else { |
| 4247 | seq_puts(seq, "Status ring\n"); |
| 4248 | for (idx = hw->st_idx; idx != last && idx < STATUS_RING_SIZE; |
| 4249 | idx = RING_NEXT(idx, STATUS_RING_SIZE)) { |
| 4250 | const struct sky2_status_le *le = hw->st_le + idx; |
| 4251 | seq_printf(seq, "[%d] %#x %d %#x\n", |
| 4252 | idx, le->opcode, le->length, le->status); |
| 4253 | } |
| 4254 | seq_puts(seq, "\n"); |
| 4255 | } |
| 4256 | |
| 4257 | seq_printf(seq, "Tx ring pending=%u...%u report=%d done=%d\n", |
| 4258 | sky2->tx_cons, sky2->tx_prod, |
| 4259 | sky2_read16(hw, port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX), |
| 4260 | sky2_read16(hw, Q_ADDR(txqaddr[port], Q_DONE))); |
| 4261 | |
| 4262 | /* Dump contents of tx ring */ |
| 4263 | sop = 1; |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 4264 | for (idx = sky2->tx_next; idx != sky2->tx_prod && idx < sky2->tx_ring_size; |
| 4265 | idx = RING_NEXT(idx, sky2->tx_ring_size)) { |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4266 | const struct sky2_tx_le *le = sky2->tx_le + idx; |
| 4267 | u32 a = le32_to_cpu(le->addr); |
| 4268 | |
| 4269 | if (sop) |
| 4270 | seq_printf(seq, "%u:", idx); |
| 4271 | sop = 0; |
| 4272 | |
| 4273 | switch(le->opcode & ~HW_OWNER) { |
| 4274 | case OP_ADDR64: |
| 4275 | seq_printf(seq, " %#x:", a); |
| 4276 | break; |
| 4277 | case OP_LRGLEN: |
| 4278 | seq_printf(seq, " mtu=%d", a); |
| 4279 | break; |
| 4280 | case OP_VLAN: |
| 4281 | seq_printf(seq, " vlan=%d", be16_to_cpu(le->length)); |
| 4282 | break; |
| 4283 | case OP_TCPLISW: |
| 4284 | seq_printf(seq, " csum=%#x", a); |
| 4285 | break; |
| 4286 | case OP_LARGESEND: |
| 4287 | seq_printf(seq, " tso=%#x(%d)", a, le16_to_cpu(le->length)); |
| 4288 | break; |
| 4289 | case OP_PACKET: |
| 4290 | seq_printf(seq, " %#x(%d)", a, le16_to_cpu(le->length)); |
| 4291 | break; |
| 4292 | case OP_BUFFER: |
| 4293 | seq_printf(seq, " frag=%#x(%d)", a, le16_to_cpu(le->length)); |
| 4294 | break; |
| 4295 | default: |
| 4296 | seq_printf(seq, " op=%#x,%#x(%d)", le->opcode, |
| 4297 | a, le16_to_cpu(le->length)); |
| 4298 | } |
| 4299 | |
| 4300 | if (le->ctrl & EOP) { |
| 4301 | seq_putc(seq, '\n'); |
| 4302 | sop = 1; |
| 4303 | } |
| 4304 | } |
| 4305 | |
| 4306 | seq_printf(seq, "\nRx ring hw get=%d put=%d last=%d\n", |
| 4307 | sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_GET_IDX)), |
Mike McCormack | c409c34 | 2009-07-21 14:51:20 +0000 | [diff] [blame] | 4308 | sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_PUT_IDX)), |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4309 | sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_LAST_IDX))); |
| 4310 | |
David S. Miller | d1d08d1 | 2008-01-07 20:53:33 -0800 | [diff] [blame] | 4311 | sky2_read32(hw, B0_Y2_SP_LISR); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4312 | napi_enable(&hw->napi); |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4313 | return 0; |
| 4314 | } |
| 4315 | |
| 4316 | static int sky2_debug_open(struct inode *inode, struct file *file) |
| 4317 | { |
| 4318 | return single_open(file, sky2_debug_show, inode->i_private); |
| 4319 | } |
| 4320 | |
| 4321 | static const struct file_operations sky2_debug_fops = { |
| 4322 | .owner = THIS_MODULE, |
| 4323 | .open = sky2_debug_open, |
| 4324 | .read = seq_read, |
| 4325 | .llseek = seq_lseek, |
| 4326 | .release = single_release, |
| 4327 | }; |
| 4328 | |
| 4329 | /* |
| 4330 | * Use network device events to create/remove/rename |
| 4331 | * debugfs file entries |
| 4332 | */ |
| 4333 | static int sky2_device_event(struct notifier_block *unused, |
| 4334 | unsigned long event, void *ptr) |
| 4335 | { |
| 4336 | struct net_device *dev = ptr; |
Stephen Hemminger | 5b296bc | 2007-08-29 12:58:11 -0700 | [diff] [blame] | 4337 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4338 | |
Stephen Hemminger | 1436b30 | 2008-11-19 21:59:54 -0800 | [diff] [blame] | 4339 | if (dev->netdev_ops->ndo_open != sky2_up || !sky2_debug) |
Stephen Hemminger | 5b296bc | 2007-08-29 12:58:11 -0700 | [diff] [blame] | 4340 | return NOTIFY_DONE; |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4341 | |
Stephen Hemminger | 5b296bc | 2007-08-29 12:58:11 -0700 | [diff] [blame] | 4342 | switch(event) { |
| 4343 | case NETDEV_CHANGENAME: |
| 4344 | if (sky2->debugfs) { |
| 4345 | sky2->debugfs = debugfs_rename(sky2_debug, sky2->debugfs, |
| 4346 | sky2_debug, dev->name); |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4347 | } |
Stephen Hemminger | 5b296bc | 2007-08-29 12:58:11 -0700 | [diff] [blame] | 4348 | break; |
| 4349 | |
| 4350 | case NETDEV_GOING_DOWN: |
| 4351 | if (sky2->debugfs) { |
| 4352 | printk(KERN_DEBUG PFX "%s: remove debugfs\n", |
| 4353 | dev->name); |
| 4354 | debugfs_remove(sky2->debugfs); |
| 4355 | sky2->debugfs = NULL; |
| 4356 | } |
| 4357 | break; |
| 4358 | |
| 4359 | case NETDEV_UP: |
| 4360 | sky2->debugfs = debugfs_create_file(dev->name, S_IRUGO, |
| 4361 | sky2_debug, dev, |
| 4362 | &sky2_debug_fops); |
| 4363 | if (IS_ERR(sky2->debugfs)) |
| 4364 | sky2->debugfs = NULL; |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4365 | } |
| 4366 | |
| 4367 | return NOTIFY_DONE; |
| 4368 | } |
| 4369 | |
| 4370 | static struct notifier_block sky2_notifier = { |
| 4371 | .notifier_call = sky2_device_event, |
| 4372 | }; |
| 4373 | |
| 4374 | |
| 4375 | static __init void sky2_debug_init(void) |
| 4376 | { |
| 4377 | struct dentry *ent; |
| 4378 | |
| 4379 | ent = debugfs_create_dir("sky2", NULL); |
| 4380 | if (!ent || IS_ERR(ent)) |
| 4381 | return; |
| 4382 | |
| 4383 | sky2_debug = ent; |
| 4384 | register_netdevice_notifier(&sky2_notifier); |
| 4385 | } |
| 4386 | |
| 4387 | static __exit void sky2_debug_cleanup(void) |
| 4388 | { |
| 4389 | if (sky2_debug) { |
| 4390 | unregister_netdevice_notifier(&sky2_notifier); |
| 4391 | debugfs_remove(sky2_debug); |
| 4392 | sky2_debug = NULL; |
| 4393 | } |
| 4394 | } |
| 4395 | |
| 4396 | #else |
| 4397 | #define sky2_debug_init() |
| 4398 | #define sky2_debug_cleanup() |
| 4399 | #endif |
| 4400 | |
Stephen Hemminger | 1436b30 | 2008-11-19 21:59:54 -0800 | [diff] [blame] | 4401 | /* Two copies of network device operations to handle special case of |
| 4402 | not allowing netpoll on second port */ |
| 4403 | static const struct net_device_ops sky2_netdev_ops[2] = { |
| 4404 | { |
| 4405 | .ndo_open = sky2_up, |
| 4406 | .ndo_stop = sky2_down, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4407 | .ndo_start_xmit = sky2_xmit_frame, |
Stephen Hemminger | 1436b30 | 2008-11-19 21:59:54 -0800 | [diff] [blame] | 4408 | .ndo_do_ioctl = sky2_ioctl, |
| 4409 | .ndo_validate_addr = eth_validate_addr, |
| 4410 | .ndo_set_mac_address = sky2_set_mac_address, |
| 4411 | .ndo_set_multicast_list = sky2_set_multicast, |
| 4412 | .ndo_change_mtu = sky2_change_mtu, |
| 4413 | .ndo_tx_timeout = sky2_tx_timeout, |
| 4414 | #ifdef SKY2_VLAN_TAG_USED |
| 4415 | .ndo_vlan_rx_register = sky2_vlan_rx_register, |
| 4416 | #endif |
| 4417 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4418 | .ndo_poll_controller = sky2_netpoll, |
| 4419 | #endif |
| 4420 | }, |
| 4421 | { |
| 4422 | .ndo_open = sky2_up, |
| 4423 | .ndo_stop = sky2_down, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4424 | .ndo_start_xmit = sky2_xmit_frame, |
Stephen Hemminger | 1436b30 | 2008-11-19 21:59:54 -0800 | [diff] [blame] | 4425 | .ndo_do_ioctl = sky2_ioctl, |
| 4426 | .ndo_validate_addr = eth_validate_addr, |
| 4427 | .ndo_set_mac_address = sky2_set_mac_address, |
| 4428 | .ndo_set_multicast_list = sky2_set_multicast, |
| 4429 | .ndo_change_mtu = sky2_change_mtu, |
| 4430 | .ndo_tx_timeout = sky2_tx_timeout, |
| 4431 | #ifdef SKY2_VLAN_TAG_USED |
| 4432 | .ndo_vlan_rx_register = sky2_vlan_rx_register, |
| 4433 | #endif |
| 4434 | }, |
| 4435 | }; |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4436 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4437 | /* Initialize network device */ |
| 4438 | static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw, |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4439 | unsigned port, |
Stephen Hemminger | be63a21 | 2008-01-15 11:29:29 -0800 | [diff] [blame] | 4440 | int highmem, int wol) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4441 | { |
| 4442 | struct sky2_port *sky2; |
| 4443 | struct net_device *dev = alloc_etherdev(sizeof(*sky2)); |
| 4444 | |
| 4445 | if (!dev) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 4446 | dev_err(&hw->pdev->dev, "etherdev alloc failed\n"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4447 | return NULL; |
| 4448 | } |
| 4449 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4450 | SET_NETDEV_DEV(dev, &hw->pdev->dev); |
shemminger@osdl.org | ef743d3 | 2005-11-30 11:45:12 -0800 | [diff] [blame] | 4451 | dev->irq = hw->pdev->irq; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4452 | SET_ETHTOOL_OPS(dev, &sky2_ethtool_ops); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4453 | dev->watchdog_timeo = TX_WATCHDOG; |
Stephen Hemminger | 1436b30 | 2008-11-19 21:59:54 -0800 | [diff] [blame] | 4454 | dev->netdev_ops = &sky2_netdev_ops[port]; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4455 | |
| 4456 | sky2 = netdev_priv(dev); |
| 4457 | sky2->netdev = dev; |
| 4458 | sky2->hw = hw; |
| 4459 | sky2->msg_enable = netif_msg_init(debug, default_msg); |
| 4460 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4461 | /* Auto speed and flow control */ |
Stephen Hemminger | 0ea065e | 2009-08-14 15:36:41 -0700 | [diff] [blame] | 4462 | sky2->flags = SKY2_FLAG_AUTO_SPEED | SKY2_FLAG_AUTO_PAUSE; |
| 4463 | if (hw->chip_id != CHIP_ID_YUKON_XL) |
| 4464 | sky2->flags |= SKY2_FLAG_RX_CHECKSUM; |
| 4465 | |
Stephen Hemminger | 16ad91e | 2006-10-17 10:24:13 -0700 | [diff] [blame] | 4466 | sky2->flow_mode = FC_BOTH; |
| 4467 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4468 | sky2->duplex = -1; |
| 4469 | sky2->speed = -1; |
| 4470 | sky2->advertising = sky2_supported_modes(hw); |
Stephen Hemminger | be63a21 | 2008-01-15 11:29:29 -0800 | [diff] [blame] | 4471 | sky2->wol = wol; |
Stephen Hemminger | 75d070c | 2005-12-09 11:35:11 -0800 | [diff] [blame] | 4472 | |
Stephen Hemminger | e07b1aa | 2006-03-20 15:48:17 -0800 | [diff] [blame] | 4473 | spin_lock_init(&sky2->phy_lock); |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 4474 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4475 | sky2->tx_pending = TX_DEF_PENDING; |
Stephen Hemminger | ee5f68f | 2009-08-18 15:17:08 +0000 | [diff] [blame] | 4476 | sky2->tx_ring_size = roundup_pow_of_two(TX_DEF_PENDING+1); |
Stephen Hemminger | 290d4de | 2006-03-20 15:48:15 -0800 | [diff] [blame] | 4477 | sky2->rx_pending = RX_DEF_PENDING; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4478 | |
| 4479 | hw->dev[port] = dev; |
| 4480 | |
| 4481 | sky2->port = port; |
| 4482 | |
Stephen Hemminger | 4a50a87 | 2007-02-06 10:45:41 -0800 | [diff] [blame] | 4483 | dev->features |= NETIF_F_TSO | NETIF_F_IP_CSUM | NETIF_F_SG; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4484 | if (highmem) |
| 4485 | dev->features |= NETIF_F_HIGHDMA; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4486 | |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 4487 | #ifdef SKY2_VLAN_TAG_USED |
Stephen Hemminger | d6c9bc1 | 2007-09-27 12:32:44 -0700 | [diff] [blame] | 4488 | /* The workaround for FE+ status conflicts with VLAN tag detection. */ |
| 4489 | if (!(sky2->hw->chip_id == CHIP_ID_YUKON_FE_P && |
| 4490 | sky2->hw->chip_rev == CHIP_REV_YU_FE2_A0)) { |
| 4491 | dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
Stephen Hemminger | d6c9bc1 | 2007-09-27 12:32:44 -0700 | [diff] [blame] | 4492 | } |
shemminger@osdl.org | d1f1370 | 2005-09-27 15:02:57 -0700 | [diff] [blame] | 4493 | #endif |
| 4494 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4495 | /* read the mac address */ |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4496 | memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8, ETH_ALEN); |
Stephen Hemminger | 2995bfb | 2005-09-28 10:01:03 -0700 | [diff] [blame] | 4497 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4498 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4499 | return dev; |
| 4500 | } |
| 4501 | |
Stephen Hemminger | 28bd181 | 2006-01-17 13:43:19 -0800 | [diff] [blame] | 4502 | static void __devinit sky2_show_addr(struct net_device *dev) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4503 | { |
| 4504 | const struct sky2_port *sky2 = netdev_priv(dev); |
| 4505 | |
| 4506 | if (netif_msg_probe(sky2)) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4507 | printk(KERN_INFO PFX "%s: addr %pM\n", |
| 4508 | dev->name, dev->dev_addr); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4509 | } |
| 4510 | |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4511 | /* Handle software interrupt used during MSI test */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 4512 | static irqreturn_t __devinit sky2_test_intr(int irq, void *dev_id) |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4513 | { |
| 4514 | struct sky2_hw *hw = dev_id; |
| 4515 | u32 status = sky2_read32(hw, B0_Y2_SP_ISRC2); |
| 4516 | |
| 4517 | if (status == 0) |
| 4518 | return IRQ_NONE; |
| 4519 | |
| 4520 | if (status & Y2_IS_IRQ_SW) { |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 4521 | hw->flags |= SKY2_HW_USE_MSI; |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4522 | wake_up(&hw->msi_wait); |
| 4523 | sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ); |
| 4524 | } |
| 4525 | sky2_write32(hw, B0_Y2_SP_ICR, 2); |
| 4526 | |
| 4527 | return IRQ_HANDLED; |
| 4528 | } |
| 4529 | |
| 4530 | /* Test interrupt path by forcing a a software IRQ */ |
| 4531 | static int __devinit sky2_test_msi(struct sky2_hw *hw) |
| 4532 | { |
| 4533 | struct pci_dev *pdev = hw->pdev; |
| 4534 | int err; |
| 4535 | |
shemminger@osdl.org | bb507fe | 2006-08-28 10:00:48 -0700 | [diff] [blame] | 4536 | init_waitqueue_head (&hw->msi_wait); |
| 4537 | |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4538 | sky2_write32(hw, B0_IMSK, Y2_IS_IRQ_SW); |
| 4539 | |
Stephen Hemminger | b0a20de | 2006-12-01 14:29:37 -0800 | [diff] [blame] | 4540 | err = request_irq(pdev->irq, sky2_test_intr, 0, DRV_NAME, hw); |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4541 | if (err) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4542 | dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq); |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4543 | return err; |
| 4544 | } |
| 4545 | |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4546 | sky2_write8(hw, B0_CTST, CS_ST_SW_IRQ); |
shemminger@osdl.org | bb507fe | 2006-08-28 10:00:48 -0700 | [diff] [blame] | 4547 | sky2_read8(hw, B0_CTST); |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4548 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 4549 | wait_event_timeout(hw->msi_wait, (hw->flags & SKY2_HW_USE_MSI), HZ/10); |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4550 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 4551 | if (!(hw->flags & SKY2_HW_USE_MSI)) { |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4552 | /* MSI test failed, go back to INTx mode */ |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4553 | dev_info(&pdev->dev, "No interrupt generated using MSI, " |
| 4554 | "switching to INTx mode.\n"); |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4555 | |
| 4556 | err = -EOPNOTSUPP; |
| 4557 | sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ); |
| 4558 | } |
| 4559 | |
| 4560 | sky2_write32(hw, B0_IMSK, 0); |
Stephen Hemminger | 2bffc23 | 2006-10-17 10:17:18 -0700 | [diff] [blame] | 4561 | sky2_read32(hw, B0_IMSK); |
Stephen Hemminger | fb2690a | 2006-03-20 15:48:19 -0800 | [diff] [blame] | 4562 | |
| 4563 | free_irq(pdev->irq, hw); |
| 4564 | |
| 4565 | return err; |
| 4566 | } |
| 4567 | |
Stephen Hemminger | c7127a3 | 2008-06-17 09:04:25 -0700 | [diff] [blame] | 4568 | /* This driver supports yukon2 chipset only */ |
| 4569 | static const char *sky2_name(u8 chipid, char *buf, int sz) |
| 4570 | { |
| 4571 | const char *name[] = { |
| 4572 | "XL", /* 0xb3 */ |
| 4573 | "EC Ultra", /* 0xb4 */ |
| 4574 | "Extreme", /* 0xb5 */ |
| 4575 | "EC", /* 0xb6 */ |
| 4576 | "FE", /* 0xb7 */ |
| 4577 | "FE+", /* 0xb8 */ |
| 4578 | "Supreme", /* 0xb9 */ |
Stephen Hemminger | 0ce8b98 | 2008-06-17 09:04:27 -0700 | [diff] [blame] | 4579 | "UL 2", /* 0xba */ |
Stephen Hemminger | 0f5aac7 | 2009-10-29 06:37:09 +0000 | [diff] [blame] | 4580 | "Unknown", /* 0xbb */ |
| 4581 | "Optima", /* 0xbc */ |
Stephen Hemminger | c7127a3 | 2008-06-17 09:04:25 -0700 | [diff] [blame] | 4582 | }; |
| 4583 | |
stephen hemminger | dae3a51 | 2009-12-14 08:33:47 +0000 | [diff] [blame] | 4584 | if (chipid >= CHIP_ID_YUKON_XL && chipid <= CHIP_ID_YUKON_OPT) |
Stephen Hemminger | c7127a3 | 2008-06-17 09:04:25 -0700 | [diff] [blame] | 4585 | strncpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz); |
| 4586 | else |
| 4587 | snprintf(buf, sz, "(chip %#x)", chipid); |
| 4588 | return buf; |
| 4589 | } |
| 4590 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4591 | static int __devinit sky2_probe(struct pci_dev *pdev, |
| 4592 | const struct pci_device_id *ent) |
| 4593 | { |
shemminger@linux-foundation.org | 7f60c64 | 2007-01-26 11:38:36 -0800 | [diff] [blame] | 4594 | struct net_device *dev; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4595 | struct sky2_hw *hw; |
Stephen Hemminger | be63a21 | 2008-01-15 11:29:29 -0800 | [diff] [blame] | 4596 | int err, using_dac = 0, wol_default; |
Stephen Hemminger | 3834507 | 2009-02-03 11:27:30 +0000 | [diff] [blame] | 4597 | u32 reg; |
Stephen Hemminger | c7127a3 | 2008-06-17 09:04:25 -0700 | [diff] [blame] | 4598 | char buf1[16]; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4599 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4600 | err = pci_enable_device(pdev); |
| 4601 | if (err) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4602 | dev_err(&pdev->dev, "cannot enable PCI device\n"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4603 | goto err_out; |
| 4604 | } |
| 4605 | |
Stephen Hemminger | 6cc90a5 | 2009-06-11 07:03:47 +0000 | [diff] [blame] | 4606 | /* Get configuration information |
| 4607 | * Note: only regular PCI config access once to test for HW issues |
| 4608 | * other PCI access through shared memory for speed and to |
| 4609 | * avoid MMCONFIG problems. |
| 4610 | */ |
| 4611 | err = pci_read_config_dword(pdev, PCI_DEV_REG2, ®); |
| 4612 | if (err) { |
| 4613 | dev_err(&pdev->dev, "PCI read config failed\n"); |
| 4614 | goto err_out; |
| 4615 | } |
| 4616 | |
| 4617 | if (~reg == 0) { |
| 4618 | dev_err(&pdev->dev, "PCI configuration read error\n"); |
| 4619 | goto err_out; |
| 4620 | } |
| 4621 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4622 | err = pci_request_regions(pdev, DRV_NAME); |
| 4623 | if (err) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4624 | dev_err(&pdev->dev, "cannot obtain PCI resources\n"); |
Stephen Hemminger | 44a1d2e | 2007-04-30 14:23:49 -0700 | [diff] [blame] | 4625 | goto err_out_disable; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4626 | } |
| 4627 | |
| 4628 | pci_set_master(pdev); |
| 4629 | |
Stephen Hemminger | d1f3d4d | 2006-01-17 13:43:11 -0800 | [diff] [blame] | 4630 | if (sizeof(dma_addr_t) > sizeof(u32) && |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 4631 | !(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)))) { |
Stephen Hemminger | d1f3d4d | 2006-01-17 13:43:11 -0800 | [diff] [blame] | 4632 | using_dac = 1; |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 4633 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); |
Stephen Hemminger | d1f3d4d | 2006-01-17 13:43:11 -0800 | [diff] [blame] | 4634 | if (err < 0) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4635 | dev_err(&pdev->dev, "unable to obtain 64 bit DMA " |
| 4636 | "for consistent allocations\n"); |
Stephen Hemminger | d1f3d4d | 2006-01-17 13:43:11 -0800 | [diff] [blame] | 4637 | goto err_out_free_regions; |
| 4638 | } |
Stephen Hemminger | d1f3d4d | 2006-01-17 13:43:11 -0800 | [diff] [blame] | 4639 | } else { |
Yang Hongyang | 284901a9 | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4640 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4641 | if (err) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4642 | dev_err(&pdev->dev, "no usable DMA configuration\n"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4643 | goto err_out_free_regions; |
| 4644 | } |
| 4645 | } |
Stephen Hemminger | d1f3d4d | 2006-01-17 13:43:11 -0800 | [diff] [blame] | 4646 | |
Stephen Hemminger | 3834507 | 2009-02-03 11:27:30 +0000 | [diff] [blame] | 4647 | |
| 4648 | #ifdef __BIG_ENDIAN |
| 4649 | /* The sk98lin vendor driver uses hardware byte swapping but |
| 4650 | * this driver uses software swapping. |
| 4651 | */ |
| 4652 | reg &= ~PCI_REV_DESC; |
| 4653 | err = pci_write_config_dword(pdev,PCI_DEV_REG2, reg); |
| 4654 | if (err) { |
| 4655 | dev_err(&pdev->dev, "PCI write config failed\n"); |
| 4656 | goto err_out_free_regions; |
| 4657 | } |
| 4658 | #endif |
| 4659 | |
Rafael J. Wysocki | 9d731d7 | 2008-10-12 20:59:48 -0700 | [diff] [blame] | 4660 | wol_default = device_may_wakeup(&pdev->dev) ? WAKE_MAGIC : 0; |
Stephen Hemminger | be63a21 | 2008-01-15 11:29:29 -0800 | [diff] [blame] | 4661 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4662 | err = -ENOMEM; |
Stephen Hemminger | 6646679 | 2009-10-01 07:11:46 +0000 | [diff] [blame] | 4663 | |
| 4664 | hw = kzalloc(sizeof(*hw) + strlen(DRV_NAME "@pci:") |
| 4665 | + strlen(pci_name(pdev)) + 1, GFP_KERNEL); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4666 | if (!hw) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4667 | dev_err(&pdev->dev, "cannot allocate hardware struct\n"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4668 | goto err_out_free_regions; |
| 4669 | } |
| 4670 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4671 | hw->pdev = pdev; |
Stephen Hemminger | 6646679 | 2009-10-01 07:11:46 +0000 | [diff] [blame] | 4672 | sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev)); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4673 | |
| 4674 | hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000); |
| 4675 | if (!hw->regs) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4676 | dev_err(&pdev->dev, "cannot map device registers\n"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4677 | goto err_out_free_hw; |
| 4678 | } |
| 4679 | |
Stephen Hemminger | 08c06d8 | 2006-01-30 11:37:54 -0800 | [diff] [blame] | 4680 | /* ring for status responses */ |
Stephen Hemminger | 167f53d | 2007-09-25 19:01:02 -0700 | [diff] [blame] | 4681 | hw->st_le = pci_alloc_consistent(pdev, STATUS_LE_BYTES, &hw->st_dma); |
Stephen Hemminger | 08c06d8 | 2006-01-30 11:37:54 -0800 | [diff] [blame] | 4682 | if (!hw->st_le) |
| 4683 | goto err_out_iounmap; |
| 4684 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4685 | err = sky2_init(hw); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4686 | if (err) |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4687 | goto err_out_iounmap; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4688 | |
Stephen Hemminger | c844d48 | 2008-08-27 20:48:23 -0700 | [diff] [blame] | 4689 | dev_info(&pdev->dev, "Yukon-2 %s chip revision %d\n", |
| 4690 | sky2_name(hw->chip_id, buf1, sizeof(buf1)), hw->chip_rev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4691 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4692 | sky2_reset(hw); |
| 4693 | |
Stephen Hemminger | be63a21 | 2008-01-15 11:29:29 -0800 | [diff] [blame] | 4694 | dev = sky2_init_netdev(hw, 0, using_dac, wol_default); |
shemminger@linux-foundation.org | 7f60c64 | 2007-01-26 11:38:36 -0800 | [diff] [blame] | 4695 | if (!dev) { |
| 4696 | err = -ENOMEM; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4697 | goto err_out_free_pci; |
shemminger@linux-foundation.org | 7f60c64 | 2007-01-26 11:38:36 -0800 | [diff] [blame] | 4698 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4699 | |
Stephen Hemminger | 9fa1b1f | 2006-09-26 11:57:40 -0700 | [diff] [blame] | 4700 | if (!disable_msi && pci_enable_msi(pdev) == 0) { |
| 4701 | err = sky2_test_msi(hw); |
| 4702 | if (err == -EOPNOTSUPP) |
| 4703 | pci_disable_msi(pdev); |
| 4704 | else if (err) |
| 4705 | goto err_out_free_netdev; |
| 4706 | } |
| 4707 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4708 | err = register_netdev(dev); |
| 4709 | if (err) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4710 | dev_err(&pdev->dev, "cannot register net device\n"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4711 | goto err_out_free_netdev; |
| 4712 | } |
| 4713 | |
Brandon Philips | 33cb7d3 | 2009-10-29 13:58:07 +0000 | [diff] [blame] | 4714 | netif_carrier_off(dev); |
| 4715 | |
Stephen Hemminger | 6de1623 | 2007-10-17 13:26:42 -0700 | [diff] [blame] | 4716 | netif_napi_add(dev, &hw->napi, sky2_poll, NAPI_WEIGHT); |
| 4717 | |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 4718 | err = request_irq(pdev->irq, sky2_intr, |
| 4719 | (hw->flags & SKY2_HW_USE_MSI) ? 0 : IRQF_SHARED, |
Stephen Hemminger | 6646679 | 2009-10-01 07:11:46 +0000 | [diff] [blame] | 4720 | hw->irq_name, hw); |
Stephen Hemminger | 9fa1b1f | 2006-09-26 11:57:40 -0700 | [diff] [blame] | 4721 | if (err) { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4722 | dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq); |
Stephen Hemminger | 9fa1b1f | 2006-09-26 11:57:40 -0700 | [diff] [blame] | 4723 | goto err_out_unregister; |
| 4724 | } |
| 4725 | sky2_write32(hw, B0_IMSK, Y2_IS_BASE); |
Stephen Hemminger | 6de1623 | 2007-10-17 13:26:42 -0700 | [diff] [blame] | 4726 | napi_enable(&hw->napi); |
Stephen Hemminger | 9fa1b1f | 2006-09-26 11:57:40 -0700 | [diff] [blame] | 4727 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4728 | sky2_show_addr(dev); |
| 4729 | |
shemminger@linux-foundation.org | 7f60c64 | 2007-01-26 11:38:36 -0800 | [diff] [blame] | 4730 | if (hw->ports > 1) { |
| 4731 | struct net_device *dev1; |
| 4732 | |
Stephen Hemminger | ca51927 | 2009-09-14 06:22:29 +0000 | [diff] [blame] | 4733 | err = -ENOMEM; |
Stephen Hemminger | be63a21 | 2008-01-15 11:29:29 -0800 | [diff] [blame] | 4734 | dev1 = sky2_init_netdev(hw, 1, using_dac, wol_default); |
Stephen Hemminger | ca51927 | 2009-09-14 06:22:29 +0000 | [diff] [blame] | 4735 | if (dev1 && (err = register_netdev(dev1)) == 0) |
| 4736 | sky2_show_addr(dev1); |
| 4737 | else { |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4738 | dev_warn(&pdev->dev, |
| 4739 | "register of second port failed (%d)\n", err); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4740 | hw->dev[1] = NULL; |
Stephen Hemminger | ca51927 | 2009-09-14 06:22:29 +0000 | [diff] [blame] | 4741 | hw->ports = 1; |
| 4742 | if (dev1) |
| 4743 | free_netdev(dev1); |
| 4744 | } |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4745 | } |
| 4746 | |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 4747 | setup_timer(&hw->watchdog_timer, sky2_watchdog, (unsigned long) hw); |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 4748 | INIT_WORK(&hw->restart_work, sky2_restart); |
| 4749 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4750 | pci_set_drvdata(pdev, hw); |
Rafael J. Wysocki | 1ae861e | 2009-12-31 12:15:54 +0100 | [diff] [blame] | 4751 | pdev->d3_delay = 150; |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4752 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4753 | return 0; |
| 4754 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4755 | err_out_unregister: |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 4756 | if (hw->flags & SKY2_HW_USE_MSI) |
Stephen Hemminger | b0a20de | 2006-12-01 14:29:37 -0800 | [diff] [blame] | 4757 | pci_disable_msi(pdev); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4758 | unregister_netdev(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4759 | err_out_free_netdev: |
| 4760 | free_netdev(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4761 | err_out_free_pci: |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4762 | sky2_write8(hw, B0_CTST, CS_RST_SET); |
Stephen Hemminger | 167f53d | 2007-09-25 19:01:02 -0700 | [diff] [blame] | 4763 | pci_free_consistent(pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4764 | err_out_iounmap: |
| 4765 | iounmap(hw->regs); |
| 4766 | err_out_free_hw: |
| 4767 | kfree(hw); |
| 4768 | err_out_free_regions: |
| 4769 | pci_release_regions(pdev); |
Stephen Hemminger | 44a1d2e | 2007-04-30 14:23:49 -0700 | [diff] [blame] | 4770 | err_out_disable: |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4771 | pci_disable_device(pdev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4772 | err_out: |
Stephen Hemminger | 549a68c | 2007-05-11 11:21:44 -0700 | [diff] [blame] | 4773 | pci_set_drvdata(pdev, NULL); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4774 | return err; |
| 4775 | } |
| 4776 | |
| 4777 | static void __devexit sky2_remove(struct pci_dev *pdev) |
| 4778 | { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4779 | struct sky2_hw *hw = pci_get_drvdata(pdev); |
Stephen Hemminger | 6de1623 | 2007-10-17 13:26:42 -0700 | [diff] [blame] | 4780 | int i; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4781 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4782 | if (!hw) |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4783 | return; |
| 4784 | |
Stephen Hemminger | 32c2c30 | 2007-08-21 14:34:03 -0700 | [diff] [blame] | 4785 | del_timer_sync(&hw->watchdog_timer); |
Stephen Hemminger | 6de1623 | 2007-10-17 13:26:42 -0700 | [diff] [blame] | 4786 | cancel_work_sync(&hw->restart_work); |
Stephen Hemminger | d27ed38 | 2006-04-25 10:58:51 -0700 | [diff] [blame] | 4787 | |
Stephen Hemminger | b877fe2 | 2007-10-22 13:39:09 -0700 | [diff] [blame] | 4788 | for (i = hw->ports-1; i >= 0; --i) |
Stephen Hemminger | 6de1623 | 2007-10-17 13:26:42 -0700 | [diff] [blame] | 4789 | unregister_netdev(hw->dev[i]); |
Stephen Hemminger | 8190679 | 2007-02-15 16:40:33 -0800 | [diff] [blame] | 4790 | |
Stephen Hemminger | d27ed38 | 2006-04-25 10:58:51 -0700 | [diff] [blame] | 4791 | sky2_write32(hw, B0_IMSK, 0); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4792 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 4793 | sky2_power_aux(hw); |
| 4794 | |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4795 | sky2_write8(hw, B0_CTST, CS_RST_SET); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 4796 | sky2_read8(hw, B0_CTST); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4797 | |
| 4798 | free_irq(pdev->irq, hw); |
Stephen Hemminger | ea76e63 | 2007-09-19 15:36:44 -0700 | [diff] [blame] | 4799 | if (hw->flags & SKY2_HW_USE_MSI) |
Stephen Hemminger | b0a20de | 2006-12-01 14:29:37 -0800 | [diff] [blame] | 4800 | pci_disable_msi(pdev); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4801 | pci_free_consistent(pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4802 | pci_release_regions(pdev); |
| 4803 | pci_disable_device(pdev); |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4804 | |
Stephen Hemminger | b877fe2 | 2007-10-22 13:39:09 -0700 | [diff] [blame] | 4805 | for (i = hw->ports-1; i >= 0; --i) |
Stephen Hemminger | 6de1623 | 2007-10-17 13:26:42 -0700 | [diff] [blame] | 4806 | free_netdev(hw->dev[i]); |
| 4807 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4808 | iounmap(hw->regs); |
| 4809 | kfree(hw); |
shemminger@osdl.org | 5afa0a9 | 2005-09-27 15:03:00 -0700 | [diff] [blame] | 4810 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4811 | pci_set_drvdata(pdev, NULL); |
| 4812 | } |
| 4813 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4814 | static int sky2_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4815 | { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4816 | struct sky2_hw *hw = pci_get_drvdata(pdev); |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4817 | int i, wol = 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4818 | |
Stephen Hemminger | 549a68c | 2007-05-11 11:21:44 -0700 | [diff] [blame] | 4819 | if (!hw) |
| 4820 | return 0; |
| 4821 | |
Stephen Hemminger | 063a0b3 | 2008-04-02 09:03:23 -0700 | [diff] [blame] | 4822 | del_timer_sync(&hw->watchdog_timer); |
| 4823 | cancel_work_sync(&hw->restart_work); |
| 4824 | |
Stephen Hemminger | 1972073 | 2009-08-14 05:15:16 +0000 | [diff] [blame] | 4825 | rtnl_lock(); |
Stephen Hemminger | f05267e | 2006-06-13 17:17:28 +0900 | [diff] [blame] | 4826 | for (i = 0; i < hw->ports; i++) { |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4827 | struct net_device *dev = hw->dev[i]; |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4828 | struct sky2_port *sky2 = netdev_priv(dev); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4829 | |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 4830 | sky2_detach(dev); |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4831 | |
| 4832 | if (sky2->wol) |
| 4833 | sky2_wol_init(sky2); |
| 4834 | |
| 4835 | wol |= sky2->wol; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4836 | } |
| 4837 | |
stephen hemminger | 5f8ae5c | 2010-02-12 06:57:59 +0000 | [diff] [blame] | 4838 | device_set_wakeup_enable(&pdev->dev, wol != 0); |
| 4839 | |
Stephen Hemminger | 8ab8fca | 2006-06-13 17:17:30 +0900 | [diff] [blame] | 4840 | sky2_write32(hw, B0_IMSK, 0); |
Stephen Hemminger | 6de1623 | 2007-10-17 13:26:42 -0700 | [diff] [blame] | 4841 | napi_disable(&hw->napi); |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 4842 | sky2_power_aux(hw); |
Stephen Hemminger | 1972073 | 2009-08-14 05:15:16 +0000 | [diff] [blame] | 4843 | rtnl_unlock(); |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4844 | |
Linus Torvalds | d374c1c | 2006-06-12 12:53:27 -0700 | [diff] [blame] | 4845 | pci_save_state(pdev); |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4846 | pci_enable_wake(pdev, pci_choose_state(pdev, state), wol); |
Stephen Hemminger | f71eb1a | 2008-08-04 13:33:37 -0700 | [diff] [blame] | 4847 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 4848 | |
Stephen Hemminger | 2ccc99b | 2006-06-13 17:17:27 +0900 | [diff] [blame] | 4849 | return 0; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4850 | } |
| 4851 | |
stephen hemminger | 5f8ae5c | 2010-02-12 06:57:59 +0000 | [diff] [blame] | 4852 | #ifdef CONFIG_PM |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4853 | static int sky2_resume(struct pci_dev *pdev) |
| 4854 | { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4855 | struct sky2_hw *hw = pci_get_drvdata(pdev); |
Stephen Hemminger | 08c06d8 | 2006-01-30 11:37:54 -0800 | [diff] [blame] | 4856 | int i, err; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4857 | |
Stephen Hemminger | 549a68c | 2007-05-11 11:21:44 -0700 | [diff] [blame] | 4858 | if (!hw) |
| 4859 | return 0; |
| 4860 | |
Stephen Hemminger | f71eb1a | 2008-08-04 13:33:37 -0700 | [diff] [blame] | 4861 | err = pci_set_power_state(pdev, PCI_D0); |
| 4862 | if (err) |
| 4863 | goto out; |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 4864 | |
| 4865 | err = pci_restore_state(pdev); |
| 4866 | if (err) |
| 4867 | goto out; |
| 4868 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4869 | pci_enable_wake(pdev, PCI_D0, 0); |
Stephen Hemminger | 1ad5b4a | 2007-04-07 16:02:27 -0700 | [diff] [blame] | 4870 | |
| 4871 | /* Re-enable all clocks */ |
stephen hemminger | a0db28b | 2010-02-07 06:23:53 +0000 | [diff] [blame] | 4872 | err = pci_write_config_dword(pdev, PCI_DEV_REG3, 0); |
| 4873 | if (err) { |
| 4874 | dev_err(&pdev->dev, "PCI write config failed\n"); |
| 4875 | goto out; |
| 4876 | } |
Stephen Hemminger | 1ad5b4a | 2007-04-07 16:02:27 -0700 | [diff] [blame] | 4877 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4878 | sky2_reset(hw); |
Stephen Hemminger | 8ab8fca | 2006-06-13 17:17:30 +0900 | [diff] [blame] | 4879 | sky2_write32(hw, B0_IMSK, Y2_IS_BASE); |
Stephen Hemminger | 6de1623 | 2007-10-17 13:26:42 -0700 | [diff] [blame] | 4880 | napi_enable(&hw->napi); |
Stephen Hemminger | 8ab8fca | 2006-06-13 17:17:30 +0900 | [diff] [blame] | 4881 | |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 4882 | rtnl_lock(); |
Stephen Hemminger | f05267e | 2006-06-13 17:17:28 +0900 | [diff] [blame] | 4883 | for (i = 0; i < hw->ports; i++) { |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 4884 | err = sky2_reattach(hw->dev[i]); |
| 4885 | if (err) |
| 4886 | goto out; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4887 | } |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 4888 | rtnl_unlock(); |
Stephen Hemminger | eb35cf6 | 2006-06-13 17:17:31 +0900 | [diff] [blame] | 4889 | |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 4890 | return 0; |
Stephen Hemminger | 08c06d8 | 2006-01-30 11:37:54 -0800 | [diff] [blame] | 4891 | out: |
Stephen Hemminger | af18d8b | 2009-08-14 15:31:25 -0700 | [diff] [blame] | 4892 | rtnl_unlock(); |
| 4893 | |
Stephen Hemminger | b02a925 | 2007-02-06 10:45:40 -0800 | [diff] [blame] | 4894 | dev_err(&pdev->dev, "resume failed (%d)\n", err); |
Stephen Hemminger | ae306cc | 2006-12-20 13:06:36 -0800 | [diff] [blame] | 4895 | pci_disable_device(pdev); |
Stephen Hemminger | 08c06d8 | 2006-01-30 11:37:54 -0800 | [diff] [blame] | 4896 | return err; |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4897 | } |
| 4898 | #endif |
| 4899 | |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4900 | static void sky2_shutdown(struct pci_dev *pdev) |
| 4901 | { |
stephen hemminger | 5f8ae5c | 2010-02-12 06:57:59 +0000 | [diff] [blame] | 4902 | sky2_suspend(pdev, PMSG_SUSPEND); |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4903 | } |
| 4904 | |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4905 | static struct pci_driver sky2_driver = { |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4906 | .name = DRV_NAME, |
| 4907 | .id_table = sky2_id_table, |
| 4908 | .probe = sky2_probe, |
| 4909 | .remove = __devexit_p(sky2_remove), |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4910 | #ifdef CONFIG_PM |
Stephen Hemminger | 793b883 | 2005-09-14 16:06:14 -0700 | [diff] [blame] | 4911 | .suspend = sky2_suspend, |
| 4912 | .resume = sky2_resume, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4913 | #endif |
Stephen Hemminger | e317383 | 2007-02-06 10:45:39 -0800 | [diff] [blame] | 4914 | .shutdown = sky2_shutdown, |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4915 | }; |
| 4916 | |
| 4917 | static int __init sky2_init_module(void) |
| 4918 | { |
Stephen Hemminger | c844d48 | 2008-08-27 20:48:23 -0700 | [diff] [blame] | 4919 | pr_info(PFX "driver version " DRV_VERSION "\n"); |
| 4920 | |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4921 | sky2_debug_init(); |
shemminger@osdl.org | 50241c4 | 2005-11-30 11:45:22 -0800 | [diff] [blame] | 4922 | return pci_register_driver(&sky2_driver); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4923 | } |
| 4924 | |
| 4925 | static void __exit sky2_cleanup_module(void) |
| 4926 | { |
| 4927 | pci_unregister_driver(&sky2_driver); |
Stephen Hemminger | 3cf2675 | 2007-07-09 15:33:35 -0700 | [diff] [blame] | 4928 | sky2_debug_cleanup(); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4929 | } |
| 4930 | |
| 4931 | module_init(sky2_init_module); |
| 4932 | module_exit(sky2_cleanup_module); |
| 4933 | |
| 4934 | MODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver"); |
Stephen Hemminger | 65ebe634 | 2007-01-23 11:38:57 -0800 | [diff] [blame] | 4935 | MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>"); |
Stephen Hemminger | cd28ab6 | 2005-08-16 16:36:49 -0700 | [diff] [blame] | 4936 | MODULE_LICENSE("GPL"); |
shemminger@osdl.org | 5f4f9dc | 2005-11-30 11:45:23 -0800 | [diff] [blame] | 4937 | MODULE_VERSION(DRV_VERSION); |