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