root/drivers/net/de600.c

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

DEFINITIONS

This source file includes following definitions.
  1. de600_read_status
  2. de600_read_byte
  3. de600_open
  4. de600_close
  5. get_stats
  6. trigger_interrupt
  7. de600_start_xmit
  8. de600_interrupt
  9. de600_tx_intr
  10. de600_rx_intr
  11. de600_probe
  12. adapter_init
  13. de600_rspace
  14. init_module
  15. cleanup_module

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

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