root/drivers/net/plip.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. plip_init
  2. plip_open
  3. plip_close
  4. plip_tx_packet
  5. plip_header
  6. plip_device_clear
  7. plip_receiver_error
  8. get_byte
  9. plip_interrupt
  10. plip_receive_packet
  11. send_byte
  12. plip_send_start
  13. plip_send_packet
  14. plip_set_physicaladdr
  15. plip_addrcmp
  16. cold_sleep
  17. double_timeoutfactor
  18. plip_get_stats

   1 /*
   2  *       Plip.c: A parallel port "network" driver for linux. 
   3  */
   4 
   5 /*
   6  *      Developement History:
   7  *
   8  *      Original version and the name 'PLIP' from Donald Becker  <becker@super.org>
   9  *              inspired by Russ Nelson's parallel port packet driver.
  10  *      Further development by Tommy Thorn <thorn@daimi.aau.dk>
  11  *      Some changes by Tanabe Hiroyasu <hiro@sanpo.t.u-tokyo.ac.jp>
  12  *      Upgraded for PL12 by Donald Becker
  13  *      Minor hacks by Alan Cox <gw4pts@gw4pts.ampr.org> to get it working
  14  *              more reliably (Ha!)
  15  *     Changes even more Peter Bauer (100136.3530@compuserve.com)
  16  *     Protocol changed back to original plip as in crynwr's packet-drivers.
  17  *     Tested this against ncsa-telnet 2.3 and pcip_pkt using plip.com (which
  18  *     contains "version        equ     0" and ";History:562,1" in the firts 2
  19  *    source-lines                                              28-Mar-94
  20  *      
  21  *      
  22  *
  23  *  This is parallel port packet pusher.  It's actually more general
  24  *  than the "IP" in its name suggests -- but 'plip' is just such a
  25  *  great name!
  26  * 
  27  *    
  28  *   Bugs: Please read this: The PLIP driver is a nasty hack and like all nasty hacks 
  29  *         has some 'features'.
  30  *
  31  *      Can lock machines solid if one end goes down or crashes, or due to cable faults.
  32  *      Can lock both machines solid on a broadcast collision.
  33  *      Some laptops don't have all the wires we use.
  34  *      Doesn't match the original Russ Nelson protocol so won't talk to Amiga or PC drivers.
  35  *      Waits far too long with interrupts off [X is unbearable, forget action games, xntp is a joke]
  36  *      Doesn't work on some fast 486DX machines
  37  *
  38  *      If it works be thankful, if not fix it!
  39  *
  40  *  Info:
  41  *      I <Alan> got 15K/second NFS throughput (about 20-25K second IP). I also got some ethernet cards
  42  *      so don't ask me for help. This code needs a real major rewrite. Any volunteers ?
  43  */
  44 
  45 static char *version =
  46     "NET3 PLIP.010 (from plip.c:v0.15 for 0.99pl12+, 8/11/93)\n";
  47 
  48 #include <linux/config.h>
  49 
  50 /*
  51   Sources:
  52         Ideas and protocols came from Russ Nelson's (nelson@crynwr.com)
  53         "parallel.asm" parallel port packet driver.
  54         TANABE Hiroyasu changes the protocol.
  55   The "Crynwr" parallel port standard specifies the following protocol:
  56    send header nibble '8'
  57    type octet '0xfd' or '0xfc'
  58    count-low octet
  59    count-high octet
  60    ... data octets
  61    checksum octet
  62 Each octet is sent as <wait for rx. '0x1?'> <send 0x10+(octet&0x0F)>
  63                         <wait for rx. '0x0?'> <send 0x00+((octet>>4)&0x0F)>
  64 
  65 The cable used is a de facto standard parallel null cable -- sold as
  66 a "LapLink" cable by various places.  You'll need a 10-conductor cable to
  67 make one yourself.  The wiring is:
  68     INIT        16 - 16         SLCTIN  17 - 17
  69     GROUND      25 - 25
  70     D0->ERROR   2 - 15          15 - 2
  71     D1->SLCT    3 - 13          13 - 3
  72     D2->PAPOUT  4 - 12          12 - 4
  73     D3->ACK     5 - 10          10 - 5
  74     D4->BUSY    6 - 11          11 - 6
  75   Do not connect the other pins.  They are
  76     D5,D6,D7 are 7,8,9
  77     STROBE is 1, FEED is 14
  78     extra grounds are 18,19,20,21,22,23,24
  79 */
  80 
  81 #include <linux/kernel.h>
  82 #include <linux/sched.h>
  83 #include <linux/types.h>
  84 #include <linux/fcntl.h>
  85 #include <linux/interrupt.h>
  86 #include <linux/string.h>
  87 #include <linux/ptrace.h>
  88 #include <linux/if_ether.h>
  89 #include <asm/system.h>
  90 #include <asm/io.h>
  91 #include <netinet/in.h>
  92 #include <errno.h>
  93 
  94 #include <linux/netdevice.h>
  95 #include <linux/etherdevice.h>
  96 #include <linux/skbuff.h>
  97 
  98 #ifdef PRINTK
  99 #undef PRINTK
 100 #endif
 101 #ifdef PRINTK2
 102 #undef PRINTK2
 103 #endif
 104 
 105 #define PLIP_DEBUG      /* debugging */
 106 #undef  PLIP_DEBUG2     /* debugging with more varbose report */
 107 
 108 #ifdef PLIP_DEBUG
 109 #define PRINTK(x) printk x
 110 #else
 111 #define PRINTK(x) /**/
 112 #endif
 113 #ifdef PLIP_DEBUG2
 114 #define PRINTK2(x) printk x
 115 #else
 116 #define PRINTK2(x) /**/
 117 #endif
 118 
 119 /* The map from IRQ number (as passed to the interrupt handler) to
 120    'struct device'. */
 121 extern struct device *irq2dev_map[16];
 122 
 123 /* Network statistics, with the same names as 'struct enet_statistics'. */
 124 #define netstats enet_statistics
 125 
 126 /* constants */
 127 #define PAR_DATA        0
 128 #define PAR_STATUS      1
 129 #define PAR_CONTROL     2
 130 #define PLIP_MTU 1600
 131 #define PLIP_HEADER_TYPE1 0xfd
 132 #define PLIP_HEADER_TYPE2 0xfc
 133 
 134 /* Index to functions, as function prototypes. */
 135 extern int plip_probe(int ioaddr, struct device *dev);
 136 static int plip_open(struct device *dev);
 137 static int plip_close(struct device *dev);
 138 static int plip_tx_packet(struct sk_buff *skb, struct device *dev);
 139 static int plip_header (unsigned char *buff, struct device *dev,
 140                  unsigned short type, void *dest,
 141                  void *source, unsigned len, struct sk_buff *skb);
 142 
 143 /* variables used internally. */
 144 #define INITIALTIMEOUTFACTOR 4
 145 #define MAXTIMEOUTFACTOR 20
 146 static int timeoutfactor = INITIALTIMEOUTFACTOR;
 147 
 148 /* Routines used internally. */
 149 static void plip_device_clear(struct device *dev);
 150 static void plip_receiver_error(struct device *dev);
 151 static void plip_set_physicaladdr(struct device *dev, unsigned long ipaddr);
 152 static int plip_addrcmp(struct ethhdr *eth);
 153 static void cold_sleep(int tics);
 154 static void plip_interrupt(int reg_ptr); /* Dispatch from interrupts. */
 155 static int plip_receive_packet(struct device *dev);
 156 static int plip_send_packet(struct device *dev, unsigned char *buf, int length);
 157 static int plip_send_start(struct device *dev, struct ethhdr *eth);
 158 static void double_timeoutfactor(void);
 159 static struct enet_statistics *plip_get_stats(struct device *dev);
 160 
 161 int
 162 plip_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 163 {
 164     int port_base = dev->base_addr;
 165     int i;
 166 
 167     /* Check that there is something at base_addr. */
 168     outb(0x00, port_base + PAR_CONTROL);
 169     outb(0x55, port_base + PAR_DATA);
 170     if (inb(port_base + PAR_DATA) != 0x55)
 171         return -ENODEV;
 172 
 173     /* Alpha testers must have the version number to report bugs. */
 174 #ifdef PLIP_DEBUG
 175     {
 176         static int version_shown = 0;
 177         if (! version_shown)
 178             printk(version), version_shown++;
 179     }
 180 #endif
 181 
 182     /* Initialize the device structure. */
 183     dev->priv = kmalloc(sizeof(struct netstats), GFP_KERNEL);
 184     memset(dev->priv, 0, sizeof(struct netstats));
 185 
 186     for (i = 0; i < DEV_NUMBUFFS; i++)
 187         skb_queue_head_init(&dev->buffs[i]);
 188 
 189     dev->hard_header = &plip_header;
 190     dev->rebuild_header = eth_rebuild_header;
 191     dev->type_trans = eth_type_trans;
 192 
 193     dev->open = &plip_open;
 194     dev->stop = &plip_close;
 195     dev->hard_start_xmit = &plip_tx_packet;
 196     dev->get_stats = &plip_get_stats;
 197 
 198     /* These are ethernet specific. */
 199     dev->type = ARPHRD_ETHER;
 200     dev->hard_header_len = ETH_HLEN;
 201     dev->mtu = PLIP_MTU;        /* PLIP may later negotiate max pkt size */
 202     dev->addr_len = ETH_ALEN;
 203     for (i = 0; i < dev->addr_len; i++) {
 204         dev->broadcast[i]=0xff;
 205         dev->dev_addr[i] = 0;
 206     }
 207     printk("%s: configured for parallel port at %#3x, IRQ %d.\n",
 208            dev->name, dev->base_addr, dev->irq);
 209 
 210     /* initialize internal value */
 211     timeoutfactor = INITIALTIMEOUTFACTOR;
 212     return 0;
 213 }
 214 
 215 /* Open/initialize the board.  This is called (in the current kernel)
 216    sometime after booting when the 'config <dev->name>' program is
 217    run.
 218 
 219    This routine gets exclusive access to the parallel port by allocating
 220    its IRQ line.
 221    */
 222 static int
 223 plip_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 224 {
 225     if (dev->irq == 0)
 226         dev->irq = 7;
 227     cli();
 228     if (request_irq(dev->irq , &plip_interrupt) != 0) {
 229         sti();
 230         PRINTK(("%s: couldn't get IRQ %d.\n", dev->name, dev->irq));
 231         return -EAGAIN;
 232     }
 233 
 234     irq2dev_map[dev->irq] = dev;
 235     sti();
 236     plip_device_clear(dev);
 237     dev->tbusy = 0;
 238     dev->interrupt = 0;
 239     dev->start = 1;
 240     return 0;
 241 }
 242 
 243 /* The inverse routine to plip_open(). */
 244 static int
 245 plip_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 246 {
 247     dev->tbusy = 1;
 248     dev->start = 0;
 249     cli();
 250     free_irq(dev->irq);
 251     irq2dev_map[dev->irq] = NULL;
 252     sti();
 253     outb(0x00, dev->base_addr);         /* Release the interrupt. */
 254     return 0;
 255 }
 256 
 257 static int
 258 plip_tx_packet(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 259 {
 260     int ret_val;
 261 
 262     if (dev->tbusy || dev->interrupt) { /* Do timeouts, to avoid hangs. */
 263         int tickssofar = jiffies - dev->trans_start;
 264         if (tickssofar < 50)
 265             return 1;
 266         printk("%s: transmit timed out\n", dev->name);
 267         /* Try to restart the adaptor. */
 268         plip_device_clear(dev);
 269         return 0;
 270     }
 271 
 272     /* If some higher layer thinks we've missed an tx-done interrupt
 273        we are passed NULL. Caution: dev_tint() handles the cli()/sti()
 274        itself. */
 275     if (skb == NULL) {
 276         dev_tint(dev);
 277         return 0;
 278     }
 279 
 280     dev->trans_start = jiffies;
 281     ret_val = plip_send_packet(dev, skb->data, skb->len);
 282     if (skb->free)
 283         kfree_skb (skb, FREE_WRITE);
 284     dev->tbusy = 0;
 285     mark_bh (INET_BH);
 286     return 0/*ret_val*/;
 287 }
 288 
 289 static int
 290 plip_header (unsigned char *buff, struct device *dev,
     /* [previous][next][first][last][top][bottom][index][help] */
 291              unsigned short type, void *daddr                ,
 292              void *saddr, unsigned len, struct sk_buff *skb)
 293 {
 294     if (dev->dev_addr[0] == 0) {
 295         /* set physical address */
 296         plip_set_physicaladdr(dev, dev->pa_addr);
 297     }
 298     return eth_header(buff, dev, type, daddr, saddr, len, skb);
 299 }
 300 
 301 static void
 302   plip_device_clear(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 303 {
 304     dev->interrupt = 0;
 305     dev->tbusy = 0;
 306     outb(0x00, dev->base_addr + PAR_DATA);
 307     outb(0x10, dev->base_addr + PAR_CONTROL);           /* Enable the rx interrupt. */
 308 }
 309 
 310 static void
 311   plip_receiver_error(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 312 {
 313     dev->interrupt = 0;
 314     dev->tbusy = 0;
 315     outb(0x02, dev->base_addr + PAR_DATA);
 316     outb(0x10, dev->base_addr + PAR_CONTROL);           /* Enable the rx interrupt. */
 317 }
 318 
 319 static int
 320   get_byte(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 321 {
 322     unsigned char val, oldval;
 323     unsigned char low_nibble;
 324     int timeout;
 325     int error = 0;
 326     val = inb(dev->base_addr + PAR_STATUS);
 327     timeout = jiffies + timeoutfactor * 2;
 328     do {
 329         oldval = val;
 330         val = inb(dev->base_addr + PAR_STATUS);
 331         if ( oldval != val ) continue; /* it's unstable */
 332         if ( timeout < jiffies ) {
 333             error++;
 334             break;
 335         }
 336     } while ( (val & 0x80) );
 337     val = inb(dev->base_addr + PAR_STATUS);
 338     low_nibble = (val >> 3) & 0x0f;
 339     outb(0x10, dev->base_addr + PAR_DATA);
 340     timeout = jiffies + timeoutfactor * 2;
 341     do {
 342         oldval = val;
 343         val = inb(dev->base_addr + PAR_STATUS);
 344         if (oldval != val) continue; /* it's unstable */
 345         if ( timeout < jiffies ) {
 346             error++;
 347             break;
 348         }
 349     } while ( !(val & 0x80) );
 350     val = inb(dev->base_addr + PAR_STATUS);
 351     PRINTK2(("%02x %s ", low_nibble | ((val << 1) & 0xf0),
 352                error ? "t":""));
 353     outb(0x00, dev->base_addr + PAR_DATA);
 354     if (error) {
 355         /* timeout error */
 356         double_timeoutfactor();
 357         return -1;
 358     }
 359     return low_nibble | ((val << 1) & 0xf0);
 360 }
 361 
 362 /* The typical workload of the driver:
 363    Handle the parallel port interrupts. */
 364 static void
 365   plip_interrupt(int reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 366 {
 367     int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
 368     struct device *dev = irq2dev_map[irq];
 369     struct netstats *localstats;
 370 
 371     if (dev == NULL) {
 372         PRINTK(("plip_interrupt(): irq %d for unknown device.\n", irq));
 373         return;
 374     }
 375     localstats = (struct netstats*) dev->priv;
 376     if (dev->tbusy || dev->interrupt) return;
 377     dev->interrupt = 1;
 378     outb(0x00, dev->base_addr + PAR_CONTROL);  /* Disable the rx interrupt. */
 379     sti(); /* Allow other interrupts. */
 380     PRINTK2(("%s: interrupt.  ", dev->name));
 381 
 382     {
 383         /* check whether the interrupt is valid or not.*/
 384         int timeout = jiffies + timeoutfactor;
 385         while ((inb(dev->base_addr + PAR_STATUS) & 0xf8) != 0xc0) {
 386             if ( timeout < jiffies ) {
 387                 PRINTK2(("%s: No interrupt (status=%#02x)!\n",
 388                          dev->name, inb(dev->base_addr + PAR_STATUS)));
 389                 plip_device_clear(dev);
 390                 return;
 391             }
 392         }
 393     }
 394     if (plip_receive_packet(dev)) {
 395         /* get some error while receiving data */
 396         localstats->rx_errors++;
 397         plip_receiver_error(dev);
 398     } else {
 399         plip_device_clear(dev);
 400     }
 401 }
 402 
 403 static int
 404 plip_receive_packet(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 405 {
 406     unsigned length;
 407     int checksum = 0;
 408     struct sk_buff *skb;
 409     struct netstats *localstats;
 410     struct ethhdr eth;
 411 
 412     localstats = (struct netstats*) dev->priv;
 413     
 414     outb(1, dev->base_addr + PAR_DATA);         /* Ack: 'Ready' */
 415 
 416     {
 417         /* get header octet and length of packet */
 418         
 419         length = get_byte(dev);
 420         length |= get_byte(dev) << 8;
 421         {
 422          int i;
 423          unsigned char *eth_p = (unsigned char*)&eth;
 424          for ( i = 0; i < sizeof(eth); i++, eth_p++) {
 425              *eth_p = get_byte(dev);
 426          }
 427         }
 428         PRINTK2(("length = %d\n", length));
 429         if (length > dev->mtu || length < 8) {
 430             PRINTK2(("%s: bogus packet size %d.\n", dev->name, length));
 431             return 1;
 432         }
 433     }
 434     {
 435         /* get skb area from kernel and 
 436          * set appropriate values to skb
 437          */
 438         skb = alloc_skb(length, GFP_ATOMIC);
 439         if (skb == NULL) {
 440             PRINTK(("%s: Couldn't allocate a sk_buff of size %d.\n",
 441                     dev->name,length));
 442             return 1;
 443         }
 444         skb->lock = 0;
 445     }
 446     {
 447         /* phase of receiving the data */
 448         /* 'skb->data' points to the start of sk_buff data area. */
 449         unsigned char *buf = skb->data;
 450         unsigned char *eth_p = (unsigned char *)&eth;
 451         int i;
 452         for ( i = 0; i < sizeof(eth); i++) {
 453             checksum += *eth_p;
 454             *buf++ = *eth_p++;
 455         }
 456         for ( i = 0; i < length - sizeof(eth); i++) {
 457             unsigned char new_byte = get_byte(dev);
 458             checksum += new_byte;
 459             *buf++ = new_byte;
 460         }
 461         checksum &= 0xff;
 462         if (checksum != get_byte(dev)) {
 463             localstats->rx_crc_errors++;
 464             PRINTK(("checksum error\n"));
 465             return 1;
 466         } else if(dev_rint((unsigned char *)skb, length, IN_SKBUFF, dev)) {
 467             printk("%s: rcv buff full.\n", dev->name);
 468             localstats->rx_dropped++;
 469             return 1;
 470         }
 471     }
 472     {
 473         /* phase of terminating this connection */
 474         int timeout;
 475 
 476         timeout = jiffies + length * timeoutfactor / 16;
 477         outb(0x00, dev->base_addr + PAR_DATA);
 478         /* Wait for the remote end to reset. */
 479         while ( (inb(dev->base_addr + PAR_STATUS) & 0xf8) != 0x80 ) {
 480             if (timeout < jiffies ) {
 481                 double_timeoutfactor();
 482                 PRINTK(("Remote has not reset.\n"));
 483                 break;
 484             }
 485         }
 486     }
 487     localstats->rx_packets++;
 488     return 0;
 489 }
 490 
 491 
 492 static int send_byte(struct device *dev, unsigned char val)
     /* [previous][next][first][last][top][bottom][index][help] */
 493 {
 494     int timeout;
 495     int error = 0;
 496     PRINTK2((" S%02x", val));
 497     outb((val & 0xf), dev->base_addr); /* this makes data bits more stable */
 498                                        /* (especially the &0xf :-> PB )    */
 499     outb(0x10 | (val & 0xf), dev->base_addr);
 500     timeout = jiffies + timeoutfactor;
 501     while( inb(dev->base_addr+PAR_STATUS) & 0x80 )
 502         if ( timeout < jiffies ) {
 503             error++;
 504             break;
 505         }
 506     outb(0x10 | (val >> 4), dev->base_addr);
 507     outb(val >> 4, dev->base_addr);
 508     timeout = jiffies + timeoutfactor;
 509     while( (inb(dev->base_addr+PAR_STATUS) & 0x80) == 0 )
 510         if ( timeout < jiffies ) {
 511             error++;
 512             break;
 513         }
 514     if (error) {
 515         /* timeout error */
 516         double_timeoutfactor();
 517         PRINTK2(("t"));
 518         return -1;
 519     }
 520     return 0;
 521 }
 522 /*
 523  * plip_send_start
 524  * trigger remoto rx interrupt and establish a connection.
 525  * 
 526  * return value
 527  * 0 : establish the connection
 528  * -1 : connection failed.
 529  */
 530 static int
 531 plip_send_start(struct device *dev, struct ethhdr *eth)
     /* [previous][next][first][last][top][bottom][index][help] */
 532 {       
 533     int timeout;
 534     int status;
 535     int lasttrigger;
 536     struct netstats *localstats = (struct netstats*) dev->priv;
 537 
 538     /* This starts the packet protocol by triggering a remote IRQ. */
 539     timeout = jiffies + timeoutfactor * 16;
 540     lasttrigger = jiffies;
 541     while ( ((status = inb(dev->base_addr+PAR_STATUS)) & 0x08) == 0 ) {
 542         dev->tbusy = 1;
 543         outb(0x00, dev->base_addr + PAR_CONTROL); /* Disable my rx intr. */
 544         outb(0x08, dev->base_addr + PAR_DATA);  /* Trigger remote rx intr. */
 545         if (status & 0x40) {
 546             /* The remote end is also trying to send a packet.
 547              * Only one end may go to the receiving phase,
 548              * so we use the "ethernet" address (set from the IP address)
 549              * to determine which end dominates.
 550              */
 551             if ( plip_addrcmp(eth) > 0 ) {
 552                 localstats->collisions++;
 553                 PRINTK2(("both ends are trying to send a packet.\n"));
 554                 if (plip_receive_packet(dev)) {
 555                     /* get some error while receiving data */
 556                     localstats->rx_errors++;
 557                     outb(0x02, dev->base_addr + PAR_DATA);
 558                 } else {
 559                     outb(0x00, dev->base_addr + PAR_DATA);
 560                 }
 561                 cold_sleep(2); /* make sure that remote end is ready */
 562             }
 563             continue; /* restart send sequence */
 564         }
 565         if (lasttrigger != jiffies) {
 566             /* trigger again */
 567             outb(0x00, dev->base_addr + PAR_DATA);
 568             cold_sleep(1);
 569             lasttrigger = jiffies;
 570         }
 571         if (timeout < jiffies) {
 572             double_timeoutfactor();
 573             plip_device_clear(dev);
 574             localstats->tx_errors++;
 575             PRINTK(("%s: Connect failed in send_packet().\n",
 576                     dev->name));
 577             /* We failed to send the packet.  To emulate the ethernet we
 578                should pretent the send worked fine */
 579             return -1;
 580         }
 581     }
 582     return 0;
 583 }
 584 static int
 585 plip_send_packet(struct device *dev, unsigned char *buf, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
 586 {
 587     int error = 0;
 588     struct netstats *localstats;
 589 
 590     PRINTK2(("%s: plip_send_packet(%d) %02x %02x %02x %02x %02x...",
 591            dev->name, length, buf[0], buf[1], buf[2], buf[3], buf[4]));
 592     if (length > dev->mtu) {
 593         printk("%s: packet too big, %d.\n", dev->name, length);
 594         return 0;
 595     }
 596     localstats = (struct netstats*) dev->priv;
 597 
 598     {
 599         /* phase of checking remote status */
 600         int i;
 601         int timeout = jiffies + timeoutfactor * 8;
 602         while ( (i = (inb(dev->base_addr+PAR_STATUS) & 0xe8)) != 0x80 ) {
 603             if (i == 0x78) {
 604                 /* probably cable is not connected */
 605                 /* Implementation Note:
 606                  * This status should result in 'Network unreachable'.
 607                  * but I don't know the way.
 608                  */
 609                 return 0;
 610             }
 611             if (timeout < jiffies) {
 612                 /* remote end is not ready */
 613                 double_timeoutfactor();
 614                 localstats->tx_errors++;
 615                 PRINTK(("remote end is not ready.\n"));
 616                 return 1; /* Failed to send the packet */
 617             }
 618         }
 619     }
 620     /* phase of making a connection */
 621     if (plip_send_start(dev, (struct ethhdr *)buf) < 0)
 622         return 1;
 623 
 624     {
 625         /* send packet's length 
 626            the byte order has changed now and then. Today it's sent as in 
 627            the original crynwr-plip ...
 628            Gruss PB
 629          */
 630         send_byte(dev, length); 
 631         send_byte(dev, length >> 8);
 632     }
 633     {
 634         /* phase of sending data */
 635         int i;
 636         int checksum = 0;
 637 
 638         for ( i = 0; i < sizeof(struct ethhdr); i++ ) {
 639             send_byte(dev, *buf);
 640             checksum += *buf++;
 641         }
 642 
 643         for (i = 0; i < length - sizeof(struct ethhdr); i++) {
 644             checksum += buf[i];
 645             if (send_byte(dev, buf[i]) < 0) {
 646                 error++;
 647                 break;
 648             }
 649         }
 650         send_byte(dev, checksum & 0xff);
 651     }
 652     {
 653         /* phase of terminating this connection */
 654         int timeout;
 655         
 656         outb(0x00, dev->base_addr + PAR_DATA);
 657         /* Wait for the remote end to reset. */
 658         timeout = jiffies + ((length * timeoutfactor) >> 4);
 659         while ((inb(dev->base_addr + PAR_STATUS) & 0xe8) != 0x80) {
 660             if (timeout < jiffies ) {   
 661                 double_timeoutfactor();
 662                 PRINTK(("Remote end has not reset.\n"));
 663                 error++;
 664                 break;
 665             }
 666         }
 667         if (inb(dev->base_addr + PAR_STATUS) & 0x10) {
 668             /* receiver reports error */
 669             error++;
 670         }
 671     }
 672     plip_device_clear(dev);
 673     localstats->tx_packets++;
 674     PRINTK2(("plip_send_packet(%d) done.\n", length));
 675     return error?1:0;
 676 }
 677 
 678 /*
 679  * some trivial functions
 680  */
 681 static void
 682 plip_set_physicaladdr(struct device *dev, unsigned long ipaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 683 {
 684     /*
 685      * set physical address to
 686      *  0xfd.0xfd.ipaddr
 687      */
 688 
 689     unsigned char *addr = dev->dev_addr;
 690     int i;
 691 
 692     if ((ipaddr >> 24) == 0 || (ipaddr >> 24) == 0xff) return;
 693     PRINTK2(("%s: set physical address to %08x\n", dev->name, ipaddr));
 694     for (i=0; i < ETH_ALEN - sizeof(unsigned long); i++) {
 695         addr[i] = 0xfd;
 696     }
 697     memcpy(&(addr[i]), &ipaddr, sizeof(unsigned long));
 698 }
 699 
 700 static int
 701 plip_addrcmp(struct ethhdr *eth)
     /* [previous][next][first][last][top][bottom][index][help] */
 702 {
 703     int i;
 704     for ( i = ETH_ALEN - 1; i >= 0; i-- ) {
 705         if (eth->h_dest[i] > eth->h_source[i]) return -1;
 706         if (eth->h_dest[i] < eth->h_source[i]) return 1;
 707     }
 708     PRINTK2(("h_dest = %08x%04x h_source = %08x%04x\n",
 709             *(long*)&eth->h_dest[2],*(short*)&eth->h_dest[0],
 710             *(long*)&eth->h_source[2],*(short*)&eth->h_source[0]));
 711     return 0;
 712 }
 713 
 714 /* This function is evil, evil, evil.  This should be a
 715    _kernel_, rescheduling sleep!. */
 716 static void
 717 cold_sleep(int tics)
     /* [previous][next][first][last][top][bottom][index][help] */
 718 {
 719     int start = jiffies;
 720     while(jiffies < start + tics)
 721         ; /* do nothing */
 722     return;
 723 }
 724 
 725 static void
 726   double_timeoutfactor()
     /* [previous][next][first][last][top][bottom][index][help] */
 727 {
 728     timeoutfactor *= 2;
 729     if (timeoutfactor >= MAXTIMEOUTFACTOR) {
 730         timeoutfactor = MAXTIMEOUTFACTOR;
 731     }
 732     return;
 733 }
 734 
 735 static struct enet_statistics *
 736 plip_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 737 {
 738     struct netstats *localstats = (struct netstats*) dev->priv;
 739     return localstats;
 740 }
 741 
 742 /*
 743  * Local variables:
 744  *  compile-command: "gcc -D__KERNEL__ -Wall -O6 -fomit-frame-pointer -x c++ -c plip.c"
 745  *  version-control: t
 746  *  kept-new-versions: 5
 747  * End:
 748  */

/* [previous][next][first][last][top][bottom][index][help] */