spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / drivers / net / ethernet / atheros / atlx / atlx.c
blob9796d0517dbda39b4026c236d92f8ea74e6a1279
1 /* atlx.c -- common functions for Attansic network drivers
3 * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved.
4 * Copyright(c) 2006 - 2007 Chris Snook <csnook@redhat.com>
5 * Copyright(c) 2006 - 2008 Jay Cliburn <jcliburn@gmail.com>
6 * Copyright(c) 2007 Atheros Corporation. All rights reserved.
8 * Derived from Intel e1000 driver
9 * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
14 * any later version.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * more details.
21 * You should have received a copy of the GNU General Public License along with
22 * this program; if not, write to the Free Software Foundation, Inc., 59
23 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 /* Including this file like a header is a temporary hack, I promise. -- CHS */
27 #ifndef ATLX_C
28 #define ATLX_C
30 #include <linux/device.h>
31 #include <linux/errno.h>
32 #include <linux/etherdevice.h>
33 #include <linux/if.h>
34 #include <linux/netdevice.h>
35 #include <linux/socket.h>
36 #include <linux/sockios.h>
37 #include <linux/spinlock.h>
38 #include <linux/string.h>
39 #include <linux/types.h>
40 #include <linux/workqueue.h>
42 #include "atlx.h"
44 static s32 atlx_read_phy_reg(struct atl1_hw *hw, u16 reg_addr, u16 *phy_data);
45 static u32 atlx_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr);
46 static void atlx_set_mac_addr(struct atl1_hw *hw);
48 static struct atlx_spi_flash_dev flash_table[] = {
49 /* MFR_NAME WRSR READ PRGM WREN WRDI RDSR RDID SEC_ERS CHIP_ERS */
50 {"Atmel", 0x00, 0x03, 0x02, 0x06, 0x04, 0x05, 0x15, 0x52, 0x62},
51 {"SST", 0x01, 0x03, 0x02, 0x06, 0x04, 0x05, 0x90, 0x20, 0x60},
52 {"ST", 0x01, 0x03, 0x02, 0x06, 0x04, 0x05, 0xAB, 0xD8, 0xC7},
55 static int atlx_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
57 switch (cmd) {
58 case SIOCGMIIPHY:
59 case SIOCGMIIREG:
60 case SIOCSMIIREG:
61 return atlx_mii_ioctl(netdev, ifr, cmd);
62 default:
63 return -EOPNOTSUPP;
68 * atlx_set_mac - Change the Ethernet Address of the NIC
69 * @netdev: network interface device structure
70 * @p: pointer to an address structure
72 * Returns 0 on success, negative on failure
74 static int atlx_set_mac(struct net_device *netdev, void *p)
76 struct atlx_adapter *adapter = netdev_priv(netdev);
77 struct sockaddr *addr = p;
79 if (netif_running(netdev))
80 return -EBUSY;
82 if (!is_valid_ether_addr(addr->sa_data))
83 return -EADDRNOTAVAIL;
85 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
86 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
88 atlx_set_mac_addr(&adapter->hw);
89 return 0;
92 static void atlx_check_for_link(struct atlx_adapter *adapter)
94 struct net_device *netdev = adapter->netdev;
95 u16 phy_data = 0;
97 spin_lock(&adapter->lock);
98 adapter->phy_timer_pending = false;
99 atlx_read_phy_reg(&adapter->hw, MII_BMSR, &phy_data);
100 atlx_read_phy_reg(&adapter->hw, MII_BMSR, &phy_data);
101 spin_unlock(&adapter->lock);
103 /* notify upper layer link down ASAP */
104 if (!(phy_data & BMSR_LSTATUS)) {
105 /* Link Down */
106 if (netif_carrier_ok(netdev)) {
107 /* old link state: Up */
108 dev_info(&adapter->pdev->dev, "%s link is down\n",
109 netdev->name);
110 adapter->link_speed = SPEED_0;
111 netif_carrier_off(netdev);
114 schedule_work(&adapter->link_chg_task);
118 * atlx_set_multi - Multicast and Promiscuous mode set
119 * @netdev: network interface device structure
121 * The set_multi entry point is called whenever the multicast address
122 * list or the network interface flags are updated. This routine is
123 * responsible for configuring the hardware for proper multicast,
124 * promiscuous mode, and all-multi behavior.
126 static void atlx_set_multi(struct net_device *netdev)
128 struct atlx_adapter *adapter = netdev_priv(netdev);
129 struct atlx_hw *hw = &adapter->hw;
130 struct netdev_hw_addr *ha;
131 u32 rctl;
132 u32 hash_value;
134 /* Check for Promiscuous and All Multicast modes */
135 rctl = ioread32(hw->hw_addr + REG_MAC_CTRL);
136 if (netdev->flags & IFF_PROMISC)
137 rctl |= MAC_CTRL_PROMIS_EN;
138 else if (netdev->flags & IFF_ALLMULTI) {
139 rctl |= MAC_CTRL_MC_ALL_EN;
140 rctl &= ~MAC_CTRL_PROMIS_EN;
141 } else
142 rctl &= ~(MAC_CTRL_PROMIS_EN | MAC_CTRL_MC_ALL_EN);
144 iowrite32(rctl, hw->hw_addr + REG_MAC_CTRL);
146 /* clear the old settings from the multicast hash table */
147 iowrite32(0, hw->hw_addr + REG_RX_HASH_TABLE);
148 iowrite32(0, (hw->hw_addr + REG_RX_HASH_TABLE) + (1 << 2));
150 /* compute mc addresses' hash value ,and put it into hash table */
151 netdev_for_each_mc_addr(ha, netdev) {
152 hash_value = atlx_hash_mc_addr(hw, ha->addr);
153 atlx_hash_set(hw, hash_value);
158 * atlx_irq_enable - Enable default interrupt generation settings
159 * @adapter: board private structure
161 static void atlx_irq_enable(struct atlx_adapter *adapter)
163 iowrite32(IMR_NORMAL_MASK, adapter->hw.hw_addr + REG_IMR);
164 ioread32(adapter->hw.hw_addr + REG_IMR);
168 * atlx_irq_disable - Mask off interrupt generation on the NIC
169 * @adapter: board private structure
171 static void atlx_irq_disable(struct atlx_adapter *adapter)
173 iowrite32(0, adapter->hw.hw_addr + REG_IMR);
174 ioread32(adapter->hw.hw_addr + REG_IMR);
175 synchronize_irq(adapter->pdev->irq);
178 static void atlx_clear_phy_int(struct atlx_adapter *adapter)
180 u16 phy_data;
181 unsigned long flags;
183 spin_lock_irqsave(&adapter->lock, flags);
184 atlx_read_phy_reg(&adapter->hw, 19, &phy_data);
185 spin_unlock_irqrestore(&adapter->lock, flags);
189 * atlx_tx_timeout - Respond to a Tx Hang
190 * @netdev: network interface device structure
192 static void atlx_tx_timeout(struct net_device *netdev)
194 struct atlx_adapter *adapter = netdev_priv(netdev);
195 /* Do the reset outside of interrupt context */
196 schedule_work(&adapter->reset_dev_task);
200 * atlx_link_chg_task - deal with link change event Out of interrupt context
202 static void atlx_link_chg_task(struct work_struct *work)
204 struct atlx_adapter *adapter;
205 unsigned long flags;
207 adapter = container_of(work, struct atlx_adapter, link_chg_task);
209 spin_lock_irqsave(&adapter->lock, flags);
210 atlx_check_link(adapter);
211 spin_unlock_irqrestore(&adapter->lock, flags);
214 static void __atlx_vlan_mode(netdev_features_t features, u32 *ctrl)
216 if (features & NETIF_F_HW_VLAN_RX) {
217 /* enable VLAN tag insert/strip */
218 *ctrl |= MAC_CTRL_RMV_VLAN;
219 } else {
220 /* disable VLAN tag insert/strip */
221 *ctrl &= ~MAC_CTRL_RMV_VLAN;
225 static void atlx_vlan_mode(struct net_device *netdev,
226 netdev_features_t features)
228 struct atlx_adapter *adapter = netdev_priv(netdev);
229 unsigned long flags;
230 u32 ctrl;
232 spin_lock_irqsave(&adapter->lock, flags);
233 /* atlx_irq_disable(adapter); FIXME: confirm/remove */
234 ctrl = ioread32(adapter->hw.hw_addr + REG_MAC_CTRL);
235 __atlx_vlan_mode(features, &ctrl);
236 iowrite32(ctrl, adapter->hw.hw_addr + REG_MAC_CTRL);
237 /* atlx_irq_enable(adapter); FIXME */
238 spin_unlock_irqrestore(&adapter->lock, flags);
241 static void atlx_restore_vlan(struct atlx_adapter *adapter)
243 atlx_vlan_mode(adapter->netdev, adapter->netdev->features);
246 static netdev_features_t atlx_fix_features(struct net_device *netdev,
247 netdev_features_t features)
250 * Since there is no support for separate rx/tx vlan accel
251 * enable/disable make sure tx flag is always in same state as rx.
253 if (features & NETIF_F_HW_VLAN_RX)
254 features |= NETIF_F_HW_VLAN_TX;
255 else
256 features &= ~NETIF_F_HW_VLAN_TX;
258 return features;
261 static int atlx_set_features(struct net_device *netdev,
262 netdev_features_t features)
264 netdev_features_t changed = netdev->features ^ features;
266 if (changed & NETIF_F_HW_VLAN_RX)
267 atlx_vlan_mode(netdev, features);
269 return 0;
272 #endif /* ATLX_C */