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