diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/net/a2065.c |
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/net/a2065.c')
-rw-r--r-- | drivers/net/a2065.c | 843 |
1 files changed, 843 insertions, 0 deletions
diff --git a/drivers/net/a2065.c b/drivers/net/a2065.c new file mode 100644 index 00000000000..8e538a6d7d9 --- /dev/null +++ b/drivers/net/a2065.c | |||
@@ -0,0 +1,843 @@ | |||
1 | /* | ||
2 | * Amiga Linux/68k A2065 Ethernet Driver | ||
3 | * | ||
4 | * (C) Copyright 1995-2003 by Geert Uytterhoeven <geert@linux-m68k.org> | ||
5 | * | ||
6 | * Fixes and tips by: | ||
7 | * - Janos Farkas (CHEXUM@sparta.banki.hu) | ||
8 | * - Jes Degn Soerensen (jds@kom.auc.dk) | ||
9 | * - Matt Domsch (Matt_Domsch@dell.com) | ||
10 | * | ||
11 | * ---------------------------------------------------------------------------- | ||
12 | * | ||
13 | * This program is based on | ||
14 | * | ||
15 | * ariadne.?: Amiga Linux/68k Ariadne Ethernet Driver | ||
16 | * (C) Copyright 1995 by Geert Uytterhoeven, | ||
17 | * Peter De Schrijver | ||
18 | * | ||
19 | * lance.c: An AMD LANCE ethernet driver for linux. | ||
20 | * Written 1993-94 by Donald Becker. | ||
21 | * | ||
22 | * Am79C960: PCnet(tm)-ISA Single-Chip Ethernet Controller | ||
23 | * Advanced Micro Devices | ||
24 | * Publication #16907, Rev. B, Amendment/0, May 1994 | ||
25 | * | ||
26 | * ---------------------------------------------------------------------------- | ||
27 | * | ||
28 | * This file is subject to the terms and conditions of the GNU General Public | ||
29 | * License. See the file COPYING in the main directory of the Linux | ||
30 | * distribution for more details. | ||
31 | * | ||
32 | * ---------------------------------------------------------------------------- | ||
33 | * | ||
34 | * The A2065 is a Zorro-II board made by Commodore/Ameristar. It contains: | ||
35 | * | ||
36 | * - an Am7990 Local Area Network Controller for Ethernet (LANCE) with | ||
37 | * both 10BASE-2 (thin coax) and AUI (DB-15) connectors | ||
38 | */ | ||
39 | |||
40 | #include <linux/errno.h> | ||
41 | #include <linux/netdevice.h> | ||
42 | #include <linux/etherdevice.h> | ||
43 | #include <linux/module.h> | ||
44 | #include <linux/stddef.h> | ||
45 | #include <linux/kernel.h> | ||
46 | #include <linux/interrupt.h> | ||
47 | #include <linux/ioport.h> | ||
48 | #include <linux/skbuff.h> | ||
49 | #include <linux/slab.h> | ||
50 | #include <linux/string.h> | ||
51 | #include <linux/config.h> | ||
52 | #include <linux/init.h> | ||
53 | #include <linux/crc32.h> | ||
54 | #include <linux/zorro.h> | ||
55 | #include <linux/bitops.h> | ||
56 | |||
57 | #include <asm/irq.h> | ||
58 | #include <asm/amigaints.h> | ||
59 | #include <asm/amigahw.h> | ||
60 | |||
61 | #include "a2065.h" | ||
62 | |||
63 | |||
64 | /* | ||
65 | * Transmit/Receive Ring Definitions | ||
66 | */ | ||
67 | |||
68 | #define LANCE_LOG_TX_BUFFERS (2) | ||
69 | #define LANCE_LOG_RX_BUFFERS (4) | ||
70 | |||
71 | #define TX_RING_SIZE (1<<LANCE_LOG_TX_BUFFERS) | ||
72 | #define RX_RING_SIZE (1<<LANCE_LOG_RX_BUFFERS) | ||
73 | |||
74 | #define TX_RING_MOD_MASK (TX_RING_SIZE-1) | ||
75 | #define RX_RING_MOD_MASK (RX_RING_SIZE-1) | ||
76 | |||
77 | #define PKT_BUF_SIZE (1544) | ||
78 | #define RX_BUFF_SIZE PKT_BUF_SIZE | ||
79 | #define TX_BUFF_SIZE PKT_BUF_SIZE | ||
80 | |||
81 | |||
82 | /* | ||
83 | * Layout of the Lance's RAM Buffer | ||
84 | */ | ||
85 | |||
86 | |||
87 | struct lance_init_block { | ||
88 | unsigned short mode; /* Pre-set mode (reg. 15) */ | ||
89 | unsigned char phys_addr[6]; /* Physical ethernet address */ | ||
90 | unsigned filter[2]; /* Multicast filter. */ | ||
91 | |||
92 | /* Receive and transmit ring base, along with extra bits. */ | ||
93 | unsigned short rx_ptr; /* receive descriptor addr */ | ||
94 | unsigned short rx_len; /* receive len and high addr */ | ||
95 | unsigned short tx_ptr; /* transmit descriptor addr */ | ||
96 | unsigned short tx_len; /* transmit len and high addr */ | ||
97 | |||
98 | /* The Tx and Rx ring entries must aligned on 8-byte boundaries. */ | ||
99 | struct lance_rx_desc brx_ring[RX_RING_SIZE]; | ||
100 | struct lance_tx_desc btx_ring[TX_RING_SIZE]; | ||
101 | |||
102 | char rx_buf [RX_RING_SIZE][RX_BUFF_SIZE]; | ||
103 | char tx_buf [TX_RING_SIZE][TX_BUFF_SIZE]; | ||
104 | }; | ||
105 | |||
106 | |||
107 | /* | ||
108 | * Private Device Data | ||
109 | */ | ||
110 | |||
111 | struct lance_private { | ||
112 | char *name; | ||
113 | volatile struct lance_regs *ll; | ||
114 | volatile struct lance_init_block *init_block; /* Hosts view */ | ||
115 | volatile struct lance_init_block *lance_init_block; /* Lance view */ | ||
116 | |||
117 | int rx_new, tx_new; | ||
118 | int rx_old, tx_old; | ||
119 | |||
120 | int lance_log_rx_bufs, lance_log_tx_bufs; | ||
121 | int rx_ring_mod_mask, tx_ring_mod_mask; | ||
122 | |||
123 | struct net_device_stats stats; | ||
124 | int tpe; /* cable-selection is TPE */ | ||
125 | int auto_select; /* cable-selection by carrier */ | ||
126 | unsigned short busmaster_regval; | ||
127 | |||
128 | #ifdef CONFIG_SUNLANCE | ||
129 | struct Linux_SBus_DMA *ledma; /* if set this points to ledma and arch=4m */ | ||
130 | int burst_sizes; /* ledma SBus burst sizes */ | ||
131 | #endif | ||
132 | struct timer_list multicast_timer; | ||
133 | }; | ||
134 | |||
135 | #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\ | ||
136 | lp->tx_old+lp->tx_ring_mod_mask-lp->tx_new:\ | ||
137 | lp->tx_old - lp->tx_new-1) | ||
138 | |||
139 | |||
140 | #define LANCE_ADDR(x) ((int)(x) & ~0xff000000) | ||
141 | |||
142 | /* Load the CSR registers */ | ||
143 | static void load_csrs (struct lance_private *lp) | ||
144 | { | ||
145 | volatile struct lance_regs *ll = lp->ll; | ||
146 | volatile struct lance_init_block *aib = lp->lance_init_block; | ||
147 | int leptr; | ||
148 | |||
149 | leptr = LANCE_ADDR (aib); | ||
150 | |||
151 | ll->rap = LE_CSR1; | ||
152 | ll->rdp = (leptr & 0xFFFF); | ||
153 | ll->rap = LE_CSR2; | ||
154 | ll->rdp = leptr >> 16; | ||
155 | ll->rap = LE_CSR3; | ||
156 | ll->rdp = lp->busmaster_regval; | ||
157 | |||
158 | /* Point back to csr0 */ | ||
159 | ll->rap = LE_CSR0; | ||
160 | } | ||
161 | |||
162 | #define ZERO 0 | ||
163 | |||
164 | /* Setup the Lance Rx and Tx rings */ | ||
165 | static void lance_init_ring (struct net_device *dev) | ||
166 | { | ||
167 | struct lance_private *lp = netdev_priv(dev); | ||
168 | volatile struct lance_init_block *ib = lp->init_block; | ||
169 | volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */ | ||
170 | int leptr; | ||
171 | int i; | ||
172 | |||
173 | aib = lp->lance_init_block; | ||
174 | |||
175 | /* Lock out other processes while setting up hardware */ | ||
176 | netif_stop_queue(dev); | ||
177 | lp->rx_new = lp->tx_new = 0; | ||
178 | lp->rx_old = lp->tx_old = 0; | ||
179 | |||
180 | ib->mode = 0; | ||
181 | |||
182 | /* Copy the ethernet address to the lance init block | ||
183 | * Note that on the sparc you need to swap the ethernet address. | ||
184 | */ | ||
185 | ib->phys_addr [0] = dev->dev_addr [1]; | ||
186 | ib->phys_addr [1] = dev->dev_addr [0]; | ||
187 | ib->phys_addr [2] = dev->dev_addr [3]; | ||
188 | ib->phys_addr [3] = dev->dev_addr [2]; | ||
189 | ib->phys_addr [4] = dev->dev_addr [5]; | ||
190 | ib->phys_addr [5] = dev->dev_addr [4]; | ||
191 | |||
192 | if (ZERO) | ||
193 | printk(KERN_DEBUG "TX rings:\n"); | ||
194 | |||
195 | /* Setup the Tx ring entries */ | ||
196 | for (i = 0; i <= (1<<lp->lance_log_tx_bufs); i++) { | ||
197 | leptr = LANCE_ADDR(&aib->tx_buf[i][0]); | ||
198 | ib->btx_ring [i].tmd0 = leptr; | ||
199 | ib->btx_ring [i].tmd1_hadr = leptr >> 16; | ||
200 | ib->btx_ring [i].tmd1_bits = 0; | ||
201 | ib->btx_ring [i].length = 0xf000; /* The ones required by tmd2 */ | ||
202 | ib->btx_ring [i].misc = 0; | ||
203 | if (i < 3 && ZERO) | ||
204 | printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr); | ||
205 | } | ||
206 | |||
207 | /* Setup the Rx ring entries */ | ||
208 | if (ZERO) | ||
209 | printk(KERN_DEBUG "RX rings:\n"); | ||
210 | for (i = 0; i < (1<<lp->lance_log_rx_bufs); i++) { | ||
211 | leptr = LANCE_ADDR(&aib->rx_buf[i][0]); | ||
212 | |||
213 | ib->brx_ring [i].rmd0 = leptr; | ||
214 | ib->brx_ring [i].rmd1_hadr = leptr >> 16; | ||
215 | ib->brx_ring [i].rmd1_bits = LE_R1_OWN; | ||
216 | ib->brx_ring [i].length = -RX_BUFF_SIZE | 0xf000; | ||
217 | ib->brx_ring [i].mblength = 0; | ||
218 | if (i < 3 && ZERO) | ||
219 | printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr); | ||
220 | } | ||
221 | |||
222 | /* Setup the initialization block */ | ||
223 | |||
224 | /* Setup rx descriptor pointer */ | ||
225 | leptr = LANCE_ADDR(&aib->brx_ring); | ||
226 | ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16); | ||
227 | ib->rx_ptr = leptr; | ||
228 | if (ZERO) | ||
229 | printk(KERN_DEBUG "RX ptr: %8.8x\n", leptr); | ||
230 | |||
231 | /* Setup tx descriptor pointer */ | ||
232 | leptr = LANCE_ADDR(&aib->btx_ring); | ||
233 | ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16); | ||
234 | ib->tx_ptr = leptr; | ||
235 | if (ZERO) | ||
236 | printk(KERN_DEBUG "TX ptr: %8.8x\n", leptr); | ||
237 | |||
238 | /* Clear the multicast filter */ | ||
239 | ib->filter [0] = 0; | ||
240 | ib->filter [1] = 0; | ||
241 | } | ||
242 | |||
243 | static int init_restart_lance (struct lance_private *lp) | ||
244 | { | ||
245 | volatile struct lance_regs *ll = lp->ll; | ||
246 | int i; | ||
247 | |||
248 | ll->rap = LE_CSR0; | ||
249 | ll->rdp = LE_C0_INIT; | ||
250 | |||
251 | /* Wait for the lance to complete initialization */ | ||
252 | for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++) | ||
253 | barrier(); | ||
254 | if ((i == 100) || (ll->rdp & LE_C0_ERR)) { | ||
255 | printk(KERN_ERR "LANCE unopened after %d ticks, csr0=%4.4x.\n", | ||
256 | i, ll->rdp); | ||
257 | return -EIO; | ||
258 | } | ||
259 | |||
260 | /* Clear IDON by writing a "1", enable interrupts and start lance */ | ||
261 | ll->rdp = LE_C0_IDON; | ||
262 | ll->rdp = LE_C0_INEA | LE_C0_STRT; | ||
263 | |||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | static int lance_rx (struct net_device *dev) | ||
268 | { | ||
269 | struct lance_private *lp = netdev_priv(dev); | ||
270 | volatile struct lance_init_block *ib = lp->init_block; | ||
271 | volatile struct lance_regs *ll = lp->ll; | ||
272 | volatile struct lance_rx_desc *rd; | ||
273 | unsigned char bits; | ||
274 | int len = 0; /* XXX shut up gcc warnings */ | ||
275 | struct sk_buff *skb = 0; /* XXX shut up gcc warnings */ | ||
276 | |||
277 | #ifdef TEST_HITS | ||
278 | int i; | ||
279 | printk(KERN_DEBUG "["); | ||
280 | for (i = 0; i < RX_RING_SIZE; i++) { | ||
281 | if (i == lp->rx_new) | ||
282 | printk ("%s", | ||
283 | ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "_" : "X"); | ||
284 | else | ||
285 | printk ("%s", | ||
286 | ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "." : "1"); | ||
287 | } | ||
288 | printk ("]\n"); | ||
289 | #endif | ||
290 | |||
291 | ll->rdp = LE_C0_RINT|LE_C0_INEA; | ||
292 | for (rd = &ib->brx_ring [lp->rx_new]; | ||
293 | !((bits = rd->rmd1_bits) & LE_R1_OWN); | ||
294 | rd = &ib->brx_ring [lp->rx_new]) { | ||
295 | |||
296 | /* We got an incomplete frame? */ | ||
297 | if ((bits & LE_R1_POK) != LE_R1_POK) { | ||
298 | lp->stats.rx_over_errors++; | ||
299 | lp->stats.rx_errors++; | ||
300 | continue; | ||
301 | } else if (bits & LE_R1_ERR) { | ||
302 | /* Count only the end frame as a rx error, | ||
303 | * not the beginning | ||
304 | */ | ||
305 | if (bits & LE_R1_BUF) lp->stats.rx_fifo_errors++; | ||
306 | if (bits & LE_R1_CRC) lp->stats.rx_crc_errors++; | ||
307 | if (bits & LE_R1_OFL) lp->stats.rx_over_errors++; | ||
308 | if (bits & LE_R1_FRA) lp->stats.rx_frame_errors++; | ||
309 | if (bits & LE_R1_EOP) lp->stats.rx_errors++; | ||
310 | } else { | ||
311 | len = (rd->mblength & 0xfff) - 4; | ||
312 | skb = dev_alloc_skb (len+2); | ||
313 | |||
314 | if (skb == 0) { | ||
315 | printk(KERN_WARNING "%s: Memory squeeze, " | ||
316 | "deferring packet.\n", dev->name); | ||
317 | lp->stats.rx_dropped++; | ||
318 | rd->mblength = 0; | ||
319 | rd->rmd1_bits = LE_R1_OWN; | ||
320 | lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask; | ||
321 | return 0; | ||
322 | } | ||
323 | |||
324 | skb->dev = dev; | ||
325 | skb_reserve (skb, 2); /* 16 byte align */ | ||
326 | skb_put (skb, len); /* make room */ | ||
327 | eth_copy_and_sum(skb, | ||
328 | (unsigned char *)&(ib->rx_buf [lp->rx_new][0]), | ||
329 | len, 0); | ||
330 | skb->protocol = eth_type_trans (skb, dev); | ||
331 | netif_rx (skb); | ||
332 | dev->last_rx = jiffies; | ||
333 | lp->stats.rx_packets++; | ||
334 | lp->stats.rx_bytes += len; | ||
335 | } | ||
336 | |||
337 | /* Return the packet to the pool */ | ||
338 | rd->mblength = 0; | ||
339 | rd->rmd1_bits = LE_R1_OWN; | ||
340 | lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask; | ||
341 | } | ||
342 | return 0; | ||
343 | } | ||
344 | |||
345 | static int lance_tx (struct net_device *dev) | ||
346 | { | ||
347 | struct lance_private *lp = netdev_priv(dev); | ||
348 | volatile struct lance_init_block *ib = lp->init_block; | ||
349 | volatile struct lance_regs *ll = lp->ll; | ||
350 | volatile struct lance_tx_desc *td; | ||
351 | int i, j; | ||
352 | int status; | ||
353 | |||
354 | /* csr0 is 2f3 */ | ||
355 | ll->rdp = LE_C0_TINT | LE_C0_INEA; | ||
356 | /* csr0 is 73 */ | ||
357 | |||
358 | j = lp->tx_old; | ||
359 | for (i = j; i != lp->tx_new; i = j) { | ||
360 | td = &ib->btx_ring [i]; | ||
361 | |||
362 | /* If we hit a packet not owned by us, stop */ | ||
363 | if (td->tmd1_bits & LE_T1_OWN) | ||
364 | break; | ||
365 | |||
366 | if (td->tmd1_bits & LE_T1_ERR) { | ||
367 | status = td->misc; | ||
368 | |||
369 | lp->stats.tx_errors++; | ||
370 | if (status & LE_T3_RTY) lp->stats.tx_aborted_errors++; | ||
371 | if (status & LE_T3_LCOL) lp->stats.tx_window_errors++; | ||
372 | |||
373 | if (status & LE_T3_CLOS) { | ||
374 | lp->stats.tx_carrier_errors++; | ||
375 | if (lp->auto_select) { | ||
376 | lp->tpe = 1 - lp->tpe; | ||
377 | printk(KERN_ERR "%s: Carrier Lost, " | ||
378 | "trying %s\n", dev->name, | ||
379 | lp->tpe?"TPE":"AUI"); | ||
380 | /* Stop the lance */ | ||
381 | ll->rap = LE_CSR0; | ||
382 | ll->rdp = LE_C0_STOP; | ||
383 | lance_init_ring (dev); | ||
384 | load_csrs (lp); | ||
385 | init_restart_lance (lp); | ||
386 | return 0; | ||
387 | } | ||
388 | } | ||
389 | |||
390 | /* buffer errors and underflows turn off the transmitter */ | ||
391 | /* Restart the adapter */ | ||
392 | if (status & (LE_T3_BUF|LE_T3_UFL)) { | ||
393 | lp->stats.tx_fifo_errors++; | ||
394 | |||
395 | printk(KERN_ERR "%s: Tx: ERR_BUF|ERR_UFL, " | ||
396 | "restarting\n", dev->name); | ||
397 | /* Stop the lance */ | ||
398 | ll->rap = LE_CSR0; | ||
399 | ll->rdp = LE_C0_STOP; | ||
400 | lance_init_ring (dev); | ||
401 | load_csrs (lp); | ||
402 | init_restart_lance (lp); | ||
403 | return 0; | ||
404 | } | ||
405 | } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) { | ||
406 | /* | ||
407 | * So we don't count the packet more than once. | ||
408 | */ | ||
409 | td->tmd1_bits &= ~(LE_T1_POK); | ||
410 | |||
411 | /* One collision before packet was sent. */ | ||
412 | if (td->tmd1_bits & LE_T1_EONE) | ||
413 | lp->stats.collisions++; | ||
414 | |||
415 | /* More than one collision, be optimistic. */ | ||
416 | if (td->tmd1_bits & LE_T1_EMORE) | ||
417 | lp->stats.collisions += 2; | ||
418 | |||
419 | lp->stats.tx_packets++; | ||
420 | } | ||
421 | |||
422 | j = (j + 1) & lp->tx_ring_mod_mask; | ||
423 | } | ||
424 | lp->tx_old = j; | ||
425 | ll->rdp = LE_C0_TINT | LE_C0_INEA; | ||
426 | return 0; | ||
427 | } | ||
428 | |||
429 | static irqreturn_t | ||
430 | lance_interrupt (int irq, void *dev_id, struct pt_regs *regs) | ||
431 | { | ||
432 | struct net_device *dev; | ||
433 | struct lance_private *lp; | ||
434 | volatile struct lance_regs *ll; | ||
435 | int csr0; | ||
436 | |||
437 | dev = (struct net_device *) dev_id; | ||
438 | |||
439 | lp = netdev_priv(dev); | ||
440 | ll = lp->ll; | ||
441 | |||
442 | ll->rap = LE_CSR0; /* LANCE Controller Status */ | ||
443 | csr0 = ll->rdp; | ||
444 | |||
445 | if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */ | ||
446 | return IRQ_NONE; /* been generated by the Lance. */ | ||
447 | |||
448 | /* Acknowledge all the interrupt sources ASAP */ | ||
449 | ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT| | ||
450 | LE_C0_INIT); | ||
451 | |||
452 | if ((csr0 & LE_C0_ERR)) { | ||
453 | /* Clear the error condition */ | ||
454 | ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA; | ||
455 | } | ||
456 | |||
457 | if (csr0 & LE_C0_RINT) | ||
458 | lance_rx (dev); | ||
459 | |||
460 | if (csr0 & LE_C0_TINT) | ||
461 | lance_tx (dev); | ||
462 | |||
463 | /* Log misc errors. */ | ||
464 | if (csr0 & LE_C0_BABL) | ||
465 | lp->stats.tx_errors++; /* Tx babble. */ | ||
466 | if (csr0 & LE_C0_MISS) | ||
467 | lp->stats.rx_errors++; /* Missed a Rx frame. */ | ||
468 | if (csr0 & LE_C0_MERR) { | ||
469 | printk(KERN_ERR "%s: Bus master arbitration failure, status " | ||
470 | "%4.4x.\n", dev->name, csr0); | ||
471 | /* Restart the chip. */ | ||
472 | ll->rdp = LE_C0_STRT; | ||
473 | } | ||
474 | |||
475 | if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0) | ||
476 | netif_wake_queue(dev); | ||
477 | |||
478 | ll->rap = LE_CSR0; | ||
479 | ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR| | ||
480 | LE_C0_IDON|LE_C0_INEA; | ||
481 | return IRQ_HANDLED; | ||
482 | } | ||
483 | |||
484 | struct net_device *last_dev = 0; | ||
485 | |||
486 | static int lance_open (struct net_device *dev) | ||
487 | { | ||
488 | struct lance_private *lp = netdev_priv(dev); | ||
489 | volatile struct lance_regs *ll = lp->ll; | ||
490 | int ret; | ||
491 | |||
492 | last_dev = dev; | ||
493 | |||
494 | /* Stop the Lance */ | ||
495 | ll->rap = LE_CSR0; | ||
496 | ll->rdp = LE_C0_STOP; | ||
497 | |||
498 | /* Install the Interrupt handler */ | ||
499 | ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, SA_SHIRQ, | ||
500 | dev->name, dev); | ||
501 | if (ret) return ret; | ||
502 | |||
503 | load_csrs (lp); | ||
504 | lance_init_ring (dev); | ||
505 | |||
506 | netif_start_queue(dev); | ||
507 | |||
508 | return init_restart_lance (lp); | ||
509 | } | ||
510 | |||
511 | static int lance_close (struct net_device *dev) | ||
512 | { | ||
513 | struct lance_private *lp = netdev_priv(dev); | ||
514 | volatile struct lance_regs *ll = lp->ll; | ||
515 | |||
516 | netif_stop_queue(dev); | ||
517 | del_timer_sync(&lp->multicast_timer); | ||
518 | |||
519 | /* Stop the card */ | ||
520 | ll->rap = LE_CSR0; | ||
521 | ll->rdp = LE_C0_STOP; | ||
522 | |||
523 | free_irq(IRQ_AMIGA_PORTS, dev); | ||
524 | return 0; | ||
525 | } | ||
526 | |||
527 | static inline int lance_reset (struct net_device *dev) | ||
528 | { | ||
529 | struct lance_private *lp = netdev_priv(dev); | ||
530 | volatile struct lance_regs *ll = lp->ll; | ||
531 | int status; | ||
532 | |||
533 | /* Stop the lance */ | ||
534 | ll->rap = LE_CSR0; | ||
535 | ll->rdp = LE_C0_STOP; | ||
536 | |||
537 | load_csrs (lp); | ||
538 | |||
539 | lance_init_ring (dev); | ||
540 | dev->trans_start = jiffies; | ||
541 | netif_start_queue(dev); | ||
542 | |||
543 | status = init_restart_lance (lp); | ||
544 | #ifdef DEBUG_DRIVER | ||
545 | printk(KERN_DEBUG "Lance restart=%d\n", status); | ||
546 | #endif | ||
547 | return status; | ||
548 | } | ||
549 | |||
550 | static void lance_tx_timeout(struct net_device *dev) | ||
551 | { | ||
552 | struct lance_private *lp = netdev_priv(dev); | ||
553 | volatile struct lance_regs *ll = lp->ll; | ||
554 | |||
555 | printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n", | ||
556 | dev->name, ll->rdp); | ||
557 | lance_reset(dev); | ||
558 | netif_wake_queue(dev); | ||
559 | } | ||
560 | |||
561 | static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev) | ||
562 | { | ||
563 | struct lance_private *lp = netdev_priv(dev); | ||
564 | volatile struct lance_regs *ll = lp->ll; | ||
565 | volatile struct lance_init_block *ib = lp->init_block; | ||
566 | int entry, skblen, len; | ||
567 | int status = 0; | ||
568 | static int outs; | ||
569 | unsigned long flags; | ||
570 | |||
571 | skblen = skb->len; | ||
572 | len = skblen; | ||
573 | |||
574 | if (len < ETH_ZLEN) { | ||
575 | len = ETH_ZLEN; | ||
576 | skb = skb_padto(skb, ETH_ZLEN); | ||
577 | if (skb == NULL) | ||
578 | return 0; | ||
579 | } | ||
580 | |||
581 | local_irq_save(flags); | ||
582 | |||
583 | if (!TX_BUFFS_AVAIL){ | ||
584 | local_irq_restore(flags); | ||
585 | return -1; | ||
586 | } | ||
587 | |||
588 | #ifdef DEBUG_DRIVER | ||
589 | /* dump the packet */ | ||
590 | { | ||
591 | int i; | ||
592 | |||
593 | for (i = 0; i < 64; i++) { | ||
594 | if ((i % 16) == 0) | ||
595 | printk("\n" KERN_DEBUG); | ||
596 | printk ("%2.2x ", skb->data [i]); | ||
597 | } | ||
598 | printk("\n"); | ||
599 | } | ||
600 | #endif | ||
601 | entry = lp->tx_new & lp->tx_ring_mod_mask; | ||
602 | ib->btx_ring [entry].length = (-len) | 0xf000; | ||
603 | ib->btx_ring [entry].misc = 0; | ||
604 | |||
605 | memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen); | ||
606 | |||
607 | /* Clear the slack of the packet, do I need this? */ | ||
608 | if (len != skblen) | ||
609 | memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen); | ||
610 | |||
611 | /* Now, give the packet to the lance */ | ||
612 | ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN); | ||
613 | lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask; | ||
614 | |||
615 | outs++; | ||
616 | |||
617 | if (TX_BUFFS_AVAIL <= 0) | ||
618 | netif_stop_queue(dev); | ||
619 | |||
620 | /* Kick the lance: transmit now */ | ||
621 | ll->rdp = LE_C0_INEA | LE_C0_TDMD; | ||
622 | dev->trans_start = jiffies; | ||
623 | dev_kfree_skb (skb); | ||
624 | |||
625 | local_irq_restore(flags); | ||
626 | |||
627 | return status; | ||
628 | } | ||
629 | |||
630 | static struct net_device_stats *lance_get_stats (struct net_device *dev) | ||
631 | { | ||
632 | struct lance_private *lp = netdev_priv(dev); | ||
633 | |||
634 | return &lp->stats; | ||
635 | } | ||
636 | |||
637 | /* taken from the depca driver */ | ||
638 | static void lance_load_multicast (struct net_device *dev) | ||
639 | { | ||
640 | struct lance_private *lp = netdev_priv(dev); | ||
641 | volatile struct lance_init_block *ib = lp->init_block; | ||
642 | volatile u16 *mcast_table = (u16 *)&ib->filter; | ||
643 | struct dev_mc_list *dmi=dev->mc_list; | ||
644 | char *addrs; | ||
645 | int i; | ||
646 | u32 crc; | ||
647 | |||
648 | /* set all multicast bits */ | ||
649 | if (dev->flags & IFF_ALLMULTI){ | ||
650 | ib->filter [0] = 0xffffffff; | ||
651 | ib->filter [1] = 0xffffffff; | ||
652 | return; | ||
653 | } | ||
654 | /* clear the multicast filter */ | ||
655 | ib->filter [0] = 0; | ||
656 | ib->filter [1] = 0; | ||
657 | |||
658 | /* Add addresses */ | ||
659 | for (i = 0; i < dev->mc_count; i++){ | ||
660 | addrs = dmi->dmi_addr; | ||
661 | dmi = dmi->next; | ||
662 | |||
663 | /* multicast address? */ | ||
664 | if (!(*addrs & 1)) | ||
665 | continue; | ||
666 | |||
667 | crc = ether_crc_le(6, addrs); | ||
668 | crc = crc >> 26; | ||
669 | mcast_table [crc >> 4] |= 1 << (crc & 0xf); | ||
670 | } | ||
671 | return; | ||
672 | } | ||
673 | |||
674 | static void lance_set_multicast (struct net_device *dev) | ||
675 | { | ||
676 | struct lance_private *lp = netdev_priv(dev); | ||
677 | volatile struct lance_init_block *ib = lp->init_block; | ||
678 | volatile struct lance_regs *ll = lp->ll; | ||
679 | |||
680 | if (!netif_running(dev)) | ||
681 | return; | ||
682 | |||
683 | if (lp->tx_old != lp->tx_new) { | ||
684 | mod_timer(&lp->multicast_timer, jiffies + 4); | ||
685 | netif_wake_queue(dev); | ||
686 | return; | ||
687 | } | ||
688 | |||
689 | netif_stop_queue(dev); | ||
690 | |||
691 | ll->rap = LE_CSR0; | ||
692 | ll->rdp = LE_C0_STOP; | ||
693 | lance_init_ring (dev); | ||
694 | |||
695 | if (dev->flags & IFF_PROMISC) { | ||
696 | ib->mode |= LE_MO_PROM; | ||
697 | } else { | ||
698 | ib->mode &= ~LE_MO_PROM; | ||
699 | lance_load_multicast (dev); | ||
700 | } | ||
701 | load_csrs (lp); | ||
702 | init_restart_lance (lp); | ||
703 | netif_wake_queue(dev); | ||
704 | } | ||
705 | |||
706 | static int __devinit a2065_init_one(struct zorro_dev *z, | ||
707 | const struct zorro_device_id *ent); | ||
708 | static void __devexit a2065_remove_one(struct zorro_dev *z); | ||
709 | |||
710 | |||
711 | static struct zorro_device_id a2065_zorro_tbl[] __devinitdata = { | ||
712 | { ZORRO_PROD_CBM_A2065_1 }, | ||
713 | { ZORRO_PROD_CBM_A2065_2 }, | ||
714 | { ZORRO_PROD_AMERISTAR_A2065 }, | ||
715 | { 0 } | ||
716 | }; | ||
717 | |||
718 | static struct zorro_driver a2065_driver = { | ||
719 | .name = "a2065", | ||
720 | .id_table = a2065_zorro_tbl, | ||
721 | .probe = a2065_init_one, | ||
722 | .remove = __devexit_p(a2065_remove_one), | ||
723 | }; | ||
724 | |||
725 | static int __devinit a2065_init_one(struct zorro_dev *z, | ||
726 | const struct zorro_device_id *ent) | ||
727 | { | ||
728 | struct net_device *dev; | ||
729 | struct lance_private *priv; | ||
730 | unsigned long board, base_addr, mem_start; | ||
731 | struct resource *r1, *r2; | ||
732 | int err; | ||
733 | |||
734 | board = z->resource.start; | ||
735 | base_addr = board+A2065_LANCE; | ||
736 | mem_start = board+A2065_RAM; | ||
737 | |||
738 | r1 = request_mem_region(base_addr, sizeof(struct lance_regs), | ||
739 | "Am7990"); | ||
740 | if (!r1) | ||
741 | return -EBUSY; | ||
742 | r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM"); | ||
743 | if (!r2) { | ||
744 | release_resource(r1); | ||
745 | return -EBUSY; | ||
746 | } | ||
747 | |||
748 | dev = alloc_etherdev(sizeof(struct lance_private)); | ||
749 | if (dev == NULL) { | ||
750 | release_resource(r1); | ||
751 | release_resource(r2); | ||
752 | return -ENOMEM; | ||
753 | } | ||
754 | |||
755 | SET_MODULE_OWNER(dev); | ||
756 | priv = netdev_priv(dev); | ||
757 | |||
758 | r1->name = dev->name; | ||
759 | r2->name = dev->name; | ||
760 | |||
761 | dev->dev_addr[0] = 0x00; | ||
762 | if (z->id != ZORRO_PROD_AMERISTAR_A2065) { /* Commodore */ | ||
763 | dev->dev_addr[1] = 0x80; | ||
764 | dev->dev_addr[2] = 0x10; | ||
765 | } else { /* Ameristar */ | ||
766 | dev->dev_addr[1] = 0x00; | ||
767 | dev->dev_addr[2] = 0x9f; | ||
768 | } | ||
769 | dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff; | ||
770 | dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff; | ||
771 | dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff; | ||
772 | dev->base_addr = ZTWO_VADDR(base_addr); | ||
773 | dev->mem_start = ZTWO_VADDR(mem_start); | ||
774 | dev->mem_end = dev->mem_start+A2065_RAM_SIZE; | ||
775 | |||
776 | priv->ll = (volatile struct lance_regs *)dev->base_addr; | ||
777 | priv->init_block = (struct lance_init_block *)dev->mem_start; | ||
778 | priv->lance_init_block = (struct lance_init_block *)A2065_RAM; | ||
779 | priv->auto_select = 0; | ||
780 | priv->busmaster_regval = LE_C3_BSWP; | ||
781 | |||
782 | priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS; | ||
783 | priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS; | ||
784 | priv->rx_ring_mod_mask = RX_RING_MOD_MASK; | ||
785 | priv->tx_ring_mod_mask = TX_RING_MOD_MASK; | ||
786 | |||
787 | dev->open = &lance_open; | ||
788 | dev->stop = &lance_close; | ||
789 | dev->hard_start_xmit = &lance_start_xmit; | ||
790 | dev->tx_timeout = &lance_tx_timeout; | ||
791 | dev->watchdog_timeo = 5*HZ; | ||
792 | dev->get_stats = &lance_get_stats; | ||
793 | dev->set_multicast_list = &lance_set_multicast; | ||
794 | dev->dma = 0; | ||
795 | |||
796 | init_timer(&priv->multicast_timer); | ||
797 | priv->multicast_timer.data = (unsigned long) dev; | ||
798 | priv->multicast_timer.function = | ||
799 | (void (*)(unsigned long)) &lance_set_multicast; | ||
800 | |||
801 | err = register_netdev(dev); | ||
802 | if (err) { | ||
803 | release_resource(r1); | ||
804 | release_resource(r2); | ||
805 | free_netdev(dev); | ||
806 | return err; | ||
807 | } | ||
808 | zorro_set_drvdata(z, dev); | ||
809 | |||
810 | printk(KERN_INFO "%s: A2065 at 0x%08lx, Ethernet Address " | ||
811 | "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board, | ||
812 | dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], | ||
813 | dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); | ||
814 | |||
815 | return 0; | ||
816 | } | ||
817 | |||
818 | |||
819 | static void __devexit a2065_remove_one(struct zorro_dev *z) | ||
820 | { | ||
821 | struct net_device *dev = zorro_get_drvdata(z); | ||
822 | |||
823 | unregister_netdev(dev); | ||
824 | release_mem_region(ZTWO_PADDR(dev->base_addr), | ||
825 | sizeof(struct lance_regs)); | ||
826 | release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE); | ||
827 | free_netdev(dev); | ||
828 | } | ||
829 | |||
830 | static int __init a2065_init_module(void) | ||
831 | { | ||
832 | return zorro_module_init(&a2065_driver); | ||
833 | } | ||
834 | |||
835 | static void __exit a2065_cleanup_module(void) | ||
836 | { | ||
837 | zorro_unregister_driver(&a2065_driver); | ||
838 | } | ||
839 | |||
840 | module_init(a2065_init_module); | ||
841 | module_exit(a2065_cleanup_module); | ||
842 | |||
843 | MODULE_LICENSE("GPL"); | ||