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));
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 dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
267 if (dev->priv == NULL)
268 return -ENOMEM;
269 memset(dev->priv, 0, sizeof(struct net_local));
270
271 dev->open = net_open;
272 dev->stop = net_close;
273 dev->hard_start_xmit = net_send_packet;
274 dev->get_stats = net_get_stats;
275 dev->set_multicast_list = &set_multicast_list;
276
277
278
279 ether_setup(dev);
280 return 0;
281 }
282
283 static int read_eeprom(int ioaddr, int location)
284 {
285 int i;
286 unsigned short retval = 0;
287 short ee_addr = ioaddr + EEPROM_Ctrl;
288 short ee_daddr = ioaddr + EEPROM_Data;
289 int read_cmd = location | EE_READ_CMD;
290 short ctrl_val = EE_CS;
291
292 outb(ctrl_val, ee_addr);
293
294
295 for (i = 9; i >= 0; i--) {
296 short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
297 outb(dataval, ee_daddr);
298 outb(EE_CS | EE_SHIFT_CLK, ee_addr);
299 eeprom_delay();
300 outb(EE_CS, ee_addr);
301 eeprom_delay();
302 }
303 outb(EE_CS, ee_addr);
304
305 for (i = 16; i > 0; i--) {
306 outb(EE_CS | EE_SHIFT_CLK, ee_addr);
307 eeprom_delay();
308 retval = (retval << 1) | ((inb(ee_daddr) & EE_DATA_READ) ? 1 : 0);
309 outb(EE_CS, ee_addr);
310 eeprom_delay();
311 }
312
313
314 ctrl_val &= ~EE_CS;
315 outb(ctrl_val | EE_SHIFT_CLK, ee_addr);
316 eeprom_delay();
317 outb(ctrl_val, ee_addr);
318 eeprom_delay();
319 return retval;
320 }
321
322
323
324 static int net_open(struct device *dev)
325 {
326 struct net_local *lp = (struct net_local *)dev->priv;
327 int ioaddr = dev->base_addr;
328 int i;
329
330
331 outb(0xe0, ioaddr + CONFIG_1);
332
333
334 for (i = 0; i < 6; i++)
335 outb(dev->dev_addr[i], ioaddr + 8 + i);
336
337
338 outb(0xe4, ioaddr + 7);
339 for (i = 0; i < 8; i++)
340 outb(0x00, ioaddr + 8 + i);
341
342
343
344 outb(0xda, ioaddr + CONFIG_0);
345
346
347 outb(0x5a, ioaddr + CONFIG_0);
348
349 outb(0xe8, ioaddr + CONFIG_1);
350
351 lp->tx_started = 0;
352 lp->tx_queue = 0;
353 lp->tx_queue_len = 0;
354
355
356 outb(0x00, ioaddr + TX_INTR);
357 outb(0x81, ioaddr + RX_INTR);
358
359 dev->tbusy = 0;
360 dev->interrupt = 0;
361 dev->start = 1;
362
363 #ifdef MODULE
364 MOD_INC_USE_COUNT;
365 #endif
366
367 return 0;
368 }
369
370 static int
371 net_send_packet(struct sk_buff *skb, struct device *dev)
372 {
373 struct net_local *lp = (struct net_local *)dev->priv;
374 int ioaddr = dev->base_addr;
375
376 if (dev->tbusy) {
377
378
379 int tickssofar = jiffies - dev->trans_start;
380 if (tickssofar < 10)
381 return 1;
382 printk("%s: transmit timed out with status %04x, %s?\n", dev->name,
383 inw(ioaddr + STATUS), inb(ioaddr + TX_STATUS) & 0x80
384 ? "IRQ conflict" : "network cable problem");
385 printk("%s: timeout registers: %04x %04x %04x %04x %04x %04x %04x %04x.\n",
386 dev->name, inw(ioaddr + 0), inw(ioaddr + 2), inw(ioaddr + 4),
387 inw(ioaddr + 6), inw(ioaddr + 8), inw(ioaddr + 10),
388 inw(ioaddr + 12), inw(ioaddr + 14));
389 lp->stats.tx_errors++;
390
391 outw(0xffff, ioaddr + 24);
392 outw(0xffff, ioaddr + TX_STATUS);
393 outw(0xe85a, ioaddr + CONFIG_0);
394 outw(0x8100, ioaddr + TX_INTR);
395 dev->tbusy=0;
396 dev->trans_start = jiffies;
397 lp->tx_started = 0;
398 lp->tx_queue = 0;
399 lp->tx_queue_len = 0;
400 }
401
402
403
404
405 if (skb == NULL) {
406 dev_tint(dev);
407 return 0;
408 }
409
410
411
412 if (set_bit(0, (void*)&dev->tbusy) != 0)
413 printk("%s: Transmitter access conflict.\n", dev->name);
414 else {
415 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
416 unsigned char *buf = skb->data;
417
418
419 outb(0x00, ioaddr + TX_INTR);
420
421 outw(length, ioaddr + DATAPORT);
422 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
423
424 lp->tx_queue++;
425 lp->tx_queue_len += length + 2;
426
427 if (lp->tx_started == 0) {
428
429 outb(0x80 | lp->tx_queue, ioaddr + TX_START);
430 lp->tx_queue = 0;
431 lp->tx_queue_len = 0;
432 dev->trans_start = jiffies;
433 lp->tx_started = 1;
434 dev->tbusy = 0;
435 } else if (lp->tx_queue_len < 4096 - 1502)
436
437 dev->tbusy = 0;
438
439
440 outb(0x82, ioaddr + TX_INTR);
441 }
442 dev_kfree_skb (skb, FREE_WRITE);
443
444 return 0;
445 }
446
447
448
449 static void
450 net_interrupt(int irq, struct pt_regs *regs)
451 {
452 struct device *dev = (struct device *)(irq2dev_map[irq]);
453 struct net_local *lp;
454 int ioaddr, status;
455
456 if (dev == NULL) {
457 printk ("at1700_interrupt(): irq %d for unknown device.\n", irq);
458 return;
459 }
460 dev->interrupt = 1;
461
462 ioaddr = dev->base_addr;
463 lp = (struct net_local *)dev->priv;
464 status = inw(ioaddr + TX_STATUS);
465 outw(status, ioaddr + TX_STATUS);
466
467 if (net_debug > 4)
468 printk("%s: Interrupt with status %04x.\n", dev->name, status);
469 if (status & 0xff00
470 || (inb(ioaddr + RX_MODE) & 0x40) == 0) {
471 net_rx(dev);
472 }
473 if (status & 0x00ff) {
474 if (status & 0x80) {
475 lp->stats.tx_packets++;
476 if (lp->tx_queue) {
477 outb(0x80 | lp->tx_queue, ioaddr + TX_START);
478 lp->tx_queue = 0;
479 lp->tx_queue_len = 0;
480 dev->trans_start = jiffies;
481 dev->tbusy = 0;
482 mark_bh(NET_BH);
483 } else {
484 lp->tx_started = 0;
485
486 outb(0x00, ioaddr + TX_INTR);
487 dev->tbusy = 0;
488 mark_bh(NET_BH);
489 }
490 }
491 }
492
493 dev->interrupt = 0;
494 return;
495 }
496
497
498 static void
499 net_rx(struct device *dev)
500 {
501 struct net_local *lp = (struct net_local *)dev->priv;
502 int ioaddr = dev->base_addr;
503 int boguscount = 5;
504
505 while ((inb(ioaddr + RX_MODE) & 0x40) == 0) {
506 ushort status = inw(ioaddr + DATAPORT);
507 ushort pkt_len = inw(ioaddr + DATAPORT);
508
509 if (net_debug > 4)
510 printk("%s: Rxing packet mode %02x status %04x.\n",
511 dev->name, inb(ioaddr + RX_MODE), status);
512 #ifndef final_version
513 if (status == 0) {
514 outb(0x05, ioaddr + 14);
515 break;
516 }
517 #endif
518
519 if ((status & 0xF0) != 0x20) {
520 lp->stats.rx_errors++;
521 if (status & 0x08) lp->stats.rx_length_errors++;
522 if (status & 0x04) lp->stats.rx_frame_errors++;
523 if (status & 0x02) lp->stats.rx_crc_errors++;
524 if (status & 0x01) lp->stats.rx_over_errors++;
525 } else {
526
527 struct sk_buff *skb;
528
529 if (pkt_len > 1550) {
530 printk("%s: The AT1700 claimed a very large packet, size %d.\n",
531 dev->name, pkt_len);
532
533 inw(ioaddr + DATAPORT); inw(ioaddr + DATAPORT);
534 outb(0x05, ioaddr + 14);
535 lp->stats.rx_errors++;
536 break;
537 }
538 skb = dev_alloc_skb(pkt_len+3);
539 if (skb == NULL) {
540 printk("%s: Memory squeeze, dropping packet (len %d).\n",
541 dev->name, pkt_len);
542
543 inw(ioaddr + DATAPORT); inw(ioaddr + DATAPORT);
544 outb(0x05, ioaddr + 14);
545 lp->stats.rx_dropped++;
546 break;
547 }
548 skb->dev = dev;
549 skb_reserve(skb,2);
550
551 insw(ioaddr + DATAPORT, skb_put(skb,pkt_len), (pkt_len + 1) >> 1);
552 skb->protocol=eth_type_trans(skb, dev);
553 netif_rx(skb);
554 lp->stats.rx_packets++;
555 }
556 if (--boguscount <= 0)
557 break;
558 }
559
560
561
562
563 {
564 int i;
565 for (i = 0; i < 20; i++) {
566 if ((inb(ioaddr + RX_MODE) & 0x40) == 0x40)
567 break;
568 inw(ioaddr + DATAPORT);
569 outb(0x05, ioaddr + 14);
570 }
571
572 if (net_debug > 5)
573 printk("%s: Exint Rx packet with mode %02x after %d ticks.\n",
574 dev->name, inb(ioaddr + RX_MODE), i);
575 }
576 return;
577 }
578
579
580 static int net_close(struct device *dev)
581 {
582 int ioaddr = dev->base_addr;
583
584 dev->tbusy = 1;
585 dev->start = 0;
586
587
588 outb(0xda, ioaddr + CONFIG_0);
589
590
591
592
593 outb(0x00, ioaddr + CONFIG_1);
594
595 #ifdef MODULE
596 MOD_DEC_USE_COUNT;
597 #endif
598
599 return 0;
600 }
601
602
603
604 static struct enet_statistics *
605 net_get_stats(struct device *dev)
606 {
607 struct net_local *lp = (struct net_local *)dev->priv;
608
609 cli();
610
611 sti();
612
613 return &lp->stats;
614 }
615
616
617
618
619
620
621
622 static void
623 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
624 {
625 short ioaddr = dev->base_addr;
626 if (num_addrs)
627 {
628
629
630
631
632
633 dev->flags|=IFF_PROMISC;
634
635 outb(3, ioaddr + RX_MODE);
636 }
637 else
638 outb(2, ioaddr + RX_MODE);
639 }
640 #ifdef MODULE
641 char kernel_version[] = UTS_RELEASE;
642 static char devicename[9] = { 0, };
643 static struct device dev_at1700 = {
644 devicename,
645 0, 0, 0, 0,
646 0, 0,
647 0, 0, 0, NULL, at1700_probe };
648
649 int io = 0x260;
650 int irq = 0;
651
652 int init_module(void)
653 {
654 if (io == 0)
655 printk("at1700: You should not use auto-probing with insmod!\n");
656 dev_at1700.base_addr = io;
657 dev_at1700.irq = irq;
658 if (register_netdev(&dev_at1700) != 0) {
659 printk("at1700: register_netdev() returned non-zero.\n");
660 return -EIO;
661 }
662 return 0;
663 }
664
665 void
666 cleanup_module(void)
667 {
668 if (MOD_IN_USE)
669 printk("at1700: device busy, remove delayed\n");
670 else
671 {
672 unregister_netdev(&dev_at1700);
673 kfree(dev_at1700.priv);
674 dev_at1700.priv = NULL;
675
676
677 free_irq(dev_at1700.irq);
678 irq2dev_map[dev_at1700.irq] = NULL;
679 release_region(dev_at1700.base_addr, AT1700_IO_EXTENT);
680 }
681 }
682 #endif
683
684
685
686
687
688
689
690
691
692