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