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