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

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