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

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