root/drivers/net/d_link.c

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

DEFINITIONS

This source file includes following definitions.
  1. d_link_read_status
  2. d_link_read_byte
  3. d_link_open
  4. d_link_close
  5. get_stats
  6. trigger_interrupt
  7. d_link_start_xmit
  8. d_link_interrupt
  9. d_link_tx_intr
  10. d_link_rx_intr
  11. d_link_init
  12. adapter_init
  13. d_link_rspace

   1 static char *version =
   2         "d_link.c: $Revision: 0.32 $,  Bjorn Ekwall (bj0rn@blox.se)\n";
   3 /*
   4  *      d_link.c
   5  *
   6  *      Linux driver for the D-Link DE-600 Ethernet pocket adapter.
   7  *
   8  *      Portions (C) Copyright 1993 by Bjorn Ekwall
   9  *      The Author may be reached as bj0rn@blox.se
  10  *
  11  *      Based on adapter information gathered from DE600.ASM by D-Link Inc.,
  12  *      as included on disk C in the v.2.11 of PC/TCP from FTP Software.
  13  *      For DE600.asm:
  14  *              Portions (C) Copyright 1990 D-Link, Inc.
  15  *              Copyright, 1988-1992, Russell Nelson, Crynwr Software
  16  *
  17  *      Adapted to the sample network driver core for linux,
  18  *      written by: Donald Becker <becker@super.org>
  19  *      C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715
  20  *
  21  *      compile-command:
  22  *      "gcc -D__KERNEL__  -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer \
  23  *       -m486 -DD_LINK_IO=0x378 -DD_LINK_IRQ=7 -UD_LINK_DEBUG -S d_link.c
  24  *
  25  **************************************************************/
  26 /*
  27  *      This program is free software; you can redistribute it and/or modify
  28  *      it under the terms of the GNU General Public License as published by
  29  *      the Free Software Foundation; either version 2, or (at your option)
  30  *      any later version.
  31  *
  32  *      This program is distributed in the hope that it will be useful,
  33  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  34  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  35  *      GNU General Public License for more details.
  36  *
  37  *      You should have received a copy of the GNU General Public License
  38  *      along with this program; if not, write to the Free Software
  39  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
  40  *
  41  **************************************************************/
  42 /* Add another "; SLOW_DOWN_IO" here if your adapter won't work OK: */
  43 #define D_LINK_SLOW_DOWN SLOW_DOWN_IO; SLOW_DOWN_IO; SLOW_DOWN_IO
  44 
  45  /*
  46  * If you still have trouble reading/writing to the adapter,
  47  * modify the following "#define": (see <asm/io.h> for more info)
  48 #define REALLY_SLOW_IO
  49  */
  50 #define SLOW_IO_BY_JUMPING /* Looks "better" than dummy write to port 0x80 :-) */
  51 
  52 /*
  53  * For fix to TCP "slowdown", take a look at the "#define D_LINK_MAX_WINDOW"
  54  * near the end of the file...
  55  */
  56 
  57 /* use 0 for production, 1 for verification, >2 for debug */
  58 #ifdef D_LINK_DEBUG
  59 #define PRINTK(x) if (d_link_debug >= 2) printk x
  60 #else
  61 #define D_LINK_DEBUG 0
  62 #define PRINTK(x) /**/
  63 #endif
  64 static unsigned int d_link_debug = D_LINK_DEBUG;
  65 
  66 #include <linux/config.h>
  67 #include <linux/kernel.h>
  68 #include <linux/sched.h>
  69 #include <linux/types.h>
  70 #include <linux/fcntl.h>
  71 #include <linux/string.h>
  72 #include <linux/interrupt.h>
  73 #include <asm/io.h>
  74 #include <netinet/in.h>
  75 #include <linux/ptrace.h>
  76 #include <asm/system.h>
  77 #include <errno.h>
  78 
  79 #include "inet.h"
  80 #include "dev.h"
  81 #include "eth.h"
  82 #include "ip.h"
  83 #include "route.h"
  84 #include "protocol.h"
  85 #include "tcp.h"
  86 #include "skbuff.h"
  87 #include "sock.h"
  88 #include "arp.h"
  89 
  90 #define netstats enet_statistics
  91 
  92 #ifndef HAVE_ALLOC_SKB
  93 #define alloc_skb(size,pri)     (struct sk_buff *)kmalloc(size,pri)
  94 #endif
  95 
  96 /**************************************************
  97  *                                                *
  98  * Definition of D-Link Ethernet Pocket adapter   *
  99  *                                                *
 100  **************************************************/
 101 /*
 102  * D-Link Ethernet pocket adapter ports
 103  */
 104 /*
 105  * OK, so I'm cheating, but there are an awful lot of
 106  * reads and writes in order to get anything in and out
 107  * of the DE-600 with 4 bits at a time in the parallel port,
 108  * so every saved instruction really helps :-)
 109  *
 110  * That is, I don't care what the device struct says
 111  * but hope that Space.c will keep the rest of the drivers happy.
 112  */
 113 #ifndef D_LINK_IO
 114 #define D_LINK_IO 0x378
 115 #endif
 116 
 117 #define DATA_PORT       (D_LINK_IO)
 118 #define STATUS_PORT     (D_LINK_IO + 1)
 119 #define COMMAND_PORT    (D_LINK_IO + 2)
 120 
 121 #ifndef D_LINK_IRQ
 122 #define D_LINK_IRQ      7
 123 #endif
 124 /*
 125  * It really should look like this, and autoprobing as well...
 126  *
 127 #define DATA_PORT       (dev->base_addr + 0)
 128 #define STATUS_PORT     (dev->base_addr + 1)
 129 #define COMMAND_PORT    (dev->base_addr + 2)
 130 #define D_LINK_IRQ      dev->irq
 131  */
 132 
 133 /*
 134  * D-Link COMMAND_PORT commands
 135  */
 136 #define SELECT_NIC      0x04 /* select Network Interface Card */
 137 #define SELECT_PRN      0x1c /* select Printer */
 138 #define NML_PRN         0xec /* normal Printer situation */
 139 #define IRQEN           0x10 /* enable IRQ line */
 140 
 141 /*
 142  * D-Link STATUS_PORT
 143  */
 144 #define RX_BUSY         0x80
 145 #define RX_GOOD         0x40
 146 #define TX_FAILED16     0x10
 147 #define TX_BUSY         0x08
 148 
 149 /*
 150  * D-Link DATA_PORT commands
 151  * command in low 4 bits
 152  * data in high 4 bits
 153  * select current data nibble with HI_NIBBLE bit
 154  */
 155 #define WRITE_DATA      0x00 /* write memory */
 156 #define READ_DATA       0x01 /* read memory */
 157 #define STATUS          0x02 /* read  status register */
 158 #define COMMAND         0x03 /* write command register (see COMMAND below) */
 159 #define NULL_COMMAND    0x04 /* null command */
 160 #define RX_LEN          0x05 /* read  received packet length */
 161 #define TX_ADDR         0x06 /* set adapter transmit memory address */
 162 #define RW_ADDR         0x07 /* set adapter read/write memory address */
 163 #define HI_NIBBLE       0x08 /* read/write the high nibble of data,
 164                                 or-ed with rest of command */
 165 
 166 /*
 167  * command register, accessed through DATA_PORT with low bits = COMMAND
 168  */
 169 #define RX_ALL          0x01 /* PROMISCIOUS */
 170 #define RX_BP           0x02 /* default: BROADCAST & PHYSICAL ADRESS */
 171 #define RX_MBP          0x03 /* MULTICAST, BROADCAST & PHYSICAL ADRESS */
 172 
 173 #define TX_ENABLE       0x04 /* bit 2 */
 174 #define RX_ENABLE       0x08 /* bit 3 */
 175 
 176 #define RESET           0x80 /* set bit 7 high */
 177 #define STOP_RESET      0x00 /* set bit 7 low */
 178 
 179 /*
 180  * data to command register
 181  * (high 4 bits in write to DATA_PORT)
 182  */
 183 #define RX_PAGE2_SELECT 0x10 /* bit 4, only 2 pages to select */
 184 #define RX_BASE_PAGE    0x20 /* bit 5, always set when specifying RX_ADDR */
 185 #define FLIP_IRQ        0x40 /* bit 6 */
 186 
 187 /*
 188  * D-Link adapter internal memory:
 189  *
 190  * 0-2K 1:st transmit page (send from pointer up to 2K)
 191  * 2-4K 2:nd transmit page (send from pointer up to 4K)
 192  *
 193  * 4-6K 1:st receive page (data from 4K upwards)
 194  * 6-8K 2:nd receive page (data from 6K upwards)
 195  *
 196  * 8K+  Adapter ROM (contains magic code and last 3 bytes of Ethernet address)
 197  */
 198 #define MEM_2K          0x0800 /* 2048 */
 199 #define MEM_4K          0x1000 /* 4096 */
 200 #define MEM_6K          0x1800 /* 6144 */
 201 #define NODE_ADDRESS    0x2000 /* 8192 */
 202 
 203 #define RUNT 60         /* Too small Ethernet packet */
 204 
 205 /**************************************************
 206  *                                                *
 207  *             End of definition                  *
 208  *                                                *
 209  **************************************************/
 210 
 211 /*
 212  * Index to functions, as function prototypes.
 213  */
 214 
 215 /* For tricking tcp.c to announce a small max window (max 2 fast packets please :-) */
 216 static unsigned long    d_link_rspace(struct sock *sk);
 217 
 218 /* Routines used internally. (See "convenience macros") */
 219 static int              d_link_read_status(struct device *dev);
 220 static unsigned char    d_link_read_byte(unsigned char type, struct device *dev);
 221 
 222 /* Put in the device structure. */
 223 static int      d_link_open(struct device *dev);
 224 static int      d_link_close(struct device *dev);
 225 static struct netstats *get_stats(struct device *dev);
 226 static int      d_link_start_xmit(struct sk_buff *skb, struct device *dev);
 227 
 228 /* Dispatch from interrupts. */
 229 static void     d_link_interrupt(int reg_ptr);
 230 static int      d_link_tx_intr(struct device *dev, int irq_status);
 231 static void     d_link_rx_intr(struct device *dev);
 232 
 233 /* Initialization */
 234 static void     trigger_interrupt(struct device *dev);
 235 int             d_link_init(struct device *dev);
 236 static void     adapter_init(struct device *dev);
 237 
 238 /*
 239  * D-Link driver variables:
 240  */
 241 extern struct device            *irq2dev_map[16];
 242 static volatile int             rx_page         = 0;
 243 
 244 #define TX_PAGES 2
 245 static volatile int             tx_fifo[TX_PAGES];
 246 static volatile int             tx_fifo_in = 0;
 247 static volatile int             tx_fifo_out = 0;
 248 static volatile int             free_tx_pages = TX_PAGES;
 249 
 250 /*
 251  * Convenience macros/functions for D-Link adapter
 252  */
 253 
 254 #define select_prn() outb_p(SELECT_PRN, COMMAND_PORT); D_LINK_SLOW_DOWN
 255 #define select_nic() outb_p(SELECT_NIC, COMMAND_PORT); D_LINK_SLOW_DOWN
 256 
 257 /* Thanks for hints from Mark Burton <markb@ordern.demon.co.uk> */
 258 #define d_link_put_byte(data) ( \
 259         outb_p(((data) << 4)   | WRITE_DATA            , DATA_PORT), \
 260         outb_p(((data) & 0xf0) | WRITE_DATA | HI_NIBBLE, DATA_PORT))
 261 
 262 /*
 263  * The first two outb_p()'s below could perhaps be deleted if there
 264  * would be more delay in the last two. Not certain about it yet...
 265  */
 266 #define d_link_put_command(cmd) ( \
 267         outb_p(( rx_page        << 4)   | COMMAND            , DATA_PORT), \
 268         outb_p(( rx_page        & 0xf0) | COMMAND | HI_NIBBLE, DATA_PORT), \
 269         outb_p(((rx_page | cmd) << 4)   | COMMAND            , DATA_PORT), \
 270         outb_p(((rx_page | cmd) & 0xf0) | COMMAND | HI_NIBBLE, DATA_PORT))
 271 
 272 #define d_link_setup_address(addr,type) ( \
 273         outb_p((((addr) << 4) & 0xf0) | type            , DATA_PORT), \
 274         outb_p(( (addr)       & 0xf0) | type | HI_NIBBLE, DATA_PORT), \
 275         outb_p((((addr) >> 4) & 0xf0) | type            , DATA_PORT), \
 276         outb_p((((addr) >> 8) & 0xf0) | type | HI_NIBBLE, DATA_PORT))
 277 
 278 #define rx_page_adr() ((rx_page & RX_PAGE2_SELECT)?(MEM_6K):(MEM_4K))
 279 
 280 /* Flip bit, only 2 pages */
 281 #define next_rx_page() (rx_page ^= RX_PAGE2_SELECT)
 282 
 283 #define tx_page_adr(a) (((a) + 1) * MEM_2K)
 284 
 285 static inline int
 286 d_link_read_status(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 287 {
 288         int     status;
 289 
 290         outb_p(STATUS, DATA_PORT);
 291         status = inb(STATUS_PORT);
 292         outb_p(NULL_COMMAND | HI_NIBBLE, DATA_PORT);
 293 
 294         return status;
 295 }
 296 
 297 static inline unsigned char
 298 d_link_read_byte(unsigned char type, struct device *dev) { /* dev used by macros */
     /* [previous][next][first][last][top][bottom][index][help] */
 299         unsigned char   lo;
 300 
 301         (void)outb_p((type), DATA_PORT);
 302         lo = ((unsigned char)inb(STATUS_PORT)) >> 4;
 303         (void)outb_p((type) | HI_NIBBLE, DATA_PORT);
 304         return ((unsigned char)inb(STATUS_PORT) & (unsigned char)0xf0) | lo;
 305 }
 306 
 307 /*
 308  * Open/initialize the board.  This is called (in the current kernel)
 309  * after booting when 'ifconfig <dev->name> $IP_ADDR' is run (in rc.inet1).
 310  *
 311  * This routine should set everything up anew at each open, even
 312  * registers that "should" only need to be set once at boot, so that
 313  * there is a non-reboot way to recover if something goes wrong.
 314  */
 315 static int
 316 d_link_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 317 {
 318         extern struct proto tcp_prot;
 319 
 320         if (request_irq(D_LINK_IRQ, d_link_interrupt)) {
 321                 printk ("%s: unable to get IRQ %d\n", dev->name, D_LINK_IRQ);
 322                 return 1;
 323         }
 324         irq2dev_map[D_LINK_IRQ] = dev;
 325 
 326         adapter_init(dev);
 327 
 328         /*
 329          * Yes, I know!
 330          * This is really not nice, but since a machine that uses DE-600
 331          * rarely uses any other TCP/IP connection device simultaneously,
 332          * this hack shouldn't really slow anything up.
 333          * (I don't know about slip though... but it won't break it)
 334          *
 335          * This fix is better than changing in tcp.h IMHO
 336          */
 337         tcp_prot.rspace = d_link_rspace; /* was: sock_rspace */
 338 
 339         return 0;
 340 }
 341 
 342 /*
 343  * The inverse routine to d_link_open().
 344  */
 345 static int
 346 d_link_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 347 {
 348         select_nic();
 349         rx_page = 0;
 350         d_link_put_command(RESET);
 351         d_link_put_command(STOP_RESET);
 352         d_link_put_command(0);
 353         select_prn();
 354 
 355         free_irq(D_LINK_IRQ);
 356         irq2dev_map[D_LINK_IRQ] = NULL;
 357         dev->start = 0;
 358         tcp_prot.rspace = sock_rspace; /* see comment above! */
 359 
 360         return 0;
 361 }
 362 
 363 static struct netstats *
 364 get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 365 {
 366     return (struct netstats *)(dev->priv);
 367 }
 368 
 369 static inline void
 370 trigger_interrupt(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 371 {
 372         d_link_put_command(FLIP_IRQ);
 373         select_prn();
 374         D_LINK_SLOW_DOWN;
 375         select_nic();
 376         d_link_put_command(0);
 377 }
 378 
 379 /*
 380  * Copy a buffer to the adapter transmit page memory.
 381  * Start sending.
 382  */
 383 static int
 384 d_link_start_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 385 {
 386         int             transmit_from;
 387         int             len;
 388         int             tickssofar;
 389         unsigned char   *buffer = (unsigned char *)(skb + 1);
 390 
 391         /*
 392          * If some higher layer thinks we've missed a
 393          * tx-done interrupt we are passed NULL.
 394          * Caution: dev_tint() handles the cli()/sti() itself.
 395          */
 396 
 397         if (skb == NULL) {
 398                 dev_tint(dev);
 399                 return 0;
 400         }
 401 
 402         /* For ethernet, fill in the header (hardware addresses) with an arp. */
 403         if (!skb->arp)
 404                 if(dev->rebuild_header(skb + 1, dev)) {
 405                         skb->dev = dev;
 406                         arp_queue (skb);
 407                         return 0;
 408                 }
 409         skb->arp = 1;
 410 
 411         if (free_tx_pages <= 0) {       /* Do timeouts, to avoid hangs. */
 412                 tickssofar = jiffies - dev->trans_start;
 413 
 414                 if (tickssofar < 5)
 415                         return 1;
 416 
 417                 /* else */
 418                 printk("%s: transmit timed out (%d), %s?\n",
 419                         dev->name,
 420                         tickssofar,
 421                         "network cable problem"
 422                         );
 423                 /* Restart the adapter. */
 424                 adapter_init(dev);
 425         }
 426 
 427         /* Start real output */
 428         PRINTK(("d_link_start_xmit:len=%d, page %d/%d\n", skb->len, tx_fifo_in, free_tx_pages));
 429 
 430         if ((len = skb->len) < RUNT)
 431                 len = RUNT;
 432 
 433         cli();
 434         select_nic();
 435 
 436         tx_fifo[tx_fifo_in] = transmit_from = tx_page_adr(tx_fifo_in) - len;
 437         tx_fifo_in = (tx_fifo_in + 1) % TX_PAGES; /* Next free tx page */
 438 
 439         d_link_setup_address(transmit_from, RW_ADDR);
 440         for ( ; len > 0; --len, ++buffer)
 441                 d_link_put_byte(*buffer);
 442 
 443         if (free_tx_pages-- == TX_PAGES) { /* No transmission going on */
 444                 dev->trans_start = jiffies;
 445                 dev->tbusy = 0; /* allow more packets into adapter */
 446                 /* Send page and generate an interrupt */
 447                 d_link_setup_address(transmit_from, TX_ADDR);
 448                 d_link_put_command(TX_ENABLE);
 449         }
 450         else {
 451                 dev->tbusy = !free_tx_pages;
 452                 select_prn();
 453         }
 454         
 455         sti(); /* interrupts back on */
 456         
 457         if (skb->free)
 458                 kfree_skb (skb, FREE_WRITE);
 459 
 460         return 0;
 461 }
 462 
 463 /*
 464  * The typical workload of the driver:
 465  * Handle the network interface interrupts.
 466  */
 467 static void
 468 d_link_interrupt(int reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 469 {
 470         int             irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
 471         struct device   *dev = irq2dev_map[irq];
 472         unsigned char   irq_status;
 473         int             retrig = 0;
 474         int             boguscount = 0;
 475 
 476         /* This might just as well be deleted now, no crummy drivers present :-) */
 477         if ((dev == NULL) || (dev->start == 0) || (D_LINK_IRQ != irq)) {
 478                 printk("%s: bogus interrupt %d\n", dev?dev->name:"DE-600", irq);
 479                 return;
 480         }
 481 
 482         dev->interrupt = 1;
 483         select_nic();
 484         irq_status = d_link_read_status(dev);
 485 
 486         do {
 487                 PRINTK(("d_link_interrupt (%2.2X)\n", irq_status));
 488 
 489                 if (irq_status & RX_GOOD)
 490                         d_link_rx_intr(dev);
 491                 else if (!(irq_status & RX_BUSY))
 492                         d_link_put_command(RX_ENABLE);
 493 
 494                 /* Any transmission in progress? */
 495                 if (free_tx_pages < TX_PAGES)
 496                         retrig = d_link_tx_intr(dev, irq_status);
 497                 else
 498                         retrig = 0;
 499 
 500                 irq_status = d_link_read_status(dev);
 501         } while ( (irq_status & RX_GOOD) || ((++boguscount < 10) && retrig) );
 502         /*
 503          * Yeah, it _looks_ like busy waiting, smells like busy waiting
 504          * and I know it's not PC, but please, it will only occur once
 505          * in a while and then only for a loop or so (< 1ms for sure!)
 506          */
 507 
 508         /* Enable adapter interrupts */
 509         dev->interrupt = 0;
 510         select_prn();
 511 
 512         if (retrig)
 513                 trigger_interrupt(dev);
 514 
 515         sti();
 516         return;
 517 }
 518 
 519 static int
 520 d_link_tx_intr(struct device *dev, int irq_status)
     /* [previous][next][first][last][top][bottom][index][help] */
 521 {
 522         /*
 523          * Returns 1 if tx still not done
 524          */
 525 
 526         mark_bh(INET_BH);
 527         /* Check if current transmission is done yet */
 528         if (irq_status & TX_BUSY)
 529                 return 1; /* tx not done, try again */
 530 
 531         /* else */
 532         /* If last transmission OK then bump fifo index */
 533         if (!(irq_status & TX_FAILED16)) {
 534                 tx_fifo_out = (tx_fifo_out + 1) % TX_PAGES;
 535                 ++free_tx_pages;
 536                 ((struct netstats *)(dev->priv))->tx_packets++;
 537                 dev->tbusy = 0;
 538         }
 539 
 540         /* More to send, or resend last packet? */
 541         if ((free_tx_pages < TX_PAGES) || (irq_status & TX_FAILED16)) {
 542                 dev->trans_start = jiffies;
 543                 d_link_setup_address(tx_fifo[tx_fifo_out], TX_ADDR);
 544                 d_link_put_command(TX_ENABLE);
 545                 return 1;
 546         }
 547         /* else */
 548 
 549         return 0;
 550 }
 551 
 552 /*
 553  * We have a good packet, get it out of the adapter.
 554  */
 555 static void
 556 d_link_rx_intr(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 557 {
 558         struct sk_buff  *skb;
 559         int             i;
 560         int             read_from;
 561         int             size;
 562         int             sksize;
 563         register unsigned char  *buffer;
 564 
 565         cli();
 566         /* Get size of received packet */
 567         size = d_link_read_byte(RX_LEN, dev);   /* low byte */
 568         size += (d_link_read_byte(RX_LEN, dev) << 8);   /* high byte */
 569         size -= 4;      /* Ignore trailing 4 CRC-bytes */
 570 
 571         /* Tell adapter where to store next incoming packet, enable receiver */
 572         read_from = rx_page_adr();
 573         next_rx_page();
 574         d_link_put_command(RX_ENABLE);
 575         sti();
 576 
 577         if ((size < 32)  ||  (size > 1535))
 578                 printk("%s: Bogus packet size %d.\n", dev->name, size);
 579 
 580         sksize = sizeof(struct sk_buff) + size;
 581         skb = alloc_skb(sksize, GFP_ATOMIC);
 582         sti();
 583         if (skb == NULL) {
 584                 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
 585                         dev->name, sksize);
 586                 return;
 587         }
 588         /* else */
 589 
 590         skb->lock = 0;
 591         skb->mem_len = sksize;
 592         skb->mem_addr = skb;
 593         /* 'skb + 1' points to the start of sk_buff data area. */
 594         buffer = (unsigned char *)(skb + 1);
 595 
 596         /* copy the packet into the buffer */
 597         d_link_setup_address(read_from, RW_ADDR);
 598         for (i = size; i > 0; --i, ++buffer)
 599                 *buffer = d_link_read_byte(READ_DATA, dev);
 600         
 601         ((struct netstats *)(dev->priv))->rx_packets++; /* count all receives */
 602 
 603         if (dev_rint((unsigned char *)skb, size, IN_SKBUFF, dev))
 604                 printk("%s: receive buffers full.\n", dev->name);
 605         /*
 606          * If any worth-while packets have been received, dev_rint()
 607          * has done a mark_bh(INET_BH) for us and will work on them
 608          * when we get to the bottom-half routine.
 609          */
 610 }
 611 
 612 int
 613 d_link_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 614 {
 615         int     i;
 616 
 617         printk("%s: D-Link DE-600 pocket adapter", dev->name);
 618         /* Alpha testers must have the version number to report bugs. */
 619         if (d_link_debug > 1)
 620                 printk(version);
 621 
 622         /* probe for adapter */
 623         rx_page = 0;
 624         select_nic();
 625         (void)d_link_read_status(dev);
 626         d_link_put_command(RESET);
 627         d_link_put_command(STOP_RESET);
 628         if (d_link_read_status(dev) & 0xf0) {
 629                 printk(": not at I/O %#3x.\n", DATA_PORT);
 630                 return ENODEV;
 631         }
 632 
 633         /*
 634          * Maybe we found one,
 635          * have to check if it is a D-Link DE-600 adapter...
 636          */
 637 
 638         /* Get the adapter ethernet address from the ROM */
 639         d_link_setup_address(NODE_ADDRESS, RW_ADDR);
 640         for (i = 0; i < ETH_ALEN; i++) {
 641                 dev->dev_addr[i] = d_link_read_byte(READ_DATA, dev);
 642                 dev->broadcast[i] = 0xff;
 643         }
 644 
 645         /* Check magic code */
 646         if ((dev->dev_addr[1] == 0xde) && (dev->dev_addr[2] == 0x15)) {
 647                 /* OK, install real address */
 648                 dev->dev_addr[0] = 0x00;
 649                 dev->dev_addr[1] = 0x80;
 650                 dev->dev_addr[2] = 0xc8;
 651                 dev->dev_addr[3] &= 0x0f;
 652                 dev->dev_addr[3] |= 0x70;
 653         } else {
 654                 printk(" not identified in the printer port\n");
 655                 return ENODEV;
 656         }
 657 
 658         printk(", Ethernet Address: %2.2X", dev->dev_addr[0]);
 659         for (i = 1; i < ETH_ALEN; i++)
 660                 printk(":%2.2X",dev->dev_addr[i]);
 661         printk("\n");
 662 
 663         /* Initialize the device structure. */
 664         dev->priv = kmalloc(sizeof(struct netstats), GFP_KERNEL);
 665         memset(dev->priv, 0, sizeof(struct netstats));
 666 
 667         for (i = 0; i < DEV_NUMBUFFS; i++)
 668                 dev->buffs[i] = NULL;
 669 
 670         dev->get_stats = get_stats;
 671         dev->hard_header = eth_header;
 672         dev->add_arp = eth_add_arp;
 673         dev->queue_xmit = dev_queue_xmit;
 674         dev->rebuild_header = eth_rebuild_header;
 675         dev->type_trans = eth_type_trans;
 676 
 677         dev->open = d_link_open;
 678         dev->stop = d_link_close;
 679         dev->hard_start_xmit = &d_link_start_xmit;
 680 
 681         /* These are ethernet specific. */
 682         dev->type = ARPHRD_ETHER;
 683         dev->hard_header_len = ETH_HLEN;
 684         dev->mtu = 1500; /* eth_mtu */
 685         dev->addr_len   = ETH_ALEN;
 686 
 687         /* New-style flags. */
 688         dev->flags = IFF_BROADCAST;
 689         dev->family = AF_INET;
 690         dev->pa_addr = 0;
 691         dev->pa_brdaddr = 0;
 692         dev->pa_mask = 0;
 693         dev->pa_alen = sizeof(unsigned long);
 694 
 695         select_prn();
 696         return 0;
 697 }
 698 
 699 static void
 700 adapter_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 701 {
 702         int     i;
 703 
 704         cli();
 705         dev->tbusy = 0;         /* Transmit busy...  */
 706         dev->interrupt = 0;
 707         dev->start = 1;
 708 
 709         select_nic();
 710         rx_page = 0; /* used by RESET */
 711         d_link_put_command(RESET);
 712         d_link_put_command(STOP_RESET);
 713 
 714         tx_fifo_in = 0;
 715         tx_fifo_out = 0;
 716         free_tx_pages = TX_PAGES;
 717 
 718         /* set the ether address. */
 719         d_link_setup_address(NODE_ADDRESS, RW_ADDR);
 720         for (i = 0; i < ETH_ALEN; i++)
 721                 d_link_put_byte(dev->dev_addr[i]);
 722 
 723         /* where to start saving incoming packets */
 724         rx_page = RX_BP | RX_BASE_PAGE;
 725         d_link_setup_address(MEM_4K, RW_ADDR);
 726         /* Enable receiver */
 727         d_link_put_command(RX_ENABLE);
 728         select_prn();
 729         sti();
 730 }
 731 
 732 #define D_LINK_MIN_WINDOW 1024
 733 #define D_LINK_MAX_WINDOW 2048
 734 #define D_LINK_TCP_WINDOW_DIFF 1024
 735 /*
 736  * Copied from sock.c
 737  *
 738  * Sets a lower max receive window in order to achieve <= 2
 739  * packets arriving at the adapter in fast succession.
 740  * (No way that a DE-600 can cope with an ethernet saturated with its packets :-)
 741  *
 742  * Since there are only 2 receive buffers in the DE-600
 743  * and it takes some time to copy from the adapter,
 744  * this is absolutely necessary for any TCP performance whatsoever!
 745  *
 746  */
 747 #define min(a,b)        ((a)<(b)?(a):(b))
 748 static unsigned long
 749 d_link_rspace(struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
 750 {
 751   int amt;
 752 
 753   if (sk != NULL) {
 754 /*
 755  * Hack! You might want to play with commenting away the following line,
 756  * if you know what you do!
 757  */
 758         sk->max_unacked = D_LINK_MAX_WINDOW - D_LINK_TCP_WINDOW_DIFF;
 759 
 760         if (sk->rmem_alloc >= SK_RMEM_MAX-2*D_LINK_MIN_WINDOW) return(0);
 761         amt = min((SK_RMEM_MAX-sk->rmem_alloc)/2-D_LINK_MIN_WINDOW, D_LINK_MAX_WINDOW);
 762         if (amt < 0) return(0);
 763         return(amt);
 764   }
 765   return(0);
 766 }

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