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