This source file includes following definitions.
- plip_init
- plip_tx_packet
- plip_open
- plip_close
- plip_header
- plip_get_stats
- plip_rebuild_header
- plip_device_clear
- plip_error
- plip_receive
- plip_receive_packet
- plip_interrupt
- plip_send
- plip_send_packet
- plip_config
- plip_ioctl
- 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 static char *version =
30 "NET3 "
31 #ifdef MODULE
32 "MODULAR "
33 #endif
34 "PLIP.010+ gniibe@mri.co.jp\n";
35
36 #include <linux/config.h>
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 #include <linux/kernel.h>
69 #include <linux/sched.h>
70 #include <linux/types.h>
71 #include <linux/fcntl.h>
72 #include <linux/interrupt.h>
73 #include <linux/string.h>
74 #include <linux/ptrace.h>
75 #include <linux/if_ether.h>
76 #include <asm/system.h>
77 #include <asm/io.h>
78 #include <netinet/in.h>
79 #include <errno.h>
80 #include <linux/delay.h>
81
82 #include <linux/netdevice.h>
83 #include <linux/etherdevice.h>
84 #include <linux/skbuff.h>
85 #include <linux/if_plip.h>
86
87 #include <linux/timer.h>
88 #include <linux/ioport.h>
89 #include <asm/bitops.h>
90 #include <asm/irq.h>
91
92 #ifdef MODULE
93 #include <linux/module.h>
94 #include "../../tools/version.h"
95 #endif
96
97
98 #ifndef NET_DEBUG
99 #define NET_DEBUG 3
100 #endif
101 static unsigned int net_debug = NET_DEBUG;
102
103
104 #define PLIP_MTU 1500
105
106
107 #define PLIP_DELAY_UNIT 1
108
109
110 #define PLIP_TRIGGER_WAIT 500
111
112
113 #define PLIP_NIBBLE_WAIT 3000
114
115 #define PAR_DATA(dev) (dev->base_addr+0)
116 #define PAR_STATUS(dev) (dev->base_addr+1)
117 #define PAR_CONTROL(dev) (dev->base_addr+2)
118
119
120 static int plip_tx_packet(struct sk_buff *skb, struct device *dev);
121 static int plip_open(struct device *dev);
122 static int plip_close(struct device *dev);
123 static int plip_header(unsigned char *buff, struct device *dev,
124 unsigned short type, void *dest,
125 void *source, unsigned len, struct sk_buff *skb);
126 static struct enet_statistics *plip_get_stats(struct device *dev);
127 static int plip_rebuild_header(void *buff, struct device *dev,
128 unsigned long raddr, struct sk_buff *skb);
129
130 enum plip_state {
131 PLIP_ST_DONE=0,
132 PLIP_ST_TRANSMIT_BEGIN,
133 PLIP_ST_TRIGGER,
134 PLIP_ST_LENGTH_LSB,
135 PLIP_ST_LENGTH_MSB,
136 PLIP_ST_DATA,
137 PLIP_ST_CHECKSUM,
138 PLIP_ST_ERROR
139 };
140
141 enum plip_nibble_state {
142 PLIP_NST_BEGIN,
143 PLIP_NST_1,
144 PLIP_NST_2,
145 PLIP_NST_END
146 };
147
148 #define PLIP_STATE_STRING(x) \
149 (((x) == PLIP_ST_DONE)?"0":\
150 ((x) == PLIP_ST_TRANSMIT_BEGIN)?"b":\
151 ((x) == PLIP_ST_TRIGGER)?"t":\
152 ((x) == PLIP_ST_LENGTH_LSB)?"l":\
153 ((x) == PLIP_ST_LENGTH_MSB)?"m":\
154 ((x) == PLIP_ST_DATA)?"d":\
155 ((x) == PLIP_ST_CHECKSUM)?"s":"B")
156
157 struct plip_local {
158 enum plip_state state;
159 enum plip_nibble_state nibble;
160 unsigned short length;
161 unsigned short count;
162 unsigned short byte;
163 unsigned char checksum;
164 unsigned char data;
165 struct sk_buff *skb;
166 };
167
168 struct net_local {
169 struct enet_statistics e;
170 struct timer_list tl;
171 struct plip_local snd_data;
172 struct plip_local rcv_data;
173 unsigned long trigger_us;
174 unsigned long nibble_us;
175 unsigned long unit_us;
176 };
177
178
179 static void plip_device_clear(struct device *dev);
180 static void plip_error(struct device *dev);
181 static int plip_receive(struct device *dev, enum plip_nibble_state *ns_p,
182 unsigned char *data_p);
183 static void plip_receive_packet(struct device *dev);
184 static void plip_interrupt(int reg_ptr);
185 static int plip_send(struct device *dev, enum plip_nibble_state *ns_p,
186 unsigned char data);
187 static void plip_send_packet(struct device *dev);
188 static int plip_ioctl(struct device *dev, struct ifreq *ifr);
189 static int plip_config(struct device *dev, struct ifmap *map);
190
191
192 int
193 plip_init(struct device *dev)
194 {
195 int i;
196 struct net_local *pl;
197
198
199 outb(0x00, PAR_CONTROL(dev));
200 outb(0x00, PAR_DATA(dev));
201 if (inb(PAR_DATA(dev)) != 0x00)
202 return -ENODEV;
203
204
205 if (net_debug)
206 printk(version);
207
208 if (dev->irq) {
209 printk("%s: configured for parallel port at %#3x, IRQ %d.\n",
210 dev->name, dev->base_addr, dev->irq);
211 } else {
212 printk("%s: configured for parallel port at %#3x",
213 dev->name, dev->base_addr);
214 autoirq_setup(0);
215 outb(0x00, PAR_CONTROL(dev));
216 outb(0x10, PAR_CONTROL(dev));
217 outb(0x00, PAR_CONTROL(dev));
218 dev->irq = autoirq_report(1);
219 if (dev->irq)
220 printk(", probed IRQ %d.\n", dev->irq);
221 else {
222 printk(", failed to detect IRQ line.\n");
223 return -ENODEV;
224 }
225 }
226
227
228 dev->rmem_end = (unsigned long) NULL;
229 dev->rmem_start = (unsigned long) NULL;
230 dev->mem_end = (unsigned long) NULL;
231 dev->mem_start = (unsigned long) NULL;
232
233 dev->priv = kmalloc(sizeof (struct net_local), GFP_KERNEL);
234 memset(dev->priv, 0, sizeof(struct net_local));
235 pl = (struct net_local *) dev->priv;
236
237 pl->trigger_us = PLIP_TRIGGER_WAIT;
238 pl->nibble_us = PLIP_NIBBLE_WAIT;
239
240 dev->mtu = PLIP_MTU;
241 dev->hard_start_xmit = plip_tx_packet;
242 dev->open = plip_open;
243 dev->stop = plip_close;
244 dev->hard_header = plip_header;
245 dev->type_trans = eth_type_trans;
246 dev->get_stats = plip_get_stats;
247 dev->set_config = plip_config;
248 dev->do_ioctl = plip_ioctl;
249
250
251 dev->hard_header_len = ETH_HLEN;
252 dev->addr_len = ETH_ALEN;
253 dev->type = ARPHRD_ETHER;
254 dev->rebuild_header = plip_rebuild_header;
255
256 for (i = 0; i < DEV_NUMBUFFS; i++)
257 skb_queue_head_init(&dev->buffs[i]);
258
259 for (i = 0; i < dev->addr_len; i++) {
260 dev->broadcast[i]=0xff;
261 dev->dev_addr[i] = 0;
262 }
263
264
265 dev->flags = 0;
266 dev->family = AF_INET;
267 dev->pa_addr = 0;
268 dev->pa_brdaddr = 0;
269 dev->pa_dstaddr = 0;
270 dev->pa_mask = 0;
271 dev->pa_alen = sizeof(unsigned long);
272
273 return 0;
274 }
275
276 static int
277 plip_tx_packet (struct sk_buff *skb, struct device *dev)
278 {
279 struct net_local *lp = (struct net_local *)dev->priv;
280 struct plip_local *snd = &lp->snd_data;
281
282 if (dev->tbusy) {
283
284 int tickssofar = jiffies - dev->trans_start;
285 if (tickssofar < 100)
286 return 1;
287
288
289 printk("%s: transmit timed out, cable problem??\n", dev->name);
290 plip_device_clear(dev);
291 }
292
293
294
295
296 if (skb == NULL) {
297 dev_tint(dev);
298 return 0;
299 }
300
301 cli();
302 if (set_bit(0, (void *)&dev->tbusy) != 0) {
303 sti();
304 printk("%s: Transmitter access conflict.\n", dev->name);
305 return 1;
306 }
307 if (dev->interrupt) {
308 sti();
309 return 1;
310 }
311 snd->state = PLIP_ST_TRANSMIT_BEGIN;
312 sti();
313
314 dev->trans_start = jiffies;
315 if (net_debug > 4)
316 printk("Ss");
317
318 if (skb->len > dev->mtu) {
319 printk("%s: packet too big, %d.\n", dev->name, (int)skb->len);
320 return 0;
321 }
322
323 snd->skb = skb;
324 snd->length = skb->len;
325 snd->count = 0;
326
327 cli();
328 if (dev->interrupt == 0) {
329
330 lp->tl.expires = 0;
331 lp->tl.data = (unsigned long)dev;
332 lp->tl.function = (void (*)(unsigned long))plip_send_packet;
333 add_timer(&lp->tl);
334 mark_bh(TIMER_BH);
335 }
336 snd->state = PLIP_ST_TRIGGER;
337 sti();
338
339 return 0;
340 }
341
342
343
344
345
346
347
348
349 static int
350 plip_open(struct device *dev)
351 {
352 struct net_local *lp = (struct net_local *)dev->priv;
353 struct plip_local *rcv = &lp->rcv_data;
354
355 rcv->skb = alloc_skb(dev->mtu, GFP_KERNEL);
356 if (rcv->skb == NULL) {
357 printk("%s: couldn't get memory for receiving packet.\n", dev->name);
358 return -EAGAIN;
359 }
360 rcv->skb->len = dev->mtu;
361 rcv->skb->dev = dev;
362 cli();
363 if (request_irq(dev->irq , plip_interrupt, 0, "plip") != 0) {
364 sti();
365 printk("%s: couldn't get IRQ %d.\n", dev->name, dev->irq);
366 return -EAGAIN;
367 }
368 irq2dev_map[dev->irq] = dev;
369 sti();
370
371 outb(0x10, PAR_CONTROL(dev));
372 plip_device_clear(dev);
373 dev->start = 1;
374 #ifdef MODULE
375 MOD_INC_USE_COUNT;
376 #endif
377 return 0;
378 }
379
380
381 static int
382 plip_close(struct device *dev)
383 {
384 struct net_local *lp = (struct net_local *)dev->priv;
385
386 dev->tbusy = 1;
387 dev->start = 0;
388 cli();
389 free_irq(dev->irq);
390 irq2dev_map[dev->irq] = NULL;
391 sti();
392 outb(0x00, PAR_DATA(dev));
393
394 del_timer(&lp->tl);
395
396 outb(0x00, PAR_CONTROL(dev));
397 #ifdef MODULE
398 MOD_DEC_USE_COUNT;
399 #endif
400 return 0;
401 }
402
403
404 static int
405 plip_header(unsigned char *buff, struct device *dev,
406 unsigned short type, void *daddr,
407 void *saddr, unsigned len, struct sk_buff *skb)
408 {
409 int i;
410
411 if (dev->dev_addr[0] == 0) {
412 for (i=0; i < ETH_ALEN - sizeof(unsigned long); i++)
413 dev->dev_addr[i] = 0xfc;
414 memcpy(&(dev->dev_addr[i]), &dev->pa_addr, sizeof(unsigned long));
415 }
416
417 return eth_header(buff, dev, type, daddr, saddr, len, skb);
418 }
419
420 static struct enet_statistics *
421 plip_get_stats(struct device *dev)
422 {
423 struct enet_statistics *localstats = (struct enet_statistics*)dev->priv;
424 return localstats;
425 }
426
427
428 static int
429 plip_rebuild_header(void *buff, struct device *dev, unsigned long dst,
430 struct sk_buff *skb)
431 {
432 struct ethhdr *eth = (struct ethhdr *)buff;
433 int i;
434
435 if (eth->h_proto != htons(ETH_P_IP)) {
436 printk("plip_rebuild_header: Don't know how to resolve type %d addresses?\n",(int)eth->h_proto);
437 memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
438 return 0;
439 }
440
441 for (i=0; i < ETH_ALEN - sizeof(unsigned long); i++)
442 eth->h_dest[i] = 0xfc;
443 memcpy(&(eth->h_dest[i]), &dst, sizeof(unsigned long));
444 return 0;
445 }
446
447 static void
448 plip_device_clear(struct device *dev)
449 {
450 struct net_local *lp = (struct net_local *)dev->priv;
451
452 outb (0x00, PAR_DATA(dev));
453 lp->snd_data.state = PLIP_ST_DONE;
454 lp->rcv_data.state = PLIP_ST_DONE;
455 cli();
456 dev->tbusy = 0;
457 dev->interrupt = 0;
458
459 del_timer(&lp->tl);
460 sti();
461 enable_irq(dev->irq);
462 }
463
464 static void
465 plip_error(struct device *dev)
466 {
467 struct net_local *lp = (struct net_local *)dev->priv;
468 struct plip_local *snd = &((struct net_local *)dev->priv)->snd_data;
469 struct plip_local *rcv = &lp->rcv_data;
470 unsigned char status;
471
472 outb(0x00, PAR_DATA(dev));
473 cli();
474 del_timer(&lp->tl);
475 snd->state = PLIP_ST_ERROR;
476 sti();
477 if (rcv->skb == NULL) {
478 rcv->skb = alloc_skb(dev->mtu, GFP_ATOMIC);
479 if (rcv->skb == NULL) {
480 printk("%s: couldn't get memory.\n", dev->name);
481 goto again;
482 }
483 rcv->skb->len = dev->mtu;
484 rcv->skb->dev = dev;
485 }
486
487 status = inb(PAR_STATUS(dev));
488 if ((status & 0xf8) == 0x80) {
489 plip_device_clear(dev);
490 mark_bh(NET_BH);
491 } else {
492 again:
493 lp->tl.expires = 1;
494 lp->tl.data = (unsigned long)dev;
495 lp->tl.function = (void (*)(unsigned long))plip_error;
496 add_timer(&lp->tl);
497 }
498 }
499
500
501
502 static int
503 plip_receive(struct device *dev, enum plip_nibble_state *ns_p,
504 unsigned char *data_p)
505 {
506 unsigned char c0, c1;
507 unsigned int cx;
508 struct net_local *nl=(struct net_local *)dev->priv;
509
510 while (1)
511 switch (*ns_p) {
512 case PLIP_NST_BEGIN:
513 cx = nl->nibble_us;
514 while (1) {
515 c0 = inb(PAR_STATUS(dev));
516 udelay(PLIP_DELAY_UNIT);
517 if ((c0 & 0x80) == 0) {
518 c1 = inb(PAR_STATUS(dev));
519 if (c0 == c1)
520 break;
521 }
522 if (--cx == 0)
523 return 1;
524 }
525 *data_p = (c0 >> 3) & 0x0f;
526 outb(0x10, PAR_DATA(dev));
527 *ns_p = PLIP_NST_1;
528 break;
529
530 case PLIP_NST_1:
531 cx = nl->nibble_us;
532 while (1) {
533 c0 = inb(PAR_STATUS(dev));
534 udelay(PLIP_DELAY_UNIT);
535 if (c0 & 0x80) {
536 c1 = inb(PAR_STATUS(dev));
537 if (c0 == c1)
538 break;
539 }
540 if (--cx == 0)
541 return 1;
542 }
543 *data_p |= (c0 << 1) & 0xf0;
544 outb(0x00, PAR_DATA(dev));
545 *ns_p = PLIP_NST_2;
546 return 0;
547 break;
548
549 default:
550 printk("plip:receive state error\n");
551 *ns_p = PLIP_NST_2;
552 return 1;
553 break;
554 }
555 }
556
557 static void
558 plip_receive_packet(struct device *dev)
559 {
560 struct net_local *lp = (struct net_local *)dev->priv;
561 struct enet_statistics *stats = (struct enet_statistics *) dev->priv;
562 struct plip_local *snd = &lp->snd_data;
563 struct plip_local *rcv = &lp->rcv_data;
564 unsigned char *lbuf = rcv->skb->data;
565 unsigned char c0;
566 unsigned char *s = PLIP_STATE_STRING(rcv->state);
567
568 if (net_debug > 4)
569 printk("R%s",s);
570
571 while (1) {
572 switch (rcv->state) {
573 case PLIP_ST_TRIGGER:
574 disable_irq(dev->irq);
575 rcv->state = PLIP_ST_LENGTH_LSB;
576 rcv->nibble = PLIP_NST_BEGIN;
577 break;
578
579 case PLIP_ST_LENGTH_LSB:
580 if (plip_receive(dev, &rcv->nibble, (unsigned char *)&rcv->length))
581 goto try_again;
582
583 rcv->state = PLIP_ST_LENGTH_MSB;
584 rcv->nibble = PLIP_NST_BEGIN;
585 break;
586
587 case PLIP_ST_LENGTH_MSB:
588 if (plip_receive(dev, &rcv->nibble,
589 (unsigned char *)&rcv->length+1))
590 goto try_again;
591
592 if (rcv->length > rcv->skb->len || rcv->length < 8) {
593 printk("%s: bogus packet size %d.\n", dev->name, rcv->length);
594 plip_error(dev);
595 return;
596 }
597 rcv->skb->len = rcv->length;
598 rcv->state = PLIP_ST_DATA;
599 rcv->nibble = PLIP_NST_BEGIN;
600 rcv->byte = 0;
601 rcv->checksum = 0;
602 break;
603
604 case PLIP_ST_DATA:
605 if (plip_receive(dev, &rcv->nibble, &lbuf[rcv->byte]))
606 goto try_again;
607
608 rcv->checksum += lbuf[rcv->byte];
609 rcv->byte++;
610 rcv->nibble = PLIP_NST_BEGIN;
611 if (rcv->byte == rcv->length)
612 rcv->state = PLIP_ST_CHECKSUM;
613 break;
614
615 case PLIP_ST_CHECKSUM:
616 if (plip_receive(dev, &rcv->nibble, &rcv->data))
617 goto try_again;
618 if (rcv->data != rcv->checksum) {
619 stats->rx_crc_errors++;
620 if (net_debug)
621 printk("%s: checksum error\n", dev->name);
622 plip_error(dev);
623 return;
624 }
625
626 rcv->state = PLIP_ST_DONE;
627 netif_rx(rcv->skb);
628
629
630 rcv->skb = alloc_skb(dev->mtu, GFP_ATOMIC);
631 if (rcv->skb == NULL) {
632 printk("%s: Memory squeeze.\n", dev->name);
633 plip_error(dev);
634 return;
635 }
636 rcv->skb->len = dev->mtu;
637 rcv->skb->dev = dev;
638 stats->rx_packets++;
639 if (net_debug > 4)
640 printk("R(%4.4d)", rcv->length);
641
642 if (snd->state == PLIP_ST_TRANSMIT_BEGIN) {
643 dev->interrupt = 0;
644 enable_irq(dev->irq);
645 } else if (snd->state == PLIP_ST_TRIGGER) {
646 cli();
647 dev->interrupt = 0;
648 if (net_debug > 3)
649 printk("%%");
650 lp->tl.expires = 0;
651 lp->tl.data = (unsigned long)dev;
652 lp->tl.function
653 = (void (*)(unsigned long))plip_send_packet;
654 add_timer(&lp->tl);
655 mark_bh(TIMER_BH);
656 enable_irq(dev->irq);
657 sti();
658 } else
659 plip_device_clear(dev);
660 return;
661
662 default:
663 printk("plip: bad STATE?? %04d", rcv->state);
664 plip_device_clear(dev);
665 return;
666 }
667 }
668
669 try_again:
670 if (++rcv->count > 2) {
671 s = PLIP_STATE_STRING(rcv->state);
672 c0 = inb(PAR_STATUS(dev));
673 stats->rx_dropped++;
674 if (net_debug > 1)
675 printk("%s: receive timeout(%s,%02x)... reset interface.\n",
676 dev->name, s, (unsigned int)c0);
677 plip_error(dev);
678 } else {
679 s = PLIP_STATE_STRING(rcv->state);
680 if (net_debug > 3)
681 printk("r%s",s);
682
683
684 lp->tl.expires = 1;
685 lp->tl.data = (unsigned long)dev;
686 lp->tl.function = (void (*)(unsigned long))plip_receive_packet;
687 add_timer(&lp->tl);
688 }
689 }
690
691
692 static void
693 plip_interrupt(int reg_ptr)
694 {
695 int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
696 struct device *dev = (struct device *) irq2dev_map[irq];
697 struct net_local *lp = (struct net_local *)dev->priv;
698 struct plip_local *rcv = &lp->rcv_data;
699 struct plip_local *snd = &lp->snd_data;
700 unsigned char c0;
701
702 if (dev == NULL) {
703 if (net_debug)
704 printk ("plip_interrupt: irq %d for unknown device.\n", irq);
705 return;
706 }
707
708 if (dev->interrupt) {
709 if (net_debug > 3)
710 printk("2");
711 return;
712 }
713
714 if (dev->tbusy) {
715 if (snd->state > PLIP_ST_TRIGGER) {
716 printk("%s: rx interrupt in transmission\n", dev->name);
717 return;
718 }
719 if (net_debug > 3)
720 printk("3");
721 }
722
723 if (snd->state == PLIP_ST_ERROR)
724 return;
725
726 c0 = inb(PAR_STATUS(dev));
727 if ((c0 & 0xf8) != 0xc0) {
728 if (net_debug > 3)
729 printk("?");
730 return;
731 }
732
733 dev->interrupt = 1;
734
735 if (net_debug > 3)
736 printk("!");
737
738 dev->last_rx = jiffies;
739 outb(0x01, PAR_DATA(dev));
740 rcv->state = PLIP_ST_TRIGGER;
741 rcv->count = 0;
742
743
744 del_timer(&lp->tl);
745 lp->tl.expires = 0;
746 lp->tl.data = (unsigned long)dev;
747 lp->tl.function = (void (*)(unsigned long))plip_receive_packet;
748 add_timer(&lp->tl);
749 mark_bh (TIMER_BH);
750 }
751
752
753
754 static int
755 plip_send(struct device *dev, enum plip_nibble_state *ns_p, unsigned char data)
756 {
757 unsigned char c0;
758 unsigned int cx;
759 struct net_local *nl= (struct net_local *)dev->priv;
760
761 while (1)
762 switch (*ns_p) {
763 case PLIP_NST_BEGIN:
764 outb((data & 0x0f), PAR_DATA(dev));
765 *ns_p = PLIP_NST_1;
766 break;
767
768 case PLIP_NST_1:
769 outb(0x10 | (data & 0x0f), PAR_DATA(dev));
770 cx = nl->nibble_us;
771 while (1) {
772 c0 = inb(PAR_STATUS(dev));
773 if ((c0 & 0x80) == 0)
774 break;
775 if (--cx == 0)
776 return 1;
777 udelay(PLIP_DELAY_UNIT);
778 }
779 outb(0x10 | (data >> 4), PAR_DATA(dev));
780 *ns_p = PLIP_NST_2;
781 break;
782
783 case PLIP_NST_2:
784 outb((data >> 4), PAR_DATA(dev));
785 cx = nl->nibble_us;
786 while (1) {
787 c0 = inb(PAR_STATUS(dev));
788 if (c0 & 0x80)
789 break;
790 if (--cx == 0)
791 return 1;
792 udelay(PLIP_DELAY_UNIT);
793 }
794 return 0;
795
796 default:
797 printk("plip:send state error\n");
798 return 1;
799 }
800 }
801
802 static void
803 plip_send_packet(struct device *dev)
804 {
805 struct enet_statistics *stats = (struct enet_statistics *) dev->priv;
806 struct net_local *lp = (struct net_local *)dev->priv;
807 struct plip_local *snd = &lp->snd_data;
808 unsigned char *lbuf = snd->skb->data;
809 unsigned char c0;
810 unsigned int cx;
811 unsigned char *s = PLIP_STATE_STRING(snd->state);
812
813 if (net_debug > 4)
814 printk("S%s",s);
815
816 while (1) {
817 switch (snd->state) {
818 case PLIP_ST_TRIGGER:
819
820 outb(0x08, PAR_DATA(dev));
821 cx = lp->trigger_us;
822 while (1) {
823 if (dev->interrupt) {
824 stats->collisions++;
825 if (net_debug > 3)
826 printk("$");
827 mark_bh(TIMER_BH);
828 return;
829 }
830 cli();
831 c0 = inb(PAR_STATUS(dev));
832 if (c0 & 0x08) {
833 disable_irq(dev->irq);
834 if (net_debug > 3)
835 printk("+");
836
837 snd->state = PLIP_ST_LENGTH_LSB;
838 snd->nibble = PLIP_NST_BEGIN;
839 snd->count = 0;
840 sti();
841 break;
842 }
843 sti();
844 udelay(PLIP_DELAY_UNIT);
845 if (--cx == 0) {
846 outb(0x00, PAR_DATA(dev));
847 goto try_again;
848 }
849 }
850 break;
851
852 case PLIP_ST_LENGTH_LSB:
853 if (plip_send(dev, &snd->nibble, snd->length & 0xff))
854 goto try_again;
855
856 snd->state = PLIP_ST_LENGTH_MSB;
857 snd->nibble = PLIP_NST_BEGIN;
858 break;
859
860 case PLIP_ST_LENGTH_MSB:
861 if (plip_send(dev, &snd->nibble, snd->length >> 8))
862 goto try_again;
863
864 snd->state = PLIP_ST_DATA;
865 snd->nibble = PLIP_NST_BEGIN;
866 snd->byte = 0;
867 snd->checksum = 0;
868 break;
869
870 case PLIP_ST_DATA:
871 if (plip_send(dev, &snd->nibble, lbuf[snd->byte]))
872 goto try_again;
873
874 snd->nibble = PLIP_NST_BEGIN;
875 snd->checksum += lbuf[snd->byte];
876 snd->byte++;
877 if (snd->byte == snd->length)
878 snd->state = PLIP_ST_CHECKSUM;
879 break;
880
881 case PLIP_ST_CHECKSUM:
882 if (plip_send(dev, &snd->nibble, snd->checksum))
883 goto try_again;
884
885 mark_bh(NET_BH);
886 plip_device_clear(dev);
887 if (net_debug > 4)
888 printk("S(%4.4d)", snd->length);
889 dev_kfree_skb(snd->skb, FREE_WRITE);
890 stats->tx_packets++;
891 return;
892
893 default:
894 printk("plip: BAD STATE?? %04d", snd->state);
895 plip_device_clear(dev);
896 return;
897 }
898 }
899
900 try_again:
901 if (++snd->count > 3) {
902
903 s = PLIP_STATE_STRING(snd->state);
904 c0 = inb(PAR_STATUS(dev));
905 stats->tx_errors++;
906 stats->tx_aborted_errors++;
907 if (net_debug > 1)
908 printk("%s: transmit timeout(%s,%02x)... reset interface.\n",
909 dev->name, s, (unsigned int)c0);
910 dev_kfree_skb(snd->skb,FREE_WRITE);
911 plip_error(dev);
912 } else {
913 s = PLIP_STATE_STRING(snd->state);
914 if (net_debug > 3)
915 printk("s%s",s);
916
917 cli();
918 if (dev->interrupt == 0) {
919
920 lp->tl.expires = 1;
921 lp->tl.data = (unsigned long)dev;
922 lp->tl.function = (void (*)(unsigned long))plip_send_packet;
923 add_timer(&lp->tl);
924 }
925 sti();
926 }
927 }
928
929 static int plip_config(struct device *dev, struct ifmap *map)
930 {
931 if(dev->flags&IFF_UP)
932 return -EBUSY;
933
934
935
936
937 if(map->base_addr!= (unsigned short)-1)
938 dev->base_addr=map->base_addr;
939 if(map->irq!= (unsigned char)-1)
940 dev->irq= map->irq;
941 return 0;
942 }
943
944 static int plip_ioctl(struct device *dev, struct ifreq *rq)
945 {
946 struct net_local *nl = (struct net_local *) dev->priv;
947 struct plipconf *pc = (struct plipconf *) &rq->ifr_data;
948
949 switch(pc->pcmd)
950 {
951 case PLIP_GET_TIMEOUT:
952 pc->trigger=nl->trigger_us;
953 pc->nibble=nl->nibble_us;
954 pc->unit=nl->unit_us;
955 break;
956 case PLIP_SET_TIMEOUT:
957 nl->trigger_us=pc->trigger;
958 nl->nibble_us=pc->nibble;
959 nl->unit_us=pc->unit;
960 break;
961 default:
962 return -EOPNOTSUPP;
963 }
964 return 0;
965 }
966
967
968 #ifdef MODULE
969 char kernel_version[] = UTS_RELEASE;
970
971 static struct device dev_plip0 =
972 {
973 "plip0" ,
974 0, 0, 0, 0,
975 0x3BC, 5,
976 0, 0, 0, NULL, plip_init
977 };
978
979 static struct device dev_plip1 =
980 {
981 "plip1" ,
982 0, 0, 0, 0,
983 0x378, 7,
984 0, 0, 0, NULL, plip_init
985 };
986
987 static struct device dev_plip2 =
988 {
989 "plip2" ,
990 0, 0, 0, 0,
991 0x278, 2,
992 0, 0, 0, NULL, plip_init
993 };
994
995 int
996 init_module(void)
997 {
998 int err;
999
1000 if ( ((err=register_netdev(&dev_plip0)) == 0) &&
1001 ((err=register_netdev(&dev_plip1)) == 0) &&
1002 ((err=register_netdev(&dev_plip2)) == 0)
1003 )
1004 {
1005 if(err==-EEXIST)
1006 printk("plip devices already present. Module not loaded.\n");
1007 return err;
1008 }
1009 return 0;
1010 }
1011
1012 void
1013 cleanup_module(void)
1014 {
1015 if (MOD_IN_USE)
1016 printk("plip: device busy, remove delayed\n");
1017 else
1018 {
1019 unregister_netdev(&dev_plip0);
1020 if(dev_plip0.priv)
1021 {
1022 kfree_s(dev_plip0.priv,sizeof(struct net_local));
1023 dev_plip0.priv=NULL;
1024 }
1025 unregister_netdev(&dev_plip1);
1026 if(dev_plip1.priv)
1027 {
1028 kfree_s(dev_plip1.priv,sizeof(struct net_local));
1029 dev_plip0.priv=NULL;
1030 }
1031 unregister_netdev(&dev_plip2);
1032 if(dev_plip2.priv)
1033 {
1034 kfree_s(dev_plip2.priv,sizeof(struct net_local));
1035 dev_plip2.priv=NULL;
1036 }
1037 }
1038 }
1039 #endif
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052