root/drivers/net/3c505.c

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

DEFINITIONS

This source file includes following definitions.
  1. get_status
  2. set_hsf
  3. wait_hcre
  4. send_pcb
  5. receive_pcb
  6. adapter_hard_reset
  7. adapter_reset
  8. start_receive
  9. receive_packet
  10. elp_interrupt
  11. elp_open
  12. elp_close
  13. send_packet
  14. elp_start_xmit
  15. elp_get_stats
  16. elp_init
  17. elp_probe

   1 /*
   2  * Linux ethernet device driver for the 3Com Etherlink Plus (3C505)
   3  *      By Craig Southeren
   4  *
   5  * 3c505.c      This module implements an interface to the 3Com
   6  *              Etherlink Plus (3c505) ethernet card. Linux device 
   7  *              driver interface reverse engineered from the Linux 3C509
   8  *              device drivers. Vital 3C505 information gleaned from
   9  *              the Crynwr packet driver
  10  *
  11  * Version:     @(#)3c505.c     0.1     23/09/93
  12  *
  13  * Authors:     Linux 3c505 device driver by:
  14  *                      Craig Southeren, <geoffw@extro.ucc.su.oz.au>
  15  *              Linux 3C509 driver by:
  16  *                      Donald Becker, <becker@super.org>
  17  *              Crynwr packet driver by
  18  *                      Krishnan Gopalan and Gregg Stefancik,
  19  *                         Clemson Univesity Engineering Computer Operations.
  20  *                      Portions of the code have been adapted from the 3c505
  21  *                         driver for NCSA Telnet by Bruce Orchard and later
  22  *                         modified by Warren Van Houten and krus@diku.dk.
  23  *              3C505 technical information provided by
  24  *                      Terry Murphy, of 3Com Network Adapter Division
  25  *              Special thanks to Juha Laiho, <jlaiho@ichaos.nullnet.fi>
  26  *                     
  27  */
  28 
  29 #include <linux/config.h>
  30 #include <linux/kernel.h>
  31 #include <linux/sched.h>
  32 #include <linux/string.h>
  33 #include <linux/interrupt.h>
  34 #include <linux/ptrace.h>
  35 #include <linux/errno.h>
  36 #include <linux/in.h>
  37 #include <asm/io.h>
  38 #ifndef port_read
  39 #include "iow.h"
  40 #endif
  41 
  42 #include <linux/netdevice.h>
  43 #include <linux/etherdevice.h>
  44 #include <linux/skbuff.h>
  45 
  46 #include "3c505.h"
  47 
  48 #ifdef ELP_DEBUG
  49 static int elp_debug = ELP_DEBUG;
  50 #else
  51 static int elp_debug = 0;
  52 #endif
  53 
  54 /*
  55  *  0 = no messages
  56  *  1 = messages when high level commands performed
  57  *  2 = messages when low level commands performed
  58  *  3 = messages when interrupts received
  59  */
  60 
  61 #define ELP_VERSION     "0.1.0"
  62 
  63 extern struct device *irq2dev_map[16];
  64 
  65 /*****************************************************************
  66  *
  67  * useful macros
  68  *
  69  *****************************************************************/
  70 
  71 #define INB(port)       inb((unsigned short)port) 
  72 #define OUTB(val,port)  outb((unsigned char)val,(unsigned short)port);
  73 
  74 #ifndef TRUE
  75 #define TRUE    1
  76 #endif
  77 
  78 #ifndef FALSE
  79 #define FALSE   0
  80 #endif
  81 
  82 
  83 /*****************************************************************
  84  *
  85  * PCB structure
  86  *
  87  *****************************************************************/
  88 
  89 typedef struct {
  90   unsigned char   command;              /* PCB command code */
  91   unsigned char   length;               /* PCB data length */
  92   unsigned char   data[MAX_PCB_DATA];   /* PCB data */
  93 } pcb_struct;
  94 
  95 
  96 /*****************************************************************
  97  *
  98  *  structure to hold context information for adapter
  99  *
 100  *****************************************************************/
 101 
 102 typedef struct {
 103   int        io_addr;        /* base I/O address */
 104   short      got_configure;  /* set to TRUE when configure response received */
 105   pcb_struct tx_pcb;         /* PCB for foreground sending */
 106   pcb_struct rx_pcb;         /* PCB for foreground receiving */
 107   pcb_struct itx_pcb;        /* PCB for background sending */
 108   pcb_struct irx_pcb;        /* PCB for background receiving */
 109   struct enet_statistics stats;
 110 } elp_device;
 111 
 112 /*****************************************************************
 113  *
 114  *  useful functions for accessing the adapter
 115  *
 116  *****************************************************************/
 117 
 118 /*
 119  * use this routine when accessing the ASF bits as they are
 120  * changed asynchronously by the adapter
 121  */
 122 
 123 /* get adapter PCB status */
 124 #define GET_ASF()       (get_status(adapter)&ASF_PCB_MASK)
 125 #define GET_STATUS()    (get_status(adapter))
 126 
 127 static int get_status (elp_device * adapter)
     /* [previous][next][first][last][top][bottom][index][help] */
 128 
 129 {
 130   register int stat1;
 131   do {
 132     stat1 = INB(adapter->io_addr+PORT_STATUS);
 133   } while (stat1 != INB(adapter->io_addr+PORT_STATUS));
 134   return stat1;
 135 }
 136 
 137 #define SET_HSF(hsf)    (set_hsf(adapter,hsf))
 138 
 139 static void set_hsf (elp_device * adapter, int hsf)
     /* [previous][next][first][last][top][bottom][index][help] */
 140 
 141 {
 142   cli();
 143   OUTB((INB(adapter->io_addr+PORT_CONTROL)&(~HSF_PCB_MASK))|hsf, adapter->io_addr+PORT_CONTROL); 
 144   sti(); 
 145 }
 146 
 147 #define WAIT_HCRE(toval)        (wait_hcre(adapter,toval))
 148 
 149 static int wait_hcre(elp_device * adapter, int toval)
     /* [previous][next][first][last][top][bottom][index][help] */
 150 
 151 {
 152   int timeout = jiffies + toval;
 153   while(((INB(adapter->io_addr+PORT_STATUS)&STATUS_HCRE)==0) &&
 154          (jiffies <= timeout))
 155     ;
 156   if (jiffies > timeout) {
 157     printk("elp0: timeout waiting for HCRE\n");
 158     return FALSE;
 159   }
 160   return TRUE;
 161 }
 162 
 163 /*****************************************************************
 164  *
 165  * send_pcb
 166  *   Send a PCB to the adapter. 
 167  *
 168  *      output byte to command reg  --<--+
 169  *      wait until HCRE is non zero      |
 170  *      loop until all bytes sent   -->--+
 171  *      set HSF1 and HSF2 to 1
 172  *      output pcb length
 173  *      wait until ASF give ACK or NAK
 174  *      set HSF1 and HSF2 to 0
 175  *
 176  *****************************************************************/
 177 
 178 static int send_pcb(elp_device * adapter, pcb_struct * pcb)
     /* [previous][next][first][last][top][bottom][index][help] */
 179 
 180 {
 181   int i;
 182   int cont;
 183   int retry = 0;
 184   int timeout;
 185 
 186   while (1) {
 187 
 188     cont = 1;
 189 
 190     /*
 191      * load each byte into the command register and
 192      * wait for the HCRE bit to indicate the adapter
 193      * had read the byte
 194      */
 195     SET_HSF(0); 
 196     OUTB(pcb->command, (adapter->io_addr)+PORT_COMMAND);
 197     cont = WAIT_HCRE(5);
 198    /* SET_HSF(0);  */
 199 
 200     if (cont) {
 201       OUTB(pcb->length, (adapter->io_addr)+PORT_COMMAND);
 202       cont = WAIT_HCRE(2);
 203     }
 204 
 205     for (i = 0; cont && (i < pcb->length); i++) {
 206       OUTB(pcb->data[i], (adapter->io_addr)+PORT_COMMAND);
 207       cont = WAIT_HCRE(2);
 208     }
 209 
 210     /* set the host status bits to indicate end of PCB */
 211     /* send the total packet length as well */
 212     /* wait for the adapter to indicate that it has read the PCB */
 213     if (cont) {
 214       SET_HSF(HSF_PCB_END);
 215       OUTB(2+pcb->length, adapter->io_addr+PORT_COMMAND);
 216       timeout = jiffies + 6;
 217       while (jiffies < timeout) {
 218         i = GET_ASF();
 219         if ((i == ASF_PCB_ACK) ||
 220             (i == ASF_PCB_NAK))
 221           break;
 222       }
 223       if (i == ASF_PCB_ACK) {
 224         SET_HSF(0); 
 225         return TRUE;
 226       } else if (i = ASF_PCB_NAK) {
 227         SET_HSF(0);
 228         printk("elp0: PCB send was NAKed\n");
 229         {
 230           int to = jiffies + 5;
 231           while (jiffies < to)
 232             ;
 233         }
 234       }
 235     }
 236 
 237     if (elp_debug >= 6)
 238       printk("elp0: NAK/timeout on send PCB\n");
 239     if ((retry++ & 7) == 0) 
 240       printk("elp0: retry #%i on send PCB\n", retry);
 241   }
 242 }
 243 
 244 /*****************************************************************
 245  *
 246  * receive_pcb
 247  *   Read a PCB to the adapter
 248  *
 249  *      wait for ACRF to be non-zero         ---<---+
 250  *      input a byte                                |
 251  *      if ASF1 and ASF2 were not both one          |
 252  *           before byte was read, loop      --->---+
 253  *      set HSF1 and HSF2 for ack
 254  *
 255  *****************************************************************/
 256 
 257 static int receive_pcb(elp_device * adapter, pcb_struct * pcb)
     /* [previous][next][first][last][top][bottom][index][help] */
 258 
 259 {
 260   int i;
 261   int total_length;
 262   int stat;
 263 
 264   /* get the command code */
 265   while (((stat = GET_STATUS())&STATUS_ACRF) == 0)
 266     ;
 267   SET_HSF(0); 
 268   pcb->command = INB(adapter->io_addr+PORT_COMMAND);
 269   if ((stat & ASF_PCB_MASK) != ASF_PCB_END) {
 270 
 271     /* read the data length */
 272     while (((stat = GET_STATUS())&STATUS_ACRF) == 0)
 273       ;
 274     pcb->length = INB(adapter->io_addr+PORT_COMMAND);
 275     if ((stat & ASF_PCB_MASK) != ASF_PCB_END) {
 276 
 277       /* read the data */
 278       i = 0;
 279       do {
 280         while (((stat = GET_STATUS())&STATUS_ACRF) == 0)
 281           ;
 282         pcb->data[i++] = INB(adapter->io_addr+PORT_COMMAND);
 283       } while ((stat & ASF_PCB_MASK) != ASF_PCB_END);
 284 
 285       /* woops, the last "data" byte was really the length! */
 286       total_length = pcb->data[--i];
 287 
 288       /* safety check total length vs data length */
 289       if (total_length != (pcb->length + 2)) {
 290         if (elp_debug >= 6)
 291           printk("elp0: mangled PCB received\n");
 292         SET_HSF(HSF_PCB_NAK);
 293         return FALSE;
 294       }
 295       SET_HSF(HSF_PCB_ACK);
 296       return TRUE;
 297     }
 298   }
 299 
 300   SET_HSF(HSF_PCB_NAK); 
 301   return FALSE;
 302 }
 303 
 304 static void adapter_hard_reset(elp_device * adapter)
     /* [previous][next][first][last][top][bottom][index][help] */
 305 
 306 {
 307   int timeout;
 308 
 309   /*
 310    * take FLSH and ATTN high
 311    */
 312   OUTB(CONTROL_ATTN|CONTROL_FLSH, adapter->io_addr+PORT_CONTROL); 
 313 
 314   /*
 315    * wait for a little bit
 316    */
 317   for (timeout = jiffies + 20; jiffies <= timeout; )
 318     ;
 319   
 320   /*
 321    * now take them low
 322    */
 323   OUTB(0, adapter->io_addr+PORT_CONTROL); 
 324 
 325   /*
 326    * wait for a little bit
 327    */
 328   for (timeout = jiffies + 20; jiffies <= timeout; )
 329     ;
 330   
 331   /*
 332    * now hang around until the board gets it's act together
 333    */
 334   for (timeout = jiffies + (100 * 15); jiffies <= timeout; ) 
 335     if (GET_ASF() != ASF_PCB_END)
 336       break;
 337 }
 338 
 339 static void adapter_reset(elp_device * adapter)
     /* [previous][next][first][last][top][bottom][index][help] */
 340 
 341 {
 342   int timeout;
 343 
 344   cli();
 345   OUTB(CONTROL_ATTN|INB(adapter->io_addr+PORT_CONTROL), adapter->io_addr+PORT_CONTROL);
 346   sti();
 347 
 348   /*
 349    * wait for a little bit
 350    */
 351   for (timeout = jiffies + 20; jiffies <= timeout; )
 352     ;
 353   
 354   cli();
 355   OUTB(INB(adapter->io_addr+PORT_CONTROL)&~(CONTROL_ATTN), adapter->io_addr+PORT_CONTROL);
 356   sti();
 357 }
 358 
 359 /******************************************************
 360  *
 361  *  queue a receive command on the adapter so we will get an
 362  *  interrupt when a packet is received.
 363  *
 364  ******************************************************/
 365 
 366 static int start_receive(elp_device * adapter, pcb_struct * tx_pcb)
     /* [previous][next][first][last][top][bottom][index][help] */
 367 
 368 {
 369   if (elp_debug > 3)
 370     printk("elp0: restarting receiver\n");
 371   tx_pcb->command = CMD_RECEIVE_PACKET;
 372   tx_pcb->length  = 8;
 373   tx_pcb->data[4] = 1600 & 0xff;
 374   tx_pcb->data[5] = 1600 >> 8;
 375   tx_pcb->data[6] = 0;          /* set timeout to zero */
 376   tx_pcb->data[7] = 0;
 377   return send_pcb(adapter, tx_pcb); 
 378 }
 379 
 380 /******************************************************
 381  *
 382  * extract a packet from the adapter
 383  * this routine is only called from within the interrupt
 384  * service routine, so no cli/sti calls are needed
 385  * note that the length is always assumed to be even
 386  *
 387  ******************************************************/
 388 
 389 static void receive_packet(struct device * dev,
     /* [previous][next][first][last][top][bottom][index][help] */
 390                               elp_device * adapter,
 391                                        int len)
 392 
 393 {
 394   register int i;
 395   unsigned short * ptr;
 396   short d;
 397 
 398   /*
 399    * allocate a buffer to put the packet into.
 400    */
 401   struct sk_buff *skb;
 402   skb = alloc_skb(len+3, GFP_ATOMIC);
 403 
 404   /*
 405    * make sure the data register is going the right way
 406    */
 407   OUTB(INB(adapter->io_addr+PORT_CONTROL)|CONTROL_DIR, adapter->io_addr+PORT_CONTROL); 
 408 
 409   /*
 410    * if buffer could not be allocated, swallow it
 411    */
 412   if (skb == NULL) {
 413     for (i = 0; i < (len/2); i++) {
 414       while ((INB(adapter->io_addr+PORT_STATUS)&STATUS_HRDY) == 0)
 415         ;
 416       d = inw(adapter->io_addr+PORT_DATA);
 417     }
 418     adapter->stats.rx_dropped++;
 419 
 420   } else {
 421 
 422     /*
 423      * now read the data from the adapter
 424      */
 425     ptr = (unsigned short *)(skb->data);
 426     for (i = 0; i < (len/2); i++) { 
 427       while ((INB(adapter->io_addr+PORT_STATUS)&STATUS_HRDY) == 0) {
 428         ;
 429       }
 430       *ptr = inw(adapter->io_addr+PORT_DATA); 
 431       ptr++; 
 432     }
 433 
 434     /*
 435      * the magic routine "dev_rint" passes the packet up the
 436      * protocol chain. If it returns 0, we can assume the packet was
 437      * swallowed up. If not, then we are responsible for freeing memory
 438      */
 439     if (dev_rint((unsigned char *)skb, len, IN_SKBUFF, dev) != 0) {
 440       printk("%s: receive buffers full.\n", dev->name);
 441       kfree_skb(skb, FREE_READ);
 442     }
 443   }
 444 
 445   OUTB(INB(adapter->io_addr+PORT_CONTROL)&(~CONTROL_DIR), adapter->io_addr+PORT_CONTROL); 
 446 }
 447 
 448 
 449 /******************************************************
 450  *
 451  * interrupt handler
 452  *
 453  ******************************************************/
 454 
 455 static void elp_interrupt(int reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 456 
 457 {
 458   int len;
 459   int dlen;
 460   int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
 461   struct device *dev;
 462   elp_device * adapter;
 463 
 464   if (irq < 0 || irq > 15) {
 465     printk ("elp0: illegal IRQ number found in interrupt routine (%i)\n", irq);
 466     return;
 467   }
 468 
 469   if (irq != 0xc) {
 470     printk ("elp0: warning - interrupt routine has incorrect IRQ of %i\n", irq);
 471     return;
 472   }
 473 
 474   dev = irq2dev_map[irq];
 475   adapter = (elp_device *) dev->priv;
 476 
 477   if (dev == NULL) {
 478     printk ("elp_interrupt(): irq %d for unknown device.\n", irq);
 479     return;
 480   }
 481 
 482   if (dev->interrupt)
 483     if (elp_debug >= 3)
 484       printk("%s: Re-entering the interrupt handler.\n", dev->name);
 485   dev->interrupt = 1;
 486 
 487   /*
 488    * allow interrupts (we need timers!)
 489    */
 490   sti();
 491 
 492   /*
 493    * receive a PCB from the adapter
 494    */
 495   while ((INB(adapter->io_addr+PORT_STATUS)&STATUS_ACRF) != 0) {
 496     
 497     if (receive_pcb(adapter, &adapter->irx_pcb)) {
 498 
 499       switch (adapter->irx_pcb.command) {
 500 
 501         /*
 502          * 82586 configured correctly
 503          */
 504         case CMD_CONFIGURE_82586_RESPONSE:
 505           adapter->got_configure = 1;
 506           if (elp_debug >= 3)
 507             printk("%s: interrupt - configure response received\n", dev->name);
 508           break;
 509 
 510         /*
 511          * received a packet
 512          */
 513         case CMD_RECEIVE_PACKET_COMPLETE:
 514           len  = adapter->irx_pcb.data[6] + (adapter->irx_pcb.data[7] << 8);
 515           dlen  = adapter->irx_pcb.data[4] + (adapter->irx_pcb.data[5] << 8);
 516           if (adapter->irx_pcb.data[8] != 0) {
 517             printk("%s: interrupt - packet not received correctly\n", dev->name);
 518           } else {
 519             if (elp_debug >= 3)
 520               printk("%s: interrupt - packet received of length %i (%i)\n", dev->name, len, dlen);
 521             receive_packet(dev, adapter, dlen);
 522             if (elp_debug >= 3)
 523               printk("%s: packet received\n", dev->name);
 524             adapter->stats.rx_packets++;
 525           }
 526           if (dev->start && !start_receive(adapter, &adapter->itx_pcb)) 
 527             if (elp_debug >= 2)
 528               printk("%s: interrupt - failed to send receive start PCB\n", dev->name);
 529           if (elp_debug >= 3)
 530             printk("%s: receive procedure complete\n", dev->name);
 531 
 532           break;
 533 
 534         /*
 535          * sent a packet
 536          */
 537         case CMD_TRANSMIT_PACKET_COMPLETE:
 538           if (elp_debug >= 3) 
 539             printk("%s: interrupt - packet sent\n", dev->name);
 540           if (adapter->irx_pcb.data[4] != 0)
 541             if (elp_debug >= 2)
 542               printk("%s: interrupt - error sending packet %4.4x\n", dev->name, 
 543                 adapter->irx_pcb.data[4] + (adapter->irx_pcb.data[5] << 8));
 544           dev->tbusy = 0;
 545           mark_bh(INET_BH);
 546           adapter->stats.tx_packets++;
 547           break;
 548 
 549         /*
 550          * some unknown PCB
 551          */
 552         default:
 553           printk("%s: unknown PCB received - %2.2x\n", dev->name, adapter->irx_pcb.command);
 554           break;
 555       }
 556     } else 
 557       printk("%s: failed to read PCB on interrupt\n", dev->name);
 558   }
 559 
 560   /*
 561    * indicate no longer in interrupt routine
 562    */
 563   dev->interrupt = 0;
 564 }
 565 
 566 
 567 /******************************************************
 568  *
 569  * open the board
 570  *
 571  ******************************************************/
 572 
 573 static int elp_open (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 574 
 575 {
 576   elp_device * adapter = (elp_device *) dev->priv;
 577 
 578   if (elp_debug >= 1)
 579     printk("%s: request to open device\n", dev->name);
 580 
 581   /*
 582    * make sure we actually found the device
 583    */
 584   if (adapter == NULL) {
 585     printk("%s: Opening a non-existent physical device\n", dev->name);
 586     return -EAGAIN;
 587   }
 588 
 589   /*
 590    * interrupt routine not entered
 591    */
 592   dev->interrupt = 0;
 593 
 594   /*
 595    *  transmitter not busy 
 596    */
 597   dev->tbusy = 0;
 598 
 599   /*
 600    * install our interrupt service routine
 601    */
 602   if (request_irq(dev->irq, &elp_interrupt))  
 603     return -EAGAIN;
 604 
 605   /*
 606    * make sure we can find the device header given the interrupt number
 607    */
 608   irq2dev_map[dev->irq] = dev;
 609 
 610   /*
 611    * enable interrupts on the board
 612    */
 613   OUTB(CONTROL_CMDE, adapter->io_addr+PORT_CONTROL);
 614 
 615   /*
 616    * device is now offically open!
 617    */
 618   dev->start = 1;
 619 
 620   /*
 621    * configure adapter to receive broadcast messages and wait for response
 622    */
 623   if (elp_debug >= 2)
 624     printk("%s: sending 82586 configure command\n", dev->name);
 625   adapter->tx_pcb.command = CMD_CONFIGURE_82586;
 626   adapter->tx_pcb.data[0] = 1;
 627   adapter->tx_pcb.data[1] = 0;
 628   adapter->tx_pcb.length  = 2;
 629   adapter->got_configure  = 0;
 630   if (!send_pcb(adapter, &adapter->tx_pcb))
 631     printk("%s: couldn't send 82586 configure command\n", dev->name);
 632   else
 633     while (adapter->got_configure == 0)
 634       ;
 635 
 636   /*
 637    * queue a receive command to start things rolling
 638    */
 639   if (!start_receive(adapter, &adapter->tx_pcb))
 640     printk("%s: start receive command failed \n", dev->name);
 641   if (elp_debug >= 2)
 642     printk("%s: start receive command sent\n", dev->name);
 643 
 644   return 0;                     /* Always succeed */
 645 }
 646 
 647 /******************************************************
 648  *
 649  * close the board
 650  *
 651  ******************************************************/
 652 
 653 static int elp_close (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 654 
 655 {
 656   elp_device * adapter = (elp_device *) dev->priv;
 657 
 658   if (elp_debug >= 1)
 659     printk("%s: request to close device\n", dev->name);
 660 
 661   /*
 662    * disable interrupts on the board
 663    */
 664   OUTB(0x00, adapter->io_addr+PORT_CONTROL);
 665 
 666   /*
 667    *  flag transmitter as busy (i.e. not available)
 668    */
 669   dev->tbusy = 1;
 670 
 671   /*
 672    *  indicate device is closed
 673    */
 674   dev->start = 0;
 675 
 676   /*
 677    * release the IRQ
 678    */
 679   free_irq(dev->irq);
 680 
 681   /*
 682    * and we no longer have to map irq to dev either
 683    */
 684   irq2dev_map[dev->irq] = 0;
 685 
 686   return 0;
 687 }
 688 
 689 
 690 /******************************************************
 691  *
 692  * send a packet to the adapter
 693  *
 694  ******************************************************/
 695 
 696 static int send_packet (elp_device * adapter, unsigned char * ptr, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 697 
 698 {
 699   int i;
 700 
 701   /*
 702    * make sure the length is even and no shorter than 60 bytes
 703    */
 704   unsigned int nlen = (((len < 60) ? 60 : len) + 1) & (~1);
 705 
 706   /*
 707    * send the adapter a transmit packet command. Ignore segment and offset
 708    * and make sure the length is even
 709    */
 710   adapter->tx_pcb.command = CMD_TRANSMIT_PACKET;
 711   adapter->tx_pcb.length  = 6;
 712   adapter->tx_pcb.data[4] = nlen & 0xff;
 713   adapter->tx_pcb.data[5] = nlen >> 8;
 714   if (!send_pcb(adapter, &adapter->tx_pcb)) 
 715     return FALSE;
 716 
 717   /*
 718    * make sure the data register is going the right way
 719    */
 720   cli(); 
 721   OUTB(INB(adapter->io_addr+PORT_CONTROL)&(~CONTROL_DIR), adapter->io_addr+PORT_CONTROL); 
 722   sti(); 
 723 
 724   /*
 725    * write data to the adapter
 726    */
 727   for (i = 0; i < (nlen/2);i++) {
 728     while ((INB(adapter->io_addr+PORT_STATUS)&STATUS_HRDY) == 0)
 729       ;
 730     outw(*(short *)ptr, adapter->io_addr+PORT_DATA);
 731     ptr +=2;
 732   }
 733   
 734   return TRUE;
 735 }
 736 
 737 /******************************************************
 738  *
 739  * start the transmitter
 740  *    return 0 if sent OK, else return 1
 741  *
 742  ******************************************************/
 743 
 744 static int elp_start_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 745 
 746 {
 747   elp_device * adapter = (elp_device *) dev->priv;
 748 
 749   /*
 750    * not sure what this does, but the 3c609 driver does it, so...
 751    */
 752   if (skb == NULL) {
 753     dev_tint(dev);
 754     return 0;
 755   }
 756 
 757   /*
 758    * if we ended up with a munged length, don't send it
 759    */
 760   if (skb->len <= 0)
 761     return 0;
 762 
 763   if (elp_debug >= 1)
 764     printk("%s: request to send packet of length %i\n", dev->name, skb->len);
 765 
 766   /*
 767    * if the transmitter is still busy, we have a transmit timeout...
 768    */
 769   if (dev->tbusy) {
 770     int tickssofar = jiffies - dev->trans_start;
 771     if (tickssofar < 500)
 772       return 1;
 773     printk("%s: transmit timed out, resetting adapter\n", dev->name);
 774     if ((INB(adapter->io_addr+PORT_STATUS)&STATUS_ACRF) != 0) 
 775       printk("%s: hmmm...seemed to have missed an interrupt!\n", dev->name);
 776     adapter_reset(adapter);
 777     dev->trans_start = jiffies;
 778     dev->tbusy = 0;
 779   }
 780 
 781   /*
 782    * send the packet at (void *)(skb+1) for skb->len
 783    */
 784   if (!send_packet(adapter, (unsigned char *)(skb->data), skb->len)) {
 785     printk("%s: send packet PCB failed\n", dev->name);
 786     return 1;
 787   }
 788 
 789   if (elp_debug >= 2)
 790     printk("%s: packet of length %i sent\n", dev->name, skb->len);
 791 
 792 
 793   /*
 794    * start the transmit timeout
 795    */
 796   dev->trans_start = jiffies;
 797 
 798   /*
 799    * the transmitter is now busy
 800    */
 801   dev->tbusy = 1;
 802 
 803   /*
 804    * if we have been asked to free the buffer, do so
 805    */
 806   dev_kfree_skb(skb, FREE_WRITE);
 807 
 808   return 0;
 809 }
 810 
 811 /******************************************************
 812  *
 813  * return statistics on the board
 814  *
 815  ******************************************************/
 816 
 817 static struct enet_statistics * elp_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 818 
 819 {
 820   if (elp_debug >= 1)
 821     printk("%s: request for stats\n", dev->name);
 822 
 823   elp_device * adapter = (elp_device *) dev->priv;
 824   return &adapter->stats;
 825 }
 826 
 827 /******************************************************
 828  *
 829  * initialise Etherlink Pus board
 830  *
 831  ******************************************************/
 832 
 833 static void elp_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 834 
 835 {
 836   int i;
 837   elp_device * adapter;
 838 
 839   /*
 840    * NULL out buffer pointers
 841    */
 842   for (i = 0; i < DEV_NUMBUFFS; i++)
 843     dev->buffs[i] = NULL;
 844 
 845   /*
 846    * set ptrs to various functions
 847    */
 848   dev->open             = elp_open;             /* local */
 849   dev->stop             = elp_close;            /* local */
 850   dev->get_stats        = elp_get_stats;        /* local */
 851   dev->hard_start_xmit  = elp_start_xmit;       /* local */
 852 
 853   dev->hard_header      = eth_header;           /* eth.c */
 854   dev->add_arp          = eth_add_arp;          /* eth.c */
 855   dev->rebuild_header   = eth_rebuild_header;   /* eth.c */
 856   dev->type_trans       = eth_type_trans;       /* eth.c */
 857 
 858   dev->queue_xmit       = dev_queue_xmit;       /* dev.c */
 859 
 860   /*
 861    * setup ptr to adapter specific information
 862    */
 863   adapter = (elp_device *)(dev->priv = kmalloc(sizeof(elp_device), GFP_KERNEL));
 864   adapter->io_addr = dev->base_addr;
 865   memset(&(adapter->stats), 0, sizeof(struct enet_statistics));
 866 
 867 
 868   /*
 869    * Ethernet information
 870    */
 871   dev->type             = ARPHRD_ETHER;
 872   dev->hard_header_len  = ETH_HLEN;
 873   dev->mtu              = 1500;         /* eth_mtu */
 874   dev->addr_len         = ETH_ALEN;
 875   for (i = 0; i < dev->addr_len; i++) 
 876     dev->broadcast[i] = 0xff;
 877 
 878   /*
 879    * New-style flags. 
 880    */
 881   dev->flags            = IFF_BROADCAST;
 882   dev->family           = AF_INET;
 883   dev->pa_addr          = 0;
 884   dev->pa_brdaddr       = 0;
 885   dev->pa_mask          = 0;
 886   dev->pa_alen          = sizeof(unsigned long);
 887 
 888   /*
 889    * memory information
 890    */
 891   dev->mem_start = dev->mem_end = dev->rmem_end = dev->mem_start = 0;
 892 }
 893 
 894 
 895 /******************************************************
 896  *
 897  * probe for an Etherlink Plus board at the specified address
 898  * by attempting to get the ethernet address. 
 899  *
 900  ******************************************************/
 901 
 902 int elp_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 903 
 904 {
 905   elp_device adapter;
 906   int            i;
 907 
 908   /*
 909    *  setup adapter structure
 910    */
 911   adapter.io_addr = dev->base_addr;
 912 
 913   printk ("%s: probing for 3c505...", dev->name);
 914 
 915   /*
 916    * get the adapter's undivided attention (if it's there!)
 917    */
 918   adapter_hard_reset(&adapter); 
 919 
 920   /*
 921    * use ethernet address command to probe for board in polled mode
 922    */
 923   adapter.tx_pcb.command = CMD_STATION_ADDRESS;
 924   adapter.tx_pcb.length  = 0;
 925   if (!send_pcb   (&adapter, &adapter.tx_pcb) ||
 926       !receive_pcb(&adapter, &adapter.rx_pcb) ||
 927       (adapter.rx_pcb.command != CMD_ADDRESS_RESPONSE) ||
 928       (adapter.rx_pcb.length != 6)) {
 929     printk("not found\n");
 930     return -ENODEV;
 931   }
 932 
 933   for (i = 0; i < 6; i++) 
 934     dev->dev_addr[i] = adapter.rx_pcb.data[i];
 935 
 936   printk("found at port 0x%x, address = %s\n", dev->base_addr, eth_print(dev->dev_addr));
 937   
 938   elp_init(dev);
 939   return 0;
 940 }
 941 

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