root/drivers/net/arcnet.c

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

DEFINITIONS

This source file includes following definitions.
  1. arcnet_probe
  2. arcnet_ioprobe
  3. arcnet_memprobe
  4. arcnet_reset
  5. arcnet_setup
  6. arcnetE_init
  7. arcnetS_init
  8. arcnet_open
  9. arcnet_close
  10. arcnet_send_packet_bad
  11. arcnetA_send_packet
  12. arcnetE_send_packet
  13. arcnetS_send_packet
  14. arcnetA_continue_tx
  15. arcnetAS_prepare_tx
  16. arcnet_go_tx
  17. arcnet_interrupt
  18. arcnet_inthandler
  19. arcnet_rx
  20. arcnetA_rx
  21. arcnetE_rx
  22. arcnetS_rx
  23. arcnet_get_stats
  24. set_multicast_list
  25. arcnetA_header
  26. arcnetS_header
  27. arcnetA_rebuild_header
  28. arcnetS_rebuild_header
  29. arcnetA_type_trans
  30. arcnetS_type_trans
  31. init_module
  32. cleanup_module

   1 /* arcnet.c
   2         Written 1994-95 by Avery Pennarun, derived from skeleton.c by Donald
   3         Becker.
   4 
   5         Contact Avery at: apenwarr@foxnet.net or
   6         RR #5 Pole Line Road, Thunder Bay, ON, Canada P7C 5M9
   7         
   8         **********************
   9         
  10         The original copyright was as follows:
  11 
  12         skeleton.c Written 1993 by Donald Becker.
  13         Copyright 1993 United States Government as represented by the
  14         Director, National Security Agency.  This software may only be used
  15         and distributed according to the terms of the GNU Public License as
  16         modified by SRC, incorporated herein by reference.
  17          
  18         **********************
  19 
  20         v2.20 ALPHA (95/11/12)
  21           - Added a bit of protocol confusion to the arc0 code to allow
  22             trxnet-compatible IPX support - and the use of all that new
  23             Linux-IPX stuff (including lwared).  Just tell the ipx_interface
  24             command that arc0 uses 802.3 (other protocols will probably also
  25             work).
  26           - Fixed lp->stats to update tx_packets on all devices, not just
  27             arc0.  Also, changed a lot of the error counting to make more
  28             sense.
  29           - rx_packets on arc0 was being updated for each completely received
  30             packet.  It now updates for each segment received, which makes
  31             more sense. 
  32           - Removed unneeded extra check of dev->start in arcnet_inthandler.
  33           - Included someone else's fixes from kernel 1.3.39.  Does it still
  34             work with kernel 1.2?
  35           - Added a new define to disable PRINTING (not checking) of RECON
  36             messages.
  37           - Separated the duplicated error checking code from the various
  38             arcnet??_send_packet routines into a new function.
  39           - Cleaned up lock variables and ping-pong buffers a bit.  This
  40             should mean more stability, fewer missing packets, and less ugly
  41             debug messages.  Assuming it works.
  42           - Changed the format of debug messages to always include the actual
  43             device name instead of just "arcnet:".  Used more macros to
  44             shorten debugging code even more.
  45           - Finally squashed the "startup NULL pointer" bug.  irq2dev_map
  46             wasn't being cleared to NULL when the driver was closed.
  47           - Improved RECON checking; if a certain number of RECON messages
  48             are received within one minute, a warning message is printed
  49             to the effect of "cabling problem."  One-log-message-per-recon
  50             now defaults to OFF.
  51 
  52         v2.12 ALPHA (95/10/27)
  53           - Tried to improve skb handling and init code to fix problems with
  54             the latest 1.3.x kernels. (We no longer use ether_setup except
  55             in arc0e since they keep coming up with new and improved
  56             incompatibilities for us.)
  57 
  58         v2.11 ALPHA (95/10/25)
  59           - Removed superfluous sti() from arcnet_inthandler.
  60           - "Cleaned up" (?) handling of dev->interrupt for multiple
  61             devices.
  62           - Place includes BEFORE configuration settings (solves some
  63             problems with insmod and undefined symbols)
  64           - Removed race condition in arcnet_open that could cause
  65             packet reception to be disabled until after the first TX.
  66           
  67         v2.10 ALPHA (95/09/10)
  68           - Integrated Tomasz Motylewski's new RFC1051 compliant "arc0s"
  69             ([S]imple [S]tandard?) device.  This should make Linux-ARCnet
  70             work with the NetBSD/AmiTCP implementation of this older RFC,
  71             via the arc0s device.
  72           - Decided the current implementation of Multiprotocol ARCnet
  73             involved way too much duplicated code, and tried to share things
  74             a _bit_ more, at least.  This means, pretty much, that any
  75             bugs in the arc0s module are now my fault :)
  76           - Added a new ARCNET_DEBUG_MAX define that sets the highest
  77             debug message level to be included in the driver.  This can
  78             reduce the size of the object file, and probably increases
  79             efficiency a bit.  I get a 0.1 ms speedup in my "ping" times if
  80             I disable all debug messages.  Oh, wow.
  81           - Fixed a long-standing annoyance with some of the power-up debug
  82             messages.  ("IRQ for unknown device" was showing up too often)
  83 
  84         v2.00 (95/09/06)
  85           - THIS IS ONLY A SUMMARY.  The complete changelog is available
  86             from me upon request.
  87 
  88           - ARCnet RECON messages are now detected and logged.  These occur
  89             when a new computer is powered up on the network, or in a
  90             constant stream when the network cable is broken.  Thanks to
  91             Tomasz Motylewski for this.  You must have D_EXTRA enabled
  92             if you want these messages sent to syslog, otherwise they will
  93             only show up in the network statistics (/proc/net/dev).
  94           - The TX Acknowledge flag is now checked, and a log message is sent
  95             if a completed transmit is not ACK'd.  (I have yet to have this
  96             happen to me.)
  97           - Debug levels are now completely different.  See the README.
  98           - Many code cleanups, with several no-longer-necessary and some
  99             completely useless options removed.
 100           - Multiprotocol support.  You can now use the "arc0e" device to
 101             send "Ethernet-Encapsulation" packets, which are compatible with
 102             Windows for Workgroups and LAN Manager, and possibly other
 103             software.  See the README for more information.
 104           - Documentation updates and improvements.
 105           
 106         v1.02 (95/06/21)
 107           - A fix to make "exception" packets sent from Linux receivable
 108             on other systems.  (The protocol_id byte was sometimes being set
 109             incorrectly, and Linux wasn't checking it on receive so it
 110             didn't show up)
 111 
 112         v1.01 (95/03/24)
 113           - Fixed some IPX-related bugs. (Thanks to Tomasz Motylewski
 114             <motyl@tichy.ch.uj.edu.pl> for the patches to make arcnet work
 115             with dosemu!)
 116             
 117         v1.00 (95/02/15)
 118           - Initial non-alpha release.
 119         
 120          
 121         TO DO:
 122         
 123          - Test in systems with NON-ARCnet network cards, just to see if
 124            autoprobe kills anything.  Currently, we do cause some NE2000's
 125            to die.  Autoprobe is also way too slow and verbose, particularly
 126            if there aren't any ARCnet cards in the system.  And why shouldn't
 127            it work as a module again?
 128          - Rewrite autoprobe.
 129          - Make sure RESET flag is cleared during an IRQ even if dev->start==0;
 130            mainly a portability fix.  This will confuse autoprobe a bit, so
 131            test that too.
 132          - What about cards with shared memory that can be "turned off?"
 133          - NFS mount freezes after several megabytes to SOSS for DOS. 
 134            unmount/remount fixes it.  Is this arcnet-specific?  I don't know.
 135          - Some newer ARCnets support promiscuous mode, supposedly.  If
 136            someone sends me information, I'll try to implement it.
 137          - Dump Linux 1.2 support and its ugly #ifdefs.
 138          - Add support for the new 1.3.x IP header cache features.
 139          - ATA protocol support?? 
 140          - Banyan VINES TCP/IP support??
 141 
 142            
 143         Sources:
 144          - Crynwr arcnet.com/arcether.com packet drivers.
 145          - arcnet.c v0.00 dated 1/1/94 and apparently by
 146                 Donald Becker - it didn't work :)
 147          - skeleton.c v0.05 dated 11/16/93 by Donald Becker
 148                 (from Linux Kernel 1.1.45)
 149          - The official ARCnet data sheets (!) thanks to Ken Cornetet
 150                 <kcornete@nyx10.cs.du.edu>
 151          - RFC's 1201 and 1051 - re: TCP/IP over ARCnet
 152          - net/inet/eth.c (from kernel 1.1.50) for header-building info...
 153          - Alternate Linux ARCnet source by V.Shergin <vsher@sao.stavropol.su>
 154          - Textual information and more alternate source from Joachim Koenig
 155                 <jojo@repas.de>
 156 */
 157 
 158 static const char *version =
 159  "arcnet.c: v2.20 ALPHA 95/11/12 Avery Pennarun <apenwarr@foxnet.net>\n";
 160 
 161  
 162 
 163 #include <linux/module.h>
 164 #include <linux/config.h>
 165 #include <linux/version.h>
 166 
 167 /* are we Linux 1.2.x? */
 168 #if LINUX_VERSION_CODE < 0x10300
 169 #define LINUX12
 170 #endif
 171 
 172 
 173 #include <linux/kernel.h>
 174 #include <linux/sched.h>
 175 #include <linux/types.h>
 176 #include <linux/fcntl.h>
 177 #include <linux/interrupt.h>
 178 #include <linux/ptrace.h>
 179 #include <linux/ioport.h>
 180 #include <linux/in.h>
 181 #include <linux/malloc.h>
 182 #include <linux/string.h>
 183 #include <linux/timer.h>
 184 #include <linux/errno.h>
 185 #include <linux/delay.h>
 186 #include <linux/if_arp.h>
 187 #include <linux/netdevice.h>
 188 #include <linux/etherdevice.h>
 189 #include <linux/skbuff.h>
 190 
 191 /*#include <linux/config.h>*/           /* For CONFIG_INET */
 192 
 193 #include <asm/system.h>
 194 #include <asm/bitops.h>
 195 #include <asm/io.h>
 196 #include <asm/dma.h>
 197 
 198 #ifdef LINUX12
 199 #include "arp.h"
 200 #else
 201 #include <net/arp.h>
 202 #endif
 203 
 204 /**************************************************************************/
 205 
 206 /* The card sends the reconfiguration signal when it loses the connection to
 207  * the rest of its network. It is a 'Hello, is anybody there?' cry.  This
 208  * usually happens when a new computer on the network is powered on or when
 209  * the cable is broken.
 210  *
 211  * Define DETECT_RECONFIGS if you want to detect network reconfigurations. 
 212  * They may be a real nuisance on a larger ARCnet network; if you are a
 213  * network administrator you probably would like to count them. 
 214  * Reconfigurations will be recorded in stats.tx_carrier_errors (the last
 215  * field of the /proc/net/dev file).
 216  *
 217  * Define SHOW_RECONFIGS if you really want to see a log message whenever
 218  * a RECON occurs.
 219  */
 220 #define DETECT_RECONFIGS
 221 #undef SHOW_RECONFIGS
 222 
 223 /* RECON_THRESHOLD is the maximum number of RECON messages to receive within
 224  * one minute before printing a "cabling problem" warning.  You must have
 225  * DETECT_RECONFIGS enabled if you want to use this.  The default value
 226  * should be fine.
 227  *
 228  * After that, a "cabling restored" message will be printed on the next IRQ
 229  * if no RECON messages have been received for 10 seconds.
 230  *
 231  * Do not define RECON_THRESHOLD at all if you want to disable this feature.
 232  */
 233 #define RECON_THRESHOLD 30
 234 
 235 /* Define this if you want to make sure transmitted packets are "acknowledged"
 236  * by the destination host, as long as they're not to the broadcast address.
 237  *
 238  * That way, if one segment of a split packet doesn't get through, it can
 239  * be resent immediately rather than confusing the other end.
 240  *
 241  * Disable this to return to 1.02-style behaviour, if you have problems.
 242  */
 243 #define VERIFY_ACK
 244 
 245 /* Define this to the minimum "timeout" value.  If a transmit takes longer
 246  * than TX_TIMEOUT jiffies, Linux will abort the TX and retry.  On a large
 247  * network, or one with heavy network traffic, this timeout may need to be
 248  * increased.
 249  */
 250 #define TX_TIMEOUT 20
 251 
 252 /* Define this if you want to make it easier to use the "call trace" when
 253  * a kernel NULL pointer assignment occurs.  Hopefully unnecessary, most of
 254  * the time.  It will make all the function names (and other things) show
 255  * up as kernel symbols.  (especially handy when using arcnet as a module)
 256  */
 257 #undef static
 258 
 259 /**************************************************************************/
 260 
 261 /* New debugging bitflags: each option can be enabled individually.
 262  *
 263  * These can be set while the driver is running by typing:
 264  *      ifconfig arc0 down metric 1xxx HOSTNAME
 265  *              where 1xxx is 1000 + the debug level you want
 266  *              and HOSTNAME is your hostname/ip address
 267  * and then resetting your routes.
 268  *
 269  * Note: only debug flags included in the ARCNET_DEBUG_MAX define will
 270  *   actually be available.  GCC will (at least, GCC 2.7.0 will) notice
 271  *   lines using a BUGLVL not in ARCNET_DEBUG_MAX and automatically optimize
 272  *   them out.
 273  */
 274 #define D_NORMAL        1       /* D_NORMAL  normal operational info    */
 275 #define D_INIT          2       /* D_INIT    show init/probe messages   */
 276 #define D_EXTRA         4       /* D_EXTRA   extra information          */
 277 /* debug levels past this point give LOTS of output! */
 278 #define D_DURING        8       /* D_DURING  during normal use (irq's)  */
 279 #define D_TX            16      /* D_TX      show tx packets            */
 280 #define D_RX            32      /* D_RX      show rx packets            */
 281 #define D_SKB           64      /* D_SKB     dump skb's                 */
 282 
 283 #ifndef ARCNET_DEBUG_MAX
 284 #define ARCNET_DEBUG_MAX (~0)           /* enable ALL debug messages */
 285 /*#define ARCNET_DEBUG_MAX (D_NORMAL|D_INIT|D_EXTRA) */
 286 /*#define ARCNET_DEBUG_MAX 0    */      /* enable NO debug messages */
 287 #endif
 288 
 289 #ifndef ARCNET_DEBUG
 290 #define ARCNET_DEBUG (D_NORMAL|D_INIT|D_EXTRA)
 291 /*#define ARCNET_DEBUG (D_NORMAL|D_INIT)*/
 292 #endif
 293 int arcnet_debug = ARCNET_DEBUG;
 294 
 295 /* macros to simplify debug checking */
 296 #define BUGLVL(x) if ((ARCNET_DEBUG_MAX)&arcnet_debug&(x))
 297 #define BUGMSG(x,msg,args...) BUGLVL(x) printk("%6s: " msg, dev->name , ## args);
 298 
 299 #ifndef HAVE_AUTOIRQ
 300 /* From auto_irq.c, in ioport.h for later versions. */
 301 extern void autoirq_setup(int waittime);
 302 extern int autoirq_report(int waittime);
 303 /* The map from IRQ number (as passed to the interrupt handler) to
 304    'struct device'. */
 305 extern struct device *irq2dev_map[16];
 306 #endif
 307 
 308 #ifndef HAVE_PORTRESERVE
 309 #define check_region(ioaddr, size)              0
 310 #define request_region(ioaddr, size)            do ; while (0)
 311 #endif
 312 
 313 /* Some useful multiprotocol macros */
 314 #define TBUSY lp->adev->tbusy \
 315                 =lp->edev->tbusy \
 316                 =lp->sdev->tbusy
 317 #define IF_TBUSY (lp->adev->tbusy \
 318                 || lp->edev->tbusy \
 319                 || lp->sdev->tbusy)
 320 
 321 #define INTERRUPT lp->adev->interrupt \
 322                 =lp->edev->interrupt \
 323                 =lp->sdev->interrupt
 324 #define IF_INTERRUPT (lp->adev->interrupt \
 325                 || lp->edev->interrupt \
 326                 || lp->sdev->interrupt)
 327 
 328 #define START lp->adev->start \
 329                 =lp->edev->start \
 330                 =lp->sdev->start
 331                 
 332 
 333 /* The number of low I/O ports used by the ethercard. */
 334 #define ARCNET_TOTAL_SIZE       16
 335 
 336 
 337 /* Handy defines for ARCnet specific stuff */
 338         /* COM 9026 controller chip --> ARCnet register addresses */
 339 #define INTMASK (ioaddr+0)              /* writable */
 340 #define STATUS  (ioaddr+0)              /* readable */
 341 #define COMMAND (ioaddr+1)      /* writable, returns random vals on read (?) */
 342 #define RESET  (ioaddr+8)               /* software reset writable */
 343 
 344         /* Time needed for various things (in clock ticks, 1/100 sec) */
 345         /* We mostly don't bother with these - watch out. */
 346 #define RESETtime 40            /* reset */
 347 #define XMITtime 10             /* send (?) */
 348 #define ACKtime 10              /* acknowledge (?) */
 349 
 350         /* these are the max/min lengths of packet data. (including
 351          * ClientData header)
 352          * note: packet sizes 250, 251, 252 are impossible (God knows why)
 353          *  so exception packets become necessary.
 354          *
 355          * These numbers are compared with the length of the full packet,
 356          * including ClientData header.
 357          */
 358 #define MTU     253     /* normal packet max size */
 359 #define MinTU   257     /* extended packet min size */
 360 #define XMTU    508     /* extended packet max size */
 361 
 362         /* status/interrupt mask bit fields */
 363 #define TXFREEflag      0x01            /* transmitter available */
 364 #define TXACKflag       0x02            /* transmitted msg. ackd */
 365 #define RECONflag       0x04            /* system reconfigured */
 366 #define TESTflag        0x08            /* test flag */
 367 #define RESETflag       0x10            /* power-on-reset */
 368 #define RES1flag        0x20            /* unused */
 369 #define RES2flag        0x40            /* unused */
 370 #define NORXflag        0x80            /* receiver inhibited */
 371 
 372 #ifdef DETECT_RECONFIGS
 373         #define RECON_flag RECONflag
 374 #else
 375         #define RECON_flag 0
 376 #endif
 377 
 378        /* in the command register, the following bits have these meanings:
 379         *                0-2     command
 380         *                3-4     page number (for enable rcv/xmt command)
 381         *                 7      receive broadcasts
 382         */
 383 #define NOTXcmd         0x01            /* disable transmitter */
 384 #define NORXcmd         0x02            /* disable receiver */
 385 #define TXcmd           0x03            /* enable transmitter */
 386 #define RXcmd           0x04            /* enable receiver */
 387 #define CONFIGcmd       0x05            /* define configuration */
 388 #define CFLAGScmd       0x06            /* clear flags */
 389 #define TESTcmd         0x07            /* load test flags */
 390 
 391        /* flags for "clear flags" command */
 392 #define RESETclear      0x08            /* power-on-reset */
 393 #define CONFIGclear     0x10            /* system reconfigured */
 394 
 395         /* flags for "load test flags" command */
 396 #define TESTload        0x08            /* test flag (diagnostic) */
 397 
 398         /* byte deposited into first address of buffers on reset */
 399 #define TESTvalue       0321             /* that's octal for 0xD1 :) */
 400 
 401         /* for "enable receiver" command */
 402 #define RXbcasts        0x80            /* receive broadcasts */
 403 
 404         /* flags for "define configuration" command */
 405 #define NORMALconf      0x00            /* 1-249 byte packets */
 406 #define EXTconf         0x08            /* 250-504 byte packets */
 407 
 408         /* Starts receiving packets into recbuf.
 409          */
 410 #define EnableReceiver()        outb(RXcmd|(recbuf<<3)|RXbcasts,COMMAND)
 411 
 412         /* RFC1201 Protocol ID's */
 413 #define ARC_P_IP        212             /* 0xD4 */
 414 #define ARC_P_ARP       213             /* 0xD5 */
 415 #define ARC_P_RARP      214             /* 0xD6 */
 416 #define ARC_P_IPX       250             /* 0xFA */
 417 
 418         /* Old RFC1051 Protocol ID's */
 419 #define ARC_P_IP_RFC1051 240            /* 0xF0 */
 420 #define ARC_P_ARP_RFC1051 241           /* 0xF1 */
 421 
 422         /* MS LanMan/WfWg protocol */
 423 #define ARC_P_ETHER     0xE8
 424 
 425         /* Unsupported/indirectly supported protocols */
 426 #define ARC_P_LANSOFT   251             /* 0xFB - what is this? */
 427 #define ARC_P_ATALK     0xDD
 428 
 429         /* the header required by the card itself */
 430 struct HardHeader
 431 {
 432         u_char  source,         /* source ARCnet - filled in automagically */
 433                 destination,    /* destination ARCnet - 0 for broadcast */
 434                 offset1,        /* offset of ClientData (256-byte packets) */
 435                 offset2;        /* offset of ClientData (512-byte packets) */
 436 };
 437 
 438         /* a complete ARCnet packet */
 439 union ArcPacket
 440 {
 441         struct HardHeader hardheader;   /* the hardware header */
 442         u_char raw[512];                /* raw packet info, incl ClientData */
 443 };
 444 
 445         /* the "client data" header - RFC1201 information
 446          * notice that this screws up if it's not an even number of bytes
 447          * <sigh>
 448          */
 449 struct ClientData
 450 {
 451         /* data that's NOT part of real packet - we MUST get rid of it before
 452          * actually sending!!
 453          */
 454         u_char  saddr,          /* Source address - needed for IPX */
 455                 daddr;          /* Destination address */
 456         
 457         /* data that IS part of real packet */
 458         u_char  protocol_id,    /* ARC_P_IP, ARC_P_ARP, etc */
 459                 split_flag;     /* for use with split packets */
 460         u_short sequence;       /* sequence number */
 461 };
 462 #define EXTRA_CLIENTDATA (sizeof(struct ClientData)-4)
 463 
 464 
 465         /* the "client data" header - RFC1051 information
 466          * this also screws up if it's not an even number of bytes
 467          * <sigh again>
 468          */
 469 struct S_ClientData
 470 {
 471         /* data that's NOT part of real packet - we MUST get rid of it before
 472          * actually sending!!
 473          */
 474         u_char  saddr,          /* Source address - needed for IPX */
 475                 daddr,          /* Destination address */
 476                 junk;           /* padding to make an even length */
 477         
 478         /* data that IS part of real packet */
 479         u_char  protocol_id;    /* ARC_P_IP, ARC_P_ARP, etc */
 480 };
 481 #define S_EXTRA_CLIENTDATA (sizeof(struct S_ClientData)-1)
 482 
 483 
 484 /* "Incoming" is information needed for each address that could be sending
 485  * to us.  Mostly for partially-received split packets.
 486  */
 487 struct Incoming
 488 {
 489         struct sk_buff *skb;            /* packet data buffer             */
 490         unsigned char lastpacket,       /* number of last packet (from 1) */
 491                       numpackets;       /* number of packets in split     */
 492         u_short sequence;               /* sequence number of assembly    */
 493 };
 494 
 495 struct Outgoing
 496 {
 497         struct sk_buff *skb;            /* buffer from upper levels */
 498         struct ClientData *hdr;         /* clientdata of last packet */
 499         u_char *data;                   /* pointer to data in packet */
 500         short length,                   /* bytes total */
 501               dataleft,                 /* bytes left */
 502               segnum,                   /* segment being sent */
 503               numsegs,                  /* number of segments */
 504               seglen;                   /* length of segment */
 505 #ifdef VERIFY_ACK
 506         short lastload_dest,            /* can last loaded packet be acked? */
 507               lasttrans_dest;           /* can last TX'd packet be acked? */
 508 #endif
 509         
 510 };
 511 
 512 
 513 /* Information that needs to be kept for each board. */
 514 struct arcnet_local {
 515         struct enet_statistics stats;
 516         u_char arcnum;          /* arcnet number - our 8-bit address */
 517         u_short sequence;       /* sequence number (incs with each packet) */
 518         u_char recbuf,          /* receive buffer # (0 or 1) */
 519                txbuf,           /* transmit buffer # (2 or 3) */
 520                txready;         /* buffer where a packet is ready to send */
 521         short intx,             /* in TX routine? */
 522               in_txhandler,     /* in TX_IRQ handler? */
 523               sending;          /* transmit in progress? */
 524         short tx_left;          /* segments of split packet left to TX */
 525 
 526 #if defined(DETECT_RECONFIGS) && defined(RECON_THRESHOLD)
 527         time_t first_recon,     /* time of "first" RECON message to count */
 528                 last_recon;     /* time of most recent RECON */
 529         int num_recons,         /* number of RECONs between first and last. */
 530             network_down;       /* do we think the network is down? */
 531 #endif
 532         
 533         struct timer_list timer; /* the timer interrupt struct */
 534         struct Incoming incoming[256];  /* one from each address */
 535         struct Outgoing outgoing; /* packet currently being sent */
 536         
 537         struct device *adev,    /* RFC1201 protocol device */
 538                         *edev,  /* Ethernet-Encap device */
 539                         *sdev;  /* RFC1051 protocol device */
 540 };
 541 
 542 
 543 /* Index to functions, as function prototypes. */
 544 extern int arcnet_probe(struct device *dev);
 545 #ifndef MODULE
 546 static int arcnet_memprobe(struct device *dev,u_char *addr);
 547 static int arcnet_ioprobe(struct device *dev, short ioaddr);
 548 #endif
 549 static void arcnet_setup(struct device *dev);
 550 static int arcnetE_init(struct device *dev);
 551 static int arcnetS_init(struct device *dev);
 552 
 553 static int arcnet_open(struct device *dev);
 554 static int arcnet_close(struct device *dev);
 555 static int arcnet_reset(struct device *dev);
 556 
 557 static int arcnet_send_packet_bad(struct sk_buff *skb,struct device *dev);
 558 static int arcnetA_send_packet(struct sk_buff *skb, struct device *dev);
 559 static int arcnetE_send_packet(struct sk_buff *skb, struct device *dev);
 560 static int arcnetS_send_packet(struct sk_buff *skb, struct device *dev);
 561 static void arcnetA_continue_tx(struct device *dev);
 562 static void arcnetAS_prepare_tx(struct device *dev,u_char *hdr,int hdrlen,
 563                 char *data,int length,int daddr,int exceptA);
 564 static int arcnet_go_tx(struct device *dev,int enable_irq);
 565 
 566 static void arcnet_interrupt(int irq,struct pt_regs *regs);
 567 static void arcnet_inthandler(struct device *dev);
 568 
 569 static void arcnet_rx(struct device *dev,int recbuf);
 570 static void arcnetA_rx(struct device *dev,u_char *buf,
 571         int length,u_char saddr, u_char daddr);
 572 static void arcnetE_rx(struct device *dev,u_char *arcsoft,
 573         int length,u_char saddr, u_char daddr);
 574 static void arcnetS_rx(struct device *dev,u_char *buf,
 575         int length,u_char saddr, u_char daddr);
 576 
 577 static struct enet_statistics *arcnet_get_stats(struct device *dev);
 578 static void set_multicast_list(struct device *dev);
 579 
 580         /* functions for header/arp/etc building */
 581 #ifdef LINUX12
 582 int arcnetA_header(unsigned char *buff,struct device *dev,
 583                 unsigned short type,void *daddr,void *saddr,unsigned len,
 584                 struct sk_buff *skb);
 585 int arcnetS_header(unsigned char *buff,struct device *dev,
 586                 unsigned short type,void *daddr,void *saddr,unsigned len,
 587                 struct sk_buff *skb);
 588 #else
 589 int arcnetA_header(struct sk_buff *skb,struct device *dev,
 590                 unsigned short type,void *daddr,void *saddr,unsigned len);
 591 int arcnetS_header(struct sk_buff *skb,struct device *dev,
 592                 unsigned short type,void *daddr,void *saddr,unsigned len);
 593 #endif
 594 int arcnetA_rebuild_header(void *eth,struct device *dev,unsigned long raddr,
 595                 struct sk_buff *skb);
 596 int arcnetS_rebuild_header(void *eth,struct device *dev,unsigned long raddr,
 597                 struct sk_buff *skb);
 598 unsigned short arcnetA_type_trans(struct sk_buff *skb,struct device *dev);
 599 unsigned short arcnetS_type_trans(struct sk_buff *skb,struct device *dev);
 600 
 601 #ifdef MODULE
 602 int  init_module(void);
 603 void cleanup_module(void);
 604 #endif
 605 
 606 #define tx_done(dev) 1
 607 
 608 #define JIFFER(time) for (delayval=0; delayval<(time*10); delayval++) \
 609                 udelay(1000);
 610                 
 611 
 612 /****************************************************************************
 613  *                                                                          *
 614  * Probe and initialization                                                 *
 615  *                                                                          *
 616  ****************************************************************************/
 617  
 618 /* Check for a network adaptor of this type, and return '0' if one exists.
 619  *  If dev->base_addr == 0, probe all likely locations.
 620  *  If dev->base_addr == 1, always return failure.
 621  *  If dev->base_addr == 2, allocate space for the device and return success
 622  *  (detachable devices only).
 623  */
 624 int
 625 arcnet_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 626 {
 627 #ifndef MODULE
 628         /* I refuse to probe anything less than 0x200, because anyone using
 629          * an address like that should probably be shot.
 630          */
 631         int *port, ports[] = {/* first the suggested values! */
 632                               0x300,0x2E0,0x2F0,0x2D0,
 633                               /* ...now everything else possible. */
 634                               0x200,0x210,0x220,0x230,0x240,0x250,0x260,0x270,
 635                               0x280,0x290,0x2a0,0x2b0,0x2c0,
 636                                     0x310,0x320,0x330,0x340,0x350,0x360,0x370,
 637                               0x380,0x390,0x3a0,/* video ports, */0x3e0,0x3f0,
 638                               /* a null ends the list */
 639                               0};
 640         /* I'm not going to probe below 0xA0000 either, for similar reasons.
 641          */
 642         unsigned long *addr, addrs[] = {0xD0000,0xE0000,0xA0000,0xB0000,
 643                                         0xC0000,0xF0000,
 644                                         /* from <mdrejhon@magi.com> */
 645                                         0xE1000,
 646                                         0xDD000,0xDC000,
 647                                         0xD9000,0xD8000,0xD5000,0xD4000,0xD1000,
 648                                         0xCD000,0xCC000,
 649                                         0xC9000,0xC8000,0xC5000,0xC4000,
 650                                         /* terminator */
 651                                         0};
 652         int base_addr=dev->base_addr, status=0;
 653 #endif /* MODULE */
 654         int delayval;
 655         struct arcnet_local *lp;
 656 
 657         printk(version);
 658         
 659 #if 1
 660         BUGLVL(D_NORMAL)
 661         {
 662                 printk("arcnet: ***\n");
 663                 printk("arcnet: * Read README.arcnet for important release notes!\n");
 664                 printk("arcnet: *\n");
 665                 printk("arcnet: * This is an ALPHA version!  (Last stable release: v2.00)  E-mail me if\n");
 666                 printk("arcnet: * you have any questions, comments, or bug reports.\n");
 667                 printk("arcnet: ***\n");
 668         }
 669 #else
 670         BUGLVL(D_INIT)
 671         {
 672                 printk("arcnet: ***\n");
 673                 printk("arcnet: * Read README.arcnet for important release notes!\n");
 674                 printk("arcnet: *\n");
 675                 printk("arcnet: * This version should be stable, but please e-mail\n");
 676                 printk("arcnet: * me if you have any questions or comments.\n");
 677                 printk("arcnet: ***\n");
 678         }
 679 #endif
 680 
 681         BUGMSG(D_INIT,"given: base %lXh, IRQ %Xh, shmem %lXh\n",
 682                         dev->base_addr,dev->irq,dev->mem_start);
 683 
 684 #ifndef MODULE
 685         if (base_addr > 0x1ff)          /* Check a single specified location. */
 686                 status=arcnet_ioprobe(dev, base_addr);
 687         else if (base_addr > 0)         /* Don't probe at all. */
 688                 return ENXIO;
 689         else for (port = &ports[0]; *port; port++)
 690         {
 691                 int ioaddr = *port;
 692                 if (check_region(ioaddr, ARCNET_TOTAL_SIZE))
 693                 {
 694                         BUGMSG(D_INIT,"Skipping %Xh because of check_region...\n",
 695                                         ioaddr);
 696                         continue;
 697                 }
 698 
 699                 status=arcnet_ioprobe(dev, ioaddr);
 700                 if (!status) break;
 701         }
 702         
 703         if (status) return status;
 704 
 705         /* ioprobe turned out okay.  Now give it a couple seconds to finish
 706          * initializing...
 707          */
 708         BUGMSG(D_INIT,"ioprobe okay!  Waiting for reset...\n");
 709         JIFFER(100);
 710 
 711         /* okay, now we have to find the shared memory area. */
 712         BUGMSG(D_INIT,"starting memory probe, given %lXh\n",
 713                         dev->mem_start);
 714         if (dev->mem_start)     /* value given - probe just that one */
 715         {
 716                 status=arcnet_memprobe(dev,(u_char *)dev->mem_start);
 717                 if (status) return status;
 718         }
 719         else                    /* no value given - probe everything */
 720         {
 721                 for (addr = &addrs[0]; *addr; addr++) {
 722                         status=arcnet_memprobe(dev,(u_char *)(*addr));
 723                         if (!status) break;
 724                 }
 725                 
 726                 if (status) return status;
 727         }
 728 #else /* MODULE */
 729         if (!dev->base_addr || !dev->irq || !dev->mem_start 
 730                 || !dev->rmem_start)
 731         {
 732                 printk("%6s: loadable modules can't autoprobe!\n",dev->name);
 733                 printk("%6s:  try using io=, irqnum=, and shmem= on the insmod line.\n",
 734                         dev->name);
 735                 printk("%6s:  you may also need num= to change the device name. (ie. num=1 for arc1)\n",
 736                         dev->name);
 737                 return ENODEV;
 738         }
 739 #endif
 740         /* now reserve the irq... */
 741         {       
 742                 int irqval = request_irq(dev->irq, &arcnet_interrupt, 0,
 743                         "arcnet");
 744                 if (irqval) {
 745                         printk("%6s: unable to get IRQ %d (irqval=%d).\n",
 746                                 dev->name,dev->irq, irqval);
 747                         return EAGAIN;
 748                  }
 749          }
 750          
 751         /* Grab the region so we can find another board if autoIRQ fails. */
 752         request_region(dev->base_addr, ARCNET_TOTAL_SIZE,"arcnet");
 753         
 754         printk("%6s: ARCnet card found at %03lXh, IRQ %d, ShMem at %lXh.\n", 
 755                 dev->name, dev->base_addr, dev->irq, dev->mem_start);
 756 
 757         /* Initialize the device structure. */
 758         dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
 759         if (dev->priv == NULL)
 760                 return -ENOMEM;
 761         memset(dev->priv, 0, sizeof(struct arcnet_local));
 762         lp=(struct arcnet_local *)(dev->priv);
 763 
 764         dev->open=arcnet_open;
 765         dev->stop=arcnet_close;
 766         dev->hard_start_xmit=arcnetA_send_packet;
 767         dev->get_stats=arcnet_get_stats;
 768 #ifdef HAVE_MULTICAST
 769         dev->set_multicast_list = &set_multicast_list;
 770 #endif
 771 
 772         /* Fill in the fields of the device structure with generic
 773          * values.
 774          */
 775         arcnet_setup(dev);
 776         
 777         /* And now fill particular fields with arcnet values */
 778         dev->mtu=1500; /* completely arbitrary - agrees with ether, though */
 779         dev->hard_header_len=sizeof(struct ClientData);
 780         BUGMSG(D_DURING,"ClientData header size is %d.\n",
 781                 sizeof(struct ClientData));
 782         BUGMSG(D_DURING,"HardHeader size is %d.\n",
 783                 sizeof(struct HardHeader));
 784 
 785                 /* since we strip EXTRA_CLIENTDATA bytes off before sending,
 786                  * we let Linux add that many bytes to the packet data...
 787                  */
 788         
 789         BUGMSG(D_INIT,"arcnet_probe: resetting card.\n");
 790         arcnet_reset(dev);
 791         JIFFER(50);
 792         BUGMSG(D_NORMAL,"We appear to be station %d (%02Xh)\n",
 793                         lp->arcnum,lp->arcnum);
 794         if (lp->arcnum==0)
 795                 printk("%6s: WARNING!  Station address 0 is reserved for broadcasts!\n",
 796                         dev->name);
 797         if (lp->arcnum==255)
 798                 printk("%6s: WARNING!  Station address 255 may confuse DOS networking programs!\n",
 799                         dev->name);
 800         dev->dev_addr[0]=lp->arcnum;
 801         lp->sequence=1;
 802         lp->recbuf=0;
 803 
 804         dev->hard_header=arcnetA_header;
 805         dev->rebuild_header=arcnetA_rebuild_header;
 806         
 807         #ifdef LINUX12
 808         dev->type_trans=arcnetA_type_trans;
 809         #endif
 810 
 811         return 0;
 812 }
 813 
 814 #ifndef MODULE
 815 
 816 int arcnet_ioprobe(struct device *dev, short ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 817 {
 818         int delayval,airq;
 819 
 820         BUGMSG(D_INIT,"probing address %Xh\n",ioaddr);
 821         BUGMSG(D_INIT," status1=%Xh\n",inb(STATUS));
 822 
 823                 
 824         /* very simple - all we have to do is reset the card, and if there's
 825          * no irq, it's not an ARCnet.  We can also kill two birds with
 826          * one stone because we detect the IRQ at the same time :)
 827          */
 828          
 829         /* reset the card by reading the reset port */
 830         inb(RESET);
 831         JIFFER(RESETtime);
 832 
 833         /* if status port is FF, there's certainly no arcnet... give up. */
 834         if (inb(STATUS)==0xFF)
 835         {
 836                 BUGMSG(D_INIT," probe failed.  Status port empty.\n");
 837                 return ENODEV;
 838         }
 839 
 840 #if 0
 841         /* we'll try to be reasonably sure it's an arcnet by making sure
 842          * the value of the COMMAND port changes automatically once in a
 843          * while.  I have no idea what those values ARE, but at least
 844          * they work.
 845          */
 846         {
 847                 int initval,curval;
 848                 
 849                 curval=initval=inb(COMMAND);
 850                 delayval=jiffies+5;
 851                 while (delayval>=jiffies && curval==initval)
 852                         curval=inb(COMMAND);
 853                         
 854                 if (curval==initval)
 855                 {
 856                         BUGLVL(D_INIT," probe failed.  never-changing command port (%02Xh).\n",
 857                                 initval);
 858                         return ENODEV;
 859                 }
 860         }
 861 #endif
 862 
 863         BUGMSG(D_INIT," status2=%Xh\n",inb(STATUS));
 864 
 865         /* now we turn the reset bit off so we can IRQ next reset... */
 866         outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
 867         if (inb(STATUS) & RESETflag) /* reset flag STILL on */
 868         {
 869                 BUGMSG(D_INIT," probe failed.  eternal reset flag1...(status=%Xh)\n",
 870                                 inb(STATUS));
 871                 return ENODEV;
 872         }
 873 
 874         /* set up automatic IRQ detection */
 875         autoirq_setup(0);
 876         
 877 
 878         /* if we do this, we're sure to get an IRQ since the card has
 879          * just reset and the NORXflag is on until we tell it to start
 880          * receiving.
 881          *
 882          * However, this could, theoretically, cause a lockup.  Maybe I'm just
 883          * not very good at theory! :)
 884          */
 885         outb(NORXflag,INTMASK);
 886         JIFFER(RESETtime);
 887         outb(0,INTMASK);
 888 
 889         /* and turn the reset flag back off */
 890         outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
 891 
 892         airq = autoirq_report(0);
 893         BUGLVL(D_INIT) if (airq)
 894                 printk("%6s:  autoirq is %d\n", dev->name, airq);
 895 
 896         /* if there was no autoirq AND the user hasn't set any defaults,
 897          * give up.
 898          */
 899         if (!airq && !(dev->base_addr && dev->irq))
 900         {
 901                 BUGMSG(D_INIT," probe failed.  no autoirq...\n");
 902                 return ENODEV;
 903         }
 904 
 905         /* otherwise we probably have a card.  Let's make sure. */
 906         
 907         if (inb(STATUS) & RESETflag) /* reset flag on */
 908         {
 909                 /* now we turn the reset bit off */
 910                 outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
 911         }
 912         
 913         if (inb(STATUS) & RESETflag) /* reset flag STILL on */
 914         {
 915                 BUGMSG(D_INIT," probe failed.  eternal reset flag...(status=%Xh)\n",
 916                                 inb(STATUS));
 917                 return ENODEV;
 918         }
 919         
 920         /* okay, we've got a real, live ARCnet on our hands. */
 921         if (!dev->base_addr) dev->base_addr=ioaddr;
 922         
 923         if (dev->irq < 2)               /* "Auto-IRQ" */
 924         {
 925                 /* we already did the autoirq above, so store the values */
 926                 dev->irq=airq;
 927         }
 928         else if (dev->irq == 2)
 929         {
 930                 BUGMSG(D_NORMAL,"IRQ2 == IRQ9, don't worry.\n");
 931                 dev->irq = 9;
 932         }
 933 
 934         BUGMSG(D_INIT,"irq and base address seem okay. (%lXh, IRQ %d)\n",
 935                         dev->base_addr,dev->irq);
 936         return 0;
 937 }
 938 
 939 
 940 /* A memory probe that is called after the card is reset.
 941  * It checks for the official TESTvalue in byte 0 and makes sure the buffer
 942  * has certain characteristics of an ARCnet.
 943  */
 944 int arcnet_memprobe(struct device *dev,u_char *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 945 {
 946         BUGMSG(D_INIT,"probing memory at %lXh\n",(u_long)addr);
 947                 
 948         dev->mem_start=0;
 949 
 950         /* ARCnet memory byte 0 is TESTvalue */
 951         if (addr[0]!=TESTvalue)
 952         {
 953                 BUGMSG(D_INIT," probe failed.  addr=%lXh, addr[0]=%Xh (not %Xh)\n",
 954                                 (unsigned long)addr,addr[0],TESTvalue);
 955                 return ENODEV;
 956         }
 957         
 958         /* now verify the shared memory writability */
 959         addr[0]=0x42;
 960         if (addr[0]!=0x42)
 961         {
 962                 BUGMSG(D_INIT," probe failed.  addr=%lXh, addr[0]=%Xh (not 42h)\n",
 963                                 (unsigned long)addr,addr[0]);
 964                 return ENODEV;
 965         }
 966 
 967         /* got it!  fill in dev */
 968         dev->mem_start=(unsigned long)addr;
 969         dev->mem_end=dev->mem_start+512*4-1;
 970         dev->rmem_start=dev->mem_start+512*0;
 971         dev->rmem_end=dev->mem_start+512*2-1;
 972 
 973         return 0;
 974 }
 975 
 976 #endif /* MODULE */
 977 
 978 
 979 /* Do a hardware reset on the card.
 980  */
 981 int arcnet_reset(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 982 {
 983         struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
 984         short ioaddr=dev->base_addr;
 985         int delayval,recbuf=lp->recbuf;
 986         u_char *cardmem;
 987         
 988         outb(0,INTMASK);        /* no IRQ's, please! */
 989         
 990         BUGMSG(D_INIT,"Resetting %s (status=%Xh)\n",
 991                         dev->name,inb(STATUS));
 992 
 993         inb(RESET);             /* Reset by reading this port */
 994         JIFFER(RESETtime);
 995 
 996         outb(CFLAGScmd|RESETclear, COMMAND); /* clear flags & end reset */
 997         outb(CFLAGScmd|CONFIGclear,COMMAND);
 998 
 999         /* after a reset, the first byte of shared mem is TESTvalue and the
1000          * second byte is our 8-bit ARCnet address.
1001          */
1002         cardmem = (u_char *) dev->mem_start;
1003         if (cardmem[0] != TESTvalue)
1004         {
1005                 BUGMSG(D_INIT,"reset failed: TESTvalue not present.\n");
1006                 return 1;
1007         }
1008         lp->arcnum=cardmem[1];  /* save address for later use */
1009         
1010         /* clear out status variables */
1011         recbuf=lp->recbuf=0;
1012         lp->txbuf=2;
1013 
1014         /* enable extended (512-byte) packets */
1015         outb(CONFIGcmd|EXTconf,COMMAND);
1016         
1017         /* clean out all the memory to make debugging make more sense :) */
1018         BUGLVL(D_DURING)
1019                 memset((void *)dev->mem_start,0x42,2048);
1020         
1021         /* and enable receive of our first packet to the first buffer */
1022         EnableReceiver();
1023 
1024         /* re-enable interrupts */
1025         outb(NORXflag|RECON_flag,INTMASK);
1026         
1027         /* done!  return success. */
1028         return 0;
1029 }
1030 
1031 
1032 /* Setup a struct device for ARCnet.  This should really be in net_init.c
1033  * but since there are three different ARCnet devices ANYWAY... <gargle>
1034  *
1035  * Actually, the whole idea of having all this kernel-dependent stuff (ie.
1036  * "new-style flags") setup per-net-device is kind of weird anyway.
1037  *
1038  * Intelligent defaults?!  Nah.
1039  */
1040 void arcnet_setup(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1041 {
1042         int i;
1043         for (i=0; i<DEV_NUMBUFFS; i++)
1044                 skb_queue_head_init(&dev->buffs[i]);
1045 
1046         dev->broadcast[0]=0x00; /* broadcasts on ARCnet are address 0 */
1047         dev->addr_len=1;
1048         dev->type=ARPHRD_ARCNET;
1049 
1050         /* New-style flags. */
1051         dev->flags      = IFF_BROADCAST;
1052         dev->family     = AF_INET;
1053         dev->pa_addr    = 0;
1054         dev->pa_brdaddr = 0;
1055         dev->pa_mask    = 0;
1056         dev->pa_alen    = 4;
1057 }
1058 
1059 
1060 /* Initialize the arc0e device.
1061  */
1062 static int arcnetE_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1063 {
1064         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1065 
1066         ether_setup(dev); /* we're emulating ether here, not ARCnet */
1067         dev->dev_addr[0]=0;
1068         dev->dev_addr[5]=lp->arcnum;
1069         dev->mtu=512-sizeof(struct HardHeader)-dev->hard_header_len-1;
1070         dev->open=NULL;
1071         dev->stop=NULL;
1072         dev->hard_start_xmit=arcnetE_send_packet;
1073 
1074         BUGMSG(D_EXTRA,"ARCnet Ethernet-Encap protocol initialized.\n");
1075                         
1076         return 0;
1077 }
1078 
1079 /* Initialize the arc0s device.
1080  */
1081 static int arcnetS_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1082 {
1083         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1084 
1085         arcnet_setup(dev);
1086        
1087         /* And now fill particular fields with arcnet values */
1088         dev->dev_addr[0]=lp->arcnum;
1089         dev->hard_header_len=sizeof(struct S_ClientData);
1090         dev->mtu=512-sizeof(struct HardHeader)-dev->hard_header_len
1091                 + S_EXTRA_CLIENTDATA;
1092         dev->open=NULL;
1093         dev->stop=NULL;
1094         dev->hard_start_xmit=arcnetS_send_packet;
1095         dev->hard_header=arcnetS_header;
1096         dev->rebuild_header=arcnetS_rebuild_header;
1097 #ifdef LINUX12
1098         dev->type_trans=arcnetS_type_trans;
1099 #endif
1100         BUGMSG(D_EXTRA,"ARCnet RFC1051 (NetBsd, AmiTCP) protocol initialized.\n");
1101 
1102         return 0;
1103 }
1104 
1105 
1106 /****************************************************************************
1107  *                                                                          *
1108  * Open and close the driver                                                *
1109  *                                                                          *
1110  ****************************************************************************/
1111  
1112 
1113 /* Open/initialize the board.  This is called sometime after booting when
1114  * the 'ifconfig' program is run.
1115  *
1116  * This routine should set everything up anew at each open, even
1117  * registers that "should" only need to be set once at boot, so that
1118  * there is non-reboot way to recover if something goes wrong.
1119  */
1120 static int
1121 arcnet_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1122 {
1123         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1124         int ioaddr=dev->base_addr,delayval;
1125         
1126         if (dev->metric>=1000)
1127         {
1128                 arcnet_debug=dev->metric-1000;
1129                 printk("%6s: debug level set to %d\n",dev->name,arcnet_debug);
1130                 dev->metric=1;
1131         }
1132 
1133         BUGLVL(D_EXTRA) printk(version);
1134 
1135         irq2dev_map[dev->irq] = dev;
1136 
1137         BUGMSG(D_EXTRA,"arcnet_open: resetting card.\n");
1138         
1139         /* try to reset - twice if it fails the first time */
1140         if (arcnet_reset(dev) && arcnet_reset(dev))
1141                 return -ENODEV;
1142         
1143         dev->tbusy=0;
1144         dev->interrupt=0;
1145         lp->intx=0;
1146         lp->in_txhandler=0;
1147         
1148         /* The RFC1201 driver is the default - just store */
1149         lp->adev=dev;
1150         BUGMSG(D_EXTRA,"ARCnet RFC1201 protocol initialized.\n");
1151         
1152         /* Initialize the ethernet-encap protocol driver */
1153         lp->edev=(struct device *)kmalloc(sizeof(struct device),GFP_KERNEL);
1154         if (lp->edev == NULL)
1155                 return -ENOMEM;
1156         memcpy(lp->edev,dev,sizeof(struct device));
1157         lp->edev->name=(char *)kmalloc(10,GFP_KERNEL);
1158         if (lp->edev->name == NULL) {
1159                 kfree(lp->edev);
1160                 lp->edev = NULL;
1161                 return -ENOMEM;
1162         }
1163         sprintf(lp->edev->name,"%se",dev->name);
1164         lp->edev->init=arcnetE_init;
1165         register_netdev(lp->edev);
1166 
1167         /* Initialize the RFC1051-encap protocol driver */
1168         lp->sdev=(struct device *)kmalloc(sizeof(struct device),GFP_KERNEL);
1169         memcpy(lp->sdev,dev,sizeof(struct device));
1170         lp->sdev->name=(char *)kmalloc(10,GFP_KERNEL);
1171         sprintf(lp->sdev->name,"%ss",dev->name);
1172         lp->sdev->init=arcnetS_init;
1173         register_netdev(lp->sdev);
1174 
1175         /* we're started */
1176         START=1;
1177         
1178         /* make sure we're ready to receive IRQ's.
1179          * arcnet_reset sets this for us, but if we receive one before
1180          * START is set to 1, bad things happen.
1181          */
1182         outb(0,INTMASK);
1183         JIFFER(ACKtime);
1184         outb(NORXflag|RECON_flag,INTMASK);
1185         
1186         MOD_INC_USE_COUNT;
1187         return 0;
1188 }
1189 
1190 
1191 /* The inverse routine to arcnet_open - shuts down the card.
1192  */
1193 static int
1194 arcnet_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1195 {
1196         int ioaddr = dev->base_addr;
1197         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1198         
1199         TBUSY=1;
1200         START=0;
1201         
1202         /* very important! */
1203         irq2dev_map[dev->irq] = NULL;
1204 
1205         
1206         /* Flush TX and disable RX */
1207         outb(0,INTMASK);        /* no IRQ's (except RESET, of course) */
1208         outb(NOTXcmd,COMMAND);  /* stop transmit */
1209         outb(NORXcmd,COMMAND);  /* disable receive */
1210         
1211         /* reset more flags */
1212         INTERRUPT=0;
1213         
1214         /* do NOT free lp->adev!!  It's static! */
1215         lp->adev=NULL;
1216         
1217         /* free the ethernet-encap protocol device */
1218         lp->edev->priv=NULL;
1219         dev_close(lp->edev);
1220         unregister_netdev(lp->edev);
1221         kfree(lp->edev->name);
1222         kfree(lp->edev);
1223         lp->edev=NULL;
1224 
1225         /* free the RFC1051-encap protocol device */
1226         lp->sdev->priv=NULL;
1227         dev_close(lp->sdev);
1228         unregister_netdev(lp->sdev);
1229         kfree(lp->sdev->name);
1230         kfree(lp->sdev);
1231         lp->sdev=NULL;
1232 
1233         /* Update the statistics here. (not necessary in ARCnet) */
1234 
1235         MOD_DEC_USE_COUNT;
1236         return 0;
1237 }
1238 
1239 
1240 
1241 /****************************************************************************
1242  *                                                                          *
1243  * Transmitter routines                                                     *
1244  *                                                                          *
1245  ****************************************************************************/
1246 
1247 /* Generic error checking routine for arcnet??_send_packet
1248  */
1249 static int
1250 arcnet_send_packet_bad(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1251 {
1252         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1253         int ioaddr=dev->base_addr;
1254         
1255         BUGMSG(D_DURING,"transmit requested (status=%Xh, inTX=%d)\n",
1256                         inb(STATUS),lp->intx);
1257                         
1258         if (lp->in_txhandler)
1259         {
1260                 BUGMSG(D_NORMAL,"send_packet called while in txhandler!\n");
1261                 lp->stats.tx_dropped++;
1262                 return 1;
1263         }
1264 
1265         if (lp->intx>1)
1266         {
1267                 BUGMSG(D_NORMAL,"send_packet called while intx!\n");
1268                 lp->stats.tx_dropped++;
1269                 return 1;
1270         }
1271 
1272         if (IF_TBUSY)
1273         {
1274                 /* If we get here, some higher level has decided we are broken.
1275                    There should really be a "kick me" function call instead. */
1276                 int tickssofar = jiffies - dev->trans_start;
1277                 /*int recbuf=lp->recbuf;*/
1278                 int status=inb(STATUS);
1279                 
1280                 if (tickssofar < TX_TIMEOUT) 
1281                 {
1282                         BUGMSG(D_DURING,"premature kickme! (status=%Xh ticks=%d o.skb=%ph numsegs=%d segnum=%d\n",
1283                                         status,tickssofar,lp->outgoing.skb,
1284                                         lp->outgoing.numsegs,
1285                                         lp->outgoing.segnum);
1286                         return 1;
1287                 }
1288 
1289                 outb(0,INTMASK);
1290 
1291                 if (status&TXFREEflag)  /* transmit _DID_ finish */
1292                 {
1293                         BUGMSG(D_EXTRA,"tx timed out - missed IRQ? (status=%Xh, inTX=%d, inTXh=%d, tickssofar=%d)\n",
1294                                         status,lp->intx,
1295                                         lp->in_txhandler,tickssofar);
1296                         lp->stats.tx_errors++;
1297                 }
1298                 else
1299                 {
1300                         BUGMSG(D_NORMAL,"tx timed out (status=%Xh, inTX=%d, inTXh=%d, tickssofar=%d)\n",
1301                                         status,lp->intx,
1302                                         lp->in_txhandler,tickssofar);
1303                         lp->stats.tx_errors++;
1304                         lp->stats.tx_aborted_errors++;
1305 
1306                         outb(NOTXcmd,COMMAND);
1307                 }
1308 
1309                 if (lp->outgoing.skb)
1310                 {
1311                         dev_kfree_skb(lp->outgoing.skb,FREE_WRITE);
1312                         lp->stats.tx_dropped++;
1313                 }
1314                 lp->outgoing.skb=NULL;
1315                 
1316                 TBUSY=0;
1317                 lp->txready=0;
1318                 lp->sending=0;
1319 
1320                 outb(NORXflag|RECON_flag,INTMASK);
1321 
1322                 return 1;
1323         }
1324 
1325         /* If some higher layer thinks we've missed a tx-done interrupt
1326            we are passed NULL. Caution: dev_tint() handles the cli()/sti()
1327            itself. */
1328         if (skb == NULL) {
1329                 printk("%6s: tx passed null skb (status=%Xh, inTX=%d, tickssofar=%ld)\n",
1330                         dev->name,inb(STATUS),lp->intx,jiffies-dev->trans_start);
1331                 lp->stats.tx_errors++;
1332                 dev_tint(dev);
1333                 return 0;
1334         }
1335         
1336         if (lp->txready)        /* transmit already in progress! */
1337         {
1338                 printk("%6s: trying to start new packet while busy! (status=%Xh)\n",
1339                         dev->name,inb(STATUS));
1340                 outb(0,INTMASK);
1341                 outb(NOTXcmd,COMMAND); /* abort current send */
1342                 arcnet_inthandler(dev); /* fake an interrupt */
1343                 lp->stats.tx_errors++;
1344                 lp->stats.tx_fifo_errors++;
1345                 lp->txready=0;  /* we definitely need this line! */
1346                 
1347                 return 1;
1348         }
1349 
1350         /* Block a timer-based transmit from overlapping.  This could better be
1351            done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
1352         if (set_bit(0, (void*)&dev->tbusy) != 0)
1353         {
1354             printk("%6s: transmitter called with busy bit set! (status=%Xh, inTX=%d, tickssofar=%ld)\n",
1355                         dev->name,inb(STATUS),lp->intx,jiffies-dev->trans_start);
1356             lp->stats.tx_errors++;
1357             lp->stats.tx_fifo_errors++;
1358             return -EBUSY;
1359         }
1360 
1361         return 0;
1362 }
1363 
1364 
1365 /* Called by the kernel in order to transmit a packet.
1366  */
1367 static int
1368 arcnetA_send_packet(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1369 {
1370         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1371         int ioaddr=dev->base_addr,bad;
1372         struct Outgoing *out=&(lp->outgoing);
1373 
1374         BUGMSG(D_DURING,"transmit requested (status=%Xh, inTX=%d)\n",
1375                         inb(STATUS),lp->intx);
1376 
1377         lp->intx++;
1378         
1379         bad=arcnet_send_packet_bad(skb,dev);
1380         if (bad)
1381         {
1382                 lp->intx--;
1383                 return bad;
1384         }
1385         
1386         TBUSY=1;
1387                 
1388         out->length = 1 < skb->len ? skb->len : 1;
1389         out->hdr=(struct ClientData*)skb->data;
1390         out->skb=skb;
1391                 
1392         BUGLVL(D_SKB)
1393         {
1394                 short i;
1395                 for( i=0; i< skb->len; i++)
1396                 {
1397                         if( i%16 == 0 ) printk("\n[%04hX] ",i);
1398                         printk("%02hX ",((unsigned char*)skb->data)[i]);
1399                 }
1400                 printk("\n");
1401         }
1402 
1403         out->hdr->sequence=(lp->sequence++);
1404         
1405         /*arcnet_go_tx(dev);*/  /* Make sure buffers are clear */
1406 
1407         /* fits in one packet? */
1408         if (out->length-EXTRA_CLIENTDATA<=XMTU)
1409         {
1410                 BUGMSG(D_DURING,"not splitting %d-byte packet. (split_flag=%d)\n",
1411                                 out->length,out->hdr->split_flag);
1412                 BUGLVL(D_EXTRA) if (out->hdr->split_flag)
1413                         printk("%6s: short packet has split_flag set?! (split_flag=%d)\n",
1414                                 dev->name,out->hdr->split_flag);
1415                 out->numsegs=1;
1416                 out->segnum=1;
1417                 arcnetAS_prepare_tx(dev,
1418                         ((char *)out->hdr)+EXTRA_CLIENTDATA,
1419                         sizeof(struct ClientData)-EXTRA_CLIENTDATA,
1420                         ((char *)skb->data)+sizeof(struct ClientData),
1421                         out->length-sizeof(struct ClientData),
1422                         out->hdr->daddr,1);
1423 
1424                 /* done right away */
1425                 dev_kfree_skb(out->skb,FREE_WRITE);
1426                 out->skb=NULL;
1427                                         
1428                 if (arcnet_go_tx(dev,1))
1429                 {
1430                         /* inform upper layers */
1431                         TBUSY=0;
1432                         mark_bh(NET_BH);
1433                 }
1434         }
1435         else                    /* too big for one - split it */
1436         {
1437                 int maxsegsize=XMTU-4;
1438 
1439                 out->data=(u_char *)skb->data
1440                                 + sizeof(struct ClientData);
1441                 out->dataleft=out->length-sizeof(struct ClientData);
1442                 out->numsegs=(out->dataleft+maxsegsize-1)/maxsegsize;
1443                                 
1444                 out->segnum=0;
1445                         
1446                 BUGMSG(D_TX,"packet (%d bytes) split into %d fragments:\n",
1447                         out->length,out->numsegs);
1448 
1449                 /* if a packet waiting, launch it */
1450                 arcnet_go_tx(dev,1);
1451 
1452                 if (!lp->txready)
1453                 {
1454                         /* prepare a packet, launch it and prepare
1455                          * another.
1456                          */
1457                         arcnetA_continue_tx(dev);
1458                         if (arcnet_go_tx(dev,1))
1459                         {
1460                                 arcnetA_continue_tx(dev);
1461                                 arcnet_go_tx(dev,1);
1462                         }
1463                 }
1464                 
1465                 /* if segnum==numsegs, the transmission is finished;
1466                  * free the skb right away.
1467                  */
1468                 if (out->segnum==out->numsegs)
1469                 {
1470                         /* transmit completed */
1471                         out->segnum++;
1472                         if (out->skb)
1473                                 dev_kfree_skb(out->skb,FREE_WRITE);
1474                         out->skb=NULL;
1475                 }
1476         }
1477 
1478         dev->trans_start=jiffies;
1479         lp->intx--;
1480         return 0;
1481 }
1482 
1483 
1484 /* Called by the kernel in order to transmit an ethernet-type packet.
1485  */
1486 static int
1487 arcnetE_send_packet(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1488 {
1489         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1490         int bad;
1491         union ArcPacket *arcpacket = 
1492                 (union ArcPacket *)(dev->mem_start+512*(lp->txbuf^1));
1493         u_char *arcsoft,daddr;
1494         short offset,length=skb->len+1;
1495 
1496         BUGMSG(D_DURING,"in arcnetE_send_packet (skb=%p)\n",skb);
1497                 
1498         lp->intx++;
1499         
1500         bad=arcnet_send_packet_bad(skb,dev);
1501         if (bad)
1502         {
1503                 lp->intx--;
1504                 return bad;
1505         }
1506 
1507         TBUSY=1;
1508                 
1509         if (length>XMTU)
1510         {
1511                 printk("%6s: MTU must be <= 493 for ethernet encap (length=%d).\n",
1512                         dev->name,length);
1513                 printk("%6s: transmit aborted.\n",dev->name);
1514 
1515                 dev_kfree_skb(skb,FREE_WRITE);
1516                 return 0;
1517         }
1518                 
1519         BUGMSG(D_DURING,"starting tx sequence...\n");
1520 
1521         lp->txbuf=lp->txbuf^1; /* XOR with 1 to alternate btw 2 & 3 */
1522 
1523         /* clean out the page to make debugging make more sense :) */
1524         BUGLVL(D_DURING)
1525                 memset((void *)dev->mem_start+lp->txbuf*512,0x42,512);
1526 
1527         /* broadcasts have address FF:FF:FF:FF:FF:FF in etherspeak */
1528         if (((struct ethhdr*)(skb->data))->h_dest[0] == 0xFF)
1529                 daddr=arcpacket->hardheader.destination=0;
1530         else
1531                 daddr=arcpacket->hardheader.destination=
1532                         ((struct ethhdr*)(skb->data))->h_dest[5];
1533 
1534         /* load packet into shared memory */
1535         offset=512-length;
1536         if (length>MTU)         /* long/exception packet */
1537         {
1538                 if (length<MinTU) offset-=3;
1539                 arcpacket->hardheader.offset1=0;
1540                 arcpacket->hardheader.offset2=offset;
1541         }
1542         else                    /* short packet */
1543         {
1544                 arcpacket->hardheader.offset1=(offset-=256);
1545         }
1546         
1547         BUGMSG(D_DURING," length=%Xh, offset=%Xh, offset1=%Xh, offset2=%Xh\n",
1548                         length,offset,arcpacket->hardheader.offset1,
1549                         arcpacket->hardheader.offset2);
1550         
1551         arcsoft=&arcpacket->raw[offset];
1552         arcsoft[0]=ARC_P_ETHER;
1553         arcsoft++;
1554                 
1555         /* copy the packet into ARCnet shmem
1556          *  - the first bytes of ClientData header are skipped
1557          */
1558         BUGMSG(D_DURING,"ready to memcpy\n");
1559         
1560         memcpy(arcsoft,skb->data,skb->len);
1561                 
1562         BUGMSG(D_DURING,"transmitting packet to station %02Xh (%d bytes)\n",
1563                         daddr,length);
1564                                 
1565         BUGLVL(D_TX)
1566         {
1567                 int countx,county;
1568                         
1569                 printk("%6s: packet dump [tx] follows:",dev->name);
1570 
1571                 for (county=0; county<16+(length>=240)*16; county++)
1572                 {
1573                         printk("\n[%04X] ",county*16);
1574                         for (countx=0; countx<16; countx++)
1575                                 printk("%02X ",
1576                                         arcpacket->raw[county*16+countx]);
1577                 }
1578                 
1579                 printk("\n");
1580         }
1581 
1582 #ifdef VERIFY_ACK
1583         lp->outgoing.lastload_dest=daddr;
1584 #endif
1585         lp->txready=lp->txbuf;  /* packet is ready for sending */
1586 
1587         dev_kfree_skb(skb,FREE_WRITE);
1588 
1589         if (arcnet_go_tx(dev,1))
1590         {
1591                 /* inform upper layers */
1592                 TBUSY=0;
1593                 mark_bh(NET_BH);
1594         }
1595 
1596         dev->trans_start=jiffies;
1597         lp->intx--;
1598         return 0;
1599 }
1600 
1601 
1602 /* Called by the kernel in order to transmit an RFC1051-type packet.
1603  */
1604 static int
1605 arcnetS_send_packet(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1606 {
1607         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1608         int ioaddr=dev->base_addr,bad,length;
1609         struct S_ClientData *hdr=(struct S_ClientData *)skb->data;
1610 
1611         lp->intx++;
1612         
1613         BUGMSG(D_DURING,"transmit requested (status=%Xh, inTX=%d)\n",
1614                         inb(STATUS),lp->intx);
1615 
1616         bad=arcnet_send_packet_bad(skb,dev);
1617         if (bad)
1618         {
1619                 lp->intx--;
1620                 return bad;
1621         }
1622         
1623         TBUSY=1;
1624 
1625         length = 1 < skb->len ? skb->len : 1;
1626 
1627         BUGLVL(D_SKB)
1628         {
1629                 short i;
1630                 for(i=0; i<skb->len; i++)
1631                 {
1632                         if( i%16 == 0 ) printk("\n[%04hX] ",i);
1633                         printk("%02hX ",((unsigned char*)skb->data)[i]);
1634                 }
1635                 printk("\n");
1636         }
1637 
1638         /*if (lp->txready && inb(STATUS)&TXFREEflag)
1639                 arcnet_go_tx(dev);*/
1640 
1641         /* fits in one packet? */
1642         if (length-S_EXTRA_CLIENTDATA<=XMTU)
1643         {
1644                 arcnetAS_prepare_tx(dev,
1645                         skb->data+S_EXTRA_CLIENTDATA,
1646                         sizeof(struct S_ClientData)-S_EXTRA_CLIENTDATA,
1647                         skb->data+sizeof(struct S_ClientData),
1648                         length-sizeof(struct S_ClientData),
1649                         hdr->daddr,0);
1650 
1651                 /* done right away */
1652                 dev_kfree_skb(skb,FREE_WRITE);
1653                                 
1654                 if (arcnet_go_tx(dev,1))
1655                 {
1656                         /* inform upper layers */
1657                         TBUSY=0;
1658                         mark_bh(NET_BH);
1659                 }
1660         }
1661         else                    /* too big for one - not accepted */
1662         {
1663                 printk("arcnetS: packet too long (length=%d)\n",
1664                         length);
1665                 dev_kfree_skb(skb,FREE_WRITE);
1666                 lp->stats.tx_dropped++;
1667                 TBUSY=0;
1668                 mark_bh(NET_BH);        
1669         }
1670 
1671         dev->trans_start=jiffies;
1672         lp->intx--;
1673         return 0;
1674 }
1675 
1676 
1677 /* After an RFC1201 split packet has been set up, this function calls
1678  * arcnetAS_prepare_tx to load the next segment into the card.  This function
1679  * does NOT automatically call arcnet_go_tx.
1680  */
1681 static void arcnetA_continue_tx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1682 {
1683         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1684         int maxsegsize=XMTU-4;
1685         struct Outgoing *out=&(lp->outgoing);
1686         
1687         if (lp->txready)
1688         {
1689                 printk("%6s: continue_tx: called with packet in buffer!\n",
1690                         dev->name);
1691                 return;
1692         }
1693 
1694         if (out->segnum>=out->numsegs)
1695         {
1696                 printk("%6s: continue_tx: building segment %d of %d!\n",
1697                         dev->name,out->segnum+1,out->numsegs);
1698         }
1699 
1700         if (!out->segnum)       /* first packet */
1701                 out->hdr->split_flag=((out->numsegs-2)<<1)+1;
1702         else
1703                 out->hdr->split_flag=out->segnum<<1;
1704 
1705         out->seglen=maxsegsize;
1706         if (out->seglen>out->dataleft) out->seglen=out->dataleft;
1707                         
1708         BUGMSG(D_TX,"building packet #%d (%d bytes) of %d (%d total), splitflag=%d\n",
1709                 out->segnum+1,out->seglen,out->numsegs,
1710                 out->length,out->hdr->split_flag);
1711 
1712         arcnetAS_prepare_tx(dev,((char *)out->hdr)+EXTRA_CLIENTDATA,
1713                 sizeof(struct ClientData)-EXTRA_CLIENTDATA,
1714                 out->data,out->seglen,out->hdr->daddr,1);
1715                 
1716         out->dataleft-=out->seglen;
1717         out->data+=out->seglen;
1718         out->segnum++;
1719 }
1720 
1721 
1722 /* Given an skb, copy a packet into the ARCnet buffers for later transmission
1723  * by arcnet_go_tx.
1724  */
1725 static void
1726 arcnetAS_prepare_tx(struct device *dev,u_char *hdr,int hdrlen,
     /* [previous][next][first][last][top][bottom][index][help] */
1727                 char *data,int length,int daddr,int exceptA)
1728 {
1729         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1730         struct ClientData *arcsoft;
1731         union ArcPacket *arcpacket = 
1732                 (union ArcPacket *)(dev->mem_start+512*(lp->txbuf^1));
1733         int offset;
1734         
1735         lp->txbuf=lp->txbuf^1;  /* XOR with 1 to alternate between 2 and 3 */
1736         
1737         length+=hdrlen;
1738 
1739         BUGMSG(D_TX,"arcnetAS_prep_tx: hdr:%ph, length:%d, data:%ph\n",
1740                         hdr,length,data);
1741 
1742         /* clean out the page to make debugging make more sense :) */
1743         BUGLVL(D_DURING)
1744                 memset((void *)dev->mem_start+lp->txbuf*512,0x42,512);
1745 
1746         arcpacket->hardheader.destination=daddr;
1747 
1748         /* load packet into shared memory */
1749         if (length<=MTU)        /* Normal (256-byte) Packet */
1750         {
1751                 arcpacket->hardheader.offset1=offset=256-length;
1752                 arcsoft=(struct ClientData *)
1753                         (&arcpacket->raw[offset]);
1754         }
1755         else if (length>=MinTU) /* Extended (512-byte) Packet */
1756         {
1757                 arcpacket->hardheader.offset1=0;
1758                 arcpacket->hardheader.offset2=offset=512-length;
1759                 
1760                 arcsoft=(struct ClientData *)
1761                         (&arcpacket->raw[offset]);
1762         }
1763         else if (exceptA)               /* RFC1201 Exception Packet */
1764         {
1765                 arcpacket->hardheader.offset1=0;
1766                 arcpacket->hardheader.offset2=offset=512-length-4;
1767                 arcsoft=(struct ClientData *)
1768                         (&arcpacket->raw[offset+4]);
1769                 
1770                 /* exception-specific stuff - these four bytes
1771                  * make the packet long enough to fit in a 512-byte
1772                  * frame.
1773                  */
1774                 arcpacket->raw[offset+0]=hdr[0];
1775                 arcpacket->raw[offset+1]=0xFF; /* FF flag */
1776                         arcpacket->raw[offset+2]=0xFF; /* FF padding */
1777                         arcpacket->raw[offset+3]=0xFF; /* FF padding */
1778         }
1779         else                            /* "other" Exception packet */
1780         {
1781                 /* RFC1051 - set 4 trailing bytes to 0 */
1782                 memset(&arcpacket->raw[508],0,4);
1783 
1784                 /* now round up to MinTU */
1785                 arcpacket->hardheader.offset1=0;
1786                 arcpacket->hardheader.offset2=offset=512-MinTU;
1787                 arcsoft=(struct ClientData *)(&arcpacket->raw[offset]);
1788         }
1789 
1790 
1791         /* copy the packet into ARCnet shmem
1792          *  - the first bytes of ClientData header are skipped
1793          */
1794         memcpy((u_char*)arcsoft,
1795                 (u_char*)hdr,hdrlen);
1796         memcpy((u_char*)arcsoft+hdrlen,
1797                 data,length-hdrlen);
1798                 
1799         BUGMSG(D_DURING,"transmitting packet to station %02Xh (%d bytes)\n",
1800                         daddr,length);
1801                         
1802         BUGLVL(D_TX)
1803         {
1804                 int countx,county;
1805                 
1806                 printk("%6s: packet dump [tx] follows:",dev->name);
1807 
1808                 for (county=0; county<16+(length>MTU)*16; county++)
1809                 {
1810                         printk("\n[%04X] ",county*16);
1811                         for (countx=0; countx<16; countx++)
1812                                 printk("%02X ",
1813                                         arcpacket->raw[county*16+countx]);
1814                 }
1815                 
1816                 printk("\n");
1817         }
1818 
1819 #ifdef VERIFY_ACK
1820         lp->outgoing.lastload_dest=daddr;
1821 #endif
1822         lp->txready=lp->txbuf;  /* packet is ready for sending */
1823 }
1824 
1825 /* Actually start transmitting a packet that was placed in the card's
1826  * buffer by arcnetAS_prepare_tx.  Returns 1 if a Tx is really started.
1827  */
1828 static int
1829 arcnet_go_tx(struct device *dev,int enable_irq)
     /* [previous][next][first][last][top][bottom][index][help] */
1830 {
1831         struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
1832         int ioaddr=dev->base_addr;
1833 
1834         BUGMSG(D_DURING,"go_tx: status=%Xh\n",
1835                         inb(STATUS));
1836                         
1837         outb(0,INTMASK);
1838 
1839         if (lp->sending || !lp->txready)
1840         {
1841                 if (enable_irq)
1842                 {
1843                         if (lp->sending)
1844                                 outb(TXFREEflag|NORXflag|RECON_flag,INTMASK);
1845                         else
1846                                 outb(NORXflag|RECON_flag,INTMASK);
1847                 }
1848                 return 0;
1849         }
1850 
1851         /* start sending */
1852         outb(TXcmd|(lp->txready<<3),COMMAND);
1853 
1854         lp->stats.tx_packets++;
1855         lp->txready=0;
1856         lp->sending++;
1857 
1858 #ifdef VERIFY_ACK       
1859         lp->outgoing.lasttrans_dest=lp->outgoing.lastload_dest;
1860         lp->outgoing.lastload_dest=0;
1861 #endif
1862 
1863         if (enable_irq)
1864                 outb(TXFREEflag|NORXflag|RECON_flag,INTMASK);
1865 
1866         return 1;
1867 }
1868 
1869 
1870 /****************************************************************************
1871  *                                                                          *
1872  * Interrupt handler                                                        *
1873  *                                                                          *
1874  ****************************************************************************/
1875 
1876 
1877 /* The typical workload of the driver:  Handle the network interface
1878  * interrupts.  This doesn't do much right now except call arcnet_inthandler,
1879  * which takes different parameters but may be called from other places
1880  * as well.
1881  */
1882 static void
1883 arcnet_interrupt(int irq,struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
1884 {
1885         struct device *dev = (struct device *)(irq2dev_map[irq]);
1886 
1887         if (dev==NULL)
1888         {
1889                 BUGLVL(D_EXTRA)
1890                         printk("arcnet: irq %d for unknown device.\n", irq);
1891                 return;
1892         }
1893         
1894         if (!dev->start) return;
1895 
1896         arcnet_inthandler(dev);
1897 }
1898 
1899 
1900 /* The actual interrupt handler routine - handle various IRQ's generated
1901  * by the card.
1902  */
1903 static void
1904 arcnet_inthandler(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1905 {       
1906         struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
1907         int ioaddr=dev->base_addr, status, boguscount = 3, didsomething;
1908 
1909         if (IF_INTERRUPT)
1910         {
1911                 printk("%6s: DRIVER PROBLEM!  Nested arcnet interrupts!\n",
1912                         dev->name);
1913                 return; /* don't even try. */
1914         }
1915         outb(0,INTMASK);
1916         INTERRUPT = 1;
1917 
1918         BUGMSG(D_DURING,"in net_interrupt (status=%Xh)\n",inb(STATUS));
1919                 
1920 #if 1 /* Whatever you do, don't set this to 0. */
1921         do
1922         {
1923                 status = inb(STATUS);
1924                 didsomething=0;
1925         
1926 #if 0 /* no longer necessary - doing checking in arcnet_interrupt now */
1927                 if (!dev->start)
1928                 {
1929                         BUGMSG(D_DURING,"ARCnet not yet initialized.  irq ignored. (status=%Xh)\n",
1930                                         status);
1931                         if (!(status&NORXflag))
1932                                 outb(NORXflag|RECON_flag,INTMASK);
1933 
1934                         /* using dev->interrupt here instead of INTERRUPT
1935                          * because if dev->start is 0, the other devices
1936                          * probably do not exist.
1937                          */
1938                         dev->interrupt=0;
1939                         return;
1940                 }
1941 #endif
1942         
1943                 /* RESET flag was enabled - card is resetting and if RX
1944                  * is disabled, it's NOT because we just got a packet.
1945                  */
1946                 if (status & RESETflag)
1947                 {
1948                         outb(CFLAGScmd|RESETclear,COMMAND);
1949                         BUGMSG(D_INIT,"reset irq (status=%Xh)\n",
1950                                         status);
1951                 }
1952 #ifdef DETECT_RECONFIGS
1953                 if (status & RECONflag)
1954                 {
1955                         outb(CFLAGScmd|CONFIGclear,COMMAND);
1956                         lp->stats.tx_carrier_errors++;
1957                         
1958                         #ifdef SHOW_RECONFIGS
1959                         BUGMSG(D_NORMAL,"Network reconfiguration detected (status=%Xh)\n",
1960                                         status);
1961                         #endif /* SHOW_RECONFIGS */
1962                         
1963                         #ifdef RECON_THRESHOLD
1964                         /* is the RECON info empty or old? */
1965                         if (!lp->first_recon || !lp->last_recon || 
1966                                 jiffies-lp->last_recon > HZ*10)
1967                         {
1968                                 if (lp->network_down)
1969                                         printk("%6s: reconfiguration detected: cabling restored?\n",
1970                                                 dev->name);
1971                                 lp->first_recon=lp->last_recon=jiffies;
1972                                 lp->num_recons=lp->network_down=0;
1973                                 
1974                                 BUGMSG(D_DURING,"recon: clearing counters.\n");
1975                         }
1976                         else /* add to current RECON counter */
1977                         {
1978                                 lp->last_recon=jiffies;
1979                                 lp->num_recons++;
1980                                 
1981                                 BUGMSG(D_DURING,"recon: counter=%d, time=%lds, net=%d\n",
1982                                         lp->num_recons,
1983                                         (lp->last_recon-lp->first_recon)/HZ,
1984                                         lp->network_down);
1985 
1986                                 /* if network is marked up;
1987                                  * and first_recon and last_recon are 60+ sec
1988                                  *   apart;
1989                                  * and the average no. of recons counted is
1990                                  *   > RECON_THRESHOLD/min;
1991                                  * then print a warning message.
1992                                  */
1993                                 if (!lp->network_down
1994                                     && (lp->last_recon-lp->first_recon)<=HZ*60
1995                                     && lp->num_recons >= RECON_THRESHOLD)
1996                                 {
1997                                         lp->network_down=1;
1998                                         printk("%6s: many reconfigurations detected: cabling problem?\n",
1999                                                 dev->name);
2000                                 }
2001                                 else if (!lp->network_down
2002                                     && lp->last_recon-lp->first_recon > HZ*60)
2003                                 {
2004                                         /* reset counters if we've gone for
2005                                          * over a minute.
2006                                          */
2007                                         lp->first_recon=lp->last_recon;
2008                                         lp->num_recons=1;
2009                                 }
2010                         }
2011                         #endif
2012                 }
2013                 #ifdef RECON_THRESHOLD
2014                 else if (lp->network_down && jiffies-lp->last_recon > HZ*10)
2015                 {
2016                         if (lp->network_down)
2017                                 printk("%6s: cabling restored?\n",dev->name);
2018                         lp->first_recon=lp->last_recon=0;
2019                         lp->num_recons=lp->network_down=0;
2020                         
2021                         BUGMSG(D_DURING,"not recon: clearing counters anyway.\n");
2022                 }
2023                 #endif
2024 #endif /* DETECT_RECONFIGS */
2025 
2026                 /* RX is inhibited - we must have received something. */
2027                 if (status & NORXflag)
2028                 {
2029                         int recbuf=lp->recbuf=!lp->recbuf;
2030 
2031                         BUGMSG(D_DURING,"receive irq (status=%Xh)\n",
2032                                         status);
2033 
2034                         /* enable receive of our next packet */
2035                         EnableReceiver();
2036 
2037                         /* Got a packet. */
2038                         arcnet_rx(dev,!recbuf);
2039                         didsomething++;
2040                 }
2041                 
2042                 /* it can only be an xmit-done irq if we're xmitting :) */
2043                 if (status&TXFREEflag && !lp->in_txhandler && lp->sending)
2044                 {
2045                         struct Outgoing *out=&(lp->outgoing);
2046                         
2047                         lp->in_txhandler++;
2048                         lp->sending--;
2049                         
2050                         BUGMSG(D_DURING,"TX IRQ (stat=%Xh, numsegs=%d, segnum=%d, skb=%ph)\n",
2051                                         status,out->numsegs,out->segnum,out->skb);
2052                                         
2053 #ifdef VERIFY_ACK
2054                         if (!(status&TXACKflag))
2055                         {
2056                                 if (lp->outgoing.lasttrans_dest != 0)
2057                                 {
2058                                         printk("%6s: transmit was not acknowledged! (status=%Xh, dest=%d)\n",
2059                                                 dev->name,status,
2060                                                 lp->outgoing.lasttrans_dest);
2061                                         lp->stats.tx_errors++;
2062                                         lp->stats.tx_carrier_errors++;
2063                                 }
2064                                 else
2065                                 {
2066                                         BUGMSG(D_DURING,"broadcast was not acknowledged; that's normal (status=%Xh, dest=%d)\n",
2067                                                         status,
2068                                                         lp->outgoing.lasttrans_dest);
2069                                 }
2070                         }
2071 #endif
2072                         /* send packet if there is one */
2073                         arcnet_go_tx(dev,0);
2074                         didsomething++;
2075                         
2076                         if (lp->intx)
2077                         {
2078                                 lp->in_txhandler--;
2079                                 continue;
2080                         }
2081 
2082                         if (!lp->outgoing.skb)
2083                         {
2084                                 BUGMSG(D_DURING,"TX IRQ done: no split to continue.\n");
2085                                 
2086                                 /* inform upper layers */
2087                                 if (!lp->txready && IF_TBUSY)
2088                                 {
2089                                         TBUSY=0;
2090                                         mark_bh(NET_BH);
2091                                 }
2092                                 
2093                                 lp->in_txhandler--;
2094                                 continue;
2095                         }
2096                         
2097                         /* if more than one segment, and not all segments
2098                          * are done, then continue xmit.
2099                          */
2100                         if (out->segnum<out->numsegs)
2101                                 arcnetA_continue_tx(dev);
2102                         arcnet_go_tx(dev,0);
2103 
2104                         /* if segnum==numsegs, the transmission is finished;
2105                          * free the skb.
2106                          */
2107                         if (out->segnum>=out->numsegs)
2108                         {
2109                                 /* transmit completed */
2110                                 out->segnum++;
2111                                 if (out->skb)
2112                                         dev_kfree_skb(out->skb,FREE_WRITE);
2113                                 out->skb=NULL;
2114 
2115                                 /* inform upper layers */
2116                                 if (!lp->txready && IF_TBUSY)
2117                                 {
2118                                         TBUSY=0;
2119                                         mark_bh(NET_BH);
2120                                 }
2121                         }
2122                         didsomething++;
2123                         
2124                         lp->in_txhandler--;
2125                 }
2126                 else if (lp->txready && !lp->sending && !lp->intx)
2127                 {
2128                         BUGMSG(D_NORMAL,"recovery from silent TX (status=%Xh)\n",
2129                                                 status);
2130                         arcnet_go_tx(dev,0);
2131                         didsomething++;
2132                 }
2133         } while (--boguscount && didsomething);
2134 
2135         BUGMSG(D_DURING,"net_interrupt complete (status=%Xh, count=%d)\n\n",
2136                         inb(STATUS),boguscount);
2137 
2138         if (dev->start && (lp->sending || (lp->txready && !lp->intx)))
2139                 outb(NORXflag|TXFREEflag|RECON_flag,INTMASK);
2140         else
2141                 outb(NORXflag|RECON_flag,INTMASK);
2142 
2143 #else /* Disable everything */
2144 
2145         outb(RXcmd|(0<<3)|RXbcasts,COMMAND);
2146         outb(NORXflag,INTMASK);
2147 
2148 #endif
2149 
2150         INTERRUPT=0;
2151 }
2152 
2153 
2154 /****************************************************************************
2155  *                                                                          *
2156  * Receiver routines                                                        *
2157  *                                                                          *
2158  ****************************************************************************/
2159 
2160 
2161 /* A packet has arrived; grab it from the buffers and possibly unsplit it.
2162  * This is a generic packet receiver that calls arcnet??_rx depending on the
2163  * protocol ID found.
2164  */
2165 static void
2166 arcnet_rx(struct device *dev,int recbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
2167 {
2168         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2169         int ioaddr = dev->base_addr;
2170         union ArcPacket *arcpacket=
2171                 (union ArcPacket *)(dev->mem_start+recbuf*512);
2172         u_char *arcsoft;
2173         short length,offset;
2174         u_char daddr,saddr;
2175         
2176         lp->stats.rx_packets++;
2177 
2178         saddr=arcpacket->hardheader.source;
2179         daddr=arcpacket->hardheader.destination;
2180         
2181         /* if source is 0, it's a "used" packet! */
2182         if (saddr==0)
2183         {
2184                 printk("%6s: discarding old packet. (status=%Xh)\n",
2185                         dev->name,inb(STATUS));
2186                 lp->stats.rx_errors++;
2187                 return;
2188         }
2189         arcpacket->hardheader.source=0;
2190         
2191         if (arcpacket->hardheader.offset1) /* Normal Packet */
2192         {
2193                 offset=arcpacket->hardheader.offset1;
2194                 arcsoft=&arcpacket->raw[offset];
2195                 length=256-offset;
2196         }
2197         else            /* ExtendedPacket or ExceptionPacket */
2198         {
2199                 offset=arcpacket->hardheader.offset2;
2200                 arcsoft=&arcpacket->raw[offset];
2201 
2202                 length=512-offset;
2203         }
2204         
2205         BUGMSG(D_DURING,"received packet from %02Xh to %02Xh (%d bytes)\n",
2206                         saddr,daddr,length);
2207 
2208         /* call the right receiver for the protocol */
2209         switch (arcsoft[0])
2210         {
2211         case ARC_P_IP:
2212         case ARC_P_ARP:
2213         case ARC_P_RARP:
2214         case ARC_P_IPX:
2215                 arcnetA_rx(lp->adev,arcsoft,length,saddr,daddr);
2216                 break;
2217         case ARC_P_ETHER:
2218                 arcnetE_rx(lp->edev,arcsoft,length,saddr,daddr);
2219                 break;          
2220         case ARC_P_IP_RFC1051:
2221         case ARC_P_ARP_RFC1051:
2222                 arcnetS_rx(lp->sdev,arcsoft,length,saddr,daddr);
2223                 break;
2224         default:
2225                 printk("%6s: received unknown protocol %d (%Xh)\n",
2226                         dev->name,arcsoft[0],arcsoft[0]);
2227                 lp->stats.rx_errors++;
2228                 lp->stats.rx_crc_errors++;
2229                 break;
2230         }
2231 
2232         BUGLVL(D_RX)
2233         {
2234                 int countx,county;
2235                 
2236                 printk("%6s: packet dump [rx] follows:",dev->name);
2237 
2238                 for (county=0; county<16+(length>240)*16; county++)
2239                 {
2240                         printk("\n[%04X] ",county*16);
2241                         for (countx=0; countx<16; countx++)
2242                                 printk("%02X ",
2243                                         arcpacket->raw[county*16+countx]);
2244                 }
2245                 
2246                 printk("\n");
2247         }
2248 
2249 
2250         /* clean out the page to make debugging make more sense :) */
2251         BUGLVL(D_DURING)
2252                 memset((void *)arcpacket->raw,0x42,512);
2253 
2254 
2255         /* If any worth-while packets have been received, a mark_bh(NET_BH)
2256          * has been done by netif_rx and Linux will handle them after we
2257          * return.
2258          */
2259 }
2260 
2261 
2262 /* Packet receiver for "standard" RFC1201-style packets
2263  */
2264 static void
2265 arcnetA_rx(struct device *dev,u_char *buf,
     /* [previous][next][first][last][top][bottom][index][help] */
2266         int length,u_char saddr, u_char daddr)
2267 {
2268         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2269         struct sk_buff *skb;
2270         struct ClientData *arcsoft,*soft;
2271         
2272         BUGMSG(D_DURING,"it's an RFC1201 packet (length=%d)\n",
2273                         length);
2274                         
2275         /* compensate for EXTRA_CLIENTDATA (which isn't actually in the
2276          * packet)
2277          */
2278         arcsoft=(struct ClientData *)(buf-EXTRA_CLIENTDATA);
2279         length+=EXTRA_CLIENTDATA;
2280 
2281         if (arcsoft->split_flag==0xFF)  /* Exception Packet */
2282         {
2283                 BUGMSG(D_DURING,"compensating for exception packet\n");
2284 
2285                 /* skip over 4-byte junkola */
2286                 arcsoft=(struct ClientData *)
2287                         ((u_char *)arcsoft + 4);
2288                 length-=4;
2289         }
2290         
2291         if (!arcsoft->split_flag)               /* not split */
2292         {
2293                 struct Incoming *in=&lp->incoming[saddr];
2294 
2295                 BUGMSG(D_RX,"incoming is not split (splitflag=%d)\n",
2296                         arcsoft->split_flag);
2297                         
2298                 if (in->skb)    /* already assembling one! */
2299                 {
2300                         BUGMSG(D_EXTRA,"aborting assembly (seq=%d) for unsplit packet (splitflag=%d, seq=%d)\n",
2301                                 in->sequence,arcsoft->split_flag,
2302                                 arcsoft->sequence);
2303                         kfree_skb(in->skb,FREE_WRITE);
2304                         lp->stats.rx_errors++;
2305                         lp->stats.rx_missed_errors++;
2306                         in->skb=NULL;
2307                 }
2308                 
2309                 in->sequence=arcsoft->sequence;
2310 
2311                 skb = alloc_skb(length, GFP_ATOMIC);
2312                 if (skb == NULL) {
2313                         printk("%6s: Memory squeeze, dropping packet.\n",
2314                                 dev->name);
2315                         lp->stats.rx_dropped++;
2316                         return;
2317                 }
2318                 soft=(struct ClientData *)skb->data;
2319                 
2320                 skb->len = length;
2321                 skb->dev = dev;
2322                 
2323                 memcpy((u_char *)soft+EXTRA_CLIENTDATA,
2324                         (u_char *)arcsoft+EXTRA_CLIENTDATA,
2325                         length-EXTRA_CLIENTDATA);
2326                 soft->daddr=daddr;
2327                 soft->saddr=saddr;
2328                 
2329                 /* ARP packets have problems when sent from DOS.
2330                  * source address is always 0 on some systems!  So we take
2331                  * the hardware source addr (which is impossible to fumble)
2332                  * and insert it ourselves.
2333                  */
2334                 if (soft->protocol_id == ARC_P_ARP)
2335                 {
2336                         struct arphdr *arp=(struct arphdr *)
2337                                         ((char *)soft+sizeof(struct ClientData));
2338 
2339                         /* make sure addresses are the right length */
2340                         if (arp->ar_hln==1 && arp->ar_pln==4)
2341                         {
2342                                 char *cptr=(char *)(arp)+sizeof(struct arphdr);
2343                                 
2344                                 if (!*cptr)     /* is saddr = 00? */
2345                                 {
2346                                         BUGMSG(D_EXTRA,"ARP source address was 00h, set to %02Xh.\n",
2347                                                         saddr);
2348                                         lp->stats.rx_crc_errors++;
2349                                         *cptr=saddr;
2350                                 }
2351                                 else
2352                                 {
2353                                         BUGMSG(D_DURING,"ARP source address (%Xh) is fine.\n",
2354                                                 *cptr);
2355                                 }
2356                         }
2357                         else
2358                         {
2359                                 printk("%6s: funny-shaped ARP packet. (%Xh, %Xh)\n",
2360                                         dev->name,arp->ar_hln,arp->ar_pln);
2361                                 lp->stats.rx_errors++;
2362                                 lp->stats.rx_crc_errors++;
2363                         }
2364                 }
2365                 
2366                 BUGLVL(D_SKB)
2367                 {
2368                     short i;
2369                         for( i=0; i< skb->len; i++)
2370                         {
2371                                 if( i%16 == 0 ) printk("\n[%04hX] ",i);
2372                                 printk("%02hX ",((unsigned char*)skb->data)[i]);
2373                         }
2374                         printk("\n");
2375                 }
2376 
2377                 #ifndef LINUX12
2378                 skb->protocol=arcnetA_type_trans(skb,dev);
2379                 #endif
2380 
2381                 netif_rx(skb);
2382          }
2383          else                   /* split packet */
2384          {
2385                  /* NOTE:  MSDOS ARP packet correction should only need to
2386                   * apply to unsplit packets, since ARP packets are so short.
2387                   *
2388                   * My interpretation of the RFC1201 (ARCnet) document is that
2389                   * if a packet is received out of order, the entire assembly
2390                   * process should be aborted.
2391                   *
2392                   * The RFC also mentions "it is possible for successfully
2393                   * received packets to be retransmitted."  As of 0.40 all
2394                   * previously received packets are allowed, not just the
2395                   * most recent one.
2396                   *
2397                   * We allow multiple assembly processes, one for each
2398                   * ARCnet card possible on the network.  Seems rather like
2399                   * a waste of memory.  Necessary?
2400                   */
2401                   
2402                 struct Incoming *in=&lp->incoming[saddr];
2403                 
2404                 BUGMSG(D_RX,"packet is split (splitflag=%d, seq=%d)\n",
2405                         arcsoft->split_flag,in->sequence);
2406 
2407                 if (in->skb && in->sequence!=arcsoft->sequence)
2408                 {
2409                         BUGMSG(D_EXTRA,"wrong seq number, aborting assembly (expected=%d, seq=%d, splitflag=%d)\n",     
2410                                 in->sequence,arcsoft->sequence,
2411                                 arcsoft->split_flag);
2412                         kfree_skb(in->skb,FREE_WRITE);
2413                         in->skb=NULL;
2414                         lp->stats.rx_errors++;
2415                         lp->stats.rx_missed_errors++;
2416                         in->lastpacket=in->numpackets=0;
2417                 }
2418                   
2419                 if (arcsoft->split_flag & 1)    /* first packet in split */
2420                 {
2421                         BUGMSG(D_RX,"brand new splitpacket (splitflag=%d)\n",
2422                                 arcsoft->split_flag);
2423                         if (in->skb)    /* already assembling one! */
2424                         {
2425                                 BUGMSG(D_EXTRA,"aborting previous (seq=%d) assembly (splitflag=%d, seq=%d)\n",
2426                                         in->sequence,arcsoft->split_flag,
2427                                         arcsoft->sequence);
2428                                 lp->stats.rx_errors++;
2429                                 lp->stats.rx_missed_errors++;
2430                                 kfree_skb(in->skb,FREE_WRITE);
2431                         }
2432 
2433                         in->sequence=arcsoft->sequence;
2434                         in->numpackets=((unsigned)arcsoft->split_flag>>1)+2;
2435                         in->lastpacket=1;
2436                         
2437                         if (in->numpackets>16)
2438                         {
2439                                 BUGMSG(D_EXTRA,"incoming packet more than 16 segments; dropping. (splitflag=%d)\n",
2440                                         arcsoft->split_flag);
2441                                 lp->stats.rx_errors++;
2442                                 lp->stats.rx_length_errors++;
2443                                 return;
2444                         }
2445                 
2446                         in->skb=skb=alloc_skb(508*in->numpackets
2447                                         + sizeof(struct ClientData),
2448                                         GFP_ATOMIC);
2449                         if (skb == NULL) {
2450                                 printk("%6s: (split) memory squeeze, dropping packet.\n", 
2451                                         dev->name);
2452                                 lp->stats.rx_dropped++;
2453                                 return;
2454                         }
2455                                         
2456                         /* I don't know what this is for, but it DOES avoid
2457                          * warnings...
2458                          */
2459                         skb->free=1;
2460                         
2461                         soft=(struct ClientData *)skb->data;
2462                         
2463                         skb->len=sizeof(struct ClientData);
2464                         skb->dev=dev;
2465 
2466                         memcpy((u_char *)soft+EXTRA_CLIENTDATA,
2467                                 (u_char *)arcsoft+EXTRA_CLIENTDATA,
2468                                 sizeof(struct ClientData)-EXTRA_CLIENTDATA);
2469                         soft->split_flag=0; /* final packet won't be split */
2470                 }
2471                 else                    /* not first packet */
2472                 {
2473                         int packetnum=((unsigned)arcsoft->split_flag>>1) + 1;
2474 
2475                         /* if we're not assembling, there's no point
2476                          * trying to continue.
2477                          */                     
2478                         if (!in->skb)
2479                         {
2480                                 BUGMSG(D_EXTRA,"can't continue split without starting first! (splitflag=%d, seq=%d)\n",
2481                                         arcsoft->split_flag,arcsoft->sequence);
2482                                 lp->stats.rx_errors++;
2483                                 lp->stats.rx_missed_errors++;
2484                                 return;
2485                         }
2486 
2487                         in->lastpacket++;
2488                         if (packetnum!=in->lastpacket) /* not the right flag! */
2489                         {
2490                                 /* harmless duplicate? ignore. */
2491                                 if (packetnum<=in->lastpacket-1)
2492                                 {
2493                                         BUGMSG(D_EXTRA,"duplicate splitpacket ignored! (splitflag=%d)\n",
2494                                                 arcsoft->split_flag);
2495                                         lp->stats.rx_errors++;
2496                                         lp->stats.rx_frame_errors++;
2497                                         return;
2498                                 }
2499                                 
2500                                 /* "bad" duplicate, kill reassembly */
2501                                 BUGMSG(D_EXTRA,"out-of-order splitpacket, reassembly (seq=%d) aborted (splitflag=%d, seq=%d)\n",        
2502                                         in->sequence,arcsoft->split_flag,
2503                                         arcsoft->sequence);
2504                                 kfree_skb(in->skb,FREE_WRITE);
2505                                 in->skb=NULL;
2506                                 lp->stats.rx_errors++;
2507                                 lp->stats.rx_missed_errors++;
2508                                 in->lastpacket=in->numpackets=0;
2509                                 return;
2510                         }
2511 
2512                         soft=(struct ClientData *)in->skb->data;
2513                 }
2514                 
2515                 skb=in->skb;
2516                 
2517                 memcpy(skb->data+skb->len,
2518                        (u_char *)arcsoft+sizeof(struct ClientData),
2519                        length-sizeof(struct ClientData));
2520 
2521                 skb->len+=length-sizeof(struct ClientData);
2522                 
2523                 soft->daddr=daddr;
2524                 soft->saddr=saddr;
2525                 
2526                 /* are we done? */
2527                 if (in->lastpacket == in->numpackets)
2528                 {
2529                         if (!skb || !in->skb)
2530                         {
2531                                 printk("%6s: ?!? done reassembling packet, no skb? (skb=%ph, in->skb=%ph)\n",
2532                                         dev->name,skb,in->skb);
2533                         }
2534                         else
2535                         {
2536                                 in->skb=NULL;
2537                                 in->lastpacket=in->numpackets=0;
2538                         
2539                                 BUGLVL(D_SKB)
2540                                 {
2541                                     short i;
2542                                         for(i=0; i<skb->len; i++)
2543                                         {
2544                                                 if( i%16 == 0 ) printk("\n[%04hX] ",i);
2545                                                 printk("%02hX ",((unsigned char*)skb->data)[i]);
2546                                         }
2547                                         printk("\n");
2548                                 }
2549 
2550                         
2551                                 #ifndef LINUX12
2552                                 skb->protocol=arcnetA_type_trans(skb,dev);
2553                                 #endif
2554                                 
2555                                 netif_rx(skb);
2556                         }
2557                 }
2558          }
2559 }
2560 
2561 
2562 /* Packet receiver for non-standard ethernet-style packets
2563  */
2564 static void
2565 arcnetE_rx(struct device *dev,u_char *arcsoft,
     /* [previous][next][first][last][top][bottom][index][help] */
2566         int length,u_char saddr, u_char daddr)
2567 {
2568         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2569         struct sk_buff *skb;
2570         
2571         BUGMSG(D_DURING,"it's an ethernet-encap packet (length=%d)\n",
2572                         length);
2573 
2574         skb = alloc_skb(length, GFP_ATOMIC);
2575         if (skb == NULL) {
2576                 printk("%6s: Memory squeeze, dropping packet.\n",dev->name);
2577                 lp->stats.rx_dropped++;
2578                 return;
2579         }
2580         
2581         skb->len = length;
2582         skb->dev = dev;
2583         
2584         memcpy(skb->data,(u_char *)arcsoft+1,length-1);
2585 
2586         BUGLVL(D_SKB)
2587         {
2588                 short i;
2589                 printk("%6s: rx skb dump follows:\n",dev->name);
2590                 for(i=0; i<skb->len; i++)
2591                 {
2592                         if (i%16==0)
2593                                 printk("\n[%04hX] ",i);
2594                         else
2595                                 printk("%02hX ",((u_char *)skb->data)[i]);
2596                 }
2597                 printk("\n");
2598         }
2599         
2600         #ifndef LINUX12
2601         skb->protocol=eth_type_trans(skb,dev);
2602         #endif
2603         
2604         netif_rx(skb);
2605 }
2606 
2607 /* Packet receiver for RFC1051 packets; 
2608  */
2609 static void
2610 arcnetS_rx(struct device *dev,u_char *buf,
     /* [previous][next][first][last][top][bottom][index][help] */
2611         int length,u_char saddr, u_char daddr)
2612 {
2613         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2614         struct sk_buff *skb;
2615         struct S_ClientData *arcsoft,*soft;
2616         
2617         arcsoft=(struct S_ClientData *)(buf-S_EXTRA_CLIENTDATA);
2618         length+=S_EXTRA_CLIENTDATA;
2619         
2620         BUGMSG(D_DURING,"it's an RFC1051 packet (length=%d)\n",
2621                         length);
2622                         
2623         
2624                         
2625         {    /* was "if not split" in A protocol, S is never split */   
2626 
2627                 skb = alloc_skb(length, GFP_ATOMIC);
2628                 if (skb == NULL) {
2629                         printk("arcnetS: Memory squeeze, dropping packet.\n");
2630                         lp->stats.rx_dropped++;
2631                         return;
2632                 }
2633                 soft=(struct S_ClientData *)skb->data;
2634                 skb->len = length;
2635                 memcpy((u_char *)soft + sizeof(struct S_ClientData)
2636                                 - S_EXTRA_CLIENTDATA,
2637                         (u_char *)arcsoft + sizeof(struct S_ClientData)
2638                                 - S_EXTRA_CLIENTDATA, 
2639                         length - sizeof(struct S_ClientData)
2640                                 + S_EXTRA_CLIENTDATA);
2641                 soft->protocol_id=arcsoft->protocol_id;
2642                 soft->daddr=daddr;
2643                 soft->saddr=saddr;
2644                 skb->dev = dev;  /* is already lp->sdev */
2645                 
2646                 BUGLVL(D_SKB)
2647                 {
2648                         short i;
2649                         for(i=0; i<skb->len; i++)
2650                         {
2651                                 if( i%16 == 0 ) printk("\n[%04hX] ",i);
2652                                 printk("%02hX ",((unsigned char*)skb->data)[i]);
2653                         }
2654                         printk("\n");
2655                 }
2656 
2657                 #ifndef LINUX12
2658                 skb->protocol=arcnetS_type_trans(skb,dev);
2659                 #endif
2660 
2661                 netif_rx(skb);
2662          }
2663 }
2664 
2665 
2666 
2667 /****************************************************************************
2668  *                                                                          *
2669  * Miscellaneous routines                                                   *
2670  *                                                                          *
2671  ****************************************************************************/
2672 
2673 
2674 /* Get the current statistics.  This may be called with the card open or
2675  * closed.
2676  */
2677 
2678 static struct enet_statistics *
2679 arcnet_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
2680 {
2681         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2682 
2683         return &lp->stats;
2684 }
2685 
2686 /* Set or clear the multicast filter for this adaptor.
2687  * num_addrs == -1      Promiscuous mode, receive all packets
2688  * num_addrs == 0       Normal mode, clear multicast list
2689  * num_addrs > 0        Multicast mode, receive normal and MC packets, and do
2690  *                      best-effort filtering.
2691  */
2692 static void
2693 set_multicast_list(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
2694 {
2695 #if 0     /* no promiscuous mode at all on most (all?) ARCnet models */
2696         struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
2697 
2698         short ioaddr = dev->base_addr;
2699         if (num_addrs) {
2700                 outw(69, ioaddr);               /* Enable promiscuous mode */
2701         } else
2702                 outw(99, ioaddr);               /* Disable promiscuous mode, use normal mode */
2703 #endif
2704 }
2705 
2706 /* Create the ARCnet ClientData header for an arbitrary protocol layer
2707  *
2708  * saddr=NULL   means use device source address (always will anyway)
2709  * daddr=NULL   means leave destination address (eg unresolved arp)
2710  */
2711 #ifdef LINUX12
2712 int arcnetA_header(unsigned char *buff,struct device *dev,
     /* [previous][next][first][last][top][bottom][index][help] */
2713                 unsigned short type,void *daddr,void *saddr,unsigned len,
2714                 struct sk_buff *skb)
2715 #else
2716 int arcnetA_header(struct sk_buff *skb,struct device *dev,
2717                 unsigned short type,void *daddr,void *saddr,unsigned len)
2718 #endif
2719 {
2720         struct ClientData *head = (struct ClientData *)
2721 #ifdef LINUX12
2722                 buff;
2723 #else
2724                 skb_push(skb,dev->hard_header_len);
2725 #endif
2726         struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
2727 
2728         BUGMSG(D_DURING,"create header from %d to %d; protocol %d (%Xh); size %u.\n",
2729                         saddr ? *(u_char*)saddr : -1,
2730                         daddr ? *(u_char*)daddr : -1,
2731                         type,type,len);
2732 
2733         /* set the protocol ID according to RFC1201 */
2734         switch(type)
2735         {
2736         case ETH_P_IP:
2737                 head->protocol_id=ARC_P_IP;
2738                 break;
2739         case ETH_P_ARP:
2740                 head->protocol_id=ARC_P_ARP;
2741                 break;
2742         case ETH_P_RARP:
2743                 head->protocol_id=ARC_P_RARP;
2744                 break;
2745         case ETH_P_IPX:
2746         case ETH_P_802_3:
2747         case ETH_P_802_2:
2748                 head->protocol_id=ARC_P_IPX;
2749                 break;
2750         case ETH_P_ATALK:
2751                 head->protocol_id=ARC_P_ATALK;
2752                 break;
2753         default:
2754                 printk("%6s: I don't understand protocol %d (%Xh)\n",
2755                         dev->name,type,type);
2756                 lp->stats.tx_errors++;
2757                 lp->stats.tx_aborted_errors++;
2758                 return 0;
2759         }       
2760 
2761         /*
2762          * Set the source hardware address.
2763          *
2764          * This is pretty pointless for most purposes, but it can help
2765          * in debugging.  saddr is stored in the ClientData header and
2766          * removed before sending the packet (since ARCnet does not allow
2767          * us to change the source address in the actual packet sent)
2768          */
2769         if(saddr)
2770                 head->saddr=((u_char*)saddr)[0];
2771         else
2772                 head->saddr=((u_char*)(dev->dev_addr))[0];
2773 
2774         head->split_flag=0;     /* split packets are done elsewhere */
2775         head->sequence=0;       /* so are sequence numbers */
2776 
2777         /* supposedly if daddr is NULL, we should ignore it... */
2778         if(daddr)
2779         {
2780                 head->daddr=((u_char*)daddr)[0];
2781                 return dev->hard_header_len;
2782         }
2783         else
2784                 head->daddr=0;  /* better fill one in anyway */
2785                 
2786         return -dev->hard_header_len;
2787 }
2788 
2789 
2790 /* Create the ARCnet ClientData header for an arbitrary protocol layer
2791  *
2792  * saddr=NULL   means use device source address (always will anyway)
2793  * daddr=NULL   means leave destination address (eg unresolved arp)
2794  */
2795 #ifdef LINUX12
2796 int arcnetS_header(unsigned char *buff,struct device *dev,
     /* [previous][next][first][last][top][bottom][index][help] */
2797                 unsigned short type,void *daddr,void *saddr,unsigned len,
2798                 struct sk_buff *skb)
2799 #else
2800 int arcnetS_header(struct sk_buff *skb,struct device *dev,
2801                 unsigned short type,void *daddr,void *saddr,unsigned len)
2802 #endif
2803 {
2804         struct S_ClientData *head = (struct S_ClientData *)
2805 #ifdef LINUX12
2806                 buff;
2807 #else
2808                 skb_push(skb,dev->hard_header_len);
2809 #endif
2810         struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
2811 
2812         /* set the protocol ID according to RFC1051 */
2813         switch(type)
2814         {
2815         case ETH_P_IP:
2816                 head->protocol_id=ARC_P_IP_RFC1051;
2817                 BUGMSG(D_DURING,"S_header: IP_RFC1051 packet.\n");
2818                 break;
2819         case ETH_P_ARP:
2820                 head->protocol_id=ARC_P_ARP_RFC1051;
2821                 BUGMSG(D_DURING,"S_header: ARP_RFC1051 packet.\n");
2822                 break;
2823         default:
2824                 printk("arcnetS: I don't understand protocol %d (%Xh)\n",
2825                         type,type);
2826                 lp->stats.tx_errors++;
2827                 lp->stats.tx_aborted_errors++;
2828                 return 0;
2829         }       
2830 
2831         /*
2832          * Set the source hardware address.
2833          *
2834          * This is pretty pointless for most purposes, but it can help
2835          * in debugging.  saddr is stored in the ClientData header and
2836          * removed before sending the packet (since ARCnet does not allow
2837          * us to change the source address in the actual packet sent)
2838          */
2839         if(saddr)
2840                 head->saddr=((u_char*)saddr)[0];
2841         else
2842                 head->saddr=((u_char*)(dev->dev_addr))[0];
2843 
2844         /* supposedly if daddr is NULL, we should ignore it... */
2845         if(daddr)
2846         {
2847                 head->daddr=((u_char*)daddr)[0];
2848                 return dev->hard_header_len;
2849         }
2850         else
2851                 head->daddr=0;  /* better fill one in anyway */
2852                 
2853         return -dev->hard_header_len;
2854 }
2855 
2856 
2857 
2858 /* Rebuild the ARCnet ClientData header. This is called after an ARP
2859  * (or in future other address resolution) has completed on this
2860  * sk_buff. We now let ARP fill in the other fields.
2861  */
2862 int arcnetA_rebuild_header(void *buff,struct device *dev,unsigned long dst,
     /* [previous][next][first][last][top][bottom][index][help] */
2863                 struct sk_buff *skb)
2864 {
2865         struct ClientData *head = (struct ClientData *)buff;
2866         struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
2867         int status;
2868 
2869         /*
2870          * Only ARP and IP are currently supported
2871          */
2872          
2873         if(head->protocol_id != ARC_P_IP) 
2874         {
2875                 printk("%6s: I don't understand protocol type %d (%Xh) addresses!\n",
2876                         dev->name,head->protocol_id,head->protocol_id);
2877                 lp->stats.tx_errors++;
2878                 lp->stats.tx_aborted_errors++;
2879                 head->daddr=0;
2880                 /*memcpy(eth->h_source, dev->dev_addr, dev->addr_len);*/
2881                 return 0;
2882         }
2883 
2884         /*
2885          * Try and get ARP to resolve the header.
2886          */
2887 #ifdef CONFIG_INET       
2888         BUGMSG(D_DURING,"rebuild header from %d to %d; protocol %Xh\n",
2889                         head->saddr,head->daddr,head->protocol_id);
2890         status=arp_find(&(head->daddr), dst, dev, dev->pa_addr, skb)? 1 : 0;
2891         BUGMSG(D_DURING," rebuilt: from %d to %d; protocol %Xh\n",
2892                         head->saddr,head->daddr,head->protocol_id);
2893         return status;
2894 #else
2895         return 0;       
2896 #endif  
2897 }
2898 
2899 
2900 int arcnetS_rebuild_header(void *buff,struct device *dev,unsigned long dst,
     /* [previous][next][first][last][top][bottom][index][help] */
2901                 struct sk_buff *skb)
2902 {
2903         struct S_ClientData *head = (struct S_ClientData *)buff;
2904         struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
2905 
2906         /*
2907          * Only ARP and IP are currently supported
2908          */
2909          
2910         if(head->protocol_id != ARC_P_IP_RFC1051) 
2911         {
2912                 printk("arcnetS: I don't understand protocol type %d (%Xh) addresses!\n",
2913                         head->protocol_id,head->protocol_id);
2914                 lp->stats.tx_errors++;
2915                 lp->stats.tx_aborted_errors++;
2916                 head->daddr=0;
2917                 /*memcpy(eth->h_source, dev->dev_addr, dev->addr_len);*/
2918                 return 0;
2919         }
2920 
2921         /*
2922          * Try and get ARP to resolve the header.
2923          */
2924 #ifdef CONFIG_INET       
2925         return arp_find(&(head->daddr), dst, dev, dev->pa_addr, skb)? 1 : 0;
2926 #else
2927         return 0;       
2928 #endif  
2929 }
2930 
2931                 
2932 /* Determine a packet's protocol ID.
2933  *
2934  * With ARCnet we have to convert everything to Ethernet-style stuff.
2935  */
2936 unsigned short arcnetA_type_trans(struct sk_buff *skb,struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
2937 {
2938         struct ClientData *head;
2939         struct arcnet_local *lp=(struct arcnet_local *) (dev->priv);
2940 
2941 #ifdef LINUX12
2942         head=(struct ClientData *)skb->data;
2943 #else
2944         /* Pull off the arcnet header. */
2945         skb->mac.raw=skb->data;
2946         skb_pull(skb,dev->hard_header_len);
2947         head=(struct ClientData *)skb->mac.raw;
2948 #endif
2949         
2950         if (head->daddr==0)
2951                 skb->pkt_type=PACKET_BROADCAST;
2952         else if (dev->flags&IFF_PROMISC)
2953         {
2954                 /* if we're not sending to ourselves :) */
2955                 if (head->daddr != dev->dev_addr[0])
2956                         skb->pkt_type=PACKET_OTHERHOST;
2957         }
2958         
2959         /* now return the protocol number */
2960         switch (head->protocol_id)
2961         {
2962         case ARC_P_IP:          return htons(ETH_P_IP);
2963         case ARC_P_ARP:         return htons(ETH_P_ARP);
2964         case ARC_P_RARP:        return htons(ETH_P_RARP);
2965         case ARC_P_IPX:         return htons(ETH_P_802_3);
2966         case ARC_P_ATALK:   return htons(ETH_P_ATALK); /* untested appletalk */
2967         case ARC_P_LANSOFT: /* don't understand.  fall through. */
2968         default:
2969                 BUGMSG(D_EXTRA,"received packet of unknown protocol id %d (%Xh)\n",
2970                                 head->protocol_id,head->protocol_id);
2971                 lp->stats.rx_errors++;
2972                 lp->stats.rx_crc_errors++;
2973                 return 0;
2974         }
2975 
2976         return htons(ETH_P_IP);
2977 }
2978 
2979 
2980 unsigned short arcnetS_type_trans(struct sk_buff *skb,struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
2981 {
2982         struct S_ClientData *head;
2983         struct arcnet_local *lp=(struct arcnet_local *) (dev->priv);
2984 
2985 #ifdef LINUX12
2986         head=(struct S_ClientData *)skb->data;
2987 #else
2988         /* Pull off the arcnet header. */
2989         skb->mac.raw=skb->data;
2990         skb_pull(skb,dev->hard_header_len);
2991         head=(struct S_ClientData *)skb->mac.raw;
2992 #endif
2993         
2994         if (head->daddr==0)
2995                 skb->pkt_type=PACKET_BROADCAST;
2996         else if (dev->flags&IFF_PROMISC)
2997         {
2998                 /* if we're not sending to ourselves :) */
2999                 if (head->daddr != dev->dev_addr[0])
3000                         skb->pkt_type=PACKET_OTHERHOST;
3001         }
3002         
3003         /* now return the protocol number */
3004         switch (head->protocol_id)
3005         {
3006         case ARC_P_IP_RFC1051:  return htons(ETH_P_IP);
3007         case ARC_P_ARP_RFC1051: return htons(ETH_P_ARP);
3008         default:
3009                 BUGMSG(D_EXTRA,"received packet of unknown protocol id %d (%Xh)\n",
3010                                 head->protocol_id,head->protocol_id);
3011                 lp->stats.rx_errors++;
3012                 lp->stats.rx_crc_errors++;
3013                 return 0;
3014         }
3015 
3016         return htons(ETH_P_IP);
3017 }
3018 
3019 
3020 
3021 /****************************************************************************
3022  *                                                                          *
3023  * Kernel Loadable Module Support                                           *
3024  *                                                                          *
3025  ****************************************************************************/
3026 
3027 
3028 #ifdef MODULE
3029 static char devicename[9] = { 0, };
3030 static struct device thiscard = {
3031   devicename, /* device name is inserted by linux/drivers/net/net_init.c */
3032   0, 0, 0, 0,
3033   0, 0,  /* I/O address, IRQ */
3034   0, 0, 0, NULL, arcnet_probe
3035 };
3036         
3037         
3038 static int io=0x0;      /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
3039 static int irqnum=0;    /* or use the insmod io= irqnum= shmem= options */
3040 static int shmem=0;
3041 static int num=0;       /* number of device (ie for 0 for arc0, 1 for arc1...) */
3042 
3043 int
3044 init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
3045 {
3046         sprintf(thiscard.name,"arc%d",num);
3047 
3048         thiscard.base_addr=io;
3049 
3050         thiscard.irq=irqnum;
3051         if (thiscard.irq==2) thiscard.irq=9;
3052 
3053         if (shmem)
3054         {
3055                 thiscard.mem_start=shmem;
3056                 thiscard.mem_end=thiscard.mem_start+512*4-1;
3057                 thiscard.rmem_start=thiscard.mem_start+512*0;
3058                 thiscard.rmem_end=thiscard.mem_start+512*2-1;
3059         }
3060 
3061         if (register_netdev(&thiscard) != 0)
3062                 return -EIO;
3063         return 0;
3064 }
3065 
3066 void
3067 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
3068 {
3069         if (thiscard.start) arcnet_close(&thiscard);
3070         if (thiscard.irq) free_irq(thiscard.irq);
3071         if (thiscard.base_addr) release_region(thiscard.base_addr,
3072                                                 ARCNET_TOTAL_SIZE);
3073         unregister_netdev(&thiscard);
3074         kfree(thiscard.priv);
3075         thiscard.priv = NULL;
3076 }
3077 
3078 #endif /* MODULE */
3079 
3080 
3081 
3082 /*
3083  * Local variables:
3084  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c arcnet.c"
3085  *  version-control: t
3086  *  kept-new-versions: 5
3087  *  tab-width: 8
3088  * End:
3089  */
3090 

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