1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifndef ATLX_C
28#define ATLX_C
29
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>
41
42#include "atlx.h"
43
44static s32 atlx_read_phy_reg(struct atl1_hw *hw, u16 reg_addr, u16 *phy_data);
45static u32 atlx_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr);
46static void atlx_set_mac_addr(struct atl1_hw *hw);
47
48static struct atlx_spi_flash_dev flash_table[] = {
49
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},
53};
54
55static int atlx_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
56{
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;
64 }
65}
66
67
68
69
70
71
72
73
74static int atlx_set_mac(struct net_device *netdev, void *p)
75{
76 struct atlx_adapter *adapter = netdev_priv(netdev);
77 struct sockaddr *addr = p;
78
79 if (netif_running(netdev))
80 return -EBUSY;
81
82 if (!is_valid_ether_addr(addr->sa_data))
83 return -EADDRNOTAVAIL;
84
85 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
86 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
87
88 atlx_set_mac_addr(&adapter->hw);
89 return 0;
90}
91
92static void atlx_check_for_link(struct atlx_adapter *adapter)
93{
94 struct net_device *netdev = adapter->netdev;
95 u16 phy_data = 0;
96
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);
102
103
104 if (!(phy_data & BMSR_LSTATUS)) {
105
106 if (netif_carrier_ok(netdev)) {
107
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);
112 }
113 }
114 schedule_work(&adapter->link_chg_task);
115}
116
117
118
119
120
121
122
123
124
125
126static void atlx_set_multi(struct net_device *netdev)
127{
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;
133
134
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);
143
144 iowrite32(rctl, hw->hw_addr + REG_MAC_CTRL);
145
146
147 iowrite32(0, hw->hw_addr + REG_RX_HASH_TABLE);
148 iowrite32(0, (hw->hw_addr + REG_RX_HASH_TABLE) + (1 << 2));
149
150
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);
154 }
155}
156
157static inline void atlx_imr_set(struct atlx_adapter *adapter,
158 unsigned int imr)
159{
160 iowrite32(imr, adapter->hw.hw_addr + REG_IMR);
161 ioread32(adapter->hw.hw_addr + REG_IMR);
162}
163
164
165
166
167
168static void atlx_irq_enable(struct atlx_adapter *adapter)
169{
170 atlx_imr_set(adapter, IMR_NORMAL_MASK);
171 adapter->int_enabled = true;
172}
173
174
175
176
177
178static void atlx_irq_disable(struct atlx_adapter *adapter)
179{
180 adapter->int_enabled = false;
181 atlx_imr_set(adapter, 0);
182 synchronize_irq(adapter->pdev->irq);
183}
184
185static void atlx_clear_phy_int(struct atlx_adapter *adapter)
186{
187 u16 phy_data;
188 unsigned long flags;
189
190 spin_lock_irqsave(&adapter->lock, flags);
191 atlx_read_phy_reg(&adapter->hw, 19, &phy_data);
192 spin_unlock_irqrestore(&adapter->lock, flags);
193}
194
195
196
197
198
199static void atlx_tx_timeout(struct net_device *netdev)
200{
201 struct atlx_adapter *adapter = netdev_priv(netdev);
202
203 schedule_work(&adapter->reset_dev_task);
204}
205
206
207
208
209static void atlx_link_chg_task(struct work_struct *work)
210{
211 struct atlx_adapter *adapter;
212 unsigned long flags;
213
214 adapter = container_of(work, struct atlx_adapter, link_chg_task);
215
216 spin_lock_irqsave(&adapter->lock, flags);
217 atlx_check_link(adapter);
218 spin_unlock_irqrestore(&adapter->lock, flags);
219}
220
221static void __atlx_vlan_mode(netdev_features_t features, u32 *ctrl)
222{
223 if (features & NETIF_F_HW_VLAN_CTAG_RX) {
224
225 *ctrl |= MAC_CTRL_RMV_VLAN;
226 } else {
227
228 *ctrl &= ~MAC_CTRL_RMV_VLAN;
229 }
230}
231
232static void atlx_vlan_mode(struct net_device *netdev,
233 netdev_features_t features)
234{
235 struct atlx_adapter *adapter = netdev_priv(netdev);
236 unsigned long flags;
237 u32 ctrl;
238
239 spin_lock_irqsave(&adapter->lock, flags);
240
241 ctrl = ioread32(adapter->hw.hw_addr + REG_MAC_CTRL);
242 __atlx_vlan_mode(features, &ctrl);
243 iowrite32(ctrl, adapter->hw.hw_addr + REG_MAC_CTRL);
244
245 spin_unlock_irqrestore(&adapter->lock, flags);
246}
247
248static void atlx_restore_vlan(struct atlx_adapter *adapter)
249{
250 atlx_vlan_mode(adapter->netdev, adapter->netdev->features);
251}
252
253static netdev_features_t atlx_fix_features(struct net_device *netdev,
254 netdev_features_t features)
255{
256
257
258
259
260 if (features & NETIF_F_HW_VLAN_CTAG_RX)
261 features |= NETIF_F_HW_VLAN_CTAG_TX;
262 else
263 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
264
265 return features;
266}
267
268static int atlx_set_features(struct net_device *netdev,
269 netdev_features_t features)
270{
271 netdev_features_t changed = netdev->features ^ features;
272
273 if (changed & NETIF_F_HW_VLAN_CTAG_RX)
274 atlx_vlan_mode(netdev, features);
275
276 return 0;
277}
278
279#endif
280