]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* 82596.c: A generic 82596 ethernet driver for linux. */ |
2 | /* | |
3 | Based on Apricot.c | |
4 | Written 1994 by Mark Evans. | |
5 | This driver is for the Apricot 82596 bus-master interface | |
6 | ||
7 | Modularised 12/94 Mark Evans | |
8 | ||
9 | ||
10 | Modified to support the 82596 ethernet chips on 680x0 VME boards. | |
11 | by Richard Hirst <richard@sleepie.demon.co.uk> | |
12 | Renamed to be 82596.c | |
13 | ||
14 | 980825: Changed to receive directly in to sk_buffs which are | |
15 | allocated at open() time. Eliminates copy on incoming frames | |
16 | (small ones are still copied). Shared data now held in a | |
17 | non-cached page, so we can run on 68060 in copyback mode. | |
18 | ||
19 | TBD: | |
20 | * look at deferring rx frames rather than discarding (as per tulip) | |
21 | * handle tx ring full as per tulip | |
22 | * performace test to tune rx_copybreak | |
23 | ||
24 | Most of my modifications relate to the braindead big-endian | |
25 | implementation by Intel. When the i596 is operating in | |
26 | 'big-endian' mode, it thinks a 32 bit value of 0x12345678 | |
27 | should be stored as 0x56781234. This is a real pain, when | |
28 | you have linked lists which are shared by the 680x0 and the | |
29 | i596. | |
30 | ||
31 | Driver skeleton | |
32 | Written 1993 by Donald Becker. | |
33 | Copyright 1993 United States Government as represented by the Director, | |
34 | National Security Agency. This software may only be used and distributed | |
35 | according to the terms of the GNU General Public License as modified by SRC, | |
36 | incorporated herein by reference. | |
37 | ||
38 | The author may be reached as becker@scyld.com, or C/O | |
39 | Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403 | |
40 | ||
41 | */ | |
42 | ||
1da177e4 LT |
43 | #include <linux/module.h> |
44 | #include <linux/kernel.h> | |
45 | #include <linux/string.h> | |
46 | #include <linux/errno.h> | |
47 | #include <linux/ioport.h> | |
48 | #include <linux/slab.h> | |
49 | #include <linux/interrupt.h> | |
50 | #include <linux/delay.h> | |
51 | #include <linux/netdevice.h> | |
52 | #include <linux/etherdevice.h> | |
53 | #include <linux/skbuff.h> | |
54 | #include <linux/init.h> | |
55 | #include <linux/bitops.h> | |
56 | ||
57 | #include <asm/io.h> | |
58 | #include <asm/dma.h> | |
59 | #include <asm/pgtable.h> | |
88accb49 | 60 | #include <asm/cacheflush.h> |
1da177e4 LT |
61 | |
62 | static char version[] __initdata = | |
63 | "82596.c $Revision: 1.5 $\n"; | |
64 | ||
65 | #define DRV_NAME "82596" | |
66 | ||
67 | /* DEBUG flags | |
68 | */ | |
69 | ||
70 | #define DEB_INIT 0x0001 | |
71 | #define DEB_PROBE 0x0002 | |
72 | #define DEB_SERIOUS 0x0004 | |
73 | #define DEB_ERRORS 0x0008 | |
74 | #define DEB_MULTI 0x0010 | |
75 | #define DEB_TDR 0x0020 | |
76 | #define DEB_OPEN 0x0040 | |
77 | #define DEB_RESET 0x0080 | |
78 | #define DEB_ADDCMD 0x0100 | |
79 | #define DEB_STATUS 0x0200 | |
80 | #define DEB_STARTTX 0x0400 | |
81 | #define DEB_RXADDR 0x0800 | |
82 | #define DEB_TXADDR 0x1000 | |
83 | #define DEB_RXFRAME 0x2000 | |
84 | #define DEB_INTS 0x4000 | |
85 | #define DEB_STRUCT 0x8000 | |
86 | #define DEB_ANY 0xffff | |
87 | ||
88 | ||
89 | #define DEB(x,y) if (i596_debug & (x)) y | |
90 | ||
91 | ||
92 | #if defined(CONFIG_MVME16x_NET) || defined(CONFIG_MVME16x_NET_MODULE) | |
93 | #define ENABLE_MVME16x_NET | |
94 | #endif | |
95 | #if defined(CONFIG_BVME6000_NET) || defined(CONFIG_BVME6000_NET_MODULE) | |
96 | #define ENABLE_BVME6000_NET | |
97 | #endif | |
98 | #if defined(CONFIG_APRICOT) || defined(CONFIG_APRICOT_MODULE) | |
99 | #define ENABLE_APRICOT | |
100 | #endif | |
101 | ||
102 | #ifdef ENABLE_MVME16x_NET | |
103 | #include <asm/mvme16xhw.h> | |
104 | #endif | |
105 | #ifdef ENABLE_BVME6000_NET | |
106 | #include <asm/bvme6000hw.h> | |
107 | #endif | |
108 | ||
109 | /* | |
110 | * Define various macros for Channel Attention, word swapping etc., dependent | |
111 | * on architecture. MVME and BVME are 680x0 based, otherwise it is Intel. | |
112 | */ | |
113 | ||
114 | #ifdef __mc68000__ | |
115 | #define WSWAPrfd(x) ((struct i596_rfd *) (((u32)(x)<<16) | ((((u32)(x)))>>16))) | |
116 | #define WSWAPrbd(x) ((struct i596_rbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16))) | |
117 | #define WSWAPiscp(x) ((struct i596_iscp *)(((u32)(x)<<16) | ((((u32)(x)))>>16))) | |
118 | #define WSWAPscb(x) ((struct i596_scb *) (((u32)(x)<<16) | ((((u32)(x)))>>16))) | |
119 | #define WSWAPcmd(x) ((struct i596_cmd *) (((u32)(x)<<16) | ((((u32)(x)))>>16))) | |
120 | #define WSWAPtbd(x) ((struct i596_tbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16))) | |
121 | #define WSWAPchar(x) ((char *) (((u32)(x)<<16) | ((((u32)(x)))>>16))) | |
122 | #define ISCP_BUSY 0x00010000 | |
123 | #define MACH_IS_APRICOT 0 | |
124 | #else | |
125 | #define WSWAPrfd(x) ((struct i596_rfd *)(x)) | |
126 | #define WSWAPrbd(x) ((struct i596_rbd *)(x)) | |
127 | #define WSWAPiscp(x) ((struct i596_iscp *)(x)) | |
128 | #define WSWAPscb(x) ((struct i596_scb *)(x)) | |
129 | #define WSWAPcmd(x) ((struct i596_cmd *)(x)) | |
130 | #define WSWAPtbd(x) ((struct i596_tbd *)(x)) | |
131 | #define WSWAPchar(x) ((char *)(x)) | |
132 | #define ISCP_BUSY 0x0001 | |
133 | #define MACH_IS_APRICOT 1 | |
134 | #endif | |
135 | ||
136 | /* | |
137 | * The MPU_PORT command allows direct access to the 82596. With PORT access | |
138 | * the following commands are available (p5-18). The 32-bit port command | |
139 | * must be word-swapped with the most significant word written first. | |
140 | * This only applies to VME boards. | |
141 | */ | |
142 | #define PORT_RESET 0x00 /* reset 82596 */ | |
143 | #define PORT_SELFTEST 0x01 /* selftest */ | |
144 | #define PORT_ALTSCP 0x02 /* alternate SCB address */ | |
145 | #define PORT_ALTDUMP 0x03 /* Alternate DUMP address */ | |
146 | ||
147 | static int i596_debug = (DEB_SERIOUS|DEB_PROBE); | |
148 | ||
149 | MODULE_AUTHOR("Richard Hirst"); | |
150 | MODULE_DESCRIPTION("i82596 driver"); | |
151 | MODULE_LICENSE("GPL"); | |
152 | ||
153 | module_param(i596_debug, int, 0); | |
154 | MODULE_PARM_DESC(i596_debug, "i82596 debug mask"); | |
155 | ||
156 | ||
157 | /* Copy frames shorter than rx_copybreak, otherwise pass on up in | |
158 | * a full sized sk_buff. Value of 100 stolen from tulip.c (!alpha). | |
159 | */ | |
160 | static int rx_copybreak = 100; | |
161 | ||
162 | #define PKT_BUF_SZ 1536 | |
163 | #define MAX_MC_CNT 64 | |
164 | ||
165 | #define I596_TOTAL_SIZE 17 | |
166 | ||
167 | #define I596_NULL ((void *)0xffffffff) | |
168 | ||
169 | #define CMD_EOL 0x8000 /* The last command of the list, stop. */ | |
170 | #define CMD_SUSP 0x4000 /* Suspend after doing cmd. */ | |
171 | #define CMD_INTR 0x2000 /* Interrupt after doing cmd. */ | |
172 | ||
173 | #define CMD_FLEX 0x0008 /* Enable flexible memory model */ | |
174 | ||
175 | enum commands { | |
176 | CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3, | |
177 | CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7 | |
178 | }; | |
179 | ||
180 | #define STAT_C 0x8000 /* Set to 0 after execution */ | |
181 | #define STAT_B 0x4000 /* Command being executed */ | |
182 | #define STAT_OK 0x2000 /* Command executed ok */ | |
183 | #define STAT_A 0x1000 /* Command aborted */ | |
184 | ||
185 | #define CUC_START 0x0100 | |
186 | #define CUC_RESUME 0x0200 | |
187 | #define CUC_SUSPEND 0x0300 | |
188 | #define CUC_ABORT 0x0400 | |
189 | #define RX_START 0x0010 | |
190 | #define RX_RESUME 0x0020 | |
191 | #define RX_SUSPEND 0x0030 | |
192 | #define RX_ABORT 0x0040 | |
193 | ||
194 | #define TX_TIMEOUT 5 | |
195 | ||
196 | ||
197 | struct i596_reg { | |
198 | unsigned short porthi; | |
199 | unsigned short portlo; | |
200 | unsigned long ca; | |
201 | }; | |
202 | ||
203 | #define EOF 0x8000 | |
204 | #define SIZE_MASK 0x3fff | |
205 | ||
206 | struct i596_tbd { | |
207 | unsigned short size; | |
208 | unsigned short pad; | |
209 | struct i596_tbd *next; | |
210 | char *data; | |
211 | }; | |
212 | ||
213 | /* The command structure has two 'next' pointers; v_next is the address of | |
214 | * the next command as seen by the CPU, b_next is the address of the next | |
215 | * command as seen by the 82596. The b_next pointer, as used by the 82596 | |
216 | * always references the status field of the next command, rather than the | |
217 | * v_next field, because the 82596 is unaware of v_next. It may seem more | |
218 | * logical to put v_next at the end of the structure, but we cannot do that | |
219 | * because the 82596 expects other fields to be there, depending on command | |
220 | * type. | |
221 | */ | |
222 | ||
223 | struct i596_cmd { | |
224 | struct i596_cmd *v_next; /* Address from CPUs viewpoint */ | |
225 | unsigned short status; | |
226 | unsigned short command; | |
227 | struct i596_cmd *b_next; /* Address from i596 viewpoint */ | |
228 | }; | |
229 | ||
230 | struct tx_cmd { | |
231 | struct i596_cmd cmd; | |
232 | struct i596_tbd *tbd; | |
233 | unsigned short size; | |
234 | unsigned short pad; | |
235 | struct sk_buff *skb; /* So we can free it after tx */ | |
236 | }; | |
237 | ||
238 | struct tdr_cmd { | |
239 | struct i596_cmd cmd; | |
240 | unsigned short status; | |
241 | unsigned short pad; | |
242 | }; | |
243 | ||
244 | struct mc_cmd { | |
245 | struct i596_cmd cmd; | |
246 | short mc_cnt; | |
247 | char mc_addrs[MAX_MC_CNT*6]; | |
248 | }; | |
249 | ||
250 | struct sa_cmd { | |
251 | struct i596_cmd cmd; | |
252 | char eth_addr[8]; | |
253 | }; | |
254 | ||
255 | struct cf_cmd { | |
256 | struct i596_cmd cmd; | |
257 | char i596_config[16]; | |
258 | }; | |
259 | ||
260 | struct i596_rfd { | |
261 | unsigned short stat; | |
262 | unsigned short cmd; | |
263 | struct i596_rfd *b_next; /* Address from i596 viewpoint */ | |
264 | struct i596_rbd *rbd; | |
265 | unsigned short count; | |
266 | unsigned short size; | |
267 | struct i596_rfd *v_next; /* Address from CPUs viewpoint */ | |
268 | struct i596_rfd *v_prev; | |
269 | }; | |
270 | ||
271 | struct i596_rbd { | |
272 | unsigned short count; | |
273 | unsigned short zero1; | |
274 | struct i596_rbd *b_next; | |
275 | unsigned char *b_data; /* Address from i596 viewpoint */ | |
276 | unsigned short size; | |
277 | unsigned short zero2; | |
278 | struct sk_buff *skb; | |
279 | struct i596_rbd *v_next; | |
280 | struct i596_rbd *b_addr; /* This rbd addr from i596 view */ | |
281 | unsigned char *v_data; /* Address from CPUs viewpoint */ | |
282 | }; | |
283 | ||
284 | #define TX_RING_SIZE 64 | |
285 | #define RX_RING_SIZE 16 | |
286 | ||
287 | struct i596_scb { | |
288 | unsigned short status; | |
289 | unsigned short command; | |
290 | struct i596_cmd *cmd; | |
291 | struct i596_rfd *rfd; | |
292 | unsigned long crc_err; | |
293 | unsigned long align_err; | |
294 | unsigned long resource_err; | |
295 | unsigned long over_err; | |
296 | unsigned long rcvdt_err; | |
297 | unsigned long short_err; | |
298 | unsigned short t_on; | |
299 | unsigned short t_off; | |
300 | }; | |
301 | ||
302 | struct i596_iscp { | |
303 | unsigned long stat; | |
304 | struct i596_scb *scb; | |
305 | }; | |
306 | ||
307 | struct i596_scp { | |
308 | unsigned long sysbus; | |
309 | unsigned long pad; | |
310 | struct i596_iscp *iscp; | |
311 | }; | |
312 | ||
313 | struct i596_private { | |
314 | volatile struct i596_scp scp; | |
315 | volatile struct i596_iscp iscp; | |
316 | volatile struct i596_scb scb; | |
317 | struct sa_cmd sa_cmd; | |
318 | struct cf_cmd cf_cmd; | |
319 | struct tdr_cmd tdr_cmd; | |
320 | struct mc_cmd mc_cmd; | |
321 | unsigned long stat; | |
322 | int last_restart __attribute__((aligned(4))); | |
323 | struct i596_rfd *rfd_head; | |
324 | struct i596_rbd *rbd_head; | |
325 | struct i596_cmd *cmd_tail; | |
326 | struct i596_cmd *cmd_head; | |
327 | int cmd_backlog; | |
328 | unsigned long last_cmd; | |
329 | struct net_device_stats stats; | |
330 | struct i596_rfd rfds[RX_RING_SIZE]; | |
331 | struct i596_rbd rbds[RX_RING_SIZE]; | |
332 | struct tx_cmd tx_cmds[TX_RING_SIZE]; | |
333 | struct i596_tbd tbds[TX_RING_SIZE]; | |
334 | int next_tx_cmd; | |
335 | spinlock_t lock; | |
336 | }; | |
337 | ||
338 | static char init_setup[] = | |
339 | { | |
340 | 0x8E, /* length, prefetch on */ | |
341 | 0xC8, /* fifo to 8, monitor off */ | |
342 | #ifdef CONFIG_VME | |
343 | 0xc0, /* don't save bad frames */ | |
344 | #else | |
345 | 0x80, /* don't save bad frames */ | |
346 | #endif | |
347 | 0x2E, /* No source address insertion, 8 byte preamble */ | |
348 | 0x00, /* priority and backoff defaults */ | |
349 | 0x60, /* interframe spacing */ | |
350 | 0x00, /* slot time LSB */ | |
351 | 0xf2, /* slot time and retries */ | |
352 | 0x00, /* promiscuous mode */ | |
353 | 0x00, /* collision detect */ | |
354 | 0x40, /* minimum frame length */ | |
355 | 0xff, | |
356 | 0x00, | |
357 | 0x7f /* *multi IA */ }; | |
358 | ||
359 | static int i596_open(struct net_device *dev); | |
360 | static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev); | |
7d12e780 | 361 | static irqreturn_t i596_interrupt(int irq, void *dev_id); |
1da177e4 LT |
362 | static int i596_close(struct net_device *dev); |
363 | static struct net_device_stats *i596_get_stats(struct net_device *dev); | |
364 | static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd); | |
365 | static void i596_tx_timeout (struct net_device *dev); | |
366 | static void print_eth(unsigned char *buf, char *str); | |
367 | static void set_multicast_list(struct net_device *dev); | |
368 | ||
369 | static int rx_ring_size = RX_RING_SIZE; | |
370 | static int ticks_limit = 25; | |
371 | static int max_cmd_backlog = TX_RING_SIZE-1; | |
372 | ||
373 | ||
374 | static inline void CA(struct net_device *dev) | |
375 | { | |
376 | #ifdef ENABLE_MVME16x_NET | |
377 | if (MACH_IS_MVME16x) { | |
378 | ((struct i596_reg *) dev->base_addr)->ca = 1; | |
379 | } | |
380 | #endif | |
381 | #ifdef ENABLE_BVME6000_NET | |
382 | if (MACH_IS_BVME6000) { | |
383 | volatile u32 i; | |
384 | ||
385 | i = *(volatile u32 *) (dev->base_addr); | |
386 | } | |
387 | #endif | |
388 | #ifdef ENABLE_APRICOT | |
389 | if (MACH_IS_APRICOT) { | |
390 | outw(0, (short) (dev->base_addr) + 4); | |
391 | } | |
392 | #endif | |
393 | } | |
394 | ||
395 | ||
396 | static inline void MPU_PORT(struct net_device *dev, int c, volatile void *x) | |
397 | { | |
398 | #ifdef ENABLE_MVME16x_NET | |
399 | if (MACH_IS_MVME16x) { | |
400 | struct i596_reg *p = (struct i596_reg *) (dev->base_addr); | |
401 | p->porthi = ((c) | (u32) (x)) & 0xffff; | |
402 | p->portlo = ((c) | (u32) (x)) >> 16; | |
403 | } | |
404 | #endif | |
405 | #ifdef ENABLE_BVME6000_NET | |
406 | if (MACH_IS_BVME6000) { | |
407 | u32 v = (u32) (c) | (u32) (x); | |
408 | v = ((u32) (v) << 16) | ((u32) (v) >> 16); | |
409 | *(volatile u32 *) dev->base_addr = v; | |
410 | udelay(1); | |
411 | *(volatile u32 *) dev->base_addr = v; | |
412 | } | |
413 | #endif | |
414 | } | |
415 | ||
416 | ||
417 | static inline int wait_istat(struct net_device *dev, struct i596_private *lp, int delcnt, char *str) | |
418 | { | |
419 | while (--delcnt && lp->iscp.stat) | |
420 | udelay(10); | |
421 | if (!delcnt) { | |
422 | printk(KERN_ERR "%s: %s, status %4.4x, cmd %4.4x.\n", | |
423 | dev->name, str, lp->scb.status, lp->scb.command); | |
424 | return -1; | |
425 | } | |
426 | else | |
427 | return 0; | |
428 | } | |
429 | ||
430 | ||
431 | static inline int wait_cmd(struct net_device *dev, struct i596_private *lp, int delcnt, char *str) | |
432 | { | |
433 | while (--delcnt && lp->scb.command) | |
434 | udelay(10); | |
435 | if (!delcnt) { | |
436 | printk(KERN_ERR "%s: %s, status %4.4x, cmd %4.4x.\n", | |
437 | dev->name, str, lp->scb.status, lp->scb.command); | |
438 | return -1; | |
439 | } | |
440 | else | |
441 | return 0; | |
442 | } | |
443 | ||
444 | ||
445 | static inline int wait_cfg(struct net_device *dev, struct i596_cmd *cmd, int delcnt, char *str) | |
446 | { | |
447 | volatile struct i596_cmd *c = cmd; | |
6aa20a22 | 448 | |
1da177e4 LT |
449 | while (--delcnt && c->command) |
450 | udelay(10); | |
451 | if (!delcnt) { | |
452 | printk(KERN_ERR "%s: %s.\n", dev->name, str); | |
453 | return -1; | |
454 | } | |
455 | else | |
456 | return 0; | |
457 | } | |
458 | ||
6aa20a22 | 459 | |
1da177e4 LT |
460 | static void i596_display_data(struct net_device *dev) |
461 | { | |
462 | struct i596_private *lp = dev->priv; | |
463 | struct i596_cmd *cmd; | |
464 | struct i596_rfd *rfd; | |
465 | struct i596_rbd *rbd; | |
466 | ||
467 | printk(KERN_ERR "lp and scp at %p, .sysbus = %08lx, .iscp = %p\n", | |
468 | &lp->scp, lp->scp.sysbus, lp->scp.iscp); | |
469 | printk(KERN_ERR "iscp at %p, iscp.stat = %08lx, .scb = %p\n", | |
470 | &lp->iscp, lp->iscp.stat, lp->iscp.scb); | |
471 | printk(KERN_ERR "scb at %p, scb.status = %04x, .command = %04x," | |
472 | " .cmd = %p, .rfd = %p\n", | |
473 | &lp->scb, lp->scb.status, lp->scb.command, | |
474 | lp->scb.cmd, lp->scb.rfd); | |
475 | printk(KERN_ERR " errors: crc %lx, align %lx, resource %lx," | |
476 | " over %lx, rcvdt %lx, short %lx\n", | |
477 | lp->scb.crc_err, lp->scb.align_err, lp->scb.resource_err, | |
478 | lp->scb.over_err, lp->scb.rcvdt_err, lp->scb.short_err); | |
479 | cmd = lp->cmd_head; | |
480 | while (cmd != I596_NULL) { | |
481 | printk(KERN_ERR "cmd at %p, .status = %04x, .command = %04x, .b_next = %p\n", | |
482 | cmd, cmd->status, cmd->command, cmd->b_next); | |
483 | cmd = cmd->v_next; | |
484 | } | |
485 | rfd = lp->rfd_head; | |
486 | printk(KERN_ERR "rfd_head = %p\n", rfd); | |
487 | do { | |
488 | printk(KERN_ERR " %p .stat %04x, .cmd %04x, b_next %p, rbd %p," | |
489 | " count %04x\n", | |
490 | rfd, rfd->stat, rfd->cmd, rfd->b_next, rfd->rbd, | |
491 | rfd->count); | |
492 | rfd = rfd->v_next; | |
493 | } while (rfd != lp->rfd_head); | |
494 | rbd = lp->rbd_head; | |
495 | printk(KERN_ERR "rbd_head = %p\n", rbd); | |
496 | do { | |
497 | printk(KERN_ERR " %p .count %04x, b_next %p, b_data %p, size %04x\n", | |
498 | rbd, rbd->count, rbd->b_next, rbd->b_data, rbd->size); | |
499 | rbd = rbd->v_next; | |
500 | } while (rbd != lp->rbd_head); | |
501 | } | |
502 | ||
503 | ||
504 | #if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET) | |
7d12e780 | 505 | static irqreturn_t i596_error(int irq, void *dev_id) |
1da177e4 LT |
506 | { |
507 | struct net_device *dev = dev_id; | |
508 | #ifdef ENABLE_MVME16x_NET | |
509 | if (MACH_IS_MVME16x) { | |
510 | volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000; | |
511 | ||
512 | pcc2[0x28] = 1; | |
513 | pcc2[0x2b] = 0x1d; | |
514 | } | |
515 | #endif | |
516 | #ifdef ENABLE_BVME6000_NET | |
517 | if (MACH_IS_BVME6000) { | |
518 | volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG; | |
519 | ||
520 | *ethirq = 1; | |
521 | *ethirq = 3; | |
522 | } | |
523 | #endif | |
524 | printk(KERN_ERR "%s: Error interrupt\n", dev->name); | |
525 | i596_display_data(dev); | |
526 | return IRQ_HANDLED; | |
527 | } | |
528 | #endif | |
529 | ||
530 | static inline void init_rx_bufs(struct net_device *dev) | |
531 | { | |
532 | struct i596_private *lp = dev->priv; | |
533 | int i; | |
534 | struct i596_rfd *rfd; | |
535 | struct i596_rbd *rbd; | |
536 | ||
537 | /* First build the Receive Buffer Descriptor List */ | |
538 | ||
539 | for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) { | |
540 | struct sk_buff *skb = dev_alloc_skb(PKT_BUF_SZ); | |
541 | ||
542 | if (skb == NULL) | |
543 | panic("82596: alloc_skb() failed"); | |
544 | skb->dev = dev; | |
545 | rbd->v_next = rbd+1; | |
546 | rbd->b_next = WSWAPrbd(virt_to_bus(rbd+1)); | |
547 | rbd->b_addr = WSWAPrbd(virt_to_bus(rbd)); | |
548 | rbd->skb = skb; | |
689be439 DM |
549 | rbd->v_data = skb->data; |
550 | rbd->b_data = WSWAPchar(virt_to_bus(skb->data)); | |
1da177e4 LT |
551 | rbd->size = PKT_BUF_SZ; |
552 | #ifdef __mc68000__ | |
689be439 | 553 | cache_clear(virt_to_phys(skb->data), PKT_BUF_SZ); |
1da177e4 LT |
554 | #endif |
555 | } | |
556 | lp->rbd_head = lp->rbds; | |
557 | rbd = lp->rbds + rx_ring_size - 1; | |
558 | rbd->v_next = lp->rbds; | |
559 | rbd->b_next = WSWAPrbd(virt_to_bus(lp->rbds)); | |
560 | ||
561 | /* Now build the Receive Frame Descriptor List */ | |
562 | ||
563 | for (i = 0, rfd = lp->rfds; i < rx_ring_size; i++, rfd++) { | |
564 | rfd->rbd = I596_NULL; | |
565 | rfd->v_next = rfd+1; | |
566 | rfd->v_prev = rfd-1; | |
567 | rfd->b_next = WSWAPrfd(virt_to_bus(rfd+1)); | |
568 | rfd->cmd = CMD_FLEX; | |
569 | } | |
570 | lp->rfd_head = lp->rfds; | |
571 | lp->scb.rfd = WSWAPrfd(virt_to_bus(lp->rfds)); | |
572 | rfd = lp->rfds; | |
573 | rfd->rbd = lp->rbd_head; | |
574 | rfd->v_prev = lp->rfds + rx_ring_size - 1; | |
575 | rfd = lp->rfds + rx_ring_size - 1; | |
576 | rfd->v_next = lp->rfds; | |
577 | rfd->b_next = WSWAPrfd(virt_to_bus(lp->rfds)); | |
578 | rfd->cmd = CMD_EOL|CMD_FLEX; | |
579 | } | |
580 | ||
581 | static inline void remove_rx_bufs(struct net_device *dev) | |
582 | { | |
583 | struct i596_private *lp = dev->priv; | |
584 | struct i596_rbd *rbd; | |
585 | int i; | |
586 | ||
587 | for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) { | |
588 | if (rbd->skb == NULL) | |
589 | break; | |
590 | dev_kfree_skb(rbd->skb); | |
591 | } | |
592 | } | |
593 | ||
594 | ||
595 | static void rebuild_rx_bufs(struct net_device *dev) | |
596 | { | |
597 | struct i596_private *lp = dev->priv; | |
598 | int i; | |
599 | ||
600 | /* Ensure rx frame/buffer descriptors are tidy */ | |
601 | ||
602 | for (i = 0; i < rx_ring_size; i++) { | |
603 | lp->rfds[i].rbd = I596_NULL; | |
604 | lp->rfds[i].cmd = CMD_FLEX; | |
605 | } | |
606 | lp->rfds[rx_ring_size-1].cmd = CMD_EOL|CMD_FLEX; | |
607 | lp->rfd_head = lp->rfds; | |
608 | lp->scb.rfd = WSWAPrfd(virt_to_bus(lp->rfds)); | |
609 | lp->rbd_head = lp->rbds; | |
610 | lp->rfds[0].rbd = WSWAPrbd(virt_to_bus(lp->rbds)); | |
611 | } | |
612 | ||
613 | ||
614 | static int init_i596_mem(struct net_device *dev) | |
615 | { | |
616 | struct i596_private *lp = dev->priv; | |
0018dfa4 | 617 | #if !defined(ENABLE_MVME16x_NET) && !defined(ENABLE_BVME6000_NET) || defined(ENABLE_APRICOT) |
1da177e4 LT |
618 | short ioaddr = dev->base_addr; |
619 | #endif | |
620 | unsigned long flags; | |
621 | ||
622 | MPU_PORT(dev, PORT_RESET, NULL); | |
623 | ||
624 | udelay(100); /* Wait 100us - seems to help */ | |
625 | ||
626 | #if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET) | |
627 | #ifdef ENABLE_MVME16x_NET | |
628 | if (MACH_IS_MVME16x) { | |
629 | volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000; | |
630 | ||
631 | /* Disable all ints for now */ | |
632 | pcc2[0x28] = 1; | |
633 | pcc2[0x2a] = 0x48; | |
634 | /* Following disables snooping. Snooping is not required | |
635 | * as we make appropriate use of non-cached pages for | |
636 | * shared data, and cache_push/cache_clear. | |
637 | */ | |
638 | pcc2[0x2b] = 0x08; | |
639 | } | |
640 | #endif | |
641 | #ifdef ENABLE_BVME6000_NET | |
642 | if (MACH_IS_BVME6000) { | |
643 | volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG; | |
644 | ||
645 | *ethirq = 1; | |
646 | } | |
647 | #endif | |
648 | ||
649 | /* change the scp address */ | |
650 | ||
651 | MPU_PORT(dev, PORT_ALTSCP, (void *)virt_to_bus((void *)&lp->scp)); | |
652 | ||
653 | #elif defined(ENABLE_APRICOT) | |
654 | ||
655 | { | |
656 | u32 scp = virt_to_bus(&lp->scp); | |
657 | ||
658 | /* change the scp address */ | |
659 | outw(0, ioaddr); | |
660 | outw(0, ioaddr); | |
661 | outb(4, ioaddr + 0xf); | |
662 | outw(scp | 2, ioaddr); | |
663 | outw(scp >> 16, ioaddr); | |
664 | } | |
665 | #endif | |
666 | ||
667 | lp->last_cmd = jiffies; | |
668 | ||
669 | #ifdef ENABLE_MVME16x_NET | |
670 | if (MACH_IS_MVME16x) | |
671 | lp->scp.sysbus = 0x00000054; | |
672 | #endif | |
673 | #ifdef ENABLE_BVME6000_NET | |
674 | if (MACH_IS_BVME6000) | |
675 | lp->scp.sysbus = 0x0000004c; | |
676 | #endif | |
677 | #ifdef ENABLE_APRICOT | |
678 | if (MACH_IS_APRICOT) | |
679 | lp->scp.sysbus = 0x00440000; | |
680 | #endif | |
681 | ||
682 | lp->scp.iscp = WSWAPiscp(virt_to_bus((void *)&lp->iscp)); | |
683 | lp->iscp.scb = WSWAPscb(virt_to_bus((void *)&lp->scb)); | |
684 | lp->iscp.stat = ISCP_BUSY; | |
685 | lp->cmd_backlog = 0; | |
686 | ||
687 | lp->cmd_head = lp->scb.cmd = I596_NULL; | |
688 | ||
689 | #ifdef ENABLE_BVME6000_NET | |
690 | if (MACH_IS_BVME6000) { | |
691 | lp->scb.t_on = 7 * 25; | |
692 | lp->scb.t_off = 1 * 25; | |
693 | } | |
694 | #endif | |
695 | ||
696 | DEB(DEB_INIT,printk(KERN_DEBUG "%s: starting i82596.\n", dev->name)); | |
697 | ||
698 | #if defined(ENABLE_APRICOT) | |
699 | (void) inb(ioaddr + 0x10); | |
700 | outb(4, ioaddr + 0xf); | |
701 | #endif | |
702 | CA(dev); | |
703 | ||
704 | if (wait_istat(dev,lp,1000,"initialization timed out")) | |
705 | goto failed; | |
706 | DEB(DEB_INIT,printk(KERN_DEBUG "%s: i82596 initialization successful\n", dev->name)); | |
707 | ||
708 | /* Ensure rx frame/buffer descriptors are tidy */ | |
709 | rebuild_rx_bufs(dev); | |
710 | lp->scb.command = 0; | |
711 | ||
712 | #ifdef ENABLE_MVME16x_NET | |
713 | if (MACH_IS_MVME16x) { | |
714 | volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000; | |
715 | ||
716 | /* Enable ints, etc. now */ | |
717 | pcc2[0x2a] = 0x55; /* Edge sensitive */ | |
718 | pcc2[0x2b] = 0x15; | |
719 | } | |
720 | #endif | |
721 | #ifdef ENABLE_BVME6000_NET | |
722 | if (MACH_IS_BVME6000) { | |
723 | volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG; | |
724 | ||
725 | *ethirq = 3; | |
726 | } | |
727 | #endif | |
728 | ||
729 | ||
730 | DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdConfigure\n", dev->name)); | |
731 | memcpy(lp->cf_cmd.i596_config, init_setup, 14); | |
732 | lp->cf_cmd.cmd.command = CmdConfigure; | |
733 | i596_add_cmd(dev, &lp->cf_cmd.cmd); | |
734 | ||
735 | DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdSASetup\n", dev->name)); | |
736 | memcpy(lp->sa_cmd.eth_addr, dev->dev_addr, 6); | |
737 | lp->sa_cmd.cmd.command = CmdSASetup; | |
738 | i596_add_cmd(dev, &lp->sa_cmd.cmd); | |
739 | ||
740 | DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdTDR\n", dev->name)); | |
741 | lp->tdr_cmd.cmd.command = CmdTDR; | |
742 | i596_add_cmd(dev, &lp->tdr_cmd.cmd); | |
743 | ||
744 | spin_lock_irqsave (&lp->lock, flags); | |
745 | ||
746 | if (wait_cmd(dev,lp,1000,"timed out waiting to issue RX_START")) { | |
747 | spin_unlock_irqrestore (&lp->lock, flags); | |
748 | goto failed; | |
749 | } | |
750 | DEB(DEB_INIT,printk(KERN_DEBUG "%s: Issuing RX_START\n", dev->name)); | |
751 | lp->scb.command = RX_START; | |
752 | CA(dev); | |
753 | ||
754 | spin_unlock_irqrestore (&lp->lock, flags); | |
755 | ||
756 | if (wait_cmd(dev,lp,1000,"RX_START not processed")) | |
757 | goto failed; | |
758 | DEB(DEB_INIT,printk(KERN_DEBUG "%s: Receive unit started OK\n", dev->name)); | |
759 | return 0; | |
760 | ||
761 | failed: | |
762 | printk(KERN_CRIT "%s: Failed to initialise 82596\n", dev->name); | |
763 | MPU_PORT(dev, PORT_RESET, NULL); | |
764 | return -1; | |
765 | } | |
766 | ||
767 | static inline int i596_rx(struct net_device *dev) | |
768 | { | |
769 | struct i596_private *lp = dev->priv; | |
770 | struct i596_rfd *rfd; | |
771 | struct i596_rbd *rbd; | |
772 | int frames = 0; | |
773 | ||
774 | DEB(DEB_RXFRAME,printk(KERN_DEBUG "i596_rx(), rfd_head %p, rbd_head %p\n", | |
775 | lp->rfd_head, lp->rbd_head)); | |
776 | ||
777 | rfd = lp->rfd_head; /* Ref next frame to check */ | |
778 | ||
779 | while ((rfd->stat) & STAT_C) { /* Loop while complete frames */ | |
780 | if (rfd->rbd == I596_NULL) | |
781 | rbd = I596_NULL; | |
782 | else if (rfd->rbd == lp->rbd_head->b_addr) | |
783 | rbd = lp->rbd_head; | |
784 | else { | |
785 | printk(KERN_CRIT "%s: rbd chain broken!\n", dev->name); | |
786 | /* XXX Now what? */ | |
787 | rbd = I596_NULL; | |
788 | } | |
789 | DEB(DEB_RXFRAME, printk(KERN_DEBUG " rfd %p, rfd.rbd %p, rfd.stat %04x\n", | |
790 | rfd, rfd->rbd, rfd->stat)); | |
6aa20a22 | 791 | |
1da177e4 LT |
792 | if (rbd != I596_NULL && ((rfd->stat) & STAT_OK)) { |
793 | /* a good frame */ | |
794 | int pkt_len = rbd->count & 0x3fff; | |
795 | struct sk_buff *skb = rbd->skb; | |
796 | int rx_in_place = 0; | |
797 | ||
798 | DEB(DEB_RXADDR,print_eth(rbd->v_data, "received")); | |
799 | frames++; | |
800 | ||
801 | /* Check if the packet is long enough to just accept | |
802 | * without copying to a properly sized skbuff. | |
803 | */ | |
804 | ||
805 | if (pkt_len > rx_copybreak) { | |
806 | struct sk_buff *newskb; | |
807 | ||
808 | /* Get fresh skbuff to replace filled one. */ | |
809 | newskb = dev_alloc_skb(PKT_BUF_SZ); | |
810 | if (newskb == NULL) { | |
811 | skb = NULL; /* drop pkt */ | |
812 | goto memory_squeeze; | |
813 | } | |
814 | /* Pass up the skb already on the Rx ring. */ | |
815 | skb_put(skb, pkt_len); | |
816 | rx_in_place = 1; | |
817 | rbd->skb = newskb; | |
818 | newskb->dev = dev; | |
689be439 DM |
819 | rbd->v_data = newskb->data; |
820 | rbd->b_data = WSWAPchar(virt_to_bus(newskb->data)); | |
1da177e4 | 821 | #ifdef __mc68000__ |
689be439 | 822 | cache_clear(virt_to_phys(newskb->data), PKT_BUF_SZ); |
1da177e4 LT |
823 | #endif |
824 | } | |
825 | else | |
826 | skb = dev_alloc_skb(pkt_len + 2); | |
827 | memory_squeeze: | |
828 | if (skb == NULL) { | |
829 | /* XXX tulip.c can defer packets here!! */ | |
830 | printk(KERN_WARNING "%s: i596_rx Memory squeeze, dropping packet.\n", dev->name); | |
831 | lp->stats.rx_dropped++; | |
832 | } | |
833 | else { | |
1da177e4 LT |
834 | if (!rx_in_place) { |
835 | /* 16 byte align the data fields */ | |
836 | skb_reserve(skb, 2); | |
837 | memcpy(skb_put(skb,pkt_len), rbd->v_data, pkt_len); | |
838 | } | |
839 | skb->protocol=eth_type_trans(skb,dev); | |
840 | skb->len = pkt_len; | |
841 | #ifdef __mc68000__ | |
689be439 | 842 | cache_clear(virt_to_phys(rbd->skb->data), |
1da177e4 LT |
843 | pkt_len); |
844 | #endif | |
845 | netif_rx(skb); | |
846 | dev->last_rx = jiffies; | |
847 | lp->stats.rx_packets++; | |
848 | lp->stats.rx_bytes+=pkt_len; | |
849 | } | |
850 | } | |
851 | else { | |
852 | DEB(DEB_ERRORS, printk(KERN_DEBUG "%s: Error, rfd.stat = 0x%04x\n", | |
853 | dev->name, rfd->stat)); | |
854 | lp->stats.rx_errors++; | |
855 | if ((rfd->stat) & 0x0001) | |
856 | lp->stats.collisions++; | |
857 | if ((rfd->stat) & 0x0080) | |
858 | lp->stats.rx_length_errors++; | |
859 | if ((rfd->stat) & 0x0100) | |
860 | lp->stats.rx_over_errors++; | |
861 | if ((rfd->stat) & 0x0200) | |
862 | lp->stats.rx_fifo_errors++; | |
863 | if ((rfd->stat) & 0x0400) | |
864 | lp->stats.rx_frame_errors++; | |
865 | if ((rfd->stat) & 0x0800) | |
866 | lp->stats.rx_crc_errors++; | |
867 | if ((rfd->stat) & 0x1000) | |
868 | lp->stats.rx_length_errors++; | |
869 | } | |
870 | ||
871 | /* Clear the buffer descriptor count and EOF + F flags */ | |
872 | ||
873 | if (rbd != I596_NULL && (rbd->count & 0x4000)) { | |
874 | rbd->count = 0; | |
875 | lp->rbd_head = rbd->v_next; | |
876 | } | |
877 | ||
878 | /* Tidy the frame descriptor, marking it as end of list */ | |
879 | ||
880 | rfd->rbd = I596_NULL; | |
881 | rfd->stat = 0; | |
882 | rfd->cmd = CMD_EOL|CMD_FLEX; | |
883 | rfd->count = 0; | |
884 | ||
885 | /* Remove end-of-list from old end descriptor */ | |
886 | ||
887 | rfd->v_prev->cmd = CMD_FLEX; | |
888 | ||
889 | /* Update record of next frame descriptor to process */ | |
890 | ||
891 | lp->scb.rfd = rfd->b_next; | |
892 | lp->rfd_head = rfd->v_next; | |
893 | rfd = lp->rfd_head; | |
894 | } | |
895 | ||
896 | DEB(DEB_RXFRAME,printk(KERN_DEBUG "frames %d\n", frames)); | |
897 | ||
898 | return 0; | |
899 | } | |
900 | ||
901 | ||
864fe05d | 902 | static void i596_cleanup_cmd(struct net_device *dev, struct i596_private *lp) |
1da177e4 LT |
903 | { |
904 | struct i596_cmd *ptr; | |
905 | ||
906 | while (lp->cmd_head != I596_NULL) { | |
907 | ptr = lp->cmd_head; | |
908 | lp->cmd_head = ptr->v_next; | |
909 | lp->cmd_backlog--; | |
910 | ||
911 | switch ((ptr->command) & 0x7) { | |
912 | case CmdTx: | |
913 | { | |
914 | struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr; | |
915 | struct sk_buff *skb = tx_cmd->skb; | |
916 | ||
917 | dev_kfree_skb(skb); | |
918 | ||
919 | lp->stats.tx_errors++; | |
920 | lp->stats.tx_aborted_errors++; | |
921 | ||
922 | ptr->v_next = ptr->b_next = I596_NULL; | |
923 | tx_cmd->cmd.command = 0; /* Mark as free */ | |
924 | break; | |
925 | } | |
926 | default: | |
927 | ptr->v_next = ptr->b_next = I596_NULL; | |
928 | } | |
929 | } | |
930 | ||
931 | wait_cmd(dev,lp,100,"i596_cleanup_cmd timed out"); | |
932 | lp->scb.cmd = I596_NULL; | |
933 | } | |
934 | ||
864fe05d AM |
935 | static void i596_reset(struct net_device *dev, struct i596_private *lp, |
936 | int ioaddr) | |
1da177e4 LT |
937 | { |
938 | unsigned long flags; | |
939 | ||
940 | DEB(DEB_RESET,printk(KERN_DEBUG "i596_reset\n")); | |
941 | ||
942 | spin_lock_irqsave (&lp->lock, flags); | |
943 | ||
944 | wait_cmd(dev,lp,100,"i596_reset timed out"); | |
945 | ||
946 | netif_stop_queue(dev); | |
947 | ||
948 | lp->scb.command = CUC_ABORT | RX_ABORT; | |
949 | CA(dev); | |
950 | ||
951 | /* wait for shutdown */ | |
952 | wait_cmd(dev,lp,1000,"i596_reset 2 timed out"); | |
953 | spin_unlock_irqrestore (&lp->lock, flags); | |
954 | ||
955 | i596_cleanup_cmd(dev,lp); | |
956 | i596_rx(dev); | |
957 | ||
958 | netif_start_queue(dev); | |
959 | init_i596_mem(dev); | |
960 | } | |
961 | ||
962 | static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd) | |
963 | { | |
964 | struct i596_private *lp = dev->priv; | |
965 | int ioaddr = dev->base_addr; | |
966 | unsigned long flags; | |
967 | ||
968 | DEB(DEB_ADDCMD,printk(KERN_DEBUG "i596_add_cmd\n")); | |
969 | ||
970 | cmd->status = 0; | |
971 | cmd->command |= (CMD_EOL | CMD_INTR); | |
972 | cmd->v_next = cmd->b_next = I596_NULL; | |
973 | ||
974 | spin_lock_irqsave (&lp->lock, flags); | |
975 | ||
976 | if (lp->cmd_head != I596_NULL) { | |
977 | lp->cmd_tail->v_next = cmd; | |
978 | lp->cmd_tail->b_next = WSWAPcmd(virt_to_bus(&cmd->status)); | |
979 | } else { | |
980 | lp->cmd_head = cmd; | |
981 | wait_cmd(dev,lp,100,"i596_add_cmd timed out"); | |
982 | lp->scb.cmd = WSWAPcmd(virt_to_bus(&cmd->status)); | |
983 | lp->scb.command = CUC_START; | |
984 | CA(dev); | |
985 | } | |
986 | lp->cmd_tail = cmd; | |
987 | lp->cmd_backlog++; | |
988 | ||
989 | spin_unlock_irqrestore (&lp->lock, flags); | |
990 | ||
991 | if (lp->cmd_backlog > max_cmd_backlog) { | |
992 | unsigned long tickssofar = jiffies - lp->last_cmd; | |
993 | ||
994 | if (tickssofar < ticks_limit) | |
995 | return; | |
996 | ||
997 | printk(KERN_NOTICE "%s: command unit timed out, status resetting.\n", dev->name); | |
998 | ||
999 | i596_reset(dev, lp, ioaddr); | |
1000 | } | |
1001 | } | |
1002 | ||
1003 | static int i596_open(struct net_device *dev) | |
1004 | { | |
1005 | int res = 0; | |
1006 | ||
1007 | DEB(DEB_OPEN,printk(KERN_DEBUG "%s: i596_open() irq %d.\n", dev->name, dev->irq)); | |
1008 | ||
1009 | if (request_irq(dev->irq, i596_interrupt, 0, "i82596", dev)) { | |
1010 | printk(KERN_ERR "%s: IRQ %d not free\n", dev->name, dev->irq); | |
1011 | return -EAGAIN; | |
1012 | } | |
1013 | #ifdef ENABLE_MVME16x_NET | |
1014 | if (MACH_IS_MVME16x) { | |
1015 | if (request_irq(0x56, i596_error, 0, "i82596_error", dev)) | |
1016 | return -EAGAIN; | |
1017 | } | |
1018 | #endif | |
1019 | init_rx_bufs(dev); | |
1020 | ||
1021 | netif_start_queue(dev); | |
1022 | ||
1023 | /* Initialize the 82596 memory */ | |
1024 | if (init_i596_mem(dev)) { | |
1025 | res = -EAGAIN; | |
1026 | free_irq(dev->irq, dev); | |
1027 | } | |
1028 | ||
1029 | return res; | |
1030 | } | |
1031 | ||
1032 | static void i596_tx_timeout (struct net_device *dev) | |
1033 | { | |
1034 | struct i596_private *lp = dev->priv; | |
1035 | int ioaddr = dev->base_addr; | |
1036 | ||
1037 | /* Transmitter timeout, serious problems. */ | |
1038 | DEB(DEB_ERRORS,printk(KERN_ERR "%s: transmit timed out, status resetting.\n", | |
1039 | dev->name)); | |
1040 | ||
1041 | lp->stats.tx_errors++; | |
1042 | ||
1043 | /* Try to restart the adaptor */ | |
1044 | if (lp->last_restart == lp->stats.tx_packets) { | |
1045 | DEB(DEB_ERRORS,printk(KERN_ERR "Resetting board.\n")); | |
1046 | /* Shutdown and restart */ | |
1047 | i596_reset (dev, lp, ioaddr); | |
1048 | } else { | |
1049 | /* Issue a channel attention signal */ | |
1050 | DEB(DEB_ERRORS,printk(KERN_ERR "Kicking board.\n")); | |
1051 | lp->scb.command = CUC_START | RX_START; | |
1052 | CA (dev); | |
1053 | lp->last_restart = lp->stats.tx_packets; | |
1054 | } | |
1055 | ||
1056 | dev->trans_start = jiffies; | |
1057 | netif_wake_queue (dev); | |
1058 | } | |
1059 | ||
1060 | ||
1061 | static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev) | |
1062 | { | |
1063 | struct i596_private *lp = dev->priv; | |
1064 | struct tx_cmd *tx_cmd; | |
1065 | struct i596_tbd *tbd; | |
1066 | short length = skb->len; | |
1067 | dev->trans_start = jiffies; | |
1068 | ||
9e8e83d1 AM |
1069 | DEB(DEB_STARTTX,printk(KERN_DEBUG "%s: i596_start_xmit(%x,%p) called\n", |
1070 | dev->name, skb->len, skb->data)); | |
1da177e4 LT |
1071 | |
1072 | if (skb->len < ETH_ZLEN) { | |
5b057c6b | 1073 | if (skb_padto(skb, ETH_ZLEN)) |
1da177e4 LT |
1074 | return 0; |
1075 | length = ETH_ZLEN; | |
1076 | } | |
1077 | netif_stop_queue(dev); | |
1078 | ||
1079 | tx_cmd = lp->tx_cmds + lp->next_tx_cmd; | |
1080 | tbd = lp->tbds + lp->next_tx_cmd; | |
1081 | ||
1082 | if (tx_cmd->cmd.command) { | |
1083 | printk(KERN_NOTICE "%s: xmit ring full, dropping packet.\n", | |
1084 | dev->name); | |
1085 | lp->stats.tx_dropped++; | |
1086 | ||
1087 | dev_kfree_skb(skb); | |
1088 | } else { | |
1089 | if (++lp->next_tx_cmd == TX_RING_SIZE) | |
1090 | lp->next_tx_cmd = 0; | |
1091 | tx_cmd->tbd = WSWAPtbd(virt_to_bus(tbd)); | |
1092 | tbd->next = I596_NULL; | |
1093 | ||
1094 | tx_cmd->cmd.command = CMD_FLEX | CmdTx; | |
1095 | tx_cmd->skb = skb; | |
1096 | ||
1097 | tx_cmd->pad = 0; | |
1098 | tx_cmd->size = 0; | |
1099 | tbd->pad = 0; | |
1100 | tbd->size = EOF | length; | |
1101 | ||
1102 | tbd->data = WSWAPchar(virt_to_bus(skb->data)); | |
1103 | ||
1104 | #ifdef __mc68000__ | |
1105 | cache_push(virt_to_phys(skb->data), length); | |
1106 | #endif | |
1107 | DEB(DEB_TXADDR,print_eth(skb->data, "tx-queued")); | |
1108 | i596_add_cmd(dev, &tx_cmd->cmd); | |
1109 | ||
1110 | lp->stats.tx_packets++; | |
1111 | lp->stats.tx_bytes += length; | |
1112 | } | |
1113 | ||
1114 | netif_start_queue(dev); | |
1115 | ||
1116 | return 0; | |
1117 | } | |
1118 | ||
1119 | static void print_eth(unsigned char *add, char *str) | |
1120 | { | |
1121 | int i; | |
1122 | ||
1123 | printk(KERN_DEBUG "i596 0x%p, ", add); | |
1124 | for (i = 0; i < 6; i++) | |
1125 | printk(" %02X", add[i + 6]); | |
1126 | printk(" -->"); | |
1127 | for (i = 0; i < 6; i++) | |
1128 | printk(" %02X", add[i]); | |
1129 | printk(" %02X%02X, %s\n", add[12], add[13], str); | |
1130 | } | |
1131 | ||
1132 | static int io = 0x300; | |
1133 | static int irq = 10; | |
1134 | ||
1135 | struct net_device * __init i82596_probe(int unit) | |
1136 | { | |
1137 | struct net_device *dev; | |
1138 | int i; | |
1139 | struct i596_private *lp; | |
1140 | char eth_addr[8]; | |
1141 | static int probed; | |
1142 | int err; | |
1143 | ||
1144 | if (probed) | |
1145 | return ERR_PTR(-ENODEV); | |
1146 | probed++; | |
1147 | ||
1148 | dev = alloc_etherdev(0); | |
1149 | if (!dev) | |
1150 | return ERR_PTR(-ENOMEM); | |
1151 | ||
1152 | if (unit >= 0) { | |
1153 | sprintf(dev->name, "eth%d", unit); | |
1154 | netdev_boot_setup_check(dev); | |
1155 | } else { | |
1156 | dev->base_addr = io; | |
1157 | dev->irq = irq; | |
1158 | } | |
1159 | ||
1160 | #ifdef ENABLE_MVME16x_NET | |
1161 | if (MACH_IS_MVME16x) { | |
1162 | if (mvme16x_config & MVME16x_CONFIG_NO_ETHERNET) { | |
1163 | printk(KERN_NOTICE "Ethernet probe disabled - chip not present\n"); | |
1164 | err = -ENODEV; | |
1165 | goto out; | |
1166 | } | |
1167 | memcpy(eth_addr, (void *) 0xfffc1f2c, 6); /* YUCK! Get addr from NOVRAM */ | |
1168 | dev->base_addr = MVME_I596_BASE; | |
1169 | dev->irq = (unsigned) MVME16x_IRQ_I596; | |
1170 | } | |
1171 | #endif | |
1172 | #ifdef ENABLE_BVME6000_NET | |
1173 | if (MACH_IS_BVME6000) { | |
1174 | volatile unsigned char *rtc = (unsigned char *) BVME_RTC_BASE; | |
1175 | unsigned char msr = rtc[3]; | |
1176 | int i; | |
1177 | ||
1178 | rtc[3] |= 0x80; | |
1179 | for (i = 0; i < 6; i++) | |
1180 | eth_addr[i] = rtc[i * 4 + 7]; /* Stored in RTC RAM at offset 1 */ | |
1181 | rtc[3] = msr; | |
1182 | dev->base_addr = BVME_I596_BASE; | |
1183 | dev->irq = (unsigned) BVME_IRQ_I596; | |
1184 | } | |
1185 | #endif | |
1186 | #ifdef ENABLE_APRICOT | |
1187 | { | |
1188 | int checksum = 0; | |
1189 | int ioaddr = 0x300; | |
1190 | ||
1191 | /* this is easy the ethernet interface can only be at 0x300 */ | |
1192 | /* first check nothing is already registered here */ | |
1193 | ||
1194 | if (!request_region(ioaddr, I596_TOTAL_SIZE, DRV_NAME)) { | |
1195 | printk(KERN_ERR "82596: IO address 0x%04x in use\n", ioaddr); | |
1196 | err = -EBUSY; | |
1197 | goto out; | |
1198 | } | |
1199 | ||
1200 | for (i = 0; i < 8; i++) { | |
1201 | eth_addr[i] = inb(ioaddr + 8 + i); | |
1202 | checksum += eth_addr[i]; | |
1203 | } | |
1204 | ||
1205 | /* checksum is a multiple of 0x100, got this wrong first time | |
1206 | some machines have 0x100, some 0x200. The DOS driver doesn't | |
1207 | even bother with the checksum. | |
1208 | Some other boards trip the checksum.. but then appear as | |
1209 | ether address 0. Trap these - AC */ | |
1210 | ||
6aa20a22 | 1211 | if ((checksum % 0x100) || |
1da177e4 LT |
1212 | (memcmp(eth_addr, "\x00\x00\x49", 3) != 0)) { |
1213 | err = -ENODEV; | |
1214 | goto out1; | |
1215 | } | |
1216 | ||
1217 | dev->base_addr = ioaddr; | |
1218 | dev->irq = 10; | |
1219 | } | |
1220 | #endif | |
1221 | dev->mem_start = (int)__get_free_pages(GFP_ATOMIC, 0); | |
1222 | if (!dev->mem_start) { | |
1223 | err = -ENOMEM; | |
1224 | goto out1; | |
1225 | } | |
1226 | ||
1227 | DEB(DEB_PROBE,printk(KERN_INFO "%s: 82596 at %#3lx,", dev->name, dev->base_addr)); | |
1228 | ||
1229 | for (i = 0; i < 6; i++) | |
1230 | DEB(DEB_PROBE,printk(" %2.2X", dev->dev_addr[i] = eth_addr[i])); | |
1231 | ||
1232 | DEB(DEB_PROBE,printk(" IRQ %d.\n", dev->irq)); | |
1233 | ||
1234 | DEB(DEB_PROBE,printk(KERN_INFO "%s", version)); | |
1235 | ||
1236 | /* The 82596-specific entries in the device structure. */ | |
1da177e4 LT |
1237 | dev->open = i596_open; |
1238 | dev->stop = i596_close; | |
1239 | dev->hard_start_xmit = i596_start_xmit; | |
1240 | dev->get_stats = i596_get_stats; | |
1241 | dev->set_multicast_list = set_multicast_list; | |
1242 | dev->tx_timeout = i596_tx_timeout; | |
1243 | dev->watchdog_timeo = TX_TIMEOUT; | |
1244 | ||
1245 | dev->priv = (void *)(dev->mem_start); | |
1246 | ||
1247 | lp = dev->priv; | |
9e8e83d1 AM |
1248 | DEB(DEB_INIT,printk(KERN_DEBUG "%s: lp at 0x%08lx (%zd bytes), " |
1249 | "lp->scb at 0x%08lx\n", | |
1da177e4 LT |
1250 | dev->name, (unsigned long)lp, |
1251 | sizeof(struct i596_private), (unsigned long)&lp->scb)); | |
1252 | memset((void *) lp, 0, sizeof(struct i596_private)); | |
1253 | ||
1254 | #ifdef __mc68000__ | |
1255 | cache_push(virt_to_phys((void *)(dev->mem_start)), 4096); | |
1256 | cache_clear(virt_to_phys((void *)(dev->mem_start)), 4096); | |
1257 | kernel_set_cachemode((void *)(dev->mem_start), 4096, IOMAP_NOCACHE_SER); | |
1258 | #endif | |
1259 | lp->scb.command = 0; | |
1260 | lp->scb.cmd = I596_NULL; | |
1261 | lp->scb.rfd = I596_NULL; | |
1262 | spin_lock_init(&lp->lock); | |
1263 | ||
1264 | err = register_netdev(dev); | |
1265 | if (err) | |
1266 | goto out2; | |
1267 | return dev; | |
1268 | out2: | |
1269 | #ifdef __mc68000__ | |
1270 | /* XXX This assumes default cache mode to be IOMAP_FULL_CACHING, | |
1271 | * XXX which may be invalid (CONFIG_060_WRITETHROUGH) | |
1272 | */ | |
1273 | kernel_set_cachemode((void *)(dev->mem_start), 4096, | |
1274 | IOMAP_FULL_CACHING); | |
1275 | #endif | |
1276 | free_page ((u32)(dev->mem_start)); | |
1277 | out1: | |
1278 | #ifdef ENABLE_APRICOT | |
1279 | release_region(dev->base_addr, I596_TOTAL_SIZE); | |
1280 | #endif | |
1281 | out: | |
1282 | free_netdev(dev); | |
1283 | return ERR_PTR(err); | |
1284 | } | |
1285 | ||
7d12e780 | 1286 | static irqreturn_t i596_interrupt(int irq, void *dev_id) |
1da177e4 LT |
1287 | { |
1288 | struct net_device *dev = dev_id; | |
1289 | struct i596_private *lp; | |
1290 | short ioaddr; | |
1291 | unsigned short status, ack_cmd = 0; | |
1292 | int handled = 0; | |
1293 | ||
1294 | #ifdef ENABLE_BVME6000_NET | |
1295 | if (MACH_IS_BVME6000) { | |
1296 | if (*(char *) BVME_LOCAL_IRQ_STAT & BVME_ETHERR) { | |
7d12e780 | 1297 | i596_error(irq, dev_id); |
1da177e4 LT |
1298 | return IRQ_HANDLED; |
1299 | } | |
1300 | } | |
1301 | #endif | |
1302 | if (dev == NULL) { | |
1303 | printk(KERN_ERR "i596_interrupt(): irq %d for unknown device.\n", irq); | |
1304 | return IRQ_NONE; | |
1305 | } | |
1306 | ||
1307 | ioaddr = dev->base_addr; | |
1308 | lp = dev->priv; | |
1309 | ||
1310 | spin_lock (&lp->lock); | |
1311 | ||
1312 | wait_cmd(dev,lp,100,"i596 interrupt, timeout"); | |
1313 | status = lp->scb.status; | |
1314 | ||
1315 | DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt, IRQ %d, status %4.4x.\n", | |
1316 | dev->name, irq, status)); | |
1317 | ||
1318 | ack_cmd = status & 0xf000; | |
1319 | ||
1320 | if ((status & 0x8000) || (status & 0x2000)) { | |
1321 | struct i596_cmd *ptr; | |
1322 | ||
1323 | handled = 1; | |
1324 | if ((status & 0x8000)) | |
1325 | DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt completed command.\n", dev->name)); | |
1326 | if ((status & 0x2000)) | |
1327 | DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt command unit inactive %x.\n", dev->name, status & 0x0700)); | |
1328 | ||
1329 | while ((lp->cmd_head != I596_NULL) && (lp->cmd_head->status & STAT_C)) { | |
1330 | ptr = lp->cmd_head; | |
1331 | ||
1332 | DEB(DEB_STATUS,printk(KERN_DEBUG "cmd_head->status = %04x, ->command = %04x\n", | |
1333 | lp->cmd_head->status, lp->cmd_head->command)); | |
1334 | lp->cmd_head = ptr->v_next; | |
1335 | lp->cmd_backlog--; | |
1336 | ||
1337 | switch ((ptr->command) & 0x7) { | |
1338 | case CmdTx: | |
1339 | { | |
1340 | struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr; | |
1341 | struct sk_buff *skb = tx_cmd->skb; | |
1342 | ||
1343 | if ((ptr->status) & STAT_OK) { | |
1344 | DEB(DEB_TXADDR,print_eth(skb->data, "tx-done")); | |
1345 | } else { | |
1346 | lp->stats.tx_errors++; | |
1347 | if ((ptr->status) & 0x0020) | |
1348 | lp->stats.collisions++; | |
1349 | if (!((ptr->status) & 0x0040)) | |
1350 | lp->stats.tx_heartbeat_errors++; | |
1351 | if ((ptr->status) & 0x0400) | |
1352 | lp->stats.tx_carrier_errors++; | |
1353 | if ((ptr->status) & 0x0800) | |
1354 | lp->stats.collisions++; | |
1355 | if ((ptr->status) & 0x1000) | |
1356 | lp->stats.tx_aborted_errors++; | |
1357 | } | |
1358 | ||
1359 | dev_kfree_skb_irq(skb); | |
1360 | ||
1361 | tx_cmd->cmd.command = 0; /* Mark free */ | |
1362 | break; | |
1363 | } | |
1364 | case CmdTDR: | |
1365 | { | |
1366 | unsigned short status = ((struct tdr_cmd *)ptr)->status; | |
1367 | ||
1368 | if (status & 0x8000) { | |
1369 | DEB(DEB_TDR,printk(KERN_INFO "%s: link ok.\n", dev->name)); | |
1370 | } else { | |
1371 | if (status & 0x4000) | |
1372 | printk(KERN_ERR "%s: Transceiver problem.\n", dev->name); | |
1373 | if (status & 0x2000) | |
1374 | printk(KERN_ERR "%s: Termination problem.\n", dev->name); | |
1375 | if (status & 0x1000) | |
1376 | printk(KERN_ERR "%s: Short circuit.\n", dev->name); | |
1377 | ||
1378 | DEB(DEB_TDR,printk(KERN_INFO "%s: Time %d.\n", dev->name, status & 0x07ff)); | |
1379 | } | |
1380 | break; | |
1381 | } | |
1382 | case CmdConfigure: | |
1383 | case CmdMulticastList: | |
1384 | /* Zap command so set_multicast_list() knows it is free */ | |
1385 | ptr->command = 0; | |
1386 | break; | |
1387 | } | |
1388 | ptr->v_next = ptr->b_next = I596_NULL; | |
1389 | lp->last_cmd = jiffies; | |
1390 | } | |
1391 | ||
1392 | ptr = lp->cmd_head; | |
1393 | while ((ptr != I596_NULL) && (ptr != lp->cmd_tail)) { | |
1394 | ptr->command &= 0x1fff; | |
1395 | ptr = ptr->v_next; | |
1396 | } | |
1397 | ||
1398 | if ((lp->cmd_head != I596_NULL)) | |
1399 | ack_cmd |= CUC_START; | |
1400 | lp->scb.cmd = WSWAPcmd(virt_to_bus(&lp->cmd_head->status)); | |
1401 | } | |
1402 | if ((status & 0x1000) || (status & 0x4000)) { | |
1403 | if ((status & 0x4000)) | |
1404 | DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt received a frame.\n", dev->name)); | |
1405 | i596_rx(dev); | |
1406 | /* Only RX_START if stopped - RGH 07-07-96 */ | |
1407 | if (status & 0x1000) { | |
1408 | if (netif_running(dev)) { | |
1409 | DEB(DEB_ERRORS,printk(KERN_ERR "%s: i596 interrupt receive unit inactive, status 0x%x\n", dev->name, status)); | |
1410 | ack_cmd |= RX_START; | |
1411 | lp->stats.rx_errors++; | |
1412 | lp->stats.rx_fifo_errors++; | |
1413 | rebuild_rx_bufs(dev); | |
1414 | } | |
1415 | } | |
1416 | } | |
1417 | wait_cmd(dev,lp,100,"i596 interrupt, timeout"); | |
1418 | lp->scb.command = ack_cmd; | |
1419 | ||
1420 | #ifdef ENABLE_MVME16x_NET | |
1421 | if (MACH_IS_MVME16x) { | |
1422 | /* Ack the interrupt */ | |
1423 | ||
1424 | volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000; | |
1425 | ||
1426 | pcc2[0x2a] |= 0x08; | |
1427 | } | |
1428 | #endif | |
1429 | #ifdef ENABLE_BVME6000_NET | |
1430 | if (MACH_IS_BVME6000) { | |
1431 | volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG; | |
1432 | ||
1433 | *ethirq = 1; | |
1434 | *ethirq = 3; | |
1435 | } | |
1436 | #endif | |
1437 | #ifdef ENABLE_APRICOT | |
1438 | (void) inb(ioaddr + 0x10); | |
1439 | outb(4, ioaddr + 0xf); | |
1440 | #endif | |
1441 | CA(dev); | |
1442 | ||
1443 | DEB(DEB_INTS,printk(KERN_DEBUG "%s: exiting interrupt.\n", dev->name)); | |
1444 | ||
1445 | spin_unlock (&lp->lock); | |
1446 | return IRQ_RETVAL(handled); | |
1447 | } | |
1448 | ||
1449 | static int i596_close(struct net_device *dev) | |
1450 | { | |
1451 | struct i596_private *lp = dev->priv; | |
1452 | unsigned long flags; | |
1453 | ||
1454 | netif_stop_queue(dev); | |
1455 | ||
1456 | DEB(DEB_INIT,printk(KERN_DEBUG "%s: Shutting down ethercard, status was %4.4x.\n", | |
1457 | dev->name, lp->scb.status)); | |
1458 | ||
1459 | spin_lock_irqsave(&lp->lock, flags); | |
1460 | ||
1461 | wait_cmd(dev,lp,100,"close1 timed out"); | |
1462 | lp->scb.command = CUC_ABORT | RX_ABORT; | |
1463 | CA(dev); | |
1464 | ||
1465 | wait_cmd(dev,lp,100,"close2 timed out"); | |
1466 | ||
1467 | spin_unlock_irqrestore(&lp->lock, flags); | |
1468 | DEB(DEB_STRUCT,i596_display_data(dev)); | |
1469 | i596_cleanup_cmd(dev,lp); | |
1470 | ||
1471 | #ifdef ENABLE_MVME16x_NET | |
1472 | if (MACH_IS_MVME16x) { | |
1473 | volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000; | |
1474 | ||
1475 | /* Disable all ints */ | |
1476 | pcc2[0x28] = 1; | |
1477 | pcc2[0x2a] = 0x40; | |
1478 | pcc2[0x2b] = 0x40; /* Set snooping bits now! */ | |
1479 | } | |
1480 | #endif | |
1481 | #ifdef ENABLE_BVME6000_NET | |
1482 | if (MACH_IS_BVME6000) { | |
1483 | volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG; | |
1484 | ||
1485 | *ethirq = 1; | |
1486 | } | |
1487 | #endif | |
1488 | ||
1489 | free_irq(dev->irq, dev); | |
1490 | remove_rx_bufs(dev); | |
1491 | ||
1492 | return 0; | |
1493 | } | |
1494 | ||
1495 | static struct net_device_stats * | |
1496 | i596_get_stats(struct net_device *dev) | |
1497 | { | |
1498 | struct i596_private *lp = dev->priv; | |
1499 | ||
1500 | return &lp->stats; | |
1501 | } | |
1502 | ||
1503 | /* | |
1504 | * Set or clear the multicast filter for this adaptor. | |
1505 | */ | |
1506 | ||
1507 | static void set_multicast_list(struct net_device *dev) | |
1508 | { | |
1509 | struct i596_private *lp = dev->priv; | |
1510 | int config = 0, cnt; | |
1511 | ||
1512 | DEB(DEB_MULTI,printk(KERN_DEBUG "%s: set multicast list, %d entries, promisc %s, allmulti %s\n", | |
1513 | dev->name, dev->mc_count, | |
1514 | dev->flags & IFF_PROMISC ? "ON" : "OFF", | |
1515 | dev->flags & IFF_ALLMULTI ? "ON" : "OFF")); | |
1516 | ||
1517 | if (wait_cfg(dev, &lp->cf_cmd.cmd, 1000, "config change request timed out")) | |
1518 | return; | |
1519 | ||
1520 | if ((dev->flags & IFF_PROMISC) && !(lp->cf_cmd.i596_config[8] & 0x01)) { | |
1521 | lp->cf_cmd.i596_config[8] |= 0x01; | |
1522 | config = 1; | |
1523 | } | |
1524 | if (!(dev->flags & IFF_PROMISC) && (lp->cf_cmd.i596_config[8] & 0x01)) { | |
1525 | lp->cf_cmd.i596_config[8] &= ~0x01; | |
1526 | config = 1; | |
1527 | } | |
1528 | if ((dev->flags & IFF_ALLMULTI) && (lp->cf_cmd.i596_config[11] & 0x20)) { | |
1529 | lp->cf_cmd.i596_config[11] &= ~0x20; | |
1530 | config = 1; | |
1531 | } | |
1532 | if (!(dev->flags & IFF_ALLMULTI) && !(lp->cf_cmd.i596_config[11] & 0x20)) { | |
1533 | lp->cf_cmd.i596_config[11] |= 0x20; | |
1534 | config = 1; | |
1535 | } | |
1536 | if (config) { | |
1537 | lp->cf_cmd.cmd.command = CmdConfigure; | |
1538 | i596_add_cmd(dev, &lp->cf_cmd.cmd); | |
1539 | } | |
1540 | ||
1541 | cnt = dev->mc_count; | |
1542 | if (cnt > MAX_MC_CNT) | |
1543 | { | |
1544 | cnt = MAX_MC_CNT; | |
1545 | printk(KERN_ERR "%s: Only %d multicast addresses supported", | |
1546 | dev->name, cnt); | |
1547 | } | |
6aa20a22 | 1548 | |
1da177e4 LT |
1549 | if (dev->mc_count > 0) { |
1550 | struct dev_mc_list *dmi; | |
1551 | unsigned char *cp; | |
1552 | struct mc_cmd *cmd; | |
1553 | ||
1554 | if (wait_cfg(dev, &lp->mc_cmd.cmd, 1000, "multicast list change request timed out")) | |
1555 | return; | |
1556 | cmd = &lp->mc_cmd; | |
1557 | cmd->cmd.command = CmdMulticastList; | |
1558 | cmd->mc_cnt = dev->mc_count * 6; | |
1559 | cp = cmd->mc_addrs; | |
1560 | for (dmi = dev->mc_list; cnt && dmi != NULL; dmi = dmi->next, cnt--, cp += 6) { | |
1561 | memcpy(cp, dmi->dmi_addr, 6); | |
1562 | if (i596_debug > 1) | |
1563 | DEB(DEB_MULTI,printk(KERN_INFO "%s: Adding address %02x:%02x:%02x:%02x:%02x:%02x\n", | |
1564 | dev->name, cp[0],cp[1],cp[2],cp[3],cp[4],cp[5])); | |
1565 | } | |
1566 | i596_add_cmd(dev, &cmd->cmd); | |
1567 | } | |
1568 | } | |
1569 | ||
1570 | #ifdef MODULE | |
1571 | static struct net_device *dev_82596; | |
1572 | ||
1573 | #ifdef ENABLE_APRICOT | |
1574 | module_param(irq, int, 0); | |
1575 | MODULE_PARM_DESC(irq, "Apricot IRQ number"); | |
1576 | #endif | |
1577 | ||
1578 | static int debug = -1; | |
1579 | module_param(debug, int, 0); | |
1580 | MODULE_PARM_DESC(debug, "i82596 debug mask"); | |
1581 | ||
864fe05d | 1582 | int __init init_module(void) |
1da177e4 LT |
1583 | { |
1584 | if (debug >= 0) | |
1585 | i596_debug = debug; | |
1586 | dev_82596 = i82596_probe(-1); | |
1587 | if (IS_ERR(dev_82596)) | |
1588 | return PTR_ERR(dev_82596); | |
1589 | return 0; | |
1590 | } | |
1591 | ||
864fe05d | 1592 | void __exit cleanup_module(void) |
1da177e4 LT |
1593 | { |
1594 | unregister_netdev(dev_82596); | |
1595 | #ifdef __mc68000__ | |
1596 | /* XXX This assumes default cache mode to be IOMAP_FULL_CACHING, | |
1597 | * XXX which may be invalid (CONFIG_060_WRITETHROUGH) | |
1598 | */ | |
1599 | ||
1600 | kernel_set_cachemode((void *)(dev_82596->mem_start), 4096, | |
1601 | IOMAP_FULL_CACHING); | |
1602 | #endif | |
1603 | free_page ((u32)(dev_82596->mem_start)); | |
1604 | #ifdef ENABLE_APRICOT | |
1605 | /* If we don't do this, we can't re-insmod it later. */ | |
1606 | release_region(dev_82596->base_addr, I596_TOTAL_SIZE); | |
1607 | #endif | |
1608 | free_netdev(dev_82596); | |
1609 | } | |
1610 | ||
1611 | #endif /* MODULE */ | |
6aa20a22 | 1612 | |
1da177e4 LT |
1613 | /* |
1614 | * Local variables: | |
1615 | * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c 82596.c" | |
1616 | * End: | |
1617 | */ |