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

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