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

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