aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2011-02-22 14:15:29 -0500
committerDavid S. Miller <davem@davemloft.net>2011-02-22 14:15:29 -0500
commitdb62983a1e4b2af9e79c97af768f0c8b80bd93f0 (patch)
tree6cfac68841ea24503be3c0b935710774f722c46e /drivers/net
parent9e1453c5c5fe670bb98a6097b262122386b0d3fe (diff)
parentf6d7f2c60d3a63d786feeb60628f930cd2d8e912 (diff)
Merge branch 'net/ax88796' of git://git.pengutronix.de/git/mkl/linux-2.6
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/Kconfig4
-rw-r--r--drivers/net/ax88796.c810
2 files changed, 395 insertions, 419 deletions
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 65027a72ca93..f4b39274308a 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -238,8 +238,8 @@ source "drivers/net/arm/Kconfig"
238config AX88796 238config AX88796
239 tristate "ASIX AX88796 NE2000 clone support" 239 tristate "ASIX AX88796 NE2000 clone support"
240 depends on ARM || MIPS || SUPERH 240 depends on ARM || MIPS || SUPERH
241 select CRC32 241 select PHYLIB
242 select MII 242 select MDIO_BITBANG
243 help 243 help
244 AX88796 driver, using platform bus to provide 244 AX88796 driver, using platform bus to provide
245 chip detection and resources 245 chip detection and resources
diff --git a/drivers/net/ax88796.c b/drivers/net/ax88796.c
index 4bebff3faeab..e7cb8c8b9776 100644
--- a/drivers/net/ax88796.c
+++ b/drivers/net/ax88796.c
@@ -9,7 +9,7 @@
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as 10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
12*/ 12 */
13 13
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
@@ -17,46 +17,45 @@
17#include <linux/isapnp.h> 17#include <linux/isapnp.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/io.h>
20#include <linux/platform_device.h> 21#include <linux/platform_device.h>
21#include <linux/delay.h> 22#include <linux/delay.h>
22#include <linux/timer.h> 23#include <linux/timer.h>
23#include <linux/netdevice.h> 24#include <linux/netdevice.h>
24#include <linux/etherdevice.h> 25#include <linux/etherdevice.h>
25#include <linux/ethtool.h> 26#include <linux/ethtool.h>
26#include <linux/mii.h> 27#include <linux/mdio-bitbang.h>
28#include <linux/phy.h>
27#include <linux/eeprom_93cx6.h> 29#include <linux/eeprom_93cx6.h>
28#include <linux/slab.h> 30#include <linux/slab.h>
29 31
30#include <net/ax88796.h> 32#include <net/ax88796.h>
31 33
32#include <asm/system.h> 34#include <asm/system.h>
33#include <asm/io.h>
34
35static int phy_debug = 0;
36 35
37/* Rename the lib8390.c functions to show that they are in this driver */ 36/* Rename the lib8390.c functions to show that they are in this driver */
38#define __ei_open ax_ei_open 37#define __ei_open ax_ei_open
39#define __ei_close ax_ei_close 38#define __ei_close ax_ei_close
40#define __ei_poll ax_ei_poll 39#define __ei_poll ax_ei_poll
41#define __ei_start_xmit ax_ei_start_xmit 40#define __ei_start_xmit ax_ei_start_xmit
42#define __ei_tx_timeout ax_ei_tx_timeout 41#define __ei_tx_timeout ax_ei_tx_timeout
43#define __ei_get_stats ax_ei_get_stats 42#define __ei_get_stats ax_ei_get_stats
44#define __ei_set_multicast_list ax_ei_set_multicast_list 43#define __ei_set_multicast_list ax_ei_set_multicast_list
45#define __ei_interrupt ax_ei_interrupt 44#define __ei_interrupt ax_ei_interrupt
46#define ____alloc_ei_netdev ax__alloc_ei_netdev 45#define ____alloc_ei_netdev ax__alloc_ei_netdev
47#define __NS8390_init ax_NS8390_init 46#define __NS8390_init ax_NS8390_init
48 47
49/* force unsigned long back to 'void __iomem *' */ 48/* force unsigned long back to 'void __iomem *' */
50#define ax_convert_addr(_a) ((void __force __iomem *)(_a)) 49#define ax_convert_addr(_a) ((void __force __iomem *)(_a))
51 50
52#define ei_inb(_a) readb(ax_convert_addr(_a)) 51#define ei_inb(_a) readb(ax_convert_addr(_a))
53#define ei_outb(_v, _a) writeb(_v, ax_convert_addr(_a)) 52#define ei_outb(_v, _a) writeb(_v, ax_convert_addr(_a))
54 53
55#define ei_inb_p(_a) ei_inb(_a) 54#define ei_inb_p(_a) ei_inb(_a)
56#define ei_outb_p(_v, _a) ei_outb(_v, _a) 55#define ei_outb_p(_v, _a) ei_outb(_v, _a)
57 56
58/* define EI_SHIFT() to take into account our register offsets */ 57/* define EI_SHIFT() to take into account our register offsets */
59#define EI_SHIFT(x) (ei_local->reg_offset[(x)]) 58#define EI_SHIFT(x) (ei_local->reg_offset[(x)])
60 59
61/* Ensure we have our RCR base value */ 60/* Ensure we have our RCR base value */
62#define AX88796_PLATFORM 61#define AX88796_PLATFORM
@@ -74,43 +73,46 @@ static unsigned char version[] = "ax88796.c: Copyright 2005,2007 Simtec Electron
74#define NE_DATAPORT EI_SHIFT(0x10) 73#define NE_DATAPORT EI_SHIFT(0x10)
75 74
76#define NE1SM_START_PG 0x20 /* First page of TX buffer */ 75#define NE1SM_START_PG 0x20 /* First page of TX buffer */
77#define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */ 76#define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
78#define NESM_START_PG 0x40 /* First page of TX buffer */ 77#define NESM_START_PG 0x40 /* First page of TX buffer */
79#define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */ 78#define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
80 79
80#define AX_GPOC_PPDSET BIT(6)
81
81/* device private data */ 82/* device private data */
82 83
83struct ax_device { 84struct ax_device {
84 struct timer_list mii_timer; 85 struct mii_bus *mii_bus;
85 spinlock_t mii_lock; 86 struct mdiobb_ctrl bb_ctrl;
86 struct mii_if_info mii; 87 struct phy_device *phy_dev;
87 88 void __iomem *addr_memr;
88 u32 msg_enable; 89 u8 reg_memr;
89 void __iomem *map2; 90 int link;
90 struct platform_device *dev; 91 int speed;
91 struct resource *mem; 92 int duplex;
92 struct resource *mem2; 93
93 struct ax_plat_data *plat; 94 void __iomem *map2;
94 95 const struct ax_plat_data *plat;
95 unsigned char running; 96
96 unsigned char resume_open; 97 unsigned char running;
97 unsigned int irqflags; 98 unsigned char resume_open;
98 99 unsigned int irqflags;
99 u32 reg_offsets[0x20]; 100
101 u32 reg_offsets[0x20];
100}; 102};
101 103
102static inline struct ax_device *to_ax_dev(struct net_device *dev) 104static inline struct ax_device *to_ax_dev(struct net_device *dev)
103{ 105{
104 struct ei_device *ei_local = netdev_priv(dev); 106 struct ei_device *ei_local = netdev_priv(dev);
105 return (struct ax_device *)(ei_local+1); 107 return (struct ax_device *)(ei_local + 1);
106} 108}
107 109
108/* ax_initial_check 110/*
111 * ax_initial_check
109 * 112 *
110 * do an initial probe for the card to check wether it exists 113 * do an initial probe for the card to check wether it exists
111 * and is functional 114 * and is functional
112 */ 115 */
113
114static int ax_initial_check(struct net_device *dev) 116static int ax_initial_check(struct net_device *dev)
115{ 117{
116 struct ei_device *ei_local = netdev_priv(dev); 118 struct ei_device *ei_local = netdev_priv(dev);
@@ -122,10 +124,10 @@ static int ax_initial_check(struct net_device *dev)
122 if (reg0 == 0xFF) 124 if (reg0 == 0xFF)
123 return -ENODEV; 125 return -ENODEV;
124 126
125 ei_outb(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD); 127 ei_outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP, ioaddr + E8390_CMD);
126 regd = ei_inb(ioaddr + 0x0d); 128 regd = ei_inb(ioaddr + 0x0d);
127 ei_outb(0xff, ioaddr + 0x0d); 129 ei_outb(0xff, ioaddr + 0x0d);
128 ei_outb(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD); 130 ei_outb(E8390_NODMA + E8390_PAGE0, ioaddr + E8390_CMD);
129 ei_inb(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */ 131 ei_inb(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
130 if (ei_inb(ioaddr + EN0_COUNTER0) != 0) { 132 if (ei_inb(ioaddr + EN0_COUNTER0) != 0) {
131 ei_outb(reg0, ioaddr); 133 ei_outb(reg0, ioaddr);
@@ -136,29 +138,28 @@ static int ax_initial_check(struct net_device *dev)
136 return 0; 138 return 0;
137} 139}
138 140
139/* Hard reset the card. This used to pause for the same period that a 141/*
140 8390 reset command required, but that shouldn't be necessary. */ 142 * Hard reset the card. This used to pause for the same period that a
141 143 * 8390 reset command required, but that shouldn't be necessary.
144 */
142static void ax_reset_8390(struct net_device *dev) 145static void ax_reset_8390(struct net_device *dev)
143{ 146{
144 struct ei_device *ei_local = netdev_priv(dev); 147 struct ei_device *ei_local = netdev_priv(dev);
145 struct ax_device *ax = to_ax_dev(dev);
146 unsigned long reset_start_time = jiffies; 148 unsigned long reset_start_time = jiffies;
147 void __iomem *addr = (void __iomem *)dev->base_addr; 149 void __iomem *addr = (void __iomem *)dev->base_addr;
148 150
149 if (ei_debug > 1) 151 if (ei_debug > 1)
150 dev_dbg(&ax->dev->dev, "resetting the 8390 t=%ld\n", jiffies); 152 netdev_dbg(dev, "resetting the 8390 t=%ld\n", jiffies);
151 153
152 ei_outb(ei_inb(addr + NE_RESET), addr + NE_RESET); 154 ei_outb(ei_inb(addr + NE_RESET), addr + NE_RESET);
153 155
154 ei_status.txing = 0; 156 ei_local->txing = 0;
155 ei_status.dmaing = 0; 157 ei_local->dmaing = 0;
156 158
157 /* This check _should_not_ be necessary, omit eventually. */ 159 /* This check _should_not_ be necessary, omit eventually. */
158 while ((ei_inb(addr + EN0_ISR) & ENISR_RESET) == 0) { 160 while ((ei_inb(addr + EN0_ISR) & ENISR_RESET) == 0) {
159 if (jiffies - reset_start_time > 2*HZ/100) { 161 if (jiffies - reset_start_time > 2 * HZ / 100) {
160 dev_warn(&ax->dev->dev, "%s: %s did not complete.\n", 162 netdev_warn(dev, "%s: did not complete.\n", __func__);
161 __func__, dev->name);
162 break; 163 break;
163 } 164 }
164 } 165 }
@@ -171,70 +172,72 @@ static void ax_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
171 int ring_page) 172 int ring_page)
172{ 173{
173 struct ei_device *ei_local = netdev_priv(dev); 174 struct ei_device *ei_local = netdev_priv(dev);
174 struct ax_device *ax = to_ax_dev(dev);
175 void __iomem *nic_base = ei_local->mem; 175 void __iomem *nic_base = ei_local->mem;
176 176
177 /* This *shouldn't* happen. If it does, it's the last thing you'll see */ 177 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
178 if (ei_status.dmaing) { 178 if (ei_local->dmaing) {
179 dev_err(&ax->dev->dev, "%s: DMAing conflict in %s " 179 netdev_err(dev, "DMAing conflict in %s "
180 "[DMAstat:%d][irqlock:%d].\n", 180 "[DMAstat:%d][irqlock:%d].\n",
181 dev->name, __func__, 181 __func__,
182 ei_status.dmaing, ei_status.irqlock); 182 ei_local->dmaing, ei_local->irqlock);
183 return; 183 return;
184 } 184 }
185 185
186 ei_status.dmaing |= 0x01; 186 ei_local->dmaing |= 0x01;
187 ei_outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); 187 ei_outb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD);
188 ei_outb(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO); 188 ei_outb(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
189 ei_outb(0, nic_base + EN0_RCNTHI); 189 ei_outb(0, nic_base + EN0_RCNTHI);
190 ei_outb(0, nic_base + EN0_RSARLO); /* On page boundary */ 190 ei_outb(0, nic_base + EN0_RSARLO); /* On page boundary */
191 ei_outb(ring_page, nic_base + EN0_RSARHI); 191 ei_outb(ring_page, nic_base + EN0_RSARHI);
192 ei_outb(E8390_RREAD+E8390_START, nic_base + NE_CMD); 192 ei_outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
193 193
194 if (ei_status.word16) 194 if (ei_local->word16)
195 readsw(nic_base + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1); 195 readsw(nic_base + NE_DATAPORT, hdr,
196 sizeof(struct e8390_pkt_hdr) >> 1);
196 else 197 else
197 readsb(nic_base + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)); 198 readsb(nic_base + NE_DATAPORT, hdr,
199 sizeof(struct e8390_pkt_hdr));
198 200
199 ei_outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ 201 ei_outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
200 ei_status.dmaing &= ~0x01; 202 ei_local->dmaing &= ~0x01;
201 203
202 le16_to_cpus(&hdr->count); 204 le16_to_cpus(&hdr->count);
203} 205}
204 206
205 207
206/* Block input and output, similar to the Crynwr packet driver. If you 208/*
207 are porting to a new ethercard, look at the packet driver source for hints. 209 * Block input and output, similar to the Crynwr packet driver. If
208 The NEx000 doesn't share the on-board packet memory -- you have to put 210 * you are porting to a new ethercard, look at the packet driver
209 the packet out through the "remote DMA" dataport using ei_outb. */ 211 * source for hints. The NEx000 doesn't share the on-board packet
210 212 * memory -- you have to put the packet out through the "remote DMA"
213 * dataport using ei_outb.
214 */
211static void ax_block_input(struct net_device *dev, int count, 215static void ax_block_input(struct net_device *dev, int count,
212 struct sk_buff *skb, int ring_offset) 216 struct sk_buff *skb, int ring_offset)
213{ 217{
214 struct ei_device *ei_local = netdev_priv(dev); 218 struct ei_device *ei_local = netdev_priv(dev);
215 struct ax_device *ax = to_ax_dev(dev);
216 void __iomem *nic_base = ei_local->mem; 219 void __iomem *nic_base = ei_local->mem;
217 char *buf = skb->data; 220 char *buf = skb->data;
218 221
219 if (ei_status.dmaing) { 222 if (ei_local->dmaing) {
220 dev_err(&ax->dev->dev, 223 netdev_err(dev,
221 "%s: DMAing conflict in %s " 224 "DMAing conflict in %s "
222 "[DMAstat:%d][irqlock:%d].\n", 225 "[DMAstat:%d][irqlock:%d].\n",
223 dev->name, __func__, 226 __func__,
224 ei_status.dmaing, ei_status.irqlock); 227 ei_local->dmaing, ei_local->irqlock);
225 return; 228 return;
226 } 229 }
227 230
228 ei_status.dmaing |= 0x01; 231 ei_local->dmaing |= 0x01;
229 232
230 ei_outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); 233 ei_outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base + NE_CMD);
231 ei_outb(count & 0xff, nic_base + EN0_RCNTLO); 234 ei_outb(count & 0xff, nic_base + EN0_RCNTLO);
232 ei_outb(count >> 8, nic_base + EN0_RCNTHI); 235 ei_outb(count >> 8, nic_base + EN0_RCNTHI);
233 ei_outb(ring_offset & 0xff, nic_base + EN0_RSARLO); 236 ei_outb(ring_offset & 0xff, nic_base + EN0_RSARLO);
234 ei_outb(ring_offset >> 8, nic_base + EN0_RSARHI); 237 ei_outb(ring_offset >> 8, nic_base + EN0_RSARHI);
235 ei_outb(E8390_RREAD+E8390_START, nic_base + NE_CMD); 238 ei_outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
236 239
237 if (ei_status.word16) { 240 if (ei_local->word16) {
238 readsw(nic_base + NE_DATAPORT, buf, count >> 1); 241 readsw(nic_base + NE_DATAPORT, buf, count >> 1);
239 if (count & 0x01) 242 if (count & 0x01)
240 buf[count-1] = ei_inb(nic_base + NE_DATAPORT); 243 buf[count-1] = ei_inb(nic_base + NE_DATAPORT);
@@ -243,34 +246,34 @@ static void ax_block_input(struct net_device *dev, int count,
243 readsb(nic_base + NE_DATAPORT, buf, count); 246 readsb(nic_base + NE_DATAPORT, buf, count);
244 } 247 }
245 248
246 ei_status.dmaing &= ~1; 249 ei_local->dmaing &= ~1;
247} 250}
248 251
249static void ax_block_output(struct net_device *dev, int count, 252static void ax_block_output(struct net_device *dev, int count,
250 const unsigned char *buf, const int start_page) 253 const unsigned char *buf, const int start_page)
251{ 254{
252 struct ei_device *ei_local = netdev_priv(dev); 255 struct ei_device *ei_local = netdev_priv(dev);
253 struct ax_device *ax = to_ax_dev(dev);
254 void __iomem *nic_base = ei_local->mem; 256 void __iomem *nic_base = ei_local->mem;
255 unsigned long dma_start; 257 unsigned long dma_start;
256 258
257 /* Round the count up for word writes. Do we need to do this? 259 /*
258 What effect will an odd byte count have on the 8390? 260 * Round the count up for word writes. Do we need to do this?
259 I should check someday. */ 261 * What effect will an odd byte count have on the 8390? I
260 262 * should check someday.
261 if (ei_status.word16 && (count & 0x01)) 263 */
264 if (ei_local->word16 && (count & 0x01))
262 count++; 265 count++;
263 266
264 /* This *shouldn't* happen. If it does, it's the last thing you'll see */ 267 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
265 if (ei_status.dmaing) { 268 if (ei_local->dmaing) {
266 dev_err(&ax->dev->dev, "%s: DMAing conflict in %s." 269 netdev_err(dev, "DMAing conflict in %s."
267 "[DMAstat:%d][irqlock:%d]\n", 270 "[DMAstat:%d][irqlock:%d]\n",
268 dev->name, __func__, 271 __func__,
269 ei_status.dmaing, ei_status.irqlock); 272 ei_local->dmaing, ei_local->irqlock);
270 return; 273 return;
271 } 274 }
272 275
273 ei_status.dmaing |= 0x01; 276 ei_local->dmaing |= 0x01;
274 /* We should already be in page 0, but to be safe... */ 277 /* We should already be in page 0, but to be safe... */
275 ei_outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD); 278 ei_outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
276 279
@@ -278,250 +281,170 @@ static void ax_block_output(struct net_device *dev, int count,
278 281
279 /* Now the normal output. */ 282 /* Now the normal output. */
280 ei_outb(count & 0xff, nic_base + EN0_RCNTLO); 283 ei_outb(count & 0xff, nic_base + EN0_RCNTLO);
281 ei_outb(count >> 8, nic_base + EN0_RCNTHI); 284 ei_outb(count >> 8, nic_base + EN0_RCNTHI);
282 ei_outb(0x00, nic_base + EN0_RSARLO); 285 ei_outb(0x00, nic_base + EN0_RSARLO);
283 ei_outb(start_page, nic_base + EN0_RSARHI); 286 ei_outb(start_page, nic_base + EN0_RSARHI);
284 287
285 ei_outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD); 288 ei_outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
286 if (ei_status.word16) { 289 if (ei_local->word16)
287 writesw(nic_base + NE_DATAPORT, buf, count>>1); 290 writesw(nic_base + NE_DATAPORT, buf, count >> 1);
288 } else { 291 else
289 writesb(nic_base + NE_DATAPORT, buf, count); 292 writesb(nic_base + NE_DATAPORT, buf, count);
290 }
291 293
292 dma_start = jiffies; 294 dma_start = jiffies;
293 295
294 while ((ei_inb(nic_base + EN0_ISR) & ENISR_RDC) == 0) { 296 while ((ei_inb(nic_base + EN0_ISR) & ENISR_RDC) == 0) {
295 if (jiffies - dma_start > 2*HZ/100) { /* 20ms */ 297 if (jiffies - dma_start > 2 * HZ / 100) { /* 20ms */
296 dev_warn(&ax->dev->dev, 298 netdev_warn(dev, "timeout waiting for Tx RDC.\n");
297 "%s: timeout waiting for Tx RDC.\n", dev->name);
298 ax_reset_8390(dev); 299 ax_reset_8390(dev);
299 ax_NS8390_init(dev,1); 300 ax_NS8390_init(dev, 1);
300 break; 301 break;
301 } 302 }
302 } 303 }
303 304
304 ei_outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ 305 ei_outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
305 ei_status.dmaing &= ~0x01; 306 ei_local->dmaing &= ~0x01;
306} 307}
307 308
308/* definitions for accessing MII/EEPROM interface */ 309/* definitions for accessing MII/EEPROM interface */
309 310
310#define AX_MEMR EI_SHIFT(0x14) 311#define AX_MEMR EI_SHIFT(0x14)
311#define AX_MEMR_MDC (1<<0) 312#define AX_MEMR_MDC BIT(0)
312#define AX_MEMR_MDIR (1<<1) 313#define AX_MEMR_MDIR BIT(1)
313#define AX_MEMR_MDI (1<<2) 314#define AX_MEMR_MDI BIT(2)
314#define AX_MEMR_MDO (1<<3) 315#define AX_MEMR_MDO BIT(3)
315#define AX_MEMR_EECS (1<<4) 316#define AX_MEMR_EECS BIT(4)
316#define AX_MEMR_EEI (1<<5) 317#define AX_MEMR_EEI BIT(5)
317#define AX_MEMR_EEO (1<<6) 318#define AX_MEMR_EEO BIT(6)
318#define AX_MEMR_EECLK (1<<7) 319#define AX_MEMR_EECLK BIT(7)
319 320
320/* ax_mii_ei_outbits 321static void ax_handle_link_change(struct net_device *dev)
321 *
322 * write the specified set of bits to the phy
323*/
324
325static void
326ax_mii_ei_outbits(struct net_device *dev, unsigned int bits, int len)
327{ 322{
328 struct ei_device *ei_local = netdev_priv(dev); 323 struct ax_device *ax = to_ax_dev(dev);
329 void __iomem *memr_addr = (void __iomem *)dev->base_addr + AX_MEMR; 324 struct phy_device *phy_dev = ax->phy_dev;
330 unsigned int memr; 325 int status_change = 0;
331
332 /* clock low, data to output mode */
333 memr = ei_inb(memr_addr);
334 memr &= ~(AX_MEMR_MDC | AX_MEMR_MDIR);
335 ei_outb(memr, memr_addr);
336
337 for (len--; len >= 0; len--) {
338 if (bits & (1 << len))
339 memr |= AX_MEMR_MDO;
340 else
341 memr &= ~AX_MEMR_MDO;
342
343 ei_outb(memr, memr_addr);
344
345 /* clock high */
346 326
347 ei_outb(memr | AX_MEMR_MDC, memr_addr); 327 if (phy_dev->link && ((ax->speed != phy_dev->speed) ||
348 udelay(1); 328 (ax->duplex != phy_dev->duplex))) {
349 329
350 /* clock low */ 330 ax->speed = phy_dev->speed;
351 ei_outb(memr, memr_addr); 331 ax->duplex = phy_dev->duplex;
332 status_change = 1;
352 } 333 }
353 334
354 /* leaves the clock line low, mdir input */ 335 if (phy_dev->link != ax->link) {
355 memr |= AX_MEMR_MDIR; 336 if (!phy_dev->link) {
356 ei_outb(memr, (void __iomem *)dev->base_addr + AX_MEMR); 337 ax->speed = 0;
357} 338 ax->duplex = -1;
358 339 }
359/* ax_phy_ei_inbits 340 ax->link = phy_dev->link;
360 *
361 * read a specified number of bits from the phy
362*/
363
364static unsigned int
365ax_phy_ei_inbits(struct net_device *dev, int no)
366{
367 struct ei_device *ei_local = netdev_priv(dev);
368 void __iomem *memr_addr = (void __iomem *)dev->base_addr + AX_MEMR;
369 unsigned int memr;
370 unsigned int result = 0;
371
372 /* clock low, data to input mode */
373 memr = ei_inb(memr_addr);
374 memr &= ~AX_MEMR_MDC;
375 memr |= AX_MEMR_MDIR;
376 ei_outb(memr, memr_addr);
377
378 for (no--; no >= 0; no--) {
379 ei_outb(memr | AX_MEMR_MDC, memr_addr);
380
381 udelay(1);
382
383 if (ei_inb(memr_addr) & AX_MEMR_MDI)
384 result |= (1<<no);
385 341
386 ei_outb(memr, memr_addr); 342 status_change = 1;
387 } 343 }
388 344
389 return result; 345 if (status_change)
390} 346 phy_print_status(phy_dev);
391
392/* ax_phy_issueaddr
393 *
394 * use the low level bit shifting routines to send the address
395 * and command to the specified phy
396*/
397
398static void
399ax_phy_issueaddr(struct net_device *dev, int phy_addr, int reg, int opc)
400{
401 if (phy_debug)
402 pr_debug("%s: dev %p, %04x, %04x, %d\n",
403 __func__, dev, phy_addr, reg, opc);
404
405 ax_mii_ei_outbits(dev, 0x3f, 6); /* pre-amble */
406 ax_mii_ei_outbits(dev, 1, 2); /* frame-start */
407 ax_mii_ei_outbits(dev, opc, 2); /* op code */
408 ax_mii_ei_outbits(dev, phy_addr, 5); /* phy address */
409 ax_mii_ei_outbits(dev, reg, 5); /* reg address */
410} 347}
411 348
412static int 349static int ax_mii_probe(struct net_device *dev)
413ax_phy_read(struct net_device *dev, int phy_addr, int reg)
414{ 350{
415 struct ei_device *ei_local = netdev_priv(dev); 351 struct ax_device *ax = to_ax_dev(dev);
416 unsigned long flags; 352 struct phy_device *phy_dev = NULL;
417 unsigned int result; 353 int ret;
418 354
419 spin_lock_irqsave(&ei_local->page_lock, flags); 355 /* find the first phy */
356 phy_dev = phy_find_first(ax->mii_bus);
357 if (!phy_dev) {
358 netdev_err(dev, "no PHY found\n");
359 return -ENODEV;
360 }
420 361
421 ax_phy_issueaddr(dev, phy_addr, reg, 2); 362 ret = phy_connect_direct(dev, phy_dev, ax_handle_link_change, 0,
363 PHY_INTERFACE_MODE_MII);
364 if (ret) {
365 netdev_err(dev, "Could not attach to PHY\n");
366 return ret;
367 }
422 368
423 result = ax_phy_ei_inbits(dev, 17); 369 /* mask with MAC supported features */
424 result &= ~(3<<16); 370 phy_dev->supported &= PHY_BASIC_FEATURES;
371 phy_dev->advertising = phy_dev->supported;
425 372
426 spin_unlock_irqrestore(&ei_local->page_lock, flags); 373 ax->phy_dev = phy_dev;
427 374
428 if (phy_debug) 375 netdev_info(dev, "PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
429 pr_debug("%s: %04x.%04x => read %04x\n", __func__, 376 phy_dev->drv->name, dev_name(&phy_dev->dev), phy_dev->irq);
430 phy_addr, reg, result);
431 377
432 return result; 378 return 0;
433} 379}
434 380
435static void 381static void ax_phy_switch(struct net_device *dev, int on)
436ax_phy_write(struct net_device *dev, int phy_addr, int reg, int value)
437{ 382{
438 struct ei_device *ei = netdev_priv(dev); 383 struct ei_device *ei_local = netdev_priv(dev);
439 struct ax_device *ax = to_ax_dev(dev); 384 struct ax_device *ax = to_ax_dev(dev);
440 unsigned long flags;
441
442 dev_dbg(&ax->dev->dev, "%s: %p, %04x, %04x %04x\n",
443 __func__, dev, phy_addr, reg, value);
444
445 spin_lock_irqsave(&ei->page_lock, flags);
446
447 ax_phy_issueaddr(dev, phy_addr, reg, 1);
448 ax_mii_ei_outbits(dev, 2, 2); /* send TA */
449 ax_mii_ei_outbits(dev, value, 16);
450
451 spin_unlock_irqrestore(&ei->page_lock, flags);
452}
453 385
454static void ax_mii_expiry(unsigned long data) 386 u8 reg_gpoc = ax->plat->gpoc_val;
455{
456 struct net_device *dev = (struct net_device *)data;
457 struct ax_device *ax = to_ax_dev(dev);
458 unsigned long flags;
459 387
460 spin_lock_irqsave(&ax->mii_lock, flags); 388 if (!!on)
461 mii_check_media(&ax->mii, netif_msg_link(ax), 0); 389 reg_gpoc &= ~AX_GPOC_PPDSET;
462 spin_unlock_irqrestore(&ax->mii_lock, flags); 390 else
391 reg_gpoc |= AX_GPOC_PPDSET;
463 392
464 if (ax->running) { 393 ei_outb(reg_gpoc, ei_local->mem + EI_SHIFT(0x17));
465 ax->mii_timer.expires = jiffies + HZ*2;
466 add_timer(&ax->mii_timer);
467 }
468} 394}
469 395
470static int ax_open(struct net_device *dev) 396static int ax_open(struct net_device *dev)
471{ 397{
472 struct ax_device *ax = to_ax_dev(dev); 398 struct ax_device *ax = to_ax_dev(dev);
473 struct ei_device *ei_local = netdev_priv(dev);
474 int ret; 399 int ret;
475 400
476 dev_dbg(&ax->dev->dev, "%s: open\n", dev->name); 401 netdev_dbg(dev, "open\n");
477 402
478 ret = request_irq(dev->irq, ax_ei_interrupt, ax->irqflags, 403 ret = request_irq(dev->irq, ax_ei_interrupt, ax->irqflags,
479 dev->name, dev); 404 dev->name, dev);
480 if (ret) 405 if (ret)
481 return ret; 406 goto failed_request_irq;
482
483 ret = ax_ei_open(dev);
484 if (ret) {
485 free_irq(dev->irq, dev);
486 return ret;
487 }
488 407
489 /* turn the phy on (if turned off) */ 408 /* turn the phy on (if turned off) */
409 ax_phy_switch(dev, 1);
490 410
491 ei_outb(ax->plat->gpoc_val, ei_local->mem + EI_SHIFT(0x17)); 411 ret = ax_mii_probe(dev);
492 ax->running = 1; 412 if (ret)
493 413 goto failed_mii_probe;
494 /* start the MII timer */ 414 phy_start(ax->phy_dev);
495
496 init_timer(&ax->mii_timer);
497 415
498 ax->mii_timer.expires = jiffies+1; 416 ret = ax_ei_open(dev);
499 ax->mii_timer.data = (unsigned long) dev; 417 if (ret)
500 ax->mii_timer.function = ax_mii_expiry; 418 goto failed_ax_ei_open;
501 419
502 add_timer(&ax->mii_timer); 420 ax->running = 1;
503 421
504 return 0; 422 return 0;
423
424 failed_ax_ei_open:
425 phy_disconnect(ax->phy_dev);
426 failed_mii_probe:
427 ax_phy_switch(dev, 0);
428 free_irq(dev->irq, dev);
429 failed_request_irq:
430 return ret;
505} 431}
506 432
507static int ax_close(struct net_device *dev) 433static int ax_close(struct net_device *dev)
508{ 434{
509 struct ax_device *ax = to_ax_dev(dev); 435 struct ax_device *ax = to_ax_dev(dev);
510 struct ei_device *ei_local = netdev_priv(dev);
511 436
512 dev_dbg(&ax->dev->dev, "%s: close\n", dev->name); 437 netdev_dbg(dev, "close\n");
513
514 /* turn the phy off */
515
516 ei_outb(ax->plat->gpoc_val | (1<<6),
517 ei_local->mem + EI_SHIFT(0x17));
518 438
519 ax->running = 0; 439 ax->running = 0;
520 wmb(); 440 wmb();
521 441
522 del_timer_sync(&ax->mii_timer);
523 ax_ei_close(dev); 442 ax_ei_close(dev);
524 443
444 /* turn the phy off */
445 ax_phy_switch(dev, 0);
446 phy_disconnect(ax->phy_dev);
447
525 free_irq(dev->irq, dev); 448 free_irq(dev->irq, dev);
526 return 0; 449 return 0;
527} 450}
@@ -529,17 +452,15 @@ static int ax_close(struct net_device *dev)
529static int ax_ioctl(struct net_device *dev, struct ifreq *req, int cmd) 452static int ax_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
530{ 453{
531 struct ax_device *ax = to_ax_dev(dev); 454 struct ax_device *ax = to_ax_dev(dev);
532 unsigned long flags; 455 struct phy_device *phy_dev = ax->phy_dev;
533 int rc;
534 456
535 if (!netif_running(dev)) 457 if (!netif_running(dev))
536 return -EINVAL; 458 return -EINVAL;
537 459
538 spin_lock_irqsave(&ax->mii_lock, flags); 460 if (!phy_dev)
539 rc = generic_mii_ioctl(&ax->mii, if_mii(req), cmd, NULL); 461 return -ENODEV;
540 spin_unlock_irqrestore(&ax->mii_lock, flags);
541 462
542 return rc; 463 return phy_mii_ioctl(phy_dev, req, cmd);
543} 464}
544 465
545/* ethtool ops */ 466/* ethtool ops */
@@ -547,56 +468,40 @@ static int ax_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
547static void ax_get_drvinfo(struct net_device *dev, 468static void ax_get_drvinfo(struct net_device *dev,
548 struct ethtool_drvinfo *info) 469 struct ethtool_drvinfo *info)
549{ 470{
550 struct ax_device *ax = to_ax_dev(dev); 471 struct platform_device *pdev = to_platform_device(dev->dev.parent);
551 472
552 strcpy(info->driver, DRV_NAME); 473 strcpy(info->driver, DRV_NAME);
553 strcpy(info->version, DRV_VERSION); 474 strcpy(info->version, DRV_VERSION);
554 strcpy(info->bus_info, ax->dev->name); 475 strcpy(info->bus_info, pdev->name);
555} 476}
556 477
557static int ax_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 478static int ax_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
558{ 479{
559 struct ax_device *ax = to_ax_dev(dev); 480 struct ax_device *ax = to_ax_dev(dev);
560 unsigned long flags; 481 struct phy_device *phy_dev = ax->phy_dev;
561 482
562 spin_lock_irqsave(&ax->mii_lock, flags); 483 if (!phy_dev)
563 mii_ethtool_gset(&ax->mii, cmd); 484 return -ENODEV;
564 spin_unlock_irqrestore(&ax->mii_lock, flags);
565 485
566 return 0; 486 return phy_ethtool_gset(phy_dev, cmd);
567} 487}
568 488
569static int ax_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 489static int ax_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
570{ 490{
571 struct ax_device *ax = to_ax_dev(dev); 491 struct ax_device *ax = to_ax_dev(dev);
572 unsigned long flags; 492 struct phy_device *phy_dev = ax->phy_dev;
573 int rc;
574 493
575 spin_lock_irqsave(&ax->mii_lock, flags); 494 if (!phy_dev)
576 rc = mii_ethtool_sset(&ax->mii, cmd); 495 return -ENODEV;
577 spin_unlock_irqrestore(&ax->mii_lock, flags);
578
579 return rc;
580}
581
582static int ax_nway_reset(struct net_device *dev)
583{
584 struct ax_device *ax = to_ax_dev(dev);
585 return mii_nway_restart(&ax->mii);
586}
587 496
588static u32 ax_get_link(struct net_device *dev) 497 return phy_ethtool_sset(phy_dev, cmd);
589{
590 struct ax_device *ax = to_ax_dev(dev);
591 return mii_link_ok(&ax->mii);
592} 498}
593 499
594static const struct ethtool_ops ax_ethtool_ops = { 500static const struct ethtool_ops ax_ethtool_ops = {
595 .get_drvinfo = ax_get_drvinfo, 501 .get_drvinfo = ax_get_drvinfo,
596 .get_settings = ax_get_settings, 502 .get_settings = ax_get_settings,
597 .set_settings = ax_set_settings, 503 .set_settings = ax_set_settings,
598 .nway_reset = ax_nway_reset, 504 .get_link = ethtool_op_get_link,
599 .get_link = ax_get_link,
600}; 505};
601 506
602#ifdef CONFIG_AX88796_93CX6 507#ifdef CONFIG_AX88796_93CX6
@@ -640,37 +545,131 @@ static const struct net_device_ops ax_netdev_ops = {
640 .ndo_get_stats = ax_ei_get_stats, 545 .ndo_get_stats = ax_ei_get_stats,
641 .ndo_set_multicast_list = ax_ei_set_multicast_list, 546 .ndo_set_multicast_list = ax_ei_set_multicast_list,
642 .ndo_validate_addr = eth_validate_addr, 547 .ndo_validate_addr = eth_validate_addr,
643 .ndo_set_mac_address = eth_mac_addr, 548 .ndo_set_mac_address = eth_mac_addr,
644 .ndo_change_mtu = eth_change_mtu, 549 .ndo_change_mtu = eth_change_mtu,
645#ifdef CONFIG_NET_POLL_CONTROLLER 550#ifdef CONFIG_NET_POLL_CONTROLLER
646 .ndo_poll_controller = ax_ei_poll, 551 .ndo_poll_controller = ax_ei_poll,
647#endif 552#endif
648}; 553};
649 554
555static void ax_bb_mdc(struct mdiobb_ctrl *ctrl, int level)
556{
557 struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
558
559 if (level)
560 ax->reg_memr |= AX_MEMR_MDC;
561 else
562 ax->reg_memr &= ~AX_MEMR_MDC;
563
564 ei_outb(ax->reg_memr, ax->addr_memr);
565}
566
567static void ax_bb_dir(struct mdiobb_ctrl *ctrl, int output)
568{
569 struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
570
571 if (output)
572 ax->reg_memr &= ~AX_MEMR_MDIR;
573 else
574 ax->reg_memr |= AX_MEMR_MDIR;
575
576 ei_outb(ax->reg_memr, ax->addr_memr);
577}
578
579static void ax_bb_set_data(struct mdiobb_ctrl *ctrl, int value)
580{
581 struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
582
583 if (value)
584 ax->reg_memr |= AX_MEMR_MDO;
585 else
586 ax->reg_memr &= ~AX_MEMR_MDO;
587
588 ei_outb(ax->reg_memr, ax->addr_memr);
589}
590
591static int ax_bb_get_data(struct mdiobb_ctrl *ctrl)
592{
593 struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
594 int reg_memr = ei_inb(ax->addr_memr);
595
596 return reg_memr & AX_MEMR_MDI ? 1 : 0;
597}
598
599static struct mdiobb_ops bb_ops = {
600 .owner = THIS_MODULE,
601 .set_mdc = ax_bb_mdc,
602 .set_mdio_dir = ax_bb_dir,
603 .set_mdio_data = ax_bb_set_data,
604 .get_mdio_data = ax_bb_get_data,
605};
606
650/* setup code */ 607/* setup code */
651 608
609static int ax_mii_init(struct net_device *dev)
610{
611 struct platform_device *pdev = to_platform_device(dev->dev.parent);
612 struct ei_device *ei_local = netdev_priv(dev);
613 struct ax_device *ax = to_ax_dev(dev);
614 int err, i;
615
616 ax->bb_ctrl.ops = &bb_ops;
617 ax->addr_memr = ei_local->mem + AX_MEMR;
618 ax->mii_bus = alloc_mdio_bitbang(&ax->bb_ctrl);
619 if (!ax->mii_bus) {
620 err = -ENOMEM;
621 goto out;
622 }
623
624 ax->mii_bus->name = "ax88796_mii_bus";
625 ax->mii_bus->parent = dev->dev.parent;
626 snprintf(ax->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id);
627
628 ax->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
629 if (!ax->mii_bus->irq) {
630 err = -ENOMEM;
631 goto out_free_mdio_bitbang;
632 }
633
634 for (i = 0; i < PHY_MAX_ADDR; i++)
635 ax->mii_bus->irq[i] = PHY_POLL;
636
637 err = mdiobus_register(ax->mii_bus);
638 if (err)
639 goto out_free_irq;
640
641 return 0;
642
643 out_free_irq:
644 kfree(ax->mii_bus->irq);
645 out_free_mdio_bitbang:
646 free_mdio_bitbang(ax->mii_bus);
647 out:
648 return err;
649}
650
652static void ax_initial_setup(struct net_device *dev, struct ei_device *ei_local) 651static void ax_initial_setup(struct net_device *dev, struct ei_device *ei_local)
653{ 652{
654 void __iomem *ioaddr = ei_local->mem; 653 void __iomem *ioaddr = ei_local->mem;
655 struct ax_device *ax = to_ax_dev(dev); 654 struct ax_device *ax = to_ax_dev(dev);
656 655
657 /* Select page 0*/ 656 /* Select page 0 */
658 ei_outb(E8390_NODMA+E8390_PAGE0+E8390_STOP, ioaddr + E8390_CMD); 657 ei_outb(E8390_NODMA + E8390_PAGE0 + E8390_STOP, ioaddr + E8390_CMD);
659 658
660 /* set to byte access */ 659 /* set to byte access */
661 ei_outb(ax->plat->dcr_val & ~1, ioaddr + EN0_DCFG); 660 ei_outb(ax->plat->dcr_val & ~1, ioaddr + EN0_DCFG);
662 ei_outb(ax->plat->gpoc_val, ioaddr + EI_SHIFT(0x17)); 661 ei_outb(ax->plat->gpoc_val, ioaddr + EI_SHIFT(0x17));
663} 662}
664 663
665/* ax_init_dev 664/*
665 * ax_init_dev
666 * 666 *
667 * initialise the specified device, taking care to note the MAC 667 * initialise the specified device, taking care to note the MAC
668 * address it may already have (if configured), ensure 668 * address it may already have (if configured), ensure
669 * the device is ready to be used by lib8390.c and registerd with 669 * the device is ready to be used by lib8390.c and registerd with
670 * the network layer. 670 * the network layer.
671 */ 671 */
672 672static int ax_init_dev(struct net_device *dev)
673static int ax_init_dev(struct net_device *dev, int first_init)
674{ 673{
675 struct ei_device *ei_local = netdev_priv(dev); 674 struct ei_device *ei_local = netdev_priv(dev);
676 struct ax_device *ax = to_ax_dev(dev); 675 struct ax_device *ax = to_ax_dev(dev);
@@ -690,23 +689,23 @@ static int ax_init_dev(struct net_device *dev, int first_init)
690 689
691 /* read the mac from the card prom if we need it */ 690 /* read the mac from the card prom if we need it */
692 691
693 if (first_init && ax->plat->flags & AXFLG_HAS_EEPROM) { 692 if (ax->plat->flags & AXFLG_HAS_EEPROM) {
694 unsigned char SA_prom[32]; 693 unsigned char SA_prom[32];
695 694
696 for(i = 0; i < sizeof(SA_prom); i+=2) { 695 for (i = 0; i < sizeof(SA_prom); i += 2) {
697 SA_prom[i] = ei_inb(ioaddr + NE_DATAPORT); 696 SA_prom[i] = ei_inb(ioaddr + NE_DATAPORT);
698 SA_prom[i+1] = ei_inb(ioaddr + NE_DATAPORT); 697 SA_prom[i + 1] = ei_inb(ioaddr + NE_DATAPORT);
699 } 698 }
700 699
701 if (ax->plat->wordlength == 2) 700 if (ax->plat->wordlength == 2)
702 for (i = 0; i < 16; i++) 701 for (i = 0; i < 16; i++)
703 SA_prom[i] = SA_prom[i+i]; 702 SA_prom[i] = SA_prom[i+i];
704 703
705 memcpy(dev->dev_addr, SA_prom, 6); 704 memcpy(dev->dev_addr, SA_prom, 6);
706 } 705 }
707 706
708#ifdef CONFIG_AX88796_93CX6 707#ifdef CONFIG_AX88796_93CX6
709 if (first_init && ax->plat->flags & AXFLG_HAS_93CX6) { 708 if (ax->plat->flags & AXFLG_HAS_93CX6) {
710 unsigned char mac_addr[6]; 709 unsigned char mac_addr[6];
711 struct eeprom_93cx6 eeprom; 710 struct eeprom_93cx6 eeprom;
712 711
@@ -719,7 +718,7 @@ static int ax_init_dev(struct net_device *dev, int first_init)
719 (__le16 __force *)mac_addr, 718 (__le16 __force *)mac_addr,
720 sizeof(mac_addr) >> 1); 719 sizeof(mac_addr) >> 1);
721 720
722 memcpy(dev->dev_addr, mac_addr, 6); 721 memcpy(dev->dev_addr, mac_addr, 6);
723 } 722 }
724#endif 723#endif
725 if (ax->plat->wordlength == 2) { 724 if (ax->plat->wordlength == 2) {
@@ -732,67 +731,56 @@ static int ax_init_dev(struct net_device *dev, int first_init)
732 stop_page = NE1SM_STOP_PG; 731 stop_page = NE1SM_STOP_PG;
733 } 732 }
734 733
735 /* load the mac-address from the device if this is the 734 /* load the mac-address from the device */
736 * first time we've initialised */ 735 if (ax->plat->flags & AXFLG_MAC_FROMDEV) {
737 736 ei_outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP,
738 if (first_init) { 737 ei_local->mem + E8390_CMD); /* 0x61 */
739 if (ax->plat->flags & AXFLG_MAC_FROMDEV) { 738 for (i = 0; i < ETHER_ADDR_LEN; i++)
740 ei_outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP, 739 dev->dev_addr[i] =
741 ei_local->mem + E8390_CMD); /* 0x61 */ 740 ei_inb(ioaddr + EN1_PHYS_SHIFT(i));
742 for (i = 0; i < ETHER_ADDR_LEN; i++)
743 dev->dev_addr[i] =
744 ei_inb(ioaddr + EN1_PHYS_SHIFT(i));
745 }
746
747 if ((ax->plat->flags & AXFLG_MAC_FROMPLATFORM) &&
748 ax->plat->mac_addr)
749 memcpy(dev->dev_addr, ax->plat->mac_addr,
750 ETHER_ADDR_LEN);
751 } 741 }
752 742
743 if ((ax->plat->flags & AXFLG_MAC_FROMPLATFORM) &&
744 ax->plat->mac_addr)
745 memcpy(dev->dev_addr, ax->plat->mac_addr,
746 ETHER_ADDR_LEN);
747
753 ax_reset_8390(dev); 748 ax_reset_8390(dev);
754 749
755 ei_status.name = "AX88796"; 750 ei_local->name = "AX88796";
756 ei_status.tx_start_page = start_page; 751 ei_local->tx_start_page = start_page;
757 ei_status.stop_page = stop_page; 752 ei_local->stop_page = stop_page;
758 ei_status.word16 = (ax->plat->wordlength == 2); 753 ei_local->word16 = (ax->plat->wordlength == 2);
759 ei_status.rx_start_page = start_page + TX_PAGES; 754 ei_local->rx_start_page = start_page + TX_PAGES;
760 755
761#ifdef PACKETBUF_MEMSIZE 756#ifdef PACKETBUF_MEMSIZE
762 /* Allow the packet buffer size to be overridden by know-it-alls. */ 757 /* Allow the packet buffer size to be overridden by know-it-alls. */
763 ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE; 758 ei_local->stop_page = ei_local->tx_start_page + PACKETBUF_MEMSIZE;
764#endif 759#endif
765 760
766 ei_status.reset_8390 = &ax_reset_8390; 761 ei_local->reset_8390 = &ax_reset_8390;
767 ei_status.block_input = &ax_block_input; 762 ei_local->block_input = &ax_block_input;
768 ei_status.block_output = &ax_block_output; 763 ei_local->block_output = &ax_block_output;
769 ei_status.get_8390_hdr = &ax_get_8390_hdr; 764 ei_local->get_8390_hdr = &ax_get_8390_hdr;
770 ei_status.priv = 0; 765 ei_local->priv = 0;
771
772 dev->netdev_ops = &ax_netdev_ops;
773 dev->ethtool_ops = &ax_ethtool_ops;
774
775 ax->msg_enable = NETIF_MSG_LINK;
776 ax->mii.phy_id_mask = 0x1f;
777 ax->mii.reg_num_mask = 0x1f;
778 ax->mii.phy_id = 0x10; /* onboard phy */
779 ax->mii.force_media = 0;
780 ax->mii.full_duplex = 0;
781 ax->mii.mdio_read = ax_phy_read;
782 ax->mii.mdio_write = ax_phy_write;
783 ax->mii.dev = dev;
784 766
785 ax_NS8390_init(dev, 0); 767 dev->netdev_ops = &ax_netdev_ops;
768 dev->ethtool_ops = &ax_ethtool_ops;
786 769
787 if (first_init) 770 ret = ax_mii_init(dev);
788 dev_info(&ax->dev->dev, "%dbit, irq %d, %lx, MAC: %pM\n", 771 if (ret)
789 ei_status.word16 ? 16:8, dev->irq, dev->base_addr, 772 goto out_irq;
790 dev->dev_addr); 773
774 ax_NS8390_init(dev, 0);
791 775
792 ret = register_netdev(dev); 776 ret = register_netdev(dev);
793 if (ret) 777 if (ret)
794 goto out_irq; 778 goto out_irq;
795 779
780 netdev_info(dev, "%dbit, irq %d, %lx, MAC: %pM\n",
781 ei_local->word16 ? 16 : 8, dev->irq, dev->base_addr,
782 dev->dev_addr);
783
796 return 0; 784 return 0;
797 785
798 out_irq: 786 out_irq:
@@ -802,24 +790,24 @@ static int ax_init_dev(struct net_device *dev, int first_init)
802 return ret; 790 return ret;
803} 791}
804 792
805static int ax_remove(struct platform_device *_dev) 793static int ax_remove(struct platform_device *pdev)
806{ 794{
807 struct net_device *dev = platform_get_drvdata(_dev); 795 struct net_device *dev = platform_get_drvdata(pdev);
808 struct ax_device *ax; 796 struct ei_device *ei_local = netdev_priv(dev);
809 797 struct ax_device *ax = to_ax_dev(dev);
810 ax = to_ax_dev(dev); 798 struct resource *mem;
811 799
812 unregister_netdev(dev); 800 unregister_netdev(dev);
813 free_irq(dev->irq, dev); 801 free_irq(dev->irq, dev);
814 802
815 iounmap(ei_status.mem); 803 iounmap(ei_local->mem);
816 release_resource(ax->mem); 804 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
817 kfree(ax->mem); 805 release_mem_region(mem->start, resource_size(mem));
818 806
819 if (ax->map2) { 807 if (ax->map2) {
820 iounmap(ax->map2); 808 iounmap(ax->map2);
821 release_resource(ax->mem2); 809 mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
822 kfree(ax->mem2); 810 release_mem_region(mem->start, resource_size(mem));
823 } 811 }
824 812
825 free_netdev(dev); 813 free_netdev(dev);
@@ -827,19 +815,20 @@ static int ax_remove(struct platform_device *_dev)
827 return 0; 815 return 0;
828} 816}
829 817
830/* ax_probe 818/*
819 * ax_probe
831 * 820 *
832 * This is the entry point when the platform device system uses to 821 * This is the entry point when the platform device system uses to
833 * notify us of a new device to attach to. Allocate memory, find 822 * notify us of a new device to attach to. Allocate memory, find the
834 * the resources and information passed, and map the necessary registers. 823 * resources and information passed, and map the necessary registers.
835*/ 824 */
836
837static int ax_probe(struct platform_device *pdev) 825static int ax_probe(struct platform_device *pdev)
838{ 826{
839 struct net_device *dev; 827 struct net_device *dev;
840 struct ax_device *ax; 828 struct ei_device *ei_local;
841 struct resource *res; 829 struct ax_device *ax;
842 size_t size; 830 struct resource *irq, *mem, *mem2;
831 resource_size_t mem_size, mem2_size = 0;
843 int ret = 0; 832 int ret = 0;
844 833
845 dev = ax__alloc_ei_netdev(sizeof(struct ax_device)); 834 dev = ax__alloc_ei_netdev(sizeof(struct ax_device));
@@ -847,120 +836,107 @@ static int ax_probe(struct platform_device *pdev)
847 return -ENOMEM; 836 return -ENOMEM;
848 837
849 /* ok, let's setup our device */ 838 /* ok, let's setup our device */
839 SET_NETDEV_DEV(dev, &pdev->dev);
840 ei_local = netdev_priv(dev);
850 ax = to_ax_dev(dev); 841 ax = to_ax_dev(dev);
851 842
852 memset(ax, 0, sizeof(struct ax_device));
853
854 spin_lock_init(&ax->mii_lock);
855
856 ax->dev = pdev;
857 ax->plat = pdev->dev.platform_data; 843 ax->plat = pdev->dev.platform_data;
858 platform_set_drvdata(pdev, dev); 844 platform_set_drvdata(pdev, dev);
859 845
860 ei_status.rxcr_base = ax->plat->rcr_val; 846 ei_local->rxcr_base = ax->plat->rcr_val;
861 847
862 /* find the platform resources */ 848 /* find the platform resources */
863 849 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
864 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 850 if (!irq) {
865 if (res == NULL) {
866 dev_err(&pdev->dev, "no IRQ specified\n"); 851 dev_err(&pdev->dev, "no IRQ specified\n");
867 ret = -ENXIO; 852 ret = -ENXIO;
868 goto exit_mem; 853 goto exit_mem;
869 } 854 }
870 855
871 dev->irq = res->start; 856 dev->irq = irq->start;
872 ax->irqflags = res->flags & IRQF_TRIGGER_MASK; 857 ax->irqflags = irq->flags & IRQF_TRIGGER_MASK;
873 858
874 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 859 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
875 if (res == NULL) { 860 if (!mem) {
876 dev_err(&pdev->dev, "no MEM specified\n"); 861 dev_err(&pdev->dev, "no MEM specified\n");
877 ret = -ENXIO; 862 ret = -ENXIO;
878 goto exit_mem; 863 goto exit_mem;
879 } 864 }
880 865
881 size = (res->end - res->start) + 1; 866 mem_size = resource_size(mem);
882
883 /* setup the register offsets from either the platform data
884 * or by using the size of the resource provided */
885 867
868 /*
869 * setup the register offsets from either the platform data or
870 * by using the size of the resource provided
871 */
886 if (ax->plat->reg_offsets) 872 if (ax->plat->reg_offsets)
887 ei_status.reg_offset = ax->plat->reg_offsets; 873 ei_local->reg_offset = ax->plat->reg_offsets;
888 else { 874 else {
889 ei_status.reg_offset = ax->reg_offsets; 875 ei_local->reg_offset = ax->reg_offsets;
890 for (ret = 0; ret < 0x18; ret++) 876 for (ret = 0; ret < 0x18; ret++)
891 ax->reg_offsets[ret] = (size / 0x18) * ret; 877 ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
892 } 878 }
893 879
894 ax->mem = request_mem_region(res->start, size, pdev->name); 880 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
895 if (ax->mem == NULL) {
896 dev_err(&pdev->dev, "cannot reserve registers\n"); 881 dev_err(&pdev->dev, "cannot reserve registers\n");
897 ret = -ENXIO; 882 ret = -ENXIO;
898 goto exit_mem; 883 goto exit_mem;
899 } 884 }
900 885
901 ei_status.mem = ioremap(res->start, size); 886 ei_local->mem = ioremap(mem->start, mem_size);
902 dev->base_addr = (unsigned long)ei_status.mem; 887 dev->base_addr = (unsigned long)ei_local->mem;
903 888
904 if (ei_status.mem == NULL) { 889 if (ei_local->mem == NULL) {
905 dev_err(&pdev->dev, "Cannot ioremap area (%08llx,%08llx)\n", 890 dev_err(&pdev->dev, "Cannot ioremap area %pR\n", mem);
906 (unsigned long long)res->start,
907 (unsigned long long)res->end);
908 891
909 ret = -ENXIO; 892 ret = -ENXIO;
910 goto exit_req; 893 goto exit_req;
911 } 894 }
912 895
913 /* look for reset area */ 896 /* look for reset area */
914 897 mem2 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
915 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 898 if (!mem2) {
916 if (res == NULL) {
917 if (!ax->plat->reg_offsets) { 899 if (!ax->plat->reg_offsets) {
918 for (ret = 0; ret < 0x20; ret++) 900 for (ret = 0; ret < 0x20; ret++)
919 ax->reg_offsets[ret] = (size / 0x20) * ret; 901 ax->reg_offsets[ret] = (mem_size / 0x20) * ret;
920 } 902 }
921
922 ax->map2 = NULL;
923 } else { 903 } else {
924 size = (res->end - res->start) + 1; 904 mem2_size = resource_size(mem2);
925 905
926 ax->mem2 = request_mem_region(res->start, size, pdev->name); 906 if (!request_mem_region(mem2->start, mem2_size, pdev->name)) {
927 if (ax->mem2 == NULL) {
928 dev_err(&pdev->dev, "cannot reserve registers\n"); 907 dev_err(&pdev->dev, "cannot reserve registers\n");
929 ret = -ENXIO; 908 ret = -ENXIO;
930 goto exit_mem1; 909 goto exit_mem1;
931 } 910 }
932 911
933 ax->map2 = ioremap(res->start, size); 912 ax->map2 = ioremap(mem2->start, mem2_size);
934 if (ax->map2 == NULL) { 913 if (!ax->map2) {
935 dev_err(&pdev->dev, "cannot map reset register\n"); 914 dev_err(&pdev->dev, "cannot map reset register\n");
936 ret = -ENXIO; 915 ret = -ENXIO;
937 goto exit_mem2; 916 goto exit_mem2;
938 } 917 }
939 918
940 ei_status.reg_offset[0x1f] = ax->map2 - ei_status.mem; 919 ei_local->reg_offset[0x1f] = ax->map2 - ei_local->mem;
941 } 920 }
942 921
943 /* got resources, now initialise and register device */ 922 /* got resources, now initialise and register device */
944 923 ret = ax_init_dev(dev);
945 ret = ax_init_dev(dev, 1);
946 if (!ret) 924 if (!ret)
947 return 0; 925 return 0;
948 926
949 if (ax->map2 == NULL) 927 if (!ax->map2)
950 goto exit_mem1; 928 goto exit_mem1;
951 929
952 iounmap(ax->map2); 930 iounmap(ax->map2);
953 931
954 exit_mem2: 932 exit_mem2:
955 release_resource(ax->mem2); 933 release_mem_region(mem2->start, mem2_size);
956 kfree(ax->mem2);
957 934
958 exit_mem1: 935 exit_mem1:
959 iounmap(ei_status.mem); 936 iounmap(ei_local->mem);
960 937
961 exit_req: 938 exit_req:
962 release_resource(ax->mem); 939 release_mem_region(mem->start, mem_size);
963 kfree(ax->mem);
964 940
965 exit_mem: 941 exit_mem:
966 free_netdev(dev); 942 free_netdev(dev);
@@ -974,7 +950,7 @@ static int ax_probe(struct platform_device *pdev)
974static int ax_suspend(struct platform_device *dev, pm_message_t state) 950static int ax_suspend(struct platform_device *dev, pm_message_t state)
975{ 951{
976 struct net_device *ndev = platform_get_drvdata(dev); 952 struct net_device *ndev = platform_get_drvdata(dev);
977 struct ax_device *ax = to_ax_dev(ndev); 953 struct ax_device *ax = to_ax_dev(ndev);
978 954
979 ax->resume_open = ax->running; 955 ax->resume_open = ax->running;
980 956
@@ -987,7 +963,7 @@ static int ax_suspend(struct platform_device *dev, pm_message_t state)
987static int ax_resume(struct platform_device *pdev) 963static int ax_resume(struct platform_device *pdev)
988{ 964{
989 struct net_device *ndev = platform_get_drvdata(pdev); 965 struct net_device *ndev = platform_get_drvdata(pdev);
990 struct ax_device *ax = to_ax_dev(ndev); 966 struct ax_device *ax = to_ax_dev(ndev);
991 967
992 ax_initial_setup(ndev, netdev_priv(ndev)); 968 ax_initial_setup(ndev, netdev_priv(ndev));
993 ax_NS8390_init(ndev, ax->resume_open); 969 ax_NS8390_init(ndev, ax->resume_open);
@@ -1001,7 +977,7 @@ static int ax_resume(struct platform_device *pdev)
1001 977
1002#else 978#else
1003#define ax_suspend NULL 979#define ax_suspend NULL
1004#define ax_resume NULL 980#define ax_resume NULL
1005#endif 981#endif
1006 982
1007static struct platform_driver axdrv = { 983static struct platform_driver axdrv = {