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