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

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