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