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