This source file includes following definitions.
- at1700_probe
- at1700_probe1
- read_eeprom
- net_open
- net_send_packet
- net_interrupt
- net_rx
- net_close
- net_get_stats
- set_multicast_list
1
2
3
4
5
6
7
8
9
10
11
12
13
14 static char *version =
15 "at1700.c:v0.06 3/3/94 Donald Becker (becker@super.org)\n";
16
17 #include <linux/config.h>
18
19
20
21
22
23
24
25
26
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/types.h>
30 #include <linux/fcntl.h>
31 #include <linux/interrupt.h>
32 #include <linux/ptrace.h>
33 #include <linux/ioport.h>
34 #include <linux/in.h>
35 #include <linux/malloc.h>
36 #include <linux/string.h>
37 #include <asm/system.h>
38 #include <asm/bitops.h>
39 #include <asm/io.h>
40 #include <asm/dma.h>
41 #include <errno.h>
42
43 #include <linux/netdevice.h>
44 #include <linux/etherdevice.h>
45 #include <linux/skbuff.h>
46
47 #ifndef HAVE_AUTOIRQ
48
49 extern void autoirq_setup(int waittime);
50 extern int autoirq_report(int waittime);
51
52
53 extern struct device *irq2dev_map[16];
54 #endif
55
56
57 #ifndef NET_DEBUG
58 #define NET_DEBUG 2
59 #endif
60 static unsigned int net_debug = NET_DEBUG;
61
62 typedef unsigned char uchar;
63
64
65 struct net_local {
66 struct enet_statistics stats;
67 long open_time;
68 uint tx_started:1;
69 uchar tx_queue;
70 ushort tx_queue_len;
71 };
72
73
74
75 #define STATUS 0
76 #define TX_STATUS 0
77 #define RX_STATUS 1
78 #define TX_INTR 2
79 #define RX_INTR 3
80 #define TX_MODE 4
81 #define RX_MODE 5
82 #define CONFIG_0 6
83 #define CONFIG_1 7
84
85 #define DATAPORT 8
86 #define TX_START 10
87 #define MODE13 13
88 #define EEPROM_Ctrl 16
89 #define EEPROM_Data 17
90
91
92 #define EE_SHIFT_CLK 0x40
93 #define EE_CS 0x20
94 #define EE_DATA_WRITE 0x80
95 #define EE_DATA_READ 0x80
96
97
98 #define eeprom_delay() do { int _i = 40; while (--_i > 0) { __SLOW_DOWN_IO; }} while (0)
99
100
101 #define EE_WRITE_CMD (5 << 6)
102 #define EE_READ_CMD (6 << 6)
103 #define EE_ERASE_CMD (7 << 6)
104
105
106
107
108 extern int at1700_probe(struct device *dev);
109
110 static int at1700_probe1(struct device *dev, short ioaddr);
111 static int read_eeprom(int ioaddr, int location);
112 static int net_open(struct device *dev);
113 static int net_send_packet(struct sk_buff *skb, struct device *dev);
114 static void net_interrupt(int reg_ptr);
115 static void net_rx(struct device *dev);
116 static int net_close(struct device *dev);
117 static struct enet_statistics *net_get_stats(struct device *dev);
118 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
119
120
121
122
123
124
125
126
127 int
128 at1700_probe(struct device *dev)
129 {
130 short ports[] = {0x300, 0x280, 0x380, 0x320, 0x340, 0x260, 0x2a0, 0x240, 0};
131 short *port, base_addr = dev->base_addr;
132
133 if (base_addr > 0x1ff)
134 return at1700_probe1(dev, base_addr);
135 else if (base_addr > 0)
136 return ENXIO;
137
138 for (port = &ports[0]; *port; port++) {
139 int ioaddr = *port;
140 if (check_region(ioaddr, 32))
141 continue;
142 if (at1700_probe1(dev, ioaddr) == 0)
143 return 0;
144 }
145
146 return ENODEV;
147 }
148
149
150
151
152
153
154
155
156
157 int at1700_probe1(struct device *dev, short ioaddr)
158 {
159 unsigned short signature[4] = {0xffff, 0xffff, 0x7ff7, 0xff5f};
160 unsigned short signature_invalid[4] = {0xffff, 0xffff, 0x7ff7, 0xdf0f};
161 char irqmap[8] = {3, 4, 5, 9, 10, 11, 14, 15};
162 unsigned short *station_address = (unsigned short *)dev->dev_addr;
163 unsigned int i, irq;
164
165
166
167
168 for (i = 0; i < 4; i++)
169 if ((inw(ioaddr + 2*i) | signature_invalid[i]) != signature[i]) {
170 if (net_debug > 2)
171 printk("AT1700 signature match failed at %d (%04x vs. %04x)\n",
172 i, inw(ioaddr + 2*i), signature[i]);
173 return -ENODEV;
174 }
175 if (read_eeprom(ioaddr, 4) != 0x0000
176 || read_eeprom(ioaddr, 5) & 0x00ff != 0x00F4)
177 return -ENODEV;
178
179
180
181 snarf_region(ioaddr, 32);
182
183 irq = irqmap[(read_eeprom(ioaddr, 12)&0x04)
184 | (read_eeprom(ioaddr, 0)>>14)];
185
186
187 if (request_irq(irq, &net_interrupt, 0, "at1700")) {
188 printk ("AT1700 found at %#3x, but it's unusable due to a conflict on"
189 "IRQ %d.\n", ioaddr, irq);
190 return EAGAIN;
191 }
192
193 printk("%s: AT1700 found at %#3x, IRQ %d, address ", dev->name,
194 ioaddr, irq);
195
196 dev->base_addr = ioaddr;
197 dev->irq = irq;
198 irq2dev_map[irq] = dev;
199
200 for(i = 0; i < 3; i++) {
201 unsigned short eeprom_val = read_eeprom(ioaddr, 4+i);
202 printk("%04x", eeprom_val);
203 station_address[i] = ntohs(eeprom_val);
204 }
205
206
207
208
209
210
211
212 {
213 char *porttype[] = {"auto-sense", "10baseT", "auto-sense", "10base2"};
214 ushort setup_value = read_eeprom(ioaddr, 12);
215
216 dev->if_port = setup_value >> 8;
217 printk(" %s interface (%04x).\n", porttype[(dev->if_port>>3) & 3],
218 setup_value);
219 }
220
221
222 outb(0xe0, ioaddr + 7);
223 for (i = 0; i < 6; i++)
224 outb(dev->dev_addr[i], ioaddr + 8 + i);
225
226
227 outb(0xe4, ioaddr + 7);
228 for (i = 0; i < 8; i++)
229 outb(0x00, ioaddr + 8 + i);
230
231
232
233 outb(0xda, ioaddr + CONFIG_0);
234
235
236 outb(0xe8, ioaddr + 7);
237 outb(dev->if_port, MODE13);
238
239
240 outb(0x00, ioaddr + CONFIG_1);
241
242 if (net_debug)
243 printk(version);
244
245
246 dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
247 memset(dev->priv, 0, sizeof(struct net_local));
248
249 dev->open = net_open;
250 dev->stop = net_close;
251 dev->hard_start_xmit = net_send_packet;
252 dev->get_stats = net_get_stats;
253 dev->set_multicast_list = &set_multicast_list;
254
255
256
257 ether_setup(dev);
258 return 0;
259 }
260
261 static int read_eeprom(int ioaddr, int location)
262 {
263 int i;
264 unsigned short retval = 0;
265 short ee_addr = ioaddr + EEPROM_Ctrl;
266 short ee_daddr = ioaddr + EEPROM_Data;
267 int read_cmd = location | EE_READ_CMD;
268 short ctrl_val = EE_CS;
269
270 outb(ctrl_val, ee_addr);
271
272
273 for (i = 9; i >= 0; i--) {
274 short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
275 outb(dataval, ee_daddr);
276 outb(EE_CS | EE_SHIFT_CLK, ee_addr);
277 eeprom_delay();
278 outb(EE_CS, ee_addr);
279 eeprom_delay();
280 }
281 outb(EE_CS, ee_addr);
282
283 for (i = 16; i > 0; i--) {
284 outb(EE_CS | EE_SHIFT_CLK, ee_addr);
285 eeprom_delay();
286 retval = (retval << 1) | ((inb(ee_daddr) & EE_DATA_READ) ? 1 : 0);
287 outb(EE_CS, ee_addr);
288 eeprom_delay();
289 }
290
291
292 ctrl_val &= ~EE_CS;
293 outb(ctrl_val | EE_SHIFT_CLK, ee_addr);
294 eeprom_delay();
295 outb(ctrl_val, ee_addr);
296 eeprom_delay();
297 return retval;
298 }
299
300
301
302 static int net_open(struct device *dev)
303 {
304 struct net_local *lp = (struct net_local *)dev->priv;
305 int ioaddr = dev->base_addr;
306 int i;
307
308
309 outb(0xe0, ioaddr + CONFIG_1);
310
311
312 for (i = 0; i < 6; i++)
313 outb(dev->dev_addr[i], ioaddr + 8 + i);
314
315
316 outb(0xe4, ioaddr + 7);
317 for (i = 0; i < 8; i++)
318 outb(0x00, ioaddr + 8 + i);
319
320
321
322 outb(0xda, ioaddr + CONFIG_0);
323
324
325 outb(0x5a, ioaddr + CONFIG_0);
326
327 outb(0xe8, ioaddr + CONFIG_1);
328
329
330 outb(0x00, ioaddr + TX_INTR);
331 outb(0x81, ioaddr + RX_INTR);
332
333 lp->open_time = jiffies;
334
335 dev->tbusy = 0;
336 dev->interrupt = 0;
337 dev->start = 1;
338
339 return 0;
340 }
341
342 static int
343 net_send_packet(struct sk_buff *skb, struct device *dev)
344 {
345 struct net_local *lp = (struct net_local *)dev->priv;
346 int ioaddr = dev->base_addr;
347
348 if (dev->tbusy) {
349
350
351 int tickssofar = jiffies - dev->trans_start;
352 if (tickssofar < 10)
353 return 1;
354 printk("%s: transmit timed out with status %04x, %s?\n", dev->name,
355 inw(ioaddr + STATUS), inb(ioaddr + TX_STATUS) & 0x80
356 ? "IRQ conflict" : "network cable problem");
357 printk("%s: timeout registers: %04x %04x %04x %04x %04x %04x %04x %04x.\n",
358 dev->name, inw(ioaddr + 0), inw(ioaddr + 2), inw(ioaddr + 4),
359 inw(ioaddr + 6), inw(ioaddr + 8), inw(ioaddr + 10),
360 inw(ioaddr + 12), inw(ioaddr + 14));
361 lp->stats.tx_errors++;
362
363 outw(0xffff, ioaddr + 24);
364 outw(0xffff, ioaddr + TX_STATUS);
365 outw(0xe85a, ioaddr + CONFIG_0);
366 outw(0x8100, ioaddr + TX_INTR);
367 dev->tbusy=0;
368 dev->trans_start = jiffies;
369 }
370
371
372
373
374 if (skb == NULL) {
375 dev_tint(dev);
376 return 0;
377 }
378
379
380
381 if (set_bit(0, (void*)&dev->tbusy) != 0)
382 printk("%s: Transmitter access conflict.\n", dev->name);
383 else {
384 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
385 unsigned char *buf = skb->data;
386
387
388 outb(0x00, ioaddr + TX_INTR);
389
390 outw(length, ioaddr + DATAPORT);
391 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
392
393 lp->tx_queue++;
394 lp->tx_queue_len += length + 2;
395
396 if (lp->tx_started == 0) {
397
398 outb(0x80 | lp->tx_queue, ioaddr + TX_START);
399 lp->tx_queue = 0;
400 lp->tx_queue_len = 0;
401 dev->trans_start = jiffies;
402 lp->tx_started = 1;
403 } else if (lp->tx_queue_len < 4096 - 1502)
404 dev->tbusy = 0;
405
406
407 outb(0x82, ioaddr + TX_INTR);
408 }
409 dev_kfree_skb (skb, FREE_WRITE);
410
411 return 0;
412 }
413
414
415
416 static void
417 net_interrupt(int reg_ptr)
418 {
419 int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
420 struct device *dev = (struct device *)(irq2dev_map[irq]);
421 struct net_local *lp;
422 int ioaddr, status;
423
424 if (dev == NULL) {
425 printk ("at1700_interrupt(): irq %d for unknown device.\n", irq);
426 return;
427 }
428 dev->interrupt = 1;
429
430 ioaddr = dev->base_addr;
431 lp = (struct net_local *)dev->priv;
432 status = inw(ioaddr + TX_STATUS);
433 outw(status, ioaddr + TX_STATUS);
434
435 if (net_debug > 4)
436 printk("%s: Interrupt with status %04x.\n", dev->name, status);
437 if (status & 0xff00
438 || (inb(ioaddr + RX_MODE) & 0x40) == 0) {
439 net_rx(dev);
440 }
441 if (status & 0x00ff) {
442 if (status & 0x80) {
443 lp->stats.tx_packets++;
444 if (lp->tx_queue) {
445 outb(0x80 | lp->tx_queue, ioaddr + TX_START);
446 lp->tx_queue = 0;
447 lp->tx_queue_len = 0;
448 dev->trans_start = jiffies;
449 dev->tbusy = 0;
450 mark_bh(NET_BH);
451 } else {
452 lp->tx_started = 0;
453
454 outb(0x00, ioaddr + TX_INTR);
455 dev->tbusy = 0;
456 }
457 }
458 }
459
460 return;
461 }
462
463
464 static void
465 net_rx(struct device *dev)
466 {
467 struct net_local *lp = (struct net_local *)dev->priv;
468 int ioaddr = dev->base_addr;
469 int boguscount = 5;
470
471 while ((inb(ioaddr + RX_MODE) & 0x40) == 0) {
472 ushort status = inw(ioaddr + DATAPORT);
473
474 if (net_debug > 4)
475 printk("%s: Rxing packet mode %02x status %04x.\n",
476 dev->name, inb(ioaddr + RX_MODE), status);
477 #ifndef final_version
478 if (status == 0) {
479 outb(0x05, ioaddr + 14);
480 break;
481 }
482 #endif
483
484 if ((status & 0xF0) != 0x20) {
485 lp->stats.rx_errors++;
486 if (status & 0x08) lp->stats.rx_length_errors++;
487 if (status & 0x04) lp->stats.rx_frame_errors++;
488 if (status & 0x02) lp->stats.rx_crc_errors++;
489 if (status & 0x01) lp->stats.rx_over_errors++;
490 } else {
491 ushort pkt_len = inw(ioaddr + DATAPORT);
492
493 struct sk_buff *skb;
494
495 if (pkt_len > 1550) {
496 printk("%s: The AT1700 claimed a very large packet, size %d.\n",
497 dev->name, pkt_len);
498 outb(0x05, ioaddr + 14);
499 lp->stats.rx_errors++;
500 break;
501 }
502 skb = alloc_skb(pkt_len, GFP_ATOMIC);
503 if (skb == NULL) {
504 printk("%s: Memory squeeze, dropping packet (len %d).\n",
505 dev->name, pkt_len);
506 outb(0x05, ioaddr + 14);
507 lp->stats.rx_dropped++;
508 break;
509 }
510 skb->len = pkt_len;
511 skb->dev = dev;
512
513 insw(ioaddr + DATAPORT, skb->data, (pkt_len + 1) >> 1);
514
515 if (net_debug > 5) {
516 int i;
517 printk("%s: Rxed packet of length %d: ", dev->name, pkt_len);
518 for (i = 0; i < 14; i++)
519 printk(" %02x", skb->data[i]);
520 printk(".\n");
521 }
522
523 netif_rx(skb);
524 lp->stats.rx_packets++;
525 }
526 if (--boguscount <= 0)
527 break;
528 }
529
530
531
532
533 {
534 int i;
535 for (i = 0; i < 20; i++) {
536 if ((inb(ioaddr + RX_MODE) & 0x40) == 0x40)
537 break;
538 outb(0x05, ioaddr + 14);
539 }
540
541 if (net_debug > 5)
542 printk("%s: Exint Rx packet with mode %02x after %d ticks.\n",
543 dev->name, inb(ioaddr + RX_MODE), i);
544 }
545 return;
546 }
547
548
549 static int net_close(struct device *dev)
550 {
551 struct net_local *lp = (struct net_local *)dev->priv;
552 int ioaddr = dev->base_addr;
553
554 lp->open_time = 0;
555
556 dev->tbusy = 1;
557 dev->start = 0;
558
559
560 outb(0xda, ioaddr + CONFIG_0);
561
562
563
564
565 outb(0x00, ioaddr + CONFIG_1);
566
567 return 0;
568 }
569
570
571
572 static struct enet_statistics *
573 net_get_stats(struct device *dev)
574 {
575 struct net_local *lp = (struct net_local *)dev->priv;
576
577 cli();
578
579 sti();
580
581 return &lp->stats;
582 }
583
584
585
586
587
588
589
590 static void
591 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
592 {
593 short ioaddr = dev->base_addr;
594 if (num_addrs) {
595 outw(3, ioaddr + RX_MODE);
596 } else
597 outw(2, ioaddr + RX_MODE);
598 }
599
600
601
602
603
604
605
606
607