1 /* $Id: plip.c,v 1.12 1995/02/11 10:26:05 gniibe Exp $ */ 2 /* PLIP: A parallel port "network" driver for Linux. */ 3 /* This driver is for parallel port with 5-bit cable (LapLink (R) cable). */ 5 * Authors: Donald Becker, <becker@super.org> 6 * Tommy Thorn, <thorn@daimi.aau.dk> 7 * Tanabe Hiroyasu, <hiro@sanpo.t.u-tokyo.ac.jp> 8 * Alan Cox, <gw4pts@gw4pts.ampr.org> 9 * Peter Bauer, <100136.3530@compuserve.com> 10 * Niibe Yutaka, <gniibe@mri.co.jp> 12 * Modularization and ifreq/ifmap support by Alan Cox. 13 * Rewritten by Niibe Yutaka. 15 * This program is free software; you can redistribute it and/or 16 * modify it under the terms of the GNU General Public License 17 * as published by the Free Software Foundation; either version 18 * 2 of the License, or (at your option) any later version. 22 * Original version and the name 'PLIP' from Donald Becker <becker@super.org> 23 * inspired by Russ Nelson's parallel port packet driver. 26 * Tanabe Hiroyasu had changed the protocol, and it was in Linux v1.0. 27 * Because of the necessity to communicate to DOS machines with the 28 * Crynwr packet driver, Peter Bauer changed the protocol again 29 * back to original protocol. 31 * This version follows original PLIP protocol. 32 * So, this PLIP can't communicate the PLIP of Linux v1.0. 35 static const char*version
="NET3 PLIP version 2.0 gniibe@mri.co.jp\n"; 39 Ideas and protocols came from Russ Nelson's <nelson@crynwr.com> 40 "parallel.asm" parallel port packet driver. 42 The "Crynwr" parallel port standard specifies the following protocol: 43 Trigger by sending '0x08' (this cause interrupt on other end) 48 Each octet is sent as <wait for rx. '0x1?'> <send 0x10+(octet&0x0F)> 49 <wait for rx. '0x0?'> <send 0x00+((octet>>4)&0x0F)> 51 The packet is encapsulated as if it were ethernet. 53 The cable used is a de facto standard parallel null cable -- sold as 54 a "LapLink" cable by various places. You'll need a 12-conductor cable to 55 make one yourself. The wiring is: 58 D0->ERROR 2 - 15 15 - 2 59 D1->SLCT 3 - 13 13 - 3 60 D2->PAPOUT 4 - 12 12 - 4 62 D4->BUSY 6 - 11 11 - 6 63 Do not connect the other pins. They are 65 STROBE is 1, FEED is 14, INIT is 16 66 extra grounds are 18,19,20,21,22,23,24 70 #include <linux/module.h> 71 #include <linux/version.h> 73 #define MOD_INC_USE_COUNT 74 #define MOD_DEC_USE_COUNT 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> 88 #include <linux/errno.h> 89 #include <linux/delay.h> 92 #include <linux/netdevice.h> 93 #include <linux/etherdevice.h> 94 #include <linux/skbuff.h> 95 #include <linux/if_plip.h> 97 #include <linux/tqueue.h> 98 #include <linux/ioport.h> 99 #include <asm/bitops.h> 101 #include <asm/byteorder.h> 103 /* Use 0 for production, 1 for verification, >2 for debug */ 107 static unsigned int net_debug
= NET_DEBUG
; 109 /* In micro second */ 110 #define PLIP_DELAY_UNIT 1 112 /* Connection time out = PLIP_TRIGGER_WAIT * PLIP_DELAY_UNIT usec */ 113 #define PLIP_TRIGGER_WAIT 500 115 /* Nibble time out = PLIP_NIBBLE_WAIT * PLIP_DELAY_UNIT usec */ 116 #define PLIP_NIBBLE_WAIT 3000 118 #define PAR_INTR_ON (LP_PINITP|LP_PSELECP|LP_PINTEN) 119 #define PAR_INTR_OFF (LP_PINITP|LP_PSELECP) 120 #define PAR_DATA(dev) ((dev)->base_addr+0) 121 #define PAR_STATUS(dev) ((dev)->base_addr+1) 122 #define PAR_CONTROL(dev) ((dev)->base_addr+2) 125 static voidplip_kick_bh(struct device
*dev
); 126 static voidplip_bh(struct device
*dev
); 128 /* Interrupt handler */ 129 static voidplip_interrupt(int irq
,struct pt_regs
*regs
); 131 /* Functions for DEV methods */ 132 static intplip_rebuild_header(void*buff
,struct device
*dev
, 133 unsigned long raddr
,struct sk_buff
*skb
); 134 static intplip_tx_packet(struct sk_buff
*skb
,struct device
*dev
); 135 static intplip_open(struct device
*dev
); 136 static intplip_close(struct device
*dev
); 137 static struct enet_statistics
*plip_get_stats(struct device
*dev
); 138 static intplip_config(struct device
*dev
,struct ifmap
*map
); 139 static intplip_ioctl(struct device
*dev
,struct ifreq
*ifr
,int cmd
); 141 enum plip_connection_state
{ 149 enum plip_packet_state
{ 158 enum plip_nibble_state
{ 165 enum plip_packet_state state
; 166 enum plip_nibble_state nibble
; 169 #if defined(LITTLE_ENDIAN) 172 #elif defined(BIG_ENDIAN) 176 #error"Please fix the endianness defines in <asm/byteorder.h>" 182 unsigned char checksum
; 188 struct enet_statistics enet_stats
; 189 struct tq_struct immediate
; 190 struct tq_struct deferred
; 191 struct plip_local snd_data
; 192 struct plip_local rcv_data
; 193 unsigned long trigger
; 194 unsigned long nibble
; 195 enum plip_connection_state connection
; 196 unsigned short timeout_count
; 198 int(*orig_rebuild_header
)(void*eth
,struct device
*dev
, 199 unsigned long raddr
,struct sk_buff
*skb
); 202 /* Entry point of PLIP driver. 203 Probe the hardware, and register/initialize the driver. */ 205 plip_init(struct device
*dev
) 207 struct net_local
*nl
; 209 /* Check region before the probe */ 210 if(check_region(PAR_DATA(dev
),3) <0) 213 /* Check that there is something at base_addr. */ 214 outb(0,PAR_DATA(dev
)); 216 if(inb(PAR_DATA(dev
)) !=0) 220 printk("%s: Parallel port at %#3lx, ", dev
->name
, dev
->base_addr
); 222 printk("using assigned IRQ %d.\n", dev
->irq
); 226 /* dev->irq==0 means autoprobe, but we don't try to do so 227 with module. We can change it by ifconfig */ 229 unsigned int irqs
=probe_irq_on(); 231 outb(0x00,PAR_CONTROL(dev
)); 233 outb(PAR_INTR_OFF
,PAR_CONTROL(dev
)); 234 outb(PAR_INTR_ON
,PAR_CONTROL(dev
)); 235 outb(PAR_INTR_OFF
,PAR_CONTROL(dev
)); 237 irq
=probe_irq_off(irqs
); 241 printk("using probed IRQ %d.\n", dev
->irq
); 243 printk("failed to detect IRQ(%d) --" 244 " Please set IRQ by ifconfig.\n", irq
); 247 request_region(PAR_DATA(dev
),3, dev
->name
); 249 /* Fill in the generic fields of the device structure. */ 252 /* Then, override parts of it */ 253 dev
->hard_start_xmit
= plip_tx_packet
; 254 dev
->open
= plip_open
; 255 dev
->stop
= plip_close
; 256 dev
->get_stats
= plip_get_stats
; 257 dev
->set_config
= plip_config
; 258 dev
->do_ioctl
= plip_ioctl
; 259 dev
->flags
= IFF_POINTOPOINT
|IFF_NOARP
; 261 /* Set the private structure */ 262 dev
->priv
=kmalloc(sizeof(struct net_local
), GFP_KERNEL
); 263 if(dev
->priv
== NULL
) 265 memset(dev
->priv
,0,sizeof(struct net_local
)); 266 nl
= (struct net_local
*) dev
->priv
; 268 nl
->orig_rebuild_header
= dev
->rebuild_header
; 269 dev
->rebuild_header
= plip_rebuild_header
; 271 /* Initialize constants */ 272 nl
->trigger
= PLIP_TRIGGER_WAIT
; 273 nl
->nibble
= PLIP_NIBBLE_WAIT
; 275 /* Initialize task queue structures */ 276 nl
->immediate
.next
= &tq_last
; 277 nl
->immediate
.sync
=0; 278 nl
->immediate
.routine
= (void*)(void*)plip_bh
; 279 nl
->immediate
.data
= dev
; 281 nl
->deferred
.next
= &tq_last
; 282 nl
->deferred
.sync
=0; 283 nl
->deferred
.routine
= (void*)(void*)plip_kick_bh
; 284 nl
->deferred
.data
= dev
; 289 /* Bottom half handler for the delayed request. 290 This routine is kicked by do_timer(). 291 Request `plip_bh' to be invoked. */ 293 plip_kick_bh(struct device
*dev
) 295 struct net_local
*nl
= (struct net_local
*)dev
->priv
; 297 if(nl
->is_deferred
) { 298 queue_task(&nl
->immediate
, &tq_immediate
); 299 mark_bh(IMMEDIATE_BH
); 303 /* Forward declarations of internal routines */ 304 static intplip_none(struct device
*,struct net_local
*, 305 struct plip_local
*,struct plip_local
*); 306 static intplip_receive_packet(struct device
*,struct net_local
*, 307 struct plip_local
*,struct plip_local
*); 308 static intplip_send_packet(struct device
*,struct net_local
*, 309 struct plip_local
*,struct plip_local
*); 310 static intplip_connection_close(struct device
*,struct net_local
*, 311 struct plip_local
*,struct plip_local
*); 312 static intplip_error(struct device
*,struct net_local
*, 313 struct plip_local
*,struct plip_local
*); 314 static intplip_bh_timeout_error(struct device
*dev
,struct net_local
*nl
, 315 struct plip_local
*snd
, 316 struct plip_local
*rcv
, 323 typedefint(*plip_func
)(struct device
*dev
,struct net_local
*nl
, 324 struct plip_local
*snd
,struct plip_local
*rcv
); 326 static plip_func connection_state_table
[] = 331 plip_connection_close
, 335 /* Bottom half handler of PLIP. */ 337 plip_bh(struct device
*dev
) 339 struct net_local
*nl
= (struct net_local
*)dev
->priv
; 340 struct plip_local
*snd
= &nl
->snd_data
; 341 struct plip_local
*rcv
= &nl
->rcv_data
; 346 f
= connection_state_table
[nl
->connection
]; 347 if((r
= (*f
)(dev
, nl
, snd
, rcv
)) != OK
348 && (r
=plip_bh_timeout_error(dev
, nl
, snd
, rcv
, r
)) != OK
) { 350 queue_task(&nl
->deferred
, &tq_timer
); 355 plip_bh_timeout_error(struct device
*dev
,struct net_local
*nl
, 356 struct plip_local
*snd
,struct plip_local
*rcv
, 362 if(nl
->connection
== PLIP_CN_SEND
) { 364 if(error
!= ERROR
) {/* Timeout */ 366 if((snd
->state
== PLIP_PK_TRIGGER
367 && nl
->timeout_count
<=10) 368 || nl
->timeout_count
<=3) { 370 /* Try again later */ 373 c0
=inb(PAR_STATUS(dev
)); 374 printk("%s: transmit timeout(%d,%02x)\n", 375 dev
->name
, snd
->state
, c0
); 377 nl
->enet_stats
.tx_errors
++; 378 nl
->enet_stats
.tx_aborted_errors
++; 379 }else if(nl
->connection
== PLIP_CN_RECEIVE
) { 380 if(rcv
->state
== PLIP_PK_TRIGGER
) { 381 /* Transmission was interrupted. */ 385 if(error
!= ERROR
) {/* Timeout */ 386 if(++nl
->timeout_count
<=3) { 388 /* Try again later */ 391 c0
=inb(PAR_STATUS(dev
)); 392 printk("%s: receive timeout(%d,%02x)\n", 393 dev
->name
, rcv
->state
, c0
); 395 nl
->enet_stats
.rx_dropped
++; 397 rcv
->state
= PLIP_PK_DONE
; 400 kfree_skb(rcv
->skb
, FREE_READ
); 403 snd
->state
= PLIP_PK_DONE
; 405 dev_kfree_skb(snd
->skb
, FREE_WRITE
); 408 disable_irq(dev
->irq
); 409 outb(PAR_INTR_OFF
,PAR_CONTROL(dev
)); 411 nl
->connection
= PLIP_CN_ERROR
; 412 outb(0x00,PAR_DATA(dev
)); 419 plip_none(struct device
*dev
,struct net_local
*nl
, 420 struct plip_local
*snd
,struct plip_local
*rcv
) 425 /* PLIP_RECEIVE --- receive a byte(two nibbles) 426 Returns OK on success, TIMEOUT on timeout */ 428 plip_receive(unsigned short nibble_timeout
,unsigned short status_addr
, 429 enum plip_nibble_state
*ns_p
,unsigned char*data_p
) 431 unsigned char c0
, c1
; 438 c0
=inb(status_addr
); 439 udelay(PLIP_DELAY_UNIT
); 441 c1
=inb(status_addr
); 448 *data_p
= (c0
>>3) &0x0f; 449 outb(0x10, --status_addr
);/* send ACK */ 456 c0
=inb(status_addr
); 457 udelay(PLIP_DELAY_UNIT
); 459 c1
=inb(status_addr
); 466 *data_p
|= (c0
<<1) &0xf0; 467 outb(0x00, --status_addr
);/* send ACK */ 469 *ns_p
= PLIP_NB_BEGIN
; 475 return TIMEOUT
;/* XX: ?? */ 478 /* PLIP_RECEIVE_PACKET --- receive a packet */ 480 plip_receive_packet(struct device
*dev
,struct net_local
*nl
, 481 struct plip_local
*snd
,struct plip_local
*rcv
) 483 unsigned short status_addr
=PAR_STATUS(dev
); 484 unsigned short nibble_timeout
= nl
->nibble
; 488 case PLIP_PK_TRIGGER
: 489 disable_irq(dev
->irq
); 490 outb(PAR_INTR_OFF
,PAR_CONTROL(dev
)); 492 outb(0x01,PAR_DATA(dev
));/* send ACK */ 494 printk("%s: receive start\n", dev
->name
); 495 rcv
->state
= PLIP_PK_LENGTH_LSB
; 496 rcv
->nibble
= PLIP_NB_BEGIN
; 498 case PLIP_PK_LENGTH_LSB
: 499 if(snd
->state
!= PLIP_PK_DONE
) { 500 if(plip_receive(nl
->trigger
, status_addr
, 501 &rcv
->nibble
, &rcv
->length
.b
.lsb
)) { 502 /* collision, here dev->tbusy == 1 */ 503 rcv
->state
= PLIP_PK_DONE
; 505 nl
->connection
= PLIP_CN_SEND
; 506 queue_task(&nl
->deferred
, &tq_timer
); 507 outb(PAR_INTR_ON
,PAR_CONTROL(dev
)); 508 enable_irq(dev
->irq
); 512 if(plip_receive(nibble_timeout
, status_addr
, 513 &rcv
->nibble
, &rcv
->length
.b
.lsb
)) 516 rcv
->state
= PLIP_PK_LENGTH_MSB
; 518 case PLIP_PK_LENGTH_MSB
: 519 if(plip_receive(nibble_timeout
, status_addr
, 520 &rcv
->nibble
, &rcv
->length
.b
.msb
)) 522 if(rcv
->length
.h
> dev
->mtu
|| rcv
->length
.h
<8) { 523 printk("%s: bogus packet size %d.\n", dev
->name
, rcv
->length
.h
); 526 /* Malloc up new buffer. */ 527 rcv
->skb
=dev_alloc_skb(rcv
->length
.h
); 528 if(rcv
->skb
== NULL
) { 529 printk("%s: Memory squeeze.\n", dev
->name
); 532 skb_put(rcv
->skb
,rcv
->length
.h
); 534 rcv
->state
= PLIP_PK_DATA
; 539 lbuf
= rcv
->skb
->data
; 541 if(plip_receive(nibble_timeout
, status_addr
, 542 &rcv
->nibble
, &lbuf
[rcv
->byte
])) 544 while(++rcv
->byte
< rcv
->length
.h
); 546 rcv
->checksum
+= lbuf
[--rcv
->byte
]; 548 rcv
->state
= PLIP_PK_CHECKSUM
; 550 case PLIP_PK_CHECKSUM
: 551 if(plip_receive(nibble_timeout
, status_addr
, 552 &rcv
->nibble
, &rcv
->data
)) 554 if(rcv
->data
!= rcv
->checksum
) { 555 nl
->enet_stats
.rx_crc_errors
++; 557 printk("%s: checksum error\n", dev
->name
); 560 rcv
->state
= PLIP_PK_DONE
; 563 /* Inform the upper layer for the arrival of a packet. */ 564 rcv
->skb
->protocol
=eth_type_trans(rcv
->skb
, dev
); 566 nl
->enet_stats
.rx_packets
++; 569 printk("%s: receive end\n", dev
->name
); 571 /* Close the connection. */ 572 outb(0x00,PAR_DATA(dev
)); 574 if(snd
->state
!= PLIP_PK_DONE
) { 575 nl
->connection
= PLIP_CN_SEND
; 577 queue_task(&nl
->immediate
, &tq_immediate
); 578 outb(PAR_INTR_ON
,PAR_CONTROL(dev
)); 579 enable_irq(dev
->irq
); 582 nl
->connection
= PLIP_CN_NONE
; 584 outb(PAR_INTR_ON
,PAR_CONTROL(dev
)); 585 enable_irq(dev
->irq
); 592 /* PLIP_SEND --- send a byte (two nibbles) 593 Returns OK on success, TIMEOUT when timeout */ 595 plip_send(unsigned short nibble_timeout
,unsigned short data_addr
, 596 enum plip_nibble_state
*ns_p
,unsigned char data
) 603 outb((data
&0x0f), data_addr
); 607 outb(0x10| (data
&0x0f), data_addr
); 616 udelay(PLIP_DELAY_UNIT
); 618 outb(0x10| (data
>>4), --data_addr
); 622 outb((data
>>4), data_addr
); 631 udelay(PLIP_DELAY_UNIT
); 634 *ns_p
= PLIP_NB_BEGIN
; 640 /* PLIP_SEND_PACKET --- send a packet */ 642 plip_send_packet(struct device
*dev
,struct net_local
*nl
, 643 struct plip_local
*snd
,struct plip_local
*rcv
) 645 unsigned short data_addr
=PAR_DATA(dev
); 646 unsigned short nibble_timeout
= nl
->nibble
; 651 if(snd
->skb
== NULL
|| (lbuf
= snd
->skb
->data
) == NULL
) { 652 printk("%s: send skb lost\n", dev
->name
); 653 snd
->state
= PLIP_PK_DONE
; 659 case PLIP_PK_TRIGGER
: 660 /* Trigger remote rx interrupt. */ 661 outb(0x08, data_addr
); 664 udelay(PLIP_DELAY_UNIT
); 666 if(nl
->connection
== PLIP_CN_RECEIVE
) { 669 nl
->enet_stats
.collisions
++; 671 printk("%s: collision.\n", dev
->name
); 674 c0
=inb(PAR_STATUS(dev
)); 676 disable_irq(dev
->irq
); 677 outb(PAR_INTR_OFF
,PAR_CONTROL(dev
)); 679 printk("%s: send start\n", dev
->name
); 680 snd
->state
= PLIP_PK_LENGTH_LSB
; 681 snd
->nibble
= PLIP_NB_BEGIN
; 682 nl
->timeout_count
=0; 688 outb(0x00, data_addr
); 693 case PLIP_PK_LENGTH_LSB
: 694 if(plip_send(nibble_timeout
, data_addr
, 695 &snd
->nibble
, snd
->length
.b
.lsb
)) 697 snd
->state
= PLIP_PK_LENGTH_MSB
; 699 case PLIP_PK_LENGTH_MSB
: 700 if(plip_send(nibble_timeout
, data_addr
, 701 &snd
->nibble
, snd
->length
.b
.msb
)) 703 snd
->state
= PLIP_PK_DATA
; 709 if(plip_send(nibble_timeout
, data_addr
, 710 &snd
->nibble
, lbuf
[snd
->byte
])) 712 while(++snd
->byte
< snd
->length
.h
); 714 snd
->checksum
+= lbuf
[--snd
->byte
]; 716 snd
->state
= PLIP_PK_CHECKSUM
; 718 case PLIP_PK_CHECKSUM
: 719 if(plip_send(nibble_timeout
, data_addr
, 720 &snd
->nibble
, snd
->checksum
)) 723 dev_kfree_skb(snd
->skb
, FREE_WRITE
); 724 nl
->enet_stats
.tx_packets
++; 725 snd
->state
= PLIP_PK_DONE
; 728 /* Close the connection */ 729 outb(0x00, data_addr
); 732 printk("%s: send end\n", dev
->name
); 733 nl
->connection
= PLIP_CN_CLOSING
; 735 queue_task(&nl
->deferred
, &tq_timer
); 736 outb(PAR_INTR_ON
,PAR_CONTROL(dev
)); 737 enable_irq(dev
->irq
); 744 plip_connection_close(struct device
*dev
,struct net_local
*nl
, 745 struct plip_local
*snd
,struct plip_local
*rcv
) 748 if(nl
->connection
== PLIP_CN_CLOSING
) { 749 nl
->connection
= PLIP_CN_NONE
; 757 /* PLIP_ERROR --- wait till other end settled */ 759 plip_error(struct device
*dev
,struct net_local
*nl
, 760 struct plip_local
*snd
,struct plip_local
*rcv
) 762 unsigned char status
; 764 status
=inb(PAR_STATUS(dev
)); 765 if((status
&0xf8) ==0x80) { 767 printk("%s: reset interface.\n", dev
->name
); 768 nl
->connection
= PLIP_CN_NONE
; 771 outb(PAR_INTR_ON
,PAR_CONTROL(dev
)); 772 enable_irq(dev
->irq
); 776 queue_task(&nl
->deferred
, &tq_timer
); 782 /* Handle the parallel port interrupts. */ 784 plip_interrupt(int irq
,struct pt_regs
* regs
) 786 struct device
*dev
= (struct device
*) irq2dev_map
[irq
]; 787 struct net_local
*nl
= (struct net_local
*)dev
->priv
; 788 struct plip_local
*rcv
= &nl
->rcv_data
; 792 printk("plip_interrupt: irq %d for unknown device.\n", irq
); 799 c0
=inb(PAR_STATUS(dev
)); 800 if((c0
&0xf8) !=0xc0) { 802 printk("%s: spurious interrupt\n", dev
->name
); 807 printk("%s: interrupt.\n", dev
->name
); 810 switch(nl
->connection
) { 811 case PLIP_CN_CLOSING
: 815 dev
->last_rx
= jiffies
; 816 rcv
->state
= PLIP_PK_TRIGGER
; 817 nl
->connection
= PLIP_CN_RECEIVE
; 818 nl
->timeout_count
=0; 819 queue_task(&nl
->immediate
, &tq_immediate
); 820 mark_bh(IMMEDIATE_BH
); 824 case PLIP_CN_RECEIVE
: 826 printk("%s: receive interrupt when receiving packet\n", dev
->name
); 831 printk("%s: receive interrupt in error state\n", dev
->name
); 836 /* We don't need to send arp, for plip is point-to-point. */ 838 plip_rebuild_header(void*buff
,struct device
*dev
,unsigned long dst
, 841 struct net_local
*nl
= (struct net_local
*)dev
->priv
; 842 struct ethhdr
*eth
= (struct ethhdr
*)buff
; 845 if((dev
->flags
& IFF_NOARP
)==0) 846 return nl
->orig_rebuild_header(buff
, dev
, dst
, skb
); 848 if(eth
->h_proto
!=htons(ETH_P_IP
)) { 849 printk("plip_rebuild_header: Don't know how to resolve type %d addresses?\n", (int)eth
->h_proto
); 850 memcpy(eth
->h_source
, dev
->dev_addr
, dev
->addr_len
); 854 for(i
=0; i
< ETH_ALEN
-sizeof(unsigned long); i
++) 855 eth
->h_dest
[i
] =0xfc; 856 memcpy(&(eth
->h_dest
[i
]), &dst
,sizeof(unsigned long)); 861 plip_tx_packet(struct sk_buff
*skb
,struct device
*dev
) 863 struct net_local
*nl
= (struct net_local
*)dev
->priv
; 864 struct plip_local
*snd
= &nl
->snd_data
; 869 /* If some higher layer thinks we've missed an tx-done interrupt 870 we are passed NULL. Caution: dev_tint() handles the cli()/sti() 877 if(set_bit(0, (void*)&dev
->tbusy
) !=0) { 878 printk("%s: Transmitter access conflict.\n", dev
->name
); 882 if(skb
->len
> dev
->mtu
) { 883 printk("%s: packet too big, %d.\n", dev
->name
, (int)skb
->len
); 889 printk("%s: send request\n", dev
->name
); 892 dev
->trans_start
= jiffies
; 894 snd
->length
.h
= skb
->len
; 895 snd
->state
= PLIP_PK_TRIGGER
; 896 if(nl
->connection
== PLIP_CN_NONE
) { 897 nl
->connection
= PLIP_CN_SEND
; 898 nl
->timeout_count
=0; 900 queue_task(&nl
->immediate
, &tq_immediate
); 901 mark_bh(IMMEDIATE_BH
); 907 /* Open/initialize the board. This is called (in the current kernel) 908 sometime after booting when the 'ifconfig' program is run. 910 This routine gets exclusive access to the parallel port by allocating 914 plip_open(struct device
*dev
) 916 struct net_local
*nl
= (struct net_local
*)dev
->priv
; 920 printk("%s: IRQ is not set. Please set it by ifconfig.\n", dev
->name
); 924 if(request_irq(dev
->irq
, plip_interrupt
,0, dev
->name
) !=0) { 926 printk("%s: couldn't get IRQ %d.\n", dev
->name
, dev
->irq
); 929 irq2dev_map
[dev
->irq
] = dev
; 932 /* Clear the data port. */ 933 outb(0x00,PAR_DATA(dev
)); 935 /* Enable rx interrupt. */ 936 outb(PAR_INTR_ON
,PAR_CONTROL(dev
)); 938 /* Initialize the state machine. */ 939 nl
->rcv_data
.state
= nl
->snd_data
.state
= PLIP_PK_DONE
; 940 nl
->rcv_data
.skb
= nl
->snd_data
.skb
= NULL
; 941 nl
->connection
= PLIP_CN_NONE
; 944 /* Fill in the MAC-level header. */ 945 for(i
=0; i
< ETH_ALEN
-sizeof(unsigned long); i
++) 946 dev
->dev_addr
[i
] =0xfc; 947 memcpy(&(dev
->dev_addr
[i
]), &dev
->pa_addr
,sizeof(unsigned long)); 956 /* The inverse routine to plip_open (). */ 958 plip_close(struct device
*dev
) 960 struct net_local
*nl
= (struct net_local
*)dev
->priv
; 961 struct plip_local
*snd
= &nl
->snd_data
; 962 struct plip_local
*rcv
= &nl
->rcv_data
; 968 irq2dev_map
[dev
->irq
] = NULL
; 970 nl
->connection
= PLIP_CN_NONE
; 972 outb(0x00,PAR_DATA(dev
)); 974 snd
->state
= PLIP_PK_DONE
; 976 dev_kfree_skb(snd
->skb
, FREE_WRITE
); 979 rcv
->state
= PLIP_PK_DONE
; 982 kfree_skb(rcv
->skb
, FREE_READ
); 987 outb(0x00,PAR_CONTROL(dev
)); 992 static struct enet_statistics
* 993 plip_get_stats(struct device
*dev
) 995 struct net_local
*nl
= (struct net_local
*)dev
->priv
; 996 struct enet_statistics
*r
= &nl
->enet_stats
; 1002 plip_config(struct device
*dev
,struct ifmap
*map
) 1004 if(dev
->flags
& IFF_UP
) 1007 if(map
->base_addr
!= (unsigned long)-1 1008 && map
->base_addr
!= dev
->base_addr
) 1009 printk("%s: You cannot change base_addr of this interface (ignored).\n", dev
->name
); 1011 if(map
->irq
!= (unsigned char)-1) 1012 dev
->irq
= map
->irq
; 1017 plip_ioctl(struct device
*dev
,struct ifreq
*rq
,int cmd
) 1019 struct net_local
*nl
= (struct net_local
*) dev
->priv
; 1020 struct plipconf
*pc
= (struct plipconf
*) &rq
->ifr_data
; 1023 case PLIP_GET_TIMEOUT
: 1024 pc
->trigger
= nl
->trigger
; 1025 pc
->nibble
= nl
->nibble
; 1027 case PLIP_SET_TIMEOUT
: 1028 nl
->trigger
= pc
->trigger
; 1029 nl
->nibble
= pc
->nibble
; 1038 char kernel_version
[] = UTS_RELEASE
; 1040 static struct device dev_plip0
= 1043 0,0,0,0,/* memory */ 1044 0x3BC,5,/* base, irq */ 1045 0,0,0, NULL
, plip_init
1048 static struct device dev_plip1
= 1051 0,0,0,0,/* memory */ 1052 0x378,7,/* base, irq */ 1053 0,0,0, NULL
, plip_init
1056 static struct device dev_plip2
= 1059 0,0,0,0,/* memory */ 1060 0x278,2,/* base, irq */ 1061 0,0,0, NULL
, plip_init
1069 if(register_netdev(&dev_plip0
) !=0) 1071 if(register_netdev(&dev_plip1
) !=0) 1073 if(register_netdev(&dev_plip2
) !=0) 1081 cleanup_module(void) 1083 if(dev_plip0
.priv
) { 1084 unregister_netdev(&dev_plip0
); 1085 release_region(PAR_DATA(&dev_plip0
),3); 1086 kfree_s(dev_plip0
.priv
,sizeof(struct net_local
)); 1087 dev_plip0
.priv
= NULL
; 1089 if(dev_plip1
.priv
) { 1090 unregister_netdev(&dev_plip1
); 1091 release_region(PAR_DATA(&dev_plip1
),3); 1092 kfree_s(dev_plip1
.priv
,sizeof(struct net_local
)); 1093 dev_plip1
.priv
= NULL
; 1095 if(dev_plip2
.priv
) { 1096 unregister_netdev(&dev_plip2
); 1097 release_region(PAR_DATA(&dev_plip2
),3); 1098 kfree_s(dev_plip2
.priv
,sizeof(struct net_local
)); 1099 dev_plip2
.priv
= NULL
; 1106 * compile-command: "gcc -DMODULE -DCONFIG_MODVERSIONS -D__KERNEL__ -Wall -Wstrict-prototypes -O2 -g -fomit-frame-pointer -pipe -m486 -c plip.c"