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