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